Commit 94fa651e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 192825 - Smiley selector in composer

FIXED-IN: 4.9
BUG: 192825
parent 8adbe68f
......@@ -7,7 +7,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
############### The kdepimlibs version (used e.g. in KdepimLibsConfig.cmake) ###############
set(KDEPIMLIBS_VERSION_MAJOR 4)
set(KDEPIMLIBS_VERSION_MINOR 8)
set(KDEPIMLIBS_VERSION_PATCH 41)
set(KDEPIMLIBS_VERSION_PATCH 42)
set(KDEPIMLIBS_VERSION ${KDEPIMLIBS_VERSION_MAJOR}.${KDEPIMLIBS_VERSION_MINOR}.${KDEPIMLIBS_VERSION_PATCH})
......
......@@ -8,6 +8,8 @@ set(kpimtextedit_lib_srcs
emailquotehighlighter.cpp
textedit.cpp
textutils.cpp
emoticontexteditaction.cpp
emoticontexteditselector.cpp
)
kde4_add_library(kpimtextedit ${LIBRARY_TYPE} ${kpimtextedit_lib_srcs})
......@@ -15,6 +17,7 @@ kde4_add_library(kpimtextedit ${LIBRARY_TYPE} ${kpimtextedit_lib_srcs})
target_link_libraries(kpimtextedit
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${KDE4_KUTILS_LIBS}
kmime
)
......
/* -*- mode: C++; c-file-style: "gnu" -*-
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "emoticontexteditaction.h"
#include "emoticontexteditselector.h"
#include <KLocale>
#include <KMenu>
#include <QWidgetAction>
using namespace KPIMTextEdit;
class EmoticonTextEditAction::EmoticonTextEditActionPrivate
{
public:
EmoticonTextEditActionPrivate() {
emoticonMenu = new KMenu();
selector = new EmoticonTextEditSelector( emoticonMenu );
QWidgetAction *action = new QWidgetAction(emoticonMenu);
action->setDefaultWidget(selector);
emoticonMenu->addAction(action);
connect( emoticonMenu, SIGNAL(aboutToShow()), selector, SLOT(slotCreateEmoticonList()) );
}
~EmoticonTextEditActionPrivate() {
delete emoticonMenu;
}
KMenu *emoticonMenu;
EmoticonTextEditSelector *selector;
};
EmoticonTextEditAction::EmoticonTextEditAction( QObject * parent )
: KActionMenu( i18n( "Add Smiley" ), parent ), d( new EmoticonTextEditActionPrivate() )
{
setMenu( d->emoticonMenu );
setIcon( KIcon(QLatin1String( "emoticon" )) );
setShortcutConfigurable( false );
connect( d->selector, SIGNAL(itemSelected(QString)),
this, SIGNAL(emoticonActivated(QString)) );
}
EmoticonTextEditAction::~EmoticonTextEditAction()
{
delete d;
}
#include "emoticontexteditaction.moc"
/* -*- mode: C++; c-file-style: "gnu" -*-
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EMOTICONTEXTEDITACTION_H
#define EMOTICONTEXTEDITACTION_H
#include <KActionMenu>
namespace KPIMTextEdit {
class EmoticonTextEditAction : public KActionMenu
{
Q_OBJECT
public:
explicit EmoticonTextEditAction( QObject * parent );
~EmoticonTextEditAction();
Q_SIGNALS:
void emoticonActivated(const QString&);
private:
class EmoticonTextEditActionPrivate;
EmoticonTextEditActionPrivate *d;
};
}
#endif /* EMOTICONTEXTEDITACTION_H */
/* -*- mode: C++; c-file-style: "gnu" -*-
Copyright (c) 2012 Montel Laurent <montel@kde.org>
based on code from kopete
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "emoticontexteditselector.h"
#include <KEmoticons>
#include <kemoticonstheme.h>
#include <QListWidget>
#include <QPixmap>
#include <QHBoxLayout>
// Use a static for this as calls to the KEmoticons constructor are expensive.
K_GLOBAL_STATIC( KEmoticons, sEmoticons )
using namespace KPIMTextEdit;
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
//
if (p.width() > 32 || p.height() > 32)
p = p.scaled(QSize(32,32), Qt::KeepAspectRatio);
setIcon(p);
}
QString EmoticonTextEditItem::text() const
{
return mText;
}
QString EmoticonTextEditItem::pixmapPath() const
{
return mPixmapPath;
}
class EmoticonTextEditSelector::EmoticonTextEditSelectorPrivate
{
public:
EmoticonTextEditSelectorPrivate() {
}
QListWidget *listEmoticon;
};
EmoticonTextEditSelector::EmoticonTextEditSelector( QWidget * parent )
:QWidget( parent ), d( new EmoticonTextEditSelectorPrivate() )
{
QHBoxLayout *lay = new QHBoxLayout(this);
lay->setSpacing( 0 );
lay->setContentsMargins( 0, 0, 0, 0 );
d->listEmoticon = new QListWidget(this);
lay->addWidget( d->listEmoticon );
d->listEmoticon->setViewMode(QListView::IconMode);
d->listEmoticon->setSelectionMode(QAbstractItemView::SingleSelection);
d->listEmoticon->setMouseTracking(true);
d->listEmoticon->setDragEnabled(false);
connect(d->listEmoticon, SIGNAL(itemEntered(QListWidgetItem*)),
this, SLOT(slotMouseOverItem(QListWidgetItem*)));
connect(d->listEmoticon, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(slotEmoticonClicked(QListWidgetItem*)));
}
EmoticonTextEditSelector::~EmoticonTextEditSelector()
{
delete d;
}
void EmoticonTextEditSelector::slotCreateEmoticonList()
{
d->listEmoticon->clear();
static QString cachedEmoticonsThemeName;
if ( cachedEmoticonsThemeName.isEmpty() ) {
cachedEmoticonsThemeName = KEmoticons::currentThemeName();
}
const QHash<QString, QStringList> list = sEmoticons->theme( cachedEmoticonsThemeName ).emoticonsMap();
QHash<QString, QStringList>::const_iterator end = list.constEnd();
for (QHash<QString, QStringList>::const_iterator it = list.constBegin(); it != end; ++it ) {
new EmoticonTextEditItem(it.value().first(), it.key(), d->listEmoticon);
}
d->listEmoticon->setIconSize(QSize(32,32));
}
void EmoticonTextEditSelector::slotMouseOverItem(QListWidgetItem* item)
{
item->setSelected(true);
if (!d->listEmoticon->hasFocus())
d->listEmoticon->setFocus();
}
void EmoticonTextEditSelector::slotEmoticonClicked(QListWidgetItem*item)
{
if (!item)
return;
EmoticonTextEditItem *itemEmoticon = static_cast<EmoticonTextEditItem*>(item);
emit itemSelected ( itemEmoticon->text() );
if ( isVisible() && parentWidget() &&
parentWidget()->inherits("QMenu") )
{
parentWidget()->close();
}
}
/* -*- mode: C++; c-file-style: "gnu" -*-
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EMOTICONTEXTEDITSELECTOR_H
#define EMOTICONTEXTEDITSELECTOR_H
#include <QWidget>
#include <QListWidgetItem>
namespace KPIMTextEdit {
class EmoticonTextEditItem : public QListWidgetItem
{
public:
explicit EmoticonTextEditItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent);
QString text() const;
QString pixmapPath() const;
private:
QString mText;
QString mPixmapPath;
};
class EmoticonTextEditSelector : public QWidget
{
Q_OBJECT
public:
explicit EmoticonTextEditSelector( QWidget * parent = 0 );
~EmoticonTextEditSelector();
public Q_SLOTS:
void slotCreateEmoticonList();
private Q_SLOTS:
void slotMouseOverItem(QListWidgetItem*);
void slotEmoticonClicked(QListWidgetItem*);
Q_SIGNALS:
void itemSelected ( const QString& );
private:
class EmoticonTextEditSelectorPrivate;
EmoticonTextEditSelectorPrivate *d;
};
}
#endif /* EMOTICONTEXTEDITSELECTOR_H */
......@@ -22,6 +22,7 @@
#include "textedit.h"
#include "emailquotehighlighter.h"
#include "emoticontexteditaction.h"
#include <kmime/kmime_codecs.h>
......@@ -55,7 +56,8 @@ class TextEditPrivate
: actionAddImage( 0 ),
actionDeleteLine( 0 ),
q( parent ),
imageSupportEnabled( false )
imageSupportEnabled( false ),
emoticonSupportEnabled( false )
{
}
......@@ -93,18 +95,21 @@ class TextEditPrivate
void _k_slotDeleteLine();
void _k_slotAddEmoticon(const QString&);
/// The action that triggers _k_slotAddImage()
KAction *actionAddImage;
/// The action that triggers _k_slotDeleteLine()
KAction *actionDeleteLine;
EmoticonTextEditAction *actionAddEmoticon;
/// The parent class
TextEdit *q;
/// Whether or not adding or pasting images is supported
bool imageSupportEnabled;
bool emoticonSupportEnabled;
/**
* The names of embedded images.
* Used to easily obtain the names of the images.
......@@ -379,6 +384,11 @@ void TextEdit::createActions( KActionCollection *actionCollection )
actionCollection->addAction( QLatin1String( "add_image" ), d->actionAddImage );
connect( d->actionAddImage, SIGNAL(triggered(bool)), SLOT(_k_slotAddImage()) );
}
if ( d->emoticonSupportEnabled ) {
d->actionAddEmoticon = new EmoticonTextEditAction( this );
actionCollection->addAction( QLatin1String( "add_emoticon" ), d->actionAddEmoticon );
connect( d->actionAddEmoticon, SIGNAL(emoticonActivated(QString)), SLOT(_k_slotAddEmoticon(QString)) );
}
d->actionDeleteLine = new KAction( i18n( "Delete Line" ), this );
d->actionDeleteLine->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_K ) );
......@@ -415,7 +425,7 @@ void TextEdit::loadImage ( const QImage &image, const QString &matchName,
QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
if ( imageFormat.isValid() && imageFormat.name() == matchName ) {
int pos = fragment.position();
if ( !cursorPositionsToSkip.contains( pos ) ) {
if ( !cursorPositionsToSkip.contains( pos ) ) {
QTextCursor cursor( document() );
cursor.setPosition( pos );
cursor.setPosition( pos + 1, QTextCursor::KeepAnchor );
......@@ -533,6 +543,12 @@ QList<QTextImageFormat> TextEditPrivate::embeddedImageFormats() const
return retList;
}
void TextEditPrivate::_k_slotAddEmoticon( const QString& text)
{
QTextCursor cursor = q->textCursor();
cursor.insertText( text );
}
void TextEditPrivate::_k_slotAddImage()
{
QPointer<KFileDialog> fdlg = new KFileDialog( QString(), QString(), q );
......@@ -562,6 +578,17 @@ bool KPIMTextEdit::TextEdit::isEnableImageActions() const
return d->imageSupportEnabled;
}
void KPIMTextEdit::TextEdit::enableEmoticonActions()
{
d->emoticonSupportEnabled = true;
}
bool KPIMTextEdit::TextEdit::isEnableEmoticonActions() const
{
return d->emoticonSupportEnabled;
}
QByteArray KPIMTextEdit::TextEdit::imageNamesToContentIds(
const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList )
{
......
......@@ -118,7 +118,13 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
* Don't call this if you don't want to support adding images.
*/
void enableImageActions();
/**
* Calling this allows createActions() to create the add emoticons actions.
* Call this method before calling createActions(), otherwise the action
* will not be added.
* Don't call this if you don't want to support emoticons actions.
*/
void enableEmoticonActions();
/**
* Destructor
*/
......@@ -267,6 +273,11 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
*/
bool isEnableImageActions() const;
/** Return true if emoticons actions supported
* @since 4.9
*/
bool isEnableEmoticonActions() const;
/**
* @since 4.6
*/
......@@ -326,6 +337,7 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
friend class TextEditPrivate;
Q_PRIVATE_SLOT( d, void _k_slotAddImage() )
Q_PRIVATE_SLOT( d, void _k_slotDeleteLine() )
Q_PRIVATE_SLOT( d, void _k_slotAddEmoticon(const QString &) )
};
} // namespace
......
Supports Markdown
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