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