SHARP Zaurus
ザウルスサポートステーション
slpainttracer.h
メインページ   クラス階層   アルファベット順リスト   データ構造リスト   ファイルリスト   データ構造メンバ  
slpainttracer.h

00001 /*
00002  * Copyright (C) 2002 SHARP CORPORATION All rights reserved.
00003  */
00004 #ifndef _SLPAINTTRACER_H_INCLUDED
00005 #define _SLPAINTTRACER_H_INCLUDED
00006 
00007 #include <qobject.h>
00008 #include <qpainter.h>
00009 #include <qpointarray.h>
00010 #include <qapplication.h>
00011 
00012 class SlImageEditTracer : public QObject
00013 {
00014     Q_OBJECT
00015 public:
00016     SlImageEditTracer() {}
00017     ~SlImageEditTracer() {}
00018     QPainter pmPainter;
00019     QPainter scPainter;
00020     virtual void begin(QMouseEvent*,QWidget*,QPaintDevice*) {}
00021     virtual void trace(QMouseEvent*) {}
00022     virtual void end(QMouseEvent*) {}
00023     virtual bool isUndoAvailable() { return FALSE; }
00024     virtual void flush(QPaintDevice*) {}
00025 };
00026 
00027 class SlImageEditPen : public SlImageEditTracer
00028 {
00029     Q_OBJECT
00030 public:
00031     SlImageEditPen(QPen& p,QBrush& b) 
00032         : points(1000) {
00033         pen = p;
00034         brush = b;
00035     }
00036     ~SlImageEditPen() {}
00037     void begin(QMouseEvent*,QWidget*,QPaintDevice*);
00038     void trace(QMouseEvent*);
00039     void end(QMouseEvent*);
00040     bool isUndoAvailable();
00041     void flush(QPaintDevice*);
00042 private:
00043     QPoint prevPenPos;
00044     QPen pen;
00045     QBrush brush;
00046     QPointArray points;
00047     uint pointNum;
00048     QPaintDevice *pd; 
00049 };
00050 
00051 class SlImageEditEraser : public SlImageEditPen
00052 {
00053     Q_OBJECT
00054 public:
00055     SlImageEditEraser(QPen& pen,QBrush& brush)
00056         : SlImageEditPen(pen,brush) {}
00057 };
00058 
00059 class SlImageEditSelector : public SlImageEditTracer
00060 {
00061     Q_OBJECT
00062 public:
00063     SlImageEditSelector() {}
00064     ~SlImageEditSelector() {}
00065     QRect selRect;
00066     bool isValidRect;
00067     void begin(QMouseEvent*,QWidget*,QPaintDevice*);
00068     void trace(QMouseEvent*);
00069     void end(QMouseEvent*);
00070 };
00071 
00072 class SlImageEditScroller : public SlImageEditTracer
00073 {
00074     Q_OBJECT
00075 public:
00076     SlImageEditScroller() {}
00077     ~SlImageEditScroller() {}
00078     void begin(QMouseEvent*,QWidget*,QPaintDevice*);
00079     void trace(QMouseEvent*);
00080     void end(QMouseEvent*);
00081 signals:
00082     void dragStart(const QPoint&);
00083     void dragExec(const QPoint&);
00084 };
00085 
00086 class SlImageEditClear : public SlImageEditTracer
00087 {
00088     Q_OBJECT
00089 public:
00090     SlImageEditClear() {}
00091     ~SlImageEditClear() {}
00092     bool isUndoAvailable() { return TRUE; }
00093     void flush(QPaintDevice*);
00094     QRect clearRect;
00095 };
00096 
00097 class SlImageEditRubberband : public SlImageEditTracer
00098 {
00099     Q_OBJECT
00100 public:
00101     SlImageEditRubberband(QPen& p,QBrush& b) {
00102         pen = p;
00103         brush = b;
00104     }
00105     ~SlImageEditRubberband() {}
00106     void begin(QMouseEvent *e,QWidget *wd,QPaintDevice *pm){
00107         scPainter.begin(wd);
00108         scPainter.setPen(QPen(Qt::white,1,
00109                               Qt::SolidLine));
00110         scPainter.setRasterOp(Qt::XorROP);
00111         startPenPos = e->pos();
00112         isPrevDraw = FALSE;
00113     }
00114     void trace(QMouseEvent *e) {
00115         if(isPrevDraw){
00116             draw(scPainter,startPenPos,prevPenPos);
00117         }else{
00118             isPrevDraw = TRUE;
00119         }
00120         draw(scPainter,startPenPos,e->pos());
00121         prevPenPos = e->pos();
00122     }
00123     void end(QMouseEvent *e) {
00124         if(isPrevDraw){
00125             draw(scPainter,startPenPos,prevPenPos);
00126         }
00127         endPenPos = e->pos();
00128         scPainter.setPen(pen);
00129         scPainter.setBrush(brush);
00130         scPainter.setRasterOp(Qt::CopyROP);
00131         draw(scPainter,startPenPos,endPenPos);
00132     }
00133     bool isUndoAvailable() { return TRUE; }
00134     void flush(QPaintDevice *p) {
00135         QPainter painter;
00136 
00137         painter.begin(p);
00138         painter.setPen(pen);
00139         painter.setBrush(brush);
00140         draw(painter,startPenPos,endPenPos);
00141         painter.end();
00142     }
00143     virtual void draw(QPainter&,const QPoint&,const QPoint&) {}
00144 protected:
00145     QPoint startPenPos,prevPenPos,endPenPos;
00146     QPen pen;
00147     QBrush brush;
00148     bool isPrevDraw;
00149 };
00150 
00151 class SlImageEditLine : public SlImageEditRubberband
00152 {
00153     Q_OBJECT
00154 public:
00155     SlImageEditLine(QPen& p,QBrush& b) : SlImageEditRubberband(p,b) {}
00156     void begin(QMouseEvent *e,QWidget *wd,QPaintDevice *pm){
00157         SlImageEditRubberband::begin(e,wd,pm);
00158         pen.setCapStyle(Qt::SquareCap);
00159     }
00160     void draw(QPainter& painter,const QPoint& s,const QPoint& e) {
00161         painter.moveTo(s);
00162         painter.lineTo(e);
00163     }
00164 };
00165 
00166 class SlImageEditBox : public SlImageEditRubberband
00167 {
00168     Q_OBJECT
00169 public:
00170     SlImageEditBox(QPen& p,QBrush& b) : SlImageEditRubberband(p,b) {}
00171     void begin(QMouseEvent *e,QWidget *wd,QPaintDevice *pm){
00172         SlImageEditRubberband::begin(e,wd,pm);
00173         pen.setCapStyle(Qt::SquareCap);
00174     }
00175     void draw(QPainter& painter,const QPoint& s,const QPoint& e) {
00176         painter.drawRect(QRect(s,e));
00177     }
00178 };
00179 
00180 class SlImageEditEllipse : public SlImageEditRubberband
00181 {
00182     Q_OBJECT
00183 public:
00184     SlImageEditEllipse(QPen& p,QBrush& b) : SlImageEditRubberband(p,b) {}
00185     void begin(QMouseEvent *e,QWidget *wd,QPaintDevice *pm){
00186         SlImageEditRubberband::begin(e,wd,pm);
00187         scPainter.setPen(QPen(Qt::white,2,Qt::SolidLine));
00188         pen.setCapStyle(Qt::RoundCap);
00189     }
00190     void draw(QPainter& painter,const QPoint& s,const QPoint& e) {
00191         painter.drawEllipse(QRect(s,e));
00192     }
00193 };
00194 
00195 #endif 
 
▲このページのトップへ
関連サイト   修理/ご相談窓口   利用上のご注意
COPYRIGHT