VirtualBox

Changeset 80206 in vbox


Ignore:
Timestamp:
Aug 9, 2019 9:45:22 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9510: Putting a small CPU load indication over the machine window status bar CPU icon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp

    r79365 r80206  
    979979    UIIndicatorFeatures(UISession *pSession)
    980980        : UISessionStateStatusBarIndicator(IndicatorType_Features, pSession)
     981        , m_iCPULoadPercentage(0)
    981982    {
    982983        /* Assign state-icons: */
     
    986987        /** @todo New indicator icon, vm_execution_engine_native_api_16px.png, V inside a turtle / tortoise.  @bugref{9044} */
    987988        setStateIcon(KVMExecutionEngine_NativeApi, UIIconPool::iconSet(":/vm_execution_engine_native_api_16px.png"));
     989
     990        /* Configure machine state-change listener: */
     991        connect(m_pSession, SIGNAL(sigMachineStateChange()),
     992                this, SLOT(sltHandleMachineStateChange()));
     993        m_pTimerAutoUpdate = new QTimer(this);
     994        if (m_pTimerAutoUpdate)
     995        {
     996            connect(m_pTimerAutoUpdate, &QTimer::timeout, this, &UIIndicatorFeatures::sltTimeout);
     997            /* Start the timer immediately if the machine is running: */
     998            sltHandleMachineStateChange();
     999        }
    9881000        /* Translate finally: */
    9891001        retranslateUi();
     1002    }
     1003
     1004protected:
     1005
     1006    virtual void paintEvent(QPaintEvent *pEvent) /* override */
     1007    {
     1008        UISessionStateStatusBarIndicator::paintEvent(pEvent);
     1009        QPainter painter(this);
     1010
     1011        /* Draw a thin bar on th right hand side of the icon indication CPU load: */
     1012        QLinearGradient gradient(0, 0, 0, height());
     1013        gradient.setColorAt(1.0, Qt::green);
     1014        gradient.setColorAt(0.0, Qt::red);
     1015        painter.setPen(Qt::NoPen);
     1016        painter.setBrush(gradient);
     1017        /* Use 20% of the icon width to draw the indicator bar: */
     1018        painter.drawRect(0.8 * width(), (100 - m_iCPULoadPercentage) / 100.f * height(), width(),  height());
     1019    }
     1020
     1021private slots:
     1022
     1023    /** Updates auto-update timer depending on machine state. */
     1024    void sltHandleMachineStateChange()
     1025    {
     1026        if (m_pSession->machineState() == KMachineState_Running)
     1027        {
     1028            /* Start auto-update timer otherwise: */
     1029            m_pTimerAutoUpdate->start(1000);
     1030            return;
     1031        }
     1032        /* Stop auto-update timer otherwise: */
     1033        m_pTimerAutoUpdate->stop();
     1034    }
     1035
     1036    void sltTimeout()
     1037    {
     1038        if (!m_pSession)
     1039            return;
     1040        CMachineDebugger comMachineDebugger = m_pSession->debugger();
     1041        if (comMachineDebugger.isNull())
     1042            return;
     1043        ULONG aPctExecuting;
     1044        ULONG aPctHalted;
     1045        ULONG aPctOther;
     1046        comMachineDebugger.GetCPULoad(0x7fffffff, aPctExecuting, aPctHalted, aPctOther);
     1047        m_iCPULoadPercentage = aPctExecuting;
     1048        update();
    9901049    }
    9911050
     
    10541113        setState(enmEngine);
    10551114    }
     1115
     1116    QTimer *m_pTimerAutoUpdate;
     1117    ULONG m_iCPULoadPercentage;
    10561118};
    10571119
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