Changeset 10474 in vbox for trunk/src/VBox/Frontends/VirtualBox4
- Timestamp:
- Jul 10, 2008 3:32:33 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialog.h
r10468 r10474 58 58 virtual void retranslateUi(); 59 59 60 virtual QString dialogTitle() const = 0; 61 QString titleExtension() const; 62 60 63 void setWarning (const QString &aWarning); 61 64 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialogSpecific.h
r10468 r10474 57 57 void retranslateUi(); 58 58 59 QString dialogTitle() const; 60 59 61 private: 60 62 … … 102 104 void retranslateUi(); 103 105 106 QString dialogTitle() const; 107 104 108 private slots: 105 109 … … 111 115 void updateAvailability(); 112 116 VBoxSettingsPage* attachPage (VBoxSettingsPage *aPage); 113 QString dialogTitle() const;114 117 115 118 CMachine mMachine; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsSelector.h
r10468 r10474 28 28 29 29 class QITreeWidget; 30 class VBoxToolBar; 31 class SelectorAction; 30 32 31 33 class QTreeWidget; 32 34 class QTreeWidgetItem; 33 35 class QIcon; 36 class QAction; 37 class QActionGroup; 34 38 35 39 class VBoxSettingsSelector: public QObject … … 57 61 virtual void clear() = 0; 58 62 59 virtual void retranslateUi() = 0; 63 virtual void polish() {}; 64 virtual int minWidth () const { return 0; } 60 65 61 66 signals: … … 87 92 virtual void clear(); 88 93 89 virtual void retranslateUi();94 virtual void polish(); 90 95 91 96 private slots: … … 103 108 }; 104 109 110 class VBoxSettingsToolBarSelector: public VBoxSettingsSelector 111 { 112 Q_OBJECT; 113 114 public: 115 116 VBoxSettingsToolBarSelector (QWidget *aParent = NULL); 117 118 virtual QWidget *widget() const; 119 120 virtual void addItem (const QIcon &aIcon, const QString &aText, int aIndex, const QString &aLink); 121 virtual QString itemText (int aId) const; 122 123 virtual int currentId() const; 124 virtual int idToIndex (int aId) const; 125 virtual int indexToId (int aIndex) const; 126 virtual int linkToId (const QString &aLink) const; 127 virtual void selectById (int aId); 128 virtual void setVisibleById (int aId, bool aShow); 129 130 virtual void clear(); 131 132 virtual int minWidth() const; 133 134 private slots: 135 136 void settingsGroupChanged (QAction *aAction); 137 138 private: 139 140 int findId (int aIndex) const; 141 int findIndex (int aId) const; 142 int findLink (const QString &aLink) const; 143 SelectorAction* findAction (int aId) const; 144 145 /* Private member vars */ 146 VBoxToolBar *mTbSelector; 147 QActionGroup *mActionGroup; 148 }; 149 105 150 #endif /* __VBoxSettingsSelector_h__ */ -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialog.cpp
r10468 r10474 27 27 #include "QIWidgetValidator.h" 28 28 #include "VBoxSettingsSelector.h" 29 #include "VBoxToolBar.h" 29 30 30 31 #ifdef Q_WS_MAC … … 36 37 #include <QPushButton> 37 38 #include <QStackedWidget> 39 40 41 #if MAC_LEOPARD_STYLE 42 # define VBOX_GUI_WITH_TOOLBAR_SETTINGS 43 #endif /* MAC_LEOPARD_STYLE */ 38 44 39 45 VBoxSettingsDialog::VBoxSettingsDialog (QWidget *aParent /* = NULL */) … … 61 67 mLbTitle->setFont (f); 62 68 69 QGridLayout *mainLayout = static_cast<QGridLayout*> (mAllWidget->layout()); 70 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS 71 mSelector = new VBoxSettingsToolBarSelector (this); 72 setUnifiedTitleAndToolBarOnMac (true); 73 addToolBar (qobject_cast<QToolBar*> (mSelector->widget())); 74 /* No title in this mode, we change the title of the window. */ 75 mLbTitle->hide(); 76 mainLayout->setColumnMinimumWidth (0, 0); 77 mainLayout->setHorizontalSpacing (0); 78 #else 63 79 /* Create the classical tree view selector */ 64 80 mSelector = new VBoxSettingsTreeSelector (mAllWidget); 65 QGridLayout *mainLayout = static_cast<QGridLayout*> (mAllWidget->layout());66 81 mainLayout->addWidget (mSelector->widget(), 0, 0, 3, 1); 67 82 mSelector->widget()->setFocus(); 83 #endif 68 84 69 85 /* Creating stack of pages */ … … 165 181 } 166 182 183 QString VBoxSettingsDialog::titleExtension() const 184 { 185 #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS 186 return mSelector->itemText (mSelector->currentId()); 187 #else 188 return tr ("Settings"); 189 #endif 190 } 191 167 192 void VBoxSettingsDialog::categoryChanged (int aId) 168 193 { 169 194 //#ifndef Q_WS_MAC 170 195 #if 1 171 mLbTitle->setText (mSelector->itemText (aId)); 172 mStack->setCurrentIndex (aId); 196 # ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS 197 setWindowTitle (dialogTitle()); 198 # endif 199 mLbTitle->setText (mSelector->itemText (aId)); 200 mStack->setCurrentIndex (aId); 173 201 #else /* Q_WS_MAC */ 174 /* We will update at once later */ 175 setUpdatesEnabled (false); 176 /* Set all tab size policies to ignored */ 177 for (int i = 0; i < mStack->count(); ++i) 178 mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored); 179 /* Set the size policy of the current tab to preferred */ 180 if (mStack->widget (id)) 181 mStack->widget (id)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); 182 /* Set the new current tab */ 183 mLbTitle->setText (::path (aItem)); 184 mStack->setCurrentIndex (id); 185 /* Activate the new layout */ 186 layout()->activate(); 187 setUpdatesEnabled (true); 188 // mAllWidget->hide(); 189 /* Play the resize animation */ 190 ::darwinWindowAnimateResize (this, QRect (x(), y(), 191 minimumSizeHint().width(), minimumSizeHint().height())); 192 // mAllWidget->show(); 193 /* Set the new size to Qt also */ 194 setFixedSize (minimumSizeHint()); 202 int index = mSelector->idToIndex (aId); 203 /* We will update at once later */ 204 setUpdatesEnabled (false); 205 /* Set all tab size policies to ignored */ 206 for (int i = 0; i < mStack->count(); ++i) 207 mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored); 208 /* Set the size policy of the current tab to preferred */ 209 if (mStack->widget (index)) 210 mStack->widget (index)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); 211 /* Set the new current tab */ 212 mLbTitle->setText (::path (aItem)); 213 mStack->setCurrentIndex (index); 214 /* Activate the new layout */ 215 layout()->activate(); 216 setUpdatesEnabled (true); 217 // mAllWidget->hide(); 218 /* Play the resize animation */ 219 ::darwinWindowAnimateResize (this, QRect (x(), y(), 220 minimumSizeHint().width(), minimumSizeHint().height())); 221 // mAllWidget->show(); 222 /* Set the new size to Qt also */ 223 setFixedSize (minimumSizeHint()); 195 224 #endif /* !Q_WS_MAC */ 196 225 } … … 303 332 304 333 /* Resize to the minimum possible size */ 305 resize (minimumSize()); 334 int minWidth = mSelector->minWidth(); 335 QSize s = minimumSize(); 336 if (minWidth > s.width()) 337 s.setWidth (minWidth); 338 resize (s); 306 339 307 340 VBoxGlobal::centerWidget (this, parentWidget()); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialogSpecific.cpp
r10468 r10474 55 55 #endif /* Q_WS_MAC */ 56 56 57 /* Applying language settings */58 retranslateUi();59 60 57 /* Creating settings pages */ 61 58 attachPage (new VBoxGLSettingsGeneral()); … … 71 68 /* Update Selector with available items */ 72 69 updateAvailability(); 70 71 /* Applying language settings */ 72 retranslateUi(); 73 73 } 74 74 … … 107 107 { 108 108 /* Set dialog's name */ 109 setWindowTitle ( tr ("VirtualBox Preferences"));109 setWindowTitle (dialogTitle()); 110 110 111 111 /* Remember old index */ … … 133 133 134 134 /* Translate the selector */ 135 mSelector-> retranslateUi();135 mSelector->polish(); 136 136 137 137 VBoxSettingsDialog::retranslateUi(); … … 142 142 /* Update Selector with available items */ 143 143 updateAvailability(); 144 } 145 146 QString VBoxGLSettingsDlg::dialogTitle() const 147 { 148 return tr ("VirtualBox - %1").arg (titleExtension()); 144 149 } 145 150 … … 192 197 connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)), 193 198 this, SLOT (onMediaEnumerationDone())); 194 195 /* Applying language settings */196 retranslateUi();197 199 198 200 /* Creating settings pages */ … … 255 257 } 256 258 } 259 /* Applying language settings */ 260 retranslateUi(); 257 261 } 258 262 … … 376 380 377 381 /* Translate the selector */ 378 mSelector-> retranslateUi();382 mSelector->polish(); 379 383 380 384 VBoxSettingsDialog::retranslateUi(); … … 391 395 if (!wval->isValid()) 392 396 revalidate (wval); 397 } 398 399 QString VBoxVMSettingsDlg::dialogTitle() const 400 { 401 QString dialogTitle; 402 if (!mMachine.isNull()) 403 dialogTitle = tr ("%1 - %2").arg (mMachine.GetName()) 404 .arg (titleExtension()); 405 return dialogTitle; 393 406 } 394 407 … … 419 432 420 433 return aPage; 421 }422 423 QString VBoxVMSettingsDlg::dialogTitle() const424 {425 QString dialogTitle;426 if (!mMachine.isNull())427 dialogTitle = tr ("%1 - Settings").arg (mMachine.GetName());428 return dialogTitle;429 434 } 430 435 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsSelector.cpp
r10468 r10474 24 24 #include "VBoxSettingsUtils.h" 25 25 #include "QITreeWidget.h" 26 #include "VBoxToolBar.h" 26 27 27 28 enum … … 94 95 const QString &aLink) 95 96 { 96 QTreeWidgetItem *item = NULL; 97 98 item = new QTreeWidgetItem (mTwSelector, QStringList() << QString (" %1 ").arg (aText) 99 << idToString (aId) 100 << aLink); 97 QTreeWidgetItem *item = new QTreeWidgetItem (mTwSelector, QStringList() << QString (" %1 ").arg (aText) 98 << idToString (aId) 99 << aLink); 101 100 item->setIcon (treeWidget_Category, aIcon); 102 101 } … … 163 162 } 164 163 165 void VBoxSettingsTreeSelector:: retranslateUi()164 void VBoxSettingsTreeSelector::polish() 166 165 { 167 166 mTwSelector->setFixedWidth (static_cast<QAbstractItemView*> (mTwSelector) … … 217 216 } 218 217 218 /* VBoxSettingsToolBarSelector */ 219 220 class SelectorAction: public QAction 221 { 222 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; 237 }; 238 239 VBoxSettingsToolBarSelector::VBoxSettingsToolBarSelector (QWidget *aParent /* = NULL */) 240 :VBoxSettingsSelector (aParent) 241 { 242 /* Init the toolbar */ 243 mTbSelector = new VBoxToolBar (aParent); 244 mTbSelector->setUsesTextLabel (true); 245 mTbSelector->setUsesBigPixmaps (true); 246 /* Init the action group for house keeping */ 247 mActionGroup = new QActionGroup (this); 248 mActionGroup->setExclusive (true); 249 connect (mActionGroup, SIGNAL (triggered (QAction*)), 250 this, SLOT (settingsGroupChanged (QAction*))); 251 } 252 253 QWidget *VBoxSettingsToolBarSelector::widget() const 254 { 255 return mTbSelector; 256 } 257 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); 267 } 268 269 QString VBoxSettingsToolBarSelector::itemText (int aId) const 270 { 271 QString result; 272 SelectorAction *action = findAction (aId); 273 if (action) 274 result = action->text(); 275 return result; 276 } 277 278 int VBoxSettingsToolBarSelector::currentId () const 279 { 280 SelectorAction *action = static_cast<SelectorAction*> (mActionGroup->checkedAction()); 281 int id = -1; 282 if (action) 283 id = action->id(); 284 return id; 285 } 286 287 int VBoxSettingsToolBarSelector::idToIndex (int aId) const 288 { 289 return findIndex (aId); 290 } 291 292 int VBoxSettingsToolBarSelector::indexToId (int aIndex) const 293 { 294 return findId (aIndex); 295 } 296 297 int VBoxSettingsToolBarSelector::linkToId (const QString &aLink) const 298 { 299 return findLink (aLink); 300 } 301 302 303 void VBoxSettingsToolBarSelector::selectById (int aId) 304 { 305 SelectorAction *action = findAction (aId); 306 307 if (action) 308 action->trigger(); 309 } 310 311 void VBoxSettingsToolBarSelector::setVisibleById (int aId, bool aShow) 312 { 313 SelectorAction *action = findAction (aId); 314 315 if (action) 316 action->setVisible (aShow); 317 } 318 319 void VBoxSettingsToolBarSelector::clear() 320 { 321 QList<QAction*> list = mActionGroup->actions(); 322 foreach (QAction *action, list) 323 delete action; 324 } 325 326 int VBoxSettingsToolBarSelector::minWidth() const 327 { 328 return mTbSelector->sizeHint().width() + 2 * 10; 329 } 330 331 void VBoxSettingsToolBarSelector::settingsGroupChanged (QAction *aAction) 332 { 333 SelectorAction *action = static_cast<SelectorAction*> (aAction); 334 if (action) 335 emit categoryChanged (action->id()); 336 } 337 338 int VBoxSettingsToolBarSelector::findId (int aIndex) const 339 { 340 int id = -1; 341 QList<QAction*> list = mActionGroup->actions(); 342 if (aIndex > -1 && 343 aIndex < list.count()) 344 { 345 SelectorAction *sa = static_cast<SelectorAction*> (list.at (aIndex)); 346 if (sa) 347 id = sa->id(); 348 } 349 return id; 350 } 351 352 int VBoxSettingsToolBarSelector::findIndex (int aId) const 353 { 354 int index = -1; 355 QList<QAction*> list = mActionGroup->actions(); 356 for (int a = 0; a < list.count(); ++a) 357 { 358 SelectorAction *sa = static_cast<SelectorAction*> (list.at(a)); 359 if (sa && 360 sa->id() == aId) 361 { 362 index = a; 363 break; 364 } 365 } 366 return index; 367 } 368 369 int VBoxSettingsToolBarSelector::findLink (const QString &aLink) const 370 { 371 int id = -1; 372 QList<QAction*> list = mActionGroup->actions(); 373 for (int a = 0; a < list.count(); ++a) 374 { 375 SelectorAction *sa = static_cast<SelectorAction*> (list.at(a)); 376 if (sa && 377 sa->link() == aLink) 378 { 379 id = sa->id(); 380 break; 381 } 382 } 383 return id; 384 } 385 386 SelectorAction* VBoxSettingsToolBarSelector::findAction (int aId) const 387 { 388 int index = findIndex (aId); 389 SelectorAction *sa = NULL; 390 QList<QAction*> list = mActionGroup->actions(); 391 if (index > -1 && 392 index < list.count()) 393 sa = static_cast<SelectorAction*> (list.at (index)); 394 return sa; 395 } 396
Note:
See TracChangeset
for help on using the changeset viewer.