00001
00023 #ifndef GRAPHIC_ITEMS_H
00024 #define GRAPHIC_ITEMS_H
00025
00026 #include <QtGui>
00027
00028 #include "module_interface.h"
00029
00030 class GraphicFactory : public ModuleFactory
00031 {
00032 public:
00033 GraphicFactory() : ModuleFactory("graphics", "Standard Graphic Items") {};
00034 void init();
00035 inline ModulType type() { return ModuleFactory::NoPlugin; }
00036 ModuleInterface* create(const QString&);
00037 };
00038
00039 class GraphicItem : public PluginInterface, public QGraphicsItem
00040 {
00041 Q_OBJECT
00042 Q_PROPERTY(QPointF pos READ pos WRITE setPos)
00043 Q_PROPERTY(qreal zvalue READ zValue WRITE setZValue)
00044 Q_PROPERTY(qreal rotate READ rotate WRITE setRotate)
00045 Q_PROPERTY(qreal scale READ scale WRITE setScale)
00046 Q_PROPERTY(qreal shear READ shear WRITE setShear)
00047
00048 private slots:
00049 void updateTimeline(qreal);
00050 void forwards();
00051 void front();
00052 void backwards();
00053 void back();
00054
00055 public:
00056 GraphicItem();
00057 bool init();
00058
00059 void setRotate(qreal);
00060 void setScale(qreal);
00061 void setShear(qreal);
00062
00063 inline QMenu* contextMenu() { return &m_contextMenu; }
00064 inline qreal rotate() { return m_rotation; }
00065 inline qreal scale() { return m_scale; }
00066 inline qreal shear() { return m_shear; }
00067
00068 protected:
00069 void drawDecoration(QPainter*, const QRectF&, const QStyleOptionGraphicsItem*);
00070 QRectF calcBoundingRect(const QRectF&) const;
00071
00072 void mousePressEvent(QGraphicsSceneMouseEvent*);
00073 void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
00074 void mouseMoveEvent(QGraphicsSceneMouseEvent*);
00075 void hoverMoveEvent(QGraphicsSceneHoverEvent*);
00076
00077 private:
00078 enum Segment { NoSegment, TopLeftSegment, TopRightSegment, BottomLeftSegment, BottomRightSegment, NumSegments };
00079 QRectF rectForSegment(Segment) const;
00080 bool isPointInSegment(const QPointF&, Segment);
00081
00082 QMenu m_contextMenu;
00083 const QSizeF segmentSize;
00084 QRectF m_boundingRect;
00085 bool m_grabbed;
00086 qreal m_opacity;
00087 qreal m_rotation;
00088 qreal m_newRotation;
00089 qreal m_scale;
00090 qreal m_newScale;
00091 qreal m_shear;
00092 QTimeLine m_timeline;
00093 };
00094
00095 class GraphicStandardItem : public GraphicItem
00096 {
00097 Q_OBJECT
00098 Q_PROPERTY(QPen pen READ pen WRITE setPen)
00099 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
00100
00101 public:
00102 bool init();
00103 inline void setBrush(const QBrush& brush){ m_brush = brush; }
00104 inline void setPen(const QPen& pen) { m_pen = pen; }
00105
00106 inline QBrush brush() const { return m_brush; }
00107 inline QPen pen() const { return m_pen; }
00108
00109 private:
00110 QPen m_pen;
00111 QBrush m_brush;
00112 };
00113
00114 class GraphicLine : public GraphicStandardItem
00115 {
00116 Q_OBJECT
00117 Q_PROPERTY(QLineF line READ line WRITE setLine)
00118
00119 public:
00120 bool init();
00121 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00122 QRectF boundingRect() const;
00123 inline QGraphicsItem* graphicsItem(){ return this; }
00124
00125 inline void setLine(const QLineF& line) { prepareGeometryChange(); m_line = line; }
00126 inline QLineF line() const { return m_line; }
00127
00128 private:
00129 QLineF m_line;
00130 };
00131
00132 class GraphicRectangle : public GraphicStandardItem
00133 {
00134 Q_OBJECT
00135 Q_PROPERTY(QRectF rect READ rect WRITE setRect)
00136
00137 public:
00138 bool init();
00139 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00140 QRectF boundingRect() const;
00141 inline QGraphicsItem* graphicsItem(){ return this; }
00142 inline void setRect(const QRectF& rect) { prepareGeometryChange(); m_rect = rect; }
00143 inline QRectF rect() const { return m_rect; }
00144
00145 private:
00146 QRectF m_rect;
00147 };
00148
00149 class GraphicEllipse : public GraphicStandardItem
00150 {
00151 Q_OBJECT
00152 Q_PROPERTY(QRectF rect READ rect WRITE setRect)
00153 Q_PROPERTY(int startangle READ startAngle WRITE setStartAngle)
00154 Q_PROPERTY(int spanangle READ spanAngle WRITE setSpanAngle)
00155
00156 public:
00157 bool init();
00158 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00159 QRectF boundingRect() const;
00160 inline QGraphicsItem* graphicsItem(){ return this; }
00161 inline void setRect(const QRectF& rect) { prepareGeometryChange(); m_rect = rect; }
00162 inline void setStartAngle(int startAngle) { m_startAngle = startAngle; }
00163 inline void setSpanAngle(int spanAngle) { m_spanAngle = spanAngle; }
00164
00165 inline QRectF rect() const { return m_rect; }
00166 inline int startAngle() { return m_startAngle; }
00167 inline int spanAngle() { return m_spanAngle; }
00168
00169 private:
00170 QRectF m_rect;
00171 int m_startAngle;
00172 int m_spanAngle;
00173 };
00174
00175 class GraphicPolygon : public GraphicStandardItem
00176 {
00177 Q_OBJECT
00178 Q_PROPERTY(QPolygon polygon READ polygon WRITE setPolygon)
00179
00180 public:
00181 bool init();
00182 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00183 QRectF boundingRect() const;
00184 inline QGraphicsItem* graphicsItem(){ return this; }
00185 inline void setPolygon(const QPolygon& polygon) { prepareGeometryChange(); m_polygon = polygon; }
00186 inline QPolygon polygon() const { return m_polygon; }
00187 void addPoint(const QPoint&);
00188
00189 private:
00190 QPolygon m_polygon;
00191
00192 };
00193
00194 class GraphicPixmap : public GraphicItem
00195 {
00196 Q_OBJECT
00197 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
00198 Q_PROPERTY(QSize size READ size WRITE setSize)
00199 Q_PROPERTY(bool invert READ invert WRITE setInvert)
00200 Q_PROPERTY(DitherStatus dither READ dither WRITE setDither)
00201 Q_PROPERTY(RatioStatus ratio READ ratio WRITE setRatio)
00202 Q_ENUMS(DitherStatus)
00203 Q_ENUMS(RatioStatus)
00204
00205 public:
00206 enum DitherStatus { DiffuseDither, OrderedDither, ThresholdDither };
00207 enum RatioStatus { IgnoreAspectRatio, KeepAspectRatio, KeepAspectRatioByExpanding };
00208 bool init();
00209 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00210 QRectF boundingRect() const;
00211 inline QGraphicsItem* graphicsItem(){ return this; }
00212 void setPixmap(const QPixmap&);
00213 void setSize(const QSize&);
00214 void setInvert(bool);
00215 void setDither(DitherStatus);
00216 void setRatio(RatioStatus);
00217 void setPath(const QString&);
00218 inline QPixmap pixmap() const { return m_pixmap; }
00219 inline QString path() const { return m_path; }
00220 inline QSize size() const { return m_size; }
00221 inline bool invert() { return m_invert; }
00222 inline DitherStatus dither() { return m_dither; }
00223 inline RatioStatus ratio() { return m_ratio; }
00224
00225 private:
00226 void updatePixmap();
00227
00228 DitherStatus m_dither;
00229 RatioStatus m_ratio;
00230 QPixmap m_pixmap;
00231 QPixmap m_tmpPixmap;
00232 QSize m_size;
00233 QString m_path;
00234 bool m_invert;
00235 };
00236
00237 class GraphicText : public GraphicItem
00238 {
00239 Q_OBJECT
00240 Q_PROPERTY(QString text READ text WRITE setText)
00241 Q_PROPERTY(qreal textwidth READ textWidth WRITE setTextWidth)
00242 Q_PROPERTY(QFont font READ font WRITE setFont)
00243 Q_PROPERTY(TextType texttype READ textType WRITE setTextType)
00244 Q_ENUMS(TextType)
00245
00246 public:
00247 enum TextType { PlainText, HtmlText };
00248 bool init();
00249 void paint(QPainter*, const QStyleOptionGraphicsItem* , QWidget* widget = 0);
00250 QRectF boundingRect() const;
00251 inline QGraphicsItem* graphicsItem(){ return this; }
00252 void setText(const QString&);
00253 inline void setFont(const QFont& font) { m_doc.setDefaultFont(font); }
00254 inline void setTextWidth(qreal textwidth) { prepareGeometryChange(); m_doc.setTextWidth(textwidth); }
00255 void setTextType(TextType);
00256
00257 inline QString text() const { return m_text; }
00258 inline QFont font() const { return m_doc.defaultFont(); }
00259 inline qreal textWidth() { return m_doc.textWidth(); }
00260 inline TextType textType() { return m_type; }
00261
00262 private:
00263 QTextDocument m_doc;
00264
00265 QString m_text;
00266 TextType m_type;
00267 };
00268
00269 #endif