Hello,

On Kubuntu 14.04, the applet have a better look if we don't fill a background. So, I added a 'Transparent Background' checkbox that render the applet with a more similar look that other one.

   I attached the patch if you want.

thanks for this applet!
Daniel Savard
XSOLI


diff --git a/kbstateapplet.cpp b/kbstateapplet.cpp
index 428e186..f6fcf5c 100644
--- a/kbstateapplet.cpp
+++ b/kbstateapplet.cpp
@@ -142,6 +142,11 @@ KbStateWidget::~KbStateWidget() {
    delete m_iconLoader;
 }
 
+bool KbStateWidget::useTransparentBackground() const
+{
+    return transparentBackground;
+}
+
 // Calculates the layout based on a given number of modifiers, lockkeys and accessx features.
 // Output:
 // lines:  number of lines
@@ -588,17 +593,22 @@ void KeyIcon::paintEvent(QPaintEvent *) {
     int x = (width()-locked.width())/2;
     int y = (height()-locked.height())/2;
     int o = 0;
+
     if (isLocked || isLatched) {
-        qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::Selection).shade(KColorScheme::LightShade), true, 1, NULL);
-        p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::Selection).background().color());
+        if (!useTransparentBackground()) {
+            qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::Selection).shade(KColorScheme::LightShade), true, 1, NULL);
+            p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::Selection).background().color());
+        }
         if (strcmp(modifierKeys[keyId].icon, ""))
             p.drawPixmap (x+1,y+1, latched);
         black = KColorScheme(QPalette::Active, KColorScheme::Selection).foreground().color();
         o = 1;
     }
     else {
-        qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::View).shade(KColorScheme::LightShade), false, 1, NULL);
-        p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::View).background().color());
+        if (!useTransparentBackground()) {
+            qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::View).shade(KColorScheme::LightShade), false, 1, NULL);
+            p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::View).background().color());
+        }
         if (strcmp(modifierKeys[keyId].icon, ""))
             p.drawPixmap (x,y, unlatched);
         black = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
@@ -687,8 +697,10 @@ void MouseIcon::updateImages () {
 
 void MouseIcon::paintEvent(QPaintEvent *) {
     QPainter p(this);
-    qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::Selection).shade(KColorScheme::LightShade), true, 1, NULL);
-    p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::View).background().color());
+    if (!useTransparentBackground()) {
+        qDrawShadePanel (&p, 0, 0, width(), height(), KColorScheme(QPalette::Active, KColorScheme::Selection).shade(KColorScheme::LightShade), true, 1, NULL);
+        p.fillRect (1,1,width()-2,height()-2, KColorScheme(QPalette::Active, KColorScheme::View).background().color());
+    }
     p.drawPixmap(0,0, mouse);
     if ((state & Button1Mask) != 0)
         p.drawPixmap(0,0, leftSelected);
@@ -830,6 +842,14 @@ StatusIcon::StatusIcon (const QString &text, QWidget *parent, const char *name)
     setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
 }
 
+bool StatusIcon::useTransparentBackground() const {
+    KbStateWidget *parent = dynamic_cast<KbStateWidget *>(parentWidget());
+    if (parent != NULL) {
+        return parent -> useTransparentBackground();
+    }
+    return false;
+}
+
 StatusIcon::~StatusIcon () {
 }
 
@@ -848,7 +868,7 @@ class KbStateApplet::Private
         KbStateWidget* m_widget;
         QGraphicsProxyWidget* m_proxy;
         QPointer<QWidget> m_configwidget;
-        QCheckBox *m_modifierCheckBox, *lockkeysCheckBox, *mouseCheckBox, *accessxCheckBox;
+        QCheckBox *m_modifierCheckBox, *lockkeysCheckBox, *mouseCheckBox, *accessxCheckBox, *transparentBackgroundCheckBox;
         explicit Private() : m_layout(0), m_widget(0), m_proxy(0), m_configwidget(0) {}
 };
 
@@ -880,6 +900,7 @@ void KbStateApplet::init()
     d->m_widget->showMouse = c.readEntry("Mouse status visible", true);
     d->m_widget->showAccessX = c.readEntry("Slowkeys status visible", true);
     d->m_widget->showAccessX = c.readEntry("AccessX status visible", d->m_widget->showAccessX);
+    d->m_widget->transparentBackground = c.readEntry("Transparent background", false);
 
     d->m_proxy = new QGraphicsProxyWidget(this);
     d->m_proxy->setWidget(d->m_widget);
@@ -924,12 +945,15 @@ void KbStateApplet::createConfigurationInterface(KConfigDialog *parent)
         l->addWidget(d->mouseCheckBox);
         d->accessxCheckBox = new QCheckBox(i18n("Show AccessX Status"), d->m_configwidget);
         l->addWidget(d->accessxCheckBox);
+        d->transparentBackgroundCheckBox = new QCheckBox(i18n("Transparent Background"), d->m_configwidget);
+        l->addWidget(d->transparentBackgroundCheckBox);
     }
 
     d->m_modifierCheckBox->setChecked(d->m_widget->showModifiers);
     d->lockkeysCheckBox->setChecked(d->m_widget->showLockkeys);
     d->mouseCheckBox->setChecked(d->m_widget->showMouse);
     d->accessxCheckBox->setChecked(d->m_widget->showAccessX);
+    d->transparentBackgroundCheckBox->setChecked(d->m_widget->transparentBackground);
 
     parent->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
     parent->addPage(d->m_configwidget, parent->windowTitle(), icon());
@@ -943,12 +967,14 @@ void KbStateApplet::configAccepted()
     d->m_widget->showLockkeys = d->lockkeysCheckBox->isChecked();
     d->m_widget->showMouse = d->mouseCheckBox->isChecked();
     d->m_widget->showAccessX = d->accessxCheckBox->isChecked();
+    d->m_widget->transparentBackground = d->transparentBackgroundCheckBox->isChecked();
 
     KConfigGroup c = config();
     c.writeEntry("Modifierkeys visible", d->m_widget->showModifiers);
     c.writeEntry("Lockkeys visible", d->m_widget->showLockkeys);
     c.writeEntry("Mouse status visible", d->m_widget->showMouse);
     c.writeEntry("AccessX status visible", d->m_widget->showAccessX);
+    c.writeEntry("Transparent background", d->m_widget->transparentBackground);
 
     d->m_widget->updateSettings();
     emit configNeedsSaving();
diff --git a/kbstateapplet.h b/kbstateapplet.h
index ade03bf..7769076 100644
--- a/kbstateapplet.h
+++ b/kbstateapplet.h
@@ -50,6 +50,7 @@ class StatusIcon : public QPushButton {
         Q_OBJECT
     public:
         StatusIcon (const QString &text, QWidget *parent, const char *name=0);
+        bool useTransparentBackground() const;
         ~StatusIcon ();
         QSize minimumSizeHint () const;
 };
@@ -137,6 +138,7 @@ class KbStateWidget : public QWidget {
         int widthForHeight(int height) const;
         int heightForWidth(int width) const;
         int orientation() const;
+        bool useTransparentBackground() const;
         Display* x11Display() const;
     signals:
         void updateLayout();
@@ -163,7 +165,7 @@ class KbStateWidget : public QWidget {
         int state;
         unsigned int accessxFeatures;
         int m_size;
-        bool showModifiers, showLockkeys, showMouse, showAccessX;
+        bool showModifiers, showLockkeys, showMouse, showAccessX, transparentBackground;
         bool fillSpace;
         KComponentData componentData;
         XkbDescPtr xkb;

-- 
Ubuntu-motu mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-motu

Reply via email to