00001 #include <qapplication.h>
00002
00003 #include "mythuiclock.h"
00004 #include "mythpainter.h"
00005 #include "mythmainwindow.h"
00006 #include "mythfontproperties.h"
00007
00008 #include "mythcontext.h"
00009
00010 MythUIClock::MythUIClock(MythUIType *parent, const char *name)
00011 : MythUIText(parent, name)
00012 {
00013 m_Time = QDateTime::currentDateTime();
00014 m_nextUpdate = m_Time.addSecs(1);
00015 m_Message = m_Time.toString(m_Format);
00016
00017 m_DateFormat = gContext->GetSetting("DateFormat", "ddd d MMMM");
00018 m_ShortDateFormat = gContext->GetSetting("ShortDateFormat", "ddd d");
00019 m_TimeFormat = gContext->GetSetting("TimeFormat", "hh:mm");
00020
00021 m_Format = QString("%1, %2").arg(m_DateFormat).arg(m_TimeFormat);
00022
00023 m_SecsFlash = false;
00024 m_Flash = false;
00025 }
00026
00027 MythUIClock::~MythUIClock()
00028 {
00029 if (m_Font)
00030 {
00031 delete m_Font;
00032 m_Font = NULL;
00033 }
00034 }
00035
00036 void MythUIClock::Pulse(void)
00037 {
00038 m_Time = QDateTime::currentDateTime();
00039
00040 if (m_Time > m_nextUpdate)
00041 {
00042 m_Message = m_Time.toString(m_Format);
00043 if (m_SecsFlash)
00044 {
00045 if (m_Flash)
00046 {
00047 m_Message.replace(":", " ");
00048 m_Message.replace(".", " ");
00049 m_Flash = false;
00050 }
00051 else
00052 m_Flash = true;
00053 }
00054
00055 m_CutMessage = "";
00056 SetRedraw();
00057 m_nextUpdate = m_Time.addSecs(1);
00058 }
00059
00060 MythUIText::Pulse();
00061 }
00062
00063 bool MythUIClock::ParseElement(QDomElement &element)
00064 {
00065 if (element.tagName() == "format")
00066 {
00067 QString format = getFirstText(element);
00068 format.replace("%TIME%", m_TimeFormat, false);
00069 format.replace("%DATE%", m_DateFormat, false);
00070 format.replace("%SHORTDATE%", m_ShortDateFormat, false);
00071 m_Format=format;
00072 }
00073 else if (element.tagName() == "secondflash")
00074 {
00075 QString flash = getFirstText(element);
00076 if (flash == "yes")
00077 {
00078 m_SecsFlash = true;
00079 }
00080 }
00081 else
00082 return MythUIText::ParseElement(element);
00083
00084 return true;
00085 }
00086
00087 void MythUIClock::CopyFrom(MythUIType *base)
00088 {
00089 MythUIClock *clock = dynamic_cast<MythUIClock *>(base);
00090 if (!clock)
00091 {
00092 VERBOSE(VB_IMPORTANT, "ERROR, bad parsing");
00093 return;
00094 }
00095
00096 m_Time = clock->m_Time;
00097 m_nextUpdate = clock->m_nextUpdate;
00098
00099 m_Format = clock->m_Format;
00100 m_TimeFormat = clock->m_TimeFormat;
00101 m_DateFormat = clock->m_DateFormat;
00102 m_ShortDateFormat = clock->m_ShortDateFormat;
00103
00104 m_SecsFlash = clock->m_SecsFlash;
00105 m_Flash = clock->m_Flash;
00106
00107 MythUIText::CopyFrom(base);
00108 }
00109
00110 void MythUIClock::CreateCopy(MythUIType *parent)
00111 {
00112 MythUIClock *clock = new MythUIClock(parent, name());
00113 clock->CopyFrom(this);
00114 }
00115