X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/bcb1c6b2328ff5dadf16cb4a0355ad2101780939..bd925ea49a7e4e7c6e652f4529dcd0c4e25fd19a:/src/selectiontoggle.cpp diff --git a/src/selectiontoggle.cpp b/src/selectiontoggle.cpp index 16d3c5979..a2abc49c2 100644 --- a/src/selectiontoggle.cpp +++ b/src/selectiontoggle.cpp @@ -19,6 +19,7 @@ #include "selectiontoggle.h" +#include #include #include #include @@ -36,11 +37,12 @@ SelectionToggle::SelectionToggle(QWidget* parent) : m_icon(), m_fadingTimeLine(0) { + setFocusPolicy(Qt::NoFocus); 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 +117,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 +165,23 @@ 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); + const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects; + const int duration = animate ? 1500 : 1; + + m_fadingTimeLine = new QTimeLine(duration, this); connect(m_fadingTimeLine, SIGNAL(frameChanged(int)), this, SLOT(setFadingValue(int))); m_fadingTimeLine->setFrameRange(0, 255);