VirtualBox

Changeset 89011 in vbox


Ignore:
Timestamp:
May 12, 2021 12:53:25 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9930. Label tab fixes

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

Legend:

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

    r88877 r89011  
    3131#include "UIVMLogViewerTextEdit.h"
    3232
    33 
    34 UIVMLogPage::UIVMLogPage(QWidget *pParent /* = 0 */)
     33/*********************************************************************************************************************************
     34*   UIVMLogTab implementation.                                                                                        *
     35*********************************************************************************************************************************/
     36
     37UIVMLogTab::UIVMLogTab(QWidget *pParent, const QUuid &uMachineId)
    3538    : QIWithRetranslateUI<QWidget>(pParent)
     39    , m_uMachineId(uMachineId)
     40{
     41}
     42const QUuid &UIVMLogTab::machineId() const
     43{
     44    return m_uMachineId;
     45}
     46
     47/*********************************************************************************************************************************
     48*   UIVMLogPage implementation.                                                                                        *
     49*********************************************************************************************************************************/
     50
     51UIVMLogPage::UIVMLogPage(QWidget *pParent, const QUuid &uMachineId)
     52    : UIVMLogTab(pParent, uMachineId)
    3653    , m_pMainLayout(0)
    3754    , m_pTextEdit(0)
     
    310327}
    311328
    312 const QUuid &UIVMLogPage::machineId() const
    313 {
    314     return m_machineId;
    315 }
    316 
    317 void UIVMLogPage::setMachineId(const QUuid &machineId)
    318 {
    319     m_machineId = machineId;
    320 }
    321 
    322329void UIVMLogPage::setLogFileId(int iLogFileId)
    323330{
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h

    r88734 r89011  
    4141typedef QPair<int, QString> LogBookmark;
    4242
     43
     44class UIVMLogTab : public QIWithRetranslateUI<QWidget>
     45{
     46
     47    Q_OBJECT;
     48
     49public:
     50
     51    UIVMLogTab(QWidget *pParent, const QUuid &uMachineId);
     52    const QUuid &machineId() const;
     53
     54private:
     55
     56    QUuid m_uMachineId;
     57};
     58
    4359/** UIVMLogPage defines data and functionalities of the each tab page of a UIVMLogViewerWidget.
    4460 *  It stores the original log file content , a list of bookmarks, etc */
    45 class UIVMLogPage  : public QIWithRetranslateUI<QWidget>
     61class UIVMLogPage  : public UIVMLogTab
    4662{
    4763    Q_OBJECT;
     
    5470public:
    5571
    56     UIVMLogPage(QWidget *pParent = 0);
     72    UIVMLogPage(QWidget *pParent, const QUuid &uMachineId);
    5773    ~UIVMLogPage();
    5874
     
    95111    QFont currentFont() const;
    96112    void setCurrentFont(QFont font);
    97 
    98     const QUuid &machineId() const;
    99     void setMachineId(const QUuid &machineId);
    100113
    101114    void setLogFileId(int iLogFileId);
     
    142155        bool           m_bFiltered;
    143156    /** @} */
    144     /** Id of the machine the log shown in this page belongs to. */
    145     QUuid m_machineId;
    146157    /** The id we pass to CMachine::ReadLog. Used while refreshing and saving page content. */
    147158    int m_iLogFileId;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r88972 r89011  
    6161const ULONG uAllowedLogSize = _256M;
    6262
    63 class UILabelTab : public QWidget
    64 {
     63class UILabelTab : public UIVMLogPage
     64{
     65
    6566    Q_OBJECT;
    6667
     
    6869
    6970    UILabelTab(QWidget *pParent, const QUuid &uMachineId)
    70         : QWidget(pParent)
    71         , m_uMachineId(uMachineId)
    72     {
    73     }
    74 
    75 private:
    76 
    77     QUuid m_uMachineId;
    78 
     71        : UIVMLogPage(pParent, uMachineId)
     72    {
     73    }
    7974};
    8075
     
    9186
    9287    UITabBar(QWidget *pParent = 0);
     88
    9389protected:
    9490
    9591    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
    96 
    97 private:
    98 
    99     QVector<QColor> m_alternateColors;
    100     QColor m_selectedTabColor;
    10192};
    10293
     
    123114    :QTabBar(pParent)
    124115{
    125     QStyleOptionTab opt;
    126     m_alternateColors << opt.palette.color(QPalette::Button).darker(180);
    127     m_alternateColors << opt.palette.color(QPalette::Button).darker(120);
    128     m_selectedTabColor = opt.palette.color(QPalette::Button).lighter(300);
    129 
    130     // QStyle *pFusionStyle = QStyleFactory::create("Fusion");
    131     // if (pFusionStyle)
    132     //     setStyle(pFusionStyle);
    133116}
    134117
     
    144127        initStyleOption(&opt, i);
    145128        bool fLabelTab = tabData(i).toBool();
    146         // if (i == currentIndex())
    147         //     opt.palette.setColor(QPalette::Button, m_selectedTabColor);
    148         // else
    149         // {
    150         //     int iColorIndex = tabData(i).toInt();
    151         //     if (iColorIndex >= 0 && iColorIndex <= m_alternateColors.size())
    152         //         opt.palette.setColor(QPalette::Button, m_alternateColors[iColorIndex]);
    153         // }
     129
    154130        if (!fLabelTab)
    155131            painter.drawControl(QStyle::CE_TabBarTabShape, opt);
     
    266242    removeLogViewerPages(unselectedMachines);
    267243    /* Assign color indexes to tabs based on machines. We use two alternating colors to indicate different machine logs. */
    268     setTabColorPerMachine();
     244    markLabelTabs();
     245    labelTabHandler();
    269246    m_pTabWidget->show();
    270247}
    271248
    272 void UIVMLogViewerWidget::setTabColorPerMachine()
     249void UIVMLogViewerWidget::markLabelTabs()
    273250{
    274251    if (!m_pTabWidget || !m_pTabWidget->tabBar() || m_pTabWidget->tabBar()->count() == 0)
    275252        return;
    276253    QTabBar *pTabBar = m_pTabWidget->tabBar();
    277     //int iColorIndex = 0;
    278254
    279255    for (int i = 0; i < pTabBar->count(); ++i)
    280256    {
    281         // UIVMLogPage *pLogPage = logPage(i);
    282         // UIVMLogPage *pLogPagePrev = logPage(i - 1);
    283         // if (!pLogPage || !pLogPagePrev)
    284         //     continue;
    285 
    286         // /* We the machine if the tab is different than that of previous alternate the color index. */
    287         // if (i > 0 && pLogPage->machineId() != pLogPagePrev->machineId())
    288         //     ++iColorIndex;
    289257        if (qobject_cast<UILabelTab*>(m_pTabWidget->widget(i)))
    290258            pTabBar->setTabData(i, true);
     
    390358
    391359    m_pTabWidget->blockSignals(false);
    392     setTabColorPerMachine();
     360    markLabelTabs();
    393361    m_pTabWidget->show();
    394362}
     
    922890}
    923891
    924 void UIVMLogViewerWidget::createLogPage(const QString &strFileName, const QString &strMachineName,
     892void UIVMLogViewerWidget::createLogPage(const QString &strFileName,
    925893                                        const QUuid &machineId, int iLogFileId,
    926894                                        const QString &strLogContent, bool noLogsToShow)
     
    930898
    931899    /* Create page-container: */
    932     UIVMLogPage* pLogPage = new UIVMLogPage(this);
     900    UIVMLogPage* pLogPage = new UIVMLogPage(this, machineId);
    933901    if (pLogPage)
    934902    {
     
    939907        pLogPage->setWrapLines(m_bWrapLines);
    940908        pLogPage->setCurrentFont(m_font);
    941         pLogPage->setMachineId(machineId);
    942909        pLogPage->setLogFileId(iLogFileId);
    943910        /* Set the file name only if we really have log file to read. */
     
    945912            pLogPage->setLogFileName(strFileName);
    946913
    947         /* Add page-container to viewer-container in stacked mode (manager UI case): */
    948         bool fTitleWithMachineName = false;//m_enmEmbedding == EmbedTo_Stack;
    949         QString strTabTitle;
    950         if (fTitleWithMachineName)
    951         {
    952             strTabTitle.append(strMachineName);
    953             strTabTitle.append(" - ");
    954         }
    955         strTabTitle.append(QFileInfo(strFileName).fileName());
    956 
    957         int iIndex = m_pTabWidget->addTab(pLogPage, strTabTitle);
     914        int iIndex = m_pTabWidget->addTab(pLogPage, QFileInfo(strFileName).fileName());
    958915        /* !!Hack alert. Setting html to text edit while th tab is not current ends up in an empty text edit: */
    959916        if (noLogsToShow)
     
    1003960        QString strMachineName = comMachine.GetName();
    1004961
    1005         m_pTabWidget->addTab(new UILabelTab(this, uMachineId), strMachineName);
     962        if (m_enmEmbedding == EmbedTo_Stack)
     963            m_pTabWidget->addTab(new UILabelTab(this, uMachineId), strMachineName);
    1006964
    1007965        bool fNoLogFileForMachine = true;
     
    1013971                fNoLogFileForMachine = false;
    1014972                createLogPage(comMachine.QueryLogFilename(iLogFileId),
    1015                               strMachineName, uMachineId, iLogFileId,
     973                              uMachineId, iLogFileId,
    1016974                              strLogContent, false);
    1017975            }
     
    1023981                                                 "<nobr><b>%2</b></nobr>.</p>")
    1024982                                              .arg(strMachineName).arg(comMachine.GetLogFolder()));
    1025             createLogPage(tr("NoLogFile"), strMachineName, uMachineId, -1 /* iLogFileId */, strDummyTabText, true);
     983            createLogPage(tr("NoLogFile"), uMachineId, -1 /* iLogFileId */, strDummyTabText, true);
    1026984        }
    1027985    }
     
    1037995    m_pTabWidget->blockSignals(true);
    1038996    /* Cache log page pointers and tab titles: */
    1039     QVector<QPair<UIVMLogPage*, QString> > logPages;
     997    QVector<QPair<UIVMLogTab*, QString> > logTabs;
    1040998    for (int i = 0; i < m_pTabWidget->count(); ++i)
    1041999    {
    1042         UIVMLogPage *pTab = logPage(i);
     1000        UIVMLogTab *pTab = logPage(i);
    10431001        if (pTab)
    1044             logPages << QPair<UIVMLogPage*, QString>(pTab, m_pTabWidget->tabText(i));
     1002            logTabs << QPair<UIVMLogTab*, QString>(pTab, m_pTabWidget->tabText(i));
    10451003    }
    10461004    /* Remove all the tabs from tab widget, note that this does not delete tab widgets: */
    10471005    m_pTabWidget->clear();
    1048     QVector<UIVMLogPage*> pagesToRemove;
     1006    QVector<UIVMLogTab*> pagesToRemove;
    10491007    /* Add tab widgets (log pages) back as long as machine id is not in machineList: */
    1050     for (int i = 0; i < logPages.size(); ++i)
    1051     {
    1052         if (!logPages[i].first)
     1008    for (int i = 0; i < logTabs.size(); ++i)
     1009    {
     1010        if (!logTabs[i].first)
    10531011            continue;
    1054         const QUuid &id = logPages[i].first->machineId();
     1012        const QUuid &id = logTabs[i].first->machineId();
    10551013
    10561014        if (machineList.contains(id))
    1057             pagesToRemove << logPages[i].first;
     1015            pagesToRemove << logTabs[i].first;
    10581016        else
    1059             m_pTabWidget->addTab(logPages[i].first, logPages[i].second);
     1017            m_pTabWidget->addTab(logTabs[i].first, logTabs[i].second);
    10601018    }
    10611019    /* Delete all the other pages: */
     
    10691027        return;
    10701028
    1071     QVector<UIVMLogPage*> pagesToRemove = logPages();
     1029    QVector<QWidget*> pagesToRemove;
     1030    for (int i = 0; i < m_pTabWidget->count(); ++i)
     1031        pagesToRemove << m_pTabWidget->widget(i);
    10721032    m_pTabWidget->clear();
    10731033    qDeleteAll(pagesToRemove.begin(), pagesToRemove.end());
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r88972 r89011  
    172172
    173173    /** Returns the newly created log-page using @a strPage filename. */
    174     void createLogPage(const QString &strFileName, const QString &strMachineName,
     174    void createLogPage(const QString &strFileName,
    175175                       const QUuid &machineId, int iLogFileId,
    176176                       const QString &strLogContent, bool noLogsToShow);
     
    187187    void removeLogViewerPages(const QVector<QUuid> &machineList);
    188188    void removeAllLogPages();
    189     /** We alternate tab colors between two `darker and lighter` one per machine. This function goes over tabs and
    190       * sets tab data so tab our QTabBar extension can color tabs correctly. */
    191     void setTabColorPerMachine();
     189    void markLabelTabs();
    192190
    193191    /** Resets document (of the curent tab) and scrollbar highligthing */
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