Changeset 10604 in vbox for trunk/src/VBox/Frontends/VirtualBox4
- Timestamp:
- Jul 14, 2008 3:16:10 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialog.h
r10474 r10604 53 53 54 54 virtual void revalidate (QIWidgetValidator * /* aWval */) {} 55 void categoryChanged (int aId); 55 56 56 57 protected: … … 71 72 void updateWhatsThis (bool aGotFocus = false); 72 73 void whatsThisCandidateDestroyed (QObject *aObj = 0); 73 74 void categoryChanged (int aId);75 74 76 75 private: -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialogSpecific.h
r10515 r10604 63 63 64 64 void updateAvailability(); 65 VBoxSettingsPage* attachPage (VBoxSettingsPage *aPage);66 65 }; 67 66 … … 79 78 { 80 79 GeneralId = 0, 80 StorageId, 81 81 HDId, 82 82 CDId, … … 84 84 AudioId, 85 85 NetworkId, 86 PortsId, 86 87 SerialId, 87 88 ParallelId, … … 114 115 private: 115 116 117 void addItem (const QIcon &aIcon, int aId, const QString &aLink, VBoxSettingsPage* aPrefPage = NULL, int aParentId = -1); 116 118 void updateAvailability(); 117 VBoxSettingsPage* attach Page(VBoxSettingsPage *aPage);119 VBoxSettingsPage* attachValidator (VBoxSettingsPage *aPage); 118 120 119 121 CMachine mMachine; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsSelector.h
r10475 r10604 29 29 class QITreeWidget; 30 30 class VBoxToolBar; 31 class SelectorAction; 31 class VBoxSettingsPage; 32 class SelectorItem; 33 class SelectorActionItem; 32 34 33 35 class QTreeWidget; … … 36 38 class QAction; 37 39 class QActionGroup; 40 template <class Key, class T> class QMap; 41 class QTabWidget; 38 42 39 43 class VBoxSettingsSelector: public QObject … … 47 51 virtual QWidget *widget() const = 0; 48 52 49 virtual void addItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink) = 0; 53 virtual QWidget *addItem (const QIcon &aIcon, int aId, const QString &aLink, VBoxSettingsPage* aPage = NULL, int aParentId = -1) = 0; 54 55 virtual void setItemText (int aId, const QString &aText); 50 56 virtual QString itemText (int aId) const = 0; 51 virtual QString itemTextBy Index (int aIndex) const { return itemText (indexToId (aIndex)); }57 virtual QString itemTextByPage (VBoxSettingsPage *aPage) const; 52 58 53 59 virtual int currentId () const = 0; 54 virtual int idToIndex (int aId) const = 0;55 virtual int indexToId (int aIndex) const = 0;56 60 virtual int linkToId (const QString &aLink) const = 0; 61 62 virtual QWidget *idToPage (int aId) const; 63 virtual QWidget *rootPage (int aId) const { return idToPage (aId); } 64 57 65 virtual void selectById (int aId) = 0; 58 66 virtual void selectByLink (const QString &aLink) { selectById (linkToId (aLink)); } 67 59 68 virtual void setVisibleById (int aId, bool aShow) = 0; 60 69 61 virtual void clear() = 0; 70 virtual QList<VBoxSettingsPage*> settingPages() const; 71 virtual QList<QWidget*> rootPages() const; 62 72 63 73 virtual void polish() {}; 74 64 75 virtual int minWidth () const { return 0; } 65 76 … … 68 79 void categoryChanged (int); 69 80 81 protected: 82 83 virtual void clear() = 0; 84 85 SelectorItem* findItem (int aId) const; 86 SelectorItem* findItemByLink (const QString &aLink) const; 87 SelectorItem* findItemByPage (VBoxSettingsPage* aPage) const; 88 89 QList<SelectorItem*> mItemList; 70 90 }; 71 91 … … 80 100 virtual QWidget *widget() const; 81 101 82 virtual void addItem (const QIcon &aIcon, const QString &aText, int aIndex, const QString &aLink); 102 virtual QWidget *addItem (const QIcon &aIcon, int aId, const QString &aLink, VBoxSettingsPage* aPage = NULL, int aParentId = -1); 103 virtual void setItemText (int aId, const QString &aText); 83 104 virtual QString itemText (int aId) const; 84 105 85 106 virtual int currentId() const; 86 virtual int idToIndex (int aId) const;87 virtual int indexToId (int aIndex) const;88 107 virtual int linkToId (const QString &aLink) const; 108 89 109 virtual void selectById (int aId); 110 90 111 virtual void setVisibleById (int aId, bool aShow); 91 92 virtual void clear();93 112 94 113 virtual void polish(); … … 99 118 100 119 private: 120 121 virtual void clear(); 101 122 102 123 QString pagePath (const QString &aMatch) const; … … 115 136 116 137 VBoxSettingsToolBarSelector (QWidget *aParent = NULL); 138 ~VBoxSettingsToolBarSelector(); 117 139 118 140 virtual QWidget *widget() const; 119 141 120 virtual void addItem (const QIcon &aIcon, const QString &aText, int aIndex, const QString &aLink); 142 virtual QWidget *addItem (const QIcon &aIcon, int aId, const QString &aLink, VBoxSettingsPage* aPage = NULL, int aParentId = -1); 143 virtual void setItemText (int aId, const QString &aText); 121 144 virtual QString itemText (int aId) const; 122 145 123 146 virtual int currentId() const; 124 virtual int idToIndex (int aId) const;125 virtual int indexToId (int aIndex) const;126 147 virtual int linkToId (const QString &aLink) const; 148 149 virtual QWidget *idToPage (int aId) const; 150 virtual QWidget *rootPage (int aId) const; 151 127 152 virtual void selectById (int aId); 153 128 154 virtual void setVisibleById (int aId, bool aShow); 155 156 virtual int minWidth() const; 157 158 virtual QList<QWidget*> rootPages() const; 159 private slots: 160 161 void settingsGroupChanged (QAction *aAction); 162 void settingsGroupChanged (int aIndex); 163 164 private: 129 165 130 166 virtual void clear(); 131 167 132 virtual int minWidth() const; 133 134 private slots: 135 136 void settingsGroupChanged (QAction *aAction); 137 138 private: 139 140 SelectorAction* findAction (int aId) const; 168 SelectorActionItem *findActionItem (int aId) const; 169 SelectorActionItem *findActionItemByAction (QAction *aAction) const; 170 SelectorActionItem *findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const; 141 171 142 172 /* Private member vars */ -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialog.cpp
r10536 r10604 27 27 #include "QIWidgetValidator.h" 28 28 #include "VBoxSettingsSelector.h" 29 #include "VBoxSettingsPage.h" 29 30 #include "VBoxToolBar.h" 30 31 … … 193 194 void VBoxSettingsDialog::categoryChanged (int aId) 194 195 { 195 int index = mSelector->idToIndex(aId);196 QWidget *rootPage = mSelector->rootPage (aId); 196 197 #ifndef Q_WS_MAC 197 198 mLbTitle->setText (mSelector->itemText (aId)); 198 mStack->setCurrentIndex ( index);199 mStack->setCurrentIndex (mStack->indexOf (rootPage)); 199 200 #else /* Q_WS_MAC */ 200 if (isVisible()) 201 { 202 int index = mSelector->idToIndex (aId); 203 /* We will update at once later */ 204 setUpdatesEnabled (false); 205 setMinimumSize (QSize (minimumWidth(), 0)); 206 setMaximumSize (QSize (minimumWidth(), QWIDGETSIZE_MAX)); 207 /* Set all tab size policies to ignored */ 208 for (int i = 0; i < mStack->count(); ++i) 209 mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored); 210 /* Set the size policy of the current tab to preferred */ 211 if (mStack->widget (index)) 212 mStack->widget (index)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); 213 /* Set the new current tab */ 214 mLbTitle->setText (mSelector->itemText (aId)); 215 mStack->setCurrentIndex (index); 216 /* Activate the new layout */ 217 layout()->activate(); 218 setUpdatesEnabled (true); 219 // mAllWidget->hide(); 220 QSize s = minimumSize(); 221 int minWidth = mSelector->minWidth(); 222 if (minWidth > s.width()) 223 s.setWidth (minWidth); 224 /* Play the resize animation */ 225 ::darwinWindowAnimateResize (this, QRect (x(), y(), 226 s.width(), s.height())); 227 // mAllWidget->show(); 228 /* Set the new size to Qt also */ 229 setFixedSize (s); 230 }else 231 { 232 mLbTitle->setText (mSelector->itemText (aId)); 233 mStack->setCurrentIndex (index); 234 } 201 /* We will update at once later */ 202 setUpdatesEnabled (false); 203 setMinimumSize (QSize (minimumWidth(), 0)); 204 setMaximumSize (QSize (minimumWidth(), QWIDGETSIZE_MAX)); 205 /* Set all tab size policies to ignored */ 206 QList<QWidget*> list = mSelector->rootPages (); 207 for (int i = 0; i < list.count(); ++i) 208 list.at (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored); 209 /* Set the size policy of the current tab to preferred */ 210 if (mStack->widget (mStack->indexOf (rootPage))) 211 mStack->widget (mStack->indexOf (rootPage))->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); 212 /* Set the new current tab */ 213 mLbTitle->setText (mSelector->itemText (aId)); 214 mStack->setCurrentIndex (mStack->indexOf (rootPage)); 215 /* Activate the new layout */ 216 layout()->activate(); 217 setUpdatesEnabled (true); 218 // mAllWidget->hide(); 219 QSize s = minimumSize(); 220 int minWidth = mSelector->minWidth(); 221 if (minWidth > s.width()) 222 s.setWidth (minWidth); 223 /* Play the resize animation */ 224 ::darwinWindowAnimateResize (this, QRect (x(), y(), 225 s.width(), s.height())); 226 // mAllWidget->show(); 227 /* Set the new size to Qt also */ 228 setFixedSize (s); 229 #endif /* !Q_WS_MAC */ 235 230 # ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS 236 231 setWindowTitle (dialogTitle()); 237 232 # endif 238 #endif /* !Q_WS_MAC */239 233 } 240 234 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialogSpecific.cpp
r10515 r10604 57 57 58 58 /* Creating settings pages */ 59 attachPage (new VBoxGLSettingsGeneral()); 60 61 attachPage (new VBoxGLSettingsInput()); 62 63 attachPage (new VBoxGLSettingsUpdate()); 64 65 attachPage (new VBoxGLSettingsLanguage()); 59 QWidget *page = NULL; 60 VBoxSettingsPage *prefPage = NULL; 61 62 /* General page */ 63 prefPage = new VBoxGLSettingsGeneral(); 64 page = mSelector->addItem (VBoxGlobal::iconSet (":/machine_16px.png"), 65 GeneralId, "#general", 66 prefPage); 67 if (page) 68 mStack->addWidget (page); 69 prefPage->setOrderAfter (mSelector->widget()); 70 71 /* Input page */ 72 prefPage = new VBoxGLSettingsInput(); 73 page = mSelector->addItem (VBoxGlobal::iconSet (":/hostkey_16px.png"), 74 InputId, "#input", 75 prefPage); 76 if (page) 77 mStack->addWidget (page); 78 prefPage->setOrderAfter (mSelector->widget()); 79 80 /* Update page */ 81 prefPage = new VBoxGLSettingsUpdate(); 82 page = mSelector->addItem (VBoxGlobal::iconSet (":/refresh_16px.png"), 83 UpdateId, "#update", 84 prefPage); 85 if (page) 86 mStack->addWidget (page); 87 prefPage->setOrderAfter (mSelector->widget()); 88 89 /* Language page */ 90 prefPage = new VBoxGLSettingsLanguage(); 91 page = mSelector->addItem (VBoxGlobal::iconSet (":/site_16px.png"), 92 LanguageId, "#language", 93 prefPage); 94 if (page) 95 mStack->addWidget (page); 96 prefPage->setOrderAfter (mSelector->widget()); 66 97 67 98 #ifdef ENABLE_GLOBAL_USB 68 attachPage (new VBoxVMSettingsUSB (VBoxVMSettingsUSB::HostType)); 99 /* USB page */ 100 prefPage = VBoxVMSettingsUSB (VBoxVMSettingsUSB::HostType); 101 page = mSelector->addItem (VBoxGlobal::iconSet (":/usb_16px.png"), 102 USBId, "#usb", 103 prefPage); 104 if (page) 105 mStack->addWidget (page); 106 prefPage->setOrderAfter (mSelector->widget()); 69 107 #endif 70 108 … … 74 112 /* Applying language settings */ 75 113 retranslateUi(); 114 115 /* First item as default */ 116 mSelector->selectById (0); 76 117 } 77 118 … … 81 122 VBoxGlobalSettings sett = vboxGlobal().settings(); 82 123 83 QList<VBoxSettingsPage*> pages = mS tack->findChildren<VBoxSettingsPage*>();124 QList<VBoxSettingsPage*> pages = mSelector->settingPages(); 84 125 foreach (VBoxSettingsPage *page, pages) 85 126 if (page->isEnabled()) … … 93 134 VBoxGlobalSettings newsett = sett; 94 135 95 QList<VBoxSettingsPage*> pages = mS tack->findChildren<VBoxSettingsPage*>();136 QList<VBoxSettingsPage*> pages = mSelector->settingPages(); 96 137 foreach (VBoxSettingsPage *page, pages) 97 138 if (page->isEnabled()) … … 112 153 setWindowTitle (dialogTitle()); 113 154 114 /* Remember old index */115 int cid = mSelector->currentId();116 /* Remove all items */117 mSelector->clear();118 119 155 /* General page */ 120 mSelector->addItem (VBoxGlobal::iconSet (":/machine_16px.png"), 121 tr ("General"), GeneralId, "#general"); 156 mSelector->setItemText (GeneralId, tr ("General")); 122 157 123 158 /* Input page */ 124 mSelector->addItem (VBoxGlobal::iconSet (":/hostkey_16px.png"), 125 tr ("Input"), InputId, "#input"); 159 mSelector->setItemText (InputId, tr ("Input")); 126 160 127 161 /* Update page */ 128 mSelector->addItem (VBoxGlobal::iconSet (":/refresh_16px.png"), 129 tr ("Update"), UpdateId, "#update"); 162 mSelector->setItemText (UpdateId, tr ("Update")); 130 163 131 164 /* Language page */ 132 mSelector->addItem (VBoxGlobal::iconSet (":/site_16px.png"), 133 tr ("Language"), LanguageId, "#language"); 165 mSelector->setItemText (LanguageId, tr ("Language")); 134 166 135 167 #ifdef ENABLE_GLOBAL_USB 136 168 /* USB page */ 137 mSelector->addItem (VBoxGlobal::iconSet (":/usb_16px.png"), 138 tr ("USB"), USBId, "#usb"); 169 mSelector->setItemText (USBId, tr ("USB")); 139 170 #endif 140 171 … … 144 175 VBoxSettingsDialog::retranslateUi(); 145 176 146 /* Select old remembered category */147 mSelector->selectById (cid == -1 ? 0 : cid);148 149 177 /* Update Selector with available items */ 150 178 updateAvailability(); … … 154 182 { 155 183 return tr ("VirtualBox - %1").arg (titleExtension()); 156 }157 158 VBoxSettingsPage* VBoxGLSettingsDlg::attachPage (VBoxSettingsPage *aPage)159 {160 mStack->addWidget (aPage);161 162 aPage->setOrderAfter (mSelector->widget());163 164 return aPage;165 184 } 166 185 … … 180 199 * not available (i.e. in VirtualBox OSE) */ 181 200 mSelector->setVisibleById (USBId, false); 182 int index = mSelector->idToIndex (USBId);183 if (index > -1)184 {185 if (mStack->widget (index))186 mStack->widget (index)->setEnabled (false);187 }188 201 } 189 202 } … … 206 219 207 220 /* Creating settings pages */ 208 VBoxSettingsPage *page = 0; 209 210 page = attachPage (new VBoxVMSettingsGeneral()); 211 connect (page, SIGNAL (tableChanged()), this, SLOT (resetFirstRunFlag())); 212 213 page = attachPage (new VBoxVMSettingsHD()); 214 connect (page, SIGNAL (hdChanged()), this, SLOT (resetFirstRunFlag())); 215 216 page = attachPage (new VBoxVMSettingsCD()); 217 connect (page, SIGNAL (cdChanged()), this, SLOT (resetFirstRunFlag())); 218 219 page = attachPage (new VBoxVMSettingsFD()); 220 connect (page, SIGNAL (fdChanged()), this, SLOT (resetFirstRunFlag())); 221 222 attachPage (new VBoxVMSettingsAudio()); 223 224 attachPage (new VBoxVMSettingsNetworkPage()); 225 226 attachPage (new VBoxVMSettingsSerialPage()); 227 228 attachPage (new VBoxVMSettingsParallelPage()); 229 230 attachPage (new VBoxVMSettingsUSB (VBoxVMSettingsUSB::MachineType)); 231 232 attachPage (new VBoxVMSettingsSF (MachineType)); 233 234 attachPage (new VBoxVMSettingsVRDP()); 221 VBoxSettingsPage *prefPage = NULL; 222 223 /* General page */ 224 prefPage = new VBoxVMSettingsGeneral(); 225 connect (prefPage, SIGNAL (tableChanged()), this, SLOT (resetFirstRunFlag())); 226 addItem (VBoxGlobal::iconSet (":/machine_16px.png"), 227 GeneralId, "#general", 228 prefPage); 229 230 /* Storage page */ 231 addItem (VBoxGlobal::iconSet (":/hd_16px.png"), 232 StorageId, "#storage"); 233 234 /* HD page */ 235 prefPage = new VBoxVMSettingsHD(); 236 connect (prefPage, SIGNAL (hdChanged()), this, SLOT (resetFirstRunFlag())); 237 addItem (VBoxGlobal::iconSet (":/hd_16px.png"), 238 HDId, "#hdds", 239 prefPage, StorageId); 240 241 /* CD page */ 242 prefPage = new VBoxVMSettingsCD(); 243 connect (prefPage, SIGNAL (cdChanged()), this, SLOT (resetFirstRunFlag())); 244 addItem (VBoxGlobal::iconSet (":/cd_16px.png"), 245 CDId, "#dvd", 246 prefPage, StorageId); 247 248 /* FD page */ 249 prefPage = new VBoxVMSettingsFD(); 250 connect (prefPage, SIGNAL (fdChanged()), this, SLOT (resetFirstRunFlag())); 251 addItem (VBoxGlobal::iconSet (":/fd_16px.png"), 252 FDId, "#floppy", 253 prefPage, StorageId); 254 255 /* Audio page */ 256 prefPage = new VBoxVMSettingsAudio(); 257 addItem (VBoxGlobal::iconSet (":/sound_16px.png"), 258 AudioId, "#audio", 259 prefPage); 260 261 /* Network page */ 262 prefPage = new VBoxVMSettingsNetworkPage(); 263 addItem (VBoxGlobal::iconSet (":/nw_16px.png"), 264 NetworkId, "#network", 265 prefPage); 266 267 /* Ports page */ 268 addItem (VBoxGlobal::iconSet (":/serial_port_16px.png"), 269 PortsId, "#ports"); 270 271 /* Serial page */ 272 prefPage = new VBoxVMSettingsSerialPage(); 273 addItem (VBoxGlobal::iconSet (":/serial_port_16px.png"), 274 SerialId, "#serialPorts", 275 prefPage, PortsId); 276 277 /* Parallel page */ 278 prefPage = new VBoxVMSettingsParallelPage(); 279 addItem (VBoxGlobal::iconSet (":/parallel_port_16px.png"), 280 ParallelId, "#parallelPorts", 281 prefPage, PortsId); 282 283 /* USB page */ 284 prefPage = new VBoxVMSettingsUSB (VBoxVMSettingsUSB::MachineType); 285 addItem (VBoxGlobal::iconSet (":/usb_16px.png"), 286 USBId, "#usb", 287 prefPage, PortsId); 288 289 /* SFolders page */ 290 prefPage = new VBoxVMSettingsSF (MachineType); 291 addItem (VBoxGlobal::iconSet (":/shared_folder_16px.png"), 292 SFId, "#sfolders", 293 prefPage); 294 295 /* VRDP page */ 296 prefPage = new VBoxVMSettingsVRDP(); 297 addItem (VBoxGlobal::iconSet (":/vrdp_16px.png"), 298 VRDPId, "#vrdp", 299 prefPage); 235 300 236 301 /* Applying language settings */ 237 302 retranslateUi(); 303 304 /* First item as default */ 238 305 239 306 /* Setup Settings Dialog */ … … 266 333 } 267 334 } 268 } 335 }else 336 mSelector->selectById (0); 337 } 338 339 void VBoxVMSettingsDlg::addItem (const QIcon &aIcon, int aId, const QString &aLink, VBoxSettingsPage* aPrefPage /* = NULL*/, int aParentId /* = -1 */) 340 { 341 QWidget *page = mSelector->addItem (aIcon, 342 aId, aLink, 343 aPrefPage, aParentId); 344 if (page) 345 mStack->addWidget (page); 346 if (aPrefPage) 347 attachValidator (aPrefPage); 269 348 } 270 349 … … 277 356 QString warningText; 278 357 279 QString pageTitle = mSelector->itemTextByIndex (mStack->indexOf (pg));280 281 358 VBoxSettingsPage *page = static_cast<VBoxSettingsPage*> (pg); 359 QString pageTitle = mSelector->itemTextByPage (page); 360 282 361 valid = page->revalidate (warningText, pageTitle); 283 362 … … 291 370 void VBoxVMSettingsDlg::getFrom() 292 371 { 293 QList<VBoxSettingsPage*> pages = mS tack->findChildren<VBoxSettingsPage*>();372 QList<VBoxSettingsPage*> pages = mSelector->settingPages(); 294 373 foreach (VBoxSettingsPage *page, pages) 295 374 page->getFrom (mMachine); … … 303 382 void VBoxVMSettingsDlg::putBackTo() 304 383 { 305 QList<VBoxSettingsPage*> pages = mS tack->findChildren<VBoxSettingsPage*>();384 QList<VBoxSettingsPage*> pages = mSelector->settingPages(); 306 385 foreach (VBoxSettingsPage *page, pages) 307 386 page->putBackTo(); … … 322 401 * vboxGlobal which is retranslated at that point already. */ 323 402 QEvent event (QEvent::LanguageChange); 324 325 /* Populate selector list */ 326 QWidget *curpage = 0; 327 328 /* Remember old index */ 329 int cid = mSelector->currentId(); 330 /* Remove all items */ 331 mSelector->clear(); 403 QWidget *page = NULL; 332 404 333 405 /* General page */ 334 mSelector->addItem (VBoxGlobal::iconSet (":/machine_16px.png"), 335 tr ("General"), GeneralId, "#general"); 406 mSelector->setItemText (GeneralId, tr ("General")); 407 408 /* Storage page */ 409 mSelector->setItemText (StorageId, tr ("Storage")); 336 410 337 411 /* HD page */ 338 mSelector->addItem (VBoxGlobal::iconSet (":/hd_16px.png"), 339 tr ("Hard Disks"), HDId, "#hdds"); 412 mSelector->setItemText (HDId, tr ("Hard Disks")); 340 413 341 414 /* CD page */ 342 mSelector->addItem (VBoxGlobal::iconSet (":/cd_16px.png"), 343 tr ("CD/DVD-ROM"), CDId, "#dvd"); 415 mSelector->setItemText (CDId, tr ("CD/DVD-ROM")); 344 416 345 417 /* FD page */ 346 mSelector->addItem (VBoxGlobal::iconSet (":/fd_16px.png"), 347 tr ("Floppy"), FDId, "#floppy"); 418 mSelector->setItemText (FDId, tr ("Floppy")); 348 419 349 420 /* Audio page */ 350 mSelector->addItem (VBoxGlobal::iconSet (":/sound_16px.png"), 351 tr ("Audio"), AudioId, "#audio"); 421 mSelector->setItemText (AudioId, tr ("Audio")); 352 422 353 423 /* Network page */ 354 mSelector-> addItem (VBoxGlobal::iconSet (":/nw_16px.png"),355 tr ("Network"), NetworkId, "#network");356 357 curpage = mStack->widget (mSelector->idToIndex (NetworkId)); 358 if (curpage)359 qApp->sendEvent (curpage, &event);424 mSelector->setItemText (NetworkId, tr ("Network")); 425 if ((page = mSelector->idToPage (NetworkId))) 426 qApp->sendEvent (page, &event); 427 428 /* Ports page */ 429 mSelector->setItemText (PortsId, tr ("Ports")); 360 430 361 431 /* Serial page */ 362 mSelector->addItem (VBoxGlobal::iconSet (":/serial_port_16px.png"), 363 tr ("Serial Ports"), SerialId, "#serialPorts"); 364 365 curpage = mStack->widget (mSelector->idToIndex (SerialId)); 366 if (curpage) 367 qApp->sendEvent (curpage, &event); 432 mSelector->setItemText (SerialId, tr ("Serial Ports")); 433 if ((page = mSelector->idToPage (SerialId))) 434 qApp->sendEvent (page, &event); 368 435 369 436 /* Parallel page */ 370 mSelector->addItem (VBoxGlobal::iconSet (":/parallel_port_16px.png"), 371 tr ("Parallel Ports"), ParallelId, "#parallelPorts"); 372 373 curpage = mStack->widget (mSelector->idToIndex (ParallelId)); 374 if (curpage) 375 qApp->sendEvent (curpage, &event); 437 mSelector->setItemText (ParallelId, tr ("Parallel Ports")); 438 if ((page = mSelector->idToPage (ParallelId))) 439 qApp->sendEvent (page, &event); 376 440 377 441 /* USB page */ 378 mSelector->addItem (VBoxGlobal::iconSet (":/usb_16px.png"), 379 tr ("USB"), USBId, "#usb"); 442 mSelector->setItemText (USBId, tr ("USB")); 380 443 381 444 /* SFolders page */ 382 mSelector->addItem (VBoxGlobal::iconSet (":/shared_folder_16px.png"), 383 tr ("Shared Folders"), SFId, "#sfolders"); 445 mSelector->setItemText (SFId, tr ("Shared Folders")); 384 446 385 447 /* VRDP page */ 386 mSelector->addItem (VBoxGlobal::iconSet (":/vrdp_16px.png"), 387 tr ("Remote Display"), VRDPId, "#vrdp"); 448 mSelector->setItemText (VRDPId, tr ("Remote Display")); 388 449 389 450 /* Translate the selector */ … … 391 452 392 453 VBoxSettingsDialog::retranslateUi(); 393 394 /* Select old remembered category */395 mSelector->selectById (cid == -1 ? 0 : cid);396 454 397 455 /* Update QTreeWidget with available items */ … … 425 483 } 426 484 427 VBoxSettingsPage* VBoxVMSettingsDlg::attachPage (VBoxSettingsPage *aPage) 428 { 429 mStack->addWidget (aPage); 430 431 QIWidgetValidator *wval = new QIWidgetValidator (mSelector->itemTextByIndex (mStack->indexOf (aPage)), 485 VBoxSettingsPage* VBoxVMSettingsDlg::attachValidator (VBoxSettingsPage *aPage) 486 { 487 QIWidgetValidator *wval = new QIWidgetValidator (mSelector->itemTextByPage (aPage), 432 488 aPage, this); 433 489 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator*)), … … 449 505 /* Parallel Port Page (currently disabled) */ 450 506 mSelector->setVisibleById (ParallelId, false); 451 int index = mSelector->idToIndex (ParallelId);452 if (index > -1)453 {454 if (mStack->widget (index))455 mStack->widget (index)->setEnabled (false);456 }457 507 458 508 /* USB Stuff */ … … 468 518 * not available (i.e. in VirtualBox OSE) */ 469 519 mSelector->setVisibleById (USBId, false); 470 int index = mSelector->idToIndex (USBId);471 if (index > -1)472 {473 if (mStack->widget (index))474 mStack->widget (index)->setEnabled (false);475 }476 520 } 477 521 … … 483 527 * not available (i.e. in VirtualBox OSE) */ 484 528 mSelector->setVisibleById (VRDPId, false); 485 int index = mSelector->idToIndex (VRDPId);486 if (index > -1)487 {488 if (mStack->widget (index))489 mStack->widget (index)->setEnabled (false);490 }491 529 /* If mMachine has something to say, show the message */ 492 530 vboxProblem().cannotLoadMachineSettings (mMachine, false /* strict */); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsSelector.cpp
r10475 r10604 23 23 #include "VBoxSettingsSelector.h" 24 24 #include "VBoxSettingsUtils.h" 25 #include "VBoxSettingsPage.h" 25 26 #include "QITreeWidget.h" 26 27 #include "VBoxToolBar.h" 28 29 /* Qt includes */ 30 #include <QTabWidget> 27 31 28 32 enum … … 34 38 }; 35 39 40 class SelectorItem 41 { 42 public: 43 SelectorItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, VBoxSettingsPage* aPage, int aParentId) 44 : mIcon (aIcon) 45 , mText (aText) 46 , mId (aId) 47 , mLink (aLink) 48 , mPage (aPage) 49 , mParentId (aParentId) 50 {} 51 52 QIcon icon() const { return mIcon; } 53 QString text() const { return mText; } 54 void setText (const QString &aText) { mText = aText; } 55 int id() const { return mId; } 56 QString link() const { return mLink; } 57 VBoxSettingsPage *page() const { return mPage; } 58 int parentId() const { return mParentId; } 59 60 protected: 61 62 QIcon mIcon; 63 QString mText; 64 int mId; 65 QString mLink; 66 VBoxSettingsPage* mPage; 67 int mParentId; 68 }; 69 36 70 VBoxSettingsSelector::VBoxSettingsSelector (QWidget *aParent /* = NULL */) 37 71 :QObject (aParent) 38 72 { 73 } 74 75 void VBoxSettingsSelector::setItemText (int aId, const QString &aText) 76 { 77 if (SelectorItem *item = findItem (aId)) 78 item->setText (aText); 79 } 80 81 QString VBoxSettingsSelector::itemTextByPage (VBoxSettingsPage *aPage) const 82 { 83 QString text; 84 if (SelectorItem *item = findItemByPage (aPage)) 85 text = item->text(); 86 return text; 87 } 88 89 QWidget *VBoxSettingsSelector::idToPage (int aId) const 90 { 91 VBoxSettingsPage *page = NULL; 92 if (SelectorItem *item = findItem (aId)) 93 page = item->page(); 94 return page; 95 } 96 97 QList<VBoxSettingsPage*> VBoxSettingsSelector::settingPages() const 98 { 99 QList<VBoxSettingsPage*> list; 100 foreach (SelectorItem *item, mItemList) 101 if (item->page()) 102 list << item->page(); 103 return list; 104 } 105 106 QList<QWidget*> VBoxSettingsSelector::rootPages() const 107 { 108 QList<QWidget*> list; 109 foreach (SelectorItem *item, mItemList) 110 if (item->page()) 111 list << item->page(); 112 return list; 113 } 114 115 116 SelectorItem *VBoxSettingsSelector::findItem (int aId) const 117 { 118 SelectorItem *result = NULL; 119 foreach (SelectorItem *item, mItemList) 120 if (item->id() == aId) 121 { 122 result = item; 123 break; 124 } 125 return result; 126 } 127 128 SelectorItem *VBoxSettingsSelector::findItemByLink (const QString &aLink) const 129 { 130 SelectorItem *result = NULL; 131 foreach (SelectorItem *item, mItemList) 132 if (item->link() == aLink) 133 { 134 result = item; 135 break; 136 } 137 return result; 138 } 139 140 SelectorItem *VBoxSettingsSelector::findItemByPage (VBoxSettingsPage* aPage) const 141 { 142 SelectorItem *result = NULL; 143 foreach (SelectorItem *item, mItemList) 144 if (item->page() == aPage) 145 { 146 result = item; 147 break; 148 } 149 return result; 39 150 } 40 151 … … 90 201 } 91 202 92 void VBoxSettingsTreeViewSelector::addItem (const QIcon &aIcon, 93 const QString &aText, 94 int aId, 95 const QString &aLink) 96 { 97 QTreeWidgetItem *item = new QTreeWidgetItem (mTwSelector, QStringList() << QString (" %1 ").arg (aText) 98 << idToString (aId) 99 << aLink); 100 item->setIcon (treeWidget_Category, aIcon); 203 QWidget *VBoxSettingsTreeViewSelector::addItem (const QIcon &aIcon, 204 int aId, 205 const QString &aLink, 206 VBoxSettingsPage* aPage /* = NULL */, 207 int aParentId /* = -1 */) 208 { 209 QWidget *result = NULL; 210 if (aPage != NULL) 211 { 212 SelectorItem *item = new SelectorItem (aIcon, "", aId, aLink, aPage, aParentId); 213 mItemList.append (item); 214 215 QTreeWidgetItem *twitem = new QTreeWidgetItem (mTwSelector, QStringList() << QString ("") 216 << idToString (aId) 217 << aLink); 218 twitem->setIcon (treeWidget_Category, aIcon); 219 result = aPage; 220 } 221 return result; 222 } 223 224 void VBoxSettingsTreeViewSelector::setItemText (int aId, const QString &aText) 225 { 226 VBoxSettingsSelector::setItemText (aId, aText); 227 QTreeWidgetItem *item = findItem (mTwSelector, idToString (aId), treeWidget_Id); 228 if (item) 229 item->setText (treeWidget_Category, QString (" %1 ").arg (aText)); 101 230 } 102 231 … … 115 244 } 116 245 117 int VBoxSettingsTreeViewSelector::idToIndex (int aId) const 118 { 119 int index = -1; 120 QTreeWidgetItem *item = findItem (mTwSelector, idToString (aId), treeWidget_Id); 121 if (item) 122 index = mTwSelector->indexOfTopLevelItem (item); 123 return index; 124 } 125 126 int VBoxSettingsTreeViewSelector::indexToId (int aIndex) const 246 int VBoxSettingsTreeViewSelector::linkToId (const QString &aLink) const 127 247 { 128 248 int id = -1; 129 QTreeWidgetItem *item = mTwSelector->topLevelItem (aIndex);249 QTreeWidgetItem *item = findItem (mTwSelector, aLink, treeWidget_Link); 130 250 if (item) 131 251 id = item->text (treeWidget_Id).toInt(); … … 133 253 } 134 254 135 int VBoxSettingsTreeViewSelector::linkToId (const QString &aLink) const136 {137 int id = -1;138 QTreeWidgetItem *item = findItem (mTwSelector, aLink, treeWidget_Link);139 if (item)140 id = item->text (treeWidget_Id).toInt();141 return id;142 }143 144 255 145 256 void VBoxSettingsTreeViewSelector::selectById (int aId) … … 155 266 if (item) 156 267 item->setHidden (aShow); 157 }158 159 void VBoxSettingsTreeViewSelector::clear()160 {161 mTwSelector->clear();162 268 } 163 269 … … 184 290 emit categoryChanged (id); 185 291 } 292 } 293 294 void VBoxSettingsTreeViewSelector::clear() 295 { 296 mTwSelector->clear(); 186 297 } 187 298 … … 202 313 * searching the 'aColumn' column. */ 203 314 QTreeWidgetItem* VBoxSettingsTreeViewSelector::findItem (QTreeWidget *aView, 204 const QString &aMatch,205 int aColumn) const315 const QString &aMatch, 316 int aColumn) const 206 317 { 207 318 QList<QTreeWidgetItem*> list = … … 218 329 /* VBoxSettingsToolBarSelector */ 219 330 220 class SelectorAction: public QAction 331 332 class SelectorActionItem: public SelectorItem 221 333 { 222 334 public: 223 SelectorAction (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, QObject *aParent) 224 : QAction (aIcon, aText, aParent) 225 , mId (aId) 226 , mLink (aLink) 227 { 228 setCheckable (true); 229 } 230 231 int id() const { return mId; } 232 QString link() const { return mLink; } 233 234 private: 235 int mId; 236 QString mLink; 335 SelectorActionItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, VBoxSettingsPage* aPage, int aParentId, QObject *aParent) 336 : SelectorItem (aIcon, aText, aId, aLink, aPage, aParentId) 337 , mAction (new QAction (aIcon, aText, aParent)) 338 , mTabWidget (NULL) 339 { 340 mAction->setCheckable (true); 341 } 342 343 QAction *action() const { return mAction; } 344 345 void setTabWidget (QTabWidget *aTabWidget) { mTabWidget = aTabWidget; } 346 QTabWidget *tabWidget() const { return mTabWidget; } 347 348 protected: 349 350 QAction *mAction; 351 QTabWidget *mTabWidget; 237 352 }; 238 353 239 354 VBoxSettingsToolBarSelector::VBoxSettingsToolBarSelector (QWidget *aParent /* = NULL */) 240 : VBoxSettingsSelector (aParent)355 : VBoxSettingsSelector (aParent) 241 356 { 242 357 /* Init the toolbar */ … … 251 366 } 252 367 368 VBoxSettingsToolBarSelector::~VBoxSettingsToolBarSelector() 369 { 370 } 371 253 372 QWidget *VBoxSettingsToolBarSelector::widget() const 254 373 { … … 256 375 } 257 376 258 void VBoxSettingsToolBarSelector::addItem (const QIcon &aIcon, 259 const QString &aText, 260 int aId, 261 const QString &aLink) 262 { 263 SelectorAction *action = new SelectorAction (aIcon, aText, aId, aLink, this); 264 265 mActionGroup->addAction (action); 266 mTbSelector->addAction (action); 377 QWidget *VBoxSettingsToolBarSelector::addItem (const QIcon &aIcon, 378 int aId, 379 const QString &aLink, 380 VBoxSettingsPage* aPage /* = NULL */, 381 int aParentId /* = -1 */) 382 { 383 QWidget *result = NULL; 384 SelectorActionItem *item = new SelectorActionItem (aIcon, "", aId, aLink, aPage, aParentId, this); 385 mItemList.append (item); 386 387 if (aParentId == -1 && 388 aPage != NULL) 389 { 390 mActionGroup->addAction (item->action()); 391 mTbSelector->addAction (item->action()); 392 result = aPage; 393 } 394 else if (aParentId == -1 && 395 aPage == NULL) 396 { 397 mActionGroup->addAction (item->action()); 398 mTbSelector->addAction (item->action()); 399 QTabWidget *tabWidget= new QTabWidget (); 400 // connect (tabWidget, SIGNAL (currentChanged (int)), 401 // this, SLOT (settingsGroupChanged (int))); 402 item->setTabWidget (tabWidget); 403 result = tabWidget; 404 }else 405 { 406 SelectorActionItem *parent = findActionItem (aParentId); 407 if (parent) 408 { 409 QTabWidget *tabWidget = parent->tabWidget(); 410 if (tabWidget) 411 tabWidget->addTab (aPage, aIcon, ""); 412 } 413 } 414 return result; 415 } 416 417 void VBoxSettingsToolBarSelector::setItemText (int aId, const QString &aText) 418 { 419 if (SelectorActionItem *item = findActionItem (aId)) 420 { 421 item->setText (aText); 422 if (item->action()) 423 item->action()->setText (aText); 424 if (item->parentId() && 425 item->page()) 426 { 427 SelectorActionItem *parent = findActionItem (item->parentId()); 428 if (parent && 429 parent->tabWidget()) 430 parent->tabWidget()->setTabText ( 431 parent->tabWidget()->indexOf (item->page()), aText); 432 } 433 } 267 434 } 268 435 … … 270 437 { 271 438 QString result; 272 SelectorAction *action = findAction (aId); 273 if (action) 274 result = action->text(); 439 if (SelectorItem *item = findItem (aId)) 440 result = item->text(); 275 441 return result; 276 442 } … … 278 444 int VBoxSettingsToolBarSelector::currentId () const 279 445 { 280 SelectorAction *action = static_cast<SelectorAction*>(mActionGroup->checkedAction());446 SelectorActionItem *action = findActionItemByAction (mActionGroup->checkedAction()); 281 447 int id = -1; 282 448 if (action) … … 285 451 } 286 452 287 int VBoxSettingsToolBarSelector::idToIndex (int aId) const 288 { 289 int index = -1; 290 QList<QAction*> list = mActionGroup->actions(); 291 for (int a = 0; a < list.count(); ++a) 292 { 293 SelectorAction *sa = static_cast<SelectorAction*> (list.at(a)); 294 if (sa && 295 sa->id() == aId) 296 { 297 index = a; 298 break; 299 } 300 } 301 return index; 302 } 303 304 int VBoxSettingsToolBarSelector::indexToId (int aIndex) const 453 int VBoxSettingsToolBarSelector::linkToId (const QString &aLink) const 305 454 { 306 455 int id = -1; 307 QList<QAction*> list = mActionGroup->actions(); 308 if (aIndex > -1 && 309 aIndex < list.count()) 310 { 311 SelectorAction *sa = static_cast<SelectorAction*> (list.at (aIndex)); 312 if (sa) 313 id = sa->id(); 314 } 456 SelectorItem *item = VBoxSettingsSelector::findItemByLink (aLink); 457 if (item) 458 id = item->id(); 315 459 return id; 316 460 } 317 461 318 int VBoxSettingsToolBarSelector::linkToId (const QString &aLink) const 319 { 320 int id = -1; 321 QList<QAction*> list = mActionGroup->actions(); 322 for (int a = 0; a < list.count(); ++a) 323 { 324 SelectorAction *sa = static_cast<SelectorAction*> (list.at(a)); 325 if (sa && 326 sa->link() == aLink) 327 { 328 id = sa->id(); 329 break; 330 } 331 } 332 return id; 333 } 334 462 QWidget *VBoxSettingsToolBarSelector::idToPage (int aId) const 463 { 464 QWidget *page = NULL; 465 if (SelectorActionItem *item = findActionItem (aId)) 466 { 467 page = item->page(); 468 if (!page) 469 page = item->tabWidget(); 470 } 471 return page; 472 } 473 474 QWidget *VBoxSettingsToolBarSelector::rootPage (int aId) const 475 { 476 QWidget *page = NULL; 477 if (SelectorActionItem *item = findActionItem (aId)) 478 { 479 if (item->parentId() > -1) 480 page = rootPage (item->parentId()); 481 else if (item->page()) 482 page = item->page(); 483 else 484 page = item->tabWidget(); 485 } 486 return page; 487 } 335 488 336 489 void VBoxSettingsToolBarSelector::selectById (int aId) 337 490 { 338 SelectorAction *action = findAction (aId); 339 340 if (action) 341 action->trigger(); 342 } 491 if (SelectorActionItem *item = findActionItem (aId)) 492 { 493 if (item->parentId() != -1) 494 { 495 SelectorActionItem *parent = findActionItem (item->parentId()); 496 if (parent && 497 parent->tabWidget()) 498 { 499 parent->action()->trigger(); 500 parent->tabWidget()->setCurrentIndex ( 501 parent->tabWidget()->indexOf (item->page())); 502 } 503 } 504 else 505 item->action()->trigger(); 506 } 507 } 508 343 509 344 510 void VBoxSettingsToolBarSelector::setVisibleById (int aId, bool aShow) 345 511 { 346 SelectorAction *action = findAction (aId); 347 348 if (action) 349 action->setVisible (aShow); 512 SelectorActionItem *item = findActionItem (aId); 513 514 if (item) 515 { 516 item->action()->setVisible (aShow); 517 if (item->parentId() > -1 && 518 item->page()) 519 { 520 SelectorActionItem *parent = findActionItem (item->parentId()); 521 if (parent && 522 parent->tabWidget()) 523 { 524 if (aShow && 525 parent->tabWidget()->indexOf (item->page()) == -1) 526 parent->tabWidget()->addTab (item->page(), item->text()); 527 else if (!aShow && 528 parent->tabWidget()->indexOf (item->page()) > -1) 529 parent->tabWidget()->removeTab ( 530 parent->tabWidget()->indexOf (item->page())); 531 } 532 } 533 } 534 350 535 } 351 536 … … 364 549 void VBoxSettingsToolBarSelector::settingsGroupChanged (QAction *aAction) 365 550 { 366 SelectorAction *action = static_cast<SelectorAction*> (aAction); 367 if (action) 368 emit categoryChanged (action->id()); 369 } 370 371 SelectorAction* VBoxSettingsToolBarSelector::findAction (int aId) const 372 { 373 int index = idToIndex (aId); 374 SelectorAction *sa = NULL; 375 QList<QAction*> list = mActionGroup->actions(); 376 if (index > -1 && 377 index < list.count()) 378 sa = static_cast<SelectorAction*> (list.at (index)); 379 return sa; 380 } 381 551 SelectorActionItem *item = findActionItemByAction (aAction); 552 if (item) 553 { 554 emit categoryChanged (item->id()); 555 // if (item->page() && 556 // !item->tabWidget()) 557 // emit categoryChanged (item->id()); 558 // else 559 // { 560 // 561 // item->tabWidget()->blockSignals (true); 562 // item->tabWidget()->setCurrentIndex (0); 563 // item->tabWidget()->blockSignals (false); 564 // printf ("%s\n", qPrintable(item->text())); 565 // SelectorActionItem *child = static_cast<SelectorActionItem*> ( 566 // findItemByPage (static_cast<VBoxSettingsPage*> (item->tabWidget()->currentWidget()))); 567 // if (child) 568 // emit categoryChanged (child->id()); 569 // } 570 } 571 } 572 573 void VBoxSettingsToolBarSelector::settingsGroupChanged (int aIndex) 574 { 575 SelectorActionItem *item = findActionItemByTabWidget (qobject_cast<QTabWidget*> (sender()), aIndex); 576 if (item) 577 { 578 if (item->page() && 579 !item->tabWidget()) 580 emit categoryChanged (item->id()); 581 else 582 { 583 SelectorActionItem *child = static_cast<SelectorActionItem*> ( 584 findItemByPage (static_cast<VBoxSettingsPage*> (item->tabWidget()->currentWidget()))); 585 if (child) 586 emit categoryChanged (child->id()); 587 } 588 } 589 } 590 591 SelectorActionItem* VBoxSettingsToolBarSelector::findActionItem (int aId) const 592 { 593 return static_cast<SelectorActionItem*> (VBoxSettingsSelector::findItem (aId)); 594 } 595 596 SelectorActionItem *VBoxSettingsToolBarSelector::findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const 597 { 598 SelectorActionItem *result = NULL; 599 foreach (SelectorItem *item, mItemList) 600 if (static_cast<SelectorActionItem*> (item)->tabWidget() == aTabWidget) 601 { 602 QTabWidget *tw = static_cast<SelectorActionItem*> (item)->tabWidget(); 603 result = static_cast<SelectorActionItem*> ( 604 findItemByPage (static_cast<VBoxSettingsPage*> (tw->widget (aIndex)))); 605 break; 606 } 607 608 return result; 609 610 } 611 612 QList<QWidget*> VBoxSettingsToolBarSelector::rootPages() const 613 { 614 QList<QWidget*> list; 615 foreach (SelectorItem *item, mItemList) 616 { 617 SelectorActionItem *ai = static_cast<SelectorActionItem*> (item); 618 if (ai->parentId() == -1 && 619 ai->page()) 620 list << ai->page(); 621 else if (ai->tabWidget()) 622 list << ai->tabWidget(); 623 } 624 return list; 625 } 626 627 SelectorActionItem *VBoxSettingsToolBarSelector::findActionItemByAction (QAction *aAction) const 628 { 629 SelectorActionItem *result = NULL; 630 foreach (SelectorItem *item, mItemList) 631 if (static_cast<SelectorActionItem*> (item)->action() == aAction) 632 { 633 result = static_cast<SelectorActionItem*> (item); 634 break; 635 } 636 637 return result; 638 } 639 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsHD.cpp
r10167 r10604 889 889 QWidget *current = QApplication::focusWidget(); 890 890 mTwAts->setFocus (Qt::TabFocusReason); 891 current->setFocus (Qt::TabFocusReason); 892 } 893 891 if (current) 892 current->setFocus (Qt::TabFocusReason); 893 } 894
Note:
See TracChangeset
for help on using the changeset viewer.