mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Added opacity effect on tab previews.
This commit is contained in:
parent
e5ce2f5e3d
commit
d03700f917
@ -65,9 +65,15 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
|
|||||||
|
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
||||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||||
connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed()));
|
connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed()));
|
||||||
connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded()));
|
connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded()));
|
||||||
|
|
||||||
|
m_tabPreviewTimer = new QTimer(this);
|
||||||
|
m_tabPreviewTimer->setInterval(200);
|
||||||
|
m_tabPreviewTimer->setSingleShot(true);
|
||||||
|
connect(m_tabPreviewTimer, SIGNAL(timeout()), m_tabPreview, SLOT(hideAnimated()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::loadSettings()
|
void TabBar::loadSettings()
|
||||||
@ -290,6 +296,13 @@ void TabBar::closeCurrentTab()
|
|||||||
m_tabWidget->closeTab(id);
|
m_tabWidget->closeTab(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabBar::currentTabChanged(int index)
|
||||||
|
{
|
||||||
|
Q_UNUSED(index)
|
||||||
|
|
||||||
|
hideTabPreview(false);
|
||||||
|
}
|
||||||
|
|
||||||
void TabBar::bookmarkTab()
|
void TabBar::bookmarkTab()
|
||||||
{
|
{
|
||||||
TabbedWebView* view = p_QupZilla->weView(m_clickedTab);
|
TabbedWebView* view = p_QupZilla->weView(m_clickedTab);
|
||||||
@ -352,13 +365,21 @@ void TabBar::showTabPreview()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_tabPreviewTimer->stop();
|
||||||
m_tabPreview->setWebTab(webTab, m_currentTabPreview == currentIndex());
|
m_tabPreview->setWebTab(webTab, m_currentTabPreview == currentIndex());
|
||||||
m_tabPreview->showOnRect(tabRect(m_currentTabPreview));
|
m_tabPreview->showOnRect(tabRect(m_currentTabPreview));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::hideTabPreview()
|
void TabBar::hideTabPreview(bool delayed)
|
||||||
{
|
{
|
||||||
m_tabPreview->hide();
|
if (delayed) {
|
||||||
|
m_tabPreviewTimer->start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_tabPreview->hideAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_currentTabPreview = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
|
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
@ -401,6 +422,7 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
|
|||||||
int manhattanLength = (event->pos() - m_dragStartPosition).manhattanLength();
|
int manhattanLength = (event->pos() - m_dragStartPosition).manhattanLength();
|
||||||
if (manhattanLength > QApplication::startDragDistance()) {
|
if (manhattanLength > QApplication::startDragDistance()) {
|
||||||
m_tabWidget->buttonAddTab()->hide();
|
m_tabWidget->buttonAddTab()->hide();
|
||||||
|
hideTabPreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +430,7 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
|
|||||||
|
|
||||||
const int tab = tabAt(event->pos());
|
const int tab = tabAt(event->pos());
|
||||||
|
|
||||||
if (tab != -1 && tab != m_currentTabPreview && event->buttons() == Qt::NoButton) {
|
if (tab != -1 && tab != m_currentTabPreview && event->buttons() == Qt::NoButton && m_dragStartPosition.isNull()) {
|
||||||
m_currentTabPreview = tab;
|
m_currentTabPreview = tab;
|
||||||
if (m_tabPreview->isVisible()) {
|
if (m_tabPreview->isVisible()) {
|
||||||
showTabPreview();
|
showTabPreview();
|
||||||
@ -423,6 +445,8 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
|
|||||||
|
|
||||||
void TabBar::mouseReleaseEvent(QMouseEvent* event)
|
void TabBar::mouseReleaseEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
|
m_dragStartPosition = QPoint();
|
||||||
|
|
||||||
if (mApp->plugins()->processMouseRelease(Qz::ON_TabBar, this, event)) {
|
if (mApp->plugins()->processMouseRelease(Qz::ON_TabBar, this, event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -452,7 +476,6 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event)
|
|||||||
void TabBar::leaveEvent(QEvent* event)
|
void TabBar::leaveEvent(QEvent* event)
|
||||||
{
|
{
|
||||||
hideTabPreview();
|
hideTabPreview();
|
||||||
m_currentTabPreview = -1;
|
|
||||||
|
|
||||||
QTabBar::leaveEvent(event);
|
QTabBar::leaveEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void currentTabChanged(int index);
|
||||||
void pinnedTabAdded();
|
void pinnedTabAdded();
|
||||||
void pinnedTabClosed();
|
void pinnedTabClosed();
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ private slots:
|
|||||||
void closeCurrentTab();
|
void closeCurrentTab();
|
||||||
|
|
||||||
void showTabPreview();
|
void showTabPreview();
|
||||||
void hideTabPreview();
|
void hideTabPreview(bool delayed = true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mouseDoubleClickEvent(QMouseEvent* event);
|
void mouseDoubleClickEvent(QMouseEvent* event);
|
||||||
@ -97,6 +98,7 @@ private:
|
|||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
TabWidget* m_tabWidget;
|
TabWidget* m_tabWidget;
|
||||||
TabPreview* m_tabPreview;
|
TabPreview* m_tabPreview;
|
||||||
|
QTimer* m_tabPreviewTimer;
|
||||||
|
|
||||||
bool m_showCloseButtonWithOneTab;
|
bool m_showCloseButtonWithOneTab;
|
||||||
bool m_showTabBarWithOneTab;
|
bool m_showTabBarWithOneTab;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QStyleOptionFrame>
|
#include <QStyleOptionFrame>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
|
|
||||||
TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
|
TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
@ -55,6 +56,11 @@ TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
|
|||||||
setMaximumHeight(170);
|
setMaximumHeight(170);
|
||||||
|
|
||||||
m_animation = new QPropertyAnimation(this, "geometry", this);
|
m_animation = new QPropertyAnimation(this, "geometry", this);
|
||||||
|
m_opacityEffect = new QGraphicsOpacityEffect(this);
|
||||||
|
m_opacityAnimation = new QPropertyAnimation(m_opacityEffect, "opacity", this);
|
||||||
|
|
||||||
|
setGraphicsEffect(m_opacityEffect);
|
||||||
|
m_opacityEffect->setOpacity(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabPreview::setWebTab(WebTab* webTab, bool noPixmap)
|
void TabPreview::setWebTab(WebTab* webTab, bool noPixmap)
|
||||||
@ -75,6 +81,54 @@ void TabPreview::setAnimationsEnabled(bool enabled)
|
|||||||
m_animationsEnabled = enabled;
|
m_animationsEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabPreview::hideAnimated()
|
||||||
|
{
|
||||||
|
if (m_opacityAnimation->state() == QPropertyAnimation::Running) {
|
||||||
|
m_opacityAnimation->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_animationsEnabled) {
|
||||||
|
m_opacityAnimation->setDuration(400);
|
||||||
|
m_opacityAnimation->setStartValue(m_opacityEffect->opacity());
|
||||||
|
m_opacityAnimation->setEndValue(0.0);
|
||||||
|
m_opacityAnimation->start();
|
||||||
|
|
||||||
|
connect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QFrame::hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabPreview::hide()
|
||||||
|
{
|
||||||
|
disconnect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
|
||||||
|
|
||||||
|
QFrame::hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabPreview::show()
|
||||||
|
{
|
||||||
|
if (!isVisible() && m_animationsEnabled) {
|
||||||
|
showAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
QFrame::show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabPreview::showAnimated()
|
||||||
|
{
|
||||||
|
disconnect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
|
||||||
|
|
||||||
|
if (m_opacityAnimation->state() == QPropertyAnimation::Running) {
|
||||||
|
m_opacityAnimation->stop();
|
||||||
|
}
|
||||||
|
m_opacityAnimation->setDuration(400);
|
||||||
|
m_opacityAnimation->setStartValue(m_opacityEffect->opacity());
|
||||||
|
m_opacityAnimation->setEndValue(1.0);
|
||||||
|
m_opacityAnimation->start();
|
||||||
|
}
|
||||||
|
|
||||||
void TabPreview::paintEvent(QPaintEvent* pe)
|
void TabPreview::paintEvent(QPaintEvent* pe)
|
||||||
{
|
{
|
||||||
QStyleOptionFrame opt;
|
QStyleOptionFrame opt;
|
||||||
@ -150,12 +204,20 @@ void TabPreview::showOnRect(const QRect &r)
|
|||||||
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
|
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_animationsEnabled || !wasVisible) {
|
if (!m_animationsEnabled) {
|
||||||
|
m_opacityEffect->setOpacity(1.0);
|
||||||
QFrame::setGeometry(finishingGeometry);
|
QFrame::setGeometry(finishingGeometry);
|
||||||
QFrame::show();
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setFinishingGeometry(oldGeometry, finishingGeometry);
|
showAnimated();
|
||||||
m_animation->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wasVisible) {
|
||||||
|
oldGeometry = finishingGeometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFinishingGeometry(oldGeometry, finishingGeometry);
|
||||||
|
m_animation->start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class WebTab;
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
class QPropertyAnimation;
|
class QPropertyAnimation;
|
||||||
class QParallelAnimationGroup;
|
class QParallelAnimationGroup;
|
||||||
|
class QGraphicsOpacityEffect;
|
||||||
|
|
||||||
class TabPreview : public QFrame
|
class TabPreview : public QFrame
|
||||||
{
|
{
|
||||||
@ -39,10 +39,17 @@ public:
|
|||||||
|
|
||||||
void setAnimationsEnabled(bool enabled);
|
void setAnimationsEnabled(bool enabled);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void hideAnimated();
|
||||||
|
void hide();
|
||||||
|
|
||||||
|
void show();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* pe);
|
void paintEvent(QPaintEvent* pe);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void showAnimated();
|
||||||
void setFinishingGeometry(const QRect &oldGeometry, const QRect &newGeometry);
|
void setFinishingGeometry(const QRect &oldGeometry, const QRect &newGeometry);
|
||||||
QPoint calculatePosition(const QRect &tabRect, const QSize &previewSize);
|
QPoint calculatePosition(const QRect &tabRect, const QSize &previewSize);
|
||||||
|
|
||||||
@ -52,6 +59,8 @@ private:
|
|||||||
|
|
||||||
bool m_animationsEnabled;
|
bool m_animationsEnabled;
|
||||||
QPropertyAnimation* m_animation;
|
QPropertyAnimation* m_animation;
|
||||||
|
QPropertyAnimation* m_opacityAnimation;
|
||||||
|
QGraphicsOpacityEffect* m_opacityEffect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TABPREVIEW_H
|
#endif // TABPREVIEW_H
|
||||||
|
@ -250,25 +250,29 @@ void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
|
|||||||
QPixmap WebTab::renderTabPreview()
|
QPixmap WebTab::renderTabPreview()
|
||||||
{
|
{
|
||||||
WebPage* page = m_view->page();
|
WebPage* page = m_view->page();
|
||||||
const QSize &contentsSize = page->mainFrame()->contentsSize();
|
|
||||||
QSize oldSize = page->viewportSize();
|
QSize oldSize = page->viewportSize();
|
||||||
|
|
||||||
int renderWidth = qMin(contentsSize.width(), 2000);
|
int renderWidth = qMin(page->mainFrame()->contentsSize().width(), 1280);
|
||||||
int renderHeight = qMin(contentsSize.height(), 1500);
|
int renderHeight = renderWidth / 23 * 15;
|
||||||
|
|
||||||
|
const int verticalScrollBarWidth = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
|
||||||
|
const int horizontalScrollBarHeight = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
|
||||||
|
|
||||||
page->setViewportSize(QSize(renderWidth, renderHeight));
|
page->setViewportSize(QSize(renderWidth, renderHeight));
|
||||||
|
|
||||||
|
renderWidth -= verticalScrollBarWidth;
|
||||||
|
renderHeight -= horizontalScrollBarHeight;
|
||||||
|
|
||||||
QPixmap pageImage(renderWidth, renderHeight);
|
QPixmap pageImage(renderWidth, renderHeight);
|
||||||
pageImage.fill(Qt::transparent);
|
pageImage.fill(Qt::transparent);
|
||||||
|
|
||||||
QPainter p(&pageImage);
|
QPainter p(&pageImage);
|
||||||
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer, m_view->visibleRegion());
|
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer);
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
page->setViewportSize(oldSize);
|
page->setViewportSize(oldSize);
|
||||||
|
|
||||||
pageImage = pageImage.scaled(230, 200, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
return pageImage.scaled(230, 150, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
return pageImage.copy(0, 0, 230, 150);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebTab::showNotification(QWidget* notif)
|
void WebTab::showNotification(QWidget* notif)
|
||||||
|
Loading…
Reference in New Issue
Block a user