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.
****************************************************************/
#include "CreateForumMsg.h"
#include <gui/settings/rsharesettings.h>
#include <QtGui>
#include <QTextStream>
#include "rsiface/rsforums.h"
/** Constructor */
@ -39,9 +41,12 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
// connect up the buttons.
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
connect( ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
newMsg();
loadEmoticonsForums();
}
@ -60,9 +65,20 @@ void CreateForumMsg::newMsg()
{
name += " In Reply to: ";
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);
}
}
ui.forumName->setText(name);
ui.forumSubject->setText(subj);
@ -131,3 +147,136 @@ void CreateForumMsg::cancelMsg()
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

@ -37,17 +37,24 @@ public:
void newMsg(); /* cleanup */
void loadEmoticonsForums();
private slots:
/* actions to take.... */
void createMsg();
void cancelMsg();
void smileyWidgetForums();
void addSmileys();
private:
std::string mForumId;
std::string mParentId;
QHash<QString, QString> smileys;
/** Qt Designer generated object */
Ui::CreateForumMsg ui;
};

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateForumMsg</class>
<widget class="QMainWindow" name="CreateForumMsg">
@ -87,6 +88,23 @@
</property>
</widget>
</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>
</item>
<item>