• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.5 API Reference
  • KDE Home
  • Contact Us
 

KPIMTextedit Library

  • kpimtextedit
emoticontexteditselector.cpp
1 /*
2  Copyright (c) 2012 Montel Laurent <montel@kde.org>
3  based on code from kopete
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "emoticontexteditselector.h"
22 
23 #include <KEmoticons>
24 #include <kemoticonstheme.h>
25 
26 #include <QListWidget>
27 #include <QPixmap>
28 #include <QHBoxLayout>
29 
30 // Use a static for this as calls to the KEmoticons constructor are expensive.
31 K_GLOBAL_STATIC( KEmoticons, sEmoticons )
32 
33  using namespace KPIMTextEdit;
34 
35 EmoticonTextEditItem::EmoticonTextEditItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent)
36  : QListWidgetItem(parent)
37 {
38  mText = emoticonText;
39  mPixmapPath = pixmapPath;
40  QPixmap p(mPixmapPath);
41  // Some of the custom icons are rather large
42  // so lets limit them to a maximum size for this display panel
43  //
44  if (p.width() > 32 || p.height() > 32)
45  p = p.scaled(QSize(32,32), Qt::KeepAspectRatio);
46 
47  setIcon(p);
48  setToolTip(mText);
49 }
50 
51 QString EmoticonTextEditItem::text() const
52 {
53  return mText;
54 }
55 
56 QString EmoticonTextEditItem::pixmapPath() const
57 {
58  return mPixmapPath;
59 }
60 
61 class EmoticonTextEditSelector::EmoticonTextEditSelectorPrivate
62 {
63 public:
64  EmoticonTextEditSelectorPrivate() {
65 
66  }
67  QListWidget *listEmoticon;
68 };
69 
70 
71 EmoticonTextEditSelector::EmoticonTextEditSelector( QWidget * parent )
72  :QWidget( parent ), d( new EmoticonTextEditSelectorPrivate() )
73 {
74  QHBoxLayout *lay = new QHBoxLayout(this);
75  lay->setSpacing( 0 );
76  lay->setContentsMargins( 0, 0, 0, 0 );
77  d->listEmoticon = new QListWidget(this);
78  lay->addWidget( d->listEmoticon );
79  d->listEmoticon->setViewMode(QListView::IconMode);
80  d->listEmoticon->setSelectionMode(QAbstractItemView::SingleSelection);
81  d->listEmoticon->setMouseTracking(true);
82  d->listEmoticon->setDragEnabled(false);
83  connect(d->listEmoticon, SIGNAL(itemEntered(QListWidgetItem*)),
84  this, SLOT(slotMouseOverItem(QListWidgetItem*)));
85  connect(d->listEmoticon, SIGNAL(itemClicked(QListWidgetItem*)),
86  this, SLOT(slotEmoticonClicked(QListWidgetItem*)));
87 
88 }
89 
90 EmoticonTextEditSelector::~EmoticonTextEditSelector()
91 {
92  delete d;
93 }
94 
95 
96 void EmoticonTextEditSelector::slotCreateEmoticonList()
97 {
98  d->listEmoticon->clear();
99  static QString cachedEmoticonsThemeName;
100  if ( cachedEmoticonsThemeName.isEmpty() ) {
101  cachedEmoticonsThemeName = KEmoticons::currentThemeName();
102  }
103  const QHash<QString, QStringList> list = sEmoticons->theme( cachedEmoticonsThemeName ).emoticonsMap();
104 
105  QHash<QString, QStringList>::const_iterator end = list.constEnd();
106  for (QHash<QString, QStringList>::const_iterator it = list.constBegin(); it != end; ++it ) {
107  new EmoticonTextEditItem(it.value().first(), it.key(), d->listEmoticon);
108  }
109 
110  d->listEmoticon->setIconSize(QSize(32,32));
111 }
112 
113 
114 void EmoticonTextEditSelector::slotMouseOverItem(QListWidgetItem* item)
115 {
116  item->setSelected(true);
117  if (!d->listEmoticon->hasFocus())
118  d->listEmoticon->setFocus();
119 }
120 
121 
122 void EmoticonTextEditSelector::slotEmoticonClicked(QListWidgetItem*item)
123 {
124  if (!item)
125  return;
126  EmoticonTextEditItem *itemEmoticon = static_cast<EmoticonTextEditItem*>(item);
127 
128  emit itemSelected ( itemEmoticon->text() );
129  if ( isVisible() && parentWidget() &&
130  parentWidget()->inherits("QMenu") )
131  {
132  parentWidget()->close();
133  }
134 
135 }
136 
137 #include "emoticontexteditselector.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:44:40 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPIMTextedit Library

Skip menu "KPIMTextedit Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.5 API Reference

Skip menu "kdepimlibs-4.9.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal