src/hbinput/inputwidgets/hbinputcandidatelist.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    32 #include <hbframeitem.h>
    32 #include <hbframeitem.h>
    33 #include <hbframedrawer.h>
    33 #include <hbframedrawer.h>
    34 
    34 
    35 #include <hbdeviceprofile.h>
    35 #include <hbdeviceprofile.h>
    36 
    36 
       
    37 #include <HbFrameDrawer>
       
    38 #include <hbframedrawerpool_p.h>
    37 #include <hbinputmethod.h>
    39 #include <hbinputmethod.h>
    38 #include <hbinputsettingproxy.h>
    40 #include <hbinputsettingproxy.h>
    39 #include <hbinputvkbhost.h>
    41 #include <hbinputvkbhost.h>
    40 #include <hbinputregioncollector_p.h>
    42 #include <hbinputregioncollector_p.h>
    41 
    43 
    42 #include "hbdialog_p.h"
    44 #include "hbinputpopupbase_p.h"
    43 
    45 
       
    46 const QString HbCandidateListBackground("qtg_fr_popup_secondary");
    44 const int HbCandListDefaultNumRows = 5;
    47 const int HbCandListDefaultNumRows = 5;
    45 const qreal HbCandListMaxWidthMultiplier = 0.8;
    48 const qreal HbCandListMaxWidthMultiplier = 0.8;
    46 const qreal HbCandListMinWidth = 30.0;
    49 const qreal HbCandListMinWidth = 30.0;
    47 const qreal HbAutoComplPopupSideMargin = 15.0;
    50 const qreal HbAutoComplPopupSideMargin = 15.0;
    48 const qreal HbAutoComplPopupVerticalMargin = 15.0;
       
    49 const qreal HbAutoComplPopupMinAllowedHeight = 25.0;
    51 const qreal HbAutoComplPopupMinAllowedHeight = 25.0;
    50 
    52 
    51 /// @cond
    53 /// @cond
    52 
    54 
    53 class HbCandidateListPrivate : public HbDialogPrivate
    55 class HbCandidateListPrivate : public HbInputPopupBasePrivate
    54 {
    56 {
    55     Q_DECLARE_PUBLIC(HbCandidateList)
    57     Q_DECLARE_PUBLIC(HbCandidateList)
    56 
    58 
    57 public:
    59 public:
    58     HbCandidateListPrivate(HbInputMethod *input);
    60     HbCandidateListPrivate(HbInputMethod *input);
    59     ~HbCandidateListPrivate();
    61     ~HbCandidateListPrivate();
    60     void calculateAndSetSize(qreal maxWidth);
    62     void calculateAndSetSize(qreal maxWidth);
    61     void initFrameIcon();
    63     void setBackground();
    62 
    64 
    63 public:
    65 public:
    64     HbListWidget *mList;
    66     HbListWidget *mList;
    65     HbInputMethod *mInput;
    67     HbInputMethod *mInput;
    66     int numRows;
    68     int numRows;
    67     int numCandidates;
    69     int numCandidates;
    68     int longestStringWidth;
    70     int longestStringWidth;
    69     HbFrameItem *mFrameBackground;
       
    70     HbListWidgetItem *mSpellQueryItem;
    71     HbListWidgetItem *mSpellQueryItem;
    71     bool mCandidateCommitted;
    72     bool mCandidateCommitted;
    72     bool mSpellQueryOpenIsPending;
    73     bool mSpellQueryOpenIsPending;
    73 };
    74 };
    74 
    75 
    75 HbCandidateListPrivate::HbCandidateListPrivate(HbInputMethod *input)
    76 HbCandidateListPrivate::HbCandidateListPrivate(HbInputMethod *input)
    76     : mInput(input),
    77     : mInput(input),
    77       numRows(HbCandListDefaultNumRows),
    78       numRows(HbCandListDefaultNumRows),
    78       numCandidates(0),
    79       numCandidates(0),
    79       longestStringWidth(0),
    80       longestStringWidth(0),
    80       mFrameBackground(0),
       
    81       mSpellQueryItem(0),
    81       mSpellQueryItem(0),
    82       mCandidateCommitted(false),
    82       mCandidateCommitted(false),
    83       mSpellQueryOpenIsPending(false)
    83       mSpellQueryOpenIsPending(false)
    84 {
    84 {
    85     Q_Q(HbCandidateList);
    85     mList = new HbListWidget();
    86 
       
    87     mList = new HbListWidget(q);
       
    88     mList->setEnabledAnimations(HbAbstractItemView::None);
    86     mList->setEnabledAnimations(HbAbstractItemView::None);
    89 }
    87 }
    90 
    88 
    91 HbCandidateListPrivate::~HbCandidateListPrivate()
    89 HbCandidateListPrivate::~HbCandidateListPrivate()
    92 {
    90 {
    93 }
    91 }
    94 
    92 
    95 void HbCandidateListPrivate::initFrameIcon()
    93 void HbCandidateListPrivate::setBackground()
    96 {
    94 {
    97     Q_Q(HbCandidateList);
    95   Q_Q(HbCandidateList);
    98 
    96   HbFrameDrawer *drawer = HbFrameDrawerPool::get(HbCandidateListBackground, HbFrameDrawer::NinePieces, QSizeF(q->boundingRect().width(), q->boundingRect().height()));
    99     mFrameBackground = static_cast<HbFrameItem *>(q->primitive(HbStyle::P_Popup_background));
    97   if (drawer) {
   100 
    98     drawer->setFillWholeRect(true);
   101     if (mFrameBackground == 0) {
    99     q->setBackgroundItem(new HbFrameItem(drawer));
   102         mFrameBackground = static_cast<HbFrameItem *>(q->style()->createPrimitive((HbStyle::Primitive)(HbStyle::P_Popup_background), q));
   100   }
   103     }
       
   104 }
   101 }
   105 
   102 
   106 
   103 
   107 void HbCandidateListPrivate::calculateAndSetSize(qreal maxWidth)
   104 void HbCandidateListPrivate::calculateAndSetSize(qreal maxWidth)
   108 {
   105 {
   142 }
   139 }
   143 
   140 
   144 /// @endcond
   141 /// @endcond
   145 
   142 
   146 /*!
   143 /*!
   147 @proto
   144 @stable
   148 @hbinput
   145 @hbinput
   149 \class HbCandidateList
   146 \class HbCandidateList
   150 \brief Hb based candidate list popup.
   147 \brief Hb based candidate list popup.
   151 
   148 
   152 Shows a list of word prediction candidates. Informs the owning
   149 Shows a list of word prediction candidates. Informs the owning
   160 Constructor.
   157 Constructor.
   161 @param input The input method that uses this widget.
   158 @param input The input method that uses this widget.
   162 @param parent parent of the widget.
   159 @param parent parent of the widget.
   163 */
   160 */
   164 HbCandidateList::HbCandidateList(HbInputMethod *input, QGraphicsItem *parent)
   161 HbCandidateList::HbCandidateList(HbInputMethod *input, QGraphicsItem *parent)
   165     : HbDialog(*new HbCandidateListPrivate(input), parent)
   162     : HbInputPopupBase(*new HbCandidateListPrivate(input), parent)
   166 {
   163 {
   167     Q_D(HbCandidateList);
   164     Q_D(HbCandidateList);
   168 
   165 
   169     HbInputRegionCollector::instance()->attach(this);
   166     HbInputRegionCollector::instance()->attach(this);
   170 
   167 
   171     d->setPriority(HbPopupPrivate::VirtualKeyboard + 1);  // Should be shown on top of virtual keyboard.
   168     d->setBackground();
   172     d->initFrameIcon();
   169   
   173 
   170     d->mList->setParent(this);
   174     // Make sure the preview pane never steals focus.
       
   175     setFlag(QGraphicsItem::ItemIsPanel, true);
       
   176     setActive(false);
       
   177 
   171 
   178     setTimeout(NoTimeout);
   172     setTimeout(NoTimeout);
   179     setAttribute(Qt::WA_InputMethodEnabled, false);
   173     setAttribute(Qt::WA_InputMethodEnabled, false);
   180     connect(d->mList, SIGNAL(activated(HbListWidgetItem *)), this, SLOT(itemActivated(HbListWidgetItem *)));
   174     connect(d->mList, SIGNAL(activated(HbListWidgetItem *)), this, SLOT(itemActivated(HbListWidgetItem *)));
   181     connect(d->mList, SIGNAL(longPressed(HbListWidgetItem *, const QPointF &)), this, SLOT(itemActivated(HbListWidgetItem *)));
   175     connect(d->mList, SIGNAL(longPressed(HbListWidgetItem *, const QPointF &)), this, SLOT(itemActivated(HbListWidgetItem *)));
   194 Populates the candidate list with text strings given as parameter.
   188 Populates the candidate list with text strings given as parameter.
   195 */
   189 */
   196 void HbCandidateList::populateList(const QStringList &candidates, bool addSpellQuery)
   190 void HbCandidateList::populateList(const QStringList &candidates, bool addSpellQuery)
   197 {
   191 {
   198     Q_D(HbCandidateList);
   192     Q_D(HbCandidateList);
   199 	// Only for the first time when we launch candidate list its not setting a layout, 
   193     // Only for the first time when we launch candidate list its not setting a layout, 
   200 	// Mostly the problem is form Qt side, for the time being to resolve issue related to candidate list
   194     // Mostly the problem is form Qt side, for the time being to resolve issue related to candidate list
   201 	// making visible property true.  
   195     // making visible property true.  
   202     setVisible(true);
   196     setVisible(true);
       
   197     QEvent event(QEvent::Polish);
       
   198     QApplication::sendEvent(this, &event);
   203     setContentWidget(d->mList);
   199     setContentWidget(d->mList);
   204 
   200 
   205     d->setPriority(HbPopupPrivate::VirtualKeyboard + 1);  // Should be shown on top of virtual keyboard.
       
   206     d->mList->clear();
   201     d->mList->clear();
   207 
   202 
   208     int longestwidth = 0;
   203     int longestwidth = 0;
   209     int finalWidth = 250;
   204     int finalWidth = 250;
   210     for (int i = 0; i < candidates.count(); i++) {
   205     for (int i = 0; i < candidates.count(); i++) {
   329         d->mSpellQueryOpenIsPending = false;
   324         d->mSpellQueryOpenIsPending = false;
   330         emit launchSpellQueryDialog();
   325         emit launchSpellQueryDialog();
   331     }
   326     }
   332 }
   327 }
   333 
   328 
   334 void HbCandidateList::updatePrimitives()
       
   335 {
       
   336     Q_D(HbCandidateList);
       
   337 
       
   338     d->mFrameBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   339     d->mFrameBackground->frameDrawer().setFrameGraphicsName("qtg_fr_popup_secondary");
       
   340     d->mFrameBackground->setGeometry(boundingRect());
       
   341 }
       
   342 
   329 
   343 /*!
   330 /*!
   344 Finds correct size and position for auto-completion popup. It checks if there is enough space to display candidate popup,
   331 Finds correct size and position for auto-completion popup. It checks if there is enough space to display candidate popup,
   345 finds out whether it is display above or below the editor and sets correct width.
   332 finds out whether it is display above or below the editor and sets correct width.
   346 Returns true if suitable position was found and set.
   333 Returns true if suitable position was found and set.
   356         if (freeViewRect.isValid() &&
   343         if (freeViewRect.isValid() &&
   357             microFocus.isValid() &&
   344             microFocus.isValid() &&
   358             freeViewRect.contains(microFocus)) {
   345             freeViewRect.contains(microFocus)) {
   359             QRectF topRect = freeViewRect;
   346             QRectF topRect = freeViewRect;
   360             topRect.setBottom(microFocus.top());
   347             topRect.setBottom(microFocus.top());
   361             topRect.adjust(HbAutoComplPopupSideMargin, HbAutoComplPopupVerticalMargin, -HbAutoComplPopupSideMargin, -HbAutoComplPopupVerticalMargin);
   348             topRect.adjust(HbAutoComplPopupSideMargin, 0, -HbAutoComplPopupSideMargin, 0);
   362 
   349 
   363             QRectF bottomRect = freeViewRect;
   350             QRectF bottomRect = freeViewRect;
   364             bottomRect.setTop(microFocus.bottom());
   351             bottomRect.setTop(microFocus.bottom());
   365             bottomRect.adjust(HbAutoComplPopupSideMargin, HbAutoComplPopupVerticalMargin, -HbAutoComplPopupSideMargin, -HbAutoComplPopupVerticalMargin);
   352             bottomRect.adjust(HbAutoComplPopupSideMargin, 0, -HbAutoComplPopupSideMargin, 0);
   366 
   353 
   367             if (topRect.height() > bottomRect.height()) {
   354             if (topRect.height() > bottomRect.height()) {
   368                 if (topRect.height() > HbAutoComplPopupMinAllowedHeight) {
   355                 if (topRect.height() > HbAutoComplPopupMinAllowedHeight) {
   369                     qreal finalHeight = (size().height() < topRect.height() ? size().height() : topRect.height());
   356                     qreal finalHeight = (size().height() < topRect.height() ? size().height() : topRect.height());
   370                     topRect.setTop(topRect.bottom() - finalHeight);
   357                     topRect.setTop(topRect.bottom() - finalHeight);