8 Commits

8 changed files with 82 additions and 22 deletions

View File

@ -6,7 +6,7 @@ include (GNUInstallDirs)
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
set (QT_MINIMUM_VERSION "5.7.1")
set (QT_MINIMUM_VERSION "5.10")
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets Svg LinguistTools)

View File

@ -1,27 +1,49 @@
environment:
CMAKE_INSTALL_ROOT: C:\projects\cmake
matrix:
- build_name: mingw73_32_qt5_12_5
QTPATH: C:\Qt\5.12.5\mingw73_32
- build_name: mingw73_32_qt5_12_6
QTPATH: C:\Qt\5.12.6\mingw73_32
MINGW32: C:\Qt\Tools\mingw730_32
# - build_name: msvc2017_64
# QTPATH: C:\Qt\5.11.2\msvc2017_64
# MINGW32: C:\Qt\Tools\mingw530_32
install:
- mkdir %CMAKE_INSTALL_ROOT%
- cd %APPVEYOR_BUILD_FOLDER%
- git submodule update --init --recursive
- set PATH=%PATH%;%QTPATH%\bin;%MINGW32%\bin
- set PATH=%PATH%;%CMAKE_INSTALL_ROOT%;%QTPATH%\bin;%MINGW32%\bin
build_script:
# prepare
- mkdir 3rdparty
- cinst ninja
# install ECM so we can build KImageFormats
- cd 3rdparty
- git clone -q git://anongit.kde.org/extra-cmake-modules.git
- cd extra-cmake-modules
- cmake -G "Ninja" . -DCMAKE_INSTALL_PREFIX=%CMAKE_INSTALL_ROOT%
- cmake --build .
- cmake --build . --target install
- cd %APPVEYOR_BUILD_FOLDER%
# install KImageFormats
- cd 3rdparty
- git clone git://anongit.kde.org/kimageformats.git
- cd kimageformats
- mkdir build
- cd build
- cmake -G "Unix Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make -DCMAKE_INSTALL_PREFIX='%cd%' ..\
- cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-s" -DCMAKE_MAKE_PROGRAM=mingw32-make -DQT_PLUGIN_INSTALL_DIR=%QTPATH%\plugins
- cmake --build . --config Release
- cmake --build . --config Release --target install
- cd %APPVEYOR_BUILD_FOLDER%
# finally...
- mkdir build
- cd build
- cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=mingw32-make -DCMAKE_INSTALL_PREFIX='%cd%'
- mingw32-make
- mingw32-make install
# fixme: I don't know how to NOT make the binary installed to the ./bin/ folder...
- cd bin
- windeployqt --no-quick-import --no-translations --no-opengl-sw --no-angle --no-system-d3d-compiler --release .\ppic.exe
- tree
- windeployqt --verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-angle --no-system-d3d-compiler --release .\ppic.exe
# for debug..
- tree /f
artifacts:
- path: build\bin

View File

@ -60,6 +60,17 @@ void GraphicsScene::showGif(const QString &filepath)
this->setSceneRect(m_theThing->boundingRect());
}
bool GraphicsScene::trySetTransformationMode(Qt::TransformationMode mode)
{
QGraphicsPixmapItem * pixmapItem = qgraphicsitem_cast<QGraphicsPixmapItem *>(m_theThing);
if (pixmapItem) {
pixmapItem->setTransformationMode(mode);
return true;
}
return false;
}
QPixmap GraphicsScene::renderToPixmap()
{
QPixmap pixmap(sceneRect().toRect().size());

View File

@ -15,6 +15,8 @@ public:
void showSvg(const QString &filepath);
void showGif(const QString &filepath);
bool trySetTransformationMode(Qt::TransformationMode mode);
QPixmap renderToPixmap();
private:

View File

@ -39,8 +39,10 @@ void GraphicsView::showFileFromUrl(const QUrl &url, bool doRequestGallery)
QImageReader imageReader(filePath);
imageReader.setAutoTransform(true);
imageReader.setDecideFormatFromContent(true);
QImage::Format imageFormat = imageReader.imageFormat();
if (imageFormat == QImage::Format_Invalid) {
// Since if the image format / plugin does not support this feature, imageFormat() will returns an invalid format.
// So we cannot use imageFormat() and check if it returns QImage::Format_Invalid to detect if we support the file.
// QImage::Format imageFormat = imageReader.imageFormat();
if (imageReader.format().isEmpty()) {
showText(tr("File is not a valid image"));
} else {
showImage(QPixmap::fromImageReader(&imageReader));
@ -117,6 +119,7 @@ void GraphicsView::zoomView(qreal scaleFactor)
{
m_enableFitInView = false;
scale(scaleFactor, scaleFactor);
applyTransformationModeByScaleFactor();
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
}
@ -136,6 +139,7 @@ void GraphicsView::rotateView(qreal rotateAngel)
void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode)
{
QGraphicsView::fitInView(rect, aspectRadioMode);
applyTransformationModeByScaleFactor();
}
void GraphicsView::checkAndDoFitInView()
@ -213,9 +217,9 @@ void GraphicsView::dragEnterEvent(QDragEnterEvent *event)
} else {
event->ignore();
}
qDebug() << event->mimeData() << "Drag Enter Event"
<< event->mimeData()->hasUrls() << event->mimeData()->hasImage()
<< event->mimeData()->formats() << event->mimeData()->hasFormat("text/uri-list");
// qDebug() << event->mimeData() << "Drag Enter Event"
// << event->mimeData()->hasUrls() << event->mimeData()->hasImage()
// << event->mimeData()->formats() << event->mimeData()->hasFormat("text/uri-list");
return QGraphicsView::dragEnterEvent(event);
}
@ -285,9 +289,9 @@ void GraphicsView::setCheckerboardEnabled(bool enabled)
if (m_checkerboardEnabled) {
// Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20);
tilePixmap.fill(QColor(35, 35, 35, 110));
tilePixmap.fill(QColor(35, 35, 35, 170));
QPainter tilePainter(&tilePixmap);
QColor color(40, 40, 40, 110);
QColor color(45, 45, 45, 170);
tilePainter.fillRect(0, 0, 0x10, 0x10, color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, color);
tilePainter.end();
@ -298,6 +302,15 @@ void GraphicsView::setCheckerboardEnabled(bool enabled)
}
}
void GraphicsView::applyTransformationModeByScaleFactor()
{
if (this->scaleFactor() < 1) {
scene()->trySetTransformationMode(Qt::SmoothTransformation);
} else {
scene()->trySetTransformationMode(Qt::FastTransformation);
}
}
void GraphicsView::resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle)
{
QGraphicsView::resetTransform();

View File

@ -54,6 +54,7 @@ private:
bool isThingSmallerThanWindowWith(const QTransform &transform) const;
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
void setCheckerboardEnabled(bool enabled);
void applyTransformationModeByScaleFactor();
void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle);

View File

@ -113,6 +113,10 @@ MainWindow::MainWindow(QWidget *parent) :
connect(quitAppShorucut, &QShortcut::activated,
std::bind(&MainWindow::quitAppAction, this, false));
QShortcut * quitAppShorucut2 = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(quitAppShorucut2, &QShortcut::activated,
std::bind(&MainWindow::quitAppAction, this, false));
QShortcut * prevPictureShorucut = new QShortcut(QKeySequence(Qt::Key_PageUp), this);
connect(prevPictureShorucut, &QShortcut::activated,
this, &MainWindow::galleryPrev);
@ -185,12 +189,18 @@ QUrl MainWindow::currentImageFileUrl() const
return QUrl();
}
void MainWindow::clearGallery()
{
m_currentFileIndex = -1;
m_files.clear();
}
void MainWindow::loadGalleryBySingleLocalFile(const QString &path)
{
QFileInfo info(path);
QDir dir(info.path());
QString currentFileName = info.fileName();
QStringList entryList = dir.entryList({"*.jpg", "*.jpeg", "*.png", "*.gif", "*.svg", "*.bmp"},
QStringList entryList = dir.entryList({"*.jpg", "*.jpeg", "*.jfif", "*.png", "*.gif", "*.svg", "*.bmp"},
QDir::Files | QDir::NoSymLinks, QDir::NoSort);
QCollator collator;
@ -198,8 +208,7 @@ void MainWindow::loadGalleryBySingleLocalFile(const QString &path)
std::sort(entryList.begin(), entryList.end(), collator);
m_currentFileIndex = -1;
m_files.clear();
clearGallery();
for (int i = 0; i < entryList.count(); i++) {
const QString & oneEntry = entryList.at(i);
@ -268,8 +277,8 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
if (event->buttons() & Qt::LeftButton && !isMaximized()) {
m_clickedOnWindow = true;
m_oldMousePos = event->pos();
qDebug() << m_oldMousePos << m_graphicsView->transform().m11()
<< m_graphicsView->transform().m22() << m_graphicsView->matrix().m12();
// qDebug() << m_oldMousePos << m_graphicsView->transform().m11()
// << m_graphicsView->transform().m22() << m_graphicsView->matrix().m12();
event->accept();
}
@ -357,6 +366,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
QAction * pasteImage = new QAction(tr("&Paste Image"));
connect(pasteImage, &QAction::triggered, this, [ = ](){
clearGallery();
m_graphicsView->showImage(clipboardImage);
});

View File

@ -27,6 +27,7 @@ public:
void adjustWindowSizeBySceneRect();
QUrl currentImageFileUrl() const;
void clearGallery();
void loadGalleryBySingleLocalFile(const QString &path);
void galleryPrev();
void galleryNext();