1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
* messagebox.cc
*
* Fri Feb 25 20:23:19 CET 2005
* Copyright 2005 Bent Bisballe
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of MIaV.
*
* MIaV 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.
*
* MIaV 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 MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <config.h>
#ifdef USE_GUI
#include "messagebox.h"
#include "miav_config.h"
// For button sizes!
#include "mainwindow.h"
////////////////////////////////////////////////////////////////////////////////////////
/* If the cpr input by the user is not valid, this dialog
* ask the user what to do. Edit the number, use it as it is,
* or clear the number.
*/
MessageBox::MessageBox(QWidget* parent,
const char* name,
const char* text,
msg_type type,
msg_icon icon)
: QDialog(parent)
{
int resolution_w = config->readInt("pixel_width");
//int resolution_h = config->readInt("pixel_height");
unit = ((float)resolution_w / config->readFloat("screensize")) / INCH_IN_CM;
setWindowTitle(name);
QFrame *topf = new QFrame(this);
topf->setFrameStyle(QFrame::Box | QFrame::Raised);
topf->setLineWidth(3);
QVBoxLayout *bl = new QVBoxLayout(this);
bl->addWidget(topf);
// Setup the icon
pix_icon = new QPixmap();
switch(icon) {
case ICON_NONE: // No icon is used
{
break;
}
case ICON_DEFAULT: // An icon matching the buttons is used
{
switch(type) {
case TYPE_OK:
pix_icon->load( PIXMAP_INFO );
break;
case TYPE_OK_CANCEL:
pix_icon->load( PIXMAP_WARNING );
break;
case TYPE_YES_NO:
case TYPE_YES_NO_MAYBE:
case TYPE_YES_NO_CANCEL:
case TYPE_YES_NO_MAYBE_CANCEL:
pix_icon->load( PIXMAP_QUESTION );
break;
}
break;
}
case ICON_INFO: // An info icon (matching the ok button)
{
pix_icon->load( PIXMAP_INFO );
break;
}
case ICON_WARNING: // An warning icon (matching the ok/cancel button)
{
pix_icon->load( PIXMAP_WARNING );
break;
}
case ICON_ERROR: // An critical error icon
{
pix_icon->load( PIXMAP_ERROR );
break;
}
case ICON_QUESTION:// An question icon (matching the yes/no and yes/no/cancel buttons)
{
pix_icon->load( PIXMAP_QUESTION );
break;
}
}
QLabel *lbl_icon = new QLabel(topf);
lbl_icon->setPixmap(*pix_icon);
QLabel *lbl_text = new QLabel(topf);
lbl_text->setText(text);
lbl_text->setFont( QFont( "Sans Serif",
//(height>1)?(int)(unit * height / 2):(int)(unit * height / 2),
(int)(unit * 0.7 * BUTTON_HEIGHT / 2),
QFont::Normal ) );
lbl_text->setFixedHeight((int)(unit * BUTTON_HEIGHT));
// lbl_text->setFont(QFont("Arial", 18));
QFrame *f = new QFrame(topf);
QVBoxLayout *blayout = new QVBoxLayout(topf);
blayout->addWidget(lbl_icon);
blayout->addWidget(lbl_text);
blayout->addWidget(f);
// Setup the buttons
switch(type) {
case TYPE_OK:
{
QPushButton *bok = createButton(f, TXT_OK );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bok, 0, 0);
connect(bok, SIGNAL( clicked() ), SLOT(bok_clicked()));
break;
}
case TYPE_OK_CANCEL:
{
QPushButton *bok = createButton(f, TXT_OK );
QPushButton *bcancel = createButton(f, TXT_CANCEL );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bcancel, 0, 1);
glayout->addWidget(bok, 0, 2);
connect(bcancel, SIGNAL( clicked() ), SLOT(bcancel_clicked()));
connect(bok, SIGNAL( clicked() ), SLOT(bok_clicked()));
break;
}
case TYPE_YES_NO:
{
QPushButton *bno = createButton(f, TXT_NO );
QPushButton *byes = createButton(f, TXT_YES );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bno, 0, 0);
glayout->addWidget(byes, 0, 1);
connect(byes, SIGNAL( clicked() ), SLOT(byes_clicked()));
connect(bno, SIGNAL( clicked() ), SLOT(bno_clicked()));
break;
}
case TYPE_YES_NO_MAYBE:
{
QPushButton *bmaybe = createButton(f, TXT_MAYBE );
QPushButton *bno = createButton(f, TXT_NO );
QPushButton *byes = createButton(f, TXT_YES );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bno, 0, 0);
glayout->addWidget(byes, 0, 1);
glayout->addWidget(bmaybe, 0, 2);
connect(byes, SIGNAL( clicked() ), SLOT(byes_clicked()));
connect(bno, SIGNAL( clicked() ), SLOT(bno_clicked()));
connect(bmaybe, SIGNAL( clicked() ), SLOT(bmaybe_clicked()));
break;
}
case TYPE_YES_NO_CANCEL:
{
QPushButton *bcancel = createButton(f, TXT_CANCEL );
QPushButton *bno = createButton(f, TXT_NO );
QPushButton *byes = createButton(f, TXT_YES );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bno, 0, 0);
glayout->addWidget(bcancel, 0, 1);
glayout->addWidget(byes, 0, 2);
connect(byes, SIGNAL( clicked() ), SLOT(byes_clicked()));
connect(bcancel, SIGNAL( clicked() ), SLOT(bcancel_clicked()));
connect(bno, SIGNAL( clicked() ), SLOT(bno_clicked()));
break;
}
case TYPE_YES_NO_MAYBE_CANCEL:
{
QPushButton *bmaybe = createButton(f, TXT_MAYBE );
QPushButton *bcancel = createButton(f, TXT_CANCEL );
QPushButton *bno = createButton(f, TXT_NO );
QPushButton *byes = createButton(f, TXT_YES );
QGridLayout *glayout = new QGridLayout(f);
glayout->addWidget(bno, 0, 0);
glayout->addWidget(bcancel, 0, 1);
glayout->addWidget(byes, 0, 2);
glayout->addWidget(bmaybe, 0, 3);
connect(bmaybe, SIGNAL( clicked() ), SLOT(bmaybe_clicked()));
connect(byes, SIGNAL( clicked() ), SLOT(byes_clicked()));
connect(bcancel, SIGNAL( clicked() ), SLOT(bcancel_clicked()));
connect(bno, SIGNAL( clicked() ), SLOT(bno_clicked()));
break;
}
}
}
MessageBox::~MessageBox()
{
delete pix_icon;
}
QPushButton *MessageBox::createButton(QWidget *parent, const char *text)
{
QPushButton *q = new QPushButton(parent);
q->setText(text);
q->setFont( QFont( "Sans Serif", (int)(unit * 0.7 * BUTTON_HEIGHT / 2 ), QFont::Normal ) );
q->setFixedSize((int)(BUTTON_WIDTH * unit), (int)(BUTTON_HEIGHT * unit));
return q;
}
void MessageBox::bok_clicked()
{
done(MSG_OK);
}
void MessageBox::bcancel_clicked()
{
done(MSG_CANCEL);
}
void MessageBox::byes_clicked()
{
done(MSG_YES);
}
void MessageBox::bno_clicked()
{
done(MSG_NO);
}
void MessageBox::bmaybe_clicked()
{
done(MSG_MAYBE);
}
#endif/*USE_GUI*/
|