src/hbinput/inputwidgets/hbinputexactwordpopup.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    28 #include <QIcon>
    28 #include <QIcon>
    29 #include <QGraphicsSceneMouseEvent>
    29 #include <QGraphicsSceneMouseEvent>
    30 #include <QGraphicsLinearLayout>
    30 #include <QGraphicsLinearLayout>
    31 
    31 
    32 #include <hbinputregioncollector_p.h>
    32 #include <hbinputregioncollector_p.h>
       
    33 #include <HbFrameDrawer>
       
    34 #include <hbframeitem.h>
       
    35 #include <hbframedrawerpool_p.h>
    33 #include "hbdeviceprofile.h"
    36 #include "hbdeviceprofile.h"
    34 #include "hbdialog.h"
    37 #include "hbdialog.h"
    35 #include "hblabel.h"
    38 #include "hblabel.h"
    36 #include "hbstyleoptionlabel_p.h"
    39 #include "hbstyleoptionlabel_p.h"
    37 #include "hbinputexactwordpopup.h"
    40 #include "hbinputexactwordpopup.h"
    38 #include "hbiconitem.h"
    41 #include "hbiconitem.h"
    39 #include "hbinputsettingproxy.h"
    42 #include "hbinputsettingproxy.h"
    40 #include "hbframeitem.h"
       
    41 #include "hbframedrawer.h"
       
    42 #include "hbdialog_p.h"
    43 #include "hbdialog_p.h"
    43 
    44 
    44 const qreal HbExactWordPopupHeight = 50.0;
    45 const QString HbCandidateListBackground("qtg_fr_popup_secondary");
    45 
       
    46 class HbExactWordPopupPrivate : public HbDialogPrivate
    46 class HbExactWordPopupPrivate : public HbDialogPrivate
    47 {
    47 {
    48     Q_DECLARE_PUBLIC(HbExactWordPopup)
    48     Q_DECLARE_PUBLIC(HbExactWordPopup)
    49 
    49 
    50 public:
    50 public:
    51     HbExactWordPopupPrivate();
    51     HbExactWordPopupPrivate();
    52     ~HbExactWordPopupPrivate();
    52     ~HbExactWordPopupPrivate();
    53 
    53 
    54     void initBackground();
    54     void setBackground();
    55 
    55 
    56 public:
    56 public:
    57     HbLabel *mText;
    57     HbLabel *mText;
    58     HbFrameItem *mPopupBackground;
       
    59 };
    58 };
    60 
    59 
    61 HbExactWordPopupPrivate::HbExactWordPopupPrivate()
    60 HbExactWordPopupPrivate::HbExactWordPopupPrivate()
    62  : mText(0), mPopupBackground(0)
    61  : mText(0)
    63 {
    62 {
    64 }
    63 }
    65 
    64 
    66 HbExactWordPopupPrivate::~HbExactWordPopupPrivate()
    65 HbExactWordPopupPrivate::~HbExactWordPopupPrivate()
    67 {
    66 {
    68 }
    67 }
    69 
    68 
    70 void HbExactWordPopupPrivate::initBackground()
    69 void HbExactWordPopupPrivate::setBackground()
    71 {
    70 {
    72     Q_Q(HbExactWordPopup);
    71     Q_Q(HbExactWordPopup);
    73 
    72 
    74     mPopupBackground = static_cast<HbFrameItem*>(q->primitive((HbStyle::Primitive)HbStylePrivate::P_Popup_background));
    73     HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbCandidateListBackground, HbFrameDrawer::NinePieces, QSizeF(q->boundingRect().width(), q->boundingRect().height()));
    75 
    74   if (drawer) {
    76     if (!mPopupBackground) {
    75     drawer->setFillWholeRect(true);
    77         mPopupBackground = static_cast<HbFrameItem*>(HbStylePrivate::createPrimitive(HbStylePrivate::P_Popup_background, q));
    76     q->setBackgroundItem(new HbFrameItem(drawer));
    78     }
    77   }
    79 
       
    80     if (mPopupBackground->frameDrawer().isNull()) {
       
    81         HbFrameDrawer *fd = new HbFrameDrawer("qtg_fr_popup_secondary", HbFrameDrawer::NinePieces);
       
    82         mPopupBackground->setFrameDrawer(fd);
       
    83     }
       
    84 }
    78 }
    85 
    79 
    86 HbExactWordPopup* HbExactWordPopup::instance(HbExactWordPopupIndicator indicatorArrow)
    80 HbExactWordPopup* HbExactWordPopup::instance(HbExactWordPopupIndicator indicatorArrow)
    87 {
    81 {
    88     static QPointer<HbExactWordPopup> exactWordPopup;
    82     static QPointer<HbExactWordPopup> exactWordPopup;
   108     d->mText->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   102     d->mText->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   109     d->mText->setContentsMargins(0, 0, 0, 0);
   103     d->mText->setContentsMargins(0, 0, 0, 0);
   110 
   104 
   111     setContentWidget(d->mText);
   105     setContentWidget(d->mText);
   112 
   106 
   113     d->initBackground();
   107     d->setBackground();
   114 
   108 
   115     setTimeout(HbPopup::NoTimeout);
   109     setTimeout(HbPopup::NoTimeout);
   116     setBackgroundFaded(false);
   110     setBackgroundFaded(false);
   117     setDismissPolicy(HbPopup::TapInside);
   111     setDismissPolicy(HbPopup::TapInside);
   118     setFocusPolicy(Qt::ClickFocus);
   112     setFocusPolicy(Qt::ClickFocus);
   158 void HbExactWordPopup::showText(QPointF pos)
   152 void HbExactWordPopup::showText(QPointF pos)
   159 {
   153 {
   160     Q_D(HbExactWordPopup);
   154     Q_D(HbExactWordPopup);
   161 
   155 
   162     QFontMetrics fontMetrics(HbFontSpec(HbFontSpec::Primary).font());
   156     QFontMetrics fontMetrics(HbFontSpec(HbFontSpec::Primary).font());
   163     qreal width = fontMetrics.width(text());
   157     qreal width = fontMetrics.width(text()) + 1;
   164 
   158 
   165     d->mText->setMinimumWidth(width);
   159     d->mText->setMinimumWidth(width);
   166     d->mText->setMaximumWidth(width);
   160     d->mText->setMaximumWidth(width);
   167   
   161   
   168     setPos(pos);
   162     setPos(pos);
   191     }
   185     }
   192     // if mouse release event happens outside popup area, don't commit or close the popup
   186     // if mouse release event happens outside popup area, don't commit or close the popup
   193 
   187 
   194 }
   188 }
   195 
   189 
   196 void HbExactWordPopup::updatePrimitives()
       
   197 {
       
   198     Q_D(HbExactWordPopup);
       
   199 
       
   200     d->mPopupBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   201     d->mPopupBackground->frameDrawer().setFrameGraphicsName("qtg_fr_popup_secondary");
       
   202     d->mPopupBackground->setGeometry(boundingRect());
       
   203 }
       
   204 
   190 
   205 // this method is called whenever there is a switch of keypad usage from h/w to virtual
   191 // this method is called whenever there is a switch of keypad usage from h/w to virtual
   206 // h/w keypad needs an indicator, whereas virtual does not, hence set the image appropriately.
   192 // h/w keypad needs an indicator, whereas virtual does not, hence set the image appropriately.
   207 void HbExactWordPopup::setIndicatorArrow(HbExactWordPopupIndicator indicatorArrow)
   193 void HbExactWordPopup::setIndicatorArrow(HbExactWordPopupIndicator indicatorArrow)
   208 {
   194 {