File indexing completed on 2024-04-28 04:03:11
0001 /* 0002 This file is part of Knights, a chess board for KDE SC 4. 0003 SPDX-FileCopyrightText: 2010, 2011 Miha Čančula <miha@noughmad.eu> 0004 0005 Plasma analog-clock drawing code: 0006 SPDX-FileCopyrightText: 2007 Aaron Seigo <aseigo@kde.org> 0007 SPDX-FileCopyrightText: 2007 Riccardo Iaconelli <riccardo@kde.org> 0008 0009 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0010 */ 0011 0012 #ifndef KNIGHTS_CLOCK_H 0013 #define KNIGHTS_CLOCK_H 0014 0015 #include <QWidget> 0016 #include <QTime> 0017 0018 namespace KSvg { 0019 class Svg; 0020 } 0021 0022 namespace Knights { 0023 /** 0024 * This class is copied from the Date and Time KCM. 0025 * See https://invent.kde.org/plasma/plasma-desktop/-/blob/master/kcms/dateandtime/dtime.h 0026 * 0027 * Note that this is a chess clock, which is set to negative time before a match, so all angles are reversed. 0028 * See paintInterface for details. 0029 */ 0030 class Clock : public QWidget { 0031 Q_OBJECT 0032 0033 public: 0034 explicit Clock( QWidget* parent = nullptr); 0035 ~Clock() override; 0036 0037 void setTime(const QTime&); 0038 void setTime(int miliSeconds); 0039 0040 protected: 0041 void paintEvent( QPaintEvent *event ) override; 0042 void showEvent( QShowEvent *event ) override; 0043 void resizeEvent( QResizeEvent *event ) override; 0044 0045 private: 0046 void setClockSize(const QSize &size); 0047 void drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName); 0048 void paintInterface(QPainter *p, const QRect &rect); 0049 0050 QTime time; 0051 KSvg::Svg *m_theme; 0052 enum RepaintCache { 0053 RepaintNone, 0054 RepaintAll, 0055 RepaintHands 0056 }; 0057 RepaintCache m_repaintCache; 0058 QPixmap m_faceCache; 0059 QPixmap m_handsCache; 0060 QPixmap m_glassCache; 0061 qreal m_verticalTranslation; 0062 }; 0063 0064 } 0065 0066 #endif // KNIGHTS_CLOCK_H