File indexing completed on 2025-01-19 03:53:23

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-05-09
0007  * Description : A combo box for selecting albums
0008  *
0009  * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
0011  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_ALBUM_SELECT_COMBO_BOX_H
0018 #define DIGIKAM_ALBUM_SELECT_COMBO_BOX_H
0019 
0020 // Local includes
0021 
0022 #include "comboboxutilities.h"
0023 
0024 class QSortFilterProxyModel;
0025 
0026 namespace Digikam
0027 {
0028 
0029 class AlbumFilterModel;
0030 class AbstractCheckableAlbumModel;
0031 
0032 class AlbumSelectComboBox : public TreeViewLineEditComboBox
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037 
0038     explicit AlbumSelectComboBox(QWidget* const parent = nullptr);
0039     ~AlbumSelectComboBox()                              override;
0040 
0041     /**
0042      * Once after creation, call one of these three methods.
0043      * Use the first one if you want a standard combo box for PAlbums and
0044      *  the second one for tags, while the third allows you to provide
0045      *  custom source and filter models.
0046      *  The first two also set a default noSelectionText. Customize afterwards if required.
0047      */
0048     void setDefaultAlbumModel();
0049     void setDefaultTagModel();
0050     void setAlbumModels(AbstractCheckableAlbumModel* model,
0051                         AlbumFilterModel* filterModel = nullptr);
0052 
0053     /**
0054      * Enable checkboxes next to the items. Default: true
0055      */
0056     void setCheckable(bool checkable);
0057     bool isCheckable() const;
0058 
0059     /**
0060      * Enable closing when an item was activated (clicked). Default: false.
0061      */
0062     void setCloseOnActivate(bool close);
0063 
0064     /**
0065      * If the box is checkable, enable showing a resume a la "3 Albums checked"
0066      * in the combo box text. Default: True
0067      */
0068     void setShowCheckStateSummary(bool show);
0069 
0070     /**
0071      * If all subalbums shall be selected when parent will be selected
0072      */
0073     void setRecursive(bool recursive);
0074 
0075     /**
0076      * Sets the text that is used to describe the state when no album is selected.
0077      * This may be something like "Any album" or "No tag selected".
0078      * Depends on the default line edit implementation of TreeViewLineEditComboBox.
0079      */
0080     void setNoSelectionText(const QString& text);
0081 
0082     /**
0083      * Enable or disable the text used to describe the status when all album is selected.
0084      */
0085     void setAllSelectedText(bool all);
0086 
0087     /**
0088      * Returns the source model. Retrieve selection information from here.
0089      */
0090     AbstractCheckableAlbumModel* model() const;
0091 
0092     /**
0093      * Return the filter model in use.
0094      */
0095     QSortFilterProxyModel* filterModel() const;
0096 
0097 public Q_SLOTS:
0098 
0099     void hidePopup()                                    override;
0100 
0101     /**
0102      * Updates the text describing the selection ("3 Albums selected").
0103      * Can be overridden to customize the default text.
0104      */
0105     virtual void updateText();
0106 
0107 protected:
0108 
0109     void installView(QAbstractItemView* view = nullptr) override;
0110 
0111 private:
0112 
0113     class Private;
0114     Private* const d;
0115 };
0116 
0117 // ------------------------------------------------------------------------------------
0118 
0119 class AbstractAlbumTreeView;
0120 class AlbumModel;
0121 class AlbumTreeView;
0122 class CheckableAlbumFilterModel;
0123 class TagPropertiesFilterModel;
0124 class TagModel;
0125 class TagTreeView;
0126 
0127 class AbstractAlbumTreeViewSelectComboBox : public AlbumSelectComboBox
0128 {
0129     Q_OBJECT
0130 
0131 public:
0132 
0133     /**
0134      * Abstract class.
0135      * This is an AlbumSelectComboBox which installs an AlbumTreeView,
0136      * not a plain QTreeView, as view.
0137      */
0138 
0139     explicit AbstractAlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);
0140 
0141     /**
0142      * Set a tree view created by you instead of creating a default view
0143      * (in the subclasses).
0144      * Only takes effect before calling setModel.
0145      */
0146     void setTreeView(AbstractAlbumTreeView* const treeView);
0147 
0148     /**
0149      * Enables a context menu which contains options to
0150      * check or uncheck groups of albums, given you have a checkable model.
0151      * Call this method after setModel().
0152      */
0153     void addCheckUncheckContextMenuActions();
0154 
0155 protected:
0156 
0157     void installView(QAbstractItemView* view = nullptr) override;
0158     void sendViewportEventToView(QEvent* e)             override;
0159 
0160 protected:
0161 
0162     AbstractAlbumTreeView* m_treeView;
0163 };
0164 
0165 // ------------------------------------------------------------------------------------
0166 
0167 class AlbumTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
0168 {
0169     Q_OBJECT
0170 
0171 public:
0172 
0173     explicit AlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);
0174 
0175     void setDefaultModel();
0176     void setAlbumModels(AlbumModel* model,
0177                         CheckableAlbumFilterModel* filterModel = nullptr);
0178     AlbumTreeView* view() const;
0179 };
0180 
0181 // ------------------------------------------------------------------------------------
0182 
0183 class TagTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
0184 {
0185     Q_OBJECT
0186 
0187 public:
0188 
0189     explicit TagTreeViewSelectComboBox(QWidget* const parent = nullptr);
0190 
0191     void setDefaultModel();
0192     void setAlbumModels(TagModel* model,
0193                         TagPropertiesFilterModel* filteredModel = nullptr,
0194                         CheckableAlbumFilterModel* filterModel = nullptr);
0195     TagTreeView* view() const;
0196 };
0197 
0198 } // namespace Digikam
0199 
0200 #endif // DIGIKAM_ALBUM_SELECT_COMBO_BOX_H