00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of the demonstration applications of the Qt Toolkit. 00006 ** 00007 ** This file may be used under the terms of the GNU General Public 00008 ** License version 2.0 as published by the Free Software Foundation 00009 ** and appearing in the file LICENSE.GPL included in the packaging of 00010 ** this file. Please review the following information to ensure GNU 00011 ** General Public Licensing requirements will be met: 00012 ** http://www.trolltech.com/products/qt/opensource.html 00013 ** 00014 ** If you are unsure which license is appropriate for your use, please 00015 ** review the following information: 00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the 00017 ** sales department at sales@trolltech.com. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ****************************************************************************/ 00023 00024 #ifndef PATHSTROKE_H 00025 #define PATHSTROKE_H 00026 00027 #include "arthurwidgets.h" 00028 #include <QtGui> 00029 00030 class PathStrokeRenderer : public ArthurFrame 00031 { 00032 Q_OBJECT 00033 Q_PROPERTY(bool animation READ animation WRITE setAnimation) 00034 Q_PROPERTY(double penWidth READ realPenWidth WRITE setRealPenWidth) 00035 public: 00036 enum PathMode { CurveMode, LineMode }; 00037 00038 PathStrokeRenderer(QWidget *parent); 00039 00040 void paint(QPainter *); 00041 void mousePressEvent(QMouseEvent *e); 00042 void mouseMoveEvent(QMouseEvent *e); 00043 void mouseReleaseEvent(QMouseEvent *e); 00044 void timerEvent(QTimerEvent *e); 00045 00046 QSize sizeHint() const { return QSize(500, 500); } 00047 00048 bool animation() const { return m_timer.isActive(); } 00049 00050 double realPenWidth() const { return m_penWidth; } 00051 void setRealPenWidth(double penWidth) { m_penWidth = penWidth; update(); } 00052 00053 public slots: 00054 void setPenWidth(int penWidth) { m_penWidth = penWidth / 10.0; update(); } 00055 void setAnimation(bool animation); 00056 00057 void setFlatCap() { m_capStyle = Qt::FlatCap; update(); } 00058 void setSquareCap() { m_capStyle = Qt::SquareCap; update(); } 00059 void setRoundCap() { m_capStyle = Qt::RoundCap; update(); } 00060 00061 void setBevelJoin() { m_joinStyle = Qt::BevelJoin; update(); } 00062 void setMiterJoin() { m_joinStyle = Qt::MiterJoin; update(); } 00063 void setRoundJoin() { m_joinStyle = Qt::RoundJoin; update(); } 00064 00065 void setCurveMode() { m_pathMode = CurveMode; update(); } 00066 void setLineMode() { m_pathMode = LineMode; update(); } 00067 00068 void setSolidLine() { m_penStyle = Qt::SolidLine; update(); } 00069 void setDashLine() { m_penStyle = Qt::DashLine; update(); } 00070 void setDotLine() { m_penStyle = Qt::DotLine; update(); } 00071 void setDashDotLine() { m_penStyle = Qt::DashDotLine; update(); } 00072 void setDashDotDotLine() { m_penStyle = Qt::DashDotDotLine; update(); } 00073 void setCustomDashLine() { m_penStyle = Qt::NoPen; update(); } 00074 00075 private: 00076 void initializePoints(); 00077 void updatePoints(); 00078 00079 QBasicTimer m_timer; 00080 00081 PathMode m_pathMode; 00082 00083 bool m_wasAnimated; 00084 00085 double m_penWidth; 00086 int m_pointCount; 00087 int m_pointSize; 00088 int m_activePoint; 00089 QVector<QPointF> m_points; 00090 QVector<QPointF> m_vectors; 00091 00092 Qt::PenJoinStyle m_joinStyle; 00093 Qt::PenCapStyle m_capStyle; 00094 00095 Qt::PenStyle m_penStyle; 00096 }; 00097 00098 class PathStrokeWidget : public QWidget 00099 { 00100 Q_OBJECT 00101 public: 00102 PathStrokeWidget(); 00103 00104 private: 00105 PathStrokeRenderer *m_renderer; 00106 }; 00107 00108 #endif // PATHSTROKE_H
1.5.1