File indexing completed on 2025-01-05 03:51:08

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-12-08
0007  * Description : a widget to display date and time statistics of pictures
0008  *
0009  * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2011-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_TIME_LINE_WIDGET_H
0017 #define DIGIKAM_TIME_LINE_WIDGET_H
0018 
0019 // Qt includes
0020 
0021 #include <QString>
0022 #include <QWidget>
0023 #include <QDateTime>
0024 #include <QPaintEvent>
0025 #include <QWheelEvent>
0026 #include <QMouseEvent>
0027 
0028 // Local includes
0029 
0030 #include "searchmodificationhelper.h"
0031 
0032 namespace Digikam
0033 {
0034 
0035 class TimeLineWidget : public QWidget
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040 
0041     enum TimeUnit
0042     {
0043         Day = 0,
0044         Week,
0045         Month,
0046         Year
0047     };
0048 
0049     enum SelectionMode
0050     {
0051         Unselected = 0,    ///< No selection.
0052         FuzzySelection,    ///< Partially selected.
0053         Selected           ///< Fully selected.
0054     };
0055 
0056     enum ScaleMode
0057     {
0058         LinScale = 0,      ///< Linear scale.
0059         LogScale           ///< Logarithmic scale.
0060     };
0061 
0062 public:
0063 
0064     explicit TimeLineWidget(QWidget* const parent = nullptr);
0065     ~TimeLineWidget() override;
0066 
0067     void      setTimeUnit(TimeUnit timeUnit);
0068     TimeUnit  timeUnit()                                                        const;
0069 
0070     void      setScaleMode(ScaleMode scaleMode);
0071     ScaleMode scaleMode()                                                       const;
0072 
0073     void      setCursorDateTime(const QDateTime& dateTime);
0074     QDateTime cursorDateTime()                                                  const;
0075     int       cursorInfo(QString& infoDate)                                     const;
0076 
0077     /**
0078      * Return a list of Date-Range based on selection performed on days-map
0079      */
0080     DateRangeList selectedDateRange(int& totalCount)                            const;
0081     void          setSelectedDateRange(const DateRangeList& list);
0082 
0083     int  totalIndex()                                                           const;
0084     int  indexForRefDateTime()                                                  const;
0085     int  indexForCursorDateTime()                                               const;
0086     void setCurrentIndex(int index);
0087 
0088 Q_SIGNALS:
0089 
0090     void signalCursorPositionChanged();
0091     void signalSelectionChanged();
0092     void signalRefDateTimeChanged();
0093     void signalDateMapChanged();
0094 
0095 public Q_SLOTS:
0096 
0097     void slotDatesHash(const QHash<QDateTime, int>&);
0098     void slotPrevious();
0099     void slotNext();
0100     void slotBackward();
0101     void slotForward();
0102     void slotResetSelection();
0103 
0104 private Q_SLOTS:
0105 
0106     void slotThemeChanged();
0107 
0108 private:
0109 
0110     QDateTime     prevDateTime(const QDateTime& dt)                             const;
0111     QDateTime     nextDateTime(const QDateTime& dt)                             const;
0112 
0113     int           maxCount()                                                    const;
0114     int           indexForDateTime(const QDateTime& date)                       const;
0115     int           statForDateTime(const QDateTime& dt, SelectionMode& selected) const;
0116     void          setRefDateTime(const QDateTime& dateTime);
0117 
0118     void          paintEvent(QPaintEvent*)        override;
0119     void          wheelEvent(QWheelEvent*)        override;
0120 
0121     void          mousePressEvent(QMouseEvent*)   override;
0122     void          mouseMoveEvent(QMouseEvent*)    override;
0123     void          mouseReleaseEvent(QMouseEvent*) override;
0124 
0125     void          keyPressEvent(QKeyEvent *e)     override;
0126     void          keyReleaseEvent(QKeyEvent *)    override;
0127     void          keyScroll(bool isScrollNext);
0128 
0129     QDateTime     dateTimeForPoint(const QPoint& pt,
0130                                    bool& isOnSelectionArea);
0131     QDateTime     firstDayOfWeek(int year, int weekNumber)                      const;
0132 
0133     void          resetSelection();
0134     void          setDateTimeSelected(const QDateTime& dt,
0135                                       SelectionMode selected);
0136     void          setDaysRangeSelection(const QDateTime& dts,
0137                                         const QDateTime& dte,
0138                                         SelectionMode selected);
0139     SelectionMode checkSelectionForDaysRange(const QDateTime& dts,
0140                                              const QDateTime& dte)              const;
0141     void          updateWeekSelection(const QDateTime& dts,
0142                                       const QDateTime& dte);
0143     void          updateMonthSelection(const QDateTime& dts,
0144                                        const QDateTime& dte);
0145     void          updateYearSelection(const QDateTime& dts,
0146                                       const QDateTime& dte);
0147     void          updateAllSelection();
0148 
0149     /**
0150      * helper methods for painting
0151      */
0152     int           calculateTop(int& val)                                        const;
0153     void          paintItem(QPainter& p,
0154                             const QRect& barRect,
0155                             const QDateTime& ref,
0156                             const int& separatorPosition,
0157                             const QColor& dateColor,
0158                             const QColor& subDateColor);
0159 
0160     void          handleSelectionRange(const QDateTime& selEndDateTime);
0161 
0162 private:
0163 
0164     class Private;
0165     Private* const d;
0166 };
0167 
0168 } // namespace Digikam
0169 
0170 #endif // DIGIKAM_TIME_LINE_WIDGET_H