Added first Emoteicons feature

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@436 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-03-29 18:21:17 +00:00
parent 967b91eea1
commit b55eb395a3
4 changed files with 169 additions and 56 deletions

View File

@ -28,6 +28,11 @@
#include <QToolBar>
#include <QTextCursor>
#include <QTextList>
#include <QString>
#include <QtDebug>
#include <QIcon>
#include <QPixmap>
#include <QHashIterator>
#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<QString, QString> i(smileys);
while(i.hasNext())
{
i.next();
currenttxt.replace(i.key(), "<img src=\"" + i.value() + "\">");
}
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<QString, QString> 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<QPushButton*>(sender())->toolTip());
}

View File

@ -23,12 +23,14 @@
#ifndef _POPUPCHATDIALOG_H
#define _POPUPCHATDIALOG_H
#include <QtGui>
#include <QDialog>
#include "ui_PopupChatDialog.h"
#include "rsiface/rsiface.h"
#include <QDialog>
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<QString, QString> smileys;
/** Qt Designer generated object */
Ui::PopupChatDialog ui;

View File

@ -83,18 +83,18 @@
</property>
</spacer>
</item>
<item row="0" column="1" >
<item row="0" column="2" >
<widget class="QPushButton" name="textboldButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -111,18 +111,18 @@
</property>
</widget>
</item>
<item row="0" column="2" >
<item row="0" column="3" >
<widget class="QPushButton" name="textunderlineButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -139,46 +139,18 @@
</property>
</widget>
</item>
<item row="0" column="3" >
<item row="0" column="4" >
<widget class="QPushButton" name="textitalicButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Italic</string>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="4" >
<widget class="QPushButton" name="fontButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -196,17 +168,45 @@
</widget>
</item>
<item row="0" column="5" >
<widget class="QPushButton" name="colorButton" >
<widget class="QPushButton" name="fontButton" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
<string>Italic</string>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="6" >
<widget class="QPushButton" name="colorButton" >
<property name="minimumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
@ -217,6 +217,37 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="emoteiconButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -85,6 +85,7 @@
<file>images/filefind.png</file>
<file>images/fileinfo.png</file>
<file>images/find.png</file>
<file>images/emoticons/kopete/kopete020.png</file>
<file>images/flags/af.png</file>
<file>images/flags/cn.png</file>
<file>images/flags/cn_simp.png</file>