Redesign MessageToaster

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1695 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2009-09-29 14:50:27 +00:00
parent e929b419f4
commit dfee01d4d4
4 changed files with 410 additions and 289 deletions

View File

@ -1,6 +1,6 @@
/*
* RetroShare
* Copyright (C) 2006,2007 crypton
* Copyright (C) 2006 - 2009 RetroShare Team
*
* 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
@ -19,49 +19,92 @@
#include "MessageToaster.h"
#include "ui_MessageToaster.h"
#include "tools.h"
#include "QtToaster.h"
#include <QtGui/QtGui>
MessageToaster::MessageToaster()
: QObject(NULL) {
_messageToasterWidget = new QWidget(NULL);
_ui = new Ui::MessageToaster();
_ui->setupUi(_messageToasterWidget);
connect(_ui->messageButton, SIGNAL(clicked()), SLOT(chatButtonSlot()));
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_messageToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
MessageToaster::MessageToaster( QWidget * parent, Qt::WFlags f)
: QWidget(parent, f)
{
setupUi(this);
// set window flags
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()));
// init state
displayState = dsInactive;
}
MessageToaster::~MessageToaster() {
delete _ui;
MessageToaster::~MessageToaster()
{
delete displayTimer;
}
void MessageToaster::setMessage(const QString & message) {
_ui->messagelabel2->setText(message);
void MessageToaster::displayTimerOnTimer()
{
if (!isVisible()) return;
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();
}
else if (displayState == dsWaiting)
{
displayState = dsHiding;
displayTimer->start(2);
}
}
void MessageToaster::setPixmap(const QPixmap & pixmap) {
_ui->pixmaplabel->setPixmap(pixmap);
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);
}
void MessageToaster::show() {
_toaster->show();
void MessageToaster::closeClicked()
{
displayState = dsHiding;
displayTimer->start(2);
}
void MessageToaster::close() {
_toaster->close();
void MessageToaster::openmessageClicked()
{
//
}
void MessageToaster::chatButtonSlot() {
chatButtonClicked();
close();
void MessageToaster::setMessage(const QString & message)
{
messagelabel->setText(message);
}
void MessageToaster::setName(const QString & name)
{
namelabel->setText(name);
}

View File

@ -1,72 +1,60 @@
/*
* RetroShare
* Copyright (C) 2006 crypton
*
* 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
*/
/*
*
* This file is part of xVideoServiceThief,
* an open-source cross-platform Video service download
*
* Copyright (C) 2007 - 2008 Xesc & Technology
*
* 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 3 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 xVideoServiceThief. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: Xesc <xeskuu.xvst@gmail.com>
* Program URL : http://xviservicethief.sourceforge.net/
*
*/
#ifndef MESSAGETOASTER_H
#define MESSAGETOASTER_H
#include "IQtToaster.h"
#include <QtCore/QObject>
class QtToaster;
class QWidget;
class QString;
class QPixmap;
namespace Ui { class MessageToaster; }
/**
* Shows a toaster when a Message is incoming.
*
*
*/
class MessageToaster : public QObject, public IQtToaster {
Q_OBJECT
public:
MessageToaster();
~MessageToaster();
#include <QtGui>
void setMessage(const QString & message);
#include "ui_MessageToaster.h"
void setPixmap(const QPixmap & pixmap);
void show();
enum DisplayState {dsInactive, dsShowing, dsWaiting, dsHiding};
Q_SIGNALS:
class MessageToaster : public QWidget, public Ui::MessageToaster
{
Q_OBJECT
public:
MessageToaster( QWidget * parent = 0, Qt::WFlags f = 0 );
~MessageToaster();
void displayPopup();
void setMessage(const QString & message);
void setName(const QString & name);
void chatButtonClicked();
private Q_SLOTS:
void chatButtonSlot();
void close();
private:
Ui::MessageToaster * _ui;
QWidget * _messageToasterWidget;
QtToaster * _toaster;
private slots:
void displayTimerOnTimer();
void closeClicked();
void openmessageClicked();
private:
QTimer *displayTimer;
QString videoFile;
DisplayState displayState;
double alpha;
};
#endif //MESSAGETOASTER_H
#endif

View File

@ -1,214 +1,303 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MessageToaster</class>
<widget class="QWidget" name="MessageToaster" >
<property name="geometry" >
<widget class="QWidget" name="MessageToaster">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>221</height>
<width>304</width>
<height>115</height>
</rect>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0" >
<widget class="QFrame" name="windowFrame" >
<property name="frameShape" >
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="styleSheet">
<string notr="true">QFrame#frame{
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #FEFEFE, stop:1 #E8E8E8);
border: 2px solid #CCCCCC;}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<item row="2" column="0" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>111</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="messagelabel2" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>111</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>366</width>
<height>91</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<item row="0" column="2" >
<widget class="QPushButton" name="closeButton" >
<property name="minimumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="icon" >
<iconset resource="../images.qrc" >
<normaloff>:/images/close-down.png</normaloff>:/images/close-down.png</iconset>
</property>
<property name="iconSize" >
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="flat" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>225</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="pixmaplabel" >
<property name="text" >
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" >
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="QPushButton" name="messageButton" >
<property name="minimumSize" >
<size>
<width>88</width>
<height>0</height>
</size>
</property>
<property name="styleSheet" >
<string notr="true" >font: bold;
</string>
</property>
<property name="text" >
<string>New Message</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>119</width>
<height>56</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string/>
</property>
<property name="pixmap" >
<pixmap resource="../images.qrc" >:/images/folder_inbox64.png</pixmap>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
<property name="margin" >
<number>6</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder></zorder>
</widget>
</item>
</layout>
<widget class="QLabel" name="imgVideoService">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>61</width>
<height>61</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/folder_inbox64.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="messagelabel">
<property name="geometry">
<rect>
<x>80</x>
<y>30</y>
<width>171</width>
<height>61</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>117</red>
<green>116</green>
<blue>118</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="styleSheet">
<string notr="true">QLabel#messagelabel{
border: 2px solid #CCCCCC;
border-radius: 10px }</string>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QToolButton" name="openmessagebtn">
<property name="geometry">
<rect>
<x>260</x>
<y>43</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Play video</string>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="accessibleName">
<string>Play button</string>
</property>
<property name="accessibleDescription">
<string>Play the downloaded video</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/evolution.png</normaloff>:/images/evolution.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="lblTitle">
<property name="geometry">
<rect>
<x>28</x>
<y>1</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>&lt;b&gt;1 new Message from&lt;/b&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>4</x>
<y>3</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/rstray3.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QToolButton" name="closebtn">
<property name="geometry">
<rect>
<x>279</x>
<y>1</y>
<width>20</width>
<height>20</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Close</string>
</property>
<property name="accessibleName">
<string>Close button</string>
</property>
<property name="accessibleDescription">
<string>Close the information dialog</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/delete.png</normaloff>:/images/delete.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="namelabel">
<property name="geometry">
<rect>
<x>150</x>
<y>0</y>
<width>111</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<zorder>frame</zorder>
<zorder>imgVideoService</zorder>
<zorder>messagelabel</zorder>
<zorder>openmessagebtn</zorder>
<zorder>lblTitle</zorder>
<zorder>label</zorder>
<zorder>closebtn</zorder>
<zorder>namelabel</zorder>
</widget>
<tabstops>
<tabstop>messageButton</tabstop>
<tabstop>closeButton</tabstop>
<tabstop>openmessagebtn</tabstop>
<tabstop>closebtn</tabstop>
</tabstops>
<resources>
<include location="../images.qrc" />
<include location="../images.qrc"/>
<include location="../resources/resources.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -218,15 +218,16 @@ void NotifyQt::UpdateGUI()
/* id the name */
std::string name = rsPeers->getPeerName(id);
std::string realmsg = msg + "<strong>" + name + "</strong>";
std::string realmsg = "<strong>" + name + "</strong>";
switch(type)
{
case RS_POPUP_MSG:
if (popupflags & RS_POPUP_MSG)
{
MessageToaster * msgToaster = new MessageToaster();
msgToaster->setMessage(QString::fromStdString(realmsg));
msgToaster->show();
//msgToaster->setMessage(QString::fromStdString(title));
msgToaster->setName(QString::fromStdString(realmsg));
msgToaster->displayPopup();
}
break;
case RS_POPUP_CHAT: