27 #include <QGridLayout>
29 #include <QDockWidget>
30 #include <QToolButton>
32 #include <QSpacerItem>
41 mainWindow(mainWindow),
42 imageOffline(QPixmap::fromImage(QImage(QString::fromUtf8(
":/icons/network-offline.png")))),
43 imageIdle(QPixmap::fromImage(QImage(QString::fromUtf8(
":/icons/network-idle.png"))))
46 this->setContentsMargins(1, 1, 1, 1);
47 dockWidget = qobject_cast<QDockWidget*>(parentWidget());
48 layout =
new QGridLayout(
this);
50 layout->setSpacing(2);
51 layout->setContentsMargins(-1, 0, -1, 0);
53 statusIcon =
new QLabel(
this);
54 statusIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
55 layout->addWidget(statusIcon, 0, 0);
58 title =
new QLabel(dockWidget->windowTitle(),
this);
59 layout->addWidget(title, 0, 1);
61 editTitleBar =
new QToolBar(
this);
62 editTitleBar->setIconSize(QSize(16, 16));
64 icon3.addFile(QString::fromUtf8(
":/icons/accessories-text-editor-6.ico"), QSize(16, 16));
65 QAction* editTitleAction = editTitleBar->addAction(icon3,
"");
66 editTitleAction->setToolTip(
"Change the name of this widget instance");
69 layout->addWidget(editTitleBar, 0, 2);
71 QSpacerItem* spacer =
new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
72 layout->addItem(spacer, 0, 4);
75 undockButton =
new QToolButton(
this);
76 undockButton->setObjectName(QString::fromUtf8(
"undockButton"));
78 icon2.addFile(QString::fromUtf8(
":/icons/tab-detach.svg"), QSize(10, 10));
79 undockButton->setIcon(icon2);
80 undockButton->setIconSize(QSize(10, 10));
82 undockButton->setToolTip(
"Toggle the floating status of the widget");
83 layout->addWidget(undockButton, 0, 5);
84 closeButton =
new QToolButton(
this);
85 closeButton->setObjectName(QString::fromUtf8(
"btnClose"));
87 icon1.addFile(QString::fromUtf8(
":/icons/dialog-close.ico"), QSize(8, 8));
88 closeButton->setIcon(icon1);
89 closeButton->setIconSize(QSize(10, 10));
90 closeButton->setToolTip(
"Close the widget");
92 layout->addWidget(closeButton, 0, 6);
96 connect(closeButton, SIGNAL(clicked()), dockWidget, SLOT(close()));
107 if (!widget->parent())
109 widget->setParent(
this);
112 layout->addWidget(widget, 0, 3);
118 QDockWidget* dockWidget = qobject_cast<QDockWidget*>(parentWidget());
125 if (dockWidget->features() & QDockWidget::DockWidgetVerticalTitleBar)
128 size.setHeight(title->minimumWidth() + 30);
134 return layout->sizeHint();
143 QDockWidget* dockWidget = qobject_cast<QDockWidget*>(parentWidget());
148 if (dockWidget->features() & QDockWidget::DockWidgetVerticalTitleBar)
151 size.setHeight(layout->minimumSize().height());
160 size.setWidth(layout->minimumSize().width());
175 QDockWidget* dockWidget = qobject_cast<QDockWidget*>(parentWidget());
177 dockWidget->setFloating(!dockWidget->isFloating());
182 auto setTextColor = [
this](QString color)
184 title->setStyleSheet(
"QLabel { color : " + color +
"; }");
186 setTextColor(
"black");
187 QDockWidget* dockWidget = qobject_cast<QDockWidget*>(parentWidget());
188 title->setText(dockWidget->windowTitle());
191 case eManagedIceObjectCreated:
192 statusIcon->setToolTip(
"Component created");
195 case eManagedIceObjectInitializing:
196 statusIcon->setToolTip(
"Component initializing");
197 setTextColor(
"yellow");
200 case eManagedIceObjectInitialized:
201 if (dependencies.length() > 0)
203 QString waitingFor =
"Component initialized & waiting for dependencies: " + dependencies.join(
", ");
204 statusIcon->setToolTip(waitingFor);
205 title->setToolTip(waitingFor);
206 title->setText(dockWidget->windowTitle() +
" waiting for " + dependencies.at(0) + (dependencies.length() > 1 ?
" ..." :
""));
211 setTextColor(
"black");
212 statusIcon->setToolTip(
"Component initialized");
217 case eManagedIceObjectExited:
218 statusIcon->setToolTip(
"Component exited");
221 case eManagedIceObjectExiting:
222 statusIcon->setToolTip(
"Component exiting");
225 case eManagedIceObjectStarting:
226 statusIcon->setToolTip(
"Component starting");
227 setTextColor(
"yellow");
231 case eManagedIceObjectStarted:
232 if (dependencies.length() > 0)
234 QString connectedTo =
"Component started & connected to " + dependencies.join(
", ");
235 statusIcon->setToolTip(connectedTo);
236 title->setToolTip(connectedTo);
240 statusIcon->setToolTip(
"Component started");
251 case eManagedIceObjectStarted:
253 statusIcon->setPixmap(imageIdle);
259 statusIcon->setPixmap(imageOffline);
269 if (d.exec() == QDialog::Accepted)