File indexing completed on 2025-01-19 03:59:37

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-01-20
0007  * Description : User interface for searches
0008  *
0009  * SPDX-FileCopyrightText: 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_SEARCH_FIELDS_H
0017 #define DIGIKAM_SEARCH_FIELDS_H
0018 
0019 // Qt includes
0020 
0021 #include <QObject>
0022 #include <QWidget>
0023 #include <QMap>
0024 
0025 // Local includes
0026 
0027 #include "coredbsearchxml.h"
0028 #include "searchutilities.h"
0029 #include "visibilitycontroller.h"
0030 
0031 class QLabel;
0032 class QCheckBox;
0033 class QGridLayout;
0034 class QSpinBox;
0035 class QDoubleSpinBox;
0036 class QTimeEdit;
0037 class QTreeView;
0038 class QComboBox;
0039 class QLineEdit;
0040 
0041 namespace Digikam
0042 {
0043 
0044 class DAdjustableLabel;
0045 class AbstractAlbumTreeViewSelectComboBox;
0046 class SearchFieldGroup;
0047 class SqueezedComboBox;
0048 class DDateEdit;
0049 class ChoiceSearchModel;
0050 class ChoiceSearchComboBox;
0051 class RatingComboBox;
0052 class PickLabelFilter;
0053 class ColorLabelFilter;
0054 
0055 class SearchField : public QObject,
0056                     public VisibilityObject
0057 {
0058     Q_OBJECT
0059 
0060 public:
0061 
0062     enum WidgetRectType
0063     {
0064         LabelAndValueWidgetRects,
0065         ValueWidgetRectsOnly
0066     };
0067 
0068 public:
0069 
0070     static SearchField* createField(const QString& fieldName, SearchFieldGroup* const parent);
0071 
0072     explicit SearchField(QObject* const parent);
0073 
0074     void setup(QGridLayout* const layout, int row = -1);
0075     void setFieldName(const QString& fieldName);
0076     void setCategoryLabelVisible(bool visible);
0077     void setCategoryLabelVisibleFromPreviousField(SearchField* const previousField);
0078 
0079     QList<QRect> widgetRects(WidgetRectType = ValueWidgetRectsOnly) const;
0080 
0081     virtual void setText(const QString& label, const QString& detailLabel);
0082 
0083     virtual bool supportsField(const QString& fieldName);
0084     virtual void read(SearchXmlCachingReader& reader) = 0;
0085     virtual void write(SearchXmlWriter& writer)       = 0;
0086     virtual void reset()                              = 0;
0087 
0088     void setVisible(bool visible) override;
0089     bool isVisible()              override;
0090 
0091 Q_SIGNALS:
0092 
0093     void signalVisibilityChanged();
0094 
0095 protected Q_SLOTS:
0096 
0097     void clearButtonClicked();
0098 
0099 protected:
0100 
0101     void setValidValueState(bool valueIsValid);
0102 
0103     virtual void setupValueWidgets(QGridLayout* layout, int row, int column) = 0;
0104     virtual void setupLabels(QGridLayout* layout, int line);
0105 
0106     virtual void setValueWidgetsVisible(bool visible)                        = 0;
0107     virtual QList<QRect> valueWidgetRects()                            const = 0;
0108 
0109 protected:
0110 
0111     QString              m_name;
0112 
0113     QLabel*              m_label;
0114     QLabel*              m_detailLabel;
0115 
0116     AnimatedClearButton* m_clearButton;
0117 
0118     bool                 m_categoryLabelVisible;
0119     bool                 m_valueIsValid;
0120 
0121 private:
0122 
0123     // Disable
0124     SearchField(const SearchField&)            = delete;
0125     SearchField& operator=(const SearchField&) = delete;
0126 };
0127 
0128 //-----------------------------------------------------------------------------
0129 
0130 class SearchFieldText : public SearchField
0131 {
0132     Q_OBJECT
0133 
0134 public:
0135 
0136     explicit SearchFieldText(QObject* const parent);
0137 
0138     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0139     void read(SearchXmlCachingReader& reader) override;
0140     void write(SearchXmlWriter& writer) override;
0141     void setValueWidgetsVisible(bool visible) override;
0142     void reset() override;
0143     QList<QRect> valueWidgetRects() const override;
0144 
0145 protected Q_SLOTS:
0146 
0147     void valueChanged(const QString& text);
0148 
0149 protected:
0150 
0151     QLineEdit* m_edit;
0152 };
0153 
0154 //-----------------------------------------------------------------------------
0155 
0156 class SearchFieldKeyword : public SearchFieldText
0157 {
0158     Q_OBJECT
0159 
0160 public:
0161 
0162     explicit SearchFieldKeyword(QObject* const parent);
0163 
0164     void read(SearchXmlCachingReader& reader) override;
0165     void write(SearchXmlWriter& writer)       override;
0166 };
0167 
0168 //-----------------------------------------------------------------------------
0169 
0170 class SearchFieldRangeInt : public SearchField
0171 {
0172     Q_OBJECT
0173 
0174 public:
0175 
0176     explicit SearchFieldRangeInt(QObject* const parent);
0177 
0178     void setBetweenText(const QString& text);
0179     void setNoValueText(const QString& text);
0180     void setNumberPrefixAndSuffix(const QString& prefix, const QString& suffix);
0181     void setBoundary(int min, int max, int step = 1);
0182     void enableFractionMagic(const QString& prefix);
0183 
0184     void setSuggestedValues(const QList<int>& values);
0185     void setSuggestedInitialValue(int initialValue);
0186     void setSingleSteps(int smaller, int larger);
0187     void setInvertStepping(bool invert);
0188 
0189     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0190     void read(SearchXmlCachingReader& reader) override;
0191     void write(SearchXmlWriter& writer) override;
0192     void reset() override;
0193     void setValueWidgetsVisible(bool visible) override;
0194     QList<QRect> valueWidgetRects() const override;
0195 
0196 protected Q_SLOTS:
0197 
0198     void valueChanged();
0199 
0200 protected:
0201 
0202     int                    m_min;
0203     int                    m_max;
0204     bool                   m_reciprocal;
0205     CustomStepsIntSpinBox* m_firstBox;
0206     CustomStepsIntSpinBox* m_secondBox;
0207     QLabel*                m_betweenLabel;
0208 
0209 private:
0210 
0211     // Disable
0212     SearchFieldRangeInt(const SearchFieldRangeInt&)            = delete;
0213     SearchFieldRangeInt& operator=(const SearchFieldRangeInt&) = delete;
0214 };
0215 
0216 //-----------------------------------------------------------------------------
0217 
0218 class SearchFieldRangeDouble : public SearchField
0219 {
0220     Q_OBJECT
0221 
0222 public:
0223 
0224     explicit SearchFieldRangeDouble(QObject* const parent);
0225 
0226     void setBetweenText(const QString& text);
0227     void setNoValueText(const QString& text);
0228     void setNumberPrefixAndSuffix(const QString& prefix, const QString& suffix);
0229     void setBoundary(double min, double max, int decimals, double step);
0230     void setFactor(double factor);
0231 
0232     void setSuggestedValues(const QList<double>& values);
0233     void setSuggestedInitialValue(double initialValue);
0234     void setSingleSteps(double smaller, double larger);
0235     void setInvertStepping(bool invert);
0236 
0237     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0238     void read(SearchXmlCachingReader& reader) override;
0239     void write(SearchXmlWriter& writer) override;
0240     void reset() override;
0241     void setValueWidgetsVisible(bool visible) override;
0242     QList<QRect> valueWidgetRects() const override;
0243 
0244 protected Q_SLOTS:
0245 
0246     void valueChanged();
0247 
0248 protected:
0249 
0250     double                    m_min;
0251     double                    m_max;
0252     double                    m_factor;
0253     CustomStepsDoubleSpinBox* m_firstBox;
0254     CustomStepsDoubleSpinBox* m_secondBox;
0255     QLabel*                   m_betweenLabel;
0256 
0257 private:
0258 
0259     // Disable
0260     SearchFieldRangeDouble(const SearchFieldRangeDouble&)            = delete;
0261     SearchFieldRangeDouble& operator=(const SearchFieldRangeDouble&) = delete;
0262 };
0263 
0264 //-----------------------------------------------------------------------------
0265 
0266 class SearchFieldRangeDate : public SearchField
0267 {
0268     Q_OBJECT
0269 
0270 public:
0271 
0272     enum Type
0273     {
0274         DateOnly,
0275         DateTime
0276     };
0277 
0278 public:
0279 
0280     SearchFieldRangeDate(QObject* const parent, Type type);
0281 
0282     void setBetweenText(const QString& between);
0283     void setBoundary(const QDateTime& min, const QDateTime& max);
0284 
0285     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0286     void read(SearchXmlCachingReader& reader) override;
0287     void write(SearchXmlWriter& writer) override;
0288     void reset() override;
0289     void setValueWidgetsVisible(bool visible) override;
0290     QList<QRect> valueWidgetRects() const override;
0291 
0292 protected Q_SLOTS:
0293 
0294     void valueChanged();
0295 
0296 protected:
0297 
0298     QTimeEdit* m_firstTimeEdit;
0299     DDateEdit* m_firstDateEdit;
0300     QTimeEdit* m_secondTimeEdit;
0301     DDateEdit* m_secondDateEdit;
0302     QLabel*    m_betweenLabel;
0303 
0304     Type       m_type;
0305 
0306 private:
0307 
0308     // Disable
0309     SearchFieldRangeDate(const SearchFieldRangeDate&)            = delete;
0310     SearchFieldRangeDate& operator=(const SearchFieldRangeDate&) = delete;
0311 };
0312 
0313 //-----------------------------------------------------------------------------
0314 
0315 class SearchFieldRangeTime : public SearchField
0316 {
0317     Q_OBJECT
0318 
0319 public:
0320 
0321     explicit SearchFieldRangeTime(QObject* const parent);
0322 
0323     void setBetweenText(const QString& between);
0324     void setBoundary(const QTime& min, const QTime& max);
0325 
0326     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0327     void read(SearchXmlCachingReader& reader) override;
0328     void write(SearchXmlWriter& writer) override;
0329     void reset() override;
0330     void setValueWidgetsVisible(bool visible) override;
0331     QList<QRect> valueWidgetRects() const override;
0332 
0333 protected Q_SLOTS:
0334 
0335     void valueChanged();
0336 
0337 protected:
0338 
0339     QTimeEdit* m_firstTimeEdit;
0340     QTimeEdit* m_secondTimeEdit;
0341     QLabel*    m_betweenLabel;
0342 
0343 private:
0344 
0345     // Disable
0346     SearchFieldRangeTime(const SearchFieldRangeTime&)            = delete;
0347     SearchFieldRangeTime& operator=(const SearchFieldRangeTime&) = delete;
0348 };
0349 
0350 //-----------------------------------------------------------------------------
0351 
0352 class SearchFieldChoice : public SearchField
0353 {
0354     Q_OBJECT
0355 
0356 public:
0357 
0358     explicit SearchFieldChoice(QObject* const parent);
0359 
0360     void setChoice(const QMap<int, QString>& map);
0361     void setChoice(const QStringList& choice);
0362     void setAnyText(const QString& anyText);
0363 
0364     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0365     void read(SearchXmlCachingReader& reader) override;
0366     void write(SearchXmlWriter& writer) override;
0367     void reset() override;
0368     void setValueWidgetsVisible(bool visible) override;
0369     QList<QRect> valueWidgetRects() const override;
0370 
0371 protected Q_SLOTS:
0372 
0373     void checkStateChanged();
0374 
0375 protected:
0376 
0377     void updateComboText();
0378 
0379 protected:
0380 
0381     ChoiceSearchComboBox* m_comboBox;
0382 
0383 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0384 
0385     QMetaType::Type       m_type;
0386 
0387 #else
0388 
0389     QVariant::Type        m_type;
0390 
0391 #endif
0392 
0393     QString               m_anyText;
0394     ChoiceSearchModel*    m_model;
0395 
0396 private:
0397 
0398     // Disable
0399     SearchFieldChoice(const SearchFieldChoice&)            = delete;
0400     SearchFieldChoice& operator=(const SearchFieldChoice&) = delete;
0401 };
0402 
0403 //-----------------------------------------------------------------------------
0404 
0405 class Album;
0406 class AbstractCheckableAlbumModel;
0407 class AbstractAlbumTreeViewSelectComboBox;
0408 class AlbumTreeViewSelectComboBox;
0409 class TagTreeViewSelectComboBox;
0410 class SqueezedComboBox;
0411 
0412 class SearchFieldAlbum : public SearchField
0413 {
0414     Q_OBJECT
0415 
0416 public:
0417 
0418     enum Type
0419     {
0420         TypeAlbum,
0421         TypeTag
0422     };
0423 
0424     enum Operation
0425     {
0426         All,
0427         OneOf,
0428         InTree
0429     };
0430 
0431 public:
0432 
0433     SearchFieldAlbum(QObject* const parent, Type type);
0434 
0435     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0436     void read(SearchXmlCachingReader& reader) override;
0437     void write(SearchXmlWriter& writer) override;
0438     void reset() override;
0439     void setValueWidgetsVisible(bool visible) override;
0440     QList<QRect> valueWidgetRects() const override;
0441 
0442 protected Q_SLOTS:
0443 
0444     void updateState();
0445 
0446 protected:
0447 
0448     QWidget*                             m_wrapperBox;
0449     AlbumTreeViewSelectComboBox*         m_albumComboBox;
0450     TagTreeViewSelectComboBox*           m_tagComboBox;
0451     SqueezedComboBox*                    m_operation;
0452     Type                                 m_type;
0453     AbstractCheckableAlbumModel*         m_model;
0454 };
0455 
0456 //-----------------------------------------------------------------------------
0457 
0458 class SearchFieldRating : public SearchField
0459 {
0460     Q_OBJECT
0461 
0462 public:
0463 
0464     explicit SearchFieldRating(QObject* const parent);
0465 
0466     void setBetweenText(const QString& text);
0467 
0468     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0469     void read(SearchXmlCachingReader& reader) override;
0470     void write(SearchXmlWriter& writer) override;
0471     void reset() override;
0472     void setValueWidgetsVisible(bool visible) override;
0473     QList<QRect> valueWidgetRects() const override;
0474 
0475 protected Q_SLOTS:
0476 
0477     void firstValueChanged();
0478     void secondValueChanged();
0479 
0480 protected:
0481 
0482     RatingComboBox* m_firstBox;
0483     RatingComboBox* m_secondBox;
0484     QLabel*         m_betweenLabel;
0485 
0486 private:
0487 
0488     // Disable
0489     SearchFieldRating(const SearchFieldRating&)            = delete;
0490     SearchFieldRating& operator=(const SearchFieldRating&) = delete;
0491 };
0492 
0493 //-----------------------------------------------------------------------------
0494 
0495 class SearchFieldComboBox : public SearchField
0496 {
0497     Q_OBJECT
0498 
0499 public:
0500 
0501     explicit SearchFieldComboBox(QObject* const  parent);
0502 
0503     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0504     void write(SearchXmlWriter& writer) override;
0505     void reset() override;
0506     void setValueWidgetsVisible(bool visible) override;
0507     QList<QRect> valueWidgetRects() const override;
0508 
0509 protected Q_SLOTS:
0510 
0511     void indexChanged(int);
0512 
0513 protected:
0514 
0515     QComboBox* m_comboBox;
0516 };
0517 
0518 //-----------------------------------------------------------------------------
0519 
0520 class SearchFieldCheckBox : public SearchField
0521 {
0522     Q_OBJECT
0523 
0524 public:
0525 
0526     explicit SearchFieldCheckBox(QObject* const parent);
0527 
0528     void setLabel(const QString& text);
0529 
0530     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0531     void read(SearchXmlCachingReader& reader) override;
0532     void write(SearchXmlWriter& writer) override;
0533     void reset() override;
0534     void setValueWidgetsVisible(bool visible) override;
0535     QList<QRect> valueWidgetRects() const override;
0536 
0537 protected Q_SLOTS:
0538 
0539     void slotToggled(bool checked);
0540 
0541 protected:
0542 
0543     QCheckBox* m_checkBox;
0544     QString    m_text;
0545 };
0546 
0547 //-----------------------------------------------------------------------------
0548 
0549 class SearchFieldColorDepth : public SearchFieldComboBox
0550 {
0551     Q_OBJECT
0552 
0553 public:
0554 
0555     explicit SearchFieldColorDepth(QObject* const parent);
0556 
0557     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0558     void read(SearchXmlCachingReader& reader) override;
0559 };
0560 
0561 //-----------------------------------------------------------------------------
0562 
0563 class SearchFieldPageOrientation: public SearchFieldComboBox
0564 {
0565     Q_OBJECT
0566 
0567 public:
0568 
0569     explicit SearchFieldPageOrientation(QObject* const parent);
0570 
0571     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0572     void read(SearchXmlCachingReader& reader) override;
0573 };
0574 
0575 //-----------------------------------------------------------------------------
0576 
0577 class SearchFieldLabels : public SearchField
0578 {
0579     Q_OBJECT
0580 
0581 public:
0582 
0583     explicit SearchFieldLabels(QObject* const parent);
0584 
0585     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0586     void read(SearchXmlCachingReader& reader) override;
0587     void write(SearchXmlWriter& writer) override;
0588     void reset() override;
0589     void setValueWidgetsVisible(bool visible) override;
0590     QList<QRect> valueWidgetRects() const override;
0591 
0592 protected Q_SLOTS:
0593 
0594     void updateState();
0595 
0596 protected:
0597 
0598     PickLabelFilter*  m_pickLabelFilter;
0599     ColorLabelFilter* m_colorLabelFilter;
0600 };
0601 
0602 //-----------------------------------------------------------------------------
0603 
0604 class SearchFieldMonthDay : public SearchField
0605 {
0606     Q_OBJECT
0607 
0608 public:
0609 
0610     explicit SearchFieldMonthDay(QObject* const parent);
0611 
0612     void setupValueWidgets(QGridLayout* layout, int row, int column) override;
0613     void read(SearchXmlCachingReader& reader) override;
0614     void write(SearchXmlWriter& writer) override;
0615     void reset() override;
0616     void setValueWidgetsVisible(bool visible) override;
0617     QList<QRect> valueWidgetRects() const override;
0618 
0619 protected Q_SLOTS:
0620 
0621     void slotIndexChanged();
0622 
0623 protected:
0624 
0625     QLabel*    m_dayLabel;
0626     QComboBox* m_monthBox;
0627     QComboBox* m_dayBox;
0628 };
0629 
0630 } // namespace Digikam
0631 
0632 #endif // DIGIKAM_SEARCH_FIELDS_H