Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Albresky committed Mar 25, 2022
1 parent 88fcccc commit cfb5e80
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 79 deletions.
11 changes: 8 additions & 3 deletions FileOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -77,7 +78,7 @@ bool storeIni(const QStringList &fileNameList,QString& targetDir)
{
file.open(QIODevice::ReadWrite|QIODevice::Text);
}
QStringList existNames;
QVector<QString> existNames;
QTextStream _ini(&file);
while(!_ini.atEnd())
{
Expand All @@ -95,7 +96,10 @@ bool storeIni(const QStringList &fileNameList,QString& targetDir)
_ini<<s<<"\r\n";
qDebug()<<"storeIni()|prefix=>"<<prefix;
if(!copyPic(prefix+"\\"+s,targetDir,QString::number(i)))
{
file.close();
return false;
}
}
}
file.close();
Expand All @@ -117,6 +121,7 @@ bool createFile(const QString& fileName)
qfile.close();
return true;
}
qfile.close();
return false;
}

Expand Down
9 changes: 6 additions & 3 deletions aboutwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ aboutWindow::aboutWindow(QWidget *parent) :
ui(new Ui::aboutWindow)
{
ui->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("<font style='font-size:18px;font-family:Microsoft YaHei;color:black'><b>WinFocus</b></font><font style='font-size:12px'>&nbsp;(x64)</font>"));

ui->version->setText(tr("<font style='font-size:14px'>版本: 1.0</font>"));
Expand All @@ -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")));
Expand Down
1 change: 1 addition & 0 deletions aboutwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ABOUTWINDOW_H

#include <QWidget>
#include <commonHeaders.h>

namespace Ui {
class aboutWindow;
Expand Down
2 changes: 1 addition & 1 deletion commonHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QDir>
#include <QString>
#include <QDebug>
#include <iostream>
#include <QIcon>
#include <QFileDialog>
#include <stdlib.h>

Expand Down
5 changes: 4 additions & 1 deletion config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ Config::Config(QString cfgFile)
else
{
pri_cfgFile=cfgFile;
qDebug()<<pri_cfgFile;
qDebug()<<"Config already exists => "<<pri_cfgFile;
}
pri_pSettings=new QSettings(pri_cfgFile,QSettings::IniFormat);
}


Config::~Config(void)
{
delete pri_pSettings;
pri_pSettings=0;
}


void Config::Set(QString nodeName,QString keyName,QVariant value)
{
pri_pSettings->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));
Expand Down
5 changes: 1 addition & 4 deletions configwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ui_configwindow.h"
#include <QDesktopServices>

configWindow::configWindow(QWidget *parent) :
configWindow::configWindow(QWidget *parent):
QWidget(parent),
ui(new Ui::configWindow)
{
Expand Down Expand Up @@ -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 => "<<langShow;

//Load FileStoreLocation
Expand Down
4 changes: 2 additions & 2 deletions configwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QWidget>
#include <config.h>
#include <mainwindow.h>

namespace Ui {
class configWindow;
Expand All @@ -13,7 +14,7 @@ class configWindow : public QWidget
Q_OBJECT

public:
explicit configWindow(QWidget *parent = nullptr);
configWindow(QWidget *parent = nullptr);
~configWindow();

private slots:
Expand All @@ -29,7 +30,6 @@ private slots:

private:
Ui::configWindow *ui;
// Config loadConfig;
};

#endif // CONFIGWINDOW_H
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int main(int argc, char *argv[])
break;
}
}

MainWindow w;
w.show();
return a.exec();
Expand Down
110 changes: 69 additions & 41 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <QPushButton>
#include <QHBoxLayout>
#include <QDesktopServices>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QAudioOutput>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Expand All @@ -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");
Expand All @@ -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<QString>();
*loct = var.value<QString>();
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()
Expand All @@ -73,6 +73,16 @@ MainWindow::~MainWindow()
}


void MainWindow::updateLocatState()
{
QVariant var=cfg->Get("Config","Location");
if(var.isValid())
{
*loct = var.value<QString>();
qDebug()<<*loct;
}
}

void MainWindow::about_clicked()
{
aboutWindow *aboutWin =new aboutWindow();
Expand All @@ -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<QString> filenamelist;
if(getPicName(prefix,filenamelist))
{
qDebug()<<"getPicNameList success!";
}

qDebug()<<"++++++++++++++++picNames+++++++++++++++++";

for(int i=0;i<filenamelist.size();i++)
{
qDebug()<<filenamelist[i];
}

qDebug()<<"++++++++++++++++picNames+++++++++++++++++";

ui->statusbar->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));
Expand Down
8 changes: 4 additions & 4 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MainWindow : public QMainWindow
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
Ui::MainWindow *ui;

private slots:
void about_clicked();
Expand All @@ -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
Loading

0 comments on commit cfb5e80

Please sign in to comment.