Пример #1
0
// Reimplemented 
void QmvItem::paintCell( QPainter *p, const QColorGroup &cg,
                                 int column, int width, int alignment )
{
    QListView *listview = listView();
    
    QColorGroup g( cg );
    g.setColor( QColorGroup::Base, backgroundColor() );
    g.setColor( QColorGroup::Foreground, Qt::black );
    g.setColor( QColorGroup::Text, Qt::black );
    
    int indent = 0;
    if ( column == 0 ) {
        indent = 20 + (shuttletupleattribute  ? 20 : 0 );
        p->fillRect( 0, 0, width, height(), backgroundColor() );
        p->save();
        p->translate( indent, 0 );
    }

    if ( isChanged() && column == 0 ) {
        p->save();
        QFont f = p->font();
        f.setBold( TRUE );
        p->setFont( f );
    }

    if ( !hasCustomContents() || column != 1 ) {
        QListViewItem::paintCell( p, g, column, width - indent, alignment  );
    } else {
        p->fillRect( 0, 0, width, height(), backgroundColor() );
        drawCustomContents( p, QRect( 0, 0, width, height() ) );
    }
    
    if ( isChanged() && column == 0 )
        p->restore();
    if ( column == 0 )
        p->restore();
        // Draw +/- open/close control icon on tuple items
    if ( !shuttletupleattribute && column == 0 ) {
        p->save();
        p->setPen( cg.foreground() );
        p->setBrush( cg.base() );
        p->drawRect( 5, height() / 2 - 4, 9, 9 );
        p->drawLine( 7, height() / 2, 11, height() / 2 );
        if ( !isOpen() )
            p->drawLine( 9, height() / 2 - 2, 9, height() / 2 + 2 );
        p->restore();
    }
    
    p->save();
    p->setPen( QPen( cg.dark(), 1 ) );
    p->drawLine( 0, height() - 1, width, height() - 1 );
    p->drawLine( width - 1, 0, width - 1, height() );
    p->restore();

    if ( listview->currentItem() == this && column == 0 &&
         !listview->hasFocus() && !listview->viewport()->hasFocus() )
        paintFocus( p, cg, QRect( 0, 0, width, height() ) );


}
Пример #2
0
void BigCharWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);

    // paint with default background color
    painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()));

    QPen pen;
    pen.setColor({149,195,244,255});
    pen.setWidth(3);
    pen.setStyle(Qt::PenStyle::SolidLine);

    State *state = State::getInstance();
    quint8* charPtr = state->getCharAtIndex(_charIndex);

    for (int y=0; y<_tileProperties.size.height(); y++) {
        for (int x=0; x<_tileProperties.size.width(); x++) {

            paintChar(painter, pen, charPtr, QPoint{x,y});
            // chars could be 64 chars away from each other
            charPtr +=  _tileProperties.interleaved * 8;
        }
    }

    paintSeparators(painter);
    paintFocus(painter);

    painter.end();
}
Пример #3
0
void TilesetWidget::paintEvent(QPaintEvent *event)
{
    auto state = MainWindow::getCurrentState();

    // no open documents?
    if (!state)
        return;

    QPainter painter;

    painter.begin(this);
    painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()));

    painter.setBrush(QColor(0,0,0));
    painter.setPen(Qt::NoPen);

    QPen pen;
    pen.setColor({149,195,244,255});
    pen.setWidth(hasFocus() ? 3 : 1 );
    pen.setStyle(Qt::PenStyle::SolidLine);

    auto tileProperties = state->getTileProperties();
    int tw = tileProperties.size.width();
    int th = tileProperties.size.height();

    int max_tiles = 256 / (tw*th);

    for (int i=0; i<max_tiles;i++)
    {
        quint8 charIdx = tileProperties.interleaved == 1 ?
                                                    i * tw * th :
                                                    i;

        int w = (i * tw) % _columns;
        int h = th * ((i * tw) / _columns);

        for (int char_idx=0; char_idx < (tw * th); char_idx++)
        {
            int local_w = w + char_idx % tw;
            int local_h = h + char_idx / tw;

            utilsDrawChar(state, &painter, _pixelSize, QPoint(OFFSET, OFFSET), QPoint(local_w, local_h), charIdx);

            charIdx += tileProperties.interleaved;
        }
    }

    painter.setPen(Qt::NoPen);

    paintFocus(painter);
    paintSelectedTile(painter);

    painter.end();
}
Пример #4
0
			void ButtonTheme::paint(Graphics &g, const Component *comp) const
			{
				const AbstractButton *button = static_cast<const AbstractButton*>(comp);

				if(button->isContentAreaFilled())
				{
					BasicComponent::paint(g,button);
				}
				util::Dimension componentBoundingBox(button->getBounds().width,button->getBounds().height);
				util::Dimension iconBoundingBox(textUtil.getIconBoundingBox(getActiveIcon(button)));

				StringInfoBuffer stringInfo(textUtil.fitStringInBoundingBox(button->getText(),componentBoundingBox,iconBoundingBox,button->getFont(),button->getInsets(),button->getMargin()));

				util::Dimension stringBoundingBox(textUtil.getStringBoundingBox(stringInfo));

				int verticalIconAlignment = textUtil.getVerticalAlignment(iconBoundingBox,componentBoundingBox,button->getVerticalAlignment(),button->getInsets(),button->getMargin());
				int verticalTextAlignment = textUtil.getVerticalAlignment(stringBoundingBox,componentBoundingBox,button->getVerticalAlignment(),button->getInsets(),button->getMargin());
				int horizontalAlignment = textUtil.getHorizontalAlignment(stringBoundingBox,iconBoundingBox,componentBoundingBox,button->getHorizontalAlignment(),button->getInsets(),button->getMargin());

				if(getActiveIcon(button) != 0)
				{
					getActiveIcon(button)->paint(button,g,horizontalAlignment,verticalIconAlignment);
					horizontalAlignment += getActiveIcon(button)->getIconWidth();
				}

				g.setPaint(button->getForeground());
				g.setFont(button->getFont());

				if(button->hasFocus() && button->isFocusPainted())
				{
					paintFocus(horizontalAlignment,verticalTextAlignment,g,componentBoundingBox,stringBoundingBox,3);
				}

				if(getActiveIcon(button) != 0)
				{
					paintButton(horizontalAlignment,verticalTextAlignment,g,stringInfo,stringBoundingBox,Component::LEFT,getActiveIcon(button));
				}
				else
				{
					paintButton(horizontalAlignment,verticalTextAlignment,g,stringInfo,stringBoundingBox,Component::CENTER,getActiveIcon(button));
				}
			}
void QSysMLAction::paint(QPainter* painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(option);
	Q_UNUSED(widget);

    painter->save();

	painter->setPen(diagram()->styleSheet()->lineStyle("ControlFlowLineStyle").pen());
	painter->drawPath(shapeConnectionLines());

    painter->restore();
    painter->save();

	QBrush b = qdiagramproperty_cast<QBrush>(property("background"));
    painter->setBrush(b);

	painter->setPen(qdiagramproperty_cast<QPen>(property("lineStyle")));
	painter->drawPath(shapeInternal());

    painter->restore();
    paintFocus(painter, option, widget);
}
void QSysMLBlock::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	QColor color = qdiagramproperty_cast<QColor>(property("backgroundColor"));
    painter->setBrush(QBrush(color, Qt::SolidPattern));
    painter->drawRect(0, 0, geometry().width(), geometry().height());

    QFont f = pointToPixel(qdiagramproperty_cast<QFont>(property("textFont")));
 
    QFontMetricsF fm(f);
    qreal pixelsWide = fm.width("M");
    qreal pixelsHigh = fm.height();
    // « »
    QRect br = boundingRect().adjusted(-2, -2, -2, -2).toRect();
    QRect r(0, 5, geometry().width(), pixelsHigh);
    painter->setFont(f);
    painter->drawText(r, Qt::AlignHCenter, "«block»");
    f.setBold(true);
    painter->setFont(f);
    painter->drawText(0, r.height() + fm.leading(), geometry().width(), geometry().height(), Qt::AlignHCenter | Qt::TextWordWrap, property("name").toString(), &br);

    paintFocus(painter, option, widget);
}
void UIGSelectorItemMachine::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget * /* pWidget = 0 */)
{
    /* Initialize some necessary variables: */
    QRect fullRect = pOption->rect;
    int iMachineItemMargin = data(MachineItemData_MachineItemMargin).toInt();
    int iMachineItemMajorSpacing = data(MachineItemData_MachineItemMajorSpacing).toInt();
    int iMachineItemMinorSpacing = data(MachineItemData_MachineItemMinorSpacing).toInt();
    int iMachineItemTextSpacing = data(MachineItemData_MachineItemTextSpacing).toInt();
    QSize machinePixmapSize = data(MachineItemData_MachinePixmapSize).toSize();
    QSize machineNameSize = data(MachineItemData_MachineNameSize).toSize();
    QString strSnapshotName = data(MachineItemData_SnapshotName).toString();
    QSize snapshotNameSize = data(MachineItemData_SnapshotNameSize).toSize();
    QSize machineStatePixmapSize = data(MachineItemData_MachineStatePixmapSize).toSize();
    QSize machineStateTextSize = data(MachineItemData_MachineStateTextSize).toSize();

    /* Paint background: */
    paintBackground(/* Painter: */
                    pPainter,
                    /* Rectangle to paint in: */
                    fullRect,
                    /* Has parent? */
                    parentItem(),
                    /* Is item selected? */
                    model()->selectionList().contains(this),
                    /* Gradient darkness for animation: */
                    gradient(),
                    /* Show drag where? */
                    dragTokenPlace());

    /* Paint pixmap: */
    paintPixmap(/* Painter: */
                pPainter,
                /* Rectangle to paint in: */
                QRect(fullRect.topLeft() +
                      QPoint(iMachineItemMargin, iMachineItemMargin),
                      machinePixmapSize),
                /* Pixmap to paint: */
                data(MachineItemData_MachinePixmap).value<QIcon>().pixmap(machinePixmapSize));

    /* Paint name: */
    paintText(/* Painter: */
              pPainter,
              /* Rectangle to paint in: */
              QRect(fullRect.topLeft() +
                    QPoint(iMachineItemMargin, iMachineItemMargin) +
                    QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0),
                    machineNameSize),
              /* Font to paint text: */
              data(MachineItemData_MachineNameFont).value<QFont>(),
              /* Text to paint: */
              data(MachineItemData_MachineName).toString());

    /* Paint snapshot name (if necessary): */
    if (!strSnapshotName.isEmpty())
        paintText(/* Painter: */
                  pPainter,
                  /* Rectangle to paint in: */
                  QRect(fullRect.topLeft() +
                        QPoint(iMachineItemMargin, iMachineItemMargin) +
                        QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                        QPoint(machineNameSize.width() + iMachineItemMinorSpacing, 0),
                        snapshotNameSize),
                  /* Font to paint text: */
                  data(MachineItemData_SnapshotNameFont).value<QFont>(),
                  /* Text to paint: */
                  QString("(%1)").arg(strSnapshotName));

    /* Paint state pixmap: */
    paintPixmap(/* Painter: */
                pPainter,
                /* Rectangle to paint in: */
                QRect(fullRect.topLeft() +
                      QPoint(iMachineItemMargin, iMachineItemMargin) +
                      QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                      QPoint(0, machineNameSize.height() + iMachineItemTextSpacing),
                      machineStatePixmapSize),
                /* Pixmap to paint: */
                data(MachineItemData_MachineStatePixmap).value<QIcon>().pixmap(machineStatePixmapSize));

    /* Paint state text: */
    paintText(/* Painter: */
              pPainter,
              /* Rectangle to paint in: */
              QRect(fullRect.topLeft() +
                    QPoint(iMachineItemMargin, iMachineItemMargin) +
                    QPoint(machinePixmapSize.width() + iMachineItemMajorSpacing, 0) +
                    QPoint(0, machineNameSize.height() + iMachineItemTextSpacing) +
                    QPoint(machineStatePixmapSize.width() + iMachineItemMinorSpacing, 0),
                    machineStateTextSize),
              /* Font to paint text: */
              data(MachineItemData_MachineStateTextFont).value<QFont>(),
              /* Text to paint: */
              data(MachineItemData_MachineStateText).toString());

    /* Paint focus (if necessary): */
    if (model()->focusItem() == this)
        paintFocus(/* Painter: */
                   pPainter,
                   /* Rectangle to paint in: */
                   fullRect);
}
Пример #8
0
void CharsetWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter;

    painter.begin(this);
    painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()));

    painter.setBrush(QColor(0,0,0));
    painter.setPen(Qt::NoPen);

    auto state = State::getInstance();

    int end_x = 8;
    int pixel_size_x = _pixelSize.width();
    int increment_x = 1;
    int bits_to_mask = 1;

    if (state->shouldBeDisplayedInMulticolor())
    {
        end_x = 4;
        pixel_size_x = _pixelSize.width() * 2;
        increment_x = 2;
        bits_to_mask = 3;
    }

    QPen pen;
    pen.setColor({149,195,244,255});
    if (hasFocus())
        pen.setWidth(3);
    else
        pen.setWidth(1);
    pen.setStyle(Qt::PenStyle::SolidLine);

    for (int w=0; w<COLUMNS; w++) {
        for (int h=0; h<ROWS; h++) {

            int index = w + h * COLUMNS;
            quint8* charPtr = state->getCharAtIndex(index);

            for (int y=0; y<8; y++) {

                char letter = charPtr[y];

                for (int x=0; x<end_x; x++) {

                    // Warning: Don't use 'char'. Instead use 'unsigned char'.
                    // 'char' doesn't work Ok with << and >>
                    // only mask the bits are needed
                    unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x);

                    unsigned char color = letter & mask;
                    // now transform those bits into values from 0-3 since those are the
                    // possible colors

                    int bits_to_shift = (((end_x-1)-x) * increment_x);
                    int color_pen = color >> bits_to_shift;

                    if (!state->shouldBeDisplayedInMulticolor() && color_pen )
                        color_pen = State::PEN_FOREGROUND;
                    painter.setBrush(Palette::getColorForPen(color_pen));
                    painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET,
                                     (h*8+y) * _pixelSize.height() + OFFSET,
                                     pixel_size_x,
                                     _pixelSize.height());
                }
            }

            painter.setPen(Qt::NoPen);
        }
    }

    if (_selecting) {
        pen.setColor({149,195,244,255});
        painter.setPen(pen);
        painter.setBrush(QColor(149,195,244,64));
        painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET,
                         _cursorPos.y() * 8 * _pixelSize.height() + OFFSET,
                         _selectingSize.width() * 8 * _pixelSize.width(),
                         _selectingSize.height() * 8 * _pixelSize.height());
    }
    else
    {
        pen.setColor({149,195,244,255});
        painter.setPen(pen);
        painter.setBrush(QColor(128,0,0,0));
        painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET,
                         _cursorPos.y() * 8 * _pixelSize.height() + OFFSET,
                         8 * _pixelSize.width(),
                         8 * _pixelSize.height());
    }

    paintFocus(painter);
    painter.end();
}