v1.0.0-rc.38
This commit is contained in:
52
viewer/widgets/NumericComboBox.cpp
Normal file
52
viewer/widgets/NumericComboBox.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "NumericComboBox.h"
|
||||
|
||||
NumericComboBox::NumericComboBox(std::vector<int> options, int min, int max, QWidget *parent) {
|
||||
setEditable(true);
|
||||
|
||||
for (const auto &i: options)
|
||||
addItem(QString::number(i));
|
||||
|
||||
validator = new QIntValidator(this);
|
||||
validator->setBottom(min);
|
||||
validator->setTop(max);
|
||||
setValidator(validator);
|
||||
|
||||
setCurrentText(QString::number(min));
|
||||
|
||||
setStyleSheet("background-color: rgb(255, 255, 255);");
|
||||
|
||||
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &NumericComboBox::onCurrentIndexChanged);
|
||||
connect(this, &QComboBox::editTextChanged,
|
||||
this, &NumericComboBox::onEditTextChanged);
|
||||
|
||||
}
|
||||
|
||||
int NumericComboBox::getValue() const {
|
||||
return currentText().toInt();
|
||||
}
|
||||
|
||||
void NumericComboBox::setValue(int value) {
|
||||
setCurrentText(QString::number(value));
|
||||
}
|
||||
|
||||
void NumericComboBox::onCurrentIndexChanged(int index) {
|
||||
if (index >= 0) {
|
||||
setStyleSheet("background-color: rgb(255, 255, 255);");
|
||||
emit valueChanged(getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void NumericComboBox::onEditTextChanged(const QString &text) {
|
||||
bool ok;
|
||||
int value = text.toInt(&ok);
|
||||
if (ok) {
|
||||
setStyleSheet("background-color: rgb(255, 255, 255);");
|
||||
emit valueChanged(value);
|
||||
} else {
|
||||
setStyleSheet("background-color: rgb(125, 0, 0);");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user