diff options
author | deva <deva> | 2005-03-24 13:07:30 +0000 |
---|---|---|
committer | deva <deva> | 2005-03-24 13:07:30 +0000 |
commit | 50adc3e1f496246e0d91a831eebd4fbb730dff1c (patch) | |
tree | 7b0e4da6992a1be55d77cdc997c2543451cd8a35 /src | |
parent | 9466b3042bc7314915a15f499bd0b087f569654d (diff) |
Added icon support for the MessageBox.
Diffstat (limited to 'src')
-rw-r--r-- | src/messagebox.cc | 153 | ||||
-rw-r--r-- | src/messagebox.h | 18 |
2 files changed, 128 insertions, 43 deletions
diff --git a/src/messagebox.cc b/src/messagebox.cc index 47799b7..a636bd7 100644 --- a/src/messagebox.cc +++ b/src/messagebox.cc @@ -31,7 +31,11 @@ * or clear the number. */ -MessageBox::MessageBox(QWidget* parent, const char* name, const char* text, msg_type type) +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); @@ -41,7 +45,6 @@ MessageBox::MessageBox(QWidget* parent, const char* name, const char* text, msg_ bl->addWidget(topf); QLabel *lbl_text = new QLabel(topf); - // text->setText("CPR ikke gyldigt, ønsker du at forsætte?"); lbl_text->setText(text); lbl_text->setFont(QFont("Lucida", 18)); QFrame *f = new QFrame(topf); @@ -50,48 +53,114 @@ MessageBox::MessageBox(QWidget* parent, const char* name, const char* text, msg_ blayout->addWidget(lbl_text); blayout->addWidget(f); - 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; + // 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) diff --git a/src/messagebox.h b/src/messagebox.h index 11a1c05..28b06a8 100644 --- a/src/messagebox.h +++ b/src/messagebox.h @@ -32,6 +32,16 @@ #include <qlayout.h> #include <qpushbutton.h> #include <qlabel.h> +#include <qpixmap.h> + +typedef enum { + ICON_NONE, // No icon is used + ICON_DEFAULT, // An icon matching the buttons is used + ICON_INFO, // An info icon (matching the ok button) + ICON_WARN, // An warning icon (matching the ok/cancel button) + ICON_ERROR, // An critical error icon + ICON_QUESTION // An question icon (matching the yes/no and yes/no/cancel buttons) +} msg_icon; typedef enum { MSG_YES, @@ -51,7 +61,12 @@ class MessageBox : public QDialog { Q_OBJECT public: - MessageBox(QWidget* parent = 0, const char* name = "", const char* text = "", msg_type type = TYPE_OK); + MessageBox(QWidget* parent = 0, + const char* name = "", + const char* text = "", + msg_type type = TYPE_OK, + msg_icon icon = ICON_DEFAULT); + ~MessageBox(); public slots: void bok_clicked(); @@ -60,6 +75,7 @@ public slots: void bno_clicked(); private: + QPixmap *pix_icon; QPushButton *createButton(QWidget *parent, const char *text); }; |