File indexing completed on 2024-04-28 15:39:47

0001 // SPDX-FileCopyrightText: 2003-2022 The KPhotoAlbum Development Team
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #ifndef LISTSELECT_H
0006 #define LISTSELECT_H
0007 
0008 #include <DB/CategoryPtr.h>
0009 #include <kpabase/SettingsData.h>
0010 #include <kpabase/enums.h>
0011 
0012 #include <QLabel>
0013 #include <QList>
0014 
0015 class QTreeWidgetItem;
0016 class QToolButton;
0017 class QEvent;
0018 class QRadioButton;
0019 class QLabel;
0020 
0021 namespace DB
0022 {
0023 class CategoryItem;
0024 class ImageInfo;
0025 }
0026 namespace CategoryListView
0027 {
0028 class DragableTreeWidget;
0029 }
0030 namespace CategoryListView
0031 {
0032 class CheckDropItem;
0033 }
0034 
0035 namespace AnnotationDialog
0036 {
0037 
0038 using Utilities::StringSet;
0039 
0040 class CompletableLineEdit;
0041 
0042 class ListSelect : public QWidget
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     ListSelect(const DB::CategoryPtr &category, QWidget *parent);
0048     QString category() const;
0049     QString text() const;
0050     void setText(const QString &);
0051     void setSelection(const StringSet &on, const StringSet &partiallyOn = StringSet());
0052     StringSet itemsOn() const;
0053     StringSet itemsOff() const;
0054     StringSet itemsUnchanged() const;
0055 
0056     bool isAND() const;
0057     /**
0058      * @brief setMode for a search dialog or for annotating images individually or by batch.
0059      * @param mode
0060      */
0061     void setMode(UsageMode mode);
0062 
0063     void populate();
0064 
0065     void showOnlyItemsMatching(const QString &text);
0066     QWidget *lineEdit() const;
0067     void setPositionable(bool positionableState);
0068     bool positionable() const;
0069     bool tagIsChecked(QString tag) const;
0070 
0071     void connectLineEdit(CompletableLineEdit *le);
0072 
0073     void deselectTag(QString tag);
0074 
0075 public Q_SLOTS:
0076     void slotReturn();
0077     void slotExternalReturn(const QString &text);
0078     void slotSortDate();
0079     void slotSortAlphaTree();
0080     void slotSortAlphaFlat();
0081     void toggleSortType();
0082     void updateListview();
0083     void rePopulate();
0084     void ensureTagIsSelected(QString category, QString tag);
0085 
0086 Q_SIGNALS:
0087     /**
0088      * This signal is emitted whenever a positionable tag is (de)selected.
0089      */
0090     void positionableTagSelected(const QString category, const QString tag);
0091     void positionableTagDeselected(const QString category, const QString tag);
0092     void positionableTagRenamed(const QString category, const QString oldTag, const QString newTag);
0093 
0094 protected Q_SLOTS:
0095     void itemSelected(QTreeWidgetItem *);
0096     void showContextMenu(const QPoint &);
0097     void setViewSortType(Settings::ViewSortType);
0098     void limitToSelection();
0099     void showAllChildren();
0100     void updateSelectionCount();
0101 
0102 protected:
0103     void addItems(DB::CategoryItem *item, QTreeWidgetItem *parent);
0104     void populateAlphaTree();
0105     void populateAlphaFlat();
0106     void populateMRU();
0107     void configureItem(CategoryListView::CheckDropItem *item);
0108     /**
0109      * @brief computedEditMode computes the edit mode taking into account the current UsageMode.
0110      * @return \c Selectable if mode is \c SearchMode, editMode otherwise.
0111      */
0112     ListSelectEditMode computedEditMode() const;
0113     StringSet itemsOfState(Qt::CheckState state) const;
0114     void checkItem(const QString itemText, bool);
0115     void ensureAllInstancesAreStateChanged(QTreeWidgetItem *item);
0116     /**
0117      * @brief setEditMode to control how the ListSelect handles input.
0118      * For normal categories, \c ListSelectEditMode::Editable is recommended.
0119      * Special categories should either be \c ReadOnly (folder, media type) or
0120      * \c Selectable (tokens category).
0121      * @param mode
0122      */
0123     void setEditMode(ListSelectEditMode mode);
0124 
0125 private: // Functions
0126     bool searchForUntaggedImagesTagNeeded();
0127     void hideUntaggedImagesTag();
0128     QTreeWidgetItem *getUntaggedImagesTag();
0129     /**
0130      * @brief updateLineEditMode sets the mode for the CompleteableLineEdit according to mode and editMode.
0131      */
0132     void updateLineEditMode();
0133 
0134 private: // Variables
0135     DB::CategoryPtr m_category;
0136     CompletableLineEdit *m_lineEdit;
0137     CategoryListView::DragableTreeWidget *m_treeWidget;
0138     QRadioButton *m_or;
0139     QRadioButton *m_and;
0140     UsageMode m_mode;
0141     ListSelectEditMode m_editMode = ListSelectEditMode::Editable;
0142     QLabel *m_roIndicator; ///< indicates computedEditMode() ReadOnly
0143     QLabel *m_selectableIndicator; ///< indicates computedEditMode() Selectable
0144     QToolButton *m_alphaTreeSort;
0145     QToolButton *m_alphaFlatSort;
0146     QToolButton *m_dateSort;
0147     QToolButton *m_showSelectedOnly;
0148     QString m_baseTitle;
0149     bool m_positionable;
0150 };
0151 }
0152 
0153 #endif /* LISTSELECT_H */
0154 
0155 // vi:expandtab:tabstop=4 shiftwidth=4: