VirtualBox

Changeset 64081 in vbox for trunk/src


Ignore:
Timestamp:
Sep 28, 2016 1:37:50 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 59): Settings selector refactoring.

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  
    2121
    2222/* Qt includes: */
     23# include <QAction>
    2324# include <QHeaderView>
     25# include <QLayout>
    2426# include <QTabWidget>
    25 # include <QLayout>
    26 # include <QAction>
    2727
    2828/* GUI includes: */
     29# include "QITabWidget.h"
     30# include "QITreeWidget.h"
    2931# include "UISettingsSelector.h"
     32# include "UIIconPool.h"
    3033# include "UISettingsPage.h"
    3134# include "UIToolBar.h"
    32 # include "QITreeWidget.h"
    33 # include "QITabWidget.h"
    34 # include "UIIconPool.h"
    3535
    3636#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3838
    3939/** Tree-widget column sections. */
    40 enum
    41 {
    42     treeWidget_Category = 0,
    43     treeWidget_Id,
    44     treeWidget_Link
     40enum TreeWidgetSection
     41{
     42    TreeWidgetSection_Category = 0,
     43    TreeWidgetSection_Id,
     44    TreeWidgetSection_Link
    4545};
    4646
    4747
    4848/** Simple container of all the selector item data. */
    49 class SelectorItem
     49class UISelectorItem
    5050{
    5151public:
    5252
    5353    /** Constructs selector item.
    54       * @param  aIcon      Brings the item icon.
    55       * @param  aText      Brings the item text.
    56       * @param  aId        Brings the item ID.
    57       * @param  aLink      Brings the item link.
    58       * @param  aPage      Brings the item page reference.
    59       * @param  aParentId  Brings the item parent ID. */
    60     SelectorItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, UISettingsPage* aPage, int aParentId)
    61         : mIcon (aIcon)
    62         , mText (aText)
    63         , mId (aId)
    64         , mLink (aLink)
    65         , mPage (aPage)
    66         , mParentId (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)
    6767    {}
    6868
    6969    /** Returns the item icon. */
    70     QIcon icon() const { return mIcon; }
     70    QIcon icon() const { return m_icon; }
    7171    /** Returns the item text. */
    72     QString text() const { return mText; }
     72    QString text() const { return m_strText; }
    7373    /** Defines the item @s strText. */
    74     void setText (const QString &aText) { mText = aText; }
     74    void setText(const QString &strText) { m_strText = strText; }
    7575    /** Returns the item ID. */
    76     int id() const { return mId; }
     76    int id() const { return m_iID; }
    7777    /** Returns the item link. */
    78     QString link() const { return mLink; }
     78    QString link() const { return m_strLink; }
    7979    /** Returns the item page reference. */
    80     UISettingsPage *page() const { return mPage; }
     80    UISettingsPage *page() const { return m_pPage; }
    8181    /** Returns the item parent ID. */
    82     int parentId() const { return mParentId; }
     82    int parentID() const { return m_iParentID; }
    8383
    8484protected:
    8585
    8686    /** Holds the item icon. */
    87     QIcon mIcon;
     87    QIcon m_icon;
    8888    /** Holds the item text. */
    89     QString mText;
     89    QString m_strText;
    9090    /** Holds the item ID. */
    91     int mId;
     91    int m_iID;
    9292    /** Holds the item link. */
    93     QString mLink;
     93    QString m_strLink;
    9494    /** Holds the item page reference. */
    95     UISettingsPage* mPage;
     95    UISettingsPage *m_pPage;
    9696    /** Holds the item parent ID. */
    97     int mParentId;
     97    int m_iParentID;
    9898};
    9999
     
    103103*********************************************************************************************************************************/
    104104
    105 UISettingsSelector::UISettingsSelector (QWidget *aParent /* = NULL */)
    106     :QObject (aParent)
     105UISettingsSelector::UISettingsSelector(QWidget *pParent /* = 0 */)
     106    : QObject(pParent)
    107107{
    108108}
     
    110110UISettingsSelector::~UISettingsSelector()
    111111{
    112     qDeleteAll (mItemList);
    113     mItemList.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) const
    123 {
    124     QString text;
    125     if (SelectorItem *item = findItemByPage (aPage))
    126         text = item->text();
    127     return text;
    128 }
    129 
    130 QWidget *UISettingsSelector::idToPage (int aId) const
    131 {
    132     UISettingsPage *page = NULL;
    133     if (SelectorItem *item = findItem (aId))
    134         page = item->page();
    135     return page;
     112    qDeleteAll(m_list);
     113    m_list.clear();
     114}
     115
     116void UISettingsSelector::setItemText(int iID, const QString &strText)
     117{
     118    if (UISelectorItem *pTtem = findItem(iID))
     119        pTtem->setText(strText);
     120}
     121
     122QString UISettingsSelector::itemTextByPage(UISettingsPage *pPage) const
     123{
     124    QString strText;
     125    if (UISelectorItem *pItem = findItemByPage(pPage))
     126        strText = pItem->text();
     127    return strText;
     128}
     129
     130QWidget *UISettingsSelector::idToPage(int iID) const
     131{
     132    UISettingsPage *pPage = 0;
     133    if (UISelectorItem *pItem = findItem(iID))
     134        pPage = pItem->page();
     135    return pPage;
    136136}
    137137
     
    139139{
    140140    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();
    144144    return list;
    145145}
     
    148148{
    149149    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();
    153153    return list;
    154154}
    155155
    156 SelectorItem *UISettingsSelector::findItem (int aId) const
    157 {
    158     SelectorItem *result = NULL;
    159     foreach (SelectorItem *item, mItemList)
    160         if (item->id() == aId)
    161         {
    162             result = item;
     156UISelectorItem *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;
    163163            break;
    164164        }
    165     return result;
    166 }
    167 
    168 SelectorItem *UISettingsSelector::findItemByLink (const QString &aLink) const
    169 {
    170     SelectorItem *result = NULL;
    171     foreach (SelectorItem *item, mItemList)
    172         if (item->link() == aLink)
    173         {
    174             result = item;
     165    return pResult;
     166}
     167
     168UISelectorItem *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;
    175175            break;
    176176        }
    177     return result;
    178 }
    179 
    180 SelectorItem *UISettingsSelector::findItemByPage (UISettingsPage* aPage) const
    181 {
    182     SelectorItem *result = NULL;
    183     foreach (SelectorItem *item, mItemList)
    184         if (item->page() == aPage)
    185         {
    186             result = item;
     177    return pResult;
     178}
     179
     180UISelectorItem *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;
    187187            break;
    188188        }
    189     return result;
     189    return pResult;
    190190}
    191191
     
    195195*********************************************************************************************************************************/
    196196
    197 static QString path (QTreeWidgetItem *aItem)
    198 {
    199     static QString sep = ": ";
    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     mTwSelector = new QITreeWidget (aParent);
     197static 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
     212UISettingsSelectorTreeView::UISettingsSelectorTreeView(QWidget *pParent /* = 0 */)
     213    : UISettingsSelector(pParent)
     214{
     215    m_pTreeWidget = new QITreeWidget(pParent);
    216216    /* Configure the selector: */
    217     QSizePolicy sizePolicy (QSizePolicy::Minimum, QSizePolicy::Expanding);
    218     sizePolicy.setHorizontalStretch (0);
    219     sizePolicy.setVerticalStretch (0);
    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());
    221221    const QStyle *pStyle = QApplication::style();
    222222    const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    223     mTwSelector->setSizePolicy (sizePolicy);
    224     mTwSelector->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    225     mTwSelector->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    226     mTwSelector->setRootIsDecorated (false);
    227     mTwSelector->setUniformRowHeights (true);
    228     mTwSelector->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)));
    229229    /* Add the columns: */
    230     mTwSelector->headerItem()->setText (treeWidget_Category, "Category");
    231     mTwSelector->headerItem()->setText (treeWidget_Id, "[id]");
    232     mTwSelector->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]");
    233233    /* Hide unnecessary columns and header: */
    234     mTwSelector->header()->hide();
    235     mTwSelector->hideColumn (treeWidget_Id);
    236     mTwSelector->hideColumn (treeWidget_Link);
     234    m_pTreeWidget->header()->hide();
     235    m_pTreeWidget->hideColumn(TreeWidgetSection_Id);
     236    m_pTreeWidget->hideColumn(TreeWidgetSection_Link);
    237237    /* 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*)));
    240240}
    241241
    242242QWidget *UISettingsSelectorTreeView::widget() const
    243243{
    244     return mTwSelector;
    245 }
    246 
    247 QWidget *UISettingsSelectorTreeView::addItem (const QString & /* strBigIcon */,
    248                                                 const QString &strMediumIcon ,
    249                                                 const QString & /* strSmallIcon */,
    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         mItemList.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) const
    283 {
    284     return pagePath (idToString (aId));
    285 }
    286 
    287 int UISettingsSelectorTreeView::currentId () const
    288 {
    289     int id = -1;
    290     QTreeWidgetItem *item = mTwSelector->currentItem();
    291     if (item)
    292         id = item->text (treeWidget_Id).toInt();
    293     return id;
    294 }
    295 
    296 int UISettingsSelectorTreeView::linkToId (const QString &aLink) const
    297 {
    298     int id = -1;
    299     QTreeWidgetItem *item = findItem (mTwSelector, aLink, treeWidget_Link);
    300     if (item)
    301         id = item->text (treeWidget_Id).toInt();
    302     return id;
    303 }
    304 
    305 void UISettingsSelectorTreeView::selectById (int aId)
    306 {
    307     QTreeWidgetItem *item = findItem (mTwSelector, idToString (aId), treeWidget_Id);
    308     if (item)
    309         mTwSelector->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
     247QWidget *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
     274void 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
     282QString UISettingsSelectorTreeView::itemText(int iID) const
     283{
     284    return pagePath(idToString(iID));
     285}
     286
     287int 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
     296int 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
     305void 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
     312void UISettingsSelectorTreeView::setVisibleById(int iID, bool fVisible)
     313{
     314    QTreeWidgetItem *pItem = findItem(m_pTreeWidget, idToString(iID), TreeWidgetSection_Id);
     315    if (pItem)
     316        pItem->setHidden(!fVisible);
    317317}
    318318
     
    322322    const QStyle *pStyle = QApplication::style();
    323323    const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    324     int iItemWidth = static_cast<QAbstractItemView*>(mTwSelector)->sizeHintForColumn(treeWidget_Category);
     324    int iItemWidth = static_cast<QAbstractItemView*>(m_pTreeWidget)->sizeHintForColumn(TreeWidgetSection_Category);
    325325    int iItemHeight = qMax((int)(iIconMetric * 1.5) /* icon height */,
    326                            mTwSelector->fontMetrics().height() /* text height */);
     326                           m_pTreeWidget->fontMetrics().height() /* text height */);
    327327    /* Add some margin to every item in the tree: */
    328328    iItemHeight += 4 /* margin itself */ * 2 /* margin count */;
    329329    /* Set final size hint for items: */
    330     mTwSelector->setSizeHintForItems(QSize(iItemWidth , iItemHeight));
     330    m_pTreeWidget->setSizeHintForItems(QSize(iItemWidth , iItemHeight));
    331331
    332332    /* Adjust selector width/height: */
    333     mTwSelector->setFixedWidth(iItemWidth + 2 * mTwSelector->frameWidth());
    334     mTwSelector->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 */);
    336336
    337337    /* Sort selector by the id column: */
    338     mTwSelector->sortItems(treeWidget_Id, Qt::AscendingOrder);
     338    m_pTreeWidget->sortItems(TreeWidgetSection_Id, Qt::AscendingOrder);
    339339
    340340    /* Resize column(s) to content: */
    341     mTwSelector->resizeColumnToContents(treeWidget_Category);
    342 }
    343 
    344 void UISettingsSelectorTreeView::settingsGroupChanged (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
     344void 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);
    352352    }
    353353}
     
    355355void UISettingsSelectorTreeView::clear()
    356356{
    357     mTwSelector->clear();
    358 }
    359 
    360 QString UISettingsSelectorTreeView::pagePath (const QString &aMatch) const
    361 {
    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) const
     357    m_pTreeWidget->clear();
     358}
     359
     360QString 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
     369QTreeWidgetItem *UISettingsSelectorTreeView::findItem(QTreeWidget *pView,
     370                                                      const QString &strMatch,
     371                                                      int iColumn) const
    372372{
    373373    QList<QTreeWidgetItem*> list =
    374         aView->findItems (aMatch, Qt::MatchExactly, aColumn);
    375 
    376     return list.count() ? list [0] : 0;
    377 }
    378 
    379 QString UISettingsSelectorTreeView::idToString (int aId) const
    380 {
    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
     379QString UISettingsSelectorTreeView::idToString(int iID) const
     380{
     381    return QString("%1").arg(iID, 2, 10, QLatin1Char('0'));
    382382}
    383383
     
    387387*********************************************************************************************************************************/
    388388
    389 /** SelectorItem subclass providing GUI
     389/** UISelectorItem subclass providing GUI
    390390  * with the tab-widget selector item. */
    391 class SelectorActionItem: public SelectorItem
     391class UISelectorActionItem : public UISelectorItem
    392392{
    393393public:
    394394
    395395    /** Constructs selector item.
    396       * @param  aIcon      Brings the item icon.
    397       * @param  aText      Brings the item text.
    398       * @param  aId        Brings the item ID.
    399       * @param  aLink      Brings the item link.
    400       * @param  aPage      Brings the item page reference.
    401       * @param  aParentId  Brings 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         , mAction (new QAction (aIcon, aText, aParent))
    406         , mTabWidget (NULL)
    407     {
    408         mAction->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);
    409409    }
    410410
    411411    /** Returns the action instance. */
    412     QAction *action() const { return mAction; }
     412    QAction *action() const { return m_pAction; }
    413413
    414414    /** Defines the @a pTabWidget instance. */
    415     void setTabWidget (QTabWidget *aTabWidget) { mTabWidget = aTabWidget; }
     415    void setTabWidget(QTabWidget *pTabWidget) { m_pTabWidget = pTabWidget; }
    416416    /** Returns the tab-widget instance. */
    417     QTabWidget *tabWidget() const { return mTabWidget; }
     417    QTabWidget *tabWidget() const { return m_pTabWidget; }
    418418
    419419protected:
    420420
    421421    /** Holds the action instance. */
    422     QAction *mAction;
     422    QAction *m_pAction;
    423423    /** Holds the tab-widget instance. */
    424     QTabWidget *mTabWidget;
     424    QTabWidget *m_pTabWidget;
    425425};
    426426
    427427
    428 UISettingsSelectorToolBar::UISettingsSelectorToolBar (QWidget *aParent /* = NULL */)
    429     : UISettingsSelector (aParent)
     428UISettingsSelectorToolBar::UISettingsSelectorToolBar(QWidget *pParent /* = 0 */)
     429    : UISettingsSelector(pParent)
    430430{
    431431    /* Init the toolbar: */
    432     mTbSelector = new UIToolBar (aParent);
    433     mTbSelector->setUseTextLabels (true);
    434     mTbSelector->setIconSize (QSize (32, 32));
     432    m_pToolBar = new UIToolBar(pParent);
     433    m_pToolBar->setUseTextLabels(true);
     434    m_pToolBar->setIconSize(QSize(32, 32));
    435435#ifdef VBOX_WS_MAC
    436     mTbSelector->setShowToolBarButton (false);
     436    m_pToolBar->setShowToolBarButton(false);
    437437#endif /* VBOX_WS_MAC */
    438438    /* Init the action group for house keeping: */
    439     mActionGroup = new QActionGroup (this);
    440     mActionGroup->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*)));
    443443}
    444444
    445445UISettingsSelectorToolBar::~UISettingsSelectorToolBar()
    446446{
    447     delete mTbSelector;
     447    delete m_pToolBar;
    448448}
    449449
    450450QWidget *UISettingsSelectorToolBar::widget() const
    451451{
    452     return mTbSelector;
    453 }
    454 
    455 QWidget *UISettingsSelectorToolBar::addItem (const QString &strBigIcon,
    456                                                const QString & /* strMediumIcon */,
    457                                                const QString &strSmallIcon,
    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     mItemList.append (item);
    468 
    469     if (aParentId == -1 &&
    470         aPage != NULL)
    471     {
    472         mActionGroup->addAction (item->action());
    473         mTbSelector->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         mActionGroup->addAction (item->action());
    482         mTbSelector->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
     455QWidget *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;
    490490    }
    491491    else
    492492    {
    493         SelectorActionItem *parent = findActionItem (aParentId);
    494         if (parent)
    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 (parent &&
    519                 parent->tabWidget())
    520                 parent->tabWidget()->setTabText (
    521                     parent->tabWidget()->indexOf (item->page()), aText);
    522         }
    523     }
    524 }
    525 
    526 QString UISettingsSelectorToolBar::itemText (int aId) const
    527 {
    528     QString result;
    529     if (SelectorItem *item = findItem (aId))
    530         result = item->text();
    531     return result;
    532 }
    533 
    534 int UISettingsSelectorToolBar::currentId () const
    535 {
    536     SelectorActionItem *action = findActionItemByAction (mActionGroup->checkedAction());
    537     int id = -1;
    538     if (action)
    539         id = action->id();
    540     return id;
    541 }
    542 
    543 int UISettingsSelectorToolBar::linkToId (const QString &aLink) const
    544 {
    545     int id = -1;
    546     SelectorItem *item = UISettingsSelector::findItemByLink (aLink);
    547     if (item)
    548         id = item->id();
    549     return id;
    550 }
    551 
    552 QWidget *UISettingsSelectorToolBar::idToPage (int aId) const
    553 {
    554     QWidget *page = NULL;
    555     if (SelectorActionItem *item = findActionItem (aId))
    556     {
    557         page = item->page();
    558         if (!page)
    559             page = item->tabWidget();
    560     }
    561     return page;
    562 }
    563 
    564 QWidget *UISettingsSelectorToolBar::rootPage (int aId) const
    565 {
    566     QWidget *page = NULL;
    567     if (SelectorActionItem *item = findActionItem (aId))
    568     {
    569         if (item->parentId() > -1)
    570             page = rootPage (item->parentId());
    571         else if (item->page())
    572             page = 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
     507void 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
     526QString UISettingsSelectorToolBar::itemText(int iID) const
     527{
     528    QString strResult;
     529    if (UISelectorItem *pItem = findItem(iID))
     530        strResult = pItem->text();
     531    return strResult;
     532}
     533
     534int 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
     543int 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
     552QWidget *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
     564QWidget *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();
    573573        else
    574             page = item->tabWidget();
    575     }
    576     return page;
    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 (parent &&
    587                 parent->tabWidget())
     574            pPage = pItem->tabWidget();
     575    }
     576    return pPage;
     577}
     578
     579void 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())
    588588            {
    589                 parent->action()->trigger();
    590                 parent->tabWidget()->setCurrentIndex (
    591                     parent->tabWidget()->indexOf (item->page()));
     589                pParent->action()->trigger();
     590                pParent->tabWidget()->setCurrentIndex(
     591                    pParent->tabWidget()->indexOf(pItem->page()));
    592592            }
    593593        }
    594594        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 (parent &&
    611                 parent->tabWidget())
     595            pItem->action()->trigger();
     596    }
     597}
     598
     599void 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())
    612612            {
    613                 if (aShow &&
    614                     parent->tabWidget()->indexOf (item->page()) == -1)
    615                     parent->tabWidget()->addTab (item->page(), item->text());
    616                 else if (!aShow &&
    617                          parent->tabWidget()->indexOf (item->page()) > -1)
    618                     parent->tabWidget()->removeTab (
    619                         parent->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()));
    620620            }
    621621        }
     
    626626void UISettingsSelectorToolBar::clear()
    627627{
    628     QList<QAction*> list = mActionGroup->actions();
    629     foreach (QAction *action, list)
    630        delete action;
     628    QList<QAction*> list = m_pActionGroup->actions();
     629    foreach (QAction *pAction, list)
     630       delete pAction;
    631631}
    632632
    633633int UISettingsSelectorToolBar::minWidth() const
    634634{
    635     return mTbSelector->sizeHint().width() + 2 * 10;
    636 }
    637 
    638 void UISettingsSelectorToolBar::settingsGroupChanged (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
     638void 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());
    647647//        else
    648648//        {
    649649//
    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())));
    656656//            if (child)
    657 //                emit categoryChanged (child->id());
     657//                emit categoryChanged(child->id());
    658658//        }
    659659    }
    660660}
    661661
    662 void UISettingsSelectorToolBar::settingsGroupChanged (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());
     662void 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());
    670670        else
    671671        {
    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) const
    681 {
    682     return static_cast<SelectorActionItem*> (UISettingsSelector::findItem (aId));
    683 }
    684 
    685 SelectorActionItem *UISettingsSelectorToolBar::findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const
    686 {
    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
     680UISelectorActionItem *UISettingsSelectorToolBar::findActionItem(int iID) const
     681{
     682    return static_cast<UISelectorActionItem*>(UISettingsSelector::findItem(iID));
     683}
     684
     685UISelectorActionItem *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))));
    694694            break;
    695695        }
    696696
    697     return result;
     697    return pResult;
    698698
    699699}
     
    702702{
    703703    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();
    712712    }
    713713    return list;
    714714}
    715715
    716 SelectorActionItem *UISettingsSelectorToolBar::findActionItemByAction (QAction *aAction) const
    717 {
    718     SelectorActionItem *result = NULL;
    719     foreach (SelectorItem *item, mItemList)
    720         if (static_cast<SelectorActionItem*> (item)->action() == aAction)
    721         {
    722             result = static_cast<SelectorActionItem*> (item);
     716UISelectorActionItem *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);
    723723            break;
    724724        }
    725725
    726     return result;
    727 }
    728 
     726    return pResult;
     727}
     728
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.h

    r64080 r64081  
    2323
    2424/* Forward declarations: */
    25 class QITreeWidget;
    26 class UIToolBar;
    27 class UISettingsPage;
    28 class SelectorItem;
    29 class SelectorActionItem;
     25class QAction;
     26class QActionGroup;
     27class QTabWidget;
    3028class QTreeWidget;
    3129class QTreeWidgetItem;
    32 class QIcon;
    33 class QAction;
    34 class QActionGroup;
    35 template <class Key, class T> class QMap;
    36 class QTabWidget;
     30class QITreeWidget;
     31class UISelectorItem;
     32class UISelectorActionItem;
     33class UISettingsPage;
     34class UIToolBar;
    3735
    3836
    3937/** QObject subclass providing settings dialog
    4038  * with the means to switch between settings pages. */
    41 class UISettingsSelector: public QObject
     39class UISettingsSelector : public QObject
    4240{
    4341    Q_OBJECT;
     
    4543public:
    4644
    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);
    4947    /** Destructs settings selector. */
    5048    ~UISettingsSelector();
     
    5755      * @param  strMediumIcon  Brings the medium icon reference.
    5856      * @param  strSmallIcon   Brings the small icon reference.
    59       * @param  aId            Brings the selector section ID.
    60       * @param  aLink          Brings the selector section link.
    61       * @param  aPage          Brings the selector section page reference.
    62       * @param  aParentId      Brings the parent section ID or -1 if there is no parent. */
    63     virtual QWidget *addItem (const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
    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;
    7270
    7371    /** Returns the current selector ID. */
    74     virtual int currentId () const = 0;
    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 aId current. */
    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;
    9189
    9290    /** Returns the list of all selector pages. */
     
    9694
    9795    /** Performs selector polishing. */
    98     virtual void polish() {};
     96    virtual void polish() {}
    9997
    10098    /** Returns minimum selector width. */
    101     virtual int minWidth () const { return 0; }
     99    virtual int minWidth() const { return 0; }
    102100
    103101signals:
    104102
    105103    /** Notifies listeners about selector @a iCategory changed. */
    106     void categoryChanged (int iCategory);
     104    void categoryChanged(int iCategory);
    107105
    108106protected:
     
    111109    virtual void clear() = 0;
    112110
    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;
    119117
    120118    /** Holds the selector item instances. */
    121     QList<SelectorItem*> mItemList;
     119    QList<UISelectorItem*> m_list;
    122120};
    123121
     
    126124  * with the means to switch between settings pages.
    127125  * This one represented as tree-widget. */
    128 class UISettingsSelectorTreeView: public UISettingsSelector
     126class UISettingsSelectorTreeView : public UISettingsSelector
    129127{
    130128    Q_OBJECT;
     
    132130public:
    133131
    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);
    136134
    137135    /** Returns the widget selector operates on. */
    138     virtual QWidget *widget() const;
     136    virtual QWidget *widget() const /* override */;
    139137
    140138    /** Adds a new selector item.
     
    142140      * @param  strMediumIcon  Brings the medium icon reference.
    143141      * @param  strSmallIcon   Brings the small icon reference.
    144       * @param  aId            Brings the selector section ID.
    145       * @param  aLink          Brings the selector section link.
    146       * @param  aPage          Brings the selector section page reference.
    147       * @param  aParentId      Brings the parent section ID or -1 if there is no parent. */
    148     virtual QWidget *addItem (const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
    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 */;
    155153
    156154    /** 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 aId current. */
    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 */;
    167165
    168166    /** Performs selector polishing. */
    169     virtual void polish();
     167    virtual void polish() /* override */;
    170168
    171169private slots:
    172170
    173     /** Handles selector section change from @a aPrevItem to @a aItem. */
    174     void settingsGroupChanged (QTreeWidgetItem *aItem, QTreeWidgetItem *aPrevItem);
     171    /** Handles selector section change from @a pPrevItem to @a pItem. */
     172    void sltSettingsGroupChanged(QTreeWidgetItem *pItem, QTreeWidgetItem *pPrevItem);
    175173
    176174private:
    177175
    178176    /** 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 aId to 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;
    187185
    188186    /** Holds the tree-widget instance. */
    189     QITreeWidget *mTwSelector;
     187    QITreeWidget *m_pTreeWidget;
    190188};
    191189
     
    194192  * with the means to switch between settings pages.
    195193  * This one represented as tab-widget. */
    196 class UISettingsSelectorToolBar: public UISettingsSelector
     194class UISettingsSelectorToolBar : public UISettingsSelector
    197195{
    198196    Q_OBJECT;
     
    200198public:
    201199
    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);
    204202    ~UISettingsSelectorToolBar();
    205203
    206204    /** Returns the widget selector operates on. */
    207     virtual QWidget *widget() const;
     205    virtual QWidget *widget() const /* override */;
    208206
    209207    /** Adds a new selector item.
     
    211209      * @param  strMediumIcon  Brings the medium icon reference.
    212210      * @param  strSmallIcon   Brings the small icon reference.
    213       * @param  aId            Brings the selector section ID.
    214       * @param  aLink          Brings the selector section link.
    215       * @param  aPage          Brings the selector section page reference.
    216       * @param  aParentId      Brings the parent section ID or -1 if there is no parent. */
    217     virtual QWidget *addItem (const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
    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 */;
    224222
    225223    /** 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 aId current. */
    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 */;
    241239
    242240    /** Returns minimum selector width. */
    243     virtual int minWidth() const;
     241    virtual int minWidth() const /* override */;
    244242
    245243    /** Returns the list of all root pages. */
    246     virtual QList<QWidget*> rootPages() const;
     244    virtual QList<QWidget*> rootPages() const /* override */;
    247245
    248246private slots:
    249247
    250     /** Handles selector section change to @a aAction . */
    251     void settingsGroupChanged (QAction *aAction);
    252     /** Handles selector section change to @a aIndex . */
    253     void settingsGroupChanged (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);
    254252
    255253private:
    256254
    257255    /** 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;
    266264
    267265    /** Holds the toolbar instance. */
    268     UIToolBar *mTbSelector;
     266    UIToolBar *m_pToolBar;
    269267    /** Holds the action group instance. */
    270     QActionGroup *mActionGroup;
     268    QActionGroup *m_pActionGroup;
    271269};
    272270
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette