Skip to content

Commit

Permalink
feat: Add a switch to preview system runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
XMuli committed Nov 28, 2020
1 parent f3a50d7 commit 3425358
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 31 deletions.
2 changes: 1 addition & 1 deletion aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void AboutDialog::init()
QVBoxLayout *vLayout = new QVBoxLayout(content);
vLayout->setContentsMargins(0, 0, 0, 0);
vLayout->addSpacing(15);
DLabel *labVersion = new DLabel(tr("Version: 0.4 2020/11/26"));
DLabel *labVersion = new DLabel(tr("Version: 0.5 2020/11/28"));
DLabel *labCopyright = new DLabel(tr("Copyright (c) 2020 By 偕臧"));
vLayout->addWidget(labVersion, 0, Qt::AlignCenter);
vLayout->addWidget(labCopyright, 0, Qt::AlignCenter);
Expand Down
18 changes: 17 additions & 1 deletion settingmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
/*
* Copyright (c) 2020 xmuli
*
* Author: xmuli(偕臧) xmulitech@gmail.com
* GitHub: https://github.com/xmuli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* */

#include "settingmodel.h"

#include <DLabel>


DWIDGET_USE_NAMESPACE

SettingModel::SettingModel(QObject *parent)
Expand Down
18 changes: 17 additions & 1 deletion settingmodel.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (c) 2020 xmuli
*
* Author: xmuli(偕臧) xmulitech@gmail.com
* GitHub: https://github.com/xmuli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* */

#ifndef SETTINGMODEL_H
#define SETTINGMODEL_H

Expand Down Expand Up @@ -39,7 +56,6 @@ class SettingModel : public QObject
void sigCpuChange(QString upload);
void sigMenoryChange(QString upload);
// void sigUpAndDownChange(Qt::CheckState check);
// void sigMouseTipsChange(Qt::CheckState check);
void sigDecimalsNumChange(const int num);
void sigIntervalChange(const int ms);
void sigSensitiveChange(const int index);
Expand Down
5 changes: 2 additions & 3 deletions speedinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ QString SpeedInfo::setRateUnitSensitive(RateUnit unit, Sensitive sensitive)
case RateUnit::RateBit:
return QString("BIT/S");
case RateUnit::RateByte:
return QString("BYTE/S");
return QString("B/S");
case RateUnit::RateKb:
return QString("KB/S");
case RateUnit::RateMb:
Expand All @@ -186,7 +186,7 @@ QString SpeedInfo::setRateUnitSensitive(RateUnit unit, Sensitive sensitive)
case RateUnit::RateBit:
return QString("bit/s");
case RateUnit::RateByte:
return QString("byte/s");
return QString("b/s");
case RateUnit::RateKb:
return QString("kb/s");
case RateUnit::RateMb:
Expand Down Expand Up @@ -252,7 +252,6 @@ double SpeedInfo::autoRateUnits(long speed, SpeedInfo::RateUnit &unit)
sp = -1;
}

// qDebug()<<"-------->sp:"<<sp<<" "<<"speed:"<<speed<<" unit:"<<unit;
return sp;
}

Expand Down
32 changes: 27 additions & 5 deletions speedplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QTimer>
#include <QDebug>

DWIDGET_USE_NAMESPACE

Expand All @@ -32,16 +33,16 @@ SpeedPlugin::SpeedPlugin(QObject *parent)
, m_winMain(nullptr)
, m_speedWidget(nullptr)
, m_proxyInter(nullptr)
, m_bMouseTip(true)
{
m_timer.setInterval(1000);
connect(&m_timer, &QTimer::timeout, this, &SpeedPlugin::onUpdateTip);
m_timer.setInterval(1000);
m_timer.start();
}

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

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

Expand All @@ -53,6 +54,7 @@ void SpeedPlugin::init(PluginProxyInterface *proxyInter)
m_speedWidget = new SpeedWidget(m_model);
m_winMain = new WinMain(m_model);

connect(m_winMain, &WinMain::sigMousTip, this, &SpeedPlugin::onMouseTip);
// 如果插件没有被禁用, 则在初始化插件时才添加主控件到面板上
if (!pluginIsDisable())
m_proxyInter->itemAdded(this, pluginName());
Expand Down Expand Up @@ -101,7 +103,13 @@ const QString SpeedPlugin::itemContextMenu(const QString &itemKey)
Q_UNUSED(itemKey);

QList<QVariant> items;
items.reserve(2);
items.reserve(3);

QMap<QString, QVariant> update;
update["itemId"] = "update";
update["itemText"] = "刷新";
update["isActive"] = true;
items.push_back(update);

QMap<QString, QVariant> setting;
setting["itemId"] = "setting";
Expand Down Expand Up @@ -131,7 +139,10 @@ void SpeedPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,

qApp->setAttribute(Qt::AA_UseHighDpiPixmaps);

if (menuId == "setting") {
if (menuId == "update") {
m_proxyInter->itemRemoved(this, pluginName());
m_proxyInter->itemAdded(this, pluginName());
} else if (menuId == "setting") {
m_winMain->move((QApplication::desktop()->width() - m_winMain->width())/2,(QApplication::desktop()->height() - m_winMain->height())/2);
m_winMain->show();
} else if (menuId == "about") {
Expand All @@ -143,10 +154,21 @@ void SpeedPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
QWidget *SpeedPlugin::itemTipsWidget(const QString &itemKey)
{
Q_UNUSED(itemKey)
return &m_labTip;
if (m_bMouseTip)
return &m_labTip;
else
return nullptr;
}

void SpeedPlugin::onUpdateTip()
{
m_labTip.setText(m_speedWidget->m_runTime);
}

void SpeedPlugin::onMouseTip(int status)
{
if (status == Qt::Checked)
m_bMouseTip = true;
else
m_bMouseTip = false;
}
2 changes: 2 additions & 0 deletions speedplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SpeedPlugin : public QObject, public PluginsItemInterface

public slots:
void onUpdateTip();
void onMouseTip(int status);

private:
PluginProxyInterface *m_proxyInter;
Expand All @@ -69,6 +70,7 @@ public slots:

DLabel m_labTip;
QTimer m_timer;
bool m_bMouseTip;
};

#endif // SPEEDPLUGIN_H
15 changes: 1 addition & 14 deletions speedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void SpeedWidget::init()
// m_diskRead = new DLabel(tr("↗: 0 kb/s"));
// m_diskWrite = new DLabel(tr("↙: 0 kb/s"));


QVBoxLayout *VLayout1 = new QVBoxLayout();
VLayout1->setContentsMargins(0, 0, 0, 0);
VLayout1->addWidget(m_labUpload);
Expand All @@ -129,8 +128,6 @@ void SpeedWidget::init()
hLayout->addLayout(VLayout4);
setLayout(hLayout);



layout = new QGridLayout();
layout->setContentsMargins(0, 0, 0, 0);
// QVBoxLayout *VLayout = new QVBoxLayout();
Expand Down Expand Up @@ -163,7 +160,7 @@ void SpeedWidget::init()
// layout->addWidget(m_diskRead, 0, 2);
// layout->addWidget(m_diskWrite, 1, 2);

qDebug()<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+>"<<layout<<layout->children();
// qDebug()<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+>"<<layout<<layout->children();

m_info = new SpeedInfo(this);
m_info->netRate(m_down, m_upload);
Expand Down Expand Up @@ -301,10 +298,6 @@ void SpeedWidget::onShowUp(int status)
// updateGeometry();
// update();
// adjustSize();

qDebug()<<"-------------------------------->"<<checkToBool(status)<<layout<<layout->children();

qDebug()<<"#################################1"<<layout->columnCount()<<layout->rowCount();
}

void SpeedWidget::onShowDown(int status)
Expand All @@ -320,8 +313,6 @@ void SpeedWidget::onShowDown(int status)
m_labDown->hide();
m_numDown->hide();
}

qDebug()<<"#################################2"<<layout->columnCount()<<layout->rowCount();
}

void SpeedWidget::onShowCPU(int status)
Expand All @@ -337,8 +328,6 @@ void SpeedWidget::onShowCPU(int status)
m_labCpu->hide();
m_numCpu->hide();
}

qDebug()<<"#################################3"<<layout->columnCount()<<layout->rowCount();
}

void SpeedWidget::onShowMem(int status)
Expand All @@ -359,8 +348,6 @@ void SpeedWidget::onShowMem(int status)
m_labMemory->hide();
m_numMemory->hide();
}

qDebug()<<"#################################4"<<layout->columnCount()<<layout->rowCount();
}

QString SpeedWidget::onRunTime()
Expand Down
5 changes: 0 additions & 5 deletions speedwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class SpeedWidget : public QWidget

void init();
// virtual QSize sizeHint() const override;

// void resizeEvent(QResizeEvent *event);
// virtual void paintEvent(QPaintEvent *event) override;
QString m_runTime;
Expand Down Expand Up @@ -90,11 +89,7 @@ public slots:
long m_cpuFree;

QGridLayout *layout;

SettingModel *m_model;

// QWidget interface
protected:
};

#endif // SPEEDWIDGET_H
20 changes: 19 additions & 1 deletion winmain.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (c) 2020 xmuli
*
* Author: xmuli(偕臧) xmulitech@gmail.com
* GitHub: https://github.com/xmuli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* */

#include "winmain.h"
#include <QVBoxLayout>
#include <QGridLayout>
Expand Down Expand Up @@ -48,6 +65,7 @@ WinMain::WinMain(SettingModel *model, QWidget *parent)
connect(m_checkShowDown, &DCheckBox::stateChanged, this, &WinMain::sigShowDown);
connect(m_checkShowCPU, &DCheckBox::stateChanged, this, &WinMain::sigShowCPU);
connect(m_checkShowMem, &DCheckBox::stateChanged, this, &WinMain::sigShowMem);
connect(m_checkMouseTips, &DCheckBox::stateChanged, this, &WinMain::sigMousTip);
// connect(m_checkUpAndDown, &DCheckBox::checkState, this, &WinMain::sigUpAndDown);

connect(this, &WinMain::sigLabUpload, m_model, &SettingModel::sigUploadChange);
Expand Down Expand Up @@ -126,7 +144,7 @@ void WinMain::init()
gridCheck->addWidget(m_checkMouseTips, 1, 0);
m_checkUpAndDown->setCheckState(Qt::Unchecked);
m_checkUpAndDown->setText(tr("上传下载互换"));
gridCheck->addWidget(m_checkUpAndDown, 1, 1);
// gridCheck->addWidget(m_checkUpAndDown, 1, 1);

QVBoxLayout* vLayout = new QVBoxLayout(boxShowText);
vLayout->addLayout(gridShowText, 0);
Expand Down
17 changes: 17 additions & 0 deletions winmain.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#ifndef WINMAIN_H
/*
* Copyright (c) 2020 xmuli
*
* Author: xmuli(偕臧) xmulitech@gmail.com
* GitHub: https://github.com/xmuli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* */

#define WINMAIN_H

#include <DMainWindow>
Expand Down

0 comments on commit 3425358

Please sign in to comment.