Changeset 14019 in vbox
- Timestamp:
- Nov 10, 2008 4:28:45 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
r13790 r14019 50 50 class QEvent; 51 51 52 class VBoxSelectorWnd: public QIWithRetranslateUI2 <QMainWindow>52 class VBoxSelectorWnd: public QIWithRetranslateUI2 <QMainWindow> 53 53 { 54 54 Q_OBJECT; … … 72 72 VBoxVMItem* getSelectedItem(); 73 73 #ifdef VBOX_GUI_WITH_SYSTRAY 74 void iconActivated (QSystemTrayIcon::ActivationReason aReason);74 void iconActivated (QSystemTrayIcon::ActivationReason aReason); 75 75 void showWindow(); 76 76 #endif … … 81 81 void vmSettings (const QString &aCategory = QString::null, 82 82 const QString &aControl = QString::null, 83 const QUuid & = "");84 void vmDelete (const QUuid& = "");85 void vmStart (const QUuid & = "");86 void vmDiscard (const QUuid& = "");87 void vmPause (bool, const QUuid & = "");88 void vmRefresh (const QUuid& = "");89 void vmShowLogs (const QUuid& = "");83 const QUuid &aMachineId = QUuid()); 84 void vmDelete (const QUuid &aMachineId = QUuid()); 85 void vmStart (const QUuid &aMachineId = QUuid()); 86 void vmDiscard (const QUuid &aMachineId = QUuid()); 87 void vmPause (bool, const QUuid &aMachineId = QUuid()); 88 void vmRefresh (const QUuid &aMachineId = QUuid()); 89 void vmShowLogs (const QUuid &aMachineId = QUuid()); 90 90 91 91 #ifdef VBOX_GUI_WITH_SYSTRAY … … 97 97 bool aDescription); 98 98 99 void showContextMenu ( VBoxVMItem *aItem,const QPoint &aPoint);99 void showContextMenu (const QPoint &aPoint); 100 100 101 101 protected: -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMListView.h
r13790 r14019 31 31 #include <QDateTime> 32 32 33 class VBoxSelectorWnd; 34 33 35 class VBoxVMItem : public QObject 34 36 { … … 50 52 public: 51 53 52 VBoxVMItem (const CMachine &aM , QObject*pParent);54 VBoxVMItem (const CMachine &aMachine, VBoxSelectorWnd *pParent); 53 55 virtual ~VBoxVMItem(); 54 56 … … 85 87 bool canSwitchTo() const; 86 88 bool switchTo(); 87 89 88 90 void updateActions(); 89 91 … … 91 93 92 94 /* Private member vars */ 93 QObject*mParent;95 VBoxSelectorWnd *mParent; 94 96 CMachine mMachine; 95 97 … … 200 202 void currentChanged(); 201 203 void activated(); 202 void contextMenuRequested (VBoxVMItem *aItem, const QPoint &aPoint);203 204 204 205 protected slots: … … 208 209 209 210 protected: 210 void mousePressEvent (QMouseEvent *aEvent);211 211 bool selectCurrent(); 212 212 }; -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
r14018 r14019 670 670 connect (mVMListView, SIGNAL (currentChanged()), 671 671 this, SLOT (vmListViewCurrentChanged())); 672 connect (mVMListView, SIGNAL (activated 672 connect (mVMListView, SIGNAL (activated()), 673 673 this, SLOT (vmStart())); 674 connect (mVMListView, SIGNAL (c ontextMenuRequested (VBoxVMItem *,const QPoint &)),675 this, SLOT (showContextMenu ( VBoxVMItem *,const QPoint &)));674 connect (mVMListView, SIGNAL (customContextMenuRequested (const QPoint &)), 675 this, SLOT (showContextMenu (const QPoint &))); 676 676 677 677 connect (vmDetailsView, SIGNAL (linkClicked (const QString &)), … … 836 836 * Opens the VM settings dialog. 837 837 */ 838 void VBoxSelectorWnd::vmSettings (const QString &aCategory, const QString &aControl, const QUuid& a _Uuid)838 void VBoxSelectorWnd::vmSettings (const QString &aCategory, const QString &aControl, const QUuid& aUuid) 839 839 { 840 840 if (!aCategory.isEmpty() && aCategory [0] != '#') … … 845 845 } 846 846 847 VBoxVMItem *item = mVMModel->itemById (a _Uuid);847 VBoxVMItem *item = mVMModel->itemById (aUuid); 848 848 if (NULL == item) 849 849 item = getSelectedItem(); … … 888 888 } 889 889 890 void VBoxSelectorWnd::vmDelete (const QUuid& a_Uuid)891 { 892 VBoxVMItem *item = mVMModel->itemById (a _Uuid);890 void VBoxSelectorWnd::vmDelete (const QUuid& aUuid) 891 { 892 VBoxVMItem *item = mVMModel->itemById (aUuid); 893 893 if (NULL == item) 894 894 item = getSelectedItem(); … … 950 950 } 951 951 952 void VBoxSelectorWnd::vmStart (const QUuid& a_Uuid)953 { 954 VBoxVMItem *item = mVMModel->itemById (a _Uuid);952 void VBoxSelectorWnd::vmStart (const QUuid& aUuid) 953 { 954 VBoxVMItem *item = mVMModel->itemById (aUuid); 955 955 if (NULL == item) 956 956 item = getSelectedItem(); … … 1029 1029 } 1030 1030 1031 void VBoxSelectorWnd::vmDiscard (const QUuid& a_Uuid)1032 { 1033 VBoxVMItem *item = mVMModel->itemById (a _Uuid);1031 void VBoxSelectorWnd::vmDiscard (const QUuid& aUuid) 1032 { 1033 VBoxVMItem *item = mVMModel->itemById (aUuid); 1034 1034 if (NULL == item) 1035 1035 item = getSelectedItem(); … … 1065 1065 } 1066 1066 1067 void VBoxSelectorWnd::vmPause (bool aPause, const QUuid& a _Uuid)1068 { 1069 VBoxVMItem *item = mVMModel->itemById (a _Uuid);1067 void VBoxSelectorWnd::vmPause (bool aPause, const QUuid& aUuid) 1068 { 1069 VBoxVMItem *item = mVMModel->itemById (aUuid); 1070 1070 if (NULL == item) 1071 1071 item = getSelectedItem(); … … 1098 1098 } 1099 1099 1100 void VBoxSelectorWnd::vmRefresh (const QUuid& a_Uuid)1101 { 1102 VBoxVMItem *item = mVMModel->itemById (a _Uuid);1100 void VBoxSelectorWnd::vmRefresh (const QUuid& aUuid) 1101 { 1102 VBoxVMItem *item = mVMModel->itemById (aUuid); 1103 1103 if (NULL == item) 1104 1104 item = getSelectedItem(); … … 1112 1112 } 1113 1113 1114 void VBoxSelectorWnd::vmShowLogs (const QUuid& a_Uuid)1115 { 1116 VBoxVMItem *item = mVMModel->itemById (a _Uuid);1114 void VBoxSelectorWnd::vmShowLogs (const QUuid& aUuid) 1115 { 1116 VBoxVMItem *item = mVMModel->itemById (aUuid); 1117 1117 if (NULL == item) 1118 1118 item = getSelectedItem(); … … 1220 1220 } 1221 1221 1222 void VBoxSelectorWnd::showContextMenu (VBoxVMItem *aItem, const QPoint &aPoint) 1223 { 1224 if (aItem) 1225 mVMCtxtMenu->exec (aPoint); 1222 void VBoxSelectorWnd::showContextMenu (const QPoint &aPoint) 1223 { 1224 /* Send a context menu request */ 1225 const QModelIndex &index = mVMListView->indexAt (aPoint); 1226 if (index.isValid()) 1227 if (VBoxVMItem *item = mVMListView->model()->data (index, 1228 VBoxVMModel::VBoxVMItemPtrRole).value <VBoxVMItem*>()) 1229 mVMCtxtMenu->exec (mVMListView->mapToGlobal (aPoint)); 1226 1230 } 1227 1231 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMListView.cpp
r13803 r14019 135 135 #endif 136 136 137 VBoxVMItem::VBoxVMItem (const CMachine &aM , QObject*pParent)138 : mParent (pParent), mMachine (aM)137 VBoxVMItem::VBoxVMItem (const CMachine &aMachine, VBoxSelectorWnd *pParent) 138 : mParent (pParent), mMachine (aMachine) 139 139 { 140 140 vmConfigAction = new QAction (this); 141 141 vmConfigAction->setIcon (VBoxGlobal::iconSetFull ( 142 143 144 142 QSize (32, 32), QSize (16, 16), 143 ":/vm_settings_32px.png", ":/settings_16px.png", 144 ":/vm_settings_disabled_32px.png", ":/settings_dis_16px.png")); 145 145 vmDeleteAction = new QAction (this); 146 146 vmDeleteAction->setIcon (VBoxGlobal::iconSetFull ( 147 148 149 150 151 152 153 154 147 QSize (32, 32), QSize (16, 16), 148 ":/vm_delete_32px.png", ":/delete_16px.png", 149 ":/vm_delete_disabled_32px.png", ":/delete_dis_16px.png")); 150 vmStartAction = new QAction (this); 151 vmStartAction->setIcon (VBoxGlobal::iconSetFull ( 152 QSize (32, 32), QSize (16, 16), 153 ":/vm_start_32px.png", ":/start_16px.png", 154 ":/vm_start_disabled_32px.png", ":/start_dis_16px.png")); 155 155 vmDiscardAction = new QAction (this); 156 156 vmDiscardAction->setIcon (VBoxGlobal::iconSetFull ( 157 158 159 157 QSize (32, 32), QSize (16, 16), 158 ":/vm_discard_32px.png", ":/discard_16px.png", 159 ":/vm_discard_disabled_32px.png", ":/discard_dis_16px.png")); 160 160 vmPauseAction = new QAction (this); 161 161 vmPauseAction->setCheckable (true); 162 162 vmPauseAction->setIcon (VBoxGlobal::iconSetFull ( 163 164 165 163 QSize (32, 32), QSize (16, 16), 164 ":/vm_pause_32px.png", ":/pause_16px.png", 165 ":/vm_pause_disabled_32px.png", ":/pause_disabled_16px.png")); 166 166 vmRefreshAction = new QAction (this); 167 167 vmRefreshAction->setIcon (VBoxGlobal::iconSetFull ( 168 169 170 168 QSize (32, 32), QSize (16, 16), 169 ":/refresh_32px.png", ":/refresh_16px.png", 170 ":/refresh_disabled_32px.png", ":/refresh_disabled_16px.png")); 171 171 vmShowLogsAction = new QAction (this); 172 172 vmShowLogsAction->setIcon (VBoxGlobal::iconSetFull ( 173 174 175 173 QSize (32, 32), QSize (16, 16), 174 ":/vm_show_logs_32px.png", ":/show_logs_16px.png", 175 ":/vm_show_logs_disabled_32px.png", ":/show_logs_disabled_16px.png")); 176 176 177 177 recache(); … … 184 184 connect (vmRefreshAction, SIGNAL (triggered()), this, SLOT (vmRefresh())); 185 185 connect (vmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs())); 186 186 187 187 updateActions(); 188 188 } … … 197 197 QString VBoxVMItem::sessionStateName() const 198 198 { 199 return mAccessible ? vboxGlobal().toString (mState) : VBoxVMListView::tr ("Inaccessible"); 199 return mAccessible ? vboxGlobal().toString (mState) : 200 VBoxVMListView::tr ("Inaccessible"); 200 201 } 201 202 202 203 void VBoxVMItem::vmSettings() 203 204 { 204 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 205 Assert (pWnd); 206 emit pWnd->vmSettings(NULL, NULL, mId); 205 mParent->vmSettings (NULL, NULL, mId); 207 206 } 208 207 209 208 void VBoxVMItem::vmDelete() 210 209 { 211 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 212 Assert (pWnd); 213 emit pWnd->vmDelete(mId); 210 mParent->vmDelete (mId); 214 211 } 215 212 216 213 void VBoxVMItem::vmStart() 217 214 { 218 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 219 Assert (pWnd); 220 emit pWnd->vmStart(mId); 215 mParent->vmStart (mId); 221 216 } 222 217 223 218 void VBoxVMItem::vmDiscard() 224 219 { 225 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 226 Assert (pWnd); 227 emit pWnd->vmDiscard(mId); 228 } 229 230 void VBoxVMItem::vmPause(bool aPause) 231 { 232 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 233 Assert (pWnd); 234 emit pWnd->vmPause(aPause, mId); 220 mParent->vmDiscard (mId); 221 } 222 223 void VBoxVMItem::vmPause (bool aPause) 224 { 225 mParent->vmPause (aPause, mId); 235 226 } 236 227 237 228 void VBoxVMItem::vmRefresh() 238 229 { 239 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 240 Assert (pWnd); 241 emit pWnd->vmRefresh(mId); 230 mParent->vmRefresh (mId); 242 231 } 243 232 244 233 void VBoxVMItem::vmShowLogs() 245 234 { 246 VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent); 247 Assert (pWnd); 248 emit pWnd->vmShowLogs(mId); 235 mParent->vmShowLogs (mId); 249 236 } 250 237 … … 296 283 { 297 284 QString name = mMachine.GetName(); 298 setObjectName (name);285 setObjectName (name); 299 286 CSnapshot snp = mMachine.GetCurrentSnapshot(); 300 287 mSnapshotName = snp.isNull() ? QString::null : snp.GetName(); … … 545 532 } 546 533 else 547 { 548 vmRefreshAction->setEnabled (true); 534 { 535 vmRefreshAction->setEnabled (true); 549 536 550 537 /* disable modify actions */ … … 563 550 vmShowLogsAction->setEnabled (false); 564 551 } 565 552 566 553 vmConfigAction->setText (tr ("&Settings...")); 567 554 vmConfigAction->setStatusTip (tr ("Configure the selected virtual machine")); 568 555 569 556 vmDeleteAction->setText (tr ("&Delete")); 570 557 vmDeleteAction->setStatusTip (tr ("Delete the selected virtual machine")); 571 558 572 559 vmDiscardAction->setText (tr ("D&iscard")); 573 560 vmDiscardAction->setStatusTip ( 574 561 tr ("Discard the saved state of the selected virtual machine")); 575 562 576 563 vmRefreshAction->setText (tr ("&Refresh")); 577 564 vmRefreshAction->setStatusTip ( 578 565 tr ("Refresh the accessibility state of the selected virtual machine")); 579 566 580 567 vmShowLogsAction->setText (tr ("Show &Log...")); 581 568 vmShowLogsAction->setIconText (tr ("Log", "icon text")); … … 693 680 } 694 681 695 int VBoxVMModel::rowCount (const QModelIndex & /* aParent = QModelIndex() */) const682 int VBoxVMModel::rowCount (const QModelIndex & /* aParent = QModelIndex() */) const 696 683 { 697 684 return mVMItemList.count(); 698 685 } 699 686 700 QVariant VBoxVMModel::data (const QModelIndex &aIndex, int aRole) const687 QVariant VBoxVMModel::data (const QModelIndex &aIndex, int aRole) const 701 688 { 702 689 if (!aIndex.isValid()) … … 710 697 { 711 698 case Qt::DisplayRole: 712 713 714 715 699 { 700 v = mVMItemList.at (aIndex.row())->name(); 701 break; 702 } 716 703 case Qt::DecorationRole: 717 718 719 720 704 { 705 v = mVMItemList.at (aIndex.row())->osIcon(); 706 break; 707 } 721 708 case Qt::ToolTipRole: 722 723 724 725 709 { 710 v = mVMItemList.at (aIndex.row())->toolTipText(); 711 break; 712 } 726 713 case Qt::FontRole: 727 728 729 730 731 732 733 714 { 715 QFont f = qApp->font(); 716 f.setPointSize (f.pointSize() + 1); 717 f.setWeight (QFont::Bold); 718 v = f; 719 break; 720 } 734 721 case Qt::AccessibleTextRole: 735 736 737 738 739 740 741 742 722 { 723 VBoxVMItem *item = mVMItemList.at (aIndex.row()); 724 v = QString ("%1 (%2)\n%3") 725 .arg (item->name()) 726 .arg (item->snapshotName()) 727 .arg (item->sessionStateName()); 728 break; 729 } 743 730 case SnapShotDisplayRole: 744 745 746 747 731 { 732 v = mVMItemList.at (aIndex.row())->snapshotName(); 733 break; 734 } 748 735 case SnapShotFontRole: 749 750 751 752 753 736 { 737 QFont f = qApp->font(); 738 v = f; 739 break; 740 } 754 741 case SessionStateDisplayRole: 755 756 757 758 742 { 743 v = mVMItemList.at (aIndex.row())->sessionStateName(); 744 break; 745 } 759 746 case SessionStateDecorationRole: 760 761 762 763 747 { 748 v = mVMItemList.at (aIndex.row())->sessionStateIcon(); 749 break; 750 } 764 751 case SessionStateFontRole: 765 766 767 768 769 770 771 772 752 { 753 QFont f = qApp->font(); 754 f.setPointSize (f.pointSize()); 755 if (mVMItemList.at (aIndex.row())->sessionState() != KSessionState_Closed) 756 f.setItalic (true); 757 v = f; 758 break; 759 } 773 760 case VBoxVMItemPtrRole: 774 775 776 761 { 762 v = qVariantFromValue (mVMItemList.at (aIndex.row())); 763 } 777 764 } 778 765 return v; 779 766 } 780 767 781 QVariant VBoxVMModel::headerData (int /*aSection*/, Qt::Orientation /*aOrientation*/,782 int /*aRole = Qt::DisplayRole */) const768 QVariant VBoxVMModel::headerData (int /*aSection*/, Qt::Orientation /*aOrientation*/, 769 int /*aRole = Qt::DisplayRole */) const 783 770 { 784 771 return QVariant(); … … 805 792 { 806 793 /* Create & set our delegation class */ 807 VBoxVMItemPainter *delegate = new VBoxVMItemPainter (this);808 setItemDelegate (delegate);794 VBoxVMItemPainter *delegate = new VBoxVMItemPainter (this); 795 setItemDelegate (delegate); 809 796 /* Default icon size */ 810 797 setIconSize (QSize (32, 32)); 811 798 /* Publish the activation of items */ 812 799 connect (this, SIGNAL (activated (const QModelIndex &)), 813 this, SIGNAL (activated ())); 800 this, SIGNAL (activated())); 801 /* Use the correct policy for the context menu */ 802 setContextMenuPolicy (Qt::CustomContextMenu); 814 803 } 815 804 … … 821 810 void VBoxVMListView::selectItemById (const QUuid &aID) 822 811 { 823 if (VBoxVMModel *m = qobject_cast <VBoxVMModel*> (model()))812 if (VBoxVMModel *m = qobject_cast <VBoxVMModel*> (model())) 824 813 { 825 814 QModelIndex i = m->indexById (aID); … … 832 821 { 833 822 VBoxVMItem *item = selectedItem(); 834 if (!item)823 if (!item) 835 824 { 836 825 aRowHint = qBound (0, aRowHint, model()->rowCount() - 1); … … 847 836 if (indexes.isEmpty()) 848 837 return NULL; 849 return model()->data (indexes.first(), VBoxVMModel::VBoxVMItemPtrRole).value <VBoxVMItem *>();838 return model()->data (indexes.first(), VBoxVMModel::VBoxVMItemPtrRole).value <VBoxVMItem *>(); 850 839 } 851 840 … … 877 866 ensureCurrentVisible(); 878 867 emit currentChanged(); 879 }880 881 void VBoxVMListView::mousePressEvent (QMouseEvent *aEvent)882 {883 /* First process event, in the case the user select a new item */884 QListView::mousePressEvent (aEvent);885 if (aEvent->button() == Qt::RightButton)886 {887 /* Send a context menu request if necessary */888 const QModelIndex &index = indexAt (aEvent->pos());889 if (index.isValid())890 {891 VBoxVMItem *item = model()->data (index, VBoxVMModel::VBoxVMItemPtrRole).value<VBoxVMItem *>();892 emit contextMenuRequested (item, aEvent->globalPos());893 }894 }895 868 } 896 869
Note:
See TracChangeset
for help on using the changeset viewer.