added for Groupchat emoteicons

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@458 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-04-01 07:00:39 +00:00
parent d51af63d51
commit 65d2196e75
3 changed files with 118 additions and 37 deletions

View File

@ -53,12 +53,14 @@ ChatDialog::ChatDialog(QWidget *parent)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
loadEmoticonsgroupchat();
setWindowIcon(QIcon(QString(":/images/rstray3.png")));
//connect(ui.lineEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendMsg( ) ));
connect(ui.lineEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) ));
connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg()));
connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat()));
connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) );
connect( ui.msgText, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoChatMenu(const QPoint&)));
@ -143,9 +145,9 @@ void ChatDialog::insertChat()
QString currenttxt = msgWidget->toHtml();
QString extraTxt;
QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
QString name = QString::fromStdString(it->name);
QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
extraTxt += line;
@ -155,6 +157,14 @@ void ChatDialog::insertChat()
/* add it everytime */
currenttxt += extraTxt;
QHashIterator<QString, QString> i(smileys);
while(i.hasNext())
{
i.next();
currenttxt.replace(i.key(), "<img src=\"" + i.value() + "\">");
}
msgWidget->setHtml(currenttxt);
@ -362,16 +372,11 @@ void ChatDialog::setFont()
ui.lineEdit->setFont(font);
}
void ChatDialog::returnPressed()
{
this->sendMsg();
}
// Update Chat Info information
void ChatDialog::setChatInfo(QString info, QColor color) {
void ChatDialog::setChatInfo(QString info, QColor color)
{
static unsigned int nbLines = 0;
++nbLines;
// Check log size, clear it if too big
@ -382,11 +387,13 @@ void ChatDialog::setChatInfo(QString info, QColor color) {
ui.msgText->append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + info + QString::fromUtf8("</i></font>"));
}
void ChatDialog::on_actionClearChat_triggered() {
void ChatDialog::on_actionClearChat_triggered()
{
ui.msgText->clear();
}
void ChatDialog::displayInfoChatMenu(const QPoint& pos) {
void ChatDialog::displayInfoChatMenu(const QPoint& pos)
{
// Log Menu
QMenu myChatMenu(this);
myChatMenu.addAction(ui.actionClearChat);
@ -394,14 +401,58 @@ void ChatDialog::displayInfoChatMenu(const QPoint& pos) {
myChatMenu.exec(mapToGlobal(pos)+QPoint(0,80));
}
bool ChatDialog::keyPressed(QEvent * event)
{
QKeyEvent * e = static_cast<QKeyEvent *>(event);
if ((e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Return)) {
event->accept();
sendMsg();
return true;
}
return false;
}
void ChatDialog::loadEmoticonsgroupchat()
{
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 ChatDialog::smileyWidgetgroupchat()
{
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(addSmileys()));
}
smWidget->show();
}
void ChatDialog::addSmileys()
{
ui.lineEdit->setText(ui.lineEdit->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip());
}

View File

@ -40,14 +40,20 @@ public:
ChatDialog(QWidget *parent = 0);
/** Default Destructor */
void insertChat();
PopupChatDialog *getPrivateChat(std::string id, std::string name, bool show);
void clearOldChats();
void insertChat();
PopupChatDialog *getPrivateChat(std::string id, std::string name, bool show);
void clearOldChats();
void loadEmoticonsgroupchat();
public slots:
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
void smileyWidgetgroupchat();
void addSmileys();
private slots:
@ -70,10 +76,6 @@ void toggleSendItem( QTreeWidgetItem *item, int col );
void on_actionClearChat_triggered();
void displayInfoChatMenu(const QPoint& pos);
void returnPressed();
bool keyPressed(QEvent * event);
private:
@ -91,7 +93,7 @@ private:
QColor textColor;
QColor _currentColor;
QHash<QString, QString> smileys;
std::map<std::string, PopupChatDialog *> chatDialogs;

View File

@ -832,7 +832,7 @@
</property>
</spacer>
</item>
<item row="0" column="3" >
<item row="0" column="4" >
<widget class="QPushButton" name="textitalicChatButton" >
<property name="minimumSize" >
<size>
@ -860,7 +860,7 @@
</property>
</widget>
</item>
<item row="0" column="2" >
<item row="0" column="3" >
<widget class="QPushButton" name="textunderlineChatButton" >
<property name="minimumSize" >
<size>
@ -888,7 +888,7 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<item row="0" column="2" >
<widget class="QPushButton" name="textboldChatButton" >
<property name="minimumSize" >
<size>
@ -916,7 +916,7 @@
</property>
</widget>
</item>
<item row="0" column="5" >
<item row="0" column="6" >
<widget class="QPushButton" name="colorChatButton" >
<property name="minimumSize" >
<size>
@ -938,7 +938,7 @@
</property>
</widget>
</item>
<item row="0" column="4" >
<item row="0" column="5" >
<widget class="QPushButton" name="fontsButton" >
<property name="minimumSize" >
<size>
@ -960,6 +960,34 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="emoticonBtn" >
<property name="minimumSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="images.qrc" >:/images/emoticons/kopete/kopete020.png</iconset>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" >