mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-29 12:45:40 +08:00
Allow to reset dockwidget settings/margins
* changed name to object name * reset to defaults possible
This commit is contained in:
@@ -63,6 +63,18 @@ namespace BlackGui
|
|||||||
connect(this, &QDockWidget::visibilityChanged, this, &CDockWidget::ps_onVisibilityChanged);
|
connect(this, &QDockWidget::visibilityChanged, this, &CDockWidget::ps_onVisibilityChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDockWidget::setMargins()
|
||||||
|
{
|
||||||
|
if (this->isFloating())
|
||||||
|
{
|
||||||
|
this->setContentsMargins(this->isFrameless() ? this->getMarginsWhenFramelessFloating() : this->getMarginsWhenFloating());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->setContentsMargins(this->getMarginsWhenDocked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CDockWidget::CDockWidget(QWidget *parent): CDockWidget(true, parent)
|
CDockWidget::CDockWidget(QWidget *parent): CDockWidget(true, parent)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -175,7 +187,6 @@ namespace BlackGui
|
|||||||
void CDockWidget::resetWasAlreadyFloating()
|
void CDockWidget::resetWasAlreadyFloating()
|
||||||
{
|
{
|
||||||
this->m_wasAlreadyFloating = false;
|
this->m_wasAlreadyFloating = false;
|
||||||
this->m_resetedFloating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::setPreferredSizeWhenFloating(const QSize &size)
|
void CDockWidget::setPreferredSizeWhenFloating(const QSize &size)
|
||||||
@@ -204,12 +215,6 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// margins
|
|
||||||
if (this->isFloating())
|
|
||||||
{
|
|
||||||
this->setContentsMargins(frameless ? this->getMarginsWhenFramelessFloating() : this->getMarginsWhenFloating());
|
|
||||||
}
|
|
||||||
|
|
||||||
// resize
|
// resize
|
||||||
if (frameless)
|
if (frameless)
|
||||||
{
|
{
|
||||||
@@ -218,6 +223,7 @@ namespace BlackGui
|
|||||||
this->resize(innerWidget->size());
|
this->resize(innerWidget->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->setMargins();
|
||||||
this->forceStyleSheetUpdate(); // force style sheet reload
|
this->forceStyleSheetUpdate(); // force style sheet reload
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,6 +286,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
return this->restoreGeometry(geo);
|
return this->restoreGeometry(geo);
|
||||||
}
|
}
|
||||||
|
this->setMargins();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,16 +338,14 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, &CDockWidget::toggleFloating);
|
contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, &CDockWidget::toggleFloating);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Margin actions
|
||||||
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);
|
||||||
// Margin action
|
this->m_input->setMargins(this->contentsMargins());
|
||||||
if (this->isFloating())
|
contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), "Margins", this, &CDockWidget::ps_dummy);
|
||||||
{
|
contextMenu->addAction(this->m_marginMenuAction);
|
||||||
this->m_input->setMargins(this->contentsMargins());
|
|
||||||
contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), "Margins", this, &CDockWidget::ps_dummy);
|
|
||||||
contextMenu->addAction(this->m_marginMenuAction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::initialFloating()
|
void CDockWidget::initialFloating()
|
||||||
@@ -377,6 +382,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
||||||
{
|
{
|
||||||
|
this->setMargins();
|
||||||
if (topLevel)
|
if (topLevel)
|
||||||
{
|
{
|
||||||
if (this->m_windowTitleBackup != QDockWidget::windowTitle())
|
if (this->m_windowTitleBackup != QDockWidget::windowTitle())
|
||||||
@@ -392,12 +398,6 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (m_wasFrameless) { setFrameless(true); }
|
if (m_wasFrameless) { setFrameless(true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setContentsMargins(
|
|
||||||
this->isFrameless() ?
|
|
||||||
this->getMarginsWhenFramelessFloating() :
|
|
||||||
this->getMarginsWhenFloating()
|
|
||||||
);
|
|
||||||
this->m_statusBar.show();
|
this->m_statusBar.show();
|
||||||
this->m_wasAlreadyFloating = true;
|
this->m_wasAlreadyFloating = true;
|
||||||
}
|
}
|
||||||
@@ -409,7 +409,6 @@ namespace BlackGui
|
|||||||
if (!this->m_windowTitleWhenDocked) { QDockWidget::setWindowTitle(""); }
|
if (!this->m_windowTitleWhenDocked) { QDockWidget::setWindowTitle(""); }
|
||||||
this->m_statusBar.hide();
|
this->m_statusBar.hide();
|
||||||
this->setEmptyTitleBar();
|
this->setEmptyTitleBar();
|
||||||
this->setContentsMargins(this->getMarginsWhenDocked());
|
|
||||||
|
|
||||||
// sometimes floating sets a new minimum size, here we reset it
|
// sometimes floating sets a new minimum size, here we reset it
|
||||||
if (this->minimumHeight() > this->m_initialDockedMinimumSize.height())
|
if (this->minimumHeight() > this->m_initialDockedMinimumSize.height())
|
||||||
@@ -509,11 +508,12 @@ namespace BlackGui
|
|||||||
this->setMarginsWhenDocked(margins);
|
this->setMarginsWhenDocked(margins);
|
||||||
}
|
}
|
||||||
this->setContentsMargins(margins);
|
this->setContentsMargins(margins);
|
||||||
|
this->repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::ps_settingsChanged()
|
void CDockWidget::ps_settingsChanged()
|
||||||
{
|
{
|
||||||
// void
|
// void, normally not used
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::ps_dummy()
|
void CDockWidget::ps_dummy()
|
||||||
@@ -539,14 +539,14 @@ namespace BlackGui
|
|||||||
CSettingsDockWidgets all = this->m_settings.get();
|
CSettingsDockWidgets all = this->m_settings.get();
|
||||||
if (all.contains(name)) { return; }
|
if (all.contains(name)) { return; }
|
||||||
all.getByNameOrInitToDefault(name);
|
all.getByNameOrInitToDefault(name);
|
||||||
this->m_settings.set(all);
|
this->m_settings.setAndSave(all);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CDockWidget::getNameForSettings() const
|
QString CDockWidget::getNameForSettings() const
|
||||||
{
|
{
|
||||||
const QString name(this->m_windowTitleBackup.toLower().remove(' ')); // let`s see how far I get with that
|
const QString n(this->objectName().toLower().remove(' '));
|
||||||
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "no name");
|
Q_ASSERT_X(!n.isEmpty(), Q_FUNC_INFO, "No settings name");
|
||||||
return name;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSettingsDockWidget CDockWidget::getSettings() const
|
CSettingsDockWidget CDockWidget::getSettings() const
|
||||||
@@ -579,4 +579,12 @@ namespace BlackGui
|
|||||||
s.setGeometry(this->saveGeometry());
|
s.setGeometry(this->saveGeometry());
|
||||||
this->setSettings(s);
|
this->setSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDockWidget::resetSettings()
|
||||||
|
{
|
||||||
|
CSettingsDockWidget s = this->getSettings();
|
||||||
|
s.reset();
|
||||||
|
this->setSettings(s);
|
||||||
|
this->restoreFromSettings();
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ namespace BlackGui
|
|||||||
//! Remember widget state
|
//! Remember widget state
|
||||||
void saveToSettings();
|
void saveToSettings();
|
||||||
|
|
||||||
|
//! Reset margin settings
|
||||||
|
void resetSettings();
|
||||||
|
|
||||||
//! Set title and internally keep a backup
|
//! Set title and internally keep a backup
|
||||||
void setWindowTitle(const QString &title);
|
void setWindowTitle(const QString &title);
|
||||||
|
|
||||||
@@ -140,6 +143,9 @@ namespace BlackGui
|
|||||||
//! Constructor
|
//! Constructor
|
||||||
CDockWidget(bool allowStatusBar, QWidget *parent = nullptr);
|
CDockWidget(bool allowStatusBar, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
//! Set margins from settings
|
||||||
|
void setMargins();
|
||||||
|
|
||||||
//! Margins when window is floating
|
//! Margins when window is floating
|
||||||
void setMarginsWhenFloating(const QMargins &margins);
|
void setMarginsWhenFloating(const QMargins &margins);
|
||||||
|
|
||||||
@@ -223,7 +229,6 @@ namespace BlackGui
|
|||||||
bool m_allowStatusBar = true;
|
bool m_allowStatusBar = true;
|
||||||
bool m_windowTitleWhenDocked = true;
|
bool m_windowTitleWhenDocked = true;
|
||||||
bool m_wasAlreadyFloating = false;
|
bool m_wasAlreadyFloating = false;
|
||||||
bool m_resetedFloating = false;
|
|
||||||
bool m_selected = false; //!< selected when tabbed
|
bool m_selected = false; //!< selected when tabbed
|
||||||
bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible()
|
bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible()
|
||||||
bool m_wasFrameless = false; //!< frameless when last floating
|
bool m_wasFrameless = false; //!< frameless when last floating
|
||||||
|
|||||||
@@ -20,6 +20,20 @@ namespace BlackGui
|
|||||||
CSettingsDockWidget::CSettingsDockWidget()
|
CSettingsDockWidget::CSettingsDockWidget()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
void CSettingsDockWidget::resetMarginsToDefault()
|
||||||
|
{
|
||||||
|
// this->setMarginsWhenFloating(QMargins(0, 3, 15, 35)); // found by trial and error on windows
|
||||||
|
this->setMarginsWhenFloating(QMargins(0, 0, 0, 0));
|
||||||
|
this->setMarginsWhenFramelessFloating(QMargins(0, 0, 0, 0));
|
||||||
|
this->setMarginsWhenDocked(QMargins(0, 0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSettingsDockWidget::reset()
|
||||||
|
{
|
||||||
|
this->resetMarginsToDefault();
|
||||||
|
this->m_geometry = "";
|
||||||
|
}
|
||||||
|
|
||||||
void CSettingsDockWidget::setMarginsWhenFramelessFloating(const QMargins &margins)
|
void CSettingsDockWidget::setMarginsWhenFramelessFloating(const QMargins &margins)
|
||||||
{
|
{
|
||||||
this->m_floatingFramelessMargins = marginsToString(margins);
|
this->m_floatingFramelessMargins = marginsToString(margins);
|
||||||
@@ -161,9 +175,17 @@ namespace BlackGui
|
|||||||
|
|
||||||
// default values can be set here, this could be enhanced if needed
|
// default values can be set here, this could be enhanced if needed
|
||||||
// e.g. by platform dependent defaults
|
// e.g. by platform dependent defaults
|
||||||
s.setMarginsWhenFloating(QMargins(0, 3, 15, 35)); // found by trial and error on windows
|
s.reset();
|
||||||
this->insert(name, s);
|
this->insert(name, s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSettingsDockWidgets::resetToDefaults(const QString &name)
|
||||||
|
{
|
||||||
|
if (this->contains(name))
|
||||||
|
{
|
||||||
|
this->remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ namespace BlackGui
|
|||||||
//! Destructor.
|
//! Destructor.
|
||||||
~CSettingsDockWidget() {}
|
~CSettingsDockWidget() {}
|
||||||
|
|
||||||
|
//! Reset margins to default
|
||||||
|
void resetMarginsToDefault();
|
||||||
|
|
||||||
|
//! Reset to defaults
|
||||||
|
void reset();
|
||||||
|
|
||||||
//! Set margins for given dock widget
|
//! Set margins for given dock widget
|
||||||
void setMarginsWhenFramelessFloating(const QMargins &margins);
|
void setMarginsWhenFramelessFloating(const QMargins &margins);
|
||||||
|
|
||||||
@@ -137,6 +143,9 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Get setting or init by estimated default values
|
//! Get setting or init by estimated default values
|
||||||
CSettingsDockWidget getByNameOrInitToDefault(const QString &name);
|
CSettingsDockWidget getByNameOrInitToDefault(const QString &name);
|
||||||
|
|
||||||
|
//! Reset to defaults
|
||||||
|
void resetToDefaults(const QString &name);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Trait for settings for dock widget
|
//! Trait for settings for dock widget
|
||||||
|
|||||||
Reference in New Issue
Block a user