Skip to content

Commit

Permalink
Initial emoticons filtering featue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 22, 2024
1 parent 0f38073 commit 9969eb6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
19 changes: 10 additions & 9 deletions src/psicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class PsiCon::Private : public QObject {
return { nullptr, QString() };
}

private slots:
public slots:
void updateIconSelect()
{
Iconset iss;
Expand Down Expand Up @@ -504,14 +504,6 @@ bool PsiCon::init()
QDir profileDir(pathToProfile(activeProfile, ApplicationInfo::DataLocation));
profileDir.rmdir("info"); // remove unused dir

d->iconSelect = new IconSelectPopup(nullptr);
d->iconSelect->setEmojiSortingEnabled(true);
connect(PsiIconset::instance(), SIGNAL(emoticonsChanged()), d, SLOT(updateIconSelect()));

const QString css = options->getOption("options.ui.chat.css").toString();
if (!css.isEmpty())
d->iconSelect->setStyleSheet(css);

// first thing, try to load the iconset
bool result = true;
if (!PsiIconset::instance()->loadAll()) {
Expand All @@ -523,6 +515,15 @@ bool PsiCon::init()
//}
}

d->iconSelect = new IconSelectPopup(nullptr);
d->iconSelect->setEmojiSortingEnabled(true);
connect(PsiIconset::instance(), SIGNAL(emoticonsChanged()), d, SLOT(updateIconSelect()));
d->updateIconSelect();

const QString css = options->getOption("options.ui.chat.css").toString();
if (!css.isEmpty())
d->iconSelect->setStyleSheet(css);

d->nam = new NetworkAccessManager(this);
updateNAMOptions();
d->fileSharingManager = new FileSharingManager(this);
Expand Down
71 changes: 56 additions & 15 deletions src/widgets/iconselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include "iconselect.h"

#include "actionlineedit.h"
#include "emojiregistry.h"
#include "iconaction.h"
#include "iconset.h"

#include <QAbstractButton>
Expand Down Expand Up @@ -208,6 +210,7 @@ class IconSelect : public QWidget {
IconSelectPopup *menu;
Iconset is;
QGridLayout *grid;
QString titleFilter;
bool shown;
bool emojiSorting;

Expand All @@ -222,11 +225,13 @@ class IconSelect : public QWidget {
const Iconset &iconset() const;

void setEmojiSortingEnabled(bool enabled);
void setTitleFilter(const QString &title);

protected:
QList<PsiIcon *> sortEmojis() const;
void noIcons();
void createLayout();
void updateGrid();

void paintEvent(QPaintEvent *)
{
Expand Down Expand Up @@ -287,7 +292,11 @@ void IconSelect::noIcons()
void IconSelect::setIconset(const Iconset &iconset)
{
is = iconset;
updateGrid();
}

void IconSelect::updateGrid()
{
// delete all children
if (grid) {
delete grid;
Expand All @@ -310,9 +319,16 @@ void IconSelect::setIconset(const Iconset &iconset)
int maxPrefTileHeight = fontSz * 3;
auto maxPrefSize = QSize(maxPrefTileHeight, maxPrefTileHeight);

double count; // the 'double' type is somewhat important for MSVC.NET here
double count; // the 'double' type is somewhat important for MSVC.NET here
QList<const EmojiRegistry::Emoji *> emojis;
if (fontEmojiMode) {
count = EmojiRegistry::instance().count();
for (auto const &emoji : EmojiRegistry::instance()) {
if (titleFilter.isEmpty() || emoji.name.contains(titleFilter)) {
emojis.append(&emoji);
}
}

count = emojis.count();
w = fontSz * 2.5;
h = fontSz * 2.5;
} else {
Expand Down Expand Up @@ -360,12 +376,12 @@ void IconSelect::setIconset(const Iconset &iconset)
#else
font.setFamily("Noto Color Emoji");
#endif
for (auto const &emoji : EmojiRegistry::instance()) {
for (auto const &emoji : emojis) {
IconSelectButton *b = new IconSelectButton(this);
b->setFont(font);
grid->addWidget(b, row, column);
b->setText(emoji.code);
b->setToolTip(emoji.name);
b->setText(emoji->code);
b->setToolTip(emoji->name);
b->setSizeHint(QSize(tileSize, tileSize));
connect(b, qOverload<const PsiIcon *>(&IconSelectButton::iconSelected), menu,
&IconSelectPopup::iconSelected);
Expand Down Expand Up @@ -405,6 +421,12 @@ const Iconset &IconSelect::iconset() const { return is; }

void IconSelect::setEmojiSortingEnabled(bool enabled) { emojiSorting = enabled; }

void IconSelect::setTitleFilter(const QString &title)
{
titleFilter = title;
updateGrid();
}

QList<PsiIcon *> IconSelect::sortEmojis() const
{
QList<PsiIcon *> ret;
Expand Down Expand Up @@ -449,35 +471,50 @@ QList<PsiIcon *> IconSelect::sortEmojis() const
class IconSelectPopup::Private : public QObject {
Q_OBJECT
public:
Private(IconSelectPopup *parent) : QObject(parent), parent_(parent), icsel_(nullptr), widgetAction_(nullptr) { }
Private(IconSelectPopup *parent) : QObject(parent), parent_(parent), icsel_(nullptr), emotsAction_(nullptr) { }

IconSelectPopup *parent_;
IconSelect *icsel_;
QWidgetAction *widgetAction_;
QWidgetAction *emotsAction_;
QScrollArea *scrollArea_;
ActionLineEdit *findBar_;
IconAction *findAct_;
QWidgetAction *findAction_;

public slots:
void updatedGeometry()
{
widgetAction_->setDefaultWidget(scrollArea_);
emotsAction_->setDefaultWidget(scrollArea_);
QRect r = scrollArea_->screen()->availableGeometry();
int maxSize = qMin(r.width(), r.height()) / 3;
int vBarWidth
= scrollArea_->verticalScrollBar()->isEnabled() ? scrollArea_->verticalScrollBar()->sizeHint().rwidth() : 0;
scrollArea_->setMinimumWidth(icsel_->sizeHint().rwidth() + vBarWidth);
scrollArea_->setMinimumHeight(qMin(icsel_->sizeHint().rheight(), maxSize));
scrollArea_->setFrameStyle(QFrame::Plain);
parent_->removeAction(widgetAction_);
parent_->addAction(widgetAction_);
parent_->removeAction(emotsAction_);
parent_->addAction(emotsAction_); // add menu item
findAct_->setPsiIcon("psi/search");
}

void setTitleFilter(const QString &filter) { icsel_->setTitleFilter(filter); }
};

IconSelectPopup::IconSelectPopup(QWidget *parent) : QMenu(parent)
{
d = new Private(this);
d->icsel_ = new IconSelect(this);
d->widgetAction_ = new QWidgetAction(this);
d->scrollArea_ = new QScrollArea(this);
d = new Private(this);
d->icsel_ = new IconSelect(this);

d->findAction_ = new QWidgetAction(this);
d->findBar_ = new ActionLineEdit(nullptr);
d->findAct_ = new IconAction(d->findBar_);
d->findBar_->addAction(d->findAct_);
d->findAction_->setDefaultWidget(d->findBar_);
addAction(d->findAction_);
connect(d->findBar_, &QLineEdit::textChanged, d, &Private::setTitleFilter);

d->emotsAction_ = new QWidgetAction(this);
d->scrollArea_ = new QScrollArea(this);
d->scrollArea_->setWidget(d->icsel_);
d->scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
Expand All @@ -486,7 +523,11 @@ IconSelectPopup::IconSelectPopup(QWidget *parent) : QMenu(parent)
d->updatedGeometry();
}

IconSelectPopup::~IconSelectPopup() { }
IconSelectPopup::~IconSelectPopup()
{
d->findAction_->setDefaultWidget(nullptr);
delete d->findBar_;
}

void IconSelectPopup::setIconset(const Iconset &i) { d->icsel_->setIconset(i); }

Expand Down

0 comments on commit 9969eb6

Please sign in to comment.