code format
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#include "touchslider.h"
|
||||
|
||||
#include "ui_touchslider.h"
|
||||
|
||||
|
||||
TouchSlider::TouchSlider(QWidget * parent): QGroupBox(parent), ui(new Ui::TouchSlider) {
|
||||
ui->setupUi(this);
|
||||
ui->barNeg->setMinimum(0);
|
||||
prec = 1;
|
||||
prec = 1;
|
||||
id_click = id_set = -1;
|
||||
hasZero = true;
|
||||
m_readOnly = false;
|
||||
m_showMinMax = true;
|
||||
m_showIncDec = true;
|
||||
hasZero = true;
|
||||
m_readOnly = false;
|
||||
m_showMinMax = true;
|
||||
m_showIncDec = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +69,8 @@ void TouchSlider::setValue(double val) {
|
||||
double TouchSlider::value() const {
|
||||
if (ui->barNeg->value() <= ui->barNeg->minimum())
|
||||
return (double)(ui->barPos->value()) * prec;
|
||||
else return -(double)(ui->barNeg->value()) * prec;
|
||||
else
|
||||
return -(double)(ui->barNeg->value()) * prec;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +119,7 @@ void TouchSlider::setPrecision(double precision) {
|
||||
double min = minimum();
|
||||
double max = maximum();
|
||||
double val = value();
|
||||
prec = precision;
|
||||
prec = precision;
|
||||
setMinimum(min);
|
||||
setMaximum(max);
|
||||
setValue(val);
|
||||
@@ -144,9 +146,9 @@ void TouchSlider::on_barPos_mouseMoveEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx =
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
e->x();
|
||||
e->x();
|
||||
#else
|
||||
e->position().toPoint().x();
|
||||
e->position().toPoint().x();
|
||||
#endif
|
||||
if (tx > ui->barPos->width()) tx = ui->barPos->width();
|
||||
if (tx < 0) {
|
||||
@@ -160,7 +162,8 @@ void TouchSlider::on_barPos_mouseMoveEvent(QMouseEvent * e) {
|
||||
}
|
||||
tx = 0;
|
||||
}
|
||||
ui->barPos->setValue(ui->barPos->minimum() + qRound((double)(tx * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barPos->setValue(ui->barPos->minimum() +
|
||||
qRound((double)(tx * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
}
|
||||
|
||||
@@ -169,9 +172,9 @@ void TouchSlider::on_barNeg_mouseMoveEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx =
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
e->x();
|
||||
e->x();
|
||||
#else
|
||||
e->position().toPoint().x();
|
||||
e->position().toPoint().x();
|
||||
#endif
|
||||
if (tx < 0) tx = 0;
|
||||
if (tx > ui->barNeg->width()) {
|
||||
@@ -192,11 +195,12 @@ void TouchSlider::on_barPos_mousePressEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx =
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
e->x();
|
||||
e->x();
|
||||
#else
|
||||
e->position().toPoint().x();
|
||||
e->position().toPoint().x();
|
||||
#endif
|
||||
ui->barPos->setValue(ui->barPos->minimum() + qRound((double)(tx * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barPos->setValue(ui->barPos->minimum() +
|
||||
qRound((double)(tx * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
}
|
||||
|
||||
@@ -205,9 +209,9 @@ void TouchSlider::on_barNeg_mousePressEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx =
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
e->x();
|
||||
e->x();
|
||||
#else
|
||||
e->position().toPoint().x();
|
||||
e->position().toPoint().x();
|
||||
#endif
|
||||
ui->barNeg->setValue(ui->barNeg->maximum() - qRound((double)(tx * ui->barNeg->maximum()) / (double)(ui->barNeg->width())));
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
@@ -226,19 +230,17 @@ void TouchSlider::on_barPos_valueChanged(int) {
|
||||
|
||||
void TouchSlider::setReadOnly(bool arg) {
|
||||
QBoxLayout * bl = qobject_cast<QBoxLayout *>(layout());
|
||||
m_readOnly = arg;
|
||||
m_readOnly = arg;
|
||||
if (arg) {
|
||||
ui->pbDec->hide();
|
||||
ui->pbInc->hide();
|
||||
if (hasZero)
|
||||
ui->pbZero->hide();
|
||||
if (hasZero) ui->pbZero->hide();
|
||||
bl->setStretchFactor(ui->pbMin, 2);
|
||||
bl->setStretchFactor(ui->pbMax, 2);
|
||||
} else {
|
||||
ui->pbDec->show();
|
||||
ui->pbInc->show();
|
||||
if (hasZero)
|
||||
ui->pbZero->show();
|
||||
if (hasZero) ui->pbZero->show();
|
||||
bl->setStretchFactor(ui->pbMin, 1);
|
||||
bl->setStretchFactor(ui->pbMax, 1);
|
||||
}
|
||||
@@ -247,7 +249,7 @@ void TouchSlider::setReadOnly(bool arg) {
|
||||
|
||||
void TouchSlider::setShowMinMax(bool arg) {
|
||||
QBoxLayout * bl = qobject_cast<QBoxLayout *>(layout());
|
||||
m_showMinMax = arg;
|
||||
m_showMinMax = arg;
|
||||
if (arg) {
|
||||
ui->pbMin->show();
|
||||
ui->pbMax->show();
|
||||
@@ -266,19 +268,17 @@ void TouchSlider::setShowMinMax(bool arg) {
|
||||
|
||||
void TouchSlider::setShowIncDec(bool arg) {
|
||||
QBoxLayout * bl = qobject_cast<QBoxLayout *>(layout());
|
||||
m_showIncDec = arg;
|
||||
m_showIncDec = arg;
|
||||
if (arg) {
|
||||
ui->pbDec->show();
|
||||
ui->pbInc->show();
|
||||
if (hasZero)
|
||||
ui->pbZero->show();
|
||||
if (hasZero) ui->pbZero->show();
|
||||
bl->setStretchFactor(ui->pbMin, 2);
|
||||
bl->setStretchFactor(ui->pbMax, 2);
|
||||
} else {
|
||||
ui->pbDec->hide();
|
||||
ui->pbInc->hide();
|
||||
if (hasZero)
|
||||
ui->pbZero->hide();
|
||||
if (hasZero) ui->pbZero->hide();
|
||||
bl->setStretchFactor(ui->pbMin, 1);
|
||||
bl->setStretchFactor(ui->pbMax, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user