| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2014-05-17 |
| 7 |
* Description : Album Labels Tree View. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> |
| 10 |
* SPDX-FileCopyrightText: 2014-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
* |
| 12 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 13 |
* |
| 14 |
* ============================================================ */ |
| 15 |
|
| 16 |
#include "labelstreeview_p.h" |
| 17 |
|
| 18 |
namespace Digikam |
| 19 |
{ |
| 20 |
|
| 21 |
LabelsTreeView::LabelsTreeView(QWidget* const parent, bool setCheckable) |
| 22 |
: QTreeWidget (parent), |
| 23 |
StateSavingObject(this), |
| 24 |
d (new Private(this)) |
| 25 |
{ |
| 26 |
d->regularFont = ApplicationSettings::instance()->getTreeViewFont(); |
| 27 |
d->iconSizeFromSetting = ApplicationSettings::instance()->getTreeViewIconSize(); |
| 28 |
d->iconSize = QSize(d->iconSizeFromSetting, d->iconSizeFromSetting); |
| 29 |
d->isCheckableTreeView = setCheckable; |
| 30 |
|
| 31 |
setHeaderLabel(i18nc("@title", "Labels")); |
| 32 |
setUniformRowHeights(false); |
| 33 |
|
| 34 |
initTreeView(); |
| 35 |
|
| 36 |
if (d->isCheckableTreeView) |
| 37 |
{ |
| 38 |
QTreeWidgetItemIterator it(this); |
| 39 |
|
| 40 |
while (*it) |
| 41 |
{ |
| 42 |
if ((*it)->parent()) |
| 43 |
{ |
| 44 |
(*it)->setFlags((*it)->flags()|Qt::ItemIsUserCheckable); |
| 45 |
(*it)->setCheckState(0, Qt::Unchecked); |
| 46 |
} |
| 47 |
|
| 48 |
++it; |
| 49 |
} |
| 50 |
} |
| 51 |
else |
| 52 |
{ |
| 53 |
setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 54 |
} |
| 55 |
|
| 56 |
// --- |
| 57 |
|
| 58 |
connect(ApplicationSettings::instance(), SIGNAL(setupChanged()), |
| 59 |
this, SLOT(slotSettingsChanged())); |
| 60 |
|
| 61 |
connect(this, &LabelsTreeView::signalColorNameChanged, |
| 62 |
TagsActionMngr::defaultManager(), &TagsActionMngr::slotColorNameChanged); |
| 63 |
|
| 64 |
connect(ThemeManager::instance(), &ThemeManager::signalThemeChanged, |
| 65 |
this, [this]() |
| 66 |
{ |
| 67 |
initTreeView(); |
| 68 |
} |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
LabelsTreeView::~LabelsTreeView() |
| 73 |
{ |
| 74 |
delete d; |
| 75 |
} |
| 76 |
|
| 77 |
bool LabelsTreeView::isCheckable() const |
| 78 |
{ |
| 79 |
return d->isCheckableTreeView; |
| 80 |
} |
| 81 |
|
| 82 |
bool LabelsTreeView::isLoadingState() const |
| 83 |
{ |
| 84 |
return d->isLoadingState; |
| 85 |
} |
| 86 |
|
| 87 |
QTreeWidgetItem* LabelsTreeView::getOrCreateItem(QTreeWidgetItem* const parent) |
| 88 |
{ |
| 89 |
QTreeWidgetItem* item = nullptr; |
| 90 |
|
| 91 |
if (*d->itemIterator) |
| 92 |
{ |
| 93 |
item = (*d->itemIterator); |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
if (parent) |
| 98 |
{ |
| 99 |
item = new QTreeWidgetItem(parent); |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
item = new QTreeWidgetItem(this); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
++d->itemIterator; |
| 108 |
|
| 109 |
return item; |
| 110 |
} |
| 111 |
|
| 112 |
QPixmap LabelsTreeView::goldenStarPixmap(bool fillin) const |
| 113 |
{ |
| 114 |
QPixmap pixmap = QPixmap(60, 60); |
| 115 |
pixmap.fill(Qt::transparent); |
| 116 |
|
| 117 |
QPainter p1(&pixmap); |
| 118 |
p1.setRenderHint(QPainter::Antialiasing, true); |
| 119 |
|
| 120 |
if (fillin) |
| 121 |
{ |
| 122 |
QPen pen(palette().color(QPalette::Active, foregroundRole())); |
| 123 |
p1.setBrush(qApp->palette().color(QPalette::Link)); |
| 124 |
p1.setPen(pen); |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
QPen pen(qApp->palette().color(QPalette::Active, QPalette::ButtonText)); |
| 129 |
p1.setPen(pen); |
| 130 |
} |
| 131 |
|
| 132 |
QTransform transform; |
| 133 |
transform.scale(4, 4); // 60px/15px (RatingWidget::starPolygon() size is 15*15px) |
| 134 |
p1.setTransform(transform); |
| 135 |
|
| 136 |
p1.drawPolygon(RatingWidget::starPolygon(), Qt::WindingFill); |
| 137 |
p1.end(); |
| 138 |
|
| 139 |
return pixmap; |
| 140 |
} |
| 141 |
|
| 142 |
QPixmap LabelsTreeView::colorRectPixmap(const QColor& color) const |
| 143 |
{ |
| 144 |
QRect rect(8, 8, 48, 48); |
| 145 |
QPixmap pixmap = QPixmap(60, 60); |
| 146 |
pixmap.fill(Qt::transparent); |
| 147 |
|
| 148 |
QPainter p1(&pixmap); |
| 149 |
p1.setRenderHint(QPainter::Antialiasing, true); |
| 150 |
p1.setBrush(color); |
| 151 |
p1.setPen((color == Qt::black) ? Qt::white : Qt::black); |
| 152 |
p1.drawRect(rect); |
| 153 |
p1.end(); |
| 154 |
|
| 155 |
return pixmap; |
| 156 |
} |
| 157 |
|
| 158 |
void LabelsTreeView::setCurrentAlbum() |
| 159 |
{ |
| 160 |
Q_EMIT signalSetCurrentAlbum(); |
| 161 |
} |
| 162 |
|
| 163 |
} // namespace Digikam |
| 164 |
|
| 165 |
#include "moc_labelstreeview.cpp" |