API Documentation
Loading...
Searching...
No Matches
Toolbar.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/ResizeVisibleAnimation.h>
3#include <NDEVR/QTTools.h>
4#include <QWidget>
5#include <QHBoxLayout>
6#include <QApplication>
7#include <QStyle>
8#include <QScreen>
9namespace NDEVR
10{
11 class Toolbar : public QWidget
12 {
13 public:
14 Toolbar(QWidget* parent = nullptr)
15 : QWidget(parent)
16 , m_layout(new QHBoxLayout(this))
17 {
18 m_layout->setContentsMargins(0, 0, 0, 0);
19 m_layout->setSpacing(0);
20 setLayout(m_layout);
21 setBackgroundRole(QPalette::ColorRole::AlternateBase);
22 setAutoFillBackground(true);
23 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
24 }
25 virtual void addWidget(const QPointer<QWidget>& widget)
26 {
27 if (widget.isNull())
28 return;
29 int location = m_layout->indexOf(widget);
30 if (location != -1)
31 return;//alread added
32 lib_assert(!m_custom_widgets.contains(widget), "already added");
33 m_custom_widgets.add(widget);
34 bool make_visible = (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
35 && widget->maximumWidth() > 0 && widget->maximumHeight() > 0;
36 widget->setParent(nullptr);
37 m_layout->addWidget(widget, 0);
38 if (make_visible)
39 {
40 widget->setVisible(false);
41 ResizeVisibleAnimation::run(widget, true, false);
42 }
43 }
44 virtual void removeWidget(const QPointer<QWidget>& widget)
45 {
46 if (widget.isNull())
47 return;
49 int index = m_layout->indexOf(widget);
50 if (index != -1)
51 {
52 if (widget->isVisible() && widget->width() > 0 && widget->height() > 0)
54 }
55 }
56 virtual void clear()
57 {
59 for (uint04 i = 0; i < m_custom_widgets.size(); i++)
60 {
61 if (m_custom_widgets[i].isNull())
62 continue;
63 //ui->left_side_layout->removeWidget(m_left_widgets[i]);
64 m_custom_widgets[i]->setParent(nullptr);
65 }
67 }
68 QSize minimumSizeHint() const override
69 {
70 QSize size;
71 size.setWidth(style()->pixelMetric(QStyle::PM_SmallIconSize));
72 size.setHeight(style()->pixelMetric(QStyle::PM_SmallIconSize));
73 return size;
74 }
75 QSize sizeHint() const override
76 {
77 QSize size = QWidget::sizeHint();
78 size.setHeight(style()->pixelMetric(QStyle::PM_SmallIconSize));
79 return size;
80 }
81 protected:
83 QHBoxLayout* m_layout;
84 };
85}
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:68
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
void add(t_type &&object)
Definition Buffer.hpp:211
bool contains(const t_type &element) const
Definition Buffer.hpp:651
constexpr t_index_type size() const
Definition Buffer.hpp:1374
void clear()
Definition Buffer.hpp:557
bool removeElement(const t_type &element)
Definition Buffer.hpp:1019
static void ClearLayout(QLayout *layout, bool delete_objects=false)
static ResizeVisibleAnimation * run(QWidget *widget, bool visible, bool vertical, int duration=-1, int delay=0)
static ResizeVisibleAnimation * runRemove(QWidget *widget, bool vertical, int duration=-1, int delay=0)
Definition Toolbar.h:12
QSize minimumSizeHint() const override
Definition Toolbar.h:68
QSize sizeHint() const override
Definition Toolbar.h:75
Toolbar(QWidget *parent=nullptr)
Definition Toolbar.h:14
virtual void removeWidget(const QPointer< QWidget > &widget)
Definition Toolbar.h:44
QHBoxLayout * m_layout
Definition Toolbar.h:83
Buffer< QPointer< QWidget > > m_custom_widgets
Definition Toolbar.h:82
virtual void clear()
Definition Toolbar.h:56
virtual void addWidget(const QPointer< QWidget > &widget)
Definition Toolbar.h:25
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94