| 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-2026 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 |
|
| 21 |
#include "abstractalbumtreeview.h" |
| 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" |
| 45 |
#include "albummodeldragdrophandler.h" |
| 46 |
#include "applicationsettings.h" |
| 47 |
#include "albumthumbnailloader.h" |
| 48 |
#include "contextmenuhelper.h" |
| 49 |
#include "fileactionmngr.h" |
| 50 |
#include "tagdragdrop.h" |
| 51 |
#include "tagmodificationhelper.h" |
| 52 |
#include "coredb.h" |
| 53 |
|
| 54 |
namespace Digikam |
| 55 |
{ |
| 56 |
|
| 57 |
template <class A> |
| 58 |
static 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 |
|
| 74 |
struct Q_DECL_HIDDEN State |
| 75 |
{ |
| 76 |
State() = default; |
| 77 |
|
| 78 |
bool selected = false; |
| 79 |
bool expanded = false; |
| 80 |
bool currentIndex = false; |
| 81 |
}; |
| 82 |
|
| 83 |
// ------------------------------------------------------------------------------- |
| 84 |
|
| 85 |
class Q_DECL_HIDDEN AlbumTreeViewDelegate : public QStyledItemDelegate |
| 86 |
{ |
| 87 |
Q_OBJECT |
| 88 |
|
| 89 |
public: |
| 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 |
|
| 107 |
void updateHeight() |
| 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 |
|
| 132 |
protected: |
| 133 |
|
| 134 |
AbstractAlbumTreeView* m_treeView = nullptr; |
| 135 |
int m_height = 0; |
| 136 |
}; |
| 137 |
|
| 138 |
// ------------------------------------------------------------------------------- |
| 139 |
|
| 140 |
class Q_DECL_HIDDEN AbstractAlbumTreeView::Private |
| 141 |
{ |
| 142 |
public: |
| 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 |
|
| 160 |
AlbumPointer<Album> lastSelectedAlbum; |
| 161 |
|
| 162 |
QList<ContextMenuElement*> contextMenuElements; |
| 163 |
|
| 164 |
QPixmap contextMenuIcon; |
| 165 |
QString contextMenuTitle; |
| 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 |