summaryrefslogtreecommitdiff
path: root/src/tabwindow
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-07-25 10:08:59 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:04 +0100
commit6a291bc696903c508ecc55fbd2b4f227d4ef6eef (patch)
tree2eac7be129ac2bc52e7d58ed245188c80fb953af /src/tabwindow
parentCoding style (diff)
downloadrekonq-6a291bc696903c508ecc55fbd2b4f227d4ef6eef.tar.xz
Re-view and re-add tab highlight feature
Diffstat (limited to 'src/tabwindow')
-rw-r--r--src/tabwindow/tabbar.cpp79
-rw-r--r--src/tabwindow/tabbar.h18
-rw-r--r--src/tabwindow/tabhighlighteffect.cpp100
-rw-r--r--src/tabwindow/tabhighlighteffect.h58
-rw-r--r--src/tabwindow/tabwindow.cpp10
5 files changed, 263 insertions, 2 deletions
diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp
index bcb39b10..0bed6e69 100644
--- a/src/tabwindow/tabbar.cpp
+++ b/src/tabwindow/tabbar.cpp
@@ -22,16 +22,33 @@
#include "tabbar.moc"
#include "tabwindow.h"
+#include "tabhighlighteffect.h"
#include <KDebug>
#include <KAcceleratorManager>
#include <KAction>
+#include <KColorScheme>
#include <KLocalizedString>
#include <KMenu>
+#include <QPropertyAnimation>
+#include <QSignalMapper>
+#include <QStyleOptionFrameV3>
+
+
+static inline QByteArray highlightPropertyName(int index)
+{
+ return QByteArray("hAnim").append(QByteArray::number(index));
+}
+
+
+// ------------------------------------------------------------------------------------
+
TabBar::TabBar(QWidget *parent)
: KTabBar(parent)
+ , m_tabHighlightEffect(new TabHighlightEffect(this))
+ , m_animationMapper(new QSignalMapper(this))
{
setElideMode(Qt::ElideRight);
@@ -47,6 +64,11 @@ TabBar::TabBar(QWidget *parent)
connect(this, SIGNAL(contextMenu(int, QPoint)), this, SLOT(contextMenu(int, QPoint)));
connect(this, SIGNAL(emptyAreaContextMenu(QPoint)), this, SLOT(emptyAreaContextMenu(QPoint)));
+
+ // Highlight effect
+ connect(m_animationMapper, SIGNAL(mapped(int)), this, SLOT(removeAnimation(int)));
+ setGraphicsEffect(m_tabHighlightEffect);
+ m_tabHighlightEffect->setEnabled(true);
}
@@ -240,3 +262,60 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos)
menu.exec(pos);
}
+
+
+void TabBar::setTabHighlighted(int index, bool b)
+{
+ if (!b)
+ {
+ removeAnimation(index);
+ setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::NormalText).color());
+
+ return;
+ }
+
+ const QByteArray propertyName = highlightPropertyName(index);
+ const QColor highlightColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color();
+
+ if (tabTextColor(index) != highlightColor)
+ {
+ m_tabHighlightEffect->setEnabled(true);
+ 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);
+ }
+}
+
+
+QRect TabBar::tabTextRect(int index)
+{
+ QStyleOptionTabV3 option;
+ initStyleOption(&option, index);
+ return style()->subElementRect(QStyle::SE_TabBarTabText, &option, this);
+}
+
+
+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;
+
+ if (m_highlightAnimation.isEmpty())
+ m_tabHighlightEffect->setEnabled(false);
+}
diff --git a/src/tabwindow/tabbar.h b/src/tabwindow/tabbar.h
index 9de5fe0a..4cc437ac 100644
--- a/src/tabwindow/tabbar.h
+++ b/src/tabwindow/tabbar.h
@@ -25,6 +25,13 @@
// KDE Includes
#include <KTabBar>
+#include <QPropertyAnimation>
+
+// Forward Declarations
+class TabHighlightEffect;
+
+class QSignalMapper;
+
class TabBar : public KTabBar
{
@@ -33,6 +40,9 @@ class TabBar : public KTabBar
public:
TabBar(QWidget *parent);
+ void setTabHighlighted(int index, bool b);
+ QRect tabTextRect(int index);
+
static const int genericTabNumber = 6;
protected:
@@ -56,6 +66,14 @@ private Q_SLOTS:
void contextMenu(int, const QPoint &);
void emptyAreaContextMenu(const QPoint &);
+
+ void removeAnimation(int index);
+
+private:
+ // highlightAnimation
+ TabHighlightEffect *m_tabHighlightEffect;
+ QHash<QByteArray, QPropertyAnimation*> m_highlightAnimation;
+ QSignalMapper *m_animationMapper;
};
#endif // TAB_BAR
diff --git a/src/tabwindow/tabhighlighteffect.cpp b/src/tabwindow/tabhighlighteffect.cpp
new file mode 100644
index 00000000..121afd15
--- /dev/null
+++ b/src/tabwindow/tabhighlighteffect.cpp
@@ -0,0 +1,100 @@
+/* ============================================================
+*
+* 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"
+
+// Local Includes
+#include "tabbar.h"
+
+// Qt Includes
+#include <QEvent>
+#include <QPainter>
+#include <QVariant>
+
+
+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)
+{
+ const QPixmap &pixmap = sourcePixmap();
+
+ if (pixmap.isNull())
+ return;
+
+ painter->drawPixmap(QPoint(0, 0), pixmap);
+
+ 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);
+
+ if (!boundingRect().contains(textRect))
+ continue;
+
+ 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);
+}
diff --git a/src/tabwindow/tabhighlighteffect.h b/src/tabwindow/tabhighlighteffect.h
new file mode 100644
index 00000000..88302283
--- /dev/null
+++ b/src/tabwindow/tabhighlighteffect.h
@@ -0,0 +1,58 @@
+/* ============================================================
+*
+* 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 <QColor>
+
+// Forward Declarations
+class TabBar;
+
+class QEvent;
+class QPainter;
+
+
+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
diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp
index 772fe3e2..a211f63e 100644
--- a/src/tabwindow/tabwindow.cpp
+++ b/src/tabwindow/tabwindow.cpp
@@ -189,9 +189,9 @@ void TabWindow::pageCreated(WebPage *page)
void TabWindow::currentChanged(int newIndex)
{
- Q_UNUSED(newIndex);
-
_openedTabsCounter = 0;
+
+ tabBar()->setTabHighlighted(newIndex, false);
}
@@ -246,6 +246,12 @@ void TabWindow::tabTitleChanged(const QString &title)
setTabText(index, tabTitle);
}
+ if (currentIndex() != index)
+ {
+ if (tabTitle != i18n("(Untitled)"))
+ tabBar()->setTabHighlighted(index, true);
+ }
+
// TODO: What about window title?
}