Example #1
0
//! [5]
void MainWindow::insertCalendar()
{
    editor->clear();
    QTextCursor cursor = editor->textCursor();
    cursor.beginEditBlock();

    QDate date(selectedDate.year(), selectedDate.month(), 1);
//! [5]

//! [6]
    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignHCenter);
    tableFormat.setBackground(QColor("#e0e0e0"));
    tableFormat.setCellPadding(2);
    tableFormat.setCellSpacing(4);
//! [6] //! [7]
    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14);
    tableFormat.setColumnWidthConstraints(constraints);
//! [7]

//! [8]
    QTextTable *table = cursor.insertTable(1, 7, tableFormat);
//! [8]

//! [9]
    QTextFrame *frame = cursor.currentFrame();
    QTextFrameFormat frameFormat = frame->frameFormat();
    frameFormat.setBorder(1);
    frame->setFrameFormat(frameFormat);
//! [9]

//! [10]
    QTextCharFormat format = cursor.charFormat();
    format.setFontPointSize(fontSize);

    QTextCharFormat boldFormat = format;
    boldFormat.setFontWeight(QFont::Bold);

    QTextCharFormat highlightedFormat = boldFormat;
    highlightedFormat.setBackground(Qt::yellow);
//! [10]

//! [11]
    for (int weekDay = 1; weekDay <= 7; ++weekDay) {
        QTextTableCell cell = table->cellAt(0, weekDay-1);
//! [11] //! [12]
        QTextCursor cellCursor = cell.firstCursorPosition();
        cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
                              boldFormat);
    }
//! [12]

//! [13]
    table->insertRows(table->rows(), 1);
//! [13]

    while (date.month() == selectedDate.month()) {
        int weekDay = date.dayOfWeek();
        QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
        QTextCursor cellCursor = cell.firstCursorPosition();

        if (date == QDate::currentDate())
            cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
        else
            cellCursor.insertText(QString("%1").arg(date.day()), format);

        date = date.addDays(1);
        if (weekDay == 7 && date.month() == selectedDate.month())
            table->insertRows(table->rows(), 1);
    }

    cursor.endEditBlock();
//! [14]
    setWindowTitle(tr("Calendar for %1 %2"
        ).arg(QDate::longMonthName(selectedDate.month())
        ).arg(selectedDate.year()));
}
QString LiteEditorWidget::wordUnderCursor() const
{
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::WordUnderCursor);
    return tc.selectedText();
}
Example #3
0
//Returning format of selected text
QTextCharFormat HtmlNote::getSelFormat() const
{
    QTextCursor cursor = text_edit->textCursor();
    return cursor.charFormat();
}
Example #4
0
void NotepadWin::onSelectionChanged()
{
    QTextCharFormat fmt;
    QTextCursor cursor = edit->textCursor();
    bool isBold = false;
    bool isItalic = false;
    bool isUnderline = false;
    bool isStrike = false;
    bool aLeft = false;
    bool aCenter = false;
    bool aRight = false;
    bool aJustify = false;
    if(cursor.hasSelection()) {
        int selStart = cursor.selectionStart();
        int selEnd = cursor.selectionEnd();
        int pos = cursor.position();
        int i = 0;

        for(i = selStart; i <= selEnd; i++) {
            cursor.setPosition(i);
            if(cursor.charFormat().fontWeight() == QFont::Bold)
                isBold = true;
            if(cursor.charFormat().fontItalic())
                isItalic = true;
            if(cursor.charFormat().fontUnderline())
                isUnderline = true;
            if(cursor.charFormat().fontStrikeOut())
                isStrike = true;
            if(edit->alignment() == Qt::AlignLeft)
                aLeft = true;
            else if(edit->alignment() == Qt::AlignCenter)
                aCenter = true;
            else if(edit->alignment() == Qt::AlignRight)
                aRight = true;
            else if(edit->alignment() == Qt::AlignJustify)
                aJustify = true;
        }
        cursor.setPosition(pos);

    }
    else {
        if(cursor.charFormat().fontWeight() == QFont::Bold)
            isBold = true;
        if(cursor.charFormat().fontItalic())
            isItalic = true;
        if(cursor.charFormat().fontUnderline())
            isUnderline = true;
        if(cursor.charFormat().fontStrikeOut())
            isStrike = true;
        if(edit->alignment() == Qt::AlignLeft)
            aLeft = true;
        else if(edit->alignment() == Qt::AlignCenter)
            aCenter = true;
        else if(edit->alignment() == Qt::AlignRight)
            aRight = true;
        else if(edit->alignment() == Qt::AlignJustify)
            aJustify = true;
    }
    bold->setChecked(isBold ? true : false);
    italic->setChecked(isItalic ? true : false);
    underline->setChecked(isUnderline ? true : false);
    strikethrough->setChecked(isStrike ? true : false);
    leftSided->setChecked(aLeft ? true : false);
    centered->setChecked(aCenter ? true : false);
    rightSided->setChecked(aRight ? true : false);
    justified->setChecked(aJustify ? true : false);
}
void LiteEditorWidget::keyPressEvent(QKeyEvent *e)
{
    if (!m_completer) {
        LiteEditorWidgetBase::keyPressEvent(e);
        return;
    }
    if (m_inputCursorOffset > 0) {
        m_completer->hidePopup();
        LiteEditorWidgetBase::keyPressEvent(e);
        return;
    }

    if (m_completer->popup()->isVisible()) {
        // The following keys are forwarded by the completer to the widget
        switch (e->key()) {
        case Qt::Key_Enter:
        case Qt::Key_Return:
        case Qt::Key_Escape:
        case Qt::Key_Tab:
        case Qt::Key_Backtab:
        case Qt::Key_Shift:
            e->ignore();
            return; // let the completer do default behavior
        case Qt::Key_N:
        case Qt::Key_P:
            if (e->modifiers() == Qt::ControlModifier) {
                e->ignore();
                return;
            }
        default:
            break;
        }
    }

    bool isInImport = false;
    if (m_textLexer->isInStringOrComment(this->textCursor())) {
        isInImport = m_textLexer->isInImport(this->textCursor());
        if (!isInImport) {
            LiteEditorWidgetBase::keyPressEvent(e);
            m_completer->hidePopup();
            return;
        }
    }

    LiteEditorWidgetBase::keyPressEvent(e);

    const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);

    //always break if ctrl is pressed and there's a key
//    if (((e->modifiers() & Qt::ControlModifier) && !e->text().isEmpty())) {
//        return;
//    }
    if (e->modifiers() & Qt::ControlModifier) {
        if (!e->text().isEmpty()) {
            m_completer->hidePopup();
        }
        return;
    }

    if (e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) {
        return;
    }

    if (e->text().isEmpty()) {
        if (e->key() != Qt::Key_Backspace) {
            m_completer->hidePopup();
            return;
        }
    }
    //import line
    if (isInImport) {
        QString completionPrefix = importUnderCursor(textCursor());
        if (completionPrefix.isEmpty()) {
            return;
        }
        m_completer->setCompletionContext(LiteApi::CompleterImportContext);
        m_completer->setCompletionPrefix("");
        m_completer->startCompleter(completionPrefix);
        return;
    }

    //static QString eow("~!@#$%^&*()+{}|:\"<>?,/;'[]\\-="); // end of word
    static QString eow("~!@#$%^&*()+{}|\"<>?,/;'[]\\-="); // end of word
    bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
    QString completionPrefix = textUnderCursor(textCursor());
    if (completionPrefix.startsWith("...")) {
        completionPrefix = completionPrefix.mid(3);
    } else if (completionPrefix.startsWith(".")) {
        completionPrefix.insert(0,'@');
    }

    if (hasModifier || e->text().isEmpty()||
                        ( completionPrefix.length() < m_completionPrefixMin && completionPrefix.right(1) != ".")
                        || eow.contains(e->text().right(1))) {
        if (m_completer->popup()->isVisible()) {
            m_completer->popup()->hide();
            //fmt.Print( -> Print
            if (e->text() == "(") {
                QTextCursor cur = textCursor();
                cur.movePosition(QTextCursor::Left);
                QString lastPrefix = textUnderCursor(cur);
                if (lastPrefix.startsWith(".")) {
                    lastPrefix.insert(0,"@");
                }
                if (!lastPrefix.isEmpty() &&
                        lastPrefix == m_completer->completionPrefix() ) {
                    if (lastPrefix == m_completer->currentCompletion() ||
                            lastPrefix.endsWith("."+m_completer->currentCompletion())) {
                        m_completer->updateCompleteInfo(m_completer->currentIndex());
                    }
                }
            }
        }
        return;
    }
    m_completer->setCompletionContext(LiteApi::CompleterCodeContext);
    emit completionPrefixChanged(completionPrefix,false);
    m_completer->startCompleter(completionPrefix);
}
Example #6
0
/*! 
 * \brief Insert process stderr output in the Error Message output window.
 *
 *  Called when the process sends an output to stderr.
 */
void SimMessage::slotDisplayErr()
{
  QTextCursor cursor = ErrText->textCursor();
  cursor.movePosition(QTextCursor::End);
  ErrText->insertPlainText(QString(SimProcess.readAllStandardError()));
}
Example #7
0
void QTerminal::keyPressEvent(QKeyEvent * event) {
  int key = event->key();
  
  this->setTextCursor(curCursorLoc);
  
  // Keep QTextEdit in sync with shell as much as possible...
  if (key != Qt::Key_Backspace) {
    if (key == Qt::Key_Return || key == Qt::Key_Enter) {
      inputCharCount = 0;
    } else if (key == Qt::Key_Up) {
      if (cmdHistory.size()) {
        if (histLocation == -1) {
          histLocation = cmdHistory.size() - 1;
          tempCmd = cmdStr;
        } else if (histLocation == 0) {
          QApplication::beep();
          event->ignore();
          return;
        } else {
          --histLocation;
        }
        
        for (int i = 0; i < inputCharCount; ++i) {
          QTextEdit::keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
        }
        
        inputCharCount = cmdHistory.at(histLocation).length();
        this->insertPlainText(cmdHistory.at(histLocation));
        cmdStr = cmdHistory.at(histLocation);
      }
      
      event->ignore();
      return;
    } else if (key == Qt::Key_Down) {
      QString str = "";
      if (histLocation == -1) {
        QApplication::beep();
        event->ignore();
        return;
      } else if (histLocation == cmdHistory.size() - 1) {
        histLocation = -1;
        str = tempCmd;
      } else {
        ++histLocation;
        str = cmdHistory.at(histLocation);
      }
      
      for (int i = 0; i < inputCharCount; ++i) {
        QTextEdit::keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
      }
      
      inputCharCount = str.length();
      this->insertPlainText(str);
      cmdStr = str;
    } else if (key == Qt::Key_Left) {
      if (inputCharCount) {
        --inputCharCount;
        QTextEdit::keyPressEvent(event);
      } else {
        QApplication::beep();
      }
    } else if (key == Qt::Key_Right) {
      QTextCursor cursor = this->textCursor();
      
      if (cursor.movePosition(QTextCursor::Right)) {
        ++inputCharCount;
        this->setTextCursor(cursor);
      } else {
        QApplication::beep();
      }
    } else if (key == Qt::Key_Tab) {
      // TODO: see if we can hack in tab completion.  Currently we don't do anything.
    } else {
      QString text = event->text();
      for (int i = 0; i < text.length(); ++i) {
        if (text.at(i).isPrint()) {
          //only increase input counter for printable characters
          ++inputCharCount;
        }
      }
      QTextEdit::keyPressEvent(event);
    }
  } else {
    if (inputCharCount) {
      --inputCharCount;
      QTextEdit::keyPressEvent(event);
      cmdStr.remove(inputCharCount, 1);
    } else {
      QApplication::beep();
    }
  }

  // now pass a char* copy of the input to the shell process
  if (key == Qt::Key_Return || key == Qt::Key_Enter) {
    this->moveCursor(QTextCursor::End);
    shell->write(cmdStr.toAscii().data(), cmdStr.length());
    shell->write("\r\n", 2);
    QTextEdit::keyPressEvent(event);
    cmdHistory.push_back(cmdStr);
    histLocation = -1;
    cmdStr = "";
    tempCmd = "";
  } else {
    QString input = event->text();
    for (int i = 0; i < input.length(); ++i) {
      if (input.at(i).isPrint()) {
        cmdStr.insert(inputCharCount - 1, input.at(i));
      }
    }
  }
  curCursorLoc = this->textCursor();
}
Example #8
0
void Editor::doBackspace()
{
    QTextCursor cursor = textCursor();
    cursor.deletePreviousChar();
    setTextCursor(cursor);
}
Example #9
0
void Editor::setCursorPosition(int position)
{
    QTextCursor cursor = textCursor();
    cursor.setPosition(position);
    setTextCursor(cursor);
}
Example #10
0
/*!
    \fn QTextTableCell QTextTable::cellAt(const QTextCursor &cursor) const

    \overload

    Returns the table cell containing the given \a cursor.
*/
QTextTableCell QTextTable::cellAt(const QTextCursor &c) const
{
    return cellAt(c.position());
}
Example #11
0
void MythRemoteLineEdit::updateCycle(QString current_choice, QString set)
{
    int index;
    QString aString, bString;

    //  Show the characters in the current set being cycled
    //  through, with the current choice in a different color. If the current
    //  character is uppercase X (interpreted as destructive
    //  backspace) or an underscore (interpreted as a space)
    //  then show these special cases in yet another color.

    if (shift)
    {
        set = set.toUpper();
        current_choice = current_choice.toUpper();
    }

    bString  = "<B>";
    if (current_choice == "_" || current_choice == "X")
    {
        bString += "<FONT COLOR=\"#";
        bString += hex_special;
        bString += "\">";
        bString += current_choice;
        bString += "</FONT>";
    }
    else
    {
        bString += "<FONT COLOR=\"#";
        bString += hex_selected;
        bString += "\">";
        bString += current_choice;
        bString += "</FONT>";
    }
    bString += "</B>";

    index = set.indexOf(current_choice);
    int length = set.length();
    if (index < 0 || index > length)
    {
        LOG(VB_GENERAL, LOG_ALERT,
                 QString("MythRemoteLineEdit passed a choice of \"%1"
                         "\" which is not in set \"%2\"")
                     .arg(current_choice).arg(set));
        setText("????");
        return;
    }
    else
    {
        set.replace(index, current_choice.length(), bString);
    }

    QString esc_upto =  pre_cycle_text_before_cursor;
    QString esc_from =  pre_cycle_text_after_cursor;

    esc_upto.replace("<", "&lt;").replace(">", "&gt;").replace("\n", "<br>");
    esc_from.replace("<", "&lt;").replace(">", "&gt;").replace("\n", "<br>");

    aString = esc_upto;
    aString += "<FONT COLOR=\"#";
    aString += hex_unselected;
    aString += "\">[";
    aString += set;
    aString += "]</FONT>";
    aString += esc_from;
    setHtml(aString);

    QTextCursor tmp = textCursor();
    tmp.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
    tmp.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor,
                     pre_cycle_pos + set.length());
    setTextCursor(tmp);
    update();

    if (current_choice == "X" && !pre_cycle_text_before_cursor.isEmpty())
    {
        //  If current selection is delete, select the character to be deleted
        QTextCursor tmp = textCursor();
        tmp.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
        tmp.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor,
                         pre_cycle_pos - 1);
        tmp.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
        setTextCursor(tmp);
    }
    else
    {
        // Restore original cursor location
        QTextCursor tmp = textCursor();
        tmp.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
        tmp.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor,
                         pre_cycle_pos);
        setTextCursor(tmp);
    }
}
Example #12
0
void Utilities::highlightParentheses(QPlainTextEdit *pPlainTextEdit, QTextCharFormat parenthesesMatchFormat,
                                     QTextCharFormat parenthesesMisMatchFormat)
{
  if (pPlainTextEdit->isReadOnly()) {
    return;
  }

  QTextCursor backwardMatch = pPlainTextEdit->textCursor();
  QTextCursor forwardMatch = pPlainTextEdit->textCursor();
  if (pPlainTextEdit->overwriteMode()) {
    backwardMatch.movePosition(QTextCursor::Right);
  }

  const TextBlockUserData::MatchType backwardMatchType = TextBlockUserData::matchCursorBackward(&backwardMatch);
  const TextBlockUserData::MatchType forwardMatchType = TextBlockUserData::matchCursorForward(&forwardMatch);
  QList<QTextEdit::ExtraSelection> selections = pPlainTextEdit->extraSelections();

  if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch) {
    pPlainTextEdit->setExtraSelections(selections);
    return;
  }

  if (backwardMatch.hasSelection()) {
    QTextEdit::ExtraSelection selection;
    if (backwardMatchType == TextBlockUserData::Mismatch) {
      selection.cursor = backwardMatch;
      selection.format = parenthesesMisMatchFormat;
      selections.append(selection);
    } else {
      selection.cursor = backwardMatch;
      selection.format = parenthesesMatchFormat;

      selection.cursor.setPosition(backwardMatch.selectionStart());
      selection.cursor.setPosition(selection.cursor.position() + 1, QTextCursor::KeepAnchor);
      selections.append(selection);

      selection.cursor.setPosition(backwardMatch.selectionEnd());
      selection.cursor.setPosition(selection.cursor.position() - 1, QTextCursor::KeepAnchor);
      selections.append(selection);
    }
  }

  if (forwardMatch.hasSelection()) {
    QTextEdit::ExtraSelection selection;
    if (forwardMatchType == TextBlockUserData::Mismatch) {
      selection.cursor = forwardMatch;
      selection.format = parenthesesMisMatchFormat;
      selections.append(selection);
    } else {
      selection.cursor = forwardMatch;
      selection.format = parenthesesMatchFormat;

      selection.cursor.setPosition(forwardMatch.selectionStart());
      selection.cursor.setPosition(selection.cursor.position() + 1, QTextCursor::KeepAnchor);
      selections.append(selection);

      selection.cursor.setPosition(forwardMatch.selectionEnd());
      selection.cursor.setPosition(selection.cursor.position() - 1, QTextCursor::KeepAnchor);
      selections.append(selection);
    }
  }
  pPlainTextEdit->setExtraSelections(selections);
}
void SimpleParagraphWidget::fillListButtons()
{
    KoZoomHandler zoomHandler;
    zoomHandler.setZoom(1.2);
    zoomHandler.setDpi(72, 72);

    KoInlineTextObjectManager itom;
    KoTextRangeManager tlm;
    TextShape textShape(&itom, &tlm);
    textShape.setSize(QSizeF(300, 100));
    QTextCursor cursor (textShape.textShapeData()->document());
    foreach(const Lists::ListStyleItem &item, Lists::genericListStyleItems()) {
        QPixmap pm(48,48);

        pm.fill(Qt::transparent);
        QPainter p(&pm);

        p.translate(0, -1.5);
        p.setRenderHint(QPainter::Antialiasing);
        if(item.style != KoListStyle::None) {
            KoListStyle listStyle;
            KoListLevelProperties llp = listStyle.levelProperties(1);
            llp.setStyle(item.style);
            if (KoListStyle::isNumberingStyle(item.style)) {
                llp.setStartValue(1);
                llp.setListItemSuffix(".");
            }
            listStyle.setLevelProperties(llp);
            cursor.select(QTextCursor::Document);
            QTextCharFormat textCharFormat=cursor.blockCharFormat();
            textCharFormat.setFontPointSize(11);
            textCharFormat.setFontWeight(QFont::Normal);
            cursor.setCharFormat(textCharFormat);

            QTextBlock cursorBlock = cursor.block();
            KoTextBlockData data(cursorBlock);
            cursor.insertText("----");
            listStyle.applyStyle(cursor.block(),1);
            cursorBlock = cursor.block();
            KoTextBlockData data1(cursorBlock);
            cursor.insertText("\n----");
            cursorBlock = cursor.block();
            KoTextBlockData data2(cursorBlock);
            cursor.insertText("\n----");
            cursorBlock = cursor.block();
            KoTextBlockData data3(cursorBlock);

            KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*>(textShape.textShapeData()->document()->documentLayout());
            if(lay)
                lay->layout();

            KoShapePaintingContext paintContext; //FIXME
            textShape.paintComponent(p, zoomHandler, paintContext);
            widget.bulletListButton->addItem(pm, static_cast<int> (item.style));
        }
    }
bool SourceViewerWidget::findText(const QString &text, WebWidget::FindFlags flags)
{
	const bool isTheSame = (text == m_findText);

	m_findText = text;
	m_findFlags = flags;

	if (!text.isEmpty())
	{
		QTextDocument::FindFlags nativeFlags;

		if (flags.testFlag(WebWidget::BackwardFind))
		{
			nativeFlags |= QTextDocument::FindBackward;
		}

		if (flags.testFlag(WebWidget::CaseSensitiveFind))
		{
			nativeFlags |= QTextDocument::FindCaseSensitively;
		}

		QTextCursor findTextCursor = m_findTextAnchor;

		if (!isTheSame)
		{
			findTextCursor = textCursor();
		}
		else if (!flags.testFlag(WebWidget::BackwardFind))
		{
			findTextCursor.setPosition(findTextCursor.selectionEnd(), QTextCursor::MoveAnchor);
		}

		m_findTextAnchor = document()->find(text, findTextCursor, nativeFlags);

		if (m_findTextAnchor.isNull())
		{
			m_findTextAnchor = textCursor();
			m_findTextAnchor.setPosition((flags.testFlag(WebWidget::BackwardFind) ? (document()->characterCount() - 1) : 0), QTextCursor::MoveAnchor);
			m_findTextAnchor = document()->find(text, m_findTextAnchor, nativeFlags);
		}

		if (!m_findTextAnchor.isNull())
		{
			const QTextCursor currentTextCursor = textCursor();

			disconnect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor()));

			setTextCursor(m_findTextAnchor);
			ensureCursorVisible();

			const QPoint position(horizontalScrollBar()->value(), verticalScrollBar()->value());

			setTextCursor(currentTextCursor);

			horizontalScrollBar()->setValue(position.x());
			verticalScrollBar()->setValue(position.y());

			connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateTextCursor()));
		}
	}

	m_findTextSelection = m_findTextAnchor;

	updateSelection();

	return !m_findTextAnchor.isNull();
}
Example #15
0
void AMGraphicsTextItem::selectAllText()
{
	QTextCursor newCursor = textCursor();
	newCursor.select(QTextCursor::Document);
	setTextCursor(newCursor);
}
Example #16
0
static void moveCursorToEnd(Editor* editor)
{
    QTextCursor cursor = editor->textCursor();
    cursor.movePosition(QTextCursor::EndOfBlock);
    editor->setTextCursor(cursor);
}
Example #17
0
void AMGraphicsTextItem::clearSelection()
{
	QTextCursor newCursor = textCursor();
	newCursor.setPosition(0);
	setTextCursor(newCursor);
}
Example #18
0
void Editor::keyPressEvent(QKeyEvent* event)
{
    int key = event->key();

    switch (key) {
    case Qt::Key_Enter:
    case Qt::Key_Return:
        QTimer::singleShot(0, this, SLOT(triggerEnter()));
        event->accept();
        return;

    case Qt::Key_Up:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftUpPressed();
        else
            historyBack();
        event->accept();
        return;

    case Qt::Key_Down:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftDownPressed();
        else
            historyForward();
        event->accept();
        return;

    case Qt::Key_PageUp:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftPageUpPressed();
        else if (event->modifiers() & Qt::ControlModifier)
            emit controlPageUpPressed();
        else
            emit pageUpPressed();
        event->accept();
        return;

    case Qt::Key_PageDown:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftPageDownPressed();
        else if (event->modifiers() & Qt::ControlModifier)
            emit controlPageDownPressed();
        else
            emit pageDownPressed();
        event->accept();
        return;

    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_Home:
    case Qt::Key_End:
        checkMatching();
        checkAutoCalc();

    case Qt::Key_Space:
        if (event->modifiers() == Qt::ControlModifier && !m_constantCompletion) {
            m_constantCompletion = new ConstantCompletion(this);
            connect(m_constantCompletion, SIGNAL(selectedCompletion(const QString&)), SLOT(insertConstant(const QString&)));
            connect(m_constantCompletion, SIGNAL(canceledCompletion()), SLOT(cancelConstantCompletion()));
            m_constantCompletion->showCompletion();
            event->accept();
            return;
        }

    case Qt::Key_P:
        if (event->modifiers() == Qt::ControlModifier) {
            QTextCursor cursor = textCursor();
            if (cursor.hasSelection()) {
                const int selectionStart = cursor.selectionStart();
                const int selectionEnd = cursor.selectionEnd();
                cursor.setPosition(selectionStart);
                cursor.insertText("(");
                cursor.setPosition(selectionEnd + 1);
                cursor.insertText(")");
            } else {
                cursor.movePosition(QTextCursor::Start);
                cursor.insertText("(");
                cursor.movePosition(QTextCursor::End);
                cursor.insertText(")");
            }
            setTextCursor(cursor);
            event->accept();
            return;
        }

    default:;
    }

    if (event->matches(QKeySequence::Copy)) {
        emit copySequencePressed();
        event->accept();
        return;
    }

    QPlainTextEdit::keyPressEvent(event);
}
void TextEdit::textStyle(int styleIndex)
{
    QTextCursor cursor = textEdit->textCursor();

    if (styleIndex != 0) {
        QTextListFormat::Style style = QTextListFormat::ListDisc;

        switch (styleIndex) {
            default:
            case 1:
                style = QTextListFormat::ListDisc;
                break;
            case 2:
                style = QTextListFormat::ListCircle;
                break;
            case 3:
                style = QTextListFormat::ListSquare;
                break;
            case 4:
                style = QTextListFormat::ListDecimal;
                break;
            case 5:
                style = QTextListFormat::ListLowerAlpha;
                break;
            case 6:
                style = QTextListFormat::ListUpperAlpha;
                break;
            case 7:
                style = QTextListFormat::ListLowerRoman;
                break;
            case 8:
                style = QTextListFormat::ListUpperRoman;
                break;
        }

        cursor.beginEditBlock();

        QTextBlockFormat blockFmt = cursor.blockFormat();

        QTextListFormat listFmt;

        if (cursor.currentList()) {
            listFmt = cursor.currentList()->format();
        } else {
            listFmt.setIndent(blockFmt.indent() + 1);
            blockFmt.setIndent(0);
            cursor.setBlockFormat(blockFmt);
        }

        listFmt.setStyle(style);

        cursor.createList(listFmt);

        cursor.endEditBlock();
    } else {
        // ####
        QTextBlockFormat bfmt;
        bfmt.setObjectIndex(-1);
        cursor.mergeBlockFormat(bfmt);
    }
}
Example #20
0
void JSEdit::updateCursor()
{
    Q_D(JSEdit);

    if (isReadOnly()) {
        setExtraSelections(QList<QTextEdit::ExtraSelection>());
    } else {

        d->matchPositions.clear();
        d->errorPositions.clear();

        if (d->bracketsMatching && textCursor().block().userData()) {
            QTextCursor cursor = textCursor();
            int cursorPosition = cursor.position();

            if (document()->characterAt(cursorPosition) == '{') {
                int matchPos = findClosingMatch(document(), cursorPosition);
                if (matchPos < 0) {
                    d->errorPositions += cursorPosition;
                } else {
                    d->matchPositions += cursorPosition;
                    d->matchPositions += matchPos;
                }
            }

            if (document()->characterAt(cursorPosition - 1) == '}') {
                int matchPos = findOpeningMatch(document(), cursorPosition);
                if (matchPos < 0) {
                    d->errorPositions += cursorPosition - 1;
                } else {
                    d->matchPositions += cursorPosition - 1;
                    d->matchPositions += matchPos;
                }
            }
        }

        QTextEdit::ExtraSelection highlight;
        highlight.format.setBackground(d->cursorColor);
        highlight.format.setProperty(QTextFormat::FullWidthSelection, true);
        highlight.cursor = textCursor();
        highlight.cursor.clearSelection();

        QList<QTextEdit::ExtraSelection> extraSelections;
        extraSelections.append(highlight);

        for (int i = 0; i < d->matchPositions.count(); ++i) {
            int pos = d->matchPositions.at(i);
            QTextEdit::ExtraSelection matchHighlight;
            matchHighlight.format.setBackground(d->bracketMatchColor);
            matchHighlight.cursor = textCursor();
            matchHighlight.cursor.setPosition(pos);
            matchHighlight.cursor.setPosition(pos + 1, QTextCursor::KeepAnchor);
            extraSelections.append(matchHighlight);
        }

        for (int i = 0; i < d->errorPositions.count(); ++i) {
            int pos = d->errorPositions.at(i);
            QTextEdit::ExtraSelection errorHighlight;
            errorHighlight.format.setBackground(d->bracketErrorColor);
            errorHighlight.cursor = textCursor();
            errorHighlight.cursor.setPosition(pos);
            errorHighlight.cursor.setPosition(pos + 1, QTextCursor::KeepAnchor);
            extraSelections.append(errorHighlight);
        }

        setExtraSelections(extraSelections);
    }
}
Example #21
0
void ContactListEdit::addContactEntry(const QString& contactText, const bts::addressbook::contact& c,
                                      bool rawPublicKey, const QString* entryTooltip /*= nullptr*/)
{
    QFont        default_font;
    default_font.setPointSize( default_font.pointSize() - 1 );
    default_font.setBold(rawPublicKey);

    QFontMetrics font_metrics(default_font);
    QRect        bounding = font_metrics.boundingRect(contactText);
    int          completion_width = font_metrics.width(contactText);
    int          completion_height = bounding.height();

    completion_width += 20;

    QImage   completion_image(completion_width, completion_height + 4, QImage::Format_ARGB32);
    completion_image.fill(QColor(0, 0, 0, 0) );
    QPainter painter;
    painter.begin(&completion_image);
    painter.setFont(default_font);
    painter.setRenderHint(QPainter::Antialiasing);

    QBrush brush(Qt::SolidPattern);
    brush.setColor( QColor( 205, 220, 241 ) );
    QPen  pen, textColorPen;

    bool isKeyhoteeFounder = rawPublicKey == false && Contact::isKeyhoteeFounder(c);

    if (isKeyhoteeFounder)
    {
        QLinearGradient grad(QPointF(0, 0), QPointF(0, 1));
        grad.setCoordinateMode(QGradient::ObjectBoundingMode);
        grad.setColorAt(0, QColor(35, 40, 3));
        grad.setColorAt(0.102273, QColor(136, 106, 22));
        grad.setColorAt(0.225, QColor(166, 140, 41));
        grad.setColorAt(0.285, QColor(204, 181, 74));
        grad.setColorAt(0.345, QColor(235, 219, 102));
        grad.setColorAt(0.415, QColor(245, 236, 112));
        grad.setColorAt(0.52, QColor(209, 190, 76));
        grad.setColorAt(0.57, QColor(187, 156, 51));
        grad.setColorAt(0.635, QColor(168, 142, 42));
        grad.setColorAt(0.695, QColor(202, 174, 68));
        grad.setColorAt(0.75, QColor(218, 202, 86));
        grad.setColorAt(0.815, QColor(208, 187, 73));
        grad.setColorAt(0.88, QColor(187, 156, 51));
        grad.setColorAt(0.935, QColor(137, 108, 26));
        grad.setColorAt(1, QColor(35, 40, 3));

        brush = QBrush(grad);
        pen.setColor( QColor( 103, 51, 1 ) );
    }
    else
    {
        if(rawPublicKey)
        {
            brush.setColor(QColor(Qt::darkGreen));
            textColorPen.setColor(QColor(Qt::white));
        }
        else
        {
            brush.setColor( QColor( 205, 220, 241 ) );
            pen.setColor( QColor( 105,110,180 ) );
        }
    }

    painter.setBrush(brush);
    painter.setPen(pen);
    painter.drawRoundedRect(0, 0, completion_width - 1, completion_image.height() - 1, 8, 8,
                            Qt::AbsoluteSize);
    painter.setPen(textColorPen);
    painter.drawText(QPoint(10, completion_height - 2), contactText);

    QTextDocument* doc = document();
    doc->addResource(QTextDocument::ImageResource, QUrl(contactText), completion_image);
    QTextImageFormat format;
    format.setName(contactText);

    encodePublicKey(c.public_key, &format);

    if(entryTooltip != nullptr)
        format.setToolTip(*entryTooltip);

    QTextCursor txtCursor = textCursor();
    txtCursor.insertImage(format);
    setTextCursor(txtCursor);
}
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition)
{
    if (!definition.hasSingleLineStyle() && !definition.hasMultiLineStyle())
        return;

    QTextCursor cursor = edit->textCursor();
    QTextDocument *doc = cursor.document();
    cursor.beginEditBlock();

    int pos = cursor.position();
    int anchor = cursor.anchor();
    int start = qMin(anchor, pos);
    int end = qMax(anchor, pos);
    bool anchorIsStart = (anchor == start);

    QTextBlock startBlock = doc->findBlock(start);
    QTextBlock endBlock = doc->findBlock(end);

    if (end > start && endBlock.position() == end) {
        --end;
        endBlock = endBlock.previous();
    }

    bool doMultiLineStyleUncomment = false;
    bool doMultiLineStyleComment = false;
    bool doSingleLineStyleUncomment = false;

    bool hasSelection = cursor.hasSelection();

    if (hasSelection && definition.hasMultiLineStyle()) {

        QString startText = startBlock.text();
        int startPos = start - startBlock.position();
        const int multiLineStartLength = definition.multiLineStart().length();
        bool hasLeadingCharacters = !startText.left(startPos).trimmed().isEmpty();

        if (startPos >= multiLineStartLength
            && isComment(startText,
                         startPos - multiLineStartLength,
                         definition,
                         &CommentDefinition::multiLineStart)) {
            startPos -= multiLineStartLength;
            start -= multiLineStartLength;
        }

        bool hasSelStart = (startPos <= startText.length() - multiLineStartLength
                            && isComment(startText,
                                         startPos,
                                         definition,
                                         &CommentDefinition::multiLineStart));

        QString endText = endBlock.text();
        int endPos = end - endBlock.position();
        const int multiLineEndLength = definition.multiLineEnd().length();
        bool hasTrailingCharacters =
                !endText.left(endPos).remove(definition.singleLine()).trimmed().isEmpty()
                && !endText.mid(endPos).trimmed().isEmpty();

        if (endPos <= endText.length() - multiLineEndLength
            && isComment(endText, endPos, definition, &CommentDefinition::multiLineEnd)) {
            endPos += multiLineEndLength;
            end += multiLineEndLength;
        }

        bool hasSelEnd = (endPos >= multiLineEndLength
                          && isComment(endText,
                                       endPos - multiLineEndLength,
                                       definition,
                                       &CommentDefinition::multiLineEnd));

        doMultiLineStyleUncomment = hasSelStart && hasSelEnd;
        doMultiLineStyleComment = !doMultiLineStyleUncomment
                                  && (hasLeadingCharacters
                                      || hasTrailingCharacters
                                      || !definition.hasSingleLineStyle());
    } else if (!hasSelection && !definition.hasSingleLineStyle()) {

        QString text = startBlock.text().trimmed();
        doMultiLineStyleUncomment = text.startsWith(definition.multiLineStart())
                                    && text.endsWith(definition.multiLineEnd());
        doMultiLineStyleComment = !doMultiLineStyleUncomment && !text.isEmpty();

        start = startBlock.position();
        end = endBlock.position() + endBlock.length() - 1;

        if (doMultiLineStyleUncomment) {
            int offset = 0;
            text = startBlock.text();
            const int length = text.length();
            while (offset < length && text.at(offset).isSpace())
                ++offset;
            start += offset;
        }
    }

    if (doMultiLineStyleUncomment) {
        cursor.setPosition(end);
        cursor.movePosition(QTextCursor::PreviousCharacter,
                            QTextCursor::KeepAnchor,
                            definition.multiLineEnd().length());
        cursor.removeSelectedText();
        cursor.setPosition(start);
        cursor.movePosition(QTextCursor::NextCharacter,
                            QTextCursor::KeepAnchor,
                            definition.multiLineStart().length());
        cursor.removeSelectedText();
    } else if (doMultiLineStyleComment) {
        cursor.setPosition(end);
        cursor.insertText(definition.multiLineEnd());
        cursor.setPosition(start);
        cursor.insertText(definition.multiLineStart());
    } else {
        endBlock = endBlock.next();
        doSingleLineStyleUncomment = true;
        for (QTextBlock block = startBlock; block != endBlock; block = block.next()) {
            QString text = block.text().trimmed();
            if (!text.isEmpty() && !text.startsWith(definition.singleLine())) {
                doSingleLineStyleUncomment = false;
                break;
            }
        }

        const int singleLineLength = definition.singleLine().length();
        for (QTextBlock block = startBlock; block != endBlock; block = block.next()) {
            if (doSingleLineStyleUncomment) {
                QString text = block.text();
                int i = 0;
                while (i <= text.size() - singleLineLength) {
                    if (isComment(text, i, definition, &CommentDefinition::singleLine)) {
                        cursor.setPosition(block.position() + i);
                        cursor.movePosition(QTextCursor::NextCharacter,
                                            QTextCursor::KeepAnchor,
                                            singleLineLength);
                        cursor.removeSelectedText();
                        break;
                    }
                    if (!text.at(i).isSpace())
                        break;
                    ++i;
                }
            } else {
                QString text = block.text();
                foreach (QChar c, text) {
                    if (!c.isSpace()) {
                        if (definition.isAfterWhiteSpaces())
                            cursor.setPosition(block.position() + text.indexOf(c));
                        else
                            cursor.setPosition(block.position());
                        cursor.insertText(definition.singleLine());
                        break;
                    }
                }
            }
        }
    }

    // adjust selection when commenting out
    if (hasSelection && !doMultiLineStyleUncomment && !doSingleLineStyleUncomment) {
        cursor = edit->textCursor();
        if (!doMultiLineStyleComment)
            start = startBlock.position(); // move the comment into the selection
        int lastSelPos = anchorIsStart ? cursor.position() : cursor.anchor();
        if (anchorIsStart) {
            cursor.setPosition(start);
            cursor.setPosition(lastSelPos, QTextCursor::KeepAnchor);
        } else {
            cursor.setPosition(lastSelPos);
            cursor.setPosition(start, QTextCursor::KeepAnchor);
        }
        edit->setTextCursor(cursor);
    }

    cursor.endEditBlock();
}
	void CodeEditorDialog::moveCursorToLine(int line)
	{
		QTextCursor cur = ui->editor->textCursor();
		cur.movePosition(QTextCursor::Start);
		cur.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, line);
	}
Example #24
0
MainWindow::MainWindow()
{
    scene = new GraphicsScene(this);
    QGraphicsView *graphicsView = new QGraphicsView(scene);

#if 0
    QGraphicsVideoItem* videoItem = new QGraphicsVideoItem;
    videoItem->setSize(QSizeF(500, 480));
    scene->addItem(videoItem);
#endif
    //installEventFilter( scene );
    textItem = new GraphicsTextItem();
    QFont font;
    font.setPointSize(font.pointSize() * 2);
    font.setBold(true);
    textItem->setFont(font);
    textItem->setPlainText("Qt Everywhere!");
    textItem->setDefaultTextColor(Qt::black);


#if 0
	QTextDocument* document = new QTextDocument;

	QTextCharFormat charFormat;
	charFormat.setFont(QFont("times", 24));

	QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
	charFormat.setTextOutline(outlinePen);
	//字体轮廓
	QTextCursor cursor = QTextCursor(document);
	cursor.insertText("Test", charFormat);
	textItem->setDocument(document);
	//textItem->setTextInteractionFlags(Qt::TextEditable);
#endif
    textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
    textItem->setZValue(1000.0);
    textItem->setPos(50, 300);


    scene->addItem(textItem);

    QWidget *tabAnimations = new QWidget;
    //tabAnimations->setMinimumHeight(200);
    //tabAnimations->setMaximumHeight(200);

    QHBoxLayout* hboxAnimations = new QHBoxLayout;
    hboxAnimations->addWidget(graphicsView);
    {
        QLabel *lbl = new QLabel(tr("Text duration:"));

        hboxAnimations->addWidget(lbl);
    }
    {
        QComboBox* m_durationTextCombo = new QComboBox();
        //m_durationTextCombo->setEditable(true);
        for (int i = 2; i < 30; i = i + 2)
            m_durationTextCombo->addItem(QString().setNum(i));

        hboxAnimations->addWidget(m_durationTextCombo);
    }
    {
        QToolButton *addPhotos = new QToolButton();
        addPhotos->setText("Add photos");
        hboxAnimations->addWidget(addPhotos);
        removeEventFilter(addPhotos);
    }
    {
        m_lineEdit =  new LineEdit(this,scene);
        hboxAnimations->addWidget(m_lineEdit);
        //removeEventFilter(m_lineEdit);
        //m_lineEdit->installEventFilter( this );
    }

    connect(m_lineEdit, SIGNAL(selectedTextSignal(const QString&)), scene,
            SLOT(activeVideoText(const QString&)));

    tabAnimations->setLayout(hboxAnimations);
    setCentralWidget(tabAnimations);
    setWindowTitle(tr("Character Map"));
}
void LiteEditorWidget::insertFromMimeData(const QMimeData *source)
{
    if (isReadOnly())
        return;

    if (source->hasFormat(QLatin1String(kVerticalTextBlockMimeType))) {
        QString text = QString::fromUtf8(source->data(QLatin1String(kVerticalTextBlockMimeType)));
        if (text.isEmpty())
            return;

        QStringList lines = text.split(QLatin1Char('\n'));
        QTextCursor cursor = textCursor();
        cursor.beginEditBlock();
        const TextEditor::TabSettings &ts = this->tabSettings();
        int initialCursorPosition = cursor.position();
        int column = ts.columnAt(cursor.block().text(), cursor.positionInBlock());
        cursor.insertText(lines.first());
        for (int i = 1; i < lines.count(); ++i) {
            QTextBlock next = cursor.block().next();
            if (next.isValid()) {
                cursor.setPosition(next.position());
            } else {
                cursor.movePosition(QTextCursor::EndOfBlock);
                cursor.insertBlock();
            }
            int offset = 0;
            int position = ts.positionAtColumn(cursor.block().text(), column, &offset);
            cursor.setPosition(cursor.block().position() + position);
            if (offset < 0) {
                cursor.deleteChar();
                cursor.insertText(QString(-offset, QLatin1Char(' ')));
            } else {
                cursor.insertText(QString(offset, QLatin1Char(' ')));
            }
            cursor.insertText(lines.at(i));
        }
        cursor.setPosition(initialCursorPosition);
        cursor.endEditBlock();
        setTextCursor(cursor);
        ensureCursorVisible();
        return;
    }

    QPlainTextEdit::insertFromMimeData(source);
}
Example #26
0
void
chat::_insert_text(const char *text, const QTextCharFormat &format) {
    ACE_DEBUG((LM_ERROR, "chat::_insert_text '%s'\n", text));
    QTextCursor c = this->textCursor();
    c.insertText(text, format);
}
Example #27
0
//Applying format to selected text
void HtmlNote::setSelFormat(const QTextCharFormat& format)
{
    QTextCursor cursor = text_edit->textCursor();
    if(!cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
}
Example #28
0
void TerminalEdit::keyPressEvent(QKeyEvent *ke)
{
    QTextCursor cur = this->textCursor();
    int pos = cur.position();
    int end = cur.position();

    if (cur.hasSelection()) {
        pos = cur.selectionStart();
        end = cur.selectionEnd();
    }

    bool bReadOnly = pos < m_endPostion;

    if (bReadOnly && ( ke == QKeySequence::Paste || ke == QKeySequence::Cut ||
                       ke == QKeySequence::DeleteEndOfWord ||
                       ke == QKeySequence::DeleteStartOfWord)) {
        return;
    }

    if (ke == QKeySequence::DeleteStartOfWord) {
        if (!cur.hasSelection()) {
            cur.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
            if (cur.selectionStart() < m_endPostion) {
                cur.movePosition(QTextCursor::Right,QTextCursor::KeepAnchor,m_endPostion-cur.selectionStart());
            }
        }
        cur.removeSelectedText();
        return;
    }


    if (ke->modifiers() == Qt::NoModifier
            || ke->modifiers() == Qt::ShiftModifier
            || ke->modifiers() == Qt::KeypadModifier) {
        if (ke->key() < Qt::Key_Escape) {
            if (bReadOnly) {
                return;
            }
        } else {
            if (ke->key() == Qt::Key_Backspace) {
                if (cur.hasSelection()) {
                    if (bReadOnly) {
                        return;
                    }
                } else if (pos <= m_endPostion) {
                    return;
                }
            } else if (bReadOnly && (
                           ke->key() == Qt::Key_Delete ||
                           ke->key() == Qt::Key_Tab ||
                           ke->key() == Qt::Key_Backtab ||
                           ke->key() == Qt::Key_Return ||
                           ke->key() == Qt::Key_Enter)) {
                return;
            }
            if (ke->key() == Qt::Key_Return ||
                    ke->key() == Qt::Key_Enter) {
                cur.setPosition(end,QTextCursor::MoveAnchor);
                cur.setPosition(m_endPostion,QTextCursor::KeepAnchor);
#ifdef Q_OS_WIN
                emit enterText(cur.selectedText()+"\r\n");
#else
                emit enterText(cur.selectedText()+"\n");
#endif
                QPlainTextEdit::keyPressEvent(ke);
                QTextCursor cur = this->textCursor();
                cur.movePosition(QTextCursor::End);
                m_endPostion = cur.position();
                return;
            }
        }
    }
    QPlainTextEdit::keyPressEvent(ke);
}
Example #29
0
QString TextEdit::textUnderCursor() const
{
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::WordUnderCursor);
    return tc.selectedText();
}
int MTicketIVAInc_pintar ( MTicketIVAInc *mtick )
{
  BL_FUNC_DEBUG
  
  QString query;
  QString buscar;
  
  BtTicket *tick = ( ( BtCompany * ) mtick->mainCompany() )->ticketActual();
  QString plainTextContent = "";
  QString htmlContent = "<font size=\"4\", font-family:monospace>";
  
  htmlContent += "Ticket: " + tick->dbValue ( "nomticket" ) + "<BR>";
  plainTextContent += "Ticket: " + tick->dbValue ( "nomticket" ) + "\n";
  
  query = "SELECT idtrabajador, nomtrabajador FROM trabajador WHERE idtrabajador = " + tick->dbValue ( "idtrabajador" );
  BlDbRecordSet *rsTrabajador = mtick->mainCompany()->loadQuery ( query );
  plainTextContent += "Trabajador: " + rsTrabajador->value( "nomtrabajador" ) + "\n";
  htmlContent += "Trabajador: " + rsTrabajador->value( "nomtrabajador" ) + "<br>";
  delete rsTrabajador;
 
  query = "SELECT idcliente, nomcliente FROM cliente WHERE idcliente = " + tick->dbValue ( "idcliente" );
  BlDbRecordSet *rsCliente = mtick->mainCompany()->loadQuery ( query );
  plainTextContent += "Cliente: " + rsCliente->value( "nomcliente" ) + "\n";
  htmlContent += "Cliente: " + rsCliente->value( "nomcliente" ) + "<br>";
  delete rsCliente;
  
  htmlContent += "<br>";
  htmlContent += "<TABLE border=\"0\" width=\"100%\">";
  htmlContent += "<tr><td>" + QString(_("CANT:")) + "</td><td width=\"30%\">" + QString(_("ARTI:")) + "</td><td>" + QString(_("TALLA:")) + "</td><td>" + QString(_("COLOR:")) + "</td><td>" + QString(_("PREC:")) + "</td></tr>";
  htmlContent += "<tr><td colspan=\"5\" width=\"100%\" ><hr></td></tr>";
  plainTextContent += "\n";
  plainTextContent += "  " + QString(_("CANT:").rightJustified( 7, ' ', true )) + "  " + QString(_("ARTI:").leftJustified ( 15, ' ', true )) + "  " + QString(_("TALLA:").leftJustified( 7, ' ', true ))+ "  " + QString(_("COLOR:").leftJustified( 7, ' ', true ))+ "  " + QString(_("PRECIO:").leftJustified( 9, ' ', true )) + "\n";
  plainTextContent += "-----------------------------------------------------------\n";
  
//   if (tick->dbValue("nomticket") != "") {
//     htmlContent += "<TR><TD colspan=\"5\" align=\"center\"><B>" + tick->dbValue ( "nomticket" ) + "</B></td></tr>";
//   } // end if

  BlDbRecord *item;
  for ( int i = 0; i < tick->listaLineas()->size(); ++i ) {
      item = tick->listaLineas()->at ( i );
      QString bgcolor = "#FFFFFF";
      if ( item == tick->lineaActBtTicket() ) {
	    buscar = item->dbValue ( "nomarticulo" );
            bgcolor = "#CCCCFF";
            plainTextContent += "> ";
        } else {
            plainTextContent += "  ";
        } // end if
      htmlContent += "<TR>";
      htmlContent += "<TD bgcolor=\"" + bgcolor + "\" align=\"right\" width=\"50\">" + item->dbValue ( "cantlalbaran" ) + "</TD>";
      htmlContent += "<TD bgcolor=\"" + bgcolor + "\" whidth>" + item->dbValue ( "nomarticulo" ) + "</TD>";
      htmlContent += "<TD bgcolor=\"" + bgcolor + "\">" + item->dbValue ( "nomtc_talla" ) + "</TD>";
      htmlContent += "<TD bgcolor=\"" + bgcolor + "\">" + item->dbValue ( "nomtc_color" ) + "</TD>";
      BlFixed totalLinea ( "0.00" );
      totalLinea = BlFixed ( item->dbValue ( "cantlalbaran" ) ) * BlFixed ( item->dbValue ( "pvpivainclalbaran" ) );
      htmlContent += "<TD bgcolor=\"" + bgcolor + "\" align=\"right\" width=\"50\">" + totalLinea.toQString() + "</TD>";
      htmlContent += "</TR>";
      
      plainTextContent += item->dbValue("cantlalbaran").rightJustified ( 7, ' ', true ) + " ";
      plainTextContent += item->dbValue("nomarticulo").leftJustified ( 20, ' ', true ) + " ";
      plainTextContent += item->dbValue("nomtc_talla").leftJustified ( 7, ' ', true ) + " ";
      plainTextContent += item->dbValue("nomtc_color").leftJustified ( 7, ' ', true ) + " ";
      plainTextContent += totalLinea.toQString().leftJustified ( 9, ' ', true ) + "\n";
      
  } // end for
  
  htmlContent+= "</TABLE>";
  htmlContent += "<HR>";
  base basesimp;
  base basesimpreqeq;
  BlDbRecord *linea;
  
  QString l;
  BlFixed irpf ( "0" );

  BlDbRecordSet *cur = mtick->mainCompany()->loadQuery ( "SELECT * FROM configuracion WHERE nombre = 'IRPF'" );
  
  if ( cur ) {
      if ( !cur->eof() ) {
	  irpf = BlFixed ( cur->value( "valor" ) );
      } // end if
      delete cur;
  } // end if

  BlFixed descuentolinea ( "0.00" );
  
  for ( int i = 0; i < tick->listaLineas()->size(); ++i ) {
      linea = tick->listaLineas()->at ( i );
      BlFixed cant ( linea->dbValue ( "cantlalbaran" ) );
      BlFixed pvpund ( linea->dbValue ( "pvpivainclalbaran" ) );
      BlFixed desc1 ( linea->dbValue ( "descuentolalbaran" ) );
      BlFixed cantpvp = cant * pvpund;
      BlFixed iva ( linea->dbValue ( "ivalalbaran" ) );
      BlFixed base = cantpvp - cantpvp * desc1 / 100;
      base = base / ( BlFixed ( "1" ) + ( iva / BlFixed ( "100" ) ) );
      descuentolinea = descuentolinea + ( cantpvp * desc1 / 100 );
      basesimp[linea->dbValue ( "ivalalbaran" ) ] = basesimp[linea->dbValue ( "ivalalbaran" ) ] + base;
      basesimpreqeq[linea->dbValue ( "reqeqlalbaran" ) ] = basesimpreqeq[linea->dbValue ( "reqeqlalbaran" ) ] + base;
  } // end for

  BlFixed basei ( "0.00" );
  base::Iterator it;
  
  for ( it = basesimp.begin(); it != basesimp.end(); ++it ) {
      basei = basei + it.value();
  } // end for
  mtick->mui_browser->setText ( htmlContent );
  mtick->mui_plainText->setPlainText ( plainTextContent );
  
  mtick->mui_browser->find ( buscar );
  QTextCursor cursor = mtick->mui_browser->textCursor();
  cursor.clearSelection();
  mtick->mui_browser->setTextCursor( cursor );
  
  
  
  return -1;
  
  
 
//     BtTicket *tick = ( ( BtCompany * ) mtick->mainCompany() )->ticketActual();
//     QString html = "<p style=\"font-family:monospace; font-size: 12pt;\">";
//     QString html1 = "<font size=\"1\">";
// 
//     html1 += "Ticket: " + tick->dbValue ( "nomticket" ) + "<BR>";
// 
//     QString querytrab = "SELECT * FROM trabajador WHERE idtrabajador = " + tick->dbValue ( "idtrabajador" );
//     BlDbRecordSet *curtrab = mtick->mainCompany()->loadQuery ( querytrab );
//     html1 += "Trabajador: " + tick->dbValue ( "idtrabajador" ) + " " + curtrab->value( "nomtrabajador" ) + "<BR>";
//     delete curtrab;
//     
//     QString query = "SELECT * FROM cliente WHERE idcliente = " + tick->dbValue ( "idcliente" );
//     BlDbRecordSet *cur1 = mtick->mainCompany()->loadQuery ( query );
//     html1 += "Cliente: " + tick->dbValue ( "idcliente" ) + " " + cur1->value( "nomcliente" ) + "<BR>";
//     delete cur1;
// 
//     html += "<TABLE border=\"0\" width=\"100%\">";
//     if (tick->dbValue("nomticket") != "") {
//       html += "<TR><TD colspan=\"5\" align=\"center\"><B>" + tick->dbValue ( "nomticket" ) + "</B></td></tr>";
//     } // end if
// 
//     BlDbRecord *item;
//     for ( int i = 0; i < tick->listaLineas()->size(); ++i ) {
//         item = tick->listaLineas()->at ( i );
//         QString bgcolor = "#FFFFFF";
//         if ( item == tick->lineaActBtTicket() ) bgcolor = "#CCCCFF";
//         html += "<TR>";
//         html += "<TD bgcolor=\"" + bgcolor + "\" align=\"right\" width=\"50\">" + item->dbValue ( "cantlalbaran" ) + "</TD>";
//         html += "<TD bgcolor=\"" + bgcolor + "\">" + item->dbValue ( "nomarticulo" ) + "</TD>";
//         html += "<TD bgcolor=\"" + bgcolor + "\">" + item->dbValue ( "nomtc_talla" ) + "</TD>";
//         html += "<TD bgcolor=\"" + bgcolor + "\">" + item->dbValue ( "nomtc_color" ) + "</TD>";
//         BlFixed totalLinea ( "0.00" );
//         totalLinea = BlFixed ( item->dbValue ( "cantlalbaran" ) ) * BlFixed ( item->dbValue ( "pvpivainclalbaran" ) );
//         html += "<TD bgcolor=\"" + bgcolor + "\" align=\"right\" width=\"50\">" + totalLinea.toQString() + "</TD>";
//         html += "</TR>";
//     } // end for
//     
//     html += "</TABLE>";    
//     html += "<BR><HR><BR>";
//     base basesimp;
//     base basesimpreqeq;
//     BlDbRecord *linea;
//     
//     /// Impresion de los contenidos.
//     QString l;
//     BlFixed irpf ( "0" );
// 
//     BlDbRecordSet *cur = mtick->mainCompany()->loadQuery ( "SELECT * FROM configuracion WHERE nombre = 'IRPF'" );
//     
//     if ( cur ) {
//         if ( !cur->eof() ) {
//             irpf = BlFixed ( cur->value( "valor" ) );
//         } // end if
//         delete cur;
//     } // end if
// 
//     BlFixed descuentolinea ( "0.00" );
//     
//     for ( int i = 0; i < tick->listaLineas()->size(); ++i ) {
//         linea = tick->listaLineas()->at ( i );
//         BlFixed cant ( linea->dbValue ( "cantlalbaran" ) );
//         BlFixed pvpund ( linea->dbValue ( "pvpivainclalbaran" ) );
//         BlFixed desc1 ( linea->dbValue ( "descuentolalbaran" ) );
//         BlFixed cantpvp = cant * pvpund;
//         BlFixed iva ( linea->dbValue ( "ivalalbaran" ) );
//         BlFixed base = cantpvp - cantpvp * desc1 / 100;
//         base = base / ( BlFixed ( "1" ) + ( iva / BlFixed ( "100" ) ) );
//         descuentolinea = descuentolinea + ( cantpvp * desc1 / 100 );
//         basesimp[linea->dbValue ( "ivalalbaran" ) ] = basesimp[linea->dbValue ( "ivalalbaran" ) ] + base;
//         basesimpreqeq[linea->dbValue ( "reqeqlalbaran" ) ] = basesimpreqeq[linea->dbValue ( "reqeqlalbaran" ) ] + base;
//     } // end for
// 
//     BlFixed basei ( "0.00" );
//     base::Iterator it;
//     
//     for ( it = basesimp.begin(); it != basesimp.end(); ++it ) {
//         basei = basei + it.value();
//     } // end for
// 
//     /// Calculamos el total de los descuentos.
//     /// De momento aqui no se usan descuentos generales en venta.
//     BlFixed porcentt ( "0.00" );
// 
//     /// Calculamos el total de base imponible.
//     BlFixed totbaseimp ( "0.00" );
//     BlFixed parbaseimp ( "0.00" );
//     
//     for ( it = basesimp.begin(); it != basesimp.end(); ++it ) {
//         if ( porcentt > BlFixed ( "0.00" ) ) {
//             parbaseimp = it.value() - it.value() * porcentt / 100;
//         } else {
//             parbaseimp = it.value();
//         } // end if
//         html1 += "Base Imp " + it.key() + "% " + parbaseimp.toQString() + "<BR>";
//         totbaseimp = totbaseimp + parbaseimp;
//     } // end for
// 
//     /// Calculamos el total de IVA.
//     BlFixed totiva ( "0.00" );
//     BlFixed pariva ( "0.00" );
//     
//     for ( it = basesimp.begin(); it != basesimp.end(); ++it ) {
//         BlFixed piva ( it.key().toLatin1().constData() );
//         if ( porcentt > BlFixed ( "0.00" ) ) {
//             pariva = ( it.value() - it.value() * porcentt / 100 ) * piva / 100;
//         } else {
//             pariva = it.value() * piva / 100;
//         } // end if
//         html1 += "IVA " + it.key() + "% " + pariva.toQString() + "<BR>";
//         totiva = totiva + pariva;
//     } // end for
// 
//     /// Calculamos el total de recargo de equivalencia.
//     BlFixed totreqeq ( "0.00" );
//     BlFixed parreqeq ( "0.00" );
//     
//     for ( it = basesimpreqeq.begin(); it != basesimpreqeq.end(); ++it ) {
//         BlFixed preqeq ( it.key().toLatin1().constData() );
//         if ( porcentt > BlFixed ( "0.00" ) ) {
//             parreqeq = ( it.value() - it.value() * porcentt / 100 ) * preqeq / 100;
//         } else {
//             parreqeq = it.value() * preqeq / 100;
//         } // end if
//         html1 += "R.Eq " + it.key() + "% " + parreqeq.toQString() + "<BR>";
//         totreqeq = totreqeq + parreqeq;
//     } // end for
// 
//     BlFixed totirpf = totbaseimp * irpf / 100;
// 
//     html1 += "<B>Base Imp. " + totbaseimp.toQString() + "<BR>";
//     html1 += "<B>IVA. " + totiva.toQString() + "<BR>";
//     html1 += "<B>IRPF. " + totirpf.toQString() + "<BR>";
// 
//     BlFixed total = totiva + totbaseimp + totreqeq - totirpf;
//     html1 += "<B>Total: " + total.toQString() + "<BR>";
// 
//     html += "</p>";
//     html1 += "</FONT>";
// 
//     /// Pintamos el HTML en el textBrowser
//     mtick->mui_browser->setText ( html );
//     
//     return -1;
}