MythTV  master
mythuiclock.cpp
Go to the documentation of this file.
1 
2 #include "mythuiclock.h"
3 
4 #include <QCoreApplication>
5 #include <QDomDocument>
6 #include <QTimeZone>
7 
8 #include "mythpainter.h"
9 #include "mythmainwindow.h"
10 #include "mythfontproperties.h"
11 
13 #include "libmythbase/mythdate.h"
14 #include "libmythbase/mythdb.h"
16 
17 MythUIClock::MythUIClock(MythUIType *parent, const QString &name)
18  : MythUIText(parent, name),
19  m_timeFormat(GetMythDB()->GetSetting("TimeFormat", "h:mm ap")),
20  m_dateFormat(GetMythDB()->GetSetting("DateFormat", "ddd d MMM yyyy")),
21  m_shortDateFormat(GetMythDB()->GetSetting("ShortDateFormat", "ddd M/d"))
22 {
23  m_format = QString("%1, %2").arg(m_dateFormat, m_timeFormat);
24 }
25 
27 {
28  delete m_font;
29  m_font = nullptr;
30 }
31 
36 {
38 
39  if (m_nextUpdate.isNull() || (m_time >= m_nextUpdate))
41 
43 }
44 
53 {
54  QDateTime dt = m_time.toLocalTime();
55  QString newMsg = gCoreContext->GetQLocale().toString(dt, m_format);
56 
57  m_nextUpdate = m_time.addSecs(1);
58 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
59  m_nextUpdate = QDateTime(m_time.date(),
60  m_time.time().addMSecs(m_time.time().msec()),
61  Qt::UTC);
62 #else
63  m_nextUpdate = QDateTime(m_time.date(),
64  m_time.time().addMSecs(m_time.time().msec()),
65  QTimeZone(QTimeZone::UTC));
66 #endif
67 
68  return newMsg;
69 }
70 
74 void MythUIClock::SetText(const QString &text)
75 {
76  QString txt = text;
77 
78  if (txt.isEmpty())
79  {
81  txt = GetTimeText();
82  }
83 
85 }
86 
91  const QString &filename, QDomElement &element, bool showWarnings)
92 {
93  if (element.tagName() == "format" ||
94  element.tagName() == "template")
95  {
96  QString format = parseText(element);
97  format = QCoreApplication::translate("ThemeUI", format.toUtf8());
98  format.replace("%TIME%", m_timeFormat, Qt::CaseInsensitive);
99  format.replace("%DATE%", m_dateFormat, Qt::CaseInsensitive);
100  format.replace("%SHORTDATE%", m_shortDateFormat, Qt::CaseInsensitive);
101  m_format = format;
102  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
103  }
104  else
105  {
106  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
107  return MythUIText::ParseElement(filename, element, showWarnings);
108  }
109 
110  return true;
111 }
112 
117 {
118  auto *clock = dynamic_cast<MythUIClock *>(base);
119 
120  if (!clock)
121  {
122  LOG(VB_GENERAL, LOG_ERR, "ERROR, bad parsing");
123  return;
124  }
125 
126  m_time = clock->m_time;
127  m_nextUpdate = clock->m_nextUpdate;
128 
129  m_format = clock->m_format;
130  m_timeFormat = clock->m_timeFormat;
131  m_dateFormat = clock->m_dateFormat;
132  m_shortDateFormat = clock->m_shortDateFormat;
133 
134  m_flash = clock->m_flash;
135 
136  MythUIText::CopyFrom(base);
137 }
138 
143 {
144  auto *clock = new MythUIClock(parent, objectName());
145  clock->CopyFrom(this);
146 }
MythUIClock::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiclock.cpp:116
MythUIClock::m_format
QString m_format
Definition: mythuiclock.h:45
mythdb.h
MythUIClock::m_shortDateFormat
QString m_shortDateFormat
Definition: mythuiclock.h:48
MythUIText::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuitext.cpp:1590
MythUIClock::MythUIClock
MythUIClock(MythUIType *parent, const QString &name)
Definition: mythuiclock.cpp:17
MythUIClock::~MythUIClock
~MythUIClock() override
Definition: mythuiclock.cpp:26
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:50
MythUIClock::m_time
QDateTime m_time
Definition: mythuiclock.h:42
MythUIClock
A simple text clock widget.
Definition: mythuiclock.h:25
MythUIText::m_message
QString m_message
Definition: mythuitext.h:116
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
mythuiclock.h
XMLParseBase::parseText
static QString parseText(QDomElement &element)
Definition: xmlparsebase.cpp:315
mythdate.h
mythfontproperties.h
mythlogging.h
MythCoreContext::GetQLocale
QLocale GetQLocale(void)
Definition: mythcorecontext.cpp:1882
MythUIClock::ParseElement
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
Definition: mythuiclock.cpp:90
MythUIClock::GetTimeText
QString GetTimeText(void)
This creates a string based on m_time, and sets m_nextUpdate to the second following m_time.
Definition: mythuiclock.cpp:52
MythUIText::ParseElement
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
Definition: mythuitext.cpp:1374
mythpainter.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:85
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
mythcorecontext.h
MythUIText::m_font
MythFontProperties * m_font
Definition: mythuitext.h:138
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
MythUIClock::m_flash
bool m_flash
Definition: mythuiclock.h:50
MythUIClock::m_nextUpdate
QDateTime m_nextUpdate
Definition: mythuiclock.h:43
MythUIClock::CreateCopy
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
Definition: mythuiclock.cpp:142
MythUIClock::SetText
void SetText(const QString &text) override
This sets the text, unless the string is blank, in that case the time is looked up and set as the tex...
Definition: mythuiclock.cpp:74
MythUIText::Pulse
void Pulse(void) override
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitext.cpp:1165
build_compdb.filename
filename
Definition: build_compdb.py:21
MythUIClock::Pulse
void Pulse(void) override
Looks up the time and sets the clock if the current time is greater than or equal to m_nextUpdate.
Definition: mythuiclock.cpp:35
mythmainwindow.h
MythUIClock::m_dateFormat
QString m_dateFormat
Definition: mythuiclock.h:47
MythUIClock::m_timeFormat
QString m_timeFormat
Definition: mythuiclock.h:46