diff --git a/src/blackgui/dockwidget.cpp b/src/blackgui/dockwidget.cpp index 9f72256bb..2a375f16d 100644 --- a/src/blackgui/dockwidget.cpp +++ b/src/blackgui/dockwidget.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include using namespace BlackMisc; using namespace BlackGui::Components; @@ -339,10 +341,12 @@ namespace BlackGui contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, &CDockWidget::toggleFloating); } - // Margin actions + // State actions (windows state) contextMenu->addAction(BlackMisc::CIcons::load16(), "Restore", this, &CDockWidget::restoreFromSettings); contextMenu->addAction(BlackMisc::CIcons::save16(), "Save state", this, &CDockWidget::saveToSettings); - contextMenu->addAction(BlackMisc::CIcons::save16(), "Reset to defaults", this, &CDockWidget::resetSettings); + contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset to defaults", this, &CDockWidget::resetSettings); + contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset position", this, &CDockWidget::resetPosition); + this->m_input->setMargins(this->contentsMargins()); contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), "Margins", this, &CDockWidget::ps_dummy); contextMenu->addAction(this->m_marginMenuAction); @@ -587,4 +591,11 @@ namespace BlackGui this->setSettings(s); this->restoreFromSettings(); } + + void CDockWidget::resetPosition() + { + // center on screen when floating + if (!this->isFloating()) { return; } + this->move(QApplication::desktop()->screen()->rect().center() - this->rect().center()); + } } // namespace diff --git a/src/blackgui/dockwidget.h b/src/blackgui/dockwidget.h index b89166db5..bb14100a3 100644 --- a/src/blackgui/dockwidget.h +++ b/src/blackgui/dockwidget.h @@ -123,6 +123,9 @@ namespace BlackGui //! Reset margin settings void resetSettings(); + //! Reset window position + void resetPosition(); + //! Set title and internally keep a backup void setWindowTitle(const QString &title); diff --git a/src/blackgui/infoarea.cpp b/src/blackgui/infoarea.cpp index cd7b02198..3397ae9d4 100644 --- a/src/blackgui/infoarea.cpp +++ b/src/blackgui/infoarea.cpp @@ -15,6 +15,7 @@ #include "blackgui/stylesheetutility.h" #include "blackmisc/icons.h" #include "blackmisc/logmessage.h" +#include "blackmisc/verify.h" #include #include @@ -100,9 +101,12 @@ namespace BlackGui QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu); QMenu *subMenuDisplay = new QMenu("Display", menu); QMenu *subMenuRestore = new QMenu("Restore", menu); + QMenu *subMenuResetPositions = new QMenu("Reset position", menu); subMenuRestore->setIcon(CIcons::load16()); + subMenuResetPositions->setIcon(CIcons::refresh16()); subMenuRestore->addActions(this->getInfoAreaRestoreActions(subMenuRestore)); subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay)); + subMenuResetPositions->addActions(this->getInfoAreaResetPositionActions(subMenuResetPositions)); QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu); bool c = false; // check connections @@ -131,6 +135,7 @@ namespace BlackGui menu->addMenu(subMenuDisplay); menu->addMenu(subMenuToggleFloat); + menu->addMenu(subMenuResetPositions); menu->addMenu(subMenuRestore); // where and how to display tab bar @@ -164,7 +169,6 @@ namespace BlackGui { if (!infoArea) { return false; } if (infoArea->isFloating()) { return false; } - return infoArea == this->getSelectedDockInfoArea(); } @@ -220,6 +224,25 @@ namespace BlackGui return actions; } + QList CInfoArea::getInfoAreaResetPositionActions(QWidget *parent) const + { + Q_ASSERT(parent); + int i = 0; + QList 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(":getInfoAreaResetPositionActions:").append(wt)); + connect(action, &QAction::triggered, this, &CInfoArea::resetPositionByAction); + actions.append(action); + i++; + } + return actions; + } + QList CInfoArea::getInfoAreaToggleFloatingActions(QWidget *parent) const { Q_ASSERT(parent); @@ -326,8 +349,8 @@ namespace BlackGui { if (!this->isValidAreaIndex(areaIndex)) { return; } CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex); - Q_ASSERT(dw); - if (!dw) return; + BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area"); + if (!dw) { return; } dw->toggleFloating(); } @@ -335,15 +358,15 @@ namespace BlackGui { if (!this->isValidAreaIndex(areaIndex)) { return; } CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex); - Q_ASSERT(dw); - if (!dw) return; + BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area"); + if (!dw) { return; } dw->toggleVisibility(); } void CInfoArea::selectArea(int areaIndex) { CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex); - Q_ASSERT(dw); + BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area"); if (!dw) { return; } Q_ASSERT(this->m_tabBar); if (m_tabBar->count() < 1) { return; } @@ -358,20 +381,35 @@ namespace BlackGui } } + void CInfoArea::resetPosition(int areaIndex) + { + CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex); + BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area"); + if (!dw) { return; } + dw->resetPosition(); + } + void CInfoArea::selectAreaByAction() { const QObject *sender = QObject::sender(); - Q_ASSERT(sender); const QAction *action = qobject_cast(sender); Q_ASSERT(action); int index = action->data().toInt(); this->selectArea(index); } + void CInfoArea::resetPositionByAction() + { + const QObject *sender = QObject::sender(); + const QAction *action = qobject_cast(sender); + Q_ASSERT(action); + int index = action->data().toInt(); + this->resetPosition(index); + } + void CInfoArea::toggleAreaFloatingByAction() { const QObject *sender = QObject::sender(); - Q_ASSERT(sender); const QAction *action = qobject_cast(sender); Q_ASSERT(action); int index = action->data().toInt(); diff --git a/src/blackgui/infoarea.h b/src/blackgui/infoarea.h index 9fdba8c1e..9a86c7dba 100644 --- a/src/blackgui/infoarea.h +++ b/src/blackgui/infoarea.h @@ -84,6 +84,11 @@ namespace BlackGui //! \param parent which will own the action (deletion) QList getInfoAreaRestoreActions(QWidget *parent) const; + //! Create a list of actions to reset the position the info areas. + //! This could be used in a menu or somewhere else. + //! \param parent which will own the action (deletion) + QList getInfoAreaResetPositionActions(QWidget *parent) const; + //! Docked area indexes QList getAreaIndexesDockedOrFloating(bool floating) const; @@ -119,12 +124,18 @@ namespace BlackGui //! Select area void selectArea(int areaIndex); + //! Reset position + void resetPosition(int areaIndex); + //! Set current tab bar index by given widget void selectArea(const CDockWidgetInfoArea *dockWidgetInfoArea); //! Select area (sender is QAction) void selectAreaByAction(); + //! Reset window position of area (sender is QAction) + void resetPositionByAction(); + //! Toggle area floating (sender is QAction) void toggleAreaFloatingByAction();