mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #680, now display CDockWidget context menus in views/info area
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "marginsinput.h"
|
#include "marginsinput.h"
|
||||||
#include "ui_marginsinput.h"
|
#include "ui_marginsinput.h"
|
||||||
|
#include "blackgui/stylesheetutility.h"
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -65,6 +66,13 @@ namespace BlackGui
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMarginsInput::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
bool s = CStyleSheetUtility::useStyleSheetInDerivedWidget(this, QStyle::PE_Widget);
|
||||||
|
if (s) { return; }
|
||||||
|
QFrame::paintEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void CMarginsInput::ps_Confirmed()
|
void CMarginsInput::ps_Confirmed()
|
||||||
{
|
{
|
||||||
const QMargins m(this->getMargins());
|
const QMargins m(this->getMargins());
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ namespace BlackGui
|
|||||||
//! Current values of margins
|
//! Current values of margins
|
||||||
QMargins getMargins() const;
|
QMargins getMargins() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! \copydoc QFrame::paintEvent
|
||||||
|
virtual void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Margins changed
|
//! Margins changed
|
||||||
void changedMargins(const QMargins &margins);
|
void changedMargins(const QMargins &margins);
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDockWidget::toggleFloating()
|
void CDockWidget::toggleFloating()
|
||||||
{
|
{
|
||||||
bool floating = !this->isFloating();
|
const bool floating = !this->isFloating();
|
||||||
if (!floating) { this->setFrameless(false); }
|
if (!floating) { this->setFrameless(false); }
|
||||||
this->setFloating(floating);
|
this->setFloating(floating);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,9 +219,9 @@ namespace BlackGui
|
|||||||
private:
|
private:
|
||||||
QWidget *m_titleBarWidgetEmpty = nullptr; //!< replacing default title bar
|
QWidget *m_titleBarWidgetEmpty = nullptr; //!< replacing default title bar
|
||||||
QWidget *m_titleBarWidgetOriginal = nullptr; //!< the original title bar
|
QWidget *m_titleBarWidgetOriginal = nullptr; //!< the original title bar
|
||||||
QWidgetAction *m_marginMenuAction = nullptr; //!< menu action for margins
|
QWidgetAction *m_marginMenuAction = nullptr; //!< menu widget(!) action for margin widget
|
||||||
Components::CMarginsInput *m_input = nullptr; //!< margins widget
|
Components::CMarginsInput *m_input = nullptr; //!< margins widget
|
||||||
CManagedStatusBar m_statusBar; //!< Status bar when floating
|
CManagedStatusBar m_statusBar; //!< status bar when floating
|
||||||
QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes
|
QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes
|
||||||
QSize m_preferredSizeWhenFloating; //!< preferred size when floating 1st time
|
QSize m_preferredSizeWhenFloating; //!< preferred size when floating 1st time
|
||||||
QSize m_initialDockedMinimumSize; //!< minimum size before first floating
|
QSize m_initialDockedMinimumSize; //!< minimum size before first floating
|
||||||
|
|||||||
@@ -50,10 +50,11 @@ namespace BlackGui
|
|||||||
//! Visible widget
|
//! Visible widget
|
||||||
bool isVisibleWidget() const;
|
bool isVisibleWidget() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
//! Contribute to menu
|
//! Contribute to menu
|
||||||
|
//! \remarks made public so other classes can nest this submenu
|
||||||
virtual void addToContextMenu(QMenu *contextMenu) const override;
|
virtual void addToContextMenu(QMenu *contextMenu) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
//! \copydoc CDockWidget::initialFloating
|
//! \copydoc CDockWidget::initialFloating
|
||||||
virtual void initialFloating() override;
|
virtual void initialFloating() override;
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ namespace BlackGui
|
|||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu);
|
QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu);
|
||||||
QMenu *subMenuDisplay = new QMenu("Display", menu);
|
QMenu *subMenuDisplay = new QMenu("Display", menu);
|
||||||
|
QMenu *subMenuRestore = new QMenu("Restore", menu);
|
||||||
|
subMenuRestore->setIcon(CIcons::load16());
|
||||||
|
subMenuRestore->addActions(this->getInfoAreaRestoreActions(subMenuRestore));
|
||||||
subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay));
|
subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay));
|
||||||
|
|
||||||
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
||||||
@@ -128,6 +131,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
menu->addMenu(subMenuDisplay);
|
menu->addMenu(subMenuDisplay);
|
||||||
menu->addMenu(subMenuToggleFloat);
|
menu->addMenu(subMenuToggleFloat);
|
||||||
|
menu->addMenu(subMenuRestore);
|
||||||
|
|
||||||
// where and how to display tab bar
|
// where and how to display tab bar
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
@@ -235,6 +239,25 @@ namespace BlackGui
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QAction *> CInfoArea::getInfoAreaRestoreActions(QWidget *parent) const
|
||||||
|
{
|
||||||
|
Q_ASSERT(parent);
|
||||||
|
int i = 0;
|
||||||
|
QList<QAction *> actions;
|
||||||
|
for (const CDockWidgetInfoArea *dockWidgetInfoArea : m_dockWidgetInfoAreas)
|
||||||
|
{
|
||||||
|
const QPixmap pm = this->indexToPixmap(i);
|
||||||
|
const QString wt(dockWidgetInfoArea->windowTitleBackup());
|
||||||
|
QAction *action = new QAction(QIcon(pm), wt, parent);
|
||||||
|
action->setData(i);
|
||||||
|
action->setObjectName(this->objectName().append(":getInfoAreaRestoreActions:").append(wt));
|
||||||
|
connect(action, &QAction::triggered, this, &CInfoArea::restoreDockWidgetInfoArea);
|
||||||
|
actions.append(action);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
QList<int> CInfoArea::getAreaIndexesDockedOrFloating(bool floating) const
|
QList<int> CInfoArea::getAreaIndexesDockedOrFloating(bool floating) const
|
||||||
{
|
{
|
||||||
QList<int> indexes;
|
QList<int> indexes;
|
||||||
@@ -355,6 +378,25 @@ namespace BlackGui
|
|||||||
this->toggleFloatingByIndex(index);
|
this->toggleFloatingByIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInfoArea::restoreDockWidgetInfoArea()
|
||||||
|
{
|
||||||
|
const QObject *sender = QObject::sender();
|
||||||
|
Q_ASSERT(sender);
|
||||||
|
const QAction *action = qobject_cast<const QAction *>(sender);
|
||||||
|
Q_ASSERT(action);
|
||||||
|
int index = action->data().toInt();
|
||||||
|
this->restoreDockWidgetInfoAreaByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoArea::restoreDockWidgetInfoAreaByIndex(int areaIndex)
|
||||||
|
{
|
||||||
|
if (!this->isValidAreaIndex(areaIndex)) { return; }
|
||||||
|
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
||||||
|
Q_ASSERT(dw);
|
||||||
|
if (!dw) return;
|
||||||
|
dw->restoreFromSettings();
|
||||||
|
}
|
||||||
|
|
||||||
void CInfoArea::selectLeftTab()
|
void CInfoArea::selectLeftTab()
|
||||||
{
|
{
|
||||||
if (!this->m_tabBar) return;
|
if (!this->m_tabBar) return;
|
||||||
|
|||||||
@@ -79,6 +79,11 @@ namespace BlackGui
|
|||||||
//! \param parent which will own the action (deletion)
|
//! \param parent which will own the action (deletion)
|
||||||
QList<QAction *> getInfoAreaToggleFloatingActions(QWidget *parent) const;
|
QList<QAction *> getInfoAreaToggleFloatingActions(QWidget *parent) const;
|
||||||
|
|
||||||
|
//! Create a list of actions to restore the info areas.
|
||||||
|
//! This could be used in a menu or somewhere else.
|
||||||
|
//! \param parent which will own the action (deletion)
|
||||||
|
QList<QAction *> getInfoAreaRestoreActions(QWidget *parent) const;
|
||||||
|
|
||||||
//! Docked area indexes
|
//! Docked area indexes
|
||||||
QList<int> getAreaIndexesDockedOrFloating(bool floating) const;
|
QList<int> getAreaIndexesDockedOrFloating(bool floating) const;
|
||||||
|
|
||||||
@@ -123,6 +128,12 @@ namespace BlackGui
|
|||||||
//! Toggle area floating (sender is QAction)
|
//! Toggle area floating (sender is QAction)
|
||||||
void toggleAreaFloatingByAction();
|
void toggleAreaFloatingByAction();
|
||||||
|
|
||||||
|
//! Restore dock widget`s state (from settings)
|
||||||
|
void restoreDockWidgetInfoArea();
|
||||||
|
|
||||||
|
//! Restore dock widget`s state (from settings)
|
||||||
|
void restoreDockWidgetInfoAreaByIndex(int areaIndex);
|
||||||
|
|
||||||
//! Select next left tab
|
//! Select next left tab
|
||||||
void selectLeftTab();
|
void selectLeftTab();
|
||||||
|
|
||||||
|
|||||||
@@ -158,19 +158,19 @@ namespace BlackGui
|
|||||||
|
|
||||||
CMenuAction CMenuActions::addMenu(const QIcon &icon, const QString &title, const QString &path)
|
CMenuAction CMenuActions::addMenu(const QIcon &icon, const QString &title, const QString &path)
|
||||||
{
|
{
|
||||||
CMenuAction menuAction(icon, title, path);
|
|
||||||
const QList<CMenuAction> exisitingMenu(this->getMenuActions(path));
|
const QList<CMenuAction> exisitingMenu(this->getMenuActions(path));
|
||||||
if (!exisitingMenu.isEmpty())
|
if (!exisitingMenu.isEmpty())
|
||||||
{
|
{
|
||||||
const CMenuAction existing(exisitingMenu.first());
|
const CMenuAction existingAction(exisitingMenu.first());
|
||||||
Q_ASSERT_X(exisitingMenu.size() > 1, Q_FUNC_INFO, "Redundant menu entries");
|
Q_ASSERT_X(exisitingMenu.size() > 1, Q_FUNC_INFO, "Redundant menu entries");
|
||||||
Q_ASSERT_X(existing.getTitle() != title, Q_FUNC_INFO, "Title mismatch");
|
Q_ASSERT_X(existingAction.getTitle() != title, Q_FUNC_INFO, "Title mismatch");
|
||||||
if (icon.isNull() && existing.hasIcon()) { return existing.getQAction(); }
|
if (icon.isNull() || existingAction.hasIcon()) { return existingAction.getQAction(); }
|
||||||
|
|
||||||
//! \todo replace if we have icon now, but not before
|
//! \todo replace if we have icon now, but not before
|
||||||
//! \todo avoid multiple menu entries
|
return existingAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMenuAction menuAction(icon, title, path);
|
||||||
menuAction.setSubMenu(true);
|
menuAction.setSubMenu(true);
|
||||||
return this->addAction(menuAction);
|
return this->addAction(menuAction);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,6 +170,10 @@ namespace BlackGui
|
|||||||
//! View load/save
|
//! View load/save
|
||||||
static const QString &pathViewLoadSave() { static const QString p("View.17.LoadSave"); return p; }
|
static const QString &pathViewLoadSave() { static const QString p("View.17.LoadSave"); return p; }
|
||||||
|
|
||||||
|
// ---- nested dock widgets ----
|
||||||
|
|
||||||
|
//! Nested dock widget
|
||||||
|
static const QString &pathDockWidgetNested() { static const QString p("DockWidget.Nested"); return p; }
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -611,6 +611,16 @@ namespace BlackGui
|
|||||||
if (menuActions.isEmpty()) { return; }
|
if (menuActions.isEmpty()) { return; }
|
||||||
menuActions.toQMenu(menu, true);
|
menuActions.toQMenu(menu, true);
|
||||||
|
|
||||||
|
// Nested dock widget menu
|
||||||
|
const CDockWidgetInfoArea *dockWidget = this->getDockWidgetInfoArea();
|
||||||
|
if (dockWidget)
|
||||||
|
{
|
||||||
|
if (!menu.isEmpty()) { menu.addSeparator(); }
|
||||||
|
const QString mm = QString("Dock widget '%1'").arg(dockWidget->windowTitleOrBackup());
|
||||||
|
QMenu *dockWidgetSubMenu = menu.addMenu(CIcons::text16(), mm);
|
||||||
|
dockWidget->addToContextMenu(dockWidgetSubMenu);
|
||||||
|
}
|
||||||
|
|
||||||
QPoint globalPos = this->mapToGlobal(pos);
|
QPoint globalPos = this->mapToGlobal(pos);
|
||||||
menu.exec(globalPos);
|
menu.exec(globalPos);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user