mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
refs #512, settings for dock widget
This commit is contained in:
@@ -31,9 +31,9 @@ HEADERS += $$PWD/views/*.h
|
||||
SOURCES += $$PWD/views/*.cpp
|
||||
|
||||
HEADERS += $$PWD/components/*.h
|
||||
# HEADERS += $$PWD/components/data/*.h
|
||||
HEADERS += $$PWD/settings/*.h
|
||||
SOURCES += $$PWD/components/*.cpp
|
||||
# SOURCES += $$PWD/components/data/*.cpp
|
||||
SOURCES += $$PWD/settings/*.cpp
|
||||
FORMS += $$PWD/components/*.ui
|
||||
|
||||
HEADERS += $$PWD/filters/*.h
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/registermetadata.h"
|
||||
#include "blackgui/settings/settingsdockwidget.h"
|
||||
#include "blackgui/components/registermetadatacomponents.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
void registerMetadata()
|
||||
{
|
||||
BlackGui::Settings::CSettingsDockWidget::registerMetadata();
|
||||
BlackGui::Settings::CSettingsDockWidgets::registerMetadata();
|
||||
BlackGui::Components::registerMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
133
src/blackgui/settings/settingsdockwidget.cpp
Normal file
133
src/blackgui/settings/settingsdockwidget.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/* 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 "settingsdockwidget.h"
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingsDockWidget::CSettingsDockWidget()
|
||||
{ }
|
||||
|
||||
void CSettingsDockWidget::setFloatingFramelessMargins(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingFramelessMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getFloatingFramelessMargins() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingFramelessMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setFloatingMargins(const QMargins &margins)
|
||||
{
|
||||
this->m_floatingMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getFloatingMargins() const
|
||||
{
|
||||
return stringToMargins(this->m_floatingMargins);
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setDockedMargins(const QMargins &margins)
|
||||
{
|
||||
this->m_dockedMargins = marginsToString(margins);
|
||||
}
|
||||
|
||||
QMargins CSettingsDockWidget::getDockedMargins() const
|
||||
{
|
||||
return stringToMargins(this->m_dockedMargins);
|
||||
}
|
||||
|
||||
QString CSettingsDockWidget::convertToQString(bool i18n) const
|
||||
{
|
||||
return convertToQString(", ", i18n);
|
||||
}
|
||||
|
||||
QString CSettingsDockWidget::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("floating: ");
|
||||
s.append(this->m_floatingMargins);
|
||||
s.append(separator);
|
||||
s.append("floating, frameless: ");
|
||||
s.append(this->m_floatingFramelessMargins);
|
||||
s.append(separator);
|
||||
s.append("docked: ");
|
||||
s.append(this->m_dockedMargins);
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CSettingsDockWidget::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexFloatingMargins:
|
||||
return CVariant::fromValue(this->m_floatingMargins);
|
||||
case IndexFloatingFramelessMargins:
|
||||
return CVariant::fromValue(this->m_floatingFramelessMargins);
|
||||
case IndexDockedMargins:
|
||||
return CVariant::fromValue(this->m_dockedMargins);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsDockWidget::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsDockWidget>(); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexFloatingMargins:
|
||||
this->m_floatingMargins = variant.toQString();
|
||||
break;
|
||||
case IndexFloatingFramelessMargins:
|
||||
this->m_floatingFramelessMargins = variant.toQString();
|
||||
break;
|
||||
case IndexDockedMargins:
|
||||
this->m_dockedMargins = variant.toQString();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
136
src/blackgui/settings/settingsdockwidget.h
Normal file
136
src/blackgui/settings/settingsdockwidget.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/* 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_DOCKWIDGET_H
|
||||
#define BLACKGUI_SETTINGS_DOCKWIDGET_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/dictionary.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Settings for dockwidget
|
||||
class BLACKGUI_EXPORT CSettingsDockWidget :
|
||||
public BlackMisc::CValueObject<CSettingsDockWidget>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexFloatingMargins = BlackMisc::CPropertyIndex::GlobalIndexCSettingsDockWidget,
|
||||
IndexFloatingFramelessMargins,
|
||||
IndexDockedMargins
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CSettingsDockWidget();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsDockWidget() {}
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setFloatingFramelessMargins(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getFloatingFramelessMargins() const;
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setFloatingMargins(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getFloatingMargins() const;
|
||||
|
||||
//! Set margins for given dock widget
|
||||
void setDockedMargins(const QMargins &margins);
|
||||
|
||||
//! Margins for given dock widget
|
||||
QMargins getDockedMargins() const;
|
||||
|
||||
//! \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_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
|
||||
|
||||
//! Convert to string
|
||||
static QString marginsToString(const QMargins &margins);
|
||||
|
||||
//! Convert from string
|
||||
static QMargins stringToMargins(const QString &str);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsDockWidget,
|
||||
BLACK_METAMEMBER(floatingMargins),
|
||||
BLACK_METAMEMBER(floatingFramelessMargins),
|
||||
BLACK_METAMEMBER(dockedMargins)
|
||||
);
|
||||
};
|
||||
|
||||
//! Needed to compile properly with Q_DECLARE_METATYPE
|
||||
using CDockWidgetSettingsDictionary = BlackMisc::CDictionary<QString, CSettingsDockWidget, QMap>;
|
||||
|
||||
//! Settings for all dock widgets
|
||||
class BLACKGUI_EXPORT CSettingsDockWidgets :
|
||||
public CDockWidgetSettingsDictionary,
|
||||
public BlackMisc::Mixin::MetaType<CSettingsDockWidgets>,
|
||||
public BlackMisc::Mixin::JsonOperators<CSettingsDockWidgets>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CSettingsDockWidgets)
|
||||
|
||||
//! Default constructor.
|
||||
CSettingsDockWidgets() {}
|
||||
|
||||
};
|
||||
|
||||
//! Trait for settings for dock widget
|
||||
struct SettingsDockWidgets : public BlackMisc::CSettingTrait<CSettingsDockWidgets>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "guidockwidget"; }
|
||||
|
||||
//! Default value
|
||||
static const CSettingsDockWidgets &defaultValue()
|
||||
{
|
||||
static const CSettingsDockWidgets defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CSettingsDockWidget)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CSettingsDockWidget>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CSettingsDockWidget>)
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CDockWidgetSettingsDictionary)
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CSettingsDockWidgets)
|
||||
|
||||
#endif // guard
|
||||
@@ -104,6 +104,7 @@ namespace BlackMisc
|
||||
GlobalIndexCVatsimSetup = 12200,
|
||||
GlobalIndexCGuiStateDbOwnModelsComponent = 14000,
|
||||
GlobalIndexCGuiStateDbOwnModelSetComponent = 14100,
|
||||
GlobalIndexCSettingsDockWidget = 14200,
|
||||
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user