- Timestamp:
- Jul 26, 2007 9:04:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/QIMessageBox.cpp
r3892 r3893 45 45 * See QMessageBox for details. 46 46 */ 47 QIMessageBox::QIMessageBox (const QString &aCaption, const QString &aText, 48 Icon aIcon, int aButton0, int aButton1, int aButton2, 49 QWidget *aParent, const char *aName, bool aModal, 50 WFlags aFlags) 51 : QDialog (aParent, aName, aModal, 52 aFlags | WStyle_Customize | WStyle_NormalBorder | 53 WStyle_Title | WStyle_SysMenu) 54 { 55 setCaption (aCaption); 56 57 mButton0 = aButton0; 58 mButton1 = aButton1; 59 mButton2 = aButton2; 47 QIMessageBox::QIMessageBox ( 48 const QString &caption, const QString &text, 49 Icon icon, int button0, int button1, int button2, 50 QWidget *parent, const char *name, bool modal, 51 WFlags f 52 ) : 53 QDialog ( 54 parent, name, modal, 55 f | WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu 56 ) 57 { 58 setCaption (caption); 59 60 b0 = button0; 61 b1 = button1; 62 b2 = button2; 60 63 61 64 QVBoxLayout *layout = new QVBoxLayout (this); … … 71 74 layout->addWidget (main); 72 75 73 mIconLabel = new QLabel (main); 74 mIconLabel->setPixmap (QMessageBox::standardIcon ((QMessageBox::Icon) aIcon)); 75 mIconLabel->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum); 76 mIconLabel->setAlignment (AlignHCenter | AlignTop); 77 78 mMessageVBox = new QVBox (main); 79 mMessageVBox->setMargin (0); 80 mMessageVBox->setSpacing (10); 81 82 mTextLabel = new QLabel (aText, mMessageVBox); 83 mTextLabel->setAlignment (AlignAuto | AlignTop | ExpandTabs | WordBreak); 84 mTextLabel->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed, true); 85 86 mFlagCB_Main = new QCheckBox (mMessageVBox); 87 88 mDetailsVBox = new QVBox (this); 89 mDetailsVBox->setMargin (0); 90 mDetailsVBox->setSpacing (10); 91 layout->addWidget (mDetailsVBox); 92 93 mDetailsText = new QTextEdit (mDetailsVBox); 76 licon = new QLabel (main); 77 licon->setPixmap (QMessageBox::standardIcon ((QMessageBox::Icon) icon)); 78 licon->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum); 79 licon->setAlignment (AlignHCenter | AlignTop); 80 81 message = new QVBox (main); 82 message->setMargin (0); 83 message->setSpacing (10); 84 85 ltext = new QLabel (text, message); 86 ltext->setAlignment (AlignAuto | AlignTop | ExpandTabs | WordBreak); 87 ltext->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed, true); 88 89 dbox = new QVBox (this); 90 dbox->setMargin (0); 91 dbox->setSpacing (10); 92 layout->addWidget (dbox); 93 94 dtext = new QTextEdit (dbox); 94 95 { 95 96 /* calculate the minimum size dynamically, approx. for 40 chars and 96 97 * 6 lines */ 97 QFontMetrics fm = mDetailsText->fontMetrics(); 98 mDetailsText->setMinimumSize (40 * fm.width ('m'), fm.lineSpacing() * 6); 99 } 100 mDetailsText->setReadOnly (true); 101 mDetailsText->setWrapPolicy (QTextEdit::AtWordOrDocumentBoundary); 102 mDetailsText->setSizePolicy (QSizePolicy::Expanding, 103 QSizePolicy::MinimumExpanding); 104 105 mFlagCB_Details = new QCheckBox (mDetailsVBox); 106 107 mSpacer = new QSpacerItem (0, 0); 108 layout->addItem (mSpacer); 98 QFontMetrics fm = dtext->fontMetrics(); 99 dtext->setMinimumSize (40 * fm.width ('m'), fm.lineSpacing() * 6); 100 } 101 dtext->setReadOnly (true); 102 dtext->setWrapPolicy (QTextEdit::AtWordOrDocumentBoundary); 103 dtext->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); 104 105 /* cbflag has no parent initially, setDetailsShown() will do that */ 106 cbflag = new QCheckBox (0); 107 cbflag->hide(); 108 109 spacer = new QSpacerItem (0, 0); 110 layout->addItem (spacer); 109 111 110 112 QHBoxLayout *buttons = new QHBoxLayout (new QWidget (this)); … … 113 115 buttons->setSpacing (5); 114 116 115 mButtonEsc = 0; 116 117 mButton0PB = createButton (buttons->mainWidget(), aButton0); 118 if (mButton0PB) 119 connect (mButton0PB, SIGNAL (clicked()), SLOT (done0())); 120 mButton1PB = createButton (buttons->mainWidget(), aButton1); 121 if (mButton1PB) 122 connect (mButton1PB, SIGNAL (clicked()), SLOT (done1())); 123 mButton2PB = createButton (buttons->mainWidget(), aButton2); 124 if (mButton2PB) 125 connect (mButton2PB, SIGNAL (clicked()), SLOT (done2())); 126 117 bescape = 0; 118 119 pb0 = createButton (buttons->mainWidget(), button0); 120 if (pb0) connect (pb0, SIGNAL( clicked() ), SLOT( done0() )); 121 pb1 = createButton (buttons->mainWidget(), button1); 122 if (pb1) connect (pb1, SIGNAL( clicked() ), SLOT( done1() )); 123 pb2 = createButton (buttons->mainWidget(), button2); 124 if (pb2) connect (pb2, SIGNAL( clicked() ), SLOT( done2() )); 127 125 buttons->setAlignment (AlignHCenter); 128 126 129 /* this call is a must -- it initializes mFlagCB and mSpacer */130 127 setDetailsShown (false); 131 128 } … … 144 141 * will hide the flag. By default, the flag is hidden. 145 142 */ 146 void QIMessageBox::setFlagText (const QString &aText) 147 { 148 if (aText.isNull()) 149 { 150 mFlagCB->hide(); 151 } 152 else 153 { 154 mFlagCB->setText (aText); 155 mFlagCB->show(); 156 mFlagCB->setFocus(); 143 void QIMessageBox::setFlagText (const QString &text) 144 { 145 if (text.isNull()) { 146 cbflag->hide(); 147 } else { 148 cbflag->setText (text); 149 cbflag->show(); 150 cbflag->setFocus(); 157 151 } 158 152 } … … 175 169 */ 176 170 177 QPushButton *QIMessageBox::createButton (QWidget * aParent, int aButton)178 { 179 if ( aButton == 0)171 QPushButton *QIMessageBox::createButton (QWidget *parent, int button) 172 { 173 if (button == 0) 180 174 return 0; 181 175 182 176 QString text; 183 switch ( aButton & ButtonMask)177 switch (button & ButtonMask) 184 178 { 185 179 case Ok: text = tr ("OK"); break; … … 189 183 case Ignore: text = tr ("Ignore"); break; 190 184 default: 191 AssertMsgFailed (("Type %d is not implemented", aButton)); 192 return NULL; 193 } 194 195 QPushButton *b = new QPushButton (text, aParent); 196 197 if (aButton & Default) 185 AssertMsgFailed (("QIMessageBox::createButton(): type %d is not implemented", 186 button)); 187 return 0; 188 } 189 190 QPushButton *b = new QPushButton (text, parent); 191 192 if (button & Default) 198 193 { 199 194 b->setDefault (true); … … 201 196 } 202 197 else 203 if ( aButton & Escape)204 mButtonEsc = aButton & ButtonMask;198 if (button & Escape) 199 bescape = button & ButtonMask; 205 200 206 201 return b; … … 222 217 * @see #setDetailsShown() 223 218 */ 224 void QIMessageBox::setDetailsText (const QString & aText)225 { 226 mDetailsText->setText (aText);219 void QIMessageBox::setDetailsText (const QString &text) 220 { 221 dtext->setText (text); 227 222 } 228 223 … … 243 238 * @see #setDetailsText() 244 239 */ 245 void QIMessageBox::setDetailsShown (bool aShown)246 { 247 if (aShown) 248 {249 mFlagCB_Details->setShown (mFlagCB->isShown()); 250 mFlagCB_Details->setChecked (mFlagCB->isChecked());251 mFlagCB_Main->setShown (false);252 mFlagCB = mFlagCB_Details;253 mSpacer->changeSize (0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum);254 }255 256 mDetailsVBox->setShown (aShown); 257 258 if (!aShown) 259 {260 mFlagCB_Main->setShown (mFlagCB_Details->isShown());261 mFlagCB_Main->setChecked (mFlagCB_Details->isChecked());262 mFlagCB = mFlagCB_Main;263 mSpacer->changeSize (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);264 } 265 } 266 240 void QIMessageBox::setDetailsShown (bool shown) 241 { 242 243 bool cbflagShown = cbflag->isShown(); 244 245 if (shown) 246 { 247 cbflag->reparent (dbox, QPoint()); 248 cbflag->setShown (cbflagShown); 249 spacer->changeSize (0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum); 250 } 251 252 dbox->setShown (shown); 253 254 if (!shown) 255 { 256 cbflag->reparent (message, QPoint(), cbflagShown); 257 cbflag->setShown (cbflagShown); 258 spacer->changeSize (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 259 } 260 } 261
Note:
See TracChangeset
for help on using the changeset viewer.