diff --git a/src/emoticon/emoticonlistwidgetselector.cpp b/src/emoticon/emoticonlistwidgetselector.cpp index b1aa261..3fc6d46 100644 --- a/src/emoticon/emoticonlistwidgetselector.cpp +++ b/src/emoticon/emoticonlistwidgetselector.cpp @@ -1,96 +1,104 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emoticonlistwidgetselector.h" #include "emoticontexteditselector.h" using namespace KPIMTextEdit; EmoticonTextEditItem::EmoticonTextEditItem(const QString &emoticonText, QListWidget *parent) : QListWidgetItem(parent) { mText = emoticonText; setText(mText); setToolTip(mText); } EmoticonTextEditItem::EmoticonTextEditItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent) : QListWidgetItem(parent) { mText = emoticonText; mPixmapPath = pixmapPath; QPixmap p(mPixmapPath); // Some of the custom icons are rather large // so lets limit them to a maximum size for this display panel // //TODO need to fix hdpi support here. if (p.width() > 32 || p.height() > 32) { p = p.scaled(QSize(32, 32), Qt::KeepAspectRatio); } setIcon(p); setToolTip(mText); } QString EmoticonTextEditItem::text() const { return mText; } QString EmoticonTextEditItem::pixmapPath() const { return mPixmapPath; } EmoticonListWidgetSelector::EmoticonListWidgetSelector(QWidget *parent) : QListWidget (parent) { setViewMode(QListView::IconMode); setSelectionMode(QAbstractItemView::SingleSelection); setMouseTracking(true); setDragEnabled(false); connect(this, &EmoticonListWidgetSelector::itemEntered, this, &EmoticonListWidgetSelector::slotMouseOverItem); connect(this, &EmoticonListWidgetSelector::itemClicked, this, &EmoticonListWidgetSelector::slotEmoticonClicked); } EmoticonListWidgetSelector::~EmoticonListWidgetSelector() { } void EmoticonListWidgetSelector::slotMouseOverItem(QListWidgetItem *item) { item->setSelected(true); if (!hasFocus()) { setFocus(); } } +void EmoticonListWidgetSelector::setEmoticons(const QList &lst) +{ + for (uint emoji : lst) { + const QString str = QString::fromUcs4(&emoji, 1); + new KPIMTextEdit::EmoticonTextEditItem(str, this); + } +} + void EmoticonListWidgetSelector::slotEmoticonClicked(QListWidgetItem *item) { if (!item) { return; } EmoticonTextEditItem *itemEmoticon = static_cast(item); Q_EMIT itemSelected(itemEmoticon->text()); } diff --git a/src/emoticon/emoticonlistwidgetselector.h b/src/emoticon/emoticonlistwidgetselector.h index f5f722e..de2257d 100644 --- a/src/emoticon/emoticonlistwidgetselector.h +++ b/src/emoticon/emoticonlistwidgetselector.h @@ -1,58 +1,59 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EMOTICONLISTWIDGETSELECTOR_H #define EMOTICONLISTWIDGETSELECTOR_H #include #include "kpimtextedit_private_export.h" namespace KPIMTextEdit { class KPIMTEXTEDIT_TESTS_EXPORT EmoticonTextEditItem : public QListWidgetItem { public: explicit EmoticonTextEditItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent); explicit EmoticonTextEditItem(const QString &emoticonText, QListWidget *parent); QString text() const; QString pixmapPath() const; private: QString mText; QString mPixmapPath; }; class KPIMTEXTEDIT_TESTS_EXPORT EmoticonListWidgetSelector : public QListWidget { Q_OBJECT public: explicit EmoticonListWidgetSelector(QWidget *parent = nullptr); ~EmoticonListWidgetSelector(); + void setEmoticons(const QList &lst); Q_SIGNALS: void itemSelected(const QString &); private: void slotMouseOverItem(QListWidgetItem *item); void slotEmoticonClicked(QListWidgetItem *item); }; } #endif // EMOTICONLISTWIDGETSELECTOR_H diff --git a/src/emoticon/emoticonunicodetab.cpp b/src/emoticon/emoticonunicodetab.cpp index 9a5e984..1ac6a46 100644 --- a/src/emoticon/emoticonunicodetab.cpp +++ b/src/emoticon/emoticonunicodetab.cpp @@ -1,36 +1,48 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emoticonunicodetab.h" #include "emoticonlistwidgetselector.h" #include "textutils.h" +#include using namespace KPIMTextEdit; EmoticonUnicodeTab::EmoticonUnicodeTab(QWidget *parent) : QTabWidget(parent) { + loadEmoticons(); } EmoticonUnicodeTab::~EmoticonUnicodeTab() { } void EmoticonUnicodeTab::loadEmoticons() { + createTab(i18n("Faces"), KPIMTextEdit::TextUtils::unicodeFacesEmoji()); + //TODO add more +} + +void EmoticonUnicodeTab::createTab(const QString &str, const QList &emoticons) +{ + EmoticonListWidgetSelector *selector = new EmoticonListWidgetSelector(this); + selector->setEmoticons(emoticons); + //TODO add i18n ? or icons ? + addTab(selector, str); } diff --git a/src/emoticon/emoticonunicodetab.h b/src/emoticon/emoticonunicodetab.h index 88ec680..cb9106d 100644 --- a/src/emoticon/emoticonunicodetab.h +++ b/src/emoticon/emoticonunicodetab.h @@ -1,43 +1,44 @@ /* Copyright (c) 2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EMOTICONUNICODETAB_H #define EMOTICONUNICODETAB_H #include #include "kpimtextedit_export.h" namespace KPIMTextEdit { class KPIMTEXTEDIT_EXPORT EmoticonUnicodeTab : public QTabWidget { Q_OBJECT public: explicit EmoticonUnicodeTab(QWidget *parent); ~EmoticonUnicodeTab(); Q_SIGNALS: void itemSelected(const QString &); private: void loadEmoticons(); + void createTab(const QString &str, const QList &emoticons); }; } #endif // EMOTICONUNICODETAB_H