From cfb5e804f91a4e42ed4959c2c7d2af3a3047db07 Mon Sep 17 00:00:00 2001 From: Albresky <78648318+Albresky@users.noreply.github.com> Date: Fri, 25 Mar 2022 21:20:09 +0800 Subject: [PATCH] fix bugs --- FileOperator.cpp | 11 +++-- aboutwindow.cpp | 9 ++-- aboutwindow.h | 1 + commonHeaders.h | 2 +- config.cpp | 5 ++- configwindow.cpp | 5 +-- configwindow.h | 4 +- main.cpp | 1 + mainwindow.cpp | 110 +++++++++++++++++++++++++++++------------------ mainwindow.h | 8 ++-- mainwindow.ui | 10 ++--- pathOperator.cpp | 28 ++++++------ 12 files changed, 115 insertions(+), 79 deletions(-) diff --git a/FileOperator.cpp b/FileOperator.cpp index 5e05f0d..e15b4d2 100644 --- a/FileOperator.cpp +++ b/FileOperator.cpp @@ -64,9 +64,10 @@ bool copyPic(QString resFile,const QString& targetDir,QString num) if(!FileCopy(resFile,targetDir+"\\"+num+".jpg")) { qDebug()<<"pic copy OK!"; - return false; + return true; } - return true; + qDebug()<<"pic copy Fail!"; + return false; } bool storeIni(const QStringList &fileNameList,QString& targetDir) @@ -77,7 +78,7 @@ bool storeIni(const QStringList &fileNameList,QString& targetDir) { file.open(QIODevice::ReadWrite|QIODevice::Text); } - QStringList existNames; + QVector existNames; QTextStream _ini(&file); while(!_ini.atEnd()) { @@ -95,7 +96,10 @@ bool storeIni(const QStringList &fileNameList,QString& targetDir) _ini<"<setupUi(this); + + setWindowFlags(windowFlags()|Qt::Dialog); + setWindowModality(Qt::ApplicationModal); + setWindowFlags(windowFlags()&~Qt::WindowMinMaxButtonsHint); + setWindowIcon(QIcon(":/icon.ico")); setWindowTitle("关于"); setFixedSize(300,200); - setWindowFlags(windowFlags()&~Qt::WindowMinMaxButtonsHint); - ui->name->setText(tr("WinFocus (x64)")); ui->version->setText(tr("版本: 1.0")); @@ -26,13 +29,13 @@ aboutWindow::aboutWindow(QWidget *parent) : connect(ui->github,&QLabel::linkActivated,this,&aboutWindow::github_linkActivated); } + aboutWindow::~aboutWindow() { delete ui; } - void aboutWindow::blog_linkActivated() { QDesktopServices::openUrl(QUrl(QLatin1String("https://cosyspark.space"))); diff --git a/aboutwindow.h b/aboutwindow.h index 24c4967..1bdfd83 100644 --- a/aboutwindow.h +++ b/aboutwindow.h @@ -2,6 +2,7 @@ #define ABOUTWINDOW_H #include +#include namespace Ui { class aboutWindow; diff --git a/commonHeaders.h b/commonHeaders.h index 8689e10..9116f72 100644 --- a/commonHeaders.h +++ b/commonHeaders.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/config.cpp b/config.cpp index 2432e7c..c5b423a 100644 --- a/config.cpp +++ b/config.cpp @@ -10,22 +10,25 @@ Config::Config(QString cfgFile) else { pri_cfgFile=cfgFile; - qDebug()< "<setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); } + QVariant Config::Get(QString nodeName, QString keyName) { QVariant qvar=pri_pSettings->value(QString("/%1/%2").arg(nodeName).arg(keyName)); diff --git a/configwindow.cpp b/configwindow.cpp index b73546a..e7fa33f 100644 --- a/configwindow.cpp +++ b/configwindow.cpp @@ -4,7 +4,7 @@ #include "ui_configwindow.h" #include -configWindow::configWindow(QWidget *parent) : +configWindow::configWindow(QWidget *parent): QWidget(parent), ui(new Ui::configWindow) { @@ -47,9 +47,6 @@ configWindow::configWindow(QWidget *parent) : langShow =(langShow=="zh-CN")?"简体中文":langShow; ui->langBox->setCurrentText(langShow); - - // if(ui->langBox->findText(langShow)==-1) - // ui->langBox->addItem("English"); qDebug()<<"load language => "< #include +#include namespace Ui { class configWindow; @@ -13,7 +14,7 @@ class configWindow : public QWidget Q_OBJECT public: - explicit configWindow(QWidget *parent = nullptr); + configWindow(QWidget *parent = nullptr); ~configWindow(); private slots: @@ -29,7 +30,6 @@ private slots: private: Ui::configWindow *ui; -// Config loadConfig; }; #endif // CONFIGWINDOW_H diff --git a/main.cpp b/main.cpp index 8613368..5510a69 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,7 @@ int main(int argc, char *argv[]) break; } } + MainWindow w; w.show(); return a.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 6927d78..c92fa4d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,8 +14,6 @@ #include #include #include -#include -#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -26,14 +24,6 @@ MainWindow::MainWindow(QWidget *parent) setWindowIcon(QIcon(":/icon.ico")); setFixedSize(320,180); - QMediaPlayer* player = new QMediaPlayer(); - QAudioOutput* audioOp= new QAudioOutput(); - connect(player,SIGNAL(positionChanged(qint64)),this,SLOT(positionChanged(qint64))); - player->setAudioOutput(audioOp); - player->setSource(QUrl::fromLocalFile(":/bgm.m4a")); - audioOp->setVolume(60); - player->play(); - this->qGif_pressed=new QMovie(":/myBtn_light.gif"); this->qGif_pressed->setScaledSize(QSize(60,60)); this->qGif_released=new QMovie(":/myBtn_dark.gif"); @@ -52,19 +42,29 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionAbout,&QAction::triggered,this,&MainWindow::about_clicked); QObject::connect(ui->actionConfig,&QAction::triggered,this,&MainWindow::config_clicked); + cfg=new Config("Config.ini"); - ui->apply_btn->setEnabled(false); - loct=new QString(); - while(!loct->length()) + loct=new QString("NULL"); + + QVariant var=cfg->Get("Config","Location"); + if(var.isValid()) { - ui->statusbar->setStyleSheet("font-size:10px;color:red"); - ui->statusbar->showMessage(tr("路径未配置"),30000); - *loct=cfg->Get("Config","Location").value(); + *loct = var.value(); + qDebug()<<*loct; + QLabel* label =new QLabel(this); + label->setFrameStyle(QFrame::Box|QFrame::Sunken); + label->setStyleSheet("font-size:10px"); + label->setStyleSheet("color:black"); + label->setStyleSheet("font-style:italic"); + label->setText("保存路径已初始化"); + ui->statusbar->addPermanentWidget(label); + } + else + { + ui->statusbar->setStyleSheet("font-size:10px"); + ui->statusbar->setStyleSheet("color:red"); + ui->statusbar->showMessage(tr("保存路径未初始化")); } - qDebug()<<*loct; - ui->statusbar->setStyleSheet("font-size:10px;color:black"); - ui->statusbar->showMessage(tr("路径已配置"),200000); - ui->apply_btn->setEnabled(true); } MainWindow::~MainWindow() @@ -73,6 +73,16 @@ MainWindow::~MainWindow() } +void MainWindow::updateLocatState() +{ + QVariant var=cfg->Get("Config","Location"); + if(var.isValid()) + { + *loct = var.value(); + qDebug()<<*loct; + } +} + void MainWindow::about_clicked() { aboutWindow *aboutWin =new aboutWindow(); @@ -89,62 +99,80 @@ void MainWindow::config_clicked() } - void MainWindow::on_apply_btn_pressed() { - qDebug()<<"pushBtn pressed"; + qDebug()<<"apply_Btn pressed"; + updateLocatState(); + if(*this->loct==QString::fromLocal8Bit("NULL")) + { + qDebug()<<"Location uninitialized."; + ui->statusbar->setStyleSheet("font-size:10px"); + ui->statusbar->setStyleSheet("color:red"); + ui->statusbar->showMessage(tr("保存路径未初始化")); + return; + } + ui->apply_btn->setEnabled(true); + ui->openFolder->setEnabled(true); ui->apply_lbl->show(); for(int i=0;i<=8;i++) { ui->apply_lbl->setStyleSheet(this->btn_list[i]); QThread::msleep(125); } + getPicPath(); - QStringList filenamelist; + QVector filenamelist; if(getPicName(prefix,filenamelist)) { qDebug()<<"getPicNameList success!"; } + qDebug()<<"++++++++++++++++picNames+++++++++++++++++"; + for(int i=0;istatusbar->setStyleSheet("font-size:10px;color:green"); + ui->statusbar->setStyleSheet("font-size:11px;color:green"); + if(storeIni(filenamelist,*loct)) { ui->statusbar->showMessage(tr("锁屏壁纸提取成功!"),200000); qDebug()<<"store FileName Success!"; + return; } + ui->statusbar->showMessage(tr("锁屏壁纸提取失败!"),200000); } void MainWindow::on_apply_btn_released() { - // qDebug()<<"pushBtn released"; - // ui->apply_lbl->setMovie(this->qGif_released); - // ui->apply_lbl->show(); - // this->qGif_released->start(); - // ui->apply_btn->setEnabled(true); - // ui->apply_btn->setCheckable(true); + qDebug()<<"pushBtn released"; + ui->apply_lbl->setMovie(this->qGif_released); + ui->apply_lbl->show(); + this->qGif_released->start(); + ui->apply_lbl->setMovie(this->qGif_pressed); + ui->apply_lbl->show(); + this->qGif_pressed->start(); } -//void MainWindow::on_apply_btn_clicked() -//{ -// qDebug()<<"pushBtn clicked"; -// ui->apply_lbl->setMovie(this->qGif_pressed); -// ui->apply_lbl->show(); -// this->qGif_pressed->start(); -// ui->apply_btn->setCheckable(true); -//} - - -void MainWindow::on_pushButton_clicked() +void MainWindow::on_openFolder_clicked() { + qDebug()<<"openFolder_Btn pressed"; + updateLocatState(); + if(*this->loct==QString::fromLocal8Bit("NULL")) + { + qDebug()<<"Location uninitialized."; + ui->statusbar->setStyleSheet("font-size:11px"); + ui->statusbar->setStyleSheet("color:red"); + ui->statusbar->showMessage(tr("保存路径未初始化")); + return; + } //Load FileStoreLocation qDebug()<<"Open Folder clicked"; QDesktopServices::openUrl(QUrl::fromLocalFile(*loct)); diff --git a/mainwindow.h b/mainwindow.h index 5dc9a70..0683392 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -17,6 +17,7 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + Ui::MainWindow *ui; private slots: void about_clicked(); @@ -27,16 +28,15 @@ private slots: void on_apply_btn_released(); -// void on_apply_btn_clicked(); - - void on_pushButton_clicked(); + void on_openFolder_clicked(); private: - Ui::MainWindow *ui; QMovie* qGif_pressed; QMovie* qGif_released; QStringList btn_list; Config* cfg; QString* loct; + + void updateLocatState(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 88231e3..aed3750 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -26,7 +26,7 @@ - 40 + 50 40 61 61 @@ -42,7 +42,7 @@ - 40 + 50 40 61 61 @@ -52,13 +52,13 @@ - + 200 40 - 51 - 51 + 61 + 61 diff --git a/pathOperator.cpp b/pathOperator.cpp index af10fce..858bb3b 100644 --- a/pathOperator.cpp +++ b/pathOperator.cpp @@ -1,28 +1,28 @@ #include "pathOperator.h" #include "commonHeaders.h" -bool getUserName(QString *str) +bool getUserName(QString& username) { const int MAX_LENGTH=256; wchar_t buffer[MAX_LENGTH]; DWORD len=MAX_LENGTH; if(GetUserName(buffer, &len)) { - *str=QString::fromWCharArray(buffer,-1); - qDebug()<<"Username:"<<*str; + username=QString::fromWCharArray(buffer,-1); + qDebug()<<"Username:"<split(":"); + QStringList list=SysDir.split(":"); QString WinLetter=list[0]; - *PicPath=WinLetter+":\\Users\\"+*UserName+"\\"+strAppend; - qDebug()<<*PicPath; + PicPath=WinLetter+":\\Users\\"+ UserName +"\\"+strAppend; + qDebug()<"<