add drop shadow to menu
This commit is contained in:
parent
d2add935b0
commit
61049f2944
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue