Warning, file /utilities/kronometer/src/gui/timedisplay.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 Copyright (C) 2014 by Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 This file is part of Kronometer. 0005 0006 Kronometer is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 2 of the License, or 0009 (at your option) any later version. 0010 0011 Kronometer is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with Kronometer. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef TIMEDISPLAY_H 0021 #define TIMEDISPLAY_H 0022 0023 #include "ui_timedisplay.h" 0024 #include "timeformat.h" 0025 0026 #include <QTime> 0027 #include <QWidget> 0028 0029 class DigitDisplay; 0030 0031 class QGroupBox; 0032 0033 /** 0034 * @brief A custom widget displaying a QTime 0035 * This custom widget implements a "digital" display for a time, formatted according to a certain format. 0036 * This widget can be connected to a generic "time source" producing the time to be displayed. 0037 */ 0038 class TimeDisplay : public QWidget, public Ui::TimeDisplay 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 0044 explicit TimeDisplay(QWidget *parent = nullptr); 0045 0046 /** 0047 * Set the internal time format of the display 0048 * @param format The format to be used as time format. 0049 */ 0050 void setTimeFormat(const TimeFormat& format); 0051 0052 /** 0053 * Set a custom font for hours 0054 * @param font The custom font to set. 0055 */ 0056 void setHoursFont(const QFont& font); 0057 0058 /** 0059 * Set a custom font for minutes 0060 * @param font The custom font to set. 0061 */ 0062 void setMinutesFont(const QFont& font); 0063 0064 /** 0065 * Set a custom font for seconds 0066 * @param font The custom font to set. 0067 */ 0068 void setSecondsFont(const QFont& font); 0069 0070 /** 0071 * Set a custom font for second fractions 0072 * @param font The custom font to set. 0073 */ 0074 void setFractionsFont(const QFont& font); 0075 0076 /** 0077 * Set a custom color for display background. 0078 * @param color The custom color to set. 0079 */ 0080 void setBackgroundColor(const QColor& color); 0081 0082 /** 0083 * Set a custom color for display fonts. 0084 * @param color The custom color to set. 0085 */ 0086 void setTextColor(const QColor& color); 0087 0088 /** 0089 * Get the current time formatted with the current format. 0090 * @return Current time formatted as string. 0091 */ 0092 QString currentTime(); 0093 0094 public slots: 0095 0096 /** 0097 * Set the time to be displayed. 0098 * @param time The time to be displayed. 0099 */ 0100 void setTime(int time); 0101 0102 /** 0103 * Reset the display to the default time format. The overridden format (if any) is lost. 0104 */ 0105 void reset(); 0106 0107 private: 0108 0109 static constexpr int MSECS_PER_HOUR = 3600000; 0110 static constexpr int MSECS_PER_MIN = 60000; 0111 static constexpr int MSECS_PER_SEC = 1000; 0112 static constexpr int SECS_PER_MIN = 60; 0113 0114 QTime m_displayTime = {0, 0}; /** Current display time */ 0115 TimeFormat m_currentFormat; /** Current display time format. */ 0116 TimeFormat m_defaultFormat; /** Default time format, to be restored on reset. */ 0117 0118 /** 0119 * Refresh the labels text implementing the display timer 0120 */ 0121 void updateTimer(); 0122 0123 /** 0124 * Refresh the minimum width of the frames, based on current font sizes 0125 */ 0126 void updateWidth(); 0127 0128 /** 0129 * Helper function, called when setting and overriding the time format. 0130 */ 0131 void updateTimeFormat(); 0132 0133 /** 0134 * Helper function, called to set frame colors. 0135 */ 0136 void setGroupboxColor(QGroupBox *groupBox, QPalette::ColorRole role, const QColor& color); 0137 0138 Q_DISABLE_COPY(TimeDisplay) 0139 }; 0140 0141 #endif