Changeset 24182 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 30, 2009 11:07:40 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/QIDialog.h
r23031 r24182 6 6 7 7 /* 8 * Copyright (C) 2008 Sun Microsystems, Inc.8 * Copyright (C) 2008-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 #include <QDialog> 28 28 29 /* Qt forwards declarations */ 30 class QEventLoop; 31 29 32 class QIDialog: public QDialog 30 33 { … … 32 35 33 36 public: 34 35 37 QIDialog (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0); 38 void setVisible (bool aVisible); 36 39 37 40 public slots: 38 int exec ();41 int exec (bool aShow = true); 39 42 40 43 protected: 41 42 44 void showEvent (QShowEvent *aEvent); 43 45 46 private: 47 /* Private member vars */ 44 48 bool mPolished; 49 QEventLoop *mEventLoop; 45 50 }; 46 51 47 52 #endif /* __QIDialog_h__ */ 53 -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxCocoaSpecialControls.h
r24107 r24182 49 49 QSize sizeHint() const; 50 50 51 void setText (const QString& aText); 51 52 void setToolTip (const QString& aTip); 52 53 -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxProgressDialog.h
r20594 r24182 30 30 class CProgress; 31 31 class QILabel; 32 class VBoxMiniCancelButton; 32 33 33 34 /* Qt forward declarations */ 34 class QEventLoop;35 35 class QProgressBar; 36 36 … … 53 53 54 54 public: 55 56 55 VBoxProgressDialog (CProgress &aProgress, const QString &aTitle, 57 56 int aMinDuration = 2000, QWidget *aParent = 0); … … 61 60 62 61 protected: 63 64 62 virtual void retranslateUi(); 65 63 … … 70 68 71 69 private slots: 72 73 70 void showDialog(); 74 71 void cancelOperation(); 75 72 76 73 private: 77 78 74 /* Private member vars */ 79 75 CProgress &mProgress; 80 76 QILabel *mLabel; 81 77 QILabel *mETA; 82 QString mETAText; 78 QString mETAText[14]; 79 QString mCancelText; 83 80 QProgressBar *mProgressBar; 84 QEventLoop *mEventLoop;81 VBoxMiniCancelButton *mCancelBtn; 85 82 bool mCancelEnabled; 86 83 const ulong mOpCount; -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxSpecialControls.h
r24107 r24182 47 47 VBoxMiniCancelButton (QWidget *aParent = 0); 48 48 49 void setText (const QString &aText) { mButton->setText (aText); } 49 50 void setToolTip (const QString &aTip) { mButton->setToolTip (aTip); } 50 51 -
trunk/src/VBox/Frontends/VirtualBox/src/QIDialog.cpp
r23031 r24182 6 6 7 7 /* 8 * Copyright (C) 2008 Sun Microsystems, Inc.8 * Copyright (C) 2008-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 */ 22 22 23 23 /* VBox includes */ 24 24 #include "QIDialog.h" 25 25 #include "VBoxGlobal.h" 26 26 #ifdef Q_WS_MAC 27 # include "VBoxUtils.h"27 # include "VBoxUtils.h" 28 28 #endif /* Q_WS_MAC */ 29 29 30 QIDialog::QIDialog (QWidget *aParent, Qt::WindowFlags aFlags) 30 /* Qt includes */ 31 #include <QPointer> 32 33 QIDialog::QIDialog (QWidget *aParent /* = 0 */, Qt::WindowFlags aFlags /* = 0 */) 31 34 : QDialog (aParent, aFlags) 32 35 , mPolished (false) 36 , mEventLoop (0) 33 37 { 34 38 } … … 61 65 } 62 66 63 int QIDialog::exec ()67 int QIDialog::exec (bool aShow /* = true */) 64 68 { 65 #if QT_VERSION >= 0x040500 66 /* After 4.5 exec ignores the Qt::Sheet flag. See "New Ways of Using 67 * Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why. Because 68 * we are lazy, we recreate the old behavior. */ 69 /* Reset the result code */ 70 setResult (QDialog::Rejected); 71 72 bool wasDeleteOnClose = testAttribute (Qt::WA_DeleteOnClose); 73 setAttribute (Qt::WA_DeleteOnClose, false); 74 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 75 /* After 4.5 Qt changed the behavior of Sheets for the window/application 76 * modal case. See "New Ways of Using Dialogs" in 77 * http://doc.trolltech.com/qq/QtQuarterly30.pdf why. We want the old 78 * behavior back, where all modal windows where shown as sheets. So make 79 * the modal mode window, but be application modal in any case. */ 80 Qt::WindowModality winModality = windowModality(); 81 bool wasSetWinModality = testAttribute (Qt::WA_SetWindowModality); 69 82 if ((windowFlags() & Qt::Sheet) == Qt::Sheet) 70 83 { 71 QEventLoop eventLoop; 72 connect(this, SIGNAL(finished(int)), 73 &eventLoop, SLOT(quit())); 74 /* Use the new open call. */ 75 open(); 76 eventLoop.exec(); 84 setWindowModality (Qt::WindowModal); 85 setAttribute (Qt::WA_SetWindowModality, false); 86 } 87 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */ 88 /* The dialog has to modal in any case. Save the current modality to 89 * restore it later. */ 90 bool wasShowModal = testAttribute (Qt::WA_ShowModal); 91 setAttribute (Qt::WA_ShowModal, true); 77 92 78 return result(); 93 /* Create a local event loop */ 94 mEventLoop = new QEventLoop(); 95 /* Show the window if requested */ 96 if (aShow) 97 show(); 98 /* A guard to ourself for the case we destroy ourself. */ 99 QPointer<QIDialog> guard = this; 100 /* Start the event loop. This blocks. */ 101 mEventLoop->exec(); 102 /* Delete the event loop */ 103 delete mEventLoop; 104 mEventLoop = 0; 105 /* Are we valid anymore? */ 106 if (guard.isNull()) 107 return QDialog::Rejected; 108 /* Save the result code in case we delete ourself */ 109 QDialog::DialogCode res = (QDialog::DialogCode)result(); 110 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 111 /* Restore old modality mode */ 112 if ((windowFlags() & Qt::Sheet) == Qt::Sheet) 113 { 114 setWindowModality (winModality); 115 setAttribute (Qt::WA_SetWindowModality, wasSetWinModality); 79 116 } 80 else 81 #endif /* QT_VERSION >= 0x040500 */ 82 return QDialog::exec(); 117 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */ 118 /* Set the old show modal attribute */ 119 setAttribute (Qt::WA_ShowModal, wasShowModal); 120 /* Delete us in the case we should do so on close */ 121 if (wasDeleteOnClose) 122 delete this; 123 /* Return the final result */ 124 return res; 83 125 } 126 127 void QIDialog::setVisible (bool aVisible) 128 { 129 QDialog::setVisible (aVisible); 130 /* Exit from the event loop if there is any and we are changing our state 131 * from visible to invisible. */ 132 if (mEventLoop && !aVisible) 133 mEventLoop->exit(); 134 } 135 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxProgressDialog.cpp
r20594 r24182 27 27 #include "VBoxGlobal.h" 28 28 #include "VBoxProgressDialog.h" 29 29 #include "VBoxSpecialControls.h" 30 30 #ifdef Q_WS_MAC 31 31 # include "VBoxUtils-darwin.h" … … 40 40 #include <QVBoxLayout> 41 41 42 #define VBOX_SECOND 1 43 #define VBOX_MINUTE VBOX_SECOND * 60 44 #define VBOX_HOUR VBOX_MINUTE * 60 45 #define VBOX_DAY VBOX_HOUR * 24 46 42 47 const char *VBoxProgressDialog::sOpDescTpl = "%1... (%2/%3)"; 43 48 … … 46 51 int aMinDuration /* = 2000 */, 47 52 QWidget *aParent /* = 0 */) 53 // : QIDialog (aParent, Qt::Sheet | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint) 48 54 : QIDialog (aParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint) 49 55 , mProgress (aProgress) 50 , m EventLoop (new QEventLoop (this))56 , mCancelBtn (0) 51 57 , mCancelEnabled (false) 52 58 , mOpCount (mProgress.GetOperationCount()) … … 56 62 setModal (true); 57 63 58 QVBoxLayout *p MainLayout= new QVBoxLayout (this);64 QVBoxLayout *pLayout1 = new QVBoxLayout (this); 59 65 60 66 #ifdef Q_WS_MAC 61 67 ::darwinSetHidesAllTitleButtons (this); 62 68 ::darwinSetShowsResizeIndicator (this, false); 63 VBoxGlobal::setLayoutMargin (p MainLayout, 6);69 VBoxGlobal::setLayoutMargin (pLayout1, 6); 64 70 #endif /* Q_WS_MAC */ 65 71 66 72 mLabel = new QILabel (this); 67 pMainLayout->addWidget (mLabel); 68 pMainLayout->setAlignment (mLabel, Qt::AlignHCenter); 73 pLayout1->addWidget (mLabel, 0, Qt::AlignHCenter); 74 75 QHBoxLayout *pLayout2 = new QHBoxLayout(); 76 pLayout2->setMargin (0); 77 pLayout1->addLayout (pLayout2); 69 78 70 79 mProgressBar = new QProgressBar (this); 71 pMainLayout->addWidget (mProgressBar); 72 73 QHBoxLayout *pLayout1 = new QHBoxLayout(); 74 pLayout1->setMargin (0); 75 mETA = new QILabel (this); 76 pLayout1->addWidget (mETA); 77 pMainLayout->addLayout (pLayout1); 80 pLayout2->addWidget (mProgressBar, 0, Qt::AlignVCenter); 78 81 79 82 if (mOpCount > 1) … … 90 93 if (mCancelEnabled) 91 94 { 92 QDialogButtonBox *pBtnBox = new QDialogButtonBox (QDialogButtonBox::Cancel, 93 Qt::Horizontal, this); 94 pLayout1->addWidget (pBtnBox); 95 connect (pBtnBox, SIGNAL (rejected()), this, SLOT (cancelOperation())); 96 } 95 mCancelBtn = new VBoxMiniCancelButton (this); 96 mCancelBtn->setFocusPolicy (Qt::ClickFocus); 97 pLayout2->addWidget (mCancelBtn, 0, Qt::AlignVCenter); 98 connect (mCancelBtn, SIGNAL (clicked()), this, SLOT (cancelOperation())); 99 } 100 101 mETA = new QILabel (this); 102 pLayout1->addWidget (mETA, 0, Qt::AlignLeft | Qt::AlignVCenter); 103 104 setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); 97 105 98 106 retranslateUi(); … … 105 113 void VBoxProgressDialog::retranslateUi() 106 114 { 107 mETAText = tr ("Time remaining: %1"); 115 mETAText[ 0] = tr ("%1 days, %2 hours remaining"); 116 mETAText[ 1] = tr ("%1 days, %2 minutes remaining"); 117 mETAText[ 2] = tr ("%1 days remaining"); 118 mETAText[ 3] = tr ("1 day, %1 hours remaining"); 119 mETAText[ 4] = tr ("1 day, %1 minutes remaining"); 120 mETAText[ 5] = tr ("1 day remaining"); 121 mETAText[ 6] = tr ("%1 hours, %2 minutes remaining"); 122 mETAText[ 7] = tr ("1 hour, %1 minutes remaining"); 123 mETAText[ 8] = tr ("1 hour remaining"); 124 mETAText[ 9] = tr ("%1 minutes remaining"); 125 mETAText[10] = tr ("1 minute, %2 seconds remaining"); 126 mETAText[11] = tr ("1 minute remaining"); 127 mETAText[12] = tr ("%1 seconds remaining"); 128 mETAText[13] = tr ("A few seconds remaining"); 129 130 mCancelText = tr ("Canceling..."); 131 if (mCancelBtn) 132 { 133 mCancelBtn->setText (tr ("&Cancel")); 134 mCancelBtn->setToolTip (tr ("Cancel the current operation")); 135 } 108 136 } 109 137 … … 118 146 QApplication::setOverrideCursor (QCursor (Qt::WaitCursor)); 119 147 120 /* Enter the modal loop */121 mEventLoop->exec();148 /* Enter the modal loop, but don't show the window immediately */ 149 exec (false); 122 150 123 151 /* Kill refresh timer */ 124 152 killTimer (id); 153 154 QApplication::restoreOverrideCursor(); 125 155 126 156 return result(); … … 142 172 void VBoxProgressDialog::cancelOperation() 143 173 { 174 if (mCancelBtn) 175 mCancelBtn->setEnabled (false); 144 176 mProgress.Cancel(); 145 177 } … … 153 185 * being exit overlapping 'this'. */ 154 186 if (mEnded && !isHidden()) 187 { 155 188 hide(); 189 return; 190 } 191 else if (mEnded) 192 return; 156 193 157 194 if (!mEnded && (!mProgress.isOk() || mProgress.GetCompleted())) … … 161 198 { 162 199 mProgressBar->setValue (100); 163 setResult(Accepted);200 done (Accepted); 164 201 } 165 202 /* Progress is not valid */ 166 203 else 167 setResult(Rejected);204 done (Rejected); 168 205 169 206 /* Request to exit loop */ 170 207 mEnded = true; 171 172 /* The progress will be finalized173 * on next timer iteration. */174 return;175 }176 177 if (mEnded)178 {179 if (mEventLoop->isRunning())180 {181 /* Exit loop if it is running */182 mEventLoop->quit();183 184 /* Restore normal cursor */185 QApplication::restoreOverrideCursor();186 }187 208 return; 188 209 } … … 193 214 /* First ETA */ 194 215 long newTime = mProgress.GetTimeRemaining(); 195 if (newTime >= 0) 196 { 197 QTime time (0, 0); 198 time = time.addSecs (newTime); 199 mETA->setText (mETAText.arg (time.toString())); 200 } 216 QDateTime time; 217 time.setTime_t (newTime); 218 QDateTime refTime; 219 refTime.setTime_t (0); 220 221 int days = refTime.daysTo (time); 222 int hours = time.addDays (-days).time().hour(); 223 int minutes = time.addDays (-days).time().minute(); 224 int seconds = time.addDays (-days).time().second(); 225 if (newTime > VBOX_DAY * 2 + VBOX_HOUR) 226 mETA->setText (mETAText[ 0].arg (days).arg (hours)); 227 else if (newTime > VBOX_DAY * 2 + VBOX_MINUTE * 5) 228 mETA->setText (mETAText[ 1].arg (days).arg (minutes)); 229 else if (newTime > VBOX_DAY * 2) 230 mETA->setText (mETAText[ 2].arg (days)); 231 else if (newTime > VBOX_DAY + VBOX_HOUR) 232 mETA->setText (mETAText[ 3].arg (hours)); 233 else if (newTime > VBOX_DAY + VBOX_MINUTE * 5) 234 mETA->setText (mETAText[ 4].arg (minutes)); 235 else if (newTime > VBOX_HOUR * 23 + VBOX_MINUTE * 55) 236 mETA->setText (mETAText[ 5]); 237 else if (newTime > VBOX_HOUR * 2) 238 mETA->setText (mETAText[ 6].arg (hours).arg (minutes)); 239 else if (newTime > VBOX_HOUR + VBOX_MINUTE * 5) 240 mETA->setText (mETAText[ 7].arg (hours).arg (minutes)); 241 else if (newTime > VBOX_MINUTE * 55) 242 mETA->setText (mETAText[ 8]); 243 else if (newTime > VBOX_MINUTE * 2) 244 mETA->setText (mETAText[ 9].arg (minutes)); 245 else if (newTime > VBOX_MINUTE + VBOX_SECOND * 5) 246 mETA->setText (mETAText[10].arg (seconds)); 247 else if (newTime > VBOX_SECOND * 55) 248 mETA->setText (mETAText[11]); 249 else if (newTime > VBOX_SECOND * 5) 250 mETA->setText (mETAText[12].arg (seconds)); 251 else if (newTime >= 0) 252 mETA->setText (mETAText[13]); 201 253 else 202 254 mETA->clear(); 255 203 256 /* Then operation text if changed */ 204 257 ulong newOp = mProgress.GetOperation() + 1; … … 211 264 } 212 265 mProgressBar->setValue (mProgress.GetPercent()); 213 } 266 }else 267 mETA->setText (mCancelText); 214 268 } 215 269 … … 217 271 { 218 272 if (mCancelEnabled) 219 QIDialog::reject();273 cancelOperation(); 220 274 } 221 275 … … 223 277 { 224 278 if (mCancelEnabled) 225 QIDialog::closeEvent (aEvent);279 cancelOperation(); 226 280 else 227 281 aEvent->ignore(); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSpecialControls.cpp
r24107 r24182 75 75 setFocusPolicy (Qt::TabFocus); 76 76 setShortcut (QKeySequence (Qt::Key_Escape)); 77 setIcon (VBoxGlobal::iconSet (":/delete_16px.png", 78 ":/delete_dis_16px.png")); 77 QIcon cancelIcon = style()->standardIcon (QStyle::SP_DialogCancelButton); 78 if (cancelIcon.isNull()) 79 cancelIcon = VBoxGlobal::iconSet (":/delete_16px.png", 80 ":/delete_dis_16px.png"); 81 setIcon (cancelIcon); 79 82 } 80 83 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaSpecialControls.mm
r24107 r24182 248 248 } 249 249 250 void VBoxCocoaButton::setText (const QString& aText) 251 { 252 QString s (aText); 253 /* Set it for accessibility reasons as alternative title */ 254 [mNativeRef setAlternateTitle: ::darwinQStringToNSString (s.remove ('&'))]; 255 } 256 250 257 void VBoxCocoaButton::setToolTip (const QString& aTip) 251 258 {
Note:
See TracChangeset
for help on using the changeset viewer.