X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/652d08c9242ed51d86dba3b2afda9d3b2e9a9cd7..d3496b12310d9fec0e52e537c341e87fcaa2f8b5:/src/views/selectiontoggle.cpp diff --git a/src/views/selectiontoggle.cpp b/src/views/selectiontoggle.cpp index 6608b5821..d602600c5 100644 --- a/src/views/selectiontoggle.cpp +++ b/src/views/selectiontoggle.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Peter Penz * + * Copyright (C) 2008 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -19,23 +19,27 @@ #include "selectiontoggle.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include +#include + SelectionToggle::SelectionToggle(QWidget* parent) : QAbstractButton(parent), m_isHovered(false), m_leftMouseButtonPressed(false), m_fadingValue(0), + m_margin(0), m_icon(), m_fadingTimeLine(0) { @@ -72,6 +76,19 @@ void SelectionToggle::setUrl(const KUrl& url) } } +void SelectionToggle::setMargin(int margin) +{ + if (margin != m_margin) { + m_margin = margin; + update(); + } +} + +int SelectionToggle::margin() const +{ + return m_margin; +} + KUrl SelectionToggle::url() const { return m_url; @@ -90,25 +107,12 @@ void SelectionToggle::setVisible(bool visible) bool SelectionToggle::eventFilter(QObject* obj, QEvent* event) { - if (obj == parent()) { - switch (event->type()) { - case QEvent::Leave: - hide(); - break; - - case QEvent::MouseMove: - if (m_leftMouseButtonPressed) { - // Don't forward mouse move events to the viewport, - // otherwise a rubberband selection will be shown when - // clicking on the selection toggle and moving the mouse - // above the viewport. - return true; - } - break; - - default: - break; - } + if ((obj == parent()) && (event->type() == QEvent::MouseMove) && m_leftMouseButtonPressed) { + // Don't forward mouse move events to the viewport, + // otherwise a rubberband selection will be shown when + // clicking on the selection toggle and moving the mouse + // above the viewport. + return true; } return QAbstractButton::eventFilter(obj, event); @@ -121,7 +125,7 @@ void SelectionToggle::enterEvent(QEvent* event) // if the mouse cursor is above the selection toggle, display // it immediately without fading timer m_isHovered = true; - if (m_fadingTimeLine != 0) { + if (m_fadingTimeLine) { m_fadingTimeLine->stop(); } m_fadingValue = 255; @@ -133,6 +137,7 @@ void SelectionToggle::enterEvent(QEvent* event) void SelectionToggle::leaveEvent(QEvent* event) { QAbstractButton::leaveEvent(event); + m_isHovered = false; update(); } @@ -161,10 +166,11 @@ void SelectionToggle::paintEvent(QPaintEvent* event) painter.setClipRect(event->rect()); // draw the icon overlay + const QPoint pos(m_margin, m_margin); if (m_isHovered) { - KIconEffect iconEffect; - QPixmap activeIcon = iconEffect.apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState); - painter.drawPixmap(0, 0, activeIcon); + KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); + QPixmap activeIcon = iconEffect->apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState); + painter.drawPixmap(pos, activeIcon); } else { if (m_fadingValue < 255) { // apply an alpha mask respecting the fading value to the icon @@ -173,19 +179,20 @@ void SelectionToggle::paintEvent(QPaintEvent* event) const QColor color(m_fadingValue, m_fadingValue, m_fadingValue); alphaMask.fill(color); icon.setAlphaChannel(alphaMask); - painter.drawPixmap(0, 0, icon); + painter.drawPixmap(pos, icon); } else { // no fading is required - painter.drawPixmap(0, 0, m_icon); + painter.drawPixmap(pos, m_icon); } } + } void SelectionToggle::setFadingValue(int value) { m_fadingValue = value; if (m_fadingValue >= 255) { - Q_ASSERT(m_fadingTimeLine != 0); + Q_ASSERT(m_fadingTimeLine); m_fadingTimeLine->stop(); } update(); @@ -194,9 +201,10 @@ void SelectionToggle::setFadingValue(int value) void SelectionToggle::setIconOverlay(bool checked) { const char* icon = checked ? "list-remove" : "list-add"; + const int size = qMin(width() - 2 * m_margin, height() - 2 * m_margin); m_icon = KIconLoader::global()->loadIcon(icon, KIconLoader::NoGroup, - qMin(width(), height())); + size); update(); } @@ -207,7 +215,7 @@ void SelectionToggle::refreshIcon() void SelectionToggle::startFading() { - Q_ASSERT(m_fadingTimeLine == 0); + Q_ASSERT(!m_fadingTimeLine); const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects; const int duration = animate ? 600 : 1; @@ -222,7 +230,7 @@ void SelectionToggle::startFading() void SelectionToggle::stopFading() { - if (m_fadingTimeLine != 0) { + if (m_fadingTimeLine) { m_fadingTimeLine->stop(); delete m_fadingTimeLine; m_fadingTimeLine = 0;