2007-11-14 22:18:48 -05:00
|
|
|
/*
|
|
|
|
* RetroShare
|
2009-09-29 10:50:27 -04:00
|
|
|
* Copyright (C) 2006 - 2009 RetroShare Team
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2008-11-16 22:03:23 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "MessageToaster.h"
|
2010-05-23 17:32:58 -04:00
|
|
|
#include "../MainWindow.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
MessageToaster::MessageToaster( QWidget * parent, Qt::WFlags f)
|
|
|
|
: QWidget(parent, f)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2010-05-05 18:03:43 -04:00
|
|
|
|
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
|
|
|
// set window flags
|
2009-09-29 10:50:27 -04:00
|
|
|
QWidget::setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
|
|
|
|
// init the timer
|
|
|
|
displayTimer = new QTimer(this);
|
|
|
|
connect(displayTimer, SIGNAL(timeout()), this, SLOT(displayTimerOnTimer()));
|
|
|
|
// connect buttons
|
|
|
|
connect(closebtn, SIGNAL(clicked()), this, SLOT(closeClicked()));
|
|
|
|
connect(openmessagebtn, SIGNAL(clicked()), this, SLOT(openmessageClicked()));
|
2010-01-25 15:16:54 -05:00
|
|
|
connect(openmessagetoolButton, SIGNAL(clicked()), this, SLOT(openmessageClicked()));
|
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
// init state
|
|
|
|
displayState = dsInactive;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
MessageToaster::~MessageToaster()
|
|
|
|
{
|
|
|
|
delete displayTimer;
|
2008-11-16 22:03:23 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::displayTimerOnTimer()
|
|
|
|
{
|
2010-05-05 18:03:43 -04:00
|
|
|
if (!isVisible()) {
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
2009-09-29 10:50:27 -04:00
|
|
|
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
QRect availableGeometry = desktop->availableGeometry(this);
|
|
|
|
|
|
|
|
// display popup animation
|
|
|
|
if (displayState == dsShowing)
|
|
|
|
if (pos().x() > availableGeometry.width() - size().width())// - 15)
|
|
|
|
move(pos().x() - 2, pos().y());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
displayState = dsWaiting;
|
|
|
|
displayTimer->start(5000);
|
|
|
|
}
|
|
|
|
// hide popup animation
|
|
|
|
else if (displayState == dsHiding)
|
|
|
|
if (pos().x() < availableGeometry.width())
|
|
|
|
move(pos().x() + 2, pos().y());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
displayState = dsWaiting;
|
|
|
|
displayTimer->stop();
|
|
|
|
hide();
|
2010-05-05 18:03:43 -04:00
|
|
|
close();
|
2009-09-29 10:50:27 -04:00
|
|
|
}
|
|
|
|
else if (displayState == dsWaiting)
|
|
|
|
{
|
|
|
|
displayState = dsHiding;
|
|
|
|
displayTimer->start(2);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-11-16 22:03:23 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::displayPopup()
|
|
|
|
{
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
QRect availableGeometry = desktop->availableGeometry(this);
|
|
|
|
move(desktop->width(), availableGeometry.height() - size().height());
|
|
|
|
this->show();
|
|
|
|
|
|
|
|
alpha = 0;
|
|
|
|
|
|
|
|
displayState = dsShowing;
|
|
|
|
displayTimer->start(2);
|
2008-11-16 22:03:23 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::closeClicked()
|
|
|
|
{
|
|
|
|
displayState = dsHiding;
|
|
|
|
displayTimer->start(2);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::openmessageClicked()
|
|
|
|
{
|
2010-05-23 17:32:58 -04:00
|
|
|
MainWindow::showWindow (MainWindow::Messages);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-11-16 22:03:23 -05:00
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::setMessage(const QString & message)
|
|
|
|
{
|
|
|
|
messagelabel->setText(message);
|
2008-11-16 22:03:23 -05:00
|
|
|
}
|
|
|
|
|
2009-09-29 10:50:27 -04:00
|
|
|
void MessageToaster::setName(const QString & name)
|
|
|
|
{
|
|
|
|
namelabel->setText(name);
|
2008-11-16 22:03:23 -05:00
|
|
|
}
|