File indexing completed on 2025-01-19 03:59:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-03-14 0007 * Description : User interface for searches 0008 * 0009 * SPDX-FileCopyrightText: 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_SEARCH_UTILITIES_H 0016 #define DIGIKAM_SEARCH_UTILITIES_H 0017 0018 // Qt includes 0019 0020 #include <QObject> 0021 #include <QWidget> 0022 #include <QLabel> 0023 #include <QLineEdit> 0024 #include <QString> 0025 #include <QComboBox> 0026 #include <QDoubleSpinBox> 0027 #include <QSpinBox> 0028 0029 // Local includes 0030 0031 #include "comboboxutilities.h" 0032 0033 class QTextEdit; 0034 class QPushButton; 0035 0036 namespace Digikam 0037 { 0038 0039 class AnimatedClearButton : public QWidget 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 0045 explicit AnimatedClearButton(QWidget* const parent = nullptr); 0046 0047 QSize sizeHint() const override; 0048 0049 void setPixmap(const QPixmap& p); 0050 QPixmap pixmap() const; 0051 0052 /** 0053 * Sets a primary condition for the button to be shown. 0054 * If false, animateVisible() will have no effect. 0055 */ 0056 void setShallBeShown(bool show); 0057 0058 /** This parameter determines the behavior when the animation 0059 * to hide the widget has finished: 0060 * If stayVisible is true, the widget remains visible, 0061 * but paints nothing. 0062 * If stayVisible is false, setVisible(false) is called, 0063 * which removes the widget for layouting etc. 0064 * Default: false 0065 */ 0066 void stayVisibleWhenAnimatedOut(bool stayVisible); 0067 0068 public Q_SLOTS: 0069 0070 /// Set visible, possibly with animation 0071 void animateVisible(bool visible); 0072 0073 /// Set visible without animation 0074 void setDirectlyVisible(bool visible); 0075 0076 Q_SIGNALS: 0077 0078 void clicked(); 0079 0080 protected: 0081 0082 void paintEvent(QPaintEvent* event) override; 0083 void mouseReleaseEvent(QMouseEvent* event) override; 0084 0085 protected Q_SLOTS: 0086 0087 void visibleChanged(); 0088 void updateAnimationSettings(); 0089 0090 private: 0091 0092 class Private; 0093 Private* const d; 0094 }; 0095 0096 // ------------------------------------------------------------------------- 0097 0098 class CustomStepsDoubleSpinBox : public QDoubleSpinBox 0099 { 0100 Q_OBJECT 0101 0102 public: 0103 0104 /** 0105 * This is a normal QDoubleSpinBox which allows to 0106 * customize the stepping behavior, for cases where 0107 * linear steps are not applicable 0108 */ 0109 explicit CustomStepsDoubleSpinBox(QWidget* const parent = nullptr); 0110 ~CustomStepsDoubleSpinBox() override; 0111 0112 /** 0113 * Set a list of values that are usually applicable for the 0114 * type of data of the combo box. The user can still type in 0115 * any other value. Boundaries are not touched. 0116 * Up or below the min and max values of the list given, 0117 * default stepping is used. 0118 */ 0119 void setSuggestedValues(const QList<double>& values); 0120 0121 /** 0122 * Sets the value that should be set as first value 0123 * when first moving away from the minimum value. 0124 */ 0125 void setSuggestedInitialValue(double initialValue); 0126 0127 /** 0128 * Allows to set to different default single steps, 0129 * for the range below m_values, the other for above. 0130 */ 0131 void setSingleSteps(double smaller, double larger); 0132 0133 void setInvertStepping(bool invert); 0134 0135 /** 0136 * Resets to minimum value. 0137 */ 0138 void reset(); 0139 0140 void stepBy(int steps) override; 0141 0142 private Q_SLOTS: 0143 0144 void slotValueChanged(double val); 0145 0146 private: 0147 0148 class Private; 0149 Private* const d; 0150 }; 0151 0152 // ------------------------------------------------------------------------- 0153 0154 class CustomStepsIntSpinBox : public QSpinBox 0155 { 0156 Q_OBJECT 0157 0158 public: 0159 0160 /** 0161 * This is a normal QIntSpinBox which allows to 0162 * customize the stepping behavior, for cases where 0163 * linear steps are not applicable 0164 */ 0165 explicit CustomStepsIntSpinBox(QWidget* const parent = nullptr); 0166 ~CustomStepsIntSpinBox() override; 0167 0168 /** 0169 * Set a list of values that are usually applicable for the 0170 * type of data of the combo box. The user can still type in 0171 * any other value. Boundaries are not touched. 0172 * Up or below the min and max values of the list given, 0173 * default stepping is used. 0174 */ 0175 void setSuggestedValues(const QList<int>& values); 0176 0177 /** 0178 * Sets the value that should be set as first value 0179 * when first moving away from the minimum value. 0180 */ 0181 void setSuggestedInitialValue(int initialValue); 0182 0183 /** 0184 * Allows to set to different default single steps, 0185 * for the range below m_values, the other for above. 0186 */ 0187 void setSingleSteps(int smaller, int larger); 0188 0189 void setInvertStepping(bool invert); 0190 0191 /** 0192 * Call this with a fraction prefix (like "1/") to enable 0193 * magic handling of the value as fraction denominator. 0194 */ 0195 void enableFractionMagic(const QString& prefix); 0196 0197 /** 0198 * Resets to minimum value 0199 */ 0200 void reset(); 0201 0202 /** 0203 * value() and setValue() for fraction magic value. 0204 */ 0205 double fractionMagicValue() const; 0206 void setFractionMagicValue(double value); 0207 0208 void stepBy(int steps) override; 0209 0210 protected: 0211 0212 QString textFromValue(int value) const override; 0213 int valueFromText(const QString& text) const override; 0214 StepEnabled stepEnabled() const override; 0215 0216 private Q_SLOTS: 0217 0218 void slotValueChanged(int val); 0219 0220 private: 0221 0222 class Private; 0223 Private* const d; 0224 }; 0225 0226 // ------------------------------------------------------------------------- 0227 0228 class StyleSheetDebugger : public QWidget 0229 { 0230 Q_OBJECT 0231 0232 public: 0233 0234 /** 0235 * This widget is for development purpose only: 0236 * It allows the developer to change the style sheet 0237 * on a widget dynamically. 0238 * If you want to develop or debug the stylesheet on your widget, 0239 * add temporary code: 0240 * new StyleSheetDebugger(myWidget); 0241 * That's all. Change the style sheet by editing it and pressing Ok. 0242 */ 0243 explicit StyleSheetDebugger(QWidget* const object); 0244 0245 protected Q_SLOTS: 0246 0247 void buttonClicked(); 0248 0249 protected: 0250 0251 QTextEdit* m_edit; 0252 QPushButton* m_okButton; 0253 QWidget* m_widget; 0254 }; 0255 0256 } // namespace Digikam 0257 0258 #endif // DIGIKAM_SEARCH_UTILITIES_H