473 mDayOffset = -1; |
467 mDayOffset = -1; |
474 mHourOffset = -1; |
468 mHourOffset = -1; |
475 mMinuteOffset = -1; |
469 mMinuteOffset = -1; |
476 mSecondOffset = -1; |
470 mSecondOffset = -1; |
477 |
471 |
478 createDividers(); |
472 QPointer<HbTumbleView> lastAdded; |
479 |
|
480 //divider stuff |
|
481 //TODO: improve the divider addition and removal |
|
482 foreach(QGraphicsItem *item, mDividers) { |
|
483 HbFrameItem *fame = qgraphicsitem_cast<HbFrameItem *>(item); |
|
484 Q_ASSERT(fame); // WRONG USE OF PRIMITIVES - Please fix it |
|
485 mLayout->removeItem(fame); |
|
486 fame->setVisible(false); |
|
487 } |
|
488 |
|
489 |
|
490 //TODO: improve the divider addition and removal |
|
491 bool hasSeparator = mParser.mSectionNodes.count() > 1; |
|
492 |
473 |
493 for(int i=0;i<mParser.mSectionNodes.count();i++) { |
474 for(int i=0;i<mParser.mSectionNodes.count();i++) { |
494 |
|
495 if(hasSeparator && (mLayout->count()>0)) { |
|
496 //TODO: improve the divider addition and removal |
|
497 HbFrameItem *f=static_cast<HbFrameItem*>(mDividers.at(i - 1)); |
|
498 if(f) { |
|
499 f->setVisible(true); |
|
500 } |
|
501 mLayout->addItem(mDividers.at(i - 1)); |
|
502 } |
|
503 |
|
504 switch(mParser.mSectionNodes[i].type) { |
475 switch(mParser.mSectionNodes[i].type) { |
505 case HbDateTimeParser::AmPmSection: |
476 case HbDateTimeParser::AmPmSection: |
506 mAmPmPicker = new HbTumbleView(q); |
477 mAmPmPicker = new HbTumbleView(q); |
507 mAmPmModel = new QStringListModel(q); |
478 mAmPmModel = new QStringListModel(q); |
508 mAmPmPicker->setModel(mAmPmModel); |
479 mAmPmPicker->setModel(mAmPmModel); |
|
480 //mAmPmPicker->setLoopingEnabled(true); |
509 mLayout->addItem(mAmPmPicker); |
481 mLayout->addItem(mAmPmPicker); |
510 break; |
482 mAmPmPicker->primitive("highlight")->hide(); |
|
483 mAmPmPicker->primitive("separator")->show(); |
|
484 lastAdded = mAmPmPicker; |
|
485 break; |
|
486 |
511 case HbDateTimeParser::DaySection: |
487 case HbDateTimeParser::DaySection: |
512 case HbDateTimeParser::DayOfWeekSection: |
488 case HbDateTimeParser::DayOfWeekSection: |
513 mDayPicker = new HbTumbleView(q); |
489 mDayPicker = new HbTumbleView(q); |
514 mDayModel = new QStringListModel(q); |
490 mDayModel = new QStringListModel(q); |
515 mDayPicker->setModel(mDayModel); |
491 mDayPicker->setModel(mDayModel); |
|
492 //mDayPicker->setLoopingEnabled(true); |
516 mLayout->addItem(mDayPicker); |
493 mLayout->addItem(mDayPicker); |
517 break; |
494 mDayPicker->primitive("highlight")->hide(); |
|
495 mDayPicker->primitive("separator")->show(); |
|
496 lastAdded = mDayPicker; |
|
497 break; |
|
498 |
518 case HbDateTimeParser::MonthSection: |
499 case HbDateTimeParser::MonthSection: |
519 mMonthPicker = new HbTumbleView(q); |
500 mMonthPicker = new HbTumbleView(q); |
520 mMonthModel = new QStringListModel(q); |
501 mMonthModel = new QStringListModel(q); |
521 mMonthPicker->setModel(mMonthModel); |
502 mMonthPicker->setModel(mMonthModel); |
|
503 //mMonthPicker->setLoopingEnabled(true); |
522 mLayout->addItem(mMonthPicker); |
504 mLayout->addItem(mMonthPicker); |
523 break; |
505 mMonthPicker->primitive("highlight")->hide(); |
|
506 mMonthPicker->primitive("separator")->show(); |
|
507 lastAdded = mMonthPicker; |
|
508 break; |
|
509 |
524 case HbDateTimeParser::YearSection: |
510 case HbDateTimeParser::YearSection: |
525 case HbDateTimeParser::YearSection2Digits: |
511 case HbDateTimeParser::YearSection2Digits: |
526 mYearPicker = new HbTumbleView(q); |
512 mYearPicker = new HbTumbleView(q); |
527 mYearModel = new QStringListModel(q); |
513 mYearModel = new QStringListModel(q); |
528 mYearPicker->setModel(mYearModel); |
514 mYearPicker->setModel(mYearModel); |
|
515 //mYearPicker->setLoopingEnabled(true); |
529 mLayout->addItem(mYearPicker); |
516 mLayout->addItem(mYearPicker); |
530 break; |
517 mYearPicker->primitive("highlight")->hide(); |
|
518 mYearPicker->primitive("separator")->show(); |
|
519 lastAdded = mYearPicker; |
|
520 break; |
|
521 |
531 case HbDateTimeParser::SecondSection: |
522 case HbDateTimeParser::SecondSection: |
532 mSecondPicker = new HbTumbleView(q); |
523 mSecondPicker = new HbTumbleView(q); |
533 mSecondModel = new QStringListModel(q); |
524 mSecondModel = new QStringListModel(q); |
534 mSecondPicker->setModel(mSecondModel); |
525 mSecondPicker->setModel(mSecondModel); |
|
526 //mSecondPicker->setLoopingEnabled(false); |
535 mLayout->addItem(mSecondPicker); |
527 mLayout->addItem(mSecondPicker); |
536 break; |
528 mSecondPicker->primitive("highlight")->hide(); |
|
529 mSecondPicker->primitive("separator")->show(); |
|
530 lastAdded = mSecondPicker; |
|
531 break; |
|
532 |
537 case HbDateTimeParser::MinuteSection: |
533 case HbDateTimeParser::MinuteSection: |
538 mMinutePicker = new HbTumbleView(q); |
534 mMinutePicker = new HbTumbleView(q); |
539 mMinuteModel = new QStringListModel(q); |
535 mMinuteModel = new QStringListModel(q); |
540 mMinutePicker->setModel(mMinuteModel); |
536 mMinutePicker->setModel(mMinuteModel); |
|
537 //mMinutePicker->setLoopingEnabled(false); |
541 mLayout->addItem(mMinutePicker); |
538 mLayout->addItem(mMinutePicker); |
542 break; |
539 mMinutePicker->primitive("highlight")->hide(); |
|
540 mMinutePicker->primitive("separator")->show(); |
|
541 lastAdded = mMinutePicker; |
|
542 break; |
|
543 |
543 case HbDateTimeParser::Hour12Section: |
544 case HbDateTimeParser::Hour12Section: |
544 case HbDateTimeParser::Hour24Section: |
545 case HbDateTimeParser::Hour24Section: |
545 mHourPicker = new HbTumbleView(q); |
546 mHourPicker = new HbTumbleView(q); |
546 mHourModel = new QStringListModel(q); |
547 mHourModel = new QStringListModel(q); |
547 mHourPicker->setModel(mHourModel); |
548 mHourPicker->setModel(mHourModel); |
|
549 //mHourPicker->setLoopingEnabled(true); |
548 mLayout->addItem(mHourPicker); |
550 mLayout->addItem(mHourPicker); |
549 break; |
551 mHourPicker->primitive("highlight")->hide(); |
550 default:break; |
552 mHourPicker->primitive("separator")->show(); |
551 } |
553 lastAdded = mHourPicker; |
552 } |
554 break; |
|
555 |
|
556 default: |
|
557 break; |
|
558 } |
|
559 } |
|
560 |
|
561 //For the last added tumble view, hide the separator. |
|
562 if(lastAdded){ |
|
563 lastAdded->primitive("separator")->hide(); |
|
564 } |
|
565 |
553 setRanges(); |
566 setRanges(); |
554 makeConnections(); |
567 makeConnections(); |
555 syncVisualDate(); |
568 syncVisualDate(); |
556 //TODO:what to do with current date, should reset ? |
569 //TODO:what to do with current date, should reset ? |
557 } |
570 } |
558 |
571 |
559 void HbDateTimePickerPrivate::makeConnections() |
572 void HbDateTimePickerPrivate::makeConnections() |
560 { |
573 { |
561 Q_Q(HbDateTimePicker); |
574 Q_Q(HbDateTimePicker); |
1119 model classes with one interface/virtual fuction specialization. |
1141 model classes with one interface/virtual fuction specialization. |
1120 */ |
1142 */ |
1121 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model, |
1143 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model, |
1122 int oldStart, int oldEnd, |
1144 int oldStart, int oldEnd, |
1123 int newStart, int newEnd, |
1145 int newStart, int newEnd, |
1124 QString (HbDateTimePickerPrivate::*localeFunc)(int)) |
1146 QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval) |
1125 { |
1147 { |
1126 //if row count is zero, then insert from newEnd to newStart |
1148 if(interval > 1){ |
|
1149 model->removeRows(0, model->rowCount()); |
|
1150 } |
|
1151 |
1127 if((model->rowCount() == 0) && (newEnd-newStart>=0)) { |
1152 if((model->rowCount() == 0) && (newEnd-newStart>=0)) { |
1128 //initialize condition |
1153 //initialize condition |
1129 model->insertRows(0,newEnd-newStart+1); |
1154 |
1130 for(int i=0;i<=newEnd-newStart;i++) { |
1155 for(int i=0;i<=newEnd-newStart;i++) { |
1131 QModelIndex index=model->index(i,0); |
1156 //model->setData(index,(this->*localeFunc)(i+newStart));//TODO:add a readable typedef |
1132 if(index.isValid()) { |
1157 QString text; |
1133 //model->setData(index,(this->*localeFunc)(i+newStart));//TODO:add a readable typedef |
1158 |
1134 QString text = (this->*localeFunc)(i+newStart); |
1159 if(interval > 1){ |
|
1160 if(((newStart + interval) * i) <= newEnd){ |
|
1161 model->insertRow(i); |
|
1162 text = (this->*localeFunc)(!((newStart + interval)*i) ? newStart : (newStart + interval)*i); |
|
1163 } |
|
1164 else{ |
|
1165 break; |
|
1166 } |
|
1167 } |
|
1168 else{ |
|
1169 model->insertRow(i); |
|
1170 text = (this->*localeFunc)(i+newStart); |
|
1171 } |
|
1172 |
1135 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
1173 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
1136 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth && |
1174 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth && |
1137 HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) { |
1175 HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) { |
1138 text.append(QChar(LOC_TEST_START)); |
1176 text.append(QChar(LOC_TEST_START)); |
1139 text.append("qtl_datetimepicker_popup_month_sec"); |
1177 text.append("qtl_datetimepicker_popup_month_sec"); |
1140 text.append(QChar(LOC_TEST_END)); |
1178 text.append(QChar(LOC_TEST_END)); |
1141 } |
1179 } |
1142 #endif |
1180 #endif |
|
1181 QModelIndex index=model->index(i,0); |
|
1182 if(index.isValid()) { |
1143 model->setData(index,text);//TODO:add a readable typedef |
1183 model->setData(index,text);//TODO:add a readable typedef |
1144 } |
1184 } |
|
1185 |
1145 } |
1186 } |
1146 return; |
1187 return; |
1147 } |
1188 } |
1148 |
1189 |
1149 if(newStart < oldStart) { |
1190 if(newStart < oldStart) { |
1184 } |
1225 } |
1185 if(!mFrame) { |
1226 if(!mFrame) { |
1186 mFrame = q->style()->createPrimitive(HbStyle::P_DateTimePicker_frame,q); |
1227 mFrame = q->style()->createPrimitive(HbStyle::P_DateTimePicker_frame,q); |
1187 q->style()->setItemName(mFrame,"frame"); |
1228 q->style()->setItemName(mFrame,"frame"); |
1188 } |
1229 } |
1189 createDividers(); |
1230 |
1190 } |
1231 if(!mHighlight){ |
1191 |
1232 mHighlight = q->style()->createPrimitive(HbStyle::P_TumbleView_highlight,q); |
1192 void HbDateTimePickerPrivate::createDividers() |
1233 q->style()->setItemName(mHighlight,"highlight"); |
1193 { |
1234 } |
1194 Q_Q(HbDateTimePicker); |
|
1195 |
|
1196 if( mParser.mSectionNodes.count() == mDividers.count() ){ |
|
1197 return; |
|
1198 } |
|
1199 |
|
1200 if( mParser.mSectionNodes.count() < mDividers.count() ){ |
|
1201 for( int i = mParser.mSectionNodes.count() - 1; i > mDividers.count(); i--) |
|
1202 { |
|
1203 QPointer<QGraphicsWidget> item = mDividers.at(i); |
|
1204 mDividers.removeAt(i); |
|
1205 delete item; |
|
1206 } |
|
1207 |
|
1208 return; |
|
1209 } |
|
1210 else if( mParser.mSectionNodes.count() > mDividers.count() ){ |
|
1211 |
|
1212 for(int i = mDividers.count();i < mParser.mSectionNodes.count(); i++) { //TODO: optimally create when required |
|
1213 QGraphicsItem *item=q->style()->createPrimitive(HbStyle::P_DateTimePicker_separator, mContent); |
|
1214 Q_ASSERT(item->isWidget()); |
|
1215 q->style()->setItemName(item,"separator"); |
|
1216 mDividers.append(static_cast<QGraphicsWidget *>(item)); |
|
1217 } |
|
1218 } |
|
1219 } |
|
1220 |
|
1221 void HbDateTimePickerPrivate::updateDividers() |
|
1222 { |
|
1223 /*Q_Q(HbDateTimePicker); |
|
1224 HbStyleOption option; |
|
1225 q->initStyleOption(&option); |
|
1226 for(int i=0;i<qMin(mDividers.count(),mDividerIndex);i++) { |
|
1227 q->style()->updatePrimitive((QGraphicsItem*)mDividers.at(i),HbStyle::P_DateTimePicker_separator,&option); |
|
1228 }*/ |
|
1229 |
|
1230 //TODO: improve the divider addition and removal |
|
1231 |
|
1232 //using the style update primitive crashes. need to investigate why |
|
1233 |
|
1234 } |
1235 } |
1235 |
1236 |
1236 void HbDateTimePickerPrivate::_q_dayChanged(int index) |
1237 void HbDateTimePickerPrivate::_q_dayChanged(int index) |
1237 { |
1238 { |
1238 #ifdef HBDATETIMEPICKER_DEBUG |
1239 #ifdef HBDATETIMEPICKER_DEBUG |