mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #512, changed dock widget to use settings
* allow to load from settings / save to settings * removed outdated members / functions * aligned naming of some functioss
This commit is contained in:
@@ -155,6 +155,7 @@ namespace BlackCore
|
||||
|
||||
CGlobalSetup CApplication::getGlobalSetup() const
|
||||
{
|
||||
if (this->m_shutdown) { return CGlobalSetup(); }
|
||||
const CSetupReader *r = this->m_setupReader.data();
|
||||
if (!r) { return CGlobalSetup(); }
|
||||
return r->getSetup();
|
||||
@@ -162,6 +163,7 @@ namespace BlackCore
|
||||
|
||||
CUpdateInfo CApplication::getUpdateInfo() const
|
||||
{
|
||||
if (this->m_shutdown) { return CUpdateInfo(); }
|
||||
const CSetupReader *r = this->m_setupReader.data();
|
||||
if (!r) { return CUpdateInfo(); }
|
||||
return r->getUpdateInfo();
|
||||
@@ -596,6 +598,7 @@ namespace BlackCore
|
||||
{
|
||||
if (this->supportsContexts())
|
||||
{
|
||||
// this will eventually also call saveToStore
|
||||
m = this->getIContextApplication()->saveSettings();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -43,18 +43,19 @@ namespace BlackGui
|
||||
CEnableForFramelessWindow(CEnableForFramelessWindow::WindowTool, false, "framelessDockWidget", this),
|
||||
m_allowStatusBar(allowStatusBar)
|
||||
{
|
||||
// init settings
|
||||
this->ps_onStyleSheetsChanged();
|
||||
this->initTitleBarWidgets();
|
||||
|
||||
// context menu
|
||||
CMarginsInput *mi = new CMarginsInput(this);
|
||||
mi->setMaximumWidth(150);
|
||||
this->m_input = new CMarginsInput(this);
|
||||
this->m_input->setMaximumWidth(150);
|
||||
this->m_marginMenuAction = new QWidgetAction(this);
|
||||
this->m_marginMenuAction->setDefaultWidget(mi);
|
||||
this->m_marginMenuAction->setDefaultWidget(this->m_input);
|
||||
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &CDockWidget::customContextMenuRequested, this, &CDockWidget::ps_showContextMenu);
|
||||
connect(mi, &CMarginsInput::changedMargins, this, &CDockWidget::ps_menuChangeMargins);
|
||||
connect(this->m_input, &CMarginsInput::changedMargins, this, &CDockWidget::ps_menuChangeMargins);
|
||||
|
||||
// connect
|
||||
connect(this, &QDockWidget::topLevelChanged, this, &CDockWidget::ps_onTopLevelChanged);
|
||||
@@ -86,9 +87,8 @@ namespace BlackGui
|
||||
|
||||
void CDockWidget::setMarginsWhenFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_marginsWhenFloating = margins;
|
||||
CSettingsDockWidget s = this->getSettings();
|
||||
s.setFloatingMargins(margins);
|
||||
s.setMarginsWhenFloating(margins);
|
||||
this->setSettings(s);
|
||||
}
|
||||
|
||||
@@ -97,11 +97,15 @@ namespace BlackGui
|
||||
this->setMarginsWhenFloating(QMargins(left, top, right, bottom));
|
||||
}
|
||||
|
||||
QMargins CDockWidget::getMarginsWhenFloating() const
|
||||
{
|
||||
return this->getSettings().getMarginsWhenFloating();
|
||||
}
|
||||
|
||||
void CDockWidget::setMarginsWhenFramelessFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_marginsWhenFramelessFloating = margins;
|
||||
CSettingsDockWidget s = this->getSettings();
|
||||
s.setFloatingFramelessMargins(margins);
|
||||
s.setMarginsWhenFramelessFloating(margins);
|
||||
this->setSettings(s);
|
||||
}
|
||||
|
||||
@@ -110,11 +114,15 @@ namespace BlackGui
|
||||
this->setMarginsWhenFramelessFloating(QMargins(left, top, right, bottom));
|
||||
}
|
||||
|
||||
QMargins CDockWidget::getMarginsWhenFramelessFloating() const
|
||||
{
|
||||
return this->getSettings().getMarginsWhenFramelessFloating();
|
||||
}
|
||||
|
||||
void CDockWidget::setMarginsWhenDocked(const QMargins &margins)
|
||||
{
|
||||
this->m_marginsWhenDocked = margins;
|
||||
CSettingsDockWidget s = this->getSettings();
|
||||
s.setDockedMargins(margins);
|
||||
s.setMarginsWhenDocked(margins);
|
||||
this->setSettings(s);
|
||||
}
|
||||
|
||||
@@ -123,6 +131,11 @@ namespace BlackGui
|
||||
this->setMarginsWhenDocked(QMargins(left, top, right, bottom));
|
||||
}
|
||||
|
||||
QMargins CDockWidget::getMarginsWhenDocked() const
|
||||
{
|
||||
return this->getSettings().getMarginsWhenDocked();
|
||||
}
|
||||
|
||||
bool CDockWidget::isWidgetVisible() const
|
||||
{
|
||||
return this->m_dockWidgetVisible && this->isVisible();
|
||||
@@ -194,7 +207,7 @@ namespace BlackGui
|
||||
// margins
|
||||
if (this->isFloating())
|
||||
{
|
||||
this->setContentsMargins(frameless ? this->m_marginsWhenFramelessFloating : this->m_marginsWhenFloating);
|
||||
this->setContentsMargins(frameless ? this->getMarginsWhenFramelessFloating() : this->getMarginsWhenFloating());
|
||||
}
|
||||
|
||||
// resize
|
||||
@@ -251,6 +264,25 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CDockWidget::restoreFromSettings()
|
||||
{
|
||||
const CSettingsDockWidget s = this->getSettings();
|
||||
if (s.isFloating() != this->isFloating())
|
||||
{
|
||||
this->toggleFloating();
|
||||
}
|
||||
if (s.isFramless() != this->isFrameless())
|
||||
{
|
||||
this->toggleFrameless();
|
||||
}
|
||||
const QByteArray geo(s.getGeometry());
|
||||
if (!geo.isEmpty())
|
||||
{
|
||||
return this->restoreGeometry(geo);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDockWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (this->isFloating())
|
||||
@@ -299,10 +331,13 @@ namespace BlackGui
|
||||
{
|
||||
contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, &CDockWidget::toggleFloating);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -310,6 +345,9 @@ namespace BlackGui
|
||||
|
||||
void CDockWidget::initialFloating()
|
||||
{
|
||||
// settings, ii here because name now is set
|
||||
this->initSettings();
|
||||
|
||||
// init status bar, as we have now all structures set
|
||||
this->initStatusBarAndProperties();
|
||||
|
||||
@@ -330,52 +368,6 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CDockWidget::setMarginsFromSettings(const QString §ion)
|
||||
{
|
||||
QString sectionUsed(section.isEmpty() ? this->objectName() : section);
|
||||
if (sectionUsed.isEmpty()) { return false; }
|
||||
const QSettings *settings = sGui->getStyleSheetUtility().iniFile();
|
||||
Q_ASSERT_X(settings, "CDockWidget::setMarginsFromSettings", "Missing ini settings");
|
||||
if (!settings) { return false; }
|
||||
|
||||
// check if value exists as there is no way to check if key/section exist
|
||||
if (settings->value(sectionUsed + "/margindocked.left").toString().isEmpty())
|
||||
{
|
||||
// no values considered as no section, now we check if an alias exists
|
||||
sectionUsed = settings->value("alias/" + sectionUsed).toString();
|
||||
if (sectionUsed.isEmpty()) { return false; }
|
||||
if (settings->value(sectionUsed + "/margindocked.left").toString().isEmpty())
|
||||
{
|
||||
Q_ASSERT_X(false, "CDockWidget::setMarginsFromSettings", "Wrong ini settings");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ok = true, ok1, ok2, ok3, ok4;
|
||||
this->setMarginsWhenDocked(
|
||||
settings->value(sectionUsed + "/margindocked.left", 1).toInt(&ok1),
|
||||
settings->value(sectionUsed + "/margindocked.top", 1).toInt(&ok2),
|
||||
settings->value(sectionUsed + "/margindocked.right", 1).toInt(&ok3),
|
||||
settings->value(sectionUsed + "/margindocked.bottom", 1).toInt(&ok4));
|
||||
if (!(ok1 && ok2 && ok3 && ok4)) { CLogMessage(this).error("Error in docked margins"); ok = false; }
|
||||
|
||||
this->setMarginsWhenFloating(
|
||||
settings->value(sectionUsed + "/marginfloating.left", 10).toInt(&ok1),
|
||||
settings->value(sectionUsed + "/marginfloating.top", 10).toInt(&ok2),
|
||||
settings->value(sectionUsed + "/marginfloating.right", 10).toInt(&ok3),
|
||||
settings->value(sectionUsed + "/marginfloating.bottom", 10).toInt(&ok4));
|
||||
if (!(ok1 && ok2 && ok3 && ok4)) { CLogMessage(this).error("Error in floating margins"); ok = false; }
|
||||
|
||||
this->setMarginsWhenFramelessFloating(
|
||||
settings->value(sectionUsed + "/marginfloating.frameless.left", 5).toInt(&ok1),
|
||||
settings->value(sectionUsed + "/marginfloating.frameless.top", 5).toInt(&ok2),
|
||||
settings->value(sectionUsed + "/marginfloating.frameless.right", 5).toInt(&ok3),
|
||||
settings->value(sectionUsed + "/marginfloating.frameless.bottom", 5).toInt(&ok4));
|
||||
if (!(ok1 && ok2 && ok3 && ok4)) { CLogMessage(this).error("Error in floating (frameless) margins"); ok = false; }
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
QString CDockWidget::windowTitleOrBackup() const
|
||||
{
|
||||
QString t(windowTitle());
|
||||
@@ -403,8 +395,8 @@ namespace BlackGui
|
||||
|
||||
this->setContentsMargins(
|
||||
this->isFrameless() ?
|
||||
this->m_marginsWhenFramelessFloating :
|
||||
this->m_marginsWhenFloating
|
||||
this->getMarginsWhenFramelessFloating() :
|
||||
this->getMarginsWhenFloating()
|
||||
);
|
||||
this->m_statusBar.show();
|
||||
this->m_wasAlreadyFloating = true;
|
||||
@@ -417,7 +409,7 @@ namespace BlackGui
|
||||
if (!this->m_windowTitleWhenDocked) { QDockWidget::setWindowTitle(""); }
|
||||
this->m_statusBar.hide();
|
||||
this->setEmptyTitleBar();
|
||||
this->setContentsMargins(this->m_marginsWhenDocked);
|
||||
this->setContentsMargins(this->getMarginsWhenDocked());
|
||||
|
||||
// sometimes floating sets a new minimum size, here we reset it
|
||||
if (this->minimumHeight() > this->m_initialDockedMinimumSize.height())
|
||||
@@ -541,9 +533,20 @@ namespace BlackGui
|
||||
this->setStyleSheet(qss);
|
||||
}
|
||||
|
||||
void CDockWidget::initSettings()
|
||||
{
|
||||
const QString name(this->getNameForSettings());
|
||||
CSettingsDockWidgets all = this->m_settings.getCopy();
|
||||
if (all.contains(name)) { return; }
|
||||
all.getByNameOrInitToDefault(name);
|
||||
this->m_settings.set(all);
|
||||
}
|
||||
|
||||
QString CDockWidget::getNameForSettings() const
|
||||
{
|
||||
return this->m_windowTitleBackup.toLower().remove(' '); // let`s see how far I get with that
|
||||
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;
|
||||
}
|
||||
|
||||
CSettingsDockWidget CDockWidget::getSettings() const
|
||||
@@ -561,10 +564,19 @@ namespace BlackGui
|
||||
CSettingsDockWidgets all = this->m_settings.getCopy();
|
||||
const QString name(this->getNameForSettings());
|
||||
all.insert(name, settings);
|
||||
const CStatusMessage m = this->m_settings.setAndSave(all);
|
||||
const CStatusMessage m = this->m_settings.set(all); // saved when shutdown
|
||||
if (m.isFailure())
|
||||
{
|
||||
CLogMessage::preformatted(m);
|
||||
}
|
||||
}
|
||||
|
||||
void CDockWidget::saveToSettings()
|
||||
{
|
||||
CSettingsDockWidget s = this->getSettings();
|
||||
s.setFloating(this->isFloating());
|
||||
s.setFrameless(this->isFrameless());
|
||||
s.setGeometry(this->saveGeometry());
|
||||
this->setSettings(s);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -35,6 +35,7 @@ class QWidgetAction;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components { class CMarginsInput; }
|
||||
|
||||
//! \brief Our base class for dockable widgets containing some specialized functionality on top of QDockWidget.
|
||||
//! \details We currently use dockable widgets either as "info area" or "info bar" dockable widget.
|
||||
@@ -60,27 +61,6 @@ namespace BlackGui
|
||||
//! Set null (nullptr) title bar
|
||||
void setNullTitleBarWidget();
|
||||
|
||||
//! Margins when window is floating
|
||||
void setMarginsWhenFloating(const QMargins &margins);
|
||||
|
||||
//! Margins when window is floating
|
||||
void setMarginsWhenFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins when window is floating (frameless)
|
||||
void setMarginsWhenFramelessFloating(const QMargins &margins);
|
||||
|
||||
//! Margins when window is floating (frameless)
|
||||
void setMarginsWhenFramelessFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins when widget is floating
|
||||
void setMarginsWhenDocked(const QMargins &margins);
|
||||
|
||||
//! Margins when widget is floating
|
||||
void setMarginsWhenDocked(int left, int top, int right, int bottom);
|
||||
|
||||
//! Set margings from .ini file
|
||||
bool setMarginsFromSettings(const QString §ion = "");
|
||||
|
||||
//! Window title backup
|
||||
const QString &windowTitleBackup() const { return this->m_windowTitleBackup; }
|
||||
|
||||
@@ -134,6 +114,12 @@ namespace BlackGui
|
||||
//! Toggle frameless mode (EXPERIMENTAL)
|
||||
void toggleFrameless();
|
||||
|
||||
//! Restore from settings
|
||||
bool restoreFromSettings();
|
||||
|
||||
//! Remember widget state
|
||||
void saveToSettings();
|
||||
|
||||
//! Set title and internally keep a backup
|
||||
void setWindowTitle(const QString &title);
|
||||
|
||||
@@ -154,6 +140,33 @@ namespace BlackGui
|
||||
//! Constructor
|
||||
CDockWidget(bool allowStatusBar, QWidget *parent = nullptr);
|
||||
|
||||
//! Margins when window is floating
|
||||
void setMarginsWhenFloating(const QMargins &margins);
|
||||
|
||||
//! Margins when window is floating
|
||||
void setMarginsWhenFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins when floating
|
||||
QMargins getMarginsWhenFloating() const;
|
||||
|
||||
//! Margins when window is floating (frameless)
|
||||
void setMarginsWhenFramelessFloating(const QMargins &margins);
|
||||
|
||||
//! Margins when window is floating (frameless)
|
||||
void setMarginsWhenFramelessFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins when floating and frameless
|
||||
QMargins getMarginsWhenFramelessFloating() const;
|
||||
|
||||
//! Margins when widget is floating
|
||||
void setMarginsWhenDocked(const QMargins &margins);
|
||||
|
||||
//! Margins when widget is floating
|
||||
void setMarginsWhenDocked(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins when docked
|
||||
QMargins getMarginsWhenDocked() const;
|
||||
|
||||
//! Override close event
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
@@ -198,25 +211,23 @@ namespace BlackGui
|
||||
void ps_dummy();
|
||||
|
||||
private:
|
||||
QWidget *m_titleBarWidgetEmpty = nullptr; //!< replacing default title bar
|
||||
QWidget *m_titleBarWidgetOriginal = nullptr; //!< the original title bar
|
||||
QWidgetAction *m_marginMenuAction = nullptr; //!< menu action for margins
|
||||
QMargins m_marginsWhenFloating; //!< Offsets when window is floating
|
||||
QMargins m_marginsWhenFramelessFloating; //!< Offsets when window is frameless floating
|
||||
QMargins m_marginsWhenDocked; //!< Offsets when window is docked
|
||||
CManagedStatusBar m_statusBar; //!< Status bar when floating
|
||||
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_initialDockedMinimumSize; //!< minimum size before first floating
|
||||
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
|
||||
QWidget *m_titleBarWidgetEmpty = nullptr; //!< replacing default title bar
|
||||
QWidget *m_titleBarWidgetOriginal = nullptr; //!< the original title bar
|
||||
QWidgetAction *m_marginMenuAction = nullptr; //!< menu action for margins
|
||||
Components::CMarginsInput *m_input = nullptr; //!< margins widget
|
||||
CManagedStatusBar m_statusBar; //!< Status bar when floating
|
||||
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_initialDockedMinimumSize; //!< minimum size before first floating
|
||||
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
|
||||
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
|
||||
BlackMisc::CSetting<BlackGui::Settings::SettingsDockWidgets> m_settings { this, &CDockWidget::ps_settingsChanged };
|
||||
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
|
||||
BlackMisc::CSetting<BlackGui::Settings::SettingsDockWidgets> m_settings { this, &CDockWidget::ps_settingsChanged }; //!< all docked wigets settings
|
||||
|
||||
//! Empty widget with no size
|
||||
void initTitleBarWidgets();
|
||||
@@ -227,6 +238,9 @@ namespace BlackGui
|
||||
//! Force a style sheet update
|
||||
void forceStyleSheetUpdate();
|
||||
|
||||
//! Init settings
|
||||
void initSettings();
|
||||
|
||||
//! Name used as key for settings
|
||||
QString getNameForSettings() const;
|
||||
|
||||
@@ -234,7 +248,7 @@ namespace BlackGui
|
||||
BlackGui::Settings::CSettingsDockWidget getSettings() const;
|
||||
|
||||
//! Save my updated settings
|
||||
void setAndSaveSettings(const BlackGui::Settings::CSettingsDockWidget &settings);
|
||||
void setSettings(const BlackGui::Settings::CSettingsDockWidget &settings);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -543,33 +543,6 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoArea::setMarginsWhenFloating(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas)
|
||||
{
|
||||
//! Margins when window is floating
|
||||
dw->setMarginsWhenFloating(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoArea::setMarginsWhenFramelessFloating(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas)
|
||||
{
|
||||
//! Margins when window is floating
|
||||
dw->setMarginsWhenFramelessFloating(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoArea::setMarginsWhenDocked(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas)
|
||||
{
|
||||
//! Margins when window is docked
|
||||
dw->setMarginsWhenDocked(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
QList<CDockWidgetInfoArea *> CInfoArea::findOwnDockWidgetInfoAreas() const
|
||||
{
|
||||
QList<CDockWidgetInfoArea *> infoAreas = this->findChildren<CDockWidgetInfoArea *>();
|
||||
|
||||
@@ -210,15 +210,6 @@ namespace BlackGui
|
||||
//! Connect all widgets
|
||||
void connectTopLevelChanged();
|
||||
|
||||
//! Margins for the floating widgets
|
||||
void setMarginsWhenFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins for the floating widgets (when frameless)
|
||||
void setMarginsWhenFramelessFloating(int left, int top, int right, int bottom);
|
||||
|
||||
//! Margins for the dockable widgets
|
||||
void setMarginsWhenDocked(int left, int top, int right, int bottom);
|
||||
|
||||
//! Nested info areas
|
||||
QList<CInfoArea *> getChildInfoAreas() const { return this->findChildren<CInfoArea *>(); }
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "settingsdockwidget.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -19,36 +20,46 @@ namespace BlackGui
|
||||
CSettingsDockWidget::CSettingsDockWidget()
|
||||
{ }
|
||||
|
||||
void CSettingsDockWidget::setFloatingFramelessMargins(const QMargins &margins)
|
||||
void CSettingsDockWidget::setMarginsWhenFramelessFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingFramelessMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getFloatingFramelessMargins() const
|
||||
QMargins CSettingsDockWidget::getMarginsWhenFramelessFloating() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingFramelessMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setFloatingMargins(const QMargins &margins)
|
||||
void CSettingsDockWidget::setMarginsWhenFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getFloatingMargins() const
|
||||
QMargins CSettingsDockWidget::getMarginsWhenFloating() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setDockedMargins(const QMargins &margins)
|
||||
void CSettingsDockWidget::setMarginsWhenDocked(const QMargins &margins)
|
||||
{
|
||||
this->m_dockedMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getDockedMargins() const
|
||||
QMargins CSettingsDockWidget::getMarginsWhenDocked() const
|
||||
{
|
||||
return stringToMargins(this->m_dockedMargins);
|
||||
}
|
||||
|
||||
QByteArray CSettingsDockWidget::getGeometry() const
|
||||
{
|
||||
return byteArrayFromHexString(this->m_geometry);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setGeometry(const QByteArray &ba)
|
||||
{
|
||||
this->m_geometry = bytesToHexString(ba);
|
||||
}
|
||||
|
||||
QString CSettingsDockWidget::convertToQString(bool i18n) const
|
||||
{
|
||||
return convertToQString(", ", i18n);
|
||||
@@ -65,6 +76,9 @@ namespace BlackGui
|
||||
s.append(separator);
|
||||
s.append("docked: ");
|
||||
s.append(this->m_dockedMargins);
|
||||
s.append(separator);
|
||||
s.append("docked: ");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -80,6 +94,10 @@ namespace BlackGui
|
||||
return CVariant::fromValue(this->m_floatingFramelessMargins);
|
||||
case IndexDockedMargins:
|
||||
return CVariant::fromValue(this->m_dockedMargins);
|
||||
case IndexFrameless:
|
||||
return CVariant::fromValue(this->m_floating);
|
||||
case IndexFloating:
|
||||
return CVariant::fromValue(this->m_floating);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -101,6 +119,12 @@ namespace BlackGui
|
||||
case IndexDockedMargins:
|
||||
this->m_dockedMargins = variant.toQString();
|
||||
break;
|
||||
case IndexFloating:
|
||||
this->m_floating = variant.toBool();
|
||||
break;
|
||||
case IndexFrameless:
|
||||
this->m_frameless = variant.toBool();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
@@ -129,5 +153,17 @@ namespace BlackGui
|
||||
Q_UNUSED(ok);
|
||||
return QMargins(l, t, r, b);
|
||||
}
|
||||
|
||||
CSettingsDockWidget CSettingsDockWidgets::getByNameOrInitToDefault(const QString &name)
|
||||
{
|
||||
if (this->contains(name)) { return this->value(name); }
|
||||
CSettingsDockWidget s;
|
||||
|
||||
// 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
|
||||
this->insert(name, s);
|
||||
return s;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -36,7 +36,9 @@ namespace BlackGui
|
||||
{
|
||||
IndexFloatingMargins = BlackMisc::CPropertyIndex::GlobalIndexCSettingsDockWidget,
|
||||
IndexFloatingFramelessMargins,
|
||||
IndexDockedMargins
|
||||
IndexDockedMargins,
|
||||
IndexFrameless,
|
||||
IndexFloating
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
@@ -46,22 +48,40 @@ namespace BlackGui
|
||||
~CSettingsDockWidget() {}
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setFloatingFramelessMargins(const QMargins &margins);
|
||||
void setMarginsWhenFramelessFloating(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getFloatingFramelessMargins() const;
|
||||
QMargins getMarginsWhenFramelessFloating() const;
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setFloatingMargins(const QMargins &margins);
|
||||
void setMarginsWhenFloating(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getFloatingMargins() const;
|
||||
QMargins getMarginsWhenFloating() const;
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setDockedMargins(const QMargins &margins);
|
||||
void setMarginsWhenDocked(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getDockedMargins() const;
|
||||
QMargins getMarginsWhenDocked() const;
|
||||
|
||||
//! Floating?
|
||||
bool isFloating() const { return m_floating; }
|
||||
|
||||
//! Frameless?
|
||||
bool isFramless() const { return m_frameless; }
|
||||
|
||||
//! Floating
|
||||
void setFloating(bool floating) { m_floating = floating; }
|
||||
|
||||
//! Frameless
|
||||
void setFrameless(bool frameless) { m_frameless = frameless; }
|
||||
|
||||
//! Geometry
|
||||
QByteArray getGeometry() const;
|
||||
|
||||
//! Set geometry
|
||||
void setGeometry(const QByteArray &ba);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
@@ -78,7 +98,10 @@ namespace BlackGui
|
||||
private:
|
||||
QString m_floatingMargins {"0:0:0:0"}; //!< margins: when floating
|
||||
QString m_floatingFramelessMargins {"0:0:0:0"}; //!< margins, when floating and frameless
|
||||
QString m_dockedMargins {"0:0:0:0"}; //!< margins, when floating and frameless
|
||||
QString m_dockedMargins {"0:0:0:0"}; //!< margins, when docked
|
||||
QString m_geometry; //!< geometry as HEX values
|
||||
bool m_floating = false; //!< floating
|
||||
bool m_frameless = false; //!< frameless
|
||||
|
||||
//! Convert to string
|
||||
static QString marginsToString(const QMargins &margins);
|
||||
@@ -90,7 +113,10 @@ namespace BlackGui
|
||||
CSettingsDockWidget,
|
||||
BLACK_METAMEMBER(floatingMargins),
|
||||
BLACK_METAMEMBER(floatingFramelessMargins),
|
||||
BLACK_METAMEMBER(dockedMargins)
|
||||
BLACK_METAMEMBER(dockedMargins),
|
||||
BLACK_METAMEMBER(floating),
|
||||
BLACK_METAMEMBER(frameless),
|
||||
BLACK_METAMEMBER(geometry)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -109,6 +135,8 @@ namespace BlackGui
|
||||
//! Default constructor.
|
||||
CSettingsDockWidgets() {}
|
||||
|
||||
//! Get setting or init by estimated default values
|
||||
CSettingsDockWidget getByNameOrInitToDefault(const QString &name);
|
||||
};
|
||||
|
||||
//! Trait for settings for dock widget
|
||||
|
||||
Reference in New Issue
Block a user