Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Diff by qqq ( 6 years ago )
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b60e9899..20534cb5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -347,6 +347,15 @@ qt5_wrap_ui(otter_ui
 	src/modules/windows/windows/WindowsContentsWidget.ui
 )
 
+foreach(_current_dir ${Qt5Widgets_PRIVATE_INCLUDE_DIRS})
+	if (EXISTS "${_current_dir}/private/qpixmapfilter_p.h")
+		add_definitions(-DOTTER_ENABLE_STARTPAGEBLUR)
+		include_directories(${Qt5Widgets_PRIVATE_INCLUDE_DIRS})
+
+		break()
+	endif()
+endforeach()
+
 if (Qt5WebEngineWidgets_FOUND AND ENABLE_QTWEBENGINE)
 	add_definitions(-DOTTER_ENABLE_QTWEBENGINE)
 
diff --git a/src/modules/windows/web/StartPageWidget.cpp b/src/modules/windows/web/StartPageWidget.cpp
index eb9e8b5db..46733d9be 100644
--- a/src/modules/windows/web/StartPageWidget.cpp
+++ b/src/modules/windows/web/StartPageWidget.cpp
@@ -46,6 +46,9 @@
 #include <QtWidgets/QGridLayout>
 #include <QtWidgets/QScrollBar>
 #include <QtWidgets/QToolTip>
+#ifdef OTTER_ENABLE_STARTPAGEBLUR
+#include <QtWidgets/private/qpixmapfilter_p.h>
+#endif
 
 namespace Otter
 {
@@ -54,7 +57,8 @@ StartPageModel* StartPageWidget::m_model(nullptr);
 Animation* StartPageWidget::m_spinnerAnimation(nullptr);
 QPointer<StartPagePreferencesDialog> StartPageWidget::m_preferencesDialog(nullptr);
 
-TileDelegate::TileDelegate(QObject *parent) : QStyledItemDelegate(parent),
+TileDelegate::TileDelegate(QWidget *parent) : QStyledItemDelegate(parent),
+	m_widget(parent),
 	m_mode(NoBackground)
 {
 	handleOptionChanged(SettingsManager::StartPage_TileBackgroundModeOption, SettingsManager::getOption(SettingsManager::StartPage_TileBackgroundModeOption));
@@ -71,8 +75,16 @@ void TileDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
 	QRect rectangle(option.rect);
 	rectangle.adjust(10, 10, -10, -10);
 
+	const QRect tileRectangle(rectangle);
+
+	if (m_mode != NoBackground)
+	{
+		rectangle.adjust(0, 0, 0, -textHeight);
+	}
+
+	const QRect textRectangle(QRect(rectangle.x(), (rectangle.y() + rectangle.height()), rectangle.width(), textHeight));
 	QPainterPath path;
-	path.addRoundedRect(rectangle, 5, 5);
+	path.addRoundedRect(tileRectangle, 5, 5);
 
 	painter->setRenderHint(QPainter::HighQualityAntialiasing);
 
@@ -96,7 +108,9 @@ void TileDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
 	{
 		if (isAddTile)
 		{
-			painter->setBrush(QColor(179, 229, 252, 224));
+			painter->setBrush(QColor(179, 229, 252, 160));
+
+			drawBlurBehind(painter, tileRectangle);
 		}
 		else
 		{
@@ -107,20 +121,30 @@ void TileDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
 
 		if (isAddTile)
 		{
-			ThemesManager::createIcon(QLatin1String("list-add")).paint(painter, rectangle);
+			ThemesManager::createIcon(QLatin1String("list-add")).paint(painter, tileRectangle);
 		}
 
 		return;
 	}
 
 	painter->setClipPath(path);
-	painter->fillRect(rectangle, QColor(179, 229, 252, 128));
 
-	if (m_mode != NoBackground)
+	switch (m_mode)
 	{
-		rectangle.adjust(0, 0, 0, -textHeight);
+		case FaviconBackground:
+			drawBlurBehind(painter, tileRectangle);
+
+			break;
+		case ThumbnailBackground:
+			drawBlurBehind(painter, textRectangle);
+
+			break;
+		default:
+			break;
 	}
 
+	painter->fillRect(tileRectangle, QColor(179, 229, 252, 128));
+
 	if (m_mode != NoBackground && static_cast<BookmarksModel::BookmarkType>(index.data(BookmarksModel::TypeRole).toInt()) == BookmarksModel::FolderBookmark)
 	{
 		ThemesManager::createIcon(QLatin1String("inode-directory")).paint(painter, rectangle, Qt::AlignCenter, (index.data(StartPageModel::IsEmptyRole).toBool() ? QIcon::Disabled : QIcon::Normal));
@@ -181,10 +205,42 @@ void TileDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
 	}
 	else
 	{
-		painter->drawText(QRect(rectangle.x(), (rectangle.y() + rectangle.height()), rectangle.width(), textHeight), Qt::AlignCenter, option.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), option.textElideMode, (rectangle.width() - 20)));
+		painter->drawText(textRectangle, Qt::AlignCenter, option.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), option.textElideMode, (rectangle.width() - 20)));
 	}
 }
 
+void TileDelegate::drawBlurBehind(QPainter *painter, const QRect &rectangle) const
+{
+#ifdef OTTER_ENABLE_STARTPAGEBLUR
+	QRect parentRectangle;
+	parentRectangle.setTopLeft(m_widget->mapToParent(rectangle.topLeft()));
+	parentRectangle.setBottomRight(m_widget->mapToParent(rectangle.bottomRight()));
+	parentRectangle.adjust(-10, -10, 10, 10);
+
+	QPixmap parentPixmap(parentRectangle.size());
+	parentPixmap.fill(Qt::transparent);
+
+	m_widget->parentWidget()->render(&parentPixmap, {}, QRegion(parentRectangle), (QWidget::DrawWindowBackground | QWidget::IgnoreMask));
+
+	QPixmap blurredPixmap(parentRectangle.size());
+	blurredPixmap.fill(Qt::transparent);
+
+	QPainter blurredPainter(&blurredPixmap);
+	QPixmapBlurFilter filter;
+	filter.setBlurHints(QGraphicsBlurEffect::PerformanceHint);
+	filter.setRadius(5);
+	filter.draw(&blurredPainter, {}, parentPixmap);
+
+	QRect blurredRectangle(rectangle);
+	blurredRectangle.moveTo(10, 10);
+
+	painter->drawPixmap(rectangle, blurredPixmap, blurredRectangle);
+#else
+	Q_UNUSED(painter)
+	Q_UNUSED(rectangle)
+#endif
+}
+
 void TileDelegate::handleOptionChanged(int identifier, const QVariant &value)
 {
 	if (identifier == SettingsManager::StartPage_TileBackgroundModeOption)
diff --git a/src/modules/windows/web/StartPageWidget.h b/src/modules/windows/web/StartPageWidget.h
index 090fd41a7..59504b86e 100644
--- a/src/modules/windows/web/StartPageWidget.h
+++ b/src/modules/windows/web/StartPageWidget.h
@@ -49,15 +49,19 @@ public:
 		ThumbnailBackground
 	};
 
-	explicit TileDelegate(QObject *parent = nullptr);
+	explicit TileDelegate(QWidget *parent = nullptr);
 
 	void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
 	QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
 
+protected:
+	void drawBlurBehind(QPainter *painter, const QRect &rectangle) const;
+
 protected slots:
 	void handleOptionChanged(int identifier, const QVariant &value);
 
 private:
+	QWidget *m_widget;
 	BackgroundMode m_mode;
 };

 

Revise this Paste

Your Name: Code Language: