File indexing completed on 2024-04-28 04:20:56
0001 // SPDX-FileCopyrightText: 2003-2022 Jesper K. Pedersen <blackie@kde.org> 0002 // SPDX-FileCopyrightText: 2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #ifndef DATEBARMOUSEHANDLER_H 0007 #define DATEBARMOUSEHANDLER_H 0008 0009 #include <DB/ImageDate.h> 0010 0011 #include <Utilities/FastDateTime.h> 0012 #include <QObject> 0013 0014 namespace DB 0015 { 0016 class ImageDate; 0017 } 0018 0019 class QTimer; 0020 namespace DateBar 0021 { 0022 class DateBarWidget; 0023 0024 class MouseHandler : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 explicit MouseHandler(DateBarWidget *dateBar); 0029 virtual void mousePressEvent(int x) = 0; 0030 virtual void mouseMoveEvent(int x) = 0; 0031 virtual void mouseReleaseEvent() {}; 0032 void startAutoScroll(); 0033 void endAutoScroll(); 0034 0035 protected Q_SLOTS: 0036 void autoScroll(); 0037 0038 protected: 0039 DateBarWidget *m_dateBar; 0040 0041 private: 0042 QTimer *m_autoScrollTimer; 0043 }; 0044 0045 /** 0046 * @brief The FocusItemDragHandler class handles mouse events for the histogram part of the DateBar. 0047 * I.e. the user clicks on the histogram part of the DateBar to jump to the corresponding date/time. 0048 */ 0049 class FocusItemDragHandler : public MouseHandler 0050 { 0051 public: 0052 explicit FocusItemDragHandler(DateBarWidget *dateBar); 0053 void mousePressEvent(int x) override; 0054 void mouseMoveEvent(int x) override; 0055 }; 0056 0057 /** 0058 * @brief The BarDragHandler class handles moving the DateBar histogram by dragging it. 0059 * If a time range selection was set (by the SelectionHandler) and the user clicks outside that range, the selection is cleared. 0060 */ 0061 class BarDragHandler : public MouseHandler 0062 { 0063 public: 0064 explicit BarDragHandler(DateBarWidget *); 0065 void mousePressEvent(int x) override; 0066 void mouseMoveEvent(int x) override; 0067 0068 private: 0069 int m_movementOffset; 0070 }; 0071 0072 /** 0073 * @brief The SelectionHandler class handles mouse events for the area below the DateBar histogram. 0074 * I.e. the user clicks somewhere in the area below the histogram part of the DateBar and selects a time range by dragging the mouse. 0075 * When the user releases the mouse button, the selection is updated to the selected area. 0076 */ 0077 class SelectionHandler : public MouseHandler 0078 { 0079 public: 0080 explicit SelectionHandler(DateBarWidget *); 0081 void mousePressEvent(int x) override; 0082 void mouseMoveEvent(int x) override; 0083 void mouseReleaseEvent() override; 0084 Utilities::FastDateTime min() const; 0085 Utilities::FastDateTime max() const; 0086 DB::ImageDate dateRange() const; 0087 void clearSelection(); 0088 bool hasSelection() const; 0089 /** 0090 * @brief setOrExtendSelection extends the selection to the given date. 0091 * If the SelectionHandler does not currently have a selection, it selects the unit corrensponding to the date. 0092 * @param date a valid FastDateTime 0093 */ 0094 void setOrExtendSelection(const Utilities::FastDateTime &date); 0095 0096 private: 0097 Utilities::FastDateTime m_start; 0098 Utilities::FastDateTime m_end; 0099 }; 0100 } 0101 0102 #endif /* DATEBARMOUSEHANDLER_H */ 0103 0104 // vi:expandtab:tabstop=4 shiftwidth=4: