src/hbinput/inputwidgets/hbinputcandidatelist.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    63     HbCandidateListPrivate(HbInputMethod* input);
    63     HbCandidateListPrivate(HbInputMethod* input);
    64     ~HbCandidateListPrivate();
    64     ~HbCandidateListPrivate();
    65     void calculateAndSetSize(qreal maxWidth);
    65     void calculateAndSetSize(qreal maxWidth);
    66     void initFrameIcon();
    66     void initFrameIcon();
    67 
    67 
    68 public: 
    68 public:
    69     HbListWidget* mList;
    69     HbListWidget* mList;
    70     HbInputMethod* mInput;
    70     HbInputMethod* mInput;
    71     int numRows;
    71     int numRows;
    72     int numCandidates;
    72     int numCandidates;
    73     int longestStringWidth;
    73     int longestStringWidth;
    77 HbCandidateListPrivate::HbCandidateListPrivate(HbInputMethod* input)
    77 HbCandidateListPrivate::HbCandidateListPrivate(HbInputMethod* input)
    78     : mInput(input),
    78     : mInput(input),
    79       numRows(HbCandListDefaultNumRows),
    79       numRows(HbCandListDefaultNumRows),
    80       numCandidates(0),
    80       numCandidates(0),
    81       longestStringWidth(0),
    81       longestStringWidth(0),
    82       mFrameBackground( 0 )
    82       mFrameBackground(0)
    83 {
    83 {
    84     Q_Q(HbCandidateList);
    84     Q_Q(HbCandidateList);
    85 
    85 
    86     mList = new HbListWidget(q);
    86     mList = new HbListWidget(q);
       
    87     mList->setEnabledAnimations(HbAbstractItemView::None);
    87 }
    88 }
    88 
    89 
    89 HbCandidateListPrivate::~HbCandidateListPrivate()
    90 HbCandidateListPrivate::~HbCandidateListPrivate()
    90 {
    91 {
    91 //    delete mBackground;
       
    92 }
    92 }
    93 
    93 
    94 void HbCandidateListPrivate::initFrameIcon()
    94 void HbCandidateListPrivate::initFrameIcon()
    95 {
    95 {
    96     Q_Q(HbCandidateList);
    96     Q_Q(HbCandidateList);
   103 }
   103 }
   104 
   104 
   105 
   105 
   106 void HbCandidateListPrivate::calculateAndSetSize(qreal maxWidth)
   106 void HbCandidateListPrivate::calculateAndSetSize(qreal maxWidth)
   107 {
   107 {
   108     Q_Q(HbCandidateList); 
   108     Q_Q(HbCandidateList);
   109 
   109 
   110     const qreal oneLineHeight = 40.0;  // temporarily as a constant, eventually we'll need to calculate this.
   110     const qreal oneLineHeight = 40.0;  // temporarily as a constant, eventually we'll need to calculate this.
   111 
   111 
   112     QRectF geom = q->geometry();
   112     QRectF geom = q->geometry();
   113     qreal finalWidth = 30 + longestStringWidth * 2;    // Use magic numbers for now until we can calculate this from font.
   113     qreal finalWidth = 30 + longestStringWidth * 2;    // Use magic numbers for now until we can calculate this from font.
   114 
       
   115     // Font has not been set yet at this point...
       
   116     /*QList<HbAbstractViewItem *>  items = mList->itemPrototypes();
       
   117     mList->adjustSize();
       
   118     HbAbstractViewItem * firstItem = items.at(0);
       
   119 
       
   120     if(firstItem){
       
   121     QFontMetrics fontMetrics(firstItem->fontSpec().font());
       
   122     finalWidth = fontMetrics.boundingRect(longestString).width();	
       
   123     }*/
       
   124 
   114 
   125     if (finalWidth > maxWidth) {
   115     if (finalWidth > maxWidth) {
   126         finalWidth = maxWidth;
   116         finalWidth = maxWidth;
   127     }
   117     }
   128 
   118 
   134     }
   124     }
   135 
   125 
   136     finalWidth = finalWidth + l + r ;
   126     finalWidth = finalWidth + l + r ;
   137     finalHeight = (qreal)numLines * oneLineHeight + 5.0 + t + b;
   127     finalHeight = (qreal)numLines * oneLineHeight + 5.0 + t + b;
   138 
   128 
   139     if(finalHeight > HbDeviceProfile::current().logicalSize().height() - 30)
   129     if(finalHeight > HbDeviceProfile::current().logicalSize().height() - 30) {
   140         finalHeight = HbDeviceProfile::current().logicalSize().height() - 30;
   130         finalHeight = HbDeviceProfile::current().logicalSize().height() - 30;
       
   131     }
   141 
   132 
   142     geom.setHeight(finalHeight);
   133     geom.setHeight(finalHeight);
   143     geom.setWidth(finalWidth);
   134     geom.setWidth(finalWidth);
   144 
   135 
   145     q->setGeometry(geom);
   136     q->setGeometry(geom);
   165 @param input The input method that uses this widget.
   156 @param input The input method that uses this widget.
   166 @param parent parent of the widget.
   157 @param parent parent of the widget.
   167 */
   158 */
   168 HbCandidateList::HbCandidateList(HbInputMethod* input, QGraphicsItem* parent)
   159 HbCandidateList::HbCandidateList(HbInputMethod* input, QGraphicsItem* parent)
   169     : HbDialog(*new HbCandidateListPrivate(input), parent)
   160     : HbDialog(*new HbCandidateListPrivate(input), parent)
   170 { 
   161 {
   171     Q_D(HbCandidateList);
   162     Q_D(HbCandidateList);
   172     
   163 
   173     d->setPriority(HbPopupPrivate::VirtualKeyboard + 1);  // Should be shown on top of virtual keyboard.
   164     d->setPriority(HbPopupPrivate::VirtualKeyboard + 1);  // Should be shown on top of virtual keyboard.
   174     d->initFrameIcon();
   165     d->initFrameIcon();
   175 
   166 
   176 #if QT_VERSION >= 0x040600
   167 #if QT_VERSION >= 0x040600
   177     // Make sure the preview pane never steals focus.
   168     // Make sure the preview pane never steals focus.
   185 #endif
   176 #endif
   186 
   177 
   187     setTimeout(NoTimeout);
   178     setTimeout(NoTimeout);
   188     setAttribute(Qt::WA_InputMethodEnabled, false);
   179     setAttribute(Qt::WA_InputMethodEnabled, false);
   189     connect(d->mList, SIGNAL(activated(HbListWidgetItem*)), this, SLOT(itemActivated(HbListWidgetItem*)));
   180     connect(d->mList, SIGNAL(activated(HbListWidgetItem*)), this, SLOT(itemActivated(HbListWidgetItem*)));
   190  
   181     connect(d->mList, SIGNAL(longPressed(HbListWidgetItem*, const QPointF&)), this, SLOT(itemActivated(HbListWidgetItem*)));
   191     setBackgroundFaded(false);        
   182 
       
   183     setBackgroundFaded(false);
   192 }
   184 }
   193 
   185 
   194 /*!
   186 /*!
   195 Destroys the object.
   187 Destroys the object.
   196 */
   188 */
   199 }
   191 }
   200 
   192 
   201 /*!
   193 /*!
   202 Populates the candidate list with text strings given as parameter.
   194 Populates the candidate list with text strings given as parameter.
   203 
   195 
   204 @param 
   196 @param
   205 */
   197 */
   206 void HbCandidateList::populateList(const QStringList& candidates)
   198 void HbCandidateList::populateList(const QStringList& candidates)
   207 {
   199 {
   208     Q_D(HbCandidateList);
   200     Q_D(HbCandidateList);
   209 
   201 
   257 
   249 
   258 /*!
   250 /*!
   259 Inherited from HbDialog.
   251 Inherited from HbDialog.
   260 */
   252 */
   261 void HbCandidateList::closeEvent(QCloseEvent* /*event*/)
   253 void HbCandidateList::closeEvent(QCloseEvent* /*event*/)
   262 {   
   254 {
   263     hide();
   255     hide();
   264 	emit candidatePopupCancelled();    
   256     emit candidatePopupCancelled();
   265 }
   257 }
   266 
   258 
   267 /*!
   259 /*!
   268 Called when an item on the list is activated. Hides the list and informs the input.
   260 Called when an item on the list is activated. Hides the list and informs the input.
   269 */
   261 */
   270 void HbCandidateList::itemActivated(HbListWidgetItem *item)
   262 void HbCandidateList::itemActivated(HbListWidgetItem *item)
   271 {
   263 {
   272     Q_UNUSED(item);
   264     Q_UNUSED(item);
   273     Q_D(HbCandidateList);
   265     Q_D(HbCandidateList);
   274 
   266 
   275     d->mInput->candidatePopupClosed();    
   267     d->mInput->candidatePopupClosed();
   276     hide();
   268     hide();
   277 }
   269 }
   278 
   270 
   279 /*!
   271 /*!
   280 Returns the currently selected candidate on the list.
   272 Returns the currently selected candidate on the list.
   293     Q_D(HbCandidateList);
   285     Q_D(HbCandidateList);
   294 
   286 
   295     d->numRows = numLines;
   287     d->numRows = numLines;
   296     update();
   288     update();
   297 }
   289 }
       
   290 
   298 /*!
   291 /*!
   299 this event handler is called, for Hide events, is delivered after the widget has been hidden.
   292 this event handler is called, for Hide events, is delivered after the widget has been hidden.
   300 */
   293 */
   301 void HbCandidateList::hideEvent(QHideEvent * event)
   294 void HbCandidateList::hideEvent(QHideEvent * event)
   302 {
   295 {