easy_chronometer_item.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /************************************************************************
  2. * file name : easy_chronometer_item.h
  3. * ----------------- :
  4. * creation time : 2016/09/15
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of EasyChronometerItem - an item
  9. * : used to display selected interval on graphics scene.
  10. * ----------------- :
  11. * change log : * 2016/09/15 Victor Zarubkin: moved sources from blocks_graphics_view.h
  12. * :
  13. * : *
  14. * ----------------- :
  15. * license : Lightweight profiler library for c++
  16. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  17. * :
  18. * : Licensed under either of
  19. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  20. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  21. * : at your option.
  22. * :
  23. * : The MIT License
  24. * :
  25. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  26. * : of this software and associated documentation files (the "Software"), to deal
  27. * : in the Software without restriction, including without limitation the rights
  28. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  29. * : of the Software, and to permit persons to whom the Software is furnished
  30. * : to do so, subject to the following conditions:
  31. * :
  32. * : The above copyright notice and this permission notice shall be included in all
  33. * : copies or substantial portions of the Software.
  34. * :
  35. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  36. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  37. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  38. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  39. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  40. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  41. * :
  42. * : The Apache License, Version 2.0 (the "License")
  43. * :
  44. * : You may not use this file except in compliance with the License.
  45. * : You may obtain a copy of the License at
  46. * :
  47. * : http://www.apache.org/licenses/LICENSE-2.0
  48. * :
  49. * : Unless required by applicable law or agreed to in writing, software
  50. * : distributed under the License is distributed on an "AS IS" BASIS,
  51. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  52. * : See the License for the specific language governing permissions and
  53. * : limitations under the License.
  54. ************************************************************************/
  55. #ifndef EASY_CHRONOMETER_ITEM_H
  56. #define EASY_CHRONOMETER_ITEM_H
  57. #include <QGraphicsItem>
  58. #include <QRectF>
  59. #include <QPolygonF>
  60. #include <QColor>
  61. //////////////////////////////////////////////////////////////////////////
  62. //////////////////////////////////////////////////////////////////////////
  63. class QWidget;
  64. class QPainter;
  65. class QStyleOptionGraphicsItem;
  66. class EasyGraphicsView;
  67. class EasyChronometerItem : public QGraphicsItem
  68. {
  69. typedef QGraphicsItem Parent;
  70. typedef EasyChronometerItem This;
  71. QPolygonF m_indicator; ///< Indicator displayed when this chrono item is out of screen (displaying only for main item)
  72. QRectF m_boundingRect; ///< boundingRect (see QGraphicsItem)
  73. QColor m_color; ///< Color of the item
  74. qreal m_left, m_right; ///< Left and right bounds of the selection zone
  75. bool m_bMain; ///< Is this chronometer main (true, by default)
  76. bool m_bReverse; ///<
  77. bool m_bHoverIndicator; ///< Mouse hover above indicator
  78. bool m_bHoverLeftBorder;
  79. bool m_bHoverRightBorder;
  80. public:
  81. explicit EasyChronometerItem(bool _main = true);
  82. virtual ~EasyChronometerItem();
  83. // Public virtual methods
  84. QRectF boundingRect() const override;
  85. void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
  86. public:
  87. // Public non-virtual methods
  88. void hide();
  89. void setColor(const QColor& _color);
  90. void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
  91. void setBoundingRect(const QRectF& _rect);
  92. void setLeftRight(qreal _left, qreal _right);
  93. void setReverse(bool _reverse);
  94. void setHoverIndicator(bool _hover);
  95. bool indicatorContains(const QPointF& _pos) const;
  96. void setHoverLeft(bool _hover);
  97. void setHoverRight(bool _hover);
  98. bool hoverLeft(qreal _x) const;
  99. bool hoverRight(qreal _x) const;
  100. QPointF toItem(const QPointF& _pos) const;
  101. qreal toItem(qreal _x) const;
  102. inline bool hoverIndicator() const
  103. {
  104. return m_bHoverIndicator;
  105. }
  106. inline bool hoverLeft() const
  107. {
  108. return m_bHoverLeftBorder;
  109. }
  110. inline bool hoverRight() const
  111. {
  112. return m_bHoverRightBorder;
  113. }
  114. inline bool reverse() const
  115. {
  116. return m_bReverse;
  117. }
  118. inline qreal left() const
  119. {
  120. return m_left;
  121. }
  122. inline qreal right() const
  123. {
  124. return m_right;
  125. }
  126. inline qreal width() const
  127. {
  128. return m_right - m_left;
  129. }
  130. private:
  131. ///< Returns pointer to the EasyGraphicsView widget.
  132. const EasyGraphicsView* view() const;
  133. EasyGraphicsView* view();
  134. }; // END of class EasyChronometerItem.
  135. //////////////////////////////////////////////////////////////////////////
  136. //////////////////////////////////////////////////////////////////////////
  137. #endif // EASY_CHRONOMETER_ITEM_H