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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-03-25
0007  * Description : Tree View for album models
0008  *
0009  * SPDX-FileCopyrightText: 2009-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: 2014      by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0012  * SPDX-FileCopyrightText: 2014      by Michael G. Hansen <mike at mghansen dot de>
0013  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0014  *
0015  * SPDX-License-Identifier: GPL-2.0-or-later
0016  *
0017  * ============================================================ */
0018 
0019 #ifndef DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H
0020 #define DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H
0021 
0022 #include "abstractalbumtreeview.h"
0023 
0024 // Qt includes
0025 
0026 #include <QStyledItemDelegate>
0027 #include <QMouseEvent>
0028 #include <QScrollBar>
0029 #include <QQueue>
0030 #include <QTimer>
0031 #include <QDrag>
0032 #include <QMenu>
0033 #include <QIcon>
0034 
0035 // KDE includes
0036 
0037 #include <klocalizedstring.h>
0038 #include <kconfiggroup.h>
0039 
0040 // Local includes
0041 
0042 #include "digikam_debug.h"
0043 #include "digikam_globals.h"
0044 #include "albumdragdrop.h"
0045 #include "albummanager.h"
0046 #include "albummodeldragdrophandler.h"
0047 #include "applicationsettings.h"
0048 #include "albumthumbnailloader.h"
0049 #include "contextmenuhelper.h"
0050 #include "fileactionmngr.h"
0051 #include "tagdragdrop.h"
0052 #include "tagmodificationhelper.h"
0053 #include "coredb.h"
0054 
0055 namespace Digikam
0056 {
0057 
0058 template <class A>
0059 static QList<A*> selectedAlbums(QItemSelectionModel* const selModel,
0060                                 AlbumFilterModel* const filterModel)
0061 {
0062     const QList<QModelIndex> indexes = selModel->selectedIndexes();
0063     QList<A*> albums;
0064 
0065     Q_FOREACH (const QModelIndex& index, indexes)
0066     {
0067         albums << static_cast<A*>(filterModel->albumForIndex(index));
0068     }
0069 
0070     return albums;
0071 }
0072 
0073 // -------------------------------------------------------------------------------
0074 
0075 struct State
0076 {
0077     State()
0078         : selected    (false),
0079           expanded    (false),
0080           currentIndex(false)
0081     {
0082     }
0083 
0084     bool selected;
0085     bool expanded;
0086     bool currentIndex;
0087 };
0088 
0089 // -------------------------------------------------------------------------------
0090 
0091 class Q_DECL_HIDDEN AlbumTreeViewDelegate : public QStyledItemDelegate
0092 {
0093     Q_OBJECT
0094 
0095 public:
0096 
0097     explicit AlbumTreeViewDelegate(AbstractAlbumTreeView* const treeView = nullptr)
0098         : QStyledItemDelegate(treeView),
0099           m_treeView         (treeView),
0100           m_height           (0)
0101     {
0102         updateHeight();
0103     }
0104 
0105     QSize sizeHint(const QStyleOptionViewItem& option,
0106                    const QModelIndex& index) const override
0107     {
0108         QSize size = QStyledItemDelegate::sizeHint(option, index);
0109         size.setHeight(qMax(size.height(), m_height));
0110 
0111         return size;
0112     }
0113 
0114     void updateHeight()
0115     {
0116         int h = qMax(AlbumThumbnailLoader::instance()->thumbnailSize() + 2,
0117                      m_treeView->fontMetrics().height());
0118 
0119         if ((h % 2) > 0)
0120         {
0121             ++h;
0122         }
0123 
0124         setHeight(h);
0125     }
0126 
0127     void setHeight(int height)
0128     {
0129         if (m_height == height)
0130         {
0131             return;
0132         }
0133 
0134         m_height = height;
0135 
0136         Q_EMIT sizeHintChanged(QModelIndex());
0137     }
0138 
0139 protected:
0140 
0141     AbstractAlbumTreeView* m_treeView;
0142     int                    m_height;
0143 };
0144 
0145 // -------------------------------------------------------------------------------
0146 
0147 class Q_DECL_HIDDEN AbstractAlbumTreeView::Private
0148 {
0149 public:
0150 
0151     explicit Private()
0152       : delegate                (nullptr),
0153         expandOnSingleClick     (false),
0154         expandNewCurrent        (false),
0155         selectAlbumOnClick      (false),
0156         selectOnContextMenu     (true),
0157         enableContextMenu       (false),
0158         setInAlbumManager       (false),
0159         resizeColumnsTimer      (nullptr),
0160         configSelectionEntry    (QLatin1String("Selection")),
0161         configExpansionEntry    (QLatin1String("Expansion")),
0162         configCurrentIndexEntry (QLatin1String("CurrentIndex")),
0163         configSortColumnEntry   (QLatin1String("SortColumn")),
0164         configSortOrderEntry    (QLatin1String("SortOrder"))
0165     {
0166     }
0167 
0168     AlbumTreeViewDelegate*     delegate;
0169 
0170     bool                       expandOnSingleClick;
0171     bool                       expandNewCurrent;
0172     bool                       selectAlbumOnClick;
0173     bool                       selectOnContextMenu;
0174     bool                       enableContextMenu;
0175     bool                       setInAlbumManager;
0176 
0177     QMap<int, Digikam::State>  statesByAlbumId;
0178     QMap<int, Digikam::State>  searchBackup;
0179 
0180     QTimer*                    resizeColumnsTimer;
0181 
0182     AlbumPointer<Album>        lastSelectedAlbum;
0183 
0184     QList<ContextMenuElement*> contextMenuElements;
0185 
0186     QPixmap                    contextMenuIcon;
0187     QString                    contextMenuTitle;
0188 
0189     const QString              configSelectionEntry;
0190     const QString              configExpansionEntry;
0191     const QString              configCurrentIndexEntry;
0192     const QString              configSortColumnEntry;
0193     const QString              configSortOrderEntry;
0194 };
0195 
0196 } // namespace Digikam
0197 
0198 #endif // DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H