mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #750, allow to reset window position of dock widget
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackGui::Components;
|
using namespace BlackGui::Components;
|
||||||
@@ -339,10 +341,12 @@ namespace BlackGui
|
|||||||
contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, &CDockWidget::toggleFloating);
|
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::load16(), "Restore", this, &CDockWidget::restoreFromSettings);
|
||||||
contextMenu->addAction(BlackMisc::CIcons::save16(), "Save state", this, &CDockWidget::saveToSettings);
|
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());
|
this->m_input->setMargins(this->contentsMargins());
|
||||||
contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), "Margins", this, &CDockWidget::ps_dummy);
|
contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), "Margins", this, &CDockWidget::ps_dummy);
|
||||||
contextMenu->addAction(this->m_marginMenuAction);
|
contextMenu->addAction(this->m_marginMenuAction);
|
||||||
@@ -587,4 +591,11 @@ namespace BlackGui
|
|||||||
this->setSettings(s);
|
this->setSettings(s);
|
||||||
this->restoreFromSettings();
|
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
|
} // namespace
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ namespace BlackGui
|
|||||||
//! Reset margin settings
|
//! Reset margin settings
|
||||||
void resetSettings();
|
void resetSettings();
|
||||||
|
|
||||||
|
//! Reset window position
|
||||||
|
void resetPosition();
|
||||||
|
|
||||||
//! Set title and internally keep a backup
|
//! Set title and internally keep a backup
|
||||||
void setWindowTitle(const QString &title);
|
void setWindowTitle(const QString &title);
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "blackgui/stylesheetutility.h"
|
#include "blackgui/stylesheetutility.h"
|
||||||
#include "blackmisc/icons.h"
|
#include "blackmisc/icons.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
@@ -100,9 +101,12 @@ namespace BlackGui
|
|||||||
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);
|
QMenu *subMenuRestore = new QMenu("Restore", menu);
|
||||||
|
QMenu *subMenuResetPositions = new QMenu("Reset position", menu);
|
||||||
subMenuRestore->setIcon(CIcons::load16());
|
subMenuRestore->setIcon(CIcons::load16());
|
||||||
|
subMenuResetPositions->setIcon(CIcons::refresh16());
|
||||||
subMenuRestore->addActions(this->getInfoAreaRestoreActions(subMenuRestore));
|
subMenuRestore->addActions(this->getInfoAreaRestoreActions(subMenuRestore));
|
||||||
subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay));
|
subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay));
|
||||||
|
subMenuResetPositions->addActions(this->getInfoAreaResetPositionActions(subMenuResetPositions));
|
||||||
|
|
||||||
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
||||||
bool c = false; // check connections
|
bool c = false; // check connections
|
||||||
@@ -131,6 +135,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
menu->addMenu(subMenuDisplay);
|
menu->addMenu(subMenuDisplay);
|
||||||
menu->addMenu(subMenuToggleFloat);
|
menu->addMenu(subMenuToggleFloat);
|
||||||
|
menu->addMenu(subMenuResetPositions);
|
||||||
menu->addMenu(subMenuRestore);
|
menu->addMenu(subMenuRestore);
|
||||||
|
|
||||||
// where and how to display tab bar
|
// where and how to display tab bar
|
||||||
@@ -164,7 +169,6 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!infoArea) { return false; }
|
if (!infoArea) { return false; }
|
||||||
if (infoArea->isFloating()) { return false; }
|
if (infoArea->isFloating()) { return false; }
|
||||||
|
|
||||||
return infoArea == this->getSelectedDockInfoArea();
|
return infoArea == this->getSelectedDockInfoArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +224,25 @@ namespace BlackGui
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QAction *> CInfoArea::getInfoAreaResetPositionActions(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(":getInfoAreaResetPositionActions:").append(wt));
|
||||||
|
connect(action, &QAction::triggered, this, &CInfoArea::resetPositionByAction);
|
||||||
|
actions.append(action);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QAction *> CInfoArea::getInfoAreaToggleFloatingActions(QWidget *parent) const
|
QList<QAction *> CInfoArea::getInfoAreaToggleFloatingActions(QWidget *parent) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
@@ -326,8 +349,8 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!this->isValidAreaIndex(areaIndex)) { return; }
|
if (!this->isValidAreaIndex(areaIndex)) { return; }
|
||||||
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
||||||
Q_ASSERT(dw);
|
BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area");
|
||||||
if (!dw) return;
|
if (!dw) { return; }
|
||||||
dw->toggleFloating();
|
dw->toggleFloating();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,15 +358,15 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!this->isValidAreaIndex(areaIndex)) { return; }
|
if (!this->isValidAreaIndex(areaIndex)) { return; }
|
||||||
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
||||||
Q_ASSERT(dw);
|
BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area");
|
||||||
if (!dw) return;
|
if (!dw) { return; }
|
||||||
dw->toggleVisibility();
|
dw->toggleVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInfoArea::selectArea(int areaIndex)
|
void CInfoArea::selectArea(int areaIndex)
|
||||||
{
|
{
|
||||||
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
CDockWidgetInfoArea *dw = this->m_dockWidgetInfoAreas.at(areaIndex);
|
||||||
Q_ASSERT(dw);
|
BLACK_VERIFY_X(dw, Q_FUNC_INFO, "Missing info area");
|
||||||
if (!dw) { return; }
|
if (!dw) { return; }
|
||||||
Q_ASSERT(this->m_tabBar);
|
Q_ASSERT(this->m_tabBar);
|
||||||
if (m_tabBar->count() < 1) { return; }
|
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()
|
void CInfoArea::selectAreaByAction()
|
||||||
{
|
{
|
||||||
const QObject *sender = QObject::sender();
|
const QObject *sender = QObject::sender();
|
||||||
Q_ASSERT(sender);
|
|
||||||
const QAction *action = qobject_cast<const QAction *>(sender);
|
const QAction *action = qobject_cast<const QAction *>(sender);
|
||||||
Q_ASSERT(action);
|
Q_ASSERT(action);
|
||||||
int index = action->data().toInt();
|
int index = action->data().toInt();
|
||||||
this->selectArea(index);
|
this->selectArea(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInfoArea::resetPositionByAction()
|
||||||
|
{
|
||||||
|
const QObject *sender = QObject::sender();
|
||||||
|
const QAction *action = qobject_cast<const QAction *>(sender);
|
||||||
|
Q_ASSERT(action);
|
||||||
|
int index = action->data().toInt();
|
||||||
|
this->resetPosition(index);
|
||||||
|
}
|
||||||
|
|
||||||
void CInfoArea::toggleAreaFloatingByAction()
|
void CInfoArea::toggleAreaFloatingByAction()
|
||||||
{
|
{
|
||||||
const QObject *sender = QObject::sender();
|
const QObject *sender = QObject::sender();
|
||||||
Q_ASSERT(sender);
|
|
||||||
const QAction *action = qobject_cast<const QAction *>(sender);
|
const QAction *action = qobject_cast<const QAction *>(sender);
|
||||||
Q_ASSERT(action);
|
Q_ASSERT(action);
|
||||||
int index = action->data().toInt();
|
int index = action->data().toInt();
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ namespace BlackGui
|
|||||||
//! \param parent which will own the action (deletion)
|
//! \param parent which will own the action (deletion)
|
||||||
QList<QAction *> getInfoAreaRestoreActions(QWidget *parent) const;
|
QList<QAction *> 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<QAction *> getInfoAreaResetPositionActions(QWidget *parent) const;
|
||||||
|
|
||||||
//! Docked area indexes
|
//! Docked area indexes
|
||||||
QList<int> getAreaIndexesDockedOrFloating(bool floating) const;
|
QList<int> getAreaIndexesDockedOrFloating(bool floating) const;
|
||||||
|
|
||||||
@@ -119,12 +124,18 @@ namespace BlackGui
|
|||||||
//! Select area
|
//! Select area
|
||||||
void selectArea(int areaIndex);
|
void selectArea(int areaIndex);
|
||||||
|
|
||||||
|
//! Reset position
|
||||||
|
void resetPosition(int areaIndex);
|
||||||
|
|
||||||
//! Set current tab bar index by given widget
|
//! Set current tab bar index by given widget
|
||||||
void selectArea(const CDockWidgetInfoArea *dockWidgetInfoArea);
|
void selectArea(const CDockWidgetInfoArea *dockWidgetInfoArea);
|
||||||
|
|
||||||
//! Select area (sender is QAction)
|
//! Select area (sender is QAction)
|
||||||
void selectAreaByAction();
|
void selectAreaByAction();
|
||||||
|
|
||||||
|
//! Reset window position of area (sender is QAction)
|
||||||
|
void resetPositionByAction();
|
||||||
|
|
||||||
//! Toggle area floating (sender is QAction)
|
//! Toggle area floating (sender is QAction)
|
||||||
void toggleAreaFloatingByAction();
|
void toggleAreaFloatingByAction();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user