• 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.14
  • 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
QHideEvent
QWidget::close
bool close()
QWidget
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
QListView::setViewMode
void setViewMode(ViewMode mode)
QPixmap::width
int width() const
QMovie::stop
void stop()
QAbstractItemView::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QFrame::setFrameShape
void setFrameShape(Shape)
QMovie
QListWidgetItem
QWidget::isVisible
bool isVisible() const
QHBoxLayout
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
EmoticonItem::pixmapPath
QString pixmapPath() const
Definition: emoticonselector.cpp:58
QWidget::hasFocus
bool hasFocus() const
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
QListWidget
QWidget::update
void update()
EmoticonSelector::emoticonClicked
void emoticonClicked(QListWidgetItem *)
Definition: emoticonselector.cpp:106
QWidget::setMinimumSize
void setMinimumSize(const QSize &)
QMovie::setFileName
void setFileName(const QString &fileName)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
EmoticonItem::text
QString text() const
Definition: emoticonselector.cpp:53
QHash::constEnd
const_iterator constEnd() const
QListWidget::clear
void clear()
QHash
QObject::inherits
bool inherits(const char *className) const
QShowEvent
QAbstractItemView::setIconSize
void setIconSize(const QSize &size)
QLabel::setMovie
void setMovie(QMovie *movie)
QWidget::setFocus
void setFocus()
emoticonselector.h
QPixmap::scaled
QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QString
EmoticonSelector::mouseOverItem
void mouseOverItem(QListWidgetItem *)
Definition: emoticonselector.cpp:121
QPixmap
QListWidget::selectedItems
QList< QListWidgetItem * > selectedItems() const
QSize
QListWidgetItem::setIcon
void setIcon(const QIcon &icon)
QPixmap::height
int height() const
QHash::const_iterator
QHash::constBegin
const_iterator constBegin() const
QWidget::parentWidget
QWidget * parentWidget() const
QWidget::setMouseTracking
void setMouseTracking(bool enable)
EmoticonSelector::prepareList
void prepareList()
Definition: emoticonselector.cpp:94
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
EmoticonSelector::EmoticonSelector
EmoticonSelector(QWidget *parent=0)
Definition: emoticonselector.cpp:63
QMovie::start
void start()
QListWidgetItem::setSelected
void setSelected(bool select)
EmoticonSelector::currentChanged
void currentChanged()
Definition: emoticonselector.cpp:128
QBoxLayout::setSpacing
void setSpacing(int spacing)
QAbstractItemView::setDragEnabled
void setDragEnabled(bool enable)
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:08 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