Back to index

scribus-ng  1.3.4.dfsg+svn20071115
autoformbuttongroup.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include <qimage.h>
00008 #include <qlayout.h>
00009 #include <qpopupmenu.h>
00010 #include <qbitmap.h>
00011 #include <qpixmap.h>
00012 #include <qbuttongroup.h>
00013 
00014 #include "autoformbuttongroup.h"
00015 #include "autoformbuttongroup.moc"
00016 #include "fpointarray.h"
00017 #include "scpainter.h"
00018 #include "util.h"
00019 
00020 AutoformButtonGroup::AutoformButtonGroup( QWidget* parent ) : QButtonGroup( parent, "autoformbuttongroup" )
00021 {
00022        this->setExclusive( true );
00023        this->setColumnLayout(0, Qt::Vertical );
00024        this->layout()->setSpacing( 0 );
00025        this->layout()->setMargin( 0 );
00026        buttonGroup1Layout = new QGridLayout( this->layout() );
00027        buttonGroup1Layout->setAlignment( Qt::AlignTop );
00028        toolButton1 = new QToolButton( this, "toolButton1" );
00029        toolButton1->setToggleButton( true );
00030        toolButton1->setPixmap(getIconPixmap(0,16));
00031        buttonGroup1Layout->addWidget( toolButton1, 0, 0 );
00032        toolButton2 = new QToolButton( this, "toolButton2" );
00033        toolButton2->setToggleButton( true );
00034        toolButton2->setPixmap(getIconPixmap(1,16));
00035        buttonGroup1Layout->addWidget( toolButton2, 0, 1 );
00036        toolButton3 = new QToolButton( this, "toolButton3" );
00037        toolButton3->setToggleButton( true );
00038        toolButton3->setPixmap(getIconPixmap(2,16));
00039        buttonGroup1Layout->addWidget( toolButton3, 0, 2 );
00040        toolButton4 = new QToolButton( this, "toolButton4" );
00041        toolButton4->setToggleButton( true );
00042        toolButton4->setPixmap(getIconPixmap(3,16));
00043        buttonGroup1Layout->addWidget( toolButton4, 0, 3 );
00044 
00045        toolButton5 = new QToolButton( this, "toolButton3" );
00046        toolButton5->setToggleButton( true );
00047        toolButton5->setPixmap(getIconPixmap(4,16));
00048        buttonGroup1Layout->addWidget( toolButton5, 1, 0 );
00049        toolButton6 = new QToolButton( this, "toolButton4" );
00050        toolButton6->setToggleButton( true );
00051        toolButton6->setPixmap(getIconPixmap(5,16));
00052        buttonGroup1Layout->addWidget( toolButton6, 1, 1 );
00053        toolButton7 = new QToolButton( this, "toolButton3" );
00054        toolButton7->setToggleButton( true );
00055        toolButton7->setPixmap(getIconPixmap(6,16));
00056        buttonGroup1Layout->addWidget( toolButton7, 1, 2 );
00057        toolButton8 = new QToolButton( this, "toolButton4" );
00058        toolButton8->setToggleButton( true );
00059        toolButton8->setPixmap(getIconPixmap(7,16));
00060        buttonGroup1Layout->addWidget( toolButton8, 1, 3 );
00061 
00062        toolButton9 = new QToolButton( this, "toolButton4" );
00063        toolButton9->setToggleButton( true );
00064        toolButton9->setPixmap(getIconPixmap(8,16));
00065        buttonGroup1Layout->addWidget( toolButton9, 2, 0 );
00066        toolButton10 = new QToolButton( this, "toolButton4" );
00067        toolButton10->setToggleButton( true );
00068        toolButton10->setPixmap(getIconPixmap(9,16));
00069        buttonGroup1Layout->addWidget( toolButton10, 2, 1 );
00070        toolButton11 = new QToolButton( this, "toolButton4" );
00071        toolButton11->setToggleButton( true );
00072        toolButton11->setPixmap(getIconPixmap(10,16));
00073        buttonGroup1Layout->addWidget( toolButton11, 2, 2 );
00074        toolButton12 = new QToolButton( this, "toolButton4" );
00075        toolButton12->setToggleButton( true );
00076        toolButton12->setPixmap(getIconPixmap(11,16));
00077        buttonGroup1Layout->addWidget( toolButton12, 2, 3 );
00078 
00079        toolButton13 = new QToolButton( this, "toolButton4" );
00080        toolButton13->setToggleButton( true );
00081        toolButton13->setPixmap(getIconPixmap(12,16));
00082        buttonGroup1Layout->addWidget( toolButton13, 3, 0 );
00083        toolButton14 = new QToolButton( this, "toolButton4" );
00084        toolButton14->setToggleButton( true );
00085        toolButton14->setPixmap(getIconPixmap(13,16));
00086        buttonGroup1Layout->addWidget( toolButton14, 3, 1 );
00087        toolButton15 = new QToolButton( this, "toolButton4" );
00088        toolButton15->setToggleButton( true );
00089        toolButton15->setPixmap(getIconPixmap(14,16));
00090        buttonGroup1Layout->addWidget( toolButton15, 3, 2 );
00091        toolButton16 = new QToolButton( this, "toolButton4" );
00092        toolButton16->setToggleButton( true );
00093        toolButton16->setPixmap(getIconPixmap(15,16));
00094        buttonGroup1Layout->addWidget( toolButton16, 3, 3 );
00095 
00096        toolButton17 = new QToolButton( this, "toolButton4" );
00097        toolButton17->setToggleButton( true );
00098        toolButton17->setPixmap(getIconPixmap(16,16));
00099        buttonGroup1Layout->addWidget( toolButton17, 4, 0 );
00100        toolButton18 = new QToolButton( this, "toolButton4" );
00101        toolButton18->setToggleButton( true );
00102        toolButton18->setPixmap(getIconPixmap(17,16));
00103        buttonGroup1Layout->addWidget( toolButton18, 4, 1 );
00104        
00105        connect(this, SIGNAL(clicked(int)), this, SLOT(selForm(int)));
00106 
00107 }
00108 
00109 double* AutoformButtonGroup::getShapeData(int a, int *n)
00110 {
00111        double *vals = NULL;
00112        static double AutoShapes0[] = {0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0,
00113                                                                100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, 100.0,
00114                                                                0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0};
00115        static double AutoShapes1[] = {100.0, 50.0, 100.0, 77.615235, 50.0, 100.0,
00116                                                                77.615235, 100.0, 50.0, 100.0,
00117                                                                22.385765, 100.0,
00118                                                                0.0, 50.0, 0.0, 77.615235, 0.0, 50.0, 0.0, 22.385765, 50.0, 0.0,
00119                                                                22.385765, 0.0,
00120                                                                50.0, 0.0, 77.615235, 0.0, 100.0, 50.0, 100.0, 22.385765};
00121        static double AutoShapes2[] = {0.0, 0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0,
00122                                                                0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0};
00123        static double AutoShapes3[] = {0.0, 25.0, 0.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0,
00124                                                                25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0,
00125                                                                75.0, 0.0, 75.0, 0.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0,
00126                                                                100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0,     100.0, 75.0, 100.0, 75.0,
00127                                                                100.0, 75.0, 100.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0,
00128                                                                75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 25.0, 100.0, 25.0, 100.0,
00129                                                                25.0, 100.0, 25.0, 100.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0,
00130                                                                0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0,      0.0, 25.0, 0.0, 25.0};
00131        static double AutoShapes4[] = {0.0, 50.0, 0.0, 50.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0,
00132                                                                50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0,  100.0, 25.0, 100.0, 25.0,
00133                                                                100.0, 25.0, 100.0,  25.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0,
00134                                                                50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 100.0, 50.0, 100.0,
00135                                                                50.0, 100.0, 50.0, 100.0,   0.0, 50.0, 0.0, 50.0};
00136        static double AutoShapes5[] = {0.0, 25.0, 0.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0,
00137                                                                50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0,      100.0, 50.0, 100.0, 50.0,
00138                                                                100.0, 50.0, 100.0, 50.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0,
00139                                                                50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 0.0, 75.0, 0.0, 75.0,
00140                                                                0.0, 75.0, 0.0, 75.0,       0.0, 25.0, 0.0, 25.0};
00141        static double AutoShapes6[] = {0.0, 50.0, 0.0, 50.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0,
00142                                                                100.0, 50.0, 100.0, 50.0,   100.0, 50.0, 100.0, 50.0, 75.0, 50.0, 75.0, 50.0,
00143                                                                75.0, 50.0, 75.0, 50.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0,
00144                                                                25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 50.0, 25.0, 50.0,
00145                                                                25.0, 50.0, 25.0, 50.0,     0.0, 50.0, 0.0, 50.0};
00146        static double AutoShapes7[] = {0.0, 50.0, 0.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0,
00147                                                                25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0,
00148                                                                75.0, 0.0, 75.0, 0.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0,
00149                                                                100.0, 50.0, 100.0, 50.0,   100.0, 50.0, 100.0, 50.0, 50.0, 100.0, 50.0, 100.0,
00150                                                                50.0, 100.0, 50.0, 100.0,   0.0, 50.0, 0.0, 50.0};
00151        static double AutoShapes8[] = {0.0, 50.0, 0.0, 22.385765, 100.0, 0.0, 44.77716, 0.0,       100.0, 0.0, 100.0, 0.0,
00152                                                                100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 44.77716, 100.0, 0.0, 50.0,
00153                                                                0.0, 77.615235};
00154        static double AutoShapes9[] = {100.0, 50.0, 100.0, 77.615235, 0.0, 100.0,
00155 55.22284, 100.0, 0.0, 100.0, 0.0, 100.0,
00156                                                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 55.22281, 0.0, 100.0, 50.0, 100.0, 22.385765};
00157        static double AutoShapes10[] = {100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0,
00158                                                                100.0, 0.0, 100.0, 0.0, 44.7715,
00159                                                                 50.0, 0.0, 22.3858, 0.0, 50.0, 0.0, 77.6152, 0.0, 100.0, 100.0, 100.0,
00160 44.7715};
00161        static double AutoShapes11[] = {100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 55.2285, 50.0, 100.0,
00162                                                                 22.3858, 100.0, 50.0, 100.0, 77.6152, 100.0, 100.0, 0.0, 100.0, 55.2285};
00163        static double AutoShapes12[] = {0.0, 50.0, 0.0, 50.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0,
00164                                                                 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 50.0, 0.0, 50.0};
00165        static double AutoShapes13[] = {0.0, 0.0, 0.0, 0.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0,
00166                                                                 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0};
00167        static double AutoShapes14[] = {0.0, 100.0, 0.0, 100.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0,
00168                                                                 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, 100.0};
00169        static double AutoShapes15[] = {0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0,
00170                                                                 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 0.0, 0.0, 0.0, 0.0};
00171        static double AutoShapes16[] = {25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 13.8071,
00172                                                                 100.0, 25.0, 86.1929, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 75.0, 100.0, 75.0,
00173                                                                 100.0, 75.0, 86.1929, 75.0, 75.0, 100.0, 75.0, 86.1929, 75.0, 100.0, 75.0, 100.0,
00174                                                                 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 86.1929, 0.0, 75.0, 13.8071, 75.0,
00175                                                                 0.0, 75.0, 0.0, 75.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 13.8071, 25.0,
00176                                                                 25.0, 0.0, 25.0, 13.8071};
00177        static double AutoShapes17[] = {100.0, 50.0, 100.0, 77.6152, 50.0, 100.0, 77.6152, 100.0, 50.0, 100.0, 22.3858, 100.0,
00178                                                                 0.0, 50.0, 0.0, 77.6152, 0.0,  50.0, 0.0, 22.3858, 50.0, 0.0, 22.3858, 0.0,
00179                                                                 50.0, 0.0, 77.6152, 0.0, 100.0, 50.0, 100.0, 22.3858, -1.0, -1.0, -1.0, -1.0,
00180                                                                 75.0, 50.0, 75.0, 63.8076, 50.0, 75.0, 63.8076, 75.0, 50.0, 75.0, 36.1929, 75.0,
00181                                                                 25.0, 50.0, 25.0, 63.8076, 25.0, 50.0, 25.0, 36.1929, 50.0, 25.0, 36.1929, 25.0,
00182                                                                 50.0, 25.0, 63.8076, 25.0, 75.0, 50.0, 75.0, 36.1929};
00183        switch (a)
00184               {
00185               case 0:
00186                      *n = 32;
00187                      vals = AutoShapes0;
00188                      break;
00189               case 1:
00190                      *n = 32;
00191                      vals = AutoShapes1;
00192                      break;
00193               case 2:
00194                      *n = 24;
00195                      vals = AutoShapes2;
00196                      break;
00197               case 3:
00198                      *n = 96;
00199                      vals = AutoShapes3;
00200                      break;
00201               case 4:
00202                      *n = 56;
00203                      vals = AutoShapes4;
00204                      break;
00205               case 5:
00206                      *n = 56;
00207                      vals = AutoShapes5;
00208                      break;
00209               case 6:
00210                      *n = 56;
00211                      vals = AutoShapes6;
00212                      break;
00213               case 7:
00214                      *n = 56;
00215                      vals = AutoShapes7;
00216                      break;
00217               case 8:
00218                      *n = 24;
00219                      vals = AutoShapes8;
00220                      break;
00221               case 9:
00222                      *n = 24;
00223                      vals = AutoShapes9;
00224                      break;
00225               case 10:
00226                      *n = 24;
00227                      vals = AutoShapes10;
00228                      break;
00229               case 11:
00230                      *n = 24;
00231                      vals = AutoShapes11;
00232                      break;
00233               case 12:
00234                      *n = 24;
00235                      vals = AutoShapes12;
00236                      break;
00237               case 13:
00238                      *n = 24;
00239                      vals = AutoShapes13;
00240                      break;
00241               case 14:
00242                      *n = 24;
00243                      vals = AutoShapes14;
00244                      break;
00245               case 15:
00246                      *n = 24;
00247                      vals = AutoShapes15;
00248                      break;
00249               case 16:
00250                      *n = 64;
00251                      vals = AutoShapes16;
00252                      break;
00253               case 17:
00254                      *n = 68;
00255                      vals = AutoShapes17;
00256                      break;
00257               default:
00258                      *n = 32;
00259                      vals = AutoShapes0;
00260                      break;
00261               }
00262        return vals;
00263 }
00264 
00265 void AutoformButtonGroup::selForm(int a)
00266 {
00267        int n;
00268        
00269        double* AutoShapes;
00270        AutoShapes = getShapeData(a, &n);
00271        emit FormSel(a, n, AutoShapes);
00272 }
00273 
00274 QPixmap AutoformButtonGroup::getIconPixmap(int nr, int pixmapSize)
00275 {
00276        if (pixmapSize!=16 && pixmapSize!=22)
00277               qDebug("%s", QString("Autoformbuttongroup: Only 16px or 22px sizes supported!").ascii());
00278        else
00279        if (nr<18)
00280        {
00281               QString strSize=QString("%1").arg(pixmapSize);
00282               switch(nr)
00283               {
00284                      case 0:
00285                             return loadIcon(strSize+"/draw-rectangle.png");
00286                      case 1:
00287                             return loadIcon(strSize+"/draw-ellipse.png");
00288                      case 2:
00289                             return loadIcon(strSize+"/draw-triangle.png");
00290                      case 3:
00291                             return loadIcon(strSize+"/draw-cross.png");
00292                      case 4:
00293                             return loadIcon(strSize+"/draw-arrow-back.png");
00294                      case 5:
00295                             return loadIcon(strSize+"/draw-arrow-forward.png");
00296                      case 6:
00297                             return loadIcon(strSize+"/draw-arrow-up.png");
00298                      case 7:
00299                             return loadIcon(strSize+"/draw-arrow-down.png");
00300                      case 8:
00301                             return loadIcon(strSize+"/draw-halfcircle1.png");
00302                      case 9:
00303                             return loadIcon(strSize+"/draw-halfcircle2.png");
00304                      case 10:
00305                             return loadIcon(strSize+"/draw-halfcircle3.png");
00306                      case 11:
00307                             return loadIcon(strSize+"/draw-halfcircle4.png");
00308                      case 12:
00309                             return loadIcon(strSize+"/draw-triangle1.png");
00310                      case 13:
00311                             return loadIcon(strSize+"/draw-triangle2.png");
00312                      case 14:
00313                             return loadIcon(strSize+"/draw-triangle3.png");
00314                      case 15:
00315                             return loadIcon(strSize+"/draw-triangle4.png");
00316                      case 16:
00317                             return loadIcon(strSize+"/draw-square-inverted-corners.png");
00318                      case 17:
00319                             return loadIcon(strSize+"/draw-donut.png");
00320               }
00321        }
00322        int count = 0;
00323        double* AutoShapes;
00324        FPointArray Path;
00325        QPixmap Ico(22, 22);
00326        Path.resize(0);
00327        AutoShapes = getShapeData(nr, &count);
00328        for (int a = 0; a < count-3; a += 4)
00329        {
00330               if (AutoShapes[a] < 0)
00331               {
00332                      Path.setMarker();
00333                      continue;
00334               }
00335               double x1 = 16 * AutoShapes[a] / 100.0;
00336               double y1 = 16 * AutoShapes[a+1] / 100.0;
00337               double x2 = 16 * AutoShapes[a+2] / 100.0;
00338               double y2 = 16 * AutoShapes[a+3] / 100.0;
00339               Path.addPoint(x1, y1);
00340               Path.addPoint(x2, y2);
00341        }
00342        ScPainter *painter = new ScPainter(&Ico, 22, 22);
00343        painter->setBrush(qRgb(255, 255, 255));
00344        painter->setPen(qRgb(0, 0, 0));
00345        painter->setFillMode(1);
00346        painter->translate(3.0, 3.0);
00347        painter->setupPolygon(&Path);
00348        painter->setLineWidth(1.0);
00349        painter->drawPolygon();
00350        painter->drawPolyLine();
00351        painter->end();
00352        delete painter;
00353        Ico.setMask( Ico.createHeuristicMask() );
00354 
00355        return Ico;
00356 }