Skip to content

Commit

Permalink
fix: Fix the bug where the taskbar height was compressed when it was …
Browse files Browse the repository at this point in the history
…minimized.

Along with modifying the display style of the control layout to achieve its purpose
  • Loading branch information
XMuli committed Nov 19, 2020
1 parent d0460b2 commit f37d744
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 19 deletions.
4 changes: 2 additions & 2 deletions speedinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ QString SpeedInfo::setRateUnitSensitive(RateUnit unit, Sensitive sensitive)
case Sensitive::Default: {
switch (unit) {
case RateUnit::RateBit:
return QString("Bit/s");
return QString("b/s");
case RateUnit::RateByte:
return QString("Byte/s");
return QString("B/s");
case RateUnit::RateKb:
return QString("Kb/s");
case RateUnit::RateMb:
Expand Down
39 changes: 38 additions & 1 deletion speedplugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "speedplugin.h"

#include <DMessageBox>
DWIDGET_USE_NAMESPACE

SpeedPlugin::SpeedPlugin(QObject *parent)
:QObject(parent)
{
Expand All @@ -8,7 +11,9 @@ SpeedPlugin::SpeedPlugin(QObject *parent)

const QString SpeedPlugin::pluginName() const
{
return QString("lfxSpeed");
// return QString("lfxSpeed");

return "datetime"; // 假装我也叫这个,否则会被压缩,在 1.2.3 版本中才被修改
}

void SpeedPlugin::init(PluginProxyInterface *proxyInter)
Expand Down Expand Up @@ -58,3 +63,35 @@ const QString SpeedPlugin::pluginDisplayName() const
{
return QString("lfxSpeed");
}

const QString SpeedPlugin::itemContextMenu(const QString &itemKey)
{
Q_UNUSED(itemKey);

QList<QVariant> items;
items.reserve(1);

QMap<QString, QVariant> about;
about["itemId"] = "about";
about["itemText"] = "关于";
about["isActive"] = true;
items.push_back(about);

QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;

// 返回 JSON 格式的菜单数据
return QJsonDocument::fromVariant(menu).toJson();
}

void SpeedPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
Q_UNUSED(itemKey);

if (menuId == "about") {
DMessageBox::about(nullptr, tr("lfxSpeed"), tr("一款轻便、快速的网速插件,欢迎反馈和贡献。\n https://github.com/xmuli/lfxSpeed"));

}
}
8 changes: 8 additions & 0 deletions speedplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

#include <QObject>
#include <pluginsiteminterface.h>
#include <dtkwidget_global.h>

#include "speedwidget.h"

class QTimer;
class SpeedInfo;

DWIDGET_USE_NAMESPACE

class SpeedPlugin : public QObject, public PluginsItemInterface
{
Q_OBJECT
Expand All @@ -26,6 +32,8 @@ class SpeedPlugin : public QObject, public PluginsItemInterface
virtual void pluginStateSwitched() override;

virtual const QString pluginDisplayName() const override;
virtual const QString itemContextMenu(const QString &itemKey) override;
virtual void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override;

private:
PluginProxyInterface *m_proxyInter;
Expand Down
49 changes: 33 additions & 16 deletions speedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ SpeedWidget::SpeedWidget(QWidget *parent)
, m_labDown(nullptr)
, m_labCpu(nullptr)
, m_labMemory(nullptr)
, m_numUpload(nullptr)
, m_numDown(nullptr)
, m_numCpu(nullptr)
, m_numMemory(nullptr)
, m_diskRead(nullptr)
, m_diskWrite(nullptr)
, m_timer(nullptr)
Expand All @@ -43,23 +47,36 @@ SpeedWidget::SpeedWidget(QWidget *parent)
*/
void SpeedWidget::init()
{
m_labUpload = new DLabel(tr("0 kb/s"));
m_labDown = new DLabel(tr("0 kb/s"));
m_labCpu = new DLabel(tr("0 %"));
m_labMemory = new DLabel(tr("0 %"));
m_numUpload = new DLabel(tr("0 Kb/s"));
m_numUpload->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_numDown = new DLabel(tr("0 Kb/s"));
m_numDown->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_numCpu = new DLabel(tr("0 %"));
m_numCpu->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_numMemory = new DLabel(tr("0 %"));
m_numMemory->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
// m_diskRead = new DLabel(tr("↗: 0 kb/s"));
// m_diskWrite = new DLabel(tr("↙: 0 kb/s"));

QGridLayout *layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(new DLabel(tr("↑: ")), 0, 0);
layout->addWidget(m_labUpload, 0, 1);
layout->addWidget(new DLabel(tr("↓: ")), 1, 0);
layout->addWidget(m_labDown, 1, 1);
layout->addWidget(new DLabel(tr("CPU: ")), 0, 2);
layout->addWidget(m_labCpu, 0, 3);
layout->addWidget(new DLabel(tr("MEM: ")), 1, 2);
layout->addWidget(m_labMemory, 1, 3);

m_labUpload = new DLabel(tr("↑: "));
m_labUpload->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_labDown = new DLabel(tr("↓: "));
m_labDown->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_labCpu = new DLabel(tr(" CPU: "));
m_labCpu->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_labMemory = new DLabel(tr(" MEM: "));
m_labMemory->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
layout->addWidget(m_labUpload, 0, 0);
layout->addWidget(m_numUpload, 0, 1);
layout->addWidget(m_labDown, 1, 0);
layout->addWidget(m_numDown, 1, 1);
layout->addWidget(m_labCpu, 0, 2);
layout->addWidget(m_numCpu, 0, 3);
layout->addWidget(m_labMemory, 1, 2);
layout->addWidget(m_numMemory, 1, 3);
// layout->addWidget(m_diskRead, 0, 2);
// layout->addWidget(m_diskWrite, 1, 2);

Expand Down Expand Up @@ -95,8 +112,8 @@ void SpeedWidget::onUpdateNet()
unit = SpeedInfo::RateByte;
uploadRate = m_info->autoRateUnits(upload - m_upload, unit);
QString uploadUnit = m_info->setRateUnitSensitive(unit, SpeedInfo::Default);
m_labDown->setText(QString("%1").arg(downRate, 0, 'f', 2, QLatin1Char(' ')) + downUnit);
m_labUpload->setText(QString("%1").arg(uploadRate, 0, 'f', 2, QLatin1Char(' ')) + uploadUnit);
m_numDown->setText(QString("%1").arg(downRate, 0, 'f', 2, QLatin1Char(' ')) + downUnit);
m_numUpload->setText(QString("%1").arg(uploadRate, 0, 'f', 2, QLatin1Char(' ')) + uploadUnit);

m_down = down;
m_upload = upload;
Expand All @@ -107,7 +124,7 @@ void SpeedWidget::onUpdateCpu()
long cpuAll = 0;
long cpuFree = 0;
m_info->cpuRate(cpuAll, cpuFree);
m_labCpu->setText(QString("%1%").arg((((cpuAll - m_cpuAll) - (cpuFree - m_cpuFree)) * 100.0 / (cpuAll - m_cpuAll)), 0, 'f', 2, QLatin1Char(' ')));
m_numCpu->setText(QString("%1%").arg((((cpuAll - m_cpuAll) - (cpuFree - m_cpuFree)) * 100.0 / (cpuAll - m_cpuAll)), 0, 'f', 2, QLatin1Char(' ')));

m_cpuAll = cpuAll;
m_cpuFree = cpuFree;
Expand All @@ -121,5 +138,5 @@ void SpeedWidget::onUpdateMemory()
long swapAll = 0;

m_info->memoryRate(memory, memoryAll, swap, swapAll);
m_labMemory->setText(QString("%1%").arg(memory * 100.0 / memoryAll, 0, 'f', 2, QLatin1Char(' ')));
m_numMemory->setText(QString("%1%").arg(memory * 100.0 / memoryAll, 0, 'f', 2, QLatin1Char(' ')));
}
5 changes: 5 additions & 0 deletions speedwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public slots:
DLabel *m_labDown;
DLabel *m_labCpu;
DLabel *m_labMemory;

DLabel *m_numUpload;
DLabel *m_numDown;
DLabel *m_numCpu;
DLabel *m_numMemory;
DLabel *m_diskRead;
DLabel *m_diskWrite;
QTimer *m_timer;
Expand Down

0 comments on commit f37d744

Please sign in to comment.