Beispiel #1
0
bool MsgViewBase::findMessage(Message *msg)
{
    bool bFound = false;
    for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        if (bFound){
            setCursorPosition(i, 0);
            moveCursor(MoveBackward, false);
            ensureCursorVisible();
            return true;
        }
        string client;
        if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client()))
            continue;
        setCursorPosition(i, 0);
        ensureCursorVisible();
        bFound = true;
    }
    if (!bFound)
        return false;
    moveCursor(MoveEnd, false);
    ensureCursorVisible();
    return true;
}
Beispiel #2
0
bool MsgViewBase::findMessage(Message *msg)
{
    bool bFound = false;
    for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_HREF);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_HREF));
        n = s.find("\"");
        if (n < 0)
            continue;
        if (bFound){
            setCursorPosition(i, 0);
            moveCursor(MoveBackward, false);
            ensureCursorVisible();
            return true;
        }
        s = s.left(n);
        unsigned id = atol(getToken(s, ',').latin1());
        if (id != msg->id())
            continue;
        getToken(s, ',');
        if (s != msg->client())
            continue;
        setCursorPosition(i, 0);
        ensureCursorVisible();
        bFound = true;
    }
    if (!bFound)
        return false;
    moveCursor(MoveEnd, false);
    ensureCursorVisible();
    return true;
}
Beispiel #3
0
CodeEditor::CodeEditor(Config* config, QWidget* parent)
    : QPlainTextEdit(parent), config(config)
{
    highlighter = new Highlighter(config, this); // тормоз

    extraArea = new QWidget(this);
    extraArea->setCursor(Qt::PointingHandCursor);
    extraArea->setAutoFillBackground(true);
    extraArea->installEventFilter(this);

    completer = new QCompleter(config->keywordsSorted, this);
    completer->setWidget(this);
    completer->setCompletionMode(QCompleter::PopupCompletion);
    completer->setWrapAround(false);

    setLineWrapMode(QPlainTextEdit::NoWrap);
    setCursorWidth(2);
    blockCountChanged(0);
    setMouseTracking(true);

    reconfig();

    // не допускаем проваливание на последнем свернутом блоке
    connect(this,       SIGNAL(cursorPositionChanged()),       SLOT(ensureCursorVisible()));
    connect(this,       SIGNAL(blockCountChanged(int)),        SLOT(blockCountChanged(int)));
    connect(document(), SIGNAL(contentsChange(int, int, int)), SLOT(contentsChange(int, int, int)));
    connect(completer,  SIGNAL(activated(const QString&)),     SLOT(insertCompletion(const QString&)));
    connect(config,     SIGNAL(reread(int)),                   SLOT(reconfig(int)));
    connect(this,       SIGNAL(updateRequest(QRect, int)), extraArea, SLOT(update()));
}
Beispiel #4
0
// Result received
void Console::result(QString result) {
  insertPlainText(result);
  insertPlainText("\n");
  insertPlainText(userPrompt);
  ensureCursorVisible();
  locked = false;
}
Beispiel #5
0
void FocusedTextEdit::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Escape) {
        emit escapePressed();
        return;
    }

    if (m_disableUpdatesOnKeyPress)
        setUpdatesEnabled(false);

    KTextEdit::keyPressEvent(event);

    // Workaround (for ensuring the cursor to be visible): signal not emitted when pressing those keys:
    if (event->key() == Qt::Key_Home
            || event->key() == Qt::Key_End
            || event->key() == Qt::Key_PageUp
            || event->key() == Qt::Key_PageDown)
        emit cursorPositionChanged();


    if (m_disableUpdatesOnKeyPress) {
        setUpdatesEnabled(true);
        if (!document()->isEmpty())
            ensureCursorVisible();
    }
}
Beispiel #6
0
void TabTerminal::_insertPrompt()
{
	QTextCursor cursor = textCursor();
	cursor.insertBlock();
	insertHtml(_userPrompt);
	ensureCursorVisible();
}
Beispiel #7
0
void TextShow::startSearch(int parag, int index)
{
    QString to_find_string = srchdialog->getText();
    if (doSearch(to_find_string, srchdialog->case_sensitive(), (!srchdialog->get_direction()), &parag, &index)){
        setSelection(parag, index, parag, index + to_find_string.length());
        setCursorPosition(parag, index + to_find_string.length());
        ensureCursorVisible();
        return;
    }
    if (!srchdialog->isVisible()){
        QApplication::beep();
        return;
    }
    QStringList btns;
    btns.append(i18n("&Yes"));
    btns.append(i18n("&No"));

    QObjectList *l = srchdialog->queryList("QPushButton");
    QObjectListIt it( *l );
    if (it.current() == 0){
        delete l;
        QApplication::beep();
        return;
    }
    QPushButton *btnOK = static_cast<QPushButton*>(it.current());
    delete l;
    QRect rc = btnOK->rect();
    rc.moveTopLeft(btnOK->mapToGlobal(rc.topLeft()));
    BalloonMsg *msg = new BalloonMsg(!srchdialog->get_direction() ?
                                     i18n("End of document reached.\nContinue from the beginning?") :
                                     i18n("Beginning of document reached.\nContinue from the end?"),
                                     rc, btns, this);
    connect(msg, SIGNAL(action(int)), this, SLOT(searchAgain(int)));
    msg->show();
}
Beispiel #8
0
void tekOutput::printDate()
{
	QDateTime tmdt = QDateTime::currentDateTime();
	appendPlainText(tr("Date:") + getDate(tmdt) + tr("\n") +
					tr("Time: ")+ getTime(tmdt) + tr("\n"));
	ensureCursorVisible();
}
Beispiel #9
0
void TextShow::resizeEvent(QResizeEvent *e)
{
#ifdef WIN32
	if (inResize()){
		if (!m_timer->isActive()){
			setHScrollBarMode(AlwaysOff);
			setVScrollBarMode(AlwaysOff);
			m_timer->start(100);
		}
		return;
	}
#endif
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
	int para;
    int pos = charAt(QPoint(x, y), &para);
    QTextEdit::resizeEvent(e);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
	sync();
	viewport()->repaint();
}
Beispiel #10
0
void Console::write(QString text) {
    QTextCursor* cursor = new QTextCursor(document());
    cursor->movePosition(QTextCursor::End);
    cursor->insertText(text);

    ensureCursorVisible();
}
/** \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();
}
void ByteArrayColumnViewPrivate::setActiveCoding( AbstractByteArrayView::CodingTypeId codingId )
{
    // no changes or not visible?
    if( codingId == activeCoding()
        || (codingId == AbstractByteArrayView::ValueCodingId && !mValueColumn->isVisible())
        || (codingId == AbstractByteArrayView::CharCodingId && !mCharColumn->isVisible()) )
        return;

    pauseCursor();
    mValueEditor->finishEdit();

    if( codingId == AbstractByteArrayView::ValueCodingId )
    {
        mActiveColumn = mValueColumn;
        mInactiveColumn = mCharColumn;
    }
    else
    {
        mActiveColumn = mCharColumn;
        mInactiveColumn = mValueColumn;
    }
    adaptController();

    ensureCursorVisible();
    unpauseCursor();
}
Beispiel #13
0
void Console::WriteOutput(QString out)
{
    activateWindow();
    moveCursor(QTextCursor::End);
    insertPlainText(out);
    ensureCursorVisible();
}
void WareSrcMsgViewer::clearMessages()
{
  clear();

  ensureCursorVisible();

  m_MessagesByBlockNumber.clear();
}
Beispiel #15
0
void ClientTextEdit::displayText(const QString& str) {
  // ANSI codes are formatted as the following:
  // escape + [ + n1 (+ n2) + m
  QRegExp ansiRx("\\0033\\[((?:\\d+;)*\\d+)m");
  QRegExp subBlockRx("\\0010");
  QStringList blocks = str.split(ansiRx);
  QStringList ansi, subAnsi, subBlock;
  int i = 0, j, k;

  ansi << "";
  while ((i = ansiRx.indexIn(str, i)) != -1) {
    ansi << ansiRx.cap(1);
    i += ansiRx.matchedLength();
  }

  for (i = 0; i < blocks.count(); i++) {
    // split several semicoloned ansi codes into individual codes
    subAnsi = ansi[i].split(";"); 
    QStringListIterator ansiIterator(subAnsi);
    while (ansiIterator.hasNext() && i != 0)
      updateFormat(_format, ansiIterator.next().toInt());

    // split the text into sub-blocks
    blocks[i].replace((char)20, " "); // replace hex-spaces with normal spaces

    if ((k = blocks[i].indexOf(subBlockRx)) != -1) {
      j = 0;
      do {
        //qDebug("j%d k%d %s", j, k, blocks[i].toAscii().data());
        if (blocks[i].length() > 2) { // this is for the "You begin to search.." etc lines
          _cursor.insertText(blocks[i].mid(j, k), _format);
          moveCursor(-1);
        } else {                     // HACK because the twiddler has a backspace following the twiddler character
          moveCursor(-1);
          _cursor.insertText(blocks[i].mid(j, k), _format);
        }
        j = k + 1;
      } while ((k = blocks[i].indexOf(subBlockRx, j)) != -1);
      _cursor.insertText(blocks[i].mid(j), _format);
    } else _cursor.insertText(blocks[i], _format);

    /*
    for (j = 0; (j = subBlockRx.indexIn(blocks[i], j)) != -1; j += subBlockRx.matchedLength()) {
    qDebug("%s", subBlock.join(",").toAscii().data());
      if (subBlockRx.cap(1).contains(QRegExp("\\0010"))) {
        _cursor.insertText(blockIterator.next(), _format);
        moveCursor(-1);
      }
      else {
        _cursor.insertText(blockIterator.next(), _format);
      }
    }
    */
  }
  setTextCursor(_cursor);
  ensureCursorVisible();

}
Beispiel #16
0
void HaiQTextEdit::goto_marker(QString id) {
	if (!marker_blocks.contains(id)) return;
	QTextBlock block=marker_blocks[id];
	defaultedit_blockdata *block_data=(defaultedit_blockdata *)block.userData();
	if (block_data) {
		setTextCursor(QTextCursor(block));
		ensureCursorVisible();
	}
}
Beispiel #17
0
void
chat::_cond_scroll() {
    if (_allow_scroll) {
        ACE_DEBUG((LM_DEBUG, "chat::_cond_scroll: scrolling to visible\n"));
        ensureCursorVisible();
    } else {
        ACE_DEBUG((LM_DEBUG, "chat::_cond_scroll: not scrolling to visible\n"));
        verticalScrollBar()->setValue(_saved_pre_insert_vertical_value);
    }
}
Beispiel #18
0
void TextEditor::focusPC() {
   if (m_program->getStatus() == PAUSED && m_pc != NULL) {
      QTextBlock *b = m_pc->getTextBlock();
      
      QTextCursor c = textCursor();
      c.setPosition(b->position());
      setTextCursor(c);
      ensureCursorVisible();
   }
}
Beispiel #19
0
void CodeEditor::gotoLine( int line ){

    QTextBlock block=document()->findBlockByNumber( line );

    setTextCursor( QTextCursor( block ) );

//    verticalScrollBar()->setValue( line );

    ensureCursorVisible();
}
Beispiel #20
0
bool EditWidget::OnKeyDown(int key, int mod)
{
	switch (key) {
	case SDLK_RETURN:
	case SDLK_KP_ENTER:
		parent->ChildNotify(this, EDIT_ENTER);
		break;
	case SDLK_ESCAPE:
		parent->ChildNotify(this, EDIT_ESCAPE);
		break;
	case SDLK_BACKSPACE:
		if (cursor > 0) {
			text.erase(--cursor, 1);
			FORGET_OBJECT(cached_text);
			ensureCursorVisible();
		}
		break;
	case SDLK_DELETE:
		if (cursor != text.size()) {
			text.erase(cursor, 1);
			FORGET_OBJECT(cached_text);
		}
		break;
	case SDLK_LEFT:
		if (cursor > 0) {
			cursor--;
			FORGET_OBJECT(cached_text);
			ensureCursorVisible();
		}
		break;
	case SDLK_RIGHT:
		if (cursor < text.size()) {
			cursor++;
			FORGET_OBJECT(cached_text);
			ensureCursorVisible();
		}
		break;
	default:
		break;
	}

	return true;
}
Beispiel #21
0
void BaseEditor::findFirstOccurrance(const QString &text, QTextDocument::FindFlags qff,
                                     bool isRE, bool init, bool isSetTextCusor)
{
    if (!finded)
        return;
    QRegExp re(text);
    QTextDocument *doc = document();
    QTextCursor currentCursor = textCursor();
    QTextCursor firstCursor;
    QTextEdit::ExtraSelection es;
    if(!init || prevFindCursor.isNull())
    {
        QTextCursor startCursor;
        if(qff&QTextDocument::FindBackward && !prevFindCursor.isNull())
        {
            prevFindCursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
                      abs(prevFindCursor.selectionStart()-prevFindCursor.selectionEnd()));
        }
        if(prevFindCursor.isNull())
            startCursor = currentCursor;
        else
            startCursor = prevFindCursor;
        firstCursor = isRE ? doc->find(re, startCursor, qff):
                             doc->find(text, startCursor, qff);
    } else {
        firstCursor = isRE ? doc->find(re, prevFindCursor.selectionStart(), qff):
                             doc->find(text, prevFindCursor.selectionStart(), qff);
    }
    if(firstCursor.isNull())
    {
        QTextCursor wholeCursor(doc);
        if(qff & QTextDocument::FindBackward)
            wholeCursor.movePosition(QTextCursor::End);
        firstCursor = isRE ? doc->find(re, wholeCursor, qff):
                             doc->find(text, wholeCursor, qff);
    }
    if(firstCursor.isNull())
    {
        prevFindCursor = firstCursor;
        return;
    }
    es.cursor = firstCursor;
    QTextCharFormat f;
    f.setBackground(Qt::blue);
    f.setForeground(Qt::white);
    es.format = f;
    currentFindSelection.clear();
    currentFindSelection.append(es);
    prevFindCursor = firstCursor;
    firstCursor.clearSelection();
    if(isSetTextCusor)
        setTextCursor(firstCursor);
    ensureCursorVisible();
    updateExtraSelection();
}
Beispiel #22
0
void QSAEditor::doRecalc()
{
    document()->invalidate();
    Q3TextParagraph *p = document()->firstParagraph();
    while ( p ) {
	p->format();
	p = p->next();
    }
    ensureCursorVisible();
    repaintContents( false );
}
/** Reimplementation to insert the text of a dragged reference into the edit view. */
void CPlainWriteDisplay::contentsDragMoveEvent( QDragMoveEvent* e ) {
	if (CDragDropMgr::canDecode(e)) {
		placeCursor(e->pos());
		ensureCursorVisible();
		e->accept(true);
	}
	else {
		e->accept(false);
		e->ignore();
	}
}
Beispiel #24
0
Console::Console(MainWindow* parent)
    : QPlainTextEdit(parent) {
    setContentsMargins(50, 50, 50, 50);

    ensureCursorVisible();
    setCenterOnScroll(false);
    setReadOnly(true);
    this->parent = parent;

    /* update all settings for the console */
    updateSettings();
}
/** 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();
	}
}
Beispiel #26
0
void CodeEditor::extraAreaMouseEvent(QMouseEvent* event)
{
    if (event->button() == Qt::LeftButton) {
        QTextBlock block = findBlockByY(event->pos().y());

        if (FOLDBOXRECT(blockBoundingGeometry(block).translated(contentOffset()).y() +
                        fontMetrics().height() / 2).contains(event->pos())) {
            foldUnfold(block);
            ensureCursorVisible();
            FULLRESIZE;
        }
    }
}
Beispiel #27
0
void QEditor::refresh()
{
	getDocument()->invalidate();
    Q3TextParagraph* p = getDocument()->firstParagraph();
    while( p ){
        p->format();
	p = p->next();
    }
    getDocument()->removeSelection( ParenMatcher::Match );
    getDocument()->removeSelection( ParenMatcher::Mismatch );
    ensureCursorVisible();
    repaintContents( false );
}
void WareSrcMsgViewer::writeMessage(const openfluid::waresdev::WareSrcMsgParser::WareSrcMsg& Msg)
{
  QTextCursor Cursor = textCursor();

  Cursor.setCharFormat(m_FormatByMsgType.value(Msg.m_Type, QTextCharFormat()));

  if (Msg.m_LineNb > 0)
    m_MessagesByBlockNumber.insert(Cursor.blockNumber(), Msg);

  Cursor.insertText(QString::fromUtf8(Msg.m_OriginalMsgLine));

  ensureCursorVisible();
}
Beispiel #29
0
void GenericCodeEditor::keyPressEvent(QKeyEvent * event)
{
    hideMouseCursor(event);

    QTextCursor cursor( textCursor() );

    bool updateCursor = false;

    if (event == QKeySequence::InsertLineSeparator) {
        // override to avoid entering a "soft" new line
        cursor.insertBlock();
        updateCursor = true;
    } else {
        switch (event->key()) {
        case Qt::Key_BraceRight:
        case Qt::Key_BracketRight:
        case Qt::Key_ParenRight:
            handleKeyRightParentheses( event, cursor );
            break;

        case Qt::Key_Delete:
            handleKeyDelete( event, cursor );
            break;

        case Qt::Key_Backspace:
            handleKeyBackspace( event, cursor, updateCursor );
            break;

        case Qt::Key_Down:
            handleKeyDown( event, cursor );
            break;

        case Qt::Key_Up:
            handleKeyUp( event, cursor );
            break;

        default:
            QPlainTextEdit::keyPressEvent(event);
        }
    }

    if (updateCursor) {
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
    }

    if (mDoc->keyDownActionEnabled() || Main::documentManager()->globalKeyDownActionEnabled())
        doKeyAction(event);
}
Beispiel #30
0
void MsgViewBase::reload()
{
    QString t;
    vector<Msg_Id> msgs;
    unsigned i;
    for (i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        Msg_Id id;
        id.id = messageId(s.left(n), client);
        id.client = client;
        unsigned nn;
        for (nn = 0; nn < msgs.size(); nn++){
            if ((msgs[nn].id == id.id) && (msgs[nn].client == id.client))
                break;
        }
        if (nn >= msgs.size())
            msgs.push_back(id);
    }
    for (i = 0; i < msgs.size(); i++){
        Message *msg = History::load(msgs[i].id, msgs[i].client.c_str(), m_id);
        if (msg == NULL)
            continue;
        t += messageText(msg, false);
        delete msg;
    }
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    setText(t);
    if (!CorePlugin::m_plugin->getOwnColors())
        setBackground(0);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}