Back to index

scribus-ng  1.3.4.dfsg+svn20071115
arrowchooser.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 "arrowchooser.h"
00008 #include "arrowchooser.moc"
00009 #include "fpointarray.h"
00010 #include <qpixmap.h>
00011 #include <qlistbox.h>
00012 #include "scpainter.h"
00013 #include <qimage.h>
00014 #include "util.h"
00015 
00016 ArrowChooser::ArrowChooser(QWidget* pa, bool direction)  : QComboBox(true, pa)
00017 {
00018        setEditable(false);
00019        clear();
00020        insertItem( tr("None"));
00021        setMaximumWidth(listBox()->maxItemWidth()*2+22);
00022        arrowDirection = direction;
00023 }
00024 
00025 void ArrowChooser::rebuildList(QValueList<ArrowDesc> *arrowStyles)
00026 {
00027        clear();
00028        FPointArray Path;
00029        Path.resize(0);
00030        insertItem( tr("None"));
00031        for (uint a = 0; a < arrowStyles->count(); ++a)
00032        {
00033               QPixmap Ico(22, 22);
00034               ScPainter *painter = new ScPainter(&Ico, 22, 22);
00035               painter->setBrush(qRgb(0, 0, 0));
00036               painter->setPen(qRgb(0, 0, 0));
00037               painter->setFillMode(1);
00038               painter->translate(3.0, 3.0);
00039               Path.resize(0);
00040               Path = (*arrowStyles->at(a)).points.copy();
00041               FPoint min = getMinClipF(&Path);
00042               Path.translate(-min.x(), -min.y());
00043               FPoint max = Path.WidthHeight();
00044               QWMatrix mm;
00045               QWMatrix mm2;
00046               if (arrowDirection)
00047               {
00048                      mm2.scale(-1, 1);
00049                      mm2.translate(-max.x(), 0);
00050               }
00051               mm.scale(16.0 / QMAX(max.x(), max.y()), 16.0 / QMAX(max.x(), max.y()));
00052               Path.map(mm2 * mm);
00053               painter->setupPolygon(&Path);
00054               painter->setLineWidth(1.0);
00055               painter->drawPolygon();
00056               painter->drawPolyLine();
00057               painter->end();
00058               delete painter;
00059               QImage image;
00060               image = Ico.convertToImage();
00061               image = image.convertDepth(32);
00062               image.setAlphaBuffer(true);
00063               int wi = image.width();
00064               int hi = image.height();
00065        for( int yi=0; yi < hi; ++yi )
00066               {
00067                      QRgb *s = (QRgb*)(image.scanLine( yi ));
00068                      for(int xi=0; xi < wi; ++xi )
00069                      {
00070                             if((*s) == 0xffffffff)
00071                                    (*s) &= 0x00ffffff;
00072                             s++;
00073                      }
00074        }
00075               Ico.convertFromImage(image);
00076               insertItem(Ico, (*arrowStyles->at(a)).name);
00077        }
00078        listBox()->setMinimumWidth(listBox()->maxItemWidth()+24);
00079 }