Add drop shadow to emoji panel
- Minor refactoring
This commit is contained in:
parent
83cdd79e08
commit
5197f8a886
4 changed files with 244 additions and 139 deletions
|
|
@ -17,9 +17,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QScrollArea>
|
||||
#include <QWidget>
|
||||
|
|
@ -27,7 +25,7 @@
|
|||
#include "EmojiCategory.h"
|
||||
#include "EmojiProvider.h"
|
||||
|
||||
class EmojiPanel : public QFrame
|
||||
class EmojiPanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
@ -43,25 +41,24 @@ signals:
|
|||
|
||||
protected:
|
||||
void leaveEvent(QEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
void showEmojiCategory(const EmojiCategory *category);
|
||||
|
||||
QPropertyAnimation *opacity_anim_;
|
||||
QPropertyAnimation *size_anim_;
|
||||
QPropertyAnimation *animation_;
|
||||
QGraphicsOpacityEffect *opacity_;
|
||||
QParallelAnimationGroup *animation_;
|
||||
|
||||
EmojiProvider emoji_provider_;
|
||||
|
||||
QScrollArea *scroll_area_;
|
||||
QScrollArea *scrollArea_;
|
||||
|
||||
int shadowMargin_;
|
||||
|
||||
// Panel dimensions.
|
||||
const int WIDTH = 370;
|
||||
const int HEIGHT = 350;
|
||||
int width_;
|
||||
int height_;
|
||||
|
||||
const int ANIMATION_DURATION = 100;
|
||||
const int ANIMATION_OFFSET = 50;
|
||||
|
||||
const int category_icon_size_ = 20;
|
||||
int animationDuration_;
|
||||
int categoryIconSize_;
|
||||
};
|
||||
|
|
|
|||
100
include/ui/DropShadow.h
Normal file
100
include/ui/DropShadow.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QLinearGradient>
|
||||
#include <QPainter>
|
||||
|
||||
class DropShadow
|
||||
{
|
||||
public:
|
||||
static void draw(QPainter &painter,
|
||||
qint16 margin,
|
||||
qreal radius,
|
||||
QColor start,
|
||||
QColor end,
|
||||
qreal startPosition,
|
||||
qreal endPosition0,
|
||||
qreal endPosition1,
|
||||
qreal width,
|
||||
qreal height)
|
||||
{
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
QLinearGradient gradient;
|
||||
gradient.setColorAt(startPosition, start);
|
||||
gradient.setColorAt(endPosition0, end);
|
||||
|
||||
// Right
|
||||
QPointF right0(width - margin, height / 2);
|
||||
QPointF right1(width, height / 2);
|
||||
gradient.setStart(right0);
|
||||
gradient.setFinalStop(right1);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(QPointF(width - margin * radius, margin), QPointF(width, height - margin)), 0.0, 0.0);
|
||||
|
||||
// Left
|
||||
QPointF left0(margin, height / 2);
|
||||
QPointF left1(0, height / 2);
|
||||
gradient.setStart(left0);
|
||||
gradient.setFinalStop(left1);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(QPointF(margin * radius, margin), QPointF(0, height - margin)), 0.0, 0.0);
|
||||
|
||||
// Top
|
||||
QPointF top0(width / 2, margin);
|
||||
QPointF top1(width / 2, 0);
|
||||
gradient.setStart(top0);
|
||||
gradient.setFinalStop(top1);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(QPointF(width - margin, 0), QPointF(margin, margin)), 0.0, 0.0);
|
||||
|
||||
// Bottom
|
||||
QPointF bottom0(width / 2, height - margin);
|
||||
QPointF bottom1(width / 2, height);
|
||||
gradient.setStart(bottom0);
|
||||
gradient.setFinalStop(bottom1);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(QPointF(margin, height - margin), QPointF(width - margin, height)), 0.0, 0.0);
|
||||
|
||||
// BottomRight
|
||||
QPointF bottomright0(width - margin, height - margin);
|
||||
QPointF bottomright1(width, height);
|
||||
gradient.setStart(bottomright0);
|
||||
gradient.setFinalStop(bottomright1);
|
||||
gradient.setColorAt(endPosition1, end);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(bottomright0, bottomright1), 0.0, 0.0);
|
||||
|
||||
// BottomLeft
|
||||
QPointF bottomleft0(margin, height - margin);
|
||||
QPointF bottomleft1(0, height);
|
||||
gradient.setStart(bottomleft0);
|
||||
gradient.setFinalStop(bottomleft1);
|
||||
gradient.setColorAt(endPosition1, end);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(bottomleft0, bottomleft1), 0.0, 0.0);
|
||||
|
||||
// TopLeft
|
||||
QPointF topleft0(margin, margin);
|
||||
QPointF topleft1(0, 0);
|
||||
gradient.setStart(topleft0);
|
||||
gradient.setFinalStop(topleft1);
|
||||
gradient.setColorAt(endPosition1, end);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(topleft0, topleft1), 0.0, 0.0);
|
||||
|
||||
// TopRight
|
||||
QPointF topright0(width - margin, margin);
|
||||
QPointF topright1(width, 0);
|
||||
gradient.setStart(topright0);
|
||||
gradient.setFinalStop(topright1);
|
||||
gradient.setColorAt(endPosition1, end);
|
||||
painter.setBrush(QBrush(gradient));
|
||||
painter.drawRoundRect(QRectF(topright0, topright1), 0.0, 0.0);
|
||||
|
||||
// Widget
|
||||
painter.setBrush(QBrush("#FFFFFF"));
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.drawRoundRect(QRectF(QPointF(margin, margin), QPointF(width - margin, height - margin)), radius, radius);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue