Commit c746b765 authored by Laurent Montel's avatar Laurent Montel 😁

Extract code

parent 65c2fae2
......@@ -50,6 +50,7 @@ set(kpimtextedit_emoticon_builder_SRCS
emoticon/emoticontexteditaction.cpp
emoticon/emoticontexteditselector.cpp
emoticon/emoticonunicodetab.cpp
emoticon/emoticonlistwidgetselector.cpp
)
set(kpimtextedit_SRCS
......
/*
Copyright (c) 2019 Montel Laurent <montel@kde.org>
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::slotEmoticonClicked(QListWidgetItem *item)
{
if (!item) {
return;
}
EmoticonTextEditItem *itemEmoticon = static_cast<EmoticonTextEditItem *>(item);
Q_EMIT itemSelected(itemEmoticon->text());
}
/*
Copyright (c) 2019 Montel Laurent <montel@kde.org>
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 <QListWidget>
namespace KPIMTextEdit {
class 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 EmoticonListWidgetSelector : public QListWidget
{
Q_OBJECT
public:
explicit EmoticonListWidgetSelector(QWidget *parent);
~EmoticonListWidgetSelector();
Q_SIGNALS:
void itemSelected(const QString &);
private:
void slotMouseOverItem(QListWidgetItem *item);
void slotEmoticonClicked(QListWidgetItem *item);
};
}
#endif // EMOTICONLISTWIDGETSELECTOR_H
......@@ -18,6 +18,7 @@
02110-1301, USA.
*/
#include "emoticonlistwidgetselector.h"
#include "emoticontexteditselector.h"
#include "textutils.h"
#include <KEmoticons>
......@@ -32,42 +33,6 @@ Q_GLOBAL_STATIC(KEmoticons, sEmoticons)
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;
}
EmoticonTextEditSelector::EmoticonTextEditSelector(QWidget *parent)
: QWidget(parent)
......@@ -75,20 +40,24 @@ EmoticonTextEditSelector::EmoticonTextEditSelector(QWidget *parent)
QHBoxLayout *lay = new QHBoxLayout(this);
lay->setSpacing(0);
lay->setContentsMargins(0, 0, 0, 0);
mListEmoticon = new QListWidget(this);
mListEmoticon = new EmoticonListWidgetSelector(this);
lay->addWidget(mListEmoticon);
mListEmoticon->setViewMode(QListView::IconMode);
mListEmoticon->setSelectionMode(QAbstractItemView::SingleSelection);
mListEmoticon->setMouseTracking(true);
mListEmoticon->setDragEnabled(false);
connect(mListEmoticon, &QListWidget::itemEntered, this, &EmoticonTextEditSelector::slotMouseOverItem);
connect(mListEmoticon, &QListWidget::itemClicked, this, &EmoticonTextEditSelector::slotEmoticonClicked);
connect(mListEmoticon, &EmoticonListWidgetSelector::itemSelected, this, &EmoticonTextEditSelector::slotItemSelected);
}
EmoticonTextEditSelector::~EmoticonTextEditSelector()
{
}
void EmoticonTextEditSelector::slotItemSelected(const QString &str)
{
Q_EMIT itemSelected(str);
if (isVisible() && parentWidget()
&& parentWidget()->inherits("QMenu")) {
parentWidget()->close();
}
}
void EmoticonTextEditSelector::slotCreateEmoticonList()
{
mListEmoticon->clear();
......@@ -129,28 +98,6 @@ void EmoticonTextEditSelector::slotCreateEmoticonList()
mListEmoticon->setIconSize(QSize(32, 32));
}
void EmoticonTextEditSelector::slotMouseOverItem(QListWidgetItem *item)
{
item->setSelected(true);
if (!mListEmoticon->hasFocus()) {
mListEmoticon->setFocus();
}
}
void EmoticonTextEditSelector::slotEmoticonClicked(QListWidgetItem *item)
{
if (!item) {
return;
}
EmoticonTextEditItem *itemEmoticon = static_cast<EmoticonTextEditItem *>(item);
Q_EMIT itemSelected(itemEmoticon->text());
if (isVisible() && parentWidget()
&& parentWidget()->inherits("QMenu")) {
parentWidget()->close();
}
}
bool EmoticonTextEditSelector::emojiPlainText() const
{
return mEmojiPlainText;
......@@ -160,3 +107,4 @@ void EmoticonTextEditSelector::setEmojiPlainText(bool emojiPlainText)
{
mEmojiPlainText = emojiPlainText;
}
......@@ -25,18 +25,8 @@
#include <QWidget>
namespace KPIMTextEdit {
class 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;
class EmoticonListWidgetSelector;
private:
QString mText;
QString mPixmapPath;
};
class EmoticonTextEditSelector : public QWidget
{
......@@ -51,15 +41,12 @@ public:
public Q_SLOTS:
void slotCreateEmoticonList();
private Q_SLOTS:
void slotMouseOverItem(QListWidgetItem *);
void slotEmoticonClicked(QListWidgetItem *);
Q_SIGNALS:
void itemSelected(const QString &);
private:
QListWidget *mListEmoticon = nullptr;
void slotItemSelected(const QString &str);
EmoticonListWidgetSelector *mListEmoticon = nullptr;
bool mEmojiPlainText = false;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment