|
|
|
@ -19,6 +19,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QImage>
|
|
|
|
@ -184,6 +186,9 @@ void MainWindow::onFolderLoaded(FmFolder* folder) {
|
|
|
|
|
thumbnailsView_->childView()->scrollTo(currentIndex_, QAbstractItemView::EnsureVisible);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// this is used to open the first image of a folder
|
|
|
|
|
else if (currentFile_ == nullptr)
|
|
|
|
|
on_actionFirst_triggered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::openImageFile(QString fileName) {
|
|
|
|
@ -193,9 +198,31 @@ void MainWindow::openImageFile(QString fileName) {
|
|
|
|
|
fm_path_unref(path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// load the image file asynchronously
|
|
|
|
|
loadImage(path);
|
|
|
|
|
loadFolder(fm_path_get_parent(path));
|
|
|
|
|
if (QFileInfo(fileName).isDir()) {
|
|
|
|
|
if(fm_path_equal(path, folderPath_)) {
|
|
|
|
|
fm_path_unref(path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QList<QByteArray> formats = QImageReader::supportedImageFormats();
|
|
|
|
|
QStringList formatsFilters;
|
|
|
|
|
for (const QByteArray& format: formats)
|
|
|
|
|
formatsFilters << QString("*.") + format;
|
|
|
|
|
QDir dir(fileName);
|
|
|
|
|
dir.setNameFilters(formatsFilters);
|
|
|
|
|
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
if(dir.entryList().isEmpty()) {
|
|
|
|
|
fm_path_unref(path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(currentFile_)
|
|
|
|
|
fm_path_unref(currentFile_);
|
|
|
|
|
currentFile_ = nullptr;
|
|
|
|
|
loadFolder(path);
|
|
|
|
|
} else {
|
|
|
|
|
// load the image file asynchronously
|
|
|
|
|
loadImage(path);
|
|
|
|
|
loadFolder(fm_path_get_parent(path));
|
|
|
|
|
}
|
|
|
|
|
fm_path_unref(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -243,6 +270,12 @@ QString MainWindow::openFileName() {
|
|
|
|
|
return fileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MainWindow::openDirectory() {
|
|
|
|
|
QString directory = QFileDialog::getExistingDirectory(this,
|
|
|
|
|
tr("Open directory"), QString());
|
|
|
|
|
return directory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// popup a file dialog and retrieve the selected image file name
|
|
|
|
|
QString MainWindow::saveFileName(QString defaultName) {
|
|
|
|
|
QString filterStr;
|
|
|
|
@ -275,6 +308,13 @@ void MainWindow::on_actionOpenFile_triggered() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionOpenDirectory_triggered() {
|
|
|
|
|
QString directory = openDirectory();
|
|
|
|
|
if(!directory.isEmpty()) {
|
|
|
|
|
openImageFile(directory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionNewWindow_triggered() {
|
|
|
|
|
Application* app = static_cast<Application*>(qApp);
|
|
|
|
|
MainWindow* window = new MainWindow();
|
|
|
|
@ -646,19 +686,19 @@ QGraphicsItem* MainWindow::getGraphicsItem() {
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionRotateClockwise_triggered() {
|
|
|
|
|
QGraphicsItem *graphItem = getGraphicsItem();
|
|
|
|
|
bool isGifOrSvg (graphItem->isWidget() // we have gif animation
|
|
|
|
|
|| dynamic_cast<QGraphicsSvgItem*>(graphItem)); // an SVG image;
|
|
|
|
|
if(!image_.isNull()) {
|
|
|
|
|
QTransform transform;
|
|
|
|
|
transform.rotate(90.0);
|
|
|
|
|
image_ = image_.transformed(transform, Qt::SmoothTransformation);
|
|
|
|
|
/* when this is GIF or SVG, we need to rotate its corresponding QImage
|
|
|
|
|
without showing it to have the right measure for auto-zooming */
|
|
|
|
|
ui.view->setImage(image_, graphItem->isWidget() // we have gif animation
|
|
|
|
|
|| static_cast<QGraphicsSvgItem*>(graphItem) // an SVG image
|
|
|
|
|
? false : true);
|
|
|
|
|
ui.view->setImage(image_, isGifOrSvg ? false : true);
|
|
|
|
|
setModified(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(graphItem) {
|
|
|
|
|
if(isGifOrSvg) {
|
|
|
|
|
QTransform transform;
|
|
|
|
|
transform.translate(graphItem->sceneBoundingRect().height(), 0);
|
|
|
|
|
transform.rotate(90);
|
|
|
|
@ -671,16 +711,17 @@ void MainWindow::on_actionRotateClockwise_triggered() {
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionRotateCounterclockwise_triggered() {
|
|
|
|
|
QGraphicsItem *graphItem = getGraphicsItem();
|
|
|
|
|
bool isGifOrSvg (graphItem->isWidget()
|
|
|
|
|
|| dynamic_cast<QGraphicsSvgItem*>(graphItem));
|
|
|
|
|
if(!image_.isNull()) {
|
|
|
|
|
QTransform transform;
|
|
|
|
|
transform.rotate(-90.0);
|
|
|
|
|
image_ = image_.transformed(transform, Qt::SmoothTransformation);
|
|
|
|
|
ui.view->setImage(image_, graphItem->isWidget() || static_cast<QGraphicsSvgItem*>(graphItem)
|
|
|
|
|
? false : true);
|
|
|
|
|
ui.view->setImage(image_, isGifOrSvg ? false : true);
|
|
|
|
|
setModified(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(graphItem) {
|
|
|
|
|
if(isGifOrSvg) {
|
|
|
|
|
QTransform transform;
|
|
|
|
|
transform.translate(0, graphItem->sceneBoundingRect().width());
|
|
|
|
|
transform.rotate(-90);
|
|
|
|
|