/demos/deform/pathdeform.h

https://bitbucket.org/ultra_iter/qt-vtl
C Header | 153 lines | 87 code | 23 blank | 43 comment | 0 complexity | c58750b3df29e49be56327f3cbcf5db7 MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the demonstration applications of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #ifndef PATHDEFORM_H
  42. #define PATHDEFORM_H
  43. #include "arthurwidgets.h"
  44. #include <QPainterPath>
  45. #include <QBasicTimer>
  46. #include <QDateTime>
  47. class PathDeformRenderer : public ArthurFrame
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(bool animated READ animated WRITE setAnimated)
  51. Q_PROPERTY(int radius READ radius WRITE setRadius)
  52. Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize)
  53. Q_PROPERTY(int intensity READ intensity WRITE setIntensity)
  54. Q_PROPERTY(QString text READ text WRITE setText)
  55. public:
  56. PathDeformRenderer(QWidget *widget, bool smallScreen = false);
  57. void paint(QPainter *painter);
  58. void mousePressEvent(QMouseEvent *e);
  59. void mouseReleaseEvent(QMouseEvent *e);
  60. void mouseMoveEvent(QMouseEvent *e);
  61. void timerEvent(QTimerEvent *e);
  62. QSize sizeHint() const { return QSize(600, 500); }
  63. bool animated() const { return m_animated; }
  64. int radius() const { return int(m_radius); }
  65. int fontSize() const { return m_fontSize; }
  66. int intensity() const { return int(m_intensity); }
  67. QString text() const { return m_text; }
  68. public slots:
  69. void setRadius(int radius);
  70. void setFontSize(int fontSize) { m_fontSize = fontSize; setText(m_text); }
  71. void setText(const QString &text);
  72. void setIntensity(int intensity);
  73. void setAnimated(bool animated);
  74. signals:
  75. void clicked();
  76. // void frameRate(double fps);
  77. private:
  78. void generateLensPixmap();
  79. QPainterPath lensDeform(const QPainterPath &source, const QPointF &offset);
  80. QBasicTimer m_repaintTimer;
  81. // QBasicTimer m_fpsTimer;
  82. // int m_fpsCounter;
  83. QTime m_repaintTracker;
  84. QVector<QPainterPath> m_paths;
  85. QVector<QPointF> m_advances;
  86. QRectF m_pathBounds;
  87. QString m_text;
  88. QPixmap m_lens_pixmap;
  89. QImage m_lens_image;
  90. int m_fontSize;
  91. bool m_animated;
  92. qreal m_intensity;
  93. qreal m_radius;
  94. QPointF m_pos;
  95. QPointF m_offset;
  96. QPointF m_direction;
  97. QPointF m_mousePress;
  98. bool m_mouseDrag;
  99. bool m_smallScreen;
  100. };
  101. class PathDeformControls : public QWidget
  102. {
  103. Q_OBJECT
  104. public:
  105. PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen);
  106. signals:
  107. void okPressed();
  108. void quitPressed();
  109. private:
  110. PathDeformRenderer* m_renderer;
  111. void layoutForDesktop();
  112. void layoutForSmallScreen();
  113. private slots:
  114. void emitQuitSignal();
  115. void emitOkSignal();
  116. };
  117. class PathDeformWidget : public QWidget
  118. {
  119. Q_OBJECT
  120. public:
  121. PathDeformWidget(QWidget *parent, bool smallScreen);
  122. void setStyle ( QStyle * style );
  123. private:
  124. PathDeformRenderer *m_renderer;
  125. PathDeformControls *m_controls;
  126. private slots:
  127. void showControls();
  128. void hideControls();
  129. };
  130. #endif // PATHDEFORM_H