Beispiel #1
0
void MainWindow::displayTooltip(QMouseEvent *e)
{
    static bool isFirstTime = true;
    static int selectionStart;
    static QString selectedText;
    static bool isExisted = false; //мы выделяли существующее в словаре?
    bool isExist = false;
    int i;

    QPoint p = e->pos();

    QTextCursor tc = ui->textEdit->cursorForPosition(p);
    tc.select(QTextCursor::WordUnderCursor);

    if (selectionStart != tc.selectionStart()) {

        //проверяем, есть ли слово в словаре
        for(i = 0; i < bptr->getListWords().size(); i++)
        {
            if(!bptr->getListWords().at(i).word.compare(tc.selectedText(), Qt::CaseInsensitive))
            {
                isExist = true;
                break;
            }
            if(!bptr->getListWords().at(i).word.compare(selectedText, Qt::CaseInsensitive))
            {
                isExisted = true;
            }
        }

        if (!isFirstTime)
        {
            QToolTip::hideText();   //скрываем предыдущий тултип
            //Надо удалить выделение предыдущего слова
            QTextCursor tc(ui->textEdit->document());
            tc.setPosition(selectionStart);
            tc.select(QTextCursor::WordUnderCursor);

            if(isExisted)
                tc.insertHtml(QString("<u>" + selectedText + "</b>"));
            else
            {
                tc.insertHtml(QString(selectedText));
            }
            isExisted = false;
        }
        selectionStart = tc.selectionStart();
        selectedText = tc.selectedText();

        if (tc.selectedText().length() > 0 && isExist)
        {
//            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
//                               ui->textEdit, ui->textEdit->cursorRect());
            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
                               ui->textEdit, ui->textEdit->cursorRect(tc));
            isFirstTime = false;
            tc.insertHtml(QString("<b>" + tc.selectedText() + "</b>"));
        }
    }
}
Beispiel #2
0
void CSVImportDialog::createCSVImportView(QString filenamein)
{
    QFile file(filenamein);
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        // read file
        ui->csvTextEdit->setText(file.readAll());
    }

    this->setWindowTitle("CSV Import - " + filenamein);

    QTextCursor cursor = ui->csvTextEdit->textCursor();
    QTextCharFormat format;

    cursor.select(QTextCursor::Document);
    format.setForeground( QBrush( QColor( "black" ) ) );
    format.setFontStrikeOut(false);
    cursor.setCharFormat( format );

    for(int i=0; i<ui->lineskipSpinBox->value(); i++){
        format.setForeground( QBrush( QColor( "red" ) ) );
        format.setFontStrikeOut(true);
        cursor.movePosition(QTextCursor::Start);
        cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, i);
        cursor.select(QTextCursor::LineUnderCursor);
        cursor.setCharFormat( format );
    }

}
Beispiel #3
0
void TabTerminal::_clearLine()
{
	QTextCursor c = this->textCursor();
	c.select(QTextCursor::LineUnderCursor);
	c.removeSelectedText();
	this->insertHtml(_userPrompt);
}
Beispiel #4
0
void TCommandLine::spellCheck()
{
    if (!mpHost->mEnableSpellCheck) {
        return;
    }

    QTextCursor oldCursor = textCursor();
    QTextCharFormat f;
    auto cred = QColor(Qt::red);
    f.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
    f.setUnderlineColor(cred);
    QTextCursor c = textCursor();
    c.select(QTextCursor::WordUnderCursor);

    if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
        f.setFontUnderline(true);
        c.setCharFormat(f);
    } else {
        f.setFontUnderline(false);
        c.setCharFormat(f);
    }
    setTextCursor(c);
    f.setFontUnderline(false);
    oldCursor.setCharFormat(f);
    setTextCursor(oldCursor);
}
void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
}
Beispiel #6
0
void DrugInputEdit::mouseReleaseEvent(QMouseEvent *event) {
    Q_UNUSED(event);
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::LineUnderCursor);
    QString name = tc.selectedText();
    emit drugNameChanged(name);
}
Beispiel #7
0
void MLEdit::contextMenuEvent(QContextMenuEvent* event)
{
  QMenu* menu=createStandardContextMenu();

  if (!isReadOnly())
  {
#ifdef HAVE_HUNSPELL
    // Save position so we know which word to replace
    myMenuPos = event->pos();

    // Get word under cursor
    QTextCursor cr = cursorForPosition(myMenuPos);
    cr.select(QTextCursor::WordUnderCursor);
    QString word = cr.selectedText();
    if (!word.isEmpty())
    {
      // Get spelling suggestions
      QStringList suggestions = mySpellChecker->getSuggestions(word);
      if (!suggestions.isEmpty())
      {
        // Add spelling suggestions at the top of the menu
        QAction* firstAction = menu->actions().first();
        foreach (QString w, suggestions)
        {
          QAction* a = new QAction(w, menu);
          connect(a, SIGNAL(triggered()), SLOT(replaceWord()));
          menu->insertAction(firstAction, a);
        }
Beispiel #8
0
void RtfCssEditor::insertBrace() {
  if (c->widget() != this)
    return;
  QTextCursor tc = textCursor();
  int currentPos = tc.position();
  tc.movePosition(QTextCursor::Down);
  tc.select(QTextCursor::LineUnderCursor);
  if (tc.selectedText().isEmpty() == true) {
    tc.setPosition(currentPos);
    //if (QTextCursor::NextWord)
    tc.insertText("\n    \n}");
    /*tc.movePosition(QTextCursor::Left);
    tc.movePosition(QTextCursor::Left);*/
    tc.movePosition(QTextCursor::Left);
    tc.movePosition(QTextCursor::Left);
    setTextCursor(tc);
    QRect cr = cursorRect();
    cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
    c->complete(cr); // popup it up!
  }
  else {
    tc.setPosition(currentPos);
    tc.insertText("\n    ");
  }
  tc.movePosition(QTextCursor::EndOfWord);
  QRect cr = cursorRect();
  cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
  c->complete(cr); // popup it up!
    
}
void XYZTextEditor::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
    QTextCursor cursor = m_ui->textEdit->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    m_ui->textEdit->mergeCurrentCharFormat(format);
}
Beispiel #10
0
void BAbstractFileType::showAutocompletionMenu(BAbstractCodeEditorDocument *doc, QTextCursor cursor, const QPoint &)
{
    if (cursor.isNull())
        return;
    QCompleter *completer = doc->findChild<QCompleter *>("beqt/completer");
    cursor.select(QTextCursor::WordUnderCursor);
    if (!cursor.hasSelection()) {
        if (completer)
            completer->popup()->hide();
        return;
    }
    QList<AutocompletionItem> list = createAutocompletionItemList(doc, cursor);
    if (list.isEmpty()) {
        if (completer)
            completer->popup()->hide();
        return;
    }
    QStandardItemModel *model = doc->findChild<QStandardItemModel *>("beqt/completion_model");
    if (!model) {
        model = new QStandardItemModel(doc);
        model->setObjectName("beqt/completion_model");
        model->setColumnCount(1);
    }
    model->clear();
    foreach (const AutocompletionItem &item, list) {
        QStandardItem *si = new QStandardItem(item.actionIcon, item.actionText);
        si->setData(item.actionToolTip, Qt::ToolTipRole);
        si->setData(item.text, Qt::UserRole);
        model->appendRow(si);
    }
void ConsoleWidget::handleHistory(bool down)
{
    int index;
    moveCursor(QTextCursor::End);
    QTextCursor cursor = textCursor();

    if (m_history.size()==0)
        return;

    if (down)
        m_histIndex--;
    else
        m_histIndex++;

    if (m_histIndex>m_history.size()-1)
        m_histIndex = m_history.size()-1;
    if (m_histIndex<0)
        m_histIndex = 0;
    index = m_history.size()-1-m_histIndex;

    cursor.select(QTextCursor::LineUnderCursor);
    cursor.removeSelectedText();

    handleColor();
    insertPlainText(m_prompt + m_history[index]);
    moveCursor(QTextCursor::End);
}
Beispiel #12
0
void Notepad::showNotepadContextMenu(const QPoint &pt)
{
    // Set Notepad popup menu
    QMenu *menu = ui->notepadTextEdit->createStandardContextMenu();
    QTextCursor cur = ui->notepadTextEdit->textCursor();
    QAction* first = menu->actions().at(0);

    if (cur.hasSelection()) {
        // Get selected text
        //this->main->add_debug_output("Selected text: " + cur.selectedText());
        this->addr = cur.selectedText();
    } else {
        // Get word under the cursor
        cur.select( QTextCursor::WordUnderCursor);
        //this->main->add_debug_output("Word: " + cur.selectedText());
        this->addr = cur.selectedText();
    }
    ui->actionDisassmble_bytes->setText( "Disassemble bytes at: " + this->addr);
    ui->actionDisassmble_function->setText( "Disassemble function at: " + this->addr);
    ui->actionHexdump_bytes->setText( "Hexdump bytes at: " + this->addr);
    ui->actionCompact_Hexdump->setText( "Compact Hexdump at: " + this->addr);
    ui->actionHexdump_function->setText( "Hexdump function at: " + this->addr);
    menu->insertAction(first, ui->actionDisassmble_bytes);
    menu->insertAction(first, ui->actionDisassmble_function);
    menu->insertAction(first, ui->actionHexdump_bytes);
    menu->insertAction(first, ui->actionCompact_Hexdump);
    menu->insertAction(first, ui->actionHexdump_function);
    menu->insertSeparator(first);
    ui->notepadTextEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
    menu->exec(ui->notepadTextEdit->mapToGlobal(pt));
    delete menu;
    ui->notepadTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
}
Beispiel #13
0
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();
       }
   }
Beispiel #14
0
void GLFOutputWindow::printMessage(const char* message)
{
    static int index = 1;
    // Remove the first few lines when the buffer is overflow.
    int nlines = _pTextEdit->document()->lineCount();
    if (nlines > MAX_NUM_LINES)
    {
        int deleteNumLines = nlines / 2;
        for (int i = 0; i < deleteNumLines; ++i)
        {
            QTextCursor tc = _pTextEdit->textCursor();

            tc.movePosition(QTextCursor::Start);
            tc.select(QTextCursor::LineUnderCursor);
            tc.removeSelectedText();
        }

        QTextCursor tc = _pTextEdit->textCursor();
        tc.movePosition(QTextCursor::End);
        _pTextEdit->setTextCursor(tc);            
    }

    // Insert the new message
    char buffer[1024];
    sprintf(buffer, "%d: %s", index++, message);
    _pTextEdit->insertPlainText(QString(buffer));

    // Scroll to the bottom
    QScrollBar *sb = _pTextEdit->verticalScrollBar();
    sb->setValue(sb->maximum());
}
Beispiel #15
0
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
    if (sender == ui->messagePlainTextEdit) {
        if (event->type() != QEvent::KeyPress) {
            return false;
        }
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
            (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
            QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
            if (!messageText.isEmpty()) {
#ifdef HAVE_QXMPP
                const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
                QXmppMessage message;
                message.setTo(publicChatRoom->jid());
                message.setType(QXmppMessage::GroupChat);
                message.setBody(messageText);
                XmppClient::getInstance().getXMPPClient().sendPacket(message);
#endif // HAVE_QXMPP
                QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
                cursor.select(QTextCursor::Document);
                cursor.removeSelectedText();
            }
            return true;
        }
    } else if (event->type() == QEvent::MouseButtonRelease) {
        QVariant userVar = sender->property("user");
        if (userVar.isValid()) {
            AddressManager::getInstance().goToUser(userVar.toString());
            return true;
        }
    }
    return QWidget::eventFilter(sender, event);
}
Beispiel #16
0
void MibEditor::Find(bool reevaluate)
{
    QTextCursor tc;

    if (reevaluate)
    {
        ff = 0;
        find_string = find_uid.comboFind->currentText();
        if (!find_strings.contains(find_string))
            find_strings.append(find_string);

        if (find_uid.checkWords->isChecked())
            ff |= QTextDocument::FindWholeWords;
        if (find_uid.checkCase->isChecked())
            ff |= QTextDocument::FindCaseSensitively;
        if (find_uid.checkBackward->isChecked())
            ff |= QTextDocument::FindBackward;
    }

    tc = s->MainUI()->MIBFile->document()->find(find_string, 
                                                s->MainUI()->MIBFile->textCursor(), 
                                                ff);

    if (!tc.isNull())
    {
        s->MainUI()->MIBFile->setTextCursor(tc);
        tc.select(QTextCursor::WordUnderCursor);
    }
}
Beispiel #17
0
void ElementTitle::startTextInteraction()
{
	// Already interacting?
	if (hasFocus())
		return;

	mOldText = toHtml();

	// Clear scene selection
	//if (!(event->modifiers() & Qt::ControlModifier)) - was here.
	scene()->clearSelection();
	parentItem()->setSelected(true);

	if (mReadOnly)
		setTextInteractionFlags(Qt::TextBrowserInteraction);
	else
		setTextInteractionFlags(Qt::TextEditorInteraction);
	setFocus(Qt::OtherFocusReason);

	// Set full text selection
	QTextCursor cursor = QTextCursor(document());
	cursor.select(QTextCursor::Document);
	setTextCursor(cursor);
	setCursor(Qt::IBeamCursor);
}
void MenuMainScreen::setCurrentOption(QGraphicsSimpleTextItem *option) {
	QBrush whiteBrush(Qt::white);
	QBrush yellowBrush(Qt::yellow);

	if (!!_currentOption)
		_currentOption->setBrush(whiteBrush);

	_currentOption = option;
	_currentOption->setBrush(yellowBrush);

	if (option->text() == QString("Character"))
		_textField->setPlainText("View more information about the selected character.");
	else if (option->text() == QString("Equipment"))
		_textField->setPlainText("View or change the equipment the selected character is wearing.");
	else if (option->text() == QString("Abilities"))
		_textField->setPlainText("View the abilities of the selected character.");
	else if (option->text() == QString("Inventory"))
		_textField->setPlainText("View the items collected by the party.");
	else if (option->text() == QString("Exit"))
		_textField->setPlainText("Exit the menu.");

	QFont font("Times", 12, QFont::Bold);
	_textField->setFont(font);

	QTextBlockFormat format;
	format.setAlignment(Qt::AlignLeft);
	QTextCursor cursor = _textField->textCursor();
	cursor.select(QTextCursor::Document);
	cursor.mergeBlockFormat(format);
	cursor.clearSelection();
	_textField->setTextCursor(cursor);
}
Beispiel #19
0
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();
}
Beispiel #20
0
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);
}
Beispiel #21
0
void SimPrologEdit::keyPressEvent(QKeyEvent *e)
{
    switch (e->key()) {

    case Qt::Key_F1: {
        QTextCursor c = textCursor();
        c.select(c.WordUnderCursor);
        QString s = c.selectedText();
        if (s.length())
            for (QWidget *w = this; w; w = w->parentWidget())
                if (auto m = qobject_cast<spqrMainWindow*>(w)) {
                    m->activate(m->t_helpdoc);
                    m->helpDoc()->setUrl(
                        QString("http://localhost:%1/search?for=%2&in=all&match=summary")
                                .arg(m->DOC_PORT).arg(s));
                    break;
                }
    }   break;

    case Qt::Key_Tab:
        e->ignore();
        return;
    case Qt::Key_Backtab:
        e->ignore();
        return;
    }

    SimPrologEditBase::keyPressEvent(e);
}
QString CWidgetReturnEmitTextEdit::textUnderCursor() const
{
	QTextCursor tc = textCursor();
	tc.select(QTextCursor::WordUnderCursor);

	// Save selected positions of current word.
	int selectionStart = tc.selectionStart();
	int selectionEnd = tc.selectionEnd();

	// If selection is at beginning of text edit then there can't be a slash to check for
	if (selectionStart == 0)
		return tc.selectedText();

	// Modify selection to include previous character
	tc.setPosition(selectionStart - 1, QTextCursor::MoveAnchor);
	tc.setPosition(selectionEnd, QTextCursor::KeepAnchor);

	// If previous character was / return current selection for command completion
	if(tc.selectedText().startsWith('/'))
		return tc.selectedText();
	else {
		// Else restore original selection and return for nick completion
		tc.setPosition(selectionStart, QTextCursor::MoveAnchor);
		tc.setPosition(selectionEnd, QTextCursor::KeepAnchor);
		return tc.selectedText();
	}
}
Beispiel #23
0
QString CodeArea::textUnderCursor() const
{
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::WordUnderCursor);

    return tc.selectedText();
}
Beispiel #24
0
void QtChatWindow::beginCorrection() {
	boost::optional<AlertID> newCorrectingAlert;
	if (correctionEnabled_ == Maybe) {
		newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
	}
	else if (correctionEnabled_ == No) {
		newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction.  If you send a correction anyway, it will appear as a duplicate message")));
	}

	if (newCorrectingAlert) {
		if (correctingAlert_) {
			removeAlert(*correctingAlert_);
		}
		correctingAlert_ = newCorrectingAlert;
	}

	QTextCursor cursor = input_->textCursor();
	cursor.select(QTextCursor::Document);
	cursor.beginEditBlock();
	cursor.insertText(QString(lastSentMessage_));
	cursor.endEditBlock();
	isCorrection_ = true;
	correctingLabel_->show();
	input_->setStyleSheet(alertStyleSheet_);
	labelsWidget_->setEnabled(false);
}
Beispiel #25
0
void DrugInputEdit::handleCompleteDrugName(QString addName) {
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::LineUnderCursor);
    tc.removeSelectedText();
    tc.insertText(addName + "\n");
    setTextCursor(tc);
}
Beispiel #26
0
void ExpressTextEdit::mouseMoveEvent(QMouseEvent *e)
{
    QTextCursor cursor = cursorForPosition(e->pos());
    cursor.select(QTextCursor::WordUnderCursor);
    QString wordUnderCursor = cursor.selectedText();

    const EntityDescriptor * entityDescriptor = m_Registry->FindEntity(wordUnderCursor.toAscii());
    const TypeDescriptor * typeDescriptor = m_Registry->FindType(wordUnderCursor.toAscii());
    if (entityDescriptor )
    {
        std::string str;
        setToolTip(entityDescriptor->GenerateExpress(str));
        if (QApplication::overrideCursor()==0)
            QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
    }
    else if(typeDescriptor)
    {
        std::string str;
        setToolTip(typeDescriptor->GenerateExpress(str));
        if (QApplication::overrideCursor()==0)
            QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
    }
    else
    {
        setToolTip(QString());
        QApplication::restoreOverrideCursor();
    }
}
/** \brief Anhängen einer Zeile ans Ende.

  Am Ende der Ausgabe wird immer ein Newline + Prompt ausgegeben!
*/
void QCommandPrompt::write(QString sMsg, QColor /*col*/)
{
    // Überprüfen, ob die Zeile mit einem Prompt anfängt
    QTextCursor tc = textCursor();
    tc.movePosition(QTextCursor::StartOfLine);
    tc.select(QTextCursor::LineUnderCursor);
    tc.removeSelectedText();
    setTextCursor(tc);

    // old: simple text
    insertPlainText(sMsg + "\n" + m_sPrompt);
/*
    // colored version
    QBrush brush(Qt::SolidPattern);
    brush.setColor(col);

    QTextCharFormat fmt;
    fmt.setForeground(brush);
    tc.insertText(sMsg + "\n", fmt);

    brush.setColor(m_colDefault);
    fmt.setForeground(brush);
    tc.insertText(m_sPrompt, fmt);
*/
    m_nPromptPos = tc.position();

    ensureCursorVisible();
}
Beispiel #28
0
void GolangEdit::findLinkOutput(QByteArray data, bool bStdErr)
{
    if (bStdErr) {
        return;
    }

    if ( m_editor == m_liteApp->editorManager()->currentEditor()) {
        QTextCursor cur = this->textCursorForPos(QCursor::pos());
        cur.select(QTextCursor::WordUnderCursor);
        if (cur.selectionStart() == m_linkCursor.selectionStart() &&
                cur.selectionEnd() == m_linkCursor.selectionEnd()) {
            QStringList info = QString::fromUtf8(data).trimmed().split("\n");
            if (info.size() == 2) {
                if (info[0] != "-") {
                    QRegExp reg(":(\\d+):(\\d+)");
                    int pos = reg.lastIndexIn(info[0]);
                    if (pos >= 0) {
                        QString fileName = info[0].left(pos);
                        int line = reg.cap(1).toInt();
                        int col = reg.cap(2).toInt();
                        LiteApi::Link link(fileName,line-1,col-1);
                        m_lastCursor.select(QTextCursor::WordUnderCursor);
                        link.linkTextStart = m_linkCursor.selectionStart();
                        link.linkTextEnd = m_linkCursor.selectionEnd();
                        m_lastLink = link;
                        m_editor->showLink(link);
                    }
                }
                QRect rc = m_plainTextEdit->cursorRect(m_linkCursor);
                QPoint pt = m_plainTextEdit->mapToGlobal(rc.topRight());
                QToolTip::showText(pt,info[1],m_plainTextEdit);
            }
        }
    }
}
Beispiel #29
0
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);
}
//init font size
void TextEdit::iniFontSize(){
  //the document contains 50 lines
  cout<<"#textedit::inifontsize";
  QString s="12";
  qreal pointSize = s.toFloat();
  QTextCharFormat fmt;
  fmt.setFontPointSize(pointSize);
  //QColor col = Qt::red;
  //fmt.setForeground(col);
  ///textEdit->setCurrentCharFormat(fmt);

  //cursor is the main widget which handle document editing
  QTextCursor cursor = textEdit->textCursor();
  //cursor.setPosition(120,QTextCursor::MoveAnchor);
  //cursor.movePosition(QTextCursor::NoMove,QTextCursor::KeepAnchor,100000);//textEdit->document().length());
  ////mergeFormatOnWordOrSelection(fmt);

  //cursor has four selection type: the last one select the entire document
  cursor.select(QTextCursor::Document);
  cursor.mergeCharFormat(fmt);
  //  QTextBlock block=cursor.block();
  //  cout<<"TextEdit.initFontSize:the block start and length:";
  //  cout<<block.position()<<","<<block.length();
  //  cout<<"TextEdit.initFontSize:the block text:"<<block.text();
  //cursor.setPosition(0);
}