Changeset 67262 in vbox
- Timestamp:
- Jun 5, 2017 4:37:11 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 115957
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r67261 r67262 58 58 59 59 60 /** Snapshot tree column tags. */ 61 enum 62 { 63 Column_Name, 64 Column_Taken, 65 Column_Max, 66 }; 67 68 60 69 /** QITreeWidgetItem subclass for snapshots items. */ 61 70 class UISnapshotItem : public QITreeWidgetItem, public UIDataSnapshot … … 87 96 QString snapshotID() const { return m_strSnapshotID; } 88 97 89 /** Returns item data for corresponding @a iColumn and @a iRole. */90 QVariant data(int iColumn, int iRole) const;91 92 /** Returns item text for corresponding @a iColumn. */93 QString text(int iColumn) const;94 95 98 /** Returns whether this is the "current state" item. */ 96 99 bool isCurrentStateItem() const { return m_fCurrentStateItem; } … … 116 119 117 120 protected: 118 119 /** Adjusts item text. */120 void adjustText();121 121 122 122 /** Recaches item tool-tip. */ … … 220 220 /* Set the bold font state 221 221 * for current state item: */ 222 QFont myFont = font( 0);222 QFont myFont = font(Column_Name); 223 223 myFont.setBold(true); 224 setFont( 0, myFont);224 setFont(Column_Name, myFont); 225 225 226 226 /* Fetch current machine state: */ … … 237 237 /* Set the bold font state 238 238 * for current state item: */ 239 QFont myFont = font( 0);239 QFont myFont = font(Column_Name); 240 240 myFont.setBold(true); 241 setFont( 0, myFont);241 setFont(Column_Name, myFont); 242 242 243 243 /* Fetch current machine state: */ 244 244 setMachineState(m_comMachine.GetState()); 245 }246 247 QVariant UISnapshotItem::data(int iColumn, int iRole) const248 {249 switch (iRole)250 {251 case Qt::DisplayRole:252 {253 /* Call to base-class for "current state" item, compose ourselves otherwise: */254 return m_fCurrentStateItem ? QTreeWidgetItem::data(iColumn, iRole)255 : QString("%1%2")256 .arg(QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString())257 .arg(QTreeWidgetItem::data(iColumn, Qt::UserRole).toString());258 }259 case Qt::SizeHintRole:260 {261 /* Determine the icon metric: */262 const QStyle *pStyle = QApplication::style();263 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);264 /* Determine the minimum size-hint for this tree-widget-item: */265 const QSize baseSizeHint = QTreeWidgetItem::data(iColumn, iRole).toSize();266 /* Determine the effective height-hint for this tree-widget-item: */267 const int iEffectiveHeightHint = qMax(baseSizeHint.height(),268 iIconMetric + 2 * 2 /* margins */);269 /* Return size-hint for this tree-widget-item: */270 return QSize(baseSizeHint.width(), iEffectiveHeightHint);271 }272 default:273 break;274 }275 276 /* Call to base-class: */277 return QTreeWidgetItem::data(iColumn, iRole);278 }279 280 QString UISnapshotItem::text(int iColumn) const281 {282 return QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString();283 245 } 284 246 … … 302 264 /* Set/clear the bold font state 303 265 * for current snapshot item: */ 304 QFont myFont = font( 0);266 QFont myFont = font(Column_Name); 305 267 myFont.setBold(fCurrent); 306 setFont( 0, myFont);268 setFont(Column_Name, myFont); 307 269 308 270 /* Update tool-tip: */ … … 321 283 ? UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") 322 284 : UISnapshotPane::tr("Current State", "Current State (Unmodified)"); 323 setText( 0, m_strName);285 setText(Column_Name, m_strName); 324 286 m_strDescription = m_fCurrentStateModified 325 287 ? UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") … … 335 297 m_strSnapshotID = m_comSnapshot.GetId(); 336 298 m_strName = m_comSnapshot.GetName(); 337 setText( 0, m_strName);299 setText(Column_Name, m_strName); 338 300 m_fOnline = m_comSnapshot.GetOnline(); 339 setIcon( 0, *m_pSnapshotWidget->snapshotItemIcon(m_fOnline));301 setIcon(Column_Name, *m_pSnapshotWidget->snapshotItemIcon(m_fOnline)); 340 302 m_strDescription = m_comSnapshot.GetDescription(); 341 303 m_timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000); … … 343 305 } 344 306 345 /* Adjust text: */346 adjustText();347 307 /* Update tool-tip: */ 348 308 recacheToolTip(); … … 368 328 m_enmMachineState = enmState; 369 329 /* Set corresponding icon: */ 370 setIcon( 0, gpConverter->toIcon(m_enmMachineState));330 setIcon(Column_Name, gpConverter->toIcon(m_enmMachineState)); 371 331 /* Update timestamp: */ 372 332 m_timestamp.setTime_t(m_comMachine.GetLastStateChange() / 1000); … … 386 346 if (then.daysTo(now) > 30) 387 347 { 388 strAge = UISnapshotPane::tr(" (%1)").arg(then.toString(Qt::LocalDate));348 strAge = then.toString(Qt::LocalDate); 389 349 enmAgeFormat = SnapshotAgeFormat_Max; 390 350 } 391 351 else if (then.secsTo(now) > 60 * 60 * 24) 392 352 { 393 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24)); 353 strAge = UISnapshotPane::tr("%1 (%2 ago)", "date time (how long ago)") 354 .arg(then.toString(Qt::LocalDate), VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24)); 394 355 enmAgeFormat = SnapshotAgeFormat_InDays; 395 356 } 396 357 else if (then.secsTo(now) > 60 * 60) 397 358 { 398 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60)); 359 strAge = UISnapshotPane::tr("%1 (%2 ago)", "date time (how long ago)") 360 .arg(then.toString(Qt::LocalDate), VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60)); 399 361 enmAgeFormat = SnapshotAgeFormat_InHours; 400 362 } 401 363 else if (then.secsTo(now) > 60) 402 364 { 403 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo(now) / 60)); 365 strAge = UISnapshotPane::tr("%1 (%2 ago)", "date time (how long ago)") 366 .arg(then.toString(Qt::LocalDate), VBoxGlobal::minutesToString(then.secsTo(now) / 60)); 404 367 enmAgeFormat = SnapshotAgeFormat_InMinutes; 405 368 } 406 369 else 407 370 { 408 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo(now))); 371 strAge = UISnapshotPane::tr("%1 (%2 ago)", "date time (how long ago)") 372 .arg(then.toString(Qt::LocalDate), VBoxGlobal::secondsToString(then.secsTo(now))); 409 373 enmAgeFormat = SnapshotAgeFormat_InSeconds; 410 374 } 411 375 412 376 /* Update data: */ 413 setData(0, Qt::UserRole, strAge); 377 if (!m_fCurrentStateItem) 378 setText(Column_Taken, strAge); 414 379 415 380 /* Return age: */ 416 381 return enmAgeFormat; 417 }418 419 void UISnapshotItem::adjustText()420 {421 /* Make sure item is initialised: */422 if (!treeWidget())423 return;424 425 /* Calculate metrics: */426 QFontMetrics metrics(font(0));427 int iHei0 = (metrics.height() > 16 ?428 metrics.height() /* text */ : 16 /* icon */) +429 2 * 2 /* 2 pixel per margin */;430 int iWid0 = metrics.width(text(0)) /* text */ +431 treeWidget()->indentation() /* indent */ +432 16 /* icon */;433 434 /* Adjust size finally: */435 setSizeHint(0, QSize(iWid0, iHei0));436 382 } 437 383 … … 458 404 else 459 405 { 406 /* Gather details: */ 407 QStringList details; 460 408 if (isCurrentSnapshotItem()) 461 strDetails = UISnapshotPane::tr(" (current, ", "Snapshot details"); 462 else 463 strDetails = " ("; 464 465 /* Add online/offline information: */ 466 strDetails += m_fOnline ? UISnapshotPane::tr("online)", "Snapshot details") 467 : UISnapshotPane::tr("offline)", "Snapshot details"); 409 details << UISnapshotPane::tr("current", "snapshot"); 410 details << (m_fOnline ? UISnapshotPane::tr("online", "snapshot") 411 : UISnapshotPane::tr("offline", "snapshot")); 412 strDetails = QString(" (%1)").arg(details.join(", ")); 468 413 469 414 /* Add date/time information: */ … … 476 421 /* Prepare tool-tip: */ 477 422 QString strToolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>") 478 .arg(text( 0)).arg(strDetails).arg(strDateTime);423 .arg(text(Column_Name)).arg(strDetails).arg(strDateTime); 479 424 480 425 /* Append description if any: */ … … 483 428 484 429 /* Assign tool-tip finally: */ 485 setToolTip( 0, strToolTip);430 setToolTip(Column_Name, strToolTip); 486 431 } 487 432 … … 494 439 : QITreeWidget(pParent) 495 440 { 496 /* No header: */ 497 header()->hide(); 498 /* All columns as one: */ 441 /* Configure snapshot tree: */ 442 setColumnCount(Column_Max); 499 443 setAllColumnsShowFocus(true); 500 /* Our own context menu: */ 444 setAlternatingRowColors(true); 445 setExpandsOnDoubleClick(false); 501 446 setContextMenuPolicy(Qt::CustomContextMenu); 447 setEditTriggers( QAbstractItemView::SelectedClicked 448 | QAbstractItemView::EditKeyPressed); 502 449 } 503 450 … … 607 554 m_pToolBar->updateLayout(); 608 555 #endif 556 557 /* Translate snapshot tree: */ 558 const QStringList fields = QStringList() 559 << tr("Name", "snapshot") 560 << tr("Taken", "snapshot"); 561 m_pSnapshotTree->setHeaderLabels(fields); 562 } 563 564 void UISnapshotPane::resizeEvent(QResizeEvent *pEvent) 565 { 566 /* Call to base-class: */ 567 QIWithRetranslateUI<QWidget>::resizeEvent(pEvent); 568 569 /* Adjust snapshot tree: */ 570 adjustTreeWidget(); 571 } 572 573 void UISnapshotPane::showEvent(QShowEvent *pEvent) 574 { 575 /* Call to base-class: */ 576 QIWithRetranslateUI<QWidget>::showEvent(pEvent); 577 578 /* Adjust snapshot tree: */ 579 adjustTreeWidget(); 609 580 } 610 581 … … 734 705 /* Allows editing again: */ 735 706 m_pLockReadWrite->unlock(); 707 708 /* Adjust snapshot tree: */ 709 adjustTreeWidget(); 736 710 } 737 711 … … 861 835 { 862 836 /* Rename corresponding snapshot if necessary: */ 863 if (comSnapshot.GetName() != pSnapshotItem->text( 0))837 if (comSnapshot.GetName() != pSnapshotItem->text(Column_Name)) 864 838 { 865 839 /* We need to open a session when we manipulate the snapshot data of a machine: */ … … 870 844 871 845 /* Save snapshot name: */ 872 comSnapshot.SetName(pSnapshotItem->text( 0));846 comSnapshot.SetName(pSnapshotItem->text(Column_Name)); 873 847 874 848 /* Close the session again: */ … … 881 855 /* Allows editing again: */ 882 856 m_pLockReadWrite->unlock(); 857 858 /* Adjust snapshot tree: */ 859 adjustTreeWidget(); 883 860 } 884 861 … … 896 873 { 897 874 /* As snapshot-restore procedure: */ 898 restoreSnapshot(true /* suppress non-critical warnings */); 875 if (pSnapshotItem->snapshot().isNotNull()) 876 restoreSnapshot(true /* suppress non-critical warnings */); 899 877 } 900 878 /* Handle other kinds of DoubleClick: */ … … 956 934 /* Prepare toolbar: */ 957 935 prepareToolbar(); 958 /* Prepare tree-widget: */936 /* Prepare snapshot tree: */ 959 937 prepareTreeWidget(); 960 938 /* Prepare details-widget: */ … … 1055 1033 { 1056 1034 /* Configure tree: */ 1057 m_pSnapshotTree->setExpandsOnDoubleClick(false);1058 m_pSnapshotTree->setEditTriggers( QAbstractItemView::SelectedClicked1059 | QAbstractItemView::EditKeyPressed);1060 1035 connect(m_pSnapshotTree, &UISnapshotTree::currentItemChanged, 1061 1036 this, &UISnapshotPane::sltHandleCurrentItemChange); … … 1159 1134 1160 1135 /* Adjust snapshot tree: */ 1161 m_pSnapshotTree->resizeColumnToContents(0);1136 adjustTreeWidget(); 1162 1137 } 1163 1138 … … 1247 1222 while (*iterator) 1248 1223 { 1249 QString strSnapshot = static_cast<UISnapshotItem*>(*iterator)->text( 0);1224 QString strSnapshot = static_cast<UISnapshotItem*>(*iterator)->text(Column_Name); 1250 1225 int iPos = regExp.indexIn(strSnapshot); 1251 1226 if (iPos != -1) … … 1298 1273 } 1299 1274 while (0); 1275 1276 /* Adjust snapshot tree: */ 1277 adjustTreeWidget(); 1300 1278 1301 1279 /* Return result: */ … … 1373 1351 while (0); 1374 1352 1353 /* Adjust snapshot tree: */ 1354 adjustTreeWidget(); 1355 1375 1356 /* Return result: */ 1376 1357 return fSuccess; … … 1448 1429 while (0); 1449 1430 1431 /* Adjust snapshot tree: */ 1432 adjustTreeWidget(); 1433 1450 1434 /* Return result: */ 1451 1435 return fSuccess; … … 1479 1463 } 1480 1464 1465 void UISnapshotPane::adjustTreeWidget() 1466 { 1467 /* Get the snapshot tree abstract interface: */ 1468 QAbstractItemView *pItemView = m_pSnapshotTree; 1469 /* Get the snapshot tree header-view: */ 1470 QHeaderView *pItemHeader = m_pSnapshotTree->header(); 1471 1472 /* Calculate the total snapshot tree width: */ 1473 const int iTotal = m_pSnapshotTree->viewport()->width(); 1474 /* Look for a minimum width hints for non-important columns: */ 1475 const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(Column_Taken), pItemHeader->sectionSizeHint(Column_Taken)); 1476 /* Propose suitable width hints for non-important columns: */ 1477 const int iWidth1 = iMinWidth1 < iTotal / Column_Max ? iMinWidth1 : iTotal / Column_Max; 1478 /* Apply the proposal: */ 1479 m_pSnapshotTree->setColumnWidth(Column_Taken, iWidth1); 1480 m_pSnapshotTree->setColumnWidth(Column_Name, iTotal - iWidth1); 1481 } 1482 1481 1483 UISnapshotItem *UISnapshotPane::findItem(const QString &strSnapshotID) const 1482 1484 { -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r67260 r67262 73 73 /** Handles translation event. */ 74 74 virtual void retranslateUi() /* override */; 75 76 /** Handles resize @a pEvent. */ 77 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 78 79 /** Handles show @a pEvent. */ 80 virtual void showEvent(QShowEvent *pEvent) /* override */; 75 81 /** @} */ 76 82 … … 159 165 /** @name Tree-widget helpers. 160 166 * @{ */ 167 /** Handles command to adjust snapshot tree. */ 168 void adjustTreeWidget(); 169 161 170 /** Searches for an item with corresponding @a strSnapshotID. */ 162 171 UISnapshotItem *findItem(const QString &strSnapshotID) const;
Note:
See TracChangeset
for help on using the changeset viewer.