Exemplo n.º 1
0
void ChatAreaWidget::mouseReleaseEvent(QMouseEvent * event)
{
    QTextEdit::mouseReleaseEvent(event);
    QPointF documentHitPost(event->pos().x() + horizontalScrollBar()->value(), event->pos().y() + verticalScrollBar()->value());
    int pos = this->document()->documentLayout()->hitTest(documentHitPost, Qt::ExactHit);
    if (pos > 0)
    {
        QTextCursor cursor(document());
        cursor.setPosition(pos);

        if(!cursor.atEnd())
        {
            cursor.setPosition(pos+1);

            QTextFormat format = cursor.charFormat();
            if (format.isImageFormat())
            {
                QString imageName = format.toImageFormat().name();
                if (QRegExp("^data:ftrans.*").exactMatch(imageName))
                {
                    QString data = imageName.right(imageName.length() - 12);
                    int endpos = data.indexOf("/png;base64");
                    data = data.left(endpos);
                    int middlepos = data.indexOf(".");
                    QString widgetID = data.left(middlepos);
                    QString widgetBtn = data.right(data.length() - middlepos - 1);
                    qDebug() << "ChatAreaWidget::mouseReleaseEvent:" << widgetID << widgetBtn;
                    emit onFileTranfertInterract(widgetID, widgetBtn);
                }
            }
        }
    }
}
Exemplo n.º 2
0
QSizeF ChartTextObject::intrinsicSize(QTextDocument *doc, int posInDocument,
            const QTextFormat &format)
{
    Q_UNUSED(posInDocument);

    QSizeF size( format.property( Size ).toSizeF() );

    switch ( format.property( Unit ).toInt() ) {
    case Percent: {
        const qreal pageWidth = doc->pageSize().width();
        const qreal percent = size.width();
        const qreal ratio = size.height() / size.width();

        qreal newWidth = pageWidth * percent / 100.0;

        //XXX For some reason 100% width charts will get cropped
        //need to make a little room
        if ( percent == 100.0 )
            newWidth -= 9;

        return QSizeF( newWidth, newWidth * ratio );
        }
    case Millimeters:
        return QSizeF( mmToPixels( size.width() ), mmToPixels( size.height() ) );
    }

    return QSizeF();
}
void QSyntaxHighlighter::setFormat( int start, int count, const QFont &font, const QColor &color )
{
    if ( !para || count <= 0 )
	return;
    QTextFormat *f = 0;
    f = para->document()->formatCollection()->format( font, color );
    para->setFormat( start, count, f );
    f->removeRef();
}
void QSyntaxHighlighter::setFormat( int start, int count, const QFont &font )
{
    if ( !para || count <= 0 )
	return;
    QTextFormat *f = 0;
    QColor c = textEdit()->viewport()->paletteForegroundColor();
    f = para->document()->formatCollection()->format( font, c );
    para->setFormat( start, count, f );
    f->removeRef();
}
Exemplo n.º 5
0
void QSASyntaxHighlighter::updateStyles( const QMap<QString, ConfigStyle> &styles )
{
    for ( QMap<QString, ConfigStyle>::ConstIterator it = styles.begin(); it != styles.end(); ++it ) {
	int id = string2Id( it.key() );
	QTextFormat *f = format( id );
	if ( !f )
	    continue;
	f->setFont( (*it).font );
	f->setColor( (*it).color );
    }
}
Exemplo n.º 6
0
void QTextOdfWriter::writeFormats(QXmlStreamWriter &writer, QSet<int> formats) const
{
    writer.writeStartElement(officeNS, QString::fromLatin1("automatic-styles"));
    QVector<QTextFormat> allStyles = m_document->allFormats();
    QSetIterator<int> formatId(formats);
    while(formatId.hasNext()) {
        int formatIndex = formatId.next();
        QTextFormat textFormat = allStyles.at(formatIndex);
        switch (textFormat.type()) {
        case QTextFormat::CharFormat:
            if (textFormat.isTableCellFormat())
                writeTableCellFormat(writer, textFormat.toTableCellFormat(), formatIndex);
            else
                writeCharacterFormat(writer, textFormat.toCharFormat(), formatIndex);
            break;
        case QTextFormat::BlockFormat:
            writeBlockFormat(writer, textFormat.toBlockFormat(), formatIndex);
            break;
        case QTextFormat::ListFormat:
            writeListFormat(writer, textFormat.toListFormat(), formatIndex);
            break;
        case QTextFormat::FrameFormat:
            writeFrameFormat(writer, textFormat.toFrameFormat(), formatIndex);
            break;
        case QTextFormat::TableFormat:
            ;break;
        }
    }

    writer.writeEndElement(); // automatic-styles
}
Exemplo n.º 7
0
QTextFormat HtmlExporter::formatDifference( const QTextFormat &from, const QTextFormat &to )
{
    //kDebug();

    QTextFormat diff = to;

    const QMap<int, QVariant> props = to.properties();
    for ( QMap<int, QVariant>::ConstIterator it = props.begin(), end = props.end();
            it != end; ++it )
        if ( it.value() == from.property( it.key() ) )
            diff.clearProperty( it.key() );

    return diff;
}
Exemplo n.º 8
0
bool KoChangeTracker::containsInlineChanges(const QTextFormat &format) const
{
    if (format.property(KoCharacterStyle::ChangeTrackerId).toInt())
        return true;

    return false;
}
Exemplo n.º 9
0
//![1]
void SvgTextObject::drawObject(QPainter *painter, const QRectF &rect,
                               QTextDocument * /*doc*/, int /*posInDocument*/,
                               const QTextFormat &format)
{
    QImage bufferedImage = qVariantValue<QImage>(format.property(Window::SvgData));

    painter->drawImage(rect, bufferedImage);
}
Exemplo n.º 10
0
void CaretInterface::drawObject(QPainter *painter, const QRectF &rect, QTextDocument *, int, const QTextFormat &format)
 {         
     painter->setRenderHint(QPainter::Antialiasing, true);
     int c = format.property(Color).toInt();     
     QColor color(c & 0xff, (c & 0xff00) / 0x100, (c & 0xff0000) / 0x10000);
     QString text = format.property(Text).toString();
     painter->setFont(m_font);
     // painter->fillRect(rect, QBrush(color));
     painter->setBrush(QBrush(color));
     painter->setPen(QPen(Qt::NoPen));
     QRectF r2( rect.x(), rect.y() + 2, rect.width(), rect.height() + 2);
     painter->drawRoundedRect(r2, 3, 3);
     painter->setPen(QPen(Qt::white));
     QRectF r( rect.x() + 2, rect.y() + 3, rect.width() - 4, rect.height() - 2);
     painter->drawText(r, text);
     painter->setRenderHint(QPainter::Antialiasing, false);
 }
QSizeF QTextImageHandler::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)
{
    Q_UNUSED(posInDocument)
    const QTextImageFormat imageFormat = format.toImageFormat();

    if (qApp->thread() != QThread::currentThread())
        return getImageSize(doc, imageFormat);
    return getPixmapSize(doc, imageFormat);
}
void
WidgetTextObject::drawObject(QPainter *painter, const QRectF &rect, QTextDocument * /*doc*/, int /*posInDocument*/, const QTextFormat &format)
{
    QWidget* widget = qVariantValue<QWidget*>(format.property( 1 ));
    widget->render( painter, QPoint( 0, 0 ));

    //Adjusted to allow for the margin
    QRect contentsRect = rect.toRect().adjusted(0, 0, -kMargin.width(), -kMargin.height());
    m_widgetRects[widget] = contentsRect;
}
Exemplo n.º 13
0
int QTextCopyHelper::convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet)
{
    QTextFormat fmt = oldFormat;
    if (objectIndexToSet != -1) {
        fmt.setObjectIndex(objectIndexToSet);
    } else if (fmt.objectIndex() != -1) {
        int newObjectIndex = objectIndexMap.value(fmt.objectIndex(), -1);
        if (newObjectIndex == -1) {
            QTextFormat objFormat = src->formatCollection()->objectFormat(fmt.objectIndex());
            Q_ASSERT(objFormat.objectIndex() == -1);
            newObjectIndex = formatCollection.createObjectIndex(objFormat);
            objectIndexMap.insert(fmt.objectIndex(), newObjectIndex);
        }
        fmt.setObjectIndex(newObjectIndex);
    }
    int idx = formatCollection.indexForFormat(fmt);
    Q_ASSERT(formatCollection.format(idx).type() == oldFormat.type());
    return idx;
}
Exemplo n.º 14
0
void ChartTextObject::drawObject(QPainter *painter, const QRectF &r,
            QTextDocument *doc, int posInDocument, const QTextFormat &format)
{
    Q_UNUSED(doc);
    Q_UNUSED(posInDocument);
    Q_UNUSED(format);

    KDChart::Chart *chart = qvariant_cast<KDChart::Chart*>( format.property( ChartObject ) );

    chart->paint( painter, r.toRect() );
}
Exemplo n.º 15
0
//![0]
QSizeF SvgTextObject::intrinsicSize(QTextDocument * /*doc*/, int /*posInDocument*/,
                                    const QTextFormat &format)
{
    QImage bufferedImage = qVariantValue<QImage>(format.property(Window::SvgData));
    QSize size = bufferedImage.size();
    
    if (size.height() > 25)
        size *= 25.0 / (double) size.height();

    return QSizeF(size);
}
void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)
{
    Q_UNUSED(posInDocument)
        const QTextImageFormat imageFormat = format.toImageFormat();

    if (qApp->thread() != QThread::currentThread()) {
        const QImage image = getImage(doc, imageFormat);
        p->drawImage(rect, image, image.rect());
    } else {
        const QPixmap pixmap = getPixmap(doc, imageFormat);
        p->drawPixmap(rect, pixmap, pixmap.rect());
    }
}
/*!
    \fn void QAbstractTextDocumentLayout::drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format)

    This function is called to draw the inline object, \a object, with the
    given \a painter within the rectangle specified by \a rect using the
    specified text \a format.

    \a posInDocument specifies the position of the object within the document.

    The default implementation calls drawObject() on the object handlers. This
    function is called only within Qt. Subclasses can reimplement this function
    to customize the drawing of inline objects.

    \sa draw()
*/
void QAbstractTextDocumentLayout::drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item,
                                                   int posInDocument, const QTextFormat &format)
{
    Q_UNUSED(item);
    Q_D(QAbstractTextDocumentLayout);

    QTextCharFormat f = format.toCharFormat();
    Q_ASSERT(f.isValid());
    QTextObjectHandler handler = d->handlers.value(f.objectType());
    if (!handler.component)
        return;

    handler.iface->drawObject(p, rect, document(), posInDocument, format);
}
/*!
    Sets the size of the inline object \a item corresponding to the text
    \a format.

    \a posInDocument specifies the position of the object within the document.

    The default implementation resizes the \a item to the size returned by
    the object handler's intrinsicSize() function. This function is called only
    within Qt. Subclasses can reimplement this function to customize the
    resizing of inline objects.
*/
void QAbstractTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format)
{
    Q_D(QAbstractTextDocumentLayout);

    QTextCharFormat f = format.toCharFormat();
    Q_ASSERT(f.isValid());
    QTextObjectHandler handler = d->handlers.value(f.objectType());
    if (!handler.component)
        return;

    QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format);
    item.setWidth(s.width());
    item.setAscent(s.height());
    item.setDescent(0);
}
Exemplo n.º 19
0
void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode)
{
    beginEditBlock();

    Q_ASSERT(newFormat.isValid());

    int newFormatIdx = -1;
    if (mode == SetFormatAndPreserveObjectIndices) {
        QTextCharFormat cleanFormat = newFormat;
        cleanFormat.clearProperty(QTextFormat::ObjectIndex);
        newFormatIdx = formats.indexForFormat(cleanFormat);
    } else if (mode == SetFormat) {
        newFormatIdx = formats.indexForFormat(newFormat);
    }

    if (pos == -1) {
        if (mode == MergeFormat) {
            QTextFormat format = formats.format(initialBlockCharFormatIndex);
            format.merge(newFormat);
            initialBlockCharFormatIndex = formats.indexForFormat(format);
        } else if (mode == SetFormatAndPreserveObjectIndices
                   && formats.format(initialBlockCharFormatIndex).objectIndex() != -1) {
            QTextCharFormat f = newFormat;
            f.setObjectIndex(formats.format(initialBlockCharFormatIndex).objectIndex());
            initialBlockCharFormatIndex = formats.indexForFormat(f);
        } else {
            initialBlockCharFormatIndex = newFormatIdx;
        }

        ++pos;
        --length;
    }

    const int startPos = pos;
    const int endPos = pos + length;

    split(startPos);
    split(endPos);

    while (pos < endPos) {
        FragmentMap::Iterator it = fragments.find(pos);
        Q_ASSERT(!it.atEnd());

        QTextFragmentData *fragment = it.value();

        Q_ASSERT(formats.format(fragment->format).type() == QTextFormat::CharFormat);

        int offset = pos - it.position();
        int length = qMin(endPos - pos, int(fragment->size - offset));
        int oldFormat = fragment->format;

        if (mode == MergeFormat) {
            QTextFormat format = formats.format(fragment->format);
            format.merge(newFormat);
            fragment->format = formats.indexForFormat(format);
        } else if (mode == SetFormatAndPreserveObjectIndices
                   && formats.format(oldFormat).objectIndex() != -1) {
            QTextCharFormat f = newFormat;
            f.setObjectIndex(formats.format(oldFormat).objectIndex());
            fragment->format = formats.indexForFormat(f);
        } else {
            fragment->format = newFormatIdx;
        }

        QTextUndoCommand c = { QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,
                               0, pos, { length }, 0 };
        appendUndoItem(c);

        pos += length;
        Q_ASSERT(pos == (int)(it.position() + fragment->size) || pos >= endPos);
    }

    int n = fragments.findNode(startPos - 1);
    if (n)
        unite(n);

    n = fragments.findNode(endPos);
    if (n)
        unite(n);

    QTextBlock blockIt = blocksFind(startPos);
    QTextBlock endIt = blocksFind(endPos);
    if (endIt.isValid())
        endIt = endIt.next();
    for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
        QTextDocumentPrivate::block(blockIt)->invalidate();

    documentChange(startPos, length);

    endEditBlock();
}
Exemplo n.º 20
0
void QTextDocumentExporter::exportElementBBox(QTextFormat& format, const cf::Element& el) const {
    format.setProperty(BBOX, toQRect(el.boundingRect()));
}
Exemplo n.º 21
0
void tst_QTextFormat::toFormat()
{
    {
        QTextFormat fmt = QTextFrameFormat();
        QCOMPARE(fmt.toFrameFormat().type(), int(QTextFormat::FrameFormat));
    }

    {
        QTextFormat fmt = QTextTableFormat();
        QCOMPARE(fmt.toTableFormat().type(), int(QTextFormat::FrameFormat));
        QCOMPARE(fmt.toTableFormat().objectType(), int(QTextFormat::TableObject));
    }

    {
        QTextFormat fmt = QTextBlockFormat();
        QCOMPARE(fmt.toBlockFormat().type(), int(QTextFormat::BlockFormat));
    }

    {
        QTextFormat fmt = QTextCharFormat();
        QCOMPARE(fmt.toCharFormat().type(), int(QTextFormat::CharFormat));
    }

    {
        QTextFormat fmt = QTextListFormat();
        QCOMPARE(fmt.toListFormat().type(), int(QTextFormat::ListFormat));
    }
}
QSizeF
WidgetTextObject::intrinsicSize(QTextDocument*, int /*posInDocument*/, const QTextFormat& format)
{
    QWidget* widget = qVariantValue<QWidget*>(format.property(1));
    return QSizeF( widget->size() + kMargin );
}
Exemplo n.º 23
0
QSizeF CaretInterface::intrinsicSize(QTextDocument *, int,
                                     const QTextFormat &format)
 {
     return format.property(Size).toSizeF();
 }
Exemplo n.º 24
0
void QTextDocumentExporter::exportElementBgColor(QTextFormat& format, const cf::Element& el) const {
    if(!el.backgroundColor().isNull())
        format.setBackground(QBrush(toQColor(el.backgroundColor())));
}