VirtualBox

Changeset 88815 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 3, 2021 8:56:02 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9930. Giving alternating colors to tabs based on machine id

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

Legend:

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

    r88766 r88815  
    2222#include <QFont>
    2323#include <QMenu>
     24#include <QPalette>
    2425#include <QPainter>
    2526#include <QPlainTextEdit>
    2627#include <QScrollBar>
    2728#include <QStyle>
     29#include <QStylePainter>
     30#include <QStyleOptionTab>
     31#include <QTabBar>
    2832#include <QTextBlock>
    2933#include <QVBoxLayout>
     
    5559/** Limit the read string size to avoid bloated log viewer pages. */
    5660const ULONG uAllowedLogSize = _256M;
     61
     62class UITabBar : public QTabBar
     63{
     64    Q_OBJECT;
     65public:
     66    UITabBar(QWidget *pParent = 0)
     67        :QTabBar(pParent)
     68    {
     69        QStyleOptionTab opt;
     70        m_alternateColors << opt.palette.color(QPalette::Button).lighter(125);
     71        m_alternateColors << opt.palette.color(QPalette::Button).darker(125);
     72    }
     73
     74    void paintEvent(QPaintEvent * /*event*/) {
     75
     76        QStylePainter painter(this);
     77        QStyleOptionTab opt;
     78
     79        for (int i = 0; i < count(); i++) {
     80            initStyleOption(&opt, i);
     81            int iColorIndex = tabData(i).toInt();
     82            if (iColorIndex >= 0 && iColorIndex <= m_alternateColors.size())
     83            {
     84                opt.palette.setColor(QPalette::Button, m_alternateColors[iColorIndex]);
     85            }
     86
     87            painter.drawControl(QStyle::CE_TabBarTabShape, opt);
     88            painter.drawControl(QStyle::CE_TabBarTabLabel, opt);
     89        }
     90    }
     91private:
     92    QVector<QColor> m_alternateColors;
     93};
     94
     95class UITabWidget : public QTabWidget
     96{
     97    Q_OBJECT;
     98public:
     99    UITabWidget(QWidget *pParent = 0)
     100        :QTabWidget(pParent)
     101    {
     102        setTabBar(new UITabBar(this));
     103    }
     104};
    57105
    58106class UIMachineListCheckBox : public QCheckBox
     
    229277    /* Remove the log pages/tabs of unselected machines from the tab widget: */
    230278    removeLogViewerPages(unselectedMachines);
     279    setTabColorPerMachine();
    231280    m_pTabWidget->show();
     281}
     282
     283void UIVMLogViewerWidget::setTabColorPerMachine()
     284{
     285    if (!m_pTabWidget || !m_pTabWidget->tabBar() || m_pTabWidget->tabBar()->count() == 0)
     286        return;
     287    QTabBar *pTabBar = m_pTabWidget->tabBar();
     288    int iColorIndex = 0;
     289    pTabBar->setTabData(0, iColorIndex);
     290
     291    for (int i = 1; i < pTabBar->count(); ++i)
     292    {
     293        UIVMLogPage *pLogPage = logPage(i);
     294        UIVMLogPage *pLogPagePrev = logPage(i - 1);
     295        if (!pLogPage || !pLogPagePrev)
     296            continue;
     297        if (pLogPage->machineId() != pLogPagePrev->machineId())
     298            ++iColorIndex;
     299        pTabBar->setTabData(i, iColorIndex % 2);
     300    }
    232301}
    233302
     
    589658
    590659        /* Create VM Log-Viewer container: */
    591         m_pTabWidget = new QITabWidget;
     660        m_pTabWidget = new UITabWidget;
    592661        if (m_pTabWidget)
    593662        {
     
    873942        }
    874943        strTabTitle.append(QFileInfo(strFileName).fileName());
    875         m_pTabWidget->insertTab(m_pTabWidget->count(), pLogPage, strTabTitle);
     944        m_pTabWidget->addTab(pLogPage, strTabTitle);
    876945
    877946        pLogPage->setLogContent(strLogContent, noLogsToShow);
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r88766 r88815  
    3838/* Forward declarations: */
    3939class QITabWidget;
     40class UITabWidget;
    4041class QPlainTextEdit;
    4142class QVBoxLayout;
     
    182183    /** Removes the log pages/tabs that shows logs of the machines from @p machineList. */
    183184    void removeLogViewerPages(const QVector<QUuid> &machineList);
     185    void setTabColorPerMachine();
    184186
    185187    /** Resets document (of the curent tab) and scrollbar highligthing */
     
    210212
    211213    /** Holds container for log-pages. */
    212     QITabWidget        *m_pTabWidget;
     214    UITabWidget        *m_pTabWidget;
    213215
    214216    /** @name Panel instances and a QMap for mapping panel instances to related actions.
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