2016-07-10 01:29:09 +03:00
|
|
|
/************************************************************************
|
2016-09-15 22:30:32 +03:00
|
|
|
* file name : easy_graphics_scrollbar.h
|
2016-07-10 01:29:09 +03:00
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/07/04
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
2016-09-06 21:49:32 +03:00
|
|
|
* description : This file contains declaration of
|
2016-07-10 01:29:09 +03:00
|
|
|
* ----------------- :
|
|
|
|
* 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
|
|
|
|
* :
|
2016-11-13 16:39:59 +03:00
|
|
|
* :
|
|
|
|
* : Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* : you may not use this file except in compliance with the License.
|
|
|
|
* : You may obtain a copy of the License at
|
|
|
|
* :
|
|
|
|
* : http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* :
|
|
|
|
* : Unless required by applicable law or agreed to in writing, software
|
|
|
|
* : distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* : See the License for the specific language governing permissions and
|
|
|
|
* : limitations under the License.
|
|
|
|
* :
|
|
|
|
* :
|
|
|
|
* : GNU General Public License Usage
|
|
|
|
* : Alternatively, this file may be used 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.
|
2016-09-06 21:49:32 +03:00
|
|
|
* :
|
|
|
|
* : 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-08-18 23:26:41 +03:00
|
|
|
#ifndef EASY__GRAPHICS_SCROLLBAR__H
|
|
|
|
#define EASY__GRAPHICS_SCROLLBAR__H
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2016-12-04 16:51:27 +03:00
|
|
|
#include <thread>
|
|
|
|
#include <atomic>
|
2016-07-10 01:29:09 +03:00
|
|
|
#include <QGraphicsView>
|
2016-07-31 13:13:48 +03:00
|
|
|
#include <QGraphicsRectItem>
|
2016-08-03 23:00:04 +03:00
|
|
|
#include <QAction>
|
2016-08-23 22:44:59 +03:00
|
|
|
#include <QPolygonF>
|
2016-12-04 16:51:27 +03:00
|
|
|
#include <QImage>
|
|
|
|
#include "easy_qtimer.h"
|
2016-08-03 00:06:36 +03:00
|
|
|
#include "common_types.h"
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
// TODO: use profiler_core/spin_lock.h
|
|
|
|
|
|
|
|
#define EASY_GUI_USE_CRITICAL_SECTION // Use CRITICAL_SECTION instead of std::atomic_flag
|
|
|
|
#if defined(_WIN32) && defined(EASY_GUI_USE_CRITICAL_SECTION)
|
|
|
|
namespace profiler_gui {
|
|
|
|
// std::atomic_flag on Windows works slower than critical section, so we will use it instead of std::atomic_flag...
|
|
|
|
// By the way, Windows critical sections are slower than std::atomic_flag on Unix.
|
|
|
|
class spin_lock { void* m_lock; public:
|
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
spin_lock();
|
|
|
|
~spin_lock();
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
namespace profiler_gui {
|
|
|
|
// std::atomic_flag on Unix works fine and very fast (almost instant!)
|
|
|
|
class spin_lock {
|
|
|
|
::std::atomic_flag m_lock; public:
|
|
|
|
|
|
|
|
void lock() {
|
|
|
|
while (m_lock.test_and_set(::std::memory_order_acquire));
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlock() {
|
|
|
|
m_lock.clear(::std::memory_order_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock() {
|
|
|
|
m_lock.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // END of namespace profiler_gui.
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
class EasyGraphicsSliderItem : public QGraphicsRectItem
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
2016-08-03 23:00:04 +03:00
|
|
|
typedef QGraphicsRectItem Parent;
|
2016-08-18 23:26:41 +03:00
|
|
|
typedef EasyGraphicsSliderItem This;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-08-23 22:44:59 +03:00
|
|
|
QPolygonF m_indicator;
|
2016-07-31 13:13:48 +03:00
|
|
|
qreal m_halfwidth;
|
2016-08-23 22:44:59 +03:00
|
|
|
bool m_bMain;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-08-19 00:35:05 +03:00
|
|
|
explicit EasyGraphicsSliderItem(bool _main);
|
2016-08-18 23:26:41 +03:00
|
|
|
virtual ~EasyGraphicsSliderItem();
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
qreal width() const;
|
|
|
|
qreal halfwidth() const;
|
|
|
|
|
|
|
|
void setWidth(qreal _width);
|
|
|
|
void setHalfwidth(qreal _halfwidth);
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
void setColor(QRgb _color);
|
2016-08-06 14:50:31 +03:00
|
|
|
void setColor(const QColor& _color);
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
}; // END of class EasyGraphicsSliderItem.
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
class EasyHystogramItem : public QGraphicsItem
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
typedef QGraphicsItem Parent;
|
2016-12-04 16:51:27 +03:00
|
|
|
typedef EasyHystogramItem This;
|
|
|
|
|
|
|
|
enum HystRegime : uint8_t { Hyst_Pointer, Hyst_Id };
|
|
|
|
|
|
|
|
QRectF m_boundingRect;
|
|
|
|
qreal m_maxDuration;
|
|
|
|
qreal m_minDuration;
|
|
|
|
QString m_maxDurationStr;
|
|
|
|
QString m_minDurationStr;
|
|
|
|
QString m_threadName;
|
|
|
|
::profiler::BlocksTree::children_t m_selectedBlocks;
|
|
|
|
QImage m_mainImage;
|
|
|
|
EasyQTimer m_timer;
|
|
|
|
::std::thread m_workerThread;
|
|
|
|
::profiler::timestamp_t m_threadDuration;
|
2016-12-14 22:16:14 +03:00
|
|
|
::profiler::timestamp_t m_threadProfiledTime;
|
|
|
|
::profiler::timestamp_t m_threadWaitTime;
|
2016-12-04 16:51:27 +03:00
|
|
|
const ::profiler_gui::EasyItems* m_pSource;
|
|
|
|
QImage* m_temporaryImage;
|
2016-12-12 22:28:54 +03:00
|
|
|
const ::profiler::BlocksTreeRoot* m_pProfilerThread;
|
2016-12-04 16:51:27 +03:00
|
|
|
::profiler::thread_id_t m_threadId;
|
|
|
|
::profiler::block_index_t m_blockId;
|
|
|
|
int m_timeouts;
|
|
|
|
::profiler_gui::TimeUnits m_timeUnits;
|
|
|
|
HystRegime m_regime;
|
|
|
|
bool m_bUpdatingImage;
|
|
|
|
::profiler_gui::spin_lock m_spin;
|
|
|
|
::std::atomic_bool m_bReady;
|
2016-08-03 00:06:36 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
explicit EasyHystogramItem();
|
|
|
|
virtual ~EasyHystogramItem();
|
2016-08-03 00:06:36 +03:00
|
|
|
|
|
|
|
// Public virtual methods
|
|
|
|
|
|
|
|
QRectF boundingRect() const override;
|
|
|
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Public non-virtual methods
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler::thread_id_t threadId() const;
|
|
|
|
|
2016-08-03 00:06:36 +03:00
|
|
|
void setBoundingRect(const QRectF& _rect);
|
2016-08-23 22:44:59 +03:00
|
|
|
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
2016-08-03 00:06:36 +03:00
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
void setSource(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems* _items);
|
2016-12-04 16:51:27 +03:00
|
|
|
void setSource(::profiler::thread_id_t _thread_id, ::profiler::block_id_t _block_id);
|
2016-12-14 21:47:33 +03:00
|
|
|
void validateName();
|
2016-12-04 16:51:27 +03:00
|
|
|
void updateImage();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void paintByPtr(QPainter* _painter);
|
|
|
|
void paintById(QPainter* _painter);
|
|
|
|
void onTimeout();
|
|
|
|
void updateImage(HystRegime _regime, qreal _current_scale,
|
|
|
|
qreal _minimum, qreal _maximum, qreal _range,
|
|
|
|
qreal _value, qreal _width, bool _bindMode,
|
|
|
|
float _frame_time, ::profiler::timestamp_t _begin_time);
|
2016-08-03 23:00:04 +03:00
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
}; // END of class EasyHystogramItem.
|
2016-08-03 23:00:04 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
class EasyGraphicsScrollbar : public QGraphicsView
|
2016-07-10 01:29:09 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
typedef QGraphicsView Parent;
|
2016-08-18 23:26:41 +03:00
|
|
|
typedef EasyGraphicsScrollbar This;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
qreal m_minimumValue;
|
|
|
|
qreal m_maximumValue;
|
|
|
|
qreal m_value;
|
|
|
|
qreal m_windowScale;
|
|
|
|
QPoint m_mousePressPos;
|
|
|
|
Qt::MouseButtons m_mouseButtons;
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsSliderItem* m_slider;
|
|
|
|
EasyGraphicsSliderItem* m_chronometerIndicator;
|
2016-12-04 16:51:27 +03:00
|
|
|
EasyHystogramItem* m_hystogramItem;
|
|
|
|
int m_defaultFontHeight;
|
2016-08-03 23:00:04 +03:00
|
|
|
bool m_bScrolling;
|
2016-11-30 22:37:11 +03:00
|
|
|
bool m_bBindMode;
|
2016-12-04 16:51:27 +03:00
|
|
|
bool m_bLocked;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-08-19 00:35:05 +03:00
|
|
|
explicit EasyGraphicsScrollbar(QWidget* _parent = nullptr);
|
2016-08-18 23:26:41 +03:00
|
|
|
virtual ~EasyGraphicsScrollbar();
|
2016-08-03 23:00:04 +03:00
|
|
|
|
|
|
|
// Public virtual methods
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void mousePressEvent(QMouseEvent* _event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent* _event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent* _event) override;
|
2016-08-21 16:48:42 +03:00
|
|
|
void wheelEvent(QWheelEvent* _event) override;
|
2016-07-31 13:13:48 +03:00
|
|
|
void resizeEvent(QResizeEvent* _event) override;
|
2016-11-30 22:37:11 +03:00
|
|
|
//void contextMenuEvent(QContextMenuEvent* _event) override;
|
2016-08-03 23:00:04 +03:00
|
|
|
|
2016-11-19 05:39:41 +03:00
|
|
|
void dragEnterEvent(QDragEnterEvent*) override {}
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Public non-virtual methods
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-09-21 22:09:04 +03:00
|
|
|
void clear();
|
|
|
|
|
2016-11-30 22:37:11 +03:00
|
|
|
bool bindMode() const;
|
2016-07-31 13:13:48 +03:00
|
|
|
qreal getWindowScale() const;
|
2016-12-04 16:51:27 +03:00
|
|
|
::profiler::thread_id_t hystThread() const;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
qreal minimum() const;
|
|
|
|
qreal maximum() const;
|
|
|
|
qreal range() const;
|
|
|
|
qreal value() const;
|
2016-08-08 22:17:56 +03:00
|
|
|
qreal sliderWidth() const;
|
|
|
|
qreal sliderHalfWidth() const;
|
2016-12-04 16:51:27 +03:00
|
|
|
int defaultFontHeight() const;
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void setValue(qreal _value);
|
|
|
|
void setRange(qreal _minValue, qreal _maxValue);
|
|
|
|
void setSliderWidth(qreal _width);
|
2016-08-03 00:06:36 +03:00
|
|
|
void setChronoPos(qreal _left, qreal _right);
|
|
|
|
void showChrono();
|
|
|
|
void hideChrono();
|
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
void setHystogramFrom(::profiler::thread_id_t _thread_id, const::profiler_gui::EasyItems* _items);
|
|
|
|
void setHystogramFrom(::profiler::thread_id_t _thread_id, ::profiler::block_id_t _block_id);
|
|
|
|
|
|
|
|
inline void setHystogramFrom(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems& _items)
|
|
|
|
{
|
|
|
|
setHystogramFrom(_thread_id, &_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void lock()
|
|
|
|
{
|
|
|
|
m_bLocked = true;
|
|
|
|
}
|
2016-08-03 00:06:36 +03:00
|
|
|
|
2016-12-04 16:51:27 +03:00
|
|
|
inline void unlock()
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
2016-12-04 16:51:27 +03:00
|
|
|
m_bLocked = false;
|
2016-08-03 00:06:36 +03:00
|
|
|
}
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void rangeChanged();
|
|
|
|
void valueChanged(qreal _value);
|
2016-08-21 16:48:42 +03:00
|
|
|
void wheeled(qreal _mouseX, int _wheelDelta);
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
private slots:
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-09-06 21:49:32 +03:00
|
|
|
void onThreadActionClicked(bool);
|
2016-07-31 13:13:48 +03:00
|
|
|
void onWindowWidthChange(qreal _width);
|
2016-07-10 01:29:09 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
}; // END of class EasyGraphicsScrollbar.
|
2016-07-10 01:29:09 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
#endif // EASY__GRAPHICS_SCROLLBAR__H
|