~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to lib/src/messagebox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * messagebox.cpp - simple message-box
 
3
 *
 
4
 * Copyright (c) 2006-2007 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
 
5
 *
 
6
 * This file is part of iTALC - http://italc.sourceforge.net
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#include "messagebox.h"
 
27
#include "local_system.h"
 
28
 
 
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>
 
37
 
 
38
#ifdef SYSTEMTRAY_SUPPORT
 
39
QSystemTrayIcon * __systray_icon = NULL;
 
40
#endif
 
41
 
 
42
 
 
43
messageBox::messageBox( const QString & _title, const QString & _msg,
 
44
                                                const QPixmap & _pixmap ) :
 
45
        QDialog()
 
46
{
 
47
        QVBoxLayout * vl = new QVBoxLayout( this );
 
48
 
 
49
        QWidget * content = new QWidget( this );
 
50
 
 
51
        QHBoxLayout * hl1 = new QHBoxLayout( content );
 
52
        hl1->setSpacing( 20 );
 
53
 
 
54
        QLabel * icon_lbl = new QLabel( content );
 
55
        if( _pixmap.isNull() == FALSE )
 
56
        {
 
57
                icon_lbl->setPixmap( _pixmap );
 
58
        }
 
59
        else
 
60
        {
 
61
                icon_lbl->setPixmap( QPixmap( ":/resources/info.png" ) );
 
62
        }
 
63
        icon_lbl->setFixedSize( icon_lbl->pixmap()->size() );
 
64
 
 
65
        QLabel * txt_lbl = new QLabel( _msg, content );
 
66
        txt_lbl->setMinimumWidth( 400 );
 
67
        txt_lbl->setWordWrap( TRUE );
 
68
        
 
69
        hl1->addWidget( icon_lbl );
 
70
        hl1->addWidget( txt_lbl );
 
71
 
 
72
        QWidget * btn_area = new QWidget( this );
 
73
        QHBoxLayout * hl2 = new QHBoxLayout( btn_area );
 
74
 
 
75
        QPushButton * ok_btn = new QPushButton( QPixmap( ":/resources/ok.png" ),
 
76
                                                tr( "OK" ), btn_area );
 
77
        connect( ok_btn, SIGNAL( clicked() ), this, SLOT( accept() ) );
 
78
 
 
79
        hl2->addStretch();
 
80
        hl2->addWidget( ok_btn );
 
81
        hl2->addStretch();
 
82
 
 
83
        vl->addWidget( content );
 
84
        vl->addWidget( btn_area );
 
85
 
 
86
        setWindowTitle( _title );
 
87
        setWindowIcon( *icon_lbl->pixmap() );
 
88
        setAttribute( Qt::WA_DeleteOnClose, TRUE );
 
89
        setModal( TRUE );
 
90
        show();
 
91
        localSystem::activateWindow( this );
 
92
}
 
93
 
 
94
 
 
95
 
 
96
 
 
97
void messageBox::information( const QString & _title, const QString & _msg,
 
98
                                                const QPixmap & _pixmap )
 
99
{
 
100
        messageBox * m = new messageBox( _title, _msg, _pixmap );
 
101
        m->exec();
 
102
}
 
103
 
 
104
 
 
105
 
 
106
void messageBox::trySysTrayMessage( const QString & _title,
 
107
                                        const QString & _msg,
 
108
                                        MessageIcon _msg_icon )
 
109
{
 
110
        qWarning( _msg.toUtf8().constData() );
 
111
        if( QThread::currentThreadId() !=
 
112
                QCoreApplication::instance()->thread()->currentThreadId() )
 
113
        {
 
114
                return;
 
115
        }
 
116
#ifdef SYSTEMTRAY_SUPPORT
 
117
        // OS X does not support messages
 
118
        if( QSystemTrayIcon::supportsMessages() && __systray_icon )
 
119
        {
 
120
                __systray_icon->showMessage( _title, _msg,
 
121
                                (QSystemTrayIcon::MessageIcon) _msg_icon, -1 );
 
122
                return;
 
123
        }
 
124
#else
 
125
        QPixmap p;
 
126
        switch( _msg_icon )
 
127
        {
 
128
                case Information:
 
129
                case Warning:
 
130
                        p = QPixmap( ":/resources/info.png" );
 
131
                        break;
 
132
                case Critical:
 
133
                        p = QPixmap( ":/resources/stop.png" );
 
134
                        break;
 
135
        }
 
136
        new messageBox( _title, _msg, p );
 
137
#endif
 
138
}
 
139
 
 
140