digiKam
itemvisibilitycontroller.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 : 2010-09-20
7  * Description : Managing visibility state with animations
8  *
9  * Copyright (C) 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2012-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_ITEM_VISIBILITY_CONTROLLER_H
26 #define DIGIKAM_ITEM_VISIBILITY_CONTROLLER_H
27 
28 // Qt includes
29 
30 #include <QAbstractAnimation>
31 #include <QVariant>
32 
33 // Local includes
34 
35 #include "digikam_export.h"
36 
37 class QEasingCurve;
38 class QPropertyAnimation;
39 
40 namespace Digikam
41 {
42 
43 class DIGIKAM_EXPORT ItemVisibilityController : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY(bool shallBeShown READ shallBeShown WRITE setShallBeShown)
47  Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
48 
49 public:
50 
71  enum State
72  {
76  FadingOut
77  };
78  Q_ENUM(State)
79 
81  {
84 
86  ExcludeFadingOut
87  };
88 
89 public:
90 
91  explicit ItemVisibilityController(QObject* const parent = nullptr);
92  ~ItemVisibilityController() override;
93 
94  bool shallBeShown() const;
95  bool isVisible() const;
96  State state() const;
97 
103  bool hasVisibleItems(IncludeFadingOutMode mode = IncludeFadingOut) const;
104 
108  void clear();
109 
118  void addItem(QObject* object);
119  void removeItem(QObject* object);
120 
124  QList<QObject*> items() const;
125 
129  QList<QObject*> visibleItems(IncludeFadingOutMode mode = IncludeFadingOut) const;
130 
134  void setEasingCurve(const QEasingCurve& easing);
135  void setAnimationDuration(int msecs);
136 
137 Q_SIGNALS:
138 
142  void propertiesAssigned(bool visible);
143 
148  void propertiesAssigned(QObject* item, bool visible);
149 
153  void hiddenAndRemoved(QObject* item);
154 
155 public Q_SLOTS:
156 
160  void setShallBeShown(bool shallBeShown);
161  void setShallBeShownDirectly(bool shallBeShown);
162 
168  void setItemThatShallBeShown(QObject* item);
169 
176  void show();
177  void hide();
178  void setVisible(bool visible);
179  void setDirectlyVisible(bool visible);
180 
187  void showItem(QObject* item);
188  void hideItem(QObject* item);
189  void setItemVisible(QObject* item, bool visible);
190  void setItemDirectlyVisible(QObject* item, bool visible);
191 
196  void hideAndRemoveItem(QObject* item);
197 
198 protected:
199 
207  virtual QPropertyAnimation* createAnimation(QObject* item);
208 
209 protected Q_SLOTS:
210 
211  void animationFinished();
212  void objectDestroyed(QObject*);
213 
214 private:
215 
216  class Private;
217  Private* const d;
218 };
219 
220 // ------------------------------------------------------------------------------------------
221 
222 class DIGIKAM_EXPORT ItemVisibilityControllerPropertyObject : public QObject
223 {
224  Q_OBJECT
225  Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
226  Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
227 
228 public:
229 
236  explicit ItemVisibilityControllerPropertyObject(QObject* const parent = nullptr);
237 
238  qreal opacity() const;
239  void setOpacity(qreal opacity);
240 
241  bool isVisible() const;
242  void setVisible(bool visible);
243 
244 Q_SIGNALS:
245 
248 
249 protected:
250 
251  qreal m_opacity;
252  bool m_visible;
253 };
254 
255 // ------------------------------------------------------------------------------------------
256 
258 {
259  Q_OBJECT
260 
261 public:
262 
270  explicit AnimatedVisibility(QObject* const parent = nullptr);
271 
272  ItemVisibilityController* controller() const;
273 
274 protected:
275 
277 };
278 
279 // ------------------------------------------------------------------------------------------
280 
281 class DIGIKAM_EXPORT HidingStateChanger : public ItemVisibilityController
282 {
283  Q_OBJECT
284 
285 public:
286 
295  explicit HidingStateChanger(QObject* const parent = nullptr);
296 
300  HidingStateChanger(QObject* const target, const QByteArray& property, QObject* const parent = nullptr);
301 
302  void setTargetObject(QObject* const object);
303  void setPropertyName(const QByteArray& propertyName);
304 
305 public Q_SLOTS:
306 
307  void changeValue(const QVariant& value);
308 
309 Q_SIGNALS:
310 
314  void stateChanged();
315 
319  void finished();
320 
321 protected Q_SLOTS:
322 
323  void slotPropertiesAssigned(bool);
324 
325 protected:
326 
327  QObject* m_object;
328  QByteArray m_property;
329  QVariant m_value;
330 };
331 
332 } // namespace Digikam
333 
334 #endif // DIGIKAM_ITEM_VISIBILITY_CONTROLLER_H
Definition: itemvisibilitycontroller.h:258
ItemVisibilityController * m_controller
Definition: itemvisibilitycontroller.h:276
Definition: itemvisibilitycontroller.h:282
QVariant m_value
Definition: itemvisibilitycontroller.h:329
QObject * m_object
Definition: itemvisibilitycontroller.h:327
QByteArray m_property
Definition: itemvisibilitycontroller.h:328
Definition: itemvisibilitycontroller.h:223
bool m_visible
Definition: itemvisibilitycontroller.h:252
qreal m_opacity
Definition: itemvisibilitycontroller.h:251
Definition: itemvisibilitycontroller.h:44
State
Definition: itemvisibilitycontroller.h:72
@ Hidden
Definition: itemvisibilitycontroller.h:73
@ FadingIn
Definition: itemvisibilitycontroller.h:74
@ Visible
Definition: itemvisibilitycontroller.h:75
void propertiesAssigned(bool visible)
void propertiesAssigned(QObject *item, bool visible)
IncludeFadingOutMode
Definition: itemvisibilitycontroller.h:81
@ IncludeFadingOut
In addition to items visible or fading in, return those fading out.
Definition: itemvisibilitycontroller.h:83
void hiddenAndRemoved(QObject *item)
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43
Definition: abstractalbumtreeview_p.h:85