diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-02-10 19:05:45 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-02-10 19:05:45 +0100 |
commit | fc669e0bf82018baa70a8b59529e1a571d5ad820 (patch) | |
tree | d347c2ffa43d4d2a261b4f4e9a21f623397f280d /src | |
parent | Fix issue 258905: mark window in taskbar when opening link from external apps... (diff) | |
download | rekonq-fc669e0bf82018baa70a8b59529e1a571d5ad820.tar.xz |
highlights inactive tabs if title changes
Courtesy patch by Johannes Troscher. Thanks :)
Reviewed by: adjam
Reviewed by: elproxy
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/mainview.cpp | 6 | ||||
-rw-r--r-- | src/tabbar.cpp | 45 | ||||
-rw-r--r-- | src/tabbar.h | 7 | ||||
-rw-r--r-- | src/tabhighlighteffect.cpp | 77 | ||||
-rw-r--r-- | src/tabhighlighteffect.h | 52 |
6 files changed, 186 insertions, 2 deletions
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 <KActionMenu> #include <KMenu> #include <KPassivePopup> #include <KToolBar> +#include <KColorScheme> // Qt Includes #include <QtGui/QLabel> #include <QtGui/QLayout> #include <QtGui/QMouseEvent> #include <QtGui/QToolButton> +#include <QPropertyAnimation> +#include <QStyleOptionFrameV3> #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 <fritz_van_tom@hotmail.com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + +//Self Includes +#include "tabhighlighteffect.h" +#include "tabhighlighteffect.moc" + +//Qt Includes +#include <QApplication> +#include <QVariant> +#include <tabbar.h> + + +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<QDynamicPropertyChangeEvent*>(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 <fritz_van_tom@hotmail.com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ +#ifndef TABHIGHLIGHTEFFECT_H +#define TABHIGHLIGHTEFFECT_H + +// Qt Includes +#include <QGraphicsEffect> +#include <QPainter> +#include <QEvent> + +// 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 |