• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • widgets
klineedit.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2 
3  Copyright (C) 1997 Sven Radej (sven.radej@iname.com)
4  Copyright (c) 1999 Patrick Ward <PAT_WARD@HP-USA-om5.om.hp.com>
5  Copyright (c) 1999 Preston Brown <pbrown@kde.org>
6 
7  Re-designed for KDE 2.x by
8  Copyright (c) 2000, 2001 Dawit Alemayehu <adawit@kde.org>
9  Copyright (c) 2000, 2001 Carsten Pfeiffer <pfeiffer@kde.org>
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License (LGPL) as published by the Free Software Foundation;
14  either version 2 of the License, or (at your option) any later
15  version.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Lesser General Public License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public License
23  along with this library; see the file COPYING.LIB. If not, write to
24  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  Boston, MA 02110-1301, USA.
26 */
27 
28 #include "klineedit.h"
29 #include "klineedit_p.h"
30 
31 #include <kaction.h>
32 #include <kapplication.h>
33 #include <kauthorized.h>
34 #include <kconfig.h>
35 #include <kconfiggroup.h>
36 #include <kcursor.h>
37 #include <kdebug.h>
38 #include <kcompletionbox.h>
39 #include <kicontheme.h>
40 #include <kicon.h>
41 #include <klocale.h>
42 #include <kmenu.h>
43 #include <kstandardaction.h>
44 #include <kstandardshortcut.h>
45 
46 #include <QtCore/QTimer>
47 #include <QtGui/QClipboard>
48 #include <QtGui/QStyleOption>
49 #include <QtGui/QToolTip>
50 
51 class KLineEditStyle;
52 
53 class KLineEditPrivate
54 {
55 public:
56  KLineEditPrivate(KLineEdit* qq)
57  : q(qq)
58  {
59  completionBox = 0L;
60  handleURLDrops = true;
61  grabReturnKeyEvents = false;
62 
63  userSelection = true;
64  autoSuggest = false;
65  disableRestoreSelection = false;
66  enableSqueezedText = false;
67 
68  enableClickMsg = false;
69  threeStars = false;
70  completionRunning = false;
71  if (!s_initialized) {
72  KConfigGroup config( KGlobal::config(), "General" );
73  s_backspacePerformsCompletion = config.readEntry("Backspace performs completion", false);
74  s_initialized = true;
75  }
76 
77  clearButton = 0;
78  clickInClear = false;
79  wideEnoughForClear = true;
80 
81  // i18n: Placeholder text in line edit widgets is the text appearing
82  // before any user input, briefly explaining to the user what to type
83  // (e.g. "Enter search pattern").
84  // By default the text is set in italic, which may not be appropriate
85  // for some languages and scripts (e.g. for CJK ideographs).
86  QString metaMsg = i18nc("Italic placeholder text in line edits: 0 no, 1 yes", "1");
87  italicizePlaceholder = (metaMsg.trimmed() != QString('0'));
88  }
89 
90  ~KLineEditPrivate()
91  {
92 // causes a weird crash in KWord at least, so let Qt delete it for us.
93 // delete completionBox;
94  delete style.data();
95  }
96 
97  void _k_slotSettingsChanged(int category)
98  {
99  Q_UNUSED(category);
100 
101  if (clearButton) {
102  clearButton->setAnimationsEnabled(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects);
103  }
104  }
105 
106  void _k_textChanged(const QString &txt)
107  {
108  // COMPAT (as documented): emit userTextChanged whenever textChanged is emitted
109  // KDE5: remove userTextChanged signal, textEdited does the same...
110  if (!completionRunning && (txt != userText)) {
111  userText = txt;
112 #ifndef KDE_NO_DEPRECATED
113  emit q->userTextChanged(txt);
114 #endif
115  }
116  }
117 
118  // Call this when a completion operation changes the lineedit text
119  // "as if it had been edited by the user".
120  void _k_updateUserText(const QString &txt)
121  {
122  if (!completionRunning && (txt != userText)) {
123  userText = txt;
124  q->setModified(true);
125 #ifndef KDE_NO_DEPRECATED
126  emit q->userTextChanged(txt);
127 #endif
128  emit q->textEdited(txt);
129  emit q->textChanged(txt);
130  }
131  }
132 
133  // This is called when the lineedit is readonly.
134  // Either from setReadOnly() itself, or when we realize that
135  // we became readonly and setReadOnly() wasn't called (because it's not virtual)
136  // Typical case: comboBox->lineEdit()->setReadOnly(true)
137  void adjustForReadOnly()
138  {
139  if (style && style.data()->m_overlap) {
140  style.data()->m_overlap = 0;
141  }
142  }
143 
144 
150  bool overrideShortcut(const QKeyEvent* e);
151 
152  static bool s_initialized;
153  static bool s_backspacePerformsCompletion; // Configuration option
154 
155  QColor previousHighlightColor;
156  QColor previousHighlightedTextColor;
157 
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;
165 
166  int squeezedEnd;
167  int squeezedStart;
168  QPalette::ColorRole bgRole;
169  QString squeezedText;
170  QString userText;
171 
172  QString clickMessage;
173  bool enableClickMsg:1;
174  bool threeStars:1;
175 
176  bool possibleTripleClick :1; // set in mousePressEvent, deleted in tripleClickTimeout
177 
178  bool clickInClear:1;
179  bool wideEnoughForClear:1;
180  KLineEditButton *clearButton;
181  QWeakPointer<KLineEditStyle> style;
182  QString lastStyleClass;
183 
184  KCompletionBox *completionBox;
185 
186  bool italicizePlaceholder:1;
187 
188  QAction *noCompletionAction, *shellCompletionAction, *autoCompletionAction, *popupCompletionAction, *shortAutoCompletionAction, *popupAutoCompletionAction, *defaultAction;
189 
190  QMap<KGlobalSettings::Completion, bool> disableCompletionMap;
191  KLineEdit* q;
192 };
193 
194 QStyle *KLineEditStyle::style() const
195 {
196  if (m_subStyle) {
197  return m_subStyle.data();
198  }
199 
200  return KdeUiProxyStyle::style();
201 }
202 
203 QRect KLineEditStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
204 {
205  if (element == SE_LineEditContents) {
206  KLineEditStyle *unconstThis = const_cast<KLineEditStyle *>(this);
207 
208  if (m_sentinel) {
209  // we are recursing: we're wrapping a style that wraps us!
210  unconstThis->m_subStyle.clear();
211  }
212 
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;
217 
218  if (option->direction == Qt::LeftToRight) {
219  return rect.adjusted(0, 0, -m_overlap, 0);
220  } else {
221  return rect.adjusted(m_overlap, 0, 0, 0);
222  }
223  }
224 
225  return KdeUiProxyStyle::subElementRect(element, option, widget);
226 }
227 
228 bool KLineEditPrivate::s_backspacePerformsCompletion = false;
229 bool KLineEditPrivate::s_initialized = false;
230 
231 
232 KLineEdit::KLineEdit( const QString &string, QWidget *parent )
233  : QLineEdit( string, parent ), d(new KLineEditPrivate(this))
234 {
235  init();
236 }
237 
238 KLineEdit::KLineEdit( QWidget *parent )
239  : QLineEdit( parent ), d(new KLineEditPrivate(this))
240 {
241  init();
242 }
243 
244 
245 KLineEdit::~KLineEdit ()
246 {
247  delete d;
248 }
249 
250 void KLineEdit::init()
251 {
252  d->possibleTripleClick = false;
253  d->bgRole = backgroundRole();
254 
255  // Enable the context menu by default.
256  QLineEdit::setContextMenuPolicy( Qt::DefaultContextMenu );
257  KCursor::setAutoHideCursor( this, true, true );
258 
259  KGlobalSettings::Completion mode = completionMode();
260  d->autoSuggest = (mode == KGlobalSettings::CompletionMan ||
261  mode == KGlobalSettings::CompletionPopupAuto ||
262  mode == KGlobalSettings::CompletionAuto);
263  connect( this, SIGNAL(selectionChanged()), this, SLOT(slotRestoreSelectionColors()));
264 
265  connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), this, SLOT(_k_slotSettingsChanged(int)));
266 
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);
272 
273  d->style = new KLineEditStyle(this);
274  setStyle(d->style.data());
275 
276  connect(this, SIGNAL(textChanged(QString)), this, SLOT(_k_textChanged(QString)));
277 }
278 
279 QString KLineEdit::clickMessage() const
280 {
281  return d->clickMessage;
282 }
283 
284 void KLineEdit::setClearButtonShown(bool show)
285 {
286  if (show) {
287  if (d->clearButton) {
288  return;
289  }
290 
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" ) );
295 
296  updateClearButtonIcon(text());
297  updateClearButton();
298  connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButtonIcon(QString)));
299  } else {
300  disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButtonIcon(QString)));
301  delete d->clearButton;
302  d->clearButton = 0;
303  d->clickInClear = false;
304  if (d->style) {
305  d->style.data()->m_overlap = 0;
306  }
307  }
308 }
309 
310 bool KLineEdit::isClearButtonShown() const
311 {
312  return d->clearButton != 0;
313 }
314 
315 QSize KLineEdit::clearButtonUsedSize() const
316 {
317  QSize s;
318  if (d->clearButton) {
319  const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this);
320  s = d->clearButton->sizeHint();
321  s.rwidth() += frameWidth;
322  }
323  return s;
324 }
325 
326 // Decides whether to show or hide the icon; called when the text changes
327 void KLineEdit::updateClearButtonIcon(const QString& text)
328 {
329  if (!d->clearButton) {
330  return;
331  }
332  if (isReadOnly()) {
333  d->adjustForReadOnly();
334  return;
335  }
336 
337  // set proper icon if necessary
338  if (d->clearButton->pixmap().isNull()) {
339  const int clearButtonState = KIconLoader::DefaultState;
340  if (layoutDirection() == Qt::LeftToRight) {
341  d->clearButton->setPixmap(SmallIcon("edit-clear-locationbar-rtl", 0, clearButtonState));
342  } else {
343  d->clearButton->setPixmap(SmallIcon("edit-clear-locationbar-ltr", 0, clearButtonState));
344  }
345  }
346 
347  // trigger animation
348  if (d->wideEnoughForClear && text.length() > 0) {
349  d->clearButton->animateVisible(true);
350  } else {
351  d->clearButton->animateVisible(false);
352  }
353 }
354 
355 // Determine geometry of clear button. Called initially, and on resizeEvent.
356 void KLineEdit::updateClearButton()
357 {
358  if (!d->clearButton) {
359  return;
360  }
361  if (isReadOnly()) {
362  d->adjustForReadOnly();
363  return;
364  }
365 
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");
372 
373  // make sure we have enough room for the clear button
374  // no point in showing it if we can't also see a few characters as well
375  const bool wideEnough = geom.width() > 4 * em + buttonWidth + frameWidth;
376 
377  if (newButtonSize != d->clearButton->size()) {
378  d->clearButton->resize(newButtonSize);
379  }
380 
381  if (d->style) {
382  d->style.data()->m_overlap = wideEnough ? buttonWidth + frameWidth : 0;
383  }
384 
385  if (layoutDirection() == Qt::LeftToRight ) {
386  d->clearButton->move(geom.width() - frameWidth - buttonWidth - 1, 0);
387  } else {
388  d->clearButton->move(frameWidth + 1, 0);
389  }
390 
391  if (wideEnough != d->wideEnoughForClear) {
392  // we may (or may not) have been showing the button, but now our
393  // positiong on that matter has shifted, so let's ensure that it
394  // is properly visible (or not)
395  d->wideEnoughForClear = wideEnough;
396  updateClearButtonIcon(text());
397  }
398 }
399 
400 void KLineEdit::setCompletionMode( KGlobalSettings::Completion mode )
401 {
402  KGlobalSettings::Completion oldMode = completionMode();
403 
404  if ( oldMode != mode && (oldMode == KGlobalSettings::CompletionPopup ||
405  oldMode == KGlobalSettings::CompletionPopupAuto ) &&
406  d->completionBox && d->completionBox->isVisible() )
407  d->completionBox->hide();
408 
409  // If the widgets echo mode is not Normal, no completion
410  // feature will be enabled even if one is requested.
411  if ( echoMode() != QLineEdit::Normal )
412  mode = KGlobalSettings::CompletionNone; // Override the request.
413 
414  if ( kapp && !KAuthorized::authorize("lineedit_text_completion") )
415  mode = KGlobalSettings::CompletionNone;
416 
417  if ( mode == KGlobalSettings::CompletionPopupAuto ||
418  mode == KGlobalSettings::CompletionAuto ||
419  mode == KGlobalSettings::CompletionMan )
420  d->autoSuggest = true;
421  else
422  d->autoSuggest = false;
423 
424  KCompletionBase::setCompletionMode( mode );
425 }
426 
427 void KLineEdit::setCompletionModeDisabled( KGlobalSettings::Completion mode, bool disable )
428 {
429  d->disableCompletionMap[ mode ] = disable;
430 }
431 
432 void KLineEdit::setCompletedText( const QString& t, bool marked )
433 {
434  if ( !d->autoSuggest )
435  return;
436 
437  const QString txt = text();
438 
439  if ( t != txt )
440  {
441  setText(t);
442  if ( marked )
443  setSelection(t.length(), txt.length()-t.length());
444  setUserSelection(false);
445  }
446  else
447  setUserSelection(true);
448 
449 }
450 
451 void KLineEdit::setCompletedText( const QString& text )
452 {
453  KGlobalSettings::Completion mode = completionMode();
454  const bool marked = ( mode == KGlobalSettings::CompletionAuto ||
455  mode == KGlobalSettings::CompletionMan ||
456  mode == KGlobalSettings::CompletionPopup ||
457  mode == KGlobalSettings::CompletionPopupAuto );
458  setCompletedText( text, marked );
459 }
460 
461 void KLineEdit::rotateText( KCompletionBase::KeyBindingType type )
462 {
463  KCompletion* comp = compObj();
464  if ( comp &&
465  (type == KCompletionBase::PrevCompletionMatch ||
466  type == KCompletionBase::NextCompletionMatch ) )
467  {
468  QString input;
469 
470  if (type == KCompletionBase::PrevCompletionMatch)
471  input = comp->previousMatch();
472  else
473  input = comp->nextMatch();
474 
475  // Skip rotation if previous/next match is null or the same text
476  if ( input.isEmpty() || input == displayText() )
477  return;
478  setCompletedText( input, hasSelectedText() );
479  }
480 }
481 
482 void KLineEdit::makeCompletion( const QString& text )
483 {
484  KCompletion *comp = compObj();
485  KGlobalSettings::Completion mode = completionMode();
486 
487  if ( !comp || mode == KGlobalSettings::CompletionNone )
488  return; // No completion object...
489 
490  const QString match = comp->makeCompletion( text );
491 
492  if ( mode == KGlobalSettings::CompletionPopup ||
493  mode == KGlobalSettings::CompletionPopupAuto )
494  {
495  if ( match.isEmpty() )
496  {
497  if ( d->completionBox )
498  {
499  d->completionBox->hide();
500  d->completionBox->clear();
501  }
502  }
503  else
504  setCompletedItems( comp->allMatches() );
505  }
506  else // Auto, ShortAuto (Man) and Shell
507  {
508  // all other completion modes
509  // If no match or the same match, simply return without completing.
510  if ( match.isEmpty() || match == text )
511  return;
512 
513  if ( mode != KGlobalSettings::CompletionShell )
514  setUserSelection(false);
515 
516  if ( d->autoSuggest )
517  setCompletedText( match );
518  }
519 }
520 
521 void KLineEdit::setReadOnly(bool readOnly)
522 {
523  // Do not do anything if nothing changed...
524  if (readOnly == isReadOnly ()) {
525  return;
526  }
527 
528  QLineEdit::setReadOnly(readOnly);
529 
530  if (readOnly) {
531  d->bgRole = backgroundRole();
532  setBackgroundRole(QPalette::Window);
533  if (d->enableSqueezedText && d->squeezedText.isEmpty()) {
534  d->squeezedText = text();
535  setSqueezedText();
536  }
537 
538  if (d->clearButton) {
539  d->clearButton->animateVisible(false);
540  d->adjustForReadOnly();
541  }
542  } else {
543  if (!d->squeezedText.isEmpty()) {
544  setText(d->squeezedText);
545  d->squeezedText.clear();
546  }
547 
548  setBackgroundRole(d->bgRole);
549  updateClearButton();
550  }
551 }
552 
553 void KLineEdit::setSqueezedText( const QString &text)
554 {
555  setSqueezedTextEnabled(true);
556  setText(text);
557 }
558 
559 void KLineEdit::setSqueezedTextEnabled( bool enable )
560 {
561  d->enableSqueezedText = enable;
562 }
563 
564 bool KLineEdit::isSqueezedTextEnabled() const
565 {
566  return d->enableSqueezedText;
567 }
568 
569 void KLineEdit::setText( const QString& text )
570 {
571  if( d->enableClickMsg )
572  {
573  update();
574  }
575  if( d->enableSqueezedText && isReadOnly() )
576  {
577  d->squeezedText = text;
578  setSqueezedText();
579  return;
580  }
581 
582  QLineEdit::setText( text );
583 }
584 
585 void KLineEdit::setSqueezedText()
586 {
587  d->squeezedStart = 0;
588  d->squeezedEnd = 0;
589  const QString fullText = d->squeezedText;
590  const int fullLength = fullText.length();
591  const QFontMetrics fm(fontMetrics());
592  const int labelWidth = size().width() - 2*style()->pixelMetric(QStyle::PM_DefaultFrameWidth) - 2;
593  const int textWidth = fm.width(fullText);
594 
595  if (textWidth > labelWidth)
596  {
597  // start with the dots only
598  QString squeezedText = "...";
599  int squeezedWidth = fm.width(squeezedText);
600 
601  // estimate how many letters we can add to the dots on both sides
602  int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2;
603  squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
604  squeezedWidth = fm.width(squeezedText);
605 
606  if (squeezedWidth < labelWidth)
607  {
608  // we estimated too short
609  // add letters while text < label
610  do
611  {
612  letters++;
613  squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
614  squeezedWidth = fm.width(squeezedText);
615  } while (squeezedWidth < labelWidth && letters <= fullLength / 2);
616  letters--;
617  squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
618  }
619  else if (squeezedWidth > labelWidth)
620  {
621  // we estimated too long
622  // remove letters while text > label
623  do
624  {
625  letters--;
626  squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
627  squeezedWidth = fm.width(squeezedText);
628  } while (squeezedWidth > labelWidth && letters >= 5);
629  }
630 
631  if (letters < 5)
632  {
633  // too few letters added -> we give up squeezing
634  QLineEdit::setText(fullText);
635  }
636  else
637  {
638  QLineEdit::setText(squeezedText);
639  d->squeezedStart = letters;
640  d->squeezedEnd = fullText.length() - letters;
641  }
642 
643  setToolTip( fullText );
644 
645  }
646  else
647  {
648  QLineEdit::setText(fullText);
649 
650  this->setToolTip( "" );
651  QToolTip::showText(pos(), QString()); // hide
652  }
653 
654  setCursorPosition(0);
655 }
656 
657 void KLineEdit::copy() const
658 {
659  if( !copySqueezedText(true))
660  QLineEdit::copy();
661 }
662 
663 bool KLineEdit::copySqueezedText(bool clipboard) const
664 {
665  if (!d->squeezedText.isEmpty() && d->squeezedStart)
666  {
667  KLineEdit *that = const_cast<KLineEdit *>(this);
668  if (!that->hasSelectedText())
669  return false;
670  int start = selectionStart(), end = start + selectedText().length();
671  if (start >= d->squeezedStart+3)
672  start = start - 3 - d->squeezedStart + d->squeezedEnd;
673  else if (start > d->squeezedStart)
674  start = d->squeezedStart;
675  if (end >= d->squeezedStart+3)
676  end = end - 3 - d->squeezedStart + d->squeezedEnd;
677  else if (end > d->squeezedStart)
678  end = d->squeezedEnd;
679  if (start == end)
680  return false;
681  QString t = d->squeezedText;
682  t = t.mid(start, end - start);
683  disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()), this, 0);
684  QApplication::clipboard()->setText( t, clipboard ? QClipboard::Clipboard : QClipboard::Selection );
685  connect( QApplication::clipboard(), SIGNAL(selectionChanged()), this,
686  SLOT(_q_clipboardChanged()) );
687  return true;
688  }
689  return false;
690 }
691 
692 void KLineEdit::resizeEvent( QResizeEvent * ev )
693 {
694  if (!d->squeezedText.isEmpty())
695  setSqueezedText();
696 
697  updateClearButton();
698  QLineEdit::resizeEvent(ev);
699 }
700 
701 
702 void KLineEdit::keyPressEvent( QKeyEvent *e )
703 {
704  const int key = e->key() | e->modifiers();
705 
706  if ( KStandardShortcut::copy().contains( key ) )
707  {
708  copy();
709  return;
710  }
711  else if ( KStandardShortcut::paste().contains( key ) )
712  {
713  // TODO:
714  // we should restore the original text (not autocompleted), otherwise the paste
715  // will get into troubles Bug: 134691
716  if( !isReadOnly() )
717  paste();
718  return;
719  }
720  else if ( KStandardShortcut::pasteSelection().contains( key ) )
721  {
722  QString text = QApplication::clipboard()->text( QClipboard::Selection);
723  insert( text );
724  deselect();
725  return;
726  }
727 
728  else if ( KStandardShortcut::cut().contains( key ) )
729  {
730  if( !isReadOnly() )
731  cut();
732  return;
733  }
734  else if ( KStandardShortcut::undo().contains( key ) )
735  {
736  if( !isReadOnly() )
737  undo();
738  return;
739  }
740  else if ( KStandardShortcut::redo().contains( key ) )
741  {
742  if( !isReadOnly() )
743  redo();
744  return;
745  }
746  else if ( KStandardShortcut::deleteWordBack().contains( key ) )
747  {
748  cursorWordBackward(true);
749  if ( hasSelectedText() )
750  del();
751 
752  e->accept();
753  return;
754  }
755  else if ( KStandardShortcut::deleteWordForward().contains( key ) )
756  {
757  // Workaround for QT bug where
758  cursorWordForward(true);
759  if ( hasSelectedText() )
760  del();
761 
762  e->accept();
763  return;
764  }
765  else if ( KStandardShortcut::backwardWord().contains( key ) )
766  {
767  cursorWordBackward(false);
768  e->accept();
769  return;
770  }
771  else if ( KStandardShortcut::forwardWord().contains( key ) )
772  {
773  cursorWordForward(false);
774  e->accept();
775  return;
776  }
777  else if ( KStandardShortcut::beginningOfLine().contains( key ) )
778  {
779  home(false);
780  e->accept();
781  return;
782  }
783  else if ( KStandardShortcut::endOfLine().contains( key ) )
784  {
785  end(false);
786  e->accept();
787  return;
788  }
789 
790 
791  // Filter key-events if EchoMode is normal and
792  // completion mode is not set to CompletionNone
793  if ( echoMode() == QLineEdit::Normal &&
794  completionMode() != KGlobalSettings::CompletionNone )
795  {
796  if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
797  const bool trap = (d->completionBox && d->completionBox->isVisible());
798  const bool stopEvent = (trap || (d->grabReturnKeyEvents &&
799  (e->modifiers() == Qt::NoButton ||
800  e->modifiers() == Qt::KeypadModifier)));
801 
802  if (stopEvent) {
803  emit QLineEdit::returnPressed();
804  e->accept();
805  }
806 
807  emit returnPressed( displayText() );
808 
809  if (trap) {
810  d->completionBox->hide();
811  deselect();
812  setCursorPosition(text().length());
813  }
814 
815  // Eat the event if the user asked for it, or if a completionbox was visible
816  if (stopEvent) {
817  return;
818  }
819  }
820 
821  const KeyBindingMap keys = getKeyBindings();
822  const KGlobalSettings::Completion mode = completionMode();
823  const bool noModifier = (e->modifiers() == Qt::NoButton ||
824  e->modifiers() == Qt::ShiftModifier ||
825  e->modifiers() == Qt::KeypadModifier);
826 
827  if ( (mode == KGlobalSettings::CompletionAuto ||
828  mode == KGlobalSettings::CompletionPopupAuto ||
829  mode == KGlobalSettings::CompletionMan) && noModifier )
830  {
831  if ( !d->userSelection && hasSelectedText() &&
832  ( e->key() == Qt::Key_Right || e->key() == Qt::Key_Left ) &&
833  e->modifiers()==Qt::NoButton )
834  {
835  const QString old_txt = text();
836  d->disableRestoreSelection = true;
837  const int start = selectionStart();
838 
839  deselect();
840  QLineEdit::keyPressEvent ( e );
841  const int cPosition=cursorPosition();
842  setText(old_txt);
843 
844  // keep cursor at cPosition
845  setSelection(old_txt.length(), cPosition - old_txt.length());
846  if (e->key() == Qt::Key_Right && cPosition > start )
847  {
848  //the user explicitly accepted the autocompletion
849  d->_k_updateUserText(text());
850  }
851 
852  d->disableRestoreSelection = false;
853  return;
854  }
855 
856  if ( e->key() == Qt::Key_Escape )
857  {
858  if (hasSelectedText() && !d->userSelection )
859  {
860  del();
861  setUserSelection(true);
862  }
863 
864  // Don't swallow the Escape press event for the case
865  // of dialogs, which have Escape associated to Cancel
866  e->ignore();
867  return;
868  }
869 
870  }
871 
872  if ( (mode == KGlobalSettings::CompletionAuto ||
873  mode == KGlobalSettings::CompletionMan) && noModifier )
874  {
875  const QString keycode = e->text();
876  if ( !keycode.isEmpty() && (keycode.unicode()->isPrint() ||
877  e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
878  {
879  const bool hasUserSelection=d->userSelection;
880  const bool hadSelection=hasSelectedText();
881 
882  bool cursorNotAtEnd=false;
883 
884  const int start = selectionStart();
885  const int cPos = cursorPosition();
886 
887  // When moving the cursor, we want to keep the autocompletion as an
888  // autocompletion, so we want to process events at the cursor position
889  // as if there was no selection. After processing the key event, we
890  // can set the new autocompletion again.
891  if ( hadSelection && !hasUserSelection && start>cPos )
892  {
893  del();
894  setCursorPosition(cPos);
895  cursorNotAtEnd=true;
896  }
897 
898  d->disableRestoreSelection = true;
899  QLineEdit::keyPressEvent ( e );
900  d->disableRestoreSelection = false;
901 
902  QString txt = text();
903  int len = txt.length();
904  if ( !hasSelectedText() && len /*&& cursorPosition() == len */)
905  {
906  if ( e->key() == Qt::Key_Backspace )
907  {
908  if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
909  {
910  backspace();
911  txt = text();
912  len = txt.length();
913  }
914 
915  if (!d->s_backspacePerformsCompletion || !len) {
916  d->autoSuggest = false;
917  }
918  }
919 
920  if (e->key() == Qt::Key_Delete )
921  d->autoSuggest=false;
922 
923  doCompletion(txt);
924 
925  if( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
926  d->autoSuggest=true;
927 
928  e->accept();
929  }
930 
931  return;
932  }
933 
934  }
935 
936  else if (( mode == KGlobalSettings::CompletionPopup ||
937  mode == KGlobalSettings::CompletionPopupAuto ) &&
938  noModifier && !e->text().isEmpty() )
939  {
940  const QString old_txt = text();
941  const bool hasUserSelection=d->userSelection;
942  const bool hadSelection=hasSelectedText();
943  bool cursorNotAtEnd=false;
944 
945  const int start = selectionStart();
946  const int cPos = cursorPosition();
947  const QString keycode = e->text();
948 
949  // When moving the cursor, we want to keep the autocompletion as an
950  // autocompletion, so we want to process events at the cursor position
951  // as if there was no selection. After processing the key event, we
952  // can set the new autocompletion again.
953  if (hadSelection && !hasUserSelection && start>cPos &&
954  ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
955  e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
956  {
957  del();
958  setCursorPosition(cPos);
959  cursorNotAtEnd=true;
960  }
961 
962  const int selectedLength=selectedText().length();
963 
964  d->disableRestoreSelection = true;
965  QLineEdit::keyPressEvent ( e );
966  d->disableRestoreSelection = false;
967 
968  if (( selectedLength != selectedText().length() ) && !hasUserSelection )
969  slotRestoreSelectionColors(); // and set userSelection to true
970 
971  QString txt = text();
972  int len = txt.length();
973  if ( ( txt != old_txt || txt != e->text() ) && len/* && ( cursorPosition() == len || force )*/ &&
974  ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
975  e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
976  {
977  if ( e->key() == Qt::Key_Backspace )
978  {
979  if ( hadSelection && !hasUserSelection && !cursorNotAtEnd )
980  {
981  backspace();
982  txt = text();
983  len = txt.length();
984  }
985 
986  if (!d->s_backspacePerformsCompletion) {
987  d->autoSuggest = false;
988  }
989  }
990 
991  if (e->key() == Qt::Key_Delete )
992  d->autoSuggest=false;
993 
994  if ( d->completionBox )
995  d->completionBox->setCancelledText( txt );
996 
997  doCompletion(txt);
998 
999  if ( (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) &&
1000  mode == KGlobalSettings::CompletionPopupAuto )
1001  d->autoSuggest=true;
1002 
1003  e->accept();
1004  }
1005  else if (!len && d->completionBox && d->completionBox->isVisible())
1006  d->completionBox->hide();
1007 
1008  return;
1009  }
1010 
1011  else if ( mode == KGlobalSettings::CompletionShell )
1012  {
1013  // Handles completion.
1014  KShortcut cut;
1015  if ( keys[TextCompletion].isEmpty() )
1016  cut = KStandardShortcut::shortcut(KStandardShortcut::TextCompletion);
1017  else
1018  cut = keys[TextCompletion];
1019 
1020  if ( cut.contains( key ) )
1021  {
1022  // Emit completion if the completion mode is CompletionShell
1023  // and the cursor is at the end of the string.
1024  const QString txt = text();
1025  const int len = txt.length();
1026  if ( cursorPosition() == len && len != 0 )
1027  {
1028  doCompletion(txt);
1029  return;
1030  }
1031  }
1032  else if ( d->completionBox )
1033  d->completionBox->hide();
1034  }
1035 
1036  // handle rotation
1037  if ( mode != KGlobalSettings::CompletionNone )
1038  {
1039  // Handles previous match
1040  KShortcut cut;
1041  if ( keys[PrevCompletionMatch].isEmpty() )
1042  cut = KStandardShortcut::shortcut(KStandardShortcut::PrevCompletion);
1043  else
1044  cut = keys[PrevCompletionMatch];
1045 
1046  if ( cut.contains( key ) )
1047  {
1048  if ( emitSignals() )
1049  emit textRotation( KCompletionBase::PrevCompletionMatch );
1050  if ( handleSignals() )
1051  rotateText( KCompletionBase::PrevCompletionMatch );
1052  return;
1053  }
1054 
1055  // Handles next match
1056  if ( keys[NextCompletionMatch].isEmpty() )
1057  cut = KStandardShortcut::shortcut(KStandardShortcut::NextCompletion);
1058  else
1059  cut = keys[NextCompletionMatch];
1060 
1061  if ( cut.contains( key ) )
1062  {
1063  if ( emitSignals() )
1064  emit textRotation( KCompletionBase::NextCompletionMatch );
1065  if ( handleSignals() )
1066  rotateText( KCompletionBase::NextCompletionMatch );
1067  return;
1068  }
1069  }
1070 
1071  // substring completion
1072  if ( compObj() )
1073  {
1074  KShortcut cut;
1075  if ( keys[SubstringCompletion].isEmpty() )
1076  cut = KStandardShortcut::shortcut(KStandardShortcut::SubstringCompletion);
1077  else
1078  cut = keys[SubstringCompletion];
1079 
1080  if ( cut.contains( key ) )
1081  {
1082  if ( emitSignals() )
1083  emit substringCompletion( text() );
1084  if ( handleSignals() )
1085  {
1086  setCompletedItems( compObj()->substringCompletion(text()));
1087  e->accept();
1088  }
1089  return;
1090  }
1091  }
1092  }
1093  const int selectedLength = selectedText().length();
1094 
1095  // Let QLineEdit handle any other keys events.
1096  QLineEdit::keyPressEvent ( e );
1097 
1098  if ( selectedLength != selectedText().length() )
1099  slotRestoreSelectionColors(); // and set userSelection to true
1100 }
1101 
1102 void KLineEdit::mouseDoubleClickEvent( QMouseEvent* e )
1103 {
1104  if ( e->button() == Qt::LeftButton )
1105  {
1106  d->possibleTripleClick=true;
1107  QTimer::singleShot( QApplication::doubleClickInterval(),this,
1108  SLOT(tripleClickTimeout()) );
1109  }
1110  QLineEdit::mouseDoubleClickEvent( e );
1111 }
1112 
1113 void KLineEdit::mousePressEvent( QMouseEvent* e )
1114 {
1115  if ( (e->button() == Qt::LeftButton ||
1116  e->button() == Qt::MidButton ) &&
1117  d->clearButton ) {
1118  d->clickInClear = ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() );
1119 
1120  if ( d->clickInClear ) {
1121  d->possibleTripleClick = false;
1122  }
1123  }
1124 
1125  if ( e->button() == Qt::LeftButton && d->possibleTripleClick ) {
1126  selectAll();
1127  e->accept();
1128  return;
1129  }
1130 
1131  // if middle clicking and if text is present in the clipboard then clear the selection
1132  // to prepare paste operation
1133  if ( e->button() == Qt::MidButton ) {
1134  if ( hasSelectedText() && !isReadOnly() ) {
1135  if ( QApplication::clipboard()->text( QClipboard::Selection ).length() >0 ) {
1136  backspace();
1137  }
1138  }
1139  }
1140 
1141  QLineEdit::mousePressEvent( e );
1142 }
1143 
1144 void KLineEdit::mouseReleaseEvent( QMouseEvent* e )
1145 {
1146  if ( d->clickInClear ) {
1147  if ( d->clearButton == childAt(e->pos()) || d->clearButton->underMouse() ) {
1148  QString newText;
1149  if ( e->button() == Qt::MidButton ) {
1150  newText = QApplication::clipboard()->text( QClipboard::Selection );
1151  setText( newText );
1152  } else {
1153  setSelection(0, text().size());
1154  del();
1155  emit clearButtonClicked();
1156  }
1157  emit textChanged( newText );
1158  }
1159 
1160  d->clickInClear = false;
1161  e->accept();
1162  return;
1163  }
1164 
1165  QLineEdit::mouseReleaseEvent( e );
1166 
1167  if (QApplication::clipboard()->supportsSelection() ) {
1168  if ( e->button() == Qt::LeftButton ) {
1169  // Fix copying of squeezed text if needed
1170  copySqueezedText( false );
1171  }
1172  }
1173 }
1174 
1175 void KLineEdit::tripleClickTimeout()
1176 {
1177  d->possibleTripleClick=false;
1178 }
1179 
1180 QMenu* KLineEdit::createStandardContextMenu()
1181 {
1182  QMenu *popup = QLineEdit::createStandardContextMenu();
1183 
1184  if( !isReadOnly() )
1185  {
1186  // FIXME: This code depends on Qt's action ordering.
1187  const QList<QAction *> actionList = popup->actions();
1188  enum { UndoAct, RedoAct, Separator1, CutAct, CopyAct, PasteAct, DeleteAct, ClearAct,
1189  Separator2, SelectAllAct, NCountActs };
1190  QAction *separatorAction = 0L;
1191  // separator we want is right after Delete right now.
1192  const int idx = actionList.indexOf( actionList[DeleteAct] ) + 1;
1193  if ( idx < actionList.count() )
1194  separatorAction = actionList.at( idx );
1195  if ( separatorAction )
1196  {
1197  KAction *clearAllAction = KStandardAction::clear( this, SLOT(clear()), popup) ;
1198  if ( text().isEmpty() )
1199  clearAllAction->setEnabled( false );
1200  popup->insertAction( separatorAction, clearAllAction );
1201  }
1202  }
1203 
1204  KIconTheme::assignIconsToContextMenu( KIconTheme::TextEditor, popup->actions () );
1205 
1206  // If a completion object is present and the input
1207  // widget is not read-only, show the Text Completion
1208  // menu item.
1209  if ( compObj() && !isReadOnly() && KAuthorized::authorize("lineedit_text_completion") )
1210  {
1211  QMenu *subMenu = popup->addMenu( KIcon("text-completion"), i18nc("@title:menu", "Text Completion") );
1212  connect( subMenu, SIGNAL(triggered(QAction*)),
1213  this, SLOT(completionMenuActivated(QAction*)) );
1214 
1215  popup->addSeparator();
1216 
1217  QActionGroup* ag = new QActionGroup( this );
1218  d->noCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "None"));
1219  d->shellCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "Manual") );
1220  d->autoCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "Automatic") );
1221  d->popupCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "Dropdown List") );
1222  d->shortAutoCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "Short Automatic") );
1223  d->popupAutoCompletionAction = ag->addAction( i18nc("@item:inmenu Text Completion", "Dropdown List && Automatic"));
1224  subMenu->addActions( ag->actions() );
1225 
1226  //subMenu->setAccel( KStandardShortcut::completion(), ShellCompletion );
1227 
1228  d->shellCompletionAction->setCheckable( true );
1229  d->noCompletionAction->setCheckable( true );
1230  d->popupCompletionAction->setCheckable( true );
1231  d->autoCompletionAction->setCheckable( true );
1232  d->shortAutoCompletionAction->setCheckable( true );
1233  d->popupAutoCompletionAction->setCheckable( true );
1234 
1235  d->shellCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionShell ] );
1236  d->noCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionNone ] );
1237  d->popupCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionPopup ] );
1238  d->autoCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionAuto ] );
1239  d->shortAutoCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionMan ] );
1240  d->popupAutoCompletionAction->setEnabled( !d->disableCompletionMap[ KGlobalSettings::CompletionPopupAuto ] );
1241 
1242  const KGlobalSettings::Completion mode = completionMode();
1243  d->noCompletionAction->setChecked( mode == KGlobalSettings::CompletionNone );
1244  d->shellCompletionAction->setChecked( mode == KGlobalSettings::CompletionShell );
1245  d->popupCompletionAction->setChecked( mode == KGlobalSettings::CompletionPopup );
1246  d->autoCompletionAction->setChecked( mode == KGlobalSettings::CompletionAuto );
1247  d->shortAutoCompletionAction->setChecked( mode == KGlobalSettings::CompletionMan );
1248  d->popupAutoCompletionAction->setChecked( mode == KGlobalSettings::CompletionPopupAuto );
1249 
1250  const KGlobalSettings::Completion defaultMode = KGlobalSettings::completionMode();
1251  if ( mode != defaultMode && !d->disableCompletionMap[ defaultMode ] )
1252  {
1253  subMenu->addSeparator();
1254  d->defaultAction = subMenu->addAction( i18nc("@item:inmenu Text Completion", "Default") );
1255  }
1256  }
1257 
1258  return popup;
1259 }
1260 
1261 void KLineEdit::contextMenuEvent( QContextMenuEvent *e )
1262 {
1263  if ( QLineEdit::contextMenuPolicy() != Qt::DefaultContextMenu )
1264  return;
1265  QMenu *popup = createStandardContextMenu();
1266 
1267  // ### do we really need this? Yes, Please do not remove! This
1268  // allows applications to extend the popup menu without having to
1269  // inherit from this class! (DA)
1270  emit aboutToShowContextMenu( popup );
1271 
1272  popup->exec(e->globalPos());
1273  delete popup;
1274 }
1275 
1276 void KLineEdit::completionMenuActivated( QAction *act)
1277 {
1278  KGlobalSettings::Completion oldMode = completionMode();
1279 
1280  if( act == d->noCompletionAction )
1281  {
1282  setCompletionMode( KGlobalSettings::CompletionNone );
1283  }
1284  else if( act == d->shellCompletionAction)
1285  {
1286  setCompletionMode( KGlobalSettings::CompletionShell );
1287  }
1288  else if( act == d->autoCompletionAction)
1289  {
1290  setCompletionMode( KGlobalSettings::CompletionAuto );
1291  }
1292  else if( act == d->popupCompletionAction)
1293  {
1294  setCompletionMode( KGlobalSettings::CompletionPopup );
1295  }
1296  else if( act == d->shortAutoCompletionAction)
1297  {
1298  setCompletionMode( KGlobalSettings::CompletionMan );
1299  }
1300  else if( act == d->popupAutoCompletionAction)
1301  {
1302  setCompletionMode( KGlobalSettings::CompletionPopupAuto );
1303  }
1304  else if( act == d->defaultAction )
1305  {
1306  setCompletionMode( KGlobalSettings::completionMode() );
1307  }
1308  else
1309  return;
1310 
1311  if ( oldMode != completionMode() )
1312  {
1313  if ( (oldMode == KGlobalSettings::CompletionPopup ||
1314  oldMode == KGlobalSettings::CompletionPopupAuto ) &&
1315  d->completionBox && d->completionBox->isVisible() )
1316  d->completionBox->hide();
1317  emit completionModeChanged( completionMode() );
1318  }
1319 }
1320 
1321 void KLineEdit::dropEvent(QDropEvent *e)
1322 {
1323  if( d->handleURLDrops )
1324  {
1325  const KUrl::List urlList = KUrl::List::fromMimeData( e->mimeData() );
1326  if ( !urlList.isEmpty() )
1327  {
1328  // Let's replace the current text with the dropped URL(s), rather than appending.
1329  // Makes more sense in general (#188129), e.g. konq location bar and kurlrequester
1330  // can only hold one url anyway. OK this code supports multiple urls being dropped,
1331  // but that's not the common case [and it breaks if they contain spaces... this is why
1332  // kfiledialog uses double quotes around filenames in multiple-selection mode]...
1333  //
1334  // Anyway, if some apps prefer "append" then we should have a
1335  // setUrlDropsSupport( {NoUrlDrops, SingleUrlDrops, MultipleUrlDrops} )
1336  // where Single replaces and Multiple appends.
1337  QString dropText;
1338  //QString dropText = text();
1339  KUrl::List::ConstIterator it;
1340  for( it = urlList.begin() ; it != urlList.end() ; ++it )
1341  {
1342  if(!dropText.isEmpty())
1343  dropText+=' ';
1344 
1345  dropText += (*it).prettyUrl();
1346  }
1347 
1348  setText(dropText);
1349  setCursorPosition(dropText.length());
1350 
1351  e->accept();
1352  return;
1353  }
1354  }
1355  QLineEdit::dropEvent(e);
1356 }
1357 
1358 bool KLineEdit::event( QEvent* ev )
1359 {
1360  KCursor::autoHideEventFilter( this, ev );
1361  if ( ev->type() == QEvent::ShortcutOverride )
1362  {
1363  QKeyEvent *e = static_cast<QKeyEvent *>( ev );
1364  if (d->overrideShortcut(e)) {
1365  ev->accept();
1366  }
1367  } else if (ev->type() == QEvent::ApplicationPaletteChange
1368  || ev->type() == QEvent::PaletteChange) {
1369  // Assume the widget uses the application's palette
1370  QPalette p = QApplication::palette();
1371  d->previousHighlightedTextColor=p.color(QPalette::Normal,QPalette::HighlightedText);
1372  d->previousHighlightColor=p.color(QPalette::Normal,QPalette::Highlight);
1373  setUserSelection(d->userSelection);
1374  } else if (ev->type() == QEvent::StyleChange) {
1375  // since we have our own style and it relies on this style to Get Things Right,
1376  // if a style is set specifically on the widget (which would replace our own style!)
1377  // hang on to this special style and re-instate our own style.
1378  //FIXME: Qt currently has a grave bug where already deleted QStyleSheetStyle objects
1379  // will get passed back in if we set a new style on it here. remove the qstrmcp test
1380  // when this is fixed in Qt (or a better approach is found)
1381  if (!qobject_cast<KLineEditStyle *>(style()) &&
1382  qstrcmp(style()->metaObject()->className(), "QStyleSheetStyle") != 0 &&
1383  QLatin1String(style()->metaObject()->className()) != d->lastStyleClass) {
1384  KLineEditStyle *kleStyle = d->style.data();
1385  if (!kleStyle) {
1386  d->style = kleStyle = new KLineEditStyle(this);
1387  }
1388 
1389  kleStyle->m_subStyle = style();
1390  // this guards against "wrap around" where another style, e.g. QStyleSheetStyle,
1391  // is setting the style on QEvent::StyleChange
1392  d->lastStyleClass = QLatin1String(style()->metaObject()->className());
1393  setStyle(kleStyle);
1394  d->lastStyleClass.clear();
1395  }
1396  } else if (ev->type() == QEvent::ApplicationLayoutDirectionChange
1397  || ev->type() == QEvent::LayoutDirectionChange) {
1398  updateClearButtonIcon(text());
1399  updateClearButton();
1400  }
1401 
1402  return QLineEdit::event( ev );
1403 }
1404 
1405 
1406 void KLineEdit::setUrlDropsEnabled(bool enable)
1407 {
1408  d->handleURLDrops=enable;
1409 }
1410 
1411 bool KLineEdit::urlDropsEnabled() const
1412 {
1413  return d->handleURLDrops;
1414 }
1415 
1416 void KLineEdit::setTrapReturnKey( bool grab )
1417 {
1418  d->grabReturnKeyEvents = grab;
1419 }
1420 
1421 bool KLineEdit::trapReturnKey() const
1422 {
1423  return d->grabReturnKeyEvents;
1424 }
1425 
1426 void KLineEdit::setUrl( const KUrl& url )
1427 {
1428  setText( url.prettyUrl() );
1429 }
1430 
1431 void KLineEdit::setCompletionBox( KCompletionBox *box )
1432 {
1433  if ( d->completionBox )
1434  return;
1435 
1436  d->completionBox = box;
1437  if ( handleSignals() )
1438  {
1439  connect( d->completionBox, SIGNAL(currentTextChanged(QString)),
1440  SLOT(_k_slotCompletionBoxTextChanged(QString)) );
1441  connect( d->completionBox, SIGNAL(userCancelled(QString)),
1442  SLOT(userCancelled(QString)) );
1443  connect( d->completionBox, SIGNAL(activated(QString)),
1444  SIGNAL(completionBoxActivated(QString)) );
1445  connect( d->completionBox, SIGNAL(activated(QString)),
1446  SIGNAL(textEdited(QString)) );
1447  }
1448 }
1449 
1450 /*
1451  * Set the line edit text without changing the modified flag. By default
1452  * calling setText resets the modified flag to false.
1453  */
1454 static void setEditText(KLineEdit* edit, const QString& text)
1455 {
1456  if (!edit) {
1457  return;
1458  }
1459 
1460  const bool wasModified = edit->isModified();
1461  edit->setText(text);
1462  edit->setModified(wasModified);
1463 }
1464 
1465 void KLineEdit::userCancelled(const QString & cancelText)
1466 {
1467  if ( completionMode() != KGlobalSettings::CompletionPopupAuto )
1468  {
1469  setEditText(this, cancelText);
1470  }
1471  else if (hasSelectedText() )
1472  {
1473  if (d->userSelection)
1474  deselect();
1475  else
1476  {
1477  d->autoSuggest=false;
1478  const int start = selectionStart() ;
1479  const QString s = text().remove(selectionStart(), selectedText().length());
1480  setEditText(this, s);
1481  setCursorPosition(start);
1482  d->autoSuggest=true;
1483  }
1484  }
1485 }
1486 
1487 bool KLineEditPrivate::overrideShortcut(const QKeyEvent* e)
1488 {
1489  KShortcut scKey;
1490 
1491  const int key = e->key() | e->modifiers();
1492  const KLineEdit::KeyBindingMap keys = q->getKeyBindings();
1493 
1494  if (keys[KLineEdit::TextCompletion].isEmpty())
1495  scKey = KStandardShortcut::shortcut(KStandardShortcut::TextCompletion);
1496  else
1497  scKey = keys[KLineEdit::TextCompletion];
1498 
1499  if (scKey.contains( key ))
1500  return true;
1501 
1502  if (keys[KLineEdit::NextCompletionMatch].isEmpty())
1503  scKey = KStandardShortcut::shortcut(KStandardShortcut::NextCompletion);
1504  else
1505  scKey = keys[KLineEdit::NextCompletionMatch];
1506 
1507  if (scKey.contains( key ))
1508  return true;
1509 
1510  if (keys[KLineEdit::PrevCompletionMatch].isEmpty())
1511  scKey = KStandardShortcut::shortcut(KStandardShortcut::PrevCompletion);
1512  else
1513  scKey = keys[KLineEdit::PrevCompletionMatch];
1514 
1515  if (scKey.contains( key ))
1516  return true;
1517 
1518  // Override all the text manupilation accelerators...
1519  if ( KStandardShortcut::copy().contains( key ) )
1520  return true;
1521  else if ( KStandardShortcut::paste().contains( key ) )
1522  return true;
1523  else if ( KStandardShortcut::cut().contains( key ) )
1524  return true;
1525  else if ( KStandardShortcut::undo().contains( key ) )
1526  return true;
1527  else if ( KStandardShortcut::redo().contains( key ) )
1528  return true;
1529  else if (KStandardShortcut::deleteWordBack().contains( key ))
1530  return true;
1531  else if (KStandardShortcut::deleteWordForward().contains( key ))
1532  return true;
1533  else if (KStandardShortcut::forwardWord().contains( key ))
1534  return true;
1535  else if (KStandardShortcut::backwardWord().contains( key ))
1536  return true;
1537  else if (KStandardShortcut::beginningOfLine().contains( key ))
1538  return true;
1539  else if (KStandardShortcut::endOfLine().contains( key ))
1540  return true;
1541 
1542  // Shortcut overrides for shortcuts that QLineEdit handles
1543  // but doesn't dare force as "stronger than kaction shortcuts"...
1544  else if (e->matches(QKeySequence::SelectAll)) {
1545  return true;
1546  }
1547 #ifdef Q_WS_X11
1548  else if (key == Qt::CTRL + Qt::Key_E || key == Qt::CTRL + Qt::Key_U)
1549  return true;
1550 #endif
1551 
1552  if (completionBox && completionBox->isVisible ())
1553  {
1554  const int key = e->key();
1555  const Qt::KeyboardModifiers modifiers = e->modifiers();
1556  if ((key == Qt::Key_Backtab || key == Qt::Key_Tab) &&
1557  (modifiers == Qt::NoModifier || (modifiers & Qt::ShiftModifier)))
1558  {
1559  return true;
1560  }
1561  }
1562 
1563 
1564  return false;
1565 }
1566 
1567 void KLineEdit::setCompletedItems( const QStringList& items, bool autoSuggest )
1568 {
1569  QString txt;
1570  if ( d->completionBox && d->completionBox->isVisible() ) {
1571  // The popup is visible already - do the matching on the initial string,
1572  // not on the currently selected one.
1573  txt = completionBox()->cancelledText();
1574  } else {
1575  txt = text();
1576  }
1577 
1578  if ( !items.isEmpty() &&
1579  !(items.count() == 1 && txt == items.first()) )
1580  {
1581  // create completion box if non-existent
1582  completionBox();
1583 
1584  if ( d->completionBox->isVisible() )
1585  {
1586  QListWidgetItem* currentItem = d->completionBox->currentItem();
1587 
1588  QString currentSelection;
1589  if ( currentItem != 0 ) {
1590  currentSelection = currentItem->text();
1591  }
1592 
1593  d->completionBox->setItems( items );
1594 
1595  const QList<QListWidgetItem*> matchedItems = d->completionBox->findItems(currentSelection, Qt::MatchExactly);
1596  QListWidgetItem* matchedItem = matchedItems.isEmpty() ? 0 : matchedItems.first();
1597 
1598  if (matchedItem) {
1599  const bool blocked = d->completionBox->blockSignals( true );
1600  d->completionBox->setCurrentItem( matchedItem );
1601  d->completionBox->blockSignals( blocked );
1602  } else {
1603  d->completionBox->setCurrentRow(-1);
1604  }
1605  }
1606  else // completion box not visible yet -> show it
1607  {
1608  if ( !txt.isEmpty() )
1609  d->completionBox->setCancelledText( txt );
1610  d->completionBox->setItems( items );
1611  d->completionBox->popup();
1612  }
1613 
1614  if ( d->autoSuggest && autoSuggest )
1615  {
1616  const int index = items.first().indexOf( txt );
1617  const QString newText = items.first().mid( index );
1618  setUserSelection(false); // can be removed? setCompletedText sets it anyway
1619  setCompletedText(newText,true);
1620  }
1621  }
1622  else
1623  {
1624  if ( d->completionBox && d->completionBox->isVisible() )
1625  d->completionBox->hide();
1626  }
1627 }
1628 
1629 KCompletionBox * KLineEdit::completionBox( bool create )
1630 {
1631  if ( create && !d->completionBox ) {
1632  setCompletionBox( new KCompletionBox( this ) );
1633  d->completionBox->setObjectName("completion box");
1634  d->completionBox->setFont(font());
1635  }
1636 
1637  return d->completionBox;
1638 }
1639 
1640 void KLineEdit::setCompletionObject( KCompletion* comp, bool hsig )
1641 {
1642  KCompletion *oldComp = compObj();
1643  if ( oldComp && handleSignals() )
1644  disconnect( oldComp, SIGNAL(matches(QStringList)),
1645  this, SLOT(setCompletedItems(QStringList)));
1646 
1647  if ( comp && hsig )
1648  connect( comp, SIGNAL(matches(QStringList)),
1649  this, SLOT(setCompletedItems(QStringList)));
1650 
1651  KCompletionBase::setCompletionObject( comp, hsig );
1652 }
1653 
1654 // QWidget::create() turns off mouse-Tracking which would break auto-hiding
1655 void KLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow )
1656 {
1657  QLineEdit::create( id, initializeWindow, destroyOldWindow );
1658  KCursor::setAutoHideCursor( this, true, true );
1659 }
1660 
1661 void KLineEdit::setUserSelection(bool userSelection)
1662 {
1663  //if !d->userSelection && userSelection we are accepting a completion,
1664  //so trigger an update
1665 
1666  if (!d->userSelection && userSelection)
1667  {
1668  d->_k_updateUserText(text());
1669  }
1670 
1671  QPalette p = palette();
1672 
1673  if (userSelection)
1674  {
1675  p.setColor(QPalette::Highlight, d->previousHighlightColor);
1676  p.setColor(QPalette::HighlightedText, d->previousHighlightedTextColor);
1677  }
1678  else
1679  {
1680  QColor color=p.color(QPalette::Disabled, QPalette::Text);
1681  p.setColor(QPalette::HighlightedText, color);
1682  color=p.color(QPalette::Active, QPalette::Base);
1683  p.setColor(QPalette::Highlight, color);
1684  }
1685 
1686  d->userSelection=userSelection;
1687  setPalette(p);
1688 }
1689 
1690 void KLineEdit::slotRestoreSelectionColors()
1691 {
1692  if (d->disableRestoreSelection)
1693  return;
1694 
1695  setUserSelection(true);
1696 }
1697 
1698 void KLineEdit::clear()
1699 {
1700  setText( QString() );
1701 }
1702 
1703 void KLineEdit::_k_slotCompletionBoxTextChanged( const QString& text )
1704 {
1705  if (!text.isEmpty())
1706  {
1707  setText( text );
1708  setModified(true);
1709  end( false ); // force cursor at end
1710  }
1711 }
1712 
1713 QString KLineEdit::originalText() const
1714 {
1715  if ( d->enableSqueezedText && isReadOnly() )
1716  return d->squeezedText;
1717 
1718  return text();
1719 }
1720 
1721 QString KLineEdit::userText() const
1722 {
1723  return d->userText;
1724 }
1725 
1726 bool KLineEdit::autoSuggest() const
1727 {
1728  return d->autoSuggest;
1729 }
1730 
1731 void KLineEdit::paintEvent( QPaintEvent *ev )
1732 {
1733  if (echoMode() == Password && d->threeStars) {
1734  // ### hack alert!
1735  // QLineEdit has currently no hooks to modify the displayed string.
1736  // When we call setText(), an update() is triggered and we get
1737  // into an infinite recursion.
1738  // Qt offers the setUpdatesEnabled() method, but when we re-enable
1739  // them, update() is triggered, and we get into the same recursion.
1740  // To work around this problem, we set/clear the internal Qt flag which
1741  // marks the updatesDisabled state manually.
1742  setAttribute(Qt::WA_UpdatesDisabled, true);
1743  blockSignals(true);
1744  const QString oldText = text();
1745  const bool isModifiedState = isModified(); // save modified state because setText resets it
1746  setText(oldText + oldText + oldText);
1747  QLineEdit::paintEvent(ev);
1748  setText(oldText);
1749  setModified(isModifiedState);
1750  blockSignals(false);
1751  setAttribute(Qt::WA_UpdatesDisabled, false);
1752  } else {
1753  QLineEdit::paintEvent( ev );
1754  }
1755 
1756  if (d->enableClickMsg && text().isEmpty()) {
1757  QPainter p(this);
1758  QFont f = font();
1759  f.setItalic(d->italicizePlaceholder);
1760  p.setFont(f);
1761 
1762  QColor color(palette().color(foregroundRole()));
1763  color.setAlphaF(0.5);
1764  p.setPen(color);
1765 
1766  QStyleOptionFrame opt;
1767  initStyleOption(&opt);
1768  QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
1769 
1770  // this is copied/adapted from QLineEdit::paintEvent
1771  const int verticalMargin(1);
1772  const int horizontalMargin(2);
1773 
1774  int left, top, right, bottom;
1775  getTextMargins( &left, &top, &right, &bottom );
1776  cr.adjust( left, top, -right, -bottom );
1777 
1778  p.setClipRect(cr);
1779 
1780  QFontMetrics fm = fontMetrics();
1781  Qt::Alignment va = alignment() & Qt::AlignVertical_Mask;
1782  int vscroll;
1783  switch (va & Qt::AlignVertical_Mask)
1784  {
1785  case Qt::AlignBottom:
1786  vscroll = cr.y() + cr.height() - fm.height() - verticalMargin;
1787  break;
1788 
1789  case Qt::AlignTop:
1790  vscroll = cr.y() + verticalMargin;
1791  break;
1792 
1793  default:
1794  vscroll = cr.y() + (cr.height() - fm.height() + 1) / 2;
1795  break;
1796 
1797  }
1798 
1799  QRect lineRect(cr.x() + horizontalMargin, vscroll, cr.width() - 2*horizontalMargin, fm.height());
1800  p.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, d->clickMessage);
1801 
1802  }
1803 }
1804 
1805 void KLineEdit::focusInEvent( QFocusEvent *ev )
1806 {
1807  QLineEdit::focusInEvent( ev );
1808 }
1809 
1810 void KLineEdit::focusOutEvent( QFocusEvent *ev )
1811 {
1812  QLineEdit::focusOutEvent( ev );
1813 }
1814 
1815 void KLineEdit::setClickMessage( const QString &msg )
1816 {
1817  d->enableClickMsg = !msg.isEmpty();
1818  d->clickMessage = msg;
1819  update();
1820 }
1821 
1822 #ifndef KDE_NO_DEPRECATED
1823 void KLineEdit::setContextMenuEnabled( bool showMenu )
1824 {
1825  QLineEdit::setContextMenuPolicy( showMenu ? Qt::DefaultContextMenu : Qt::NoContextMenu );
1826 }
1827 #endif
1828 
1829 #ifndef KDE_NO_DEPRECATED
1830 bool KLineEdit::isContextMenuEnabled() const
1831 {
1832  return ( contextMenuPolicy() == Qt::DefaultContextMenu );
1833 }
1834 #endif
1835 
1836 void KLineEdit::setPasswordMode(bool b)
1837 {
1838  if(b)
1839  {
1840  KConfigGroup cg(KGlobal::config(), "Passwords");
1841  const QString val = cg.readEntry("EchoMode", "OneStar");
1842  if (val == "NoEcho")
1843  setEchoMode(NoEcho);
1844  else {
1845  d->threeStars = (val == "ThreeStars");
1846  setEchoMode(Password);
1847  }
1848  }
1849  else
1850  {
1851  setEchoMode( Normal );
1852  }
1853 }
1854 
1855 bool KLineEdit::passwordMode() const
1856 {
1857  return echoMode() == NoEcho || echoMode() == Password;
1858 }
1859 
1860 void KLineEdit::doCompletion(const QString& txt)
1861 {
1862  if (emitSignals()) {
1863  emit completion(txt); // emit when requested...
1864  }
1865  d->completionRunning = true;
1866  if (handleSignals()) {
1867  makeCompletion(txt); // handle when requested...
1868  }
1869  d->completionRunning = false;
1870 }
1871 
1872 #include "klineedit.moc"
1873 #include "klineedit_p.moc"
QObject::className
const char * className() const
QLineEdit::initStyleOption
void initStyleOption(QStyleOptionFrame *option) const
QLineEdit::undo
void undo()
KIconLoader::DefaultState
The default state.
Definition: kiconloader.h:172
KShortcut::contains
bool contains(const QKeySequence &needle) const
Returns whether at least one of the key sequences is equal to needle.
Definition: kshortcut.cpp:149
kapp
#define kapp
Definition: kapplication.h:56
KLineEdit::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:1102
QEvent
QResizeEvent
QWidget
QKeyEvent::modifiers
Qt::KeyboardModifiers modifiers() const
KStandardShortcut::deleteWordForward
const KShortcut & deleteWordForward()
Delete a word forward from mouse/cursor position.
Definition: kstandardshortcut.cpp:339
KCompletionBase::getKeyBindings
KeyBindingMap getKeyBindings() const
Returns a key-binding map.
Definition: kcompletionbase.cpp:226
QEvent::type
Type type() const
QApplication::doubleClickInterval
int doubleClickInterval()
QWidget::palette
const QPalette & palette() const
QWidget::create
void create(WId window, bool initializeWindow, bool destroyOldWindow)
QSize::width
int width() const
setEditText
static void setEditText(KLineEdit *edit, const QString &text)
Definition: klineedit.cpp:1454
KLineEdit::doCompletion
void doCompletion(const QString &txt)
Do completion now.
Definition: klineedit.cpp:1860
kdebug.h
QDropEvent::mimeData
const QMimeData * mimeData() const
QActionGroup
kapplication.h
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QLineEdit::text
QString text() const
KStandardShortcut::forwardWord
const KShortcut & forwardWord()
ForwardWord.
Definition: kstandardshortcut.cpp:354
KLineEdit::aboutToShowContextMenu
void aboutToShowContextMenu(QMenu *menu)
Emitted before the context menu is displayed.
KStandardShortcut::SubstringCompletion
Definition: kstandardshortcut.h:82
KLineEdit::create
virtual void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Reimplemented for internal reasons, the API is not affected.
Definition: klineedit.cpp:1655
KCompletionBox
A helper widget for "completion-widgets" (KLineEdit, KComboBox))
Definition: kcompletionbox.h:43
KLineEdit::setUrl
void setUrl(const KUrl &url)
Sets url into the lineedit.
Definition: klineedit.cpp:1426
QWidget::addActions
void addActions(QList< QAction * > actions)
kauthorized.h
KLineEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
Re-implemented for internal reasons.
Definition: klineedit.cpp:1180
KStandardShortcut::redo
const KShortcut & redo()
Redo.
Definition: kstandardshortcut.cpp:341
QLineEdit::event
virtual bool event(QEvent *e)
QLineEdit::paste
void paste()
kcompletionbox.h
QFont
QWidget::style
QStyle * style() const
KStandardShortcut::shortcut
const KShortcut & shortcut(StandardShortcut id)
Returns the keybinding for accel.
Definition: kstandardshortcut.cpp:285
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
KStandardShortcut::undo
const KShortcut & undo()
Undo last operation.
Definition: kstandardshortcut.cpp:340
KLineEdit::setCompletionObject
virtual void setCompletionObject(KCompletion *, bool hsig=true)
Reimplemented for internal reasons, the API is not affected.
Definition: klineedit.cpp:1640
kconfig.h
QWidget::childAt
QWidget * childAt(int x, int y) const
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QList::at
const T & at(int i) const
QMap< KGlobalSettings::Completion, bool >
QSize::rwidth
int & rwidth()
KLineEdit::setCompletedText
virtual void setCompletedText(const QString &)
See KCompletionBase::setCompletedText.
Definition: klineedit.cpp:451
QMenu::addAction
void addAction(QAction *action)
KLineEdit::userText
QString userText() const
Returns the text as given by the user (i.e.
Definition: klineedit.cpp:1721
KCompletionBase::NextCompletionMatch
Switch to next completion (by default Ctrl-Down).
Definition: kcompletion.h:665
QLineEdit::hasSelectedText
bool hasSelectedText() const
QListWidgetItem
KLineEdit::setCompletionBox
void setCompletionBox(KCompletionBox *box)
Set the completion-box to be used in completion mode KGlobalSettings::CompletionPopup.
Definition: klineedit.cpp:1431
KLineEdit::focusOutEvent
virtual void focusOutEvent(QFocusEvent *ev)
Definition: klineedit.cpp:1810
QLineEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
QObject::metaObject
virtual const QMetaObject * metaObject() const
KLineEdit::isSqueezedTextEnabled
bool isSqueezedTextEnabled() const
Returns true if text squeezing is enabled.
Definition: klineedit.cpp:564
KLineEdit::trapReturnKey
bool trapReturnKey() const
Definition: klineedit.cpp:1421
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QLineEdit::echoMode
EchoMode echoMode() const
QLineEdit::textChanged
void textChanged(const QString &text)
KLineEdit::autoSuggest
bool autoSuggest() const
Whether in current state text should be auto-suggested.
Definition: klineedit.cpp:1726
QRect::height
int height() const
QActionGroup::addAction
QAction * addAction(QAction *action)
QRect::x
int x() const
QRect::y
int y() const
KCompletionBase::compObj
KCompletion * compObj() const
Returns a pointer to the completion object.
Definition: kcompletionbase.cpp:220
KLineEdit::clickMessage
QString clickMessage() const
QFontMetrics
QMouseEvent
KLineEdit::textRotation
void textRotation(KCompletionBase::KeyBindingType)
Emitted when the text rotation key-bindings are pressed.
QString::remove
QString & remove(int position, int n)
KCompletionBase::TextCompletion
Text completion (by default Ctrl-E).
Definition: kcompletion.h:657
KGlobalSettings::self
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
Definition: kglobalsettings.cpp:188
Qt::Alignment
typedef Alignment
klocale.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
KLineEdit::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:1261
QContextMenuEvent::globalPos
const QPoint & globalPos() const
QToolTip::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
QWidget::foregroundRole
QPalette::ColorRole foregroundRole() const
QLineEdit::selectedText
QString selectedText() const
QLineEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QWidget::update
void update()
KLineEdit::completionBox
KCompletionBox * completionBox(bool create=true)
Definition: klineedit.cpp:1629
KUrl
QLineEdit::cursorWordBackward
void cursorWordBackward(bool mark)
KCursor::autoHideEventFilter
static void autoHideEventFilter(QObject *, QEvent *)
KCursor has to install an eventFilter over the widget you want to auto-hide.
Definition: kcursor.cpp:208
KLineEdit::clear
virtual void clear()
Reimplemented to workaround a buggy QLineEdit::clear() (changing the clipboard to the text we just ha...
Definition: klineedit.cpp:1698
i18nc
QString i18nc(const char *ctxt, const char *text)
QLineEdit::isModified
bool isModified() const
KLineEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:702
config
KSharedConfigPtr config()
KLineEdit::userCancelled
void userCancelled(const QString &cancelText)
Resets the current displayed text.
Definition: klineedit.cpp:1465
QList::indexOf
int indexOf(const T &value, int from) const
KShortcut
Represents a keyboard shortcut.
Definition: kshortcut.h:57
QLineEdit::isReadOnly
bool isReadOnly() const
KLineEdit::clearButtonClicked
void clearButtonClicked()
Emitted when the user clicked on the clear button.
KLineEdit::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:1113
kcursor.h
QWidget::size
QSize size() const
KLineEdit::setContextMenuEnabled
virtual void setContextMenuEnabled(bool showMenu)
Enables/disables the popup (context) menu.
Definition: klineedit.cpp:1823
KLineEdit::setUrlDropsEnabled
void setUrlDropsEnabled(bool enable)
Enables/Disables handling of URL drops.
Definition: klineedit.cpp:1406
QStyleOption
QChar::isPrint
bool isPrint() const
QRect
QPainter::setFont
void setFont(const QFont &font)
QWidget::insertAction
void insertAction(QAction *before, QAction *action)
QList::count
int count(const T &value) const
KLineEdit::dropEvent
virtual void dropEvent(QDropEvent *)
Re-implemented to handle URI drops.
Definition: klineedit.cpp:1321
QEvent::ignore
void ignore()
KCompletionBase::SubstringCompletion
Substring completion (by default Ctrl-T).
Definition: kcompletion.h:669
KLineEdit::substringCompletion
void substringCompletion(const QString &)
Emitted when the shortcut for substring completion is pressed.
KCompletionBase::PrevCompletionMatch
Switch to previous completion (by default Ctrl-Up).
Definition: kcompletion.h:661
KLineEdit::completion
void completion(const QString &)
Emitted when the completion key is pressed.
QWidget::layoutDirection
Qt::LayoutDirection layoutDirection() const
KStandardShortcut::PrevCompletion
Definition: kstandardshortcut.h:82
QApplication::clipboard
QClipboard * clipboard()
KUrl::List::fromMimeData
static KUrl::List fromMimeData(const QMimeData *mimeData, KUrl::MetaDataMap *metaData=0)
kmenu.h
KLineEdit::passwordMode
bool passwordMode() const
QContextMenuEvent
QStyle
QPainter::setPen
void setPen(const QColor &color)
KLineEdit::urlDropsEnabled
bool urlDropsEnabled() const
Returns true when decoded URL drops are enabled.
KCompletion::allMatches
QStringList allMatches()
Returns a list of all items matching the last completed string.
Definition: kcompletion.cpp:339
QMouseEvent::button
Qt::MouseButton button() const
KStandardShortcut::endOfLine
const KShortcut & endOfLine()
Goto end of current line.
Definition: kstandardshortcut.cpp:350
CTRL
#define CTRL(x)
Definition: kstandardshortcut.cpp:70
QWidget::backgroundRole
QPalette::ColorRole backgroundRole() const
QDropEvent
QList::isEmpty
bool isEmpty() const
QPainter
QString::isEmpty
bool isEmpty() const
KCompletionBase::setCompletionMode
virtual void setCompletionMode(KGlobalSettings::Completion mode)
Sets the type of completion to be used.
Definition: kcompletionbase.cpp:167
QString::trimmed
QString trimmed() const
KCompletion
A generic class for completing QStrings.
Definition: kcompletion.h:130
KStandardAction::SelectAll
Definition: kstandardaction.h:133
KGlobalSettings::CompletionAuto
Text is automatically filled in whenever possible.
Definition: kglobalsettings.h:187
KLineEdit::setUserSelection
void setUserSelection(bool userSelection)
Sets the widget in userSelection mode or in automatic completion selection mode.
Definition: klineedit.cpp:1661
QKeyEvent::text
QString text() const
KLineEdit::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:692
KStandardShortcut::backwardWord
const KShortcut & backwardWord()
BackwardWord.
Definition: kstandardshortcut.cpp:353
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KStandardShortcut::beginningOfLine
const KShortcut & beginningOfLine()
Goto beginning of current line.
Definition: kstandardshortcut.cpp:349
QWidget::pos
QPoint pos() const
KStandardAction::clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
Clear the content of the focus widget.
Definition: kstandardaction.cpp:314
KLineEdit::setSqueezedTextEnabled
void setSqueezedTextEnabled(bool enable)
Enable text squeezing whenever the supplied text is too long.
Definition: klineedit.cpp:559
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
KLineEdit::~KLineEdit
virtual ~KLineEdit()
Destructor.
Definition: klineedit.cpp:245
QLineEdit::focusOutEvent
virtual void focusOutEvent(QFocusEvent *e)
KCompletionBase::handleSignals
bool handleSignals() const
Returns true if the object handles the signals.
Definition: kcompletionbase.cpp:157
QList::first
T & first()
QMenu::addSeparator
QAction * addSeparator()
QString
kstandardaction.h
QList< QAction * >
QLineEdit::selectAll
void selectAll()
QColor
KLineEdit::setCompletionMode
virtual void setCompletionMode(KGlobalSettings::Completion mode)
Re-implemented from KCompletionBase for internal reasons.
Definition: klineedit.cpp:400
KLineEdit::setSqueezedText
void setSqueezedText(const QString &text)
Squeezes text into the line edit.
Definition: klineedit.cpp:553
QApplication::palette
QPalette palette()
QMenu::exec
QAction * exec()
QLineEdit::paintEvent
virtual void paintEvent(QPaintEvent *)
QLineEdit::backspace
void backspace()
QKeyEvent::matches
bool matches(QKeySequence::StandardKey key) const
QLineEdit::redo
void redo()
QStringList
KStandardShortcut::copy
const KShortcut & copy()
Copy selected area into the clipboard.
Definition: kstandardshortcut.cpp:335
KLineEdit::completionBoxActivated
void completionBoxActivated(const QString &)
Emitted whenever the completion box is activated.
QString::right
QString right(int n) const
QRect::adjusted
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const
QLineEdit::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
QLineEdit::selectionStart
int selectionStart() const
KLineEdit::originalText
QString originalText() const
Returns the original text if text squeezing is enabled.
Definition: klineedit.cpp:1713
kaction.h
QList::end
iterator end()
KCursor::setAutoHideCursor
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
Sets auto-hiding the cursor for widget w.
Definition: kcursor.cpp:202
kstandardshortcut.h
QKeyEvent::key
int key() const
QLineEdit::textEdited
void textEdited(const QString &text)
QLineEdit::getTextMargins
void getTextMargins(int *left, int *top, int *right, int *bottom) const
QMenu
QEvent::accept
void accept()
QLineEdit::insert
void insert(const QString &newText)
QObject::blockSignals
bool blockSignals(bool block)
QSize
KLineEdit::setTrapReturnKey
void setTrapReturnKey(bool trap)
By default, KLineEdit recognizes Key_Return and Key_Enter and emits the returnPressed() signals...
Definition: klineedit.cpp:1416
QWidget::font
const QFont & font() const
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
QLineEdit::alignment
Qt::Alignment alignment() const
KCompletion::nextMatch
QString nextMatch()
Returns the next item from the matching-items-list.
Definition: kcompletion.cpp:404
KLineEdit::clearButtonUsedSize
QSize clearButtonUsedSize() const
Definition: klineedit.cpp:315
QFont::setItalic
void setItalic(bool enable)
KLineEdit::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:1144
KStandardShortcut::cut
const KShortcut & cut()
Cut selected area and store it in the clipboard.
Definition: kstandardshortcut.cpp:334
KGlobalSettings::CompletionPopup
Lists all possible matches in a popup list-box to choose from.
Definition: kglobalsettings.h:199
KStandardShortcut::TextCompletion
Definition: kstandardshortcut.h:82
kicontheme.h
KLineEdit::isContextMenuEnabled
bool isContextMenuEnabled() const
Returns true when the context menu is enabled.
Definition: klineedit.cpp:1830
KConfigGroup
QLineEdit::returnPressed
void returnPressed()
QClipboard::text
QString text(Mode mode) const
QString::unicode
const QChar * unicode() const
KUrl::List
QKeyEvent
KLineEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *ev)
Definition: klineedit.cpp:1805
KGlobalSettings::CompletionMan
Same as automatic except shortest match is used for completion.
Definition: kglobalsettings.h:191
QLineEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *e)
QActionGroup::actions
QList< QAction * > actions() const
QLineEdit::end
void end(bool mark)
KCompletion::makeCompletion
virtual QString makeCompletion(const QString &string)
Attempts to find an item in the list of available completions, that begins with string.
Definition: kcompletion.cpp:229
KLineEdit
An enhanced QLineEdit widget for inputting text.
Definition: klineedit.h:149
QLineEdit::cut
void cut()
QRect::width
int width() const
QPainter::setClipRect
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
QString::mid
QString mid(int position, int n) const
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QLineEdit::del
void del()
KStandardShortcut::deleteWordBack
const KShortcut & deleteWordBack()
Delete a word back from mouse/cursor position.
Definition: kstandardshortcut.cpp:338
KGlobalSettings::CompletionNone
No completion is used.
Definition: kglobalsettings.h:183
QLatin1String
KLineEdit::KLineEdit
KLineEdit(const QString &string, QWidget *parent=0)
Constructs a KLineEdit object with a default text, a parent, and a name.
Definition: klineedit.cpp:232
KStandardShortcut::pasteSelection
const KShortcut & pasteSelection()
Paste the selection at mouse/cursor position.
Definition: kstandardshortcut.cpp:337
QLineEdit::home
void home(bool mark)
QLineEdit::cursorWordForward
void cursorWordForward(bool mark)
KStandardShortcut::NextCompletion
Definition: kstandardshortcut.h:82
KLineEdit::copy
virtual void copy() const
Reimplemented for internal reasons, the API is not affected.
Definition: klineedit.cpp:657
QLineEdit::selectionChanged
void selectionChanged()
QMenu::addMenu
QAction * addMenu(QMenu *menu)
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
QList< KUrl >::ConstIterator
typedef ConstIterator
QFontMetrics::height
int height() const
QSize::height
int height() const
KStandardAction::create
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.
Definition: kstandardaction.cpp:82
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
KLineEdit::isClearButtonShown
bool isClearButtonShown() const
Definition: klineedit.cpp:310
KGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the KCompletion class.
Definition: kglobalsettings.h:179
KCompletionBase::setCompletionObject
virtual void setCompletionObject(KCompletion *compObj, bool hsig=true)
Sets up the completion object to be used.
Definition: kcompletionbase.cpp:109
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
Definition: kiconloader.cpp:1553
KLineEdit::event
virtual bool event(QEvent *)
Re-implemented for internal reasons.
Definition: klineedit.cpp:1358
KLineEdit::paintEvent
virtual void paintEvent(QPaintEvent *ev)
Definition: klineedit.cpp:1731
QString::length
int length() const
KCompletionBase::emitSignals
bool emitSignals() const
Returns true if the object emits the signals.
Definition: kcompletionbase.cpp:162
KCompletionBase::KeyBindingType
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
Definition: kcompletion.h:653
KLineEdit::setPasswordMode
void setPasswordMode(bool b=true)
set the line edit in password mode.
Definition: klineedit.cpp:1836
QWeakPointer< KLineEditStyle >
QString::left
QString left(int n) const
KAuthorized::authorize
bool authorize(const QString &genericAction)
KLineEdit::completionModeChanged
void completionModeChanged(KGlobalSettings::Completion)
Emitted when the user changed the completion mode by using the popupmenu.
QColor::setAlphaF
void setAlphaF(qreal alpha)
KLineEdit::setClearButtonShown
void setClearButtonShown(bool show)
This makes the line edit display an icon on one side of the line edit which, when clicked...
Definition: klineedit.cpp:284
KLineEdit::KLineEditStyle
friend class KLineEditStyle
Definition: klineedit.h:152
QClipboard::setText
void setText(const QString &text, Mode mode)
klineedit.h
QLineEdit
KGlobalSettings::CompletionShell
Complete text much in the same way as a typical *nix shell would.
Definition: kglobalsettings.h:195
KLineEdit::setClickMessage
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...
Definition: klineedit.cpp:1815
QStyle::subElementRect
virtual QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const =0
QMouseEvent::pos
const QPoint & pos() const
QWidget::setToolTip
void setToolTip(const QString &)
KGlobalSettings::graphicEffectsLevel
static GraphicEffects graphicEffectsLevel()
This function determines the desired level of effects on the GUI.
Definition: kglobalsettings.cpp:782
QPaintEvent
QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
QLineEdit::copy
void copy() const
KGlobalSettings::completionMode
static Completion completionMode()
Returns the preferred completion mode setting.
Definition: kglobalsettings.cpp:267
QWidget::setBackgroundRole
void setBackgroundRole(QPalette::ColorRole role)
QLineEdit::setCursorPosition
void setCursorPosition(int)
kicon.h
KIconTheme::assignIconsToContextMenu
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
Definition: kicontheme.cpp:599
KLineEdit::makeCompletion
virtual void makeCompletion(const QString &)
Completes the remaining text with a matching one from a given list.
Definition: klineedit.cpp:482
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QWidget::actions
QList< QAction * > actions() const
KLineEdit::setReadOnly
virtual void setReadOnly(bool)
Sets the lineedit to read-only.
Definition: klineedit.cpp:521
KLineEdit::setText
virtual void setText(const QString &)
Re-implemented to enable text squeezing.
Definition: klineedit.cpp:569
QWidget::setStyle
void setStyle(QStyle *style)
QStyleOptionFrame
KLineEdit::setCompletedItems
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...
Definition: klineedit.cpp:1567
QLineEdit::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *e)
QLineEdit::deselect
void deselect()
QString::data
QChar * data()
KIconTheme::TextEditor
Definition: kicontheme.h:202
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
QFocusEvent
QDropEvent::accept
void accept(bool accept)
QList::begin
iterator begin()
KGlobalSettings::SimpleAnimationEffects
GUI with simple animations enabled.
Definition: kglobalsettings.h:467
KUrl::prettyUrl
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
QAction::setEnabled
void setEnabled(bool)
QListWidgetItem::text
QString text() const
KCompletionBase::completionMode
KGlobalSettings::Completion completionMode() const
Returns the current completion mode.
Definition: kcompletionbase.cpp:181
KCompletion::previousMatch
QString previousMatch()
Returns the next item from the matching-items-list.
Definition: kcompletion.cpp:442
KLineEdit::rotateText
void rotateText(KCompletionBase::KeyBindingType type)
Iterates through all possible matches of the completed text or the history list.
Definition: klineedit.cpp:461
QPalette
KGlobalSettings::CompletionPopupAuto
Lists all possible matches in a popup list-box to choose from, and automatically fill the result when...
Definition: kglobalsettings.h:204
QLineEdit::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
KLineEdit::setCompletionModeDisabled
void setCompletionModeDisabled(KGlobalSettings::Completion mode, bool disable=true)
Disables completion modes by makeing them non-checkable.
Definition: klineedit.cpp:427
kconfiggroup.h
KCompletionBox::cancelledText
QString cancelledText
Definition: kcompletionbox.h:47
KStandardShortcut::paste
const KShortcut & paste()
Paste contents of clipboard at mouse/cursor position.
Definition: kstandardshortcut.cpp:336
QLineEdit::setSelection
void setSelection(int start, int length)
QTimer::singleShot
singleShot
QLineEdit::displayText
QString displayText() const
Qt::KeyboardModifiers
typedef KeyboardModifiers
QLineEdit::dropEvent
virtual void dropEvent(QDropEvent *e)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal