Skip to content

Commit

Permalink
fix: 插件里延迟读取系统信息
Browse files Browse the repository at this point in the history
插件里延迟读取系统信息

Log: 插件里延迟读取系统信息
  • Loading branch information
wyu71 committed Mar 14, 2024
1 parent 7f2031d commit 5891efb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
28 changes: 23 additions & 5 deletions deepin-system-monitor-plugin/gui/monitor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,23 @@ QIcon MonitorPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::Color
}
#endif

void MonitorPlugin::udpateTipsInfo()
void MonitorPlugin::udpateInfo()
{
// memory
qlonglong memory = 0;
qlonglong memoryAll = 0;
calcMemRate(memory, memoryAll);
m_memStr = QString("%1").arg(memory * 100.0 / memoryAll, 1, 'f', 1, QLatin1Char(' '));
m_memStr = QString("%1").arg(memory * 100.0 / memoryAll, 1, 'f', 1, QLatin1Char(' ')) + QString("%");

// CPU
qlonglong totalCPU = 0;
qlonglong availableCPU = 0;
calcCpuRate(totalCPU, availableCPU);
m_cpuStr = QString("%1").arg((((totalCPU - m_totalCPU) - (availableCPU - m_availableCPU)) * 100.0 / (totalCPU - m_totalCPU)), 1, 'f', 1, QLatin1Char(' '));
double cpuPercent = 0.0;
if (totalCPU != m_totalCPU) {
cpuPercent = ((totalCPU - m_totalCPU) - (availableCPU - m_availableCPU)) * 100.0 / (totalCPU - m_totalCPU);
}
m_cpuStr = QString("%1").arg(cpuPercent, 1, 'f', 1, QLatin1Char(' ')) + QString("%");
m_totalCPU = totalCPU;
m_availableCPU = availableCPU;

Expand All @@ -278,7 +282,11 @@ void MonitorPlugin::udpateTipsInfo()

m_down = netDownload;
m_upload = netUpload;
}

void MonitorPlugin::udpateTipsInfo()
{
udpateInfo();
m_dataTipsLabel->setSystemMonitorTipsText(QStringList() << m_cpuStr << m_memStr << m_downloadStr << m_uploadStr);
}

Expand All @@ -292,8 +300,18 @@ void MonitorPlugin::loadPlugin()
m_dataTipsLabel.reset(new SystemMonitorTipsWidget);
m_dataTipsLabel->setObjectName("systemmonitorpluginlabel");

m_refershTimer->setInterval(2000);
m_refershTimer->start();
m_refershTimer->setInterval(1000);
// m_refershTimer->start();

connect(m_dataTipsLabel.get(),&SystemMonitorTipsWidget::visibleChanged,this,[=](bool visible){
if (!visible) {
m_refershTimer->stop();
} else {
udpateInfo();
m_dataTipsLabel->setSystemMonitorTipsText(QStringList() << "..." << "..." << "..." << "...");
m_refershTimer->start();
}
});

m_itemWidget = new MonitorPluginButtonWidget;

Expand Down
4 changes: 4 additions & 0 deletions deepin-system-monitor-plugin/gui/monitor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class MonitorPlugin : public QObject, PLUGIN_INTERDACE
#endif

private slots:
//!
//! \brief udpateInfo 更新CPU MEM NET信息
//!
void udpateInfo();

//!
//! \brief udpateTipsInfo 更新CPU MEM NET信息
Expand Down
13 changes: 9 additions & 4 deletions deepin-system-monitor-plugin/gui/systemmonitortipswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ void SystemMonitorTipsWidget::setSystemMonitorTipsText(QStringList strList)

// 设置左侧字符串宽度
if (cpu.length() == 3) {
m_leftWidth = fontMetrics().width(QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": 0") + cpu + QString("%") + QString(" "));
m_leftWidth = fontMetrics().width(QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": 0") + cpu + QString(" "));
} else {
m_leftWidth = fontMetrics().width(QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": ") + cpu + QString("%") + QString(" "));
m_leftWidth = fontMetrics().width(QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": ") + cpu + QString(" "));
}
// 左侧宽度预留20个像素
m_leftWidth += 20;
Expand Down Expand Up @@ -125,7 +125,7 @@ void SystemMonitorTipsWidget::paintEvent(QPaintEvent *event)

painter.setPen(QPen(palette().brightText(), 1));
// 绘制CPU文字信息
painter.drawText(QRectF(leftMargin, 0.0, m_leftWidth, rectHeight / 2.0), QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": ") + cpu + QString("%"), optionLeft);
painter.drawText(QRectF(leftMargin, 0.0, m_leftWidth, rectHeight / 2.0), QString(" ") + DApplication::translate("Plugin.cpu", "CPU") + QString(": ") + cpu, optionLeft);


// 绘制下箭头
Expand All @@ -151,7 +151,7 @@ void SystemMonitorTipsWidget::paintEvent(QPaintEvent *event)
painter.restore();

// 绘制内存文字信息
painter.drawText(QRectF(leftMargin, rectHeight / 2.0, m_leftWidth, rectHeight / 2.0), QString(" ") + DApplication::translate("Plugin.mem", "MEM") + QString(": ") + mem + QString("%"), optionLeft);
painter.drawText(QRectF(leftMargin, rectHeight / 2.0, m_leftWidth, rectHeight / 2.0), QString(" ") + DApplication::translate("Plugin.mem", "MEM") + QString(": ") + mem, optionLeft);
painter.save();
painter.setPen(QPen(palette().brightText(), 2));
painter.setRenderHints(QPainter::Antialiasing);
Expand All @@ -177,6 +177,11 @@ bool SystemMonitorTipsWidget::event(QEvent *event)
setSystemMonitorTipsText(m_textList);
else
setSystemMonitorTipsText(QStringList() << "0.0" << "0.0" << "0KB/s" << "0KB/s");
} else if (event->type() == QEvent::Hide) {
Q_EMIT visibleChanged(false);
} else if (event->type() == QEvent::Show) {
Q_EMIT visibleChanged(true);
}

return QFrame::event(event);
}
4 changes: 4 additions & 0 deletions deepin-system-monitor-plugin/gui/systemmonitortipswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QFrame>
class SystemMonitorTipsWidget : public QFrame
{
Q_OBJECT
public:
explicit SystemMonitorTipsWidget(QWidget *parent = nullptr);

Expand All @@ -18,6 +19,9 @@ class SystemMonitorTipsWidget : public QFrame
//!
void setSystemMonitorTipsText(QStringList strList);

Q_SIGNALS:
void visibleChanged(bool visible);

protected:
//!
//! \brief paintEvent 重绘系统监视器插件提示框
Expand Down

0 comments on commit 5891efb

Please sign in to comment.