• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.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 
48  setIcon( p );
49  setToolTip( mText );
50 }
51 
52 QString EmoticonTextEditItem::text() const
53 {
54  return mText;
55 }
56 
57 QString EmoticonTextEditItem::pixmapPath() const
58 {
59  return mPixmapPath;
60 }
61 
62 class EmoticonTextEditSelector::EmoticonTextEditSelectorPrivate
63 {
64 public:
65  EmoticonTextEditSelectorPrivate() {
66  }
67  QListWidget *listEmoticon;
68 };
69 
70 EmoticonTextEditSelector::EmoticonTextEditSelector( QWidget * parent )
71  :QWidget( parent ), d( new EmoticonTextEditSelectorPrivate() )
72 {
73  QHBoxLayout *lay = new QHBoxLayout( this );
74  lay->setSpacing( 0 );
75  lay->setContentsMargins( 0, 0, 0, 0 );
76  d->listEmoticon = new QListWidget( this );
77  lay->addWidget( d->listEmoticon );
78  d->listEmoticon->setViewMode( QListView::IconMode );
79  d->listEmoticon->setSelectionMode( QAbstractItemView::SingleSelection );
80  d->listEmoticon->setMouseTracking( true );
81  d->listEmoticon->setDragEnabled( false );
82  connect( d->listEmoticon, SIGNAL(itemEntered(QListWidgetItem*)),
83  this, SLOT(slotMouseOverItem(QListWidgetItem*)) );
84  connect( d->listEmoticon, SIGNAL(itemClicked(QListWidgetItem*)),
85  this, SLOT(slotEmoticonClicked(QListWidgetItem*)) );
86 }
87 
88 EmoticonTextEditSelector::~EmoticonTextEditSelector()
89 {
90  delete d;
91 }
92 
93 void EmoticonTextEditSelector::slotCreateEmoticonList()
94 {
95  d->listEmoticon->clear();
96  static QString cachedEmoticonsThemeName;
97  if ( cachedEmoticonsThemeName.isEmpty() ) {
98  cachedEmoticonsThemeName = KEmoticons::currentThemeName();
99  }
100  const QHash<QString, QStringList> list = sEmoticons->theme( cachedEmoticonsThemeName ).emoticonsMap();
101 
102  //Keep in sync with linklocator.cpp
103  QStringList exclude;
104  exclude << QLatin1String("(c)") << QLatin1String("(C)") << QLatin1String("&gt;:-(") << QLatin1String("&gt;:(") << QLatin1String("(B)") << QLatin1String("(b)") << QLatin1String("(P)") << QLatin1String("(p)");
105  exclude << QLatin1String("(O)") << QLatin1String("(o)") << QLatin1String("(D)") << QLatin1String("(d)") << QLatin1String("(E)") << QLatin1String("(e)") << QLatin1String("(K)") << QLatin1String("(k)");
106  exclude << QLatin1String("(I)") << QLatin1String("(i)") << QLatin1String("(L)") << QLatin1String("(l)") << QLatin1String("(8)") << QLatin1String("(T)") << QLatin1String("(t)") << QLatin1String("(G)");
107  exclude << QLatin1String("(g)") << QLatin1String("(F)") << QLatin1String("(f)") << QLatin1String("(H)");
108  exclude << QLatin1String("8)") << QLatin1String("(N)") << QLatin1String("(n)") << QLatin1String("(Y)") << QLatin1String("(y)") << QLatin1String("(U)") << QLatin1String("(u)") << QLatin1String("(W)") << QLatin1String("(w)");
109 
110  QHash<QString, QStringList>::const_iterator end = list.constEnd();
111  for ( QHash<QString, QStringList>::const_iterator it = list.constBegin(); it != end; ++it ) {
112  if (!exclude.contains(it.value().first()))
113  new EmoticonTextEditItem( it.value().first(), it.key(), d->listEmoticon );
114  }
115 
116  d->listEmoticon->setIconSize( QSize( 32, 32 ) );
117 }
118 
119 
120 void EmoticonTextEditSelector::slotMouseOverItem(QListWidgetItem* item)
121 {
122  item->setSelected( true );
123  if ( !d->listEmoticon->hasFocus() ) {
124  d->listEmoticon->setFocus();
125  }
126 }
127 
128 
129 void EmoticonTextEditSelector::slotEmoticonClicked(QListWidgetItem*item)
130 {
131  if ( !item ) {
132  return;
133  }
134  EmoticonTextEditItem *itemEmoticon = static_cast<EmoticonTextEditItem*>( item );
135 
136  emit itemSelected ( itemEmoticon->text() );
137  if ( isVisible() && parentWidget() &&
138  parentWidget()->inherits( "QMenu" ) ) {
139  parentWidget()->close();
140  }
141 }
142 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:01 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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