VirtualBox

Ignore:
Timestamp:
Apr 28, 2024 8:59:22 AM (10 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
162958
Message:

FE/Qt. bugref:9510. Now data series colors can be changed via the preferences widget.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/activity
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/overview/UIVMActivityToolWidget.cpp

    r104445 r104449  
    6363    , m_pTabWidget(0)
    6464{
     65    m_dataSeriesColor[0] = QApplication::palette().color(QPalette::LinkVisited);
     66    m_dataSeriesColor[1] = QApplication::palette().color(QPalette::Link);
    6567    prepare();
    6668    prepareActions();
     
    9698
    9799    m_pPaneContainer = new UIVMActivityMonitorPaneContainer(this, m_enmEmbedding);
     100    for (int i = 0; i < 2; ++i)
     101        m_pPaneContainer->setDataSeriesColor(i, m_dataSeriesColor[i]);
    98102    m_pPaneContainer->hide();
    99103    pMainLayout->addWidget(m_pPaneContainer);
    100104    connect(m_pTabWidget, &QTabWidget::currentChanged,
    101105            this, &UIVMActivityToolWidget::sltCurrentTabChanged);
     106    connect(m_pPaneContainer, &UIVMActivityMonitorPaneContainer::sigColorChanged,
     107            this, &UIVMActivityToolWidget::sltDataSeriesColorChanged);
    102108}
    103109
     
    209215        {
    210216            CMachine comMachine = pMachine->toLocal()->machine();
    211             m_pTabWidget->addTab(new UIVMActivityMonitorLocal(m_enmEmbedding, this, comMachine), comMachine.GetName());
     217            UIVMActivityMonitorLocal *pActivityMonitor = new UIVMActivityMonitorLocal(m_enmEmbedding, this, comMachine);
     218            pActivityMonitor->setDataSeriesColor(0, m_dataSeriesColor[0]);
     219            pActivityMonitor->setDataSeriesColor(1, m_dataSeriesColor[1]);
     220            m_pTabWidget->addTab(pActivityMonitor, comMachine.GetName());
    212221            continue;
    213222        }
     
    217226            if (!comMachine.isOk())
    218227                continue;
    219             m_pTabWidget->addTab(new UIVMActivityMonitorCloud(m_enmEmbedding, this, comMachine), comMachine.GetName());
     228            UIVMActivityMonitorCloud *pActivityMonitor = new UIVMActivityMonitorCloud(m_enmEmbedding, this, comMachine);
     229            pActivityMonitor->setDataSeriesColor(0, m_dataSeriesColor[0]);
     230            pActivityMonitor->setDataSeriesColor(1, m_dataSeriesColor[1]);
     231            m_pTabWidget->addTab(pActivityMonitor, comMachine.GetName());
    220232            continue;
    221233        }
     
    252264}
    253265
     266void UIVMActivityToolWidget::sltDataSeriesColorChanged(int iIndex, const QColor &color)
     267{
     268    for (int i = m_pTabWidget->count() - 1; i >= 0; --i)
     269    {
     270        UIVMActivityMonitor *pMonitor = qobject_cast<UIVMActivityMonitor*>(m_pTabWidget->widget(i));
     271        if (!pMonitor)
     272            continue;
     273        pMonitor->setDataSeriesColor(iIndex, color);
     274        if (iIndex >= 0 && iIndex < 2)
     275            m_dataSeriesColor[iIndex] = color;
     276    }
     277}
     278
    254279void UIVMActivityToolWidget::setExportActionEnabled(bool fEnabled)
    255280{
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/overview/UIVMActivityToolWidget.h

    r104445 r104449  
    3333
    3434/* Qt includes: */
     35#include <QColor>
    3536#include <QWidget>
    3637#include <QUuid>
     
    7778    void sltCurrentTabChanged(int iIndex);
    7879    void sltTogglePreferencesPane(bool fChecked);
     80    void sltDataSeriesColorChanged(int iIndex, const QColor &color);
    7981
    8082private:
     
    111113    UIVMActivityMonitorPaneContainer *m_pPaneContainer;
    112114    QTabWidget *m_pTabWidget;
     115    QColor m_dataSeriesColor[2];
    113116};
    114117
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp

    r104445 r104449  
    130130    void sltSetShowPieChart(bool fShowPieChart);
    131131    void sltSetUseAreaChart(bool fUseAreaChart);
    132     void sltSelectDataSeriesColor();
    133132    void sltRetranslateUI();
    134133
     
    227226    connect(this, &UIChart::customContextMenuRequested,
    228227            this, &UIChart::sltCreateContextMenu);
    229 
    230     setDataSeriesColor(0, QApplication::palette().color(QPalette::LinkVisited));
    231     setDataSeriesColor(1, QApplication::palette().color(QPalette::Link));
    232228
    233229    m_iMarginLeft = 3 * QFontMetricsF(m_axisFont).averageCharWidth();
     
    849845        connect(pAreaChartToggle, &QAction::toggled, this, &UIChart::sltSetUseAreaChart);
    850846    }
    851     QAction *pSelectColor0 = menu.addAction(m_strSelectChartColor0);
    852     pSelectColor0->setData(0);
    853     connect(pSelectColor0, &QAction::triggered, this, &UIChart::sltSelectDataSeriesColor);
    854 
    855     QAction *pSelectColor1 = menu.addAction(m_strSelectChartColor1);
    856     pSelectColor1->setData(1);
    857     connect(pSelectColor1, &QAction::triggered, this, &UIChart::sltSelectDataSeriesColor);
    858 
    859847    menu.exec(mapToGlobal(point));
    860848}
     
    874862{
    875863    setUseAreaChart(fUseAreaChart);
    876 }
    877 
    878 void UIChart::sltSelectDataSeriesColor()
    879 {
    880     QAction *pSenderAction = qobject_cast<QAction*>(sender());
    881     if (!pSenderAction)
    882         return;
    883     int iIndex = pSenderAction->data().toInt();
    884     if (iIndex < 0 || iIndex >= DATA_SERIES_SIZE)
    885         return;
    886 
    887     QColorDialog colorDialog(m_dataSeriesColor[iIndex], this);
    888     if (colorDialog.exec() == QDialog::Rejected)
    889         return;
    890     QColor newColor = colorDialog.selectedColor();
    891     if (m_dataSeriesColor[iIndex] == newColor)
    892         return;
    893     m_dataSeriesColor[iIndex] = newColor;
    894     update();
    895864}
    896865
     
    12661235}
    12671236
     1237void UIVMActivityMonitor::setDataSeriesColor(int iIndex, const QColor &color)
     1238{
     1239    if (iIndex < 0 || iIndex >= DATA_SERIES_SIZE)
     1240        return;
     1241    m_dataSeriesColor[iIndex] = color;
     1242
     1243    foreach (UIChart *pChart, m_charts)
     1244        if (pChart)
     1245            pChart->setDataSeriesColor(iIndex, color);
     1246}
     1247
    12681248/*********************************************************************************************************************************
    12691249*   UIVMActivityMonitorLocal definition.                                                                         *
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h

    r104445 r104449  
    3333
    3434/* Qt includes: */
     35#include <QColor>
    3536#include <QWidget>
    3637#include <QMap>
     
    157158    virtual QUuid machineId() const = 0;
    158159    virtual QString machineName() const = 0;
     160    void setDataSeriesColor(int iIndex, const QColor &color);
    159161
    160162public slots:
     
    184186    void prepareActions();
    185187    void setInfoLabelWidth();
     188
    186189    QGridLayout            *m_pContainerLayout;
    187190    QTimer                 *m_pTimer;
     
    222225    int m_iMaximumLabelLength;
    223226    int m_iMaximumQueueSize;
     227    QColor m_dataSeriesColor[DATA_SERIES_SIZE];
    224228
    225229private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitorPaneContainer.cpp

    r104448 r104449  
    2828/* Qt includes: */
    2929#include <QApplication>
     30#include <QColor>
     31#include <QColorDialog>
    3032#include <QHBoxLayout>
    3133#include <QLabel>
     34#include <QPainter>
     35#include <QPixmap>
    3236#include <QPlainTextEdit>
    3337#include <QPushButton>
     38#include <QStyle>
    3439
    3540/* GUI includes: */
     
    3742#include "UIVMActivityMonitorPaneContainer.h"
    3843
     44/* Other includes: */
     45#include "iprt/assert.h"
     46
    3947UIVMActivityMonitorPaneContainer::UIVMActivityMonitorPaneContainer(QWidget *pParent,
    4048                                                                   EmbedTo enmEmbedTo /* = EmbedTo_Stack */)
    4149    : UIPaneContainer(pParent, enmEmbedTo, false /* detach not allowed */)
    42     , m_pColorLabel0(0)
    43     , m_pColorLabel1(0)
    44     , m_pColorChangeButton0(0)
    45     , m_pColorChangeButton1(0)
     50    , m_pColorLabel{0, 0}
     51    , m_pColorChangeButton{0, 0}
    4652{
    4753    prepare();
     
    5056void UIVMActivityMonitorPaneContainer::prepare()
    5157{
    52     sltRetranslateUI();
    53 
    5458    QWidget *pContainerWidget = new QWidget(this);
    5559    QVBoxLayout *pContainerLayout = new QVBoxLayout(pContainerWidget);
    56     insertTab(0, pContainerWidget, m_strTabText);
     60    insertTab(Tab_Preferences, pContainerWidget, "");
    5761
    58     QHBoxLayout *pColorLayout0 = new QHBoxLayout(this);
    59     m_pColorLabel0 = new QLabel(this);
    60     m_pColorChangeButton0 = new QPushButton(this);
    61     pColorLayout0->addWidget(m_pColorLabel0);
    62     pColorLayout0->addWidget(m_pColorChangeButton0);
     62    for (int i = 0; i < 2; ++i)
     63    {
     64        QHBoxLayout *pColorLayout = new QHBoxLayout;
     65        m_pColorLabel[i] = new QLabel(this);
     66        m_pColorChangeButton[i] = new QPushButton(this);
     67        pColorLayout->addWidget(m_pColorLabel[i]);
     68        pColorLayout->addWidget(m_pColorChangeButton[i]);
     69        pColorLayout->addStretch();
     70        pContainerLayout->addLayout(pColorLayout);
     71        connect(m_pColorChangeButton[i], &QPushButton::pressed,
     72                this, &UIVMActivityMonitorPaneContainer::sltColorChangeButtonPressed);
     73    }
    6374
    64     QHBoxLayout *pColorLayout1 = new QHBoxLayout(this);
    65     m_pColorLabel1 = new QLabel(this);
    66     m_pColorChangeButton1 = new QPushButton(this);
    67     pColorLayout1->addWidget(m_pColorLabel1);
    68     pColorLayout1->addWidget(m_pColorChangeButton1);
     75    pContainerLayout->addStretch();
    6976
    70     pContainerLayout->addLayout(pColorLayout0);
    71     pContainerLayout->addLayout(pColorLayout1);
    72 
    73 
     77    sltRetranslateUI();
    7478    connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
    7579            this, &UIVMActivityMonitorPaneContainer::sltRetranslateUI);
     
    7882void UIVMActivityMonitorPaneContainer::sltRetranslateUI()
    7983{
    80     m_strTabText = QApplication::translate("UIVMActivityMonitorPaneContainer", "Preferences");
     84    setTabText(Tab_Preferences, QApplication::translate("UIVMActivityMonitorPaneContainer", "Preferences"));
    8185
    82     if (m_pColorLabel0)
    83         m_pColorLabel0->setText(QApplication::translate("UIVMActivityMonitorPaneContainer", "Data Series 1 Color"));
    84     if (m_pColorLabel1)
    85         m_pColorLabel1->setText(QApplication::translate("UIVMActivityMonitorPaneContainer", "Data Series 1 Color"));
     86    if (m_pColorLabel[0])
     87        m_pColorLabel[0]->setText(QApplication::translate("UIVMActivityMonitorPaneContainer", "Data Series 1 Color"));
     88    if (m_pColorLabel[1])
     89        m_pColorLabel[1]->setText(QApplication::translate("UIVMActivityMonitorPaneContainer", "Data Series 2 Color"));
    8690}
     91
     92void UIVMActivityMonitorPaneContainer::colorPushButtons(QPushButton *pButton, const QColor &color)
     93{
     94    AssertReturnVoid(pButton);
     95    int iSize = qApp->style()->pixelMetric(QStyle::PM_ButtonIconSize);
     96    QPixmap iconPixmap(iSize, iSize);
     97    QPainter painter(&iconPixmap);
     98    painter.setBrush(color);
     99    painter.drawRect(iconPixmap.rect());
     100    pButton->setIcon(QIcon(iconPixmap));
     101}
     102
     103void UIVMActivityMonitorPaneContainer::setDataSeriesColor(int iIndex, const QColor &color)
     104{
     105    if (iIndex == 0 || iIndex == 1)
     106    {
     107        m_color[iIndex] = color;
     108        colorPushButtons(m_pColorChangeButton[iIndex], color);
     109    }
     110}
     111
     112void UIVMActivityMonitorPaneContainer::sltColorChangeButtonPressed()
     113{
     114    int iIndex = -1;
     115    if (sender() == m_pColorChangeButton[0])
     116        iIndex = 0;
     117    else if (sender() == m_pColorChangeButton[1])
     118        iIndex = 1;
     119    else
     120        return;
     121
     122    QColorDialog colorDialog(m_color[iIndex], this);
     123    if (colorDialog.exec() == QDialog::Rejected)
     124        return;
     125    QColor newColor = colorDialog.selectedColor();
     126    if (m_color[iIndex] == newColor)
     127        return;
     128    m_color[iIndex] = newColor;
     129    colorPushButtons(m_pColorChangeButton[iIndex], newColor);
     130    emit sigColorChanged(iIndex, newColor);
     131}
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitorPaneContainer.h

    r104448 r104449  
    3636#include "UIPaneContainer.h"
    3737
     38class QColor;
    3839class QLabel;
    3940class QPushButton;
     
    4445    Q_OBJECT;
    4546
     47signals:
     48
     49    void sigColorChanged(int iIndex, const QColor &color);
     50
    4651public:
    4752
    4853    UIVMActivityMonitorPaneContainer(QWidget *pParent, EmbedTo enmEmbedTo = EmbedTo_Stack);
     54    void setDataSeriesColor(int iIndex, const QColor &color);
    4955
    5056private slots:
    5157
    5258    void sltRetranslateUI();
     59    void sltColorChangeButtonPressed();
    5360
    5461private:
     62    enum Tab
     63    {
     64        Tab_Preferences = 0
     65    };
    5566
    5667    void prepare();
     68    void colorPushButtons(QPushButton *pButton, const QColor &color);
    5769    QString m_strTabText;
    5870
    5971
    60     QLabel *m_pColorLabel0;
    61     QLabel *m_pColorLabel1;
     72    QLabel *m_pColorLabel[2];
     73    QPushButton *m_pColorChangeButton[2];
    6274
    63     QPushButton *m_pColorChangeButton0;
    64     QPushButton *m_pColorChangeButton1;
    6575
     76    QColor m_color[2];
    6677
    6778};
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