Пример #1
0
void QtnPropertyDelegateQFont::drawValueImpl(QStylePainter& painter, const QRect& rect, const QStyle::State& state, bool* needTooltip) const
{
    QFont value = owner().value();

    QRect textRect = rect;

    if (textRect.isValid())
    {
        QRect br;

        QFont oldFont = painter.font();
        QFont newFont(value);
        newFont.setPointSize(oldFont.pointSize());
        painter.setFont(newFont);
        painter.drawText(textRect, Qt::AlignLeading | Qt::AlignVCenter, "A", &br);
        painter.setFont(oldFont);

        textRect.setLeft(br.right() + 3);
    }

    if (textRect.isValid())
    {
        QtnPropertyDelegateTypedEx<QtnPropertyQFontBase>::drawValueImpl(painter, textRect, state, needTooltip);
    }
}
Пример #2
0
void TrackView::paintTrack(QStylePainter &painter, const QRegion &region, int track)
{
	const QRect &rect = region.boundingRect();
	int firstRow = qBound(0, getRowFromPhysicalY(qMax(rect.top(), topMarginHeight)), getRows() - 1);
	int lastRow = qBound(0, getRowFromPhysicalY(qMax(rect.bottom(), topMarginHeight)), getRows() - 1);

	QRect selection = getSelection();

	const SyncTrack *t = getTrack(track);

	for (int row = firstRow; row <= lastRow; ++row) {
		QRect patternDataRect(getPhysicalX(track), getPhysicalY(row), trackWidth, rowHeight);
		if (!region.intersects(patternDataRect))
			continue;

		const SyncTrack::TrackKey *key = t->getPrevKeyFrame(row);

		SyncTrack::TrackKey::KeyType interpolationType = key ? key->type : SyncTrack::TrackKey::STEP;
		bool selected = selection.contains(track, row);

		QBrush baseBrush = bgBaseBrush;
		QBrush darkBrush = bgDarkBrush;

		if (selected) {
			baseBrush = selectBaseBrush;
			darkBrush = selectDarkBrush;
		}

		QBrush bgBrush = (row % 8 == 0) ? darkBrush : baseBrush;

		QRect fillRect = patternDataRect;
		painter.fillRect(fillRect, bgBrush);
		if (row % 8 == 0) {
			painter.setPen(selected ? rowSelectPen : rowPen);
			painter.drawLine(QPointF(patternDataRect.left() + 0.5, patternDataRect.top() + 0.5),
			                 QPointF(patternDataRect.right() + 0.5, patternDataRect.top() + 0.5));
		}

		if (interpolationType != SyncTrack::TrackKey::STEP) {
			painter.setPen(getInterpolationPen(interpolationType));
			painter.drawLine(QPoint(patternDataRect.right(), patternDataRect.top() + 1),
			                 QPoint(patternDataRect.right(), patternDataRect.bottom()));
		}

		if (row == editRow && track == editTrack) {
			QRectF selectRect = QRectF(patternDataRect).adjusted(0.5, 0.5, -0.5, -0.5);
			painter.setPen(QColor(0, 0, 0));
			painter.drawRect(selectRect);
		}

		painter.setPen(selected ?
		    palette().color(QPalette::HighlightedText) :
		    palette().color(QPalette::WindowText));
		painter.drawText(patternDataRect, t->isKeyFrame(row) ?
		                 QString::number(t->getKeyFrame(row).value, 'f', 2) :
		                 "  ---");
	}
}
void QIRichToolButton::paintEvent (QPaintEvent *aEvent)
{
    /* Draw focus around mLabel if focused */
    if (hasFocus())
    {
        QStylePainter painter (this);
        QStyleOptionFocusRect option;
        option.initFrom (this);
        option.rect = mLabel->frameGeometry();
        painter.drawPrimitive (QStyle::PE_FrameFocusRect, option);
    }
    QWidget::paintEvent (aEvent);
}
Пример #4
0
void TrackView::paintTracks(QStylePainter &painter, const QRegion &region)
{
	const QRect &rect = region.boundingRect();
	int startTrack = qBound(0, getTrackFromPhysicalX(qMax(rect.left(), leftMarginWidth)), getTrackCount());
	int endTrack = qBound(0, getTrackFromPhysicalX(rect.right()) + 1, getTrackCount());

	painter.setClipRect(QRectF(QPointF(leftMarginWidth - 0.5f, topMarginHeight - 0.5f),
	                           QPointF(rect.right() + 1.0f, rect.bottom() + 1.0f)));
	painter.fillRect(rect, palette().dark());

	for (int track = startTrack; track < endTrack; ++track)
		paintTrack(painter, region, track);
}
void QtnPropertyDelegateQStringInvalidBase::drawValueImpl(QStylePainter& painter, const QRect& rect, const QStyle::State& state, bool* needTooltip) const
{
    if ((m_invalidColor.alpha() != 0) && !isPropertyValid())
    {
        QPen oldPen = painter.pen();
        painter.setPen(m_invalidColor);
        QtnPropertyDelegateQString::drawValueImpl(painter, rect, state, needTooltip);
        painter.setPen(oldPen);
    }
    else
    {
        QtnPropertyDelegateQString::drawValueImpl(painter, rect, state, needTooltip);
    }
}
Пример #6
0
	void SeparateTabBar::paintEvent (QPaintEvent *event)
	{
		QTabBar::paintEvent (event);
		QStylePainter painter (this);

		if (count () > 0 && IsLastTab_)
		{
			CoreProxy proxy;
			QStyleOptionTabV2 option;
			initStyleOption (&option, count () - 1);
			QIcon icon = proxy.GetIcon ("list-add");
			painter.drawItemPixmap (option.rect, Qt::AlignCenter, 
					icon.pixmap (QSize (15, 15)));
		}
	}
Пример #7
0
///
/// \brief 绘制左上角按钮
/// \param painter 设置好绘制设备的painter
/// \param btn 左上角按钮,左上角按钮指针,Painter已经把此按钮设置为此绘制设备
///
void DTableWidgetEx::paintConnerButton(QStylePainter &painter,QAbstractButton* btn)
{
    QStyleOptionHeader opt;
    opt.init(btn);
    QStyle::State state = QStyle::State_None;
    if (btn->isEnabled())
        state |= QStyle::State_Enabled;
    if (btn->isActiveWindow())
        state |= QStyle::State_Active;
    if (btn->isDown())
        state |= QStyle::State_Sunken;
    opt.state = state;
    opt.rect = btn->rect();
    opt.text = btn->text(); // this line is the only difference to QTableCornerButton

    opt.position = QStyleOptionHeader::OnlyOneSection;
    painter.drawControl(QStyle::CE_Header, opt);
}
Пример #8
0
void TrackView::paintTopMargin(QStylePainter &painter, const QRegion &region)
{
	const QRect &rect = region.boundingRect();
	painter.setClipRect(QRectF(QPointF(0.0f, 0.0f),
	                    QPointF(rect.right() + 1.0f, topMarginHeight - 0.5f)));

	QRect topMargin(QPoint(-2, 0),
	                QPoint(rect.right() + 3, topMarginHeight - 1));
	painter.fillRect(topMargin.adjusted(1, 1, -1, -1), palette().button());
	qDrawWinButton(&painter, topMargin, palette());

	int startTrack = qBound(0, getTrackFromPhysicalX(qMax(rect.left(), leftMarginWidth)), getTrackCount());
	int endTrack = qBound(0, getTrackFromPhysicalX(rect.right()) + 1, getTrackCount());

	for (int track = startTrack; track < endTrack; ++track) {
		const SyncTrack *t = getTrack(track);

		QRect topMargin(getPhysicalX(track), 0, trackWidth, topMarginHeight);
		if (!region.intersects(topMargin))
			continue;

		QRect fillRect = topMargin;

		QBrush bgBrush = palette().button();
		if (track == editTrack)
			bgBrush = editBrush;

		painter.fillRect(fillRect.adjusted(1, 1, -1, -1), bgBrush);
		qDrawWinButton(&painter, fillRect, bgBrush.color());

		if (!t->isActive())
			painter.setPen(QColor(128, 128, 128));
		else
			painter.setPen(QColor(0, 0, 0));

		painter.drawText(fillRect, t->getDisplayName());
	}

	// make sure that the top margin isn't overdrawn by the track-data
	painter.setClipRegion(QRect(0, topMarginHeight, rect.right() + 1, rect.bottom() + 1));
}
Пример #9
0
void TrackView::paintLeftMargin(QStylePainter &painter, const QRegion &region)
{
	const QRect &rect = region.boundingRect();
	const SyncDocument *doc = getDocument();

	int firstRow = qBound(0, getRowFromPhysicalY(qMax(rect.top(), topMarginHeight)), getRows() - 1);
	int lastRow = qBound(0, getRowFromPhysicalY(qMax(rect.bottom(), topMarginHeight)), getRows() - 1);

	painter.setClipRect(QRectF(QPointF(0.0f, topMarginHeight - 0.5f),
	                           QPointF(leftMarginWidth - 0.5f, rect.bottom() + 1.0f)));

	QRectF padding(QPointF(rect.left(), topMarginHeight - 0.5f),
	               QPointF(leftMarginWidth - 0.5f, rect.bottom() + 1.0f));
	painter.fillRect(padding, palette().dark());

	for (int row = firstRow; row <= lastRow; ++row) {
		QRect leftMargin(0, getPhysicalY(row), leftMarginWidth, rowHeight);
		if (!region.intersects(leftMargin))
			continue;

		QBrush fillBrush;
		if (row == editRow)
			fillBrush = editBrush;
		else if (doc->isRowBookmark(row))
			fillBrush = bookmarkBrush;
		else
			fillBrush = palette().button();

		painter.fillRect(leftMargin.adjusted(1, 1, -1, -1), fillBrush);
		qDrawWinButton(&painter, leftMargin, QPalette(fillBrush.color()));

		if ((row % 8) == 0)      painter.setPen(QColor(0, 0, 0));
		else if ((row % 4) == 0) painter.setPen(QColor(64, 64, 64));
		else                     painter.setPen(QColor(128, 128, 128));

		painter.drawText(leftMargin, QString("%1").arg(row, 5, 16, QChar('0')).toUpper() + "h");
	}
}
Пример #10
0
void TabBar::paintRoundedTabs(QStylePainter &p, int dist)
{
	/// TODO: minor highlight bug when mouse goes on another tab without click
	// Draw all tabs before the selected tab
	QList<int> tabs;
	for (int i = 0; i < count(); i++)
		if (currentIndex() != i) tabs.append(i);
	tabs.append(currentIndex());

	for (int idx = 0; idx < count(); idx++) {
		int i = tabs.at(idx);
		QStyleOptionTab o;
		initStyleOption(&o, i);

		// Background color
		if (i != currentIndex()) {
			o.rect.adjust(0, 2, 0, 0);
		} else if (i == count()) {
			o.rect.adjust(2, 2, -4, 0);
		}

		/// Adjust parameters to tighten tabs
		//o.rect.adjust(-dist / 2, 0, dist / 2, 0);

		// Rounded frame tab
		QPainterPath ppLeft, ppRight;
		ppLeft.moveTo(o.rect.x() + dist * 0, o.rect.y() + o.rect.height());
		ppLeft.cubicTo(o.rect.x() + dist * 1, o.rect.y() + o.rect.height(),
					o.rect.x() + dist * 1, o.rect.y() + 1,
					o.rect.x() + dist * 2, o.rect.y() + 1);
		QPainterPath ppLeftCurve(ppLeft);
		// Add another point to be able to fill the path afterwards
		ppLeft.lineTo(o.rect.x() + dist * 2, o.rect.y() + o.rect.height());

		QLine topHozLine(o.rect.x() + dist * 2, o.rect.y(),
						 o.rect.x() + o.rect.width() - dist * 1, o.rect.y());

		ppRight.moveTo(o.rect.x() + o.rect.width() - dist * 1, o.rect.y() + 1);
		ppRight.cubicTo(o.rect.x() + o.rect.width() - dist * 0, o.rect.y() + 1,
					o.rect.x() + o.rect.width() - dist * 0, o.rect.y() + o.rect.height(),
					o.rect.x() + o.rect.width() + dist * 1, o.rect.y() + o.rect.height());
		QPainterPath ppRightCurve(ppRight);
		// Like first curve
		ppRight.lineTo(o.rect.x() + o.rect.width() - dist * 1, o.rect.y() + o.rect.height());

		p.save();
		if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.highlight().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		QRect midRect(topHozLine.p1(), QPoint(topHozLine.p2().x(), topHozLine.p2().y() + o.rect.height()));
		if (i == currentIndex()) {
			p.fillPath(ppLeft, o.palette.base());
			p.fillRect(midRect, o.palette.base());
			p.fillPath(ppRight, o.palette.base());
		} else if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.fillPath(ppLeft, o.palette.highlight().color().lighter());
			p.fillRect(midRect, o.palette.highlight().color().lighter());
			p.fillPath(ppRight, o.palette.highlight().color().lighter());
		} else {
			p.fillPath(ppLeft, o.palette.window());
			p.fillRect(midRect, o.palette.window());
			p.fillPath(ppRight, o.palette.window());
		}
		p.setRenderHint(QPainter::Antialiasing, true);
		p.drawPath(ppLeftCurve);
		p.drawPath(ppRightCurve);
		p.setRenderHint(QPainter::Antialiasing, false);
		p.drawLine(topHozLine);

		p.restore();

		/// DEBUG
		//p.drawRect(o.rect);

		// Icon
		QRect r = tabRect(i);
		r.setHeight(fontMetrics().ascent());
		r.translate(3 + dist * 1.25, (height() - r.height()) / 2);
		r.setWidth(r.height() / 2);
		p.setRenderHint(QPainter::SmoothPixmapTransform);
		o.icon.paint(&p, r, Qt::AlignLeft | Qt::AlignVCenter);

		// Playlist name
		if (i == currentIndex()) {
			p.setPen(o.palette.windowText().color());
		} else if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.windowText().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		QRect rText(r.x() + r.width() + 5, this->rect().y(),
					o.rect.width() - (r.width() + 5), this->height() - 2);
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, o.text);
	}
}
Пример #11
0
void TabBar::paintRectTabs(QStylePainter &p)
{
	static const qreal penScaleFactor = 0.2;
	for (int i = 0; i < count(); i++) {
		QStyleOptionTab o;
		initStyleOption(&o, i);

		// Background color
		p.save();
		if (i != currentIndex()) {
			o.rect.adjust(0, 2, 0, 0);
		} else if (i == count()) {
			o.rect.adjust(2, 2, -4, -4);
		}

		// Highlight the tab under the cursor
		if (o.state.testFlag(QStyle::State_MouseOver) && i != currentIndex()) {
			p.setPen(QPen(o.palette.highlight(), penScaleFactor));
			p.fillRect(o.rect, o.palette.highlight().color().lighter());
		} else {
			p.setPen(QPen(o.palette.mid(), penScaleFactor));
			if (i == currentIndex()) {
				/// XXX
				if (SettingsPrivate::instance()->isCustomColors()) {
					p.fillRect(o.rect, o.palette.base().color().lighter(110));
				} else {
					p.fillRect(o.rect, o.palette.base());
				}
			} else {
				p.fillRect(o.rect, o.palette.window());
			}
		}

		if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.highlight().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		// Frame tab, it is not a rectangle but only 3 lines
		p.drawLine(o.rect.topLeft(), o.rect.bottomLeft());
		p.drawLine(o.rect.topRight(), o.rect.bottomRight());
		p.drawLine(o.rect.topLeft(), o.rect.topRight());
		//}
		p.restore();

		// Icon
		QRect r = tabRect(i);
		r.setHeight(fontMetrics().ascent());
		r.translate(10, (height() - r.height()) / 2);
		r.setWidth(r.height() / 2);
		p.setRenderHint(QPainter::SmoothPixmapTransform);
		o.icon.paint(&p, r, Qt::AlignLeft | Qt::AlignVCenter);

		// Playlist name
		if (i == currentIndex()) {
			p.setPen(o.palette.windowText().color());
		} else if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.windowText().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		QRect rText(r.x() + r.width() + 10, r.y(), o.rect.width() - r.width() - 10, r.height());
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, o.text);
	}
}