Changeset 48088 in vbox for trunk/src/VBox
- Timestamp:
- Aug 27, 2013 3:59:36 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r48086 r48088 23 23 24 24 /* Qt includes: */ 25 #include <QCloseEvent> 26 #include <QDir> 27 #include <QDragEnterEvent> 28 #include <QDropEvent> 29 #include <QFileInfo> 25 #include <QLabel> 26 #include <QProgressBar> 27 #include <QMenuBar> 30 28 #include <QHeaderView> 31 #include <QMenuBar>32 #include <QProgressBar>33 29 #include <QPushButton> 34 30 #include <QTimer> 35 #include <QUrl>36 31 37 32 /* GUI includes: */ … … 41 36 #include "UIMessageCenter.h" 42 37 #include "UIToolBar.h" 43 #include "QIFileDialog.h"44 38 #include "QILabel.h" 45 39 #include "UIIconPool.h" … … 59 53 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 60 54 55 56 /* Medium-item: */ 61 57 class UIMediumItem : public QTreeWidgetItem 62 58 { 63 59 public: 64 60 61 /* Medium-item type: */ 65 62 enum { MediaItemType = QTreeWidgetItem::UserType + 1 }; 66 63 67 UIMediumItem (UIMediumItem *aParent, const UIMedium &aMedium, const UIMediumManager *aManager)68 : QTreeWidgetItem (aParent, MediaItemType)69 , mMedium (aMedium)70 , m Manager (aManager)64 /* Constructor: Top-level item: */ 65 UIMediumItem(const UIMedium &medium, QTreeWidget *pParent) 66 : QTreeWidgetItem(pParent, MediaItemType) 67 , m_medium(medium) 71 68 { refresh(); } 72 69 73 UIMediumItem (QTreeWidget *aParent, const UIMedium &aMedium, const UIMediumManager *aManager)74 : QTreeWidgetItem (aParent, MediaItemType)75 , mMedium (aMedium)76 , m Manager (aManager)70 /* Constructor: Child item: */ 71 UIMediumItem(const UIMedium &medium, UIMediumItem *pParent) 72 : QTreeWidgetItem(pParent, MediaItemType) 73 , m_medium(medium) 77 74 { refresh(); } 78 75 76 /* API: Refresh stuff: */ 79 77 void refreshAll() 80 78 { 81 m Medium.refresh();79 m_medium.refresh(); 82 80 refresh(); 83 81 } 84 82 85 void setMedium (const UIMedium &aMedium) 86 { 87 mMedium = aMedium; 83 /* API: Medium stuff: */ 84 const UIMedium& medium() const { return m_medium; } 85 void setMedium(const UIMedium &medium) 86 { 87 m_medium = medium; 88 88 refresh(); 89 89 } 90 90 91 const UIMedium& medium() const { return mMedium; } 92 93 UIMediumType type() const { return mMedium.type(); } 94 95 KMediumState state() const { return mMedium.state(); } 96 97 QString id() const { return mMedium.id(); } 98 99 QString location() const { return mMedium.location(); } 100 101 QString hardDiskFormat() const { return mMedium.hardDiskFormat(); } 102 QString hardDiskType() const { return mMedium.hardDiskType(); } 103 104 QString details() const { return mMedium.storageDetails(); } 105 106 QString usage() const { return mMedium.usage(); } 107 108 QString toolTip() const { return mMedium.toolTip(); } 109 110 bool isUsed() const { return mMedium.isUsed(); } 111 bool isUsedInSnapshots() const { return mMedium.isUsedInSnapshots(); } 112 113 bool operator< (const QTreeWidgetItem &aOther) const 91 /* API: Type stuff: */ 92 UIMediumType type() const { return m_medium.type(); } 93 94 /* API: State stuff: */ 95 KMediumState state() const { return m_medium.state(); } 96 97 /* API: ID stuff: */ 98 QString id() const { return m_medium.id(); } 99 100 /* API: Location stuff: */ 101 QString location() const { return m_medium.location(); } 102 103 /* API: Hard-disk stuff: */ 104 QString hardDiskFormat() const { return m_medium.hardDiskFormat(); } 105 QString hardDiskType() const { return m_medium.hardDiskType(); } 106 107 /* API: Details stuff: */ 108 QString details() const { return m_medium.storageDetails(); } 109 110 /* API: Tool-tip stuff: */ 111 QString toolTip() const { return m_medium.toolTip(); } 112 113 /* API: Usage stuff: */ 114 QString usage() const { return m_medium.usage(); } 115 bool isUsed() const { return m_medium.isUsed(); } 116 bool isUsedInSnapshots() const { return m_medium.isUsedInSnapshots(); } 117 118 /* API: Sorting stuff: */ 119 bool operator<(const QTreeWidgetItem &other) const 114 120 { 115 121 int column = treeWidget()->sortColumn(); 116 ULONG64 thisValue = vboxGlobal().parseSize ( text(column));117 ULONG64 thatValue = vboxGlobal().parseSize (aOther.text(column));118 return thisValue && thatValue ? thisValue < thatValue : QTreeWidgetItem::operator< (aOther);122 ULONG64 thisValue = vboxGlobal().parseSize( text(column)); 123 ULONG64 thatValue = vboxGlobal().parseSize(other.text(column)); 124 return thisValue && thatValue ? thisValue < thatValue : QTreeWidgetItem::operator<(other); 119 125 } 120 126 121 127 private: 122 128 129 /* Helper: Refresh stuff: */ 123 130 void refresh() 124 131 { 125 /* Fill in columns */ 126 setIcon (0, mMedium.icon()); 127 /* Set the text */ 128 setText (0, mMedium.name()); 129 setText (1, mMedium.logicalSize()); 130 setText (2, mMedium.size()); 131 /* All columns get the same tooltip */ 132 QString tt = mMedium.toolTip(); 133 for (int i = 0; i < treeWidget()->columnCount(); ++ i) 134 setToolTip (i, tt); 135 } 136 137 UIMedium mMedium; 138 const UIMediumManager *mManager; 132 /* Fill-in columns: */ 133 setIcon(0, m_medium.icon()); 134 setText(0, m_medium.name()); 135 setText(1, m_medium.logicalSize()); 136 setText(2, m_medium.size()); 137 /* All columns get the same tooltip: */ 138 QString strToolTip = m_medium.toolTip(); 139 for (int i = 0; i < treeWidget()->columnCount(); ++i) 140 setToolTip(i, strToolTip); 141 } 142 143 /* Variables: */ 144 UIMedium m_medium; 139 145 }; 140 146 141 class MediaItemIterator : public QTreeWidgetItemIterator 147 148 /* Medium-item: */ 149 class UIMediumItemIterator : public QTreeWidgetItemIterator 142 150 { 143 151 public: 144 152 145 MediaItemIterator (QTreeWidget* aTree)146 : QTreeWidgetItemIterator (aTree) {}153 UIMediumItemIterator(QTreeWidget *pTree) 154 : QTreeWidgetItemIterator(pTree) {} 147 155 148 156 UIMediumItem* operator*() 149 157 { 150 QTreeWidgetItem * item = QTreeWidgetItemIterator::operator*();151 return item && item->type() == UIMediumItem::MediaItemType ?152 static_cast <UIMediumItem*> (item) : 0;153 } 154 155 MediaItemIterator& operator++()156 { 157 return static_cast <MediaItemIterator&>(QTreeWidgetItemIterator::operator++());158 QTreeWidgetItem *pItem = QTreeWidgetItemIterator::operator*(); 159 return pItem && pItem->type() == UIMediumItem::MediaItemType ? 160 static_cast<UIMediumItem*>(pItem) : 0; 161 } 162 163 UIMediumItemIterator& operator++() 164 { 165 return static_cast<UIMediumItemIterator&>(QTreeWidgetItemIterator::operator++()); 158 166 } 159 167 }; 160 168 161 class VBoxProgressBar: public QWidget 169 170 /* Medium manager progress-bar: */ 171 class UIEnumerationProgressBar : public QWidget 162 172 { 163 173 Q_OBJECT; … … 165 175 public: 166 176 167 VBoxProgressBar (QWidget *aParent) 168 : QWidget (aParent) 169 { 170 mText = new QLabel (this); 171 m_pProgressBar = new QProgressBar (this); 172 m_pProgressBar->setTextVisible (false); 173 174 QHBoxLayout *layout = new QHBoxLayout (this); 175 layout->setContentsMargins(0, 0, 0, 0); 176 layout->addWidget (mText); 177 layout->addWidget (m_pProgressBar); 178 } 179 180 void setText (const QString &aText) { mText->setText (aText); } 181 void setValue (int aValue) { m_pProgressBar->setValue (aValue); } 182 void setMaximum (int aValue) { m_pProgressBar->setMaximum (aValue); } 183 177 /* Constructor: */ 178 UIEnumerationProgressBar(QWidget *pParent) 179 : QWidget(pParent) 180 { 181 /* Prepare: */ 182 prepare(); 183 } 184 185 /* API: Text stuff: */ 186 void setText(const QString &strText) { mText->setText(strText); } 187 188 /* API: Value stuff: */ 184 189 int value() const { return m_pProgressBar->value(); } 190 void setValue(int iValue) { m_pProgressBar->setValue(iValue); } 191 void setMaximum(int iValue) { m_pProgressBar->setMaximum(iValue); } 185 192 186 193 private: 187 194 195 /* Helper: Prepare stuff: */ 196 void prepare() 197 { 198 /* Create layout: */ 199 QHBoxLayout *pLayout = new QHBoxLayout(this); 200 { 201 /* Configure layout: */ 202 pLayout->setContentsMargins(0, 0, 0, 0); 203 /* Create label: */ 204 mText = new QLabel; 205 /* Create progress-bar: */ 206 m_pProgressBar = new QProgressBar; 207 { 208 /* Configure progress-bar: */ 209 m_pProgressBar->setTextVisible(false); 210 } 211 /* Add widgets into layout: */ 212 pLayout->addWidget(mText); 213 pLayout->addWidget(m_pProgressBar); 214 } 215 } 216 217 /* Widgets: */ 188 218 QLabel *mText; 189 219 QProgressBar *m_pProgressBar; … … 270 300 case UIMediumType_DVD: 271 301 { 272 pMediumItem = new UIMediumItem(m TwCD, medium, this);302 pMediumItem = new UIMediumItem(medium, mTwCD); 273 303 AssertReturnVoid(pMediumItem); 274 304 if (pMediumItem->id() == m_strSelectedIdCD) … … 281 311 case UIMediumType_Floppy: 282 312 { 283 pMediumItem = new UIMediumItem(m TwFD, medium, this);313 pMediumItem = new UIMediumItem(medium, mTwFD); 284 314 AssertReturnVoid(pMediumItem); 285 315 if (pMediumItem->id() == m_strSelectedIdFD) … … 639 669 bool fNotInEnumeration = !vboxGlobal().isMediaEnumerationStarted(); 640 670 bool fActionEnabledCopy = currentTreeWidgetType() == UIMediumType_HardDisk && 641 fNotInEnumeration && pMediumItem && checkMediumFor 671 fNotInEnumeration && pMediumItem && checkMediumFor(pMediumItem, Action_Copy); 642 672 bool fActionEnabledModify = currentTreeWidgetType() == UIMediumType_HardDisk && 643 fNotInEnumeration && pMediumItem && checkMediumFor 644 bool fActionEnabledRemove = fNotInEnumeration && pMediumItem && checkMediumFor 645 bool fActionEnabledRelease = pMediumItem && checkMediumFor 673 fNotInEnumeration && pMediumItem && checkMediumFor(pMediumItem, Action_Modify); 674 bool fActionEnabledRemove = fNotInEnumeration && pMediumItem && checkMediumFor(pMediumItem, Action_Remove); 675 bool fActionEnabledRelease = pMediumItem && checkMediumFor(pMediumItem, Action_Release); 646 676 m_pActionCopy->setEnabled(fActionEnabledCopy); 647 677 m_pActionModify->setEnabled(fActionEnabledModify); … … 666 696 else if (pMediumItem->treeWidget() == mTwCD) 667 697 { 668 mIpCD1->setText (formatPaneText(pMediumItem->location(), true, "end"));669 mIpCD2->setText 698 mIpCD1->setText(formatPaneText(pMediumItem->location(), true, "end")); 699 mIpCD2->setText(strUsage); 670 700 } 671 701 else if (pMediumItem->treeWidget() == mTwFD) 672 702 { 673 mIpFD1->setText (formatPaneText(pMediumItem->location(), true, "end"));674 mIpFD2->setText 703 mIpFD1->setText(formatPaneText(pMediumItem->location(), true, "end")); 704 mIpFD2->setText(strUsage); 675 705 } 676 706 } … … 917 947 { 918 948 /* Create tool-bar: */ 919 m ToolBar = new UIToolBar(this);949 m_pToolBar = new UIToolBar(this); 920 950 { 921 951 /* Configure tool-bar: */ 922 m ToolBar->setIconSize(QSize(22, 22));923 m ToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);924 m ToolBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);952 m_pToolBar->setIconSize(QSize(22, 22)); 953 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 954 m_pToolBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); 925 955 /* Add tool-bar actions: */ 926 m ToolBar->addAction(m_pActionCopy);927 m ToolBar->addAction(m_pActionModify);928 m ToolBar->addAction(m_pActionRemove);929 m ToolBar->addAction(m_pActionRelease);930 m ToolBar->addAction(m_pActionRefresh);956 m_pToolBar->addAction(m_pActionCopy); 957 m_pToolBar->addAction(m_pActionModify); 958 m_pToolBar->addAction(m_pActionRemove); 959 m_pToolBar->addAction(m_pActionRelease); 960 m_pToolBar->addAction(m_pActionRefresh); 931 961 /* Integrate tool-bar into dialog: */ 932 962 QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout()); … … 934 964 #if MAC_LEOPARD_STYLE 935 965 /* Enable unified tool-bars on Mac OS X. Available on Qt >= 4.3: */ 936 addToolBar(m ToolBar);937 m ToolBar->setMacToolbar();966 addToolBar(m_pToolBar); 967 m_pToolBar->setMacToolbar(); 938 968 /* No spacing/margin on the Mac: */ 939 969 pMainLayout->setContentsMargins(0, 0, 0, 0); … … 941 971 #else /* MAC_LEOPARD_STYLE */ 942 972 /* Add the tool-bar: */ 943 pMainLayout->insertWidget(0, m ToolBar);973 pMainLayout->insertWidget(0, m_pToolBar); 944 974 /* Set spacing/margin like in the selector window: */ 945 975 pMainLayout->setSpacing(5); … … 1086 1116 { 1087 1117 /* Create progress-bar: */ 1088 m_pProgressBar = new VBoxProgressBar(this);1118 m_pProgressBar = new UIEnumerationProgressBar(this); 1089 1119 { 1090 1120 /* Hidden by default: */ … … 1195 1225 the with doesn't match if the text increase. So manually adjust the size 1196 1226 after changing the text. */ 1197 m ToolBar->updateLayout();1227 m_pToolBar->updateLayout(); 1198 1228 # endif /* QT_MAC_USE_COCOA */ 1199 1229 #endif /* Q_WS_MAC */ … … 1449 1479 if (!parent.isNull()) 1450 1480 if (UIMediumItem *pRoot = searchItem(pTree, parent.GetId())) 1451 pMediumItem = new UIMediumItem( pRoot, medium, this);1481 pMediumItem = new UIMediumItem(medium, pRoot); 1452 1482 /* Else just create item as top-level one: */ 1453 1483 if (!pMediumItem) 1454 pMediumItem = new UIMediumItem( pTree, medium, this);1484 pMediumItem = new UIMediumItem(medium, pTree); 1455 1485 1456 1486 /* Return created item: */ … … 1531 1561 1532 1562 /* Find the first pfInaccessible item to be in charge: */ 1533 MediaItemIterator it(pTree);1563 UIMediumItemIterator it(pTree); 1534 1564 for (; *it; ++ it) 1535 1565 { … … 1559 1589 1560 1590 /* Iterate other all the mediums of passed tree: */ 1561 MediaItemIterator iterator(pTree);1591 UIMediumItemIterator iterator(pTree); 1562 1592 while (*iterator) 1563 1593 { … … 1650 1680 if (m_strSelectedIdHD.isNull()) 1651 1681 m_strSelectedIdHD = pMediumItem ? pMediumItem->id() : QString(); 1652 pMediumItem = toMediumItem 1682 pMediumItem = toMediumItem(mTwCD->currentItem()); 1653 1683 if (m_strSelectedIdCD.isNull()) 1654 1684 m_strSelectedIdCD = pMediumItem ? pMediumItem->id() : QString(); 1655 pMediumItem = toMediumItem 1685 pMediumItem = toMediumItem(mTwFD->currentItem()); 1656 1686 if (m_strSelectedIdFD.isNull()) 1657 1687 m_strSelectedIdFD = pMediumItem ? pMediumItem->id() : QString(); -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h
r48086 r48088 34 34 class UIToolBar; 35 35 class UIMediumItem; 36 class VBoxProgressBar;36 class UIEnumerationProgressBar; 37 37 38 38 /* Medium Manager Dialog: */ … … 174 174 175 175 /* Variables: Menu & Toolbar stuff: */ 176 UIToolBar *m ToolBar;176 UIToolBar *m_pToolBar; 177 177 QMenu *m_pContextMenu; 178 178 QMenu *m_pMenu; … … 184 184 185 185 /* Variable: Progress-bar stuff: */ 186 VBoxProgressBar *m_pProgressBar;186 UIEnumerationProgressBar *m_pProgressBar; 187 187 }; 188 188
Note:
See TracChangeset
for help on using the changeset viewer.