1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2010-12-26
* Description : images versions tree view overlays
*
* SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
* SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "versionsoverlays.h"
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "digikam_debug.h"
#include "iteminfo.h"
#include "itemhistorygraphmodel.h"
#include "itemlistmodel.h"
#include "itemviewhoverbutton.h"
#include "tagscache.h"
#include "versionmanagersettings.h"
namespace Digikam
{
class Q_DECL_HIDDEN ShowHideVersionsOverlay::Button : public ItemViewHoverButton
{
Q_OBJECT
public:
explicit Button(QAbstractItemView* const parentView);
QSize sizeHint() const override;
protected:
QIcon icon() override;
void updateToolTip() override;
};
ShowHideVersionsOverlay::Button::Button(QAbstractItemView* const parentView)
: ItemViewHoverButton(parentView)
{
setup();
}
QSize ShowHideVersionsOverlay::Button::sizeHint() const
{
return QSize(24, 24);
}
QIcon ShowHideVersionsOverlay::Button::icon()
{
QString icon = isChecked() ? QLatin1String("edit-bomb")
: QLatin1String("edit-clear-history");
return QIcon::fromTheme(icon);
}
void ShowHideVersionsOverlay::Button::updateToolTip()
{
setToolTip(isChecked() ?
i18nc("@info:tooltip", "Hide item permanently") :
i18nc("@info:tooltip", "Show item permanently"));
}
// ------------------------------------------------------------------------------------
ShowHideVersionsOverlay::ShowHideVersionsOverlay(QObject* const parent)
: HoverButtonDelegateOverlay(parent)
{
}
void ShowHideVersionsOverlay::setSettings(const VersionManagerSettings& settings)
{
m_filter = VersionItemFilterSettings(settings);
}
void ShowHideVersionsOverlay::setActive(bool active)
{
HoverButtonDelegateOverlay::setActive(active);
if (active)
{
connect(button(), SIGNAL(clicked(bool)),
this, SLOT(slotClicked(bool)));
}
else
{
// button is deleted
}
}
ItemViewHoverButton* ShowHideVersionsOverlay::createButton()
{
return new Button(view());
}
void ShowHideVersionsOverlay::updateButton(const QModelIndex& index)
{
const QRect rect = m_view->visualRect(index);
const QSize size = button()->size();
const int gap = 5;
const int x = rect.right() - gap - size.width();
const int y = rect.bottom() - gap - size.height();
button()->move(QPoint(x, y));
ItemInfo info = ItemModel::retrieveItemInfo(index);
button()->setChecked(m_filter.isExemptedBySettings(info));
}
void ShowHideVersionsOverlay::slotClicked(bool checked)
{
QModelIndex index = button()->index();
if (index.isValid())
{
ItemInfo info = ItemModel::retrieveItemInfo(index);
int tagId = TagsCache::instance()->getOrCreateInternalTag(InternalTagName::versionAlwaysVisible());
if (checked)
{
info.setTag(tagId);
}
else
{
info.removeTag(tagId);
}
}
}
bool ShowHideVersionsOverlay::checkIndex(const QModelIndex& index) const
{
if (index.data(ItemHistoryGraphModel::IsImageItemRole).toBool())
{
ItemInfo info = ItemModel::retrieveItemInfo(index);
return m_filter.isHiddenBySettings(info);
}
return false;
}
// --------------------------------------------------------------------
class Q_DECL_HIDDEN ActionVersionsOverlay::Button : public ItemViewHoverButton
{
Q_OBJECT
public:
Button(QAbstractItemView* const parentView, const QIcon& icon, const QString& text, const QString& tip);
QSize sizeHint() const override;
protected:
QIcon icon() override;
void updateToolTip() override;
protected:
QIcon m_icon;
QString m_text;
QString m_tip;
};
ActionVersionsOverlay::Button::Button(QAbstractItemView* const parentView, const QIcon& icon, const QString& text, const QString& tip)
: ItemViewHoverButton(parentView),
m_icon (icon),
m_text (text),
m_tip (tip)
{
setup();
}
QSize ActionVersionsOverlay::Button::sizeHint() const
{
return QSize(24, 24);
}
QIcon ActionVersionsOverlay::Button::icon()
{
return m_icon;
}
void ActionVersionsOverlay::Button::updateToolTip()
{
setToolTip(m_tip);
}
// ------------------------------------------------------------------------------------------
ActionVersionsOverlay::ActionVersionsOverlay(QObject* const parent, const QIcon& icon, const QString& text, const QString& tip)
: HoverButtonDelegateOverlay(parent),
m_icon (icon),
m_text (text),
m_tip (tip)
{
}
ActionVersionsOverlay::Button* ActionVersionsOverlay::button() const<--- Derived function 'ActionVersionsOverlay::button'
{
return static_cast<Button*>(HoverButtonDelegateOverlay::button());
}
void ActionVersionsOverlay::setReferenceModel(const ItemModel* model)
{
m_referenceModel = model;
}
void ActionVersionsOverlay::setActive(bool active)
{
HoverButtonDelegateOverlay::setActive(active);
if (active)
{
connect(button(), SIGNAL(clicked(bool)),
this, SLOT(slotClicked(bool)));
}
else
{
// button is deleted
}
}
ItemViewHoverButton* ActionVersionsOverlay::createButton()
{
return new Button(view(), m_icon, m_text, m_tip);
}
void ActionVersionsOverlay::updateButton(const QModelIndex& index)
{
const QRect rect = m_view->visualRect(index);
const QSize size = button()->size();
const int gap = 5;
const int x = rect.right() - gap - size.width();
const int y = rect.top() + gap;
button()->move(QPoint(x, y));
}
void ActionVersionsOverlay::slotClicked(bool checked)
{
Q_UNUSED(checked);
QModelIndex index = button()->index();
if (index.isValid())
{
Q_EMIT activated(ItemModel::retrieveItemInfo(index));
}
}
bool ActionVersionsOverlay::checkIndex(const QModelIndex& index) const
{
if (index.data(ItemHistoryGraphModel::IsImageItemRole).toBool())
{
if (m_referenceModel)
{
ItemInfo info = ItemModel::retrieveItemInfo(index);
// show overlay if image is not contained in reference model
return (!m_referenceModel->hasImage(info));
}
return true;
}
return false;
}
} // namespace Digikam
#include "versionsoverlays.moc"
#include "moc_versionsoverlays.cpp"
|