src/hbwidgets/widgets/hbdatetimepicker_p.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbdatetimepicker_p.h"
    26 #include "hbdatetimepicker_p.h"
    27 #include "hbdatetimepicker.h"
    27 #include "hbdatetimepicker.h"
    28 #include "hbstyleoption_p.h"
    28 #include "hbstyleoption_p.h"
    29 #include "hbfeaturemanager_r.h"
    29 #include "hbtextitem.h"
    30 
    30 #ifdef HB_TEXT_MEASUREMENT_UTILITY
    31 //TODO:remove frameitem dependency
    31 #include "hbtextmeasurementutility_r.h"
    32 #include "hbframeitem.h"
    32 #include "hbtextmeasurementutility_r_p.h"
    33 
    33 #endif
    34 #include <QStringListModel>
       
    35 #include <QGraphicsLinearLayout>
       
    36 #include <QModelIndex>
       
    37 #include <QDate>
       
    38 #include <QLocale>
       
    39 #include <QPointer>
       
    40 
    34 
    41 //#define HBDATETIMEPICKER_DEBUG
    35 //#define HBDATETIMEPICKER_DEBUG
    42 #ifdef HBDATETIMEPICKER_DEBUG
    36 #ifdef HBDATETIMEPICKER_DEBUG
    43 #include <QDebug>
    37 #include <QDebug>
    44 #endif
    38 #endif
   125                     const SectionNode sn = { hour, i - add, countRepeat(format, i, 2) };
   119                     const SectionNode sn = { hour, i - add, countRepeat(format, i, 2) };
   126                     newSectionNodes.append(sn);
   120                     newSectionNodes.append(sn);
   127                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   121                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   128                     i += sn.count - 1;
   122                     i += sn.count - 1;
   129                     index = i + 1;
   123                     index = i + 1;
       
   124                     if(newDisplay & hour) {
       
   125                         return false; // error in format
       
   126                     }
   130                     newDisplay |= hour;
   127                     newDisplay |= hour;
   131                 }
   128                 }
   132                 break;
   129                 break;
   133             case 'm':
   130             case 'm':
   134                 {
   131                 {
   135                     const SectionNode sn = { MinuteSection, i - add, countRepeat(format, i, 2) };
   132                     const SectionNode sn = { MinuteSection, i - add, countRepeat(format, i, 2) };
   136                     newSectionNodes.append(sn);
   133                     newSectionNodes.append(sn);
   137                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   134                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   138                     i += sn.count - 1;
   135                     i += sn.count - 1;
   139                     index = i + 1;
   136                     index = i + 1;
       
   137                     if(newDisplay & MinuteSection) {
       
   138                         return false; // error in format
       
   139                     }
   140                     newDisplay |= MinuteSection;
   140                     newDisplay |= MinuteSection;
   141                 }
   141                 }
   142                 break;
   142                 break;
   143             case 's':
   143             case 's':
   144                 {
   144                 {
   145                     const SectionNode sn = { SecondSection, i - add, countRepeat(format, i, 2) };
   145                     const SectionNode sn = { SecondSection, i - add, countRepeat(format, i, 2) };
   146                     newSectionNodes.append(sn);
   146                     newSectionNodes.append(sn);
   147                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   147                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   148                     i += sn.count - 1;
   148                     i += sn.count - 1;
   149                     index = i + 1;
   149                     index = i + 1;
       
   150                     if(newDisplay & SecondSection) {
       
   151                         return false; // error in format
       
   152                     }
   150                     newDisplay |= SecondSection;
   153                     newDisplay |= SecondSection;
   151                 }
   154                 }
   152                 break;
   155                 break;
   153 
   156 
   154             case 'z':
   157             case 'z':
   156                     const SectionNode sn = { MSecSection, i - add, countRepeat(format, i, 3) < 3 ? 1 : 3 };
   159                     const SectionNode sn = { MSecSection, i - add, countRepeat(format, i, 3) < 3 ? 1 : 3 };
   157                     newSectionNodes.append(sn);
   160                     newSectionNodes.append(sn);
   158                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   161                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   159                     i += sn.count - 1;
   162                     i += sn.count - 1;
   160                     index = i + 1;
   163                     index = i + 1;
       
   164                     if(newDisplay & MSecSection) {
       
   165                         return false; // error in format
       
   166                     }
   161                     newDisplay |= MSecSection;
   167                     newDisplay |= MSecSection;
   162                 }
   168                 }
   163                 break;
   169                 break;
   164             case 'A':
   170             case 'A':
   165             case 'a':
   171             case 'a':
   166                 {
   172                 {
   167                     const bool cap = (sect == 'A');
   173                     const bool cap = (sect == 'A');
   168                     const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) };
   174                     const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) };
   169                     newSectionNodes.append(sn);
   175                     newSectionNodes.append(sn);
   170                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   176                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
       
   177                     if(newDisplay & AmPmSection) {
       
   178                         return false; // error in format
       
   179                     }
   171                     newDisplay |= AmPmSection;
   180                     newDisplay |= AmPmSection;
   172                     if (i + 1 < format.size()
   181                     if (i + 1 < format.size()
   173                         && format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
   182                         && format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
   174                             ++i;
   183                         ++i;
   175                     }
   184                     }
   176                     index = i + 1;
   185                     index = i + 1;
   177                 }
   186                 }
   178                 break;
   187                 break;
   179             case 'y':
   188             case 'y':
   180                 {
   189                 {
   181                     const int repeat = countRepeat(format, i, 4);
   190                     const int repeat = countRepeat(format, i, 4);
   182                     if (repeat >= 2) {
   191                     if (repeat >= 2) {
   183                         const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits,
   192                         const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits,
   184                             i - add, repeat == 4 ? 4 : 2 };
   193                                                  i - add, repeat == 4 ? 4 : 2 };
   185                         newSectionNodes.append(sn);
   194                         newSectionNodes.append(sn);
   186                         appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   195                         appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   187                         i += sn.count - 1;
   196                         i += sn.count - 1;
   188                         index = i + 1;
   197                         index = i + 1;
       
   198                         if(newDisplay & sn.type) {
       
   199                             return false; //error in format
       
   200                         }
   189                         newDisplay |= sn.type;
   201                         newDisplay |= sn.type;
   190                     }
   202                     }
   191                 }
   203                 }
   192                 break;
   204                 break;
   193             case 'M':
   205             case 'M':
   195                     const SectionNode sn = { MonthSection, i - add, countRepeat(format, i, 4) };
   207                     const SectionNode sn = { MonthSection, i - add, countRepeat(format, i, 4) };
   196                     newSectionNodes.append(sn);
   208                     newSectionNodes.append(sn);
   197                     newSeparators.append(unquote(format.mid(index, i - index)));
   209                     newSeparators.append(unquote(format.mid(index, i - index)));
   198                     i += sn.count - 1;
   210                     i += sn.count - 1;
   199                     index = i + 1;
   211                     index = i + 1;
       
   212                     if(newDisplay & MonthSection) {
       
   213                         return false; // error in format
       
   214                     }
   200                     newDisplay |= MonthSection;
   215                     newDisplay |= MonthSection;
   201                 }
   216                 }
   202                 break;
   217                 break;
   203             case 'd':
   218             case 'd':
   204                 {
   219                 {
   206                     const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat };
   221                     const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat };
   207                     newSectionNodes.append(sn);
   222                     newSectionNodes.append(sn);
   208                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   223                     appendSeparator(&newSeparators, format, index, i - index, lastQuote);
   209                     i += sn.count - 1;
   224                     i += sn.count - 1;
   210                     index = i + 1;
   225                     index = i + 1;
       
   226                     if(newDisplay & (DayOfWeekSection | DaySection)) {
       
   227                         return false; // error in format, dd and ddd not yet supported in same format
       
   228                     }
   211                     newDisplay |= sn.type;
   229                     newDisplay |= sn.type;
   212                 }
   230                 }
   213                 break;
   231                 break;
   214 
   232 
   215             default:
   233             default:
   252     }
   270     }
   253     if (sectionIndex == mSectionNodes.size() - 1) {
   271     if (sectionIndex == mSectionNodes.size() - 1) {
   254         return mDisplayFormat.size() - sectionPos(sectionIndex) - mSeparators.last().size();
   272         return mDisplayFormat.size() - sectionPos(sectionIndex) - mSeparators.last().size();
   255     } else {
   273     } else {
   256         return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex)
   274         return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex)
   257             - mSeparators.at(sectionIndex + 1).size();
   275                 - mSeparators.at(sectionIndex + 1).size();
   258     }
   276     }
   259 }
   277 }
   260 
   278 
   261 int HbDateTimeParser::sectionPos(int sectionIndex) const
   279 int HbDateTimeParser::sectionPos(int sectionIndex) const
   262 {
   280 {
   276 {
   294 {
   277     return mSectionNodes.at(sectionIndex);
   295     return mSectionNodes.at(sectionIndex);
   278 }
   296 }
   279 /////////////////////////////////////////////////
   297 /////////////////////////////////////////////////
   280 
   298 
   281 
   299 HbDatePickerViewLabel::HbDatePickerViewLabel(QGraphicsItem *parent) : HbWidget(parent){
       
   300     mTextItem = 0;
       
   301     createPrimitives();
       
   302     updatePrimitives();
       
   303 }
       
   304 HbDatePickerViewLabel::HbDatePickerViewLabel(const QString &displayText, QGraphicsItem *parent):HbWidget(parent){
       
   305     mTextItem = 0;
       
   306     createPrimitives();
       
   307     updatePrimitives();
       
   308 
       
   309     ((HbTextItem*)mTextItem)->setText(displayText);
       
   310 }
       
   311 
       
   312 void HbDatePickerViewLabel::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive){
       
   313     HbWidget::initPrimitiveData(primitiveData, primitive);
       
   314 }
       
   315 
       
   316 void HbDatePickerViewLabel::createPrimitives(){
       
   317     if(!mTextItem){
       
   318         mTextItem = style()->createPrimitive(HbStyle::PT_TextItem,"text", this);
       
   319     }
       
   320 }
       
   321 
       
   322 void HbDatePickerViewLabel::updatePrimitives(){
       
   323     HbWidget::updatePrimitives();
       
   324     if(mTextItem){
       
   325         HbStyleTextPrimitiveData data;
       
   326         initPrimitiveData(&data, mTextItem);
       
   327         style()->updatePrimitive(mTextItem, &data, this);
       
   328     }
       
   329 }
       
   330 
       
   331 /////////////////////////////////////////////////
   282 HbDateTimePickerPrivate::HbDateTimePickerPrivate()
   332 HbDateTimePickerPrivate::HbDateTimePickerPrivate()
   283 :HbWidgetPrivate()
   333     :HbWidgetPrivate()
   284     ,mDayPicker(0)
   334     ,mDayPicker(0)
   285     ,mMonthPicker(0)
   335     ,mMonthPicker(0)
   286     ,mYearPicker(0)
   336     ,mYearPicker(0)
   287     ,mHourPicker(0)
   337     ,mHourPicker(0)
   288     ,mMinutePicker(0)
   338     ,mMinutePicker(0)
   303     ,mSecondOffset(-1)
   353     ,mSecondOffset(-1)
   304     ,mDateTime(QDateTime::currentDateTime())
   354     ,mDateTime(QDateTime::currentDateTime())
   305     ,mDateTimeMode(QVariant::Date) //default is date mode
   355     ,mDateTimeMode(QVariant::Date) //default is date mode
   306     ,mLayout(0)         
   356     ,mLayout(0)         
   307     //,mFormat() //set the format again in init()
   357     //,mFormat() //set the format again in init()
       
   358     ,mFormatEventType(-1)
   308     //,mDisplaySecions() //is blank by default
   359     //,mDisplaySecions() //is blank by default
   309     ,mParser()
   360     ,mParser()
   310     ,mYearFormat()
   361     ,mYearFormat()
   311     ,mMonthFormat()
   362     ,mMonthFormat()
   312     ,mDayFormat()
   363     ,mDayFormat()
   313     ,mHourFormat()
   364     ,mHourFormat()
   314     ,mMinuteFormat()
   365     ,mMinuteFormat()
   315     ,mSecondFormat() 
   366     ,mSecondFormat() 
   316     ,mIs24HourFormat(false)
   367     ,mIs24HourFormat(false)
   317     ,mIsTwoDigitYearFormat(false)
   368     ,mIsTwoDigitYearFormat(false)
       
   369     ,mContent(0)
       
   370     ,mIntervals()
   318     ,mBackground(0)
   371     ,mBackground(0)
   319     ,mFrame(0)
   372     ,mFrame(0)
   320     ,mContent(0)
       
   321     ,mIntervals()
       
   322     ,mHighlight(0)
   373     ,mHighlight(0)
   323 {
   374 {
   324     mMinimumDate = HBDATETIMEPICKER_DATETIME_MIN;
   375     mMinimumDate = HBDATETIMEPICKER_DATETIME_MIN;
   325     mMaximumDate = HBDATETIMEPICKER_DATETIME_MAX;
   376     mMaximumDate = HBDATETIMEPICKER_DATETIME_MAX;
   326     mDateTime = mMinimumDate;
   377     mDateTime = mMinimumDate;
   338 {
   389 {
   339     Q_Q(HbDateTimePicker);
   390     Q_Q(HbDateTimePicker);
   340 
   391 
   341     //create base content widget which contains the tumble views
   392     //create base content widget which contains the tumble views
   342     mContent=new HbWidget(q);
   393     mContent=new HbWidget(q);
   343     mLayout = new QGraphicsLinearLayout(Qt::Horizontal);
   394     mLayout = new QGraphicsGridLayout;
   344     mLayout->setSpacing(1);
   395     mLayout->setSpacing(1);
   345     mLayout->setContentsMargins(0,0,0,0);
   396     mLayout->setContentsMargins(0,0,0,0);
   346     mContent->setLayout(mLayout);
   397     mContent->setLayout(mLayout);
   347     q->style()->setItemName(mContent,"content");
   398     HbStyle::setItemName(mContent,"content");
   348 
   399 
   349     mDateTimeMode = dateTimeMode;
   400     mDateTimeMode = dateTimeMode;
   350     mIntervals[QDateTimeEdit::MinuteSection]=1;
   401     mIntervals[QDateTimeEdit::MinuteSection]=1;
   351 
   402     mFormatEventType = QEvent::registerEventType(QEvent::User+1);
   352     //read the format from locale
   403     //read the format from locale
   353     mFormat = localeDateTimeFormat(dateTimeMode);
   404     QString newFormat = localeDateTimeFormat(dateTimeMode);
   354 
   405     if(isFormatValid(newFormat)){
   355     //parse the format and set the sections in order
   406         mFormat = newFormat;
   356     parseDisplayFormat(mFormat);
   407         postFormatEvent();
   357 
   408     }
       
   409     
   358     //create primitives
   410     //create primitives
   359     createPrimitives();
   411     createPrimitives();
   360 
       
   361     //recreate and rearrange depending on the format
       
   362     rearrangeTumbleViews();
       
   363 }
   412 }
   364 
   413 
   365 /*!
   414 /*!
   366   \internal
   415   \internal
   367 
   416 
   380 bool HbDateTimePickerPrivate::isFormatValid(const QString &newDisplayFormat)
   429 bool HbDateTimePickerPrivate::isFormatValid(const QString &newDisplayFormat)
   381 {
   430 {
   382     if(newDisplayFormat == mFormat) {
   431     if(newDisplayFormat == mFormat) {
   383         return false;
   432         return false;
   384     }
   433     }
   385     return true;
   434 
       
   435     return mParser.parseFormat(newDisplayFormat);
   386 }
   436 }
   387 
   437 
   388 /* 
   438 /* 
   389    this will reset the display sections and re add them in order
   439    this will reset the display sections and re add them in order
   390    mentioned in the display format passed. this also sets the mIs24HourFormat var.
   440    mentioned in the display format passed. this also sets the mIs24HourFormat var.
   391 */
   441 */
   392 void HbDateTimePickerPrivate::parseDisplayFormat(const QString &format)
   442 void HbDateTimePickerPrivate::processDisplaySections()
   393 {
   443 {
   394     if(mParser.parseFormat(format)) {
   444     for(int i=0;i<mParser.mSectionNodes.count();++i) {
   395         for(int i=0;i<mParser.mSectionNodes.count();++i) {
   445         switch(mParser.mSectionNodes[i].type) {
   396             switch(mParser.mSectionNodes[i].type) {
   446         case HbDateTimeParser::DaySection:
   397                 case HbDateTimeParser::DaySection:
   447         case HbDateTimeParser::DayOfWeekSection:
   398                 case HbDateTimeParser::DayOfWeekSection:
   448             mDayFormat = QString(mParser.mSectionNodes[i].count,'d');
   399                     mDayFormat = QString(mParser.mSectionNodes[i].count,'d');
   449             break;
   400                     break;
   450 
   401 
   451         case HbDateTimeParser::MonthSection:
   402                 case HbDateTimeParser::MonthSection:
   452             mMonthFormat = QString(mParser.mSectionNodes[i].count,'M');
   403                     mMonthFormat = QString(mParser.mSectionNodes[i].count,'M');
   453             break;
   404                     break;
   454 
   405 
   455         case HbDateTimeParser::YearSection:
   406                 case HbDateTimeParser::YearSection:
   456             mIsTwoDigitYearFormat = false;
   407                     mIsTwoDigitYearFormat = false;
   457             mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
   408                     mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
   458             break;
   409                     break;
   459 
   410 
   460         case HbDateTimeParser::YearSection2Digits:
   411                 case HbDateTimeParser::YearSection2Digits:
   461             mIsTwoDigitYearFormat = true;
   412                     mIsTwoDigitYearFormat = true;
   462             mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
   413                     mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
   463             break;
   414                     break;
   464 
   415 
   465         case HbDateTimeParser::SecondSection:
   416                 case HbDateTimeParser::SecondSection:
   466             mSecondFormat = QString(mParser.mSectionNodes[i].count,'s');
   417                     mSecondFormat = QString(mParser.mSectionNodes[i].count,'s');
   467             break;
   418                     break;
   468 
   419 
   469         case HbDateTimeParser::MinuteSection:
   420                 case HbDateTimeParser::MinuteSection:
   470             mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m');
   421                     mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m');
   471             break;
   422                     break;
   472 
   423 
   473         case HbDateTimeParser::Hour12Section:
   424                 case HbDateTimeParser::Hour12Section:
   474             mIs24HourFormat = false;
   425                     mIs24HourFormat = false;
   475             mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
   426                     mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
   476             break;
   427                     break;
   477 
   428 
   478         case HbDateTimeParser::Hour24Section:
   429                 case HbDateTimeParser::Hour24Section:
   479             mIs24HourFormat = true;
   430                     mIs24HourFormat = true;
   480             mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
   431                     mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
   481             break;
   432                     break;
   482 
   433 
   483         default:
   434                 default:
   484             break;
   435                     break;
   485             /*case HbDateTimeParser::DayOfWeekSection: not supported */
   436                     /*case HbDateTimeParser::DayOfWeekSection: not supported */
       
   437             }
       
   438         }
   486         }
   439     }
   487     }
   440 }
   488 }
   441 
   489 
   442 /*
   490 /*
   445    it creates the ones which are required and makes the connections.
   493    it creates the ones which are required and makes the connections.
   446 */
   494 */
   447 void HbDateTimePickerPrivate::rearrangeTumbleViews()
   495 void HbDateTimePickerPrivate::rearrangeTumbleViews()
   448 {                  
   496 {                  
   449     Q_Q(HbDateTimePicker);
   497     Q_Q(HbDateTimePicker);
   450 
       
   451     if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection|
   498     if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection|
   452 				     HbDateTimeParser::YearSection2Digits))) {
   499                      HbDateTimeParser::YearSection2Digits))) {
   453       deleteAndNull(mYearPicker);
   500       deleteAndNull(mYearPicker);
       
   501             delete mLabelYear;
   454       mYearModel = 0;
   502       mYearModel = 0;
   455     }
   503     }
   456     if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) {
   504     if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) {
   457       deleteAndNull(mMonthPicker);
   505         deleteAndNull(mMonthPicker);
   458       mMonthModel = 0;
   506         delete mLabelMonth;
       
   507         mMonthModel = 0;
   459     }
   508     }
   460     if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) {
   509     if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) {
   461       deleteAndNull(mDayPicker);
   510         deleteAndNull(mDayPicker);
   462       mDayModel = 0;
   511         delete mLabelDay;
       
   512         mDayModel = 0;
   463     }
   513     }
   464     if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section|
   514     if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section|
   465 				     HbDateTimeParser::Hour24Section))) {
   515                      HbDateTimeParser::Hour24Section))) {
   466       deleteAndNull(mHourPicker);
   516       deleteAndNull(mHourPicker);
       
   517             delete mLabelHour;
   467       mHourModel = 0;
   518       mHourModel = 0;
   468     }
   519     }
   469     if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) {
   520     if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) {
   470       deleteAndNull(mMinutePicker);
   521         deleteAndNull(mMinutePicker);
   471       mMinuteModel = 0;
   522         delete mLabelMinute;
       
   523         mMinuteModel = 0;
   472     }
   524     }
   473     if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) {
   525     if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) {
   474       deleteAndNull(mSecondPicker);
   526         deleteAndNull(mSecondPicker);
   475       mSecondModel = 0;
   527         delete mLabelSecond;
       
   528         mSecondModel = 0;
   476     }
   529     }
   477     if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) {
   530     if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) {
   478       deleteAndNull(mAmPmPicker);
   531         deleteAndNull(mAmPmPicker);
   479       mAmPmModel = 0;
   532         mAmPmModel = 0;
   480     }
   533     }
   481 
   534 
   482     mYearOffset = -1;
   535     mYearOffset = -1;
   483     mMonthOffset = -1;
   536     mMonthOffset = -1;
   484     mDayOffset = -1;
   537     mDayOffset = -1;
   485     mHourOffset = -1;
   538     mHourOffset = -1;
   486     mMinuteOffset = -1;
   539     mMinuteOffset = -1;
   487     mSecondOffset = -1;
   540     mSecondOffset = -1;
   488 
   541 
   489     while(mLayout->count()) {
   542     while(mLayout->count()) {
   490       mLayout->removeAt(0);
   543         mLayout->removeAt(0);
   491     }
   544     }
   492 
       
   493     QPointer<VIEWER> lastAdded;
       
   494 
   545 
   495     for(int i=0;i<mParser.mSectionNodes.count();i++) {
   546     for(int i=0;i<mParser.mSectionNodes.count();i++) {
   496         switch(mParser.mSectionNodes[i].type) {
   547         switch(mParser.mSectionNodes[i].type) {
   497             case HbDateTimeParser::AmPmSection:
   548         case HbDateTimeParser::AmPmSection:
   498                 if(!mAmPmPicker) {
   549             if(!mAmPmPicker) {
   499                     mAmPmPicker = new VIEWER(q);
   550                 mAmPmPicker = new VIEWER(q);
   500                     mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model());
   551                 mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model());
   501                 }
   552             }
   502                 mLayout->addItem(mAmPmPicker);
   553 
   503                 lastAdded = mAmPmPicker;
   554             mLayout->addItem(mAmPmPicker, 1, i);
   504                 break;
   555             mLastAdded = mAmPmPicker;
       
   556             break;
   505 
   557 
   506             case HbDateTimeParser::DaySection:
   558             case HbDateTimeParser::DaySection:
   507             case HbDateTimeParser::DayOfWeekSection:
   559             case HbDateTimeParser::DayOfWeekSection:
   508                 if(!mDayPicker) {
   560             if(!mDayPicker) {
   509                     mDayPicker = new VIEWER(q);
   561                 mDayPicker = new VIEWER(q);
   510                     mDayModel = static_cast<QStringListModel*>(mDayPicker->model());
   562                 mDayModel = static_cast<QStringListModel*>(mDayPicker->model());
   511                     mDayPicker->setLoopingEnabled(true);
   563                 mDayPicker->setLoopingEnabled(true);
       
   564             }
       
   565 
       
   566                 if(mLabelDay.isNull()){
       
   567                     mLabelDay = new HbDatePickerViewLabel("Day", q);//TODO:Text should come from common.ts
   512                 }
   568                 }
   513                 mLayout->addItem(mDayPicker);
   569 
   514                 lastAdded = mDayPicker;
   570                 mLayout->addItem(mLabelDay, 0, i);
   515                 break;
   571                 mLayout->addItem(mDayPicker, 1, i);
       
   572                 mLastAdded = mDayPicker;
       
   573             break;
   516 
   574 
   517             case HbDateTimeParser::MonthSection:
   575             case HbDateTimeParser::MonthSection:
   518                 if(!mMonthPicker) {
   576             if(!mMonthPicker) {
   519                     mMonthPicker = new VIEWER(q);
   577                 mMonthPicker = new VIEWER(q);
   520                     mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model());
   578                 mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model());
   521                     mMonthPicker->setLoopingEnabled(true);
   579                 mMonthPicker->setLoopingEnabled(true);
       
   580             }
       
   581 
       
   582                 if(mLabelMonth.isNull()){
       
   583                     mLabelMonth = new HbDatePickerViewLabel("Month", q);//TODO:Text should come from common.ts
   522                 }
   584                 }
   523                 mLayout->addItem(mMonthPicker);
   585 
   524                 lastAdded = mMonthPicker;
   586                 mLastAdded = mMonthPicker;
   525                 break;
   587                 mLayout->addItem(mLabelMonth, 0, i);
       
   588                 mLayout->addItem(mMonthPicker, 1, i);
       
   589             break;
   526 
   590 
   527             case HbDateTimeParser::YearSection:
   591             case HbDateTimeParser::YearSection:
   528             case HbDateTimeParser::YearSection2Digits:
   592             case HbDateTimeParser::YearSection2Digits:
   529                 if(!mYearPicker) {
   593             if(!mYearPicker) {
   530                     mYearPicker = new VIEWER(q);
   594                 mYearPicker = new VIEWER(q);
   531                     mYearModel = static_cast<QStringListModel*>(mYearPicker->model());
   595                 mYearModel = static_cast<QStringListModel*>(mYearPicker->model());
   532                     mYearPicker->setLoopingEnabled(true);
   596                 mYearPicker->setLoopingEnabled(true);
       
   597             }
       
   598 
       
   599                 if(mLabelYear.isNull()){
       
   600                     mLabelYear = new HbDatePickerViewLabel("Year", q);//TODO:Text should come from common.ts
   533                 }
   601                 }
   534                 mLayout->addItem(mYearPicker);
   602 
   535                 lastAdded = mYearPicker;
   603                 mLayout->addItem(mLabelYear, 0, i);
   536                 break;
   604                 mLayout->addItem(mYearPicker, 1, i);
       
   605                 mLastAdded = mYearPicker;
       
   606             break;
   537 
   607 
   538             case HbDateTimeParser::SecondSection:
   608             case HbDateTimeParser::SecondSection:
   539                 if(!mSecondPicker) {
   609             if(!mSecondPicker) {
   540                     mSecondPicker = new VIEWER(q);
   610                 mSecondPicker = new VIEWER(q);
   541                     mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model());
   611                 mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model());
   542                     mSecondPicker->setLoopingEnabled(true);
   612                 mSecondPicker->setLoopingEnabled(true);
       
   613             }
       
   614 
       
   615                 if(mLabelSecond.isNull()){
       
   616                     mLabelSecond = new HbDatePickerViewLabel("Seconds", q);//TODO:Text should come from common.ts
   543                 }
   617                 }
   544                 mLayout->addItem(mSecondPicker);
   618 
   545                 lastAdded = mSecondPicker;
   619                 mLayout->addItem(mLabelSecond, 0, i);
   546                 break;
   620                 mLayout->addItem(mSecondPicker, 1, i);
       
   621                 mLastAdded = mSecondPicker;
       
   622             break;
   547 
   623 
   548             case HbDateTimeParser::MinuteSection:
   624             case HbDateTimeParser::MinuteSection:
   549                 if(!mMinutePicker) {
   625             if(!mMinutePicker) {
   550                     mMinutePicker = new VIEWER(q);
   626                 mMinutePicker = new VIEWER(q);
   551                     mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model());
   627                 mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model());
   552                     mMinutePicker->setLoopingEnabled(true);
   628                 mMinutePicker->setLoopingEnabled(true);
       
   629             }
       
   630                 if(mLabelMinute.isNull()){
       
   631                     mLabelMinute = new HbDatePickerViewLabel("Minute", q);//TODO:Text should come from common.ts
   553                 }
   632                 }
   554                 mLayout->addItem(mMinutePicker);
   633                 mLayout->addItem(mLabelMinute, 0, i);
   555                 lastAdded = mMinutePicker;
   634                 mLayout->addItem(mMinutePicker, 1, i);
   556                 break;
   635                 mLastAdded = mMinutePicker;
       
   636             break;
   557 
   637 
   558             case HbDateTimeParser::Hour12Section:
   638             case HbDateTimeParser::Hour12Section:
   559             case HbDateTimeParser::Hour24Section:
   639             case HbDateTimeParser::Hour24Section:
   560                 if(!mHourPicker) {
   640             if(!mHourPicker) {
   561                     mHourPicker = new VIEWER(q);
   641                 mHourPicker = new VIEWER(q);
   562                     mHourModel = static_cast<QStringListModel*>(mHourPicker->model());
   642                 mHourModel = static_cast<QStringListModel*>(mHourPicker->model());
   563                     mHourPicker->setLoopingEnabled(true);
   643                 mHourPicker->setLoopingEnabled(true);
       
   644             }
       
   645 
       
   646                 if(mLabelHour.isNull()){
       
   647                     mLabelHour = new HbDatePickerViewLabel("Hour", q);//TODO:Text should come from common.ts
   564                 }
   648                 }
   565                 mLayout->addItem(mHourPicker);
   649 
   566                 lastAdded = mHourPicker;
   650                 mLayout->addItem(mLabelHour, 0, i); 
   567                 break;
   651                 mLayout->addItem(mHourPicker, 1, i);
       
   652                 mLastAdded = mHourPicker;
       
   653 
       
   654             break;
   568 
   655 
   569             default:
   656             default:
   570                 break;
   657             break;
   571         }
   658         }
   572         
   659 
   573         if(lastAdded){
   660         if(mLastAdded){
   574             lastAdded->primitive("highlight")->hide();
   661             mLastAdded->primitive("highlight")->hide();
   575             lastAdded->primitive("separator")->show();
   662             mLastAdded->primitive("separator")->show();
       
   663             mLastAdded->primitive("background")->hide();
       
   664             mLastAdded->primitive("frame")->hide();
   576         }
   665         }
   577 
   666 
   578     }
   667     }
   579 
   668 
   580     //For the last added tumble view, hide the separator.
   669     //For the last added tumble view, hide the separator.
   581     if(lastAdded){
   670     if(mLastAdded){
   582         lastAdded->primitive("separator")->hide();
   671         mLastAdded->primitive("separator")->hide();
   583     }
   672     }
   584 
   673 
   585     setRanges();
   674     setRanges();
   586     makeConnections();
   675     makeConnections();
   587     syncVisualDate();
   676     syncVisualDate();
   745 
   834 
   746 }
   835 }
   747 
   836 
   748 
   837 
   749 void HbDateTimePickerPrivate::setDateTimeRange(const QDateTime &startdt,
   838 void HbDateTimePickerPrivate::setDateTimeRange(const QDateTime &startdt,
   750         const QDateTime &enddt)
   839                                                const QDateTime &enddt)
   751 {
   840 {
   752     Q_Q(HbDateTimePicker);
   841     Q_Q(HbDateTimePicker);
   753     QDateTime start(startdt);
   842     QDateTime start(startdt);
   754     QDateTime end(enddt);
   843     QDateTime end(enddt);
   755     if(start.isValid() && end.isValid()) {
   844     if(start.isValid() && end.isValid()) {
   864             }
   953             }
   865             else{
   954             else{
   866                 index = newDateTime.time().minute()-mMinuteOffset;
   955                 index = newDateTime.time().minute()-mMinuteOffset;
   867             }
   956             }
   868 #ifdef HBDATETIMEPICKER_DEBUG
   957 #ifdef HBDATETIMEPICKER_DEBUG
   869     qDebug() << "setMinuteRange:selecting= " << index;
   958             qDebug() << "setMinuteRange:selecting= " << index;
   870 #endif
   959 #endif
   871             mMinutePicker->setSelected(index);
   960             mMinutePicker->setSelected(index);
   872         }
   961         }
   873 
   962 
   874         if(mSecondPicker) {
   963         if(mSecondPicker) {
   924 #endif
  1013 #endif
   925 
  1014 
   926 
  1015 
   927 
  1016 
   928     resizeModel(mYearModel, mYearOffset, 
  1017     resizeModel(mYearModel, mYearOffset, 
   929         mYearOffset+mYearModel->rowCount()-1, start, 
  1018                 mYearOffset+mYearModel->rowCount()-1, start,
   930         end, &HbDateTimePickerPrivate::localeYear);
  1019                 end, &HbDateTimePickerPrivate::localeYear);
   931 
  1020 
   932     mYearOffset = start;
  1021     mYearOffset = start;
   933 
  1022 
   934     mYearPicker->setSelected(newIndex);
  1023     mYearPicker->setSelected(newIndex);
   935 }
  1024 }
   951     }
  1040     }
   952     if(newIndex > (end-start)) {
  1041     if(newIndex > (end-start)) {
   953         newIndex = end-start;
  1042         newIndex = end-start;
   954     }
  1043     }
   955     resizeModel(mMonthModel,
  1044     resizeModel(mMonthModel,
   956             mMonthOffset,mMonthOffset+mMonthModel->rowCount()-1,
  1045                 mMonthOffset,mMonthOffset+mMonthModel->rowCount()-1,
   957             start,end,
  1046                 start,end,
   958             &HbDateTimePickerPrivate::localeMonth);
  1047                 &HbDateTimePickerPrivate::localeMonth);
   959     mMonthOffset = start;
  1048     mMonthOffset = start;
   960 
  1049 
   961     mMonthPicker->setSelected(newIndex);
  1050     mMonthPicker->setSelected(newIndex);
   962 
  1051 
   963     //check if current month is valid
  1052     //check if current month is valid
   988     if(newIndex > (end-start)) {
  1077     if(newIndex > (end-start)) {
   989         newIndex = end-start;
  1078         newIndex = end-start;
   990     }
  1079     }
   991 
  1080 
   992     resizeModel(mDayModel,
  1081     resizeModel(mDayModel,
   993             mDayOffset,mDayOffset+mDayModel->rowCount()-1,
  1082                 mDayOffset,mDayOffset+mDayModel->rowCount()-1,
   994             start,end,
  1083                 start,end,
   995             &HbDateTimePickerPrivate::localeDay);
  1084                 &HbDateTimePickerPrivate::localeDay);
   996     mDayOffset = start;
  1085     mDayOffset = start;
   997 
  1086 
   998     mDayPicker->setSelected(newIndex);
  1087     mDayPicker->setSelected(newIndex);
   999 
  1088 
  1000 
  1089 
  1026     if(newIndex > (end-start)) {
  1115     if(newIndex > (end-start)) {
  1027         newIndex = end-start;
  1116         newIndex = end-start;
  1028     }
  1117     }
  1029 
  1118 
  1030     resizeModel(mHourModel,
  1119     resizeModel(mHourModel,
  1031             mHourOffset,mHourOffset+mHourModel->rowCount()-1,
  1120                 mHourOffset,mHourOffset+mHourModel->rowCount()-1,
  1032             start,end,
  1121                 start,end,
  1033             &HbDateTimePickerPrivate::localeHour);
  1122                 &HbDateTimePickerPrivate::localeHour);
  1034     mHourOffset = start;
  1123     mHourOffset = start;
  1035 
  1124 
  1036     mHourPicker->setSelected(newIndex);
  1125     mHourPicker->setSelected(newIndex);
  1037 
  1126 
  1038     //check if hour is valid
  1127     //check if hour is valid
  1063     if(newIndex > (end-start)) {
  1152     if(newIndex > (end-start)) {
  1064         newIndex = end-start;
  1153         newIndex = end-start;
  1065     }
  1154     }
  1066 
  1155 
  1067     resizeModel(mMinuteModel, 
  1156     resizeModel(mMinuteModel, 
  1068 		mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt(),
  1157                 mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt(),
  1069 		start,end,
  1158                 start,end,
  1070 		&HbDateTimePickerPrivate::localeMinute, 
  1159                 &HbDateTimePickerPrivate::localeMinute,
  1071 		mIntervals[QDateTimeEdit::MinuteSection]);
  1160                 mIntervals[QDateTimeEdit::MinuteSection]);
  1072     mMinuteOffset = start;
  1161     mMinuteOffset = start;
  1073 
  1162 
  1074     //Select the nearest value when the range is set.
  1163     //Select the nearest value when the range is set.
  1075     int index = 0;
  1164     int index = 0;
  1076 
  1165 
  1077     for(int i=start;i<newIndex;i+=mIntervals[QDateTimeEdit::MinuteSection]) {
  1166     for(int i=start;i<newIndex;i+=mIntervals[QDateTimeEdit::MinuteSection]) {
  1078       index++;
  1167         index++;
  1079     }
  1168     }
  1080 #ifdef HBDATETIMEPICKER_DEBUG
  1169 #ifdef HBDATETIMEPICKER_DEBUG
  1081     qDebug() << "initMinute:selecting= " << index;
  1170     qDebug() << "initMinute:selecting= " << index;
  1082 #endif
  1171 #endif
  1083     mMinutePicker->setSelected(index);
  1172     mMinutePicker->setSelected(index);
  1111     if(newIndex > (end-start)) {
  1200     if(newIndex > (end-start)) {
  1112         newIndex = end-start;
  1201         newIndex = end-start;
  1113     }
  1202     }
  1114 
  1203 
  1115     resizeModel(mSecondModel,
  1204     resizeModel(mSecondModel,
  1116             mSecondOffset,mSecondOffset+mSecondModel->rowCount()-1,
  1205                 mSecondOffset,mSecondOffset+mSecondModel->rowCount()-1,
  1117             start,end,
  1206                 start,end,
  1118             &HbDateTimePickerPrivate::localeSecond);
  1207                 &HbDateTimePickerPrivate::localeSecond);
  1119     mSecondOffset = start;
  1208     mSecondOffset = start;
  1120 
  1209 
  1121     mSecondPicker->setSelected(newIndex);
  1210     mSecondPicker->setSelected(newIndex);
  1122 
  1211 
  1123     //check if second is valid
  1212     //check if second is valid
  1185 
  1274 
  1186 QString HbDateTimePickerPrivate::localeAmPm(bool isAm)
  1275 QString HbDateTimePickerPrivate::localeAmPm(bool isAm)
  1187 {
  1276 {
  1188     QString text = isAm ? mLocale.amText() : mLocale.pmText();
  1277     QString text = isAm ? mLocale.amText() : mLocale.pmText();
  1189 #ifdef HB_TEXT_MEASUREMENT_UTILITY
  1278 #ifdef HB_TEXT_MEASUREMENT_UTILITY
  1190     if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
  1279     if (HbTextMeasurementUtility::instance()->locTestMode()) {
  1191         text.append(QChar(LOC_TEST_START));
  1280         text.append(QChar(LOC_TEST_START));
  1192         text.append("qtl_datetimepicker_popup_ampm_sec");
  1281         text.append("qtl_datetimepicker_popup_ampm_sec");
  1193         text.append(QChar(LOC_TEST_END));
  1282         text.append(QChar(LOC_TEST_END));
  1194     }
  1283     }
  1195 #endif
  1284 #endif
  1202    data need the appropriate locale and format converted data. which is passed
  1291    data need the appropriate locale and format converted data. which is passed
  1203    as a function pointer instead of creating seven different QStringListModel derived
  1292    as a function pointer instead of creating seven different QStringListModel derived
  1204    model classes with one interface/virtual function specialization.
  1293    model classes with one interface/virtual function specialization.
  1205 */
  1294 */
  1206 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model,
  1295 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model,
  1207             int oldStart, int oldEnd,
  1296                                           int oldStart, int oldEnd,
  1208             int newStart, int newEnd,
  1297                                           int newStart, int newEnd,
  1209             QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
  1298                                           QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
  1210 {
  1299 {
  1211     class ConnectionRemover {
  1300     class ConnectionRemover {
  1212     public:
  1301     public:
  1213         ConnectionRemover(HbDateTimePickerPrivate *priv){
  1302         ConnectionRemover(HbDateTimePickerPrivate *priv){
  1214             this->priv = priv;
  1303             this->priv = priv;
  1219         }
  1308         }
  1220         HbDateTimePickerPrivate *priv;
  1309         HbDateTimePickerPrivate *priv;
  1221     }Obj(this);
  1310     }Obj(this);
  1222 
  1311 
  1223 #ifdef HBDATETIMEPICKER_DEBUG
  1312 #ifdef HBDATETIMEPICKER_DEBUG
  1224             qDebug() << "resizeModel: oldStart=" << oldStart
  1313     qDebug() << "resizeModel: oldStart=" << oldStart
  1225                      << " oldEnd=" << oldEnd << " newStart=" 
  1314             << " oldEnd=" << oldEnd << " newStart="
  1226                      << newStart << " newEnd=" << newEnd
  1315             << newStart << " newEnd=" << newEnd
  1227                      << " interval=" << interval;
  1316             << " interval=" << interval;
  1228 #endif
  1317 #endif
  1229 	    bool b1=false,b2=false;
  1318     bool b1=false,b2=false;
  1230             int oldinterval=model->rowCount()>1 ? (model->index(1,0).data().toInt(&b1)-model->index(0,0).data().toInt(&b2)):0; 
  1319     int oldinterval=model->rowCount()>1 ? (model->index(1,0).data().toInt(&b1)-model->index(0,0).data().toInt(&b2)):0;
  1231 #ifdef HBDATETIMEPICKER_DEBUG
  1320 #ifdef HBDATETIMEPICKER_DEBUG
  1232             qDebug() << "resizeModel:sameoldInterval=" << oldinterval;
  1321     qDebug() << "resizeModel:sameoldInterval=" << oldinterval;
  1233 #endif
  1322 #endif
  1234             if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) {
  1323     if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) {
  1235                 if(newEnd>oldEnd) {
       
  1236                     int rowCount=model->rowCount();
       
  1237 #ifdef HBDATETIMEPICKER_DEBUG
       
  1238                     qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
       
  1239 #endif
       
  1240                     model->insertRows(rowCount,(newEnd-oldEnd)/interval);
       
  1241                     for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
       
  1242                         QModelIndex index=model->index(i+rowCount,0);
       
  1243                         if(index.isValid()) {
       
  1244                             model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
       
  1245 #ifdef HBDATETIMEPICKER_DEBUG
       
  1246                             qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
       
  1247 #endif
       
  1248                         }
       
  1249                     }
       
  1250                 }
       
  1251                 if(oldEnd>newEnd) {
       
  1252                     //if the start offset is preset more items can fit at end
       
  1253                     int stay=((newEnd-newStart)/interval)+1;
       
  1254                     int count=model->rowCount()-stay;
       
  1255 #ifdef HBDATETIMEPICKER_DEBUG
       
  1256                     qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
       
  1257                              << " data=" << model->index((model->rowCount()-count),0).data().toString();
       
  1258 #endif
       
  1259                     model->removeRows((model->rowCount()-count),count);
       
  1260                 }
       
  1261                 return;//optimizing inserts when interval is set
       
  1262             } else {
       
  1263 	        if(b1 && b2) {		
       
  1264 		    model->removeRows(0,model->rowCount());
       
  1265                     oldStart = oldEnd = 0;
       
  1266 	        }
       
  1267             }
       
  1268 
       
  1269         if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
       
  1270 #ifdef HBDATETIMEPICKER_DEBUG
       
  1271             qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")";
       
  1272 #endif
       
  1273 
       
  1274             model->insertRows(0,((newEnd-newStart)/interval)+1);
       
  1275             for(int i=0;i<=((newEnd-newStart)/interval);++i) {
       
  1276                 QString text=(this->*localeFunc)((i*interval)+newStart);
       
  1277 #ifdef HB_TEXT_MEASUREMENT_UTILITY
       
  1278                 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
       
  1279                         HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
       
  1280                     text.append(QChar(LOC_TEST_START));
       
  1281                     text.append("qtl_datetimepicker_popup_month_sec");
       
  1282                     text.append(QChar(LOC_TEST_END));
       
  1283                 }
       
  1284 #endif
       
  1285                 QModelIndex index=model->index(i,0);
       
  1286                 if(index.isValid()) {
       
  1287                     model->setData(index,text);
       
  1288 #ifdef HBDATETIMEPICKER_DEBUG
       
  1289                     qDebug() << "resizeModel:setData(" << i << "," << text << ")";
       
  1290 #endif
       
  1291                 }
       
  1292             }
       
  1293             return;
       
  1294         }
       
  1295 
       
  1296         if(newStart<oldStart) {
       
  1297 #ifdef HBDATETIMEPICKER_DEBUG
       
  1298             qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")";
       
  1299 #endif
       
  1300             model->insertRows(0,(oldStart-newStart)/interval);
       
  1301             for(int i=0;i<((oldStart-newStart)/interval);++i) {
       
  1302                 QModelIndex index=model->index(i,0);
       
  1303                 if(index.isValid()) {
       
  1304                     model->setData(index,(this->*localeFunc)((i*interval)+newStart));
       
  1305 #ifdef HBDATETIMEPICKER_DEBUG
       
  1306                     qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")";
       
  1307 #endif
       
  1308                 }
       
  1309             }
       
  1310         }
       
  1311 
       
  1312         if(newEnd>oldEnd) {
  1324         if(newEnd>oldEnd) {
  1313             int rowCount=model->rowCount();
  1325             int rowCount=model->rowCount();
  1314 #ifdef HBDATETIMEPICKER_DEBUG
  1326 #ifdef HBDATETIMEPICKER_DEBUG
  1315             qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
  1327             qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
  1316 #endif
  1328 #endif
  1317             model->insertRows(rowCount,(newEnd-oldEnd)/interval);
  1329             model->insertRows(rowCount,(newEnd-oldEnd)/interval);
  1318             for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
  1330             for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
  1319                 QModelIndex index=model->index(i+rowCount,0);
  1331                 QModelIndex index=model->index(i+rowCount,0);
  1320                 if(index.isValid()) {
  1332                 if(index.isValid()) {
  1321                     model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
  1333                     model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
  1322 #ifdef HBDATETIMEPICKER_DEBUG
  1334 #ifdef HBDATETIMEPICKER_DEBUG
  1323                     qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
  1335                     qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
  1324 #endif
  1336 #endif
  1325                 }
  1337                 }
  1326             }
  1338             }
  1327         }
  1339         }
  1328         if(newStart>oldStart) {
       
  1329 #ifdef HBDATETIMEPICKER_DEBUG
       
  1330             qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")"
       
  1331                              << " data=" << model->index((newStart-oldStart)/interval,0).data().toString();
       
  1332 #endif
       
  1333             model->removeRows(0,(newStart-oldStart)/interval);
       
  1334         }
       
  1335 
       
  1336         if(oldEnd>newEnd) {
  1340         if(oldEnd>newEnd) {
  1337 //#ifdef HBDATETIMEPICKER_DEBUG
  1341             //if the start offset is preset more items can fit at end
  1338 //            qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")";
  1342             int stay=((newEnd-newStart)/interval)+1;
  1339 //#endif
  1343             int count=model->rowCount()-stay;
  1340 //            model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval);
  1344 #ifdef HBDATETIMEPICKER_DEBUG
  1341                     //if the start offset is preset more items can fit at end
  1345             qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
  1342                     int stay=((newEnd-newStart)/interval)+1;
  1346                     << " data=" << model->index((model->rowCount()-count),0).data().toString();
  1343                     int count=model->rowCount()-stay;
  1347 #endif
  1344 #ifdef HBDATETIMEPICKER_DEBUG
  1348             model->removeRows((model->rowCount()-count),count);
  1345                     qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
  1349         }
  1346                              << " data=" << model->index((model->rowCount()-count),0).data().toString();
  1350         return;//optimizing inserts when interval is set
  1347 #endif
  1351     } else {
  1348                     model->removeRows((model->rowCount()-count),count);
  1352         if(b1 && b2) {
  1349         }
  1353             model->removeRows(0,model->rowCount());
       
  1354             oldStart = oldEnd = 0;
       
  1355         }
       
  1356     }
       
  1357 
       
  1358     if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
       
  1359 #ifdef HBDATETIMEPICKER_DEBUG
       
  1360         qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")";
       
  1361 #endif
       
  1362 
       
  1363         model->insertRows(0,((newEnd-newStart)/interval)+1);
       
  1364         for(int i=0;i<=((newEnd-newStart)/interval);++i) {
       
  1365             QString text=(this->*localeFunc)((i*interval)+newStart);
       
  1366 #ifdef HB_TEXT_MEASUREMENT_UTILITY
       
  1367             if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
       
  1368                  HbTextMeasurementUtility::instance()->locTestMode() ) {
       
  1369                 text.append(QChar(LOC_TEST_START));
       
  1370                 text.append("qtl_datetimepicker_popup_month_sec");
       
  1371                 text.append(QChar(LOC_TEST_END));
       
  1372             }
       
  1373 #endif
       
  1374             QModelIndex index=model->index(i,0);
       
  1375             if(index.isValid()) {
       
  1376                 model->setData(index,text);
       
  1377 #ifdef HBDATETIMEPICKER_DEBUG
       
  1378                 qDebug() << "resizeModel:setData(" << i << "," << text << ")";
       
  1379 #endif
       
  1380             }
       
  1381         }
       
  1382         return;
       
  1383     }
       
  1384 
       
  1385     if(newStart<oldStart) {
       
  1386 #ifdef HBDATETIMEPICKER_DEBUG
       
  1387         qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")";
       
  1388 #endif
       
  1389         model->insertRows(0,(oldStart-newStart)/interval);
       
  1390         for(int i=0;i<((oldStart-newStart)/interval);++i) {
       
  1391             QModelIndex index=model->index(i,0);
       
  1392             if(index.isValid()) {
       
  1393                 model->setData(index,(this->*localeFunc)((i*interval)+newStart));
       
  1394 #ifdef HBDATETIMEPICKER_DEBUG
       
  1395                 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")";
       
  1396 #endif
       
  1397             }
       
  1398         }
       
  1399     }
       
  1400 
       
  1401     if(newEnd>oldEnd) {
       
  1402         int rowCount=model->rowCount();
       
  1403 #ifdef HBDATETIMEPICKER_DEBUG
       
  1404         qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
       
  1405 #endif
       
  1406         model->insertRows(rowCount,(newEnd-oldEnd)/interval);
       
  1407         for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
       
  1408             QModelIndex index=model->index(i+rowCount,0);
       
  1409             if(index.isValid()) {
       
  1410                 model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
       
  1411 #ifdef HBDATETIMEPICKER_DEBUG
       
  1412                 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
       
  1413 #endif
       
  1414             }
       
  1415         }
       
  1416     }
       
  1417     if(newStart>oldStart) {
       
  1418 #ifdef HBDATETIMEPICKER_DEBUG
       
  1419         qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")"
       
  1420                 << " data=" << model->index((newStart-oldStart)/interval,0).data().toString();
       
  1421 #endif
       
  1422         model->removeRows(0,(newStart-oldStart)/interval);
       
  1423     }
       
  1424 
       
  1425     if(oldEnd>newEnd) {
       
  1426         //#ifdef HBDATETIMEPICKER_DEBUG
       
  1427         //            qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")";
       
  1428         //#endif
       
  1429         //            model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval);
       
  1430         //if the start offset is preset more items can fit at end
       
  1431         int stay=((newEnd-newStart)/interval)+1;
       
  1432         int count=model->rowCount()-stay;
       
  1433 #ifdef HBDATETIMEPICKER_DEBUG
       
  1434         qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
       
  1435                 << " data=" << model->index((model->rowCount()-count),0).data().toString();
       
  1436 #endif
       
  1437         model->removeRows((model->rowCount()-count),count);
       
  1438     }
  1350 }  
  1439 }  
  1351 
  1440 
  1352 
  1441 
  1353 void HbDateTimePickerPrivate::createPrimitives()
  1442 void HbDateTimePickerPrivate::createPrimitives()
  1354 {
  1443 {    
  1355     Q_Q(HbDateTimePicker);
  1444     Q_Q(HbDateTimePicker);
  1356     if(!mBackground) {
  1445     if (!mBackground) {
  1357         mBackground = q->style()->createPrimitive(HbStyle::P_DateTimePicker_background,q);
  1446         mBackground = q->style()->createPrimitive(HbStyle::PT_FrameItem,"background",q);
  1358         q->style()->setItemName(mBackground,"background");
  1447     }
  1359     }
  1448 
  1360     if(!mFrame) {
  1449     if(!mFrame) {
  1361         mFrame = q->style()->createPrimitive(HbStyle::P_DateTimePicker_frame,q);
  1450         mFrame = q->style()->createPrimitive(HbStyle::PT_FrameItem,"frame",q);
  1362         q->style()->setItemName(mFrame,"frame");
  1451     }
  1363     }
  1452 
  1364 
  1453     if(!mHighlight) {
  1365     if(!mHighlight){
  1454         mHighlight = q->style()->createPrimitive(HbStyle::PT_FrameItem,"highlight",q);
  1366         mHighlight = q->style()->createPrimitive(HbStyle::P_TumbleView_highlight,q);
       
  1367         q->style()->setItemName(mHighlight,"highlight");
       
  1368     }
  1455     }
  1369 }
  1456 }
  1370 
  1457 
  1371 void HbDateTimePickerPrivate::_q_dayChanged(int index)
  1458 void HbDateTimePickerPrivate::_q_dayChanged(int index)
  1372 {
  1459 {
  1444             end = mDateTime.date().daysInMonth();
  1531             end = mDateTime.date().daysInMonth();
  1445         }
  1532         }
  1446 
  1533 
  1447         //set if dayrange changed
  1534         //set if dayrange changed
  1448         if((start != mDayOffset)
  1535         if((start != mDayOffset)
  1449                 ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
  1536             ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
  1450             setDayRange(start,end);
  1537             setDayRange(start,end);
  1451         }
  1538         }
  1452     }
  1539     }
  1453 
  1540 
  1454     emitDateChange();
  1541     emitDateChange();
  1501             end = 12;
  1588             end = 12;
  1502         }
  1589         }
  1503 
  1590 
  1504         //set if range changed
  1591         //set if range changed
  1505         if((start != mMonthOffset)
  1592         if((start != mMonthOffset)
  1506                 || (end != mMonthModel->rowCount()-1)) {
  1593             || (end != mMonthModel->rowCount()-1)) {
  1507             setMonthRange(start,end);
  1594             setMonthRange(start,end);
  1508         }
  1595         }
  1509 
  1596 
  1510     }
  1597     }
  1511     
  1598     
  1524             end = mDateTime.date().daysInMonth();
  1611             end = mDateTime.date().daysInMonth();
  1525         }
  1612         }
  1526 
  1613 
  1527         //set if dayrange changed
  1614         //set if dayrange changed
  1528         if((start != mDayOffset)
  1615         if((start != mDayOffset)
  1529                 ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
  1616             ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
  1530             setDayRange(start,end);
  1617             setDayRange(start,end);
  1531         }
  1618         }
  1532     }
  1619     }
  1533 
  1620 
  1534     emitDateChange();
  1621     emitDateChange();
  1572             end = 59;
  1659             end = 59;
  1573         }
  1660         }
  1574 
  1661 
  1575         //set if range changed
  1662         //set if range changed
  1576         if((start != mMinuteOffset)
  1663         if((start != mMinuteOffset)
  1577                 || (end != start+mMinuteModel->rowCount()-1)) {
  1664             || (end != start+mMinuteModel->rowCount()-1)) {
  1578             setMinuteRange(start,end);
  1665             setMinuteRange(start,end);
  1579         }
  1666         }
  1580 
  1667 
  1581     }
  1668     }
  1582     
  1669     
  1595             end = 59;
  1682             end = 59;
  1596         }
  1683         }
  1597 
  1684 
  1598         //set if seconds range changed
  1685         //set if seconds range changed
  1599         if((start != mSecondOffset)
  1686         if((start != mSecondOffset)
  1600                 ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
  1687             ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
  1601             setSecondRange(start,end);
  1688             setSecondRange(start,end);
  1602         }
  1689         }
  1603     }
  1690     }
  1604 
  1691 
  1605     //check if am or pm and scroll to respective time
  1692     //check if am or pm and scroll to respective time
  1625     bool *bOk = false;
  1712     bool *bOk = false;
  1626 #ifdef HBDATETIMEPICKER_DEBUG
  1713 #ifdef HBDATETIMEPICKER_DEBUG
  1627     qDebug() << "_q_minutesChanged:" << index;
  1714     qDebug() << "_q_minutesChanged:" << index;
  1628     qDebug() << mLocale.toInt(mMinuteModel->index(mMinuteOffset+index,0).data().toString(),bOk, 10);
  1715     qDebug() << mLocale.toInt(mMinuteModel->index(mMinuteOffset+index,0).data().toString(),bOk, 10);
  1629 #endif
  1716 #endif
  1630 	QTime newTime(mDateTime.time().hour(),mLocale.toInt(mMinuteModel->index(index,0).data().toString(),bOk, 10),mDateTime.time().second());
  1717     QTime newTime(mDateTime.time().hour(),mLocale.toInt(mMinuteModel->index(index,0).data().toString(),bOk, 10),mDateTime.time().second());
  1631     if(newTime.isValid()) {
  1718     if(newTime.isValid()) {
  1632         mDateTime.setTime(newTime);
  1719         mDateTime.setTime(newTime);
  1633     }
  1720     }
  1634     else {
  1721     else {
  1635 #ifdef HBDATETIMEPICKER_DEBUG
  1722 #ifdef HBDATETIMEPICKER_DEBUG
  1655             end = 59;
  1742             end = 59;
  1656         }
  1743         }
  1657 
  1744 
  1658         //set if seconds range changed
  1745         //set if seconds range changed
  1659         if((start != mSecondOffset)
  1746         if((start != mSecondOffset)
  1660                 ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
  1747             ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
  1661             setSecondRange(start,end);
  1748             setSecondRange(start,end);
  1662         }
  1749         }
  1663     }
  1750     }
  1664 
  1751 
  1665     emitTimeChange();
  1752     emitTimeChange();
  1721                 mAmPmPicker->setSelected(0);//invalid so scrollback
  1808                 mAmPmPicker->setSelected(0);//invalid so scrollback
  1722             }
  1809             }
  1723         } 
  1810         } 
  1724     }
  1811     }
  1725 }
  1812 }
       
  1813 void HbDateTimePickerPrivate::processFormatEvent()
       
  1814 {
       
  1815     QDateTime tempDate=mDateTime;
       
  1816     processDisplaySections();
       
  1817     //recreate and rearrange depending on the format
       
  1818     rearrangeTumbleViews();
       
  1819     setDateTime(tempDate);
       
  1820     emitDateTimeChange();
       
  1821 }
       
  1822 void HbDateTimePickerPrivate::postFormatEvent()
       
  1823 {
       
  1824     Q_Q(HbDateTimePicker);
       
  1825     
       
  1826     QCoreApplication::removePostedEvents(q,QEvent::Type(mFormatEventType));
       
  1827 
       
  1828     QCoreApplication::postEvent(q,new QEvent(QEvent::Type(mFormatEventType)));
       
  1829 }