From f80b2293f535bfc6d321619c8d35e6f17474b427 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 24 May 2018 13:02:36 +0200 Subject: [PATCH] Scale UI component, used in launcher --- src/blackgui/components/scalescreenfactor.cpp | 77 ++++++++ src/blackgui/components/scalescreenfactor.h | 59 ++++++ src/blackgui/components/scalescreenfactor.ui | 66 +++++++ src/swiftlauncher/swiftlauncher.cpp | 3 + src/swiftlauncher/swiftlauncher.ui | 168 ++++++++++-------- 5 files changed, 303 insertions(+), 70 deletions(-) create mode 100644 src/blackgui/components/scalescreenfactor.cpp create mode 100644 src/blackgui/components/scalescreenfactor.h create mode 100644 src/blackgui/components/scalescreenfactor.ui diff --git a/src/blackgui/components/scalescreenfactor.cpp b/src/blackgui/components/scalescreenfactor.cpp new file mode 100644 index 000000000..9476c78d2 --- /dev/null +++ b/src/blackgui/components/scalescreenfactor.cpp @@ -0,0 +1,77 @@ +/* Copyright (C) 2018 + * 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 "scalescreenfactor.h" +#include "ui_scalescreenfactor.h" +#include + +namespace BlackGui +{ + namespace Components + { + CScaleScreenFactor::CScaleScreenFactor(QWidget *parent) : + QFrame(parent), + ui(new Ui::CScaleScreenFactor) + { + ui->setupUi(this); + this->setMinMax(50, 150); + + connect(ui->hs_Factor, &QSlider::valueChanged, this, &CScaleScreenFactor::onSliderChanged); + connect(ui->le_Factor, &QLineEdit::editingFinished, this, &CScaleScreenFactor::onEditFinished); + } + + CScaleScreenFactor::~CScaleScreenFactor() + { } + + void CScaleScreenFactor::setMinMax(int min, int max) + { + ui->hs_Factor->setMinimum(min); + ui->hs_Factor->setMaximum(max); + ui->le_Factor->setValidator(new QIntValidator(min, max, ui->le_Factor)); + + static const QString info("%1-%2"); + ui->le_Factor->setToolTip(info.arg(min).arg(max)); + ui->le_Factor->setPlaceholderText(info.arg(min).arg(max)); + ui->hs_Factor->setToolTip(info.arg(min, max)); + + const int v = (min + max) / 2; + ui->hs_Factor->setValue(v); + ui->le_Factor->setText(QString::number(v)); + } + + qreal CScaleScreenFactor::getScaleFactor() const + { + return 0.01 * ui->hs_Factor->value(); + } + + QString CScaleScreenFactor::getScaleFactorAsString() const + { + const QString sf = QString::number(this->getScaleFactor(), 'f', 2); + return sf; + } + + void CScaleScreenFactor::onSliderChanged(int value) + { + const QString v = QString::number(value); + if (ui->le_Factor->text() == v) { return; } // avoid signal roundtrips + ui->le_Factor->setText(v); + } + + void CScaleScreenFactor::onEditFinished() + { + const QString v = ui->le_Factor->text(); + if (v.isEmpty()) { return; } + bool ok; + const int value = v.toInt(&ok); + if (!ok) { return; } + if (ui->hs_Factor->value() == value) { return; } // avoid signal roundtrips + ui->hs_Factor->setValue(value); + } + } // ns +} // ns diff --git a/src/blackgui/components/scalescreenfactor.h b/src/blackgui/components/scalescreenfactor.h new file mode 100644 index 000000000..e5efaf247 --- /dev/null +++ b/src/blackgui/components/scalescreenfactor.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2018 + * 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_COMPONENTS_SCALESCREENFACTOR_H +#define BLACKGUI_COMPONENTS_SCALESCREENFACTOR_H + +#include "blackgui/blackguiexport.h" +#include +#include + +namespace Ui { class CScaleScreenFactor; } +namespace BlackGui +{ + namespace Components + { + /** + * UI to scale screen factor + */ + class BLACKGUI_EXPORT CScaleScreenFactor : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CScaleScreenFactor(QWidget *parent = nullptr); + + //! Destructor + virtual ~CScaleScreenFactor(); + + //! Minimum/maximum values + void setMinMax(int min, int max); + + //! Scale factor + qreal getScaleFactor() const; + + //! Scale factor as string + QString getScaleFactorAsString() const; + + private: + //! Slider value changed + void onSliderChanged(int value); + + //! Line edit change + void onEditFinished(); + + QScopedPointer ui; + }; + } // ns +}// ns + +#endif // guard diff --git a/src/blackgui/components/scalescreenfactor.ui b/src/blackgui/components/scalescreenfactor.ui new file mode 100644 index 000000000..2d6d85bd8 --- /dev/null +++ b/src/blackgui/components/scalescreenfactor.ui @@ -0,0 +1,66 @@ + + + CScaleScreenFactor + + + + 0 + 0 + 165 + 24 + + + + Scale screen factor + + + + 1 + + + 1 + + + 1 + + + 1 + + + + + Scale: + + + + + + + 5 + + + + + + + 50 + + + 150 + + + 5 + + + 100 + + + Qt::Horizontal + + + + + + + + diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index adf116f8e..a14e6a02b 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -357,6 +357,9 @@ QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs void CSwiftLauncher::startButtonPressed() { const QObject *sender = QObject::sender(); + const qreal scaleFactor = ui->comp_Scale->getScaleFactor(); + CGuiApplication::highDpiScreenSupport(scaleFactor); + if (sender == ui->tb_SwiftGui) { if (this->setSwiftGuiExecutable()) diff --git a/src/swiftlauncher/swiftlauncher.ui b/src/swiftlauncher/swiftlauncher.ui index 6a55c08c7..c3beed1cd 100644 --- a/src/swiftlauncher/swiftlauncher.ui +++ b/src/swiftlauncher/swiftlauncher.ui @@ -99,7 +99,7 @@ 0 0 392 - 319 + 299 @@ -130,7 +130,7 @@ 0 0 392 - 319 + 299 @@ -195,7 +195,7 @@ 0 0 392 - 319 + 299 @@ -361,7 +361,7 @@ 0 0 392 - 319 + 299 @@ -443,7 +443,7 @@ 0 0 376 - 156 + 136 @@ -494,7 +494,7 @@ 0 0 392 - 319 + 299 @@ -531,7 +531,7 @@ 0 - 140 + 160 @@ -543,68 +543,36 @@ 0 0 392 - 116 + 136 Start application - - - - start swift data (the mapping tool) + + 3 + + + 3 + + + 3 + + + 3 + + + + + QFrame::StyledPanel - - mapping tool - - - - :/own/icons/own/swift3D/sw3DGreen-256.png:/own/icons/own/swift3D/sw3DGreen-256.png - - - - 64 - 64 - + + QFrame::Raised - - - - open browser for swift database - - - goto swift database - - - - :/own/icons/own/swift3D/sw3DGreen-256.png:/own/icons/own/swift3D/sw3DGreen-256.png - - - - 48 - 48 - - - - - - - - mapping tool - - - - - - - core - - - - + start swift GUI @@ -624,14 +592,7 @@ - - - - GUI - - - - + start swift core @@ -651,7 +612,27 @@ - + + + + start swift data (the mapping tool) + + + mapping tool + + + + :/own/icons/own/swift3D/sw3DGreen-256.png:/own/icons/own/swift3D/sw3DGreen-256.png + + + + 64 + 64 + + + + + ... @@ -668,14 +649,55 @@ - + + + + open browser for swift database + + + goto swift database + + + + :/own/icons/own/swift3D/sw3DGreen-256.png:/own/icons/own/swift3D/sw3DGreen-256.png + + + + 48 + 48 + + + + + + + + GUI + + + + + + + core + + + + + + + mapping tool + + + + config - + goto DB @@ -778,6 +800,12 @@
blackgui/components/abouthtmlcomponent.h
1 + + BlackGui::Components::CScaleScreenFactor + QFrame +
blackgui/components/scalescreenfactor.h
+ 1 +
tbr_LatestNews