00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kivio_custom_drag_data.h"
00020 #include "kivio_fill_style.h"
00021 #include "kivio_intra_stencil_data.h"
00022 #include "kivio_painter.h"
00023 #include "kivio_stencil.h"
00024
00025 #include <KoZoomHandler.h>
00026 #include <KoRect.h>
00027 #include <KIvioStencilIface.h>
00028
00029 KivioStencil::KivioStencil()
00030 : m_pSpawner(NULL),
00031 m_pProtection(NULL),
00032 m_pCanProtect(NULL)
00033 {
00034 m_x = m_y = 0.0f;
00035 m_w = m_h = 72.0f;
00036
00037 m_rotation = 0;
00038
00039 m_hidden = false;
00040
00041 m_selected = false;
00042
00043 m_pProtection = new QBitArray(NUM_PROTECTIONS);
00044 m_pCanProtect = new QBitArray(NUM_PROTECTIONS);
00045
00046 for( int i = 0; i < NUM_PROTECTIONS; i++ )
00047 {
00048 m_pProtection->clearBit(i);
00049 m_pCanProtect->setBit(i);
00050 }
00051
00052 m_type = kstNormal;
00053 m_connected = false;
00054
00055 iface = new KivioStencilIface(this);
00056 }
00057
00058 KivioStencil::~KivioStencil()
00059 {
00060 kdDebug(43000)<<" KivioStencil::~KivioStencil() !"<<this<<endl;
00061 delete m_pProtection;
00062 m_pProtection = NULL;
00063 delete m_pCanProtect;
00064 m_pCanProtect = NULL;
00065
00066
00067 m_pSpawner = NULL;
00068 }
00069
00070 KoRect KivioStencil::rect()
00071 {
00072 return KoRect( m_x, m_y, m_w, m_h );
00073 }
00074
00075
00076 bool KivioStencil::loadXML( const QDomElement & )
00077 {
00078 return false;
00079 }
00080
00081 QDomElement KivioStencil::saveXML( QDomDocument &doc )
00082 {
00083 return doc.createElement("");
00084 }
00085
00086 void KivioStencil::paint( KivioIntraStencilData * )
00087 {
00088 }
00089
00090
00091
00092
00093 void KivioStencil::paintOutline( KivioIntraStencilData * )
00094 {
00095 }
00096
00097 void KivioStencil::paintConnectorTargets( KivioIntraStencilData * )
00098 {
00099 }
00100
00101 void KivioStencil::paintSelectionHandles( KivioIntraStencilData *pData )
00102 {
00103 int newX, newY, newW, newH;
00104
00105
00106
00107
00108
00109
00110
00111
00112 KoZoomHandler* zoomHandler = pData->zoomHandler;
00113
00114 KivioPainter *painter = pData->painter;
00115
00116 newX = zoomHandler->zoomItX(m_x - qRound(lineWidth() / 2));
00117 newY = zoomHandler->zoomItY(m_y - qRound(lineWidth() / 2));
00118 newW = zoomHandler->zoomItX(m_w + lineWidth() + 1);
00119 newH = zoomHandler->zoomItY(m_h + lineWidth() + 1);
00120
00121 painter->saveState();
00122 painter->setTranslation(newX, newY);
00123 rotatePainter(pData);
00124
00125 painter->drawSelectionBox(QRect(0, 0, newW, newH));
00126
00127
00128 if( m_pProtection->at( kpWidth ) ||
00129 m_pProtection->at( kpHeight ) )
00130 {
00131 painter->drawHandle( 0, 0, KivioPainter::cpfLock );
00132 painter->drawHandle( newW, 0, KivioPainter::cpfLock );
00133 painter->drawHandle( 0, newH, KivioPainter::cpfLock );
00134 painter->drawHandle( newW, newH, KivioPainter::cpfLock );
00135 }
00136 else
00137 {
00138 painter->drawHandle( 0, 0, 0 );
00139 painter->drawHandle( newW, 0, 0 );
00140 painter->drawHandle( 0, newH, 0 );
00141 painter->drawHandle( newW, newH, 0 );
00142 }
00143
00144
00145 if( m_pProtection->at( kpHeight ) ||
00146 m_pProtection->at( kpAspect ) )
00147 {
00148 painter->drawHandle( newW / 2, 0, KivioPainter::cpfLock );
00149 painter->drawHandle( newW / 2, newH, KivioPainter::cpfLock );
00150 }
00151 else
00152 {
00153 painter->drawHandle( newW / 2, 0, 0 );
00154 painter->drawHandle( newW / 2, newH, 0 );
00155 }
00156
00157
00158 if( m_pProtection->at( kpWidth ) ||
00159 m_pProtection->at( kpAspect ) )
00160 {
00161 painter->drawHandle( 0, newH / 2, KivioPainter::cpfLock );
00162 painter->drawHandle( newW, newH / 2, KivioPainter::cpfLock );
00163 }
00164 else
00165 {
00166 painter->drawHandle( 0, newH / 2, 0 );
00167 painter->drawHandle( newW, newH / 2, 0 );
00168 }
00169 painter->restoreState();
00170 }
00171
00172 KivioCollisionType KivioStencil::checkForCollision( KoPoint *, double )
00173 {
00174 return kctNone;
00175 }
00176
00177 void KivioStencil::addToGroup( KivioStencil * )
00178 {
00179
00180 }
00181
00182 void KivioStencil::customDrag( KivioCustomDragData * )
00183 {
00184 }
00185
00186 void KivioStencil::updateGeometry()
00187 {
00188 }
00189
00190 KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, double )
00191 {
00192 return NULL;
00193 }
00194
00195 KivioConnectorTarget *KivioStencil::connectToTarget( KivioConnectorPoint *, int )
00196 {
00197 return NULL;
00198 }
00199
00200 KoPoint KivioStencil::snapToTarget( const KoPoint& p, double , bool& hit )
00201 {
00202 KoPoint retVal = p;
00203 hit = false;
00204 return retVal;
00205 }
00206
00207 int KivioStencil::generateIds(int nextAvailable)
00208 {
00209 return nextAvailable;
00210 }
00211
00212 void KivioStencil::searchForConnections( KivioPage * )
00213 {
00214 }
00215
00216 void KivioStencil::searchForConnections( KivioPage *, double )
00217 {
00218 }
00219
00220 void KivioStencil::updateConnectorPoints(KivioConnectorPoint *, double, double)
00221 {
00222
00223 updateGeometry();
00224 }
00225
00226 void KivioStencil::rotatePainter(KivioIntraStencilData *pData)
00227 {
00228 if(m_rotation != 0) {
00229 QWMatrix m;
00230 m.translate(pData->zoomHandler->zoomItX(m_pinPoint.x()), pData->zoomHandler->zoomItY(m_pinPoint.y()));
00231 m.rotate(m_rotation);
00232 m.translate(pData->zoomHandler->zoomItX(-m_pinPoint.x()), pData->zoomHandler->zoomItY(-m_pinPoint.y()));
00233 pData->painter->setWorldMatrix(m, true);
00234 }
00235 }
00236
00237 KoRect KivioStencil::calculateBoundingBox()
00238 {
00239 KoRect r;
00240 return r;
00241 }
00242
00243 void KivioStencil::setRotation(int d)
00244 {
00245 m_rotation = d;
00246 m_pinPoint.setCoords(m_w / 2.0, m_h / 2.0);
00247 updateGeometry();
00248 }
00249
00250 void KivioStencil::move(double xOffset, double yOffset)
00251 {
00252 setX(x() + xOffset);
00253 setY(y() + yOffset);
00254 }
00255
00256 bool KivioStencil::isInRect(const KoRect& rect)
00257 {
00258 bool retVal;
00259 retVal = rect.contains(m_x, m_y);
00260 retVal = retVal && rect.contains(m_x + m_w, m_y + m_h);
00261
00262 return retVal;
00263 }