mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Scale UI component, used in launcher
This commit is contained in:
77
src/blackgui/components/scalescreenfactor.cpp
Normal file
77
src/blackgui/components/scalescreenfactor.cpp
Normal 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
|
||||
59
src/blackgui/components/scalescreenfactor.h
Normal file
59
src/blackgui/components/scalescreenfactor.h
Normal 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
|
||||
66
src/blackgui/components/scalescreenfactor.ui
Normal file
66
src/blackgui/components/scalescreenfactor.ui
Normal 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>
|
||||
Reference in New Issue
Block a user