29 #include "klineedit_p.h"
46 #include <QtCore/QTimer>
47 #include <QtGui/QClipboard>
48 #include <QtGui/QStyleOption>
49 #include <QtGui/QToolTip>
53 class KLineEditPrivate
60 handleURLDrops =
true;
61 grabReturnKeyEvents =
false;
65 disableRestoreSelection =
false;
66 enableSqueezedText =
false;
69 enableClickMsg =
false;
71 completionRunning =
false;
74 s_backspacePerformsCompletion =
config.readEntry(
"Backspace performs completion",
false);
80 wideEnoughForClear =
true;
87 QString metaMsg =
i18nc(
"Italic placeholder text in line edits: 0 no, 1 yes",
"1");
88 italicizePlaceholder = (metaMsg.trimmed() !=
QString(
'0'));
98 void _k_slotSettingsChanged(
int category)
107 void _k_textChanged(
const QString &txt)
111 if (!completionRunning && (txt != userText)) {
113 #ifndef KDE_NO_DEPRECATED
114 emit q->userTextChanged(txt);
121 void _k_updateUserText(
const QString &txt)
123 if (!completionRunning && (txt != userText)) {
125 q->setModified(
true);
126 #ifndef KDE_NO_DEPRECATED
127 emit q->userTextChanged(txt);
129 emit q->textEdited(txt);
130 emit q->textChanged(txt);
138 void adjustForReadOnly()
140 if (style && style.data()->m_overlap) {
141 style.data()->m_overlap = 0;
151 bool overrideShortcut(
const QKeyEvent* e);
153 static bool s_initialized;
154 static bool s_backspacePerformsCompletion;
156 QColor previousHighlightColor;
157 QColor previousHighlightedTextColor;
159 bool userSelection: 1;
160 bool autoSuggest : 1;
161 bool disableRestoreSelection: 1;
162 bool handleURLDrops:1;
163 bool grabReturnKeyEvents:1;
164 bool enableSqueezedText:1;
165 bool completionRunning:1;
169 QPalette::ColorRole bgRole;
174 bool enableClickMsg:1;
178 bool possibleTripleClick :1;
181 bool wideEnoughForClear:1;
182 KLineEditButton *clearButton;
183 QWeakPointer<KLineEditStyle> style;
188 bool italicizePlaceholder:1;
190 QAction *noCompletionAction, *shellCompletionAction, *autoCompletionAction, *popupCompletionAction, *shortAutoCompletionAction, *popupAutoCompletionAction, *defaultAction;
196 QStyle *KLineEditStyle::style()
const
199 return m_subStyle.data();
202 return KdeUiProxyStyle::style();
205 QRect KLineEditStyle::subElementRect(SubElement element,
const QStyleOption *option,
const QWidget *widget)
const
207 if (element == SE_LineEditContents) {
208 KLineEditStyle *unconstThis =
const_cast<KLineEditStyle *
>(
this);
212 unconstThis->m_subStyle.clear();
215 unconstThis->m_sentinel =
true;
216 QStyle *s = m_subStyle ? m_subStyle.data() : style();
217 QRect rect = s->subElementRect(SE_LineEditContents, option, widget);
218 unconstThis->m_sentinel =
false;
220 if (option->direction == Qt::LeftToRight) {
221 return rect.adjusted(0, 0, -m_overlap, 0);
223 return rect.adjusted(m_overlap, 0, 0, 0);
227 return KdeUiProxyStyle::subElementRect(element, option, widget);
230 bool KLineEditPrivate::s_backspacePerformsCompletion =
false;
231 bool KLineEditPrivate::s_initialized =
false;
235 :
QLineEdit( string, parent ), d(new KLineEditPrivate(this))
241 :
QLineEdit( parent ), d(new KLineEditPrivate(this))
252 void KLineEdit::init()
254 d->possibleTripleClick =
false;
255 d->bgRole = backgroundRole();
258 QLineEdit::setContextMenuPolicy( Qt::DefaultContextMenu );
265 connect(
this, SIGNAL(selectionChanged()),
this, SLOT(slotRestoreSelectionColors()));
267 connect(
KGlobalSettings::self(), SIGNAL(settingsChanged(
int)),
this, SLOT(_k_slotSettingsChanged(
int)));
269 const QPalette p = palette();
270 if ( !d->previousHighlightedTextColor.isValid() )
271 d->previousHighlightedTextColor=p.color(QPalette::Normal,QPalette::HighlightedText);
272 if ( !d->previousHighlightColor.isValid() )
273 d->previousHighlightColor=p.color(QPalette::Normal,QPalette::Highlight);
276 setStyle(d->style.data());
278 connect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(_k_textChanged(
QString)));
283 return d->clickMessage;
289 if (d->clearButton) {
293 d->clearButton =
new KLineEditButton(
this);
294 d->clearButton->setObjectName(
"KLineEditButton");
295 d->clearButton->setCursor( Qt::ArrowCursor );
296 d->clearButton->setToolTip(
i18nc(
"@action:button Clear current text in the line edit",
"Clear text" ) );
298 updateClearButtonIcon(text());
300 connect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(updateClearButtonIcon(
QString)));
302 disconnect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(updateClearButtonIcon(
QString)));
303 delete d->clearButton;
305 d->clickInClear =
false;
307 d->style.data()->m_overlap = 0;
314 return d->clearButton != 0;
320 if (d->clearButton) {
321 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0,
this);
322 s = d->clearButton->sizeHint();
323 s.rwidth() += frameWidth;
329 void KLineEdit::updateClearButtonIcon(
const QString& text)
331 if (!d->clearButton) {
335 d->adjustForReadOnly();
341 if (d->wideEnoughForClear && text.length() > 0) {
342 d->clearButton->animateVisible(
true);
344 d->clearButton->animateVisible(
false);
347 if (!d->clearButton->pixmap().isNull()) {
351 if (layoutDirection() == Qt::LeftToRight) {
352 d->clearButton->setPixmap(
SmallIcon(
"edit-clear-locationbar-rtl", 0, clearButtonState));
354 d->clearButton->setPixmap(
SmallIcon(
"edit-clear-locationbar-ltr", 0, clearButtonState));
357 d->clearButton->setVisible(text.length() > 0);
361 void KLineEdit::updateClearButton()
363 if (!d->clearButton) {
367 d->adjustForReadOnly();
371 const QSize geom = size();
372 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0,
this);
373 const int buttonWidth = d->clearButton->sizeHint().width();
374 const QSize newButtonSize(buttonWidth, geom.height());
375 const QFontMetrics fm(font());
376 const int em = fm.width(
"m");
380 const bool wideEnough = geom.width() > 4 * em + buttonWidth + frameWidth;
382 if (newButtonSize != d->clearButton->size()) {
383 d->clearButton->resize(newButtonSize);
387 d->style.data()->m_overlap = wideEnough ? buttonWidth + frameWidth : 0;
390 if (layoutDirection() == Qt::LeftToRight ) {
391 d->clearButton->move(geom.width() - frameWidth - buttonWidth - 1, 0);
393 d->clearButton->move(frameWidth + 1, 0);
396 if (wideEnough != d->wideEnoughForClear) {
400 d->wideEnoughForClear = wideEnough;
401 updateClearButtonIcon(text());
411 d->completionBox && d->completionBox->isVisible() )
412 d->completionBox->hide();
416 if ( echoMode() != QLineEdit::Normal )
425 d->autoSuggest =
true;
427 d->autoSuggest =
false;
434 d->disableCompletionMap[ mode ] = disable;
439 if ( !d->autoSuggest )
448 setSelection(t.length(), txt.length()-t.length());
481 if ( input.isEmpty() || input == displayText() )
500 if ( match.isEmpty() )
502 if ( d->completionBox )
504 d->completionBox->hide();
505 d->completionBox->clear();
515 if ( match.isEmpty() || match == text )
521 if ( d->autoSuggest )
529 if (readOnly == isReadOnly ()) {
536 d->bgRole = backgroundRole();
537 setBackgroundRole(QPalette::Window);
538 if (d->enableSqueezedText && d->squeezedText.isEmpty()) {
539 d->squeezedText = text();
543 if (d->clearButton) {
544 d->clearButton->animateVisible(
false);
545 d->adjustForReadOnly();
548 if (!d->squeezedText.isEmpty()) {
550 d->squeezedText.clear();
553 setBackgroundRole(d->bgRole);
566 d->enableSqueezedText = enable;
571 return d->enableSqueezedText;
576 if( d->enableClickMsg )
578 d->drawClickMsg = text.isEmpty();
581 if( d->enableSqueezedText && isReadOnly() )
583 d->squeezedText = text;
591 void KLineEdit::setSqueezedText()
593 d->squeezedStart = 0;
595 const QString fullText = d->squeezedText;
596 const QFontMetrics fm(fontMetrics());
597 const int labelWidth = size().width() - 2*style()->pixelMetric(QStyle::PM_DefaultFrameWidth) - 2;
598 const int textWidth = fm.width(fullText);
600 if (textWidth > labelWidth)
604 int squeezedWidth = fm.width(squeezedText);
607 int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2;
608 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
609 squeezedWidth = fm.width(squeezedText);
611 if (squeezedWidth < labelWidth)
618 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
619 squeezedWidth = fm.width(squeezedText);
620 }
while (squeezedWidth < labelWidth);
622 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
624 else if (squeezedWidth > labelWidth)
631 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
632 squeezedWidth = fm.width(squeezedText);
633 }
while (squeezedWidth > labelWidth);
644 d->squeezedStart = letters;
645 d->squeezedEnd = fullText.length() - letters;
648 setToolTip( fullText );
655 this->setToolTip(
"" );
656 QToolTip::showText(pos(),
QString());
659 setCursorPosition(0);
664 if( !copySqueezedText(
true))
668 bool KLineEdit::copySqueezedText(
bool clipboard)
const
670 if (!d->squeezedText.isEmpty() && d->squeezedStart)
673 if (!that->hasSelectedText())
675 int start = selectionStart(),
end = start + selectedText().length();
676 if (start >= d->squeezedStart+3)
677 start = start - 3 - d->squeezedStart + d->squeezedEnd;
678 else if (start > d->squeezedStart)
679 start = d->squeezedStart;
680 if (
end >= d->squeezedStart+3)
681 end =
end - 3 - d->squeezedStart + d->squeezedEnd;
682 else if (
end > d->squeezedStart)
683 end = d->squeezedEnd;
687 t = t.mid(start,
end - start);
688 disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()),
this, 0);
689 QApplication::clipboard()->setText( t, clipboard ? QClipboard::Clipboard : QClipboard::Selection );
690 connect( QApplication::clipboard(), SIGNAL(selectionChanged()),
this,
691 SLOT(_q_clipboardChanged()) );
699 if (!d->squeezedText.isEmpty())
709 const int key = e->key() | e->modifiers();
727 QString text = QApplication::clipboard()->text( QClipboard::Selection);
753 cursorWordBackward(
true);
754 if ( hasSelectedText() )
763 cursorWordForward(
true);
764 if ( hasSelectedText() )
772 cursorWordBackward(
false);
778 cursorWordForward(
false);
798 if ( echoMode() == QLineEdit::Normal &&
801 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
802 const bool trap = (d->completionBox && d->completionBox->isVisible());
803 const bool stopEvent = (trap || (d->grabReturnKeyEvents &&
804 (e->modifiers() == Qt::NoButton ||
805 e->modifiers() == Qt::KeypadModifier)));
815 d->completionBox->hide();
817 setCursorPosition(text().length());
828 const bool noModifier = (e->modifiers() == Qt::NoButton ||
829 e->modifiers() == Qt::ShiftModifier ||
830 e->modifiers() == Qt::KeypadModifier);
836 if ( !d->userSelection && hasSelectedText() &&
837 ( e->key() == Qt::Key_Right || e->key() == Qt::Key_Left ) &&
838 e->modifiers()==Qt::NoButton )
840 const QString old_txt = text();
841 d->disableRestoreSelection =
true;
842 const int start = selectionStart();
846 const int cPosition=cursorPosition();
850 setSelection(old_txt.length(), cPosition - old_txt.length());
851 if (e->key() == Qt::Key_Right && cPosition > start )
854 d->_k_updateUserText(text());
857 d->disableRestoreSelection =
false;
861 if ( e->key() == Qt::Key_Escape )
863 if (hasSelectedText() && !d->userSelection )
880 const QString keycode = e->text();
881 if ( !keycode.isEmpty() && (keycode.unicode()->isPrint() ||
882 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
884 const bool hasUserSelection=d->userSelection;
885 const bool hadSelection=hasSelectedText();
887 bool cursorNotAtEnd=
false;
889 const int start = selectionStart();
890 const int cPos = cursorPosition();
896 if ( hadSelection && !hasUserSelection && start>cPos )
899 setCursorPosition(cPos);
903 d->disableRestoreSelection =
true;
905 d->disableRestoreSelection =
false;
908 int len = txt.length();
909 if ( !hasSelectedText() && len )
911 if ( e->key() == Qt::Key_Backspace )
913 if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
920 if (!d->s_backspacePerformsCompletion || !len) {
921 d->autoSuggest =
false;
925 if (e->key() == Qt::Key_Delete )
926 d->autoSuggest=
false;
930 if( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
943 noModifier && !e->text().isEmpty() )
945 const QString old_txt = text();
946 const bool hasUserSelection=d->userSelection;
947 const bool hadSelection=hasSelectedText();
948 bool cursorNotAtEnd=
false;
950 const int start = selectionStart();
951 const int cPos = cursorPosition();
952 const QString keycode = e->text();
958 if (hadSelection && !hasUserSelection && start>cPos &&
959 ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
960 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
963 setCursorPosition(cPos);
967 const int selectedLength=selectedText().length();
969 d->disableRestoreSelection =
true;
971 d->disableRestoreSelection =
false;
973 if (( selectedLength != selectedText().length() ) && !hasUserSelection )
974 slotRestoreSelectionColors();
977 int len = txt.length();
978 if ( ( txt != old_txt || txt != e->text() ) && len &&
979 ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
980 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
982 if ( e->key() == Qt::Key_Backspace )
984 if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
991 if (!d->s_backspacePerformsCompletion) {
992 d->autoSuggest =
false;
996 if (e->key() == Qt::Key_Delete )
997 d->autoSuggest=
false;
999 if ( d->completionBox )
1000 d->completionBox->setCancelledText( txt );
1004 if ( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) &&
1006 d->autoSuggest=
true;
1010 else if (!len && d->completionBox && d->completionBox->isVisible())
1011 d->completionBox->hide();
1030 const int len = txt.length();
1031 if ( cursorPosition() == len && len != 0 )
1037 else if ( d->completionBox )
1038 d->completionBox->hide();
1098 const int selectedLength = selectedText().length();
1103 if ( selectedLength != selectedText().length() )
1104 slotRestoreSelectionColors();
1109 if ( e->button() == Qt::LeftButton )
1111 d->possibleTripleClick=
true;
1112 QTimer::singleShot( QApplication::doubleClickInterval(),
this,
1113 SLOT(tripleClickTimeout()) );
1120 if ( (e->button() == Qt::LeftButton ||
1121 e->button() == Qt::MidButton ) &&
1123 d->clickInClear = ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() );
1125 if ( d->clickInClear ) {
1126 d->possibleTripleClick =
false;
1130 if ( e->button() == Qt::LeftButton && d->possibleTripleClick ) {
1138 if ( e->button() == Qt::MidButton ) {
1139 if ( hasSelectedText() ) {
1140 if ( QApplication::clipboard()->text( QClipboard::Selection ).length() >0 ) {
1151 if ( d->clickInClear ) {
1152 if ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() ) {
1154 if ( e->button() == Qt::MidButton ) {
1155 newText = QApplication::clipboard()->text( QClipboard::Selection );
1158 setSelection(0, text().size());
1162 emit textChanged( newText );
1165 d->clickInClear =
false;
1172 if (QApplication::clipboard()->supportsSelection() ) {
1173 if ( e->button() == Qt::LeftButton ) {
1175 copySqueezedText(
false );
1180 void KLineEdit::tripleClickTimeout()
1182 d->possibleTripleClick=
false;
1192 const QList<QAction *> actionList = popup->actions();
1193 enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct,
1194 Separator2, SelectAllAct, NCountActs };
1195 QAction *separatorAction = 0L;
1197 const int idx = actionList.indexOf( actionList[DeleteAct] ) + 1;
1198 if ( idx < actionList.count() )
1199 separatorAction = actionList.at( idx );
1200 if ( separatorAction )
1203 if ( text().isEmpty() )
1204 clearAllAction->setEnabled(
false );
1205 popup->insertAction( separatorAction, clearAllAction );
1216 QMenu *subMenu = popup->addMenu(
KIcon(
"text-completion"),
i18nc(
"@title:menu",
"Text Completion") );
1217 connect( subMenu, SIGNAL(triggered(
QAction*)),
1218 this, SLOT(completionMenuActivated(
QAction*)) );
1220 popup->addSeparator();
1222 QActionGroup* ag =
new QActionGroup(
this );
1223 d->noCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"None"));
1224 d->shellCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Manual") );
1225 d->autoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Automatic") );
1226 d->popupCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Dropdown List") );
1227 d->shortAutoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Short Automatic") );
1228 d->popupAutoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Dropdown List && Automatic"));
1229 subMenu->addActions( ag->actions() );
1233 d->shellCompletionAction->setCheckable(
true );
1234 d->noCompletionAction->setCheckable(
true );
1235 d->popupCompletionAction->setCheckable(
true );
1236 d->autoCompletionAction->setCheckable(
true );
1237 d->shortAutoCompletionAction->setCheckable(
true );
1238 d->popupAutoCompletionAction->setCheckable(
true );
1256 if ( mode != defaultMode && !d->disableCompletionMap[ defaultMode ] )
1258 subMenu->addSeparator();
1259 d->defaultAction = subMenu->addAction(
i18nc(
"@item:inmenu Text Completion",
"Default") );
1268 if ( QLineEdit::contextMenuPolicy() != Qt::DefaultContextMenu )
1277 popup->exec(e->globalPos());
1281 void KLineEdit::completionMenuActivated(
QAction *act)
1285 if( act == d->noCompletionAction )
1289 else if( act == d->shellCompletionAction)
1293 else if( act == d->autoCompletionAction)
1297 else if( act == d->popupCompletionAction)
1301 else if( act == d->shortAutoCompletionAction)
1305 else if( act == d->popupAutoCompletionAction)
1309 else if( act == d->defaultAction )
1320 d->completionBox && d->completionBox->isVisible() )
1321 d->completionBox->hide();
1328 if( d->handleURLDrops )
1331 if ( !urlList.isEmpty() )
1344 KUrl::List::ConstIterator it;
1345 for( it = urlList.begin() ; it != urlList.end() ; ++it )
1347 if(!dropText.isEmpty())
1350 dropText += (*it).prettyUrl();
1354 setCursorPosition(dropText.length());
1366 if ( ev->type() == QEvent::ShortcutOverride )
1368 QKeyEvent *e =
static_cast<QKeyEvent *
>( ev );
1369 if (d->overrideShortcut(e)) {
1372 }
else if (ev->type() == QEvent::ApplicationPaletteChange
1373 || ev->type() == QEvent::PaletteChange) {
1375 QPalette p = QApplication::palette();
1376 d->previousHighlightedTextColor=p.color(QPalette::Normal,QPalette::HighlightedText);
1377 d->previousHighlightColor=p.color(QPalette::Normal,QPalette::Highlight);
1379 }
else if (ev->type() == QEvent::StyleChange) {
1386 if (!qobject_cast<KLineEditStyle *>(style()) &&
1387 qstrcmp(style()->metaObject()->className(),
"QStyleSheetStyle") != 0 &&
1388 QLatin1String(style()->metaObject()->className()) != d->lastStyleClass) {
1394 kleStyle->m_subStyle = style();
1397 d->lastStyleClass = QLatin1String(style()->metaObject()->className());
1399 d->lastStyleClass.clear();
1409 d->handleURLDrops=enable;
1414 return d->handleURLDrops;
1419 d->grabReturnKeyEvents = grab;
1424 return d->grabReturnKeyEvents;
1434 if ( d->completionBox )
1437 d->completionBox = box;
1440 connect( d->completionBox, SIGNAL(currentTextChanged(
QString)),
1441 SLOT(_k_slotCompletionBoxTextChanged(
QString)) );
1444 connect( d->completionBox, SIGNAL(activated(
QString)),
1446 connect( d->completionBox, SIGNAL(activated(
QString)),
1447 SIGNAL(textEdited(
QString)) );
1461 const bool wasModified = edit->isModified();
1463 edit->setModified(wasModified);
1472 else if (hasSelectedText() )
1474 if (d->userSelection)
1478 d->autoSuggest=
false;
1479 const int start = selectionStart() ;
1480 const QString s = text().remove(selectionStart(), selectedText().length());
1482 setCursorPosition(start);
1483 d->autoSuggest=
true;
1488 bool KLineEditPrivate::overrideShortcut(
const QKeyEvent* e)
1492 const int key = e->key() | e->modifiers();
1553 if (completionBox && completionBox->isVisible ())
1555 const int key = e->key();
1556 const Qt::KeyboardModifiers modifiers = e->modifiers();
1557 if ((key == Qt::Key_Backtab || key == Qt::Key_Tab) &&
1558 (modifiers == Qt::NoModifier || (modifiers & Qt::ShiftModifier)))
1571 if ( d->completionBox && d->completionBox->isVisible() ) {
1579 if ( !items.isEmpty() &&
1580 !(items.count() == 1 && txt == items.first()) )
1585 if ( d->completionBox->isVisible() )
1587 QListWidgetItem* currentItem = d->completionBox->currentItem();
1590 if ( currentItem != 0 ) {
1591 currentSelection = currentItem->text();
1594 d->completionBox->setItems( items );
1596 const QList<QListWidgetItem*> matchedItems = d->completionBox->findItems(currentSelection, Qt::MatchExactly);
1597 QListWidgetItem* matchedItem = matchedItems.isEmpty() ? 0 : matchedItems.first();
1600 const bool blocked = d->completionBox->blockSignals(
true );
1601 d->completionBox->setCurrentItem( matchedItem );
1602 d->completionBox->blockSignals( blocked );
1604 d->completionBox->setCurrentRow(-1);
1609 if ( !txt.isEmpty() )
1610 d->completionBox->setCancelledText( txt );
1611 d->completionBox->setItems( items );
1612 d->completionBox->popup();
1615 if ( d->autoSuggest && autoSuggest )
1617 const int index = items.first().indexOf( txt );
1618 const QString newText = items.first().mid( index );
1625 if ( d->completionBox && d->completionBox->isVisible() )
1626 d->completionBox->hide();
1632 if ( create && !d->completionBox ) {
1634 d->completionBox->setObjectName(
"completion box");
1635 d->completionBox->setFont(font());
1638 return d->completionBox;
1645 disconnect( oldComp, SIGNAL(matches(
QStringList)),
1667 if (!d->userSelection && userSelection)
1669 d->_k_updateUserText(text());
1672 QPalette p = palette();
1676 p.setColor(QPalette::Highlight, d->previousHighlightColor);
1677 p.setColor(QPalette::HighlightedText, d->previousHighlightedTextColor);
1681 QColor color=p.color(QPalette::Disabled, QPalette::Text);
1682 p.setColor(QPalette::HighlightedText, color);
1683 color=p.color(QPalette::Active, QPalette::Base);
1684 p.setColor(QPalette::Highlight, color);
1687 d->userSelection=userSelection;
1691 void KLineEdit::slotRestoreSelectionColors()
1693 if (d->disableRestoreSelection)
1704 void KLineEdit::_k_slotCompletionBoxTextChanged(
const QString& text )
1706 if (!text.isEmpty())
1716 if ( d->enableSqueezedText && isReadOnly() )
1717 return d->squeezedText;
1729 return d->autoSuggest;
1734 if (echoMode() == Password && d->threeStars) {
1743 setAttribute(Qt::WA_UpdatesDisabled,
true);
1745 const QString oldText = text();
1746 const bool isModifiedState = isModified();
1747 setText(oldText + oldText + oldText);
1750 setModified(isModifiedState);
1751 blockSignals(
false);
1752 setAttribute(Qt::WA_UpdatesDisabled,
false);
1757 if (d->enableClickMsg && d->drawClickMsg && !hasFocus() && text().isEmpty()) {
1760 f.setItalic(d->italicizePlaceholder);
1763 QColor color(palette().color(foregroundRole()));
1764 color.setAlphaF(0.5);
1767 QStyleOptionFrame opt;
1768 initStyleOption(&opt);
1769 QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt,
this);
1772 const int verticalMargin(1);
1773 const int horizontalMargin(2);
1775 int left, top, right, bottom;
1776 getTextMargins( &left, &top, &right, &bottom );
1777 cr.adjust( left, top, -right, -bottom );
1781 QFontMetrics fm = fontMetrics();
1782 Qt::Alignment va = alignment() & Qt::AlignVertical_Mask;
1784 switch (va & Qt::AlignVertical_Mask)
1786 case Qt::AlignBottom:
1787 vscroll = cr.y() + cr.height() - fm.height() - verticalMargin;
1791 vscroll = cr.y() + verticalMargin;
1795 vscroll = cr.y() + (cr.height() - fm.height() + 1) / 2;
1800 QRect lineRect(cr.x() + horizontalMargin, vscroll, cr.width() - 2*horizontalMargin, fm.height());
1801 p.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, d->clickMessage);
1808 if ( d->enableClickMsg && d->drawClickMsg )
1810 d->drawClickMsg =
false;
1818 if ( d->enableClickMsg && text().isEmpty() )
1820 d->drawClickMsg =
true;
1828 d->enableClickMsg = !msg.isEmpty();
1829 d->clickMessage = msg;
1830 d->drawClickMsg = text().isEmpty();
1834 #ifndef KDE_NO_DEPRECATED
1837 QLineEdit::setContextMenuPolicy( showMenu ? Qt::DefaultContextMenu : Qt::NoContextMenu );
1841 #ifndef KDE_NO_DEPRECATED
1844 return ( contextMenuPolicy() == Qt::DefaultContextMenu );
1854 if (val ==
"NoEcho")
1855 setEchoMode(NoEcho);
1857 d->threeStars = (val ==
"ThreeStars");
1858 setEchoMode(Password);
1863 setEchoMode( Normal );
1869 return echoMode() == NoEcho || echoMode() == Password;
1877 d->completionRunning =
true;
1881 d->completionRunning =
false;
1884 #include "klineedit.moc"
1885 #include "klineedit_p.moc"