Hi I've reworked the emoticon theme selector in order to show a preview of each theme below the theme name (so that the user doesn't have to click each theme to see what the theme is). The time loading the config module is a bit bigger, but I guess it is still an improvement.
Screenshots at http://boiko.rallyzeiros.com.br/?p=23 Please review it. Cheers -- Gustavo Pichorim Boiko ----------------------------------- KDE Developer www.kde.org Mandriva Labs www.mandriva.com
Index: kopete/config/chatwindow/emoticonthemeitem.cpp =================================================================== --- kopete/config/chatwindow/emoticonthemeitem.cpp (revisão 0) +++ kopete/config/chatwindow/emoticonthemeitem.cpp (revisão 0) @@ -0,0 +1,32 @@ +/* + emoticonthemeitem - Kopete Emoticon Theme Item + + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> + + Kopete (c) 2007 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "emoticonthemeitem.h" + +#include <kopeteemoticons.h> + +EmoticonThemeItem::EmoticonThemeItem(const QString &theme) +: QListWidgetItem(theme, 0, UserType) +{ + // list the theme + Kopete::Emoticons emoticons( theme ); + setData(EmoticonList, QStringList(emoticons.emoticonAndPicList().keys())); + + // set the emoticon pixmap list as an empty list: pixmaps will be added to + // the list as they are rendered by the delegator + setData(EmoticonPixmaps, QList<QVariant>()); +} Mudanças de propriedades em: kopete/config/chatwindow/emoticonthemeitem.cpp ___________________________________________________________________ Nome: svn:eol-style + native Index: kopete/config/chatwindow/emoticonthemedelegate.h =================================================================== --- kopete/config/chatwindow/emoticonthemedelegate.h (revisão 0) +++ kopete/config/chatwindow/emoticonthemedelegate.h (revisão 0) @@ -0,0 +1,32 @@ +#ifndef EMOTICONTHEMEDELEGATE_H +#define EMOTICONTHEMEDELEGATE_H + +/* + emoticonthemedelegate - Kopete Emoticon Theme Delegate + + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> + + Kopete (c) 2007 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <QAbstractItemDelegate> + +class EmoticonThemeDelegate : public QAbstractItemDelegate +{ + Q_OBJECT +public: + EmoticonThemeDelegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + +#endif Mudanças de propriedades em: kopete/config/chatwindow/emoticonthemedelegate.h ___________________________________________________________________ Nome: svn:eol-style + native Index: kopete/config/chatwindow/chatwindowconfig.h =================================================================== --- kopete/config/chatwindow/chatwindowconfig.h (revisão 733223) +++ kopete/config/chatwindow/chatwindowconfig.h (cópia de trabalho) @@ -1,10 +1,11 @@ /* - appearanceconfig.h - Kopete Look Feel Config + chatwindowconfig.h - Kopete Look Feel Config Copyright (c) 2005-2006 by Michaël Larouche <[EMAIL PROTECTED]> Copyright (c) 2005-2006 by Olivier Goffart <ogoffart at kde.org> + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> - Kopete (c) 2005-2006 by the Kopete developers <[email protected]> + Kopete (c) 2005-2007 by the Kopete developers <[email protected]> ************************************************************************* * * Index: kopete/config/chatwindow/emoticonthemeitem.h =================================================================== --- kopete/config/chatwindow/emoticonthemeitem.h (revisão 0) +++ kopete/config/chatwindow/emoticonthemeitem.h (revisão 0) @@ -0,0 +1,36 @@ +#ifndef EMOTICONTHEMEITEM_H +#define EMOTICONTHEMEITEM_H + +/* + emoticonthemeitem - Kopete Emoticon Theme Item + + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> + + Kopete (c) 2007 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <QListWidgetItem> + +class QLabel; + +class EmoticonThemeItem : public QListWidgetItem +{ +public: + enum DataRole + { + EmoticonList = 32, + EmoticonPixmaps = 33 + }; + EmoticonThemeItem(const QString &theme); +}; + +#endif Mudanças de propriedades em: kopete/config/chatwindow/emoticonthemeitem.h ___________________________________________________________________ Nome: svn:eol-style + native Index: kopete/config/chatwindow/chatwindowconfig_emoticons.ui =================================================================== --- kopete/config/chatwindow/chatwindowconfig_emoticons.ui (revisão 733223) +++ kopete/config/chatwindow/chatwindowconfig_emoticons.ui (cópia de trabalho) @@ -65,65 +65,10 @@ </widget> </item> <item row="3" column="0" colspan="4" > - <widget class="QSplitter" name="splitter" > - <property name="orientation" > - <enum>Qt::Vertical</enum> + <widget class="QListWidget" name="icon_theme_list" > + <property name="alternatingRowColors" > + <bool>true</bool> </property> - <widget class="K3ListBox" name="icon_theme_list" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Expanding" hsizetype="Preferred" > - <horstretch>0</horstretch> - <verstretch>10</verstretch> - </sizepolicy> - </property> - </widget> - <widget class="QGroupBox" name="previewBox" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Preferred" hsizetype="Preferred" > - <horstretch>0</horstretch> - <verstretch>1</verstretch> - </sizepolicy> - </property> - <property name="title" > - <string>Preview</string> - </property> - <property name="flat" > - <bool>true</bool> - </property> - <layout class="QHBoxLayout" > - <property name="leftMargin" > - <number>1</number> - </property> - <property name="topMargin" > - <number>1</number> - </property> - <property name="rightMargin" > - <number>1</number> - </property> - <property name="bottomMargin" > - <number>1</number> - </property> - <item> - <widget class="KTextEdit" name="icon_theme_preview" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Expanding" hsizetype="Preferred" > - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize" > - <size> - <width>32767</width> - <height>32767</height> - </size> - </property> - <property name="readOnly" > - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> </widget> </item> <item row="4" column="0" > @@ -188,18 +133,6 @@ </widget> <layoutdefault spacing="6" margin="11" /> <pixmapfunction>qPixmapFromMimeSource</pixmapfunction> - <customwidgets> - <customwidget> - <class>KTextEdit</class> - <extends>QTextEdit</extends> - <header>ktextedit.h</header> - </customwidget> - <customwidget> - <class>K3ListBox</class> - <extends>Q3ListBox</extends> - <header>k3listbox.h</header> - </customwidget> - </customwidgets> <resources/> <connections> <connection> @@ -221,22 +154,6 @@ <connection> <sender>kcfg_useEmoticons</sender> <signal>toggled(bool)</signal> - <receiver>icon_theme_list</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel" > - <x>20</x> - <y>20</y> - </hint> - <hint type="destinationlabel" > - <x>20</x> - <y>20</y> - </hint> - </hints> - </connection> - <connection> - <sender>kcfg_useEmoticons</sender> - <signal>toggled(bool)</signal> <receiver>textLabel1</receiver> <slot>setEnabled(bool)</slot> <hints> Index: kopete/config/chatwindow/emoticonthemedelegate.cpp =================================================================== --- kopete/config/chatwindow/emoticonthemedelegate.cpp (revisão 0) +++ kopete/config/chatwindow/emoticonthemedelegate.cpp (revisão 0) @@ -0,0 +1,107 @@ +/* + emoticonthemedelegate - Kopete Emoticon Theme Delegate + + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> + + Kopete (c) 2007 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "emoticonthemedelegate.h" +#include "emoticonthemeitem.h" // for the enum +#include <QModelIndex> +#include <QPainter> + +EmoticonThemeDelegate::EmoticonThemeDelegate(QObject *parent) +: QAbstractItemDelegate(parent) +{ +} + +void EmoticonThemeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QString theme = index.data().toString(); + + QVariant v = index.data(EmoticonThemeItem::EmoticonPixmaps); + QList<QVariant> pixmapList = qvariant_cast<QList<QVariant> >(v); + + if (option.state & QStyle::State_Selected) + painter->fillRect(option.rect, option.palette.brush(QPalette::Normal, QPalette::Highlight)); + else + { + QVariant value = index.data(Qt::BackgroundRole); + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(option.rect.topLeft()); + painter->fillRect(option.rect, qvariant_cast<QBrush>(value)); + painter->setBrushOrigin(oldBO); + } + painter->save(); + painter->translate(option.rect.topLeft()); + if (option.state & QStyle::State_Selected) + painter->setPen(option.palette.color(QPalette::Normal, QPalette::HighlightedText)); + else + painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text)); + QFont f = painter->font(); + f.setBold(true); + painter->setFont(f); + painter->drawText(10,20, theme); + + QSize s = sizeHint(option, index); + + // draw the emoticons themselves + QPoint top(10, 22); + int maxHeight = s.height() - top.y() - 2; + int middle = (maxHeight / 2) + top.y(); + QStringList emotes = qvariant_cast<QStringList>(index.data(Qt::UserRole)); + int count = 0; + foreach(QString emote, emotes) + { + QPixmap pix; + + // check if we have already loaded the requested pixmap + if (count < pixmapList.count()) + { + pix = pixmapList.at(count++).value<QPixmap>(); + } + else + { + pix.load(emote); + pixmapList.append(pix); + } + + if (pix.isNull()) + continue; + + if (top.x() + pix.width() > option.rect.width() - 10) + break; + + // check if the emoticon height is bigger than the maximum allowed + if (pix.height() > maxHeight) + pix = pix.scaledToHeight(maxHeight); + + top.setY(middle - pix.height()/2); + painter->drawPixmap(top, pix); + top.setX(top.x() + pix.width() + 2); + } + painter->restore(); + + // set the pixmapList as data of the index + QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model()); + model->setData(index, pixmapList, EmoticonThemeItem::EmoticonPixmaps); +} + +QSize EmoticonThemeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + Q_UNUSED(option); + Q_UNUSED(index); + + return QSize(100,100); +} + Mudanças de propriedades em: kopete/config/chatwindow/emoticonthemedelegate.cpp ___________________________________________________________________ Nome: svn:eol-style + native Index: kopete/config/chatwindow/CMakeLists.txt =================================================================== --- kopete/config/chatwindow/CMakeLists.txt (revisão 733223) +++ kopete/config/chatwindow/CMakeLists.txt (cópia de trabalho) @@ -9,7 +9,9 @@ ########### next target ############### set(kcm_kopete_chatwindowconfig_PART_SRCS - chatwindowconfig.cpp ) + chatwindowconfig.cpp + emoticonthemedelegate.cpp + emoticonthemeitem.cpp ) kde4_add_ui_files(kcm_kopete_chatwindowconfig_PART_SRCS chatwindowconfig_style.ui Index: kopete/config/chatwindow/chatwindowconfig.cpp =================================================================== --- kopete/config/chatwindow/chatwindowconfig.cpp (revisão 733223) +++ kopete/config/chatwindow/chatwindowconfig.cpp (cópia de trabalho) @@ -1,10 +1,11 @@ /* - appearanceconfig.cpp - Kopete Look Feel Config + chatwindowconfig.cpp - Kopete Look Feel Config Copyright (c) 2005-2006 by Michaël Larouche <[EMAIL PROTECTED]> Copyright (c) 2005-2006 by Olivier Goffart <ogoffart at kde.org> + Copyright (c) 2007 by Gustavo Pichorim Boiko <[EMAIL PROTECTED]> - Kopete (c) 2005-2006 by the Kopete developers <[email protected]> + Kopete (c) 2005-2007 by the Kopete developers <[email protected]> ************************************************************************* * * @@ -17,6 +18,8 @@ */ #include "chatwindowconfig.h" +#include "emoticonthemedelegate.h" +#include "emoticonthemeitem.h" #include <QCheckBox> #include <QDir> @@ -257,6 +260,8 @@ QWidget *emoticonsWidget = new QWidget(m_tab); m_emoticonsUi.setupUi(emoticonsWidget); m_tab->addTab(emoticonsWidget, i18n("&Emoticons")); + + m_emoticonsUi.icon_theme_list->setItemDelegate(new EmoticonThemeDelegate(this)); addConfig( Kopete::AppearanceSettings::self(), emoticonsWidget ); connect(m_emoticonsUi.icon_theme_list, SIGNAL(selectionChanged()), @@ -310,7 +315,10 @@ } Kopete::AppearanceSettings *appearanceSettings = Kopete::AppearanceSettings::self(); - appearanceSettings->setEmoticonTheme( m_emoticonsUi.icon_theme_list->currentText() ); + QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem(); + + if (item) + appearanceSettings->setEmoticonTheme( item->text() ); appearanceSettings->writeConfig(); settings->writeConfig(); @@ -606,10 +614,13 @@ void ChatWindowConfig::slotUpdateEmoticonsButton(bool _b) { - QString themeName = m_emoticonsUi.icon_theme_list->currentText(); - QFileInfo fileInf(KGlobal::dirs()->findResource("emoticons", themeName+'/')); - m_emoticonsUi.btnRemoveTheme->setEnabled( _b && fileInf.isWritable()); - m_emoticonsUi.btnGetThemes->setEnabled( false ); + QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem(); + if (!item) + return; + QString themeName = item->text(); + QFileInfo fileInf(KGlobal::dirs()->findResource("emoticons", themeName+'/')); + m_emoticonsUi.btnRemoveTheme->setEnabled( _b && fileInf.isWritable()); + m_emoticonsUi.btnGetThemes->setEnabled( false ); } void ChatWindowConfig::updateEmoticonList() @@ -628,41 +639,36 @@ for(unsigned int y = 0; y < themeQDir.count(); y++) { QStringList themes = themeQDir.entryList(QDir::Dirs, QDir::Name); + // We don't care for '.' and '..' if ( themeQDir[y] != "." && themeQDir[y] != ".." ) { // Add ourselves to the list, using our directory name FIXME: use the first emoticon of the theme. - QPixmap previewPixmap = QPixmap(KStandardDirs::locate("emoticons", themeQDir[y]+"/smile.png")); - m_emoticonsUi.icon_theme_list->insertItem(previewPixmap,themeQDir[y]); + QListWidgetItem *item = new EmoticonThemeItem(themeQDir[y]); + m_emoticonsUi.icon_theme_list->addItem(item); } } } // Where is that theme in our big-list-o-themes? - Q3ListBoxItem *item = m_emoticonsUi.icon_theme_list->findItem( Kopete::AppearanceSettings::self()->emoticonTheme() ); + QList<QListWidgetItem*> items = m_emoticonsUi.icon_theme_list->findItems( Kopete::AppearanceSettings::self()->emoticonTheme(), Qt::MatchExactly ); - if (item) // found it... make it the currently selected theme - m_emoticonsUi.icon_theme_list->setCurrentItem( item ); + if (items.count()) // found it... make it the currently selected theme + m_emoticonsUi.icon_theme_list->setCurrentItem( items.first() ); else // Er, it's not there... select the current item m_emoticonsUi.icon_theme_list->setCurrentItem( 0 ); } void ChatWindowConfig::slotSelectedEmoticonsThemeChanged() { - QString themeName = m_emoticonsUi.icon_theme_list->currentText(); + QListWidgetItem *item = m_emoticonsUi.icon_theme_list->currentItem(); + if (!item) + return; + QString themeName = item->text(); QFileInfo fileInf(KGlobal::dirs()->findResource("emoticons", themeName+'/')); m_emoticonsUi.btnRemoveTheme->setEnabled( fileInf.isWritable() ); - Kopete::Emoticons emoticons( themeName ); - QStringList smileys = emoticons.emoticonAndPicList().keys(); - QString newContentText = "<qt>"; - - for(QStringList::Iterator it = smileys.begin(); it != smileys.end(); ++it ) - newContentText += QString::fromLatin1("<img src=\"%1\"> ").arg(*it); - - newContentText += QLatin1String("</qt>"); - m_emoticonsUi.icon_theme_preview->setHtml(newContentText); emitChanged(); } @@ -687,8 +693,8 @@ void ChatWindowConfig::slotRemoveEmoticonTheme() { - Q3ListBoxItem *selected = m_emoticonsUi.icon_theme_list->selectedItem(); - if(selected==0) + QListWidgetItem *selected = m_emoticonsUi.icon_theme_list->currentItem(); + if(!selected) return; QString themeName = selected->text();
_______________________________________________ kopete-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kopete-devel
