| 1 |
/* |
| 2 |
* Copyright (C) 2019 ~ 2020 Deepin Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: Deng jinhui<[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: Deng jinhui <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "mainwindow.h" |
| 22 |
#include "ui_mainwindow.h" |
| 23 |
|
| 24 |
MainWindow::MainWindow(QWidget *parent) : |
| 25 |
QMainWindow(parent), |
| 26 |
ui(new Ui::MainWindow) |
| 27 |
{ |
| 28 |
ui->setupUi(this); |
| 29 |
ui->centralWidget->setLayout(ui->verticalLayout); |
| 30 |
this->move(500, 200); |
| 31 |
//ui->otherinfolabel->setStyleSheet(""); |
| 32 |
connect(ui->open_pushButton, &QPushButton::pressed, this, &MainWindow::on_pushButton_clicked); |
| 33 |
connect(&controler, &ImageDemoThreadControler::updateRotate, this, &MainWindow::updateRotateAngel); |
| 34 |
//connect(ui->leftrotate_pushButton, &QPushButton::pressed, this, &MainWindow::on_leftrotate_pushButton_pressed); |
| 35 |
//connect(ui->rightrotate_pushButton, &QPushButton::pressed, this, &MainWindow::on_rightrotate_pushButton_pressed); |
| 36 |
|
| 37 |
m_scence = new QGraphicsScene; |
| 38 |
ui->m_graphicsView->setScene(m_scence); |
| 39 |
} |
| 40 |
|
| 41 |
MainWindow::~MainWindow() |
| 42 |
{ |
| 43 |
delete ui; |
| 44 |
} |
| 45 |
|
| 46 |
void MainWindow::updateRotateAngel(int angel) |
| 47 |
{ |
| 48 |
ui->rotate_label->setText(QString::number(angel)); |
| 49 |
} |
| 50 |
|
| 51 |
void MainWindow::on_pushButton_clicked() |
| 52 |
{ |
| 53 |
QFileDialog dialog; |
| 54 |
dialog.setMimeTypeFilters(unionImageSupportFormat()); |
| 55 |
//dialog.setOption(QFileDialog::HideNameFilterDetails); |
| 56 |
dialog.setWindowTitle(tr("Import Photos")); |
| 57 |
const QString path = dialog.getOpenFileName(); |
| 58 |
QTime time; |
| 59 |
time.start(); |
| 60 |
QImage image; |
| 61 |
QString errMsg; |
| 62 |
QString format = QFileInfo(path).suffix().toUtf8().toUpper(); |
| 63 |
if (supportMovieFormat().contains(format)) { |
| 64 |
ici.setFileName(path); |
| 65 |
if (nullptr != dynamicImageTimer) { |
| 66 |
dynamicImageTimer->stop(); |
| 67 |
delete dynamicImageTimer; |
| 68 |
dynamicImageTimer = nullptr; |
| 69 |
} |
| 70 |
dynamicImageTimer = new QTimer(this); |
| 71 |
connect(dynamicImageTimer, &QTimer::timeout, this, &MainWindow::loaddynamicImage); |
| 72 |
dynamicImageTimer->start(100); |
| 73 |
m_scence->clear(); |
| 74 |
m_item = new QGraphicsPixmapItem; |
| 75 |
m_scence->addItem(m_item); |
| 76 |
} else { |
| 77 |
if (nullptr != dynamicImageTimer) { |
| 78 |
dynamicImageTimer->stop(); |
| 79 |
delete dynamicImageTimer; |
| 80 |
dynamicImageTimer = nullptr; |
| 81 |
} |
| 82 |
if (!loadStaticImageFromFile(path, image, errMsg)) { |
| 83 |
|
| 84 |
} |
| 85 |
qDebug() << errMsg; |
| 86 |
//getThumbnail(image, path); |
| 87 |
qDebug() << "打开图片耗时:" << time.elapsed(); |
| 88 |
currentImage = new QImage(image); |
| 89 |
currentImagePath = path; |
| 90 |
QSize size = ui->m_graphicsView->size(); |
| 91 |
ui->filenamelabel->setText(path); |
| 92 |
m_scence->clear(); |
| 93 |
m_item = new QGraphicsPixmapItem; |
| 94 |
m_scence->addItem(m_item); |
| 95 |
m_item->setPixmap(QPixmap::fromImage(image).scaled(size.width(), size.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); |
| 96 |
qDebug() << image; |
| 97 |
} |
| 98 |
|
| 99 |
QMap<QString, QString> Datas = getAllMetaData(path); |
| 100 |
QString str; |
| 101 |
for (auto data : Datas) { |
| 102 |
str += data; |
| 103 |
str += " "; |
| 104 |
} |
| 105 |
ui->otherinfolabel->setGeometry(QRect(328, 240, 329, 27 * 4)); //四倍行距 |
| 106 |
ui->otherinfolabel->setWordWrap(true); |
| 107 |
ui->otherinfolabel->setAlignment(Qt::AlignTop); |
| 108 |
ui->otherinfolabel->setText(str); |
| 109 |
} |
| 110 |
|
| 111 |
void MainWindow::on_leftrotate_pushButton_pressed() |
| 112 |
{ |
| 113 |
QTime time; |
| 114 |
if (nullptr == currentImage) { |
| 115 |
return; |
| 116 |
} |
| 117 |
time.start(); |
| 118 |
QImage image = QImage(*currentImage); |
| 119 |
RotateSaveRequest request; |
| 120 |
request.path = currentImagePath; |
| 121 |
request.angel = -90; |
| 122 |
request.image = image; |
| 123 |
controler.addRotateAndSave(request, 1000); |
| 124 |
rotateImage(-90, image); |
| 125 |
delete currentImage; |
| 126 |
currentImage = new QImage(image); |
| 127 |
QSize size = ui->m_graphicsView->size(); |
| 128 |
m_item->setPixmap(QPixmap::fromImage(image).scaled(size.width() - 5, size.height() - 5, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); |
| 129 |
qDebug() << "本次旋转耗时" << time.elapsed(); |
| 130 |
} |
| 131 |
|
| 132 |
void MainWindow::on_rightrotate_pushButton_pressed() |
| 133 |
{ |
| 134 |
QTime time; |
| 135 |
if (nullptr == currentImage) { |
| 136 |
return; |
| 137 |
} |
| 138 |
time.start(); |
| 139 |
QImage image = QImage(*currentImage); |
| 140 |
RotateSaveRequest request; |
| 141 |
request.path = currentImagePath; |
| 142 |
request.angel = 90; |
| 143 |
request.image = image; |
| 144 |
//对文件的旋转操作 |
| 145 |
controler.addRotateAndSave(request, 1000); |
| 146 |
rotateImage(90, image); |
| 147 |
delete currentImage; |
| 148 |
currentImage = new QImage(image); |
| 149 |
QSize size = ui->m_graphicsView->size(); |
| 150 |
m_item->setPixmap(QPixmap::fromImage(image).scaled(size.width() - 5, size.height() - 5, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); |
| 151 |
qDebug() << "本次旋转耗时" << time.elapsed(); |
| 152 |
} |
| 153 |
|
| 154 |
void MainWindow::loaddynamicImage() |
| 155 |
{ |
| 156 |
m_item->setPixmap(QPixmap::fromImage(ici++)); |
| 157 |
} |