Changeset 43819 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 7, 2012 7:20:34 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 81884
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp
r43810 r43819 48 48 49 49 /* Add item to the scene: */ 50 if (pScene)51 50 AssertMsg(pScene, ("Incorrect scene passed!")); 51 pScene->addItem(this); 52 52 53 53 /* Translate finally: */ … … 70 70 71 71 /* Add item to the scene: */ 72 if (pScene)73 72 AssertMsg(pScene, ("Incorrect scene passed!")); 73 pScene->addItem(this); 74 74 75 75 /* Copy content to 'this': */ … … 177 177 return "/"; 178 178 /* Get full parent name, append with '/' if not yet appended: */ 179 QString str ParentFullName = parentItem()->fullName();180 if (!str ParentFullName.endsWith('/'))181 str ParentFullName.append('/');179 QString strFullParentName = parentItem()->fullName(); 180 if (!strFullParentName.endsWith('/')) 181 strFullParentName.append('/'); 182 182 /* Return full item name based on parent prefix: */ 183 return str ParentFullName + name();183 return strFullParentName + name(); 184 184 } 185 185 … … 191 191 void UIGChooserItemGroup::setName(const QString &strName) 192 192 { 193 /* Something changed? */ 194 if (m_strName == strName) 195 return; 196 197 /* Remember new name: */ 193 198 m_strName = strName; 199 200 /* Update visible name: */ 201 recacheVisibleName(); 202 /* Update minimum header size: */ 203 recacheHeaderSize(); 194 204 } 195 205 … … 207 217 { 208 218 AssertMsg(parentItem(), ("Can't close root-item!")); 209 m_pToggleButton->setToggled(false ,fAnimated);219 m_pToggleButton->setToggled(false, fAnimated); 210 220 } 211 221 … … 216 226 } 217 227 218 bool UIGChooserItemGroup:: contains(const QString &strId) const219 { 220 /* Check machine items: */228 bool UIGChooserItemGroup::isContainsMachine(const QString &strId) const 229 { 230 /* Check each machine-item: */ 221 231 foreach (UIGChooserItem *pItem, m_machineItems) 222 232 if (pItem->toMachineItem()->id() == strId) … … 227 237 bool UIGChooserItemGroup::isContainsLockedMachine() 228 238 { 229 /* Foreach machine-item: */239 /* Check each machine-item: */ 230 240 foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Machine)) 231 241 if (pItem->toMachineItem()->isLockedMachine()) 232 242 return true; 233 /* Foreach group-item: */243 /* Check each group-item: */ 234 244 foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Group)) 235 245 if (pItem->toGroupItem()->isContainsLockedMachine()) … … 240 250 void UIGChooserItemGroup::sltHandleGeometryChange() 241 251 { 242 /* Wh ich isnew geometry? */252 /* What is the new geometry? */ 243 253 QRectF newGeometry = geometry(); 244 254 … … 247 257 recacheVisibleName(); 248 258 249 /* Remember new geometry: */259 /* Remember the new geometry: */ 250 260 m_previousGeometry = newGeometry; 251 261 } … … 264 274 foreach (UIGChooserItem *pItem, parentItem()->items(UIGChooserItemType_Group)) 265 275 groupNames << pItem->name(); 266 267 276 /* If proposed name is empty or not unique, reject it: */ 268 277 QString strNewName = m_pNameEditorWidget->text().trimmed(); … … 274 283 strNewName.replace(QRegExp("[\\\\/:*?\"<>]"), "_"); 275 284 276 /* Set new name / update model: */ 277 m_strName = strNewName; 278 recacheVisibleName(); 279 recacheHeaderSize(); 285 /* Set new name, save settings: */ 286 setName(strNewName); 280 287 model()->saveGroupSettings(); 281 288 } … … 298 305 { 299 306 /* Toggle-state and navigation will be 300 * updated on toggle 307 * updated on toggle-finish signal! */ 301 308 } 302 309 /* Group opened, we are closing it: */ … … 334 341 void UIGChooserItemGroup::sltIndentRoot() 335 342 { 343 /* Unhover before indenting: */ 336 344 setHovered(false); 345 346 /* Indent to this root: */ 337 347 model()->indentRoot(this); 338 348 } … … 340 350 void UIGChooserItemGroup::sltUnindentRoot() 341 351 { 352 /* Unhover before unindenting: */ 342 353 setHovered(false); 354 355 /* Unindent to previous root: */ 343 356 model()->unindentRoot(); 344 357 } … … 396 409 m_machinesPixmap = QPixmap(":/machine_16px.png"); 397 410 398 /* Geometry 411 /* Geometry-change handler: */ 399 412 connect(this, SIGNAL(geometryChanged()), this, SLOT(sltHandleGeometryChange())); 400 413 401 /* Non root item only: */414 /* Items except roots: */ 402 415 if (!isRoot()) 403 416 { … … 414 427 415 428 /* Setup name-editor: */ 416 m_pNameEditorWidget = new UIGroupRenameEditor( m_strName, this);429 m_pNameEditorWidget = new UIGroupRenameEditor(name(), this); 417 430 m_pNameEditorWidget->setFont(m_nameFont); 418 431 connect(m_pNameEditorWidget, SIGNAL(sigEditingFinished()), this, SLOT(sltNameEditingFinished())); … … 421 434 m_pNameEditor->hide(); 422 435 } 423 /* Root item but non main: */436 /* Items except main root: */ 424 437 if (!isMainRoot()) 425 438 { … … 437 450 void UIGChooserItemGroup::copyContent(UIGChooserItemGroup *pFrom, UIGChooserItemGroup *pTo) 438 451 { 439 /* Copy group 452 /* Copy group-items: */ 440 453 foreach (UIGChooserItem *pGroupItem, pFrom->items(UIGChooserItemType_Group)) 441 454 new UIGChooserItemGroup(pTo, pGroupItem->toGroupItem()); 442 /* Copy machine 455 /* Copy machine-items: */ 443 456 foreach (UIGChooserItem *pMachineItem, pFrom->items(UIGChooserItemType_Machine)) 444 457 new UIGChooserItemMachine(pTo, pMachineItem->toMachineItem()); … … 449 462 /* Update visible name: */ 450 463 recacheVisibleName(); 451 452 464 /* Update minimum header size: */ 453 465 recacheHeaderSize(); … … 456 468 void UIGChooserItemGroup::recacheVisibleName() 457 469 { 470 /* Not for main root: */ 471 if (isMainRoot()) 472 return; 473 458 474 /* Prepare variables: */ 459 475 int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt(); … … 468 484 int iMaximumWidth = geometry().width(); 469 485 470 /* Calculate name width: */ 471 iMaximumWidth -= 2 * iHorizontalMargin; 486 /* Left margin: */ 487 iMaximumWidth -= iHorizontalMargin; 488 /* Button width: */ 472 489 if (isRoot()) 473 { 474 iMaximumWidth -= (iExitButtonWidth + iMajorSpacing); 475 } 490 iMaximumWidth -= iExitButtonWidth; 476 491 else 477 { 478 iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing); 479 if (isHovered()) 480 iMaximumWidth -= iEnterButtonWidth; 481 } 492 iMaximumWidth -= iToggleButtonWidth; 493 /* Spacing between button and name: */ 494 iMaximumWidth -= iMajorSpacing; 482 495 if (isHovered()) 483 496 { 497 /* Spacing between name and info: */ 484 498 iMaximumWidth -= iMajorSpacing; 485 if (iGroupCountTextWidth != 0) 499 /* Group info width: */ 500 if (!m_groupItems.isEmpty()) 486 501 iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth); 487 if (iMachineCountTextWidth != 0) 502 /* Machine info width: */ 503 if (!m_machineItems.isEmpty()) 488 504 iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth); 489 505 } 490 491 /* Recache name: */ 492 m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth); 506 /* Button width: */ 507 if (!isRoot() && isHovered()) 508 iMaximumWidth -= iEnterButtonWidth; 509 /* Right margin: */ 510 iMaximumWidth -= iHorizontalMargin; 511 512 /* Recache visible name: */ 513 m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), name(), iMaximumWidth); 514 515 /* Repaint item: */ 493 516 update(); 494 517 } … … 514 537 QFontMetrics fm(m_nameFont, pPaintDevice); 515 538 int iMaximumNameWidth = textWidth(m_nameFont, pPaintDevice, 20); 516 QString strCompressedName = compressText(m_nameFont, pPaintDevice, m_strName, iMaximumNameWidth);539 QString strCompressedName = compressText(m_nameFont, pPaintDevice, name(), iMaximumNameWidth); 517 540 int iMinimumNameWidth = fm.width(strCompressedName); 518 541 int iMinimumNameHeight = fm.height(); … … 533 556 /* Group info width: */ 534 557 if (!m_groupItems.isEmpty()) 535 iHeaderWidth += groupPixmapSize.width() + 536 groupCountTextSize.width(); 558 iHeaderWidth += (groupPixmapSize.width() + groupCountTextSize.width()); 537 559 /* Machine info width: */ 538 560 if (!m_machineItems.isEmpty()) 539 iHeaderWidth += machinePixmapSize.width() + 540 machineCountTextSize.width(); 561 iHeaderWidth += (machinePixmapSize.width() + machineCountTextSize.width()); 541 562 /* Button width: */ 542 563 if (!isRoot()) … … 552 573 heights /* Minimum name height: */ 553 574 << iMinimumNameHeight 554 /* Group info height : */575 /* Group info heights: */ 555 576 << groupPixmapSize.height() << groupCountTextSize.height() 556 /* Machine info height : */577 /* Machine info heights: */ 557 578 << machinePixmapSize.height() << machineCountTextSize.height(); 558 579 /* Button height: */ … … 611 632 /* Unlock name-editor: */ 612 633 m_pNameEditor->show(); 613 m_pNameEditorWidget->setText( m_strName);634 m_pNameEditorWidget->setText(name()); 614 635 m_pNameEditorWidget->setFocus(); 615 636 } … … 1169 1190 { 1170 1191 /* Make sure passed item is ours or there is no other item with such id: */ 1171 return m_machineItems.contains(pItem) || ! contains(pItem->toMachineItem()->id());1192 return m_machineItems.contains(pItem) || !isContainsMachine(pItem->toMachineItem()->id()); 1172 1193 } 1173 1194 case Qt::CopyAction: 1174 1195 { 1175 1196 /* Make sure there is no other item with such id: */ 1176 return ! contains(pItem->toMachineItem()->id());1197 return !isContainsMachine(pItem->toMachineItem()->id()); 1177 1198 } 1178 1199 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h
r43810 r43819 79 79 80 80 /* API: Children stuff: */ 81 bool contains(const QString &strId) const;81 bool isContainsMachine(const QString &strId) const; 82 82 bool isContainsLockedMachine(); 83 83
Note:
See TracChangeset
for help on using the changeset viewer.