calendarui/views/dayview/src/calendayhourelement.cpp
changeset 81 ce92091cbd61
parent 63 a3cb48f6c889
equal deleted inserted replaced
75:7ac58b2aae6f 81:ce92091cbd61
    47  \param parent Widget's parent
    47  \param parent Widget's parent
    48  */
    48  */
    49 CalenDayHourElement::CalenDayHourElement(
    49 CalenDayHourElement::CalenDayHourElement(
    50     const QTime &time,
    50     const QTime &time,
    51     QGraphicsItem *parent) :
    51     QGraphicsItem *parent) :
    52     HbWidget(parent), mHour(time)
    52     HbWidget(parent), mHour(time), mTimeTextItem(NULL), mAmpmTextItem(NULL)
    53 {
    53 {
    54     // Necessary when widget implements own paint method
    54     // Necessary when widget implements own paint method
    55     setFlag(QGraphicsItem::ItemHasNoContents, false);
    55     setFlag(QGraphicsItem::ItemHasNoContents, false);
    56 
    56     
    57     HbDeviceProfile deviceProfile;
    57     HbDeviceProfile deviceProfile;
    58     mUnitInPixels = deviceProfile.unitValue();
    58     mUnitInPixels = deviceProfile.unitValue();
       
    59     mHour = time;
    59 
    60 
    60     // Initialize hour line color
    61     // Initialize hour line color
    61     mHourLineColor = HbColorScheme::color(KCalenHourLineColor);
    62     mHourLineColor = HbColorScheme::color(KCalenHourLineColor); 
    62 
    63     
    63     // Create text items
    64     mTimeTextItem = new HbTextItem(this);
    64     HbExtendedLocale systemLocale = HbExtendedLocale::system();
    65     mAmpmTextItem = new HbTextItem(this);
    65 
    66     HbStyle::setItemName(mTimeTextItem, QLatin1String("time"));
    66     // Get current time format and (if there's a need) separate time from am/pm text
    67     HbStyle::setItemName(mAmpmTextItem, QLatin1String("ampm"));
    67     QChar timeSeparator = ' ';
    68     
    68     QStringList timeTextList = systemLocale.format(time,
    69     setupWithLocale();
    69         r_qtn_time_usual_with_zero).split(timeSeparator);
       
    70 
       
    71     // If needed, prepend '0' to get proper time format: [0-9][0-9]:[0-9][0-9]
       
    72     QString timeString = timeTextList[0];
       
    73     if (timeString.length() < KCalenTimeFormatLength) {
       
    74         timeString.prepend('0');
       
    75     }
       
    76 
       
    77     QString ampmString = "";
       
    78     if (timeTextList.count() > 1) {
       
    79         ampmString = timeTextList[1].toLower();
       
    80     }
       
    81 
       
    82     HbTextItem* timeTextItem = new HbTextItem(timeString, this);
       
    83     HbTextItem* ampmTextItem = new HbTextItem(ampmString, this);
       
    84 
       
    85     HbStyle::setItemName(timeTextItem, QLatin1String("time"));
       
    86     HbStyle::setItemName(ampmTextItem, QLatin1String("ampm"));
       
    87 
    70 
    88     // Parent container is needed to update widget's time
    71     // Parent container is needed to update widget's time
    89     mContainer = static_cast<CalenDayHourScrollArea*> (parent);
    72     mContainer = static_cast<CalenDayHourScrollArea*> (parent);
    90 }
    73 }
    91 
    74 
    92 /*!
    75 /*!
    93  \brief Destructor
    76  \brief Destructor
    94  */
    77  */
    95 CalenDayHourElement::~CalenDayHourElement()
    78 CalenDayHourElement::~CalenDayHourElement()
    96 {
    79 {
    97 
       
    98 }
    80 }
    99 
    81 
   100 /*!
    82 /*!
   101  \brief Customized paint() function
    83  \brief Customized paint() function
   102  
    84  
   170 QTime CalenDayHourElement::time() const
   152 QTime CalenDayHourElement::time() const
   171 {
   153 {
   172     return mHour;
   154     return mHour;
   173 }
   155 }
   174 
   156 
       
   157 /*!
       
   158  \brief SLOT updates control when system locale changes
       
   159  */
       
   160 void CalenDayHourElement::localeChanged()
       
   161 {
       
   162     setupWithLocale();
       
   163     repolish();
       
   164 }
       
   165 
       
   166 /*!
       
   167  \brief Sets up internal data using current system locale.
       
   168  */
       
   169 void CalenDayHourElement::setupWithLocale()
       
   170 {
       
   171     HbDeviceProfile deviceProfile;
       
   172 
       
   173     // Create text items
       
   174     HbExtendedLocale systemLocale = HbExtendedLocale::system();
       
   175 
       
   176     // Get current time format and (if there's a need) separate time from am/pm text
       
   177     QChar timeSeparator = ' ';
       
   178     QStringList timeTextList = systemLocale.format(mHour, r_qtn_time_usual_with_zero).split(timeSeparator);
       
   179 
       
   180     // If needed, prepend '0' to get proper time format: [0-9][0-9]:[0-9][0-9]
       
   181     QString timeString = timeTextList[0];
       
   182     if (timeString.length() < KCalenTimeFormatLength) {
       
   183         timeString.prepend('0');
       
   184     }
       
   185 
       
   186     QString ampmString = "";
       
   187     if (timeTextList.count() > 1) {
       
   188         ampmString = timeTextList[1].toLower();
       
   189     }
       
   190     
       
   191     mTimeTextItem->setText(timeString);
       
   192     mAmpmTextItem->setText(ampmString);
       
   193 }
       
   194 
   175 // End of File
   195 // End of File