20 |
20 |
21 #include <HbScrollbar> |
21 #include <HbScrollbar> |
22 #include <HbStyle> |
22 #include <HbStyle> |
23 #include <HbApplication> |
23 #include <HbApplication> |
24 #include <HbEffect> |
24 #include <HbEffect> |
25 #include <HbStyleOptionIndexFeedback> |
25 #include <HbFrameItem> |
|
26 #include <HbTextItem> |
26 #include <hgwidgets/hgwidgets.h> |
27 #include <hgwidgets/hgwidgets.h> |
27 |
28 |
28 #include <QTimer> |
29 #include <QTimer> |
29 #include <QSize> |
30 #include <QSize> |
30 #include <QGraphicsScene> |
31 #include <QGraphicsScene> |
327 */ |
328 */ |
328 void HgIndexFeedbackPrivate::updatePrimitives() |
329 void HgIndexFeedbackPrivate::updatePrimitives() |
329 { |
330 { |
330 Q_Q( HgIndexFeedback ); |
331 Q_Q( HgIndexFeedback ); |
331 |
332 |
332 HbStyleOptionIndexFeedback option; |
|
333 q->initStyleOption(&option); |
|
334 if (mTextItem) { |
333 if (mTextItem) { |
335 q->style()->updatePrimitive(mTextItem, HbStyle::P_IndexFeedback_popup_text, &option); |
334 if (HbTextItem* textItem = qgraphicsitem_cast<HbTextItem*>(mTextItem)) { |
|
335 textItem->setFontSpec(FontSpec()); |
|
336 textItem->setGeometry(mPopupTextRect); |
|
337 textItem->setText(mPopupContent); |
|
338 } |
336 } |
339 } |
337 if (mPopupItem) { |
340 if (mPopupItem) { |
338 q->style()->updatePrimitive(mPopupItem, HbStyle::P_IndexFeedback_popup_background, &option); |
341 if (HbFrameItem* frameItem = qgraphicsitem_cast<HbFrameItem*>(mPopupItem)) { |
|
342 frameItem->setGeometry(mPopupBackgroundRect); |
|
343 } |
339 } |
344 } |
340 } |
345 } |
341 |
346 |
342 /* |
347 /* |
343 Create the primitives for the index feedback. |
348 Create the primitives for the index feedback. |
347 Q_Q( HgIndexFeedback ); |
352 Q_Q( HgIndexFeedback ); |
348 |
353 |
349 mPopupItemList.clear(); |
354 mPopupItemList.clear(); |
350 |
355 |
351 if (!mTextItem) { |
356 if (!mTextItem) { |
352 mTextItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_text, q); |
357 HbTextItem *textItem = new HbTextItem(q); |
|
358 textItem->setAlignment(Qt::AlignCenter); |
|
359 textItem->setTextWrapping(Hb::TextNoWrap); |
|
360 HbStyle::setItemName(textItem, QLatin1String("index-text")); |
|
361 textItem->setZValue(q->zValue()+2); |
|
362 mTextItem = textItem; |
353 mTextItem->hide(); |
363 mTextItem->hide(); |
354 mPopupItemList.append(mTextItem); |
364 mPopupItemList.append(mTextItem); |
355 } |
365 } |
356 |
366 |
357 if (!mPopupItem) { |
367 if (!mPopupItem) { |
358 mPopupItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_background, q); |
368 HbFrameItem *frame = new HbFrameItem(q); |
|
369 frame->frameDrawer().setFrameGraphicsName("qtg_fr_popup_preview"); |
|
370 frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
371 qreal cornerPieceSize = 0; |
|
372 q->style()->parameter(QLatin1String("hb-param-background-popup-preview"),cornerPieceSize); |
|
373 frame->frameDrawer().setBorderWidths(cornerPieceSize, cornerPieceSize); |
|
374 HbStyle::setItemName(frame, QLatin1String("index-background")); |
|
375 frame->setZValue(q->zValue()+1); |
|
376 mPopupItem = frame; |
359 mPopupItem->hide(); |
377 mPopupItem->hide(); |
360 mPopupItemList.append(mPopupItem); |
378 mPopupItemList.append(mPopupItem); |
361 } |
379 } |
362 } |
380 } |
363 |
381 |
371 if (mWidget) { |
389 if (mWidget) { |
372 // disconnect from the existing itemView's scrollbars |
390 // disconnect from the existing itemView's scrollbars |
373 mWidget->disconnect(q); |
391 mWidget->disconnect(q); |
374 // uninstall the event filters; |
392 // uninstall the event filters; |
375 mWidget->scrollBar()->removeEventFilter(q); |
393 mWidget->scrollBar()->removeEventFilter(q); |
376 |
394 mWidget->removeEventFilter(q); |
|
395 |
377 mWidget->removeSceneEventFilter(q); |
396 mWidget->removeSceneEventFilter(q); |
378 if (mWidget->scene()) { |
397 if (mWidget->scene()) { |
379 mWidget->scene()->removeItem(q); |
398 mWidget->scene()->removeItem(q); |
380 } |
399 } |
381 } |
400 } |
384 } |
403 } |
385 |
404 |
386 /* |
405 /* |
387 Hooks up the private slots & event filter to a scrollbar. |
406 Hooks up the private slots & event filter to a scrollbar. |
388 */ |
407 */ |
389 void HgIndexFeedbackPrivate::connectScrollBarToIndexFeedback(HbScrollBar* scrollBar) |
408 void HgIndexFeedbackPrivate::connectWidgetToIndexFeedback() |
390 { |
409 { |
391 Q_Q( HgIndexFeedback ); |
410 Q_Q( HgIndexFeedback ); |
392 |
411 |
|
412 if(!mWidget) return; |
|
413 |
|
414 // Install event filter so we receive resize events from parent widget. |
|
415 mWidget->installEventFilter(q); |
|
416 |
|
417 // Install eventfilter to scrollbar so we can receive mousepress and released events |
|
418 HbScrollBar *scrollBar = mWidget->scrollBar(); |
393 if (scrollBar) { |
419 if (scrollBar) { |
394 //q->connect(scrollBar, SIGNAL(valueChanged(qreal, Qt::Orientation)), |
|
395 // q, SLOT(_q_scrollPositionChanged(qreal, Qt::Orientation))); |
|
396 scrollBar->installEventFilter(q); |
420 scrollBar->installEventFilter(q); |
397 } |
421 } |
398 } |
422 } |
399 |
423 |
400 /* |
424 /* |
408 |
432 |
409 if (!mWidget) { |
433 if (!mWidget) { |
410 return; |
434 return; |
411 } |
435 } |
412 |
436 |
413 QRectF contentRect = mWidget->rect(); |
437 QRectF contentRect = mWidget->boundingRect(); |
414 |
438 |
415 HbScrollBar *scrollBar = mWidget->scrollBar(); |
439 HbScrollBar *scrollBar = mWidget->scrollBar(); |
416 if (scrollBar->isInteractive() && mWidget->scrollDirection() == Qt::Vertical) { |
440 if (scrollBar->isInteractive() && mWidget->scrollDirection() == Qt::Vertical) { |
417 contentRect.setWidth( contentRect.width() - scrollBar->rect().width() ); |
441 contentRect.setWidth( contentRect.width() - scrollBar->rect().width() ); |
418 if (HbApplication::layoutDirection() == Qt::RightToLeft) { |
442 if (HbApplication::layoutDirection() == Qt::RightToLeft) { |
562 |
586 |
563 if (mScrollBarPressed) |
587 if (mScrollBarPressed) |
564 updateIndex(); |
588 updateIndex(); |
565 } |
589 } |
566 |
590 |
567 |
591 HbFontSpec HgIndexFeedbackPrivate::FontSpec() const |
|
592 { |
|
593 HbFontSpec fontSpec(HbFontSpec::Primary); |
|
594 switch (mIndexFeedbackPolicy) { |
|
595 case HgWidget::IndexFeedbackSingleCharacter: |
|
596 { |
|
597 fontSpec.setTextHeight(textHeight()); |
|
598 } |
|
599 break; |
|
600 case HgWidget::IndexFeedbackThreeCharacter: |
|
601 { |
|
602 fontSpec.setTextHeight(textHeight()); |
|
603 } |
|
604 break; |
|
605 case HgWidget::IndexFeedbackString: |
|
606 { |
|
607 qreal textPaneHeight = 0; |
|
608 Q_Q(const HgIndexFeedback); |
|
609 q->style()->parameter(QLatin1String("hb-param-text-height-primary"), textPaneHeight); |
|
610 fontSpec.setTextHeight( textPaneHeight ); |
|
611 } |
|
612 break; |
|
613 case HgWidget::IndexFeedbackNone: |
|
614 default: |
|
615 break; |
|
616 } |
|
617 return fontSpec; |
|
618 } |
|
619 |