1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2  * (c)LGPL2+
3  *
4  * LXQt - a lightweight, Qt based, desktop toolset
5  * https://lxqt.org
6  *
7  * Copyright: 2012-2013 Razor team
8  *            2014 LXQt team
9  * Authors:
10  *   Kuzma Shapran <kuzma.shapran@gmail.com>
11  *
12  * This program or library is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21 
22  * You should have received a copy of the GNU Lesser General
23  * Public License along with this library; if not, write to the
24  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  * Boston, MA 02110-1301 USA
26  *
27  * END_COMMON_COPYRIGHT_HEADER */
28 
29 #ifndef LXQT_PANEL_WORLDCLOCK_H
30 #define LXQT_PANEL_WORLDCLOCK_H
31 
32 #include <QTimeZone>
33 
34 #include <QDialog>
35 #include <QLabel>
36 
37 
38 #include <LXQt/RotatedWidget>
39 
40 #include "../panel/ilxqtpanelplugin.h"
41 #include "lxqtworldclockconfiguration.h"
42 
43 
44 class ActiveLabel;
45 class QTimer;
46 class LXQtWorldClockPopup;
47 
48 
49 class LXQtWorldClock : public QObject, public ILXQtPanelPlugin
50 {
51     Q_OBJECT
52 public:
53     LXQtWorldClock(const ILXQtPanelPluginStartupInfo &startupInfo);
54     ~LXQtWorldClock();
55 
widget()56     virtual QWidget *widget() { return mMainWidget; }
themeId()57     virtual QString themeId() const { return QLatin1String("WorldClock"); }
flags()58     virtual ILXQtPanelPlugin::Flags flags() const { return PreferRightAlignment | HaveConfigDialog ; }
isSeparate()59     bool isSeparate() const { return true; }
60     void activated(ActivationReason reason);
61 
62     virtual void settingsChanged();
63     virtual void realign();
64     QDialog *configureDialog();
65     bool eventFilter(QObject * watched, QEvent * event);
66 
67 private slots:
68     void timeout();
69     void wheelScrolled(int);
70     void deletePopup();
71     void updateTimeText();
72 
73 private:
74     QWidget *mMainWidget;
75     LXQt::RotatedWidget* mRotatedWidget;
76     ActiveLabel *mContent;
77     LXQtWorldClockPopup* mPopup;
78 
79     QTimer *mTimer;
80     int mUpdateInterval;
81 
82     QStringList mTimeZones;
83     QMap<QString, QString> mTimeZoneCustomNames;
84     QString mDefaultTimeZone;
85     QString mActiveTimeZone;
86     QString mFormat;
87 
88     bool mAutoRotate;
89     bool mShowWeekNumber;
90     bool mShowTooltip;
91     QLabel *mPopupContent;
92 
93     QDateTime mShownTime;
94 
95     void restartTimer();
96 
97     void setTimeText();
98     QString formatDateTime(const QDateTime &datetime, const QString &timeZoneName);
99     void updatePopupContent();
100     bool formatHasTimeZone(QString format);
101     QString preformat(const QString &format, const QTimeZone &timeZone, const QDateTime& dateTime);
102 };
103 
104 
105 class ActiveLabel : public QLabel
106 {
107 Q_OBJECT
108 
109 public:
110     explicit ActiveLabel(QWidget * = nullptr);
111 
112 signals:
113     void wheelScrolled(int);
114     void leftMouseButtonClicked();
115     void middleMouseButtonClicked();
116 
117 protected:
118     void wheelEvent(QWheelEvent *);
119     void mouseReleaseEvent(QMouseEvent* event);
120 };
121 
122 class LXQtWorldClockPopup : public QDialog
123 {
124     Q_OBJECT
125 
126 public:
127     LXQtWorldClockPopup(QWidget *parent = nullptr);
128 
129     void show();
130 
131 signals:
132     void deactivated();
133 
134 protected:
135     virtual bool event(QEvent* );
136 
137 };
138 
139 class LXQtWorldClockLibrary: public QObject, public ILXQtPanelPluginLibrary
140 {
141     Q_OBJECT
142     Q_PLUGIN_METADATA(IID "lxqt.org/Panel/PluginInterface/3.0")
Q_INTERFACES(ILXQtPanelPluginLibrary)143     Q_INTERFACES(ILXQtPanelPluginLibrary)
144 public:
145     ILXQtPanelPlugin *instance(const ILXQtPanelPluginStartupInfo &startupInfo) const
146     {
147         return new LXQtWorldClock(startupInfo);
148     }
149 };
150 
151 #endif // LXQT_PANEL_WORLDCLOCK_H
152