Changeset 80206 in vbox
- Timestamp:
- Aug 9, 2019 9:45:22 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp
r79365 r80206 979 979 UIIndicatorFeatures(UISession *pSession) 980 980 : UISessionStateStatusBarIndicator(IndicatorType_Features, pSession) 981 , m_iCPULoadPercentage(0) 981 982 { 982 983 /* Assign state-icons: */ … … 986 987 /** @todo New indicator icon, vm_execution_engine_native_api_16px.png, V inside a turtle / tortoise. @bugref{9044} */ 987 988 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 } 988 1000 /* Translate finally: */ 989 1001 retranslateUi(); 1002 } 1003 1004 protected: 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 1021 private 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(); 990 1049 } 991 1050 … … 1054 1113 setState(enmEngine); 1055 1114 } 1115 1116 QTimer *m_pTimerAutoUpdate; 1117 ULONG m_iCPULoadPercentage; 1056 1118 }; 1057 1119
Note:
See TracChangeset
for help on using the changeset viewer.