Changeset 45160 in vbox
- Timestamp:
- Mar 25, 2013 10:57:34 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r44562 r45160 440 440 src/extensions/QIAdvancedToolBar.cpp \ 441 441 src/globals/UIActionPool.cpp \ 442 src/globals/UIMessageCenter.cpp \ 442 443 src/globals/UIExtraDataEventHandler.cpp \ 443 444 src/medium/UIMediumManager.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r44561 r45160 69 69 #include <iprt/param.h> 70 70 #include <iprt/path.h> 71 72 /* Object which contains stack(s) of guarded-pointer(s) 73 * to the current top-level modal-window(s) 74 * which could be used as the common-parent(s): */ 75 class UIModalWindowStackManager : public QObject 76 { 77 Q_OBJECT; 78 79 public: 80 81 /* Constructor: */ 82 UIModalWindowStackManager(QObject *pParent) : QObject(pParent) {} 83 84 /* API: Stack stuff: */ 85 QWidget* realParentWindow(QWidget *pPossibleParentWidget); 86 bool contains(QWidget *pParentWindow, bool fAsTheTopOfStack = false); 87 88 /* API: Register stuff: */ 89 void registerWidnowAboveTheParentWindow(QWidget *pWidget, QWidget *pParentWindow); 90 91 private slots: 92 93 /* Handler: Stack cleanup stuff: */ 94 void sltRemoveFromStack(QObject *pObject); 95 96 private: 97 98 /* Variables: */ 99 QList<QList<QWidget*> > m_windows; 100 }; 101 102 QWidget* UIModalWindowStackManager::realParentWindow(QWidget *pPossibleParentWidget) 103 { 104 /* Null if possible-parent-widget pointer is null: */ 105 if (!pPossibleParentWidget) 106 return 0; 107 108 /* Get the top-level window for the possible-parent-widget: */ 109 QWidget *pPossibleParentWindow = pPossibleParentWidget->window(); 110 111 /* Search through all the stack(s) we have: */ 112 foreach (const QList<QWidget*> &iteratedWindowStack, m_windows) 113 { 114 /* Search through all the window(s) iterated-stack contains: */ 115 foreach (QWidget *pIteratedWindow, iteratedWindowStack) 116 { 117 /* If possible-parent-window found: */ 118 if (pIteratedWindow == pPossibleParentWindow) 119 { 120 /* Return the 'top' of the iterated-window-stack as the result: */ 121 return iteratedWindowStack.last(); 122 } 123 } 124 } 125 126 /* If we unable to found the possible-parent-window among all ours, 127 * we have to add it as the new-window-stack only element: */ 128 QList<QWidget*> newWindowStack(QList<QWidget*>() << pPossibleParentWindow); 129 m_windows << newWindowStack; 130 /* And return as the result: */ 131 return pPossibleParentWindow; 132 } 133 134 bool UIModalWindowStackManager::contains(QWidget *pParentWindow, bool fAsTheTopOfStack /*= false*/) 135 { 136 /* False if passed-parent-widget pointer is null: */ 137 if (!pParentWindow) 138 { 139 AssertMsgFailed(("Passed pointer is NULL!")); 140 return false; 141 } 142 143 /* False if passed-parent-widget is not of 'top-level window' type: */ 144 if (!pParentWindow->isWindow()) 145 { 146 AssertMsgFailed(("Passed widget is NOT top-level window!")); 147 return false; 148 } 149 150 /* Search through all the stack(s) we have: */ 151 foreach (const QList<QWidget*> &iteratedWindowStack, m_windows) 152 { 153 /* Search through all the window(s) iterated-stack contains: */ 154 int iIteratedWindowStackSize = iteratedWindowStack.size(); 155 for (int iIteratedWidnowIndex = 0; iIteratedWidnowIndex < iIteratedWindowStackSize; ++iIteratedWidnowIndex) 156 { 157 /* Get iterated-window: */ 158 QWidget *pIteratedWindow = iteratedWindowStack[iIteratedWidnowIndex]; 159 /* If passed-parent-window found: */ 160 if (pIteratedWindow == pParentWindow) 161 { 162 /* True if we are not looking for 'top' of the stack or its the 'top': */ 163 return !fAsTheTopOfStack || iIteratedWidnowIndex == iIteratedWindowStackSize - 1; 164 } 165 } 166 } 167 168 /* False by default: */ 169 return false; 170 } 171 172 void UIModalWindowStackManager::registerWidnowAboveTheParentWindow(QWidget *pWindow, QWidget *pParentWindow) 173 { 174 /* Make sure passed-widget-pointer is not null: */ 175 if (!pWindow) 176 { 177 AssertMsgFailed(("Passed pointer is NULL!")); 178 return; 179 } 180 181 /* Make sure passed-widget is of 'top-level window' type: */ 182 if (!pWindow->isWindow()) 183 { 184 AssertMsgFailed(("Passed widget is NOT top-level window!")); 185 return; 186 } 187 188 /* Make sure passed-parent-widget is of 'top-level window' type: */ 189 if (pParentWindow && !pParentWindow->isWindow()) 190 { 191 AssertMsgFailed(("Passed parent widget is NOT top-level window!")); 192 return; 193 } 194 195 /* If parent-window really passed: */ 196 if (pParentWindow) 197 { 198 /* Make sure we have passed-parent-window registered already. 199 * If so, we have to make sure its the 'top' element in his stack also. 200 * If so, we have to register passed-window as the new 'top' in that stack. */ 201 for (int iIteratedStackIndex = 0; iIteratedStackIndex < m_windows.size(); ++iIteratedStackIndex) 202 { 203 /* Get current-stack: */ 204 QList<QWidget*> &iteratedWindowStack = m_windows[iIteratedStackIndex]; 205 /* Search through all the window(s) iterated-stack contains: */ 206 int iIteratedWindwStackSize = iteratedWindowStack.size(); 207 for (int iIteratedWindowIndex = 0; iIteratedWindowIndex < iIteratedWindwStackSize; ++iIteratedWindowIndex) 208 { 209 /* Get iterated-window: */ 210 QWidget *pIteratedWindow = iteratedWindowStack[iIteratedWindowIndex]; 211 /* If passed-parent-window found: */ 212 if (pIteratedWindow == pParentWindow) 213 { 214 /* Make sure it was the last one of the iterated-window(s): */ 215 if (iIteratedWindowIndex != iIteratedWindwStackSize - 1) 216 { 217 AssertMsgFailed(("Passed parent window is not on the top of his current-stack!")); 218 return; 219 } 220 /* Register passed-window as the new 'top' in iterated-window-stack: */ 221 iteratedWindowStack << pWindow; 222 connect(pWindow, SIGNAL(destroyed(QObject*)), this, SLOT(sltRemoveFromStack(QObject*))); 223 return; 224 } 225 } 226 } 227 } 228 /* If no parent-window passed: */ 229 else 230 { 231 /* Register passed-window as the only one item in new-window-stack: */ 232 QList<QWidget*> newWindowStack(QList<QWidget*>() << pWindow); 233 m_windows << newWindowStack; 234 connect(pWindow, SIGNAL(destroyed(QObject*)), this, SLOT(sltRemoveFromStack(QObject*))); 235 } 236 } 237 238 void UIModalWindowStackManager::sltRemoveFromStack(QObject *pObject) 239 { 240 /* Make sure passed-object still valid: */ 241 if (!pObject) 242 return; 243 244 /* Object is already of QObject type, 245 * because inheritance wrapper(s) destructor(s) already called 246 * so we can't search through the m_windows stack 247 * using the standard algorithm functionality. 248 * Lets do it manually: */ 249 for (int iIteratedStackIndex = 0; iIteratedStackIndex < m_windows.size(); ++iIteratedStackIndex) 250 { 251 /* Get iterated-stack: */ 252 QList<QWidget*> &iteratedWindowStack = m_windows[iIteratedStackIndex]; 253 /* Search through all the window(s) iterated-stack contains: */ 254 int iIteratedWindowStackSize = iteratedWindowStack.size(); 255 for (int iIteratedWindowIndex = 0; iIteratedWindowIndex < iIteratedWindowStackSize; ++iIteratedWindowIndex) 256 { 257 /* Get iterated-window: */ 258 QWidget *pIteratedWindow = iteratedWindowStack[iIteratedWindowIndex]; 259 /* If passed-object is almost-destroyed iterated-window: */ 260 if (pIteratedWindow == pObject) 261 { 262 /* Make sure it was the last added window: */ 263 AssertMsg(iIteratedWindowIndex == iIteratedWindowStackSize - 1, ("Removing element from the middle of the stack!")); 264 /* Cleanup window pointer: */ 265 iteratedWindowStack.removeAt(iIteratedWindowIndex); 266 /* And stack itself if necessary: */ 267 if (iteratedWindowStack.isEmpty()) 268 m_windows.removeAt(iIteratedStackIndex); 269 } 270 } 271 } 272 } 71 273 72 274 bool UIMessageCenter::isAnyWarningShown() … … 3005 3207 } 3006 3208 3209 bool UIMessageCenter::isInTheModalWindowStack(QWidget *pWindow) 3210 { 3211 return m_pModalWindowStackManager->contains(pWindow); 3212 } 3213 3214 bool UIMessageCenter::isOnTheTopOfTheModalWindowStack(QWidget *pWindow) 3215 { 3216 return m_pModalWindowStackManager->contains(pWindow, true); 3217 } 3218 3007 3219 // Public slots 3008 3220 ///////////////////////////////////////////////////////////////////////////// … … 3259 3471 3260 3472 UIMessageCenter::UIMessageCenter() 3473 : m_pModalWindowStackManager(0) 3261 3474 { 3262 3475 /* Register required objects as meta-types: */ … … 3309 3522 tr("The USB Proxy Service has not yet been ported to this host"); 3310 3523 tr("Could not load the Host USB Proxy service"); 3524 3525 /* Create modal-window-stack manager: */ 3526 m_pModalWindowStackManager = new UIModalWindowStackManager(this); 3311 3527 } 3312 3528 … … 3401 3617 } 3402 3618 3619 #include "UIMessageCenter.moc" 3620 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r44528 r45160 33 33 34 34 /* Forward declarations: */ 35 class UIModalWindowStackManager; 35 36 class UIMedium; 36 37 struct StorageSlot; … … 441 442 void remindAboutUnsupportedUSB2(const QString &strExtPackName, QWidget *pParent = 0); 442 443 444 bool isInTheModalWindowStack(QWidget *pWindow); 445 bool isOnTheTopOfTheModalWindowStack(QWidget *pWindow); 446 443 447 signals: 444 448 … … 504 508 QStringList m_strShownWarnings; 505 509 mutable QList<QPointer<QIMessageBox> > m_warnings; 510 mutable UIModalWindowStackManager *m_pModalWindowStackManager; 506 511 }; 507 512
Note:
See TracChangeset
for help on using the changeset viewer.