[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: [PATCH] Applet opacity
From:       Andre Duffeck <andre () duffeck ! de>
Date:       2008-04-04 5:35:05
Message-ID: 6d29add0eaaccb85413a50218d89d7e0 () duffeck ! de
[Download RAW message or body]

On Thu, 3 Apr 2008 14:37:23 -0600, "Aaron J. Seigo" <aseigo@kde.org> wrote:
> Andre: can we delay the UI portion to a discussion of reworking the
applet
> handles? and can you touch up your patch to only all setOpacity when it's


Sure. Here's the updated patch meanwhile.
["opacity.diff" (text/x-patch)]

Index: workspace/libs/plasma/applet.h
===================================================================
--- workspace/libs/plasma/applet.h	(Revision 793470)
+++ workspace/libs/plasma/applet.h	(Arbeitskopie)
@@ -628,6 +628,17 @@
          **/
         Containment* containment() const;
 
+        /**
+         * Sets the opacity of this Plasma::Applet
+         * @param opacity the new opacity
+         */
+        void setOpacity( qreal opacity );
+
+        /**
+         * @return opacity of this Applet
+         **/
+        qreal opacity() const;
+
     Q_SIGNALS:
         /**
          * Emitted when the applet needs to take (or lose) keyboard focus.
Index: workspace/libs/plasma/applethandle_p.h
===================================================================
--- workspace/libs/plasma/applethandle_p.h	(Revision 793470)
+++ workspace/libs/plasma/applethandle_p.h	(Arbeitskopie)
@@ -37,7 +37,7 @@
     Q_OBJECT
     public:
         enum FadeType { FadeIn, FadeOut };
-        enum ButtonType { NoButton, MoveButton, RotateButton, ConfigureButton, \
RemoveButton, ResizeButton }; +        enum ButtonType { NoButton, MoveButton, \
RotateButton, ConfigureButton, RemoveButton, ResizeButton, OpacityButton };  
         AppletHandle(Containment *parent, Applet *applet);
         virtual ~AppletHandle();
@@ -96,6 +96,8 @@
         QTimer *m_hoverTimer;
         bool m_buttonsOnRight;
         bool m_pendingFade;
+        QRect m_sliderRect;
+        qreal m_appletOpacity;
 };
 
 }
Index: workspace/libs/plasma/applet.cpp
===================================================================
--- workspace/libs/plasma/applet.cpp	(Revision 793470)
+++ workspace/libs/plasma/applet.cpp	(Arbeitskopie)
@@ -116,7 +116,8 @@
           hasConfigurationInterface(false),
           failed(false),
           isContainment(false),
-          square(false)
+          square(false),
+          opacity(1.0)
     {
         if (appletId == 0) {
             appletId = ++s_maxAppletId;
@@ -331,6 +332,7 @@
     bool failed : 1;
     bool isContainment : 1;
     bool square : 1;
+    qreal opacity;
 };
 
 uint Applet::Private::s_maxAppletId = 0;
@@ -398,6 +400,7 @@
     //kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() \
<< "bounding rect is" << boundingRect();  group->writeEntry("geometry", geometry());
     group->writeEntry("zvalue", zValue());
+    group->writeEntry("opacity", d->opacity);
 
     if (transform() == QTransform()) {
         group->deleteEntry("transform");
@@ -435,6 +438,8 @@
     if (c->readEntry("locked", false)) {
         setImmutable(true);
     }
+
+    setOpacity(c->readEntry("opacity", 1.0));
 }
 
 void Applet::saveState(KConfigGroup* group) const
@@ -933,6 +938,12 @@
     }
 
     painter->save();
+
+    //Set opacity
+    if (d->opacity >= 0.1 && d->opacity <= 0.9) {
+        painter->setOpacity(d->opacity);
+    }
+
     if (transform().isRotating()) {
         painter->setRenderHint(QPainter::SmoothPixmapTransform);
         painter->setRenderHint(QPainter::Antialiasing);
@@ -1595,6 +1606,16 @@
     update();
 }
 
+void Applet::setOpacity( qreal opacity )
+{
+    d->opacity = opacity;
+}
+
+qreal Applet::opacity() const
+{
+    return d->opacity;
+}
+
 } // Plasma namespace
 
 #include "applet.moc"
Index: workspace/libs/plasma/applethandle.cpp
===================================================================
--- workspace/libs/plasma/applethandle.cpp	(Revision 793470)
+++ workspace/libs/plasma/applethandle.cpp	(Arbeitskopie)
@@ -57,7 +57,8 @@
       m_scaleWidth(1.0),
       m_scaleHeight(1.0),
       m_buttonsOnRight(false),
-      m_pendingFade(false)
+      m_pendingFade(false),
+      m_appletOpacity(applet->opacity())
 {
     KColorScheme colors(QPalette::Active, KColorScheme::View, \
                Theme::self()->colors());
     m_gradientColor = colors.background(KColorScheme::NormalBackground).color();
@@ -176,6 +177,7 @@
     QPointF shiftD;
     QPointF shiftR;
     QPointF shiftM;
+    QPointF shiftO;
 
     switch(m_pressedButton)
     {
@@ -191,6 +193,9 @@
     case ResizeButton:
         shiftM = QPointF(2, 2);
         break;
+      case OpacityButton:
+        shiftO = QPointF(2, 2);
+        break;
     default:
         break;
     }
@@ -208,6 +213,22 @@
     basePoint += separator;
     painter->drawPixmap(basePoint + shiftD, KIcon("edit-delete").pixmap(ICON_SIZE, \
ICON_SIZE));  
+    basePoint += separator;
+    painter->drawPixmap(basePoint + shiftO, KIcon("edit").pixmap(ICON_SIZE, \
ICON_SIZE)); +
+    if (m_pressedButton == OpacityButton) {
+      QRect r(basePoint.toPoint()-QPoint(0,80), QSize(ICON_SIZE, 80));
+      painter->setBrush(Qt::gray);
+      painter->setOpacity(0.7);
+      painter->drawRoundedRect(r, 3, 3);
+
+      painter->setBrush(Qt::black);
+      painter->drawRoundedRect(r.adjusted(9, 2, -9, -2), 1, 1);
+
+      painter->drawRoundedRect(QRect(r.left()+2, r.bottom()-6-(m_appletOpacity*68), \
ICON_SIZE-4, 4), 1, 1); +      m_sliderRect = r;
+    }
+
     painter->restore();
 }
 
@@ -246,6 +267,11 @@
         return RemoveButton;
     }
 
+    activeArea.translate(separator);
+    if (activeArea.containsPoint(point, Qt::OddEvenFill)) {
+        return OpacityButton;
+    }
+
     return MoveButton;
     //return m_applet->mapToParent(m_applet->shape()).contains(point) ? NoButton : \
MoveButton;  }
@@ -358,7 +384,6 @@
                 break;
         }
     }
-
     m_pressedButton = NoButton;
     update();
 }
@@ -506,6 +531,13 @@
         matrix.scale(m_scaleWidth, m_scaleHeight);
         matrix.translate(-center.x(), -center.y());
         setTransform(matrix);
+    } else if (m_pressedButton == OpacityButton) {
+        if( m_sliderRect.contains( curPos.toPoint() ) ) {
+            m_appletOpacity = qBound(.0, \
(double)(m_sliderRect.bottom()-curPos.y())/(double)m_sliderRect.height(), 1.0); +     \
m_applet->setOpacity((m_appletOpacity * 0.85) + 0.1 ); // Translate the value to \
[0.1;0.9] +            m_applet->update();
+            update();
+        }
     } else {
         QGraphicsItem::mouseMoveEvent(event);
     }



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic