IPBS_Station/UI/W3/widget3.cpp
2025-09-05 10:47:36 +08:00

78 lines
2.9 KiB
C++

#include "widget3.h"
#include <CCFile.h>
#include <QFileDialog>
#include <QMessageBox>
#include "ui_widget3.h"
#include "UI/Language/Index.h"
widget3::widget3(QWidget *parent) :QWidget(parent), ui(new Ui::widget3) {
ui->setupUi(this);
setWindowFlags(this->windowFlags() &~ Qt::WindowMaximizeButtonHint);
connect(ui->LogoBtn, &QPushButton::clicked,this, &widget3::SelectFile);
LanguageSwitching();
}
widget3::~widget3() {
delete ui;
}
void widget3::SelectFile() {
try {
//定义文件对话框类
QFileDialog *fileDialog = new QFileDialog(this);
//定义文件对话框标题
fileDialog->setWindowTitle(QStringLiteral("选择文件"));
//设置打开的文件路径
fileDialog->setDirectory("./");
//设置文件过滤器,只显示.ui .cpp 文件,多个过滤文件使用空格隔开
fileDialog->setNameFilter(tr("File(*.png*)"));
//设置可以选择多个文件,默认为只能选择一个文件QFileDialog::ExistingFiles
fileDialog->setFileMode(QFileDialog::ExistingFile);
//设置视图模式
fileDialog->setViewMode(QFileDialog::Detail);
//获取选择的文件的路径
QStringList fileNames;
if (fileDialog->exec()) {
fileNames = fileDialog->selectedFiles();
}
if(!fileNames.isEmpty()){
CCString fileName = fileNames[0].toStdString();
CCFile file = CCFile(fileName.c_str(), CC::ios::rb, false);
#ifdef _WIN32
CCString Path = CCEncode::Format(WebSubPaths,Encode.UTF8,Encode.GBK);
#elif __linux__
CCString Path = CCEncode::Format(WebSubPaths,Encode.UTF8,Encode.UTF8);
#endif
CCString str = Path + "SubControl/html/assets/logo-CuXNbvLG.png";
bool F = file.Copy(str);
if(F){
CCString str = WebSubPaths + "SubControl/html/assets/logo-CuXNbvLG.png";
QPixmap pixmap(str.c_str()); // 替换为你的图片路径
if(ImGLoad != nullptr)
{
ImGLoad->setPixmap(pixmap);
ImGLoad->setScaledContents(true); // 图片自动缩放以适应 QLabel 大小
ImGLoad->setMaximumSize(111,61); // 设置 QLabel 最小尺寸
ImGLoad->setMaximumSize(320,180); // 设置 QLabel 最小尺寸
}
QMessageBox::information(this, "Success", "Copy OK!");
}
else{
QMessageBox::information(this, "Error", "Failed to copy file,Chinese is not supported");
}
}
}
catch (const std::exception& e) {
}
}
void widget3::LanguageSwitching(){
this->setWindowTitle(Index::Lang("W3Title").c_str());
ui->LogoBtn->setText(Index::Lang("LogoBtn").c_str());
ui->localUpdate->setText(Index::Lang("localUpdate").c_str());
ui->label_11->setText(Index::Lang("label_11").c_str());
}