]> cloud.milkyroute.net Git - dolphin.git/commitdiff
use different icons dependent on the checked state of the toggle
authorPeter Penz <peter.penz19@gmail.com>
Tue, 12 Feb 2008 01:04:03 +0000 (01:04 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 12 Feb 2008 01:04:03 +0000 (01:04 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=773902

src/selectiontoggle.cpp
src/selectiontoggle.h

index 16d3c5979f3391733fe626947f42ba736298d3cb..eb02edcb274bb4209c462844431a28a0eacade76 100644 (file)
@@ -38,9 +38,9 @@ SelectionToggle::SelectionToggle(QWidget* parent) :
 {
     parent->installEventFilter(this);
     resize(sizeHint());
-    m_icon = KIconLoader::global()->loadIcon("dialog-ok",
-                                             KIconLoader::NoGroup,
-                                             KIconLoader::SizeSmall);
+    setIconOverlay(isChecked());
+    connect(this, SIGNAL(toggled(bool)),
+            this, SLOT(setIconOverlay(bool)));
 }
 
 SelectionToggle::~SelectionToggle()
@@ -115,7 +115,24 @@ void SelectionToggle::paintEvent(QPaintEvent* event)
 {
     QPainter painter(this);
     painter.setClipRect(event->rect());
+    painter.setRenderHint(QPainter::Antialiasing);
+
+    // draw an alpha blended circle as background
+    const QPalette& palette = parentWidget()->palette();
+
+    const QBrush& backgroundBrush = palette.brush(QPalette::Normal, QPalette::Window);
+    QColor background = backgroundBrush.color();
+    background.setAlpha(m_fadingValue / 2);
+    painter.setBrush(background);
+
+    const QBrush& foregroundBrush = palette.brush(QPalette::Normal, QPalette::WindowText);
+    QColor foreground = foregroundBrush.color();
+    foreground.setAlpha(m_fadingValue / 4);
+    painter.setPen(foreground);
+
+    painter.drawEllipse(0, 0, width(), height());
 
+    // draw the icon overlay
     if (m_isHovered) {
         KIconEffect iconEffect;
         QPixmap activeIcon = iconEffect.apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState);
@@ -146,11 +163,20 @@ void SelectionToggle::setFadingValue(int value)
     update();
 }
 
+void SelectionToggle::setIconOverlay(bool checked)
+{
+    const char* icon = checked ? "list-remove" : "list-add";
+    m_icon = KIconLoader::global()->loadIcon(icon,
+                                             KIconLoader::NoGroup,
+                                             KIconLoader::SizeSmall);
+    update();
+}
+
 void SelectionToggle::startFading()
 {
     Q_ASSERT(m_fadingTimeLine == 0);
 
-    m_fadingTimeLine = new QTimeLine(2000, this);
+    m_fadingTimeLine = new QTimeLine(1500, this);
     connect(m_fadingTimeLine, SIGNAL(frameChanged(int)),
             this, SLOT(setFadingValue(int)));
     m_fadingTimeLine->setFrameRange(0, 255);
index a6d5eae580f3ec62444d037b0b5aa9c3ec73fe2b..c303b662fdca6b40df2156fe67fdd8a08872ee87 100644 (file)
@@ -69,6 +69,8 @@ private slots:
      */
     void setFadingValue(int value);
 
+    void setIconOverlay(bool checked);
+
 private:
     void startFading();
     void stopFading();