From b55eb395a3d7e5ca92932da2ceba04ebb6ceaf60 Mon Sep 17 00:00:00 2001 From: defnax Date: Sat, 29 Mar 2008 18:21:17 +0000 Subject: [PATCH] Added first Emoteicons feature git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@436 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/chat/PopupChatDialog.cpp | 81 ++++++++++- retroshare-gui/src/gui/chat/PopupChatDialog.h | 16 ++- .../src/gui/chat/PopupChatDialog.ui | 127 +++++++++++------- retroshare-gui/src/gui/images.qrc | 1 + 4 files changed, 169 insertions(+), 56 deletions(-) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index ae053ba32..003aa6859 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -28,6 +28,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "rsiface/rspeers.h" #include "rsiface/rsmsgs.h" @@ -49,6 +54,8 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, /* Invoke Qt Designer generated QObject setup routine */ ui.setupUi(this); + loadEmoticons(); + /* Hide ToolBox frame */ showAvatarFrame(true); connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool))); @@ -62,6 +69,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont())); connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont())); connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor())); + connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget())); // Create the status bar std::ostringstream statusstr; @@ -81,6 +89,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png"))); ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png"))); ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png"))); + ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png"))); ui.textboldButton->setCheckable(true); ui.textunderlineButton->setCheckable(true); @@ -140,7 +149,7 @@ void PopupChatDialog::updateChat() void PopupChatDialog::addChatMsg(ChatInfo *ci) { - QTextBrowser *msgWidget = ui.textBrowser; + QTextEdit *msgWidget = ui.textBrowser; QString currenttxt = msgWidget->toHtml(); @@ -182,12 +191,17 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci) extraTxt += QString::fromStdWString(ci -> msg); - currenttxt += extraTxt; + currenttxt += extraTxt; + + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + currenttxt.replace(i.key(), ""); + } msgWidget->setHtml(currenttxt); -// std::cerr << " Added Text: " << std::endl; -// std::cerr << out.str() << std::endl; QScrollBar *qsb = msgWidget->verticalScrollBar(); qsb -> setValue(qsb->maximum()); } @@ -197,7 +211,10 @@ void PopupChatDialog::sendChat() { QTextEdit *chatWidget = ui.chattextEdit; - ChatInfo ci; + ChatInfo ci; + + + { rsiface->lockData(); /* Lock Interface */ @@ -292,4 +309,58 @@ void PopupChatDialog::setFont() ui.chattextEdit->setFont(font); } +void PopupChatDialog::loadEmoticons() +{ + QDir smdir(QApplication::applicationDirPath() + "/emoticons/kopete"); + //QDir smdir(":/gui/images/emoticons/kopete"); + QFileInfoList sminfo = smdir.entryInfoList(QStringList() << "*.gif" << "*.png", QDir::Files, QDir::Name); + foreach(QFileInfo info, sminfo) + { + QString smcode = info.fileName().replace(".gif", ""); + QString smstring; + for(int i = 0; i < 9; i+=3) + { + smstring += QString((char)smcode.mid(i,3).toInt()); + } + //qDebug(smstring.toAscii()); + smileys.insert(smstring, info.absoluteFilePath()); + } +} +void PopupChatDialog::smileyWidget() +{ + qDebug("MainWindow::smileyWidget()"); + QWidget *smWidget = new QWidget; + smWidget->setWindowTitle("Emoteicons"); + smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png"))); + smWidget->setFixedSize(256,256); + + + + int x = 0, y = 0; + + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + QPushButton *smButton = new QPushButton("", smWidget); + smButton->setGeometry(x*24, y*24, 24,24); + smButton->setIconSize(QSize(24,24)); + smButton->setIcon(QPixmap(i.value())); + smButton->setToolTip(i.key()); + ++x; + if(x > 4) + { + x = 0; + y++; + } + connect(smButton, SIGNAL(clicked()), this, SLOT(addSmiley())); + } + + smWidget->show(); +} + +void PopupChatDialog::addSmiley() +{ + ui.chattextEdit->setText(ui.chattextEdit->toHtml() + qobject_cast(sender())->toolTip()); +} diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index c668d1686..b7eb84c49 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -23,12 +23,14 @@ #ifndef _POPUPCHATDIALOG_H #define _POPUPCHATDIALOG_H +#include +#include #include "ui_PopupChatDialog.h" #include "rsiface/rsiface.h" -#include + class QAction; class QTextEdit; @@ -49,10 +51,16 @@ public: void updateChat(); void addChatMsg(ChatInfo *ci); - + + void loadEmoticons(); + + public slots: /** Overloaded QWidget.show */ - void show(); + void show(); + + void smileyWidget(); + void addSmiley(); protected: @@ -81,6 +89,8 @@ private: std::string dialogId, dialogName; unsigned int lastChatTime; std::string lastChatName; + + QHash smileys; /** Qt Designer generated object */ Ui::PopupChatDialog ui; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.ui b/retroshare-gui/src/gui/chat/PopupChatDialog.ui index bdb98492d..45e3869dc 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.ui +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.ui @@ -83,18 +83,18 @@ - + - 24 - 24 + 28 + 28 - 24 - 24 + 28 + 28 @@ -111,18 +111,18 @@ - + - 24 - 24 + 28 + 28 - 24 - 24 + 28 + 28 @@ -139,46 +139,18 @@ - + - 24 - 24 + 28 + 28 - 24 - 24 - - - - Italic - - - - - - C:/Dokumente und Einstellungen/Linux/.designer/backup - - - false - - - - - - - - 24 - 24 - - - - - 24 - 24 + 28 + 28 @@ -196,17 +168,45 @@ - + - 24 - 24 + 28 + 28 - 24 - 24 + 28 + 28 + + + + Italic + + + + + + C:/Dokumente und Einstellungen/Linux/.designer/backup + + + false + + + + + + + + 28 + 28 + + + + + 28 + 28 @@ -217,6 +217,37 @@ + + + + + 0 + 0 + + + + + 28 + 28 + + + + + 28 + 28 + + + + + + + + 24 + 24 + + + + diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index b45455854..75bae9b43 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -85,6 +85,7 @@ images/filefind.png images/fileinfo.png images/find.png + images/emoticons/kopete/kopete020.png images/flags/af.png images/flags/cn.png images/flags/cn_simp.png