/** Reimplementation to manage drops of our drag and drop objects. */ void CPlainWriteDisplay::dropEvent( QDropEvent* e ) { //qDebug("CPlainWriteDisplay::dropEvent"); const BTMimeData* mimedata = qobject_cast<const BTMimeData*>(e->mimeData()); if ( mimedata && mimedata->hasFormat("BibleTime/Bookmark") ) { //qDebug("format was bookmark"); e->acceptProposedAction(); BTMimeData::ItemList items = mimedata->bookmarks(); BTMimeData::ItemList::iterator it; for (it = items.begin(); it != items.end(); ++it) { CSwordModuleInfo* module = backend()->findModuleByName((*it).module()); boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) ); key->key( (*it).key() ); QString moduleText = key->strippedText(); const QString text = QString::fromLatin1("%1\n(%2, %3)\n").arg(moduleText).arg((*it).key()).arg((*it).module()); setTextCursor(cursorForPosition(e->pos())); textCursor().insertText( text ); } } else if ( e->mimeData()->hasFormat("text/plain")) { //qDebug("format was plain text"); e->acceptProposedAction(); setTextCursor(cursorForPosition(e->pos())); textCursor().insertText( e->mimeData()->text() ); } }
void CCodeEdit::mouseMoveLineNumEvent(QMouseEvent* event) { QPoint pt(0, event->y()); if( m_lineIconSize.width() < event->x() && 0 != (event->buttons()& Qt::LeftButton) ) { QTextCursor cursor = textCursor(); if( cursor.position() == cursor.selectionStart() ) { // 選択開始位置より前を選択 cursor.setPosition(cursor.selectionEnd()); cursor.movePosition(QTextCursor::EndOfLine); cursor.setPosition(cursorForPosition(pt).position(), QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); } else { // 選択開始位置より後ろを選択 cursor.setPosition(cursor.selectionStart()); cursor.movePosition(QTextCursor::StartOfLine); cursor.setPosition(cursorForPosition(pt).position(), QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); } setTextCursor(cursor); } }
void TextEditor::addSpellSuggestMenu(QMenu * menu, const QPoint& pos) { if(document()->isEmpty()) return; if(!highlighter_->isEnabled()) return; QTextCursor cursor = cursorForPosition(pos); cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); QString word = cursor.selectedText(); if(word.isEmpty()) return; if(!highlighter_->spellChecker()->hasErrors(word)) return; QStringList suggestions = highlighter_->spellChecker()->suggest(word); if(suggestions.isEmpty()) { qDebug() << "no suggestions for" << word; } else { foreach(const QString& variant, suggestions) { QAction * act = menu->addAction(variant, this, SLOT(handleSuggestion())); act->setData(pos); } }
void QgsComposerItem::hoverMoveEvent( QGraphicsSceneHoverEvent * event ) { if ( isSelected() ) { setCursor( cursorForPosition( event->pos() ) ); } }
QString OutputWindowPlainTextEdit::identifierUnderCursor(const QPoint &widgetPos, QString *repository) const { if (repository) repository->clear(); // Get the blank-delimited word under cursor. Note that // using "SelectWordUnderCursor" does not work since it breaks // at delimiters like '/'. Get the whole line QTextCursor cursor = cursorForPosition(widgetPos); const int cursorDocumentPos = cursor.position(); cursor.select(QTextCursor::BlockUnderCursor); if (!cursor.hasSelection()) return QString(); QString block = cursor.selectedText(); // Determine cursor position within line and find blank-delimited word const int cursorPos = cursorDocumentPos - cursor.block().position(); const int blockSize = block.size(); if (cursorPos < 0 || cursorPos >= blockSize || block.at(cursorPos).isSpace()) return QString(); // Retrieve repository if desired if (repository) if (QTextBlockUserData *data = cursor.block().userData()) *repository = static_cast<const RepositoryUserData*>(data)->repository(); // Find first non-space character of word and find first non-space character past const int startPos = firstWordCharacter(block, cursorPos); int endPos = cursorPos; for ( ; endPos < blockSize && !block.at(endPos).isSpace(); endPos++) ; return endPos > startPos ? block.mid(startPos, endPos - startPos) : QString(); }
void RZQtCodeEditor::MoveCursorTo(QPoint pos) { QTextCursor c = cursorForPosition(pos); textCursor().setPosition(c.position()); setTextCursor(c); highlightCurrentLine(); }
void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData()); if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped { QPlainTextEdit::dropEvent(event); return; } setTextCursor (cursorForPosition (event->pos())); if (mime->fromDocument (mDocument)) { std::vector<CSMWorld::UniversalId> records (mime->getData()); for (std::vector<CSMWorld::UniversalId>::iterator it = records.begin(); it != records.end(); ++it) { if (mAllowedTypes.contains (it->getType())) { if (stringNeedsQuote(it->getId())) { insertPlainText(QString::fromUtf8 (('"' + it->getId() + '"').c_str())); } else { insertPlainText(QString::fromUtf8 (it->getId().c_str())); } } } } }
//Mouse moving void TextEdit::mouseMoveEvent(QMouseEvent *e) { bool onLink = false; int position_start, position_end; if(settings.getNoteLinksOpen() && e->buttons()==Qt::NoButton && e->modifiers()&Qt::ControlModifier) //Ctrl+NoMouseButton { QTextCursor cursor = cursorForPosition(e->pos()); onLink = isOnLink(*document(), cursor, position_start, position_end); } if(onLink) //if link under cursor { QTextEdit::ExtraSelection sel; sel.cursor = textCursor(); sel.cursor.setPosition(position_start); sel.cursor.setPosition(position_end, QTextCursor::KeepAnchor); sel.format = highlighter->linkFormat; sel.format.setFontUnderline(true); setExtraSelections(QList<QTextEdit::ExtraSelection>() << sel); //Underlining link viewport()->setCursor(Qt::PointingHandCursor); } else { setExtraSelections(QList<QTextEdit::ExtraSelection>()); //Clearing viewport()->setCursor(Qt::IBeamCursor); } QTextEdit::mouseMoveEvent(e); }
void CodeEditor::dropEvent(QDropEvent *event) { QTextCursor insertingCursor = cursorForPosition(event->pos()); insertingCursor.insertText(event->mimeData()->text()); setTextCursor(insertingCursor); event->acceptProposedAction(); }
void TCommandLine::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::RightButton) { QTextCursor c = cursorForPosition(event->pos()); c.select(QTextCursor::WordUnderCursor); if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) { char** sl; mHunspellSuggestionNumber = Hunspell_suggest(mpHunspell, &sl, c.selectedText().toLatin1().data()); auto popup = new QMenu(this); for (int i = 0; i < mHunspellSuggestionNumber; i++) { QAction* pA; pA = popup->addAction(sl[i]); connect(pA, &QAction::triggered, this, &TCommandLine::slot_popupMenu); } mpHunspellSuggestionList = sl; mPopupPosition = event->pos(); popup->popup(event->globalPos()); } event->accept(); return; } QPlainTextEdit::mousePressEvent(event); }
void OCamlSource::mousePressEvent ( QMouseEvent * e ) { QTextCursor current_cur = textCursor(); QTextCursor cur = cursorForPosition( e->pos() ); if ( current_cur.hasSelection() ) cur = current_cur; _breakpoint_line = cur.blockNumber() + 1; _breakpoint_column = cur.position() - cur.block().position() + 1; if ( ! cur.hasSelection() ) { cur.select(QTextCursor::WordUnderCursor); setTextCursor(cur); } _selected_text = cur.selectedText(); if ( e->button() == Qt::LeftButton ) { lineSearchArea->hide(); lineSearchArea->setEnabled(false); setFocus(); } if ( e->button() == Qt::MidButton ) { watchVar(); } else QPlainTextEdit::mousePressEvent(e); }
QMenu* PsiTextView::createStandardContextMenu(const QPoint &position) { QTextCursor textcursor = cursorForPosition(position); QMenu *menu; QString anc = anchorAt(position); if (!anc.isEmpty()) { menu = URLObject::getInstance()->createPopupMenu(anc); int posInBlock = textcursor.position() - textcursor.block().position(); QString textblock = textcursor.block().text(); int begin = textcursor.block().position() + textblock.lastIndexOf(QRegExp("\\s|^"), posInBlock) + 1; int end = textcursor.block().position() + textblock.indexOf(QRegExp("\\s|$"), posInBlock); textcursor.setPosition(begin); textcursor.setPosition(end, QTextCursor::KeepAnchor); setTextCursor(textcursor); menu = URLObject::getInstance()->createPopupMenu(anc); } else { if (isSelectedBlock() || !textCursor().hasSelection()) { // only if no selection we select text block int begin = textcursor.block().position(); int end = begin + textcursor.block().length() - 1; textcursor.setPosition(begin); textcursor.setPosition(end, QTextCursor::KeepAnchor); setTextCursor(textcursor); } menu = QTextEdit::createStandardContextMenu(); } return menu; }
void RZQtCodeEditor::mouseReleaseEvent ( QMouseEvent * event ) { if (!m_mouseMoved) { QTextCursor c = cursorForPosition(event->pos()); emit clicked(event->pos(), c.position()); } }
void CCodeEdit::mousePressLineNumEvent(QMouseEvent* event) { if( m_lineIconSize.width() < event->x() ) { QPoint pt(0, event->y()); QTextCursor cursor = cursorForPosition(pt); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); setTextCursor(cursor); } else { // アイコン部分がクリックされた QPoint pt(0, event->y()); QTextCursor cursor = cursorForPosition(pt); emit pressIconArea(cursor.blockNumber()); } }
void HaiQTextEdit::contextMenuEvent(QContextMenuEvent *event) { //QTextEdit::contextMenuEvent(event); if (textCursor().selectedText().isEmpty()) setTextCursor(cursorForPosition(event->pos())); qApp->processEvents(); emit context_menu(event->globalPos()); }
void MorphologyViewer::mouseMoveEvent(QMouseEvent *e) { ExtraSelection current; QTextCursor cursor = cursorForPosition(e->pos()); cursor.select(QTextCursor::WordUnderCursor); current.cursor = cursor; current.format = *selectedFormat; setExtraSelections(QList<ExtraSelection>() << current); }
void MorphologyViewer::mousePressEvent(QMouseEvent *e) { QTextCursor cursor = cursorForPosition(e->pos()); cursor.select(QTextCursor::WordUnderCursor); QString word = cursor.selectedText(); if (!word.isEmpty()){ this->setToolTip(getToolTip(word)); toolTipPos = e->globalPos(); } }
void XTextEdit::sIgnoreWord() { QTextCursor cursor = cursorForPosition(_lastPos); QString textBlock = cursor.block().text(); int pos = cursor.columnNumber(); int end = textBlock.indexOf(QRegExp("\\W+"),pos); int begin = textBlock.left(pos).lastIndexOf(QRegExp("\\W+"),pos); textBlock = textBlock.mid(begin+1,end-begin-1); _guiClientInterface->hunspell_ignore(textBlock); _highlighter->rehighlight(); }
bool ScriptEditorWidget::contextSensitiveHelp() const { QRect r = cursorRect(); QTextCursor cur = cursorForPosition(QPoint(r.x(), r.y())); cur.select(QTextCursor::WordUnderCursor); QString szText = cur.selectedText(); QString szTmp = szText; return true; }
void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData()); if (!mime) QPlainTextEdit::dragMoveEvent(event); else { setTextCursor (cursorForPosition (event->pos())); event->accept(); } }
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const { QTextCursor cursor(cursorForPosition(pos)); QTextBlock block(cursor.block()); QTextBlock::iterator it; for (it = block.begin(); !(it.atEnd()); ++it) { QTextFragment frag = it.fragment(); if (frag.contains(cursor.position())) return frag; } return QTextFragment(); }
/** Reimplementation to insert the text of a dragged reference into the edit view. */ void CPlainWriteDisplay::dragMoveEvent( QDragMoveEvent* e ) { if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) { //placeCursor(e->pos()); setTextCursor(cursorForPosition(e->pos())); ensureCursorVisible(); e->acceptProposedAction(); } else { //e->accept(false); e->ignore(); } }
void XTextEdit::sCorrectWord() { QAction *action = qobject_cast<QAction *>(sender()); if (action) { QString replacement = action->text(); QTextCursor cursor = cursorForPosition(_lastPos); cursor.select(QTextCursor::WordUnderCursor); cursor.deleteChar(); cursor.insertText(replacement); _highlighter->rehighlight(); } }
void MarkdownEditor::contextMenuEvent( QContextMenuEvent *e ) { // copy as Html e->accept(); QMenu *menu = createStandardContextMenu(); menu->addSeparator(); QAction *spellCheckStatusAction = new QAction( tr( "Check spelling" ), menu ); spellCheckStatusAction->setCheckable( true ); spellCheckStatusAction->setChecked( !spellCheckLanguage.isEmpty() ); menu->addAction( spellCheckStatusAction ); QList<QAction *> spellCheckLanguageActions = addSpellCheckLanguageActions( menu ); menu->addSeparator(); copyAsHtmlAction->setEnabled( textCursor().hasSelection() ); menu->addAction( copyAsHtmlAction ); QList<QAction *> spellCheckActions; if ( e->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection() ) { setTextCursor( cursorForPosition( e->pos() ) ); spellCheckActions = addSpellCheckActions( menu ); } QAction *selected = menu->exec( e->globalPos() ); if ( selected ) { if ( spellCheckActions.indexOf( selected ) != -1 ) { replaceTextInCurrentCursor( selected->text() ); } else if ( selected == spellCheckStatusAction ) { if ( selected->isChecked() ) { //enable spell check spellCheckLanguage = conf->getSpellCheckLanguage(); if ( conf->getSpellCheckLanguage().isEmpty() ) { spellCheckLanguage = conf->getAllAvailableSpellCheckDictNames().first(); } enableSpellCheck(); } else {//disable spell check spellCheckLanguage.clear(); disableSpellCheck(); } } else if ( spellCheckLanguageActions.indexOf( selected ) != -1 && selected->data().canConvert( QVariant::String ) && !selected->data().toString().isEmpty() && selected->data().toString() != spellCheckLanguage ) { disableSpellCheck(); spellCheckLanguage = selected->data().toString(); enableSpellCheck(); } } menu->deleteLater(); }
bool TextEdit::event(QEvent* event) { if(event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); QTextCursor cursor = cursorForPosition(helpEvent->pos()); cursor.select(QTextCursor::WordUnderCursor); QToolTip::showText(helpEvent->globalPos(), cursor.selectedText()); return true; } return QTextEdit::event(event); }
/* void ScriptEditorWidget::mouseReleaseEvent(QMouseEvent * e) { return; QRect r = cursorRect(); QTextCursor cur = cursorForPosition(e->pos()); // cur.select( //completelistbox->hide(); if (e->button() == Qt::RightButton) { QString szBuffer; /\* int iPara = paragraphAt(e->pos()); int iIndex=charAt(e->pos(),&iPara); szBuffer = this->text(iPara); getWordOnCursor(szBuffer,iIndex); *\/ QRect r = cursorRect(); QTextCursor cur = cursorForPosition(e->pos()); cur.select(QTextCursor::WordUnderCursor); szBuffer = cur.selectedText(); QString szTmp = szBuffer; KviPointerList<QString> * pList; if(szTmp.left(1) == "$") { szTmp.remove(0,1); pList = KviKvsKernel::instance()->completeCommandAllocateResult(szTmp); if (pList->count() != 1) szBuffer = ""; else szBuffer = *(pList->at(0)); } else { pList = KviKvsKernel::instance()->completeCommandAllocateResult(szTmp); if (pList->count() != 1) szBuffer = ""; else szBuffer = *(pList->at(0)); } for (unsigned int i=0; i < pList->count(); i++) QString str = *(pList->at(i)); KviKvsKernel::instance()->freeCompletionResult(pList); m_szHelp = szBuffer; } QTextEdit::mouseReleaseEvent(e); } */ bool ScriptEditorWidget::contextSensitiveHelp() const { /* QString szBuffer; int iPara, iIndex; getCursorPosition(&iPara,&iIndex); szBuffer = text(iPara); getWordOnCursor(szBuffer,iIndex); */ QRect r = cursorRect(); QTextCursor cur = cursorForPosition(QPoint(r.x(),r.y())); cur.select(QTextCursor::WordUnderCursor); QString szText = cur.selectedText(); QString szTmp = szText; /* KviPointerList<QString> * pList; if(szTmp.left(1) == "$") { szTmp.remove(0,1); pList = g_pUserParser->completeFunctionAllocateResult(szTmp); } else { pList = g_pUserParser->completeCommandAllocateResult(szTmp); } qDebug("command or func %s",szTmp.toUtf8().data()); bool bOk = false; if(pList) { for(QString * s = pList->first(); s; s = pList->next()) { if(KviQString::equalCI(*s,szBuffer)) { pList->last(); bOk = true; } } } g_pUserParser->freeCompletionResult(pList); if(!bOk)return false; QString szParse = QString("timer -s (help,0){ help -s %Q; }").arg(szBuffer); qDebug("parsing %s",szParse.toLatin1()); KviKvsScript::run(szParse,(KviWindow*)g_pApp->activeConsole()); */ return true; }
void TCommandLine::slot_popupMenu() { auto* pA = qobject_cast<QAction*>(sender()); if (!pA) { return; } QString t = pA->text(); QTextCursor c = cursorForPosition(mPopupPosition); c.select(QTextCursor::WordUnderCursor); c.removeSelectedText(); c.insertText(t); c.clearSelection(); Hunspell_free_list(mpHunspell, &mpHunspellSuggestionList, mHunspellSuggestionNumber); }
void ScCodeEditor::mouseDoubleClickEvent( QMouseEvent * e ) { if (e->button() == Qt::LeftButton) { QTextCursor cursor = cursorForPosition(e->pos()); QTextCursor selection = selectionForPosition( cursor.position() ); if (!selection.isNull()) { mMouseBracketMatch = true; setTextCursor(selection); return; } } GenericCodeEditor::mouseDoubleClickEvent(e); }
void ScCodeEditor::mouseDoubleClickEvent( QMouseEvent * e ) { // Always pass to superclass so as to handle line selection on triple click GenericCodeEditor::mouseDoubleClickEvent(e); if (e->button() == Qt::LeftButton) { QTextCursor cursor = cursorForPosition(e->pos()); QTextCursor selection = selectionForPosition( cursor.position() ); if (!selection.isNull()) { mMouseBracketMatch = true; setTextCursor(selection); return; } } }
void SourceWindow::infoMousePress(QMouseEvent* ev) { // we handle left and middle button if (ev->button() != Qt::LeftButton && ev->button() != Qt::MidButton) { return; } // get row int row = cursorForPosition(QPoint(0, ev->y())).blockNumber(); if (row < 0) return; if (ev->x() > m_widthItems) { if (isRowExpanded(row)) { actionCollapseRow(row); } else { actionExpandRow(row); } return; } int sourceRow; int line = rowToLine(row, &sourceRow); // find address if row is disassembled code DbgAddr address; if (row > sourceRow) { // get offset from source code line int off = row - sourceRow; address = m_sourceCode[line].disassAddr[off-1]; } switch (ev->button()) { case Qt::LeftButton: TRACE(QString().sprintf("left-clicked line %d", line)); emit clickedLeft(m_fileName, line, address, (ev->modifiers() & Qt::ShiftModifier) != 0); break; case Qt::MidButton: TRACE(QString().sprintf("mid-clicked row %d", line)); emit clickedMid(m_fileName, line, address); break; default:; } }