mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
Add background blur effect
Change-Id: I87f33cdd45fb9723960ade98978de378638b9ee8
This commit is contained in:
parent
395cd66b23
commit
8cb3c7de59
Notes:
Deepin Code Review
2017-02-16 14:29:15 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: Hualet Wang <mr.asianwang@gmail.com> Submitted-by: Hualet Wang <mr.asianwang@gmail.com> Submitted-at: Thu, 16 Feb 2017 14:29:15 +0800 Reviewed-on: https://cr.deepin.io/20252 Project: dde/dde-dock Branch: refs/heads/master
@ -1,7 +1,7 @@
|
||||
|
||||
include(../interfaces/interfaces.pri)
|
||||
|
||||
QT += core gui widgets dbus x11extras svg
|
||||
QT += core gui widgets dbus x11extras svg
|
||||
|
||||
TARGET = dde-dock
|
||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||
|
@ -16,11 +16,18 @@ MainPanel::MainPanel(QWidget *parent)
|
||||
m_itemLayout(new QBoxLayout(QBoxLayout::LeftToRight)),
|
||||
|
||||
m_itemAdjustTimer(new QTimer(this)),
|
||||
m_itemController(DockItemController::instance(this))
|
||||
m_itemController(DockItemController::instance(this)),
|
||||
|
||||
m_updateEffectTimer(new QTimer(this)),
|
||||
m_effectWidget(new DBlurEffectWidget(this))
|
||||
{
|
||||
m_itemLayout->setSpacing(0);
|
||||
m_itemLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_effectWidget->setMaskColor(QColor(10, 10, 10));
|
||||
m_effectWidget->setBlendMode(DBlurEffectWidget::BehindWindowBlend);
|
||||
m_effectWidget->setDisabled(true);
|
||||
|
||||
setAcceptDrops(true);
|
||||
setAccessibleName("dock-mainpanel");
|
||||
setObjectName("MainPanel");
|
||||
@ -74,10 +81,14 @@ MainPanel::MainPanel(QWidget *parent)
|
||||
connect(m_itemController, &DockItemController::itemManaged, this, &MainPanel::manageItem);
|
||||
connect(m_itemController, &DockItemController::itemUpdated, m_itemAdjustTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_itemAdjustTimer, &QTimer::timeout, this, &MainPanel::adjustItemSize, Qt::QueuedConnection);
|
||||
connect(m_updateEffectTimer, &QTimer::timeout, this, &MainPanel::updateBlurEffect, Qt::QueuedConnection);
|
||||
|
||||
m_itemAdjustTimer->setSingleShot(true);
|
||||
m_itemAdjustTimer->setInterval(100);
|
||||
|
||||
m_updateEffectTimer->setSingleShot(true);
|
||||
m_updateEffectTimer->setInterval(100);
|
||||
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
@ -105,6 +116,7 @@ void MainPanel::updateDockPosition(const Position dockPosition)
|
||||
}
|
||||
|
||||
m_itemAdjustTimer->start();
|
||||
m_updateEffectTimer->start();
|
||||
}
|
||||
|
||||
///
|
||||
@ -125,6 +137,8 @@ void MainPanel::updateDockDisplayMode(const DisplayMode displayMode)
|
||||
|
||||
// reload qss
|
||||
setStyleSheet(styleSheet());
|
||||
|
||||
m_updateEffectTimer->start();
|
||||
}
|
||||
|
||||
///
|
||||
@ -149,6 +163,8 @@ void MainPanel::moveEvent(QMoveEvent* e)
|
||||
{
|
||||
QFrame::moveEvent(e);
|
||||
|
||||
m_updateEffectTimer->start();
|
||||
|
||||
emit geometryChanged();
|
||||
}
|
||||
|
||||
@ -157,24 +173,16 @@ void MainPanel::paintEvent(QPaintEvent *e)
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter p(this);
|
||||
if (m_displayMode == Dock::Efficient)
|
||||
{
|
||||
p.fillRect(rect(), QColor(10, 10, 10, 255 * 0.6));
|
||||
return;
|
||||
} else {
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
if (m_displayMode == Dock::Fashion) {
|
||||
QPen pen;
|
||||
pen.setWidth(1);
|
||||
pen.setColor(QColor(162, 162, 162, 255 * 0.2));
|
||||
|
||||
QBrush brush(QColor(10, 10, 10, 255 * 0.6));
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
const QRect r = rect();
|
||||
// border radius
|
||||
const int br = 8;
|
||||
// background radius
|
||||
const int bgr = 7;
|
||||
|
||||
// draw border
|
||||
QRect borderRect = r;
|
||||
@ -189,17 +197,6 @@ void MainPanel::paintEvent(QPaintEvent *e)
|
||||
p.setPen(pen);
|
||||
p.setBrush(Qt::transparent);
|
||||
p.drawRoundedRect(borderRect, br, br);
|
||||
|
||||
// draw rounded content
|
||||
p.setPen(Qt::transparent);
|
||||
p.setBrush(brush);
|
||||
switch (m_position)
|
||||
{
|
||||
case Top: p.drawRoundedRect(r.marginsRemoved(QMargins(1, -bgr, 1, 1)), bgr, bgr); break;
|
||||
case Bottom: p.drawRoundedRect(r.marginsRemoved(QMargins(1, 1, 1, -bgr)), bgr, bgr); break;
|
||||
case Left: p.drawRoundedRect(r.marginsRemoved(QMargins(-bgr, 1, 1, 1)), bgr, bgr); break;
|
||||
case Right: p.drawRoundedRect(r.marginsRemoved(QMargins(1, 1, -bgr, 1)), bgr, bgr); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +205,7 @@ void MainPanel::resizeEvent(QResizeEvent *e)
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
m_itemAdjustTimer->start();
|
||||
m_updateEffectTimer->start();
|
||||
|
||||
emit geometryChanged();
|
||||
}
|
||||
@ -351,6 +349,54 @@ DockItem *MainPanel::itemAt(const QPoint &point)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainPanel::updateBlurEffect() const
|
||||
{
|
||||
qDebug() << m_position;
|
||||
if (m_displayMode == Efficient) {
|
||||
m_effectWidget->setBlurRectXRadius(0);
|
||||
m_effectWidget->setBlurRectYRadius(0);
|
||||
m_effectWidget->move(0, 0);
|
||||
m_effectWidget->resize(size());
|
||||
} else {
|
||||
const int expandSize = 10;
|
||||
int width = this->width();
|
||||
int height = this->height();
|
||||
|
||||
m_effectWidget->setBlurRectXRadius(5);
|
||||
m_effectWidget->setBlurRectYRadius(5);
|
||||
|
||||
switch (m_position)
|
||||
{
|
||||
case Top: {
|
||||
height += expandSize;
|
||||
m_effectWidget->move(0, -expandSize);
|
||||
m_effectWidget->resize(width, height);
|
||||
break;
|
||||
}
|
||||
case Bottom:
|
||||
height += expandSize;
|
||||
m_effectWidget->move(0, 0);
|
||||
m_effectWidget->resize(width, height);
|
||||
break;
|
||||
case Left: {
|
||||
width += expandSize;
|
||||
m_effectWidget->move(-expandSize, 0);
|
||||
m_effectWidget->resize(width, height);
|
||||
break;
|
||||
}
|
||||
case Right: {
|
||||
width += expandSize;
|
||||
m_effectWidget->move(0, 0);
|
||||
m_effectWidget->resize(width, height);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief MainPanel::adjustItemSize adjust all dock item size to fit panel size,
|
||||
/// for optimize cpu usage, DO NOT call this func immediately, you should use m_itemAdjustTimer
|
||||
|
@ -8,11 +8,15 @@
|
||||
#include <QTimer>
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include <DBlurEffectWidget>
|
||||
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
#define PANEL_BORDER 0
|
||||
#define PANEL_PADDING 6
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class MainPanel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -44,6 +48,8 @@ private:
|
||||
void manageItem(DockItem *item);
|
||||
DockItem *itemAt(const QPoint &point);
|
||||
|
||||
void updateBlurEffect() const;
|
||||
|
||||
private slots:
|
||||
void adjustItemSize();
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
@ -60,6 +66,9 @@ private:
|
||||
QTimer *m_itemAdjustTimer;
|
||||
DockItemController *m_itemController;
|
||||
|
||||
QTimer *m_updateEffectTimer;
|
||||
DBlurEffectWidget *m_effectWidget;
|
||||
|
||||
static DockItem *DragingItem;
|
||||
static PlaceholderItem *RequestDockItem;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user