Exemplo n.º 1
0
void QQuickTextNode::addTextDocument(const QPointF &position, QTextDocument *textDocument,
                                  const QColor &textColor,
                                  QQuickText::TextStyle style, const QColor &styleColor,
                                  const QColor &anchorColor,
                                  const QColor &selectionColor, const QColor &selectedTextColor,
                                  int selectionStart, int selectionEnd)
{
    QQuickTextNodeEngine engine;
    engine.setTextColor(textColor);
    engine.setSelectedTextColor(selectedTextColor);
    engine.setSelectionColor(selectionColor);
    engine.setAnchorColor(anchorColor);
    engine.setPosition(position);

    QList<QTextFrame *> frames;
    frames.append(textDocument->rootFrame());
    while (!frames.isEmpty()) {
        QTextFrame *textFrame = frames.takeFirst();
        frames.append(textFrame->childFrames());

        engine.addFrameDecorations(textDocument, textFrame);

        if (textFrame->firstPosition() > textFrame->lastPosition()
         && textFrame->frameFormat().position() != QTextFrameFormat::InFlow) {
            const int pos = textFrame->firstPosition() - 1;
            ProtectedLayoutAccessor *a = static_cast<ProtectedLayoutAccessor *>(textDocument->documentLayout());
            QTextCharFormat format = a->formatAccessor(pos);
            QRectF rect = a->frameBoundingRect(textFrame);

            QTextBlock block = textFrame->firstCursorPosition().block();
            engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position()));
            engine.addTextObject(rect.topLeft(), format, QQuickTextNodeEngine::Unselected, textDocument,
                                 pos, textFrame->frameFormat().position());
        } else {
            QTextFrame::iterator it = textFrame->begin();

            while (!it.atEnd()) {
                Q_ASSERT(!engine.currentLine().isValid());

                QTextBlock block = it.currentBlock();
                engine.addTextBlock(textDocument, block, position, textColor, anchorColor, selectionStart, selectionEnd);
                ++it;
            }
        }
    }

    engine.addToSceneGraph(this, style, styleColor);
}
Exemplo n.º 2
0
    QwtRichTextDocument( const QString &text, int flags, const QFont &font )
    {
        setUndoRedoEnabled( false );
        setDefaultFont( font );
        setHtml( text );

        // make sure we have a document layout
        ( void )documentLayout();

        QTextOption option = defaultTextOption();
        if ( flags & Qt::TextWordWrap )
            option.setWrapMode( QTextOption::WordWrap );
        else
            option.setWrapMode( QTextOption::NoWrap );

        option.setAlignment( ( Qt::Alignment ) flags );
        setDefaultTextOption( option );

        QTextFrame *root = rootFrame();
        QTextFrameFormat fm = root->frameFormat();
        fm.setBorder( 0 );
        fm.setMargin( 0 );
        fm.setPadding( 0 );
        fm.setBottomMargin( 0 );
        fm.setLeftMargin( 0 );
        root->setFrameFormat( fm );

        adjustSize();
    }
Exemplo n.º 3
0
TextLayer::TextLayer(const int layer_id , QGraphicsItem *parent , QGraphicsScene *scene )
    : QGraphicsItem(parent,scene),evesum(0),modus(Show),border(1.),currentprintrender(false),
    hi(Metric("30px")),wi(Metric("110px")),bgcolor(QColor(Qt::white)),SwapLockBreak(false),
    bordercolor(QColor(Qt::red)),Rotate(0),check_view_area_time(0),ActionHover(false),
    format(DIV_ABSOLUTE),mount(new TextController)
{
    mount->q = this;
    setAcceptsHoverEvents(true);
    wisub_border = wi + border;
    history.clear();
    id = layer_id;
    setAcceptDrops(true);
    setFlag(QGraphicsItem::ItemIsSelectable,true);
    setFlag(QGraphicsItem::ItemIsFocusable,true);
    setFlag(QGraphicsItem::ItemIsMovable,false);
    setSelected(false);
    _doc = new QTextDocument();  
    _doc->setHtml(tr("<p>Write your text<p>"));
        QTextFrame  *Tframe = _doc->rootFrame();
        QTextFrameFormat rootformats = Tframe->frameFormat();
        rootformats.setWidth(wi);
        rootformats.setBorder(0);
        Tframe->setFrameFormat(rootformats);
        _doc->setPageSize(QSizeF(wi,hi)); 
        DLayout = _doc->documentLayout();
    setDocument(_doc);
    mount->txtControl()->document()->toHtml().size();  /* connect all */
    setZValue(1.99999);
    RestoreMoveAction();
    init();
}
Exemplo n.º 4
0
ClientTextEdit::ClientTextEdit(QWidget* parent) : QTextEdit(parent) {
    setReadOnly(true);
    setOverwriteMode(true);
    setUndoRedoEnabled(false);
    setDocumentTitle("mClient");
    setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
    setTabChangesFocus(false);

    //_doc->setMaximumBlockCount(Config().scrollbackSize); // max number of lines?
    document()->setUndoRedoEnabled(false);
    QTextFrame* frame = document()->rootFrame();
    _cursor = frame->firstCursorPosition();

    // Default Colors
    _foregroundColor = Qt::lightGray;
    _backgroundColor = Qt::black;
    _blackColor = Qt::darkGray;
    _redColor = Qt::darkRed;
    _greenColor = Qt::darkGreen;
    _yellowColor = Qt::darkYellow;
    _blueColor = Qt::darkBlue;
    _magentaColor = Qt::darkMagenta;
    _cyanColor = Qt::darkCyan;
    _grayColor = Qt::lightGray;
    _darkGrayColor = Qt::gray;
    _brightRedColor = Qt::red;
    _brightGreenColor = Qt::green;
    _brightYellowColor = Qt::yellow;
    _brightBlueColor = Qt::blue;
    _brightMagentaColor = Qt::magenta;
    _brightCyanColor = Qt::cyan;
    _whiteColor = Qt::white;
    // Default Fonts
    _serverOutputFont = QFont("Monospace", 10);
    _inputLineFont = QFont("Monospace", 10); //QApplication::font();
    _serverOutputFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);

    QTextFrameFormat frameFormat = frame->frameFormat();
    frameFormat.setBackground(_backgroundColor);
    frameFormat.setForeground(_foregroundColor);
    frame->setFrameFormat(frameFormat);

    _format = _cursor.charFormat();
    setDefaultFormat(_format);
    _defaultFormat = _format;
    _cursor.setCharFormat(_format);

    QFontMetrics fm(_serverOutputFont);
    setTabStopWidth(fm.width(" ") * 8); // A tab is 8 spaces wide
    QScrollBar* scrollbar = verticalScrollBar();
    scrollbar->setSingleStep(fm.leading()+fm.height());

    connect(scrollbar, SIGNAL(sliderReleased()), 
                this, SLOT(scrollBarReleased()));

    previous = 0;
}
Exemplo n.º 5
0
void KoSectionStyle::unapplyStyle(QTextFrame &section) const
{
    if (d->parentStyle)
        d->parentStyle->unapplyStyle(section);

    QTextFrameFormat format = section.frameFormat();

    QList<int> keys = d->stylesPrivate.keys();
    for (int i = 0; i < keys.count(); i++) {
        QVariant variant = d->stylesPrivate.value(keys[i]);
        if (variant == format.property(keys[i]))
            format.clearProperty(keys[i]);
    }
    section.setFrameFormat(format);
}
Exemplo n.º 6
0
/* form qtexdocument to this margin an papersize */
void M_PageSize::HandlePrint( QTextDocument *doc )
{
			const qreal RightMargin = P_margin.y();
			const qreal LeftMargin = P_margin.height();
			const qreal LargeDoc = G_regt.width() - RightMargin  - LeftMargin;
			doc->setPageSize ( G_regt.size() );
			QTextFrame  *Tframe = doc->rootFrame();
	    QTextFrameFormat Ftf = Tframe->frameFormat();
	    Ftf.setLeftMargin(P_margin.height());
	    Ftf.setBottomMargin(P_margin.width());
	    Ftf.setTopMargin(P_margin.x());
	   Ftf.setBackground(QBrush(Qt::transparent));
			Ftf.setRightMargin(P_margin.y());
	    Ftf.setPadding ( 0);
			Tframe->setFrameFormat(Ftf);
		  doc->setPageSize ( G_regt.size() );
}
Exemplo n.º 7
0
//! [2]
void MainWindow::newLetter()
{
    textEdit->clear();

    QTextCursor cursor(textEdit->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextFrame *topFrame = cursor.currentFrame();
    QTextFrameFormat topFrameFormat = topFrame->frameFormat();
    topFrameFormat.setPadding(16);
    topFrame->setFrameFormat(topFrameFormat);

    QTextCharFormat textFormat;
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);
    QTextCharFormat italicFormat;
    italicFormat.setFontItalic(true);

    QTextTableFormat tableFormat;
    tableFormat.setBorder(1);
    tableFormat.setCellPadding(16);
    tableFormat.setAlignment(Qt::AlignRight);
    cursor.insertTable(1, 1, tableFormat);
    cursor.insertText("The Firm", boldFormat);
    cursor.insertBlock();
    cursor.insertText("321 City Street", textFormat);
    cursor.insertBlock();
    cursor.insertText("Industry Park");
    cursor.insertBlock();
    cursor.insertText("Some Country");
    cursor.setPosition(topFrame->lastPosition());
    cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
    cursor.insertBlock();
    cursor.insertBlock();
    cursor.insertText("Dear ", textFormat);
    cursor.insertText("NAME", italicFormat);
    cursor.insertText(",", textFormat);
    for (int i = 0; i < 3; ++i)
        cursor.insertBlock();
    cursor.insertText(tr("Yours sincerely,"), textFormat);
    for (int i = 0; i < 3; ++i)
        cursor.insertBlock();
    cursor.insertText("The Boss", textFormat);
    cursor.insertBlock();
    cursor.insertText("ADDRESS", italicFormat);
}
Exemplo n.º 8
0
void MainWindow::newLetter(){
    chatbox->clear();


    QTextCursor cursor(chatbox->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextFrame *topFrame = cursor.currentFrame();
    QTextFrameFormat topFrameFormat = topFrame->frameFormat();
    topFrameFormat.setPadding(16);
    topFrame->setFrameFormat(topFrameFormat);

    QTextCharFormat textFormat;
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);
    QTextCharFormat italicFormat;
    italicFormat.setFontItalic(true);

    /*QTextTableFormat tableFormat;
    tableFormat.setBorder(1);
    tableFormat.setCellPadding(16);
    tableFormat.setAlignment(Qt::AlignRight);
    cursor.insertTable(1, 1, tableFormat);
    cursor.insertText("The Firm", boldFormat);
    cursor.insertBlock();
    cursor.insertText("321 City Street", textFormat);
    cursor.insertBlock();
    cursor.insertText("Industry Park");
    cursor.insertBlock();
    cursor.insertText("Some Country"); */
    cursor.setPosition(topFrame->lastPosition());
    cursor.insertText("Railguy: ", boldFormat);
    cursor.insertText("lol nub", textFormat);
    cursor.insertBlock();
    cursor.insertText("Chaos: ", boldFormat);
    cursor.insertText("nou", textFormat);
    cursor.insertBlock();

    QFont font = chattitle->font();
    font.setBold(true);
    chattitle->setFont(font);
    chattitle->setText("#General");
}
Exemplo n.º 9
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()));
}
Exemplo n.º 10
0
void KoSectionStyle::applyStyle(QTextFrame &section) const
{
    QTextFrameFormat format = section.frameFormat();
    applyStyle(format);
    section.setFrameFormat(format);
}
void QQuickTextNodeEngine::addTextBlock(QTextDocument *textDocument, const QTextBlock &block, const QPointF &position, const QColor &textColor, const QColor &anchorColor, int selectionStart, int selectionEnd)
{
    Q_ASSERT(textDocument);
#ifndef QT_NO_IM
    int preeditLength = block.isValid() ? block.layout()->preeditAreaText().length() : 0;
    int preeditPosition = block.isValid() ? block.layout()->preeditAreaPosition() : -1;
#endif

    QVarLengthArray<QTextLayout::FormatRange> colorChanges;
    mergeFormats(block.layout(), &colorChanges);

    QPointF blockPosition = textDocument->documentLayout()->blockBoundingRect(block).topLeft() + position;
    if (QTextList *textList = block.textList()) {
        QPointF pos = blockPosition;
        QTextLayout *layout = block.layout();
        if (layout->lineCount() > 0) {
            QTextLine firstLine = layout->lineAt(0);
            Q_ASSERT(firstLine.isValid());

            setCurrentLine(firstLine);

            QRectF textRect = firstLine.naturalTextRect();
            pos += textRect.topLeft();
            if (block.textDirection() == Qt::RightToLeft)
                pos.rx() += textRect.width();

            const QTextCharFormat charFormat = block.charFormat();
            QFont font(charFormat.font());
            QFontMetricsF fontMetrics(font);
            QTextListFormat listFormat = textList->format();

            QString listItemBullet;
            switch (listFormat.style()) {
            case QTextListFormat::ListCircle:
                listItemBullet = QChar(0x25E6); // White bullet
                break;
            case QTextListFormat::ListSquare:
                listItemBullet = QChar(0x25AA); // Black small square
                break;
            case QTextListFormat::ListDecimal:
            case QTextListFormat::ListLowerAlpha:
            case QTextListFormat::ListUpperAlpha:
            case QTextListFormat::ListLowerRoman:
            case QTextListFormat::ListUpperRoman:
                listItemBullet = textList->itemText(block);
                break;
            default:
                listItemBullet = QChar(0x2022); // Black bullet
                break;
            };

            QSizeF size(fontMetrics.width(listItemBullet), fontMetrics.height());
            qreal xoff = fontMetrics.width(QLatin1Char(' '));
            if (block.textDirection() == Qt::LeftToRight)
                xoff = -xoff - size.width();
            setPosition(pos + QPointF(xoff, 0));

            QTextLayout layout;
            layout.setFont(font);
            layout.setText(listItemBullet); // Bullet
            layout.beginLayout();
            QTextLine line = layout.createLine();
            line.setPosition(QPointF(0, 0));
            layout.endLayout();

            QList<QGlyphRun> glyphRuns = layout.glyphRuns();
            for (int i=0; i<glyphRuns.size(); ++i)
                addUnselectedGlyphs(glyphRuns.at(i));
        }
    }

    int textPos = block.position();
    QTextBlock::iterator blockIterator = block.begin();

    while (!blockIterator.atEnd()) {
        QTextFragment fragment = blockIterator.fragment();
        QString text = fragment.text();
        if (text.isEmpty())
            continue;

        QTextCharFormat charFormat = fragment.charFormat();
        QFont font(charFormat.font());
        QFontMetricsF fontMetrics(font);

        int fontHeight = fontMetrics.descent() + fontMetrics.ascent();
        int valign = charFormat.verticalAlignment();
        if (valign == QTextCharFormat::AlignSuperScript)
            setPosition(QPointF(blockPosition.x(), blockPosition.y() - fontHeight / 2));
        else if (valign == QTextCharFormat::AlignSubScript)
            setPosition(QPointF(blockPosition.x(), blockPosition.y() + fontHeight / 6));
        else
            setPosition(blockPosition);

        if (text.contains(QChar::ObjectReplacementCharacter)) {
            QTextFrame *frame = qobject_cast<QTextFrame *>(textDocument->objectForFormat(charFormat));
            if (frame && frame->frameFormat().position() == QTextFrameFormat::InFlow) {
                int blockRelativePosition = textPos - block.position();
                QTextLine line = block.layout()->lineForTextPosition(blockRelativePosition);
                if (!currentLine().isValid()
                        || line.lineNumber() != currentLine().lineNumber()) {
                    setCurrentLine(line);
                }

                QQuickTextNodeEngine::SelectionState selectionState =
                        (selectionStart < textPos + text.length()
                         && selectionEnd >= textPos)
                        ? QQuickTextNodeEngine::Selected
                        : QQuickTextNodeEngine::Unselected;

                addTextObject(QPointF(), charFormat, selectionState, textDocument, textPos);
            }
            textPos += text.length();
        } else {
            if (charFormat.foreground().style() != Qt::NoBrush)
                setTextColor(charFormat.foreground().color());
            else if (charFormat.isAnchor())
                setTextColor(anchorColor);
            else
                setTextColor(textColor);

            int fragmentEnd = textPos + fragment.length();
#ifndef QT_NO_IM
            if (preeditPosition >= 0
                    && (preeditPosition + block.position()) >= textPos
                    && (preeditPosition + block.position()) <= fragmentEnd) {
                fragmentEnd += preeditLength;
            }
#endif
            if (charFormat.background().style() != Qt::NoBrush) {
                QTextLayout::FormatRange additionalFormat;
                additionalFormat.start = textPos - block.position();
                additionalFormat.length = fragmentEnd - textPos;
                additionalFormat.format = charFormat;
                colorChanges << additionalFormat;
            }

            textPos = addText(block, charFormat, textColor, colorChanges, textPos, fragmentEnd,
                                                 selectionStart, selectionEnd);
        }

        ++blockIterator;
    }

#ifndef QT_NO_IM
    if (preeditLength >= 0 && textPos <= block.position() + preeditPosition) {
        setPosition(blockPosition);
        textPos = block.position() + preeditPosition;
        QTextLine line = block.layout()->lineForTextPosition(preeditPosition);
        if (!currentLine().isValid()
                || line.lineNumber() != currentLine().lineNumber()) {
            setCurrentLine(line);
        }
        textPos = addText(block, block.charFormat(), textColor, colorChanges,
                                             textPos, textPos + preeditLength,
                                             selectionStart, selectionEnd);
    }
#endif

    setCurrentLine(QTextLine()); // Reset current line because the text layout changed
    m_hasContents = true;
}
Exemplo n.º 12
0
TextEditor::TextEditor(Graph *g): QTextEdit(g), d_graph(g)
{
	setAttribute(Qt::WA_DeleteOnClose);
	setFrameShadow(QFrame::Plain);
	setFrameShape(QFrame::Box);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

	QPalette palette = this->palette();
	palette.setColor(QPalette::Active, QPalette::WindowText, Qt::blue);
	palette.setColor(QPalette::Active, QPalette::Base, Qt::white);
	setPalette(palette);

	bool moveCrs = true;
	QString text;
	if (g->activeText()){
		setParent(g->multiLayer()->canvas());
		d_target = g->activeText();
		setGeometry(d_target->geometry());
		text = ((LegendWidget*)d_target)->text();
		d_target->hide();
		setFont(((LegendWidget*)d_target)->font());
	} else if (g->titleSelected()){
		d_target = g->titleLabel();
		QwtText t = g->title();
		text = t.text();
		setAlignment((Qt::Alignment)t.renderFlags());
		setFont(t.font());
		setGeometry(d_target->geometry());
	} else if (g->selectedScale()){
		d_target = g->selectedScale();
		QwtScaleWidget *scale = (QwtScaleWidget*)d_target;
		QwtText t = scale->title();
		text = t.text();
		setAlignment((Qt::Alignment)t.renderFlags());
		setFont(t.font());

		QRect rect = g->axisTitleRect(scale);
		if (scale->alignment() == QwtScaleDraw::BottomScale ||
			scale->alignment() == QwtScaleDraw::TopScale){
			resize(rect.size());
			move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y()));
		} else {
			resize(QSize(rect.height(), rect.width()));
			if (scale->alignment() == QwtScaleDraw::LeftScale)
                move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y() + rect.height()/2));
            else if (scale->alignment() == QwtScaleDraw::RightScale)
                move(QPoint(d_target->x() - rect.height(), d_target->y() + rect.y() + rect.height()/2));

			t.setText(" ");
			t.setBackgroundPen(QPen(Qt::NoPen));
			scale->setTitle(t);
			moveCrs = false;
		}
	}

	QTextCursor cursor = textCursor();
	cursor.insertText(text);
	d_initial_text = text;

	setWordWrapMode (QTextOption::NoWrap);
	setAlignment(Qt::AlignCenter);

	QTextFrame *frame = document()->rootFrame();
	QTextFrameFormat format = frame->frameFormat();
	format.setTopMargin(format.topMargin () + 3);
	frame->setFrameFormat(format);
	show();

	if (moveCrs)
		setTextCursor(cursorForPosition(mapFromGlobal(QCursor::pos())));
	setFocus();
}
Exemplo n.º 13
0
QString Format::frameToString( QTextFrame *frame )
{
  QString out;

  QTextFrame::iterator it;
  for( it = frame->begin(); it != frame->end(); ++it ) {
    QTextBlock block = it.currentBlock();
    if ( block.isValid() ) {
      out += "<block";

      QTextCursor c( block );

      QDateTime dt = TextFormats::lastModified( c );
      if ( dt.isValid() ) {
        out += " lastmodified=\"" + dt.toString( Qt::ISODate ) + "\"";
      }

      if ( TextFormats::isTitle( c ) ) {
        out += " titlestyle=\"title\"";
      } else if ( TextFormats::isSubTitle( c ) ) {
        out += " titlestyle=\"subtitle\"";
      }

      QTextBlockFormat blockFormat = block.blockFormat();
      if ( blockFormat.isValid() ) {
        QTextList *list = block.textList();
        if ( list ) {
          QTextListFormat f = list->format();
          out += " liststyle=\"";
          switch( f.style() ) {
            default:
            case QTextListFormat::ListDisc:
              out += "disc";
              break;
            case QTextListFormat::ListDecimal:
              out += "decimal";
              break;
          }
          out += "\"";

          out += " listindent=\"" + QString::number( f.indent() ) + "\"";
        } else {
          if ( blockFormat.indent() != 0 ) {
            out += " blockindent=\"" + QString::number( blockFormat.indent() ) +
              "\"";
          }
        }
      }

      out += ">\n";
      
      QTextBlock::iterator it2;
      for( it2 = block.begin(); it2 != block.end(); ++it2 ) {
        QTextFragment fragment = it2.fragment();
        if ( !fragment.isValid() ) continue;

        QString text = fragment.text();

        QString outText;
        for( int i = 0; i < text.size(); ++i ) {
          if ( text.at( i ) == 0xfffc ) {
            outText += "<todo status=\"";

            QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
            if ( imageFormat.isValid() ) {
              if ( imageFormat.name().contains( "done" ) ) outText += "done";
              else outText += "todo";
            } else {
              dbg() << "NO IMAGE FORMAT" << endl;
            }
            
            outText += "\"/>";
          } else {
            outText += escape( QString( text.at( i ) ) );
          }
        }

        out += "  <fragment";

        QTextCharFormat format = fragment.charFormat();
        if ( !format.anchorHref().isEmpty() ) {
          out += " link=\"" + escape( format.anchorHref() ) + "\"";
        }
        if ( format.fontWeight() == QFont::Bold ) {
          out += " bold=\"true\"";
        }
        if ( format.fontItalic() ) {
          out += " italic=\"true\"";
        }
        if ( format.hasProperty( QTextFormat::FontPointSize ) &&
             format.fontPointSize() != 10 ) {
          out += " fontsize=\"" + QString::number( format.fontPointSize() ) +
            "\"";
        }

        if ( outText.trimmed().isEmpty() ) outText.replace( " ", "[FIXME:space]" );

        out += ">" + outText + "</fragment>\n";
      }
      
      out += "</block>";

      out += "\n";
    }
    QTextFrame *f = it.currentFrame();
    if ( f ) {
      QTextFrameFormat format = f->frameFormat();
      out += "<frame";
      if ( format.hasProperty( TextFormats::FrameType ) ) {
        out += " type=";
        if ( format.property( TextFormats::FrameType ) == TextFormats::CodeFrame ) {
          out += "\"code\"";
        } else {
          out += "\"undefined\"";
        }
      }
      out += ">\n";
      out += frameToString( f );
      out += "</frame>\n";
    }
  }

  return out;
}
Exemplo n.º 14
0
WymsingTxt::WymsingTxt( QRectF recter , QColor sfondo , QColor margincolor , qreal borders , int rotate , QTextDocument *item , TypImageContainer block ,  QGraphicsItem  * parent )
{
	setupUi( this );
    Qfontlist->setFontFilters( QFontComboBox::ScalableFonts );
    
    
    stackedWidget->hide();
    
    QStringList palign;
    palign << "[1] AlignLeft" << "[2] AlignRight" << "[4] AlignHCenter";
    alignetable->clear();
    alignetable->addItems(palign);
    
    
    if (QGraphicsTextItem *image = qgraphicsitem_cast<QGraphicsTextItem *>(parent)) {
    ////////qDebug() << "### trovato " << image->boundingRect();
    
        connect(XxAxys, SIGNAL(valueChanged(int)), this, SLOT(RotateFloat(int)));
        
        wtxt->setDocument ( image->document() );
        wtxt->document()->adjustSize();
        
        DocFrameFormings =  wtxt->document()->rootFrame()->frameFormat();
        DocFrameFormings.setBackground(sfondo);
        DocFrameFormings.setWidth( image->boundingRect().width() );
        wtxt->document()->rootFrame()->setFrameFormat ( DocFrameFormings ); 
        wtxt->document()->setUseDesignMetrics (true );
       
        
        
      /////tablegr->hide();    /* propryetys setter */
      /////imagegr->hide();   /* propryetys setter */
      wtxt->AppendImageBlocks(block);
      CatchPixmapCurrent("");
        
        QPointF globalpos = image->pos();
        XXset->setValue(globalpos.x());
        YYset->setValue(globalpos.y());
        
        connect(XXset, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
        connect(YYset, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));

    destimage = image;
    /////wtxt->setEnabled(true);
    loadetConnection = false;
    workfont = item->defaultFont();
    ////////qDebug() << "### textWidth   " << item->textWidth();
    tdoc = item->clone();
    QTextFrame  *Tframe = tdoc->rootFrame();
    rootformat = Tframe->frameFormat();
    pnord->setValue(rootformat.topMargin());
    psud->setValue(rootformat.bottomMargin());
    pwest->setValue(rootformat.leftMargin());
    post->setValue(rootformat.rightMargin());
    
    connect(pnord, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
    connect(psud, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
    connect(pwest, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
    connect(post, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
    LoadButtonControll();
    InitValue = recter;
    
    
   
    
    
    
    BorderDicks = borders;
    BGColor = sfondo;
    AlphaColor = sfondo.alpha();
    MarginColor = margincolor;
    
     QPixmap pixbg(22, 22);
     pixbg.fill(sfondo);
    
     QPixmap pixma(22, 22);
     pixma.fill(margincolor);
    
      Mabg->setIcon(pixma);
      Cobg->setIcon(pixbg);
      MarginSize->setValue ( borders );
    
      BoxAltezza->setValue ( recter.height() );
      BoxLarghezza->setValue ( recter.width() );
    
      ///////Vol_Rotate->setValue ( rotate );
      connect(BoxAltezza, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
      connect(BoxLarghezza, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
      connect(MarginSize, SIGNAL(valueChanged(double)), this, SLOT(UpdateVars()));
      
      connect(Mabg, SIGNAL(clicked()), this,  SLOT(SetMarginColor()));
      connect(Cobg, SIGNAL(clicked()), this,  SLOT(SetBGColor()));
      connect(CurrentImagePlay, SIGNAL(clicked()), this,  SLOT(ImageToClipbord()));
      connect(SaveToPath, SIGNAL(clicked()), this,  SLOT(SaveCurrentImageStream()));
      
      
      connect(Vol_21, SIGNAL(clicked()), wtxt, SLOT(InsertImageonCursor()));
      
      
      connect(pushButton, SIGNAL(clicked()), this, SLOT(SaveNewFormat()));
      connect(EditableOr, SIGNAL(toggled(bool)), wtxt, SLOT(Editablemodus(bool)));
      connect(wtxt, SIGNAL(SaveStreamer()), this, SLOT(SaveNewFormat()));
      connect(wtxt, SIGNAL(DDclick()), this, SLOT(TableImageSetup()));
      
      connect(tabiborder, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));
      connect(imghi, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentImage()));
      connect(imgwi, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentImage()));
   
      
      
      connect(tabiwi, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));
      connect(tabipadding, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));
      connect(tabiborder, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));
      connect(tabispacing, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));
      
      connect(alignetable, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(UpdateCurrentTable()));
      
      connect(Vol_6, SIGNAL(clicked(bool)), wtxt, SLOT(MakeHrefLink()));
      connect(Vol_22, SIGNAL(clicked()), this, SLOT(CurrentParamMargin()));
      
    
    
      
///////////connect(tabiborder, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurrentTable()));

      //////////FontChanged(workfont);
      
  }