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 
11 #include "mythcorecontext.h"
12 #include "mythlogging.h"
13 #include "mythdate.h"
14 #include "mythdb.h"
15 
16 MythUIClock::MythUIClock(MythUIType *parent, const QString &name)
17  : MythUIText(parent, name)
18 {
19  m_dateFormat = GetMythDB()->GetSetting("DateFormat", "ddd d MMM yyyy");
20  m_shortDateFormat = GetMythDB()->GetSetting("ShortDateFormat", "ddd M/d");
21  m_timeFormat = GetMythDB()->GetSetting("TimeFormat", "h:mm ap");
22 
23  m_format = QString("%1, %2").arg(m_dateFormat).arg(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  m_nextUpdate = QDateTime(m_time.date(),
59  m_time.time().addMSecs(m_time.time().msec()),
60  Qt::UTC);
61 
62  return newMsg;
63 }
64 
68 void MythUIClock::SetText(const QString &text)
69 {
70  QString txt = text;
71 
72  if (txt.isEmpty())
73  {
75  txt = GetTimeText();
76  }
77 
79 }
80 
85  const QString &filename, QDomElement &element, bool showWarnings)
86 {
87  if (element.tagName() == "format" ||
88  element.tagName() == "template")
89  {
90  QString format = parseText(element);
91  format = QCoreApplication::translate("ThemeUI", format.toUtf8());
92  format.replace("%TIME%", m_timeFormat, Qt::CaseInsensitive);
93  format.replace("%DATE%", m_dateFormat, Qt::CaseInsensitive);
94  format.replace("%SHORTDATE%", m_shortDateFormat, Qt::CaseInsensitive);
95  m_format = format;
96  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
97  }
98  else
99  {
100  m_message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_format);
101  return MythUIText::ParseElement(filename, element, showWarnings);
102  }
103 
104  return true;
105 }
106 
111 {
112  auto *clock = dynamic_cast<MythUIClock *>(base);
113 
114  if (!clock)
115  {
116  LOG(VB_GENERAL, LOG_ERR, "ERROR, bad parsing");
117  return;
118  }
119 
120  m_time = clock->m_time;
121  m_nextUpdate = clock->m_nextUpdate;
122 
123  m_format = clock->m_format;
124  m_timeFormat = clock->m_timeFormat;
125  m_dateFormat = clock->m_dateFormat;
126  m_shortDateFormat = clock->m_shortDateFormat;
127 
128  m_flash = clock->m_flash;
129 
130  MythUIText::CopyFrom(base);
131 }
132 
137 {
138  auto *clock = new MythUIClock(parent, objectName());
139  clock->CopyFrom(this);
140 }
MythUIClock::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiclock.cpp:110
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:1600
MythUIClock::MythUIClock
MythUIClock(MythUIType *parent, const QString &name)
Definition: mythuiclock.cpp:16
MythUIClock::~MythUIClock
~MythUIClock() override
Definition: mythuiclock.cpp:26
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:46
MythUIClock::m_time
QDateTime m_time
Definition: mythuiclock.h:42
MythUIClock
A simple text clock widget.
Definition: mythuiclock.h:26
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:10
mythuiclock.h
XMLParseBase::parseText
static QString parseText(QDomElement &element)
Definition: xmlparsebase.cpp:324
mythdate.h
mythfontproperties.h
mythlogging.h
MythCoreContext::GetQLocale
QLocale GetQLocale(void)
Definition: mythcorecontext.cpp:1854
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:84
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
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
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:1381
mythpainter.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:64
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
mythcorecontext.h
MythDB::GetSetting
QString GetSetting(const QString &_key, const QString &defaultval)
Definition: mythdb.cpp:370
MythUIText::m_font
MythFontProperties * m_font
Definition: mythuitext.h:138
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:134
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:136
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:68
MythUIText::Pulse
void Pulse(void) override
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitext.cpp:1191
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