From faace1f322664c8a15bf3b141eac47fb44e7760b Mon Sep 17 00:00:00 2001 From: leander-256 Date: Wed, 12 May 2010 19:03:30 +0000 Subject: [PATCH] Memory leak fix Instantiate the smiley pop-up window (and all its buttons) only once. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2890 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 112 +++++++++++++------------ retroshare-gui/src/gui/PeersDialog.h | 1 + 2 files changed, 59 insertions(+), 54 deletions(-) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 73682d0e6..4b193d0bc 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -96,7 +96,8 @@ /** Constructor */ PeersDialog::PeersDialog(QWidget *parent) : RsAutoUpdatePage(1500,parent), - historyKeeper(Rshare::dataDirectory() + "/his1.xml") + historyKeeper(Rshare::dataDirectory() + "/his1.xml"), + smWidget(0) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -238,6 +239,7 @@ PeersDialog::~PeersDialog () delete (it->second); } } + delete smWidget; } void PeersDialog::pasteLink() @@ -1403,65 +1405,67 @@ void PeersDialog::loadEmoticonsgroupchat() void PeersDialog::smileyWidgetgroupchat() { qDebug("MainWindow::smileyWidget()"); - QWidget *smWidget = new QWidget(this , Qt::Popup ); - smWidget->setWindowTitle("Emoticons"); - smWidget->setWindowIcon(QIcon(QString(":/images/rstray3.png"))); - //smWidget->setFixedSize(256,256); + if(smWidget == 0) { + 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 ); + 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); + //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); - x = 0; - y = 0; + 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) + QHashIterator i(smileys); + while(i.hasNext()) { - x = 0; - y++; + 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())); } - connect(smButton, SIGNAL(clicked()), this, SLOT(addSmileys())); - connect(smButton, SIGNAL(clicked()), smWidget, SLOT(close())); } smWidget->show(); diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index aca4dbc7c..65e19da1c 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -194,6 +194,7 @@ private: time_t last_status_send_time ; QHash smileys; + QWidget *smWidget; std::map chatDialogs;