digiKam
timelinewidget.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 : 2007-12-08
7  * Description : a widget to display date and time statistics of pictures
8  *
9  * Copyright (C) 2007-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2011-2012 by Andi Clemens <andi dot clemens 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_TIME_LINE_WIDGET_H
26 #define DIGIKAM_TIME_LINE_WIDGET_H
27 
28 // Qt includes
29 
30 #include <QString>
31 #include <QWidget>
32 #include <QDateTime>
33 #include <QPaintEvent>
34 #include <QWheelEvent>
35 #include <QMouseEvent>
36 
37 // Local includes
38 
40 
41 namespace Digikam
42 {
43 
44 class TimeLineWidget : public QWidget
45 {
46  Q_OBJECT
47 
48 public:
49 
50  enum TimeUnit
51  {
52  Day = 0,
55  Year
56  };
57 
59  {
60  Unselected = 0,
62  Selected
63  };
64 
65  enum ScaleMode
66  {
67  LinScale = 0,
68  LogScale
69  };
70 
71 public:
72 
73  explicit TimeLineWidget(QWidget* const parent = nullptr);
74  ~TimeLineWidget() override;
75 
77  TimeUnit timeUnit() const;
78 
80  ScaleMode scaleMode() const;
81 
82  void setCursorDateTime(const QDateTime& dateTime);
83  QDateTime cursorDateTime() const;
84  int cursorInfo(QString& infoDate) const;
85 
89  DateRangeList selectedDateRange(int& totalCount) const;
90  void setSelectedDateRange(const DateRangeList& list);
91 
92  int totalIndex() const;
93  int indexForRefDateTime() const;
94  int indexForCursorDateTime() const;
95  void setCurrentIndex(int index);
96 
97 Q_SIGNALS:
98 
103 
104 public Q_SLOTS:
105 
106  void slotDatesHash(const QHash<QDateTime, int>&);
107  void slotPrevious();
108  void slotNext();
109  void slotBackward();
110  void slotForward();
111  void slotResetSelection();
112 
113 private Q_SLOTS:
114 
115  void slotThemeChanged();
116 
117 private:
118 
119  QDateTime prevDateTime(const QDateTime& dt) const;
120  QDateTime nextDateTime(const QDateTime& dt) const;
121 
122  int maxCount() const;
123  int indexForDateTime(const QDateTime& date) const;
124  int statForDateTime(const QDateTime& dt, SelectionMode& selected) const;
125  void setRefDateTime(const QDateTime& dateTime);
126 
127  void paintEvent(QPaintEvent*) override;
128  void wheelEvent(QWheelEvent*) override;
129 
130  void mousePressEvent(QMouseEvent*) override;
131  void mouseMoveEvent(QMouseEvent*) override;
132  void mouseReleaseEvent(QMouseEvent*) override;
133 
134  void keyPressEvent(QKeyEvent *e) override;
135  void keyReleaseEvent(QKeyEvent *) override;
136  void keyScroll(bool isScrollNext);
137 
138  QDateTime dateTimeForPoint(const QPoint& pt,
139  bool& isOnSelectionArea);
140  QDateTime firstDayOfWeek(int year, int weekNumber) const;
141 
142  void resetSelection();
143  void setDateTimeSelected(const QDateTime& dt,
144  SelectionMode selected);
145  void setDaysRangeSelection(const QDateTime& dts,
146  const QDateTime& dte,
147  SelectionMode selected);
148  SelectionMode checkSelectionForDaysRange(const QDateTime& dts,
149  const QDateTime& dte) const;
150  void updateWeekSelection(const QDateTime& dts,
151  const QDateTime& dte);
152  void updateMonthSelection(const QDateTime& dts,
153  const QDateTime& dte);
154  void updateYearSelection(const QDateTime& dts,
155  const QDateTime& dte);
156  void updateAllSelection();
157 
161  int calculateTop(int& val) const;
162  void paintItem(QPainter& p,
163  const QRect& barRect,
164  const QDateTime& ref,
165  const int& separatorPosition,
166  const QColor& dateColor,
167  const QColor& subDateColor);
168 
169  void handleSelectionRange(QDateTime& selEndDateTime);
170 
171 private:
172 
173  class Private;
174  Private* const d;
175 };
176 
177 } // namespace Digikam
178 
179 #endif // DIGIKAM_TIME_LINE_WIDGET_H
Definition: timelinewidget.h:45
void slotForward()
Definition: timelinewidget.cpp:1758
void slotNext()
Definition: timelinewidget.cpp:1747
TimeUnit
Definition: timelinewidget.h:51
@ Week
Definition: timelinewidget.h:53
@ Day
Definition: timelinewidget.h:52
@ Month
Definition: timelinewidget.h:54
@ Year
Definition: timelinewidget.h:55
void setScaleMode(ScaleMode scaleMode)
Definition: timelinewidget.cpp:166
DateRangeList selectedDateRange(int &totalCount) const
Definition: timelinewidget.cpp:462
void setTimeUnit(TimeUnit timeUnit)
Definition: timelinewidget.cpp:154
ScaleMode scaleMode() const
Definition: timelinewidget.cpp:172
void setSelectedDateRange(const DateRangeList &list)
Definition: timelinewidget.cpp:429
ScaleMode
Definition: timelinewidget.h:66
@ LinScale
Linear scale.
Definition: timelinewidget.h:67
@ LogScale
Logarithmic scale.
Definition: timelinewidget.h:68
TimeLineWidget(QWidget *const parent=nullptr)
Definition: timelinewidget.cpp:120
void setCurrentIndex(int index)
Definition: timelinewidget.cpp:227
~TimeLineWidget() override
Definition: timelinewidget.cpp:149
int totalIndex() const
Definition: timelinewidget.cpp:177
int indexForCursorDateTime() const
Definition: timelinewidget.cpp:222
int cursorInfo(QString &infoDate) const
Definition: timelinewidget.cpp:304
QDateTime cursorDateTime() const
Definition: timelinewidget.cpp:299
void slotPrevious()
Definition: timelinewidget.cpp:1736
void setCursorDateTime(const QDateTime &dateTime)
Definition: timelinewidget.cpp:247
TimeUnit timeUnit() const
Definition: timelinewidget.cpp:161
int indexForRefDateTime() const
Definition: timelinewidget.cpp:217
void slotDatesHash(const QHash< QDateTime, int > &)
Definition: timelinewidget.cpp:563
void slotResetSelection()
Definition: timelinewidget.cpp:396
void slotBackward()
Definition: timelinewidget.cpp:1681
SelectionMode
Definition: timelinewidget.h:59
@ Unselected
No selection.
Definition: timelinewidget.h:60
@ FuzzySelection
Partially selected.
Definition: timelinewidget.h:61
@ Selected
Fully selected.
Definition: timelinewidget.h:62
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43