From 0a42ea91c9635ee0752207efd91c71935cb2fe9f Mon Sep 17 00:00:00 2001 From: Rylan Dmello Date: Sat, 26 Aug 2017 16:28:31 -0400 Subject: [PATCH] Added File Menu items and fixed large image bug --- src/gui-qt/PixelSortApp.cpp | 41 +++++++++++++++++++-------------- src/gui-qt/PixelSortApp.hpp | 2 ++ src/gui-qt/PixelSortOptions.cpp | 4 ++-- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/gui-qt/PixelSortApp.cpp b/src/gui-qt/PixelSortApp.cpp index e10cfc6..6fbba3e 100644 --- a/src/gui-qt/PixelSortApp.cpp +++ b/src/gui-qt/PixelSortApp.cpp @@ -67,7 +67,18 @@ PixelSortApp::PixelSortApp(QApplication* parent): dockwidget.setAllowedAreas(Qt::LeftDockWidgetArea); dockwidget.setFeatures(QDockWidget::NoDockWidgetFeatures); dockwidget.setWidget(&dockwidget_mid); - + + // Set up menubar actions + QAction* openAction = fileMenu.addAction("&Open"); + QAction* saveAction = fileMenu.addAction("&Save"); + openAction->setShortcuts(QKeySequence::Open); + saveAction->setShortcuts(QKeySequence::Save); + + // Set up menubar + menuBar()->addMenu(&fileMenu); + menuBar()->addAction(fileMenu.menuAction()); + menuBar()->show(); + // add import and export button to vbox vbox.addWidget(&importbutton); vbox.addWidget(&exportbutton); @@ -77,19 +88,23 @@ PixelSortApp::PixelSortApp(QApplication* parent): fileimport.setAcceptMode(QFileDialog::AcceptOpen); fileimport.setNameFilter("Images (*.png *.tiff *.tif)"); fileimport.fileSelected(imageFilePath); + // reload image view after importing + QObject::connect(&fileimport, SIGNAL(fileSelected(QString)), this, SLOT(reloadImage(QString))); // file export dialog settings fileexport.setFileMode(QFileDialog::AnyFile); fileexport.setAcceptMode(QFileDialog::AcceptSave); - - // Connect actual import button events - QObject::connect(&importbutton, SIGNAL(clicked()), &fileimport, SLOT(exec())); - QObject::connect(&fileimport, SIGNAL(fileSelected(QString)), this, SLOT(reloadImage(QString))); - - // Connect actual export button events - QObject::connect(&exportbutton, SIGNAL(clicked()), &fileexport, SLOT(exec())); + // write image after selecting export filename QObject::connect(&fileexport, SIGNAL(fileSelected(QString)), this, SLOT(writeImage(QString))); - + + // Set up openAction and saveAction + QObject::connect(openAction, &QAction::triggered, &fileimport, &QFileDialog::exec); + QObject::connect(saveAction, &QAction::triggered, &fileexport, &QFileDialog::exec); + + // Connect import and export button events + QObject::connect(&importbutton, &QPushButton::clicked, openAction, &QAction::trigger); + QObject::connect(&exportbutton, &QPushButton::clicked, saveAction, &QAction::trigger); + // Set up the form layout widget vbox.addLayout(&formlayout); formlayout.setLabelAlignment(Qt::AlignCenter); @@ -194,14 +209,6 @@ PixelSortApp::PixelSortApp(QApplication* parent): // vbox.addWidget(&quitbutton); // QObject::connect(&quitbutton, SIGNAL(clicked()), appPtr, SLOT(quit())); - // Set up menubar - fileMenu.addAction("Item 1"); - fileMenu.addAction("Item 2"); - menuBar()->addMenu(&fileMenu); - menuBar()->addAction(fileMenu.menuAction()); - menuBar()->show(); - // menuBar()->setNativeMenuBar(false); - // Read initial image file imageFilePath = "./pixelsort.app/Contents/resources/lake.png"; img.load(imageFilePath); diff --git a/src/gui-qt/PixelSortApp.hpp b/src/gui-qt/PixelSortApp.hpp index 031946e..b4e4298 100644 --- a/src/gui-qt/PixelSortApp.hpp +++ b/src/gui-qt/PixelSortApp.hpp @@ -16,10 +16,12 @@ #include #include #include +#include #include #include #include +#include // PixelSort includes #include "PixelSortOptions.hpp" diff --git a/src/gui-qt/PixelSortOptions.cpp b/src/gui-qt/PixelSortOptions.cpp index 904b981..cce4145 100644 --- a/src/gui-qt/PixelSortOptions.cpp +++ b/src/gui-qt/PixelSortOptions.cpp @@ -96,10 +96,10 @@ void PixelSortOptions::doSort() /* Create Xrepeat, Yrepeat parameters */ int Xstart = Xrepeat[0]; int Xpitch = Xrepeat[1]; - int Xend = img->columns() < unsigned(Xrepeat[2]) ? img->columns() : Xrepeat[2]; + int Xend = img->columns(); // not controllable yet int Ystart = Yrepeat[0]; int Ypitch = Yrepeat[1]; - int Yend = img->rows() < unsigned(Yrepeat[2]) ? img->rows() : Yrepeat[2]; + int Yend = img->rows(); // not controllable yet /* * Start PixelSorting