VirtualBox

Changeset 72447 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 5, 2018 10:09:26 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: ​bugref:9183 Some improvements to UIMediumSelector widget

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r72444 r72447  
    3232# include "QIMessageBox.h"
    3333# include "QITabWidget.h"
     34# include "QIToolButton.h"
    3435# include "VBoxGlobal.h"
    3536# include "UIDesktopWidgetWatchdog.h"
     
    5556#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    5657
     58/*********************************************************************************************************************************
     59*   UISearchLineEdit definition.                                                                                           *
     60*********************************************************************************************************************************/
     61
     62class UISearchLineEdit : public QILineEdit
     63{
     64    Q_OBJECT;
     65
     66signals:
     67
     68    void sigFilterTermRemoved(QString removedString);
     69    void sigClearAll();
     70
     71public:
     72
     73    UISearchLineEdit(QWidget *parent = 0);
     74
     75protected:
     76
     77    // /* Delete mouseDoubleClick and mouseMoveEvent implementations of the base class */
     78    // virtual void        mouseDoubleClickEvent(QMouseEvent *) /* override */{}
     79    // virtual void        mouseMoveEvent(QMouseEvent *) /* override */{}
     80    // /* Override the mousePressEvent to control how selection is done: */
     81    // virtual void        mousePressEvent(QMouseEvent * event) /* override */;
     82    // virtual void        mouseReleaseEvent(QMouseEvent *){}
     83    virtual void        paintEvent(QPaintEvent *event) /* override */;
     84
     85private slots:
     86
     87    /* The whole content is removed. Listeners are notified: */
     88    void sltClearAll();
     89
     90private:
     91
     92    void          createButtons();
     93    QIToolButton *m_pClearAllButton;
     94};
     95
    5796class UIMediumSearchWidget : public QWidget
    5897{
     
    82121
    83122    void prepareWidgets();
    84     QIComboBox *m_pSearchComboxBox;
    85     QILineEdit *m_pSearchTermLineEdit;
     123    QIComboBox       *m_pSearchComboxBox;
     124    UISearchLineEdit *m_pSearchTermLineEdit;
    86125};
     126
     127
     128/*********************************************************************************************************************************
     129*   UISearchLineEdit implementation.                                                                                             *
     130*********************************************************************************************************************************/
     131
     132UISearchLineEdit::UISearchLineEdit(QWidget *parent /*= 0*/)
     133    :QILineEdit(parent)
     134    , m_pClearAllButton(0)
     135{
     136    createButtons();
     137}
     138
     139void UISearchLineEdit::paintEvent(QPaintEvent *event)
     140{
     141    QLineEdit::paintEvent(event);
     142
     143    if (!m_pClearAllButton)
     144        createButtons();
     145    int clearButtonSize = height();
     146    m_pClearAllButton->setGeometry(width() - clearButtonSize, 0, clearButtonSize, clearButtonSize);
     147}
     148
     149void UISearchLineEdit::sltClearAll()
     150{
     151    /* Check if we have some text to avoid recursive calls: */
     152    if (text().isEmpty())
     153        return;
     154
     155    clear();
     156    emit sigClearAll();
     157}
     158
     159void UISearchLineEdit::createButtons()
     160{
     161    if (!m_pClearAllButton)
     162    {
     163        m_pClearAllButton = new QIToolButton(this);
     164        if (m_pClearAllButton)
     165        {
     166            m_pClearAllButton->setIcon(m_pClearAllButton->style()->standardIcon(QStyle::SP_LineEditClearButton));
     167            connect(m_pClearAllButton, &QIToolButton::clicked, this, &UISearchLineEdit::sltClearAll);
     168        }
     169    }
     170}
     171
     172
     173/*********************************************************************************************************************************
     174*   UIMediumSearchWidget implementation.                                                                                         *
     175*********************************************************************************************************************************/
    87176
    88177UIMediumSearchWidget::UIMediumSearchWidget(QWidget *pParent)
     
    105194    {
    106195        m_pSearchComboxBox->setEditable(false);
    107         m_pSearchComboxBox->insertItem(SearchByName, "By Name");
    108         m_pSearchComboxBox->insertItem(SearchByUUID, "By UUID");
     196        m_pSearchComboxBox->insertItem(SearchByName, "Search By Name");
     197        m_pSearchComboxBox->insertItem(SearchByUUID, "Search By UUID");
    109198        pLayout->addWidget(m_pSearchComboxBox);
    110199
     
    114203    }
    115204
    116     m_pSearchTermLineEdit = new QILineEdit;
     205    m_pSearchTermLineEdit = new UISearchLineEdit;
    117206    if (pLayout)
    118207    {
     
    154243    configure();
    155244    finalize();
    156     //setAttribute(Qt::WA_DeleteOnClose);
    157245}
    158246
     
    401489        m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    402490        m_pMainLayout->addWidget(m_pTreeWidget);
    403 
    404491        m_pTreeWidget->setAlternatingRowColors(true);
    405 
     492        int iColumnCount = (m_enmMediumType == UIMediumType_HardDisk) ? 3 : 2;
     493        m_pTreeWidget->setColumnCount(iColumnCount);
     494        m_pTreeWidget->setSortingEnabled(true);
     495        m_pTreeWidget->sortItems(0, Qt::AscendingOrder);
    406496    }
    407497
     
    537627    if (!m_pTreeWidget)
    538628        return;
    539 
    540629    /* Cache the currently selected items: */
    541630    QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems();
     
    591680    if (m_pNotAttachedSubTreeRoot)
    592681        m_pTreeWidget->expandItem(m_pNotAttachedSubTreeRoot);
     682
     683    m_pTreeWidget->resizeColumnToContents(0);
     684    performMediumSearch();
    593685}
    594686
     
    645737    for (int i = 0; i < m_mediumItemList.size(); ++i)
    646738    {
    647         m_mediumItemList[i]->setData(0, Qt::ForegroundRole, m_defaultItemForeground);
     739        for (int j = 0; j < m_pTreeWidget->columnCount(); ++j)
     740            m_mediumItemList[i]->setData(j, Qt::ForegroundRole, m_defaultItemForeground);
    648741    }
    649742
     
    671764        {
    672765            // mark the item
    673             m_mediumItemList[i]->setData(0, Qt::ForegroundRole, QBrush(QColor(255, 0, 0)));
     766            for (int j = 0; j < m_pTreeWidget->columnCount(); ++j)
     767                m_mediumItemList[i]->setData(j, Qt::ForegroundRole, QBrush(QColor(255, 0, 0)));
    674768        }
    675769    }
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