From fe13f77930056dd3c03c286c7e5808bcba9e4e6b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Jos=C3=A9=20Fonseca?= <jose.r.fonseca@gmail.com>
Date: Wed, 21 Mar 2012 08:49:40 +0000
Subject: [PATCH] Allow to turn off transparency on image viewer.

---
 gui/imageviewer.cpp   | 11 +++++++++--
 gui/ui/imageviewer.ui |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gui/imageviewer.cpp b/gui/imageviewer.cpp
index f4ba766..7b1e425 100644
--- a/gui/imageviewer.cpp
+++ b/gui/imageviewer.cpp
@@ -17,6 +17,8 @@ ImageViewer::ImageViewer(QWidget *parent)
             SLOT(slotUpdate()));
     connect(flipCheckBox, SIGNAL(stateChanged(int)),
             SLOT(slotUpdate()));
+    connect(opaqueCheckBox, SIGNAL(stateChanged(int)),
+            SLOT(slotUpdate()));
 
     QPixmap px(32, 32);
     QPainter p(&px);
@@ -59,7 +61,9 @@ void ImageViewer::slotUpdate()
     double lowerValue = lowerSpinBox->value();
     double upperValue = upperSpinBox->value();
 
-    if (lowerValue != 0.0 || upperValue != 1.0) {
+    bool opaque = opaqueCheckBox->isChecked();
+
+    if (lowerValue != 0.0 || upperValue != 1.0 || opaque) {
         /*
          * Rescale the image.
          *
@@ -81,6 +85,8 @@ void ImageViewer::slotUpdate()
         int width = m_temp.width();
         int height = m_temp.height();
 
+        int aMask = opaque ? 0xff : 0;
+
         for (int y = 0; y < height; ++y) {
             QRgb *scanline = (QRgb *)m_temp.scanLine(y);
             for (int x = 0; x < width; ++x) {
@@ -88,10 +94,11 @@ void ImageViewer::slotUpdate()
                 int r = qRed(pixel);
                 int g = qGreen(pixel);
                 int b = qBlue(pixel);
+                int a = qAlpha(pixel);
                 r = clamp(((r + offset) * scale) >> 8);
                 g = clamp(((g + offset) * scale) >> 8);
                 b = clamp(((b + offset) * scale) >> 8);
-                int a = 255;
+                a |= aMask;
                 scanline[x] = qRgba(r, g, b, a);
             }
         }
diff --git a/gui/ui/imageviewer.ui b/gui/ui/imageviewer.ui
index 7c5964a..c6ab846 100644
--- a/gui/ui/imageviewer.ui
+++ b/gui/ui/imageviewer.ui
@@ -83,6 +83,13 @@
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QCheckBox" name="opaqueCheckBox">
+       <property name="text">
+        <string>Opaque</string>
+       </property>
+      </widget>
+     </item>
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
-- 
2.45.2