first commit
This commit is contained in:
+102
@@ -0,0 +1,102 @@
|
||||
#include "ImageLoader.h"
|
||||
#include "ui_ImageLoader.h"
|
||||
#include "SysPara.h"
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
ImageLoader::ImageLoader(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ImageLoader)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
updateFileList(ui->rootPathCBox->currentIndex());
|
||||
onFilenameCBoxIndexChanged(ui->filenameCBox->currentIndex());
|
||||
}
|
||||
|
||||
ImageLoader::~ImageLoader()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString ImageLoader::imgPath()
|
||||
{
|
||||
return m_imgPath;
|
||||
}
|
||||
|
||||
void ImageLoader::initAndShow(bool fullScreen)
|
||||
{
|
||||
ui->rootPathCBox->setCurrentIndex(FromWhere::SYSTEM);
|
||||
updateFileList(FromWhere::SYSTEM);
|
||||
ui->filenameCBox->setCurrentIndex(0);
|
||||
|
||||
if(fullScreen)
|
||||
showFullScreen();
|
||||
else
|
||||
show();
|
||||
}
|
||||
|
||||
void ImageLoader::onFilenameCBoxIndexChanged(int i)
|
||||
{
|
||||
if(i > ui->filenameCBox->count() || i < 0) {
|
||||
m_img = QImage(nullptr);
|
||||
m_imgPath = nullptr;
|
||||
ui->imgPreviewWidget->setImg(QImage());
|
||||
ui->imgPreviewWidget->repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
QDir fileDir(ui->filenameCBox->itemData(i).toString());
|
||||
QString imgPath = fileDir.absoluteFilePath(ui->filenameCBox->itemText(i));
|
||||
QImage img(imgPath);
|
||||
m_img = img;
|
||||
m_imgPath = imgPath;
|
||||
ui->imgPreviewWidget->setImg(img);
|
||||
ui->imgPreviewWidget->repaint();
|
||||
}
|
||||
|
||||
void ImageLoader::onRootPathCBoxIndexChanged(int i)
|
||||
{
|
||||
updateFileList(i);
|
||||
}
|
||||
|
||||
void ImageLoader::onOkBtnClicked()
|
||||
{
|
||||
emit accepted();
|
||||
hide();
|
||||
}
|
||||
|
||||
void ImageLoader::updateFileList(ImageLoader::FromWhere where)
|
||||
{
|
||||
m_img = QImage();
|
||||
m_imgPath = nullptr;
|
||||
ui->filenameCBox->clear();
|
||||
ui->filenameCBox->setCurrentIndex(-1);
|
||||
|
||||
QString rootPath;
|
||||
switch(where) {
|
||||
case FromWhere::SYSTEM:
|
||||
rootPath = DOC_ROOT_DIR;
|
||||
break;
|
||||
case FromWhere::UDISK:
|
||||
rootPath = UDISK_DOC_ROOT_DIR;
|
||||
break;
|
||||
default:
|
||||
rootPath = DOC_ROOT_DIR;
|
||||
break;
|
||||
}
|
||||
|
||||
QDir dir(rootPath);
|
||||
if(!dir.exists()) {
|
||||
qWarning() << "Cannot open path: " << rootPath;
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList nameFilters;
|
||||
nameFilters << "*.png" << "*.jpeg" << "*.gif" << "*.jpg" << "*.bmp"<< "*.BMP";
|
||||
auto imgFileList = dir.entryInfoList(nameFilters, QDir::Files);
|
||||
|
||||
for(const auto& f : imgFileList) {
|
||||
ui->filenameCBox->addItem(f.fileName(), f.absolutePath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user