diff -r 4e8ebe173323 -r 23b5d6a29cce homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsclockwidget.cpp --- a/homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsclockwidget.cpp Mon May 03 12:24:59 2010 +0300 +++ b/homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsclockwidget.cpp Fri May 14 15:43:04 2010 +0300 @@ -15,20 +15,15 @@ * */ -#include -#include -#include +#include #include -#include -#include -#include // temp #include "hsclockwidget.h" #include "hsanalogclockwidget.h" #include "hsdigitalclockwidget.h" #ifdef Q_OS_SYMBIAN -#include "hsclockwidgettype_symbian.h" +#include "hsclocksettingsnotifier_symbian.h" #include #include #endif //Q_OS_SYMBIAN @@ -37,6 +32,8 @@ { const char ANALOG[] = "analog"; const char DIGITAL[] = "digital"; + const char TIME12[] = "TIME12"; + const char TIME24[] = "TIME24"; const int clockUpdateInterval = 1000; // msec } @@ -50,35 +47,27 @@ \class HsClockWidget \ingroup group_hsclockwidgetplugin \brief Implementation for the homescreen clock widget. - */ - /*! - \fn HsClockWidget::HsClockWidget(QGraphicsItem *parent, Qt::WindowFlags flags) - Constructs widget. */ HsClockWidget::HsClockWidget(QGraphicsItem *parent, Qt::WindowFlags flags) - : HbWidget(parent, flags), - mTimer(0), - mClockType(ANALOG), - mWidget(0), - mLayout(0), - mWidgetShown(false) + : HbWidget(parent, flags), + mWidget(0), + mLayout(0), + mTimer(0), + mClockType(ANALOG), + mTimeType(TIME12) { -#if 0 #ifdef Q_OS_SYMBIAN - HsClockWidgetType *clockType = new HsClockWidgetType(this); - mClockType=clockType->type(); - connect(clockType, SIGNAL(typeChanged(QString)), this, SLOT(onTypeChanged(QString))); -#endif + mClockSettingsNotifier = new HsClockSettingsNotifier(this); + mClockType = mClockSettingsNotifier->clockFormat(); + mTimeType = mClockSettingsNotifier->timeFormat(); #endif } /*! - \fn HsClockWidget::~HsClockWidget() - Destructor. */ HsClockWidget::~HsClockWidget() @@ -86,70 +75,42 @@ } /*! - Returns the clock type. -*/ -QString HsClockWidget::clockType() const -{ - return mClockType; -} - -/*! - Sets the clock type; -*/ -void HsClockWidget::setClockType(const QString &type) -{ - if (type == DIGITAL) { - mClockType = DIGITAL; - } else { - mClockType = ANALOG; - } -} - -/*! - \fn void HsClockWidget::onInitialize() - - Initializes clock widget + Initializes this widget. */ void HsClockWidget::onInitialize() { mLayout = new QGraphicsLinearLayout(Qt::Vertical); - mLayout->setContentsMargins(0,0,0,0); - + mLayout->setContentsMargins(0, 0, 0, 0); mWidget = loadClockWidget(); - mLayout->addItem(mWidget); - setPreferredSize(mWidget->preferredSize()); - parentWidget()->resize(preferredSize()); // workaround for layouting - + mLayout->addItem(mWidget); mTimer = new QTimer(this); connect(mTimer, SIGNAL(timeout()), SLOT(updateTime())); setLayout(mLayout); +#ifdef Q_OS_SYMBIAN + connect(mClockSettingsNotifier, SIGNAL(settingsChanged(QString, QString)), this, SLOT(onSettingsChanged(QString, QString))); +#endif + } /*! - \fn void HsClockWidget::show() - - Shows the widget + Shows this widget. */ void HsClockWidget::onShow() -{ - mWidgetShown = true; +{ mTimer->start(clockUpdateInterval); } /*! - \fn void HsClockWidget::show() - - Hides the widget + Hides this widget. */ void HsClockWidget::onHide() { - mWidgetShown = false; mTimer->stop(); } /*! - Uninitializes the widget. + Uninitializes this widget. */ void HsClockWidget::onUninitialize() { @@ -157,51 +118,65 @@ } /*! - \fn void HsClockWidget::updateTime() - - Draws the clock with every second + Draws the clock with every second. */ void HsClockWidget::updateTime() { if (mClockType == DIGITAL) { - hide(); // workaround for clock not updating - static_cast(mWidget)->setPlainText( - HbExtendedLocale().format(QTime::currentTime(), r_qtn_time_usual_with_zero)); - show(); // workaround for clock not updating + static_cast(mWidget)->tick(); } else { static_cast(mWidget)->tick(); } } /*! - Toggles the clock type. + \internal */ -void HsClockWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void HsClockWidget::onSettingsChanged(const QString &clockFormat, const QString &timeFormat) { - if (!contains(event->pos())) { - return; + if (mClockType != clockFormat) { + mClockType = clockFormat; + mLayout->removeItem(mWidget); + delete mWidget; + mWidget = 0; + mWidget = loadClockWidget(); + mLayout->addItem(mWidget); + } + + if (mTimeType != timeFormat) { + mTimeType = timeFormat; + if (mClockType == DIGITAL) { + if (mTimeType == TIME12) { + static_cast(mWidget)->setAmPm(true); + } else { + static_cast(mWidget)->setAmPm(false); + } + } } +} -#ifndef Q_OS_SYMBIAN - mTimer->stop(); - toggleClockType(); - emit setPreferences(QStringList() << "clockType"); - - hide(); - +/*! + Clock tapped. +*/ +void HsClockWidget::onClockTapped() +{ +#ifndef Q_OS_SYMBIAN + if (mClockType == ANALOG) { + mClockType = DIGITAL; + if (mTimeType == TIME12) { + mTimeType = TIME24; + } else { + mTimeType = TIME12; + } + } else { + mClockType = ANALOG; + } mLayout->removeItem(mWidget); delete mWidget; mWidget = 0; mWidget = loadClockWidget(); - mLayout->addItem(mWidget); - setPreferredSize(mWidget->preferredSize()); - parentWidget()->resize(preferredSize()); - - show(); + mLayout->addItem(mWidget); updateTime(); - update(); - - mTimer->start(clockUpdateInterval); #else //Q_OS_SYMBIAN TApaTaskList taskList(CEikonEnv::Static()->WsSession()); TApaTask task = taskList.FindApp(KClockAppUid); @@ -221,19 +196,6 @@ #endif //Q_OS_SYMBIAN } - -/*! - Toggles the clock type. -*/ -void HsClockWidget::toggleClockType() -{ - if (mClockType == ANALOG) { - mClockType = DIGITAL; - } else { - mClockType = ANALOG; - } -} - /*! Loads the digital or analog clock widget. */ @@ -242,38 +204,15 @@ HbWidget *clockWidget = 0; if (mClockType == DIGITAL) { - clockWidget = new HsDigitalClockWidget(); - clockWidget->setBackgroundItem(HbStyle::P_Fade_background); + bool useAmPm = true; + if (mTimeType == TIME24) { + useAmPm = false; + } + clockWidget = new HsDigitalClockWidget(useAmPm); } else { clockWidget = new HsAnalogClockWidget(); } - qreal unit = HbDeviceProfile::current().unitValue(); - clockWidget->setPreferredSize(QSizeF(25 * unit, 25 * unit)); // TODO: temp workaround - + connect(clockWidget, SIGNAL(clockTapped()), this, SLOT(onClockTapped()), Qt::QueuedConnection); return clockWidget; } - -void HsClockWidget::onTypeChanged(QString type) -{ - Q_UNUSED(type); -#if 0 - if (mClockType != type) { - mTimer->stop(); - mClockType = type; - emit setPreferences(QStringList() << "clockType"); - hide(); - mLayout->removeItem(mWidget); - delete mWidget; - mWidget = 0; - mWidget = loadClockWidget(); - mLayout->addItem(mWidget); - setPreferredSize(mWidget->preferredSize()); - parentWidget()->resize(preferredSize()); - if ( mWidgetShown ) { - mTimer->start(clockUpdateInterval); - show(); - } - } -#endif -}