summaryrefslogtreecommitdiff
path: root/src/messagebox.cc
blob: a636bd7eca7aa84186a833053d0118c8fd8d3982 (plain)
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/* -*- 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 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 Library 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.
 */

#include "messagebox.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, name, TRUE)
{
	QFrame *topf = new QFrame(this);
		topf->setFrameStyle(QFrame::Box | QFrame::Raised);
		topf->setLineWidth(3);	
	QVBoxLayout *bl = new QVBoxLayout(this);
	bl->addWidget(topf);
	
	QLabel *lbl_text = new QLabel(topf);
	lbl_text->setText(text);
	lbl_text->setFont(QFont("Lucida", 18));
	QFrame *f = new QFrame(topf);

	QVBoxLayout *blayout = new QVBoxLayout(topf, 20, 20);
	blayout->addWidget(lbl_text);
	blayout->addWidget(f);

  // 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:
        printf("using info icon!\n");
        pix_icon->load( "info.png" );
        break;
      case TYPE_OK_CANCEL: 
        printf("using warning icon!\n");
        pix_icon->load( "warning.png" );
        break;
      case TYPE_YES_NO: 
        printf("using question icon!\n");
        pix_icon->load( "question.png" );
        break;
      case TYPE_YES_NO_CANCEL: 
        printf("using question icon!\n");
        pix_icon->load( "question.png" );
        break;
      }
      break;
    }
  case ICON_INFO:    // An info icon (matching the ok button)
    {
      printf("using info icon!\n");
      pix_icon->load( "info.png" );
      break;
    }
  case ICON_WARN:    // An warning icon (matching the ok/cancel button)
    {
      printf("using warning icon!\n");
      pix_icon->load( "warning.png" );
      break;
    }
  case ICON_ERROR:   // An critical error  icon
    {
      printf("using error icon!\n");
      pix_icon->load( "error.png" );
      break;
    }
  case ICON_QUESTION:// An question icon (matching the yes/no and yes/no/cancel buttons)
    {
      printf("using question icon!\n");
      pix_icon->load( "question.png" );
      break;
    }
  }
  
  // Setup the buttons
  switch(type) {
  case TYPE_OK: 
    {
      QPushButton *bok = createButton(f, "Ok");
      QGridLayout *glayout = new QGridLayout(f, 1, 1, 20, 20);
      glayout->addWidget(bok, 0, 0);
      connect(bok, SIGNAL( clicked() ), SLOT(bok_clicked()));	
      break;
    }
  case TYPE_OK_CANCEL: 
    {
      QPushButton *bok = createButton(f, "Ok");
      QPushButton *bcancel = createButton(f, "Cancel");
      QGridLayout *glayout = new QGridLayout(f, 1, 2, 20, 20);
      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 *byes = createButton(f, "Ja");
      QPushButton *bno = createButton(f, "Nej");
      QGridLayout *glayout = new QGridLayout(f, 1, 2, 20, 20);
      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_CANCEL: 
    {
      QPushButton *byes = createButton(f, "Ja");
      QPushButton *bcancel = createButton(f, "Cancel");
      QPushButton *bno = createButton(f, "Nej");
      QGridLayout *glayout = new QGridLayout(f, 1, 3, 20, 20);
      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;
    }
  }

}

MessageBox::~MessageBox() 
{
  delete pix_icon;
}

QPushButton *MessageBox::createButton(QWidget *parent, const char *text)
{
	QPushButton *q = new QPushButton(parent);
	q->setText(text);
	q->setFont(QFont("Lucida", 18));
	q->setFixedSize(200, 75);
	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);
}	


/*
////////////////////////////////////////////////////////////////////////////////////////
// A generic alert dialog that can either give the user a choice
// (yes or no - returns true or false) or simply give a statement and await the users
// acknowledgement (OK - returns true)
// 

Alert::Alert(QWidget *parent, const char *text, bool single, const char* name, bool mode) 
: QDialog(parent, name, mode) 
// Sets up the dialog. Two buttons if mode=true otherwise one button 
{

	QPushButton *b_true; ;
	QPushButton *b_false;

	QFrame *topf = new QFrame(this);
	topf->setFrameStyle(QFrame::Box | QFrame::Raised);
	topf->setLineWidth(3);	
	QVBoxLayout *bl1 = new QVBoxLayout(topf, 20, 20);

	QLabel *l_text = new QLabel(topf);
	QFont font("Lucida", 18);
	l_text->setText(text);
	l_text->setFont(font);

	QFrame *f = new QFrame(topf);
	QHBoxLayout *bl2 = new QHBoxLayout(f, 20, 20);


	QVBoxLayout *toplayout = new QVBoxLayout(this);
	toplayout->addWidget(topf);
	bl1->addWidget(l_text);
	bl1->addWidget(f);
	if(!single)
	{
	b_true = createButton(f, M_YES);
	b_false = createButton(f, M_NO);
	bl2->addWidget(b_false);
	bl2->addWidget(b_true);
	connect(b_false, SIGNAL(clicked()), SLOT(false_clicked()));
	connect(b_true, SIGNAL(clicked()), SLOT(true_clicked()));
	}
	else
	{
	b_true = createButton(f, M_OK);
	bl2->addWidget(b_true);
	connect(b_true, SIGNAL(clicked()), SLOT(true_clicked()));
	}

}

QPushButton *Alert::createButton(QWidget *parent, const char *text) 
{
	QPushButton *q = new QPushButton(parent);
	QFont font("Lucida", 18);
	q->setFont(font);
	q->setText(text);
	q->setFixedSize(200,75);
	return q;
}

void Alert::true_clicked() 
{
	accept();
}

void Alert::false_clicked() 
{
	reject();
}
*/