mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-19 04:44:21 -05:00
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:
parent
6dbc7fd9bc
commit
086c13cce7
@ -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());
|
||||
}
|
@ -35,19 +35,26 @@ class CreateForumMsg : public QMainWindow
|
||||
public:
|
||||
CreateForumMsg(std::string fId, std::string pId);
|
||||
|
||||
void newMsg(); /* cleanup */
|
||||
void newMsg(); /* cleanup */
|
||||
|
||||
void loadEmoticonsForums();
|
||||
|
||||
private slots:
|
||||
|
||||
/* actions to take.... */
|
||||
void createMsg();
|
||||
void cancelMsg();
|
||||
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;
|
||||
};
|
||||
|
@ -1,7 +1,8 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateForumMsg</class>
|
||||
<widget class="QMainWindow" name="CreateForumMsg" >
|
||||
<property name="geometry" >
|
||||
<widget class="QMainWindow" name="CreateForumMsg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@ -9,32 +10,32 @@
|
||||
<height>353</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Post Forum Message</string>
|
||||
</property>
|
||||
<property name="windowIcon" >
|
||||
<iconset resource="../images.qrc" >
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||
</property>
|
||||
<property name="toolButtonStyle" >
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget" >
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Forum</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="forumName" >
|
||||
<property name="enabled" >
|
||||
<widget class="QLineEdit" name="forumName">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
@ -42,34 +43,34 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Forum Post Subject</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="forumSubject" />
|
||||
<widget class="QLineEdit" name="forumSubject"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5" >
|
||||
<property name="text" >
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Forum Post</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
@ -78,58 +79,75 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="signBox" >
|
||||
<property name="text" >
|
||||
<widget class="QCheckBox" name="signBox">
|
||||
<property name="text">
|
||||
<string>Sign Message</string>
|
||||
</property>
|
||||
<property name="checked" >
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</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>
|
||||
<widget class="QTextEdit" name="forumMessage" />
|
||||
<widget class="QTextEdit" name="forumMessage"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar" >
|
||||
<property name="windowTitle" >
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea" >
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak" >
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="postmessage_action" />
|
||||
<addaction name="close_action" />
|
||||
<addaction name="postmessage_action"/>
|
||||
<addaction name="close_action"/>
|
||||
</widget>
|
||||
<action name="postmessage_action" >
|
||||
<property name="icon" >
|
||||
<iconset resource="../images.qrc" >
|
||||
<action name="postmessage_action">
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/mail_send24.png</normaloff>:/images/mail_send24.png</iconset>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>Post Forum Msg</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="close_action" >
|
||||
<property name="icon" >
|
||||
<iconset resource="../images.qrc" >
|
||||
<action name="close_action">
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_cancel.png</normaloff>:/images/button_cancel.png</iconset>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../images.qrc" />
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user