MythTV  master
mythuiclock.cpp
Go to the documentation of this file.
1 
2 #include "mythuiclock.h"
3 
4 #include <QCoreApplication>
5 #include <QDomDocument>
6 
7 #include "mythpainter.h"
8 #include "mythmainwindow.h"
9 #include "mythfontproperties.h"
10 
12 #include "libmythbase/mythdate.h"
13 #include "libmythbase/mythdb.h"
15 
16 MythUIClock::MythUIClock(MythUIType *parent, const QString &name)
17  : MythUIText(parent, name),
18  m_timeFormat(GetMythDB()->GetSetting("TimeFormat", "h:mm ap")),
19  m_dateFormat(GetMythDB()->GetSetting("DateFormat", "ddd d MMM yyyy")),
20  m_shortDateFormat(GetMythDB()->GetSetting("ShortDateFormat", "ddd M/d"))
21 {
22  m_format = QString("%1, %2").arg(m_dateFormat, m_timeFormat);
23 }
24 
26 {
27  delete m_font;
28  m_font = nullptr;
29 }
30 
35 {
37 
38  if (m_nextUpdate.isNull() || (m_time >= m_nextUpdate))
40 
42 }
43 
52 {
53  QDateTime dt = m_time.toLocalTime();
54  QString newMsg = gCoreContext->GetQLocale().toString(dt, m_format);
55 
56  m_nextUpdate = m_time.addSecs(1);
57  m_nextUpdate = QDateTime(m_time.date(),
58  m_time.time().addMSecs(m_time.time().msec()),
59  Qt::UTC);
60 
61  return newMsg;
62 }
63 
67 void MythUIClock::SetText(const QString &text)
68 {
69  QString txt = text;
70 
71  if (txt.isEmpty())
72  {
74  txt = GetTimeText();
75  }
76 
78 }
79 
84  const QString &filename, QDomElement &element, bool showWarnings)
85 {
86  if (element.tagName() == "format" ||
87  element.tagName() == "template")
88  {
89  QString format = parseText(element);
90  format = QCoreApplication::translate("ThemeUI", format.toUtf8());
91  format.replace("%TIME%", m_timeFormat, Qt::CaseInsensitive);
92  format.replace("%DATE%", m_dateFormat, Qt::CaseInsensitive);
93  format.replace("%SHORTDATE%", m_shortDateFormat, Qt::CaseInsensitive);
94  m_format = format;
95  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
96  }
97  else
98  {
99  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
100  return MythUIText::ParseElement(filename, element, showWarnings);
101  }
102 
103  return true;
104 }
105 
110 {
111  auto *clock = dynamic_cast<MythUIClock *>(base);
112 
113  if (!clock)
114  {
115  LOG(VB_GENERAL, LOG_ERR, "ERROR, bad parsing");
116  return;
117  }
118 
119  m_time = clock->m_time;
120  m_nextUpdate = clock->m_nextUpdate;
121 
122  m_format = clock->m_format;
123  m_timeFormat = clock->m_timeFormat;
124  m_dateFormat = clock->m_dateFormat;
125  m_shortDateFormat = clock->m_shortDateFormat;
126 
127  m_flash = clock->m_flash;
128 
129  MythUIText::CopyFrom(base);
130 }
131 
136 {
137  auto *clock = new MythUIClock(parent, objectName());
138  clock->CopyFrom(this);
139 }
MythUIClock::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiclock.cpp:109
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:1592
MythUIClock::MythUIClock
MythUIClock(MythUIType *parent, const QString &name)
Definition: mythuiclock.cpp:16
MythUIClock::~MythUIClock
~MythUIClock() override
Definition: mythuiclock.cpp:25
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:14
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:1874
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:83
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:51
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:1380
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:132
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:135
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:67
MythUIText::Pulse
void Pulse(void) override
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitext.cpp:1179
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:34
mythmainwindow.h
MythUIClock::m_dateFormat
QString m_dateFormat
Definition: mythuiclock.h:47
MythUIClock::m_timeFormat
QString m_timeFormat
Definition: mythuiclock.h:46