00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <util/html.h>
00029 #include "vmessagebox.h"
00030
00031
00032
00033 VMessageBox::VMessageBox(QWidget *parent)
00034 : QMessageBox(parent)
00035 {
00036 }
00037
00038
00039
00040 int
00041 VMessageBox::defaultButton(int button0, int button1, int button2)
00042 {
00043 Q_UNUSED(button0);
00044 int defaultButton = 0;
00045 if (button1 & QMessageBox::Default) {
00046 defaultButton = 1;
00047 } else if (button2 & QMessageBox::Default) {
00048 defaultButton = 2;
00049 }
00050 return defaultButton;
00051 }
00052
00053
00054
00055 int
00056 VMessageBox::escapeButton(int button0, int button1, int button2)
00057 {
00058 int escapeButton = -1;
00059 if (button0 & QMessageBox::Escape) {
00060 escapeButton = 0;
00061 } else if (button1 & QMessageBox::Escape) {
00062 escapeButton = 1;
00063 } else if (button2 & QMessageBox::Escape) {
00064 escapeButton = 2;
00065 }
00066 return escapeButton;
00067 }
00068
00069
00070 int
00071 VMessageBox::selected(int ret, int button0, int button1, int button2)
00072 {
00073 if (ret == 0) {
00074 return (button0 & QMessageBox::ButtonMask);
00075 } else if (ret == 1) {
00076 return (button1 & QMessageBox::ButtonMask);
00077 }
00078 return (button2 & QMessageBox::ButtonMask);
00079 }
00080
00081
00082 QString
00083 VMessageBox::buttonText(int btn)
00084 {
00085 QString text;
00086 int button = (btn & ~QMessageBox::FlagMask);
00087 switch (button) {
00088 case Ok: text = tr("OK"); break;
00089 case Cancel: text = tr("Cancel"); break;
00090 case Yes: text = tr("Yes"); break;
00091 case No: text = tr("No"); break;
00092 case Help: text = tr("Help"); break;
00093 case Retry: text = tr("Retry"); break;
00094 case ShowLog: text = tr("Show Log"); break;
00095 case ShowSettings: text = tr("Show Settings"); break;
00096 case Continue: text = tr("Continue"); break;
00097 case Quit: text = tr("Quit"); break;
00098 case Browse: text = tr("Browse"); break;
00099 default: break;
00100 }
00101 return text;
00102 }
00103
00104
00105
00106
00107
00108 int
00109 VMessageBox::critical(QWidget *parent, QString caption, QString text,
00110 int button0, int button1, int button2)
00111 {
00112 int ret = QMessageBox::critical(parent, caption, p(text),
00113 VMessageBox::buttonText(button0),
00114 VMessageBox::buttonText(button1),
00115 VMessageBox::buttonText(button2),
00116 VMessageBox::defaultButton(button0, button1, button2),
00117 VMessageBox::escapeButton(button0, button1, button2));
00118 return VMessageBox::selected(ret, button0, button1, button2);
00119 }
00120
00121
00122
00123
00124
00125 int
00126 VMessageBox::question(QWidget *parent, QString caption, QString text,
00127 int button0, int button1, int button2)
00128 {
00129 int ret = QMessageBox::question(parent, caption, p(text),
00130 VMessageBox::buttonText(button0),
00131 VMessageBox::buttonText(button1),
00132 VMessageBox::buttonText(button2),
00133 VMessageBox::defaultButton(button0, button1, button2),
00134 VMessageBox::escapeButton(button0, button1, button2));
00135 return VMessageBox::selected(ret, button0, button1, button2);
00136 }
00137
00138
00139
00140
00141
00142 int
00143 VMessageBox::information(QWidget *parent, QString caption, QString text,
00144 int button0, int button1, int button2)
00145 {
00146 int ret = QMessageBox::information(parent, caption, p(text),
00147 VMessageBox::buttonText(button0),
00148 VMessageBox::buttonText(button1),
00149 VMessageBox::buttonText(button2),
00150 VMessageBox::defaultButton(button0, button1, button2),
00151 VMessageBox::escapeButton(button0, button1, button2));
00152 return VMessageBox::selected(ret, button0, button1, button2);
00153 }
00154
00155
00156
00157
00158
00159 int
00160 VMessageBox::warning(QWidget *parent, QString caption, QString text,
00161 int button0, int button1, int button2)
00162 {
00163 int ret = QMessageBox::warning(parent, caption, p(text),
00164 VMessageBox::buttonText(button0),
00165 VMessageBox::buttonText(button1),
00166 VMessageBox::buttonText(button2),
00167 VMessageBox::defaultButton(button0, button1, button2),
00168 VMessageBox::escapeButton(button0, button1, button2));
00169 return VMessageBox::selected(ret, button0, button1, button2);
00170 }
00171