src/hbwidgets/editors/hblineedit.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    32 #include "hbtextmeasurementutility_p.h"
    32 #include "hbtextmeasurementutility_p.h"
    33 #include "hbfeaturemanager_p.h"
    33 #include "hbfeaturemanager_p.h"
    34 #endif //HB_TEXT_MEASUREMENT_UTILITY
    34 #endif //HB_TEXT_MEASUREMENT_UTILITY
    35 
    35 
    36 #include <QFontMetrics>
    36 #include <QFontMetrics>
    37 #include <QGraphicsSceneMouseEvent>
       
    38 #include <QPainter>
    37 #include <QPainter>
    39 #include <QTextBlock>
    38 #include <QTextBlock>
    40 #include <QTextDocument>
    39 #include <QTextDocument>
       
    40 #include <QGraphicsSceneResizeEvent>
    41 
    41 
    42 /*!
    42 /*!
    43  \class HbLineEdit
    43  \class HbLineEdit
    44  \brief HbLineEdit is a one line text editor widget
    44  \brief HbLineEdit is a one line text editor widget
    45  @alpha
    45  @alpha
   178 void HbLineEdit::setMinRows (int rows)
   178 void HbLineEdit::setMinRows (int rows)
   179 {
   179 {
   180     Q_D(HbLineEdit);
   180     Q_D(HbLineEdit);
   181     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMin, true);
   181     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMin, true);
   182 
   182 
   183     if (rows > 0) {
   183     if (rows<=0) {
       
   184         qWarning("HbLineEdit::setMinRows wrong argument, value \"%d\" has been ignored.",
       
   185                  rows);
       
   186         return;
       
   187     }
       
   188 
       
   189     if (rows != d->minimumRows) {
   184         d->minimumRows = rows;
   190         d->minimumRows = rows;
   185 
   191 
   186         if (d->minimumRows > d->maximumRows) {
   192         if (d->minimumRows > d->maximumRows) {
   187             d->maximumRows = d->minimumRows;
   193             d->maximumRows = d->minimumRows;
   188         }
   194         }
   189         d->expandable = isExpandable();
       
   190 
   195 
   191         d->updateWrappingMode();
   196         d->updateWrappingMode();
   192 
   197 
   193         updateGeometry();
   198         if (d->adjustFontSizeToFitHeight) {
       
   199             d->readjustStretchFont();
       
   200         } else {
       
   201             updateGeometry();
       
   202         }
   194     }
   203     }
   195 }
   204 }
   196 
   205 
   197 /*!
   206 /*!
   198  Returns the minimum number of editor rows.
   207  Returns the minimum number of editor rows.
   224 void HbLineEdit::setMaxRows (int rows)
   233 void HbLineEdit::setMaxRows (int rows)
   225 {
   234 {
   226     Q_D(HbLineEdit);
   235     Q_D(HbLineEdit);
   227     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, true);
   236     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, true);
   228 
   237 
   229     if (rows > 0) {
   238     if (rows<=0) {
       
   239         qWarning("HbLineEdit::setMaxRows wrong argument, value \"%d\" has been ignored.",
       
   240                  rows);
       
   241         return;
       
   242     }
       
   243 
       
   244     if (rows != d->maximumRows) {
   230         d->maximumRows = rows;
   245         d->maximumRows = rows;
   231 
   246 
   232         if (d->maximumRows  < d->minimumRows) {
   247         if (d->maximumRows  < d->minimumRows) {
   233             d->minimumRows = d->maximumRows;
   248             d->minimumRows = d->maximumRows;
   234         }
   249         }
   235 
   250 
   236         d->expandable = isExpandable();
       
   237 
       
   238         d->updateWrappingMode();
   251         d->updateWrappingMode();
   239 
   252 
   240         updateGeometry();
   253         if (d->adjustFontSizeToFitHeight) {
       
   254             d->readjustStretchFont();
       
   255         } else {
       
   256             updateGeometry();
       
   257         }
   241 
   258 
   242 #ifdef HB_TEXT_MEASUREMENT_UTILITY
   259 #ifdef HB_TEXT_MEASUREMENT_UTILITY
   243         if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
   260         if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
   244             setProperty( HbTextMeasurementUtilityNameSpace::textMaxLines, d->maximumRows );
   261             setProperty( HbTextMeasurementUtilityNameSpace::textMaxLines, d->maximumRows );
   245         }
   262         }
   573 }
   590 }
   574 
   591 
   575 /*!
   592 /*!
   576     \reimp
   593     \reimp
   577  */
   594  */
   578 void HbLineEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
       
   579 {
       
   580     HbAbstractEdit::resizeEvent(event);
       
   581 
       
   582     document()->setTextWidth(primitive(HbStyle::P_Edit_text)->boundingRect().width());
       
   583 }
       
   584 
       
   585 /*!
       
   586     \reimp
       
   587  */
       
   588 bool HbLineEdit::canInsertFromMimeData(const QMimeData *source) const
   595 bool HbLineEdit::canInsertFromMimeData(const QMimeData *source) const
   589 {
   596 {
   590     return source->hasText() && !source->text().isEmpty();
   597     return source->hasText() && !source->text().isEmpty();
   591 }
   598 }
   592 
   599 
   618     \reimp
   625     \reimp
   619  */
   626  */
   620 void HbLineEdit::focusOutEvent(QFocusEvent * event)
   627 void HbLineEdit::focusOutEvent(QFocusEvent * event)
   621 {
   628 {
   622     Q_D(HbLineEdit);
   629     Q_D(HbLineEdit);
   623     setBackgroundItem(HbStyle::P_LineEdit_frame_normal);
       
   624 
   630 
   625     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
   631     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
   626         setPlainText(d->passwordString(d->passwordText));
   632         setPlainText(d->passwordString(d->passwordText));
   627     }
   633     }
   628 
   634 
   635     \reimp
   641     \reimp
   636  */
   642  */
   637 void HbLineEdit::focusInEvent(QFocusEvent * event)
   643 void HbLineEdit::focusInEvent(QFocusEvent * event)
   638 {
   644 {
   639     Q_D(HbLineEdit);
   645     Q_D(HbLineEdit);
   640     setBackgroundItem(HbStyle::P_LineEdit_frame_highlight);
       
   641 
   646 
   642     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
   647     if(echoMode() == HbLineEdit::PasswordEchoOnEdit) {
   643         // we need to clear the editor when typing starts
   648         // we need to clear the editor when typing starts
   644         d->clearOnEdit = true;
   649         d->clearOnEdit = true;
   645     }
   650     }
   646 
   651 
   647     HbAbstractEdit::focusInEvent(event);
   652     HbAbstractEdit::focusInEvent(event);
   648 }
   653 }
       
   654 
       
   655 /*!
       
   656     @proto
       
   657 
       
   658     Enables or disables vertical font stretch mode.
       
   659 
       
   660     In this mode font size is depending on editor size and number of rows.
       
   661     Font is adjusted in such way to show as much text as possible and as big
       
   662     as possible and still have visible number of rows in range defined by
       
   663     \l{HbLineEdit::setMinRows}{minimum} and \l{HbLineEdit::setMaxRows}{maximum}
       
   664     number of rows.
       
   665 
       
   666     \sa HbLineEdit::setMinRows(int)
       
   667     \sa HbLineEdit::setMaxRows(int)
       
   668     \sa HbLineEdit::adjustFontSizeToFitHeight()
       
   669  */
       
   670 void HbLineEdit::setAdjustFontSizeToFitHeight(bool active)
       
   671 {
       
   672     Q_D(HbLineEdit);
       
   673     if (d->adjustFontSizeToFitHeight != active) {
       
   674         d->adjustFontSizeToFitHeight = active;
       
   675         if(!active) {
       
   676             // clear font stretch
       
   677             d->canvas->setFont(QFont());
       
   678         }
       
   679         updateGeometry();
       
   680     }
       
   681 }
       
   682 
       
   683 /*!
       
   684     @proto
       
   685 
       
   686     Returns true if vertical font streach mode is active.
       
   687     See HbLineEdit::setAdjustFontSizeToFitHeight for details.
       
   688 
       
   689     \sa HbLineEdit::setAdjustFontSizeToFitHeight(bool)
       
   690  */
       
   691 bool HbLineEdit::adjustFontSizeToFitHeight() const
       
   692 {
       
   693     return d_func()->adjustFontSizeToFitHeight;
       
   694 }
       
   695 
       
   696 /*!
       
   697     \reimp
       
   698  */
       
   699 bool HbLineEdit::eventFilter(QObject *obj, QEvent *event)
       
   700 {
       
   701     Q_D(HbLineEdit);
       
   702 
       
   703     if (obj == d->scrollArea && event->type()==QEvent::GraphicsSceneResize) {
       
   704         document()->setTextWidth(d->scrollArea->size().width());
       
   705         d->onResizeFontChange();
       
   706     }
       
   707     return HbAbstractEdit::eventFilter(obj, event);
       
   708 }