From a619df7d9e26b6c30a57a4652be85e6e2aa0ff5f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 14 Feb 2011 22:41:44 +0100 Subject: Highlights inactive tabs if title changes. Fantastic patch by Johannes Troscher. Reviewed by benjaminp (mainly) and adjam --- src/tabbar.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'src/tabbar.cpp') diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 7a8419a3..6b12a794 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -41,29 +41,41 @@ #include "webpage.h" #include "webtab.h" #include "websnap.h" +#include "tabhighlighteffect.h" // KDE Includes #include #include #include #include +#include // Qt Includes #include #include #include #include +#include +#include #define BASE_WIDTH_DIVISOR 4 #define MIN_WIDTH_DIVISOR 8 +static inline QByteArray highlightPropertyName(int index) +{ + return QByteArray("hAnim").append(QByteArray::number(index)); +} + + TabBar::TabBar(QWidget *parent) : KTabBar(parent) , m_actualIndex(-1) , m_currentTabPreviewIndex(-1) , m_isFirstTimeOnTab(true) + , m_tabHighlightEffect(new TabHighlightEffect(this)) + , m_animationMapper(new QSignalMapper(this)) { setElideMode(Qt::ElideRight); @@ -75,6 +87,9 @@ TabBar::TabBar(QWidget *parent) connect(this, SIGNAL(contextMenu(int, const QPoint &)), this, SLOT(contextMenu(int, const QPoint &))); connect(this, SIGNAL(emptyAreaContextMenu(const QPoint &)), this, SLOT(emptyAreaContextMenu(const QPoint &))); + + connect(m_animationMapper, SIGNAL(mapped(int)), this, SLOT(removeAnimation(int))); + setGraphicsEffect(m_tabHighlightEffect); } @@ -351,7 +366,7 @@ void TabBar::mouseReleaseEvent(QMouseEvent *event) } -void TabBar::tabRemoved(int /*index*/) +void TabBar::tabRemoved(int index) { if (ReKonfig::hoveringTabOption() == 0) { @@ -361,6 +376,8 @@ void TabBar::tabRemoved(int /*index*/) } m_currentTabPreviewIndex = -1; } + + removeAnimation(index); } @@ -394,3 +411,55 @@ void TabBar::setupHistoryActions() am->addAction(a); } } + + +QRect TabBar::tabTextRect(int index) +{ + QStyleOptionTabV3 option; + initStyleOption(&option, index); + return style()->subElementRect(QStyle::SE_TabBarTabText, &option, this); +} + + +void TabBar::setTabHighlighted(int index) +{ + const QByteArray propertyName = highlightPropertyName(index); + const QColor highlightColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color(); + + if (tabTextColor(index) != highlightColor) + { + m_tabHighlightEffect->setProperty(propertyName, qreal(0.9)); + QPropertyAnimation *anim = new QPropertyAnimation(m_tabHighlightEffect, propertyName); + m_highlightAnimation.insert(propertyName, anim); + + //setup the animation + anim->setStartValue(0.9); + anim->setEndValue(0.0); + anim->setDuration(500); + anim->setLoopCount(2); + anim->start(QAbstractAnimation::DeleteWhenStopped); + + m_animationMapper->setMapping(anim, index); + connect(anim, SIGNAL(finished()), m_animationMapper, SLOT(map())); + setTabTextColor(index, highlightColor); + } +} + + +void TabBar::resetTabHighlighted(int index) +{ + removeAnimation(index); + setTabTextColor(index, palette().text().color()); +} + + +void TabBar::removeAnimation(int index) +{ + const QByteArray propertyName = highlightPropertyName(index); + m_tabHighlightEffect->setProperty(propertyName, QVariant()); //destroy the property + + QPropertyAnimation *anim = m_highlightAnimation.take(propertyName); + m_animationMapper->removeMappings(anim); + delete anim; +} + -- cgit v1.2.1