mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 08:37:55 +08:00
(GraphicsView) Using GraphicsScrollbar with qreal values instead of standard QScrollBar with int values.
(GraphicsView) Does not use standard QGraphicsView::scale and QGraphicsView::centerOn methods, does not use standard QScrollBar because of it's fast value overflow. Using manual offset for all scene items instead of standard scrolling.
This commit is contained in:
parent
ac484a1ae4
commit
c943431104
File diff suppressed because it is too large
Load Diff
@ -32,30 +32,23 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "graphics_scrollbar.h"
|
||||||
#include "profiler/reader.h"
|
#include "profiler/reader.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define DRAW_METHOD 2
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct ProfBlockItem
|
struct ProfBlockItem
|
||||||
{
|
{
|
||||||
const BlocksTree* block;
|
const BlocksTree* block;
|
||||||
qreal x;
|
qreal x;
|
||||||
float w;
|
float w;
|
||||||
float y;
|
float y;
|
||||||
float h;
|
float h;
|
||||||
QRgb color;
|
QRgb color;
|
||||||
#if DRAW_METHOD > 0
|
unsigned int children_begin;
|
||||||
unsigned int children_begin;
|
unsigned short totalHeight;
|
||||||
#endif
|
char state;
|
||||||
unsigned short totalHeight;
|
|
||||||
#if DRAW_METHOD > 0
|
|
||||||
char state;
|
|
||||||
#else
|
|
||||||
bool state;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void setRect(qreal _x, float _y, float _w, float _h);
|
void setRect(qreal _x, float _y, float _w, float _h);
|
||||||
qreal left() const;
|
qreal left() const;
|
||||||
@ -67,21 +60,22 @@ struct ProfBlockItem
|
|||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class ProfGraphicsView;
|
||||||
|
|
||||||
class ProfGraphicsItem : public QGraphicsItem
|
class ProfGraphicsItem : public QGraphicsItem
|
||||||
{
|
{
|
||||||
typedef ::std::vector<ProfBlockItem> Children;
|
typedef ::std::vector<ProfBlockItem> Children;
|
||||||
|
typedef ::std::vector<unsigned int> DrawIndexes;
|
||||||
|
typedef ::std::vector<Children> Sublevels;
|
||||||
|
|
||||||
#if DRAW_METHOD == 2
|
DrawIndexes m_levelsIndexes;
|
||||||
typedef ::std::vector<unsigned int> DrawIndexes;
|
Sublevels m_levels;
|
||||||
DrawIndexes m_levelsIndexes;
|
|
||||||
typedef ::std::vector<Children> Sublevels;
|
|
||||||
Sublevels m_levels;
|
|
||||||
#else
|
|
||||||
Children m_items;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QRectF m_rect;
|
QRectF m_rect;
|
||||||
const bool m_bTest;
|
QRgb m_backgroundColor;
|
||||||
|
const bool m_bTest;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -92,18 +86,13 @@ public:
|
|||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
||||||
|
|
||||||
|
QRgb backgroundColor() const;
|
||||||
|
|
||||||
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
||||||
void setBoundingRect(const QRectF& _rect);
|
void setBoundingRect(const QRectF& _rect);
|
||||||
|
|
||||||
#if DRAW_METHOD == 0
|
void setBackgroundColor(QRgb _color);
|
||||||
void reserve(size_t _items);
|
|
||||||
const Children& items() const;
|
|
||||||
const ProfBlockItem& getItem(size_t _index) const;
|
|
||||||
ProfBlockItem& getItem(size_t _index);
|
|
||||||
size_t addItem();
|
|
||||||
size_t addItem(const ProfBlockItem& _item);
|
|
||||||
size_t addItem(ProfBlockItem&& _item);
|
|
||||||
#else
|
|
||||||
unsigned short levels() const;
|
unsigned short levels() const;
|
||||||
void setLevels(unsigned short _levels);
|
void setLevels(unsigned short _levels);
|
||||||
void reserve(unsigned short _level, size_t _items);
|
void reserve(unsigned short _level, size_t _items);
|
||||||
@ -113,7 +102,10 @@ public:
|
|||||||
size_t addItem(unsigned short _level);
|
size_t addItem(unsigned short _level);
|
||||||
size_t addItem(unsigned short _level, const ProfBlockItem& _item);
|
size_t addItem(unsigned short _level, const ProfBlockItem& _item);
|
||||||
size_t addItem(unsigned short _level, ProfBlockItem&& _item);
|
size_t addItem(unsigned short _level, ProfBlockItem&& _item);
|
||||||
#endif
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const ProfGraphicsView* view() const;
|
||||||
|
|
||||||
}; // END of class ProfGraphicsItem.
|
}; // END of class ProfGraphicsItem.
|
||||||
|
|
||||||
@ -144,8 +136,6 @@ private:
|
|||||||
void clearSilent();
|
void clearSilent();
|
||||||
|
|
||||||
void setTree(const thread_blocks_tree_t& _blocksTree);
|
void setTree(const thread_blocks_tree_t& _blocksTree);
|
||||||
|
|
||||||
qreal setTree(const BlocksTree::children_t& _children, qreal& _height, qreal _y);
|
|
||||||
qreal setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level);
|
qreal setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level);
|
||||||
|
|
||||||
inline qreal time2position(const profiler::timestamp_t& _time) const
|
inline qreal time2position(const profiler::timestamp_t& _time) const
|
||||||
@ -165,17 +155,20 @@ private:
|
|||||||
|
|
||||||
typedef ProfGraphicsView This;
|
typedef ProfGraphicsView This;
|
||||||
|
|
||||||
QTimer m_flickerTimer;
|
QTimer m_flickerTimer;
|
||||||
QRectF m_visibleSceneRect;
|
QRectF m_visibleSceneRect;
|
||||||
qreal m_scale;
|
qreal m_scale;
|
||||||
qreal m_scaleCoeff;
|
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;
|
QPoint m_mousePressPos;
|
||||||
Qt::MouseButtons m_mouseButtons;
|
Qt::MouseButtons m_mouseButtons;
|
||||||
int m_flickerSpeed;
|
GraphicsHorizontalScrollbar* m_pScrollbar;
|
||||||
bool m_bUpdatingRect;
|
int m_flickerSpeed;
|
||||||
|
bool m_bUpdatingRect;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using QGraphicsView::scale;
|
||||||
|
|
||||||
ProfGraphicsView(bool _test = false);
|
ProfGraphicsView(bool _test = false);
|
||||||
ProfGraphicsView(const thread_blocks_tree_t& _blocksTree);
|
ProfGraphicsView(const thread_blocks_tree_t& _blocksTree);
|
||||||
virtual ~ProfGraphicsView();
|
virtual ~ProfGraphicsView();
|
||||||
@ -185,16 +178,22 @@ public:
|
|||||||
void mouseReleaseEvent(QMouseEvent* _event) override;
|
void mouseReleaseEvent(QMouseEvent* _event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* _event) override;
|
void mouseMoveEvent(QMouseEvent* _event) override;
|
||||||
|
|
||||||
inline qreal currentScale() const
|
inline qreal scale() const
|
||||||
{
|
{
|
||||||
return m_scale;
|
return m_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline qreal offset() const
|
||||||
|
{
|
||||||
|
return m_offset;
|
||||||
|
}
|
||||||
|
|
||||||
inline const QRectF& visibleSceneRect() const
|
inline const QRectF& visibleSceneRect() const
|
||||||
{
|
{
|
||||||
return m_visibleSceneRect;
|
return m_visibleSceneRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setScrollbar(GraphicsHorizontalScrollbar* _scrollbar);
|
||||||
void setTree(const thread_blocks_tree_t& _blocksTree);
|
void setTree(const thread_blocks_tree_t& _blocksTree);
|
||||||
void clearSilent();
|
void clearSilent();
|
||||||
|
|
||||||
@ -204,14 +203,39 @@ private:
|
|||||||
|
|
||||||
void initMode();
|
void initMode();
|
||||||
void updateVisibleSceneRect();
|
void updateVisibleSceneRect();
|
||||||
|
void updateScene();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void onScrollbarValueChange(int);
|
void onScrollbarValueChange(int);
|
||||||
|
void onGraphicsScrollbarValueChange(qreal);
|
||||||
void onFlickerTimeout();
|
void onFlickerTimeout();
|
||||||
|
|
||||||
}; // END of class ProfGraphicsView.
|
}; // END of class ProfGraphicsView.
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class ProfGraphicsViewWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
ProfGraphicsView* m_view;
|
||||||
|
GraphicsHorizontalScrollbar* m_scrollbar;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ProfGraphicsViewWidget(bool _test = false);
|
||||||
|
ProfGraphicsViewWidget(const thread_blocks_tree_t& _blocksTree);
|
||||||
|
virtual ~ProfGraphicsViewWidget();
|
||||||
|
|
||||||
|
ProfGraphicsView* view();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
}; // END of class ProfGraphicsViewWidget.
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#endif // MY____GRAPHICS___VIEW_H
|
#endif // MY____GRAPHICS___VIEW_H
|
||||||
|
@ -15,12 +15,20 @@
|
|||||||
* license : TODO: add license text
|
* license : TODO: add license text
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
#include <QScrollBar>
|
#include <algorithm>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QResizeEvent>
|
||||||
#include "graphics_scrollbar.h"
|
#include "graphics_scrollbar.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
auto const clamp = [](double _minValue, double _value, double _maxValue)
|
const qreal SCALING_COEFFICIENT = 1.25;
|
||||||
|
const qreal SCALING_COEFFICIENT_INV = 1.0 / SCALING_COEFFICIENT;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
auto const clamp = [](qreal _minValue, qreal _value, qreal _maxValue)
|
||||||
{
|
{
|
||||||
return (_value < _minValue ? _minValue : (_value > _maxValue ? _maxValue : _value));
|
return (_value < _minValue ? _minValue : (_value > _maxValue ? _maxValue : _value));
|
||||||
};
|
};
|
||||||
@ -38,32 +46,58 @@ GraphicsHorizontalSlider::~GraphicsHorizontalSlider()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsHorizontalSlider::width() const
|
void GraphicsHorizontalSlider::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
||||||
|
{
|
||||||
|
//Parent::paint(_painter, _option, _widget);
|
||||||
|
const auto currentScale = static_cast<const GraphicsHorizontalScrollbar*>(scene()->parent())->getWindowScale();
|
||||||
|
const auto br = rect();
|
||||||
|
|
||||||
|
qreal w = width() * currentScale;
|
||||||
|
qreal dx = 0;
|
||||||
|
|
||||||
|
if (w < 1.0)
|
||||||
|
{
|
||||||
|
dx = (w - 1.0) * 0.5;
|
||||||
|
w = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_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->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal GraphicsHorizontalSlider::width() const
|
||||||
{
|
{
|
||||||
return m_halfwidth * 2.0;
|
return m_halfwidth * 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsHorizontalSlider::halfwidth() const
|
qreal GraphicsHorizontalSlider::halfwidth() const
|
||||||
{
|
{
|
||||||
return m_halfwidth;
|
return m_halfwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsHorizontalSlider::setWidth(double _width)
|
void GraphicsHorizontalSlider::setWidth(qreal _width)
|
||||||
{
|
{
|
||||||
m_halfwidth = _width * 0.5;
|
m_halfwidth = _width * 0.5;
|
||||||
setPolygon(QRectF(-m_halfwidth, -10, _width, 20));
|
setRect(-m_halfwidth, -10, _width, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsHorizontalSlider::setHalfwidth(double _halfwidth)
|
void GraphicsHorizontalSlider::setHalfwidth(qreal _halfwidth)
|
||||||
{
|
{
|
||||||
m_halfwidth = _halfwidth;
|
m_halfwidth = _halfwidth;
|
||||||
setPolygon(QRectF(-m_halfwidth, -10, m_halfwidth * 2.0, 20));
|
setRect(-m_halfwidth, -10, m_halfwidth * 2.0, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsHorizontalSlider::setColor(QRgb _color)
|
void GraphicsHorizontalSlider::setColor(QRgb _color)
|
||||||
{
|
{
|
||||||
|
QColor c(_color);
|
||||||
|
c.setAlpha((_color & 0xff000000) >> 24);
|
||||||
|
|
||||||
auto b = brush();
|
auto b = brush();
|
||||||
b.setColor(_color);
|
b.setColor(c);
|
||||||
setBrush(b);
|
setBrush(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +108,10 @@ GraphicsHorizontalScrollbar::GraphicsHorizontalScrollbar(QWidget* _parent)
|
|||||||
, m_minimumValue(0)
|
, m_minimumValue(0)
|
||||||
, m_maximumValue(500)
|
, m_maximumValue(500)
|
||||||
, m_value(10)
|
, m_value(10)
|
||||||
|
, m_windowScale(1)
|
||||||
|
, m_mouseButtons(Qt::NoButton)
|
||||||
, m_slider(nullptr)
|
, m_slider(nullptr)
|
||||||
|
, m_bScrolling(false)
|
||||||
{
|
{
|
||||||
setCacheMode(QGraphicsView::CacheNone);
|
setCacheMode(QGraphicsView::CacheNone);
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
@ -93,10 +130,10 @@ GraphicsHorizontalScrollbar::GraphicsHorizontalScrollbar(QWidget* _parent)
|
|||||||
|
|
||||||
m_slider = new GraphicsHorizontalSlider();
|
m_slider = new GraphicsHorizontalSlider();
|
||||||
m_slider->setPos(10, 0);
|
m_slider->setPos(10, 0);
|
||||||
m_slider->setColor(0xffff0404);
|
m_slider->setColor(0x80e00000);
|
||||||
selfScene->addItem(m_slider);
|
selfScene->addItem(m_slider);
|
||||||
|
|
||||||
centerOn(10, 0);
|
centerOn(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsHorizontalScrollbar::~GraphicsHorizontalScrollbar()
|
GraphicsHorizontalScrollbar::~GraphicsHorizontalScrollbar()
|
||||||
@ -106,34 +143,120 @@ GraphicsHorizontalScrollbar::~GraphicsHorizontalScrollbar()
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
double GraphicsHorizontalScrollbar::minimum() const
|
qreal GraphicsHorizontalScrollbar::getWindowScale() const
|
||||||
|
{
|
||||||
|
return m_windowScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal GraphicsHorizontalScrollbar::minimum() const
|
||||||
{
|
{
|
||||||
return m_minimumValue;
|
return m_minimumValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsHorizontalScrollbar::maximum() const
|
qreal GraphicsHorizontalScrollbar::maximum() const
|
||||||
{
|
{
|
||||||
return m_maximumValue;
|
return m_maximumValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsHorizontalScrollbar::value() const
|
qreal GraphicsHorizontalScrollbar::range() const
|
||||||
|
{
|
||||||
|
return m_maximumValue - m_minimumValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal GraphicsHorizontalScrollbar::value() const
|
||||||
{
|
{
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GraphicsHorizontalScrollbar::setValue(double _value)
|
void GraphicsHorizontalScrollbar::setValue(qreal _value)
|
||||||
{
|
{
|
||||||
m_value = clamp(m_minimumValue + m_slider->halfwidth(), _value, m_maximumValue - m_slider->halfwidth());
|
m_value = clamp(m_minimumValue, _value, m_maximumValue - m_slider->width());
|
||||||
|
m_slider->setX(m_value + m_slider->halfwidth());
|
||||||
emit valueChanged(m_value);
|
emit valueChanged(m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsHorizontalScrollbar::setRange(double _minValue, double _maxValue)
|
void GraphicsHorizontalScrollbar::setRange(qreal _minValue, qreal _maxValue)
|
||||||
{
|
{
|
||||||
|
const auto oldRange = range();
|
||||||
|
const auto oldValue = oldRange < 1e-3 ? 0.0 : m_value / oldRange;
|
||||||
|
|
||||||
m_minimumValue = _minValue;
|
m_minimumValue = _minValue;
|
||||||
m_maximumValue = _maxValue;
|
m_maximumValue = _maxValue;
|
||||||
|
scene()->setSceneRect(_minValue, -10, _maxValue - _minValue, 20);
|
||||||
|
emit rangeChanged();
|
||||||
|
|
||||||
|
setValue(_minValue + oldValue * range());
|
||||||
|
onWindowWidthChange(width());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::setSliderWidth(qreal _width)
|
||||||
|
{
|
||||||
|
m_slider->setWidth(_width);
|
||||||
setValue(m_value);
|
setValue(m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::mousePressEvent(QMouseEvent* _event)
|
||||||
|
{
|
||||||
|
m_mouseButtons = _event->buttons();
|
||||||
|
|
||||||
|
if (m_mouseButtons & Qt::LeftButton)
|
||||||
|
{
|
||||||
|
m_bScrolling = true;
|
||||||
|
m_mousePressPos = _event->pos();
|
||||||
|
setValue(mapToScene(m_mousePressPos).x() - m_minimumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
_event->accept();
|
||||||
|
//QGraphicsView::mousePressEvent(_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::mouseReleaseEvent(QMouseEvent* _event)
|
||||||
|
{
|
||||||
|
m_mouseButtons = _event->buttons();
|
||||||
|
m_bScrolling = false;
|
||||||
|
_event->accept();
|
||||||
|
//QGraphicsView::mouseReleaseEvent(_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::mouseMoveEvent(QMouseEvent* _event)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::resizeEvent(QResizeEvent* _event)
|
||||||
|
{
|
||||||
|
onWindowWidthChange(_event->size().width());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsHorizontalScrollbar::onWindowWidthChange(qreal _width)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -21,29 +21,31 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsPolygonItem>
|
#include <QGraphicsRectItem>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class GraphicsHorizontalSlider : public QGraphicsPolygonItem
|
class GraphicsHorizontalSlider : public QGraphicsRectItem
|
||||||
{
|
{
|
||||||
typedef QGraphicsPolygonItem Parent;
|
typedef QGraphicsRectItem Parent;
|
||||||
typedef GraphicsHorizontalSlider This;
|
typedef GraphicsHorizontalSlider This;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
double m_halfwidth;
|
qreal m_halfwidth;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphicsHorizontalSlider();
|
GraphicsHorizontalSlider();
|
||||||
virtual ~GraphicsHorizontalSlider();
|
virtual ~GraphicsHorizontalSlider();
|
||||||
|
|
||||||
double width() const;
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
||||||
double halfwidth() const;
|
|
||||||
|
|
||||||
void setWidth(double _width);
|
qreal width() const;
|
||||||
void setHalfwidth(double _halfwidth);
|
qreal halfwidth() const;
|
||||||
|
|
||||||
|
void setWidth(qreal _width);
|
||||||
|
void setHalfwidth(qreal _halfwidth);
|
||||||
|
|
||||||
void setColor(QRgb _color);
|
void setColor(QRgb _color);
|
||||||
|
|
||||||
@ -60,24 +62,44 @@ private:
|
|||||||
typedef QGraphicsView Parent;
|
typedef QGraphicsView Parent;
|
||||||
typedef GraphicsHorizontalScrollbar This;
|
typedef GraphicsHorizontalScrollbar This;
|
||||||
|
|
||||||
double m_minimumValue, m_maximumValue, m_value;
|
qreal m_minimumValue;
|
||||||
GraphicsHorizontalSlider* m_slider;
|
qreal m_maximumValue;
|
||||||
|
qreal m_value;
|
||||||
|
qreal m_windowScale;
|
||||||
|
QPoint m_mousePressPos;
|
||||||
|
Qt::MouseButtons m_mouseButtons;
|
||||||
|
GraphicsHorizontalSlider* m_slider;
|
||||||
|
bool m_bScrolling;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphicsHorizontalScrollbar(QWidget* _parent = nullptr);
|
GraphicsHorizontalScrollbar(QWidget* _parent = nullptr);
|
||||||
virtual ~GraphicsHorizontalScrollbar();
|
virtual ~GraphicsHorizontalScrollbar();
|
||||||
|
|
||||||
double minimum() const;
|
void mousePressEvent(QMouseEvent* _event) override;
|
||||||
double maximum() const;
|
void mouseReleaseEvent(QMouseEvent* _event) override;
|
||||||
double value() const;
|
void mouseMoveEvent(QMouseEvent* _event) override;
|
||||||
|
void resizeEvent(QResizeEvent* _event) override;
|
||||||
|
|
||||||
void setValue(double _value);
|
qreal getWindowScale() const;
|
||||||
void setRange(double _minValue, double _maxValue);
|
|
||||||
|
qreal minimum() const;
|
||||||
|
qreal maximum() const;
|
||||||
|
qreal range() const;
|
||||||
|
qreal value() const;
|
||||||
|
|
||||||
|
void setValue(qreal _value);
|
||||||
|
void setRange(qreal _minValue, qreal _maxValue);
|
||||||
|
void setSliderWidth(qreal _width);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void valueChanged(double _value) const;
|
void rangeChanged();
|
||||||
|
void valueChanged(qreal _value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void onWindowWidthChange(qreal _width);
|
||||||
|
|
||||||
}; // END of class GraphicsHorizontalScrollbar.
|
}; // END of class GraphicsHorizontalScrollbar.
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "main_window.h"
|
#include "main_window.h"
|
||||||
#include "blocks_tree_widget.h"
|
#include "blocks_tree_widget.h"
|
||||||
#include "blocks_graphics_view.h"
|
#include "blocks_graphics_view.h"
|
||||||
//#include "graphics_scrollbar.h"
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
|
|||||||
|
|
||||||
setStatusBar(new QStatusBar());
|
setStatusBar(new QStatusBar());
|
||||||
|
|
||||||
auto graphicsView = new ProfGraphicsView(false);
|
auto graphicsView = new ProfGraphicsViewWidget(false);
|
||||||
m_graphicsView = new QDockWidget("Blocks diagram");
|
m_graphicsView = new QDockWidget("Blocks diagram");
|
||||||
m_graphicsView->setMinimumHeight(50);
|
m_graphicsView->setMinimumHeight(50);
|
||||||
m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas);
|
m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||||
@ -56,14 +55,7 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
|
|||||||
m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
|
m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||||
m_treeWidget->setWidget(treeWidget);
|
m_treeWidget->setWidget(treeWidget);
|
||||||
|
|
||||||
//auto bar = new GraphicsHorizontalScrollbar();
|
|
||||||
//auto dock = new QDockWidget();
|
|
||||||
//dock->setMinimumHeight(20);
|
|
||||||
//dock->setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
||||||
//dock->setWidget(bar);
|
|
||||||
|
|
||||||
addDockWidget(Qt::TopDockWidgetArea, m_graphicsView);
|
addDockWidget(Qt::TopDockWidgetArea, m_graphicsView);
|
||||||
//addDockWidget(Qt::TopDockWidgetArea, dock);
|
|
||||||
addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
|
addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
|
||||||
|
|
||||||
auto actionOpen = new QAction("Open", nullptr);
|
auto actionOpen = new QAction("Open", nullptr);
|
||||||
@ -120,8 +112,8 @@ void ProfMainWindow::loadFile(const std::string& stdfilename)
|
|||||||
{
|
{
|
||||||
m_lastFile = stdfilename;
|
m_lastFile = stdfilename;
|
||||||
m_currentProf.swap(prof_blocks);
|
m_currentProf.swap(prof_blocks);
|
||||||
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(nblocks, m_currentProf);
|
//static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(nblocks, m_currentProf);
|
||||||
static_cast<ProfGraphicsView*>(m_graphicsView->widget())->setTree(m_currentProf);
|
static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view()->setTree(m_currentProf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,8 +132,8 @@ void ProfMainWindow::onReloadFileClicked(bool)
|
|||||||
if (nblocks != 0)
|
if (nblocks != 0)
|
||||||
{
|
{
|
||||||
m_currentProf.swap(prof_blocks);
|
m_currentProf.swap(prof_blocks);
|
||||||
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(nblocks, m_currentProf);
|
//static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(nblocks, m_currentProf);
|
||||||
static_cast<ProfGraphicsView*>(m_graphicsView->widget())->setTree(m_currentProf);
|
static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view()->setTree(m_currentProf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +150,7 @@ void ProfMainWindow::onTestViewportClicked(bool)
|
|||||||
{
|
{
|
||||||
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->clearSilent();
|
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->clearSilent();
|
||||||
|
|
||||||
auto view = static_cast<ProfGraphicsView*>(m_graphicsView->widget());
|
auto view = static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view();
|
||||||
view->clearSilent();
|
view->clearSilent();
|
||||||
m_currentProf.clear();
|
m_currentProf.clear();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user