00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "painter.h"
00013 #include "canvas.h"
00014
00015 #include <iostream>
00016 #include <qvariant.h>
00017 #include <qcombobox.h>
00018 #include <qspinbox.h>
00019 #include <qtoolbutton.h>
00020 #include <qlayout.h>
00021 #include <qtooltip.h>
00022 #include <qwhatsthis.h>
00023 #include <qimage.h>
00024 #include <qcolordialog.h>
00025 #include <qregexp.h>
00026
00027 PLUGIN_FACTORY(Painter,"drawing");
00028
00029
00030
00031
00032 Painter::Painter( QWidget* parent, const char* name, Master * session )
00033 : Page( parent, name, session ) {
00034 if ( !name )
00035 setName( "Painter" );
00036 PainterLayout = new QGridLayout( this, 1, 1, 6, 6, "PainterLayout");
00037
00038 canvas = new Canvas( this, "myCustomWidget1" );
00039
00040 PainterLayout->addMultiCellWidget( canvas, 1, 1, 0, 3 );
00041 QSpacerItem* spacer = new QSpacerItem( 330, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00042 PainterLayout->addItem( spacer, 0, 3 );
00043
00044 color_button = new QToolButton( this, "color_button" );
00045 connect(color_button, SIGNAL(pressed()), this, SLOT(slotColor()));
00046
00047 PainterLayout->addWidget( color_button, 0, 0 );
00048
00049 size_box = new QSpinBox( this, "size_box" );
00050 size_box->setMaxValue( 20 );
00051 size_box->setMinValue( 1 );
00052 size_box->setValue( 3 );
00053
00054 PainterLayout->addWidget( size_box, 0, 1 );
00055
00056 shape_combo = new QComboBox( FALSE, this, "shape_combo" );
00057 connect(shape_combo, SIGNAL(activated(int)), this, SLOT(slotShape(int)));
00058
00059 PainterLayout->addWidget( shape_combo, 0, 2 );
00060 languageChange();
00061 resize( QSize(548, 426).expandedTo(minimumSizeHint()) );
00062
00063 connect( size_box, SIGNAL( valueChanged( int ) ), this, SLOT( slotWidth( int ) ) );
00064
00065 connect(canvas,SIGNAL(drawing(QString&)),SLOT(sendOutput(QString&)));
00066 }
00067
00068
00069
00070
00071 Painter::~Painter() {
00072
00073 }
00074
00075
00076
00077
00078
00079 void Painter::languageChange() {
00080 setCaption( tr( "Form1" ) );
00081 color_button->setText( tr( "Color" ) );
00082 shape_combo->clear();
00083 shape_combo->insertItem( tr( "Line" ) );
00084 shape_combo->insertItem( tr( "Circle" ) );
00085 shape_combo->insertItem( tr( "Text" ) );
00086 }
00087
00088 void Painter::slotColor() {
00089 QColor c = QColorDialog::getColor( canvas->penColor(), this );
00090 if ( c.isValid() )
00091 canvas->setPenColor( c );
00092 }
00093
00094 void Painter::slotWidth( int w ) {
00095 canvas->setPenWidth( w );
00096 }
00097
00098 void Painter::slotShape(int s) {
00099 canvas->setDrawingShape((Canvas::Shape)s);
00100 }
00101
00102 void Painter::append(const QString & s) {
00103
00104 if (s.startsWith("}L")) {
00105
00106 QRegExp re("\\}L *([0-9]*) *(\\d+) *(\\d+) *(\\d+) *(\\d+) *(\\d+) *");
00107 if (re.exactMatch(s)) {
00108 QColor col(re.cap(1).toUInt());
00109 QPoint s(re.cap(2).toInt(),re.cap(3).toInt());
00110 QPoint e(re.cap(4).toInt(),re.cap(5).toInt());
00111 int w = re.cap(6).toInt();
00112 canvas->draw(Canvas::LINE,col,s,e,w);
00113
00114 }
00115 }
00116 else if (s.startsWith("}C")) {
00117
00118 QRegExp re("\\}C *([0-9]*) *(\\d+) *(\\d+) *(\\d+) *(\\d+) *");
00119 if (re.exactMatch(s)) {
00120 QColor col(re.cap(1).toUInt());
00121 QPoint s(re.cap(2).toInt(),re.cap(3).toInt());
00122 QPoint e(re.cap(2).toInt(),re.cap(3).toInt()+re.cap(4).toInt());
00123 int w = re.cap(5).toInt();
00124 canvas->draw(Canvas::CIRCLE,col,s,e,w);
00125 }
00126 }
00127 else if (s.startsWith("}T")) {
00128
00129 QRegExp re("\\}T *([0-9]*) *(\\d+) *(\\d+) *(\\d+) *(\\d+) *([\\w ]+) *");
00130 if (re.exactMatch(s)) {
00131 QColor col(re.cap(1).toUInt());
00132 QPoint s(re.cap(2).toInt(),re.cap(3).toInt());
00133 QPoint e(re.cap(2).toInt()+re.cap(4).toInt(),re.cap(3).toInt()+re.cap(5).toInt());
00134 QString text = re.cap(6);
00135 canvas->draw(Canvas::TEXT,col,s,e,0,text);
00136 }
00137 }
00138 }
00139
00140 void Painter::sendOutput(const QString& msg) {
00141 if(getMaster()->context()->getValue("channel") == "Dessin")
00142 getMaster()->send(msg);
00143 }