第一阶段初稿+修复部分内容
This commit is contained in:
188
OfficeAssistant_msvc/switchbutton.cpp
Normal file
188
OfficeAssistant_msvc/switchbutton.cpp
Normal file
@ -0,0 +1,188 @@
|
||||
#include "switchbutton.h"
|
||||
#include "config.h"
|
||||
#include <Windows.h>
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
SwitchButton::SwitchButton(int action,QWidget *parent=nullptr)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
checked = false;
|
||||
this->action = action;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||
bgColorOff = QColor(225, 225, 225);
|
||||
bgColorOn = QColor(250, 250, 250);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||
sliderColorOff = QColor(100, 100, 100);
|
||||
sliderColorOn = QColor(100, 184, 255);
|
||||
|
||||
space = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
rectRadius = 5;
|
||||
|
||||
step = width() / 50; //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
//<2F><>ʼ<EFBFBD><CABC>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
||||
startX = 0;
|
||||
endX = 0;
|
||||
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(10);
|
||||
connect(timer, &QTimer::timeout, this, &SwitchButton::updateValue);
|
||||
|
||||
}
|
||||
|
||||
void SwitchButton::updateValue()
|
||||
{
|
||||
if (checked) {
|
||||
if (startX < endX) {
|
||||
startX = startX + step;
|
||||
}
|
||||
else {
|
||||
startX = endX;
|
||||
timer->stop();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (startX > endX) {
|
||||
startX = startX - step;
|
||||
}
|
||||
else {
|
||||
startX = endX;
|
||||
timer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
void SwitchButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
checked = !checked;
|
||||
if (action == ADD_AUTOSTART) {
|
||||
if (checked == true) {
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>"));
|
||||
return;
|
||||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
lRet = RegSetValueEx(hKey, L"SelfRun", 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length());
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
else {
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>"));
|
||||
return;
|
||||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
lRet = RegDeleteValue(hKey, L"SelfRun");
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
//ÿ<><C3BF><EFBFBD>ƶ<EFBFBD><C6B6>IJ<EFBFBD><C4B2><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ȵ<EFBFBD> 50<35><30>֮һ
|
||||
step = width() / 50;
|
||||
|
||||
//״̬<D7B4>л<EFBFBD><D0BB>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (checked)
|
||||
{
|
||||
endX = width() - width() / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
endX = 0;
|
||||
}
|
||||
|
||||
timer->start();
|
||||
}
|
||||
|
||||
void SwitchButton::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
//ÿ<><C3BF><EFBFBD>ƶ<EFBFBD><C6B6>IJ<EFBFBD><C4B2><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ȵ<EFBFBD> 50<35><30>֮һ
|
||||
step = width() / 50;
|
||||
|
||||
//<2F>ߴ<EFBFBD><DFB4><EFBFBD>С<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>յ<EFBFBD>
|
||||
if (checked)
|
||||
{
|
||||
startX = width() - width() / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
startX = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
void SwitchButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
//<2F><><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
|
||||
drawBg(&painter);
|
||||
//<2F><><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>
|
||||
drawSlider(&painter);
|
||||
}
|
||||
|
||||
void SwitchButton::drawBg(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
if (!checked)
|
||||
{
|
||||
painter->setBrush(bgColorOff);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setBrush(bgColorOn);
|
||||
}
|
||||
painter->drawRoundedRect(rect(), rectRadius, rectRadius);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
void SwitchButton::drawSlider(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
if (!checked) {
|
||||
painter->setBrush(sliderColorOff);
|
||||
}
|
||||
else {
|
||||
painter->setBrush(sliderColorOn);
|
||||
}
|
||||
int sliderWidth = width() / 2 - space * 2;
|
||||
int sliderHeight = height() - space * 2;
|
||||
QRect sliderRect(startX + space, space, sliderWidth, sliderHeight);
|
||||
painter->drawRoundedRect(sliderRect, rectRadius, rectRadius);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
SwitchButton::~SwitchButton()
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user