void DigraphLineEdit::keyPressEvent( QKeyEvent* event ) { if( digraphEnabled ) { // We consider only printable keys. Control keys are processed normally. // I'm not sure if this test covers all the cases though. if( event->count() > 0 ) { if( event->key() == Qt::Key_Backspace ) { if( cursorPosition() > 0 ) { if( buffer.isNull() ) { QString charToDelete( text().mid( cursorPosition() - 1, 1 ) ); buffer = charToDelete; } else buffer = QString::null; } } else { // Shift key is required to input some digraphs so it's a special case. if( !buffer.isNull() && event->key() != Qt::Key_Shift ) { buffer += event->text(); const QString newChar( Util::getDigraph( buffer ) ); if( newChar == QString::null ) buffer = QString::null; else { QKeyEvent* digraphEvent = new QKeyEvent( QEvent::KeyPress, 0, Qt::NoModifier, newChar, event->isAutoRepeat(), 0 ); QLineEdit::keyPressEvent( digraphEvent ); buffer = QString::null; return; } } } } } QLineEdit::keyPressEvent( event ); }
void lcl_OnyxLineEdit::keyPressEvent(QKeyEvent * ke) { if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) { NumberDialog dialog(0, name); if (dialog.popup(text().toInt(), maxval) == QDialog::Accepted) { int val = dialog.value(); QString s_val; s_val = QString("%1").arg(val); setText(s_val); onyx::screen::instance().updateWidget(0, onyx::screen::ScreenProxy::GU); emit valueChanged(this); } } if ((ke->key() == Qt::Key_Left && cursorPosition() <= 0) || (ke->key() == Qt::Key_Right && cursorPosition() >= text().size())) { out_of_range_ = true; } QLineEdit::keyPressEvent(ke); ke->accept(); update(); onyx::screen::watcher().enqueue(this, onyx::screen::ScreenProxy::DW, onyx::screen::ScreenCommand::WAIT_NONE); }
/** TagButton instances are converted with whitespaces in the LineEdit in order to move them. */ void TagLineEdit::insertSpaces() { TagButton *t = qobject_cast<TagButton*>(sender()); int cx = cursorRect().x(); t->setPosition(cursorPosition()); int numberOfSpace = 2; this->setText(this->text().insert(cursorPosition(), " ")); cursorForward(false, 2); while (t->frameGeometry().contains(cursorRect().center())) { this->setText(this->text().insert(cursorPosition(), " ")); cursorForward(false); numberOfSpace++; } t->setMinimumWidth(numberOfSpace * fontMetrics().width(" ") - 5); t->setSpaceCount(numberOfSpace); t->disconnect(); for (TagButton *tag : _tags) { //qDebug() << Q_FUNC_INFO << "trying to move tag"; if (t != tag && tag->frameGeometry().x() > cx) { //qDebug() << Q_FUNC_INFO << "moving tag" << tag->text(); tag->move(tag->x() + fontMetrics().width(" ") * numberOfSpace, 0); } } }
void GuidLineEdit::keyPressEvent(QKeyEvent * event) { if (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace) { int pos = cursorPosition(); if (event->key() == Qt::Key_Backspace && pos > 0) { cursorBackward(false); pos = cursorPosition(); } QString txt = text(); QString selected = selectedText(); if (!selected.isEmpty()) { pos = QLineEdit::selectionStart(); for (int i = pos; i < pos + selected.count(); i++) if (txt[i] != QChar('-')) txt[i] = QChar('.'); } else txt[pos] = QChar('.'); setCursorPosition(0); insert(txt); setCursorPosition(pos); return; } // Call original event handler QLineEdit::keyPressEvent(event); }
void StatusEdit::shortenUrl() { if( hasSelectedText() ) { selectedUrl = selectedText(); emit shortenUrl( selectedUrl ); } else { QRegExp rx( "((ftp|http|https)://(\\w+:{0,1}\\w*@)?([^ ]+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!-/]))?)", Qt::CaseInsensitive ); int position = rx.indexIn( text() ); QString url = rx.capturedTexts().at( 1 ); if( cursorPosition() >= position && cursorPosition() <= url.length() + position ) { selectedUrl = url; emit shortenUrl( selectedUrl ); } } }
void NumberEdit::texttChanged(const QString& text) { QString in=text; if (!suffix.isEmpty()) { if (text.endsWith(suffix)) { in=in.remove(text.size()-suffix.size(), suffix.size()); } } double d=extractVal(text); setViewOK(); if ((checkMax) && (d>max)) { d=max; setViewError(); }//setValue(d);} if ((checkMin) && (d<min)) { d=min; setViewError(); }//setValue(d); } //std::cout<<d<<std::endl; //QMessageBox::information(this, "", QString("value is %1").arg(d)); else emit valueChanged(d); if ((!suffix.isEmpty()) && (!text.contains(suffix))) { int cp=cursorPosition(); setText(text+suffix); setCursorPosition(cp); } }
void ByteArrayColumnViewPrivate::placeCursor( const QPoint& point ) { Q_Q( ByteArrayColumnView ); // switch active column if needed if( mCharColumn->isVisible() && point.x() >= mCharColumn->x() ) { mActiveColumn = mCharColumn; mInactiveColumn = mValueColumn; } else { mActiveColumn = mValueColumn; mInactiveColumn = mCharColumn; } adaptController(); // get coord of click and whether this click was closer to the end of the pos const int linePosition = mActiveColumn->magneticLinePositionOfX( point.x() ); const int lineIndex = q->lineAt( point.y() ); const Coord coord( linePosition, lineIndex ); mTableCursor->gotoCCoord( coord ); emit q->cursorPositionChanged( cursorPosition() ); }
void QLineEditEx::keyPressEvent(QKeyEvent *e) { if(e->key() == Qt::Key_Up) { loadHistory(true,m_History,m_Index); return; } else if (e->key() == Qt::Key_Down) { loadHistory(false,m_History,m_Index); return; } else if(e->key() == Qt::Key_Left) { if(m_TabIndex != -1) { suggest(false); return; } } else if(e->key() == Qt::Key_Right) { if(cursorPosition() == text().length() || m_TabIndex != -1) { suggest(true); return; } } else { m_TabBase.clear(); m_TabIndex = -1; } QLineEdit::keyPressEvent(e); }
void KonqCombo::saveState() { m_cursorPos = cursorPosition(); m_currentText = currentText(); m_selectedText = lineEdit()->selectedText(); m_currentIndex = currentIndex(); }
void KTextBox::fitText() { int startindex, endindex, countindex, testlength, line, column; // Map the text to the width of the widget cursorPosition( &line, &column ); countindex =-1; QString testText = text().simplifyWhiteSpace() + " "; startindex = 0; testlength = testText.length(); countindex = testText.find(" ", 0); while ((endindex = testText.find(" ", countindex+1)) > -1) { QString middle; int len; len = endindex - startindex; middle = testText.mid( startindex, len ); if (textWidth( &middle ) > width()) { testText.replace( countindex, 1, "\n" ); startindex = countindex; } countindex = endindex; } setText( testText.stripWhiteSpace() ); setCursorPosition( line, column ); }
//VOXOX CHANGE by Rolando - 2009.05.11 - method called when lineedit lost focus void VoxOxToolTipLineEdit::leaveEvent ( QEvent * event ){ if (QLineEdit::text() == _toolTip || QLineEdit::text().isEmpty()) {//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is equal to tooltip or is empty displayToolTipMessage(); } else{ int cursorPositionValue = cursorPosition();//VOXOX CHANGE by Rolando - 2009.06.02 - gets current Cursor Position int intSelectedStart = -1; QString stringText; if(hasSelectedText()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is selected text stringText = selectedText();//VOXOX CHANGE by Rolando - 2009.06.02 - gets selected text intSelectedStart = selectionStart();//VOXOX CHANGE by Rolando - 2009.06.02 - gets position where selection starts } if(_message == QLineEdit::text()){//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is equal to _message then sets _shortMessage QLineEdit::setText(_shortMessage); } else{//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is not equal to _message then updates _shortMessage and _message and then sets _shortMessage as current text updateMessageText(QLineEdit::text()); QLineEdit::setText(_shortMessage); } //VOXOX CHANGE by Rolando - 2009.10.13 if(intSelectedStart >= 0 && intSelectedStart + stringText.length() <= getMaximumCharsAllowed()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is a text selected setSelection(intSelectedStart, stringText.length());//VOXOX CHANGE by Rolando - 2009.06.02 - as we set the long message in lineedit, we need to set the text was selected } currentTextChanged(text()); } QLineEdit::leaveEvent(event); //changeFocusToParent();//VOXOX CHANGE by Rolando - 2009.05.22 - method to send focus to another widget when mouse leaves the lineedit }
void MgCommandLine::keyPressEvent(QKeyEvent * e) { if(e->key() == Qt::Key_Escape ) clear(); else if((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) && m_scriptEngine && m_completer->popup()->isVisible()) { insertText(m_completer->popup()->currentIndex().data().toString()); m_completer->popup()->hide(); } else if((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) && m_scriptEngine) { m_scriptEngine->execCommand(text()); clear(); } else if(e->key() == Qt::Key_Space && e->modifiers().testFlag(Qt::ControlModifier)) { if(!m_completer->popup()->isVisible()) { MgCommandCompleter completer(m_scriptEngine); MgCommandCompleter::CompletionResult result = completer.completionOf(text(),cursorPosition()); m_completer->setCompletionPrefix(""); m_prefix = result.prefix; m_completionModel->setStringList(result.completion); m_completer->complete(); } else { m_completer->popup()->hide(); } } else QLineEdit::keyPressEvent(e); }
void QcrLineEdit::doSetValue(QString val) { //keep cursor pos, so the cursor doesn't always jump to the end: int oldCursorPos = cursorPosition(); setText(val); this->setCursorPosition(oldCursorPos); }
void LineEditHistory::complete() { QString para = this->text(); int wordStart = beginOfWord( false ); while (wordStart > 0 && para[wordStart - 1].isLetterOrNumber()) --wordStart; wordPrefix = para.mid(wordStart, cursorPosition() - wordStart); // if (wordPrefix.isEmpty()) // return; QStringList list = searchSymbols; QMap<QString, QString> map; QStringList::Iterator it = list.begin(); while (it != list.end()) { if ((*it).startsWith(wordPrefix) && (*it).length() > wordPrefix.length()) map[(*it).toLower()] = *it; ++it; } if (map.count() == 1) { insert((*map.begin()).mid(wordPrefix.length())); } else if (map.count() > 1) { if (!listBox) createListBox(); listBox->clear(); listBox->addItems( map.values() ); QPoint point = textCursorPoint(); listBox->move(point); listBox->show(); listBox->raise(); listBox->activateWindow(); } }
void BaseValidatingLineEdit::slotChanged(const QString &t) { m_bd->m_errorMessage.clear(); // Are we displaying the initial text? const bool isDisplayingInitialText = !m_bd->m_initialText.isEmpty() && t == m_bd->m_initialText; const State newState = isDisplayingInitialText ? DisplayingInitialText : (validate(t, &m_bd->m_errorMessage) ? Valid : Invalid); setToolTip(m_bd->m_errorMessage); if (debug) qDebug() << Q_FUNC_INFO << t << "State" << m_bd->m_state << "->" << newState << m_bd->m_errorMessage; // Changed..figure out if valid changed. DisplayingInitialText is not valid, // but should not show error color. Also trigger on the first change. if (newState != m_bd->m_state || m_bd->m_firstChange) { const bool validHasChanged = (m_bd->m_state == Valid) != (newState == Valid); m_bd->m_state = newState; m_bd->m_firstChange = false; setTextColor(this, newState == Invalid ? m_bd->m_errorTextColor : m_bd->m_okTextColor); if (validHasChanged) { emit validChanged(newState == Valid); emit validChanged(); } } bool block = blockSignals(true); const QString fixedString = fixInputString(t); if (t != fixedString) { const int cursorPos = cursorPosition(); setText(fixedString); setCursorPosition(qMin(cursorPos, fixedString.length())); } blockSignals(block); }
void BookTextView::replaceCurrentPositionInStack() { const ZLTextWordCursor &cursor = textArea().startCursor(); if (!cursor.isNull()) { myPositionStack[myCurrentPointInStack] = cursorPosition(cursor); myStackChanged = true; } }
void line_edit_autocomplete::show_completions() { if (!m_completer_enabled) return; QString prefix; // substring on which the completion is to be based int pos = cursorPosition(); int start = get_prefix_pos(text(), pos); if (start>=0) { prefix=text().mid(start, pos-start); } if (prefix.isEmpty()) { // nothing to complete if (popup->isVisible()) { popup->clear(); popup->hide(); } } else { QList<QString> completions = get_completions(prefix); redisplay_popup(completions); } }
void PropertyLineEdit::insertText(const QString &text) { // position cursor after new text and grab focus const int oldCursorPosition = cursorPosition (); insert(text); setCursorPosition (oldCursorPosition + text.length()); setFocus(Qt::OtherFocusReason); }
QPair<int, int> TagWidget::getCursorTagPosition() { int i = 0, start = 0, end = 0; /* Parse string near cursor */ i = cursorPosition(); while (--i > 0) { if (text().at(i) == ',') { if (i > 0 && text().at(i - 1) != '\\') { i++; break; } } } start = i; while (++i < text().length()) { if (text().at(i) == ',') { if (i > 0 && text().at(i - 1) != '\\') break; } } end = i; if (start < 0 || end < 0) { start = 0; end = 0; } return qMakePair(start, end); }
void VoxOxToolTipLineEdit::keyPressEvent(QKeyEvent * event) { if (!_cleared) { clearLineEdit(); repaintPrimaryColor(); } if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter) {//if key pressed was return or enter if(!QLineEdit::text().isEmpty()){ updateMessageText(QLineEdit::text()); QLineEdit::setText(_shortMessage); currentTextChanged(text()); } QLineEdit::keyPressEvent(event); changeFocusToParent();//VOXOX CHANGE by Rolando - 2009.05.22 - method to send focus to another widget when mouse leaves the lineedit } else{//if key pressed was not return or enter key int cursorPositionValue = cursorPosition();//VOXOX CHANGE by Rolando - 2009.06.02 - gets current Cursor Position bool isShortMessage = QLineEdit::text() == _shortMessage;//VOXOX CHANGE by Rolando - 2009.06.02 - we need to check if current text is equal to _shortMessage int intSelectedStart = -1; QString text; if(hasSelectedText()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is selected text text = selectedText();//VOXOX CHANGE by Rolando - 2009.06.02 - gets selected text intSelectedStart = selectionStart();//VOXOX CHANGE by Rolando - 2009.06.02 - gets position where selection starts } QLineEdit::setText(_message);//VOXOX CHANGE by Rolando - 2009.06.02 - sets long message if(intSelectedStart >= 0){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is a text selected setSelection(intSelectedStart, text.length());//VOXOX CHANGE by Rolando - 2009.06.02 - as we set the long message in lineedit, we need to set the text was selected } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if there is not a text selected if(isShortMessage){//VOXOX CHANGE by Rolando - 2009.06.02 - if we had currentText equal to _shortMessage //VOXOX CHANGE by Rolando - 2009.10.13 if(cursorPositionValue == _shortMessage.length()){//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is the rightest pos allowed setCursorPosition(_message.length());//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to rightest position after we changed the current text by _message } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed } } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if we had not currentText equal to _shortMessage setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to old position + 1 } } QLineEdit::keyPressEvent(event);//processes event - it should be processed before update _shortMessage and _message variables updateMessageText(QLineEdit::text());//VOXOX CHANGE by Rolando - 2009.06.02 - we update the short and long messages } keyPressedSignal(event->key()); }
void SpinBox::setValue_internal(double d, bool reformat) { if ( ( d == text().toDouble() ) && !reformat && _imp->valueInitialized ) { // the value is already OK return; } int pos = cursorPosition(); QString str; switch (_imp->type) { case eSpinBoxTypeDouble: { str.setNum(d, 'f', _imp->decimals); double toDouble = str.toDouble(); if (d != toDouble) { str.setNum(d, 'g', 8); } break; } case eSpinBoxTypeInt: str.setNum( (int)d ); break; } assert( !str.isEmpty() ); ///Remove trailing 0s by hand... int decimalPtPos = str.indexOf( QLatin1Char('.') ); if (decimalPtPos != -1) { int i = str.size() - 1; while ( i > decimalPtPos && str.at(i) == QLatin1Char('0') ) { --i; } ///let 1 trailing 0 if (i < str.size() - 1) { ++i; } str = str.left(i + 1); } // The following removes leading zeroes, but this is not necessary /* int i = 0; bool skipFirst = false; if (str.at(0) == '-') { skipFirst = true; ++i; } while (i < str.size() && i == '0') { ++i; } if (i > int(skipFirst)) { str = str.remove(int(skipFirst), i - int(skipFirst)); } */ _imp->valueWhenEnteringFocus = str; setText(str, pos); _imp->valueInitialized = true; }
QChar WizTitleEdit::charBeforeCursor() { int i = cursorPosition() - 1; if (i >= 0) return text().at(i); return QChar(); }
void aHistLineEdit::slot_insert( QString str ) { QString s = text(); int curPos = cursorPosition(); s.insert(curPos, str); setText(s); setCursorPosition(curPos + str.length()); }
QPoint LineEditHistory::textCursorPoint() const { //getCursorPosition(&cursorPara, &cursorPos); QRect rect = QWidget::rect(); QPoint point(rect.left(), rect.bottom()); //while (charAt(point, 0) < cursorPos) point.rx() += QFontMetrics(this->font()).boundingRect( text().mid(0,cursorPosition())).width(); return mapToGlobal(point); }
QPointF CustomEdit::startPoint(const QPointF &hitPoint) const { // Prefer to select something even though the tap hit between words MBreakIterator breakIterator(text()); if (breakIterator.isBoundary(cursorPosition(hitPoint))) { // Hit the boundary -> try to find a word nearby QList<QPoint> baseOffsets; baseOffsets << QPoint(3,0) << QPoint(-3,0) << QPoint(0,-3) << QPoint(0,3); for (int i=1; i<=4; i++) { // Check each direction at 3,6,9 and 12 pixel distances -> a change to get the closest one Q_FOREACH(QPoint offset, baseOffsets) { QPointF checkPoint = hitPoint + i*offset; int checkPos = cursorPosition(checkPoint); if (checkPos >= 0 && !breakIterator.isBoundary(checkPos)) { return checkPoint; } } }
/** Redefined to be able to move tag buttons. * Backspace method is not virtual in QLineEdit, therefore keyPressEvent must be intercepted and eaten. */ void TagLineEdit::backspace() { bool oneTagNeedToBeRemoved = false; TagButton *tag = nullptr; QPoint cursorCenter; cursorBackward(false); int dx = fontMetrics().width(text().at(cursorPosition())); for (TagButton *button : _tags) { cursorCenter = cursorRect().center(); // One tag button need to be removed if (button->frameGeometry().contains(cursorCenter)) { oneTagNeedToBeRemoved = true; tag = button; } // Tags need to be moved to the left if (button->x() > cursorCenter.x()) { button->move(button->x() - dx, 0); button->setPosition(cursorPosition()); } } cursorForward(false); if (oneTagNeedToBeRemoved) { for (int i = 0; i < tag->spaceCount(); i++) { LineEdit::backspace(); } dx = fontMetrics().width(" ") * tag->spaceCount(); for (TagButton *button : _tags) { if (button != tag && button->x() > cursorCenter.x()) { button->move(button->x() - dx, 0); button->setPosition(cursorPosition()); } } _tags.removeOne(tag); delete tag; /// FIXME //emit taglistHasChanged(this->toStringList()); } else { LineEdit::backspace(); } }
void MgCommandLine::insertText(const QString & newText) { QString myText(text()); int pos(cursorPosition()-m_prefix.size()); myText.remove(pos,m_prefix.size()); myText.insert(pos,newText); setText(myText); m_prefix.clear(); }
QString QAccessibleLineEdit::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, int *startOffset, int *endOffset) const { if (lineEdit()->echoMode() != QLineEdit::Normal) { *startOffset = *endOffset = -1; return QString(); } if (offset == -2) offset = cursorPosition(); return QAccessibleTextInterface::textAtOffset(offset, boundaryType, startOffset, endOffset); }
void QHexEdit::mousePressEvent(QMouseEvent * event) { _blink = false; viewport()->update(); qint64 cPos = cursorPosition(event->pos()); if (cPos >= 0) { resetSelection(cPos); setCursorPosition(cPos); } }
/** Redefined to automatically move cursor outside TagButton. */ void TagLineEdit::mousePressEvent(QMouseEvent *event) { LineEdit::mousePressEvent(event); for (TagButton *t : _tags) { QRect r = t->frameGeometry(); if (r.contains(event->pos())) { if (r.x() + r.width() / 2 >= event->pos().x()) { while (r.contains(cursorRect().center()) && cursorPosition() > 0) { cursorBackward(false); //qDebug() << "cursorBackward" << "pos" << t->position() << "spaces" << t->spaceCount(); } } else { while (r.contains(cursorRect().center()) && cursorPosition() < text().length()) { cursorForward(false); //qDebug() << "cursorForward" << "pos" << t->position() << "spaces" << t->spaceCount(); } } break; } } }