402
404
void KivioPyStencil::paint( KivioIntraStencilData *d, bool outlined )
405
float scale = d->scale;
407
PyObject *shapes = PyDict_Values( PyDict_GetItemString( vars, "shapes" ) );
411
int size = PyList_Size( shapes );
413
for ( int i=0; i<size; i++ ) {
414
PyObject *shape = PyList_GetItem( shapes, i );
415
if ( !PyDict_Check(shape) )
418
int fill = KivioFillStyle::kcsNone;
420
// if style dosn't defined for shape, applay default for stencil
421
setStyle( d, PyDict_GetItemString( vars, "style" ) , fill );
422
setStyle( d, shape, fill );
425
setStyle( d, PyDict_GetItemString( shape, "selected" ) , fill );
428
fill = KivioFillStyle::kcsNone;
430
QString stype = getStringFromDict( shape, "type" );
431
stype = stype.lower();
433
double x = getDoubleFromDict(shape,"x")*scale;
434
double y = getDoubleFromDict(shape,"y")*scale;
435
double w = getDoubleFromDict(shape,"w")*scale;
436
double h = getDoubleFromDict(shape,"h")*scale;
437
double x2 = getDoubleFromDict(shape,"x2")*scale;
438
double y2 = getDoubleFromDict(shape,"y2")*scale;
441
QList<KivioPoint> points;
442
points.setAutoDelete(true);
443
PyObject *pyPoints = PyDict_GetItemString( shape, "points" );
444
if ( pyPoints && PyList_Check(pyPoints) ) {
445
int size = PyList_Size(pyPoints);
446
for ( int i=0; i<size; i++ ) {
447
PyObject *pyPoint = PyList_GetItem(pyPoints,i);
448
double x = getDoubleFromDict(pyPoint,"x")*scale;
449
double y = getDoubleFromDict(pyPoint,"y")*scale;
450
points.append( new KivioPoint( x, y, KivioPoint::kptNormal ) );
455
if ( stype == "rectangle" ) {
457
d->painter->fillRect( x, y, w, h );
459
d->painter->drawRect( x, y, w, h );
462
if ( stype == "textbox" ) {
463
int tf = vTextAlign() | hTextAlign();
465
QFont f = textFont();
466
f.setPointSize( f.pointSize() * scale );
468
d->painter->setFont( f );
469
QString text = getStringFromDict(shape,"text");
470
if ( !text.isEmpty() )
471
d->painter->drawText( x, y, w, h, tf | Qt::WordBreak, text );
474
if ( stype == "arc" ) {
475
double a1 = getDoubleFromDict(shape,"a1");
476
double a2 = getDoubleFromDict(shape,"a2");
477
d->painter->drawArc(x,y,w,h,a1,a2);
480
if ( stype == "roundrect" ) {
481
double rx = getDoubleFromDict(shape,"rx")*scale;
482
double ry = getDoubleFromDict(shape,"ry")*scale;
484
d->painter->fillRoundRect( x, y, w, h, rx, ry );
486
d->painter->drawRoundRect( x, y, w, h, rx, ry );
489
if ( stype == "linearray" ) {
490
d->painter->drawLineArray(&points);
493
if ( stype == "ellipse" ) {
495
d->painter->fillEllipse( x, y, w, h );
497
d->painter->drawEllipse( x, y, w, h );
501
KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
504
pTarget ->paintOutline( d );
505
pTarget = m_pConnectorTargets->next();
406
KoZoomHandler* zoomHandler = d->zoomHandler;
408
PyObject *shapes = PyDict_Values( PyDict_GetItemString( vars, "shapes" ) );
414
int size = PyList_Size( shapes );
416
for ( int i=0; i<size; i++ ) {
417
PyObject *shape = PyList_GetItem( shapes, i );
418
if ( !PyDict_Check(shape) )
421
int fill = KivioFillStyle::kcsNone;
423
// if style dosn't defined for shape, applay default for stencil
424
setStyle( d, PyDict_GetItemString( vars, "style" ) , fill );
425
setStyle( d, shape, fill );
428
setStyle( d, PyDict_GetItemString( shape, "selected" ) , fill );
431
fill = KivioFillStyle::kcsNone;
433
QString stype = getStringFromDict( shape, "type" );
434
stype = stype.lower();
436
double x = zoomHandler->zoomItX(getDoubleFromDict(shape,"x"));
437
double y = zoomHandler->zoomItY(getDoubleFromDict(shape,"y"));
438
double w = zoomHandler->zoomItX(getDoubleFromDict(shape,"w"));
439
double h = zoomHandler->zoomItY(getDoubleFromDict(shape,"h"));
440
double x2 = zoomHandler->zoomItX(getDoubleFromDict(shape,"x2"));
441
double y2 = zoomHandler->zoomItY(getDoubleFromDict(shape,"y2"));
444
QPtrList<KivioPoint> points;
445
points.setAutoDelete(true);
446
PyObject *pyPoints = PyDict_GetItemString( shape, "points" );
447
if ( pyPoints && PyList_Check(pyPoints) ) {
448
int size = PyList_Size(pyPoints);
449
for ( int i=0; i<size; i++ ) {
450
PyObject *pyPoint = PyList_GetItem(pyPoints,i);
451
double x = zoomHandler->zoomItX(getDoubleFromDict(pyPoint,"x"));
452
double y = zoomHandler->zoomItY(getDoubleFromDict(pyPoint,"y"));
453
points.append( new KivioPoint( x, y, KivioPoint::kptNormal ) );
458
if ( stype == "rectangle" ) {
460
d->painter->fillRect( x, y, w, h );
462
d->painter->drawRect( x, y, w, h );
465
if ( stype == "textbox" ) {
466
int tf = vTextAlign() | hTextAlign();
468
QFont f = textFont();
469
f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0));
471
d->painter->setFont( f );
472
QString text = getStringFromDict(shape,"text");
474
if ( !text.isEmpty() ) {
475
d->painter->drawText( x, y, w, h, tf | Qt::WordBreak, text );
479
if ( stype == "arc" ) {
480
double a1 = getDoubleFromDict(shape,"a1");
481
double a2 = getDoubleFromDict(shape,"a2");
482
d->painter->drawArc(x,y,w,h,a1,a2);
485
if ( stype == "roundrect" ) {
486
double rx = zoomHandler->zoomItX(getDoubleFromDict(shape,"rx"));
487
double ry = zoomHandler->zoomItY(getDoubleFromDict(shape,"ry"));
490
d->painter->fillRoundRect( x, y, w, h, rx, ry );
492
d->painter->drawRoundRect( x, y, w, h, rx, ry );
496
if ( stype == "linearray" ) {
497
d->painter->drawLineArray(&points);
500
if ( stype == "ellipse" ) {
502
d->painter->fillEllipse( x, y, w, h );
504
d->painter->drawEllipse( x, y, w, h );
508
if(stype == "polygon") {
509
d->painter->drawPolygon(&points);
512
if(stype == "polyline") {
513
d->painter->drawPolyline(&points);
517
KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
521
pTarget->paintOutline( d );
522
pTarget = m_pConnectorTargets->next();
610
627
void KivioPyStencil::paintConnectorTargets( KivioIntraStencilData *pData )
613
KivioPainter *painter;
616
// We don't draw these if we are selected!!!
620
// Obtain the graphic used for KivioConnectorTargets
621
targetPic = KivioConfig::config()->connectorTargetPixmap();
624
float _scale = pData->scale;
625
painter = pData->painter;
627
KivioConnectorTarget *pTarget;
628
pTarget = m_pConnectorTargets->first();
631
x = pTarget->x() * _scale;
632
y = pTarget->y() * _scale;
634
painter->drawPixmap( x-3, y-3, *targetPic );
636
pTarget = m_pConnectorTargets->next();
630
KivioPainter *painter;
633
// We don't draw these if we are selected!!!
637
// Obtain the graphic used for KivioConnectorTargets
638
targetPic = KivioConfig::config()->connectorTargetPixmap();
641
KoZoomHandler* zoomHandler = pData->zoomHandler;
642
painter = pData->painter;
644
KivioConnectorTarget *pTarget;
645
pTarget = m_pConnectorTargets->first();
648
x = zoomHandler->zoomItX(pTarget->x());
649
y = zoomHandler->zoomItY(pTarget->y());
651
painter->drawPixmap( x-3, y-3, *targetPic );
653
pTarget = m_pConnectorTargets->next();
641
658
* Attempts to connect a KivioConnectorPoint to this stencil.
643
660
* This function will attempt to locate a KivioConnectorTarget in this
644
* stencil with-in a given threshhold. If it finds it, it will connect
661
* stencil with-in a given threshold. If it finds it, it will connect
645
662
* the point to it, and return the target of the connection.
647
KivioConnectorTarget *KivioPyStencil::connectToTarget( KivioConnectorPoint *p, float threshHold )
664
KivioConnectorTarget *KivioPyStencil::connectToTarget( KivioConnectorPoint *p, double threshHold )
654
671
KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
727
744
void KivioPyStencil::setStyle( KivioIntraStencilData *d, PyObject *s, int &fillStyle )
732
if ( !PyDict_Check(s) )
735
KivioPainter *p = d->painter;
736
double scale = d->scale;
739
PyObject *color = PyDict_GetItemString(s,"color");
741
QColor c = readColor(color);
746
color = PyDict_GetItemString(s,"bgcolor");
748
QColor c = readColor(color);
753
color = PyDict_GetItemString(s,"textcolor");
755
QColor c = readColor(color);
760
PyObject *lineWidth = PyDict_GetItemString(s,"linewidth");
762
float lw = getDoubleFromDict(s,"linewidth");
763
p->setLineWidth( lw*scale );
767
PyObject *o_fillStyle = PyDict_GetItemString(s,"fillstyle");
769
QString sfill = getStringFromDict(s,"fillstyle");
770
if ( sfill == "solid" )
771
fillStyle = KivioFillStyle::kcsSolid;
773
if ( sfill == "none" )
774
fillStyle = KivioFillStyle::kcsNone;
777
QString sfont = getStringFromDict(s,"font");
778
int fontSize = int(getDoubleFromDict(s,"fontsize")*scale);
780
if ( !sfont.isEmpty() ) {
782
fontSize = int( 12*scale );
783
p->setFont( QFont( sfont, fontSize ) );
787
p->setFont( QFont( "times", fontSize ) );
749
if ( !PyDict_Check(s) )
752
KivioPainter *p = d->painter;
753
KoZoomHandler* zoomHandler = d->zoomHandler;
755
PyObject *color = PyDict_GetItemString(s,"color");
758
QColor c = readColor(color);
765
color = PyDict_GetItemString(s,"bgcolor");
768
QColor c = readColor(color);
775
color = PyDict_GetItemString(s,"textcolor");
778
QColor c = readColor(color);
785
PyObject *lineWidth = PyDict_GetItemString(s,"linewidth");
788
double lw = getDoubleFromDict(s,"linewidth");
789
p->setLineWidth( zoomHandler->zoomItY(lw) );
792
PyObject *o_fillStyle = PyDict_GetItemString(s,"fillstyle");
795
QString sfill = getStringFromDict(s,"fillstyle");
797
if ( sfill == "solid" ) {
798
fillStyle = KivioFillStyle::kcsSolid;
801
if ( sfill == "none" ) {
802
fillStyle = KivioFillStyle::kcsNone;
806
QString sfont = getStringFromDict(s,"font");
808
int fontSize = (int)getDoubleFromDict(s,"fontsize");
811
fontSize = 12; // FIXME: Should use some kind of global setting!!!
814
f.setPointSize(fontSize);
815
f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0));
817
if ( !sfont.isEmpty() ) {
820
f.setFamily("times"); // FIXME: Should use some kind of global setting!!!
792
826
QColor KivioPyStencil::readColor( PyObject *color )