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

kopete/kopete

emoticonselector.cpp

Go to the documentation of this file.
00001 /*
00002     emoticonselector.cpp
00003 
00004     a button that pops up a list of all emoticons and returns
00005     the emoticon-string if one is selected in the list
00006 
00007     Copyright (c) 2002      by Stefan Gehn            <metz@gehn.net>
00008     Copyright (c) 2003      by Martijn Klingens       <klingens@kde.org>
00009 
00010     Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>
00011 
00012     *************************************************************************
00013     *                                                                       *
00014     * This program is free software; you can redistribute it and/or modify  *
00015     * it under the terms of the GNU General Public License as published by  *
00016     * the Free Software Foundation; either version 2 of the License, or     *
00017     * (at your option) any later version.                                   *
00018     *                                                                       *
00019     *************************************************************************
00020 */
00021 
00022 #include "emoticonselector.h"
00023 #include "kopeteemoticons.h"
00024 
00025 #include <math.h>
00026 
00027 #include <QPixmap>
00028 #include <QMouseEvent>
00029 #include <QHBoxLayout>
00030 #include <QObject>
00031 #include <QHideEvent>
00032 #include <QShowEvent>
00033 
00034 #include <kdebug.h>
00035 #include <kemoticons.h>
00036 
00037 EmoticonItem::EmoticonItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent)
00038     : QListWidgetItem(parent)
00039 {
00040     m_text = emoticonText;
00041     m_pixmapPath = pixmapPath;
00042     QPixmap p(m_pixmapPath);
00043     //
00044     // Some of the custom icons are rather large
00045     // so lets limit them to a maximum size for this display panel
00046     //
00047     if (p.width() > 32 || p.height() > 32)
00048         p = p.scaled(QSize(32,32), Qt::KeepAspectRatio);
00049 
00050     setIcon(p);
00051 }
00052 
00053 QString EmoticonItem::text() const
00054 {
00055     return m_text;
00056 }
00057 
00058 QString EmoticonItem::pixmapPath() const
00059 {
00060     return m_pixmapPath;
00061 }
00062 
00063 EmoticonSelector::EmoticonSelector(QWidget *parent)
00064     : QWidget(parent)
00065 {
00066     QHBoxLayout *lay = new QHBoxLayout(this);
00067     lay->setSpacing( 0 );
00068     lay->setContentsMargins( 0, 0, 0, 0 );
00069     m_emoticonList = new QListWidget(this);
00070     lay->addWidget(m_emoticonList);
00071     m_emoticonList->setViewMode(QListView::IconMode);
00072     m_emoticonList->setSelectionMode(QAbstractItemView::SingleSelection);
00073     m_emoticonList->setMouseTracking(true);
00074     m_emoticonList->setDragEnabled(false);
00075 
00076     m_currentEmoticon = new QLabel( this );
00077     m_currentEmoticon->setFrameShape( QFrame::Box );
00078     m_currentEmoticon->setMinimumSize(QSize(128,128));
00079     m_currentEmoticon->setAlignment( Qt::AlignCenter );
00080     lay->addWidget(m_currentEmoticon);
00081 
00082     m_currentMovie = new QMovie(this);
00083     m_currentEmoticon->setMovie(m_currentMovie);
00084 
00085     connect(m_emoticonList, SIGNAL(itemEntered(QListWidgetItem*)),
00086             this, SLOT(mouseOverItem(QListWidgetItem*)));
00087     connect(m_emoticonList, SIGNAL(itemSelectionChanged()),
00088             this, SLOT(currentChanged()));
00089     connect(m_emoticonList, SIGNAL(itemActivated(QListWidgetItem*)),
00090             this, SLOT(emoticonClicked(QListWidgetItem*)));
00091 
00092 }
00093 
00094 void EmoticonSelector::prepareList(void)
00095 {
00096     m_emoticonList->clear();
00097 //  kDebug(14000) << "called.";
00098     QHash<QString, QStringList> list = Kopete::Emoticons::self()->theme().emoticonsMap();
00099 
00100     for (QHash<QString, QStringList>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
00101         (void) new EmoticonItem(it.value().first(), it.key(), m_emoticonList);
00102 
00103     m_emoticonList->setIconSize(QSize(32,32));
00104 }
00105 
00106 void EmoticonSelector::emoticonClicked(QListWidgetItem *i)
00107 {
00108     EmoticonItem *item = dynamic_cast<EmoticonItem*>(i);
00109     if (!item)
00110         return;
00111 
00112     // KDE4/Qt TODO: use qobject_cast instead.
00113     emit itemSelected ( item->text() );
00114     if ( isVisible() && parentWidget() &&
00115         parentWidget()->inherits("QMenu") )
00116     {
00117         parentWidget()->close();
00118     }
00119 }
00120 
00121 void EmoticonSelector::mouseOverItem(QListWidgetItem *item)
00122 {
00123     item->setSelected(true);    
00124     if (!m_emoticonList->hasFocus())
00125         m_emoticonList->setFocus();
00126 }
00127 
00128 void EmoticonSelector::currentChanged()
00129 {
00130 
00131     if (!m_emoticonList->selectedItems().count())
00132         return;
00133 
00134     EmoticonItem *item = dynamic_cast<EmoticonItem*>(m_emoticonList->selectedItems().first());
00135     if (!item)
00136         return;
00137 
00138     m_currentMovie->stop();
00139     m_currentMovie->setFileName(item->pixmapPath());
00140     m_currentMovie->start();
00141     // schedule a full update of the label, so there are no glitches of the previous emoticon
00142     // (Qt bug?)
00143     m_currentEmoticon->update();
00144 }
00145 
00146 void EmoticonSelector::hideEvent( QHideEvent* )
00147 {
00148     m_currentMovie->stop();
00149 }
00150 
00151 void EmoticonSelector::showEvent( QShowEvent* )
00152 {
00153     m_currentMovie->start();
00154 }
00155 
00156 #include "emoticonselector.moc"
00157 
00158 // vim: set noet ts=4 sts=4 sw=4:
00159 

kopete/kopete

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal