File indexing completed on 2024-05-05 05:54:32
0001 /* 0002 SPDX-FileCopyrightText: 2014 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef TIMEDISPLAY_H 0008 #define TIMEDISPLAY_H 0009 0010 #include "ui_timedisplay.h" 0011 #include "timeformat.h" 0012 0013 #include <QTime> 0014 #include <QWidget> 0015 0016 class DigitDisplay; 0017 0018 class QGroupBox; 0019 0020 /** 0021 * @brief A custom widget displaying a QTime 0022 * This custom widget implements a "digital" display for a time, formatted according to a certain format. 0023 * This widget can be connected to a generic "time source" producing the time to be displayed. 0024 */ 0025 class TimeDisplay : public QWidget, public Ui::TimeDisplay 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 0031 explicit TimeDisplay(QWidget *parent = nullptr); 0032 0033 /** 0034 * Set the internal time format of the display 0035 * @param format The format to be used as time format. 0036 */ 0037 void setTimeFormat(const TimeFormat& format); 0038 0039 /** 0040 * Set a custom font for hours 0041 * @param font The custom font to set. 0042 */ 0043 void setHoursFont(const QFont& font); 0044 0045 /** 0046 * Set a custom font for minutes 0047 * @param font The custom font to set. 0048 */ 0049 void setMinutesFont(const QFont& font); 0050 0051 /** 0052 * Set a custom font for seconds 0053 * @param font The custom font to set. 0054 */ 0055 void setSecondsFont(const QFont& font); 0056 0057 /** 0058 * Set a custom font for second fractions 0059 * @param font The custom font to set. 0060 */ 0061 void setFractionsFont(const QFont& font); 0062 0063 /** 0064 * Set a custom color for display background. 0065 * @param color The custom color to set. 0066 */ 0067 void setBackgroundColor(const QColor& color); 0068 0069 /** 0070 * Set a custom color for display fonts. 0071 * @param color The custom color to set. 0072 */ 0073 void setTextColor(const QColor& color); 0074 0075 /** 0076 * Get the current time formatted with the current format. 0077 * @return Current time formatted as string. 0078 */ 0079 QString currentTime(); 0080 0081 public Q_SLOTS: 0082 0083 /** 0084 * Set the time to be displayed. 0085 * @param time The time to be displayed. 0086 */ 0087 void setTime(int time); 0088 0089 /** 0090 * Reset the display to the default time format. The overridden format (if any) is lost. 0091 */ 0092 void reset(); 0093 0094 private: 0095 0096 static constexpr int MSECS_PER_HOUR = 3600000; 0097 static constexpr int MSECS_PER_MIN = 60000; 0098 static constexpr int MSECS_PER_SEC = 1000; 0099 static constexpr int SECS_PER_MIN = 60; 0100 0101 QTime m_displayTime = {0, 0}; /** Current display time */ 0102 TimeFormat m_currentFormat; /** Current display time format. */ 0103 TimeFormat m_defaultFormat; /** Default time format, to be restored on reset. */ 0104 0105 /** 0106 * Refresh the labels text implementing the display timer 0107 */ 0108 void updateTimer(); 0109 0110 /** 0111 * Refresh the minimum width of the frames, based on current font sizes 0112 */ 0113 void updateWidth(); 0114 0115 /** 0116 * Helper function, called when setting and overriding the time format. 0117 */ 0118 void updateTimeFormat(); 0119 0120 /** 0121 * Helper function, called to set frame colors. 0122 */ 0123 void setGroupboxColor(QGroupBox *groupBox, QPalette::ColorRole role, const QColor& color); 0124 0125 Q_DISABLE_COPY(TimeDisplay) 0126 }; 0127 0128 #endif