Changeset 89103 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- May 17, 2021 3:11:53 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/details
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsSet.cpp
r88805 r89103 142 142 else 143 143 emit sigBuildDone(); 144 }145 146 void UIDetailsSet::sltBuildStep(const QUuid &uStepId, int iStepNumber)147 {148 /* Cleanup build-step: */149 delete m_pBuildStep;150 m_pBuildStep = 0;151 152 /* Is step id valid? */153 if (uStepId != m_uSetId)154 return;155 156 /* Step number feats the bounds: */157 if (iStepNumber >= 0 && iStepNumber < m_types.size())158 {159 /* Load details settings: */160 const DetailsElementType enmElementType = m_types.at(iStepNumber);161 /* Should the element be visible? */162 bool fVisible = m_settings.contains(enmElementType);163 /* Should the element be opened? */164 bool fOpen = fVisible && m_settings[enmElementType];165 166 /* Check if element is present already: */167 UIDetailsElement *pElement = element(enmElementType);168 if (pElement && fOpen)169 pElement->open(false);170 /* Create element if necessary: */171 bool fJustCreated = false;172 if (!pElement)173 {174 fJustCreated = true;175 pElement = createElement(enmElementType, fOpen);176 }177 178 /* Show element if necessary: */179 if (fVisible && !pElement->isVisible())180 {181 /* Show the element: */182 pElement->show();183 /* Recursively update size-hint: */184 pElement->updateGeometry();185 /* Update layout: */186 model()->updateLayout();187 }188 /* Hide element if necessary: */189 else if (!fVisible && pElement->isVisible())190 {191 /* Hide the element: */192 pElement->hide();193 /* Recursively update size-hint: */194 updateGeometry();195 /* Update layout: */196 model()->updateLayout();197 }198 /* Update model if necessary: */199 else if (fJustCreated)200 model()->updateLayout();201 202 /* For visible element: */203 if (pElement->isVisible())204 {205 /* Create next build-step: */206 m_pBuildStep = new UIPrepareStep(this, pElement, uStepId, iStepNumber + 1);207 208 /* Build element: */209 pElement->updateAppearance();210 }211 /* For invisible element: */212 else213 {214 /* Just build next step: */215 sltBuildStep(uStepId, iStepNumber + 1);216 }217 }218 /* Step number out of bounds: */219 else220 {221 /* Update model: */222 model()->updateLayout();223 /* Repaint all the items: */224 foreach (UIDetailsItem *pItem, items())225 pItem->update();226 /* Notify listener about build done: */227 emit sigBuildDone();228 }229 }230 231 void UIDetailsSet::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *)232 {233 /* Paint background: */234 paintBackground(pPainter, pOptions);235 }236 237 QString UIDetailsSet::description() const238 {239 return tr("Contains the details of virtual machine '%1'").arg(m_pMachineItem->name());240 }241 242 void UIDetailsSet::addItem(UIDetailsItem *pItem)243 {244 switch (pItem->type())245 {246 case UIDetailsItemType_Element:247 {248 UIDetailsElement *pElement = pItem->toElement();249 DetailsElementType type = pElement->elementType();250 AssertMsg(!m_elements.contains(type), ("Element already added!"));251 m_elements.insert(type, pItem);252 break;253 }254 default:255 {256 AssertMsgFailed(("Invalid item type!"));257 break;258 }259 }260 }261 262 void UIDetailsSet::removeItem(UIDetailsItem *pItem)263 {264 switch (pItem->type())265 {266 case UIDetailsItemType_Element:267 {268 UIDetailsElement *pElement = pItem->toElement();269 DetailsElementType type = pElement->elementType();270 AssertMsg(m_elements.contains(type), ("Element do not present (type = %d)!", (int)type));271 m_elements.remove(type);272 break;273 }274 default:275 {276 AssertMsgFailed(("Invalid item type!"));277 break;278 }279 }280 }281 282 QList<UIDetailsItem*> UIDetailsSet::items(UIDetailsItemType enmType /* = UIDetailsItemType_Element */) const283 {284 switch (enmType)285 {286 case UIDetailsItemType_Element: return m_elements.values();287 case UIDetailsItemType_Any: return items(UIDetailsItemType_Element);288 default: AssertMsgFailed(("Invalid item type!")); break;289 }290 return QList<UIDetailsItem*>();291 }292 293 bool UIDetailsSet::hasItems(UIDetailsItemType enmType /* = UIDetailsItemType_Element */) const294 {295 switch (enmType)296 {297 case UIDetailsItemType_Element: return !m_elements.isEmpty();298 case UIDetailsItemType_Any: return hasItems(UIDetailsItemType_Element);299 default: AssertMsgFailed(("Invalid item type!")); break;300 }301 return false;302 }303 304 void UIDetailsSet::clearItems(UIDetailsItemType enmType /* = UIDetailsItemType_Element */)305 {306 switch (enmType)307 {308 case UIDetailsItemType_Element:309 {310 foreach (int iKey, m_elements.keys())311 delete m_elements[iKey];312 AssertMsg(m_elements.isEmpty(), ("Set items cleanup failed!"));313 break;314 }315 case UIDetailsItemType_Any:316 {317 clearItems(UIDetailsItemType_Element);318 break;319 }320 default:321 {322 AssertMsgFailed(("Invalid item type!"));323 break;324 }325 }326 }327 328 UIDetailsElement *UIDetailsSet::element(DetailsElementType enmElementType) const329 {330 UIDetailsItem *pItem = m_elements.value(enmElementType, 0);331 if (pItem)332 return pItem->toElement();333 return 0;334 144 } 335 145 … … 429 239 } 430 240 } 241 } 242 243 void UIDetailsSet::sltBuildStep(const QUuid &uStepId, int iStepNumber) 244 { 245 /* Cleanup build-step: */ 246 delete m_pBuildStep; 247 m_pBuildStep = 0; 248 249 /* Is step id valid? */ 250 if (uStepId != m_uSetId) 251 return; 252 253 /* Step number feats the bounds: */ 254 if (iStepNumber >= 0 && iStepNumber < m_types.size()) 255 { 256 /* Load details settings: */ 257 const DetailsElementType enmElementType = m_types.at(iStepNumber); 258 /* Should the element be visible? */ 259 bool fVisible = m_settings.contains(enmElementType); 260 /* Should the element be opened? */ 261 bool fOpen = fVisible && m_settings[enmElementType]; 262 263 /* Check if element is present already: */ 264 UIDetailsElement *pElement = element(enmElementType); 265 if (pElement && fOpen) 266 pElement->open(false); 267 /* Create element if necessary: */ 268 bool fJustCreated = false; 269 if (!pElement) 270 { 271 fJustCreated = true; 272 pElement = createElement(enmElementType, fOpen); 273 } 274 275 /* Show element if necessary: */ 276 if (fVisible && !pElement->isVisible()) 277 { 278 /* Show the element: */ 279 pElement->show(); 280 /* Recursively update size-hint: */ 281 pElement->updateGeometry(); 282 /* Update layout: */ 283 model()->updateLayout(); 284 } 285 /* Hide element if necessary: */ 286 else if (!fVisible && pElement->isVisible()) 287 { 288 /* Hide the element: */ 289 pElement->hide(); 290 /* Recursively update size-hint: */ 291 updateGeometry(); 292 /* Update layout: */ 293 model()->updateLayout(); 294 } 295 /* Update model if necessary: */ 296 else if (fJustCreated) 297 model()->updateLayout(); 298 299 /* For visible element: */ 300 if (pElement->isVisible()) 301 { 302 /* Create next build-step: */ 303 m_pBuildStep = new UIPrepareStep(this, pElement, uStepId, iStepNumber + 1); 304 305 /* Build element: */ 306 pElement->updateAppearance(); 307 } 308 /* For invisible element: */ 309 else 310 { 311 /* Just build next step: */ 312 sltBuildStep(uStepId, iStepNumber + 1); 313 } 314 } 315 /* Step number out of bounds: */ 316 else 317 { 318 /* Update model: */ 319 model()->updateLayout(); 320 /* Repaint all the items: */ 321 foreach (UIDetailsItem *pItem, items()) 322 pItem->update(); 323 /* Notify listener about build done: */ 324 emit sigBuildDone(); 325 } 326 } 327 328 void UIDetailsSet::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *) 329 { 330 /* Paint background: */ 331 paintBackground(pPainter, pOptions); 332 } 333 334 QString UIDetailsSet::description() const 335 { 336 return tr("Contains the details of virtual machine '%1'").arg(m_pMachineItem->name()); 337 } 338 339 void UIDetailsSet::addItem(UIDetailsItem *pItem) 340 { 341 switch (pItem->type()) 342 { 343 case UIDetailsItemType_Element: 344 { 345 UIDetailsElement *pElement = pItem->toElement(); 346 DetailsElementType type = pElement->elementType(); 347 AssertMsg(!m_elements.contains(type), ("Element already added!")); 348 m_elements.insert(type, pItem); 349 break; 350 } 351 default: 352 { 353 AssertMsgFailed(("Invalid item type!")); 354 break; 355 } 356 } 357 } 358 359 void UIDetailsSet::removeItem(UIDetailsItem *pItem) 360 { 361 switch (pItem->type()) 362 { 363 case UIDetailsItemType_Element: 364 { 365 UIDetailsElement *pElement = pItem->toElement(); 366 DetailsElementType type = pElement->elementType(); 367 AssertMsg(m_elements.contains(type), ("Element do not present (type = %d)!", (int)type)); 368 m_elements.remove(type); 369 break; 370 } 371 default: 372 { 373 AssertMsgFailed(("Invalid item type!")); 374 break; 375 } 376 } 377 } 378 379 QList<UIDetailsItem*> UIDetailsSet::items(UIDetailsItemType enmType /* = UIDetailsItemType_Element */) const 380 { 381 switch (enmType) 382 { 383 case UIDetailsItemType_Element: return m_elements.values(); 384 case UIDetailsItemType_Any: return items(UIDetailsItemType_Element); 385 default: AssertMsgFailed(("Invalid item type!")); break; 386 } 387 return QList<UIDetailsItem*>(); 388 } 389 390 bool UIDetailsSet::hasItems(UIDetailsItemType enmType /* = UIDetailsItemType_Element */) const 391 { 392 switch (enmType) 393 { 394 case UIDetailsItemType_Element: return !m_elements.isEmpty(); 395 case UIDetailsItemType_Any: return hasItems(UIDetailsItemType_Element); 396 default: AssertMsgFailed(("Invalid item type!")); break; 397 } 398 return false; 399 } 400 401 void UIDetailsSet::clearItems(UIDetailsItemType enmType /* = UIDetailsItemType_Element */) 402 { 403 switch (enmType) 404 { 405 case UIDetailsItemType_Element: 406 { 407 foreach (int iKey, m_elements.keys()) 408 delete m_elements[iKey]; 409 AssertMsg(m_elements.isEmpty(), ("Set items cleanup failed!")); 410 break; 411 } 412 case UIDetailsItemType_Any: 413 { 414 clearItems(UIDetailsItemType_Element); 415 break; 416 } 417 default: 418 { 419 AssertMsgFailed(("Invalid item type!")); 420 break; 421 } 422 } 423 } 424 425 UIDetailsElement *UIDetailsSet::element(DetailsElementType enmElementType) const 426 { 427 UIDetailsItem *pItem = m_elements.value(enmElementType, 0); 428 if (pItem) 429 return pItem->toElement(); 430 return 0; 431 431 } 432 432 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsSet.h
r84623 r89103 75 75 /** @} */ 76 76 77 /** @name Layout stuff. 78 * @{ */ 79 /** Updates layout. */ 80 virtual void updateLayout() /* override */; 81 /** @} */ 82 77 83 protected slots: 78 84 … … 122 128 /** @name Layout stuff. 123 129 * @{ */ 124 /** Updates layout. */125 virtual void updateLayout() /* override */;126 127 130 /** Returns minimum width-hint. */ 128 131 virtual int minimumWidthHint() const /* override */;
Note:
See TracChangeset
for help on using the changeset viewer.