void Label::setTextInteraction(bool on, bool selectAll) { if(on && textInteractionFlags() == Qt::NoTextInteraction) { // switch on editor mode: qDebug() << textInteractionFlags(); setTextInteractionFlags(Qt::TextEditorInteraction); qDebug() << textInteractionFlags(); // manually do what a mouse click would do else: setFocus(Qt::MouseFocusReason); // this gives the item keyboard focus setSelected(true); // this ensures that itemChange() gets called when we click out of the item if(selectAll) // option to select the whole text (e.g. after creation of the TextItem) { QTextCursor c = textCursor(); c.select(QTextCursor::Document); setTextCursor(c); } } else if(!on && textInteractionFlags() == Qt::TextEditorInteraction) { // turn off editor mode: setTextInteractionFlags(Qt::NoTextInteraction); // deselect text (else it keeps gray shade): QTextCursor c = this->textCursor(); c.clearSelection(); this->setTextCursor(c); clearFocus(); } }
void ItemLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { QTextCursor myCursor = this->textCursor(); if (textInteractionFlags() == Qt::NoTextInteraction) { //QPoint p = this->textCursor()->pos(); setTextInteractionFlags(Qt::TextEditorInteraction);//|Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse|Qt::TextEditable); setTextInteractionFlags(Qt::TextEditable); //myCursor->setCursorMoveStyle; //cursor.movePosition(QTextCursor::Start); //setTextInteractionFlags(Qt::TextEditable); //this->cursor().setS //QTextCursor tt = ; //this->setMQt::LogicalMoveStyle. //this->textCursor()->setTabChangesFocus(true); //this->cursor().setCursorMoveStyle(); //this->textCursor().setPos(p); } /*myCursor.setKeepPositionOnInsert(true); bool flag = myCursor.keepPositionOnInsert(); bool mflag = myCursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1);*/ QGraphicsTextItem::mouseDoubleClickEvent(event); //myCursor.setPosition(10, QTextCursor::MoveAnchor); return; }
void GraphNodeText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if(textInteractionFlags() == Qt::NoTextInteraction) setTextInteractionFlags(Qt::TextEditable | Qt::TextSelectableByKeyboard); QGraphicsTextItem::mouseDoubleClickEvent(event); }
int QLabel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QFrame::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 12) qt_static_metacall(this, _c, _id, _a); _id -= 12; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = text(); break; case 1: *reinterpret_cast< Qt::TextFormat*>(_v) = textFormat(); break; case 2: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(pixmap())); break; case 3: *reinterpret_cast< bool*>(_v) = hasScaledContents(); break; case 4: *reinterpret_cast< Qt::Alignment*>(_v) = alignment(); break; case 5: *reinterpret_cast< bool*>(_v) = wordWrap(); break; case 6: *reinterpret_cast< int*>(_v) = margin(); break; case 7: *reinterpret_cast< int*>(_v) = indent(); break; case 8: *reinterpret_cast< bool*>(_v) = openExternalLinks(); break; case 9: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 10: *reinterpret_cast< bool*>(_v) = hasSelectedText(); break; case 11: *reinterpret_cast< QString*>(_v) = selectedText(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setText(*reinterpret_cast< QString*>(_v)); break; case 1: setTextFormat(*reinterpret_cast< Qt::TextFormat*>(_v)); break; case 2: setPixmap(*reinterpret_cast< QPixmap*>(_v)); break; case 3: setScaledContents(*reinterpret_cast< bool*>(_v)); break; case 4: setAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break; case 5: setWordWrap(*reinterpret_cast< bool*>(_v)); break; case 6: setMargin(*reinterpret_cast< int*>(_v)); break; case 7: setIndent(*reinterpret_cast< int*>(_v)); break; case 8: setOpenExternalLinks(*reinterpret_cast< bool*>(_v)); break; case 9: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
void TupTextItem::focusOutEvent(QFocusEvent * event) { QGraphicsTextItem::focusOutEvent(event); if (textInteractionFlags() & Qt::TextEditorInteraction && m_isEditable) { QTimer::singleShot(0, this, SLOT(toggleEditable())); emit edited(); } }
bool CWidgetReturnEmitTextEdit::focusNextPrevChild(bool next) { if (!tabChangesFocus() && (textInteractionFlags() & Qt::TextEditable)) { emit tabPressed(); return true; } else { return QAbstractScrollArea::focusNextPrevChild(next); } }
void InputTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event){ position_change = pos(); if(hasFocus()){ if (textInteractionFlags() == Qt::NoTextInteraction) setTextInteractionFlags(Qt::TextEditorInteraction); } QGraphicsTextItem::mousePressEvent(event); }
/** Gere les double-clics sur ce champ de texte. @param event un QGraphicsSceneMouseEvent decrivant le double-clic */ void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (!(textInteractionFlags() & Qt::TextEditable)) { // rend le champ de texte editable setTextInteractionFlags(Qt::TextEditorInteraction); // edite le champ de texte setFocus(Qt::MouseFocusReason); } else { QGraphicsTextItem::mouseDoubleClickEvent(event); } }
void LabelItem::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent* event ) { if ( event->button() != Qt::LeftButton ) return; setFlag ( QGraphicsItem::ItemIsSelectable, true ); if ( textInteractionFlags() == Qt::NoTextInteraction ) { setTextInteractionFlags ( Qt::TextEditorInteraction ); } QGraphicsTextItem::mouseDoubleClickEvent ( event ); }
int QTextControl::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 38) qt_static_metacall(this, _c, _id, _a); _id -= 38; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = toHtml(); break; case 1: *reinterpret_cast< bool*>(_v) = overwriteMode(); break; case 2: *reinterpret_cast< bool*>(_v) = acceptRichText(); break; case 3: *reinterpret_cast< int*>(_v) = cursorWidth(); break; case 4: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 5: *reinterpret_cast< bool*>(_v) = openExternalLinks(); break; case 6: *reinterpret_cast< bool*>(_v) = ignoreUnusedNavigationEvents(); break; } _id -= 7; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setHtml(*reinterpret_cast< QString*>(_v)); break; case 1: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break; case 2: setAcceptRichText(*reinterpret_cast< bool*>(_v)); break; case 3: setCursorWidth(*reinterpret_cast< int*>(_v)); break; case 4: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; case 5: setOpenExternalLinks(*reinterpret_cast< bool*>(_v)); break; case 6: setIgnoreUnusedNavigationEvents(*reinterpret_cast< bool*>(_v)); break; } _id -= 7; } else if (_c == QMetaObject::ResetProperty) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 7; } #endif // QT_NO_PROPERTIES return _id; }
WChatLog::WChatLog(QWidget * pwParent, ITreeItemChatLogEvents * pContactOrGroup) : WTextBrowser(pwParent) { Assert(pContactOrGroup != NULL); m_pContactOrGroup = pContactOrGroup; m_fDisplayAllMessages = FALSE; m_tsMidnightNext = d_ts_zNA; setMinimumSize(10, 50); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setTextInteractionFlags((textInteractionFlags() & ~Qt::TextEditable) | Qt::LinksAccessibleByMouse); setUndoRedoEnabled(false); // setMaximumBlockCount setCursorWidth(0); //document()->setDefaultStyleSheet("p {text-indent:-10px; margin-left:10px; margin-top:5; margin-bottom:0; white-space:pre-wrap;}"); document()->setDefaultStyleSheet( "a."d_szClassForChatLog_ButtonHtml " { color: black; background-color: silver; text-decoration: none; font-weight: bold } " "a."d_szClassForChatLog_HyperlinkDisabled " { color: gray; text-decoration: none; } " "a.ha { color: navy; text-decoration: none; } " // Active Hyperlink (displayed in the normal blue color) ".d { color: green } " //"a.hb { padding: 6px; margin-left:10px; background-color: silver; border-style: outset; border-width: 2px; border-radius: 10px; border-color: black; } " //"a.hb:hover { background-color: rgb(224, 0, 0); border-style: inset; }"); ); /* QTextCursor oTextCursor = textCursor(); //oTextCursor.select(QTextCursor::Document); //oTextCursor.setBlockFormat(QTextBlockFormat()); oTextCursor.insertBlock(); m_oTextBlockComposing = oTextCursor.block(); CArrayPtrEvents arraypEvents; pContactOrGroup->Vault_GetEventsForChatLog(OUT &arraypEvents); ChatLog_EventsDisplay(IN arraypEvents); */ ChatLog_EventsRepopulate(); setOpenLinks(false); // Prevent the chat history to automatically open the hyperlinks connect(this, SIGNAL(highlighted(QUrl)), this, SLOT(SL_HyperlinkMouseHovering(QUrl))); connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(SL_HyperlinkClicked(QUrl))); }
void KSqueezedTextLabel::mouseReleaseEvent(QMouseEvent* ev) { #if QT_VERSION >= 0x040700 if (QApplication::clipboard()->supportsSelection() && textInteractionFlags() != Qt::NoTextInteraction && ev->button() == Qt::LeftButton && !d->fullText.isEmpty() && hasSelectedText()) { // Expand "..." when selecting with the mouse QString txt = selectedText(); const QChar ellipsisChar(0x2026); // from qtextengine.cpp const int dotsPos = txt.indexOf(ellipsisChar); if (dotsPos > -1) { // Ex: abcde...yz, selecting de...y (selectionStart=3) // charsBeforeSelection = selectionStart = 2 (ab) // charsAfterSelection = 1 (z) // final selection length= 26 - 2 - 1 = 23 const int start = selectionStart(); int charsAfterSelection = text().length() - start - selectedText().length(); txt = d->fullText; // Strip markup tags if (textFormat() == Qt::RichText || (textFormat() == Qt::AutoText && Qt::mightBeRichText(txt))) { txt.replace(QRegExp(QStringLiteral("<[^>]*>")), QStringLiteral("")); // account for stripped characters charsAfterSelection -= d->fullText.length() - txt.length(); } txt = txt.mid(selectionStart(), txt.length() - start - charsAfterSelection); } QApplication::clipboard()->setText(txt, QClipboard::Selection); } else #endif { QLabel::mouseReleaseEvent(ev); } }
void PetriTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if(textInteractionFlags() == Qt::NoTextInteraction) setTextInteractionFlags(Qt::TextEditorInteraction); QGraphicsTextItem::mouseDoubleClickEvent(event); }
int QPlainTextEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QAbstractScrollArea::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 25) qt_static_metacall(this, _c, _id, _a); _id -= 25; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = tabChangesFocus(); break; case 1: *reinterpret_cast< QString*>(_v) = documentTitle(); break; case 2: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 3: *reinterpret_cast< LineWrapMode*>(_v) = lineWrapMode(); break; case 4: *reinterpret_cast< bool*>(_v) = isReadOnly(); break; case 5: *reinterpret_cast< QString*>(_v) = toPlainText(); break; case 6: *reinterpret_cast< bool*>(_v) = overwriteMode(); break; case 7: *reinterpret_cast< int*>(_v) = tabStopWidth(); break; case 8: *reinterpret_cast< int*>(_v) = cursorWidth(); break; case 9: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 10: *reinterpret_cast< int*>(_v) = blockCount(); break; case 11: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; case 12: *reinterpret_cast< bool*>(_v) = backgroundVisible(); break; case 13: *reinterpret_cast< bool*>(_v) = centerOnScroll(); break; } _id -= 14; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setTabChangesFocus(*reinterpret_cast< bool*>(_v)); break; case 1: setDocumentTitle(*reinterpret_cast< QString*>(_v)); break; case 2: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 3: setLineWrapMode(*reinterpret_cast< LineWrapMode*>(_v)); break; case 4: setReadOnly(*reinterpret_cast< bool*>(_v)); break; case 5: setPlainText(*reinterpret_cast< QString*>(_v)); break; case 6: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break; case 7: setTabStopWidth(*reinterpret_cast< int*>(_v)); break; case 8: setCursorWidth(*reinterpret_cast< int*>(_v)); break; case 9: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; case 11: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; case 12: setBackgroundVisible(*reinterpret_cast< bool*>(_v)); break; case 13: setCenterOnScroll(*reinterpret_cast< bool*>(_v)); break; } _id -= 14; } else if (_c == QMetaObject::ResetProperty) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 14; } #endif // QT_NO_PROPERTIES return _id; }
void BaseEditor::paintEvent(QPaintEvent *e) { //copy from QPlainTextEditor QPainter painter(viewport()); Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout())); QPointF offset(contentOffset()); QRect er = e->rect(); QRect viewportRect = viewport()->rect(); bool editable = !isReadOnly(); QTextBlock block = firstVisibleBlock(); qreal maximumWidth = document()->documentLayout()->documentSize().width(); //margin qreal lineX = 0; if (conf->isDisplayRightColumnMargin()) { // Don't use QFontMetricsF::averageCharWidth here, due to it returning // a fractional size even when this is not supported by the platform. lineX = QFontMetricsF(document()->defaultFont()).width(QLatin1Char('X')) * conf->getRightMarginColumn() + offset.x() + 4; if (lineX < viewportRect.width()) { const QBrush background = QBrush(QColor(239, 239, 239)); painter.fillRect(QRectF(lineX, er.top(), viewportRect.width() - lineX, er.height()), background); const QColor col = (palette().base().color().value() > 128) ? Qt::black : Qt::white; const QPen pen = painter.pen(); painter.setPen(blendColors(background.isOpaque() ? background.color() : palette().base().color(), col, 32)); painter.drawLine(QPointF(lineX, er.top()), QPointF(lineX, er.bottom())); painter.setPen(pen); } } // Set a brush origin so that the WaveUnderline knows where the wave started painter.setBrushOrigin(offset); // keep right margin clean from full-width selection int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth) - document()->documentMargin(); er.setRight(qMin(er.right(), maxX)); painter.setClipRect(er); QAbstractTextDocumentLayout::PaintContext context = getPaintContext(); while (block.isValid()) { QRectF r = blockBoundingRect(block).translated(offset); QTextLayout *layout = block.layout(); if (!block.isVisible()) { offset.ry() += r.height(); block = block.next(); continue; } if (r.bottom() >= er.top() && r.top() <= er.bottom()) { QTextBlockFormat blockFormat = block.blockFormat(); QBrush bg = blockFormat.background(); if (bg != Qt::NoBrush) { QRectF contentsRect = r; contentsRect.setWidth(qMax(r.width(), maximumWidth)); fillBackground(&painter, contentsRect, bg); } QVector<QTextLayout::FormatRange> selections; int blpos = block.position(); int bllen = block.length(); for (int i = 0; i < context.selections.size(); ++i) { const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i); const int selStart = range.cursor.selectionStart() - blpos; const int selEnd = range.cursor.selectionEnd() - blpos; if (selStart < bllen && selEnd > 0 && selEnd > selStart) { QTextLayout::FormatRange o; o.start = selStart; o.length = selEnd - selStart; o.format = range.format; selections.append(o); } else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection) && block.contains(range.cursor.position())) { // for full width selections we don't require an actual selection, just // a position to specify the line. that's more convenience in usage. QTextLayout::FormatRange o; QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos); o.start = l.textStart(); o.length = l.textLength(); if (o.start + o.length == bllen - 1) ++o.length; // include newline o.format = range.format; selections.append(o); } } bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard)) && context.cursorPosition >= blpos && context.cursorPosition < blpos + bllen); bool drawCursorAsBlock = drawCursor && overwriteMode() ; if (drawCursorAsBlock) { if (context.cursorPosition == blpos + bllen - 1) { drawCursorAsBlock = false; } else { QTextLayout::FormatRange o; o.start = context.cursorPosition - blpos; o.length = 1; o.format.setForeground(palette().base()); o.format.setBackground(palette().text()); selections.append(o); } } layout->draw(&painter, offset, selections, er); if ((drawCursor && !drawCursorAsBlock) || (editable && context.cursorPosition < -1 && !layout->preeditAreaText().isEmpty())) { int cpos = context.cursorPosition; if (cpos < -1) cpos = layout->preeditAreaPosition() - (cpos + 2); else cpos -= blpos; layout->drawCursor(&painter, offset, cpos, cursorWidth()); } } offset.ry() += r.height(); if (offset.y() > viewportRect.height()) break; block = block.next(); } if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom() && (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) { painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background()); } }