-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DockModeMenu: a better menu to handle dock panels
Closes #529.
- Loading branch information
1 parent
f0d77a8
commit fe77cc7
Showing
4 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "dockmodemenu.h" | ||
|
||
#include <QtWidgets/QDockWidget> | ||
|
||
DockModeMenu::DockModeMenu(QString name, QDockWidget* w) | ||
: QMenu(name) | ||
, dockWidget(w) | ||
, offAction(addAction(tr("&Off", "The dock panel is hidden"), | ||
[this] { dockWidget->setVisible(false); })) | ||
, dockedAction(addAction(tr("&Docked"), | ||
[this] { | ||
dockWidget->setVisible(true); | ||
dockWidget->setFloating(false); | ||
})) | ||
, floatingAction(addAction( | ||
tr("&Floating", "The dock panel is floating, aka undocked"), [this] { | ||
dockWidget->setVisible(true); | ||
dockWidget->setFloating(true); | ||
})) | ||
{ | ||
offAction->setStatusTip(tr("Completely hide this list")); | ||
offAction->setCheckable(true); | ||
dockedAction->setStatusTip(tr("The list is shown within the main window")); | ||
dockedAction->setCheckable(true); | ||
floatingAction->setStatusTip( | ||
tr("The list is shown separately from the main window")); | ||
floatingAction->setCheckable(true); | ||
auto* radioGroup = new QActionGroup(this); | ||
for (auto* a : { offAction, dockedAction, floatingAction }) | ||
radioGroup->addAction(a); | ||
connect(dockWidget, &QDockWidget::visibilityChanged, this, | ||
&DockModeMenu::updateMode); | ||
connect(dockWidget, &QDockWidget::topLevelChanged, this, | ||
&DockModeMenu::updateMode); | ||
updateMode(); | ||
} | ||
|
||
void DockModeMenu::updateMode() | ||
{ | ||
if (dockWidget->isHidden()) | ||
offAction->setChecked(true); | ||
else if (dockWidget->isFloating()) | ||
floatingAction->setChecked(true); | ||
else | ||
dockedAction->setChecked(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <QtWidgets/QMenu> | ||
|
||
class QDockWidget; | ||
|
||
class DockModeMenu : public QMenu { | ||
Q_OBJECT | ||
public: | ||
DockModeMenu(QString name, QDockWidget* w); | ||
|
||
private slots: | ||
void updateMode(); | ||
|
||
private: | ||
QDockWidget* dockWidget; | ||
QAction* offAction; | ||
QAction* dockedAction; | ||
QAction* floatingAction; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters