예제 #1
0
 void setUnicodeText(const QString &text, const QFont &font, const QColor &color)
 {
     deleteContent();
     QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);
     qreal line_width = raw_font.averageCharWidth() * text.size();
     QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
     QTextLayout layout(text,font);
     layout.beginLayout();
     QTextLine line = layout.createLine();
     line.setLineWidth(line_width);
     //Q_ASSERT(!layout.createLine().isValid());
     layout.endLayout();
     QList<QGlyphRun> glyphRuns = line.glyphRuns();
     qreal xpos = 0;
     for (int i = 0; i < glyphRuns.size(); i++) {
         QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
         node->setOwnerElement(m_owner);
         node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
         node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
         node->setGlyphs(QPointF(xpos, raw_font.ascent()), glyphRuns.at(i));
         node->setStyle(QQuickText::Normal);
         node->setColor(color);
         xpos += raw_font.averageCharWidth() * glyphRuns.at(i).positions().size();
         node->update();
         appendChildNode(node);
     }
 }
예제 #2
0
void ContentData::clear()
{
    deleteContent();

    ContentData* n = m_next;
    m_next = 0;

    // Reverse the list so we can delete without recursing.
    ContentData* last = 0;
    ContentData* c;
    while ((c = n)) {
        n = c->m_next;
        c->m_next = last;
        last = c;
    }
    for (c = last; c; c = n) {
        n = c->m_next;
        c->m_next = 0;
        delete c;
    }
}
예제 #3
0
    void setLatinText(const QString &text, const QFont &font, const QColor &color) {
        QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);

        if (raw_font != m_raw_font) {
            m_raw_font = raw_font;
            m_positions.clear();
        }

        if (m_positions.size() < text.size()) {
            qreal x_pos = 0;
            qreal max_char_width = raw_font.averageCharWidth();
            qreal ascent = raw_font.ascent();
            if (m_positions.size())
                x_pos = m_positions.last().x() + max_char_width;
            int to_add = text.size() - m_positions.size();
            for (int i = 0; i < to_add; i++) {
                m_positions << QPointF(x_pos, ascent);
                x_pos += max_char_width;
            }
        }

        deleteContent();

        QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
        QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
        node->setOwnerElement(m_owner);
        node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
        node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
        node->setStyle(QQuickText::Normal);

        node->setColor(color);
        QGlyphRun glyphrun;
        glyphrun.setRawFont(raw_font);
        glyphrun.setGlyphIndexes(raw_font.glyphIndexesForString(text));

        glyphrun.setPositions(m_positions);
        node->setGlyphs(QPointF(0, raw_font.ascent()), glyphrun);
        node->update();
        appendChildNode(node);
    }
예제 #4
0
파일: scgview.cpp 프로젝트: pkkazantsev/kbe
void SCgView::createActions()
{
    QAction* sep = new QAction(this);
    sep->setSeparator(true);
    mActionsList.append(sep);

    mActionChangeContent = new QAction(mWindow->findIcon("edit-content-change.png"),tr("Set content"),mWindow);
    mActionChangeContent->setShortcut(QKeySequence( tr("C") ));
    connect(mActionChangeContent, SIGNAL(triggered()), this, SLOT(changeContent()));

    mActionShowContent = new QAction(tr("Show content"),mWindow);
    mActionShowContent->setCheckable(true);
    mActionShowContent->setShortcut(QKeySequence( tr("H") ));
    connect(mActionShowContent, SIGNAL(triggered(bool)), this, SLOT(setContentVisible(bool)));

    mActionShowAllContent = new QAction(tr("Show all content"), mWindow);
    connect(mActionShowAllContent, SIGNAL(triggered(bool)), this, SLOT(setContentVisible(bool)));

    mActionHideAllContent = new QAction(tr("Hide all content"), mWindow);
    connect(mActionHideAllContent, SIGNAL(triggered(bool)), this, SLOT(setContentVisible(bool)));

    mActionDeleteContent = new QAction(mWindow->findIcon("edit-content-delete.png"), tr("Delete content"), mWindow);
    mActionDeleteContent->setShortcut(QKeySequence( tr("D") ));
    connect(mActionDeleteContent, SIGNAL(triggered()), this, SLOT(deleteContent()));

    mActionChangeIdtf = new QAction(mWindow->findIcon("edit-change-idtf.png"), tr("Change identifier"), mWindow);
    mActionChangeIdtf->setShortcut(QKeySequence( tr("I") ));
    connect(mActionChangeIdtf, SIGNAL(triggered()), this, SLOT(changeIdentifier()));

    mActionDelete = new QAction(QIcon::fromTheme("edit-delete", mWindow->findIcon("edit-delete.png")), tr("Delete"), mWindow);
    mActionDelete->setShortcut(QKeySequence::Delete);
    connect(mActionDelete, SIGNAL(triggered()), this, SLOT(deleteSelected()));

    mActionContourDelete = new QAction(mWindow->findIcon("edit-delete.png"), tr("Delete contour"), mWindow);
    mActionContourDelete->setShortcut( QKeySequence(tr("Backspace")) );
    connect(mActionContourDelete, SIGNAL(triggered()), this, SLOT(deleteJustContour()));

    mActionSwapPairOrient = new QAction(mWindow->findIcon("edit-swap-pair.png"), tr("Swap orientation"), mWindow);
    mActionSwapPairOrient->setShortcut( QKeySequence(tr("S")));
    connect(mActionSwapPairOrient, SIGNAL(triggered()), this, SLOT(swapPairOrient()));

    mActionCopy = new QAction(QIcon::fromTheme("edit-copy", mWindow->findIcon("edit-copy.png")), tr("Copy"),this);
    mActionCopy->setShortcut(QKeySequence::Copy);
    connect(mActionCopy, SIGNAL(triggered()), mWindow, SLOT(copy()));

    mActionCut = new QAction(QIcon::fromTheme("edit-cut", mWindow->findIcon("edit-cut.png")), tr("Cut"),this);
    mActionCut->setShortcut(QKeySequence::Cut);
    connect(mActionCut, SIGNAL(triggered()), mWindow, SLOT(cut()));

    mActionPaste = new QAction(QIcon::fromTheme("edit-paste", mWindow->findIcon("edit-paste.png")), tr("Paste"),this);
    mActionPaste->setShortcut(QKeySequence::Paste);
    connect(mActionPaste, SIGNAL(triggered()), mWindow, SLOT(paste()));

    mActionSelectAll = new QAction(QIcon::fromTheme("edit-select-all", mWindow->findIcon("edit-select-all.png")), tr("Select All"),this);
    mActionSelectAll->setShortcut(QKeySequence::SelectAll);
    connect(mActionSelectAll, SIGNAL(triggered()), this, SLOT(selectAllCommand()));


    mActionsList.append(mActionChangeContent);
    mActionsList.append(mActionShowContent);
    mActionsList.append(mActionShowAllContent);
    mActionsList.append(mActionHideAllContent);
    mActionsList.append(mActionDeleteContent);

    sep = new QAction(this);
    sep->setSeparator(true);
    mActionsList.append(sep);

    mActionsList.append(mActionChangeIdtf);
    mActionsList.append(mActionSwapPairOrient);

    sep = new QAction(this);
    sep->setSeparator(true);
    mActionsList.append(sep);

    mActionsList.append(mActionCopy);
    mActionsList.append(mActionCut);
    mActionsList.append(mActionPaste);

    sep = new QAction(this);
    sep->setSeparator(true);
    mActionsList.append(sep);

    mActionsList.append(mActionSelectAll);

    sep = new QAction(this);
    sep->setSeparator(true);
    mActionsList.append(sep);

    mActionsList.append(mActionContourDelete);
    mActionsList.append(mActionDelete);
}
예제 #5
0
void QQuickTextNode::updateNodes()
{
    return;
    deleteContent();
    if (m_text.isEmpty())
        return;

    if (m_usePixmapCache) {
        // ### gunnar: port properly
//        QPixmap pixmap = generatedPixmap();
//        if (pixmap.isNull())
//            return;

//        QSGImageNode *pixmapNode = m_context->createImageNode();
//        pixmapNode->setRect(pixmap.rect());
//        pixmapNode->setSourceRect(pixmap.rect());
//        pixmapNode->setOpacity(m_opacity);
//        pixmapNode->setClampToEdge(true);
//        pixmapNode->setLinearFiltering(m_linearFiltering);

//        appendChildNode(pixmapNode);
    } else {
        if (m_text.isEmpty())
            return;

        // Implement styling by drawing text several times at slight shifts. shiftForStyle
        // contains the sequence of shifted positions at which to draw the text. All except
        // the last will be drawn with styleColor.
        QList<QPointF> shiftForStyle;
        switch (m_textStyle) {
        case OutlineTextStyle:
            // ### Should be made faster by implementing outline material
            shiftForStyle << QPointF(-1, 0);
            shiftForStyle << QPointF(0, -1);
            shiftForStyle << QPointF(1, 0);
            shiftForStyle << QPointF(0, 1);
            break;
        case SunkenTextStyle:
            shiftForStyle << QPointF(0, -1);
            break;
        case RaisedTextStyle:
            shiftForStyle << QPointF(0, 1);
            break;
        default:
            break;
        }

        shiftForStyle << QPointF(0, 0); // Regular position
        while (!shiftForStyle.isEmpty()) {
            QPointF shift = shiftForStyle.takeFirst();

            // Use styleColor for all but last shift
            if (m_richText) {
                QColor overrideColor = shiftForStyle.isEmpty() ? QColor() : m_styleColor;

                QTextFrame *textFrame = m_textDocument->rootFrame();
                QPointF p = m_textDocument->documentLayout()->frameBoundingRect(textFrame).topLeft();

                QTextFrame::iterator it = textFrame->begin();
                while (!it.atEnd()) {
                    addTextBlock(shift + p, it.currentBlock(), overrideColor);
                    ++it;
                }
            } else {
                addTextLayout(shift, m_textLayout, shiftForStyle.isEmpty()
                              ? m_color
                              : m_styleColor);
            }
        }
    }
}