digiKam
Loading...
Searching...
No Matches
abstractalbumtreeview_p.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2009-03-25
7 * Description : Tree View for album models
8 *
9 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
11 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
12 * SPDX-FileCopyrightText: 2014 by Michael G. Hansen <mike at mghansen dot de>
13 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
14 *
15 * SPDX-License-Identifier: GPL-2.0-or-later
16 *
17 * ============================================================ */
18
19#pragma once
20
22
23// Qt includes
24
25#include <QStyledItemDelegate>
26#include <QMouseEvent>
27#include <QScrollBar>
28#include <QQueue>
29#include <QTimer>
30#include <QDrag>
31#include <QMenu>
32#include <QIcon>
33
34// KDE includes
35
36#include <klocalizedstring.h>
37#include <kconfiggroup.h>
38
39// Local includes
40
41#include "digikam_debug.h"
42#include "digikam_globals.h"
43#include "albumdragdrop.h"
44#include "albummanager.h"
46#include "applicationsettings.h"
48#include "contextmenuhelper.h"
49#include "fileactionmngr.h"
50#include "tagdragdrop.h"
52#include "coredb.h"
53
54namespace Digikam
55{
56
57template <class A>
58static QList<A*> selectedAlbums(const QItemSelectionModel* const selModel,
59 const AlbumFilterModel* const filterModel)
60{
61 const QList<QModelIndex> indexes = selModel->selectedIndexes();
62 QList<A*> albums;
63
64 for (const QModelIndex& index : std::as_const(indexes))
65 {
66 albums << static_cast<A*>(filterModel->albumForIndex(index));
67 }
68
69 return albums;
70}
71
72// -------------------------------------------------------------------------------
73
74struct State
75{
76 State() = default;
77
78 bool selected = false;
79 bool expanded = false;
80 bool currentIndex = false;
81};
82
83// -------------------------------------------------------------------------------
84
85class Q_DECL_HIDDEN AlbumTreeViewDelegate : public QStyledItemDelegate
86{
87 Q_OBJECT
88
89public:
90
91 explicit AlbumTreeViewDelegate(AbstractAlbumTreeView* const treeView = nullptr)
92 : QStyledItemDelegate(treeView),
93 m_treeView (treeView)
94 {
95 updateHeight();
96 }
97
98 QSize sizeHint(const QStyleOptionViewItem& option,
99 const QModelIndex& index) const override
100 {
101 QSize size = QStyledItemDelegate::sizeHint(option, index);
102 size.setHeight(qMax(size.height(), m_height));
103
104 return size;
105 }
106
108 {
109 int h = qMax(AlbumThumbnailLoader::instance()->thumbnailSize() + 2,
110 m_treeView->fontMetrics().height());
111
112 if ((h % 2) > 0)
113 {
114 ++h;
115 }
116
117 setHeight(h);
118 }
119
120 void setHeight(int height)
121 {
122 if (m_height == height)
123 {
124 return;
125 }
126
127 m_height = height;
128
129 Q_EMIT sizeHintChanged(QModelIndex());
130 }
131
132protected:
133
134 AbstractAlbumTreeView* m_treeView = nullptr;
135 int m_height = 0;
136};
137
138// -------------------------------------------------------------------------------
139
140class Q_DECL_HIDDEN AbstractAlbumTreeView::Private
141{
142public:
143
144 Private() = default;
145
146 AlbumTreeViewDelegate* delegate = nullptr;
147
148 bool expandOnSingleClick = false;
149 bool expandNewCurrent = false;
150 bool selectAlbumOnClick = false;
151 bool selectOnContextMenu = true;
152 bool enableContextMenu = false;
153 bool setInAlbumManager = false;
154
155 QMap<int, Digikam::State> statesByAlbumId;
156 QMap<int, Digikam::State> searchBackup;
157
158 QTimer* resizeColumnsTimer = nullptr;
159
161
162 QList<ContextMenuElement*> contextMenuElements;
163
166
167 const QString configSelectionEntry = QLatin1String("Selection");
168 const QString configExpansionEntry = QLatin1String("Expansion");
169 const QString configCurrentIndexEntry = QLatin1String("CurrentIndex");
170 const QString configSortColumnEntry = QLatin1String("SortColumn");
171 const QString configSortOrderEntry = QLatin1String("SortOrder");
172};
173
174} // namespace Digikam
Definition abstractalbumtreeview_p.h:141
QMap< int, Digikam::State > searchBackup
Definition abstractalbumtreeview_p.h:156
QPixmap contextMenuIcon
Definition abstractalbumtreeview_p.h:164
AlbumPointer< Album > lastSelectedAlbum
Definition abstractalbumtreeview_p.h:160
QString contextMenuTitle
Definition abstractalbumtreeview_p.h:165
QMap< int, Digikam::State > statesByAlbumId
Definition abstractalbumtreeview_p.h:155
QList< ContextMenuElement * > contextMenuElements
Definition abstractalbumtreeview_p.h:162
Definition abstractalbumtreeview.h:53
Definition albumpointer.h:38
Definition abstractalbumtreeview_p.h:86
void updateHeight()
Definition abstractalbumtreeview_p.h:107
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition abstractalbumtreeview_p.h:98
void setHeight(int height)
Definition abstractalbumtreeview_p.h:120
AlbumTreeViewDelegate(AbstractAlbumTreeView *const treeView=nullptr)
Definition abstractalbumtreeview_p.h:91
Definition datefolderview.cpp:34
Definition abstractalbumtreeview_p.h:75
bool expanded
Definition abstractalbumtreeview_p.h:79
bool currentIndex
Definition abstractalbumtreeview_p.h:80
State()=default
bool selected
Definition abstractalbumtreeview_p.h:78