KDE/kdebase/workspace/plasma/generic/applets/devicenotifier

Jacopo De Simoi wilderkde at gmail.com
Wed Jul 14 20:10:42 CEST 2010


SVN commit 1149977 by jacopods:

First attempt to get rid of the capacity bar in the device notifier: use a Plasma::Meter with tooltips.
Screenshot: http://imagebin.ca/view/ccJ3dD.html

Feedback is more than welcome
CCMAIL:plasma-devel at kde.org


 M  +17 -17    deviceitem.cpp  
 M  +3 -2      deviceitem.h  


--- trunk/KDE/kdebase/workspace/plasma/generic/applets/devicenotifier/deviceitem.cpp #1149976:1149977
@@ -33,7 +33,6 @@
 #include <KStandardDirs>
 #include <KDesktopFile>
 #include <KGlobalSettings>
-#include <kcapacitybar.h>
 #include <kdesktopfileactions.h>
 
 //Plasma
@@ -42,6 +41,7 @@
 #include <Plasma/BusyWidget>
 #include <Plasma/ItemBackground>
 #include <Plasma/Label>
+#include <Plasma/Meter>
 #include <Plasma/Animator>
 #include <Plasma/Animation>
 
@@ -107,16 +107,16 @@
     m_descriptionLabel->setOpacity(0);
     updateColors();
 
-    KCapacityBar *capacityBarWidget = new KCapacityBar(KCapacityBar::DrawTextInline);
-    m_capacityBar = new QGraphicsProxyWidget(this);
-    m_capacityBar->setWidget(capacityBarWidget);
-    capacityBarWidget->setAttribute(Qt::WA_TranslucentBackground);
-    capacityBarWidget->setContinuous(true);
-    m_capacityBar->setAcceptHoverEvents(false);
-    m_capacityBar->setOpacity(0);
+
+    m_freeSpaceBar = new Plasma::Meter();
+    m_freeSpaceBar->setMeterType(Plasma::Meter::BarMeterHorizontal);
+    m_freeSpaceBar->setLabelAlignment(0, Qt::AlignCenter);
+    m_freeSpaceBar->setOpacity(0);
+    m_freeSpaceBar->setMaximumHeight(12);
+
     info_layout->addItem(m_nameLabel);
     info_layout->addItem(m_descriptionLabel);
-    info_layout->addItem(m_capacityBar);
+    info_layout->addItem(m_freeSpaceBar);
 
     m_leftActionIcon = new Plasma::IconWidget(this);
     m_leftActionIcon->setMaximumSize(m_leftActionIcon->sizeFromIconSize(LEFTACTION_SIZE));
@@ -317,9 +317,9 @@
         }
     }
 
-    const bool barVisible = m_capacityBar->isVisible();
-    m_capacityBar->setVisible(m_mounted && allowsCapacityBar());
-    if (!barVisible && m_capacityBar->isVisible()) {
+    const bool barVisible = m_freeSpaceBar->isVisible();
+    m_freeSpaceBar->setVisible(m_mounted && allowsCapacityBar());
+    if (!barVisible && m_freeSpaceBar->isVisible()) {
         // work around for a QGraphicsLayout bug when used with proxy widgets
         m_mainLayout->invalidate();
     }
@@ -360,7 +360,7 @@
             m_barFade = Plasma::Animator::create(Plasma::Animator::FadeAnimation, this);
 
             m_labelFade->setTargetWidget(m_descriptionLabel);
-            m_barFade->setTargetWidget(m_capacityBar);
+            m_barFade->setTargetWidget(m_freeSpaceBar);
 
             m_labelFade->setProperty("targetOpacity", 0);
             m_barFade->setProperty("targetOpacity", 0);
@@ -378,15 +378,15 @@
 void DeviceItem::setHoverDisplayOpacity(qreal opacity)
 {
     m_descriptionLabel->setOpacity(opacity);
-    m_capacityBar->setOpacity(opacity);
+    m_freeSpaceBar->setOpacity(opacity);
 }
 
 void DeviceItem::setFreeSpace(qulonglong freeSpace, qulonglong size)
 {
     qulonglong usedSpace = size - freeSpace;
-    KCapacityBar *capacityBarWidget = static_cast<KCapacityBar*>(m_capacityBar->widget());
-    capacityBarWidget->setText(i18nc("@info:status Free disk space", "%1 free", KGlobal::locale()->formatByteSize(freeSpace)));
-    capacityBarWidget->setValue(size > 0 ? (usedSpace * 100) / size : 0);
+
+    m_freeSpaceBar->setToolTip(i18nc("@info:status Free disk space", "%1 free", KGlobal::locale()->formatByteSize(freeSpace)));
+    m_freeSpaceBar->setValue(size > 0 ? (usedSpace * 100) / size : 0);
 }
 
 void DeviceItem::leftActionClicked()
--- trunk/KDE/kdebase/workspace/plasma/generic/applets/devicenotifier/deviceitem.h #1149976:1149977
@@ -33,6 +33,7 @@
     class IconWidget;
     class BusyWidget;
     class Label;
+    class Meter;
 }
 
 namespace Notifier
@@ -332,8 +333,8 @@
         ///The label that draws the description of the device
         Plasma::Label *m_descriptionLabel;
 
-        ///The proxy hosting the capacity bar
-        QGraphicsProxyWidget *m_capacityBar;
+        ///The meter that draws free space for the device
+        Plasma::Meter *m_freeSpaceBar;
 
         ///The busy widget
         Plasma::BusyWidget *m_busyWidget;


More information about the Plasma-devel mailing list