File indexing completed on 2025-04-27 03:58:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2017-08-09 0007 * Description : Generic range boxes, i.e. ranges where a minimum and maximum can be given. 0008 * 0009 * SPDX-FileCopyrightText: 2017 by Mario Frank <mario dot frank at uni minus potsdam dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "drangebox.h" 0016 0017 // Qt includes 0018 0019 #include <QSpinBox> 0020 #include <QLabel> 0021 #include <QHBoxLayout> 0022 0023 namespace Digikam 0024 { 0025 0026 class Q_DECL_HIDDEN DIntRangeBox::Private 0027 { 0028 0029 public: 0030 0031 explicit Private() 0032 : intervalLabel(nullptr), 0033 minValueBox(nullptr), 0034 maxValueBox(nullptr) 0035 { 0036 } 0037 0038 QLabel* intervalLabel; 0039 QSpinBox* minValueBox; 0040 QSpinBox* maxValueBox; 0041 }; 0042 0043 DIntRangeBox::DIntRangeBox(QWidget* const parent) 0044 : QWidget(parent), 0045 d(new Private) 0046 { 0047 d->minValueBox = new QSpinBox(this); 0048 d->minValueBox->setRange(0, 100); 0049 d->minValueBox->setValue(0); 0050 d->minValueBox->setSingleStep(1); 0051 0052 d->intervalLabel = new QLabel(QLatin1String("-"), this); 0053 d->intervalLabel->setAlignment(Qt::AlignCenter); 0054 0055 d->maxValueBox = new QSpinBox(this); 0056 d->maxValueBox->setRange(d->minValueBox->value(), 100); 0057 d->maxValueBox->setValue(100); 0058 d->maxValueBox->setSingleStep(1); 0059 /* 0060 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0061 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0062 */ 0063 QHBoxLayout* const mainLayout = new QHBoxLayout(this); 0064 mainLayout->addWidget(d->minValueBox); 0065 mainLayout->addWidget(d->intervalLabel); 0066 mainLayout->addWidget(d->maxValueBox); 0067 /* 0068 mainLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0069 */ 0070 mainLayout->setContentsMargins(QMargins()); 0071 setLayout(mainLayout); 0072 0073 connect(d->minValueBox, SIGNAL(valueChanged(int)), 0074 this, SLOT(slotMinimumChanged(int))); 0075 0076 connect(d->minValueBox, SIGNAL(valueChanged(int)), 0077 this, SIGNAL(minChanged(int))); 0078 0079 connect(d->maxValueBox, SIGNAL(valueChanged(int)), 0080 this, SIGNAL(maxChanged(int))); 0081 } 0082 0083 DIntRangeBox::~DIntRangeBox() 0084 { 0085 delete d; 0086 } 0087 0088 void DIntRangeBox::setRange(int min, int max) 0089 { 0090 if (min <= max) 0091 { 0092 d->minValueBox->setMinimum(min); 0093 d->maxValueBox->setMaximum(max); 0094 } 0095 } 0096 0097 void DIntRangeBox::setInterval(int min, int max) 0098 { 0099 if (min <= max) 0100 { 0101 d->minValueBox->setValue(min); 0102 d->maxValueBox->setValue(max); 0103 } 0104 } 0105 0106 void DIntRangeBox::setSuffix(const QString& suffix) 0107 { 0108 d->minValueBox->setSuffix(suffix); 0109 d->maxValueBox->setSuffix(suffix); 0110 } 0111 0112 void DIntRangeBox::setEnabled(bool enabled) 0113 { 0114 d->intervalLabel->setEnabled(enabled); 0115 d->minValueBox->setEnabled(enabled); 0116 d->maxValueBox->setEnabled(enabled); 0117 } 0118 0119 int DIntRangeBox::minValue() 0120 { 0121 return d->minValueBox->value(); 0122 } 0123 0124 int DIntRangeBox::maxValue() 0125 { 0126 return d->maxValueBox->value(); 0127 } 0128 0129 void DIntRangeBox::slotMinimumChanged(int newValue) 0130 { 0131 // Set the new minimum value of the maximum similarity 0132 0133 d->maxValueBox->setMinimum(newValue); 0134 0135 // If the new value of the minimum is now higher than the maximum similarity, 0136 // set the maximum similarity to the new value. 0137 0138 if (newValue > d->maxValueBox->value()) 0139 { 0140 d->maxValueBox->setValue(d->minValueBox->value()); 0141 } 0142 } 0143 0144 } // namespace Digikam 0145 0146 #include "moc_drangebox.cpp"