1 /***************************************************************************** 2 * Copyright (C) 2004-2018 by Thomas Fischer <fischer@unix-ag.uni-kl.de> * 3 * * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 17 *****************************************************************************/ 18 19 #ifndef KBIBTEX_GUI_RANGEWIDGET_H 20 #define KBIBTEX_GUI_RANGEWIDGET_H 21 22 #include "kbibtexgui_export.h" 23 24 #include <QWidget> 25 26 /** 27 * Allows the user to specify a minimum and a maximum out of a range of values. 28 * Values are provided as a QStringList for visualization in two QComboBox lists 29 * (one of minimum, one for maximum). Programmatically, the range of values 30 * goes from 0 to QStringList's size - 1. The two QComboBox's values shown to 31 * the user are interlinked, so that for the 'minimum' QComboBox no values above 32 * the 'maximum' QComboBox's current value are available; vice versa, the 33 * 'maximum' QComboBox shows no values below the 'minimum' QComboBox's current 34 * value. 35 * 36 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 37 */ 38 class KBIBTEXGUI_EXPORT RangeWidget : public QWidget 39 { 40 Q_OBJECT 41 42 Q_PROPERTY(int lowerValue READ lowerValue WRITE setLowerValue NOTIFY lowerValueChanged) 43 Q_PROPERTY(int upperValue READ upperValue WRITE setUpperValue NOTIFY upperValueChanged) 44 45 public: 46 /** 47 * @brief RangeWidget 48 * @param values List of alternatives shown in the QComboBoxes 49 * @param parent QWidget's parent 50 */ 51 explicit RangeWidget(const QStringList &values, QWidget *parent = nullptr); 52 ~RangeWidget(); 53 54 /** 55 * Returns the maximum value of this RangeWidget. 56 * Will always be the last index of the QStringList passed at construction, 57 * i.e. QStringList's size - 1 58 * @return maximum range value 59 */ 60 int maximum() const; 61 62 /** 63 * Sets the lower value. The value will be normalized to fit the following 64 * criteria: (1) at least as large as the minimum value (=0), (2) at most 65 * as large as the maximum value, (3) not larger than the upper value. 66 * @param newLowerValue new lower value of the range 67 */ 68 void setLowerValue(int newLowerValue); 69 70 /** 71 * Returns the current lower value 72 * @return lower value of the range 73 */ 74 int lowerValue() const; 75 76 /** 77 * Sets the upper value. The value will be normalized to fit the following 78 * criteria: (1) at least as large as the minimum value (=0), (2) at most 79 * as large as the maximum value, (3) not smaller than the lower value. 80 * @param newUpperValue new upper value of the range 81 */ 82 void setUpperValue(int newUpperValue); 83 84 /** 85 * Returns the current upper value 86 * @return upper value of the range 87 */ 88 int upperValue() const; 89 90 signals: 91 /** 92 * Signal notifying about the change of the lower value. This signal 93 * will not be triggered if the value is set to the same value it 94 * already has. 95 */ 96 void lowerValueChanged(int); 97 98 /** 99 * Signal notifying about the change of the upper value. This signal 100 * will not be triggered if the value is set to the same value it 101 * already has. 102 */ 103 void upperValueChanged(int); 104 105 private slots: 106 void lowerComboBoxChanged(int); 107 void upperComboBoxChanged(int); 108 109 private: 110 class Private; 111 Private *const d; 112 }; 113 114 #endif // KBIBTEX_GUI_RANGEWIDGET_H 115