summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/mainview.cpp6
-rw-r--r--src/tabbar.cpp71
-rw-r--r--src/tabbar.h18
-rw-r--r--src/tabhighlighteffect.cpp81
-rw-r--r--src/tabhighlighteffect.h51
6 files changed, 226 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 e321f486..3e173d93 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -267,6 +267,8 @@ void MainView::currentChanged(int index)
m_widgetBar->currentWidget()->setFocus();
else
tab->view()->setFocus();
+
+ tabBar()->resetTabHighlighted(index);
}
@@ -575,6 +577,10 @@ void MainView::webViewTitleChanged(const QString &title)
{
emit currentTitle(viewTitle);
}
+ else
+ {
+ tabBar()->setTabHighlighted(index);
+ }
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..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 <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
#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;
+}
+
diff --git a/src/tabbar.h b/src/tabbar.h
index b505f78b..d0d9d3e6 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -37,8 +37,13 @@
// KDE Includes
#include <KTabBar>
+//Qt Includes
+#include <QSignalMapper>
+
// Forward Declarations
class KPassivePopup;
+class TabHighlightEffect;
+class QPropertyAnimation;
/**
@@ -54,6 +59,10 @@ public:
explicit TabBar(QWidget *parent);
virtual ~TabBar() {}
+ void setTabHighlighted(int index);
+ void resetTabHighlighted(int index);
+ QRect tabTextRect(int index);
+
signals:
void cloneTab(int index);
void closeTab(int index);
@@ -74,7 +83,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();
@@ -88,6 +97,8 @@ private slots:
void showTabPreview();
+ void removeAnimation(int index);
+
private:
void setupHistoryActions();
friend class MainView;
@@ -104,6 +115,11 @@ private:
*/
int m_currentTabPreviewIndex;
bool m_isFirstTimeOnTab;
+
+ //highlightAnimation
+ TabHighlightEffect *m_tabHighlightEffect;
+ QHash<QByteArray, QPropertyAnimation*> m_highlightAnimation;
+ QSignalMapper *m_animationMapper;
};
#endif
diff --git a/src/tabhighlighteffect.cpp b/src/tabhighlighteffect.cpp
new file mode 100644
index 00000000..621263fe
--- /dev/null
+++ b/src/tabhighlighteffect.cpp
@@ -0,0 +1,81 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 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 <QVariant>
+#include <tabbar.h>
+
+const QByteArray prep("hAnim");
+
+TabHighlightEffect::TabHighlightEffect(TabBar *tabBar)
+ : QGraphicsEffect(tabBar)
+ , m_tabBar(tabBar)
+ , m_highlightColor(tabBar->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())
+ {
+ if (!propertyName.startsWith(prep))
+ continue;
+
+ int index = propertyName.right(propertyName.size() - prep.size()).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().startsWith(prep))
+ {
+ 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..26292a9e
--- /dev/null
+++ b/src/tabhighlighteffect.h
@@ -0,0 +1,51 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 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:
+ QColor m_highlightColor;
+ TabBar * const m_tabBar;
+};
+
+#endif // TABHIGHLIGHTEFFECT_H \ No newline at end of file