2016-07-10 01:29:09 +03:00
|
|
|
/************************************************************************
|
2016-09-15 22:30:32 +03:00
|
|
|
* file name : easy_graphics_scrollbar.cpp
|
2016-07-10 01:29:09 +03:00
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/07/04
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
|
|
|
* description : .
|
|
|
|
* ----------------- :
|
|
|
|
* change log : * 2016/07/04 Victor Zarubkin: Initial commit.
|
|
|
|
* :
|
|
|
|
* : *
|
|
|
|
* ----------------- :
|
2016-09-06 21:49:32 +03:00
|
|
|
* license : Lightweight profiler library for c++
|
|
|
|
* : Copyright(C) 2016 Sergey Yagovtsev, Victor Zarubkin
|
|
|
|
* :
|
|
|
|
* : This program is free software : you can redistribute it and / or modify
|
|
|
|
* : it under the terms of the GNU General Public License as published by
|
|
|
|
* : the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* : (at your option) any later version.
|
|
|
|
* :
|
|
|
|
* : This program is distributed in the hope that it will be useful,
|
|
|
|
* : but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* : GNU General Public License for more details.
|
|
|
|
* :
|
|
|
|
* : You should have received a copy of the GNU General Public License
|
|
|
|
* : along with this program.If not, see <http://www.gnu.org/licenses/>.
|
2016-07-10 01:29:09 +03:00
|
|
|
************************************************************************/
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
#include <algorithm>
|
2016-08-18 23:26:41 +03:00
|
|
|
#include <QGraphicsScene>
|
2016-07-31 13:13:48 +03:00
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QResizeEvent>
|
2016-08-03 23:00:04 +03:00
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
2016-09-15 22:30:32 +03:00
|
|
|
#include "easy_graphics_scrollbar.h"
|
2016-08-08 22:45:57 +03:00
|
|
|
#include "globals.h"
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
const int DEFAULT_TOP = -40;
|
|
|
|
const int DEFAULT_HEIGHT = 80;
|
2016-08-08 23:39:37 +03:00
|
|
|
const int INDICATOR_SIZE = 8;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
auto const clamp = [](qreal _minValue, qreal _value, qreal _maxValue)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return (_value < _minValue ? _minValue : (_value > _maxValue ? _maxValue : _value));
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
EasyGraphicsSliderItem::EasyGraphicsSliderItem(bool _main) : Parent(), m_halfwidth(0), m_bMain(_main)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
2016-08-23 22:44:59 +03:00
|
|
|
m_indicator.reserve(3);
|
|
|
|
|
|
|
|
if (_main)
|
|
|
|
{
|
|
|
|
m_indicator.push_back(QPointF(0, DEFAULT_TOP + INDICATOR_SIZE));
|
|
|
|
m_indicator.push_back(QPointF(-INDICATOR_SIZE, DEFAULT_TOP));
|
|
|
|
m_indicator.push_back(QPointF(INDICATOR_SIZE, DEFAULT_TOP));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_indicator.push_back(QPointF(0, DEFAULT_TOP + DEFAULT_HEIGHT - INDICATOR_SIZE));
|
|
|
|
m_indicator.push_back(QPointF(-INDICATOR_SIZE, DEFAULT_TOP + DEFAULT_HEIGHT));
|
|
|
|
m_indicator.push_back(QPointF(INDICATOR_SIZE, DEFAULT_TOP + DEFAULT_HEIGHT));
|
|
|
|
}
|
2016-08-08 23:39:37 +03:00
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
setWidth(1);
|
2016-07-10 01:29:09 +03:00
|
|
|
setBrush(Qt::SolidPattern);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsSliderItem::~EasyGraphicsSliderItem()
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsSliderItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
//Parent::paint(_painter, _option, _widget);
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto currentScale = static_cast<const EasyGraphicsScrollbar*>(scene()->parent())->getWindowScale();
|
2016-07-31 13:13:48 +03:00
|
|
|
const auto br = rect();
|
|
|
|
|
|
|
|
qreal w = width() * currentScale;
|
|
|
|
qreal dx = 0;
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
// if (w < 1.0)
|
|
|
|
// {
|
|
|
|
// dx = (w - 1.0) * 0.5;
|
|
|
|
// w = 1.0;
|
|
|
|
// }
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
QRectF r(dx + br.left() * currentScale, br.top() + INDICATOR_SIZE, w, br.height() - (INDICATOR_SIZE << 1));
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto r_right = r.right();
|
|
|
|
const auto r_bottom = r.bottom();
|
|
|
|
auto b = brush();
|
2016-08-06 14:50:31 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
_painter->save();
|
|
|
|
_painter->setTransform(QTransform::fromScale(1.0 / currentScale, 1), true);
|
2016-08-18 23:26:41 +03:00
|
|
|
_painter->setBrush(b);
|
2016-08-23 22:44:59 +03:00
|
|
|
|
|
|
|
if (w > 1)
|
|
|
|
{
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
_painter->drawRect(r);
|
|
|
|
|
|
|
|
// Draw left and right borders
|
|
|
|
auto cmode = _painter->compositionMode();
|
|
|
|
if (m_bMain) _painter->setCompositionMode(QPainter::CompositionMode_Exclusion);
|
|
|
|
_painter->setPen(QColor::fromRgba(0xe0000000 | b.color().rgb()));
|
|
|
|
_painter->drawLine(QPointF(r.left(), r.top()), QPointF(r.left(), r_bottom));
|
|
|
|
_painter->drawLine(QPointF(r_right, r.top()), QPointF(r_right, r_bottom));
|
|
|
|
if (!m_bMain) _painter->setCompositionMode(cmode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_painter->setPen(QColor::fromRgba(0xe0000000 | b.color().rgb()));
|
|
|
|
_painter->drawLine(QPointF(r.left(), r.top()), QPointF(r.left(), r_bottom));
|
|
|
|
if (m_bMain) _painter->setCompositionMode(QPainter::CompositionMode_Exclusion);
|
|
|
|
}
|
2016-08-18 23:26:41 +03:00
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
// Draw triangle indicators for small slider
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(r.left() + w * 0.5, 0), true);
|
|
|
|
_painter->setPen(b.color().rgb());
|
|
|
|
_painter->drawPolygon(m_indicator);
|
2016-08-08 23:39:37 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
_painter->restore();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsSliderItem::width() const
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return m_halfwidth * 2.0;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsSliderItem::halfwidth() const
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return m_halfwidth;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsSliderItem::setWidth(qreal _width)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
m_halfwidth = _width * 0.5;
|
2016-08-03 00:06:36 +03:00
|
|
|
setRect(-m_halfwidth, DEFAULT_TOP, _width, DEFAULT_HEIGHT);
|
2016-07-10 01:29:09 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsSliderItem::setHalfwidth(qreal _halfwidth)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
m_halfwidth = _halfwidth;
|
2016-08-03 00:06:36 +03:00
|
|
|
setRect(-m_halfwidth, DEFAULT_TOP, m_halfwidth * 2.0, DEFAULT_HEIGHT);
|
2016-07-10 01:29:09 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsSliderItem::setColor(QRgb _color)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
|
|
|
setColor(QColor::fromRgba(_color));
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsSliderItem::setColor(const QColor& _color)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
auto b = brush();
|
2016-08-06 14:50:31 +03:00
|
|
|
b.setColor(_color);
|
2016-07-10 01:29:09 +03:00
|
|
|
setBrush(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyMinimapItem::EasyMinimapItem() : Parent(), m_pSource(nullptr), m_maxDuration(0), m_minDuration(0), m_threadId(0)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyMinimapItem::~EasyMinimapItem()
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
QRectF EasyMinimapItem::boundingRect() const
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
return m_boundingRect;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyMinimapItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
if (m_pSource == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto currentScale = static_cast<const EasyGraphicsScrollbar*>(scene()->parent())->getWindowScale();
|
2016-08-03 00:06:36 +03:00
|
|
|
const auto bottom = m_boundingRect.bottom();
|
2016-08-04 22:38:45 +03:00
|
|
|
const auto coeff = m_boundingRect.height() / (m_maxDuration - m_minDuration);
|
|
|
|
const auto heightRevert = 1.0 / m_boundingRect.height();
|
2016-08-03 00:06:36 +03:00
|
|
|
|
|
|
|
QRectF rect;
|
|
|
|
QBrush brush(Qt::SolidPattern);
|
|
|
|
QRgb previousColor = 0;
|
|
|
|
|
2016-08-04 22:38:45 +03:00
|
|
|
//brush.setColor(QColor::fromRgba(0x80808080));
|
2016-08-03 00:06:36 +03:00
|
|
|
|
|
|
|
_painter->save();
|
|
|
|
_painter->setPen(Qt::NoPen);
|
2016-08-04 22:38:45 +03:00
|
|
|
//_painter->setBrush(brush);
|
2016-08-03 00:06:36 +03:00
|
|
|
_painter->setTransform(QTransform::fromScale(1.0 / currentScale, 1), true);
|
|
|
|
|
|
|
|
auto& items = *m_pSource;
|
|
|
|
for (const auto& item : items)
|
|
|
|
{
|
|
|
|
// Draw rectangle
|
2016-08-04 22:38:45 +03:00
|
|
|
|
|
|
|
const auto h = ::std::max((item.width() - m_minDuration) * coeff, 5.0);
|
2016-08-11 23:48:29 +03:00
|
|
|
const auto col = ::std::min(h * heightRevert, 0.9999999);
|
2016-08-07 19:38:31 +03:00
|
|
|
//const auto color = ::profiler_gui::toRgb(col * 255, (1.0 - col) * 255, 0); // item.color;
|
|
|
|
const auto color = 0x00ffffff & QColor::fromHsvF((1.0 - col) * 0.35, 0.85, 0.85).rgb();
|
2016-08-04 22:38:45 +03:00
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
if (previousColor != color)
|
|
|
|
{
|
|
|
|
// Set background color brush for rectangle
|
|
|
|
previousColor = color;
|
|
|
|
brush.setColor(QColor::fromRgba(0xc0000000 | color));
|
|
|
|
_painter->setBrush(brush);
|
2016-08-04 22:38:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
rect.setRect(item.left() * currentScale, bottom - h, ::std::max(item.width() * currentScale, 1.0), h);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
_painter->setPen(Qt::darkGray);
|
|
|
|
_painter->drawLine(0, bottom, m_boundingRect.width(), bottom);
|
|
|
|
_painter->drawLine(0, m_boundingRect.top(), m_boundingRect.width(), m_boundingRect.top());
|
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
_painter->restore();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
::profiler::thread_id_t EasyMinimapItem::threadId() const
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
return m_threadId;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyMinimapItem::setBoundingRect(const QRectF& _rect)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
m_boundingRect = _rect;
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
void EasyMinimapItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h)
|
|
|
|
{
|
|
|
|
m_boundingRect.setRect(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
void EasyMinimapItem::setSource(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems* _items)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
m_pSource = _items;
|
2016-08-03 23:00:04 +03:00
|
|
|
m_threadId = _thread_id;
|
2016-08-03 00:06:36 +03:00
|
|
|
|
|
|
|
if (m_pSource)
|
|
|
|
{
|
|
|
|
if (m_pSource->empty())
|
|
|
|
{
|
|
|
|
m_pSource = nullptr;
|
|
|
|
}
|
2016-08-08 22:17:56 +03:00
|
|
|
else
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
2016-08-08 22:17:56 +03:00
|
|
|
m_maxDuration = 0;
|
|
|
|
m_minDuration = 1e30;
|
|
|
|
for (const auto& item : *m_pSource)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
2016-08-08 22:17:56 +03:00
|
|
|
auto w = item.width();
|
2016-08-04 22:38:45 +03:00
|
|
|
|
2016-08-08 22:17:56 +03:00
|
|
|
if (w > m_maxDuration)
|
|
|
|
{
|
|
|
|
m_maxDuration = item.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w < m_minDuration)
|
|
|
|
{
|
|
|
|
m_minDuration = w;
|
|
|
|
}
|
2016-08-04 22:38:45 +03:00
|
|
|
}
|
2016-08-03 00:06:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_pSource == nullptr)
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsScrollbar::EasyGraphicsScrollbar(QWidget* _parent)
|
2016-07-10 01:29:09 +03:00
|
|
|
: Parent(_parent)
|
|
|
|
, m_minimumValue(0)
|
|
|
|
, m_maximumValue(500)
|
|
|
|
, m_value(10)
|
2016-07-31 13:13:48 +03:00
|
|
|
, m_windowScale(1)
|
|
|
|
, m_mouseButtons(Qt::NoButton)
|
2016-07-10 01:29:09 +03:00
|
|
|
, m_slider(nullptr)
|
2016-08-03 00:06:36 +03:00
|
|
|
, m_chronometerIndicator(nullptr)
|
|
|
|
, m_minimap(nullptr)
|
2016-07-31 13:13:48 +03:00
|
|
|
, m_bScrolling(false)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
setCacheMode(QGraphicsView::CacheNone);
|
|
|
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
2016-08-08 23:39:37 +03:00
|
|
|
//setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
|
|
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
2016-07-10 01:29:09 +03:00
|
|
|
setOptimizationFlag(QGraphicsView::DontSavePainterState, true);
|
|
|
|
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2016-08-21 14:26:36 +03:00
|
|
|
setFixedHeight(DEFAULT_HEIGHT + 2);
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
auto selfScene = new QGraphicsScene(this);
|
2016-08-03 00:06:36 +03:00
|
|
|
selfScene->setSceneRect(0, DEFAULT_TOP, 500, DEFAULT_HEIGHT);
|
2016-07-10 01:29:09 +03:00
|
|
|
setScene(selfScene);
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
m_minimap = new EasyMinimapItem();
|
|
|
|
m_minimap->setPos(0, 0);
|
|
|
|
m_minimap->setBoundingRect(0, DEFAULT_TOP + INDICATOR_SIZE, scene()->width(), DEFAULT_HEIGHT - (INDICATOR_SIZE << 1));
|
|
|
|
selfScene->addItem(m_minimap);
|
|
|
|
m_minimap->hide();
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
m_chronometerIndicator = new EasyGraphicsSliderItem(false);
|
2016-08-03 00:06:36 +03:00
|
|
|
m_chronometerIndicator->setPos(0, 0);
|
2016-08-07 19:38:31 +03:00
|
|
|
m_chronometerIndicator->setColor(0x40000000 | ::profiler_gui::CHRONOMETER_COLOR.rgba());
|
2016-08-03 00:06:36 +03:00
|
|
|
selfScene->addItem(m_chronometerIndicator);
|
|
|
|
m_chronometerIndicator->hide();
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
m_slider = new EasyGraphicsSliderItem(true);
|
|
|
|
m_slider->setPos(0, 0);
|
|
|
|
m_slider->setColor(0x40c0c0c0);
|
|
|
|
selfScene->addItem(m_slider);
|
2016-08-24 01:00:24 +03:00
|
|
|
m_slider->hide();
|
2016-08-03 00:06:36 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
centerOn(0, 0);
|
2016-07-10 01:29:09 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsScrollbar::~EasyGraphicsScrollbar()
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::getWindowScale() const
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
return m_windowScale;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
::profiler::thread_id_t EasyGraphicsScrollbar::minimapThread() const
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
return m_minimap->threadId();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::minimum() const
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return m_minimumValue;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::maximum() const
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return m_maximumValue;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::range() const
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
return m_maximumValue - m_minimumValue;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::value() const
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::sliderWidth() const
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
return m_slider->width();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsScrollbar::sliderHalfWidth() const
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
return m_slider->halfwidth();
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:29:09 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::setValue(qreal _value)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
m_value = clamp(m_minimumValue, _value, ::std::max(m_minimumValue, m_maximumValue - m_slider->width()));
|
2016-07-31 13:13:48 +03:00
|
|
|
m_slider->setX(m_value + m_slider->halfwidth());
|
2016-07-10 01:29:09 +03:00
|
|
|
emit valueChanged(m_value);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::setRange(qreal _minValue, qreal _maxValue)
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
const auto oldRange = range();
|
|
|
|
const auto oldValue = oldRange < 1e-3 ? 0.0 : m_value / oldRange;
|
|
|
|
|
2016-07-10 01:29:09 +03:00
|
|
|
m_minimumValue = _minValue;
|
|
|
|
m_maximumValue = _maxValue;
|
2016-08-03 00:06:36 +03:00
|
|
|
scene()->setSceneRect(_minValue, DEFAULT_TOP, _maxValue - _minValue, DEFAULT_HEIGHT);
|
2016-08-23 22:44:59 +03:00
|
|
|
m_minimap->setBoundingRect(_minValue, DEFAULT_TOP + INDICATOR_SIZE, _maxValue, DEFAULT_HEIGHT - (INDICATOR_SIZE << 1));
|
2016-07-31 13:13:48 +03:00
|
|
|
emit rangeChanged();
|
|
|
|
|
|
|
|
setValue(_minValue + oldValue * range());
|
|
|
|
onWindowWidthChange(width());
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::setSliderWidth(qreal _width)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
m_slider->setWidth(_width);
|
2016-07-10 01:29:09 +03:00
|
|
|
setValue(m_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::setChronoPos(qreal _left, qreal _right)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
m_chronometerIndicator->setWidth(_right - _left);
|
|
|
|
m_chronometerIndicator->setX(_left + m_chronometerIndicator->halfwidth());
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::showChrono()
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
m_chronometerIndicator->show();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::hideChrono()
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
m_chronometerIndicator->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
void EasyGraphicsScrollbar::setMinimapFrom(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems* _items)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
2016-08-03 23:00:04 +03:00
|
|
|
m_minimap->setSource(_thread_id, _items);
|
2016-08-24 01:00:24 +03:00
|
|
|
m_slider->setVisible(m_minimap->isVisible());
|
2016-08-03 23:00:04 +03:00
|
|
|
scene()->update();
|
2016-08-03 00:06:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::mousePressEvent(QMouseEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
m_mouseButtons = _event->buttons();
|
|
|
|
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
m_bScrolling = true;
|
|
|
|
m_mousePressPos = _event->pos();
|
2016-08-06 14:50:31 +03:00
|
|
|
setValue(mapToScene(m_mousePressPos).x() - m_minimumValue - m_slider->halfwidth());
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_event->accept();
|
|
|
|
//QGraphicsView::mousePressEvent(_event);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::mouseReleaseEvent(QMouseEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
m_mouseButtons = _event->buttons();
|
|
|
|
m_bScrolling = false;
|
|
|
|
_event->accept();
|
|
|
|
//QGraphicsView::mouseReleaseEvent(_event);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::mouseMoveEvent(QMouseEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
const auto pos = _event->pos();
|
|
|
|
const auto delta = pos - m_mousePressPos;
|
|
|
|
m_mousePressPos = pos;
|
|
|
|
|
|
|
|
if (m_bScrolling)
|
|
|
|
{
|
|
|
|
setValue(m_value + delta.x() / m_windowScale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 16:48:42 +03:00
|
|
|
void EasyGraphicsScrollbar::wheelEvent(QWheelEvent* _event)
|
|
|
|
{
|
2016-08-21 22:44:03 +03:00
|
|
|
auto w = m_slider->halfwidth() * (_event->delta() < 0 ? ::profiler_gui::SCALING_COEFFICIENT : ::profiler_gui::SCALING_COEFFICIENT_INV);
|
|
|
|
setValue(mapToScene(_event->pos()).x() - m_minimumValue - w);
|
|
|
|
emit wheeled(w * m_windowScale, _event->delta());
|
2016-08-21 16:48:42 +03:00
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::resizeEvent(QResizeEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
onWindowWidthChange(_event->size().width());
|
|
|
|
}
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::contextMenuEvent(QContextMenuEvent* _event)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
2016-08-30 22:51:18 +03:00
|
|
|
if (EASY_GLOBALS.profiler_blocks.empty())
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
for (const auto& it : EASY_GLOBALS.profiler_blocks)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
QString label;
|
2016-09-13 23:40:58 +03:00
|
|
|
if (it.second.got_name())
|
2016-09-13 23:03:01 +03:00
|
|
|
label = ::std::move(QString("%1 Thread %2").arg(it.second.name()).arg(it.first));
|
2016-08-03 23:00:04 +03:00
|
|
|
else
|
|
|
|
label = ::std::move(QString("Thread %1").arg(it.first));
|
|
|
|
|
2016-09-06 21:49:32 +03:00
|
|
|
auto action = new QAction(label, nullptr);
|
|
|
|
action->setData(it.first);
|
2016-08-03 23:00:04 +03:00
|
|
|
action->setCheckable(true);
|
2016-08-30 22:51:18 +03:00
|
|
|
action->setChecked(it.first == EASY_GLOBALS.selected_thread);
|
2016-09-06 21:49:32 +03:00
|
|
|
connect(action, &QAction::triggered, this, &This::onThreadActionClicked);
|
2016-08-03 23:00:04 +03:00
|
|
|
|
|
|
|
menu.addAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.exec(QCursor::pos());
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-06 21:49:32 +03:00
|
|
|
void EasyGraphicsScrollbar::onThreadActionClicked(bool)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
2016-09-06 21:49:32 +03:00
|
|
|
auto action = qobject_cast<QAction*>(sender());
|
|
|
|
if (action == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto thread_id = action->data().toUInt();
|
2016-09-08 22:42:35 +03:00
|
|
|
if (thread_id != EASY_GLOBALS.selected_thread)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
2016-09-06 21:49:32 +03:00
|
|
|
EASY_GLOBALS.selected_thread = thread_id;
|
|
|
|
emit EASY_GLOBALS.events.selectedThreadChanged(thread_id);
|
2016-08-03 23:00:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsScrollbar::onWindowWidthChange(qreal _width)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
const auto oldScale = m_windowScale;
|
|
|
|
const auto scrollingRange = range();
|
|
|
|
|
|
|
|
if (scrollingRange < 1e-3)
|
|
|
|
{
|
|
|
|
m_windowScale = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_windowScale = _width / scrollingRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
scale(m_windowScale / oldScale, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|