Edwin Leuven wrote:
Abdelrazak Younes wrote:
Edwin Leuven wrote:
Abdelrazak Younes wrote:
Yes, rather than fixing the symptom we should fix the origin of
the problem.

afaics, every time we contruct a painter:

QPainter qp(qwa_->paintDevice());

Wait, there is something fishy here. My original patched used to
cache also the current QPainter in qp_ and I see that it is not
there.

it's in the header, but not used

The proper fix would be to use that and to transform
setPainterPen(...) into a QPainter * getPainter(...) that will reset
the QPainter if needed.

shall i in the meantime commit the fix to setPainterPen ?

No, please try this patch instead. If it works for you I'll check it in.

Abdel.
Index: QLPainter.C
===================================================================
--- QLPainter.C (revision 14183)
+++ QLPainter.C (working copy)
@@ -46,6 +46,18 @@
 }
 
 
+void QLPainter::start()
+{
+       qp_.reset(new QPainter(qwa_->paintDevice()));
+}
+
+
+void QLPainter::end()
+{
+       qp_->end();
+}
+
+
 int QLPainter::paperWidth() const
 {
        return qwa_->viewport()->width();
@@ -86,9 +98,8 @@
 
 void QLPainter::point(int x, int y, LColor_color col)
 {
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col);
-       qp.drawPoint(x, y);
+       setQPainterPen(*qp_.get(), col);
+       qp_->drawPoint(x, y);
 }
 
 
@@ -97,9 +108,8 @@
        line_style ls,
        line_width lw)
 {
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col, ls, lw);
-       qp.drawLine(x1, y1, x2, y2);
+       setQPainterPen(*qp_.get(), col, ls, lw);
+       qp_->drawLine(x1, y1, x2, y2);
 }
 
 
@@ -118,9 +128,8 @@
                points[i].setY(yp[i]);
        }
 
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col, ls, lw);
-       qp.drawPolyline(points.get(), np);
+       setQPainterPen(*qp_.get(), col, ls, lw);
+       qp_->drawPolyline(points.get(), np);
 }
 
 
@@ -129,16 +138,14 @@
        line_style ls,
        line_width lw)
 {
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col, ls, lw);
-       qp.drawRect(x, y, w, h);
+       setQPainterPen(*qp_.get(), col, ls, lw);
+       qp_->drawRect(x, y, w, h);
 }
 
 
 void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
 {
-       QPainter qp(qwa_->paintDevice());
-       qp.fillRect(x, y, w, h, lcolorcache.get(col));
+       qp_->fillRect(x, y, w, h, lcolorcache.get(col));
 }
 
 
@@ -153,11 +160,10 @@
                points[i].setY(yp[i]);
        }
 
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col);
-       qp.setBrush(lcolorcache.get(col));
-       qp.drawPolygon(points.get(), np);
-       qp.setBrush(Qt::NoBrush);
+       setQPainterPen(*qp_.get(), col);
+       qp_->setBrush(lcolorcache.get(col));
+       qp_->drawPolygon(points.get(), np);
+       qp_->setBrush(Qt::NoBrush);
 }
 
 
@@ -165,9 +171,8 @@
        int a1, int a2, LColor_color col)
 {
        // LyX usings 1/64ths degree, Qt usings 1/16th
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, col);
-       qp.drawArc(x, y, w, h, a1 / 4, a2 / 4);
+       setQPainterPen(*qp_.get(), col);
+       qp_->drawArc(x, y, w, h, a1 / 4, a2 / 4);
 }
 
 
@@ -179,8 +184,7 @@
 
        fillRectangle(x, y, w, h, LColor::graphicsbg);
 
-       QPainter qp(qwa_->paintDevice());
-       qp.drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
+       qp_->drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
 }
 
 
@@ -208,19 +212,18 @@
        QFontMetrics const & qfontm = QFontMetrics(qfont);
        QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
 
-       QPainter qp(qwa_->paintDevice());
-       setQPainterPen(qp, f.realColor());
+       setQPainterPen(*qp_.get(), f.realColor());
        int tmpx = x;
        size_t ls = s.length();
        for (size_t i = 0; i < ls; ++i) {
                QChar const c = s[i].upper();
                if (c != s.at(i)) {
-                       qp.setFont(qsmallfont);
-                       qp.drawText(tmpx, y, c);
+                       qp_->setFont(qsmallfont);
+                       qp_->drawText(tmpx, y, c);
                        tmpx += qsmallfontm.width(c);
                } else {
-                       qp.setFont(qfont);
-                       qp.drawText(tmpx, y, c);
+                       qp_->setFont(qfont);
+                       qp_->drawText(tmpx, y, c);
                        tmpx += qfontm.width(c);
                }
        }
@@ -245,12 +248,11 @@
                str = ' ' + str;
 
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               QPainter qp(qwa_->paintDevice());
-               setQPainterPen(qp, f.realColor());
-               qp.setFont(fontloader.get(f));
+               setQPainterPen(*qp_.get(), f.realColor());
+               qp_->setFont(fontloader.get(f));
                // We need to draw the text as LTR as we use our own bidi code.
-               qp.setLayoutDirection(Qt::LeftToRight);
-               qp.drawText(x, y, str);
+               qp_->setLayoutDirection(Qt::LeftToRight);
+               qp_->drawText(x, y, str);
        } else {
                smallCapsText(x, y, str, f);
        }
@@ -263,14 +265,12 @@
 /// draw a pixmap from the image cache
 void QLPainter::drawPixmap(int x, int y, QPixmap const & pixmap)
 {
-       QPainter qp(qwa_->paintDevice());
-       qp.drawPixmap(x, y, pixmap);
+       qp_->drawPixmap(x, y, pixmap);
 }
 
 void QLPainter::drawImage(int x, int y, QImage const & image)
 {
-       QPainter qp(qwa_->paintDevice());
-       qp.drawImage(x, y, image);
+       qp_->drawImage(x, y, image);
 }
 
 } // namespace frontend
Index: QLPainter.h
===================================================================
--- QLPainter.h (revision 14183)
+++ QLPainter.h (working copy)
@@ -39,16 +39,10 @@
        ~QLPainter();
 
        /// begin painting
-       /**
-       Not used in the the Qt4 frontend.
-       */
-       virtual void start() {}
+       virtual void start();
 
        /// end painting
-       /**
-       Not used in the the Qt4 frontend.
-       */
-       virtual void end() {}
+       virtual void end();
 
        /// return the width of the work area in pixels
        virtual int paperWidth() const;

Reply via email to