kimageformats-psdplugin-test/mainwindow.cpp

62 lines
1.4 KiB
C++
Raw Permalink Normal View History

2020-10-27 13:19:09 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImageReader>
#include <QDebug>
#include <QMimeData>
#include <QMouseEvent>
2020-10-27 13:19:09 +08:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_filePath(R"(E:\16bit-raw-argb-affinityphoto.psd)")
2020-10-27 13:19:09 +08:00
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
} else {
event->ignore();
}
return QMainWindow::dragEnterEvent(event);
}
void MainWindow::dropEvent(QDropEvent *event)
{
event->acceptProposedAction();
const QMimeData * mimeData = event->mimeData();
if (mimeData->hasUrls()) {
const QList<QUrl> &urls = mimeData->urls();
if (!urls.isEmpty()) {
m_filePath = urls.first().toLocalFile();
ui->label->setText(m_filePath);
}
}
}
2020-10-27 13:19:09 +08:00
void MainWindow::on_pushButton_clicked()
{
// 如果输出里有 psd 说明确实加载进去了
qDebug() << QImageReader::supportedImageFormats();
// 后面的文件改成 psd 文件的路径
QScopedPointer< QImageReader> ir(new QImageReader(m_filePath));
2020-10-27 13:19:09 +08:00
qDebug() << ir->canRead();
QImage read = ir->read();
if (read.isNull()) {
qDebug() << "read is null";
}
ui->label->setPixmap(QPixmap::fromImage(read));
}