void QLineEdit::mouseReleaseEvent( QMouseEvent * e ) { if ( d->inDoubleClick ) { d->inDoubleClick = FALSE; return; } #if defined(_WS_X11_) if ( hasMarkedText() && echoMode() == Normal ) copyText(); #else if ( style() == MotifStyle && hasMarkedText() && echoMode() == Normal ) copyText(); #endif if ( dragScrolling ) dragScrolling = FALSE; if ( e->button() != LeftButton ) return; int margin = frame() ? 4 : 2; if ( !QRect( margin, margin, width() - 2*margin, height() - 2*margin ).contains( e->pos() ) ) return; int mousePos = offset + xPosToCursorPos( &tbuf[(int)offset], fontMetrics(), e->pos().x() - margin, width() - margin - margin ); int m1 = markDrag; newMark( mousePos, FALSE ); repaintArea( m1, mousePos ); }
void LineEditWidget::draw() { Rectanglei pos = rule().recti(); // Temporary buffer for drawing. TextCanvas buf(pos.size()); TextCanvas::Char::Attribs attr = (hasFocus()? TextCanvas::Char::Reverse : TextCanvas::Char::DefaultAttributes); buf.clear(TextCanvas::Char(' ', attr)); buf.drawText(Vector2i(0, 0), prompt(), attr | TextCanvas::Char::Bold); // Underline the suggestion for completion. if(isSuggestingCompletion()) { buf.setRichFormatRange(TextCanvas::Char::Underline, completionRange()); } // Echo mode determines what we actually draw. String txt = text(); if(echoMode() == PasswordEchoMode) { txt = String(txt.size(), '*'); } buf.drawWrappedText(Vector2i(prompt().size(), 0), txt, lineWraps(), attr); targetCanvas().draw(buf, pos.topLeft); }
void QLineEdit::markWord( int pos ) { int i = pos - 1; while ( i >= 0 && isprint(tbuf.at(i)) && !isspace(tbuf.at(i)) ) i--; i++; markAnchor = i; int lim = tbuf.length(); i = pos; while ( i < lim && isprint(tbuf.at(i)) && !isspace(tbuf.at(i)) ) i++; markDrag = i; int maxVis = lastCharVisible(); int markBegin = minMark(); int markEnd = maxMark(); if ( markBegin < offset || markBegin > maxVis ) { if ( markEnd >= offset && markEnd <= maxVis ) { cursorPos = markEnd; } else { offset = markBegin; cursorPos = markBegin; } } else { cursorPos = markBegin; } if ( style() == MotifStyle && echoMode() == Normal ) copyText(); d->pmDirty = TRUE; }
void KLineEdit::setCompletionMode( KGlobalSettings::Completion mode ) { KGlobalSettings::Completion oldMode = completionMode(); if ( oldMode != mode && (oldMode == KGlobalSettings::CompletionPopup || oldMode == KGlobalSettings::CompletionPopupAuto ) && d->completionBox && d->completionBox->isVisible() ) d->completionBox->hide(); // If the widgets echo mode is not Normal, no completion // feature will be enabled even if one is requested. if ( echoMode() != QLineEdit::Normal ) mode = KGlobalSettings::CompletionNone; // Override the request. if ( kapp && !kapp->authorize("lineedit_text_completion") ) mode = KGlobalSettings::CompletionNone; if ( mode == KGlobalSettings::CompletionPopupAuto || mode == KGlobalSettings::CompletionAuto || mode == KGlobalSettings::CompletionMan ) d->autoSuggest = true; else d->autoSuggest = false; KCompletionBase::setCompletionMode( mode ); }
void QLineEdit::newMark( int pos, bool copy ) { if ( markDrag != pos || cursorPos != pos ) d->pmDirty = TRUE; markDrag = pos; cursorPos = pos; if ( copy && style() == MotifStyle && echoMode() == Normal ) copyText(); // ### ???????????? }
void QDeclarativeTextInput::setEchoMode(QDeclarativeTextInput::EchoMode echo) { Q_D(QDeclarativeTextInput); if (echoMode() == echo) return; Qt::InputMethodHints imHints = inputMethodHints(); if (echo == Password || echo == NoEcho) imHints |= Qt::ImhHiddenText; else imHints &= ~Qt::ImhHiddenText; if (echo != Normal) imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); else imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); setInputMethodHints(imHints); d->control->setEchoMode((uint)echo); update(); emit echoModeChanged(echoMode()); }
void QLineEdit::paintEvent( QPaintEvent *e ) { if ( !d->pm || d->pmDirty ) { if ( !d->pm ) d->pm = new QPixmap( size() ); QPainter p( d->pm, this ); QColorGroup g = colorGroup(); QColor bg = isEnabled() ? g.base() : g.background(); QFontMetrics fm = fontMetrics(); int markBegin = minMark(); int markEnd = maxMark(); int margin = frame() ? 2 : 0; if ( frame() ) { QBrush fill( bg ); qDrawWinPanel( &p, 0, 0, width(), height(), g, TRUE, &fill ); } else { p.fillRect( 0, 0, width(), height(), bg ); } QString displayText; switch( echoMode() ) { case Normal: displayText = tbuf.mid( offset, tbuf.length() ); break; case NoEcho: displayText = ""; break; case Password: displayText.fill( '*', tbuf.length() - offset ); break; } int ypos = height() - margin - fm.descent() - 1 - (height() - 2*margin - fm.height())/2; if ( !displayText.isEmpty() ) { int charsVisible = lastCharVisible() - offset; if ( displayText[ charsVisible ] != '\0' ) charsVisible++; int mark1,mark2; if ( markBegin > offset ) { if ( markBegin < offset + charsVisible ) mark1 = markBegin - offset; else mark1 = charsVisible; } else { mark1 = 0; } if ( markEnd > offset ) { if ( markEnd < offset + charsVisible ) mark2 = markEnd - offset; else mark2 = charsVisible; } else { mark2 = 0; } // display code comes here - a bit yucky but it works if ( mark1 != mark2 ) { QString marked( displayText.mid( mark1, mark2 - mark1 ) ); int xpos1 = margin + 2 + fm.width( displayText, mark1 ); int xpos2 = xpos1 + fm.width( marked ) - 1; p.fillRect( xpos1, ypos - fm.ascent(), xpos2 - xpos1, fm.height(), style() == WindowsStyle ? QApplication::winStyleHighlightColor() : g.text() ); p.setPen( style() == WindowsStyle ? white : g.base() ); p.drawText( xpos1, ypos, marked ); } p.setPen( g.text() ); if ( mark1 != 0 ) p.drawText( margin + 2, ypos, displayText, mark1 ); if ( mark2 != charsVisible ) { QString rest( displayText.mid( mark2, charsVisible - mark2 ) ); p.drawText( margin + 2 + fm.width( displayText.left( mark2) ), ypos, rest ); } } p.setPen( g.foreground() ); int curXPos = margin + 2; if ( echoMode() != NoEcho ) curXPos += offset > cursorPos ? -1 : // ?: for scrolling case fm.width( displayText, cursorPos - offset ) - 1; int curYPos = ypos - fm.ascent(); d->cursorRepaintRect.setRect( curXPos-2, curYPos, 5, fm.height() ); d->pmDirty = FALSE; } bitBlt( this, e->rect().topLeft(), d->pm, e->rect() ); if ( hasFocus() ) { if ( cursorOn && d->cursorRepaintRect.intersects( e->rect() ) ) { QPainter p( this ); int curYTop = d->cursorRepaintRect.y(); int curYBot = d->cursorRepaintRect.bottom(); int curXPos = d->cursorRepaintRect.x() + 2; p.drawLine( curXPos, curYTop, curXPos, curYBot ); if ( style() != WindowsStyle ) { p.drawLine( curXPos - 2, curYTop, curXPos + 2, curYTop ); p.drawLine( curXPos - 2, curYBot, curXPos + 2, curYBot ); } } } else { delete d->pm; d->pm = 0; } }
void QLineEdit::keyPressEvent( QKeyEvent *e ) { if ( e->key() == Key_Enter || e->key() == Key_Return ) { QValidator * v = validator(); if ( !v || v->validate( tbuf, cursorPos ) == QValidator::Acceptable ) { emit returnPressed(); } else if ( v ) { v->fixup( tbuf ); if ( v->validate( tbuf, cursorPos ) == QValidator::Acceptable ) emit returnPressed(); } // ### 2.0 must fix this e->ignore(); return; } if ( e->ascii() >= 32 && e->key() != Key_Delete && e->key() != Key_Backspace ) { QString t( 2 ); t[0] = e->ascii(); t[1] = '\0'; insert( t ); return; } int unknown = 0; if ( e->state() & ControlButton ) { switch ( e->key() ) { case Key_A: case Key_Left: home( e->state() & ShiftButton ); break; case Key_B: cursorLeft( e->state() & ShiftButton ); break; case Key_C: if ( hasMarkedText() && echoMode() == Normal ) copyText(); break; case Key_D: del(); break; case Key_E: case Key_Right: end( e->state() & ShiftButton ); break; case Key_F: cursorRight( e->state() & ShiftButton ); break; case Key_H: backspace(); break; case Key_K: if ( cursorPos < (int)tbuf.length() ) { QString t( tbuf ); t.detach(); // ### 2.0 t.truncate( cursorPos ); validateAndSet( t, cursorPos, cursorPos, cursorPos ); } break; case Key_V: insert( QApplication::clipboard()->text() ); case Key_X: if ( hasMarkedText() && echoMode() == Normal ) { copyText(); del(); } break; default: unknown++; } } else { switch ( e->key() ) { case Key_Left: cursorLeft( e->state() & ShiftButton ); break; case Key_Right: cursorRight( e->state() & ShiftButton ); break; case Key_Backspace: backspace(); break; case Key_Home: home( e->state() & ShiftButton ); break; case Key_End: end( e->state() & ShiftButton ); break; case Key_Delete: del(); break; default: unknown++; } } if ( unknown ) { // unknown key e->ignore(); return; } }
void KLineEdit::keyPressEvent( QKeyEvent *e ) { KKey key( e ); if ( KStdAccel::copy().contains( key ) ) { copy(); return; } else if ( KStdAccel::paste().contains( key ) ) { paste(); return; } else if ( KStdAccel::pasteSelection().contains( key ) ) { QString text = QApplication::clipboard()->text( QClipboard::Selection); insert( text ); deselect(); return; } else if ( KStdAccel::cut().contains( key ) ) { cut(); return; } else if ( KStdAccel::undo().contains( key ) ) { undo(); return; } else if ( KStdAccel::redo().contains( key ) ) { redo(); return; } else if ( KStdAccel::deleteWordBack().contains( key ) ) { cursorWordBackward(true); if ( hasSelectedText() ) del(); e->accept(); return; } else if ( KStdAccel::deleteWordForward().contains( key ) ) { // Workaround for QT bug where cursorWordForward(true); if ( hasSelectedText() ) del(); e->accept(); return; } else if ( KStdAccel::backwardWord().contains( key ) ) { cursorWordBackward(false); e->accept(); return; } else if ( KStdAccel::forwardWord().contains( key ) ) { cursorWordForward(false); e->accept(); return; } else if ( KStdAccel::beginningOfLine().contains( key ) ) { home(false); e->accept(); return; } else if ( KStdAccel::endOfLine().contains( key ) ) { end(false); e->accept(); return; } // Filter key-events if EchoMode is normal and // completion mode is not set to CompletionNone if ( echoMode() == QLineEdit::Normal && completionMode() != KGlobalSettings::CompletionNone ) { KeyBindingMap keys = getKeyBindings(); KGlobalSettings::Completion mode = completionMode(); bool noModifier = (e->state() == NoButton || e->state() == ShiftButton || e->state() == Keypad); if ( (mode == KGlobalSettings::CompletionAuto || mode == KGlobalSettings::CompletionPopupAuto || mode == KGlobalSettings::CompletionMan) && noModifier ) { if ( !d->userSelection && hasSelectedText() && ( e->key() == Key_Right || e->key() == Key_Left ) && e->state()==NoButton ) { QString old_txt = text(); d->disableRestoreSelection = true; int start,end; getSelection(&start, &end); deselect(); QLineEdit::keyPressEvent ( e ); int cPosition=cursorPosition(); if (e->key() ==Key_Right && cPosition > start ) validateAndSet(old_txt, cPosition, cPosition, old_txt.length()); else validateAndSet(old_txt, cPosition, start, old_txt.length()); d->disableRestoreSelection = false; return; } if ( e->key() == Key_Escape ) { if (hasSelectedText() && !d->userSelection ) { del(); setUserSelection(true); } // Don't swallow the Escape press event for the case // of dialogs, which have Escape associated to Cancel e->ignore(); return; } } if ( (mode == KGlobalSettings::CompletionAuto || mode == KGlobalSettings::CompletionMan) && noModifier ) { QString keycode = e->text(); if ( !keycode.isEmpty() && (keycode.unicode()->isPrint() || e->key() == Key_Backspace || e->key() == Key_Delete ) ) { bool hasUserSelection=d->userSelection; bool hadSelection=hasSelectedText(); bool cursorNotAtEnd=false; int start,end; getSelection(&start, &end); int cPos = cursorPosition(); // When moving the cursor, we want to keep the autocompletion as an // autocompletion, so we want to process events at the cursor position // as if there was no selection. After processing the key event, we // can set the new autocompletion again. if ( hadSelection && !hasUserSelection && start>cPos ) { del(); setCursorPosition(cPos); cursorNotAtEnd=true; } d->disableRestoreSelection = true; QLineEdit::keyPressEvent ( e ); d->disableRestoreSelection = false; QString txt = text(); int len = txt.length(); if ( !hasSelectedText() && len /*&& cursorPosition() == len */) { if ( e->key() == Key_Backspace ) { if ( hadSelection && !hasUserSelection && !cursorNotAtEnd ) { backspace(); txt = text(); len = txt.length(); } if ( !d->backspacePerformsCompletion || !len ) d->autoSuggest = false; } if (e->key() == Key_Delete ) d->autoSuggest=false; if ( emitSignals() ) emit completion( txt ); if ( handleSignals() ) makeCompletion( txt ); if( (e->key() == Key_Backspace || e->key() == Key_Delete) ) d->autoSuggest=true; e->accept(); } return; } } else if (( mode == KGlobalSettings::CompletionPopup || mode == KGlobalSettings::CompletionPopupAuto ) && noModifier && !e->text().isEmpty() ) { QString old_txt = text(); bool hasUserSelection=d->userSelection; bool hadSelection=hasSelectedText(); bool cursorNotAtEnd=false; int start,end; getSelection(&start, &end); int cPos = cursorPosition(); QString keycode = e->text(); // When moving the cursor, we want to keep the autocompletion as an // autocompletion, so we want to process events at the cursor position // as if there was no selection. After processing the key event, we // can set the new autocompletion again. if (hadSelection && !hasUserSelection && start>cPos && ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) || e->key() == Key_Backspace || e->key() == Key_Delete ) ) { del(); setCursorPosition(cPos); cursorNotAtEnd=true; } uint selectedLength=selectedText().length(); d->disableRestoreSelection = true; QLineEdit::keyPressEvent ( e ); d->disableRestoreSelection = false; if (( selectedLength != selectedText().length() ) && !hasUserSelection ) slotRestoreSelectionColors(); // and set userSelection to true QString txt = text(); int len = txt.length(); if ( txt != old_txt && len/* && ( cursorPosition() == len || force )*/ && ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) || e->key() == Key_Backspace || e->key() == Key_Delete) ) { if ( e->key() == Key_Backspace ) { if ( hadSelection && !hasUserSelection && !cursorNotAtEnd ) { backspace(); txt = text(); len = txt.length(); } if ( !d->backspacePerformsCompletion ) d->autoSuggest = false; } if (e->key() == Key_Delete ) d->autoSuggest=false; if ( d->completionBox ) d->completionBox->setCancelledText( txt ); if ( emitSignals() ) emit completion( txt ); // emit when requested... if ( handleSignals() ) { makeCompletion( txt ); // handle when requested... } if ( (e->key() == Key_Backspace || e->key() == Key_Delete ) && mode == KGlobalSettings::CompletionPopupAuto ) d->autoSuggest=true; e->accept(); } else if (!len && d->completionBox && d->completionBox->isVisible()) d->completionBox->hide(); return; } else if ( mode == KGlobalSettings::CompletionShell ) { // Handles completion. KShortcut cut; if ( keys[TextCompletion].isNull() ) cut = KStdAccel::shortcut(KStdAccel::TextCompletion); else cut = keys[TextCompletion]; if ( cut.contains( key ) ) { // Emit completion if the completion mode is CompletionShell // and the cursor is at the end of the string. QString txt = text(); int len = txt.length(); if ( cursorPosition() == len && len != 0 ) { if ( emitSignals() ) emit completion( txt ); if ( handleSignals() ) makeCompletion( txt ); return; } } else if ( d->completionBox ) d->completionBox->hide(); } // handle rotation if ( mode != KGlobalSettings::CompletionNone ) { // Handles previous match KShortcut cut; if ( keys[PrevCompletionMatch].isNull() ) cut = KStdAccel::shortcut(KStdAccel::PrevCompletion); else cut = keys[PrevCompletionMatch]; if ( cut.contains( key ) ) { if ( emitSignals() ) emit textRotation( KCompletionBase::PrevCompletionMatch ); if ( handleSignals() ) rotateText( KCompletionBase::PrevCompletionMatch ); return; } // Handles next match if ( keys[NextCompletionMatch].isNull() ) cut = KStdAccel::shortcut(KStdAccel::NextCompletion); else cut = keys[NextCompletionMatch]; if ( cut.contains( key ) ) { if ( emitSignals() ) emit textRotation( KCompletionBase::NextCompletionMatch ); if ( handleSignals() ) rotateText( KCompletionBase::NextCompletionMatch ); return; } } // substring completion if ( compObj() ) { KShortcut cut; if ( keys[SubstringCompletion].isNull() ) cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion); else cut = keys[SubstringCompletion]; if ( cut.contains( key ) ) { if ( emitSignals() ) emit substringCompletion( text() ); if ( handleSignals() ) { setCompletedItems( compObj()->substringCompletion(text())); e->accept(); } return; } } } uint selectedLength = selectedText().length(); // Let QLineEdit handle any other keys events. QLineEdit::keyPressEvent ( e ); if ( selectedLength != selectedText().length() ) slotRestoreSelectionColors(); // and set userSelection to true }
int QLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 21) qt_static_metacall(this, _c, _id, _a); _id -= 21; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = inputMask(); break; case 1: *reinterpret_cast< QString*>(_v) = text(); break; case 2: *reinterpret_cast< int*>(_v) = maxLength(); break; case 3: *reinterpret_cast< bool*>(_v) = hasFrame(); break; case 4: *reinterpret_cast< EchoMode*>(_v) = echoMode(); break; case 5: *reinterpret_cast< QString*>(_v) = displayText(); break; case 6: *reinterpret_cast< int*>(_v) = cursorPosition(); break; case 7: *reinterpret_cast< Qt::Alignment*>(_v) = alignment(); break; case 8: *reinterpret_cast< bool*>(_v) = isModified(); break; case 9: *reinterpret_cast< bool*>(_v) = hasSelectedText(); break; case 10: *reinterpret_cast< QString*>(_v) = selectedText(); break; case 11: *reinterpret_cast< bool*>(_v) = dragEnabled(); break; case 12: *reinterpret_cast< bool*>(_v) = isReadOnly(); break; case 13: *reinterpret_cast< bool*>(_v) = isUndoAvailable(); break; case 14: *reinterpret_cast< bool*>(_v) = isRedoAvailable(); break; case 15: *reinterpret_cast< bool*>(_v) = hasAcceptableInput(); break; case 16: *reinterpret_cast< QString*>(_v) = placeholderText(); break; case 17: *reinterpret_cast< Qt::CursorMoveStyle*>(_v) = cursorMoveStyle(); break; } _id -= 18; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setInputMask(*reinterpret_cast< QString*>(_v)); break; case 1: setText(*reinterpret_cast< QString*>(_v)); break; case 2: setMaxLength(*reinterpret_cast< int*>(_v)); break; case 3: setFrame(*reinterpret_cast< bool*>(_v)); break; case 4: setEchoMode(*reinterpret_cast< EchoMode*>(_v)); break; case 6: setCursorPosition(*reinterpret_cast< int*>(_v)); break; case 7: setAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break; case 8: setModified(*reinterpret_cast< bool*>(_v)); break; case 11: setDragEnabled(*reinterpret_cast< bool*>(_v)); break; case 12: setReadOnly(*reinterpret_cast< bool*>(_v)); break; case 16: setPlaceholderText(*reinterpret_cast< QString*>(_v)); break; case 17: setCursorMoveStyle(*reinterpret_cast< Qt::CursorMoveStyle*>(_v)); break; } _id -= 18; } else if (_c == QMetaObject::ResetProperty) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 18; } #endif // QT_NO_PROPERTIES return _id; }