1 /*
2   SPDX-FileCopyrightText: 2000, 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
3   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
4   SPDX-FileCopyrightText: 2007 Bruno Virlet <bruno@virlet.org>
5 
6   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
7 */
8 #pragma once
9 
10 #include <QTimeZone>
11 
12 #include <QFrame>
13 
14 namespace EventViews
15 {
16 class Agenda;
17 class TimeLabelsZone;
18 
19 class Prefs;
20 using PrefsPtr = QSharedPointer<Prefs>;
21 
22 class TimeLabels : public QWidget
23 {
24     Q_OBJECT
25 public:
26     using List = QList<TimeLabels *>;
27 
28     TimeLabels(const QTimeZone &zone, int rows, TimeLabelsZone *parent = nullptr, Qt::WindowFlags f = {});
29 
30     /** updates widget's internal state */
31     void updateConfig();
32 
33     /**  */
34     void setAgenda(Agenda *agenda);
35 
36     /**  */
37     void paintEvent(QPaintEvent *e) override;
38 
39     /** */
40     void contextMenuEvent(QContextMenuEvent *event) override;
41 
42     /** Returns the time zone of this label */
43     Q_REQUIRED_RESULT QTimeZone timeZone() const;
44 
45     /**
46       Return string which can be used as a header for the time label.
47     */
48     Q_REQUIRED_RESULT QString header() const;
49 
50     /**
51       Return string which can be used as a tool tip for the header.
52     */
53     Q_REQUIRED_RESULT QString headerToolTip() const;
54 
55     QSize sizeHint() const override;
56 
57     QSize minimumSizeHint() const override;
58 
59     /** */
60     bool event(QEvent *event) override;
61 
62 private:
63     Q_REQUIRED_RESULT int yposToCell(const int ypos) const;
64     Q_REQUIRED_RESULT int cellToHour(const int cell) const;
65     Q_REQUIRED_RESULT QString cellToSuffix(const int cell) const;
66 
67     /** update the position of the marker showing the mouse position */
68     void mousePosChanged(QPoint pos);
69 
70     void showMousePos();
71     void hideMousePos();
72 
73     void setCellHeight(double height);
74     void colorMousePos();
75     const QTimeZone mTimezone;
76     int mRows;
77     double mCellHeight;
78     int mMiniWidth;
79     Agenda *mAgenda = nullptr;
80     TimeLabelsZone *mTimeLabelsZone = nullptr;
81 
82     QFrame *mMousePos = nullptr; // shows a marker for the current mouse position in y direction
83 };
84 }
85 
86