diff options
Diffstat (limited to 'client/messagebox.cc')
-rw-r--r-- | client/messagebox.cc | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/client/messagebox.cc b/client/messagebox.cc new file mode 100644 index 0000000..fd812eb --- /dev/null +++ b/client/messagebox.cc @@ -0,0 +1,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, name, TRUE) +{ + int resolution_w = config->readInt("pixel_width"); + //int resolution_h = config->readInt("pixel_height"); + unit = ((float)resolution_w / config->readFloat("screensize")) / INCH_IN_CM; + + + setCaption(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, 20, 20); + + 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, 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, TXT_OK ); + QPushButton *bcancel = createButton(f, TXT_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 *bno = createButton(f, TXT_NO ); + QPushButton *byes = createButton(f, TXT_YES ); + 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_MAYBE: + { + QPushButton *bmaybe = createButton(f, TXT_MAYBE ); + QPushButton *bno = createButton(f, TXT_NO ); + QPushButton *byes = createButton(f, TXT_YES ); + QGridLayout *glayout = new QGridLayout(f, 1, 3, 20, 20); + 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, 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; + } + 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, 1, 4, 20, 20); + 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*/ |