From fc669e0bf82018baa70a8b59529e1a571d5ad820 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 10 Feb 2011 19:05:45 +0100 Subject: highlights inactive tabs if title changes Courtesy patch by Johannes Troscher. Thanks :) Reviewed by: adjam Reviewed by: elproxy --- src/CMakeLists.txt | 1 + src/mainview.cpp | 6 ++++ src/tabbar.cpp | 45 ++++++++++++++++++++++++++- src/tabbar.h | 7 ++++- src/tabhighlighteffect.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++ src/tabhighlighteffect.h | 52 +++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 src/tabhighlighteffect.cpp create mode 100644 src/tabhighlighteffect.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f9fe19f..e0f75a04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ SET( rekonq_KDEINIT_SRCS protocolhandler.cpp sessionmanager.cpp tabbar.cpp + tabhighlighteffect.cpp urlfilterproxymodel.cpp urlpanel.cpp walletbar.cpp diff --git a/src/mainview.cpp b/src/mainview.cpp index 66c86bc5..af7a9511 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -266,6 +266,8 @@ void MainView::currentChanged(int index) m_widgetBar->currentWidget()->setFocus(); else tab->view()->setFocus(); + + tabBar()->setTabHighlighted(index, false); } @@ -574,6 +576,10 @@ void MainView::webViewTitleChanged(const QString &title) { emit currentTitle(viewTitle); } + else + { + tabBar()->setTabHighlighted(index, true); + } Application::historyManager()->updateHistoryEntry(tab->url(), tabTitle); if (ReKonfig::hoveringTabOption() == 1) tabBar()->setTabToolTip(index, tabTitle.remove('&')); diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 7a8419a3..655b93c0 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -41,18 +41,22 @@ #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 @@ -64,6 +68,7 @@ TabBar::TabBar(QWidget *parent) , m_actualIndex(-1) , m_currentTabPreviewIndex(-1) , m_isFirstTimeOnTab(true) + , m_tabHighlightEffect(new TabHighlightEffect(this)) { setElideMode(Qt::ElideRight); @@ -75,6 +80,8 @@ 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 &))); + + setGraphicsEffect(m_tabHighlightEffect); } @@ -351,7 +358,7 @@ void TabBar::mouseReleaseEvent(QMouseEvent *event) } -void TabBar::tabRemoved(int /*index*/) +void TabBar::tabRemoved(int index) { if (ReKonfig::hoveringTabOption() == 0) { @@ -361,6 +368,9 @@ void TabBar::tabRemoved(int /*index*/) } m_currentTabPreviewIndex = -1; } + + QString propertyName = QString("hAnim").append(QString::number(index)); + setProperty(propertyName.toAscii(), QVariant()); //destroy property } @@ -394,3 +404,36 @@ 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, bool highlighted) +{ + QString propertyName = QString("hAnim").append(QString::number(index)); + if (highlighted) + { + m_tabHighlightEffect->setProperty(propertyName.toAscii(), qreal(0.9)); + QPropertyAnimation *highlightAnimation = new QPropertyAnimation(m_tabHighlightEffect, propertyName.toAscii()); + + //setup the animation + highlightAnimation->setStartValue(0.9); + highlightAnimation->setEndValue(0.0); + highlightAnimation->setDuration(500); + highlightAnimation->setLoopCount(2); + highlightAnimation->start(QAbstractAnimation::DeleteWhenStopped); + + setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color()); + } + else + { + m_tabHighlightEffect->setProperty(propertyName.toAscii(), QVariant()); //destroy the property + setTabTextColor(index, QApplication::palette().text().color()); + } +} \ No newline at end of file diff --git a/src/tabbar.h b/src/tabbar.h index b505f78b..a467e96e 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -39,6 +39,7 @@ // Forward Declarations class KPassivePopup; +class TabHighlightEffect; /** @@ -54,6 +55,9 @@ public: explicit TabBar(QWidget *parent); virtual ~TabBar() {} + void setTabHighlighted(int index, bool highlighted); + QRect tabTextRect(int index); + signals: void cloneTab(int index); void closeTab(int index); @@ -74,7 +78,7 @@ protected: virtual void leaveEvent(QEvent *event); virtual void mousePressEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void tabRemoved(int); + virtual void tabRemoved(int index); private slots: void cloneTab(); @@ -104,6 +108,7 @@ private: */ int m_currentTabPreviewIndex; bool m_isFirstTimeOnTab; + TabHighlightEffect *m_tabHighlightEffect; }; #endif diff --git a/src/tabhighlighteffect.cpp b/src/tabhighlighteffect.cpp new file mode 100644 index 00000000..b03af0f2 --- /dev/null +++ b/src/tabhighlighteffect.cpp @@ -0,0 +1,77 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 Tröscher Johannes +* +* +* 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 the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + +//Self Includes +#include "tabhighlighteffect.h" +#include "tabhighlighteffect.moc" + +//Qt Includes +#include +#include +#include + + +TabHighlightEffect::TabHighlightEffect(TabBar* tabBar) + : QGraphicsEffect (tabBar) + , m_tabBar(tabBar) + , m_highlightColor(QApplication::palette().highlight().color().lighter()) +{ + Q_ASSERT(m_tabBar); +} + +void TabHighlightEffect::draw(QPainter* painter) +{ + painter->drawPixmap(QPoint(0,0), sourcePixmap()); + + Q_FOREACH(const QByteArray &propertyName, dynamicPropertyNames()) + { + int index = QString(propertyName).remove(0,5).toInt(); + qreal opacity = property(propertyName).toReal(); + QRect textRect = m_tabBar->tabTextRect(index); + + QString tabText = m_tabBar->fontMetrics().elidedText(m_tabBar->tabText(index), Qt::ElideRight, + textRect.width(), Qt::TextShowMnemonic); + + painter->setOpacity(opacity); + painter->setPen(m_highlightColor); + painter->drawText(textRect, Qt::AlignCenter | Qt::TextShowMnemonic, tabText); + } +} + +bool TabHighlightEffect::event(QEvent* event) +{ + if (event->type() == QEvent::DynamicPropertyChange) + { + QDynamicPropertyChangeEvent *pChangeEv = dynamic_cast(event); + + if(pChangeEv->propertyName().contains("hAnim")) + { + update(); + return true; + } + } + + return QGraphicsEffect::event(event); +} \ No newline at end of file diff --git a/src/tabhighlighteffect.h b/src/tabhighlighteffect.h new file mode 100644 index 00000000..2459e778 --- /dev/null +++ b/src/tabhighlighteffect.h @@ -0,0 +1,52 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 Tröscher Johannes +* +* +* 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 the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ +#ifndef TABHIGHLIGHTEFFECT_H +#define TABHIGHLIGHTEFFECT_H + +// Qt Includes +#include +#include +#include + +// Forward Declarations +class TabBar; + +class TabHighlightEffect : public QGraphicsEffect +{ + Q_OBJECT + +public: + explicit TabHighlightEffect (TabBar *tabBar = 0); + +protected: + virtual void draw(QPainter *painter); + virtual bool event(QEvent *event); + +private: + TabBar * const m_tabBar; + QColor m_highlightColor; +}; + +#endif // TABHIGHLIGHTEFFECT_H -- cgit v1.2.1