Add geometry animation on emoji picker

This commit is contained in:
Konstantinos Sideris 2017-05-16 21:21:31 +03:00
parent 992af5611b
commit c470e49aa9
2 changed files with 28 additions and 9 deletions

View file

@ -20,6 +20,7 @@
#include <QFrame> #include <QFrame>
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QParallelAnimationGroup>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QScrollArea> #include <QScrollArea>
#include <QWidget> #include <QWidget>
@ -47,13 +48,22 @@ protected:
private: private:
void showEmojiCategory(const EmojiCategory *category); void showEmojiCategory(const EmojiCategory *category);
QPropertyAnimation *animation_; QPropertyAnimation *opacity_anim_;
QPropertyAnimation *size_anim_;
QGraphicsOpacityEffect *opacity_; QGraphicsOpacityEffect *opacity_;
QParallelAnimationGroup *animation_;
EmojiProvider emoji_provider_; EmojiProvider emoji_provider_;
QScrollArea *scroll_area_; QScrollArea *scroll_area_;
// Panel dimensions.
const int WIDTH = 370;
const int HEIGHT = 350;
const int ANIMATION_DURATION = 100;
const int ANIMATION_OFFSET = 50;
const int category_icon_size_ = 20; const int category_icon_size_ = 20;
}; };

View file

@ -44,8 +44,7 @@ EmojiPanel::EmojiPanel(QWidget *parent)
// TODO: Make it MainWindow aware // TODO: Make it MainWindow aware
auto main_frame_ = new QFrame(this); auto main_frame_ = new QFrame(this);
main_frame_->setMinimumSize(370, 350); main_frame_->setMaximumSize(WIDTH, HEIGHT);
main_frame_->setMaximumSize(370, 350);
auto top_layout = new QVBoxLayout(this); auto top_layout = new QVBoxLayout(this);
top_layout->addWidget(main_frame_); top_layout->addWidget(main_frame_);
@ -150,16 +149,26 @@ EmojiPanel::EmojiPanel(QWidget *parent)
setLayout(top_layout); setLayout(top_layout);
// TODO: Add parallel animation with geometry
opacity_ = new QGraphicsOpacityEffect(this); opacity_ = new QGraphicsOpacityEffect(this);
opacity_->setOpacity(1.0); opacity_->setOpacity(1.0);
setGraphicsEffect(opacity_); setGraphicsEffect(opacity_);
animation_ = new QPropertyAnimation(opacity_, "opacity", this); opacity_anim_ = new QPropertyAnimation(opacity_, "opacity", this);
animation_->setDuration(180); opacity_anim_->setDuration(ANIMATION_DURATION);
animation_->setStartValue(1.0); opacity_anim_->setStartValue(1);
animation_->setEndValue(0.0); opacity_anim_->setEndValue(0);
size_anim_ = new QPropertyAnimation(this);
size_anim_->setTargetObject(main_frame_);
size_anim_->setPropertyName("geometry");
size_anim_->setDuration(ANIMATION_DURATION);
size_anim_->setStartValue(QRect(0, 0, WIDTH, HEIGHT));
size_anim_->setEndValue(QRect(ANIMATION_OFFSET, ANIMATION_OFFSET, WIDTH - ANIMATION_OFFSET, HEIGHT - ANIMATION_OFFSET));
animation_ = new QParallelAnimationGroup(this);
animation_->addAnimation(opacity_anim_);
animation_->addAnimation(size_anim_);
connect(people_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); connect(people_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected);
connect(people_category, &QPushButton::clicked, [this, people_emoji]() { connect(people_category, &QPushButton::clicked, [this, people_emoji]() {
@ -201,7 +210,7 @@ EmojiPanel::EmojiPanel(QWidget *parent)
this->showEmojiCategory(flags_emoji); this->showEmojiCategory(flags_emoji);
}); });
connect(animation_, &QPropertyAnimation::finished, [this]() { connect(animation_, &QAbstractAnimation::finished, [this]() {
if (animation_->direction() == QAbstractAnimation::Forward) if (animation_->direction() == QAbstractAnimation::Forward)
this->hide(); this->hide();
}); });