SpinSlider and ScrollSpinBox read-only support

PIVariantEdit - support for read-only for all types
PIValueTreeEdit - drop Parent grouping, default now Groups, full grouping control, global read-only support, fix new label error
This commit is contained in:
2023-04-28 19:51:22 +03:00
parent e7ef97dc6a
commit 46fd68a0fd
13 changed files with 102 additions and 27 deletions

View File

@@ -54,6 +54,12 @@ double ScrollSpinBox::value() const {
}
void ScrollSpinBox::setReadOnly(bool r) {
m_read_only = r;
ui->spin->setReadOnly(r);
}
void ScrollSpinBox::changeEvent(QEvent * e) {
QWidget::changeEvent(e);
switch (e->type()) {
@@ -84,7 +90,7 @@ bool ScrollSpinBox::eventFilter(QObject * o, QEvent * e) {
void ScrollSpinBox::mousePress(QMouseEvent * e) {
if (canceled || !isEnabled()) return;
if (canceled || !isEnabled() || m_read_only) return;
if (e->button() == Qt::RightButton) {
canceled = true;
ui->spin->setExpression(last_text);
@@ -99,13 +105,13 @@ void ScrollSpinBox::mousePress(QMouseEvent * e) {
void ScrollSpinBox::mouseRelease(QMouseEvent * e) {
if (!isEnabled()) return;
if (!isEnabled() || m_read_only) return;
if (e->buttons() == Qt::NoButton) canceled = false;
}
void ScrollSpinBox::mouseMove(QMouseEvent * e) {
if (canceled || !isEnabled()) return;
if (canceled || !isEnabled() || m_read_only) return;
if (e->buttons().testFlag(Qt::LeftButton)) {
double dv = (down_pos.y() - e->pos().y()) * scroll_scale;
if (dv != 0.) {

View File

@@ -49,6 +49,9 @@ public:
int minimum() const { return m_minimum; }
int maximum() const { return m_maximum; }
void setReadOnly(bool r);
bool isReadOnly() const { return m_read_only; }
protected:
void changeEvent(QEvent * e);
void resizeEvent(QResizeEvent * e);
@@ -62,7 +65,7 @@ protected:
QString last_text;
double last_value, scroll_scale, sensivity_;
double m_minimum, m_maximum;
bool canceled;
bool canceled, m_read_only = false;
public slots:
void setSensivity(double s) { sensivity_ = s; }

View File

@@ -50,6 +50,13 @@ bool SpinSlider::adaptiveStep() const {
}
void SpinSlider::setReadOnly(bool r) {
m_read_only = r;
spin->setReadOnly(r);
slider->setEnabled(!r);
}
void SpinSlider::setAdaptiveStep(bool on) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
if (on)

View File

@@ -77,6 +77,9 @@ public:
bool invertedAppearance() const { return slider->invertedAppearance(); }
bool squareScale() const { return square; }
void setReadOnly(bool r);
bool isReadOnly() const { return m_read_only; }
void setSingleStep(double step) {
spin->setSingleStep(step);
slider->setPageStep(qRound(step * delim));
@@ -134,7 +137,7 @@ private:
double min_, max_, val_, delim, page;
int dec_, ticks_;
bool adjusting, square;
bool adjusting, square, m_read_only = false;
QSlider * slider;
QDoubleSpinBox * spin;
QBoxLayout * layout;