digiKam
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  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
11  * Copyright (C) 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
12  * Copyright (C) 2014 by Michael G. Hansen <mike at mghansen dot de>
13  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
14  *
15  * This program is free software; you can redistribute it
16  * and/or modify it under the terms of the GNU General
17  * Public License as published by the Free Software Foundation;
18  * either version 2, or (at your option)
19  * any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * ============================================================ */
27 
28 #ifndef DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H
29 #define DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H
30 
31 #include "abstractalbumtreeview.h"
32 
33 // Qt includes
34 
35 #include <QStyledItemDelegate>
36 #include <QMouseEvent>
37 #include <QScrollBar>
38 #include <QQueue>
39 #include <QTimer>
40 #include <QDrag>
41 #include <QMenu>
42 #include <QIcon>
43 
44 // KDE includes
45 
46 #include <klocalizedstring.h>
47 #include <kconfiggroup.h>
48 
49 // Local includes
50 
51 #include "digikam_debug.h"
52 #include "digikam_globals.h"
53 #include "albumdragdrop.h"
54 #include "albummanager.h"
56 #include "applicationsettings.h"
57 #include "albumthumbnailloader.h"
58 #include "contextmenuhelper.h"
59 #include "fileactionmngr.h"
60 #include "tagdragdrop.h"
61 #include "tagmodificationhelper.h"
62 #include "coredb.h"
63 
64 namespace Digikam
65 {
66 
67 template <class A>
68 static QList<A*> selectedAlbums(QItemSelectionModel* const selModel,
69  AlbumFilterModel* const filterModel)
70 {
71  const QList<QModelIndex> indexes = selModel->selectedIndexes();
72  QList<A*> albums;
73 
74  foreach (const QModelIndex& index, indexes)
75  {
76  albums << static_cast<A*>(filterModel->albumForIndex(index));
77  }
78 
79  return albums;
80 }
81 
82 // -------------------------------------------------------------------------------
83 
84 struct State
85 {
87  : selected (false),
88  expanded (false),
89  currentIndex(false)
90  {
91  }
92 
93  bool selected;
94  bool expanded;
96 };
97 
98 // -------------------------------------------------------------------------------
99 
100 class Q_DECL_HIDDEN AlbumTreeViewDelegate : public QStyledItemDelegate
101 {
102  Q_OBJECT
103 
104 public:
105 
106  explicit AlbumTreeViewDelegate(AbstractAlbumTreeView* const treeView = nullptr)
107  : QStyledItemDelegate(treeView),
108  m_treeView (treeView),
109  m_height (0)
110  {
111  updateHeight();
112  }
113 
114  QSize sizeHint(const QStyleOptionViewItem& option,
115  const QModelIndex& index) const override
116  {
117  QSize size = QStyledItemDelegate::sizeHint(option, index);
118  size.setHeight(qMax(size.height(), m_height));
119 
120  return size;
121  }
122 
124  {
125  int h = qMax(AlbumThumbnailLoader::instance()->thumbnailSize() + 2,
126  m_treeView->fontMetrics().height());
127 
128  if ((h % 2) > 0)
129  {
130  ++h;
131  }
132 
133  setHeight(h);
134  }
135 
136  void setHeight(int height)
137  {
138  if (m_height == height)
139  {
140  return;
141  }
142 
143  m_height = height;
144 
145  emit sizeHintChanged(QModelIndex());
146  }
147 
148 protected:
149 
151  int m_height;
152 };
153 
154 // -------------------------------------------------------------------------------
155 
156 class Q_DECL_HIDDEN AbstractAlbumTreeView::Private
157 {
158 public:
159 
160  explicit Private()
161  : delegate (nullptr),
162  expandOnSingleClick (false),
163  expandNewCurrent (false),
164  selectAlbumOnClick (false),
165  selectOnContextMenu (true),
166  enableContextMenu (false),
167  setInAlbumManager (false),
168  resizeColumnsTimer (nullptr),
169  configSelectionEntry (QLatin1String("Selection")),
170  configExpansionEntry (QLatin1String("Expansion")),
171  configCurrentIndexEntry (QLatin1String("CurrentIndex")),
172  configSortColumnEntry (QLatin1String("SortColumn")),
173  configSortOrderEntry (QLatin1String("SortOrder"))
174  {
175  }
176 
178 
185 
186  QMap<int, Digikam::State> statesByAlbumId;
187  QMap<int, Digikam::State> searchBackup;
188 
190 
192 
194 
197 
198  const QString configSelectionEntry;
199  const QString configExpansionEntry;
200  const QString configCurrentIndexEntry;
201  const QString configSortColumnEntry;
202  const QString configSortOrderEntry;
203 };
204 
205 } // namespace Digikam
206 
207 #endif // DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H
Definition: abstractalbumtreeview_p.h:157
bool enableContextMenu
Definition: abstractalbumtreeview_p.h:183
const QString configExpansionEntry
Definition: abstractalbumtreeview_p.h:199
bool selectAlbumOnClick
Definition: abstractalbumtreeview_p.h:181
const QString configSortOrderEntry
Definition: abstractalbumtreeview_p.h:202
const QString configCurrentIndexEntry
Definition: abstractalbumtreeview_p.h:200
bool selectOnContextMenu
Definition: abstractalbumtreeview_p.h:182
const QString configSortColumnEntry
Definition: abstractalbumtreeview_p.h:201
QMap< int, Digikam::State > searchBackup
Definition: abstractalbumtreeview_p.h:187
bool setInAlbumManager
Definition: abstractalbumtreeview_p.h:184
const QString configSelectionEntry
Definition: abstractalbumtreeview_p.h:198
QPixmap contextMenuIcon
Definition: abstractalbumtreeview_p.h:195
AlbumPointer< Album > lastSelectedAlbum
Definition: abstractalbumtreeview_p.h:191
QString contextMenuTitle
Definition: abstractalbumtreeview_p.h:196
Private()
Definition: abstractalbumtreeview_p.h:160
AlbumTreeViewDelegate * delegate
Definition: abstractalbumtreeview_p.h:177
QTimer * resizeColumnsTimer
Definition: abstractalbumtreeview_p.h:189
QMap< int, Digikam::State > statesByAlbumId
Definition: abstractalbumtreeview_p.h:186
QList< ContextMenuElement * > contextMenuElements
Definition: abstractalbumtreeview_p.h:193
bool expandNewCurrent
Definition: abstractalbumtreeview_p.h:180
bool expandOnSingleClick
Definition: abstractalbumtreeview_p.h:179
Definition: abstractalbumtreeview.h:63
Definition: albumpointer.h:48
static AlbumThumbnailLoader * instance()
Definition: albumthumbnailloader.cpp:111
Definition: abstractalbumtreeview_p.h:101
int m_height
Definition: abstractalbumtreeview_p.h:151
void updateHeight()
Definition: abstractalbumtreeview_p.h:123
AbstractAlbumTreeView * m_treeView
Definition: abstractalbumtreeview_p.h:150
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: abstractalbumtreeview_p.h:114
void setHeight(int height)
Definition: abstractalbumtreeview_p.h:136
AlbumTreeViewDelegate(AbstractAlbumTreeView *const treeView=nullptr)
Definition: abstractalbumtreeview_p.h:106
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43
Definition: abstractalbumtreeview_p.h:85
bool expanded
Definition: abstractalbumtreeview_p.h:94
bool currentIndex
Definition: abstractalbumtreeview_p.h:95
State()
Definition: abstractalbumtreeview_p.h:86
bool selected
Definition: abstractalbumtreeview_p.h:93