From 61049f2944048448f04b908107c4242a8dca0099 Mon Sep 17 00:00:00 2001 From: laserpants Date: Thu, 28 Apr 2016 00:01:27 +0300 Subject: [PATCH] add drop shadow to menu --- components/iconmenu.cpp | 16 ++++++++++++---- components/menu.cpp | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/iconmenu.cpp b/components/iconmenu.cpp index cff3181..c5cbaff 100644 --- a/components/iconmenu.cpp +++ b/components/iconmenu.cpp @@ -32,15 +32,21 @@ IconMenu::IconMenu(const QIcon &icon, QWidget *parent) _animation->setPropertyName("progress"); _animation->setTargetObject(this); - _animation->setDuration(200); + _animation->setDuration(270); _animation->setStartValue(1); _animation->setEndValue(0); - _animation->setEasingCurve(QEasingCurve::InOutCubic); + _animation->setEasingCurve(QEasingCurve::OutCubic); _menu->hide(); _menu->setGraphicsEffect(_effect); + QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; + effect->setBlurRadius(9); + effect->setOffset(QPoint(0, 0)); + effect->setColor(QColor(0, 0, 0, 200)); + _menuOverlay->setGraphicsEffect(effect); + _menuOverlay->installEventFilter(this); connect(this, SIGNAL(clicked(bool)), this, SLOT(toggleMenu())); @@ -62,7 +68,7 @@ void IconMenu::setProgress(qreal progress) return; _progress = progress; - _effect->setScale(0.5*(1 + progress), progress); + _effect->setScale(progress, progress); emit progressChanged(progress); update(); @@ -118,5 +124,7 @@ bool IconMenu::event(QEvent *event) void IconMenu::updateOverlayGeometry() { - _menu->setGeometry(QRect(_menuPos, _menu->layout()->sizeHint())); + const QSize size = iconSize(); + const QPoint pos = _menuPos + QPoint(size.width()/2, size.height()/2); + _menu->setGeometry(QRect(pos, _menu->layout()->sizeHint())); } diff --git a/components/menu.cpp b/components/menu.cpp index e08d5d5..3e4c5bc 100644 --- a/components/menu.cpp +++ b/components/menu.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "menu.h" MenuItem::MenuItem(QWidget *parent) @@ -34,6 +35,12 @@ Menu::Menu(QWidget *parent) QSizePolicy policy; policy.setVerticalPolicy(QSizePolicy::Maximum); setSizePolicy(policy); + + QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; + effect->setBlurRadius(9); + effect->setOffset(QPoint(0, 0)); + effect->setColor(QColor(0, 0, 0, 200)); + setGraphicsEffect(effect); } Menu::~Menu() @@ -56,7 +63,6 @@ void Menu::paintEvent(QPaintEvent *event) QPainter painter(this); painter.fillRect(rect(), Qt::white); - painter.drawRect(rect().adjusted(0, 0, -1, -1)); QWidget::paintEvent(event); }