File indexing completed on 2024-04-21 16:30:32

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2017 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef _ClockWidget_H_
0022 #define _ClockWidget_H_
0023 
0024 #include <QTimer>
0025 #include <QLabel>
0026 #include <QFrame>
0027 #include <QCalendarWidget>
0028 
0029 #include <DesktopPanel.hxx>
0030 
0031 class CalendarPopup : public QFrame
0032 {
0033   Q_OBJECT
0034 
0035   public:
0036     CalendarPopup(QWidget *parent);
0037 
0038   protected:
0039     void showEvent(QShowEvent *event) override;
0040     void hideEvent(QHideEvent *event) override;
0041 
0042   public Q_SLOTS:
0043     void goToday();
0044 
0045   private Q_SLOTS:
0046     void tick();
0047 
0048   private:
0049     QCalendarWidget *cal;
0050     QTimer timer;
0051     QLabel *timeLabel;
0052     QLabel *dateLabel;
0053 };
0054 
0055 //--------------------------------------------------------------------------------
0056 
0057 class ClockWidget : public QFrame
0058 {
0059   Q_OBJECT
0060   Q_PROPERTY(QString timeFormat MEMBER timeFormat)
0061   Q_PROPERTY(QString dayFormat  MEMBER dayFormat)
0062   Q_PROPERTY(QString dateFormat MEMBER dateFormat)
0063 
0064   public:
0065     ClockWidget(DesktopPanel *parent);
0066 
0067   protected:
0068     void mousePressEvent(QMouseEvent *event) override;
0069 
0070   private Q_SLOTS:
0071     void fill();
0072     void tick();
0073 
0074   private:
0075     QTimer *timer;
0076     QLabel *timeLabel, *dayLabel, *dateLabel;
0077     CalendarPopup *calendar;
0078 
0079     QString timeFormat;
0080     QString dayFormat  = QStringLiteral("ddd");
0081     QString dateFormat = QStringLiteral("d.MMM yyyy");
0082 
0083     QVector<QByteArray> timeZoneIds;
0084 };
0085 
0086 #endif