- Timestamp:
- Sep 28, 2016 1:37:50 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.cpp
r64080 r64081 21 21 22 22 /* Qt includes: */ 23 # include <QAction> 23 24 # include <QHeaderView> 25 # include <QLayout> 24 26 # include <QTabWidget> 25 # include <QLayout>26 # include <QAction>27 27 28 28 /* GUI includes: */ 29 # include "QITabWidget.h" 30 # include "QITreeWidget.h" 29 31 # include "UISettingsSelector.h" 32 # include "UIIconPool.h" 30 33 # include "UISettingsPage.h" 31 34 # include "UIToolBar.h" 32 # include "QITreeWidget.h"33 # include "QITabWidget.h"34 # include "UIIconPool.h"35 35 36 36 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 38 38 39 39 /** Tree-widget column sections. */ 40 enum 41 { 42 treeWidget_Category = 0,43 treeWidget_Id,44 treeWidget_Link40 enum TreeWidgetSection 41 { 42 TreeWidgetSection_Category = 0, 43 TreeWidgetSection_Id, 44 TreeWidgetSection_Link 45 45 }; 46 46 47 47 48 48 /** Simple container of all the selector item data. */ 49 class SelectorItem49 class UISelectorItem 50 50 { 51 51 public: 52 52 53 53 /** Constructs selector item. 54 * @param aIconBrings the item icon.55 * @param aTextBrings the item text.56 * @param aIdBrings the item ID.57 * @param aLinkBrings the item link.58 * @param aPage Brings the item page reference.59 * @param aParentIdBrings the item parent ID. */60 SelectorItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, UISettingsPage* aPage, int aParentId)61 : m Icon (aIcon)62 , m Text (aText)63 , m Id (aId)64 , m Link (aLink)65 , m Page (aPage)66 , m ParentId (aParentId)54 * @param icon Brings the item icon. 55 * @param strText Brings the item text. 56 * @param iID Brings the item ID. 57 * @param strLink Brings the item link. 58 * @param pPage Brings the item page reference. 59 * @param iParentID Brings the item parent ID. */ 60 UISelectorItem(const QIcon &icon, const QString &strText, int iID, const QString &strLink, UISettingsPage *pPage, int iParentID) 61 : m_icon(icon) 62 , m_strText(strText) 63 , m_iID(iID) 64 , m_strLink(strLink) 65 , m_pPage(pPage) 66 , m_iParentID(iParentID) 67 67 {} 68 68 69 69 /** Returns the item icon. */ 70 QIcon icon() const { return m Icon; }70 QIcon icon() const { return m_icon; } 71 71 /** Returns the item text. */ 72 QString text() const { return m Text; }72 QString text() const { return m_strText; } 73 73 /** Defines the item @s strText. */ 74 void setText (const QString &aText) { mText = aText; }74 void setText(const QString &strText) { m_strText = strText; } 75 75 /** Returns the item ID. */ 76 int id() const { return m Id; }76 int id() const { return m_iID; } 77 77 /** Returns the item link. */ 78 QString link() const { return m Link; }78 QString link() const { return m_strLink; } 79 79 /** Returns the item page reference. */ 80 UISettingsPage *page() const { return m Page; }80 UISettingsPage *page() const { return m_pPage; } 81 81 /** Returns the item parent ID. */ 82 int parentI d() const { return mParentId; }82 int parentID() const { return m_iParentID; } 83 83 84 84 protected: 85 85 86 86 /** Holds the item icon. */ 87 QIcon m Icon;87 QIcon m_icon; 88 88 /** Holds the item text. */ 89 QString m Text;89 QString m_strText; 90 90 /** Holds the item ID. */ 91 int m Id;91 int m_iID; 92 92 /** Holds the item link. */ 93 QString m Link;93 QString m_strLink; 94 94 /** Holds the item page reference. */ 95 UISettingsPage * mPage;95 UISettingsPage *m_pPage; 96 96 /** Holds the item parent ID. */ 97 int m ParentId;97 int m_iParentID; 98 98 }; 99 99 … … 103 103 *********************************************************************************************************************************/ 104 104 105 UISettingsSelector::UISettingsSelector (QWidget *aParent /* = NULL*/)106 : QObject (aParent)105 UISettingsSelector::UISettingsSelector(QWidget *pParent /* = 0 */) 106 : QObject(pParent) 107 107 { 108 108 } … … 110 110 UISettingsSelector::~UISettingsSelector() 111 111 { 112 qDeleteAll (mItemList);113 m ItemList.clear();114 } 115 116 void UISettingsSelector::setItemText (int aId, const QString &aText)117 { 118 if ( SelectorItem *item = findItem (aId))119 item->setText (aText);120 } 121 122 QString UISettingsSelector::itemTextByPage (UISettingsPage *aPage) const123 { 124 QString text;125 if ( SelectorItem *item = findItemByPage (aPage))126 text = item->text();127 return text;128 } 129 130 QWidget *UISettingsSelector::idToPage (int aId) const131 { 132 UISettingsPage *p age = NULL;133 if ( SelectorItem *item = findItem (aId))134 p age = item->page();135 return p age;112 qDeleteAll(m_list); 113 m_list.clear(); 114 } 115 116 void UISettingsSelector::setItemText(int iID, const QString &strText) 117 { 118 if (UISelectorItem *pTtem = findItem(iID)) 119 pTtem->setText(strText); 120 } 121 122 QString UISettingsSelector::itemTextByPage(UISettingsPage *pPage) const 123 { 124 QString strText; 125 if (UISelectorItem *pItem = findItemByPage(pPage)) 126 strText = pItem->text(); 127 return strText; 128 } 129 130 QWidget *UISettingsSelector::idToPage(int iID) const 131 { 132 UISettingsPage *pPage = 0; 133 if (UISelectorItem *pItem = findItem(iID)) 134 pPage = pItem->page(); 135 return pPage; 136 136 } 137 137 … … 139 139 { 140 140 QList<UISettingsPage*> list; 141 foreach ( SelectorItem *item, mItemList)142 if ( item->page())143 list << item->page();141 foreach (UISelectorItem *pItem, m_list) 142 if (pItem->page()) 143 list << pItem->page(); 144 144 return list; 145 145 } … … 148 148 { 149 149 QList<QWidget*> list; 150 foreach ( SelectorItem *item, mItemList)151 if ( item->page())152 list << item->page();150 foreach (UISelectorItem *pItem, m_list) 151 if (pItem->page()) 152 list << pItem->page(); 153 153 return list; 154 154 } 155 155 156 SelectorItem *UISettingsSelector::findItem (int aId) const157 { 158 SelectorItem *result = NULL;159 foreach ( SelectorItem *item, mItemList)160 if ( item->id() == aId)161 { 162 result = item;156 UISelectorItem *UISettingsSelector::findItem(int iID) const 157 { 158 UISelectorItem *pResult = 0; 159 foreach (UISelectorItem *pItem, m_list) 160 if (pItem->id() == iID) 161 { 162 pResult = pItem; 163 163 break; 164 164 } 165 return result;166 } 167 168 SelectorItem *UISettingsSelector::findItemByLink (const QString &aLink) const169 { 170 SelectorItem *result = NULL;171 foreach ( SelectorItem *item, mItemList)172 if ( item->link() == aLink)173 { 174 result = item;165 return pResult; 166 } 167 168 UISelectorItem *UISettingsSelector::findItemByLink(const QString &strLink) const 169 { 170 UISelectorItem *pResult = 0; 171 foreach (UISelectorItem *pItem, m_list) 172 if (pItem->link() == strLink) 173 { 174 pResult = pItem; 175 175 break; 176 176 } 177 return result;178 } 179 180 SelectorItem *UISettingsSelector::findItemByPage (UISettingsPage* aPage) const181 { 182 SelectorItem *result = NULL;183 foreach ( SelectorItem *item, mItemList)184 if ( item->page() == aPage)185 { 186 result = item;177 return pResult; 178 } 179 180 UISelectorItem *UISettingsSelector::findItemByPage(UISettingsPage *pPage) const 181 { 182 UISelectorItem *pResult = 0; 183 foreach (UISelectorItem *pItem, m_list) 184 if (pItem->page() == pPage) 185 { 186 pResult = pItem; 187 187 break; 188 188 } 189 return result;189 return pResult; 190 190 } 191 191 … … 195 195 *********************************************************************************************************************************/ 196 196 197 static QString path (QTreeWidgetItem *aItem)198 { 199 static QString s ep = ": ";200 QString p;201 QTreeWidgetItem *cur = aItem;202 while ( cur)203 { 204 if (! p.isNull())205 p = sep + p;206 p = cur->text (treeWidget_Category).simplified() + p;207 cur = cur->parent();208 } 209 return p;210 } 211 212 UISettingsSelectorTreeView::UISettingsSelectorTreeView (QWidget *aParent /* = NULL*/)213 : UISettingsSelector (aParent)214 { 215 m TwSelector = new QITreeWidget (aParent);197 static QString path(const QTreeWidgetItem *pItem) 198 { 199 static QString strSep = ": "; 200 QString strPath; 201 const QTreeWidgetItem *pCurrentItem = pItem; 202 while (pCurrentItem) 203 { 204 if (!strPath.isNull()) 205 strPath = strSep + strPath; 206 strPath = pCurrentItem->text(TreeWidgetSection_Category).simplified() + strPath; 207 pCurrentItem = pCurrentItem->parent(); 208 } 209 return strPath; 210 } 211 212 UISettingsSelectorTreeView::UISettingsSelectorTreeView(QWidget *pParent /* = 0 */) 213 : UISettingsSelector(pParent) 214 { 215 m_pTreeWidget = new QITreeWidget(pParent); 216 216 /* Configure the selector: */ 217 QSizePolicy sizePolicy 218 sizePolicy.setHorizontalStretch 219 sizePolicy.setVerticalStretch 220 sizePolicy.setHeightForWidth (mTwSelector->sizePolicy().hasHeightForWidth());217 QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); 218 sizePolicy.setHorizontalStretch(0); 219 sizePolicy.setVerticalStretch(0); 220 sizePolicy.setHeightForWidth(m_pTreeWidget->sizePolicy().hasHeightForWidth()); 221 221 const QStyle *pStyle = QApplication::style(); 222 222 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 223 m TwSelector->setSizePolicy(sizePolicy);224 m TwSelector->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);225 m TwSelector->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);226 m TwSelector->setRootIsDecorated(false);227 m TwSelector->setUniformRowHeights(true);228 m TwSelector->setIconSize(QSize((int)(1.5 * iIconMetric), (int)(1.5 * iIconMetric)));223 m_pTreeWidget->setSizePolicy(sizePolicy); 224 m_pTreeWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 225 m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 226 m_pTreeWidget->setRootIsDecorated(false); 227 m_pTreeWidget->setUniformRowHeights(true); 228 m_pTreeWidget->setIconSize(QSize((int)(1.5 * iIconMetric), (int)(1.5 * iIconMetric))); 229 229 /* Add the columns: */ 230 m TwSelector->headerItem()->setText (treeWidget_Category, "Category");231 m TwSelector->headerItem()->setText (treeWidget_Id, "[id]");232 m TwSelector->headerItem()->setText (treeWidget_Link, "[link]");230 m_pTreeWidget->headerItem()->setText(TreeWidgetSection_Category, "Category"); 231 m_pTreeWidget->headerItem()->setText(TreeWidgetSection_Id, "[id]"); 232 m_pTreeWidget->headerItem()->setText(TreeWidgetSection_Link, "[link]"); 233 233 /* Hide unnecessary columns and header: */ 234 m TwSelector->header()->hide();235 m TwSelector->hideColumn (treeWidget_Id);236 m TwSelector->hideColumn (treeWidget_Link);234 m_pTreeWidget->header()->hide(); 235 m_pTreeWidget->hideColumn(TreeWidgetSection_Id); 236 m_pTreeWidget->hideColumn(TreeWidgetSection_Link); 237 237 /* Setup connections: */ 238 connect (mTwSelector, SIGNAL (currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),239 this, SLOT (settingsGroupChanged(QTreeWidgetItem *, QTreeWidgetItem*)));238 connect(m_pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), 239 this, SLOT(sltSettingsGroupChanged(QTreeWidgetItem *, QTreeWidgetItem*))); 240 240 } 241 241 242 242 QWidget *UISettingsSelectorTreeView::widget() const 243 243 { 244 return m TwSelector;245 } 246 247 QWidget *UISettingsSelectorTreeView::addItem 248 249 250 int aId,251 const QString &aLink,252 UISettingsPage* aPage /* = NULL*/,253 int aParentId/* = -1 */)254 { 255 QWidget * result = NULL;256 if ( aPage != NULL)257 { 258 QIcon icon = UIIconPool::iconSet(strMediumIcon);259 260 SelectorItem *item = new SelectorItem (icon, "", aId, aLink, aPage, aParentId);261 m ItemList.append (item);262 263 QTreeWidgetItem * twitem = new QTreeWidgetItem (mTwSelector, QStringList() << QString("")264 << idToString (aId)265 << aLink);266 twitem->setIcon (treeWidget_Category, item->icon());267 aPage->setContentsMargins(0, 0, 0, 0);268 aPage->layout()->setContentsMargins(0, 0, 0, 0);269 result = aPage;270 } 271 return result;272 } 273 274 void UISettingsSelectorTreeView::setItemText (int aId, const QString &aText)275 { 276 UISettingsSelector::setItemText (aId, aText);277 QTreeWidgetItem * item = findItem (mTwSelector, idToString (aId), treeWidget_Id);278 if ( item)279 item->setText (treeWidget_Category, QString (" %1 ").arg (aText));280 } 281 282 QString UISettingsSelectorTreeView::itemText (int aId) const283 { 284 return pagePath (idToString (aId));285 } 286 287 int UISettingsSelectorTreeView::currentId 288 { 289 int i d= -1;290 QTreeWidgetItem *item = mTwSelector->currentItem();291 if ( item)292 i d = item->text (treeWidget_Id).toInt();293 return i d;294 } 295 296 int UISettingsSelectorTreeView::linkToId (const QString &aLink) const297 { 298 int i d= -1;299 QTreeWidgetItem *item = findItem (mTwSelector, aLink, treeWidget_Link);300 if ( item)301 i d = item->text (treeWidget_Id).toInt();302 return i d;303 } 304 305 void UISettingsSelectorTreeView::selectById (int aId)306 { 307 QTreeWidgetItem * item = findItem (mTwSelector, idToString (aId), treeWidget_Id);308 if ( item)309 m TwSelector->setCurrentItem (item);310 } 311 312 void UISettingsSelectorTreeView::setVisibleById (int aId, bool aShow)313 { 314 QTreeWidgetItem * item = findItem (mTwSelector, idToString (aId), treeWidget_Id);315 if ( item)316 item->setHidden (!aShow);244 return m_pTreeWidget; 245 } 246 247 QWidget *UISettingsSelectorTreeView::addItem(const QString & /* strBigIcon */, 248 const QString &strMediumIcon , 249 const QString & /* strSmallIcon */, 250 int iID, 251 const QString &strLink, 252 UISettingsPage *pPage /* = 0 */, 253 int iParentID /* = -1 */) 254 { 255 QWidget *pResult = 0; 256 if (pPage != 0) 257 { 258 const QIcon icon = UIIconPool::iconSet(strMediumIcon); 259 260 UISelectorItem *pItem = new UISelectorItem(icon, "", iID, strLink, pPage, iParentID); 261 m_list.append(pItem); 262 263 QTreeWidgetItem *pTwItem = new QTreeWidgetItem(m_pTreeWidget, QStringList() << QString("") 264 << idToString(iID) 265 << strLink); 266 pTwItem->setIcon(TreeWidgetSection_Category, pItem->icon()); 267 pPage->setContentsMargins(0, 0, 0, 0); 268 pPage->layout()->setContentsMargins(0, 0, 0, 0); 269 pResult = pPage; 270 } 271 return pResult; 272 } 273 274 void UISettingsSelectorTreeView::setItemText(int iID, const QString &strText) 275 { 276 UISettingsSelector::setItemText(iID, strText); 277 QTreeWidgetItem *pItem = findItem(m_pTreeWidget, idToString(iID), TreeWidgetSection_Id); 278 if (pItem) 279 pItem->setText(TreeWidgetSection_Category, QString(" %1 ").arg(strText)); 280 } 281 282 QString UISettingsSelectorTreeView::itemText(int iID) const 283 { 284 return pagePath(idToString(iID)); 285 } 286 287 int UISettingsSelectorTreeView::currentId() const 288 { 289 int iID = -1; 290 const QTreeWidgetItem *pItem = m_pTreeWidget->currentItem(); 291 if (pItem) 292 iID = pItem->text(TreeWidgetSection_Id).toInt(); 293 return iID; 294 } 295 296 int UISettingsSelectorTreeView::linkToId(const QString &strLink) const 297 { 298 int iID = -1; 299 const QTreeWidgetItem *pItem = findItem(m_pTreeWidget, strLink, TreeWidgetSection_Link); 300 if (pItem) 301 iID = pItem->text(TreeWidgetSection_Id).toInt(); 302 return iID; 303 } 304 305 void UISettingsSelectorTreeView::selectById(int iID) 306 { 307 QTreeWidgetItem *pItem = findItem(m_pTreeWidget, idToString(iID), TreeWidgetSection_Id); 308 if (pItem) 309 m_pTreeWidget->setCurrentItem(pItem); 310 } 311 312 void UISettingsSelectorTreeView::setVisibleById(int iID, bool fVisible) 313 { 314 QTreeWidgetItem *pItem = findItem(m_pTreeWidget, idToString(iID), TreeWidgetSection_Id); 315 if (pItem) 316 pItem->setHidden(!fVisible); 317 317 } 318 318 … … 322 322 const QStyle *pStyle = QApplication::style(); 323 323 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 324 int iItemWidth = static_cast<QAbstractItemView*>(m TwSelector)->sizeHintForColumn(treeWidget_Category);324 int iItemWidth = static_cast<QAbstractItemView*>(m_pTreeWidget)->sizeHintForColumn(TreeWidgetSection_Category); 325 325 int iItemHeight = qMax((int)(iIconMetric * 1.5) /* icon height */, 326 m TwSelector->fontMetrics().height() /* text height */);326 m_pTreeWidget->fontMetrics().height() /* text height */); 327 327 /* Add some margin to every item in the tree: */ 328 328 iItemHeight += 4 /* margin itself */ * 2 /* margin count */; 329 329 /* Set final size hint for items: */ 330 m TwSelector->setSizeHintForItems(QSize(iItemWidth , iItemHeight));330 m_pTreeWidget->setSizeHintForItems(QSize(iItemWidth , iItemHeight)); 331 331 332 332 /* Adjust selector width/height: */ 333 m TwSelector->setFixedWidth(iItemWidth + 2 * mTwSelector->frameWidth());334 m TwSelector->setMinimumHeight(mTwSelector->topLevelItemCount() * iItemHeight +335 1 /* margin itself */ * 2 /* margin count */);333 m_pTreeWidget->setFixedWidth(iItemWidth + 2 * m_pTreeWidget->frameWidth()); 334 m_pTreeWidget->setMinimumHeight(m_pTreeWidget->topLevelItemCount() * iItemHeight + 335 1 /* margin itself */ * 2 /* margin count */); 336 336 337 337 /* Sort selector by the id column: */ 338 m TwSelector->sortItems(treeWidget_Id, Qt::AscendingOrder);338 m_pTreeWidget->sortItems(TreeWidgetSection_Id, Qt::AscendingOrder); 339 339 340 340 /* Resize column(s) to content: */ 341 m TwSelector->resizeColumnToContents(treeWidget_Category);342 } 343 344 void UISettingsSelectorTreeView::s ettingsGroupChanged (QTreeWidgetItem *aItem,345 QTreeWidgetItem * /* aPrevItem */)346 { 347 if ( aItem)348 { 349 int id = aItem->text (treeWidget_Id).toInt();350 Assert (id>= 0);351 emit categoryChanged (id);341 m_pTreeWidget->resizeColumnToContents(TreeWidgetSection_Category); 342 } 343 344 void UISettingsSelectorTreeView::sltSettingsGroupChanged(QTreeWidgetItem *pItem, 345 QTreeWidgetItem * /* pPrevItem */) 346 { 347 if (pItem) 348 { 349 const int iID = pItem->text(TreeWidgetSection_Id).toInt(); 350 Assert(iID >= 0); 351 emit categoryChanged(iID); 352 352 } 353 353 } … … 355 355 void UISettingsSelectorTreeView::clear() 356 356 { 357 m TwSelector->clear();358 } 359 360 QString UISettingsSelectorTreeView::pagePath (const QString &aMatch) const361 { 362 QTreeWidgetItem *li=363 findItem (mTwSelector,364 aMatch,365 treeWidget_Id);366 return ::path (li);367 } 368 369 QTreeWidgetItem * UISettingsSelectorTreeView::findItem (QTreeWidget *aView,370 const QString &aMatch,371 int aColumn) const357 m_pTreeWidget->clear(); 358 } 359 360 QString UISettingsSelectorTreeView::pagePath(const QString &strMatch) const 361 { 362 const QTreeWidgetItem *pTreeItem = 363 findItem(m_pTreeWidget, 364 strMatch, 365 TreeWidgetSection_Id); 366 return ::path(pTreeItem); 367 } 368 369 QTreeWidgetItem *UISettingsSelectorTreeView::findItem(QTreeWidget *pView, 370 const QString &strMatch, 371 int iColumn) const 372 372 { 373 373 QList<QTreeWidgetItem*> list = 374 aView->findItems (aMatch, Qt::MatchExactly, aColumn);375 376 return list.count() ? list 377 } 378 379 QString UISettingsSelectorTreeView::idToString (int aId) const380 { 381 return QString ("%1").arg (aId, 2, 10, QLatin1Char('0'));374 pView->findItems(strMatch, Qt::MatchExactly, iColumn); 375 376 return list.count() ? list[0] : 0; 377 } 378 379 QString UISettingsSelectorTreeView::idToString(int iID) const 380 { 381 return QString("%1").arg(iID, 2, 10, QLatin1Char('0')); 382 382 } 383 383 … … 387 387 *********************************************************************************************************************************/ 388 388 389 /** SelectorItem subclass providing GUI389 /** UISelectorItem subclass providing GUI 390 390 * with the tab-widget selector item. */ 391 class SelectorActionItem: publicSelectorItem391 class UISelectorActionItem : public UISelectorItem 392 392 { 393 393 public: 394 394 395 395 /** Constructs selector item. 396 * @param aIconBrings the item icon.397 * @param aTextBrings the item text.398 * @param aIdBrings the item ID.399 * @param aLinkBrings the item link.400 * @param aPage Brings the item page reference.401 * @param aParentIdBrings the item parent ID.402 * @param aParent Brings the item parent. */403 SelectorActionItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, UISettingsPage* aPage, int aParentId, QObject *aParent)404 : SelectorItem (aIcon, aText, aId, aLink, aPage, aParentId)405 , m Action (new QAction (aIcon, aText, aParent))406 , m TabWidget (NULL)407 { 408 m Action->setCheckable(true);396 * @param icon Brings the item icon. 397 * @param strText Brings the item text. 398 * @param iID Brings the item ID. 399 * @param strLink Brings the item link. 400 * @param pPage Brings the item page reference. 401 * @param iParentID Brings the item parent ID. 402 * @param pParent Brings the item parent. */ 403 UISelectorActionItem(const QIcon &icon, const QString &strText, int iID, const QString &strLink, UISettingsPage *pPage, int iParentID, QObject *pParent) 404 : UISelectorItem(icon, strText, iID, strLink, pPage, iParentID) 405 , m_pAction(new QAction(icon, strText, pParent)) 406 , m_pTabWidget(0) 407 { 408 m_pAction->setCheckable(true); 409 409 } 410 410 411 411 /** Returns the action instance. */ 412 QAction *action() const { return m Action; }412 QAction *action() const { return m_pAction; } 413 413 414 414 /** Defines the @a pTabWidget instance. */ 415 void setTabWidget (QTabWidget *aTabWidget) { mTabWidget = aTabWidget; }415 void setTabWidget(QTabWidget *pTabWidget) { m_pTabWidget = pTabWidget; } 416 416 /** Returns the tab-widget instance. */ 417 QTabWidget *tabWidget() const { return m TabWidget; }417 QTabWidget *tabWidget() const { return m_pTabWidget; } 418 418 419 419 protected: 420 420 421 421 /** Holds the action instance. */ 422 QAction *m Action;422 QAction *m_pAction; 423 423 /** Holds the tab-widget instance. */ 424 QTabWidget *m TabWidget;424 QTabWidget *m_pTabWidget; 425 425 }; 426 426 427 427 428 UISettingsSelectorToolBar::UISettingsSelectorToolBar (QWidget *aParent /* = NULL*/)429 : UISettingsSelector (aParent)428 UISettingsSelectorToolBar::UISettingsSelectorToolBar(QWidget *pParent /* = 0 */) 429 : UISettingsSelector(pParent) 430 430 { 431 431 /* Init the toolbar: */ 432 m TbSelector = new UIToolBar (aParent);433 m TbSelector->setUseTextLabels(true);434 m TbSelector->setIconSize (QSize(32, 32));432 m_pToolBar = new UIToolBar(pParent); 433 m_pToolBar->setUseTextLabels(true); 434 m_pToolBar->setIconSize(QSize(32, 32)); 435 435 #ifdef VBOX_WS_MAC 436 m TbSelector->setShowToolBarButton(false);436 m_pToolBar->setShowToolBarButton(false); 437 437 #endif /* VBOX_WS_MAC */ 438 438 /* Init the action group for house keeping: */ 439 m ActionGroup = new QActionGroup(this);440 m ActionGroup->setExclusive(true);441 connect (mActionGroup, SIGNAL (triggered(QAction*)),442 this, SLOT (settingsGroupChanged(QAction*)));439 m_pActionGroup = new QActionGroup(this); 440 m_pActionGroup->setExclusive(true); 441 connect(m_pActionGroup, SIGNAL(triggered(QAction*)), 442 this, SLOT(sltSettingsGroupChanged(QAction*))); 443 443 } 444 444 445 445 UISettingsSelectorToolBar::~UISettingsSelectorToolBar() 446 446 { 447 delete m TbSelector;447 delete m_pToolBar; 448 448 } 449 449 450 450 QWidget *UISettingsSelectorToolBar::widget() const 451 451 { 452 return m TbSelector;453 } 454 455 QWidget *UISettingsSelectorToolBar::addItem 456 457 458 int aId,459 const QString &aLink,460 UISettingsPage* aPage /* = NULL*/,461 int aParentId/* = -1 */)462 { 463 QIcon icon = UIIconPool::iconSet(strBigIcon);464 465 QWidget * result = NULL;466 SelectorActionItem *item = new SelectorActionItem (icon, "", aId, aLink, aPage, aParentId, this);467 m ItemList.append (item);468 469 if ( aParentId== -1 &&470 aPage != NULL)471 { 472 m ActionGroup->addAction (item->action());473 m TbSelector->addAction (item->action());474 aPage->setContentsMargins(0, 0, 0, 0);475 aPage->layout()->setContentsMargins(0, 0, 0, 0);476 result = aPage;477 } 478 else if ( aParentId== -1 &&479 aPage == NULL)480 { 481 m ActionGroup->addAction (item->action());482 m TbSelector->addAction (item->action());483 QITabWidget * tabWidget= new QITabWidget();484 tabWidget->setIconSize(QSize(16, 16));485 tabWidget->setContentsMargins(0, 0, 0, 0);486 // connect (tabWidget, SIGNAL (currentChanged(int)),487 // this, SLOT (settingsGroupChanged(int)));488 item->setTabWidget (tabWidget);489 result = tabWidget;452 return m_pToolBar; 453 } 454 455 QWidget *UISettingsSelectorToolBar::addItem(const QString &strBigIcon, 456 const QString & /* strMediumIcon */, 457 const QString &strSmallIcon, 458 int iID, 459 const QString &strLink, 460 UISettingsPage *pPage /* = 0 */, 461 int iParentID /* = -1 */) 462 { 463 const QIcon icon = UIIconPool::iconSet(strBigIcon); 464 465 QWidget *pResult = 0; 466 UISelectorActionItem *pItem = new UISelectorActionItem(icon, "", iID, strLink, pPage, iParentID, this); 467 m_list.append(pItem); 468 469 if (iParentID == -1 && 470 pPage != 0) 471 { 472 m_pActionGroup->addAction(pItem->action()); 473 m_pToolBar->addAction(pItem->action()); 474 pPage->setContentsMargins(0, 0, 0, 0); 475 pPage->layout()->setContentsMargins(0, 0, 0, 0); 476 pResult = pPage; 477 } 478 else if (iParentID == -1 && 479 pPage == 0) 480 { 481 m_pActionGroup->addAction(pItem->action()); 482 m_pToolBar->addAction(pItem->action()); 483 QITabWidget *pTabWidget = new QITabWidget(); 484 pTabWidget->setIconSize(QSize(16, 16)); 485 pTabWidget->setContentsMargins(0, 0, 0, 0); 486 // connect(pTabWidget, SIGNAL(currentChanged(int)), 487 // this, SLOT(sltSettingsGroupChanged(int))); 488 pItem->setTabWidget(pTabWidget); 489 pResult = pTabWidget; 490 490 } 491 491 else 492 492 { 493 SelectorActionItem *parent = findActionItem (aParentId);494 if (p arent)495 { 496 QTabWidget * tabWidget = parent->tabWidget();497 aPage->setContentsMargins(9, 5, 9, 9);498 aPage->layout()->setContentsMargins(0, 0, 0, 0);499 QIcon icon1 = UIIconPool::iconSet(strSmallIcon);500 if ( tabWidget)501 tabWidget->addTab (aPage, icon1, "");502 } 503 } 504 return result;505 } 506 507 void UISettingsSelectorToolBar::setItemText (int aId, const QString &aText)508 { 509 if ( SelectorActionItem *item = findActionItem (aId))510 { 511 item->setText (aText);512 if ( item->action())513 item->action()->setText (aText);514 if ( item->parentId() &&515 item->page())516 { 517 SelectorActionItem *parent = findActionItem (item->parentId());518 if (p arent &&519 p arent->tabWidget())520 p arent->tabWidget()->setTabText(521 p arent->tabWidget()->indexOf (item->page()), aText);522 } 523 } 524 } 525 526 QString UISettingsSelectorToolBar::itemText (int aId) const527 { 528 QString result;529 if ( SelectorItem *item = findItem (aId))530 result = item->text();531 return result;532 } 533 534 int UISettingsSelectorToolBar::currentId 535 { 536 SelectorActionItem *action = findActionItemByAction (mActionGroup->checkedAction());537 int i d= -1;538 if ( action)539 i d = action->id();540 return i d;541 } 542 543 int UISettingsSelectorToolBar::linkToId (const QString &aLink) const544 { 545 int i d= -1;546 SelectorItem *item = UISettingsSelector::findItemByLink (aLink);547 if ( item)548 i d = item->id();549 return i d;550 } 551 552 QWidget *UISettingsSelectorToolBar::idToPage (int aId) const553 { 554 QWidget *p age = NULL;555 if ( SelectorActionItem *item = findActionItem (aId))556 { 557 p age = item->page();558 if (!p age)559 p age = item->tabWidget();560 } 561 return p age;562 } 563 564 QWidget *UISettingsSelectorToolBar::rootPage (int aId) const565 { 566 QWidget *p age = NULL;567 if ( SelectorActionItem *item = findActionItem (aId))568 { 569 if ( item->parentId() > -1)570 p age = rootPage (item->parentId());571 else if ( item->page())572 p age = item->page();493 UISelectorActionItem *pParent = findActionItem(iParentID); 494 if (pParent) 495 { 496 QTabWidget *pTabWidget = pParent->tabWidget(); 497 pPage->setContentsMargins(9, 5, 9, 9); 498 pPage->layout()->setContentsMargins(0, 0, 0, 0); 499 const QIcon icon1 = UIIconPool::iconSet(strSmallIcon); 500 if (pTabWidget) 501 pTabWidget->addTab(pPage, icon1, ""); 502 } 503 } 504 return pResult; 505 } 506 507 void UISettingsSelectorToolBar::setItemText(int iID, const QString &strText) 508 { 509 if (UISelectorActionItem *pItem = findActionItem(iID)) 510 { 511 pItem->setText(strText); 512 if (pItem->action()) 513 pItem->action()->setText(strText); 514 if (pItem->parentID() && 515 pItem->page()) 516 { 517 const UISelectorActionItem *pParent = findActionItem(pItem->parentID()); 518 if (pParent && 519 pParent->tabWidget()) 520 pParent->tabWidget()->setTabText( 521 pParent->tabWidget()->indexOf(pItem->page()), strText); 522 } 523 } 524 } 525 526 QString UISettingsSelectorToolBar::itemText(int iID) const 527 { 528 QString strResult; 529 if (UISelectorItem *pItem = findItem(iID)) 530 strResult = pItem->text(); 531 return strResult; 532 } 533 534 int UISettingsSelectorToolBar::currentId() const 535 { 536 const UISelectorActionItem *pAction = findActionItemByAction(m_pActionGroup->checkedAction()); 537 int iID = -1; 538 if (pAction) 539 iID = pAction->id(); 540 return iID; 541 } 542 543 int UISettingsSelectorToolBar::linkToId(const QString &strLink) const 544 { 545 int iID = -1; 546 const UISelectorItem *pItem = UISettingsSelector::findItemByLink(strLink); 547 if (pItem) 548 iID = pItem->id(); 549 return iID; 550 } 551 552 QWidget *UISettingsSelectorToolBar::idToPage(int iID) const 553 { 554 QWidget *pPage = 0; 555 if (const UISelectorActionItem *pItem = findActionItem(iID)) 556 { 557 pPage = pItem->page(); 558 if (!pPage) 559 pPage = pItem->tabWidget(); 560 } 561 return pPage; 562 } 563 564 QWidget *UISettingsSelectorToolBar::rootPage(int iID) const 565 { 566 QWidget *pPage = 0; 567 if (const UISelectorActionItem *pItem = findActionItem(iID)) 568 { 569 if (pItem->parentID() > -1) 570 pPage = rootPage(pItem->parentID()); 571 else if (pItem->page()) 572 pPage = pItem->page(); 573 573 else 574 p age = item->tabWidget();575 } 576 return p age;577 } 578 579 void UISettingsSelectorToolBar::selectById (int aId)580 { 581 if ( SelectorActionItem *item = findActionItem (aId))582 { 583 if ( item->parentId() != -1)584 { 585 SelectorActionItem *parent = findActionItem (item->parentId());586 if (p arent &&587 p arent->tabWidget())574 pPage = pItem->tabWidget(); 575 } 576 return pPage; 577 } 578 579 void UISettingsSelectorToolBar::selectById(int iID) 580 { 581 if (const UISelectorActionItem *pItem = findActionItem(iID)) 582 { 583 if (pItem->parentID() != -1) 584 { 585 const UISelectorActionItem *pParent = findActionItem(pItem->parentID()); 586 if (pParent && 587 pParent->tabWidget()) 588 588 { 589 p arent->action()->trigger();590 p arent->tabWidget()->setCurrentIndex(591 p arent->tabWidget()->indexOf (item->page()));589 pParent->action()->trigger(); 590 pParent->tabWidget()->setCurrentIndex( 591 pParent->tabWidget()->indexOf(pItem->page())); 592 592 } 593 593 } 594 594 else 595 item->action()->trigger();596 } 597 } 598 599 void UISettingsSelectorToolBar::setVisibleById (int aId, bool aShow)600 { 601 SelectorActionItem *item = findActionItem (aId);602 603 if ( item)604 { 605 item->action()->setVisible (aShow);606 if ( item->parentId() > -1 &&607 item->page())608 { 609 SelectorActionItem *parent = findActionItem (item->parentId());610 if (p arent &&611 p arent->tabWidget())595 pItem->action()->trigger(); 596 } 597 } 598 599 void UISettingsSelectorToolBar::setVisibleById(int iID, bool fVisible) 600 { 601 const UISelectorActionItem *pItem = findActionItem(iID); 602 603 if (pItem) 604 { 605 pItem->action()->setVisible(fVisible); 606 if (pItem->parentID() > -1 && 607 pItem->page()) 608 { 609 const UISelectorActionItem *pParent = findActionItem(pItem->parentID()); 610 if (pParent && 611 pParent->tabWidget()) 612 612 { 613 if ( aShow&&614 p arent->tabWidget()->indexOf (item->page()) == -1)615 p arent->tabWidget()->addTab (item->page(), item->text());616 else if (! aShow&&617 p arent->tabWidget()->indexOf (item->page()) > -1)618 p arent->tabWidget()->removeTab(619 p arent->tabWidget()->indexOf (item->page()));613 if (fVisible && 614 pParent->tabWidget()->indexOf(pItem->page()) == -1) 615 pParent->tabWidget()->addTab(pItem->page(), pItem->text()); 616 else if (!fVisible && 617 pParent->tabWidget()->indexOf(pItem->page()) > -1) 618 pParent->tabWidget()->removeTab( 619 pParent->tabWidget()->indexOf(pItem->page())); 620 620 } 621 621 } … … 626 626 void UISettingsSelectorToolBar::clear() 627 627 { 628 QList<QAction*> list = m ActionGroup->actions();629 foreach (QAction * action, list)630 delete action;628 QList<QAction*> list = m_pActionGroup->actions(); 629 foreach (QAction *pAction, list) 630 delete pAction; 631 631 } 632 632 633 633 int UISettingsSelectorToolBar::minWidth() const 634 634 { 635 return m TbSelector->sizeHint().width() + 2 * 10;636 } 637 638 void UISettingsSelectorToolBar::s ettingsGroupChanged (QAction *aAction)639 { 640 SelectorActionItem *item = findActionItemByAction (aAction);641 if ( item)642 { 643 emit categoryChanged (item->id());644 // if ( item->page() &&645 // ! item->tabWidget())646 // emit categoryChanged (item->id());635 return m_pToolBar->sizeHint().width() + 2 * 10; 636 } 637 638 void UISettingsSelectorToolBar::sltSettingsGroupChanged(QAction *pAction) 639 { 640 const UISelectorActionItem *pItem = findActionItemByAction(pAction); 641 if (pItem) 642 { 643 emit categoryChanged(pItem->id()); 644 // if (pItem->page() && 645 // !pItem->tabWidget()) 646 // emit categoryChanged(pItem->id()); 647 647 // else 648 648 // { 649 649 // 650 // item->tabWidget()->blockSignals(true);651 // item->tabWidget()->setCurrentIndex(0);652 // item->tabWidget()->blockSignals(false);653 // printf ("%s\n", qPrintable(item->text()));654 // SelectorActionItem *child = static_cast<SelectorActionItem*>(655 // findItemByPage (static_cast<UISettingsPage*> (item->tabWidget()->currentWidget())));650 // pItem->tabWidget()->blockSignals(true); 651 // pItem->tabWidget()->setCurrentIndex(0); 652 // pItem->tabWidget()->blockSignals(false); 653 // printf("%s\n", qPrintable(pItem->text())); 654 // UISelectorActionItem *child = static_cast<UISelectorActionItem*>( 655 // findItemByPage(static_cast<UISettingsPage*>(pItem->tabWidget()->currentWidget()))); 656 656 // if (child) 657 // emit categoryChanged 657 // emit categoryChanged(child->id()); 658 658 // } 659 659 } 660 660 } 661 661 662 void UISettingsSelectorToolBar::s ettingsGroupChanged (int aIndex)663 { 664 SelectorActionItem *item = findActionItemByTabWidget (qobject_cast<QTabWidget*> (sender()), aIndex);665 if ( item)666 { 667 if ( item->page() &&668 ! item->tabWidget())669 emit categoryChanged (item->id());662 void UISettingsSelectorToolBar::sltSettingsGroupChanged(int iIndex) 663 { 664 const UISelectorActionItem *pItem = findActionItemByTabWidget(qobject_cast<QTabWidget*>(sender()), iIndex); 665 if (pItem) 666 { 667 if (pItem->page() && 668 !pItem->tabWidget()) 669 emit categoryChanged(pItem->id()); 670 670 else 671 671 { 672 SelectorActionItem *child = static_cast<SelectorActionItem*>(673 findItemByPage (static_cast<UISettingsPage*> (item->tabWidget()->currentWidget())));674 if ( child)675 emit categoryChanged (child->id());676 } 677 } 678 } 679 680 SelectorActionItem* UISettingsSelectorToolBar::findActionItem (int aId) const681 { 682 return static_cast< SelectorActionItem*> (UISettingsSelector::findItem (aId));683 } 684 685 SelectorActionItem *UISettingsSelectorToolBar::findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const686 { 687 SelectorActionItem *result = NULL;688 foreach ( SelectorItem *item, mItemList)689 if (static_cast< SelectorActionItem*> (item)->tabWidget() == aTabWidget)690 { 691 QTabWidget * tw = static_cast<SelectorActionItem*> (item)->tabWidget();692 result = static_cast<SelectorActionItem*>(693 findItemByPage (static_cast<UISettingsPage*> (tw->widget (aIndex))));672 const UISelectorActionItem *pChild = static_cast<UISelectorActionItem*>( 673 findItemByPage(static_cast<UISettingsPage*>(pItem->tabWidget()->currentWidget()))); 674 if (pChild) 675 emit categoryChanged(pChild->id()); 676 } 677 } 678 } 679 680 UISelectorActionItem *UISettingsSelectorToolBar::findActionItem(int iID) const 681 { 682 return static_cast<UISelectorActionItem*>(UISettingsSelector::findItem(iID)); 683 } 684 685 UISelectorActionItem *UISettingsSelectorToolBar::findActionItemByTabWidget(QTabWidget *pTabWidget, int iIndex) const 686 { 687 UISelectorActionItem *pResult = 0; 688 foreach (UISelectorItem *pItem, m_list) 689 if (static_cast<UISelectorActionItem*>(pItem)->tabWidget() == pTabWidget) 690 { 691 QTabWidget *pTabWidget = static_cast<UISelectorActionItem*>(pItem)->tabWidget(); 692 pResult = static_cast<UISelectorActionItem*>( 693 findItemByPage(static_cast<UISettingsPage*>(pTabWidget->widget(iIndex)))); 694 694 break; 695 695 } 696 696 697 return result;697 return pResult; 698 698 699 699 } … … 702 702 { 703 703 QList<QWidget*> list; 704 foreach ( SelectorItem *item, mItemList)705 { 706 SelectorActionItem *ai = static_cast<SelectorActionItem*> (item);707 if ( ai->parentId() == -1 &&708 ai->page())709 list << ai->page();710 else if ( ai->tabWidget())711 list << ai->tabWidget();704 foreach (UISelectorItem *pItem, m_list) 705 { 706 const UISelectorActionItem *pActionItem = static_cast<UISelectorActionItem*>(pItem); 707 if (pActionItem->parentID() == -1 && 708 pActionItem->page()) 709 list << pActionItem->page(); 710 else if (pActionItem->tabWidget()) 711 list << pActionItem->tabWidget(); 712 712 } 713 713 return list; 714 714 } 715 715 716 SelectorActionItem *UISettingsSelectorToolBar::findActionItemByAction (QAction *aAction) const717 { 718 SelectorActionItem *result = NULL;719 foreach ( SelectorItem *item, mItemList)720 if (static_cast< SelectorActionItem*> (item)->action() == aAction)721 { 722 result = static_cast<SelectorActionItem*> (item);716 UISelectorActionItem *UISettingsSelectorToolBar::findActionItemByAction(QAction *pAction) const 717 { 718 UISelectorActionItem *pResult = 0; 719 foreach (UISelectorItem *pItem, m_list) 720 if (static_cast<UISelectorActionItem*>(pItem)->action() == pAction) 721 { 722 pResult = static_cast<UISelectorActionItem*>(pItem); 723 723 break; 724 724 } 725 725 726 return result;727 } 728 726 return pResult; 727 } 728 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.h
r64080 r64081 23 23 24 24 /* Forward declarations: */ 25 class QITreeWidget; 26 class UIToolBar; 27 class UISettingsPage; 28 class SelectorItem; 29 class SelectorActionItem; 25 class QAction; 26 class QActionGroup; 27 class QTabWidget; 30 28 class QTreeWidget; 31 29 class QTreeWidgetItem; 32 class QI con;33 class QAction;34 class QActionGroup;35 template <class Key, class T> class QMap;36 class QTabWidget;30 class QITreeWidget; 31 class UISelectorItem; 32 class UISelectorActionItem; 33 class UISettingsPage; 34 class UIToolBar; 37 35 38 36 39 37 /** QObject subclass providing settings dialog 40 38 * with the means to switch between settings pages. */ 41 class UISettingsSelector : public QObject39 class UISettingsSelector : public QObject 42 40 { 43 41 Q_OBJECT; … … 45 43 public: 46 44 47 /** Constructs settings selector passing @a aParent to the base-class. */48 UISettingsSelector (QWidget *aParent = NULL);45 /** Constructs settings selector passing @a pParent to the base-class. */ 46 UISettingsSelector(QWidget *pParent = 0); 49 47 /** Destructs settings selector. */ 50 48 ~UISettingsSelector(); … … 57 55 * @param strMediumIcon Brings the medium icon reference. 58 56 * @param strSmallIcon Brings the small icon reference. 59 * @param aIdBrings the selector section ID.60 * @param aLinkBrings the selector section link.61 * @param aPage Brings the selector section page reference.62 * @param aParentIdBrings the parent section ID or -1 if there is no parent. */63 virtual QWidget *addItem 64 int aId, const QString &aLink, UISettingsPage* aPage = NULL, int aParentId= -1) = 0;65 66 /** Defines the @a aText for section with @a aId. */67 virtual void setItemText (int aId, const QString &aText);68 /** Returns the text for section with @a aId. */69 virtual QString itemText (int aId) const = 0;70 /** Returns the text for section with @a aPage. */71 virtual QString itemTextByPage (UISettingsPage *aPage) const;57 * @param iID Brings the selector section ID. 58 * @param strLink Brings the selector section link. 59 * @param pPage Brings the selector section page reference. 60 * @param iParentID Brings the parent section ID or -1 if there is no parent. */ 61 virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon, 62 int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) = 0; 63 64 /** Defines the @a strText for section with @a iID. */ 65 virtual void setItemText(int iID, const QString &strText); 66 /** Returns the text for section with @a iID. */ 67 virtual QString itemText(int iID) const = 0; 68 /** Returns the text for section with @a pPage. */ 69 virtual QString itemTextByPage(UISettingsPage *pPage) const; 72 70 73 71 /** Returns the current selector ID. */ 74 virtual int currentId 75 76 /** Returns the section ID for passed @a aLink. */77 virtual int linkToId (const QString &aLink) const = 0;78 79 /** Returns the section page for passed @a aId. */80 virtual QWidget *idToPage (int aId) const;81 /** Returns the section root-page for passed @a aId. */82 virtual QWidget *rootPage (int aId) const { return idToPage (aId); }83 84 /** Make the section with @a aIdcurrent. */85 virtual void selectById (int aId) = 0;86 /** Make the section with @a aLink current. */87 virtual void selectByLink (const QString &aLink) { selectById (linkToId (aLink)); }88 89 /** Make the section with @a aId @a aShow. */90 virtual void setVisibleById (int aId, bool aShow) = 0;72 virtual int currentId() const = 0; 73 74 /** Returns the section ID for passed @a strLink. */ 75 virtual int linkToId(const QString &strLink) const = 0; 76 77 /** Returns the section page for passed @a iID. */ 78 virtual QWidget *idToPage(int iID) const; 79 /** Returns the section root-page for passed @a iID. */ 80 virtual QWidget *rootPage(int iID) const { return idToPage(iID); } 81 82 /** Make the section with @a iID current. */ 83 virtual void selectById(int iID) = 0; 84 /** Make the section with @a strLink current. */ 85 virtual void selectByLink(const QString &strLink) { selectById(linkToId(strLink)); } 86 87 /** Make the section with @a iID @a fVisible. */ 88 virtual void setVisibleById(int iID, bool fVisible) = 0; 91 89 92 90 /** Returns the list of all selector pages. */ … … 96 94 97 95 /** Performs selector polishing. */ 98 virtual void polish() {} ;96 virtual void polish() {} 99 97 100 98 /** Returns minimum selector width. */ 101 virtual int minWidth 99 virtual int minWidth() const { return 0; } 102 100 103 101 signals: 104 102 105 103 /** Notifies listeners about selector @a iCategory changed. */ 106 void categoryChanged 104 void categoryChanged(int iCategory); 107 105 108 106 protected: … … 111 109 virtual void clear() = 0; 112 110 113 /** Searches for item with passed @a aId. */114 SelectorItem* findItem (int aId) const;115 /** Searches for item with passed @a aLink. */116 SelectorItem* findItemByLink (const QString &aLink) const;117 /** Searches for item with passed @a aPage. */118 SelectorItem* findItemByPage (UISettingsPage* aPage) const;111 /** Searches for item with passed @a iID. */ 112 UISelectorItem *findItem(int iID) const; 113 /** Searches for item with passed @a strLink. */ 114 UISelectorItem *findItemByLink(const QString &strLink) const; 115 /** Searches for item with passed @a pPage. */ 116 UISelectorItem *findItemByPage(UISettingsPage *pPage) const; 119 117 120 118 /** Holds the selector item instances. */ 121 QList< SelectorItem*> mItemList;119 QList<UISelectorItem*> m_list; 122 120 }; 123 121 … … 126 124 * with the means to switch between settings pages. 127 125 * This one represented as tree-widget. */ 128 class UISettingsSelectorTreeView : public UISettingsSelector126 class UISettingsSelectorTreeView : public UISettingsSelector 129 127 { 130 128 Q_OBJECT; … … 132 130 public: 133 131 134 /** Constructs settings selector passing @a aParent to the base-class. */135 UISettingsSelectorTreeView (QWidget *aParent = NULL);132 /** Constructs settings selector passing @a pParent to the base-class. */ 133 UISettingsSelectorTreeView(QWidget *pParent = 0); 136 134 137 135 /** Returns the widget selector operates on. */ 138 virtual QWidget *widget() const ;136 virtual QWidget *widget() const /* override */; 139 137 140 138 /** Adds a new selector item. … … 142 140 * @param strMediumIcon Brings the medium icon reference. 143 141 * @param strSmallIcon Brings the small icon reference. 144 * @param aIdBrings the selector section ID.145 * @param aLinkBrings the selector section link.146 * @param aPage Brings the selector section page reference.147 * @param aParentIdBrings the parent section ID or -1 if there is no parent. */148 virtual QWidget *addItem 149 int aId, const QString &aLink, UISettingsPage* aPage = NULL, int aParentId = -1);150 151 /** Defines the @a aText for section with @a aId. */152 virtual void setItemText (int aId, const QString &aText);153 /** Returns the text for section with @a aId. */154 virtual QString itemText (int aId) const;142 * @param iID Brings the selector section ID. 143 * @param strLink Brings the selector section link. 144 * @param pPage Brings the selector section page reference. 145 * @param iParentID Brings the parent section ID or -1 if there is no parent. */ 146 virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon, 147 int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) /* override */; 148 149 /** Defines the @a strText for section with @a iID. */ 150 virtual void setItemText(int iID, const QString &strText) /* override */; 151 /** Returns the text for section with @a iID. */ 152 virtual QString itemText(int iID) const /* override */; 155 153 156 154 /** Returns the current selector ID. */ 157 virtual int currentId() const ;158 159 /** Returns the section ID for passed @a aLink. */160 virtual int linkToId (const QString &aLink) const;161 162 /** Make the section with @a aIdcurrent. */163 virtual void selectById (int aId);164 165 /** Make the section with @a aId @a aShow. */166 virtual void setVisibleById (int aId, bool aShow);155 virtual int currentId() const /* override */; 156 157 /** Returns the section ID for passed @a strLink. */ 158 virtual int linkToId(const QString &strLink) const /* override */; 159 160 /** Make the section with @a iID current. */ 161 virtual void selectById(int iID) /* override */; 162 163 /** Make the section with @a iID @a fVisible. */ 164 virtual void setVisibleById(int iID, bool fVisible) /* override */; 167 165 168 166 /** Performs selector polishing. */ 169 virtual void polish() ;167 virtual void polish() /* override */; 170 168 171 169 private slots: 172 170 173 /** Handles selector section change from @a aPrevItem to @a aItem. */174 void s ettingsGroupChanged (QTreeWidgetItem *aItem, QTreeWidgetItem *aPrevItem);171 /** Handles selector section change from @a pPrevItem to @a pItem. */ 172 void sltSettingsGroupChanged(QTreeWidgetItem *pItem, QTreeWidgetItem *pPrevItem); 175 173 176 174 private: 177 175 178 176 /** Clears selector of all the items. */ 179 virtual void clear() ;180 181 /** Returns page path for passed @a aMatch. */182 QString pagePath (const QString &aMatch) const;183 /** Find item within the passed @a aView and @a aColumn matching @a aMatch. */184 QTreeWidgetItem * findItem (QTreeWidget *aView, const QString &aMatch, int aColumn) const;185 /** Performs @a aIdto QString serialization. */186 QString idToString (int aId) const;177 virtual void clear() /* override */; 178 179 /** Returns page path for passed @a strMatch. */ 180 QString pagePath(const QString &strMatch) const; 181 /** Find item within the passed @a pView and @a iColumn matching @a strMatch. */ 182 QTreeWidgetItem *findItem(QTreeWidget *pView, const QString &strMatch, int iColumn) const; 183 /** Performs @a iID to QString serialization. */ 184 QString idToString(int iID) const; 187 185 188 186 /** Holds the tree-widget instance. */ 189 QITreeWidget *m TwSelector;187 QITreeWidget *m_pTreeWidget; 190 188 }; 191 189 … … 194 192 * with the means to switch between settings pages. 195 193 * This one represented as tab-widget. */ 196 class UISettingsSelectorToolBar : public UISettingsSelector194 class UISettingsSelectorToolBar : public UISettingsSelector 197 195 { 198 196 Q_OBJECT; … … 200 198 public: 201 199 202 /** Constructs settings selector passing @a aParent to the base-class. */203 UISettingsSelectorToolBar (QWidget *aParent = NULL);200 /** Constructs settings selector passing @a pParent to the base-class. */ 201 UISettingsSelectorToolBar(QWidget *pParent = 0); 204 202 ~UISettingsSelectorToolBar(); 205 203 206 204 /** Returns the widget selector operates on. */ 207 virtual QWidget *widget() const ;205 virtual QWidget *widget() const /* override */; 208 206 209 207 /** Adds a new selector item. … … 211 209 * @param strMediumIcon Brings the medium icon reference. 212 210 * @param strSmallIcon Brings the small icon reference. 213 * @param aIdBrings the selector section ID.214 * @param aLinkBrings the selector section link.215 * @param aPage Brings the selector section page reference.216 * @param aParentIdBrings the parent section ID or -1 if there is no parent. */217 virtual QWidget *addItem 218 int aId, const QString &aLink, UISettingsPage* aPage = NULL, int aParentId = -1);219 220 /** Defines the @a aText for section with @a aId. */221 virtual void setItemText (int aId, const QString &aText);222 /** Returns the text for section with @a aId. */223 virtual QString itemText (int aId) const;211 * @param iID Brings the selector section ID. 212 * @param strLink Brings the selector section link. 213 * @param pPage Brings the selector section page reference. 214 * @param iParentID Brings the parent section ID or -1 if there is no parent. */ 215 virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon, 216 int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) /* override */; 217 218 /** Defines the @a strText for section with @a iID. */ 219 virtual void setItemText(int iID, const QString &strText) /* override */; 220 /** Returns the text for section with @a iID. */ 221 virtual QString itemText(int iID) const /* override */; 224 222 225 223 /** Returns the current selector ID. */ 226 virtual int currentId() const ;227 228 /** Returns the section ID for passed @a aLink. */229 virtual int linkToId (const QString &aLink) const;230 231 /** Returns the section page for passed @a aId. */232 virtual QWidget *idToPage (int aId) const;233 /** Returns the section root-page for passed @a aId. */234 virtual QWidget *rootPage (int aId) const;235 236 /** Make the section with @a aIdcurrent. */237 virtual void selectById (int aId);238 239 /** Make the section with @a aId @a aShow. */240 virtual void setVisibleById (int aId, bool aShow);224 virtual int currentId() const /* override */; 225 226 /** Returns the section ID for passed @a strLink. */ 227 virtual int linkToId(const QString &strLink) const /* override */; 228 229 /** Returns the section page for passed @a iID. */ 230 virtual QWidget *idToPage(int iID) const /* override */; 231 /** Returns the section root-page for passed @a iID. */ 232 virtual QWidget *rootPage(int iID) const /* override */; 233 234 /** Make the section with @a iID current. */ 235 virtual void selectById(int iID) /* override */; 236 237 /** Make the section with @a iID @a fVisible. */ 238 virtual void setVisibleById(int iID, bool fVisible) /* override */; 241 239 242 240 /** Returns minimum selector width. */ 243 virtual int minWidth() const ;241 virtual int minWidth() const /* override */; 244 242 245 243 /** Returns the list of all root pages. */ 246 virtual QList<QWidget*> rootPages() const ;244 virtual QList<QWidget*> rootPages() const /* override */; 247 245 248 246 private slots: 249 247 250 /** Handles selector section change to @a aAction. */251 void s ettingsGroupChanged (QAction *aAction);252 /** Handles selector section change to @a aIndex. */253 void s ettingsGroupChanged (int aIndex);248 /** Handles selector section change to @a pAction. */ 249 void sltSettingsGroupChanged(QAction *pAction); 250 /** Handles selector section change to @a iIndex. */ 251 void sltSettingsGroupChanged(int iIndex); 254 252 255 253 private: 256 254 257 255 /** Clears selector of all the items. */ 258 virtual void clear() ;259 260 /** Searches for action item with passed @a aId. */261 SelectorActionItem *findActionItem (int aId) const;262 /** Searches for action item with passed @a aAction. */263 SelectorActionItem *findActionItemByAction (QAction *aAction) const;264 /** Searches for action item with passed @a aTabWidget and @a aIndex. */265 SelectorActionItem *findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const;256 virtual void clear() /* override */; 257 258 /** Searches for action item with passed @a iID. */ 259 UISelectorActionItem *findActionItem(int iID) const; 260 /** Searches for action item with passed @a pAction. */ 261 UISelectorActionItem *findActionItemByAction(QAction *pAction) const; 262 /** Searches for action item with passed @a pTabWidget and @a iIndex. */ 263 UISelectorActionItem *findActionItemByTabWidget(QTabWidget *pTabWidget, int iIndex) const; 266 264 267 265 /** Holds the toolbar instance. */ 268 UIToolBar *m TbSelector;266 UIToolBar *m_pToolBar; 269 267 /** Holds the action group instance. */ 270 QActionGroup *m ActionGroup;268 QActionGroup *m_pActionGroup; 271 269 }; 272 270
Note:
See TracChangeset
for help on using the changeset viewer.