@@ -44,26 +44,6 @@ void removeDirectory(const QString &path);
4444#define HISTORY 15
4545#endif
4646
47- class ValueStorage {
48- public:
49- void saveValue (qint64 id, QPointF data) {
50- values[id] = data;
51- }
52-
53- QPointF loadValue (qint64 id) {
54- if (values.contains (id)) {
55- return values[id];
56- } else {
57- // -1 -1 means disable drawing
58- return QPointF (-1 ,-1 );
59- }
60- }
61-
62- private:
63- QMap<qint64, QPointF> values;
64- };
65- ValueStorage storage;
66-
6747class CursorStorage {
6848public:
6949 void init (qint64 id){
@@ -275,7 +255,6 @@ PageStorage pages;
275255
276256int curEventButtons = 0 ;
277257bool isMoved = 0 ;
278- float fpressure = 0 ;
279258
280259DrawingWidget::DrawingWidget (QWidget *parent): QWidget(parent) {
281260 initializeImage (size ());
@@ -300,8 +279,6 @@ DrawingWidget::~DrawingWidget() {}
300279
301280void DrawingWidget::mousePressEvent (QMouseEvent *event) {
302281 drawing = true ;
303- lastPoint = event->position ();
304- firstPoint = event->position ();
305282 mergeSelection ();
306283 imageBackup = image;
307284 if (floatingSettings->isVisible ()){
@@ -319,6 +296,8 @@ void DrawingWidget::mousePressEvent(QMouseEvent *event) {
319296 }
320297 curs.setCursor (-1 , penSize[ev_pen]);
321298 curEventButtons = event->buttons ();
299+ geo.clear (-1 );
300+ geo.addValue (-1 ,event->position ());
322301 isMoved = false ;
323302
324303}
@@ -345,10 +324,11 @@ void DrawingWidget::mouseMoveEvent(QMouseEvent *event) {
345324 switch (penMode) {
346325 case DRAW:
347326 updateCursorMouse (-1 , event->position ());
348- drawLineTo (event->position ());
327+ geo.addValue (-1 , event->position ());
328+ drawLineToFunc (-1 , 1.0 );
349329 break ;
350330 case SELECTION:
351- selectionDraw (firstPoint , event->position ());
331+ selectionDraw (geo. first (- 1 ) , event->position ());
352332 break ;
353333 }
354334 } else {
@@ -366,7 +346,8 @@ void DrawingWidget::addImage(QImage img){
366346
367347void DrawingWidget::mouseReleaseEvent (QMouseEvent *event) {
368348 if (curEventButtons & Qt::LeftButton && !isMoved) {
369- drawLineTo (event->position ()+QPointF (0 ,1 ));
349+ geo.addValue (-1 , event->position ()+QPointF (0 ,1 ));
350+ drawLineToFunc (-1 , 1.0 );
370351 }
371352 if (drawing) {
372353 drawing = false ;
@@ -410,21 +391,11 @@ void DrawingWidget::clear() {
410391}
411392
412393
413- int rad = 0 ;
414- int frad = 0 ;
415-
416- void DrawingWidget::drawLineTo (const QPointF &endPoint) {
417- drawLineToFunc (lastPoint, endPoint, 1.0 );
418- lastPoint = endPoint;
419- }
420- static QPointF last_end = QPointF(0 ,0 );
421- static QPointF last_begin = QPointF(0 ,0 );
422394
423395void DrawingWidget::selectionDraw (QPointF startPoint, QPointF endPoint) {
424396 image = imageBackup;
425397 update ();
426398 painter.begin (&image);
427- lastPoint = endPoint;
428399 painter.setPen (Qt::NoPen);
429400 penColor.setAlpha (127 );
430401 painter.setBrush (QBrush (penColor));
@@ -433,105 +404,6 @@ void DrawingWidget::selectionDraw(QPointF startPoint, QPointF endPoint) {
433404 painter.end ();
434405}
435406
436-
437- void DrawingWidget::drawLineToFunc (QPointF startPoint, QPointF endPoint, qreal pressure) {
438- if (startPoint.x () < 0 || startPoint.y () < 0 ){
439- return ;
440- }
441- if (fpressure > 0 ){
442- pressure = fpressure;
443- }
444- int fpenStyle = penStyle;
445- if (penType == ERASER) {
446- fpenStyle = SPLINE;
447- }
448-
449- switch (fpenStyle){
450- case SPLINE:
451- painter.begin (&image);
452- break ;
453- case LINE:
454- case CIRCLE:
455- case RECTANGLE:
456- case TRIANGLE:
457- startPoint = firstPoint;
458- image = imageBackup;
459- painter.begin (&image);
460- break ;
461- }
462- penColor.setAlpha (255 );
463- painter.setCompositionMode (QPainter::CompositionMode_Source);
464- switch (penType){
465- case PEN:
466- break ;
467- case ERASER:
468- painter.setCompositionMode (QPainter::CompositionMode_Clear);
469- break ;
470- case MARKER:
471- penColor.setAlpha (127 );
472- break ;
473- }
474-
475- painter.setPen (QPen (penColor, penSize[penType]*pressure, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
476- painter.setRenderHint (QPainter::Antialiasing, true );
477- painter.setRenderHint (QPainter::SmoothPixmapTransform, true );
478-
479- switch (fpenStyle){
480- case SPLINE:
481- painter.drawLine (startPoint, endPoint);
482- break ;
483- case LINE:
484- painter.drawLine (startPoint, endPoint);
485- break ;
486- case CIRCLE:
487- rad = QLineF (startPoint, endPoint).length ();
488- painter.drawEllipse (startPoint, rad, rad);
489- break ;
490- case RECTANGLE:
491- painter.drawRect (QRectF (startPoint,endPoint));
492- break ;
493- case TRIANGLE:
494- painter.drawLine (startPoint, endPoint);
495- painter.drawLine (startPoint, QPointF (startPoint.x (), endPoint.y ()));
496- painter.drawLine (QPointF (startPoint.x (), endPoint.y ()), endPoint);
497- break ;
498- }
499- switch (fpenStyle){
500- case SPLINE:
501- rad = penSize[penType];
502- update (QRectF (
503- startPoint, endPoint
504- ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
505- break ;
506- case LINE:
507- case TRIANGLE:
508- case RECTANGLE:
509- rad = penSize[penType];
510- update (QRectF (
511- last_begin, last_end
512- ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
513- update (QRectF (
514- startPoint, endPoint
515- ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
516- break ;
517- case CIRCLE:
518- rad = QLineF (startPoint, endPoint).length () + penSize[penType];
519- frad = QLineF (last_begin, last_end).length () + penSize[penType];
520- update (QRectF (
521- startPoint,startPoint
522- ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
523- update (QRectF (
524- startPoint,startPoint
525- ).toRect ().normalized ().adjusted (-frad, -frad, +frad, +frad));
526- break ;
527- }
528-
529- last_begin = startPoint;
530- last_end = endPoint;
531-
532- painter.end ();
533-
534- }
535407#ifdef LIBARCHIVE
536408void DrawingWidget::saveAll (QString file){
537409 if (!file.isEmpty ()) {
@@ -612,25 +484,24 @@ bool DrawingWidget::event(QEvent *ev) {
612484 foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
613485 QPointF pos = touchPoint.position ();
614486 if ((Qt::TouchPointState)touchPoint.state () == Qt::TouchPointPressed) {
615- storage. saveValue (touchPoint.id (), pos);
487+ geo. addValue (touchPoint.id (), pos);
616488 }
617489 else if ((Qt::TouchPointState)touchPoint.state () == Qt::TouchPointReleased) {
618490 curs.hide (touchPoint.id ());
619- storage. saveValue (touchPoint.id (), QPointF (- 1 ,- 1 ) );
491+ geo. load (touchPoint.id ()). clear ( );
620492 continue ;
621493 }
622- QPointF oldPos = storage.loadValue (touchPoint.id ());
623- drawLineToFunc (oldPos.toPoint (), pos.toPoint (), touchPoint.pressure ());
624- storage.saveValue (touchPoint.id (), pos);
494+ drawLineToFunc (touchPoint.id (), touchPoint.pressure ());
495+ geo.addValue (touchPoint.id (), pos);
625496 updateCursorMouse (touchPoint.id (), pos.toPoint ());
626497 curs.setCursor (touchPoint.id (), penSize[penType]);
627498 }
628499 break ;
629500 }
630501 case QEvent::TabletPress: {
631502 QTabletEvent *tabletEvent = static_cast <QTabletEvent*>(ev);
632- lastPoint = tabletEvent-> position ( );
633- firstPoint = tabletEvent->position ();
503+ geo. clear (- 1 );
504+ geo. addValue (- 1 , tabletEvent->position () );
634505 imageBackup = image;
635506 tabletActive = true ;
636507 break ;
@@ -648,9 +519,8 @@ bool DrawingWidget::event(QEvent *ev) {
648519 if (tabletEvent->buttons () & Qt::RightButton) {
649520 penType = ERASER;
650521 }
651- QPointF pos = tabletEvent->position ();
652- drawLineToFunc (lastPoint, pos.toPoint (), tabletEvent->pressure ());
653- lastPoint = tabletEvent->position ();
522+ geo.addValue (-1 , tabletEvent->position ());
523+ drawLineToFunc (-1 , tabletEvent->pressure ());
654524 penType = penTypeBak;
655525 }
656526
0 commit comments