diff --git a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp index 72a43e68c..a107d9c89 100644 --- a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp +++ b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp @@ -19,11 +19,13 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ - #include "CreateForumMsg.h" #include +#include +#include + #include "rsiface/rsforums.h" /** Constructor */ @@ -39,8 +41,11 @@ 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,7 +65,18 @@ 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); @@ -122,7 +138,7 @@ void CreateForumMsg::createMsg() } -void CreateForumMsg::cancelMsg() +void CreateForumMsg::cancelMsg() { close(); return; @@ -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 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(sender())->toolTip().split("|").first()); +} \ No newline at end of file diff --git a/retroshare-gui/src/gui/forums/CreateForumMsg.h b/retroshare-gui/src/gui/forums/CreateForumMsg.h index 9cf377725..7bf9d968d 100644 --- a/retroshare-gui/src/gui/forums/CreateForumMsg.h +++ b/retroshare-gui/src/gui/forums/CreateForumMsg.h @@ -35,18 +35,25 @@ 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 smileys; /** Qt Designer generated object */ Ui::CreateForumMsg ui; diff --git a/retroshare-gui/src/gui/forums/CreateForumMsg.ui b/retroshare-gui/src/gui/forums/CreateForumMsg.ui index 991cc752c..7f2538dd3 100644 --- a/retroshare-gui/src/gui/forums/CreateForumMsg.ui +++ b/retroshare-gui/src/gui/forums/CreateForumMsg.ui @@ -1,7 +1,8 @@ - + + CreateForumMsg - - + + 0 0 @@ -9,32 +10,32 @@ 353 - + Post Forum Message - - + + :/images/rstray3.png:/images/rstray3.png - + Qt::ToolButtonTextUnderIcon - - - - + + + + - + - - + + Forum - - + + false @@ -42,34 +43,34 @@ - + - - + + Forum Post Subject - + - + - - + + Forum Post - + Qt::Horizontal - + 40 20 @@ -78,58 +79,75 @@ - - + + Sign Message - + true + + + + + + + + :/smileys/smile.png:/smileys/smile.png + + + + 24 + 24 + + + + - + - - + + toolBar - + TopToolBarArea - + false - - + + - - - + + + :/images/mail_send24.png:/images/mail_send24.png - + Post Forum Msg - - - + + + :/images/button_cancel.png:/images/button_cancel.png - + Close - +