From 32c12542dc08be0707330399f8ce1253d10e33c5 Mon Sep 17 00:00:00 2001 From: beardog_uk Date: Thu, 12 Mar 2009 17:57:30 +0000 Subject: [PATCH] feature: since now smilie widget will appear near smile button (as it usually is in all messengers). Both in group and private chats git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1073 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 47 +++++++++++++++++-- .../src/gui/chat/PopupChatDialog.cpp | 46 ++++++++++++++++-- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 9cba652fa..abf4d0f19 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -866,7 +866,10 @@ void PeersDialog::toggleSendItem( QTreeWidgetItem *item, int col ) return; } -PopupChatDialog *PeersDialog::getPrivateChat(std::string id, std::string name, uint chatflags) +//============================================================================ + +PopupChatDialog * +PeersDialog::getPrivateChat(std::string id, std::string name, uint chatflags) { /* see if it exists already */ PopupChatDialog *popupchatdialog = NULL; @@ -935,6 +938,7 @@ PopupChatDialog *PeersDialog::getPrivateChat(std::string id, std::string name, u return popupchatdialog; } +//============================================================================ void PeersDialog::clearOldChats() { @@ -1074,14 +1078,46 @@ void PeersDialog::loadEmoticonsgroupchat() void PeersDialog::smileyWidgetgroupchat() { qDebug("MainWindow::smileyWidget()"); - QWidget *smWidget = new QWidget; + QWidget *smWidget = new QWidget(this , Qt::Popup ); smWidget->setWindowTitle("Emoticons"); smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png"))); - smWidget->setFixedSize(256,256); + //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.emoticonBtn; + 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); - - int x = 0, y = 0; + x = 0; + y = 0; QHashIterator i(smileys); while(i.hasNext()) @@ -1100,6 +1136,7 @@ void PeersDialog::smileyWidgetgroupchat() y++; } connect(smButton, SIGNAL(clicked()), this, SLOT(addSmileys())); + connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close())); } smWidget->show(); diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index ea09c0dbb..47f90a49c 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -456,18 +456,51 @@ void PopupChatDialog::loadEmoticons() } } +//============================================================================ void PopupChatDialog::smileyWidget() { qDebug("MainWindow::smileyWidget()"); - QWidget *smWidget = new QWidget; + QWidget *smWidget = new QWidget(this , Qt::Popup); + smWidget->setAttribute( Qt::WA_DeleteOnClose); 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.emoteiconButton; + 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); - - int x = 0, y = 0; + x = 0; + y = 0; QHashIterator i(smileys); while(i.hasNext()) @@ -485,16 +518,21 @@ void PopupChatDialog::smileyWidget() y++; } connect(smButton, SIGNAL(clicked()), this, SLOT(addSmiley())); + connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close())); } smWidget->show(); } +//============================================================================ + void PopupChatDialog::addSmiley() { ui.chattextEdit->setText(ui.chattextEdit->toHtml() + qobject_cast(sender())->toolTip().split("|").first()); } +//============================================================================ + QString PopupChatDialog::loadEmptyStyle() { #ifdef CHAT_DEBUG