src/hbwidgets/editors/hblineedit_p.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    34 // We mean it.
    34 // We mean it.
    35 //
    35 //
    36 
    36 
    37 #include "hblineedit_p.h"
    37 #include "hblineedit_p.h"
    38 #include "hblineedit.h"
    38 #include "hblineedit.h"
    39 #include "hbmeshlayout_p.h"
       
    40 #include "hbcolorscheme.h"
    39 #include "hbcolorscheme.h"
    41 
    40 
    42 #include <QTextDocument>
    41 #include <QTextDocument>
    43 #include <QTextBlock>
    42 #include <QTextBlock>
    44 #include <math.h>
    43 #include <math.h>
    56     maximumRows(1),
    55     maximumRows(1),
    57     echoMode(HbLineEdit::Normal),
    56     echoMode(HbLineEdit::Normal),
    58     clearOnEdit(false),
    57     clearOnEdit(false),
    59     emitTextChanged(true),
    58     emitTextChanged(true),
    60     adjustFontSizeToFitHeight(false),
    59     adjustFontSizeToFitHeight(false),
    61     stretchedToLineCount(-1)
    60     stretchedToLineCount(-1),
       
    61     mCustomAutoCompContent(0),
       
    62     mCustomAutoCompPopup(0)
    62 {
    63 {
    63 }
    64 }
    64 
    65 
    65 HbLineEditPrivate::~HbLineEditPrivate ()
    66 HbLineEditPrivate::~HbLineEditPrivate ()
    66 {
    67 {
    77 
    78 
    78     q->setScrollable(true);
    79     q->setScrollable(true);
    79     scrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); 
    80     scrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); 
    80     defaultWrapMode = doc->defaultTextOption().wrapMode(); // cannot be changed.
    81     defaultWrapMode = doc->defaultTextOption().wrapMode(); // cannot be changed.
    81     q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    82     q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    82     q->setBackgroundItem(HbStyle::P_LineEdit_frame_normal);
    83     setBackgroundItem(HbStyle::P_LineEdit_frame_normal);
    83     q->setFocusHighlight(HbStyle::P_LineEdit_frame_highlight,HbWidget::FocusHighlightActive);
    84     q->setFocusHighlight(HbStyle::P_LineEdit_frame_highlight,HbWidget::FocusHighlightActive);
    84     updateWrappingMode();
    85     updateWrappingMode();
    85 
    86 
    86     Q_ASSERT(scrollArea);
    87     Q_ASSERT(scrollArea);
    87     scrollArea->installEventFilter(q); // needed for resize event processing
    88     scrollArea->installEventFilter(q); // needed for resize event processing
       
    89 
       
    90     // createCustomAutoCompPopup();
       
    91 }
       
    92 
       
    93 void HbLineEditPrivate::createCustomAutoCompPopup()
       
    94 {
       
    95     Q_Q(HbLineEdit);
       
    96 
       
    97     mCustomAutoCompPopup = new HbPopup(q);
       
    98     mCustomAutoCompPopup->setVisible(false);
       
    99     mCustomAutoCompPopup->setFlag(QGraphicsItem::ItemIsPanel, true);
       
   100     mCustomAutoCompPopup->setActive(false);
       
   101     mCustomAutoCompPopup->setFocusPolicy(Qt::NoFocus);
       
   102     mCustomAutoCompPopup->setBackgroundFaded(false);
       
   103     mCustomAutoCompPopup->setDismissPolicy(HbPopup::NoDismiss);
       
   104     mCustomAutoCompPopup->setTimeout(HbPopup::NoTimeout);
       
   105     HbStyle::setItemName(mCustomAutoCompPopup, QString("autoCompletePopup"));
    88 }
   106 }
    89 
   107 
    90 void HbLineEditPrivate::updatePaletteFromTheme()
   108 void HbLineEditPrivate::updatePaletteFromTheme()
    91 {
   109 {
    92     HbAbstractEditPrivate::updatePaletteFromTheme();
   110     HbAbstractEditPrivate::updatePaletteFromTheme();
   174         emit q->textChanged(q->text());
   192         emit q->textChanged(q->text());
   175     }
   193     }
   176 
   194 
   177     if(adjustFontSizeToFitHeight) {
   195     if(adjustFontSizeToFitHeight) {
   178         readjustStretchFont();
   196         readjustStretchFont();
       
   197     }
       
   198 
       
   199     if (doc->isEmpty()) {
       
   200         hideCustomAutoCompPopup();
       
   201     } else {
       
   202         showCustomAutoCompPopup();
   179     }
   203     }
   180 }
   204 }
   181 
   205 
   182 void HbLineEditPrivate::_q_textChange(int position, int charsRemoved,int charsAdded)
   206 void HbLineEditPrivate::_q_textChange(int position, int charsRemoved,int charsAdded)
   183 {
   207 {
   295     return QString(text.length(), passChar);
   319     return QString(text.length(), passChar);
   296 }
   320 }
   297 
   321 
   298 QString HbLineEditPrivate::echoString(const QString &text)
   322 QString HbLineEditPrivate::echoString(const QString &text)
   299 {
   323 {
   300     Q_Q(HbLineEdit);
       
   301 
   324 
   302     QString retText(text);
   325     QString retText(text);
   303 
   326 
   304     if(echoMode == HbLineEdit::Password || (echoMode == HbLineEdit::PasswordEchoOnEdit && !q->hasFocus())) {
   327     if(echoMode == HbLineEdit::Password || (echoMode == HbLineEdit::PasswordEchoOnEdit && !hasInputFocus())) {
   305         retText = passwordString(text);
   328         retText = passwordString(text);
   306     } else if (echoMode == HbLineEdit::NoEcho) {
   329     } else if (echoMode == HbLineEdit::NoEcho) {
   307         retText.clear();
   330         retText.clear();
   308     } // else Normal
   331     } // else Normal
   309 
   332 
   393         deltaFont.setPixelSize(static_cast<int>(singleLineHeight));
   416         deltaFont.setPixelSize(static_cast<int>(singleLineHeight));
   394         canvas->setFont(deltaFont);
   417         canvas->setFont(deltaFont);
   395     }
   418     }
   396 }
   419 }
   397 
   420 
       
   421 void HbLineEditPrivate::showCustomAutoCompPopup()
       
   422 {
       
   423     if (mCustomAutoCompContent) {
       
   424         Q_ASSERT(mCustomAutoCompPopup);
       
   425 
       
   426         if (!mCustomAutoCompPopup->isVisible() && !doc->isEmpty()) {
       
   427             mCustomAutoCompPopup->show();
       
   428         }
       
   429     }
       
   430 }
       
   431 
       
   432 void HbLineEditPrivate::hideCustomAutoCompPopup()
       
   433 {
       
   434     if (mCustomAutoCompContent) {
       
   435         Q_ASSERT(mCustomAutoCompPopup);
       
   436 
       
   437         if (mCustomAutoCompPopup->isVisible()) {
       
   438             mCustomAutoCompPopup->hide();
       
   439         }
       
   440     }
       
   441 }
       
   442 
       
   443 void HbLineEditPrivate::editingFinished()
       
   444 {
       
   445     Q_Q(HbLineEdit);
       
   446 
       
   447     if(q->echoMode() == HbLineEdit::PasswordEchoOnEdit) {
       
   448         q->setPlainText(passwordString(passwordText));
       
   449      }
       
   450     emit q->editingFinished();
       
   451 }
       
   452 
   398 #include "moc_hblineedit.cpp"
   453 #include "moc_hblineedit.cpp"