Scale UI component, used in launcher

This commit is contained in:
Klaus Basan
2018-05-24 13:02:36 +02:00
parent 86d02716a2
commit f80b2293f5
5 changed files with 303 additions and 70 deletions

View File

@@ -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 <QIntValidator>
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

View File

@@ -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 <QFrame>
#include <QScopedPointer>
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::CScaleScreenFactor> ui;
};
} // ns
}// ns
#endif // guard

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CScaleScreenFactor</class>
<widget class="QFrame" name="CScaleScreenFactor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>165</width>
<height>24</height>
</rect>
</property>
<property name="windowTitle">
<string>Scale screen factor</string>
</property>
<layout class="QHBoxLayout" name="hl_ScaleScreenFactor" stretch="0,1,5">
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="lbl_Scale">
<property name="text">
<string>Scale:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_Factor">
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="hs_Factor">
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>150</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -357,6 +357,9 @@ QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs
void CSwiftLauncher::startButtonPressed() void CSwiftLauncher::startButtonPressed()
{ {
const QObject *sender = QObject::sender(); const QObject *sender = QObject::sender();
const qreal scaleFactor = ui->comp_Scale->getScaleFactor();
CGuiApplication::highDpiScreenSupport(scaleFactor);
if (sender == ui->tb_SwiftGui) if (sender == ui->tb_SwiftGui)
{ {
if (this->setSwiftGuiExecutable()) if (this->setSwiftGuiExecutable())

View File

@@ -99,7 +99,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>319</height> <height>299</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@@ -130,7 +130,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>319</height> <height>299</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@@ -195,7 +195,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>319</height> <height>299</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@@ -361,7 +361,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>319</height> <height>299</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@@ -443,7 +443,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>376</width> <width>376</width>
<height>156</height> <height>136</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="vl_DataUpdatesScrollArea"> <layout class="QVBoxLayout" name="vl_DataUpdatesScrollArea">
@@ -494,7 +494,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>319</height> <height>299</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@@ -531,7 +531,7 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>140</height> <height>160</height>
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
@@ -543,68 +543,36 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>392</width> <width>392</width>
<height>116</height> <height>136</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Start application</string> <string>Start application</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gl_Start"> <layout class="QGridLayout" name="gl_Start">
<item row="0" column="2"> <property name="leftMargin">
<widget class="QToolButton" name="tb_SwiftMappingTool"> <number>3</number>
<property name="toolTip">
<string>start swift data (the mapping tool)</string>
</property> </property>
<property name="text"> <property name="topMargin">
<string>mapping tool</string> <number>3</number>
</property> </property>
<property name="icon"> <property name="rightMargin">
<iconset resource="../blackmisc/blackmisc.qrc"> <number>3</number>
<normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</iconset>
</property> </property>
<property name="iconSize"> <property name="bottomMargin">
<size> <number>3</number>
<width>64</width> </property>
<height>64</height> <item row="0" column="0" colspan="5">
</size> <widget class="BlackGui::Components::CScaleScreenFactor" name="comp_Scale">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="1" column="0">
<widget class="QToolButton" name="tb_Database">
<property name="toolTip">
<string>open browser for swift database</string>
</property>
<property name="text">
<string>goto swift database</string>
</property>
<property name="icon">
<iconset resource="../blackmisc/blackmisc.qrc">
<normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</iconset>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="lbl_SwiftData">
<property name="text">
<string>mapping tool</string>
</property>
</widget>
</item>
<item row="1" column="1" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="lbl_SwiftCore">
<property name="text">
<string>core</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="tb_SwiftGui"> <widget class="QToolButton" name="tb_SwiftGui">
<property name="toolTip"> <property name="toolTip">
<string>start swift GUI</string> <string>start swift GUI</string>
@@ -624,14 +592,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" alignment="Qt::AlignHCenter"> <item row="1" column="1">
<widget class="QLabel" name="lbl_SwiftGui">
<property name="text">
<string>GUI</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="tb_SwiftCore"> <widget class="QToolButton" name="tb_SwiftCore">
<property name="toolTip"> <property name="toolTip">
<string>start swift core</string> <string>start swift core</string>
@@ -651,7 +612,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="1" column="2">
<widget class="QToolButton" name="tb_SwiftMappingTool">
<property name="toolTip">
<string>start swift data (the mapping tool)</string>
</property>
<property name="text">
<string>mapping tool</string>
</property>
<property name="icon">
<iconset resource="../blackmisc/blackmisc.qrc">
<normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="tb_ConfigurationWizard"> <widget class="QToolButton" name="tb_ConfigurationWizard">
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
@@ -668,14 +649,55 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="3" alignment="Qt::AlignHCenter"> <item row="1" column="4">
<widget class="QToolButton" name="tb_Database">
<property name="toolTip">
<string>open browser for swift database</string>
</property>
<property name="text">
<string>goto swift database</string>
</property>
<property name="icon">
<iconset resource="../blackmisc/blackmisc.qrc">
<normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</normaloff>:/own/icons/own/swift3D/sw3DGreen-256.png</iconset>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_SwiftGui">
<property name="text">
<string>GUI</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="lbl_SwiftCore">
<property name="text">
<string>core</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="lbl_SwiftData">
<property name="text">
<string>mapping tool</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="lbl_Wizard"> <widget class="QLabel" name="lbl_Wizard">
<property name="text"> <property name="text">
<string>config</string> <string>config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="4" alignment="Qt::AlignHCenter"> <item row="2" column="4">
<widget class="QLabel" name="lbl_Database"> <widget class="QLabel" name="lbl_Database">
<property name="text"> <property name="text">
<string>goto DB</string> <string>goto DB</string>
@@ -778,6 +800,12 @@
<header>blackgui/components/abouthtmlcomponent.h</header> <header>blackgui/components/abouthtmlcomponent.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>BlackGui::Components::CScaleScreenFactor</class>
<extends>QFrame</extends>
<header>blackgui/components/scalescreenfactor.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>tbr_LatestNews</tabstop> <tabstop>tbr_LatestNews</tabstop>