File indexing completed on 2024-05-12 17:07:09

0001 /*
0002     SPDX-FileCopyrightText: 1998 Luca Montecchiani <m.luca@usa.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #pragma once
0007 
0008 #include "ui_dateandtime.h"
0009 
0010 #include <QCheckBox>
0011 #include <QComboBox>
0012 #include <QPaintEvent>
0013 #include <QSpinBox>
0014 #include <QTime>
0015 #include <QTimer>
0016 #include <QWidget>
0017 
0018 #include <KDatePicker>
0019 
0020 class Kclock;
0021 class QTimeEdit;
0022 
0023 namespace Plasma
0024 {
0025 class Svg;
0026 }
0027 
0028 class Dtime : public QWidget, public Ui::DateAndTime
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit Dtime(QWidget *parent, bool haveTimedated);
0033 
0034     void processHelperErrors(int code);
0035     void load();
0036 
0037     QString selectedTimeZone() const;
0038     QStringList ntpServers() const;
0039     bool ntpEnabled() const;
0040     QDateTime userTime() const;
0041 
0042     QString quickHelp() const;
0043 
0044 Q_SIGNALS:
0045     void timeChanged(bool);
0046 
0047 private Q_SLOTS:
0048     void configChanged();
0049     void serverTimeCheck();
0050     void timeout();
0051     void set_time();
0052     void changeDate(const QDate &);
0053 
0054 private:
0055     void currentZone();
0056     void findNTPutility();
0057     QString ntpUtility;
0058 
0059     QTimeEdit *timeEdit;
0060 
0061     Kclock *kclock;
0062 
0063     QTime time;
0064     QDate date;
0065     QTimer internalTimer;
0066 
0067     QString timeServer;
0068     int BufI;
0069     bool refresh;
0070     bool ontimeout;
0071     bool m_haveTimedated;
0072 };
0073 
0074 class Kclock : public QWidget
0075 {
0076     Q_OBJECT
0077 
0078 public:
0079     Kclock(QWidget *parent = nullptr);
0080     ~Kclock() override;
0081 
0082     void setTime(const QTime &);
0083 
0084 protected:
0085     void paintEvent(QPaintEvent *event) override;
0086     void showEvent(QShowEvent *event) override;
0087     void resizeEvent(QResizeEvent *event) override;
0088 
0089 private:
0090     void setClockSize(const QSize &size);
0091     void drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName);
0092     void paintInterface(QPainter *p, const QRect &rect);
0093 
0094 private:
0095     QTime time;
0096     Plasma::Svg *m_theme;
0097     enum RepaintCache {
0098         RepaintNone,
0099         RepaintAll,
0100         RepaintHands,
0101     };
0102     RepaintCache m_repaintCache;
0103     QPixmap m_faceCache;
0104     QPixmap m_handsCache;
0105     QPixmap m_glassCache;
0106     qreal m_verticalTranslation;
0107 };