diff options
Diffstat (limited to 'Swift/QtUI/QtEmojisSelector.cpp')
-rw-r--r-- | Swift/QtUI/QtEmojisSelector.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Swift/QtUI/QtEmojisSelector.cpp b/Swift/QtUI/QtEmojisSelector.cpp new file mode 100644 index 0000000..8b21380 --- /dev/null +++ b/Swift/QtUI/QtEmojisSelector.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swift/QtUI/QtEmojisSelector.h> + +#include <QScrollArea> +#include <QSettings> +#include <QString> +#include <QWidget> + +#include <SwifTools/EmojiMapper.h> + +#include <Swift/QtUI/QtEmojisGrid.h> +#include <Swift/QtUI/QtEmojisScroll.h> +#include <Swift/QtUI/QtRecentEmojisGrid.h> +#include <Swift/QtUI/QtSwiftUtil.h> + +namespace Swift { + QtEmojisSelector::QtEmojisSelector(QSettings* settings, QWidget* parent) : QTabWidget(parent), settings_(settings) { + recentEmojisGrid_ = addRecentTab(); + connect(recentEmojisGrid_, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString))); + + for (const auto& category : EmojiMapper::getCategories()) { + if (category != "modifier") { + QtEmojisGrid* grid = addTab(P2QSTRING(category)); + connect(grid, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString))); + } + } + + loadSettings(); + } + + QtEmojisSelector::~QtEmojisSelector() { + writeSettings(); + } + + QtRecentEmojisGrid* QtEmojisSelector::addRecentTab() { + QtRecentEmojisGrid* recent = new QtRecentEmojisGrid(settings_); + QtEmojisScroll* scroll = new QtEmojisScroll(recent); + QTabWidget::addTab(scroll, QString::fromStdString(EmojiMapper::categoryToFlagshipUnicodeEmoji("recent"))); + + setTabToolTip(count()-1, tr("Recent")); + + return recent; + } + + QtEmojisGrid* QtEmojisSelector::addTab(QString categoryName) { + QtEmojisGrid* grid = new QtEmojisGrid(categoryName); + QtEmojisScroll* scroll = new QtEmojisScroll(grid); + QTabWidget::addTab(scroll, QString::fromStdString(EmojiMapper::categoryToFlagshipUnicodeEmoji(Q2PSTRING(categoryName)))); + setTabToolTip(count()-1, categoryName.replace(0, 1, categoryName[0].toUpper())); + + return grid; + } + + void QtEmojisSelector::loadSettings() { + if (settings_->contains("currentEmojiTab")) { + setCurrentIndex(settings_->value("currentEmojiTab").toInt()); + } else { + setCurrentIndex(1); //index of people category + } + } + + void QtEmojisSelector::writeSettings() { + settings_->setValue("currentEmojiTab", currentIndex()); + } + + void QtEmojisSelector::emojiClickedSlot(QString emoji) { + recentEmojisGrid_->handleEmojiClicked(emoji); + emit emojiClicked(emoji); + } +} |