diff --git a/.cproject b/.cproject
index 8084a7c..59a6803 100644
--- a/.cproject
+++ b/.cproject
@@ -24,6 +24,7 @@
+
@@ -33,8 +34,9 @@
+
-
+
@@ -42,8 +44,9 @@
+
-
+
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index ef6f6a9..05c71b6 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/demo/mainwindow.cpp b/demo/mainwindow.cpp
index 7c36326..4ac1ddc 100644
--- a/demo/mainwindow.cpp
+++ b/demo/mainwindow.cpp
@@ -58,6 +58,7 @@ static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
DockWidget->setWidget(w);
DockWidget->setObjectName(DockWidget->windowTitle());
+ DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
}
@@ -84,6 +85,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
+ ui->toolBar->addAction(ui->actionSaveState);
+ ui->actionSaveState->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
+ ui->toolBar->addAction(ui->actionRestoreState);
+ ui->actionRestoreState->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
m_DockManager = new ads::CDockManager(this);
createContent();
@@ -102,10 +107,11 @@ void MainWindow::createContent()
// Test container docking
QMenu* ViewMenu = this->ui->menuView;
auto DockWidget = createCalendarDockWidget(ViewMenu);
+ DockWidget->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
- /*m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
+ m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
DockWidget = createCalendarDockWidget(ViewMenu);
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
@@ -116,7 +122,7 @@ void MainWindow::createContent()
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
- m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/
+ m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
}
diff --git a/demo/mainwindow.ui b/demo/mainwindow.ui
index 11d4336..3f2c89c 100644
--- a/demo/mainwindow.ui
+++ b/demo/mainwindow.ui
@@ -13,6 +13,9 @@
MainWindow
+
+ QMainWindow::AllowTabbedDocks
+
+
+
+ toolBar
+
+
+ TopToolBarArea
+
+
+ false
+
+
Exit
diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp
index 494ebed..8269377 100644
--- a/src/DockWidget.cpp
+++ b/src/DockWidget.cpp
@@ -330,9 +330,31 @@ QAction* CDockWidget::toggleViewAction() const
}
+//============================================================================
+void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode)
+{
+ if (ActionModeToggle == Mode)
+ {
+ d->ToggleViewAction->setCheckable(true);
+ d->ToggleViewAction->setIcon(QIcon());
+ }
+ else
+ {
+ d->ToggleViewAction->setCheckable(false);
+ d->ToggleViewAction->setIcon(d->TitleWidget->icon());
+ }
+}
+
+
//============================================================================
void CDockWidget::toggleView(bool Open)
{
+ QAction* Sender = qobject_cast(sender());
+ if (Sender == d->ToggleViewAction && !d->ToggleViewAction->isCheckable())
+ {
+ Open = true;
+ }
+
if (Open)
{
d->showDockWidget();
@@ -391,6 +413,17 @@ bool CDockWidget::event(QEvent *e)
}
+//============================================================================
+void CDockWidget::setIcon(const QIcon& Icon)
+{
+ d->TitleWidget->setIcon(Icon);
+ if (!d->ToggleViewAction->isCheckable())
+ {
+ d->ToggleViewAction->setIcon(Icon);
+ }
+}
+
+
} // namespace ads
diff --git a/src/DockWidget.h b/src/DockWidget.h
index dd86551..15ec1dc 100644
--- a/src/DockWidget.h
+++ b/src/DockWidget.h
@@ -115,6 +115,20 @@ public:
StateFloating
};
+ /**
+ * This mode configures the behavior of the toggle view action.
+ * If the mode if ActionModeToggle, then the toggle view action is
+ * a checkable action to show / hide the dock widget. If the mode
+ * is ActionModeShow, then the action is not checkable an it will
+ * always show the dock widget if clicked. If the mode is ActionModeShow,
+ * the user can only close the DockWidget with the close button.
+ */
+ enum eToggleViewActionMode
+ {
+ ActionModeToggle,//!< ActionModeToggle
+ ActionModeShow //!< ActionModeShow
+ };
+
/**
* Default Constructor
*/
@@ -189,16 +203,28 @@ public:
QAction* toggleViewAction() const;
/**
- * Emits titleChanged signal if title change event occures
+ * Configures the behavior of the toggle view action.
+ * \see eToggleViewActionMode for a detailed description
+ */
+ void setToggleViewActionMode(eToggleViewActionMode Mode);
+
+ /**
+ * Emits titleChanged signal if title change event occurs
*/
virtual bool event(QEvent *e) override;
+ /**
+ * Sets the dock widget icon that is shown in tabs and in toggle view
+ * actions
+ */
+ void setIcon(const QIcon& Icon);
+
public slots:
/**
* This property controls whether the dock widget is open or closed.
* The toogleViewAction triggers this slot
*/
- void toggleView(bool Open);
+ void toggleView(bool Open = true);
signals:
/**
diff --git a/src/DockWidgetTitleBar.cpp b/src/DockWidgetTitleBar.cpp
index 90adc22..2663206 100644
--- a/src/DockWidgetTitleBar.cpp
+++ b/src/DockWidgetTitleBar.cpp
@@ -73,6 +73,7 @@ struct DockWidgetTitleBarPrivate
CDockAreaWidget* DockArea = nullptr;
eDragState DragState = DraggingInactive;
CFloatingDockContainer* FloatingWidget = nullptr;
+ QIcon Icon;
/**
* Private data constructor
@@ -347,6 +348,22 @@ CDockAreaWidget* CDockWidgetTitleBar::dockAreaWidget() const
{
return d->DockArea;
}
+
+
+//============================================================================
+void CDockWidgetTitleBar::setIcon(const QIcon& Icon)
+{
+ d->Icon = Icon;
+ d->IconLabel->setPixmap(Icon.pixmap(this->windowHandle(), QSize(16, 16)));
+ d->IconLabel->setVisible(true);
+}
+
+
+//============================================================================
+const QIcon& CDockWidgetTitleBar::icon() const
+{
+ return d->Icon;
+}
} // namespace ads
//---------------------------------------------------------------------------
diff --git a/src/DockWidgetTitleBar.h b/src/DockWidgetTitleBar.h
index 24944ab..e96b42b 100644
--- a/src/DockWidgetTitleBar.h
+++ b/src/DockWidgetTitleBar.h
@@ -96,6 +96,16 @@ public:
*/
CDockAreaWidget* dockAreaWidget() const;
+ /**
+ * Sets the icon to show in title bar
+ */
+ void setIcon(const QIcon& Icon);
+
+ /**
+ * Returns the icon
+ */
+ const QIcon& icon() const;
+
signals:
void activeTabChanged();
void clicked();