VirtualBox

Changeset 88658 in vbox


Ignore:
Timestamp:
Apr 22, 2021 3:25:31 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9930. Using a custom menu

Location:
trunk/src/VBox/Frontends/VirtualBox/src/logviewer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r88647 r88658  
    1717
    1818/* Qt includes: */
     19#include <QCheckBox>
    1920#include <QDateTime>
    2021#include <QDir>
     
    5556const ULONG uAllowedLogSize = _256M;
    5657
     58class UIMachineListCheckBox : public QCheckBox
     59{
     60
     61    Q_OBJECT;
     62
     63public:
     64
     65    UIMachineListCheckBox(const QString &strText, QWidget *pParent = 0);
     66    void setId(const QUuid &id);
     67    const QUuid &id() const;
     68private:
     69    QUuid m_id;
     70};
     71
     72UIMachineListCheckBox::UIMachineListCheckBox(const QString &strText, QWidget *pParent /* = 0 */)
     73    :QCheckBox(strText, pParent)
     74{
     75}
     76
     77void UIMachineListCheckBox::setId(const QUuid &id)
     78{
     79    m_id = id;
     80}
     81
     82const QUuid &UIMachineListCheckBox::id() const
     83{
     84    return m_id;
     85}
     86
    5787class UIMachineListMenu : public QWidget
    5888{
     
    6595    /** Removes the actions and deletes them. */
    6696    void clear();
    67     QAction *addAction(const QString &strText);
     97    void addListItem(const QString &strText, const QUuid &id);
     98
     99private:
     100
     101    void computeMinimumSize();
     102    QVector<UIMachineListCheckBox*> m_checkboxes;
     103    QVBoxLayout *m_pLayout;
    68104};
    69105
    70106UIMachineListMenu::UIMachineListMenu(QWidget *pParent /* = 0 */)
    71107    :QWidget(pParent)
    72 {
     108    , m_pLayout(0)
     109{
     110    m_pLayout = new QVBoxLayout(this);
    73111}
    74112
    75113void UIMachineListMenu::clear()
    76114{
    77     QList<QAction*> actionList = actions();
    78     for (int i = 0; i < actionList.size(); ++i)
    79     {
    80         removeAction(actionList[i]);
    81         delete actionList[i];
    82     }
    83 }
    84 
    85 QAction *UIMachineListMenu::addAction(const QString &strText)
    86 {
    87     QAction *pAction = new QAction(strText, this);
    88     QWidget::addAction(pAction);
    89     return pAction;
    90 }
     115    qDeleteAll(m_checkboxes.begin(), m_checkboxes.end());
     116    m_checkboxes.clear();
     117}
     118
     119void UIMachineListMenu::addListItem(const QString &strText, const QUuid &id)
     120{
     121    UIMachineListCheckBox *pCheckBox = new UIMachineListCheckBox(strText, this);
     122    m_checkboxes << pCheckBox;
     123    pCheckBox->setId(id);
     124    m_pLayout->addWidget(pCheckBox);
     125    computeMinimumSize();
     126}
     127
     128void UIMachineListMenu::computeMinimumSize()
     129{
     130    int iMaxTextLen = 0;
     131    foreach(const UIMachineListCheckBox *pCheckBox, m_checkboxes)
     132    {
     133        if (!pCheckBox)
     134            continue;
     135        //iMaxTextLen = qMax(iMaxTextLen, fontMetrics().horizontalAdvance(pCheckBox->text()));
     136        iMaxTextLen = qMax(iMaxTextLen, pCheckBox->width());
     137    }
     138    int iWidth = iMaxTextLen + 2 * qApp->style()->pixelMetric(QStyle::PM_ButtonIconSize);
     139    int iHeight = m_checkboxes.size() * fontMetrics().height() +
     140        qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) +
     141        qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
     142    //printf("%d %d\n", iWidth, iHeight);
     143    setMinimumSize(iWidth, iHeight);
     144    update();
     145}
     146
    91147
    92148UIVMLogViewerWidget::Machine::Machine(const QUuid &id, const QString &strName)
     
    192248}
    193249
     250void UIVMLogViewerWidget::resizeEvent(QResizeEvent *pEvent)
     251{
     252    QIWithRetranslateUI<QWidget>::resizeEvent(pEvent);
     253    if (m_pMachineSelectionMenu)
     254        m_pMachineSelectionMenu->move(0, 40);
     255}
     256
    194257void UIVMLogViewerWidget::sltRefresh()
    195258{
     
    486549void UIVMLogViewerWidget::sltCornerButtonToggled(bool fToggle)
    487550{
    488     printf("%d\n", fToggle);
     551    if (m_pMachineSelectionMenu)
     552        m_pMachineSelectionMenu->setVisible(fToggle);
    489553}
    490554
     
    561625            if (m_pCornerButton)
    562626            {
    563                 m_pTabWidget->setCornerWidget(m_pCornerButton, Qt::TopLeftCorner);
     627                m_pTabWidget->setCornerWidget(m_pCornerButton);//, Qt::TopLeftCorner);
     628                m_pCornerButton->setCheckable(true);
    564629                m_pCornerButton->setIcon(UIIconPool::iconSet(":/machine_16px.png"));
    565630                m_pCornerButton->setCheckable(true);
    566631                m_pMachineSelectionMenu = new UIMachineListMenu(this);
     632                m_pMachineSelectionMenu->setAutoFillBackground(true);
     633                m_pMachineSelectionMenu->setVisible(false);
    567634                connect(m_pCornerButton, &QIToolButton::toggled, this, &UIVMLogViewerWidget::sltCornerButtonToggled);
    568635                //m_pCornerButton->setMenu(m_pMachineSelectionMenu);
     
    10081075    foreach (const Machine &machine, m_machines)
    10091076    {
    1010         QAction *pAction = m_pMachineSelectionMenu->addAction(machine.m_strName);
    1011         pAction->setCheckable(true);
    1012         pAction->setData(machine.m_id);
     1077
     1078        m_pMachineSelectionMenu->addListItem(machine.m_strName, machine.m_id);
    10131079    }
    10141080}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r88647 r88658  
    9595    /** Returns whether the window should be maximized when geometry being restored. */
    9696    virtual bool shouldBeMaximized() const /* override */;
     97    void resizeEvent(QResizeEvent *pEvent) /* override */;
    9798
    9899private slots:
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