1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Added animated tab previews (by Alexander Samilovskih)

- thanks a lot for his work!
- option to disable animations in preferences -> tabs
This commit is contained in:
nowrep 2012-04-08 21:45:40 +02:00
parent 283412d85d
commit e5ce2f5e3d
13 changed files with 323 additions and 17 deletions

View File

@ -217,7 +217,7 @@ void BookmarksModel::removeBookmark(const QList<int> list)
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
foreach (int id, list) {
foreach(int id, list) {
QSqlQuery query;
query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?");
query.bindValue(0, id);

View File

@ -34,6 +34,7 @@ INCLUDEPATH += 3rdparty\
popupwindow\
SOURCES += \
webview/tabpreview.cpp \
3rdparty/qtwin.cpp \
3rdparty/lineedit.cpp \
app/qupzilla.cpp \
@ -171,6 +172,7 @@ SOURCES += \
tools/plaineditwithlines.cpp
HEADERS += \
webview/tabpreview.h \
3rdparty/qtwin.h \
3rdparty/lineedit.h \
app/qupzilla.h \

View File

@ -226,7 +226,7 @@ void Plugins::refreshLoadedPlugins()
bool Plugins::alreadySpecInAvailable(const PluginSpec &spec)
{
foreach (const Plugin & plugin, m_availablePlugins) {
foreach(const Plugin & plugin, m_availablePlugins) {
if (plugin.pluginSpec == spec) {
return true;
}

View File

@ -279,7 +279,7 @@ QString SpeedDial::getOpenFileName()
const QString &image = QFileDialog::getOpenFileName(0, tr("Select image..."), QDir::homePath(), fileTypes);
if (image.isEmpty()) {
return image;
return image;
}
return QUrl::fromLocalFile(image).toString();

View File

@ -168,6 +168,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
ui->dontQuitOnTab->setChecked(settings.value("dontQuitWithOneTab", false).toBool());
ui->askWhenClosingMultipleTabs->setChecked(settings.value("AskOnClosing", false).toBool());
ui->closedInsteadOpened->setChecked(settings.value("closedInsteadOpenedTabs", false).toBool());
ui->animatedTabPreviews->setChecked(settings.value("previewAnimationsEnabled", true).toBool());
settings.endGroup();
//AddressBar
settings.beginGroup("AddressBar");
@ -759,6 +760,7 @@ void Preferences::saveSettings()
settings.setValue("dontQuitWithOneTab", ui->dontQuitOnTab->isChecked());
settings.setValue("AskOnClosing", ui->askWhenClosingMultipleTabs->isChecked());
settings.setValue("closedInsteadOpenedTabs", ui->closedInsteadOpened->isChecked());
settings.setValue("previewAnimationsEnabled", ui->animatedTabPreviews->isChecked());
settings.endGroup();
//DOWNLOADS

View File

@ -626,21 +626,21 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="3" column="1" colspan="2">
<widget class="QCheckBox" name="hideTabsOnTab">
<property name="text">
<string>Hide tabs when there is only one tab</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="4">
<item row="11" column="0" colspan="4">
<widget class="QLabel" name="label_25">
<property name="text">
<string>&lt;b&gt;Address Bar behaviour&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="14" column="1">
<item row="15" column="1">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -653,7 +653,7 @@
</property>
</spacer>
</item>
<item row="9" column="1">
<item row="10" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -666,28 +666,28 @@
</property>
</spacer>
</item>
<item row="11" column="1" colspan="3">
<item row="12" column="1" colspan="3">
<widget class="QCheckBox" name="selectAllOnFocus">
<property name="text">
<string>Select all text by double clicking in address bar</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="3">
<item row="14" column="1" colspan="3">
<widget class="QCheckBox" name="addCountryWithAlt">
<property name="text">
<string>Add .co.uk domain by pressing ALT key</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QCheckBox" name="askWhenClosingMultipleTabs">
<property name="text">
<string>Ask when closing multiple tabs</string>
</property>
</widget>
</item>
<item row="12" column="1" colspan="3">
<item row="13" column="1" colspan="3">
<widget class="QCheckBox" name="selectAllOnClick">
<property name="text">
<string>Select all text by clicking in address bar</string>
@ -707,34 +707,41 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="activateLastTab">
<property name="text">
<string>Activate last tab when closing active tab</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QCheckBox" name="dontQuitOnTab">
<property name="text">
<string>Don't quit upon closing last tab</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QCheckBox" name="closedInsteadOpened">
<property name="text">
<string>Closed tabs list instead of opened in tab bar</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QCheckBox" name="openNewTabAfterActive">
<property name="text">
<string>Open new tabs after active tab</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="animatedTabPreviews">
<property name="text">
<string>Make tab previews animated</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="stackedWidgetPage4">

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "tabbar.h"
#include "tabwidget.h"
#include "tabpreview.h"
#include "qupzilla.h"
#include "webtab.h"
#include "iconprovider.h"
@ -29,6 +30,7 @@
#include <QMenu>
#include <QApplication>
#include <QTimer>
#include <QRect>
#define MAXIMUM_TAB_WIDTH 250
#define MINIMUM_TAB_WIDTH 50
@ -45,8 +47,10 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
: QTabBar()
, p_QupZilla(mainClass)
, m_tabWidget(tabWidget)
, m_tabPreview(new TabPreview(mainClass, tabWidget))
, m_clickedTab(0)
, m_pinnedTabsCount(0)
, m_currentTabPreview(-1)
, m_normalTabWidth(0)
, m_lastTabWidth(0)
, m_adjustingLastTab(false)
@ -57,6 +61,7 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
setTabsClosable(true);
setDocumentMode(true);
setFocusPolicy(Qt::NoFocus);
setMouseTracking(true);
setAcceptDrops(true);
@ -71,6 +76,7 @@ void TabBar::loadSettings()
settings.beginGroup("Browser-Tabs-Settings");
setMovable(settings.value("makeTabsMovable", true).toBool());
m_tabPreview->setAnimationsEnabled(settings.value("previewAnimationsEnabled", true).toBool());
if (settings.value("ActivateLastTabWhenClosingActual", false).toBool()) {
setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
@ -107,6 +113,8 @@ void TabBar::setVisible(bool visible)
emit hideButtons();
}
m_tabPreview->setVisible(false);
QTabBar::setVisible(visible);
}
@ -337,6 +345,22 @@ int TabBar::normalTabsCount()
return count() - m_pinnedTabsCount;
}
void TabBar::showTabPreview()
{
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_currentTabPreview));
if (!webTab) {
return;
}
m_tabPreview->setWebTab(webTab, m_currentTabPreview == currentIndex());
m_tabPreview->showOnRect(tabRect(m_currentTabPreview));
}
void TabBar::hideTabPreview()
{
m_tabPreview->hide();
}
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
{
if (mApp->plugins()->processMouseDoubleClick(Qz::ON_TabBar, this, event)) {
@ -380,6 +404,20 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
}
}
//Tab Preview
const int tab = tabAt(event->pos());
if (tab != -1 && tab != m_currentTabPreview && event->buttons() == Qt::NoButton) {
m_currentTabPreview = tab;
if (m_tabPreview->isVisible()) {
showTabPreview();
}
else {
QTimer::singleShot(200, this, SLOT(showTabPreview()));
}
}
QTabBar::mouseMoveEvent(event);
}
@ -411,6 +449,14 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event)
QTabBar::mouseReleaseEvent(event);
}
void TabBar::leaveEvent(QEvent* event)
{
hideTabPreview();
m_currentTabPreview = -1;
QTabBar::leaveEvent(event);
}
void TabBar::wheelEvent(QWheelEvent* event)
{
if (mApp->plugins()->processWheelEvent(Qz::ON_TabBar, this, event)) {

View File

@ -24,6 +24,7 @@
class QupZilla;
class TabWidget;
class TabPreview;
class QT_QUPZILLA_EXPORT TabBar : public QTabBar
{
@ -74,11 +75,15 @@ private slots:
void pinTab();
void closeCurrentTab();
void showTabPreview();
void hideTabPreview();
private:
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void leaveEvent(QEvent* event);
void wheelEvent(QWheelEvent* event);
void dragEnterEvent(QDragEnterEvent* event);
@ -91,12 +96,14 @@ private:
QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
TabPreview* m_tabPreview;
bool m_showCloseButtonWithOneTab;
bool m_showTabBarWithOneTab;
int m_clickedTab;
int m_pinnedTabsCount;
int m_currentTabPreview;
int m_normalTabWidth;
int m_lastTabWidth;

View File

@ -180,7 +180,6 @@ void TabbedWebView::setIp(const QHostInfo &info)
void TabbedWebView::titleChanged()
{
const QString &t = title();
m_tabWidget->setTabToolTip(tabIndex(), t);
if (isCurrent()) {
p_QupZilla->setWindowTitle(tr("%1 - QupZilla").arg(t));

View File

@ -0,0 +1,161 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Alexander Samilovskih <alexsamilovskih@gmail.com>
* David Rosca <nowrep@gmail.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 3 of the License, or
* (at your option) any later version.
*
* 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/>.
* ============================================================ */
#include "qupzilla.h"
#include "tabpreview.h"
#include "webtab.h"
#include "tabbedwebview.h"
#include <QFrame>
#include <QLabel>
#include <QPalette>
#include <QStylePainter>
#include <QVBoxLayout>
#include <QStyleOptionFrame>
#include <QPropertyAnimation>
TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
: QFrame(parent)
, p_QupZilla(mainClass)
, m_pixmap(new QLabel)
, m_title(new QLabel)
, m_animationsEnabled(true)
{
m_pixmap->setAlignment(Qt::AlignHCenter);
m_title->setAlignment(Qt::AlignHCenter);
m_title->setWordWrap(true);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_pixmap);
layout->addWidget(m_title);
layout->setMargin(0);
layout->setAlignment(Qt::AlignCenter);
setLayout(layout);
setBackgroundRole(QPalette::ToolTipBase);
setForegroundRole(QPalette::ToolTipText);
setContentsMargins(5, 5, 5, 5);
setMaximumWidth(250);
setMaximumHeight(170);
m_animation = new QPropertyAnimation(this, "geometry", this);
}
void TabPreview::setWebTab(WebTab* webTab, bool noPixmap)
{
if (webTab->isRestored() && !webTab->isLoading() && !noPixmap) {
m_title->setText(webTab->title());
m_pixmap->setPixmap(webTab->renderTabPreview());
m_pixmap->show();
}
else {
m_title->setText(webTab->title());
m_pixmap->hide();
}
}
void TabPreview::setAnimationsEnabled(bool enabled)
{
m_animationsEnabled = enabled;
}
void TabPreview::paintEvent(QPaintEvent* pe)
{
QStyleOptionFrame opt;
opt.init(this);
QStylePainter painter(this);
painter.setClipRegion(pe->region());
painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
}
void TabPreview::setFinishingGeometry(const QRect &oldGeometry, const QRect &newGeometry)
{
m_animation->setDuration(400);
m_animation->setStartValue(oldGeometry);
m_animation->setEndValue(newGeometry);
}
QPoint TabPreview::calculatePosition(const QRect &tabRect, const QSize &previewSize)
{
QPoint p;
p.setY(tabRect.y() + tabRect.height() + 2);
// Map to center of tab
if (tabRect.width() > previewSize.width()) {
int extraWidth = tabRect.width() - previewSize.width();
p.setX(tabRect.x() + extraWidth / 2);
}
else {
int extraWidth = previewSize.width() - tabRect.width();
p.setX(tabRect.x() - extraWidth / 2);
}
// Ensure the whole preview is always shown
if (p.x() < 0) {
p.setX(0);
}
if (p.x() + previewSize.width() > p_QupZilla->width()) {
int extraWidth = p.x() + previewSize.width() - p_QupZilla->width();
p.setX(p.x() - extraWidth);
}
return p;
}
void TabPreview::showOnRect(const QRect &r)
{
if (m_animation->state() == QPropertyAnimation::Running) {
m_animation->stop();
}
QRect oldGeometry = geometry();
bool wasVisible = isVisible();
resize(QSize(250, 170));
QFrame::show();
QRect finishingGeometry;
if (m_pixmap->isVisible()) {
m_title->setWordWrap(false);
m_title->setText(m_title->fontMetrics().elidedText(m_title->text(), Qt::ElideRight, 240));
QSize previewSize(250, 170);
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
}
else {
m_title->setWordWrap(true);
QSize previewSize = sizeHint();
previewSize.setWidth(qMin(previewSize.width() + 2 * 5, 240));
previewSize.setHeight(qMin(previewSize.height() + 2 * 5, 130));
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
}
if (!m_animationsEnabled || !wasVisible) {
QFrame::setGeometry(finishingGeometry);
QFrame::show();
}
else {
setFinishingGeometry(oldGeometry, finishingGeometry);
m_animation->start();
}
}

View File

@ -0,0 +1,57 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Alexander Samilovskih <alexsamilovskih@gmail.com>
* David Rosca <nowrep@gmail.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 3 of the License, or
* (at your option) any later version.
*
* 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 TABPREVIEW_H
#define TABPREVIEW_H
#include <QFrame>
class QupZilla;
class WebTab;
class QLabel;
class QPropertyAnimation;
class QParallelAnimationGroup;
class TabPreview : public QFrame
{
Q_OBJECT
public:
explicit TabPreview(QupZilla* mainClass, QWidget* parent);
void setWebTab(WebTab* webTab, bool noPixmap);
void showOnRect(const QRect &rect);
void setAnimationsEnabled(bool enabled);
protected:
void paintEvent(QPaintEvent* pe);
private:
void setFinishingGeometry(const QRect &oldGeometry, const QRect &newGeometry);
QPoint calculatePosition(const QRect &tabRect, const QSize &previewSize);
QupZilla* p_QupZilla;
QLabel* m_pixmap;
QLabel* m_title;
bool m_animationsEnabled;
QPropertyAnimation* m_animation;
};
#endif // TABPREVIEW_H

View File

@ -27,6 +27,7 @@
#include <QVBoxLayout>
#include <QWebHistory>
#include <QWebFrame>
#include <QLabel>
WebTab::SavedTab::SavedTab(WebTab* webTab)
@ -226,7 +227,6 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab)
m_view->tabWidget()->setTabIcon(index, tab.icon);
m_view->tabWidget()->setTabText(index, tab.title);
m_view->tabWidget()->setTabToolTip(index, tab.title);
m_locationBar.data()->showUrl(tab.url);
}
else {
@ -247,6 +247,29 @@ void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
p_restoreTab(tab.url, tab.history);
}
QPixmap WebTab::renderTabPreview()
{
WebPage* page = m_view->page();
const QSize &contentsSize = page->mainFrame()->contentsSize();
QSize oldSize = page->viewportSize();
int renderWidth = qMin(contentsSize.width(), 2000);
int renderHeight = qMin(contentsSize.height(), 1500);
page->setViewportSize(QSize(renderWidth, renderHeight));
QPixmap pageImage(renderWidth, renderHeight);
pageImage.fill(Qt::transparent);
QPainter p(&pageImage);
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer, m_view->visibleRegion());
p.end();
page->setViewportSize(oldSize);
pageImage = pageImage.scaled(230, 200, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
return pageImage.copy(0, 0, 230, 150);
}
void WebTab::showNotification(QWidget* notif)
{

View File

@ -91,6 +91,8 @@ public:
void p_restoreTab(const SavedTab &tab);
void p_restoreTab(const QUrl &url, const QByteArray &history);
QPixmap renderTabPreview();
void disconnectObjects();
private slots: