mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs 419, improved pilot client navigator
* added setting and allow to restore/save state * allow to set margins * fixed style sheet * moved margin function to utility
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/components/navigatordialog.h"
|
||||
#include "blackgui/components/marginsinput.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "ui_navigatordialog.h"
|
||||
|
||||
@@ -31,6 +33,7 @@
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackGui::Settings;
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
@@ -49,8 +52,14 @@ namespace BlackGui
|
||||
|
||||
// context menu
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &CNavigatorDialog::customContextMenuRequested, this, &CNavigatorDialog::ps_showContextMenu);
|
||||
this->m_input = new CMarginsInput(this);
|
||||
this->m_input->setMaximumWidth(150);
|
||||
this->m_marginMenuAction = new QWidgetAction(this);
|
||||
this->m_marginMenuAction->setDefaultWidget(this->m_input);
|
||||
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this->m_input, &CMarginsInput::changedMargins, this, &CNavigatorDialog::ps_menuChangeMargins);
|
||||
connect(this, &CNavigatorDialog::customContextMenuRequested, this, &CNavigatorDialog::ps_showContextMenu);
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CNavigatorDialog::ps_onStyleSheetsChanged);
|
||||
this->ps_onStyleSheetsChanged();
|
||||
}
|
||||
@@ -77,7 +86,6 @@ namespace BlackGui
|
||||
gridLayout->setSpacing(0);
|
||||
gridLayout->setMargin(0);
|
||||
gridLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
this->ui->fr_NavigatorDialogInner->setLayout(gridLayout);
|
||||
int r = 0;
|
||||
int c = 0;
|
||||
@@ -94,14 +102,8 @@ namespace BlackGui
|
||||
c = 0;
|
||||
r++;
|
||||
}
|
||||
|
||||
int w = 16 * gridLayout->columnCount();
|
||||
int h = 16 * gridLayout->rowCount();
|
||||
this->m_currentColumns = gridLayout->columnCount();
|
||||
QSize min(w + 2, h + 2);
|
||||
this->ui->fr_NavigatorDialogInner->setMinimumSize(min);
|
||||
this->setMinimumSize(min);
|
||||
this->adjustSize();
|
||||
this->adjustNavigatorSize(gridLayout);
|
||||
}
|
||||
|
||||
void CNavigatorDialog::toggleFrameless()
|
||||
@@ -114,11 +116,33 @@ namespace BlackGui
|
||||
this->setVisible(!this->isVisible());
|
||||
}
|
||||
|
||||
void CNavigatorDialog::restoreFromSettings()
|
||||
{
|
||||
const CSettingsNavigator s = this->m_settings.get();
|
||||
this->setContentsMargins(s.getMargins());
|
||||
if (this->isFrameless() != s.isFramless()) { this->toggleFrameless(); }
|
||||
this->buildNavigator(s.getColumns());
|
||||
const QByteArray geo(s.getGeometry());
|
||||
this->restoreGeometry(geo);
|
||||
}
|
||||
|
||||
void CNavigatorDialog::saveToSettings()
|
||||
{
|
||||
CSettingsNavigator s = this->m_settings.get();
|
||||
s.setFrameless(this->isFrameless());
|
||||
s.setMargins(this->contentsMargins());
|
||||
s.setGeometry(this->saveGeometry());
|
||||
s.setColumns(this->m_currentColumns);
|
||||
const CStatusMessage m = this->m_settings.setAndSave(s);
|
||||
if (!m.isSuccess()) { CLogMessage::preformatted(m); }
|
||||
}
|
||||
|
||||
void CNavigatorDialog::ps_onStyleSheetsChanged()
|
||||
{
|
||||
const QString fn(CStyleSheetUtility::fileNameNavigator());
|
||||
const QString qss(sGui->getStyleSheetUtility().style(fn));
|
||||
this->setStyleSheet(qss);
|
||||
this->adjustNavigatorSize();
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
@@ -179,6 +203,22 @@ namespace BlackGui
|
||||
else if (v == "2r") { buildNavigator(columnsForRows(2));}
|
||||
}
|
||||
|
||||
void CNavigatorDialog::ps_menuChangeMargins(const QMargins &margins)
|
||||
{
|
||||
this->setContentsMargins(margins);
|
||||
this->adjustNavigatorSize();
|
||||
}
|
||||
|
||||
void CNavigatorDialog::ps_dummy()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CNavigatorDialog::ps_settingsChanged()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CNavigatorDialog::insertOwnActions()
|
||||
{
|
||||
// add some space for frameless navigators where I can move the navigator
|
||||
@@ -197,6 +237,11 @@ namespace BlackGui
|
||||
a = new QAction(i, "Close", this);
|
||||
connect(a, &QAction::triggered, this, &CNavigatorDialog::close);
|
||||
this->addAction(a);
|
||||
|
||||
// save
|
||||
a = new QAction(CIcons::save16(), "Save state", this);
|
||||
connect(a, &QAction::triggered, this, &CNavigatorDialog::saveToSettings);
|
||||
this->addAction(a);
|
||||
}
|
||||
|
||||
int CNavigatorDialog::columnsForRows(int rows)
|
||||
@@ -207,6 +252,31 @@ namespace BlackGui
|
||||
return (c * rows) < items ? c + 1 : c;
|
||||
}
|
||||
|
||||
QGridLayout *CNavigatorDialog::myGridLayout() const
|
||||
{
|
||||
return qobject_cast<QGridLayout *>(this->layout());
|
||||
}
|
||||
|
||||
void CNavigatorDialog::adjustNavigatorSize(QGridLayout *layout)
|
||||
{
|
||||
QGridLayout *gridLayout = layout ? layout : this->myGridLayout();
|
||||
Q_ASSERT_X(gridLayout, Q_FUNC_INFO, "Missing layout");
|
||||
|
||||
int w = 16 * gridLayout->columnCount();
|
||||
int h = 16 * gridLayout->rowCount();
|
||||
|
||||
// margins
|
||||
QMargins margins = gridLayout->contentsMargins() + this->contentsMargins();
|
||||
h = h + margins.top() + margins.bottom();
|
||||
w = w + margins.left() + margins.right();
|
||||
|
||||
// adjust
|
||||
const QSize min(w + 2, h + 2);
|
||||
this->ui->fr_NavigatorDialogInner->setMinimumSize(min);
|
||||
this->setMinimumSize(min);
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
void CNavigatorDialog::addToContextMenu(QMenu *contextMenu) const
|
||||
{
|
||||
QAction *a = contextMenu->addAction(CIcons::resize16(), "1 row", this, &CNavigatorDialog::ps_changeLayout);
|
||||
@@ -217,11 +287,13 @@ namespace BlackGui
|
||||
a->setData("1c");
|
||||
a = contextMenu->addAction(CIcons::resize16(), "2 columns", this, &CNavigatorDialog::ps_changeLayout);
|
||||
a->setData("2c");
|
||||
|
||||
contextMenu->addSeparator();
|
||||
|
||||
QString frameLessActionText = this->isFrameless() ? "Normal window" : "Frameless";
|
||||
contextMenu->addAction(BlackMisc::CIcons::tableSheet16(), frameLessActionText, this, SLOT(toggleFrameless()));
|
||||
contextMenu->addAction("Adjust margins", this, &CNavigatorDialog::ps_dummy);
|
||||
contextMenu->addAction(this->m_marginMenuAction);
|
||||
contextMenu->addSeparator();
|
||||
contextMenu->addAction(CIcons::load16(), "Restore state", this, &CNavigatorDialog::restoreFromSettings);
|
||||
contextMenu->addAction(CIcons::save16(), "Save state", this, &CNavigatorDialog::saveToSettings);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -14,10 +14,13 @@
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/enableforframelesswindow.h"
|
||||
#include "blackgui/settings/settingsnavigator.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QWidgetAction>
|
||||
#include <QGridLayout>
|
||||
|
||||
class QEvent;
|
||||
class QMenu;
|
||||
@@ -31,6 +34,8 @@ namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
class CMarginsInput;
|
||||
|
||||
/*!
|
||||
* Navigator dialog
|
||||
*/
|
||||
@@ -57,6 +62,12 @@ namespace BlackGui
|
||||
//! Toggle visibility
|
||||
void toggleNavigator();
|
||||
|
||||
//! Restore from settings
|
||||
void restoreFromSettings();
|
||||
|
||||
//! Save to settings
|
||||
void saveToSettings();
|
||||
|
||||
protected:
|
||||
//! Style sheet has changed
|
||||
void ps_onStyleSheetsChanged();
|
||||
@@ -77,6 +88,15 @@ namespace BlackGui
|
||||
//! Change the layout
|
||||
void ps_changeLayout();
|
||||
|
||||
//! Margins context menu
|
||||
void ps_menuChangeMargins(const QMargins &margins);
|
||||
|
||||
//! Dummy slot
|
||||
void ps_dummy();
|
||||
|
||||
//! Changed settigs
|
||||
void ps_settingsChanged();
|
||||
|
||||
private:
|
||||
//! Insert own actions
|
||||
void insertOwnActions();
|
||||
@@ -87,9 +107,18 @@ namespace BlackGui
|
||||
//! How many columns for given rows
|
||||
int columnsForRows(int rows);
|
||||
|
||||
//! Get my own grid layout
|
||||
QGridLayout *myGridLayout() const;
|
||||
|
||||
//! Adjust navigator size
|
||||
void adjustNavigatorSize(QGridLayout *layout = nullptr);
|
||||
|
||||
QScopedPointer<Ui::CNavigatorDialog> ui;
|
||||
bool m_firstBuild = true;
|
||||
bool m_firstBuild = true;
|
||||
int m_currentColumns = 1;
|
||||
QWidgetAction *m_marginMenuAction = nullptr; //!< menu widget(!) action for margin widget
|
||||
CMarginsInput *m_input = nullptr; //!< margins widget
|
||||
BlackMisc::CSetting<BlackGui::Settings::SettingsNavigator> m_settings { this, &CNavigatorDialog::ps_settingsChanged };
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
#fr_NavigatorDialogInner[navigatorFrameless="true"] {
|
||||
margin: 0px;
|
||||
padding: 3px;
|
||||
border: 2px solid green;
|
||||
border-radius: 10px;
|
||||
QDialog {
|
||||
background: lightgrey;
|
||||
}
|
||||
|
||||
#fr_NavigatorDialogInner[navigatorFrameless="false"] {
|
||||
margin: 0px;
|
||||
padding: 3px;
|
||||
border: 0px;
|
||||
border-radius: 0px;
|
||||
}
|
||||
/*
|
||||
#fr_NavigatorDialogInner[navigatorFrameless="true"] {}
|
||||
#fr_NavigatorDialogInner[navigatorFrameless="false"] {}
|
||||
*/
|
||||
|
||||
#fr_NavigatorDialogInner QToolButton {
|
||||
margin: 0px;
|
||||
|
||||
@@ -304,4 +304,27 @@ namespace BlackGui
|
||||
widget->show();
|
||||
return Qt::WindowStaysOnTopHint & flags;
|
||||
}
|
||||
|
||||
QString CGuiUtility::marginsToString(const QMargins &margins)
|
||||
{
|
||||
const QString s("%1:%2:%3:%4");
|
||||
return s.arg(margins.left()).arg(margins.top()).arg(margins.right()).arg(margins.bottom());
|
||||
}
|
||||
|
||||
QMargins CGuiUtility::stringToMargins(const QString &str)
|
||||
{
|
||||
const QStringList parts = str.split(":");
|
||||
Q_ASSERT_X(parts.size() == 4, Q_FUNC_INFO, "malformed");
|
||||
bool ok = false;
|
||||
const int l = parts.at(0).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int t = parts.at(1).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int r = parts.at(2).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int b = parts.at(3).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
Q_UNUSED(ok);
|
||||
return QMargins(l, t, r, b);
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -94,6 +94,12 @@ namespace BlackGui
|
||||
//! From a given widget try to find parent tab widget (where widget is embedded)
|
||||
static QTabWidget *parentTabWidget(QWidget *widget, int maxLevels = 5);
|
||||
|
||||
//! Convert to string
|
||||
static QString marginsToString(const QMargins &margins);
|
||||
|
||||
//! Convert from string
|
||||
static QMargins stringToMargins(const QString &str);
|
||||
|
||||
private:
|
||||
//! Constructor, use static methods only
|
||||
CGuiUtility() {}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "blackgui/registermetadata.h"
|
||||
#include "blackgui/settings/settingsdockwidget.h"
|
||||
#include "blackgui/settings/settingsnavigator.h"
|
||||
#include "blackgui/components/registermetadatacomponents.h"
|
||||
|
||||
namespace BlackGui
|
||||
@@ -16,7 +17,7 @@ namespace BlackGui
|
||||
void registerMetadata()
|
||||
{
|
||||
BlackGui::Settings::CSettingsDockWidget::registerMetadata();
|
||||
BlackGui::Settings::CSettingsDockWidgets::registerMetadata();
|
||||
BlackGui::Settings::CSettingsNavigator::registerMetadata();
|
||||
BlackGui::Components::registerMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
*/
|
||||
|
||||
#include "settingsdockwidget.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -36,32 +38,32 @@ namespace BlackGui
|
||||
|
||||
void CSettingsDockWidget::setMarginsWhenFramelessFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingFramelessMargins = marginsToString(margins);
|
||||
this->m_floatingFramelessMargins = CGuiUtility::marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getMarginsWhenFramelessFloating() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingFramelessMargins);
|
||||
return CGuiUtility::stringToMargins(this->m_floatingFramelessMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setMarginsWhenFloating(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingMargins = marginsToString(margins);
|
||||
this->m_floatingMargins = CGuiUtility::marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getMarginsWhenFloating() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingMargins);
|
||||
return CGuiUtility::stringToMargins(this->m_floatingMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setMarginsWhenDocked(const QMargins &margins)
|
||||
{
|
||||
this->m_dockedMargins = marginsToString(margins);
|
||||
this->m_dockedMargins = CGuiUtility::marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getMarginsWhenDocked() const
|
||||
{
|
||||
return stringToMargins(this->m_dockedMargins);
|
||||
return CGuiUtility::stringToMargins(this->m_dockedMargins);
|
||||
}
|
||||
|
||||
QByteArray CSettingsDockWidget::getGeometry() const
|
||||
@@ -91,8 +93,11 @@ namespace BlackGui
|
||||
s.append("docked: ");
|
||||
s.append(this->m_dockedMargins);
|
||||
s.append(separator);
|
||||
s.append("docked: ");
|
||||
|
||||
s.append("frameless: ");
|
||||
s.append(boolToTrueFalse(this->m_frameless));
|
||||
s.append(separator);
|
||||
s.append("floating: ");
|
||||
s.append(boolToTrueFalse(this->m_floating));
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -145,29 +150,6 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
QString CSettingsDockWidget::marginsToString(const QMargins &margins)
|
||||
{
|
||||
const QString s("%1:%2:%3:%4");
|
||||
return s.arg(margins.left()).arg(margins.top()).arg(margins.right()).arg(margins.bottom());
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::stringToMargins(const QString &str)
|
||||
{
|
||||
const QStringList parts = str.split(":");
|
||||
Q_ASSERT_X(parts.size() == 4, Q_FUNC_INFO, "malformed");
|
||||
bool ok = false;
|
||||
const int l = parts.at(0).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int t = parts.at(1).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int r = parts.at(2).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
const int b = parts.at(3).toInt(&ok);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "malformed number");
|
||||
Q_UNUSED(ok);
|
||||
return QMargins(l, t, r, b);
|
||||
}
|
||||
|
||||
CSettingsDockWidget CSettingsDockWidgets::getByNameOrInitToDefault(const QString &name)
|
||||
{
|
||||
if (this->contains(name)) { return this->value(name); }
|
||||
|
||||
@@ -109,12 +109,6 @@ namespace BlackGui
|
||||
bool m_floating = false; //!< floating
|
||||
bool m_frameless = false; //!< frameless
|
||||
|
||||
//! Convert to string
|
||||
static QString marginsToString(const QMargins &margins);
|
||||
|
||||
//! Convert from string
|
||||
static QMargins stringToMargins(const QString &str);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsDockWidget,
|
||||
BLACK_METAMEMBER(floatingMargins),
|
||||
|
||||
106
src/blackgui/settings/settingsnavigator.cpp
Normal file
106
src/blackgui/settings/settingsnavigator.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "settingsnavigator.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingsNavigator::CSettingsNavigator()
|
||||
{ }
|
||||
|
||||
void CSettingsNavigator::reset()
|
||||
{ }
|
||||
|
||||
void CSettingsNavigator::setMargins(const QMargins &margins)
|
||||
{
|
||||
this->m_margins = CGuiUtility::marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsNavigator::getMargins() const
|
||||
{
|
||||
return CGuiUtility::stringToMargins(this->m_margins);
|
||||
}
|
||||
|
||||
QByteArray CSettingsNavigator::getGeometry() const
|
||||
{
|
||||
return byteArrayFromHexString(this->m_geometry);
|
||||
}
|
||||
|
||||
void CSettingsNavigator::setGeometry(const QByteArray &ba)
|
||||
{
|
||||
this->m_geometry = bytesToHexString(ba);
|
||||
}
|
||||
|
||||
QString CSettingsNavigator::convertToQString(bool i18n) const
|
||||
{
|
||||
return convertToQString(", ", i18n);
|
||||
}
|
||||
|
||||
QString CSettingsNavigator::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("margins: ");
|
||||
s.append(this->m_margins);
|
||||
s.append(separator);
|
||||
s.append("frameless: ");
|
||||
s.append(boolToTrueFalse(this->m_frameless));
|
||||
s.append(separator);
|
||||
s.append("columns: ");
|
||||
s.append(this->m_columns);
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CSettingsNavigator::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMargins:
|
||||
return CVariant::fromValue(this->m_margins);
|
||||
case IndexFrameless:
|
||||
return CVariant::fromValue(this->isFramless());
|
||||
case IndexColumns:
|
||||
return CVariant::fromValue(this->m_columns);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsNavigator::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsNavigator>(); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMargins:
|
||||
this->m_margins = variant.toQString();
|
||||
break;
|
||||
case IndexColumns:
|
||||
this->m_columns = variant.toInt();
|
||||
break;
|
||||
case IndexFrameless:
|
||||
this->m_frameless = variant.toBool();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
114
src/blackgui/settings/settingsnavigator.h
Normal file
114
src/blackgui/settings/settingsnavigator.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_SETTINGS_NAVIGATOR_H
|
||||
#define BLACKGUI_SETTINGS_NAVIGATOR_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Settings for dockwidget
|
||||
class BLACKGUI_EXPORT CSettingsNavigator :
|
||||
public BlackMisc::CValueObject<CSettingsNavigator>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexMargins = BlackMisc::CPropertyIndex::GlobalIndexCSettingsNavigator,
|
||||
IndexFrameless,
|
||||
IndexColumns
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CSettingsNavigator();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsNavigator() {}
|
||||
|
||||
//! Reset to defaults
|
||||
void reset();
|
||||
|
||||
//! Set margins
|
||||
void setMargins(const QMargins &margins);
|
||||
|
||||
//! Margins
|
||||
QMargins getMargins() const;
|
||||
|
||||
//! Frameless?
|
||||
bool isFramless() const { return m_frameless; }
|
||||
|
||||
//! Frameless
|
||||
void setFrameless(bool frameless) { m_frameless = frameless; }
|
||||
|
||||
//! Number pf columns
|
||||
int getColumns() const { return m_columns; }
|
||||
|
||||
//! Set columns
|
||||
void setColumns(int columns) { this->m_columns = columns; }
|
||||
|
||||
//! Geometry
|
||||
QByteArray getGeometry() const;
|
||||
|
||||
//! Set geometry
|
||||
void setGeometry(const QByteArray &ba);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! To string
|
||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
QString m_margins {"0:0:0:0"}; //!< margins
|
||||
QString m_geometry; //!< geometry as HEX values
|
||||
bool m_frameless = false; //!< frameless
|
||||
int m_columns = 1; //!< number of columns
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsNavigator,
|
||||
BLACK_METAMEMBER(margins),
|
||||
BLACK_METAMEMBER(frameless),
|
||||
BLACK_METAMEMBER(columns),
|
||||
BLACK_METAMEMBER(geometry)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for settings for navigator
|
||||
struct SettingsNavigator : public BlackMisc::CSettingTrait<CSettingsNavigator>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "guinavigator"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CSettingsNavigator)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CSettingsNavigator>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CSettingsNavigator>)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user