Fix emoji picker's theme

This commit is contained in:
Konstantinos Sideris 2017-11-22 21:03:53 +02:00
parent 552941118b
commit 56d8be5a27
6 changed files with 42 additions and 63 deletions

View file

@ -37,6 +37,9 @@ public:
signals:
void emojiSelected(const QString &emoji);
protected:
void paintEvent(QPaintEvent *event) override;
private slots:
void clickIndex(const QModelIndex &index)
{

View file

@ -17,8 +17,6 @@
#pragma once
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QScrollArea>
#include "EmojiProvider.h"
@ -32,9 +30,6 @@ class EmojiPanel : public QWidget
public:
EmojiPanel(QWidget *parent = nullptr);
void fadeOut();
void fadeIn();
signals:
void mouseLeft();
void emojiSelected(const QString &emoji);
@ -46,9 +41,6 @@ protected:
private:
void showEmojiCategory(const EmojiCategory *category);
QPropertyAnimation *animation_;
QGraphicsOpacityEffect *opacity_;
EmojiProvider emoji_provider_;
QScrollArea *scrollArea_;
@ -59,6 +51,5 @@ private:
int width_;
int height_;
int animationDuration_;
int categoryIconSize_;
};

View file

@ -77,3 +77,15 @@ RegisterPage {
background-color: white;
color: #333;
}
EmojiPanel,
EmojiPanel > * {
background-color: white;
color: #333;
}
EmojiCategory,
EmojiCategory > * {
background-color: white;
color: #ccc;
}

View file

@ -16,6 +16,8 @@
*/
#include <QScrollBar>
#include <QStyleOption>
#include <QPainter>
#include "Config.h"
#include "EmojiCategory.h"
@ -25,6 +27,7 @@ EmojiCategory::EmojiCategory(QString category, QList<Emoji> emoji, QWidget *pare
{
mainLayout_ = new QVBoxLayout(this);
mainLayout_->setMargin(0);
mainLayout_->setSpacing(0);
emojiListView_ = new QListView();
itemModel_ = new QStandardItemModel(this);
@ -33,7 +36,6 @@ EmojiCategory::EmojiCategory(QString category, QList<Emoji> emoji, QWidget *pare
data_ = new Emoji;
emojiListView_->setItemDelegate(delegate_);
emojiListView_->setSpacing(5);
emojiListView_->setModel(itemModel_);
emojiListView_->setViewMode(QListView::IconMode);
emojiListView_->setFlow(QListView::LeftToRight);
@ -67,16 +69,21 @@ EmojiCategory::EmojiCategory(QString category, QList<Emoji> emoji, QWidget *pare
category_ = new QLabel(category, this);
category_->setFont(font);
category_->setStyleSheet("color: #ccc; margin: 20px 0px 15px 8px;");
category_->setStyleSheet("margin: 20px 0 20px 8px;");
auto labelLayout_ = new QHBoxLayout();
labelLayout_->addWidget(category_);
labelLayout_->addStretch(1);
mainLayout_->addLayout(labelLayout_);
mainLayout_->addWidget(category_);
mainLayout_->addWidget(emojiListView_);
connect(emojiListView_, &QListView::clicked, this, &EmojiCategory::clickIndex);
}
void
EmojiCategory::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
EmojiCategory::~EmojiCategory() {}

View file

@ -29,14 +29,11 @@ EmojiPanel::EmojiPanel(QWidget *parent)
, shadowMargin_{2}
, width_{370}
, height_{350}
, animationDuration_{100}
, categoryIconSize_{20}
{
setStyleSheet("QWidget {border: none;}"
"QScrollBar:vertical { width: 8px; margin: 0px 2px 0 2px; }"
"QScrollBar::handle:vertical { min-height: 20px; }"
"QScrollBar::add-line:vertical { border: none; background: none; }"
"QScrollBar::sub-line:vertical { border: none; background: none; }");
"QScrollBar:vertical { width: 0px; margin: 0px; }"
"QScrollBar::handle:vertical { min-height: 30px; }");
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_ShowWithoutActivating, true);
@ -48,16 +45,18 @@ EmojiPanel::EmojiPanel(QWidget *parent)
auto topLayout = new QVBoxLayout(this);
topLayout->addWidget(mainWidget);
topLayout->setMargin(shadowMargin_);
topLayout->setSpacing(0);
auto contentLayout = new QVBoxLayout(mainWidget);
contentLayout->setMargin(0);
contentLayout->setSpacing(0);
auto emojiCategories = new QFrame(mainWidget);
// emojiCategories->setStyleSheet("background-color: #f2f2f2");
emojiCategories->setStyleSheet("background-color: #f2f2f2");
auto categoriesLayout = new QHBoxLayout(emojiCategories);
categoriesLayout->setSpacing(6);
categoriesLayout->setMargin(5);
categoriesLayout->setSpacing(0);
categoriesLayout->setMargin(0);
QIcon icon;
@ -126,6 +125,7 @@ EmojiPanel::EmojiPanel(QWidget *parent)
auto scrollLayout = new QVBoxLayout(scrollWidget);
scrollLayout->setMargin(0);
scrollLayout->setSpacing(0);
scrollArea_->setWidget(scrollWidget);
auto peopleEmoji =
@ -156,20 +156,9 @@ EmojiPanel::EmojiPanel(QWidget *parent)
auto flagsEmoji = new EmojiCategory(tr("Flags"), emoji_provider_.flags, scrollWidget);
scrollLayout->addWidget(flagsEmoji);
contentLayout->addStretch(1);
contentLayout->addWidget(scrollArea_);
contentLayout->addWidget(emojiCategories);
opacity_ = new QGraphicsOpacityEffect(this);
opacity_->setOpacity(1.0);
setGraphicsEffect(opacity_);
animation_ = new QPropertyAnimation(opacity_, "opacity", this);
animation_->setDuration(animationDuration_);
animation_->setStartValue(1);
animation_->setEndValue(0);
connect(peopleEmoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected);
connect(peopleCategory, &QPushButton::clicked, [this, peopleEmoji]() {
this->showEmojiCategory(peopleEmoji);
@ -209,11 +198,6 @@ EmojiPanel::EmojiPanel(QWidget *parent)
connect(flagsCategory, &QPushButton::clicked, [this, flagsEmoji]() {
this->showEmojiCategory(flagsEmoji);
});
connect(animation_, &QAbstractAnimation::finished, [this]() {
if (animation_->direction() == QAbstractAnimation::Forward)
this->hide();
});
}
void
@ -238,11 +222,9 @@ EmojiPanel::showEmojiCategory(const EmojiCategory *category)
}
void
EmojiPanel::leaveEvent(QEvent *event)
EmojiPanel::leaveEvent(QEvent *)
{
Q_UNUSED(event);
fadeOut();
hide();
}
void
@ -253,6 +235,8 @@ EmojiPanel::paintEvent(QPaintEvent *event)
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
DropShadow::draw(p,
shadowMargin_,
4.0,
@ -263,21 +247,4 @@ EmojiPanel::paintEvent(QPaintEvent *event)
0.6,
width(),
height());
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
// QWidget::paintEvent(event);
}
void
EmojiPanel::fadeOut()
{
animation_->setDirection(QAbstractAnimation::Forward);
animation_->start();
}
void
EmojiPanel::fadeIn()
{
animation_->setDirection(QAbstractAnimation::Backward);
animation_->start();
}

View file

@ -43,7 +43,6 @@ EmojiPickButton::enterEvent(QEvent *e)
auto y = pos.y() - panel_size.height() - vertical_distance_;
panel_->move(x, y);
panel_->fadeIn();
panel_->show();
}
@ -62,5 +61,5 @@ EmojiPickButton::leaveEvent(QEvent *e)
if (panel_geometry.contains(pos))
return;
panel_->fadeOut();
panel_->hide();
}