mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +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,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