[Marble-commits] branches/KDE/4.4/kdeedu/marble/src/lib

Dennis Nienhüser earthwings at gentoo.org
Fri Jan 15 22:40:27 CET 2010


SVN commit 1075344 by nienhueser:

When the MarbleWidget is disabled, disable keyboard and mouse input and draw contents grayscaled.
Backport of commit 1073273.
BUG: 221490


 M  +35 -2     MarbleWidget.cpp  
 M  +6 -0      MarbleWidget.h  


--- branches/KDE/4.4/kdeedu/marble/src/lib/MarbleWidget.cpp #1075343:1075344
@@ -843,9 +843,18 @@
         doClip = ( d->m_map->radius() > width() / 2
                    || d->m_map->radius() > height() / 2 );
 
+    QPaintDevice *paintDevice = this;
+    QImage image;
+    if (!isEnabled())
+    {
+        // Paint to an intermediate image
+        image = QImage(rect().size(), QImage::Format_ARGB32_Premultiplied);
+        paintDevice = ℑ
+    }
+
     // Create a painter that will do the painting.
-    GeoPainter painter( this, map()->viewParams()->viewport(),
-			map()->viewParams()->mapQuality(), doClip );
+    GeoPainter painter( paintDevice, map()->viewParams()->viewport(),
+                        map()->viewParams()->mapQuality(), doClip );
 
     QRect  dirtyRect = evt->rect();
 
@@ -855,6 +864,20 @@
     customPaint( &painter );
     d->m_map->d->paintOverlay( painter, dirtyRect );
 
+    if (!isEnabled())
+    {
+        // Draw a grayscale version of the intermediate image
+        QRgb* pixel = reinterpret_cast<QRgb*>(image.scanLine(0));
+        for (int i=0; i<image.width()*image.height(); ++i, ++pixel) {
+            int gray = qGray(*pixel);
+            *pixel = qRgb(gray,gray,gray);
+        }
+
+        GeoPainter widgetPainter( this, map()->viewParams()->viewport(),
+                            map()->viewParams()->mapQuality(), doClip );
+        widgetPainter.drawImage(rect(), image);
+    }
+
     if (d->m_map->showFrameRate())
     {
         qreal fps = 1000.0 / (qreal)( t.elapsed() + 1 );
@@ -1392,6 +1415,16 @@
     return d->m_model->floatItems();
 }
 
+void MarbleWidget::changeEvent ( QEvent * event )
+{
+    if (event->type() == QEvent::EnabledChange)
+    {
+        setInputEnabled(isEnabled());
+    }
+
+    QWidget::changeEvent(event);
 }
 
+}
+
 #include "MarbleWidget.moc"
--- branches/KDE/4.4/kdeedu/marble/src/lib/MarbleWidget.h #1075343:1075344
@@ -1008,6 +1008,12 @@
     void  connectNotify ( const char * signal );
     void  disconnectNotify ( const char * signal );
 
+    /**
+      * @brief Reimplementation of the changeEvent() function in QWidget to
+      * react to changes of the enabled state
+      */
+    void changeEvent ( QEvent * event );
+
  private:
     Q_DISABLE_COPY( MarbleWidget )
     MarbleWidgetPrivate  * const d;


More information about the Marble-commits mailing list