Fixed calculation of the minimum available space for the hash status string. The window was resized again on hashing with the animation.

Fixed memory leak in hash status.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3885 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-11-30 20:33:09 +00:00
parent 75b0d2e797
commit dc764eaf0e
2 changed files with 19 additions and 11 deletions

View File

@ -30,9 +30,10 @@
class StatusLabel : public QLabel class StatusLabel : public QLabel
{ {
public: public:
StatusLabel(QLayout *layout, QWidget *parent = NULL, Qt::WindowFlags f = 0) : QLabel(parent, f) StatusLabel(QLayout *layout, int diffWidth, QWidget *parent = NULL, Qt::WindowFlags f = 0) : QLabel(parent, f)
{ {
m_layout = layout; m_layout = layout;
m_diffWidth = diffWidth;
} }
virtual QSize minimumSizeHint() const virtual QSize minimumSizeHint() const
@ -40,11 +41,12 @@ public:
const QSize sizeHint = QLabel::minimumSizeHint(); const QSize sizeHint = QLabel::minimumSizeHint();
// do not resize the layout // do not resize the layout
return QSize(qMin(sizeHint.width(), m_layout->geometry().width()), sizeHint.height()); return QSize(qMin(sizeHint.width(), m_layout->geometry().width() - m_diffWidth), sizeHint.height());
} }
private: private:
QLayout *m_layout; QLayout *m_layout;
int m_diffWidth;
}; };
HashingStatus::HashingStatus(QWidget *parent) HashingStatus::HashingStatus(QWidget *parent)
@ -54,10 +56,14 @@ HashingStatus::HashingStatus(QWidget *parent)
hbox->setMargin(0); hbox->setMargin(0);
hbox->setSpacing(6); hbox->setSpacing(6);
movie = new QMovie(":/images/loader/16-loader.gif");
movie->setSpeed(80); // 2x speed
hashloader = new QLabel(this); hashloader = new QLabel(this);
hashloader->setMovie(movie);
hbox->addWidget(hashloader); hbox->addWidget(hashloader);
statusHashing = new StatusLabel(hbox, this); movie->jumpToNextFrame(); // to calculate the real width
statusHashing = new StatusLabel(hbox, movie->frameRect().width() + hbox->spacing(), this);
hbox->addWidget(statusHashing); hbox->addWidget(statusHashing);
QSpacerItem *horizontalSpacer = new QSpacerItem(1000, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem *horizontalSpacer = new QSpacerItem(1000, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
@ -69,23 +75,25 @@ HashingStatus::HashingStatus(QWidget *parent)
statusHashing->hide(); statusHashing->hide();
connect(NotifyQt::getInstance(), SIGNAL(hashingInfoChanged(const QString&)), SLOT(updateHashingInfo(const QString&))); connect(NotifyQt::getInstance(), SIGNAL(hashingInfoChanged(const QString&)), SLOT(updateHashingInfo(const QString&)));
}
HashingStatus::~HashingStatus()
{
delete(movie);
} }
void HashingStatus::updateHashingInfo(const QString& s) void HashingStatus::updateHashingInfo(const QString& s)
{ {
QMovie *movie = new QMovie(":/images/loader/16-loader.gif");
if(s.isEmpty()) { if(s.isEmpty()) {
statusHashing->hide(); statusHashing->hide();
hashloader->hide(); hashloader->hide();
movie->stop();
} else { } else {
statusHashing->setText(s); statusHashing->setText(s);
statusHashing->show(); statusHashing->show();
hashloader->show(); hashloader->show();
hashloader->setMovie(movie);
movie->start(); movie->start();
movie->setSpeed(80); // 2x speed
} }
} }

View File

@ -31,6 +31,7 @@ class HashingStatus : public QWidget
public: public:
HashingStatus(QWidget *parent = 0); HashingStatus(QWidget *parent = 0);
~HashingStatus();
public slots: public slots:
void updateHashingInfo(const QString&) ; void updateHashingInfo(const QString&) ;
@ -38,7 +39,6 @@ public slots:
private: private:
QLabel *statusHashing, *hashloader; QLabel *statusHashing, *hashloader;
QMovie *movie; QMovie *movie;
}; };
#endif #endif