Ejemplo n.º 1
0
void Slider::paintEvent(QPaintEvent *event)
{
	QPainter painter(this);

	int w = event->rect().width();
	int h = event->rect().height();
	painter.fillRect(event->rect(), QBrush(backcolor));
	painter.fillRect(3, h/2, w-6, 4, QBrush(bordercolor));
	painter.fillRect(4, h/2+1, w-8, 2, QBrush(forecolor));
	int x = clamp((w/100.0) * value, 0, w-8);
	painter.fillRect(x, h/2-6, 8, 16, QBrush(bordercolor));
	painter.fillRect(x+1, h/2-5, 6, 14, QBrush(forecolor));
	if(mousedown)
	{
		if(style == 1 && parent->trackView->status != TrackView::Status::Stop)
		{
			int length = parent->trackView->playtrack.length;
			int time = length / 100.0 * value;
			QString text = QString("%1:%2").arg(QString::number(time / 60), QString::number(time % 60));
			painter.fillRect(x-16, 0, 38, 16, QBrush(bordercolor));
			painter.fillRect(x-15, 1, 36, 14, QBrush(forecolor));
			painter.drawStaticText(x-14, 0, QStaticText(text));
		}
		else 
		{
		
		}
	}
}
Ejemplo n.º 2
0
Intro::Intro(Force *f, QWidget *parent) :
	QWidget(parent)
{
	QFile file(":/texts/intro.txt");
	QTextStream in(&file);
	QString tmp;
	QTextOption tops;

	in.setCodec("UTF-8");

	if(file.open(QFile::ReadOnly)) {
		do {
			tmp = in.readLine();
			text.append(tmp + "<br />");
		} while(!(tmp.isNull()));
	}

	st = QStaticText(text);
	st.setTextFormat(Qt::RichText);

	tops.setAlignment(Qt::AlignJustify);
	tops.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

	font.setBold(true);
	font.setPixelSize(60);

	connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
	timer.setInterval(66);
	timer.start();
}
Ejemplo n.º 3
0
void tst_QStaticText::drawUnderlinedText()
{
    QPixmap imageDrawText(1000, 1000);
    QPixmap imageDrawStaticText(1000, 1000);

    imageDrawText.fill(Qt::white);
    imageDrawStaticText.fill(Qt::white);

    QString s = QString::fromLatin1("Foobar");

    QFont font;
    font.setUnderline(true);

    {
        QPainter p(&imageDrawText);
        p.setFont(font);
        p.drawText(QPointF(50, 50), s);
    }

    {
        QPainter p(&imageDrawStaticText);
        QStaticText text = QStaticText(s);
        p.setFont(font);
        p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
    }

#if defined(DEBUG_SAVE_IMAGE)
    imageDrawText.save("drawUnderlinedText_imageDrawText.png");
    imageDrawStaticText.save("drawUnderlinedText_imageDrawStaticText.png");
#endif

    QCOMPARE(imageDrawText, imageDrawStaticText);
}
Ejemplo n.º 4
0
void Device::drawStuff(QPainter *p)
{
    qDebug()<<"Drawing Stuffs";
    while (!items.empty()) {
        DrawingItem *item = items.front();
        switch (item->eType) {
        case DrawingItem::RECT:
            qDebug("Drawing Rect");
            p->fillRect(item->eRect.x, item->eRect.y,
                                        item->eRect.width, item->eRect.height,
                                        QColor(item->eRect.backgroundColor.r,
                                               item->eRect.backgroundColor.g,
                                               item->eRect.backgroundColor.b,
                                               item->eRect.backgroundColor.a));
            break;t
        case DrawingItem::TEXT:
            p->drawStaticText(item->eText.x,
                                                item->eText.y,
                                                QStaticText(item->eText.text));
            break;
        case DrawingItem::IMG:

            break;
        default:
            break;
        }
         items.pop_front();
        free(item);
        item = NULL;
    }
}
Ejemplo n.º 5
0
void NodeLabel::setText(const QString & text)
{
    // update the text
    m_text = QStaticText(text);
    m_text.setTextFormat(Qt::PlainText);
    QTextOption textOption =
        QTextOption(Qt::AlignHCenter | Qt::AlignBaseline);
    textOption.setUseDesignMetrics(false);
    m_text.setTextOption(textOption);
    updateStyle();
}
Ejemplo n.º 6
0
void KGVisualItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setPen(QColor(Qt::black));
    painter->setBrush(QBrush(Qt::black));
    painter->drawRect(QRectF(QPointF(0,0),layout()->effectiveSizeHint(Qt::MinimumSize) - QSizeF(20, 0)));

    painter->setPen(QColor(155,155,155));
    painter->setFont(QFont(painter->font().family(), 12, QFont::Bold));
    painter->drawStaticText(45,8, QStaticText(m_name));

}
Ejemplo n.º 7
0
void SelectionHighlight::paint(QPainter *painter)
{
    if (!item())
        return;
    painter->save();
    painter->fillRect(QRectF(0,0,contentsSize().width(), contentsSize().height()),
                      QColor(0,0,0,127));
    painter->setTransform(transform());
    // Setting the composition mode such that the transparency will
    // be erased as per the selected item.
    painter->setCompositionMode(QPainter::CompositionMode_Clear);
    painter->fillRect(0, 0, item()->width(), item()->height(), Qt::black);
    painter->restore();

    // Use the painter with the original transform and not with the
    // item's transform for display of name.
    if (!m_nameDisplayActive)
        return;

    // Paint the text in gray background if display name is active..
    QRect textRect = painter->boundingRect(QRect(10, contentsSize().height() - 10 ,
                                 contentsSize().width() - 20, contentsSize().height()),
                                 Qt::AlignCenter | Qt::ElideRight, m_name);

    qreal xPosition = m_displayPoint.x();
    if (xPosition + textRect.width() > contentsSize().width())
        xPosition = contentsSize().width() - textRect.width();
    if (xPosition < 0) {
        xPosition = 0;
        textRect.setWidth(contentsSize().width());
    }
    qreal yPosition = m_displayPoint.y() - textRect.height() - 20;
    if (yPosition < 50 )
        yPosition = 50;

    painter->fillRect(QRectF(xPosition - 5, yPosition - 5,
                      textRect.width() + 10, textRect.height() + 10), Qt::gray);
    painter->drawRect(QRectF(xPosition - 5, yPosition - 5,
                      textRect.width() + 10, textRect.height() + 10));

    painter->drawStaticText(xPosition, yPosition, QStaticText(m_name));
}
Ejemplo n.º 8
0
void TransferFunctionEditor::drawGrid(QPainter & painter, int w, int h)
{
  QColor c(128, 128, 128, 128);

  QPen pen(c);
  pen.setWidth(1);

  QBrush brush(c);

  painter.setPen(pen);
  painter.setBrush(brush);

  // vykreslenie samotnej mriezky
  painter.setRenderHint(QPainter::Antialiasing, false);
  painter.setRenderHint(QPainter::HighQualityAntialiasing, false);

  const int vert_step = 20;
  const int horz_step = 10;

  // horizontalne ciary mriezky
  for (int i = INNER_PADDING_BOTTOM; i < h - INNER_PADDING_TOP; i += horz_step)
  {
    painter.drawLine(INNER_PADDING_LEFT, h - i, w - INNER_PADDING_RIGHT, h - i);
  }

  // vertikalne ciary mriezky
  for (int i = INNER_PADDING_LEFT; i < w - INNER_PADDING_RIGHT; i += vert_step)
  {
    painter.drawLine(i, INNER_PADDING_TOP, i, h - INNER_PADDING_BOTTOM);
  }

  painter.setRenderHint(QPainter::Antialiasing, true);
  painter.setRenderHint(QPainter::HighQualityAntialiasing, true);

  pen.setWidth(2);
  painter.setPen(pen);

  // vykreslenie horizontalnej osi
  const QPointF triangle_horz[3] = {
    QPointF(w - INNER_PADDING_RIGHT + EXTRA_INNNER_PADDING_RIGHT,                   h - INNER_PADDING_BOTTOM - 2.5f),
    QPointF(w - INNER_PADDING_RIGHT + EXTRA_INNNER_PADDING_RIGHT + AXIS_ARROW_SIZE, h - INNER_PADDING_BOTTOM + 0.0f),
    QPointF(w - INNER_PADDING_RIGHT + EXTRA_INNNER_PADDING_RIGHT,                   h - INNER_PADDING_BOTTOM + 2.5f)
  };

  painter.drawLine(INNER_PADDING_LEFT, h - INNER_PADDING_BOTTOM, w - INNER_PADDING_RIGHT + EXTRA_INNNER_PADDING_RIGHT, h - INNER_PADDING_BOTTOM);
  painter.drawPolygon(triangle_horz, 3);

  // vykreslenie vertikalnej osi
  const QPointF triangle_vert[3] = {
    //                       x      y
    QPointF(INNER_PADDING_LEFT - 2.5f, INNER_PADDING_TOP - EXTRA_INNNER_PADDING_TOP), // lavy bod
    QPointF(INNER_PADDING_LEFT + 2.5f, INNER_PADDING_TOP - EXTRA_INNNER_PADDING_TOP), // pravy bod
    QPointF(INNER_PADDING_LEFT + 0.0f, INNER_PADDING_TOP - EXTRA_INNNER_PADDING_TOP - AXIS_ARROW_SIZE)  // stredny bod
  };

  painter.drawLine(INNER_PADDING_LEFT, h - INNER_PADDING_BOTTOM, INNER_PADDING_LEFT, INNER_PADDING_TOP - EXTRA_INNNER_PADDING_TOP);
  painter.drawPolygon(triangle_vert, 3);

  // vykreslenie horizontalneho popisku
  painter.drawStaticText(w - INNER_PADDING_RIGHT - 40, h - INNER_PADDING_BOTTOM + 2, QStaticText("intensity"));

  // vykreslenie vertikalneho popisku
  {
    QTransform old_t = painter.transform();
    QTransform t;
    t.translate(0, INNER_PADDING_TOP + 30);
    t.rotate(-90);
    painter.setTransform(t);
    painter.drawStaticText(0, 0, QStaticText("opacity"));
    painter.setTransform(old_t);
  }
}