2
* messagebox.cpp - simple message-box
4
* Copyright (c) 2006-2007 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
6
* This file is part of iTALC - http://italc.sourceforge.net
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
26
#include "messagebox.h"
27
#include "local_system.h"
29
#include <QtCore/QThread>
30
#include <QtGui/QApplication>
31
#include <QtGui/QWidget>
32
#include <QtGui/QPixmap>
33
#include <QtGui/QIcon>
34
#include <QtGui/QLabel>
35
#include <QtGui/QBoxLayout>
36
#include <QtGui/QPushButton>
38
#ifdef SYSTEMTRAY_SUPPORT
39
QSystemTrayIcon * __systray_icon = NULL;
43
messageBox::messageBox( const QString & _title, const QString & _msg,
44
const QPixmap & _pixmap ) :
47
QVBoxLayout * vl = new QVBoxLayout( this );
49
QWidget * content = new QWidget( this );
51
QHBoxLayout * hl1 = new QHBoxLayout( content );
52
hl1->setSpacing( 20 );
54
QLabel * icon_lbl = new QLabel( content );
55
if( _pixmap.isNull() == FALSE )
57
icon_lbl->setPixmap( _pixmap );
61
icon_lbl->setPixmap( QPixmap( ":/resources/info.png" ) );
63
icon_lbl->setFixedSize( icon_lbl->pixmap()->size() );
65
QLabel * txt_lbl = new QLabel( _msg, content );
66
txt_lbl->setMinimumWidth( 400 );
67
txt_lbl->setWordWrap( TRUE );
69
hl1->addWidget( icon_lbl );
70
hl1->addWidget( txt_lbl );
72
QWidget * btn_area = new QWidget( this );
73
QHBoxLayout * hl2 = new QHBoxLayout( btn_area );
75
QPushButton * ok_btn = new QPushButton( QPixmap( ":/resources/ok.png" ),
76
tr( "OK" ), btn_area );
77
connect( ok_btn, SIGNAL( clicked() ), this, SLOT( accept() ) );
80
hl2->addWidget( ok_btn );
83
vl->addWidget( content );
84
vl->addWidget( btn_area );
86
setWindowTitle( _title );
87
setWindowIcon( *icon_lbl->pixmap() );
88
setAttribute( Qt::WA_DeleteOnClose, TRUE );
91
localSystem::activateWindow( this );
97
void messageBox::information( const QString & _title, const QString & _msg,
98
const QPixmap & _pixmap )
100
messageBox * m = new messageBox( _title, _msg, _pixmap );
106
void messageBox::trySysTrayMessage( const QString & _title,
107
const QString & _msg,
108
MessageIcon _msg_icon )
110
qWarning( _msg.toUtf8().constData() );
111
if( QThread::currentThreadId() !=
112
QCoreApplication::instance()->thread()->currentThreadId() )
116
#ifdef SYSTEMTRAY_SUPPORT
117
// OS X does not support messages
118
if( QSystemTrayIcon::supportsMessages() && __systray_icon )
120
__systray_icon->showMessage( _title, _msg,
121
(QSystemTrayIcon::MessageIcon) _msg_icon, -1 );
130
p = QPixmap( ":/resources/info.png" );
133
p = QPixmap( ":/resources/stop.png" );
136
new messageBox( _title, _msg, p );