Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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 <QPixmap>
00009 #include <QImage>
00010 #include "fpointarray.h"
00011 #include "scpainter.h"
00012 #include "util_math.h"
00013 #include "commonstrings.h"
00014 #include "scribusstructs.h"
00015 
00016 ArrowChooser::ArrowChooser(QWidget* pa, bool direction)  : QComboBox(pa)
00017 {
00018     setEditable(false);
00019     clear();
00020     setIconSize(QSize(22, 22));
00021     addItem(CommonStrings::tr_None);
00022     arrowDirection = direction;
00023 }
00024 
00025 void ArrowChooser::rebuildList(QList<ArrowDesc> *arrowStyles)
00026 {
00027     clear();
00028     FPointArray Path;
00029     Path.resize(0);
00030     addItem(CommonStrings::tr_None);
00031     for (int a = 0; a < arrowStyles->count(); ++a)
00032     {
00033         QImage image(22, 22, QImage::Format_ARGB32);
00034         ScPainter *painter = new ScPainter(&image, 22, 22);
00035         painter->clear();
00036         painter->setBrush(qRgb(0, 0, 0));
00037         painter->setPen(qRgb(0, 0, 0));
00038         painter->setFillMode(1);
00039         painter->translate(3.0, 3.0);
00040         Path.resize(0);
00041         Path = arrowStyles->at(a).points.copy();
00042         FPoint min = getMinClipF(&Path);
00043         Path.translate(-min.x(), -min.y());
00044         FPoint max = Path.WidthHeight();
00045         QMatrix mm;
00046         QMatrix mm2;
00047         if (arrowDirection)
00048         {
00049             mm2.scale(-1, 1);
00050             mm2.translate(-max.x(), 0);
00051         }
00052         mm.scale(16.0 / qMax(max.x(), max.y()), 16.0 / qMax(max.x(), max.y()));
00053         Path.map(mm2 * mm);
00054         painter->setupPolygon(&Path);
00055         painter->setLineWidth(1.0);
00056         painter->drawPolygon();
00057         painter->drawPolyLine();
00058         painter->end();
00059         delete painter;
00060         int wi = image.width();
00061         int hi = image.height();
00062         for( int yi=0; yi < hi; ++yi )
00063         {
00064             QRgb *s = (QRgb*)(image.scanLine( yi ));
00065             for(int xi=0; xi < wi; ++xi )
00066             {
00067                 if((*s) == 0xffffffff)
00068                     (*s) &= 0x00ffffff;
00069                 s++;
00070             }
00071         }
00072         QPixmap Ico;
00073         Ico=QPixmap::fromImage(image);
00074         addItem(Ico, arrowStyles->at(a).name);
00075     }
00076 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.