[rkward-cvs] SF.net SVN: rkward-code:[4730] trunk/rkward/rkward/rbackend/rkwarddevice

tfry at users.sf.net tfry at users.sf.net
Sun Apr 28 09:27:07 UTC 2013


Revision: 4730
          http://sourceforge.net/p/rkward/code/4730
Author:   tfry
Date:     2013-04-28 09:27:06 +0000 (Sun, 28 Apr 2013)
Log Message:
-----------
QPixmap-based buffer does not work on Mac

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-04-27 13:30:23 UTC (rev 4729)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-04-28 09:27:06 UTC (rev 4730)
@@ -37,7 +37,14 @@
 
 QHash<int, RKGraphicsDevice*> RKGraphicsDevice::devices;
 
-RKGraphicsDevice::RKGraphicsDevice (double width, double height, const QString &title, bool antialias) : QObject (), area (qAbs (width) + 1, qAbs (height) + 1), base_title (title) {
+RKGraphicsDevice::RKGraphicsDevice (double width, double height, const QString &title, bool antialias) : 
+		QObject (),
+#ifdef USE_QIMAGE_BUFFER
+		area (qAbs (width) + 1, qAbs (height) + 1, QImage::Format_ARGB32),
+#else
+		area (qAbs (width) + 1, qAbs (height) + 1),
+#endif
+		base_title (title) {
 	RK_TRACE (GRAPHICS_DEVICE);
 
 	interaction_opcode = -1;
@@ -73,7 +80,11 @@
 
 void RKGraphicsDevice::updateNow () {
 	if (painter.isActive ()) painter.end ();
+#ifdef USE_QIMAGE_BUFFER
+	view->setPixmap (QPixmap::fromImage (area));
+#else
 	view->setPixmap (area);
+#endif
 	if (!view->isVisible ()) {
 		view->resize (area.size ());
 		view->show ();
@@ -121,7 +132,11 @@
 void RKGraphicsDevice::setAreaSize (const QSize& size) {
 	if (painter.isActive ()) painter.end ();
 	RK_DEBUG (GRAPHICS_DEVICE, DL_INFO, "New Size %d, %d (view size is %d, %d)", size.width (), size.height (), view->width (), view->height ());
+#ifdef USE_QIMAGE_BUFFER
+	area = QImage (size.width (), size.height (), QImage::Format_ARGB32);
+#else 
 	area = QPixmap (size.width (), size.height ());
+#endif
 	clear ();
 }
 
@@ -224,8 +239,11 @@
 
 QImage RKGraphicsDevice::capture () const {
 	RK_TRACE (GRAPHICS_DEVICE);
-
+#ifdef USE_QIMAGE_BUFFER
+	return area;
+#else
 	return area.toImage ();
+#endif
 }
 
 void RKGraphicsDevice::setActive (bool active) {

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2013-04-27 13:30:23 UTC (rev 4729)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2013-04-28 09:27:06 UTC (rev 4730)
@@ -21,10 +21,22 @@
 #include <QHash>
 #include <QPen>
 #include <QTimer>
-#include <QPixmap>
 #include <QPainter>
 #include <QLabel>
 
+#ifdef Q_WS_MAC
+// On Mac, drawing on a pixmap does not work correctly. Probably can only be done inside paint
+// events. (MacOSX 10.6.8, Qt 4.8.4).
+// Fortunately, a QImage based buffer does not seem to be _that_ much slower
+// (around 5-10% on X11, on plot (rnorm (100000)))
+#	define USE_QIMAGE_BUFFER
+#endif
+#ifdef USE_QIMAGE_BUFFER
+#	include <QImage>
+#else
+#	include <QPixmap>
+#endif
+
 class KDialog;
 
 /** This is the class that actually does all the drawing for the RKGraphicsDevice */
@@ -91,7 +103,11 @@
 	void checkSize ();
 
 	QTimer updatetimer;
+#ifdef USE_QIMAGE_BUFFER
+	QImage area;
+#else
 	QPixmap area;
+#endif
 	QPainter painter;
 	QLabel *view;
 	QString base_title;





More information about the rkward-tracker mailing list