mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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
This commit is contained in:
parent
988c6c31f5
commit
faace1f322
@ -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<63> widgetu do kt<6B>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<63> w zale<6C>no<6E>ci od tego czy po lewej stronie
|
||||
// jest wi<77>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<63> y - centrujemy w pionie
|
||||
int y = w_pos.y() + w->height()/2 - e_size.height()/2;
|
||||
// je<6A>li wychodzi poza doln<6C> kraw<61>d<EFBFBD> to r<>wnamy do niej
|
||||
if (y + e_size.height() > s_size.height())
|
||||
y = s_size.height() - e_size.height();
|
||||
// je<6A>li wychodzi poza g<>rn<72> kraw<61>d<EFBFBD> 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<63> widgetu do kt<6B>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<63> w zale<6C>no<6E>ci od tego czy po lewej stronie
|
||||
// jest wi<77>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<63> y - centrujemy w pionie
|
||||
int y = w_pos.y() + w->height()/2 - e_size.height()/2;
|
||||
// je<6A>li wychodzi poza doln<6C> kraw<61>d<EFBFBD> to r<>wnamy do niej
|
||||
if (y + e_size.height() > s_size.height())
|
||||
y = s_size.height() - e_size.height();
|
||||
// je<6A>li wychodzi poza g<>rn<72> kraw<61>d<EFBFBD> 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<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)
|
||||
QHashIterator<QString, QString> 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();
|
||||
|
@ -194,6 +194,7 @@ private:
|
||||
time_t last_status_send_time ;
|
||||
|
||||
QHash<QString, QString> smileys;
|
||||
QWidget *smWidget;
|
||||
|
||||
std::map<std::string, PopupChatDialog *> chatDialogs;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user