mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 00:31:02 +08:00
Added GraphicsScrollbar (still in development phase) for big graphics scene. Standard QScrollBar's int value gets overflow very fast when doing zoom-in for graphics scene. So it is necessary to create a Scrollbar with double value.
This commit is contained in:
parent
f734104280
commit
3978535a99
@ -11,16 +11,18 @@ find_package(Qt5Widgets REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
treemodel.h
|
||||
treemodel.cpp
|
||||
treeitem.h
|
||||
treeitem.cpp
|
||||
blocks_graphics_view.h
|
||||
blocks_graphics_view.cpp
|
||||
blocks_tree_widget.h
|
||||
blocks_tree_widget.cpp
|
||||
graphics_scrollbar.h
|
||||
graphics_scrollbar.cpp
|
||||
main_window.h
|
||||
main_window.cpp
|
||||
treemodel.h
|
||||
treemodel.cpp
|
||||
treeitem.h
|
||||
treeitem.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Widgets easy_profiler)
|
||||
|
139
profiler_gui/graphics_scrollbar.cpp
Normal file
139
profiler_gui/graphics_scrollbar.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/************************************************************************
|
||||
* file name : graphics_scrollbar.cpp
|
||||
* ----------------- :
|
||||
* creation time : 2016/07/04
|
||||
* copyright : (c) 2016 Victor Zarubkin
|
||||
* author : Victor Zarubkin
|
||||
* email : v.s.zarubkin@gmail.com
|
||||
* ----------------- :
|
||||
* description : .
|
||||
* ----------------- :
|
||||
* change log : * 2016/07/04 Victor Zarubkin: Initial commit.
|
||||
* :
|
||||
* : *
|
||||
* ----------------- :
|
||||
* license : TODO: add license text
|
||||
************************************************************************/
|
||||
|
||||
#include <QScrollBar>
|
||||
#include "graphics_scrollbar.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
auto const clamp = [](double _minValue, double _value, double _maxValue)
|
||||
{
|
||||
return (_value < _minValue ? _minValue : (_value > _maxValue ? _maxValue : _value));
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GraphicsHorizontalSlider::GraphicsHorizontalSlider() : Parent(), m_halfwidth(0)
|
||||
{
|
||||
setWidth(40);
|
||||
setBrush(Qt::SolidPattern);
|
||||
}
|
||||
|
||||
GraphicsHorizontalSlider::~GraphicsHorizontalSlider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double GraphicsHorizontalSlider::width() const
|
||||
{
|
||||
return m_halfwidth * 2.0;
|
||||
}
|
||||
|
||||
double GraphicsHorizontalSlider::halfwidth() const
|
||||
{
|
||||
return m_halfwidth;
|
||||
}
|
||||
|
||||
void GraphicsHorizontalSlider::setWidth(double _width)
|
||||
{
|
||||
m_halfwidth = _width * 0.5;
|
||||
setPolygon(QRectF(-m_halfwidth, -10, _width, 20));
|
||||
}
|
||||
|
||||
void GraphicsHorizontalSlider::setHalfwidth(double _halfwidth)
|
||||
{
|
||||
m_halfwidth = _halfwidth;
|
||||
setPolygon(QRectF(-m_halfwidth, -10, m_halfwidth * 2.0, 20));
|
||||
}
|
||||
|
||||
void GraphicsHorizontalSlider::setColor(QRgb _color)
|
||||
{
|
||||
auto b = brush();
|
||||
b.setColor(_color);
|
||||
setBrush(b);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GraphicsHorizontalScrollbar::GraphicsHorizontalScrollbar(QWidget* _parent)
|
||||
: Parent(_parent)
|
||||
, m_minimumValue(0)
|
||||
, m_maximumValue(500)
|
||||
, m_value(10)
|
||||
, m_slider(nullptr)
|
||||
{
|
||||
setCacheMode(QGraphicsView::CacheNone);
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||
setOptimizationFlag(QGraphicsView::DontSavePainterState, true);
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
setMinimumHeight(20);
|
||||
setMaximumHeight(20);
|
||||
|
||||
auto selfScene = new QGraphicsScene(this);
|
||||
selfScene->setSceneRect(0, -10, 500, 20);
|
||||
setScene(selfScene);
|
||||
|
||||
m_slider = new GraphicsHorizontalSlider();
|
||||
m_slider->setPos(10, 0);
|
||||
m_slider->setColor(0xffff0404);
|
||||
selfScene->addItem(m_slider);
|
||||
|
||||
centerOn(10, 0);
|
||||
}
|
||||
|
||||
GraphicsHorizontalScrollbar::~GraphicsHorizontalScrollbar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
double GraphicsHorizontalScrollbar::minimum() const
|
||||
{
|
||||
return m_minimumValue;
|
||||
}
|
||||
|
||||
double GraphicsHorizontalScrollbar::maximum() const
|
||||
{
|
||||
return m_maximumValue;
|
||||
}
|
||||
|
||||
double GraphicsHorizontalScrollbar::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GraphicsHorizontalScrollbar::setValue(double _value)
|
||||
{
|
||||
m_value = clamp(m_minimumValue + m_slider->halfwidth(), _value, m_maximumValue - m_slider->halfwidth());
|
||||
emit valueChanged(m_value);
|
||||
}
|
||||
|
||||
void GraphicsHorizontalScrollbar::setRange(double _minValue, double _maxValue)
|
||||
{
|
||||
m_minimumValue = _minValue;
|
||||
m_maximumValue = _maxValue;
|
||||
setValue(m_value);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
86
profiler_gui/graphics_scrollbar.h
Normal file
86
profiler_gui/graphics_scrollbar.h
Normal file
@ -0,0 +1,86 @@
|
||||
/************************************************************************
|
||||
* file name : graphics_scrollbar.h
|
||||
* ----------------- :
|
||||
* creation time : 2016/07/04
|
||||
* copyright : (c) 2016 Victor Zarubkin
|
||||
* author : Victor Zarubkin
|
||||
* email : v.s.zarubkin@gmail.com
|
||||
* ----------------- :
|
||||
* description : .
|
||||
* ----------------- :
|
||||
* change log : * 2016/07/04 Victor Zarubkin: Initial commit.
|
||||
* :
|
||||
* : *
|
||||
* ----------------- :
|
||||
* license : TODO: add license text
|
||||
************************************************************************/
|
||||
|
||||
#ifndef EASY_PROFILER__GRAPHICS_SCROLLBAR__H
|
||||
#define EASY_PROFILER__GRAPHICS_SCROLLBAR__H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsPolygonItem>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GraphicsHorizontalSlider : public QGraphicsPolygonItem
|
||||
{
|
||||
typedef QGraphicsPolygonItem Parent;
|
||||
typedef GraphicsHorizontalSlider This;
|
||||
|
||||
private:
|
||||
|
||||
double m_halfwidth;
|
||||
|
||||
public:
|
||||
|
||||
GraphicsHorizontalSlider();
|
||||
virtual ~GraphicsHorizontalSlider();
|
||||
|
||||
double width() const;
|
||||
double halfwidth() const;
|
||||
|
||||
void setWidth(double _width);
|
||||
void setHalfwidth(double _halfwidth);
|
||||
|
||||
void setColor(QRgb _color);
|
||||
|
||||
}; // END of class GraphicsHorizontalSlider.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GraphicsHorizontalScrollbar : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
typedef QGraphicsView Parent;
|
||||
typedef GraphicsHorizontalScrollbar This;
|
||||
|
||||
double m_minimumValue, m_maximumValue, m_value;
|
||||
GraphicsHorizontalSlider* m_slider;
|
||||
|
||||
public:
|
||||
|
||||
GraphicsHorizontalScrollbar(QWidget* _parent = nullptr);
|
||||
virtual ~GraphicsHorizontalScrollbar();
|
||||
|
||||
double minimum() const;
|
||||
double maximum() const;
|
||||
double value() const;
|
||||
|
||||
void setValue(double _value);
|
||||
void setRange(double _minValue, double _maxValue);
|
||||
|
||||
signals:
|
||||
|
||||
void valueChanged(double _value) const;
|
||||
|
||||
}; // END of class GraphicsHorizontalScrollbar.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // EASY_PROFILER__GRAPHICS_SCROLLBAR__H
|
@ -28,6 +28,7 @@
|
||||
#include "main_window.h"
|
||||
#include "blocks_tree_widget.h"
|
||||
#include "blocks_graphics_view.h"
|
||||
//#include "graphics_scrollbar.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -52,7 +53,14 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
|
||||
m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||
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, dock);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
|
||||
|
||||
auto actionOpen = new QAction("Open", nullptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user