mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 00:31:02 +08:00
(ProfGraphicsView) Displaying additional chronometer item on mouse double click and move. This item is used just to measure time. This is not affecting tree displayed in ProfTreeWidget.
This commit is contained in:
parent
67ed94c774
commit
57654670f0
@ -34,6 +34,8 @@
|
||||
#include <algorithm>
|
||||
#include "blocks_graphics_view.h"
|
||||
|
||||
using namespace profiler_gui;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -50,11 +52,12 @@ const unsigned short ROW_SPACING = 4;
|
||||
const QRgb BORDERS_COLOR = 0x00a07050;
|
||||
const QRgb BACKGROUND_1 = 0x00dddddd;
|
||||
const QRgb BACKGROUND_2 = 0x00ffffff;
|
||||
const QColor CHRONOMETER_COLOR = QColor(64, 64, 64, 64);
|
||||
const QRgb CHRONOMETER_TEXT_COLOR = 0xff302010;
|
||||
const QColor CHRONOMETER_COLOR2 = QColor::fromRgba(0x40408040);
|
||||
|
||||
const unsigned int TEST_PROGRESSION_BASE = 4;
|
||||
|
||||
const int FLICKER_INTERVAL = 16; // 60Hz
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
auto const sign = [](int _value) { return _value < 0 ? -1 : 1; };
|
||||
@ -500,9 +503,10 @@ unsigned int ProfGraphicsItem::addItem(unsigned short _level)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfChronometerItem::ProfChronometerItem() : QGraphicsItem(), m_left(0), m_right(0), m_font(QFont("CourierNew", 16, 2))
|
||||
ProfChronometerItem::ProfChronometerItem(bool _main) : QGraphicsItem(), m_font(QFont("CourierNew", 16, 2)), m_color(CHRONOMETER_COLOR), m_left(0), m_right(0), m_bMain(_main), m_bReverse(false)
|
||||
{
|
||||
setZValue(10);
|
||||
m_indicator.reserve(3);
|
||||
}
|
||||
|
||||
ProfChronometerItem::~ProfChronometerItem()
|
||||
@ -525,6 +529,36 @@ void ProfChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
if (m_left > sceneRight || m_right < sceneLeft)
|
||||
{
|
||||
// This item is out of screen
|
||||
|
||||
if (m_bMain)
|
||||
{
|
||||
auto vcenter = visibleSceneRect.top() + visibleSceneRect.height() * 0.5;
|
||||
|
||||
m_indicator.clear();
|
||||
if (m_left > sceneRight)
|
||||
{
|
||||
auto vbar = sceneView->verticalScrollBar();
|
||||
sceneRight = ((sceneRight - offset) * currentScale) - 2 - (vbar->isVisible() ? vbar->width() : 0);
|
||||
m_indicator.push_back(QPointF(sceneRight - 10, vcenter - 10));
|
||||
m_indicator.push_back(QPointF(sceneRight, vcenter));
|
||||
m_indicator.push_back(QPointF(sceneRight - 10, vcenter + 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneLeft = (sceneLeft - offset) * currentScale;
|
||||
m_indicator.push_back(QPointF(sceneLeft + 10, vcenter - 10));
|
||||
m_indicator.push_back(QPointF(sceneLeft, vcenter));
|
||||
m_indicator.push_back(QPointF(sceneLeft + 10, vcenter + 10));
|
||||
}
|
||||
|
||||
_painter->save();
|
||||
_painter->setTransform(QTransform::fromTranslate(-x(), -y()), true);
|
||||
_painter->setBrush(QColor::fromRgb(m_color.rgb()));
|
||||
_painter->setPen(Qt::NoPen);
|
||||
_painter->drawPolygon(m_indicator);
|
||||
_painter->restore();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -550,12 +584,12 @@ void ProfChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
_painter->setTransform(QTransform::fromTranslate(-x(), -y()), true);
|
||||
|
||||
// draw transparent rectangle
|
||||
_painter->setBrush(CHRONOMETER_COLOR);
|
||||
_painter->setBrush(m_color);
|
||||
_painter->setPen(Qt::NoPen);
|
||||
_painter->drawRect(rect);
|
||||
|
||||
// draw text
|
||||
_painter->setPen(CHRONOMETER_TEXT_COLOR);
|
||||
_painter->setPen(0xffffffff - m_color.rgb());
|
||||
_painter->setFont(m_font);
|
||||
|
||||
if (m_left < sceneLeft)
|
||||
@ -568,6 +602,11 @@ void ProfChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
rect.setWidth((sceneRight - offset) * currentScale - rect.left());
|
||||
}
|
||||
|
||||
if (!m_bMain)
|
||||
{
|
||||
rect.setTop(rect.top() + textRect.height() * 1.33);
|
||||
}
|
||||
|
||||
if (textRect.width() < rect.width())
|
||||
{
|
||||
// Text will be drawed inside rectangle
|
||||
@ -598,6 +637,11 @@ void ProfChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
// END Paint!~~~~~~~~~~~~~~~~~~~~~~
|
||||
}
|
||||
|
||||
void ProfChronometerItem::setColor(const QColor& _color)
|
||||
{
|
||||
m_color = _color;
|
||||
}
|
||||
|
||||
void ProfChronometerItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h)
|
||||
{
|
||||
m_boundingRect.setRect(x, y, w, h);
|
||||
@ -622,6 +666,11 @@ void ProfChronometerItem::setLeftRight(qreal _left, qreal _right)
|
||||
}
|
||||
}
|
||||
|
||||
void ProfChronometerItem::setReverse(bool _reverse)
|
||||
{
|
||||
m_bReverse = _reverse;
|
||||
}
|
||||
|
||||
const ProfGraphicsView* ProfChronometerItem::view() const
|
||||
{
|
||||
return static_cast<const ProfGraphicsView*>(scene()->parent());
|
||||
@ -637,11 +686,13 @@ ProfGraphicsView::ProfGraphicsView(bool _test)
|
||||
, m_mouseButtons(Qt::NoButton)
|
||||
, m_pScrollbar(nullptr)
|
||||
, m_chronometerItem(nullptr)
|
||||
, m_flickerSpeed(0)
|
||||
, m_chronometerItemAux(nullptr)
|
||||
, m_flickerSpeedX(0)
|
||||
, m_flickerSpeedY(0)
|
||||
, m_bDoubleClick(false)
|
||||
, m_bUpdatingRect(false)
|
||||
, m_bTest(_test)
|
||||
, m_bEmpty(true)
|
||||
, m_bStrictSelection(false)
|
||||
{
|
||||
initMode();
|
||||
setScene(new QGraphicsScene(this));
|
||||
@ -662,11 +713,13 @@ ProfGraphicsView::ProfGraphicsView(const ::profiler::thread_blocks_tree_t& _bloc
|
||||
, m_mouseButtons(Qt::NoButton)
|
||||
, m_pScrollbar(nullptr)
|
||||
, m_chronometerItem(nullptr)
|
||||
, m_flickerSpeed(0)
|
||||
, m_chronometerItemAux(nullptr)
|
||||
, m_flickerSpeedX(0)
|
||||
, m_flickerSpeedY(0)
|
||||
, m_bDoubleClick(false)
|
||||
, m_bUpdatingRect(false)
|
||||
, m_bTest(false)
|
||||
, m_bEmpty(true)
|
||||
, m_bStrictSelection(false)
|
||||
{
|
||||
initMode();
|
||||
setScene(new QGraphicsScene(this));
|
||||
@ -680,6 +733,19 @@ ProfGraphicsView::~ProfGraphicsView()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfChronometerItem* ProfGraphicsView::createChronometer(bool _main)
|
||||
{
|
||||
auto chronoItem = new ProfChronometerItem(_main);
|
||||
chronoItem->setColor(_main ? CHRONOMETER_COLOR : CHRONOMETER_COLOR2);
|
||||
chronoItem->setBoundingRect(scene()->sceneRect());
|
||||
chronoItem->hide();
|
||||
scene()->addItem(chronoItem);
|
||||
|
||||
return chronoItem;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ProfGraphicsView::fillTestChildren(ProfGraphicsItem* _item, const int _maxlevel, int _level, qreal _x, qreal _y, unsigned int _childrenNumber, unsigned int& _total_items)
|
||||
{
|
||||
unsigned int nchildren = _childrenNumber;
|
||||
@ -815,10 +881,8 @@ void ProfGraphicsView::test(unsigned int _frames_number, unsigned int _total_ite
|
||||
|
||||
// Create new chronometer item (previous item was destroyed by scene on scene()->clear()).
|
||||
// It will be shown on mouse right button click.
|
||||
m_chronometerItem = new ProfChronometerItem();
|
||||
m_chronometerItem->setBoundingRect(scene()->sceneRect());
|
||||
m_chronometerItem->hide();
|
||||
scene()->addItem(m_chronometerItem);
|
||||
m_chronometerItem = createChronometer(true);
|
||||
m_chronometerItemAux = createChronometer(false);
|
||||
|
||||
// Set necessary flags
|
||||
m_bTest = true;
|
||||
@ -837,7 +901,8 @@ void ProfGraphicsView::clearSilent()
|
||||
|
||||
// Stop flicking
|
||||
m_flickerTimer.stop();
|
||||
m_flickerSpeed = 0;
|
||||
m_flickerSpeedX = 0;
|
||||
m_flickerSpeedY = 0;
|
||||
|
||||
// Clear all items
|
||||
scene()->clear();
|
||||
@ -932,10 +997,8 @@ void ProfGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr
|
||||
|
||||
// Create new chronometer item (previous item was destroyed by scene on scene()->clear()).
|
||||
// It will be shown on mouse right button click.
|
||||
m_chronometerItem = new ProfChronometerItem();
|
||||
m_chronometerItem->setBoundingRect(scene()->sceneRect());
|
||||
m_chronometerItem->hide();
|
||||
scene()->addItem(m_chronometerItem);
|
||||
m_chronometerItem = createChronometer(true);
|
||||
m_chronometerItemAux = createChronometer(false);
|
||||
|
||||
// Setting flags
|
||||
m_bTest = false;
|
||||
@ -1133,9 +1196,9 @@ void ProfGraphicsView::mousePressEvent(QMouseEvent* _event)
|
||||
|
||||
if (m_mouseButtons & Qt::RightButton)
|
||||
{
|
||||
m_bStrictSelection = false;
|
||||
const auto mouseX = m_offset + mapToScene(_event->pos()).x() / m_scale;
|
||||
m_chronometerItem->setLeftRight(mouseX, mouseX);
|
||||
m_chronometerItem->setReverse(false);
|
||||
m_chronometerItem->hide();
|
||||
m_pScrollbar->hideChrono();
|
||||
}
|
||||
@ -1143,6 +1206,28 @@ void ProfGraphicsView::mousePressEvent(QMouseEvent* _event)
|
||||
_event->accept();
|
||||
}
|
||||
|
||||
void ProfGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event)
|
||||
{
|
||||
if (m_bEmpty)
|
||||
{
|
||||
_event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
m_mouseButtons = _event->buttons();
|
||||
m_bDoubleClick = true;
|
||||
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
const auto mouseX = m_offset + mapToScene(_event->pos()).x() / m_scale;
|
||||
m_chronometerItemAux->setLeftRight(mouseX, mouseX);
|
||||
m_chronometerItemAux->setReverse(false);
|
||||
m_chronometerItemAux->hide();
|
||||
}
|
||||
|
||||
_event->accept();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ProfGraphicsView::mouseReleaseEvent(QMouseEvent* _event)
|
||||
@ -1184,19 +1269,64 @@ void ProfGraphicsView::mouseReleaseEvent(QMouseEvent* _event)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
if (m_chronometerItemAux->isVisible() && m_chronometerItemAux->width() < 1e-6)
|
||||
{
|
||||
m_chronometerItemAux->hide();
|
||||
}
|
||||
}
|
||||
|
||||
m_bDoubleClick = false;
|
||||
m_mouseButtons = _event->buttons();
|
||||
_event->accept();
|
||||
|
||||
if (changedSelection)
|
||||
{
|
||||
emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_bStrictSelection);
|
||||
emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse());
|
||||
}
|
||||
|
||||
m_bStrictSelection = false;
|
||||
m_chronometerItem->setReverse(false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ProfGraphicsView::moveChrono(ProfChronometerItem* _chronometerItem, qreal _mouseX)
|
||||
{
|
||||
if (_chronometerItem->reverse())
|
||||
{
|
||||
if (_mouseX > _chronometerItem->right())
|
||||
{
|
||||
_chronometerItem->setReverse(false);
|
||||
_chronometerItem->setLeftRight(_chronometerItem->right(), _mouseX);
|
||||
}
|
||||
else
|
||||
{
|
||||
_chronometerItem->setLeftRight(_mouseX, _chronometerItem->right());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_mouseX < _chronometerItem->left())
|
||||
{
|
||||
_chronometerItem->setReverse(true);
|
||||
_chronometerItem->setLeftRight(_mouseX, _chronometerItem->left());
|
||||
}
|
||||
else
|
||||
{
|
||||
_chronometerItem->setLeftRight(_chronometerItem->left(), _mouseX);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_chronometerItem->isVisible() && _chronometerItem->width() > 1e-6)
|
||||
{
|
||||
_chronometerItem->show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProfGraphicsView::mouseMoveEvent(QMouseEvent* _event)
|
||||
{
|
||||
if (m_bEmpty)
|
||||
@ -1210,36 +1340,11 @@ void ProfGraphicsView::mouseMoveEvent(QMouseEvent* _event)
|
||||
if (m_mouseButtons & Qt::RightButton)
|
||||
{
|
||||
const auto mouseX = m_offset + mapToScene(_event->pos()).x() / m_scale;
|
||||
if (m_bStrictSelection)
|
||||
{
|
||||
if (mouseX > m_chronometerItem->right())
|
||||
{
|
||||
m_bStrictSelection = false;
|
||||
m_chronometerItem->setLeftRight(m_chronometerItem->right(), mouseX);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_chronometerItem->setLeftRight(mouseX, m_chronometerItem->right());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mouseX < m_chronometerItem->left())
|
||||
{
|
||||
m_bStrictSelection = true;
|
||||
m_chronometerItem->setLeftRight(mouseX, m_chronometerItem->left());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_chronometerItem->setLeftRight(m_chronometerItem->left(), mouseX);
|
||||
}
|
||||
}
|
||||
|
||||
bool showItem = moveChrono(m_chronometerItem, mouseX);
|
||||
m_pScrollbar->setChronoPos(m_chronometerItem->left(), m_chronometerItem->right());
|
||||
|
||||
if (!m_chronometerItem->isVisible() && m_chronometerItem->width() > 1e-6)
|
||||
if (showItem)
|
||||
{
|
||||
m_chronometerItem->show();
|
||||
m_pScrollbar->showChrono();
|
||||
}
|
||||
|
||||
@ -1248,26 +1353,35 @@ void ProfGraphicsView::mouseMoveEvent(QMouseEvent* _event)
|
||||
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
const auto pos = _event->globalPos();
|
||||
const auto delta = pos - m_mousePressPos;
|
||||
m_mousePressPos = pos;
|
||||
|
||||
auto vbar = verticalScrollBar();
|
||||
|
||||
m_bUpdatingRect = true; // Block scrollbars from updating scene rect to make it possible to do it only once
|
||||
vbar->setValue(vbar->value() - delta.y());
m_pScrollbar->setValue(m_pScrollbar->value() - delta.x() / m_scale);
|
||||
m_bUpdatingRect = false;
|
||||
// Seems like an ugly stub, but QSignalBlocker is also a bad decision
|
||||
// because if scrollbar does not emit valueChanged signal then viewport does not move
|
||||
|
||||
updateVisibleSceneRect(); // Update scene visible rect only once
|
||||
|
||||
// Update flicker speed
|
||||
m_flickerSpeed += delta.x() >> 1;
|
||||
if (!m_flickerTimer.isActive())
|
||||
if (m_bDoubleClick)
|
||||
{
|
||||
// If flicker timer is not started, then start it
|
||||
m_flickerTimer.start(20);
|
||||
const auto mouseX = m_offset + mapToScene(_event->pos()).x() / m_scale;
|
||||
moveChrono(m_chronometerItemAux, mouseX);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto pos = _event->globalPos();
|
||||
const auto delta = pos - m_mousePressPos;
|
||||
m_mousePressPos = pos;
|
||||
|
||||
auto vbar = verticalScrollBar();
|
||||
|
||||
m_bUpdatingRect = true; // Block scrollbars from updating scene rect to make it possible to do it only once
|
||||
vbar->setValue(vbar->value() - delta.y());
m_pScrollbar->setValue(m_pScrollbar->value() - delta.x() / m_scale);
|
||||
m_bUpdatingRect = false;
|
||||
// Seems like an ugly stub, but QSignalBlocker is also a bad decision
|
||||
// because if scrollbar does not emit valueChanged signal then viewport does not move
|
||||
|
||||
updateVisibleSceneRect(); // Update scene visible rect only once
|
||||
|
||||
// Update flicker speed
|
||||
m_flickerSpeedX += delta.x() >> 2;
|
||||
m_flickerSpeedY += delta.y() >> 1;
|
||||
if (!m_flickerTimer.isActive())
|
||||
{
|
||||
// If flicker timer is not started, then start it
|
||||
m_flickerTimer.start(FLICKER_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
needUpdate = true;
|
||||
@ -1287,6 +1401,7 @@ void ProfGraphicsView::resizeEvent(QResizeEvent* _event)
|
||||
{
|
||||
updateVisibleSceneRect(); // Update scene visible rect only once
|
||||
updateScene(); // repaint scene
|
||||
QGraphicsView::resizeEvent(_event);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -1335,24 +1450,30 @@ void ProfGraphicsView::onFlickerTimeout()
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
// Fast slow-down and stop if mouse button is pressed, no flicking.
|
||||
m_flickerSpeed >>= 1;
|
||||
m_flickerSpeedX >>= 1;
|
||||
m_flickerSpeedY >>= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Flick when mouse button is not pressed
|
||||
|
||||
auto vbar = verticalScrollBar();
|
||||
|
||||
m_bUpdatingRect = true; // Block scrollbars from updating scene rect to make it possible to do it only once
|
||||
m_pScrollbar->setValue(m_pScrollbar->value() - m_flickerSpeed / m_scale);
|
||||
m_pScrollbar->setValue(m_pScrollbar->value() - m_flickerSpeedX / m_scale);
|
||||
vbar->setValue(vbar->value() - m_flickerSpeedY);
|
||||
m_bUpdatingRect = false;
|
||||
// Seems like an ugly stub, but QSignalBlocker is also a bad decision
|
||||
// because if scrollbar does not emit valueChanged signal then viewport does not move
|
||||
|
||||
updateVisibleSceneRect(); // Update scene visible rect only once
|
||||
updateScene(); // repaint scene
|
||||
m_flickerSpeed -= absmin(3 * sign(m_flickerSpeed), m_flickerSpeed);
|
||||
|
||||
m_flickerSpeedX -= absmin(sign(m_flickerSpeedX), m_flickerSpeedX);
|
||||
m_flickerSpeedY -= absmin(sign(m_flickerSpeedY), m_flickerSpeedY);
|
||||
}
|
||||
|
||||
if (m_flickerSpeed == 0)
|
||||
if (m_flickerSpeedX == 0 && m_flickerSpeedY == 0)
|
||||
{
|
||||
// Flicker stopped, no timer needed.
|
||||
m_flickerTimer.stop();
|
||||
|
@ -139,12 +139,16 @@ private:
|
||||
class ProfChronometerItem : public QGraphicsItem
|
||||
{
|
||||
QFont m_font; ///< Font which is used to draw text
|
||||
QPolygonF m_indicator; ///< Indicator displayed when this chrono item is out of screen (displaying only for main item)
|
||||
QRectF m_boundingRect; ///< boundingRect (see QGraphicsItem)
|
||||
QColor m_color; ///< Color of the item
|
||||
qreal m_left, m_right; ///< Left and right bounds of the selection zone
|
||||
bool m_bMain; ///< Is this chronometer main (true, by default)
|
||||
bool m_bReverse;
|
||||
|
||||
public:
|
||||
|
||||
ProfChronometerItem();
|
||||
ProfChronometerItem(bool _main = true);
|
||||
virtual ~ProfChronometerItem();
|
||||
|
||||
// Public virtual methods
|
||||
@ -156,10 +160,20 @@ public:
|
||||
|
||||
// Public non-virtual methods
|
||||
|
||||
void setColor(const QColor& _color);
|
||||
|
||||
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
||||
void setBoundingRect(const QRectF& _rect);
|
||||
|
||||
void setLeftRight(qreal _left, qreal _right);
|
||||
|
||||
void setReverse(bool _reverse);
|
||||
|
||||
inline bool reverse() const
|
||||
{
|
||||
return m_bReverse;
|
||||
}
|
||||
|
||||
inline qreal left() const
|
||||
{
|
||||
return m_left;
|
||||
@ -202,13 +216,15 @@ private:
|
||||
qreal m_offset; ///< Have to use manual offset for all scene content instead of using scrollbars because QScrollBar::value is 32-bit integer :(
|
||||
QPoint m_mousePressPos; ///< Last mouse global position (used by mousePressEvent and mouseMoveEvent)
|
||||
Qt::MouseButtons m_mouseButtons; ///< Pressed mouse buttons
|
||||
ProfGraphicsScrollbar* m_pScrollbar; ///< Pointer to the graphics scrollbar widget
|
||||
ProfChronometerItem* m_chronometerItem; ///< Pointer to the ProfChronometerItem which is displayed when you press right mouse button and move mouse left or right
|
||||
int m_flickerSpeed; ///< Current flicking speed
|
||||
ProfGraphicsScrollbar* m_pScrollbar; ///< Pointer to the graphics scrollbar widget
|
||||
ProfChronometerItem* m_chronometerItem; ///< Pointer to the ProfChronometerItem which is displayed when you press right mouse button and move mouse left or right. This item is used to select blocks to display in tree widget.
|
||||
ProfChronometerItem* m_chronometerItemAux; ///< Pointer to the ProfChronometerItem which is displayed when you double click left mouse button and move mouse left or right. This item is used only to measure time.
|
||||
int m_flickerSpeedX; ///< Current flicking speed x
|
||||
int m_flickerSpeedY; ///< Current flicking speed y
|
||||
bool m_bDoubleClick; ///< Is mouse buttons double clicked
|
||||
bool m_bUpdatingRect; ///< Stub flag which is used to avoid excess calculations on some scene update (flicking, scaling and so on)
|
||||
bool m_bTest; ///< Testing flag (true when test() is called)
|
||||
bool m_bEmpty; ///< Indicates whether scene is empty and has no items
|
||||
bool m_bStrictSelection; ///< Strict selection flag used by ProfTreeWidget to interpret left and right bounds of selection zone in different ways
|
||||
|
||||
public:
|
||||
|
||||
@ -220,6 +236,7 @@ public:
|
||||
|
||||
void wheelEvent(QWheelEvent* _event) override;
|
||||
void mousePressEvent(QMouseEvent* _event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent* _event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* _event) override;
|
||||
void mouseMoveEvent(QMouseEvent* _event) override;
|
||||
void resizeEvent(QResizeEvent* _event) override;
|
||||
@ -244,6 +261,8 @@ private:
|
||||
|
||||
// Private non-virtual methods
|
||||
|
||||
ProfChronometerItem* createChronometer(bool _main = true);
|
||||
bool moveChrono(ProfChronometerItem* _chronometerItem, qreal _mouseX);
|
||||
void initMode();
|
||||
void updateVisibleSceneRect();
|
||||
void updateScene();
|
||||
|
@ -87,8 +87,6 @@ struct do_no_hash {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const QRgb SELECTED_THREAD_BACKGROUND = 0x00d8d840;
|
||||
const QRgb SELECTED_THREAD_FOREGROUND = 0x00ffffff - SELECTED_THREAD_BACKGROUND;
|
||||
const QRgb DEFAULT_COLOR = 0x00f0e094;
|
||||
|
||||
inline QRgb toRgb(unsigned int _red, unsigned int _green, unsigned int _blue)
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
#include "common_types.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -35,6 +36,10 @@ namespace profiler_gui {
|
||||
const QString ORGANAZATION_NAME = "EasyProfiler";
|
||||
const QString APPLICATION_NAME = "Easy profiler gui application";
|
||||
|
||||
const QColor CHRONOMETER_COLOR = QColor::fromRgba(0x402020c0);
|
||||
const QRgb SELECTED_THREAD_BACKGROUND = 0x00d8d840;
|
||||
const QRgb SELECTED_THREAD_FOREGROUND = 0x00ffffff - SELECTED_THREAD_BACKGROUND;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProfGlobalSignals final : public QObject
|
||||
|
@ -65,11 +65,24 @@ void ProfGraphicsSliderItem::paint(QPainter* _painter, const QStyleOptionGraphic
|
||||
w = 1.0;
|
||||
}
|
||||
|
||||
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(QRectF(dx + br.left() * currentScale, br.top(), w, br.height()));
|
||||
_painter->drawRect(r);
|
||||
//b.setColor(b.color().rgb());
|
||||
//_painter->setBrush(b);
|
||||
//_painter->drawPolygon(indicator);
|
||||
_painter->restore();
|
||||
}
|
||||
|
||||
@ -96,9 +109,14 @@ void ProfGraphicsSliderItem::setHalfwidth(qreal _halfwidth)
|
||||
}
|
||||
|
||||
void ProfGraphicsSliderItem::setColor(QRgb _color)
|
||||
{
|
||||
setColor(QColor::fromRgba(_color));
|
||||
}
|
||||
|
||||
void ProfGraphicsSliderItem::setColor(const QColor& _color)
|
||||
{
|
||||
auto b = brush();
|
||||
b.setColor(QColor::fromRgba(_color));
|
||||
b.setColor(_color);
|
||||
setBrush(b);
|
||||
}
|
||||
|
||||
@ -233,6 +251,7 @@ ProfGraphicsScrollbar::ProfGraphicsScrollbar(QWidget* _parent)
|
||||
setCacheMode(QGraphicsView::CacheNone);
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setOptimizationFlag(QGraphicsView::DontSavePainterState, true);
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
@ -255,7 +274,7 @@ ProfGraphicsScrollbar::ProfGraphicsScrollbar(QWidget* _parent)
|
||||
m_chronometerIndicator = new ProfGraphicsSliderItem();
|
||||
m_chronometerIndicator->setPos(0, 0);
|
||||
m_chronometerIndicator->setZValue(10);
|
||||
m_chronometerIndicator->setColor(0x80404040);
|
||||
m_chronometerIndicator->setColor(::profiler_gui::CHRONOMETER_COLOR);
|
||||
selfScene->addItem(m_chronometerIndicator);
|
||||
m_chronometerIndicator->hide();
|
||||
|
||||
@ -371,7 +390,7 @@ void ProfGraphicsScrollbar::mousePressEvent(QMouseEvent* _event)
|
||||
{
|
||||
m_bScrolling = true;
|
||||
m_mousePressPos = _event->pos();
|
||||
setValue(mapToScene(m_mousePressPos).x() - m_minimumValue);
|
||||
setValue(mapToScene(m_mousePressPos).x() - m_minimumValue - m_slider->halfwidth());
|
||||
}
|
||||
|
||||
_event->accept();
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
void setHalfwidth(qreal _halfwidth);
|
||||
|
||||
void setColor(QRgb _color);
|
||||
void setColor(const QColor& _color);
|
||||
|
||||
}; // END of class ProfGraphicsSliderItem.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user