added Smiley Support when creating new Forum Message

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1971 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2010-01-04 14:28:21 +00:00
parent 6dbc7fd9bc
commit 086c13cce7
3 changed files with 223 additions and 49 deletions

View File

@ -19,11 +19,13 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include "CreateForumMsg.h" #include "CreateForumMsg.h"
#include <gui/settings/rsharesettings.h> #include <gui/settings/rsharesettings.h>
#include <QtGui>
#include <QTextStream>
#include "rsiface/rsforums.h" #include "rsiface/rsforums.h"
/** Constructor */ /** Constructor */
@ -39,8 +41,11 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
// connect up the buttons. // connect up the buttons.
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) ); connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) ); connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
connect( ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
newMsg(); newMsg();
loadEmoticonsForums();
} }
@ -60,7 +65,18 @@ void CreateForumMsg::newMsg()
{ {
name += " In Reply to: "; name += " In Reply to: ";
name += QString::fromStdWString(msg.title); name += QString::fromStdWString(msg.title);
QString text = ui.forumSubject->text();
if (text.startsWith("Re:"))
{
subj = QString::fromStdWString(msg.title);
}
else
{
subj = "Re: " + QString::fromStdWString(msg.title); subj = "Re: " + QString::fromStdWString(msg.title);
}
} }
ui.forumName->setText(name); ui.forumName->setText(name);
@ -122,7 +138,7 @@ void CreateForumMsg::createMsg()
} }
void CreateForumMsg::cancelMsg() void CreateForumMsg::cancelMsg()
{ {
close(); close();
return; return;
@ -131,3 +147,136 @@ void CreateForumMsg::cancelMsg()
config.saveWidgetInformation(this); config.saveWidgetInformation(this);
} }
void CreateForumMsg::loadEmoticonsForums()
{
QString sm_codes;
#if defined(Q_OS_WIN32)
QFile sm_file(QApplication::applicationDirPath() + "/emoticons/emotes.acs");
#else
QFile sm_file(QString(":/smileys/emotes.acs"));
#endif
if(!sm_file.open(QIODevice::ReadOnly))
{
std::cerr << "Could not open resouce file :/emoticons/emotes.acs" << endl ;
return ;
}
sm_codes = sm_file.readAll();
sm_file.close();
sm_codes.remove("\n");
sm_codes.remove("\r");
int i = 0;
QString smcode;
QString smfile;
while(sm_codes[i] != '{')
{
i++;
}
while (i < sm_codes.length()-2)
{
smcode = "";
smfile = "";
while(sm_codes[i] != '\"')
{
i++;
}
i++;
while (sm_codes[i] != '\"')
{
smcode += sm_codes[i];
i++;
}
i++;
while(sm_codes[i] != '\"')
{
i++;
}
i++;
while(sm_codes[i] != '\"' && sm_codes[i+1] != ';')
{
smfile += sm_codes[i];
i++;
}
i++;
if(!smcode.isEmpty() && !smfile.isEmpty())
#if defined(Q_OS_WIN32)
smileys.insert(smcode, smfile);
#else
smileys.insert(smcode, ":/"+smfile);
#endif
}
}
void CreateForumMsg::smileyWidgetForums()
{
qDebug("MainWindow::smileyWidget()");
QWidget *smWidget = new QWidget(this , Qt::Popup );
smWidget->setWindowTitle("Emoticons");
smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png")));
//smWidget->setFixedSize(256,256);
smWidget->setBaseSize( 4*24, (smileys.size()/4)*24 );
//Warning: this part of code was taken from kadu instant messenger;
// It was EmoticonSelector::alignTo(QWidget* w) function there
// comments are Polish, I dont' know how does it work...
// oblicz pozycj? widgetu do kt?rego r?wnamy
QWidget* w = ui.emoticonButton;
QPoint w_pos = w->mapToGlobal(QPoint(0,0));
// oblicz rozmiar selektora
QSize e_size = smWidget->sizeHint();
// oblicz rozmiar pulpitu
QSize s_size = QApplication::desktop()->size();
// oblicz dystanse od widgetu do lewego brzegu i do prawego
int l_dist = w_pos.x();
int r_dist = s_size.width() - (w_pos.x() + w->width());
// oblicz pozycj? w zale?no?ci od tego czy po lewej stronie
// jest wi?cej miejsca czy po prawej
int x;
if (l_dist >= r_dist)
x = w_pos.x() - e_size.width();
else
x = w_pos.x() + w->width();
// oblicz pozycj? y - centrujemy w pionie
int y = w_pos.y() + w->height()/2 - e_size.height()/2;
// je?li wychodzi poza doln? kraw?d? to r?wnamy do niej
if (y + e_size.height() > s_size.height())
y = s_size.height() - e_size.height();
// je?li wychodzi poza g?rn? kraw?d? to r?wnamy do niej
if (y < 0)
y = 0;
// ustawiamy selektor na wyliczonej pozycji
smWidget->move(x, y);
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());
//smButton->setFixedSize(24,24);
++x;
if(x > 4)
{
x = 0;
y++;
}
connect(smButton, SIGNAL(clicked()), this, SLOT(addSmileys()));
connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close()));
}
smWidget->show();
}
void CreateForumMsg::addSmileys()
{
ui.forumMessage->setText(ui.forumMessage->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip().split("|").first());
}

View File

@ -35,18 +35,25 @@ class CreateForumMsg : public QMainWindow
public: public:
CreateForumMsg(std::string fId, std::string pId); CreateForumMsg(std::string fId, std::string pId);
void newMsg(); /* cleanup */ void newMsg(); /* cleanup */
void loadEmoticonsForums();
private slots: private slots:
/* actions to take.... */ /* actions to take.... */
void createMsg(); void createMsg();
void cancelMsg(); void cancelMsg();
void smileyWidgetForums();
void addSmileys();
private: private:
std::string mForumId; std::string mForumId;
std::string mParentId; std::string mParentId;
QHash<QString, QString> smileys;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::CreateForumMsg ui; Ui::CreateForumMsg ui;

View File

@ -1,7 +1,8 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateForumMsg</class> <class>CreateForumMsg</class>
<widget class="QMainWindow" name="CreateForumMsg" > <widget class="QMainWindow" name="CreateForumMsg">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,32 +10,32 @@
<height>353</height> <height>353</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Post Forum Message</string> <string>Post Forum Message</string>
</property> </property>
<property name="windowIcon" > <property name="windowIcon">
<iconset resource="../images.qrc" > <iconset resource="../images.qrc">
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset> <normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property> </property>
<property name="toolButtonStyle" > <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum> <enum>Qt::ToolButtonTextUnderIcon</enum>
</property> </property>
<widget class="QWidget" name="centralwidget" > <widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" > <layout class="QGridLayout">
<item row="0" column="0" > <item row="0" column="0">
<layout class="QVBoxLayout" > <layout class="QVBoxLayout">
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="label_2" > <widget class="QLabel" name="label_2">
<property name="text" > <property name="text">
<string>Forum</string> <string>Forum</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="forumName" > <widget class="QLineEdit" name="forumName">
<property name="enabled" > <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
@ -42,34 +43,34 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="label" > <widget class="QLabel" name="label">
<property name="text" > <property name="text">
<string>Forum Post Subject</string> <string>Forum Post Subject</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="forumSubject" /> <widget class="QLineEdit" name="forumSubject"/>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="label_5" > <widget class="QLabel" name="label_5">
<property name="text" > <property name="text">
<string>Forum Post</string> <string>Forum Post</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -78,58 +79,75 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="signBox" > <widget class="QCheckBox" name="signBox">
<property name="text" > <property name="text">
<string>Sign Message</string> <string>Sign Message</string>
</property> </property>
<property name="checked" > <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="emoticonButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/smileys/smile.png</normaloff>:/smileys/smile.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QTextEdit" name="forumMessage" /> <widget class="QTextEdit" name="forumMessage"/>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QToolBar" name="toolBar" > <widget class="QToolBar" name="toolBar">
<property name="windowTitle" > <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
<attribute name="toolBarArea" > <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
<attribute name="toolBarBreak" > <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="postmessage_action" /> <addaction name="postmessage_action"/>
<addaction name="close_action" /> <addaction name="close_action"/>
</widget> </widget>
<action name="postmessage_action" > <action name="postmessage_action">
<property name="icon" > <property name="icon">
<iconset resource="../images.qrc" > <iconset resource="../images.qrc">
<normaloff>:/images/mail_send24.png</normaloff>:/images/mail_send24.png</iconset> <normaloff>:/images/mail_send24.png</normaloff>:/images/mail_send24.png</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>Post Forum Msg</string> <string>Post Forum Msg</string>
</property> </property>
</action> </action>
<action name="close_action" > <action name="close_action">
<property name="icon" > <property name="icon">
<iconset resource="../images.qrc" > <iconset resource="../images.qrc">
<normaloff>:/images/button_cancel.png</normaloff>:/images/button_cancel.png</iconset> <normaloff>:/images/button_cancel.png</normaloff>:/images/button_cancel.png</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>Close</string> <string>Close</string>
</property> </property>
</action> </action>
</widget> </widget>
<resources> <resources>
<include location="../images.qrc" /> <include location="../images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>