00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KIVIO_STENCIL_H
00021 #define KIVIO_STENCIL_H
00022
00023 #include <qfont.h>
00024 #include <qcolor.h>
00025 #include <qdom.h>
00026 #include <qptrlist.h>
00027 #include <qbitarray.h>
00028 #include <KoPoint.h>
00029 #include <kglobalsettings.h>
00030 #include <KoRect.h>
00031 #include <koffice_export.h>
00032
00033 #include "kivio_line_style.h"
00034
00035 class KivioCustomDragData;
00036 class KivioConnectorPoint;
00037 class KivioConnectorTarget;
00038 class KivioFillStyle;
00039 class KivioIntraStencilData;
00040 class KivioPage;
00041 class KoPoint;
00042 class KoRect;
00043 class KivioStencilSpawner;
00044 class KivioStencil;
00045 class KivioStencilIface;
00046
00047
00048 typedef enum
00049 {
00050 kctNone = 0,
00051 kctBody,
00052 kctCustom=500
00053 } KivioCollisionType;
00054
00055 typedef enum
00056 {
00057 kpX = 0,
00058 kpY,
00059 kpWidth,
00060 kpHeight,
00061 kpAspect,
00062 kpDeletion
00063 } KivioProtection;
00064 #define NUM_PROTECTIONS 6
00065
00066 typedef enum
00067 {
00068 krhpNone=0x0000,
00069 krhpNW=0x0001,
00070 krhpN=0x0002,
00071 krhpNE=0x0004,
00072 krhpE=0x0008,
00073 krhpSE=0x0010,
00074 krhpS=0x0020,
00075 krhpSW=0x0040,
00076 krhpW=0x0080,
00077 krhpC=0x0100
00078 } KivioResizeHandlePosition;
00079
00080 typedef enum
00081 {
00082 kstNormal = 0,
00083 kstConnector,
00084 kstGroup,
00085 kstText
00086 } KivioStencilType;
00087
00088 #define KIVIO_RESIZE_HANDLE_POSITION_ALL \
00089 ( krhpNW \
00090 | krhpN \
00091 | krhpNE \
00092 | krhpE \
00093 | krhpSE \
00094 | krhpS \
00095 | krhpSW \
00096 | krhpW \
00097 | krhpC )
00098
00099 #define KIVIO_RESIZE_HANDLE_POSITION_BORDER \
00100 ( krhpNW \
00101 | krhpN \
00102 | krhpNE \
00103 | krhpE \
00104 | krhpSE \
00105 | krhpS \
00106 | krhpSW \
00107 | krhpW )
00108
00109 #define KIVIO_RESIZE_HANDLE_POSITION_CORNERS \
00110 ( krhpNW \
00111 | krhpNE \
00112 | krhpSE \
00113 | krhpSW )
00114
00115
00116
00117 class KIVIO_EXPORT KivioStencil
00118 {
00119 protected:
00120
00121 double m_x, m_y, m_w, m_h;
00122
00123
00124 int m_rotation;
00125 KoPoint m_pinPoint;
00126
00127
00128 KivioStencilSpawner *m_pSpawner;
00129
00130
00131 QBitArray *m_pProtection;
00132 QBitArray *m_pCanProtect;
00133
00134
00135 KivioStencilType m_type;
00136 bool m_connected;
00137
00138
00139 bool m_selected;
00140
00141
00142 bool m_hidden;
00143
00144 protected:
00145 void rotatePainter(KivioIntraStencilData *);
00146 KoRect calculateBoundingBox();
00147
00148 public:
00149 KivioStencil();
00150 virtual ~KivioStencil();
00151
00152 virtual KivioStencil *duplicate() { return NULL; }
00153
00154 virtual KivioStencilType type() { return m_type; }
00155 virtual void setType(KivioStencilType t) { m_type = t; }
00156 virtual bool connected() { return m_connected; }
00157 virtual void setConnected(bool c) { m_connected = c; }
00158
00159 virtual double x() { return m_x; }
00160 virtual void setX( double f ) { m_x=f; updateGeometry(); }
00161
00162 virtual double y() { return m_y; }
00163 virtual void setY( double f ) { m_y=f; updateGeometry(); }
00164
00165 virtual double w() { return m_w; }
00166 virtual void setW( double f ) { if( f > 0 ) { m_w=f; updateGeometry(); } }
00167
00168 virtual double h() { return m_h; }
00169 virtual void setH( double f ) { if( f > 0 ) { m_h=f; updateGeometry(); } }
00170
00171 virtual void move(double xOffset, double yOffset);
00172
00173 virtual KoRect rect();
00174
00175 virtual void setPosition( double f1, double f2 ) { m_x=f1; m_y=f2; updateGeometry(); }
00176 virtual void setDimensions( double f1, double f2 ) { m_w=f1; m_h=f2; updateGeometry(); }
00177
00178 virtual QColor fgColor() { return QColor(0,0,0); }
00179 virtual void setFGColor( QColor ) { ; }
00180
00181 virtual void setBGColor( QColor ) { ; }
00182 virtual QColor bgColor() { return QColor(0,0,0); }
00183 virtual void setFillPattern(int) { ; }
00184 virtual int fillPattern() { return 1; }
00185
00186 virtual KivioFillStyle *fillStyle() { return NULL; }
00187 virtual KivioLineStyle lineStyle() { return KivioLineStyle(); }
00188 virtual void setLineStyle(KivioLineStyle) { ; }
00189
00190 virtual void setLineWidth( double ) { ; }
00191 virtual double lineWidth() { return 1.0f; }
00192
00193 virtual void setLinePattern(int) { ; }
00194 virtual int linePattern() { return 1; }
00195
00196
00197 virtual QColor textColor() { return QColor(0,0,0); }
00198 virtual void setTextColor( QColor ) {;}
00199
00200 virtual QFont textFont() { return KGlobalSettings::generalFont(); }
00201 virtual void setTextFont( const QFont & ) {;}
00202
00203 virtual int hTextAlign() { return -1; }
00204 virtual int vTextAlign() { return -1; }
00205
00206 virtual void setHTextAlign(int) { ; }
00207 virtual void setVTextAlign(int) { ; }
00208
00209 virtual void setText( const QString & ) { ; }
00210 virtual QString text() { return QString(""); }
00211
00212 virtual void setRotation(int d);
00213 virtual int rotation() { return m_rotation; }
00214
00215 virtual KivioStencilSpawner *spawner() { return m_pSpawner; }
00216 virtual void setSpawner( KivioStencilSpawner *s ) { m_pSpawner=s; }
00217
00218 virtual void paint( KivioIntraStencilData * );
00219 virtual void paintOutline( KivioIntraStencilData * );
00220 virtual void paintConnectorTargets( KivioIntraStencilData * );
00221 virtual void paintSelectionHandles( KivioIntraStencilData * );
00222
00223 virtual KivioCollisionType checkForCollision( KoPoint *, double );
00224 virtual void customDrag( KivioCustomDragData * );
00225
00226
00227 virtual bool loadXML( const QDomElement & );
00228 virtual QDomElement saveXML( QDomDocument & );
00229
00230 virtual bool isSelected() { return m_selected; }
00231 virtual void select() { m_selected = true; }
00232 virtual void unselect() { m_selected = false; }
00233 virtual void subSelect( const double &, const double & ) { ; }
00234
00235 virtual QBitArray *protection() { return m_pProtection; }
00236 virtual QBitArray *canProtect() { return m_pCanProtect; }
00237
00238 virtual void addToGroup( KivioStencil * );
00239 virtual QPtrList<KivioStencil>* groupList() { return NULL; }
00240
00241 virtual void updateGeometry();
00242 virtual void updateConnectorPoints(KivioConnectorPoint *, double oldX, double oldY);
00243
00244
00245 virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, double );
00246
00247
00248
00249 virtual KivioConnectorTarget *connectToTarget( KivioConnectorPoint *, int );
00250
00251 virtual KoPoint snapToTarget( const KoPoint& p, double , bool& hit );
00252
00253 virtual void searchForConnections( KivioPage * );
00254 virtual void searchForConnections( KivioPage *pPage, double threshold );
00255
00256 virtual int generateIds( int );
00257
00258 virtual int resizeHandlePositions() { return krhpNone; }
00259
00264 virtual QString getTextBoxName(const KoPoint& ) { return QString::null; }
00265
00266 virtual void setText(const QString& , const QString& ) { ; }
00267 virtual QString text(const QString& ) { return QString(""); }
00268
00270 virtual bool hasTextBox() const { return false; }
00271
00272 virtual QColor textColor(const QString& ) { return QColor(); }
00273 virtual void setTextColor(const QString& , const QColor& ) {}
00274
00275 virtual QFont textFont(const QString& ) { return KGlobalSettings::generalFont(); }
00276 virtual void setTextFont(const QString& , const QFont& ) {}
00277
00278 virtual int hTextAlign(const QString& ) { return -1; }
00279 virtual int vTextAlign(const QString& ) { return -1; }
00280
00281 virtual void setHTextAlign(const QString& , int ) {}
00282 virtual void setVTextAlign(const QString& , int ) {}
00283
00284 virtual void setPinPoint(const KoPoint& p) { m_pinPoint = p; }
00285 virtual KoPoint pinPoint() const { return m_pinPoint; }
00286
00287 virtual void addConnectorTarget(const KoPoint&) {}
00288 virtual void removeConnectorTarget(const KoPoint&) {}
00289
00290 virtual bool isInRect(const KoRect& rect);
00291
00292 virtual void setHidden(bool hide) { m_hidden = hide; }
00293 virtual bool hidden() { return m_hidden; }
00294
00295 virtual void setCustomIDPoint(int, const KoPoint&, KivioPage*) {}
00296 virtual KoPoint customIDPoint(int) { return KoPoint(); }
00297
00298
00299 virtual void setStartAHType( int ) { ; }
00300 virtual void setStartAHWidth( double ) { ; }
00301 virtual void setStartAHLength( double ) { ; }
00302 virtual void setEndAHType( int ) { ; }
00303 virtual void setEndAHWidth( double ) { ; }
00304 virtual void setEndAHLength( double ) { ; }
00305
00306 virtual int startAHType() { return 0; }
00307 virtual double startAHWidth() { return 0.0f; }
00308 virtual double startAHLength() { return 0.0f; }
00309 virtual int endAHType() { return 0; }
00310 virtual double endAHWidth() { return 0.0f; }
00311 virtual double endAHLength() { return 0.0f; }
00312
00313 private:
00314 KivioStencilIface *iface;
00315 };
00316
00317 #endif