Пример #1
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) :
		                 "  ---");
	}
}
Пример #2
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);
	}
}
Пример #3
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);
	}
}