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 * RetroShare
* Copyright (C) 2006,2007 crypton * Copyright (C) 2006 - 2009 RetroShare Team
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,49 +19,92 @@
#include "MessageToaster.h" #include "MessageToaster.h"
#include "ui_MessageToaster.h" #include "tools.h"
#include "QtToaster.h" MessageToaster::MessageToaster( QWidget * parent, Qt::WFlags f)
: QWidget(parent, f)
#include <QtGui/QtGui> {
setupUi(this);
MessageToaster::MessageToaster() // set window flags
: QObject(NULL) { QWidget::setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
// init the timer
_messageToasterWidget = new QWidget(NULL); displayTimer = new QTimer(this);
connect(displayTimer, SIGNAL(timeout()), this, SLOT(displayTimerOnTimer()));
_ui = new Ui::MessageToaster(); // connect buttons
_ui->setupUi(_messageToasterWidget); connect(closebtn, SIGNAL(clicked()), this, SLOT(closeClicked()));
connect(openmessagebtn, SIGNAL(clicked()), this, SLOT(openmessageClicked()));
connect(_ui->messageButton, SIGNAL(clicked()), SLOT(chatButtonSlot())); // init state
displayState = dsInactive;
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_messageToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
} }
MessageToaster::~MessageToaster() { MessageToaster::~MessageToaster()
delete _ui; {
delete displayTimer;
} }
void MessageToaster::setMessage(const QString & message) { void MessageToaster::displayTimerOnTimer()
_ui->messagelabel2->setText(message); {
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) { void MessageToaster::displayPopup()
_ui->pixmaplabel->setPixmap(pixmap); {
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() { void MessageToaster::closeClicked()
_toaster->show(); {
displayState = dsHiding;
displayTimer->start(2);
} }
void MessageToaster::close() { void MessageToaster::openmessageClicked()
_toaster->close(); {
//
} }
void MessageToaster::chatButtonSlot() { void MessageToaster::setMessage(const QString & message)
chatButtonClicked(); {
close(); messagelabel->setText(message);
}
void MessageToaster::setName(const QString & name)
{
namelabel->setText(name);
} }

View file

@ -1,10 +1,13 @@
/* /*
* RetroShare
* Copyright (C) 2006 crypton
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
@ -13,60 +16,45 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with xVideoServiceThief. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* Contact e-mail: Xesc <xeskuu.xvst@gmail.com>
* Program URL : http://xviservicethief.sourceforge.net/
*
*/ */
#ifndef MESSAGETOASTER_H #ifndef MESSAGETOASTER_H
#define MESSAGETOASTER_H #define MESSAGETOASTER_H
#include "IQtToaster.h" #include <QtGui>
#include <QtCore/QObject> #include "ui_MessageToaster.h"
class QtToaster; enum DisplayState {dsInactive, dsShowing, dsWaiting, dsHiding};
class QWidget; class MessageToaster : public QWidget, public Ui::MessageToaster
class QString; {
class QPixmap;
namespace Ui { class MessageToaster; }
/**
* Shows a toaster when a Message is incoming.
*
*
*/
class MessageToaster : public QObject, public IQtToaster {
Q_OBJECT Q_OBJECT
public: public:
MessageToaster( QWidget * parent = 0, Qt::WFlags f = 0 );
MessageToaster();
~MessageToaster(); ~MessageToaster();
void displayPopup();
void setMessage(const QString & message); void setMessage(const QString & message);
void setName(const QString & name);
void setPixmap(const QPixmap & pixmap);
void show(); private slots:
void displayTimerOnTimer();
Q_SIGNALS: void closeClicked();
void openmessageClicked();
void chatButtonClicked();
private Q_SLOTS:
void chatButtonSlot();
void close();
private: private:
QTimer *displayTimer;
Ui::MessageToaster * _ui; QString videoFile;
DisplayState displayState;
QWidget * _messageToasterWidget; double alpha;
QtToaster * _toaster;
}; };
#endif
#endif //MESSAGETOASTER_H

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>MessageToaster</class> <class>MessageToaster</class>
<widget class="QWidget" name="MessageToaster"> <widget class="QWidget" name="MessageToaster">
@ -5,11 +6,26 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>370</width> <width>304</width>
<height>221</height> <height>115</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" > <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"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
@ -17,170 +33,38 @@
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QFrame" name="windowFrame" > <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"> <property name="frameShape">
<enum>QFrame::StyledPanel</enum> <enum>QFrame::StyledPanel</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </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> </widget>
</item> </item>
</layout> </layout>
</item> <widget class="QLabel" name="imgVideoService">
<item row="1" column="0" > <property name="geometry">
<layout class="QGridLayout" > <rect>
<property name="margin" > <x>10</x>
<number>0</number> <y>30</y>
<width>61</width>
<height>61</height>
</rect>
</property> </property>
<property name="spacing" > <property name="sizePolicy">
<number>6</number> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </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"> <property name="text">
<string/> <string/>
</property> </property>
@ -190,25 +74,230 @@
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<property name="margin" > </widget>
<number>6</number> <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> </property>
</widget> </widget>
</item> <widget class="QToolButton" name="openmessagebtn">
</layout> <property name="geometry">
</item> <rect>
</layout> <x>260</x>
<zorder></zorder> <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>
</item> <widget class="QLabel" name="lblTitle">
</layout> <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> </widget>
<tabstops> <tabstops>
<tabstop>messageButton</tabstop> <tabstop>openmessagebtn</tabstop>
<tabstop>closeButton</tabstop> <tabstop>closebtn</tabstop>
</tabstops> </tabstops>
<resources> <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> </resources>
<connections/> <connections/>
</ui> </ui>

View file

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