• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • chatwindow
emoticonselector.cpp
Go to the documentation of this file.
1 /*
2  emoticonselector.cpp
3 
4  a button that pops up a list of all emoticons and returns
5  the emoticon-string if one is selected in the list
6 
7  Copyright (c) 2002 by Stefan Gehn <metz@gehn.net>
8  Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
9 
10  Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
11 
12  *************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  *************************************************************************
20 */
21 
22 #include "emoticonselector.h"
23 #include "kopeteemoticons.h"
24 
25 #include <math.h>
26 
27 #include <QPixmap>
28 #include <QMouseEvent>
29 #include <QHBoxLayout>
30 #include <QObject>
31 #include <QHideEvent>
32 #include <QShowEvent>
33 
34 #include <kdebug.h>
35 #include <kemoticons.h>
36 
37 EmoticonItem::EmoticonItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent)
38  : QListWidgetItem(parent)
39 {
40  m_text = emoticonText;
41  m_pixmapPath = pixmapPath;
42  QPixmap p(m_pixmapPath);
43  //
44  // Some of the custom icons are rather large
45  // so lets limit them to a maximum size for this display panel
46  //
47  if (p.width() > 32 || p.height() > 32)
48  p = p.scaled(QSize(32,32), Qt::KeepAspectRatio);
49 
50  setIcon(p);
51 }
52 
53 QString EmoticonItem::text() const
54 {
55  return m_text;
56 }
57 
58 QString EmoticonItem::pixmapPath() const
59 {
60  return m_pixmapPath;
61 }
62 
63 EmoticonSelector::EmoticonSelector(QWidget *parent)
64  : QWidget(parent)
65 {
66  QHBoxLayout *lay = new QHBoxLayout(this);
67  lay->setSpacing( 0 );
68  lay->setContentsMargins( 0, 0, 0, 0 );
69  m_emoticonList = new QListWidget(this);
70  lay->addWidget(m_emoticonList);
71  m_emoticonList->setViewMode(QListView::IconMode);
72  m_emoticonList->setSelectionMode(QAbstractItemView::SingleSelection);
73  m_emoticonList->setMouseTracking(true);
74  m_emoticonList->setDragEnabled(false);
75 
76  m_currentEmoticon = new QLabel( this );
77  m_currentEmoticon->setFrameShape( QFrame::Box );
78  m_currentEmoticon->setMinimumSize(QSize(128,128));
79  m_currentEmoticon->setAlignment( Qt::AlignCenter );
80  lay->addWidget(m_currentEmoticon);
81 
82  m_currentMovie = new QMovie(this);
83  m_currentEmoticon->setMovie(m_currentMovie);
84 
85  connect(m_emoticonList, SIGNAL(itemEntered(QListWidgetItem*)),
86  this, SLOT(mouseOverItem(QListWidgetItem*)));
87  connect(m_emoticonList, SIGNAL(itemSelectionChanged()),
88  this, SLOT(currentChanged()));
89  connect(m_emoticonList, SIGNAL(itemClicked(QListWidgetItem*)),
90  this, SLOT(emoticonClicked(QListWidgetItem*)));
91 
92 }
93 
94 void EmoticonSelector::prepareList(void)
95 {
96  m_emoticonList->clear();
97 // kDebug(14000) << "called.";
98  QHash<QString, QStringList> list = Kopete::Emoticons::self()->theme().emoticonsMap();
99 
100  for (QHash<QString, QStringList>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
101  (void) new EmoticonItem(it.value().first(), it.key(), m_emoticonList);
102 
103  m_emoticonList->setIconSize(QSize(32,32));
104 }
105 
106 void EmoticonSelector::emoticonClicked(QListWidgetItem *i)
107 {
108  EmoticonItem *item = dynamic_cast<EmoticonItem*>(i);
109  if (!item)
110  return;
111 
112  // KDE4/Qt TODO: use qobject_cast instead.
113  emit itemSelected ( item->text() );
114  if ( isVisible() && parentWidget() &&
115  parentWidget()->inherits("QMenu") )
116  {
117  parentWidget()->close();
118  }
119 }
120 
121 void EmoticonSelector::mouseOverItem(QListWidgetItem *item)
122 {
123  item->setSelected(true);
124  if (!m_emoticonList->hasFocus())
125  m_emoticonList->setFocus();
126 }
127 
128 void EmoticonSelector::currentChanged()
129 {
130 
131  if (!m_emoticonList->selectedItems().count())
132  return;
133 
134  EmoticonItem *item = dynamic_cast<EmoticonItem*>(m_emoticonList->selectedItems().first());
135  if (!item)
136  return;
137 
138  m_currentMovie->stop();
139  m_currentMovie->setFileName(item->pixmapPath());
140  m_currentMovie->start();
141  // schedule a full update of the label, so there are no glitches of the previous emoticon
142  // (Qt bug?)
143  m_currentEmoticon->update();
144 }
145 
146 void EmoticonSelector::hideEvent( QHideEvent* )
147 {
148  m_currentMovie->stop();
149 }
150 
151 void EmoticonSelector::showEvent( QShowEvent* )
152 {
153  m_currentMovie->start();
154 }
155 
156 #include "emoticonselector.moc"
157 
158 // vim: set noet ts=4 sts=4 sw=4:
159 
EmoticonSelector::showEvent
virtual void showEvent(QShowEvent *)
Definition: emoticonselector.cpp:151
QWidget
EmoticonItem::pixmapPath
QString pixmapPath() const
Definition: emoticonselector.cpp:58
EmoticonItem::EmoticonItem
EmoticonItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent=0)
Definition: emoticonselector.cpp:37
EmoticonSelector::hideEvent
virtual void hideEvent(QHideEvent *)
Definition: emoticonselector.cpp:146
EmoticonSelector::emoticonClicked
void emoticonClicked(QListWidgetItem *)
Definition: emoticonselector.cpp:106
EmoticonItem::text
QString text() const
Definition: emoticonselector.cpp:53
emoticonselector.h
EmoticonSelector::mouseOverItem
void mouseOverItem(QListWidgetItem *)
Definition: emoticonselector.cpp:121
QListWidgetItem
QLabel
EmoticonSelector::prepareList
void prepareList()
Definition: emoticonselector.cpp:94
EmoticonSelector::EmoticonSelector
EmoticonSelector(QWidget *parent=0)
Definition: emoticonselector.cpp:63
EmoticonSelector::currentChanged
void currentChanged()
Definition: emoticonselector.cpp:128
EmoticonSelector::itemSelected
void itemSelected(const QString &)
gets emitted when an emoticon has been selected from the list the QString holds the emoticon as a str...
EmoticonItem
Definition: emoticonselector.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



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