0
0
mirror of https://github.com/yse/easy_profiler.git synced 2025-01-14 00:27:55 +08:00

(ProfGraphicsScrollbar) Draw indicators if slider width is too small

This commit is contained in:
Victor Zarubkin 2016-08-08 23:39:37 +03:00
parent b2ac7e0fbd
commit dd31bb080b
2 changed files with 37 additions and 17 deletions

View File

@ -30,6 +30,7 @@ const qreal SCALING_COEFFICIENT = 1.25;
const qreal SCALING_COEFFICIENT_INV = 1.0 / SCALING_COEFFICIENT;
const int DEFAULT_TOP = -40;
const int DEFAULT_HEIGHT = 80;
const int INDICATOR_SIZE = 8;
//////////////////////////////////////////////////////////////////////////
@ -40,8 +41,20 @@ auto const clamp = [](qreal _minValue, qreal _value, qreal _maxValue)
//////////////////////////////////////////////////////////////////////////
ProfGraphicsSliderItem::ProfGraphicsSliderItem() : Parent(), m_halfwidth(0)
ProfGraphicsSliderItem::ProfGraphicsSliderItem(bool _main) : Parent(), m_halfwidth(0)
{
m_leftIndicator.reserve(3);
m_rightIndicator.reserve(3);
const auto vcenter = DEFAULT_TOP + (_main ? INDICATOR_SIZE : DEFAULT_HEIGHT - INDICATOR_SIZE);
m_leftIndicator.push_back(QPointF(-INDICATOR_SIZE, vcenter - INDICATOR_SIZE));
m_leftIndicator.push_back(QPointF(0, vcenter));
m_leftIndicator.push_back(QPointF(-INDICATOR_SIZE, vcenter + INDICATOR_SIZE));
m_rightIndicator.push_back(QPointF(INDICATOR_SIZE, vcenter - INDICATOR_SIZE));
m_rightIndicator.push_back(QPointF(0, vcenter));
m_rightIndicator.push_back(QPointF(INDICATOR_SIZE, vcenter + INDICATOR_SIZE));
setWidth(1);
setBrush(Qt::SolidPattern);
}
@ -68,22 +81,27 @@ void ProfGraphicsSliderItem::paint(QPainter* _painter, const QStyleOptionGraphic
QRectF r(dx + br.left() * currentScale, br.top(), w, br.height());
//auto center = r.center();
//auto b = brush();
//QPolygonF indicator;
//indicator.reserve(3);
//indicator.push_back(QPointF(center.x() - 4, r.top()));
//indicator.push_back(QPointF(center.x(), r.top() + 5));
//indicator.push_back(QPointF(center.x() + 4, r.top()));
_painter->save();
_painter->setTransform(QTransform::fromScale(1.0 / currentScale, 1), true);
_painter->setBrush(brush());
_painter->setPen(Qt::NoPen);
_painter->drawRect(r);
//b.setColor(b.color().rgb());
//_painter->setBrush(b);
//_painter->drawPolygon(indicator);
if (w < INDICATOR_SIZE)
{
m_leftIndicator[0].setX(r.left() - INDICATOR_SIZE);
m_leftIndicator[1].setX(r.left());
m_leftIndicator[2].setX(r.left() - INDICATOR_SIZE);
const auto r_right = r.right();
m_rightIndicator[0].setX(r_right + INDICATOR_SIZE);
m_rightIndicator[1].setX(r_right);
m_rightIndicator[2].setX(r_right + INDICATOR_SIZE);
_painter->drawPolygon(m_leftIndicator);
_painter->drawPolygon(m_rightIndicator);
}
_painter->restore();
}
@ -254,8 +272,8 @@ ProfGraphicsScrollbar::ProfGraphicsScrollbar(QWidget* _parent)
{
setCacheMode(QGraphicsView::CacheNone);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setOptimizationFlag(QGraphicsView::DontSavePainterState, true);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -269,13 +287,13 @@ ProfGraphicsScrollbar::ProfGraphicsScrollbar(QWidget* _parent)
selfScene->setSceneRect(0, DEFAULT_TOP, 500, DEFAULT_HEIGHT);
setScene(selfScene);
m_slider = new ProfGraphicsSliderItem();
m_slider = new ProfGraphicsSliderItem(true);
m_slider->setPos(0, 0);
m_slider->setZValue(5);
m_slider->setColor(0x80e00000);
selfScene->addItem(m_slider);
m_chronometerIndicator = new ProfGraphicsSliderItem();
m_chronometerIndicator = new ProfGraphicsSliderItem(false);
m_chronometerIndicator->setPos(0, 0);
m_chronometerIndicator->setZValue(10);
m_chronometerIndicator->setColor(0x40000000 | ::profiler_gui::CHRONOMETER_COLOR.rgba());

View File

@ -23,6 +23,7 @@
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QAction>
#include <QPolygonF>
#include "common_types.h"
//////////////////////////////////////////////////////////////////////////
@ -34,11 +35,12 @@ class ProfGraphicsSliderItem : public QGraphicsRectItem
private:
QPolygonF m_leftIndicator, m_rightIndicator;
qreal m_halfwidth;
public:
ProfGraphicsSliderItem();
ProfGraphicsSliderItem(bool _main);
virtual ~ProfGraphicsSliderItem();
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;