From 0033619d3c4dae176e679bc3320afe03e9d4e0d1 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Fri, 3 Sep 2010 15:36:00 +0200 Subject: Fixes the multiple preview/walet bars in a single tab. This also adds a colorful blink effect when an already visible bar is requested again. --- src/CMakeLists.txt | 1 + src/notificationbar.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++ src/notificationbar.h | 49 ++++++++++++++++++++++++++ src/previewselectorbar.cpp | 2 +- src/previewselectorbar.h | 6 ++-- src/walletbar.cpp | 2 +- src/walletbar.h | 5 ++- src/webtab.cpp | 44 ++++++++++++------------ 8 files changed, 164 insertions(+), 31 deletions(-) create mode 100644 src/notificationbar.cpp create mode 100644 src/notificationbar.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef623499..5f99a608 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ SET( rekonq_KDEINIT_SRCS mainwindow.cpp networkaccessmanager.cpp newtabpage.cpp + notificationbar.cpp paneltreeview.cpp previewselectorbar.cpp protocolhandler.cpp diff --git a/src/notificationbar.cpp b/src/notificationbar.cpp new file mode 100644 index 00000000..4325d73b --- /dev/null +++ b/src/notificationbar.cpp @@ -0,0 +1,86 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Pierre Rossi +* +* +* 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 . +* +* ============================================================ */ +#include +#include +#include +#include +#include + +#include "notificationbar.h" + + +class BlinkEffect : public QGraphicsEffect +{ + Q_OBJECT + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) + +public: + BlinkEffect(QObject *parent = 0) + : QGraphicsEffect(parent) + , m_opacity(0) + , m_backgroundColor(QApplication::palette().highlight().color().lighter()) + {} + + qreal opacity() const { return m_opacity; } + void setOpacity(qreal opacity) + { + m_opacity = opacity; + update(); + } + +protected: + void draw(QPainter *painter) + { + painter->drawPixmap(QPoint(0,0), sourcePixmap()); + painter->setOpacity(m_opacity); + painter->fillRect(boundingRect(), m_backgroundColor); + } + +private: + double m_opacity; + QColor m_backgroundColor; + +}; + + +NotificationBar::NotificationBar(QWidget *parent) + : QWidget(parent) + , m_blinkEffect(new BlinkEffect(this)) + , m_opacityAnimation(new QPropertyAnimation(m_blinkEffect, "opacity")) +{ + m_blinkEffect->setOpacity(0); + setGraphicsEffect(m_blinkEffect); +} + +void NotificationBar::notifyUser(int animationDuration) +{ + m_opacityAnimation->setDuration(animationDuration); + m_opacityAnimation->setStartValue(0.9); + m_opacityAnimation->setEndValue(0.0); + m_opacityAnimation->start(); + +} + +#include "notificationbar.moc" diff --git a/src/notificationbar.h b/src/notificationbar.h new file mode 100644 index 00000000..15b0255c --- /dev/null +++ b/src/notificationbar.h @@ -0,0 +1,49 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Pierre Rossi +* +* +* 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 NOTIFICATIONBAR_H +#define NOTIFICATIONBAR_H + +// Qt Includes +#include + +// Forward Declarations +class QPropertyAnimation; +class BlinkEffect; + +class NotificationBar : public QWidget +{ +public: + explicit NotificationBar(QWidget *parent = 0); + + void notifyUser(int animationDuration = 500); + +private: + BlinkEffect *m_blinkEffect; + QPropertyAnimation *m_opacityAnimation; + +}; + +#endif // NOTIFICATIONBAR_H diff --git a/src/previewselectorbar.cpp b/src/previewselectorbar.cpp index 2dcdbeff..209a0a92 100644 --- a/src/previewselectorbar.cpp +++ b/src/previewselectorbar.cpp @@ -51,7 +51,7 @@ PreviewSelectorBar::PreviewSelectorBar(int index, QWidget* parent) - : QWidget(parent) + : NotificationBar(parent) , m_button(0) , m_label(0) , m_previewIndex(index) diff --git a/src/previewselectorbar.h b/src/previewselectorbar.h index ff2c7e2a..214514db 100644 --- a/src/previewselectorbar.h +++ b/src/previewselectorbar.h @@ -30,16 +30,14 @@ // Rekonq Includes #include "rekonq_defines.h" - -// Qt Includes -#include +#include "notificationbar.h" // Forward Declarations class QLabel; class QPushButton; -class REKONQ_TESTS_EXPORT PreviewSelectorBar : public QWidget +class REKONQ_TESTS_EXPORT PreviewSelectorBar : public NotificationBar { Q_OBJECT diff --git a/src/walletbar.cpp b/src/walletbar.cpp index f02c74b8..c2397da9 100644 --- a/src/walletbar.cpp +++ b/src/walletbar.cpp @@ -43,7 +43,7 @@ WalletBar::WalletBar(QWidget *parent) - : QWidget(parent) + : NotificationBar(parent) , m_label(new QLabel(this)) { m_label->setWordWrap(true); diff --git a/src/walletbar.h b/src/walletbar.h index a33dc4d3..afd657f4 100644 --- a/src/walletbar.h +++ b/src/walletbar.h @@ -30,15 +30,14 @@ // Rekonq Includes #include "rekonq_defines.h" +#include "notificationbar.h" // Qt Includes #include -#include class QLabel; - -class REKONQ_TESTS_EXPORT WalletBar : public QWidget +class REKONQ_TESTS_EXPORT WalletBar : public NotificationBar { Q_OBJECT diff --git a/src/webtab.cpp b/src/webtab.cpp index a9a43bd9..02c94d32 100644 --- a/src/webtab.cpp +++ b/src/webtab.cpp @@ -129,35 +129,35 @@ void WebTab::createWalletBar(const QString &key, const QUrl &url) if (blackList.contains(urlString)) return; - if(!_walletBar.isNull()) - { - _walletBar.clear(); + if(_walletBar.isNull()) { + _walletBar = new WalletBar(this); + KWebWallet *wallet = page()->wallet(); + _walletBar.data()->onSaveFormData(key, url); + qobject_cast(layout())->insertWidget(0, _walletBar.data() ); + + connect(_walletBar.data(), SIGNAL(saveFormDataAccepted(const QString &)), + wallet, SLOT(acceptSaveFormDataRequest(const QString &))); + connect(_walletBar.data(), SIGNAL(saveFormDataRejected(const QString &)), + wallet, SLOT(rejectSaveFormDataRequest(const QString &))); + } else { + _walletBar.data()->notifyUser(); } - KWebWallet *wallet = page()->wallet(); - _walletBar = new WalletBar(this); - _walletBar.data()->onSaveFormData(key, url); - qobject_cast(layout())->insertWidget(0, _walletBar.data() ); - - connect(_walletBar.data(), SIGNAL(saveFormDataAccepted(const QString &)), - wallet, SLOT(acceptSaveFormDataRequest(const QString &))); - connect(_walletBar.data(), SIGNAL(saveFormDataRejected(const QString &)), - wallet, SLOT(rejectSaveFormDataRequest(const QString &))); } void WebTab::createPreviewSelectorBar(int index) { - if(!_previewSelectorBar.isNull()) - { - _previewSelectorBar.clear(); + if(_previewSelectorBar.isNull()) { + _previewSelectorBar = new PreviewSelectorBar(index, this); + qobject_cast(layout())->insertWidget(0, _previewSelectorBar.data()); + + connect(page(), SIGNAL(loadStarted()), _previewSelectorBar.data(), SLOT(loadProgress())); + connect(page(), SIGNAL(loadProgress(int)), _previewSelectorBar.data(), SLOT(loadProgress())); + connect(page(), SIGNAL(loadFinished(bool)), _previewSelectorBar.data(), SLOT(loadFinished())); + connect(page()->mainFrame(), SIGNAL(urlChanged(QUrl)), _previewSelectorBar.data(), SLOT(verifyUrl())); + } else { + _previewSelectorBar.data()->notifyUser(); } - _previewSelectorBar = new PreviewSelectorBar(index, this); - qobject_cast(layout())->insertWidget(0, _previewSelectorBar.data()); - - connect(page(), SIGNAL(loadStarted()), _previewSelectorBar.data(), SLOT(loadProgress())); - connect(page(), SIGNAL(loadProgress(int)), _previewSelectorBar.data(), SLOT(loadProgress())); - connect(page(), SIGNAL(loadFinished(bool)), _previewSelectorBar.data(), SLOT(loadFinished())); - connect(page()->mainFrame(), SIGNAL(urlChanged(QUrl)), _previewSelectorBar.data(), SLOT(verifyUrl())); } -- cgit v1.2.1