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;
68 enableClickMsg =
false;
70 completionRunning =
false;
73 s_backspacePerformsCompletion =
config.readEntry(
"Backspace performs completion",
false);
79 wideEnoughForClear =
true;
86 QString metaMsg =
i18nc(
"Italic placeholder text in line edits: 0 no, 1 yes",
"1");
87 italicizePlaceholder = (metaMsg.trimmed() !=
QString(
'0'));
97 void _k_slotSettingsChanged(
int category)
106 void _k_textChanged(
const QString &txt)
110 if (!completionRunning && (txt != userText)) {
112 #ifndef KDE_NO_DEPRECATED
113 emit q->userTextChanged(txt);
120 void _k_updateUserText(
const QString &txt)
122 if (!completionRunning && (txt != userText)) {
124 q->setModified(
true);
125 #ifndef KDE_NO_DEPRECATED
126 emit q->userTextChanged(txt);
128 emit q->textEdited(txt);
129 emit q->textChanged(txt);
137 void adjustForReadOnly()
139 if (style && style.data()->m_overlap) {
140 style.data()->m_overlap = 0;
150 bool overrideShortcut(
const QKeyEvent* e);
152 static bool s_initialized;
153 static bool s_backspacePerformsCompletion;
155 QColor previousHighlightColor;
156 QColor previousHighlightedTextColor;
158 bool userSelection: 1;
159 bool autoSuggest : 1;
160 bool disableRestoreSelection: 1;
161 bool handleURLDrops:1;
162 bool grabReturnKeyEvents:1;
163 bool enableSqueezedText:1;
164 bool completionRunning:1;
168 QPalette::ColorRole bgRole;
173 bool enableClickMsg:1;
176 bool possibleTripleClick :1;
179 bool wideEnoughForClear:1;
180 KLineEditButton *clearButton;
181 QWeakPointer<KLineEditStyle> style;
186 bool italicizePlaceholder:1;
188 QAction *noCompletionAction, *shellCompletionAction, *autoCompletionAction, *popupCompletionAction, *shortAutoCompletionAction, *popupAutoCompletionAction, *defaultAction;
194 QStyle *KLineEditStyle::style()
const
197 return m_subStyle.data();
200 return KdeUiProxyStyle::style();
203 QRect KLineEditStyle::subElementRect(SubElement element,
const QStyleOption *option,
const QWidget *widget)
const
205 if (element == SE_LineEditContents) {
206 KLineEditStyle *unconstThis =
const_cast<KLineEditStyle *
>(
this);
210 unconstThis->m_subStyle.clear();
213 unconstThis->m_sentinel =
true;
214 QStyle *s = m_subStyle ? m_subStyle.data() : style();
215 QRect rect = s->subElementRect(SE_LineEditContents, option, widget);
216 unconstThis->m_sentinel =
false;
218 if (option->direction == Qt::LeftToRight) {
219 return rect.adjusted(0, 0, -m_overlap, 0);
221 return rect.adjusted(m_overlap, 0, 0, 0);
225 return KdeUiProxyStyle::subElementRect(element, option, widget);
228 bool KLineEditPrivate::s_backspacePerformsCompletion =
false;
229 bool KLineEditPrivate::s_initialized =
false;
233 :
QLineEdit( string, parent ), d(new KLineEditPrivate(this))
239 :
QLineEdit( parent ), d(new KLineEditPrivate(this))
250 void KLineEdit::init()
252 d->possibleTripleClick =
false;
253 d->bgRole = backgroundRole();
256 QLineEdit::setContextMenuPolicy( Qt::DefaultContextMenu );
263 connect(
this, SIGNAL(selectionChanged()),
this, SLOT(slotRestoreSelectionColors()));
265 connect(
KGlobalSettings::self(), SIGNAL(settingsChanged(
int)),
this, SLOT(_k_slotSettingsChanged(
int)));
267 const QPalette p = palette();
268 if ( !d->previousHighlightedTextColor.isValid() )
269 d->previousHighlightedTextColor=p.color(QPalette::Normal,QPalette::HighlightedText);
270 if ( !d->previousHighlightColor.isValid() )
271 d->previousHighlightColor=p.color(QPalette::Normal,QPalette::Highlight);
274 setStyle(d->style.data());
276 connect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(_k_textChanged(
QString)));
281 return d->clickMessage;
287 if (d->clearButton) {
291 d->clearButton =
new KLineEditButton(
this);
292 d->clearButton->setObjectName(
"KLineEditButton");
293 d->clearButton->setCursor( Qt::ArrowCursor );
294 d->clearButton->setToolTip(
i18nc(
"@action:button Clear current text in the line edit",
"Clear text" ) );
296 updateClearButtonIcon(text());
298 connect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(updateClearButtonIcon(
QString)));
300 disconnect(
this, SIGNAL(textChanged(
QString)),
this, SLOT(updateClearButtonIcon(
QString)));
301 delete d->clearButton;
303 d->clickInClear =
false;
305 d->style.data()->m_overlap = 0;
312 return d->clearButton != 0;
318 if (d->clearButton) {
319 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0,
this);
320 s = d->clearButton->sizeHint();
321 s.rwidth() += frameWidth;
327 void KLineEdit::updateClearButtonIcon(
const QString& text)
329 if (!d->clearButton) {
333 d->adjustForReadOnly();
338 if (d->clearButton->pixmap().isNull()) {
340 if (layoutDirection() == Qt::LeftToRight) {
341 d->clearButton->setPixmap(
SmallIcon(
"edit-clear-locationbar-rtl", 0, clearButtonState));
343 d->clearButton->setPixmap(
SmallIcon(
"edit-clear-locationbar-ltr", 0, clearButtonState));
348 if (d->wideEnoughForClear && text.length() > 0) {
349 d->clearButton->animateVisible(
true);
351 d->clearButton->animateVisible(
false);
356 void KLineEdit::updateClearButton()
358 if (!d->clearButton) {
362 d->adjustForReadOnly();
366 const QSize geom = size();
367 const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0,
this);
368 const int buttonWidth = d->clearButton->sizeHint().width();
369 const QSize newButtonSize(buttonWidth, geom.height());
370 const QFontMetrics fm(font());
371 const int em = fm.width(
"m");
375 const bool wideEnough = geom.width() > 4 * em + buttonWidth + frameWidth;
377 if (newButtonSize != d->clearButton->size()) {
378 d->clearButton->resize(newButtonSize);
382 d->style.data()->m_overlap = wideEnough ? buttonWidth + frameWidth : 0;
385 if (layoutDirection() == Qt::LeftToRight ) {
386 d->clearButton->move(geom.width() - frameWidth - buttonWidth - 1, 0);
388 d->clearButton->move(frameWidth + 1, 0);
391 if (wideEnough != d->wideEnoughForClear) {
395 d->wideEnoughForClear = wideEnough;
396 updateClearButtonIcon(text());
406 d->completionBox && d->completionBox->isVisible() )
407 d->completionBox->hide();
411 if ( echoMode() != QLineEdit::Normal )
420 d->autoSuggest =
true;
422 d->autoSuggest =
false;
429 d->disableCompletionMap[ mode ] = disable;
434 if ( !d->autoSuggest )
443 setSelection(t.length(), txt.length()-t.length());
476 if ( input.isEmpty() || input == displayText() )
495 if ( match.isEmpty() )
497 if ( d->completionBox )
499 d->completionBox->hide();
500 d->completionBox->clear();
510 if ( match.isEmpty() || match == text )
516 if ( d->autoSuggest )
524 if (readOnly == isReadOnly ()) {
528 QLineEdit::setReadOnly(readOnly);
531 d->bgRole = backgroundRole();
532 setBackgroundRole(QPalette::Window);
533 if (d->enableSqueezedText && d->squeezedText.isEmpty()) {
534 d->squeezedText = text();
538 if (d->clearButton) {
539 d->clearButton->animateVisible(
false);
540 d->adjustForReadOnly();
543 if (!d->squeezedText.isEmpty()) {
545 d->squeezedText.clear();
548 setBackgroundRole(d->bgRole);
561 d->enableSqueezedText = enable;
566 return d->enableSqueezedText;
571 if( d->enableClickMsg )
575 if( d->enableSqueezedText && isReadOnly() )
577 d->squeezedText = text;
582 QLineEdit::setText( text );
585 void KLineEdit::setSqueezedText()
587 d->squeezedStart = 0;
589 const QString fullText = d->squeezedText;
590 const QFontMetrics fm(fontMetrics());
591 const int labelWidth = size().width() - 2*style()->pixelMetric(QStyle::PM_DefaultFrameWidth) - 2;
592 const int textWidth = fm.width(fullText);
594 if (textWidth > labelWidth)
598 int squeezedWidth = fm.width(squeezedText);
601 int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2;
602 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
603 squeezedWidth = fm.width(squeezedText);
605 if (squeezedWidth < labelWidth)
612 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
613 squeezedWidth = fm.width(squeezedText);
614 }
while (squeezedWidth < labelWidth);
616 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
618 else if (squeezedWidth > labelWidth)
625 squeezedText = fullText.left(letters) +
"..." + fullText.right(letters);
626 squeezedWidth = fm.width(squeezedText);
627 }
while (squeezedWidth > labelWidth);
633 QLineEdit::setText(fullText);
637 QLineEdit::setText(squeezedText);
638 d->squeezedStart = letters;
639 d->squeezedEnd = fullText.length() - letters;
642 setToolTip( fullText );
647 QLineEdit::setText(fullText);
649 this->setToolTip(
"" );
650 QToolTip::showText(pos(),
QString());
653 setCursorPosition(0);
658 if( !copySqueezedText(
true))
662 bool KLineEdit::copySqueezedText(
bool clipboard)
const
664 if (!d->squeezedText.isEmpty() && d->squeezedStart)
667 if (!that->hasSelectedText())
669 int start = selectionStart(),
end = start + selectedText().length();
670 if (start >= d->squeezedStart+3)
671 start = start - 3 - d->squeezedStart + d->squeezedEnd;
672 else if (start > d->squeezedStart)
673 start = d->squeezedStart;
674 if (
end >= d->squeezedStart+3)
675 end =
end - 3 - d->squeezedStart + d->squeezedEnd;
676 else if (
end > d->squeezedStart)
677 end = d->squeezedEnd;
681 t = t.mid(start,
end - start);
682 disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()),
this, 0);
683 QApplication::clipboard()->setText( t, clipboard ? QClipboard::Clipboard : QClipboard::Selection );
684 connect( QApplication::clipboard(), SIGNAL(selectionChanged()),
this,
685 SLOT(_q_clipboardChanged()) );
693 if (!d->squeezedText.isEmpty())
697 QLineEdit::resizeEvent(ev);
703 const int key = e->key() | e->modifiers();
721 QString text = QApplication::clipboard()->text( QClipboard::Selection);
747 cursorWordBackward(
true);
748 if ( hasSelectedText() )
757 cursorWordForward(
true);
758 if ( hasSelectedText() )
766 cursorWordBackward(
false);
772 cursorWordForward(
false);
792 if ( echoMode() == QLineEdit::Normal &&
795 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
796 const bool trap = (d->completionBox && d->completionBox->isVisible());
797 const bool stopEvent = (trap || (d->grabReturnKeyEvents &&
798 (e->modifiers() == Qt::NoButton ||
799 e->modifiers() == Qt::KeypadModifier)));
802 emit QLineEdit::returnPressed();
809 d->completionBox->hide();
811 setCursorPosition(text().length());
822 const bool noModifier = (e->modifiers() == Qt::NoButton ||
823 e->modifiers() == Qt::ShiftModifier ||
824 e->modifiers() == Qt::KeypadModifier);
830 if ( !d->userSelection && hasSelectedText() &&
831 ( e->key() == Qt::Key_Right || e->key() == Qt::Key_Left ) &&
832 e->modifiers()==Qt::NoButton )
834 const QString old_txt = text();
835 d->disableRestoreSelection =
true;
836 const int start = selectionStart();
839 QLineEdit::keyPressEvent ( e );
840 const int cPosition=cursorPosition();
844 setSelection(old_txt.length(), cPosition - old_txt.length());
845 if (e->key() == Qt::Key_Right && cPosition > start )
848 d->_k_updateUserText(text());
851 d->disableRestoreSelection =
false;
855 if ( e->key() == Qt::Key_Escape )
857 if (hasSelectedText() && !d->userSelection )
874 const QString keycode = e->text();
875 if ( !keycode.isEmpty() && (keycode.unicode()->isPrint() ||
876 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
878 const bool hasUserSelection=d->userSelection;
879 const bool hadSelection=hasSelectedText();
881 bool cursorNotAtEnd=
false;
883 const int start = selectionStart();
884 const int cPos = cursorPosition();
890 if ( hadSelection && !hasUserSelection && start>cPos )
893 setCursorPosition(cPos);
897 d->disableRestoreSelection =
true;
898 QLineEdit::keyPressEvent ( e );
899 d->disableRestoreSelection =
false;
902 int len = txt.length();
903 if ( !hasSelectedText() && len )
905 if ( e->key() == Qt::Key_Backspace )
907 if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
914 if (!d->s_backspacePerformsCompletion || !len) {
915 d->autoSuggest =
false;
919 if (e->key() == Qt::Key_Delete )
920 d->autoSuggest=
false;
924 if( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
937 noModifier && !e->text().isEmpty() )
939 const QString old_txt = text();
940 const bool hasUserSelection=d->userSelection;
941 const bool hadSelection=hasSelectedText();
942 bool cursorNotAtEnd=
false;
944 const int start = selectionStart();
945 const int cPos = cursorPosition();
946 const QString keycode = e->text();
952 if (hadSelection && !hasUserSelection && start>cPos &&
953 ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
954 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
957 setCursorPosition(cPos);
961 const int selectedLength=selectedText().length();
963 d->disableRestoreSelection =
true;
964 QLineEdit::keyPressEvent ( e );
965 d->disableRestoreSelection =
false;
967 if (( selectedLength != selectedText().length() ) && !hasUserSelection )
968 slotRestoreSelectionColors();
971 int len = txt.length();
972 if ( ( txt != old_txt || txt != e->text() ) && len &&
973 ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
974 e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
976 if ( e->key() == Qt::Key_Backspace )
978 if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
985 if (!d->s_backspacePerformsCompletion) {
986 d->autoSuggest =
false;
990 if (e->key() == Qt::Key_Delete )
991 d->autoSuggest=
false;
993 if ( d->completionBox )
994 d->completionBox->setCancelledText( txt );
998 if ( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) &&
1000 d->autoSuggest=
true;
1004 else if (!len && d->completionBox && d->completionBox->isVisible())
1005 d->completionBox->hide();
1024 const int len = txt.length();
1025 if ( cursorPosition() == len && len != 0 )
1031 else if ( d->completionBox )
1032 d->completionBox->hide();
1092 const int selectedLength = selectedText().length();
1095 QLineEdit::keyPressEvent ( e );
1097 if ( selectedLength != selectedText().length() )
1098 slotRestoreSelectionColors();
1103 if ( e->button() == Qt::LeftButton )
1105 d->possibleTripleClick=
true;
1106 QTimer::singleShot( QApplication::doubleClickInterval(),
this,
1107 SLOT(tripleClickTimeout()) );
1109 QLineEdit::mouseDoubleClickEvent( e );
1114 if ( (e->button() == Qt::LeftButton ||
1115 e->button() == Qt::MidButton ) &&
1117 d->clickInClear = ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() );
1119 if ( d->clickInClear ) {
1120 d->possibleTripleClick =
false;
1124 if ( e->button() == Qt::LeftButton && d->possibleTripleClick ) {
1132 if ( e->button() == Qt::MidButton ) {
1133 if ( hasSelectedText() ) {
1134 if ( QApplication::clipboard()->text( QClipboard::Selection ).length() >0 ) {
1140 QLineEdit::mousePressEvent( e );
1145 if ( d->clickInClear ) {
1146 if ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() ) {
1148 if ( e->button() == Qt::MidButton ) {
1149 newText = QApplication::clipboard()->text( QClipboard::Selection );
1152 setSelection(0, text().size());
1156 emit textChanged( newText );
1159 d->clickInClear =
false;
1164 QLineEdit::mouseReleaseEvent( e );
1166 if (QApplication::clipboard()->supportsSelection() ) {
1167 if ( e->button() == Qt::LeftButton ) {
1169 copySqueezedText(
false );
1174 void KLineEdit::tripleClickTimeout()
1176 d->possibleTripleClick=
false;
1181 QMenu *popup = QLineEdit::createStandardContextMenu();
1187 enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct,
1188 Separator2, SelectAllAct, NCountActs };
1189 QAction *separatorAction = 0L;
1191 const int idx = actionList.indexOf( actionList[DeleteAct] ) + 1;
1192 if ( idx < actionList.count() )
1193 separatorAction = actionList.at( idx );
1194 if ( separatorAction )
1197 if ( text().isEmpty() )
1198 clearAllAction->setEnabled(
false );
1199 popup->insertAction( separatorAction, clearAllAction );
1210 QMenu *subMenu = popup->addMenu(
KIcon(
"text-completion"),
i18nc(
"@title:menu",
"Text Completion") );
1211 connect( subMenu, SIGNAL(triggered(
QAction*)),
1212 this, SLOT(completionMenuActivated(
QAction*)) );
1214 popup->addSeparator();
1216 QActionGroup* ag =
new QActionGroup(
this );
1217 d->noCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"None"));
1218 d->shellCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Manual") );
1219 d->autoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Automatic") );
1220 d->popupCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Dropdown List") );
1221 d->shortAutoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Short Automatic") );
1222 d->popupAutoCompletionAction = ag->addAction(
i18nc(
"@item:inmenu Text Completion",
"Dropdown List && Automatic"));
1223 subMenu->addActions( ag->actions() );
1227 d->shellCompletionAction->setCheckable(
true );
1228 d->noCompletionAction->setCheckable(
true );
1229 d->popupCompletionAction->setCheckable(
true );
1230 d->autoCompletionAction->setCheckable(
true );
1231 d->shortAutoCompletionAction->setCheckable(
true );
1232 d->popupAutoCompletionAction->setCheckable(
true );
1250 if ( mode != defaultMode && !d->disableCompletionMap[ defaultMode ] )
1252 subMenu->addSeparator();
1253 d->defaultAction = subMenu->addAction(
i18nc(
"@item:inmenu Text Completion",
"Default") );
1262 if ( QLineEdit::contextMenuPolicy() != Qt::DefaultContextMenu )
1271 popup->exec(e->globalPos());
1275 void KLineEdit::completionMenuActivated(
QAction *act)
1279 if( act == d->noCompletionAction )
1283 else if( act == d->shellCompletionAction)
1287 else if( act == d->autoCompletionAction)
1291 else if( act == d->popupCompletionAction)
1295 else if( act == d->shortAutoCompletionAction)
1299 else if( act == d->popupAutoCompletionAction)
1303 else if( act == d->defaultAction )
1314 d->completionBox && d->completionBox->isVisible() )
1315 d->completionBox->hide();
1322 if( d->handleURLDrops )
1325 if ( !urlList.isEmpty() )
1338 KUrl::List::ConstIterator it;
1339 for( it = urlList.begin() ; it != urlList.end() ; ++it )
1341 if(!dropText.isEmpty())
1344 dropText += (*it).prettyUrl();
1348 setCursorPosition(dropText.length());
1354 QLineEdit::dropEvent(e);
1360 if ( ev->type() == QEvent::ShortcutOverride )
1362 QKeyEvent *e =
static_cast<QKeyEvent *
>( ev );
1363 if (d->overrideShortcut(e)) {
1366 }
else if (ev->type() == QEvent::ApplicationPaletteChange
1367 || ev->type() == QEvent::PaletteChange) {
1369 QPalette p = QApplication::palette();
1370 d->previousHighlightedTextColor=p.color(QPalette::Normal,QPalette::HighlightedText);
1371 d->previousHighlightColor=p.color(QPalette::Normal,QPalette::Highlight);
1373 }
else if (ev->type() == QEvent::StyleChange) {
1380 if (!qobject_cast<KLineEditStyle *>(style()) &&
1381 qstrcmp(style()->metaObject()->className(),
"QStyleSheetStyle") != 0 &&
1382 QLatin1String(style()->metaObject()->className()) != d->lastStyleClass) {
1388 kleStyle->m_subStyle = style();
1391 d->lastStyleClass = QLatin1String(style()->metaObject()->className());
1393 d->lastStyleClass.clear();
1397 return QLineEdit::event( ev );
1403 d->handleURLDrops=enable;
1408 return d->handleURLDrops;
1413 d->grabReturnKeyEvents = grab;
1418 return d->grabReturnKeyEvents;
1428 if ( d->completionBox )
1431 d->completionBox = box;
1434 connect( d->completionBox, SIGNAL(currentTextChanged(
QString)),
1435 SLOT(_k_slotCompletionBoxTextChanged(
QString)) );
1438 connect( d->completionBox, SIGNAL(activated(
QString)),
1440 connect( d->completionBox, SIGNAL(activated(
QString)),
1441 SIGNAL(textEdited(
QString)) );
1455 const bool wasModified = edit->isModified();
1457 edit->setModified(wasModified);
1466 else if (hasSelectedText() )
1468 if (d->userSelection)
1472 d->autoSuggest=
false;
1473 const int start = selectionStart() ;
1474 const QString s = text().remove(selectionStart(), selectedText().length());
1476 setCursorPosition(start);
1477 d->autoSuggest=
true;
1482 bool KLineEditPrivate::overrideShortcut(
const QKeyEvent* e)
1486 const int key = e->key() | e->modifiers();
1547 if (completionBox && completionBox->isVisible ())
1549 const int key = e->key();
1550 const Qt::KeyboardModifiers modifiers = e->modifiers();
1551 if ((key == Qt::Key_Backtab || key == Qt::Key_Tab) &&
1552 (modifiers == Qt::NoModifier || (modifiers & Qt::ShiftModifier)))
1565 if ( d->completionBox && d->completionBox->isVisible() ) {
1573 if ( !items.isEmpty() &&
1574 !(items.count() == 1 && txt == items.first()) )
1579 if ( d->completionBox->isVisible() )
1581 QListWidgetItem* currentItem = d->completionBox->currentItem();
1584 if ( currentItem != 0 ) {
1585 currentSelection = currentItem->text();
1588 d->completionBox->setItems( items );
1591 QListWidgetItem* matchedItem = matchedItems.isEmpty() ? 0 : matchedItems.first();
1594 const bool blocked = d->completionBox->blockSignals(
true );
1595 d->completionBox->setCurrentItem( matchedItem );
1596 d->completionBox->blockSignals( blocked );
1598 d->completionBox->setCurrentRow(-1);
1603 if ( !txt.isEmpty() )
1604 d->completionBox->setCancelledText( txt );
1605 d->completionBox->setItems( items );
1606 d->completionBox->popup();
1609 if ( d->autoSuggest && autoSuggest )
1611 const int index = items.first().indexOf( txt );
1612 const QString newText = items.first().mid( index );
1619 if ( d->completionBox && d->completionBox->isVisible() )
1620 d->completionBox->hide();
1626 if ( create && !d->completionBox ) {
1628 d->completionBox->setObjectName(
"completion box");
1629 d->completionBox->setFont(font());
1632 return d->completionBox;
1639 disconnect( oldComp, SIGNAL(matches(
QStringList)),
1661 if (!d->userSelection && userSelection)
1663 d->_k_updateUserText(text());
1666 QPalette p = palette();
1670 p.setColor(QPalette::Highlight, d->previousHighlightColor);
1671 p.setColor(QPalette::HighlightedText, d->previousHighlightedTextColor);
1675 QColor color=p.color(QPalette::Disabled, QPalette::Text);
1676 p.setColor(QPalette::HighlightedText, color);
1677 color=p.color(QPalette::Active, QPalette::Base);
1678 p.setColor(QPalette::Highlight, color);
1681 d->userSelection=userSelection;
1685 void KLineEdit::slotRestoreSelectionColors()
1687 if (d->disableRestoreSelection)
1698 void KLineEdit::_k_slotCompletionBoxTextChanged(
const QString& text )
1700 if (!text.isEmpty())
1710 if ( d->enableSqueezedText && isReadOnly() )
1711 return d->squeezedText;
1723 return d->autoSuggest;
1728 if (echoMode() == Password && d->threeStars) {
1737 setAttribute(Qt::WA_UpdatesDisabled,
true);
1739 const QString oldText = text();
1740 const bool isModifiedState = isModified();
1741 setText(oldText + oldText + oldText);
1742 QLineEdit::paintEvent(ev);
1744 setModified(isModifiedState);
1745 blockSignals(
false);
1746 setAttribute(Qt::WA_UpdatesDisabled,
false);
1748 QLineEdit::paintEvent( ev );
1751 if (d->enableClickMsg && text().isEmpty()) {
1754 f.setItalic(d->italicizePlaceholder);
1757 QColor color(palette().color(foregroundRole()));
1758 color.setAlphaF(0.5);
1761 QStyleOptionFrame opt;
1762 initStyleOption(&opt);
1763 QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt,
this);
1766 const int verticalMargin(1);
1767 const int horizontalMargin(2);
1769 int left, top, right, bottom;
1770 getTextMargins( &left, &top, &right, &bottom );
1771 cr.adjust( left, top, -right, -bottom );
1775 QFontMetrics fm = fontMetrics();
1776 Qt::Alignment va = alignment() & Qt::AlignVertical_Mask;
1778 switch (va & Qt::AlignVertical_Mask)
1780 case Qt::AlignBottom:
1781 vscroll = cr.y() + cr.height() - fm.height() - verticalMargin;
1785 vscroll = cr.y() + verticalMargin;
1789 vscroll = cr.y() + (cr.height() - fm.height() + 1) / 2;
1794 QRect lineRect(cr.x() + horizontalMargin, vscroll, cr.width() - 2*horizontalMargin, fm.height());
1795 p.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, d->clickMessage);
1802 QLineEdit::focusInEvent( ev );
1807 QLineEdit::focusOutEvent( ev );
1812 d->enableClickMsg = !msg.isEmpty();
1813 d->clickMessage = msg;
1817 #ifndef KDE_NO_DEPRECATED
1820 QLineEdit::setContextMenuPolicy( showMenu ? Qt::DefaultContextMenu : Qt::NoContextMenu );
1824 #ifndef KDE_NO_DEPRECATED
1827 return ( contextMenuPolicy() == Qt::DefaultContextMenu );
1837 if (val ==
"NoEcho")
1838 setEchoMode(NoEcho);
1840 d->threeStars = (val ==
"ThreeStars");
1841 setEchoMode(Password);
1846 setEchoMode( Normal );
1852 return echoMode() == NoEcho || echoMode() == Password;
1860 d->completionRunning =
true;
1864 d->completionRunning =
false;
1867 #include "klineedit.moc"
1868 #include "klineedit_p.moc"
bool contains(const QKeySequence &needle) const
Returns whether at least one of the key sequences is equal to needle.
virtual void mouseDoubleClickEvent(QMouseEvent *)
Re-implemented for internal reasons.
const KShortcut & deleteWordForward()
Delete a word forward from mouse/cursor position.
KAction * cut(const QObject *recvr, const char *slot, QObject *parent)
Cut selected area and store it in the clipboard.
KeyBindingMap getKeyBindings() const
Returns a key-binding map.
static void setEditText(KLineEdit *edit, const QString &text)
void doCompletion(const QString &txt)
Do completion now.
KAction * undo(const QObject *recvr, const char *slot, QObject *parent)
Undo the last operation.
const KShortcut & forwardWord()
ForwardWord.
void aboutToShowContextMenu(QMenu *menu)
Emitted before the context menu is displayed.
virtual void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Reimplemented for internal reasons, the API is not affected.
A helper widget for "completion-widgets" (KLineEdit, KComboBox))
void setUrl(const KUrl &url)
Sets url into the lineedit.
QMenu * createStandardContextMenu()
Re-implemented for internal reasons.
const KShortcut & redo()
Redo.
KAction * copy(const QObject *recvr, const char *slot, QObject *parent)
Copy the selected area into the clipboard.
const KShortcut & shortcut(StandardShortcut id)
Returns the keybinding for accel.
const KShortcut & undo()
Undo last operation.
virtual void setCompletionObject(KCompletion *, bool hsig=true)
Reimplemented for internal reasons, the API is not affected.
virtual void setCompletedText(const QString &)
See KCompletionBase::setCompletedText.
QString userText() const
Returns the text as given by the user (i.e.
Switch to next completion (by default Ctrl-Down).
void setCompletionBox(KCompletionBox *box)
Set the completion-box to be used in completion mode KGlobalSettings::CompletionPopup.
virtual void focusOutEvent(QFocusEvent *ev)
bool isSqueezedTextEnabled() const
Returns true if text squeezing is enabled.
bool trapReturnKey() const
bool autoSuggest() const
Whether in current state text should be auto-suggested.
KCompletion * compObj() const
Returns a pointer to the completion object.
QString clickMessage() const
KAction * deselect(const QObject *recvr, const char *slot, QObject *parent)
Deselect any selected elements in the current document.
void textRotation(KCompletionBase::KeyBindingType)
Emitted when the text rotation key-bindings are pressed.
Text completion (by default Ctrl-E).
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
virtual void contextMenuEvent(QContextMenuEvent *)
Re-implemented for internal reasons.
KAction * paste(const QObject *recvr, const char *slot, QObject *parent)
Paste the contents of clipboard at the current mouse or cursor position.
KCompletionBox * completionBox(bool create=true)
static void autoHideEventFilter(QObject *, QEvent *)
KCursor has to install an eventFilter over the widget you want to auto-hide.
KGuiItem del()
Returns the 'Delete' gui item.
virtual void clear()
Reimplemented to workaround a buggy QLineEdit::clear() (changing the clipboard to the text we just ha...
QString i18nc(const char *ctxt, const char *text)
virtual void keyPressEvent(QKeyEvent *)
Re-implemented for internal reasons.
KSharedConfigPtr config()
void userCancelled(const QString &cancelText)
Resets the current displayed text.
Represents a keyboard shortcut.
void clearButtonClicked()
Emitted when the user clicked on the clear button.
virtual void mousePressEvent(QMouseEvent *)
Re-implemented for internal reasons.
virtual void setContextMenuEnabled(bool showMenu)
Enables/disables the popup (context) menu.
void setUrlDropsEnabled(bool enable)
Enables/Disables handling of URL drops.
virtual void dropEvent(QDropEvent *)
Re-implemented to handle URI drops.
Substring completion (by default Ctrl-T).
void substringCompletion(const QString &)
Emitted when the shortcut for substring completion is pressed.
Switch to previous completion (by default Ctrl-Up).
void completion(const QString &)
Emitted when the completion key is pressed.
static KUrl::List fromMimeData(const QMimeData *mimeData, KUrl::MetaDataMap *metaData=0)
bool passwordMode() const
const KShortcut & insert()
Toggle insert/overwrite (with visual feedback, e.g.
bool urlDropsEnabled() const
Returns true when decoded URL drops are enabled.
QStringList allMatches()
Returns a list of all items matching the last completed string.
const KShortcut & endOfLine()
Goto end of current line.
virtual void setCompletionMode(KGlobalSettings::Completion mode)
Sets the type of completion to be used.
A generic class for completing QStrings.
Text is automatically filled in whenever possible.
void setUserSelection(bool userSelection)
Sets the widget in userSelection mode or in automatic completion selection mode.
virtual void resizeEvent(QResizeEvent *)
Re-implemented for internal reasons.
const KShortcut & backwardWord()
BackwardWord.
A wrapper around QIcon that provides KDE icon features.
const KShortcut & beginningOfLine()
Goto beginning of current line.
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
Clear the content of the focus widget.
void setSqueezedTextEnabled(bool enable)
Enable text squeezing whenever the supplied text is too long.
KAction * home(const QObject *recvr, const char *slot, QObject *parent)
Go to the "Home" position or document.
virtual ~KLineEdit()
Destructor.
bool handleSignals() const
Returns true if the object handles the signals.
KAction * redo(const QObject *recvr, const char *slot, QObject *parent)
Redo the last operation.
virtual void setCompletionMode(KGlobalSettings::Completion mode)
Re-implemented from KCompletionBase for internal reasons.
void setSqueezedText(const QString &text)
Squeezes text into the line edit.
const KShortcut & copy()
Copy selected area into the clipboard.
void completionBoxActivated(const QString &)
Emitted whenever the completion box is activated.
QString originalText() const
Returns the original text if text squeezing is enabled.
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
Sets auto-hiding the cursor for widget w.
void setTrapReturnKey(bool trap)
By default, KLineEdit recognizes Key_Return and Key_Enter and emits the returnPressed() signals...
QString nextMatch()
Returns the next item from the matching-items-list.
QSize clearButtonUsedSize() const
virtual void mouseReleaseEvent(QMouseEvent *)
Re-implemented for internal reasons.
const KShortcut & cut()
Cut selected area and store it in the clipboard.
Lists all possible matches in a popup list-box to choose from.
bool isContextMenuEnabled() const
Returns true when the context menu is enabled.
virtual void focusInEvent(QFocusEvent *ev)
Same as automatic except shortest match is used for completion.
virtual QString makeCompletion(const QString &string)
Attempts to find an item in the list of available completions, that begins with string.
An enhanced QLineEdit widget for inputting text.
const KShortcut & deleteWordBack()
Delete a word back from mouse/cursor position.
KLineEdit(const QString &string, QWidget *parent=0)
Constructs a KLineEdit object with a default text, a parent, and a name.
const KShortcut & pasteSelection()
Paste the selection at mouse/cursor position.
virtual void copy() const
Reimplemented for internal reasons, the API is not affected.
Class to encapsulate user-driven action or event.
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
Creates an action corresponding to one of the KStandardAction::StandardAction actions, which is connected to the given object and slot, and is owned by parent.
bool isClearButtonShown() const
Completion
This enum describes the completion mode used for by the KCompletion class.
virtual void setCompletionObject(KCompletion *compObj, bool hsig=true)
Sets up the completion object to be used.
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
virtual bool event(QEvent *)
Re-implemented for internal reasons.
virtual void paintEvent(QPaintEvent *ev)
bool emitSignals() const
Returns true if the object emits the signals.
KAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
Select all elements in the current document.
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
void setPasswordMode(bool b=true)
set the line edit in password mode.
bool authorize(const QString &genericAction)
void completionModeChanged(KGlobalSettings::Completion)
Emitted when the user changed the completion mode by using the popupmenu.
void setClearButtonShown(bool show)
This makes the line edit display an icon on one side of the line edit which, when clicked...
friend class KLineEditStyle
Complete text much in the same way as a typical *nix shell would.
void setClickMessage(const QString &msg)
This makes the line edit display a grayed-out hinting text as long as the user didn't enter any text...
static GraphicEffects graphicEffectsLevel()
This function determines the desired level of effects on the GUI.
static Completion completionMode()
Returns the preferred completion mode setting.
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
virtual void makeCompletion(const QString &)
Completes the remaining text with a matching one from a given list.
void returnPressed(const QString &)
Emitted when the user presses the return key.
virtual void setReadOnly(bool)
Sets the lineedit to read-only.
virtual void setText(const QString &)
Re-implemented to enable text squeezing.
void setCompletedItems(const QStringList &items, bool autoSuggest=true)
Same as the above function except it allows you to temporarily turn off text completion in Completion...
const KShortcut & end()
Goto end of the document.
T readEntry(const QString &key, const T &aDefault) const
GUI with simple animations enabled.
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
KGlobalSettings::Completion completionMode() const
Returns the current completion mode.
QString previousMatch()
Returns the next item from the matching-items-list.
void rotateText(KCompletionBase::KeyBindingType type)
Iterates through all possible matches of the completed text or the history list.
Lists all possible matches in a popup list-box to choose from, and automatically fill the result when...
void setCompletionModeDisabled(KGlobalSettings::Completion mode, bool disable=true)
Disables completion modes by makeing them non-checkable.
const KShortcut & paste()
Paste contents of clipboard at mouse/cursor position.