summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-07-25 17:30:52 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:04 +0100
commit197455a6044b66bdfdd479f07f4ad52649816998 (patch)
treeaac283db573bc86c5a9a1c9e8908741a7cc0c448 /src
parentSet window icon & title (diff)
downloadrekonq-197455a6044b66bdfdd479f07f4ad52649816998.tar.xz
Re-add && Re-view tab preview popup
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/tabwindow/tabbar.cpp126
-rw-r--r--src/tabwindow/tabbar.h15
-rw-r--r--src/tabwindow/tabpreviewpopup.cpp124
-rw-r--r--src/tabwindow/tabpreviewpopup.h58
-rw-r--r--src/webwindow/webwindow.cpp52
-rw-r--r--src/webwindow/webwindow.h9
7 files changed, 355 insertions, 30 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 31966664..0143874f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,6 +9,7 @@ set(rekonq_KDEINIT_SRCS
#----------------------------------------
tabwindow/tabbar.cpp
tabwindow/tabhighlighteffect.cpp
+ tabwindow/tabpreviewpopup.cpp
tabwindow/tabwindow.cpp
#----------------------------------------
webwindow/webpage.cpp
diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp
index 0bed6e69..133ece5c 100644
--- a/src/tabwindow/tabbar.cpp
+++ b/src/tabwindow/tabbar.cpp
@@ -23,6 +23,8 @@
#include "tabwindow.h"
#include "tabhighlighteffect.h"
+#include "tabpreviewpopup.h"
+#include "webwindow.h"
#include <KDebug>
#include <KAcceleratorManager>
@@ -34,6 +36,9 @@
#include <QPropertyAnimation>
#include <QSignalMapper>
#include <QStyleOptionFrameV3>
+#include <QMouseEvent>
+#include <QTimer>
+#include <QUrl>
static inline QByteArray highlightPropertyName(int index)
@@ -85,7 +90,7 @@ QSize TabBar::tabSizeHint(int index) const
int minTabWidth = p->sizeHint().width() / genericTabNumber;
int w = baseTabWidth;
- if (count() >= genericTabNumber)
+ if (count() > genericTabNumber)
{
w = minTabWidth;
}
@@ -270,7 +275,6 @@ void TabBar::setTabHighlighted(int index, bool b)
{
removeAnimation(index);
setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::NormalText).color());
-
return;
}
@@ -319,3 +323,121 @@ void TabBar::removeAnimation(int index)
if (m_highlightAnimation.isEmpty())
m_tabHighlightEffect->setEnabled(false);
}
+
+
+void TabBar::tabRemoved(int index)
+{
+ hideTabPreview();
+ removeAnimation(index);
+}
+
+
+void TabBar::mouseMoveEvent(QMouseEvent *event)
+{
+ KTabBar::mouseMoveEvent(event);
+
+ if (count() == 1)
+ {
+ return;
+ }
+
+ // Find the tab under the mouse
+ const int tabIndex = tabAt(event->pos());
+
+ // if found and not the current tab then show tab preview
+ if (tabIndex != -1
+ && tabIndex != currentIndex()
+ && m_currentTabPreviewIndex != tabIndex
+ && event->buttons() == Qt::NoButton
+ )
+ {
+ m_currentTabPreviewIndex = tabIndex;
+
+ // if first time over tab, apply a small delay. If not, show it now!
+ m_isFirstTimeOnTab
+ ? QTimer::singleShot(200, this, SLOT(showTabPreview()))
+ : showTabPreview();
+ }
+
+ // if current tab or not found then hide previous tab preview
+ if (tabIndex == currentIndex() || tabIndex == -1)
+ {
+ hideTabPreview();
+ }
+}
+
+
+void TabBar::leaveEvent(QEvent *event)
+{
+ hideTabPreview();
+ m_isFirstTimeOnTab = true;
+
+ KTabBar::leaveEvent(event);
+}
+
+
+void TabBar::mousePressEvent(QMouseEvent *event)
+{
+ hideTabPreview();
+
+ // just close tab on middle mouse click
+ if (event->button() == Qt::MidButton)
+ return;
+
+ KTabBar::mousePressEvent(event);
+}
+
+
+void TabBar::showTabPreview()
+{
+ if (m_isFirstTimeOnTab)
+ m_isFirstTimeOnTab = false;
+
+ //delete previous tab preview
+ delete m_previewPopup.data();
+ m_previewPopup.clear();
+
+ TabWindow *tabW = qobject_cast<TabWindow *>(parent());
+
+ WebWindow *indexedTab = tabW->webWindow(m_currentTabPreviewIndex);
+ WebWindow *currentTab = tabW->webWindow(currentIndex());
+
+ // check if view && currentView exist before using them :)
+ if (!currentTab || !indexedTab)
+ return;
+
+ // no previews during load
+ if (indexedTab->isLoading())
+ return;
+
+ int w = tabSizeHint(0).width();
+ int h = w * tabW->size().height() / tabW->size().width();
+
+ m_previewPopup = new TabPreviewPopup(indexedTab->tabPreview(w,h), indexedTab->url().toString() , this);
+
+ int tabBarWidth = tabW->size().width();
+ int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - w) / 2;
+
+ if (leftIndex < 0)
+ {
+ leftIndex = 0;
+ }
+ else if (leftIndex + w > tabBarWidth)
+ {
+ leftIndex = tabBarWidth - w;
+ }
+
+ QPoint pos(leftIndex, tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height());
+ m_previewPopup.data()->show(mapToGlobal(pos));
+}
+
+
+void TabBar::hideTabPreview()
+{
+ if (!m_previewPopup.isNull())
+ {
+ m_previewPopup.data()->hide();
+ }
+ m_currentTabPreviewIndex = -1;
+
+}
diff --git a/src/tabwindow/tabbar.h b/src/tabwindow/tabbar.h
index 4cc437ac..af97c998 100644
--- a/src/tabwindow/tabbar.h
+++ b/src/tabwindow/tabbar.h
@@ -28,6 +28,7 @@
#include <QPropertyAnimation>
// Forward Declarations
+class TabPreviewPopup;
class TabHighlightEffect;
class QSignalMapper;
@@ -48,6 +49,12 @@ public:
protected:
virtual QSize tabSizeHint(int index) const;
+ virtual void mouseMoveEvent(QMouseEvent *event);
+ virtual void leaveEvent(QEvent *event);
+ virtual void mousePressEvent(QMouseEvent *event);
+
+ virtual void tabRemoved(int index);
+
Q_SIGNALS:
void cloneTab(int);
void closeTab(int);
@@ -69,11 +76,19 @@ private Q_SLOTS:
void removeAnimation(int index);
+ void showTabPreview();
+ void hideTabPreview();
+
private:
// highlightAnimation
TabHighlightEffect *m_tabHighlightEffect;
QHash<QByteArray, QPropertyAnimation*> m_highlightAnimation;
QSignalMapper *m_animationMapper;
+
+ // tab preview
+ QWeakPointer<TabPreviewPopup> m_previewPopup;
+ int m_currentTabPreviewIndex;
+ bool m_isFirstTimeOnTab;
};
#endif // TAB_BAR
diff --git a/src/tabwindow/tabpreviewpopup.cpp b/src/tabwindow/tabpreviewpopup.cpp
new file mode 100644
index 00000000..2a05c414
--- /dev/null
+++ b/src/tabwindow/tabpreviewpopup.cpp
@@ -0,0 +1,124 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 by Vyacheslav Blinov <blinov dot vyacheslav at gmail dot com>
+* Copyright (C) 2011-2012 by Andrea Diamantini <adjam7 at gmail dot 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 "tabpreviewpopup.h"
+#include "tabpreviewpopup.moc"
+
+// Rekonq Includes
+#include "tabbar.h"
+
+// Qt Includes
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QPalette>
+#include <QBitmap>
+#include <QPoint>
+#include <QPaintEvent>
+#include <QStylePainter>
+#include <QStyleOptionFrame>
+
+
+TabPreviewPopup::TabPreviewPopup(const QPixmap &pixmap, const QString &urlText, QWidget *parent)
+ : KPassivePopup(parent),
+ m_thumbLabel(new QLabel(this)),
+ m_urlLabel(new QLabel(this))
+{
+ m_thumbLabel->setAlignment(Qt::AlignHCenter);
+ m_urlLabel->setAlignment(Qt::AlignHCenter);
+
+ QVBoxLayout *vb = new QVBoxLayout(this);
+ vb->addWidget(m_thumbLabel);
+ vb->addWidget(m_urlLabel);
+ this->setLayout(vb);
+
+ layout()->setAlignment(Qt::AlignTop);
+ layout()->setMargin(0);
+
+ setPopupStyle(KPassivePopup::CustomStyle + 1);
+
+ // use ToolTip appearance
+ QPalette p;
+
+ // adjust background color to use tooltip colors
+ p.setColor(backgroundRole(), p.color(QPalette::ToolTipBase));
+ p.setColor(QPalette::Base, p.color(QPalette::ToolTipBase));
+
+ // adjust foreground color to use tooltip colors
+ p.setColor(foregroundRole(), p.color(QPalette::ToolTipText));
+ p.setColor(QPalette::Text, p.color(QPalette::ToolTipText));
+
+ setPalette(p);
+
+ // window flags and attributes
+ setWindowFlags(Qt::ToolTip);
+ setAttribute(Qt::WA_TranslucentBackground);
+ setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0);
+
+ // margins
+ const int margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this);
+ setContentsMargins(margin, margin, margin, margin);
+
+ m_thumbLabel->setPixmap(pixmap);
+ m_urlLabel->setText(urlText);
+
+ setFixedSize(pixmap.width(), pixmap.height() + m_urlLabel->heightForWidth(pixmap.width()));
+}
+
+
+TabPreviewPopup::~TabPreviewPopup()
+{
+ delete m_thumbLabel;
+ delete m_urlLabel;
+}
+
+
+void TabPreviewPopup::setFixedSize(int w, int h)
+{
+ KPassivePopup::setFixedSize(w, h);
+ const int margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this);
+ m_urlLabel->setText(m_urlLabel->fontMetrics().elidedText(m_urlLabel->text(), Qt::ElideMiddle, this->width() - margin * 2));
+
+ //calculate mask
+ QStyleOptionFrame opt;
+ opt.init(this);
+
+ QStyleHintReturnMask mask;
+ style()->styleHint(QStyle::SH_ToolTip_Mask, &opt, this, &mask);
+ setMask(mask.region);
+}
+
+
+void TabPreviewPopup::paintEvent(QPaintEvent* event)
+{
+ QStyleOptionFrame opt;
+ opt.init(this);
+
+ QStylePainter painter(this);
+ painter.setClipRegion(event->region());
+ painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
+}
diff --git a/src/tabwindow/tabpreviewpopup.h b/src/tabwindow/tabpreviewpopup.h
new file mode 100644
index 00000000..b496f60f
--- /dev/null
+++ b/src/tabwindow/tabpreviewpopup.h
@@ -0,0 +1,58 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 by Vyacheslav Blinov <blinov dot vyacheslav at gmail dot com>
+* Copyright (C) 2011-2012 by Andrea Diamantini <adjam7 at gmail dot 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 TABPREVIEWPOPUP_H
+#define TABPREVIEWPOPUP_H
+
+// KDE Includes
+#include <KPassivePopup>
+
+// forward declatrations
+class QLabel;
+class QPixmap;
+class QString;
+
+class TabPreviewPopup : public KPassivePopup
+{
+ Q_OBJECT
+
+public:
+ TabPreviewPopup(const QPixmap &pixmap, const QString &urlText, QWidget *parent = 0);
+ virtual ~TabPreviewPopup();
+
+private:
+ void setFixedSize(int w, int h);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ QLabel *m_thumbLabel;
+ QLabel *m_urlLabel;
+};
+
+#endif // TABPREVIEWPOPUP_H
diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp
index 6d0d4d72..4b94414a 100644
--- a/src/webwindow/webwindow.cpp
+++ b/src/webwindow/webwindow.cpp
@@ -32,37 +32,14 @@
WebWindow::WebWindow(QWidget *parent)
: QWidget(parent)
+ , _progress(0)
, _view(new QWebView(this))
, _edit(new QLineEdit(this))
{
WebPage *p = new WebPage(_view);
_view->setPage(p);
- // layout
- QVBoxLayout *l = new QVBoxLayout;
- l->addWidget(_edit);
- l->addWidget(_view);
- l->setContentsMargins(0, 0, 0, 0);
- setLayout(l);
-
- setContentsMargins(0, 0, 0, 0);
-
- // line edit signals
- connect(_edit, SIGNAL(returnPressed()), this, SLOT(checkLoadUrl()));
-
- // url signal
- connect(_view, SIGNAL(urlChanged(QUrl)), this, SLOT(setUrlText(QUrl)));
-
- // things changed signals
- connect(_view, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString)));
-
- // load signals
- connect(_view, SIGNAL(loadStarted()), this, SIGNAL(loadStarted()));
- connect(_view, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int)));
- connect(_view, SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
-
- // page signals
- connect(p, SIGNAL(pageCreated(WebPage *)), this, SIGNAL(pageCreated(WebPage *)));
+ init();
}
@@ -74,6 +51,12 @@ WebWindow::WebWindow(WebPage *page, QWidget *parent)
_view->setPage(page);
page->setParent(_view);
+ init();
+}
+
+
+void WebWindow::init()
+{
// layout
QVBoxLayout *l = new QVBoxLayout;
l->addWidget(_edit);
@@ -94,12 +77,12 @@ WebWindow::WebWindow(WebPage *page, QWidget *parent)
// load signals
connect(_view, SIGNAL(loadStarted()), this, SIGNAL(loadStarted()));
- connect(_view, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int)));
connect(_view, SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
- // page signals
- connect(page, SIGNAL(pageCreated(WebPage *)), this, SIGNAL(pageCreated(WebPage *)));
+ connect(_view, SIGNAL(loadProgress(int)), this, SLOT(checkLoadProgress(int)));
+ // page signals
+ connect(page(), SIGNAL(pageCreated(WebPage *)), this, SIGNAL(pageCreated(WebPage *)));
}
@@ -133,6 +116,13 @@ void WebWindow::setUrlText(const QUrl &u)
}
+void WebWindow::checkLoadProgress(int p)
+{
+ _progress = p;
+ emit loadProgress(p);
+}
+
+
QUrl WebWindow::url() const
{
return _view->url();
@@ -155,3 +145,9 @@ QPixmap WebWindow::tabPreview(int width, int height)
{
return WebSnap::renderPagePreview(*page(), width, height);
}
+
+
+bool WebWindow::isLoading()
+{
+ return _progress != 0 && _progress != 100;
+}
diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h
index 189f111f..fdcb0383 100644
--- a/src/webwindow/webwindow.h
+++ b/src/webwindow/webwindow.h
@@ -51,10 +51,17 @@ public:
QPixmap tabPreview(int width, int height);
+ bool isLoading();
+
+private:
+ void init();
+
private Q_SLOTS:
void checkLoadUrl();
void setUrlText(const QUrl &);
+ void checkLoadProgress(int);
+
Q_SIGNALS:
void titleChanged(QString);
@@ -65,6 +72,8 @@ Q_SIGNALS:
void pageCreated(WebPage *);
private:
+ int _progress;
+
QWebView *_view;
QLineEdit *_edit;
};