File indexing completed on 2024-05-12 05:35:39

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 KSvg
0024 {
0025 class Svg;
0026 class ImageSet;
0027 }
0028 
0029 class Dtime : public QWidget, public Ui::DateAndTime
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit Dtime(QWidget *parent, bool haveTimedated);
0034 
0035     void processHelperErrors(int code);
0036     void load();
0037 
0038     QString selectedTimeZone() const;
0039     QStringList ntpServers() const;
0040     bool ntpEnabled() const;
0041     QDateTime userTime() const;
0042 
0043     QString quickHelp() const;
0044 
0045 Q_SIGNALS:
0046     void timeChanged(bool);
0047 
0048 private Q_SLOTS:
0049     void configChanged();
0050     void serverTimeCheck();
0051     void timeout();
0052     void set_time();
0053     void changeDate(const QDate &);
0054 
0055 private:
0056     void currentZone();
0057     void findNTPutility();
0058     QString ntpUtility;
0059 
0060     QTimeEdit *timeEdit;
0061 
0062     Kclock *kclock;
0063 
0064     QTime time;
0065     QDate date;
0066     QTimer internalTimer;
0067 
0068     QString timeServer;
0069     int BufI;
0070     bool refresh;
0071     bool ontimeout;
0072     bool m_haveTimedated;
0073 };
0074 
0075 class Kclock : public QWidget
0076 {
0077     Q_OBJECT
0078 
0079 public:
0080     Kclock(QWidget *parent = nullptr);
0081     ~Kclock() override;
0082 
0083     void setTime(const QTime &);
0084 
0085 protected:
0086     void paintEvent(QPaintEvent *event) override;
0087     void showEvent(QShowEvent *event) override;
0088     void resizeEvent(QResizeEvent *event) override;
0089     bool event(QEvent *event) override;
0090 
0091 private:
0092     void setClockSize(const QSize &size);
0093     void drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName);
0094     void paintInterface(QPainter *p, const QRect &rect);
0095 
0096 private:
0097     QTime time;
0098     KSvg::ImageSet *m_imageSet;
0099     KSvg::Svg *m_theme;
0100     enum RepaintCache {
0101         RepaintNone,
0102         RepaintAll,
0103         RepaintHands,
0104     };
0105     RepaintCache m_repaintCache;
0106     QPixmap m_faceCache;
0107     QPixmap m_handsCache;
0108     QPixmap m_glassCache;
0109     qreal m_verticalTranslation;
0110 };