Change startup behavior of the standalone version

This commit is contained in:
Sebastien Fourey 2018-03-17 17:39:04 +01:00
parent b2a61efc7d
commit b349646534
8 changed files with 86 additions and 27 deletions

View File

@ -364,7 +364,10 @@ FORMS += ui/inoutpanel.ui \
ui/languageselectionwidget.ui \
ui/filtersview.ui
RESOURCES = gmic_qt.qrc translations.qrc
RESOURCES += gmic_qt.qrc translations.qrc
equals( HOST, "none") {
RESOURCES += standalone.qrc
}
TRANSLATIONS = \
translations/cs.ts \

BIN
resources/gmicky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

View File

@ -27,7 +27,9 @@
#include <QDesktopWidget>
#include <QFileDialog>
#include <QFileInfo>
#include <QProcess>
#include <QFont>
#include <QMessageBox>
#include <QPainter>
#include <QRegularExpression>
#include <algorithm>
#include <iostream>
@ -35,6 +37,7 @@
#include "Host/None/ImageDialog.h"
#include "Host/host.h"
#include "ImageConverter.h"
#include "MainWindow.h"
#include "gmic_qt.h"
#include "gmic.h"
@ -44,7 +47,7 @@
//#define DEFAULT_IMAGE "local/space-shuttle.png"
//#define DEFAULT_IMAGE "local/space-shuttle-transp.png"
//#define DEFAULT_IMAGE "local/bug.jpg"
#define DEFAULT_IMAGE "local/bug2.jpg"
//#define DEFAULT_IMAGE "local/bug2.jpg"
//#define DEFAULT_IMAGE "local/crop_inktober.jpg"
//#define DEFAULT_IMAGE "local/lena.png"
//#define DEFAULT_IMAGE "local/transp.png"
@ -62,6 +65,41 @@ namespace gmic_qt_standalone
{
QImage input_image;
QString image_filename;
QWidget * visibleMainWindow()
{
for (QWidget * w : QApplication::topLevelWidgets()) {
if ((typeid(*w) == typeid(MainWindow)) && (w->isVisible())) {
return w;
}
}
return nullptr;
}
void askForImageFilename()
{
QWidget * mainWidget = visibleMainWindow();
Q_ASSERT_X(mainWidget, __PRETTY_FUNCTION__, "No top level window yet");
QString filename = QFileDialog::getOpenFileName(mainWidget, QObject::tr("Select an image to open..."), ".", QObject::tr("PNG & JPG files (*.png *.jpeg *.jpg *.PNG *.JPEG *.JPG)"), nullptr);
if (!filename.isEmpty() && QFileInfo(filename).isReadable() && input_image.load(filename)) {
input_image = input_image.convertToFormat(QImage::Format_ARGB32);
image_filename = QFileInfo(filename).fileName();
} else {
if (!filename.isEmpty()) {
QMessageBox::warning(mainWidget, QObject::tr("Error"), QObject::tr("Could not open file."));
}
input_image.load(":/resources/gmicky.png");
input_image = input_image.convertToFormat(QImage::Format_ARGB32);
image_filename = QObject::tr("Default image");
}
}
const QImage & transparentImage()
{
static QImage image;
if (image.isNull()) {
image = QImage(640, 480, QImage::Format_ARGB32);
image.fill(QColor(0, 0, 0, 0));
}
return image;
}
}
namespace GmicQt
@ -72,8 +110,20 @@ const char * HostApplicationShortname = XSTRINGIFY(GMIC_HOST);
void gmic_qt_get_image_size(int * x, int * y)
{
*x = gmic_qt_standalone::input_image.width();
*y = gmic_qt_standalone::input_image.height();
// TSHOW(gmic_qt_standalone::visibleMainWindow());
if (gmic_qt_standalone::input_image.isNull()) {
if (gmic_qt_standalone::visibleMainWindow()) {
gmic_qt_standalone::askForImageFilename();
*x = gmic_qt_standalone::input_image.width();
*y = gmic_qt_standalone::input_image.height();
} else {
*x = 640;
*y = 480;
}
} else {
*x = gmic_qt_standalone::input_image.width();
*y = gmic_qt_standalone::input_image.height();
}
}
void gmic_qt_get_layers_extent(int * width, int * height, GmicQt::InputMode)
@ -83,7 +133,8 @@ void gmic_qt_get_layers_extent(int * width, int * height, GmicQt::InputMode)
void gmic_qt_get_cropped_images(gmic_list<float> & images, gmic_list<char> & imageNames, double x, double y, double width, double height, GmicQt::InputMode mode)
{
QImage & input_image = gmic_qt_standalone::input_image;
const QImage & input_image = gmic_qt_standalone::input_image.isNull() ? gmic_qt_standalone::transparentImage() : gmic_qt_standalone::input_image;
const bool entireImage = x < 0 && y < 0 && width < 0 && height < 0;
if (entireImage) {
x = 0.0;
@ -156,7 +207,9 @@ int main(int argc, char * argv[])
filename = DEFAULT_IMAGE;
}
#endif
if (!filename.isEmpty()) {
if (filename.isEmpty()) {
return launchPlugin();
} else {
if (QFileInfo(filename).isReadable() && gmic_qt_standalone::input_image.load(filename)) {
gmic_qt_standalone::input_image = gmic_qt_standalone::input_image.convertToFormat(QImage::Format_ARGB32);
gmic_qt_standalone::image_filename = QFileInfo(filename).fileName();
@ -165,21 +218,6 @@ int main(int argc, char * argv[])
std::cerr << "Could not open file " << filename.toLocal8Bit().constData() << "\n";
return 1;
}
} else {
QApplication app(argc, argv);
QWidget mainWidget;
mainWidget.setWindowTitle(QString("G'MIC-Qt - %1").arg(GmicQt::gmicVersionString()));
QRect position = mainWidget.frameGeometry();
position.moveCenter(QDesktopWidget().availableGeometry().center());
mainWidget.move(position.topLeft());
mainWidget.show();
QString filename = QFileDialog::getOpenFileName(&mainWidget, QObject::tr("Select an image to open..."), ".", QObject::tr("PNG & JPG files (*.png *.jpeg *.jpg *.PNG *.JPEG *.JPG)"), nullptr);
mainWidget.hide();
if (!filename.isEmpty() && QFileInfo(filename).isReadable()) {
return QProcess::execute(app.applicationFilePath(), QStringList() << filename);
} else {
return 1;
}
}
}

View File

@ -23,6 +23,8 @@
*
*/
#include "LayersExtentProxy.h"
#include <QDebug>
#include "Common.h"
#include "Host/host.h"
int LayersExtentProxy::_width = -1;

View File

@ -322,9 +322,16 @@ void MainWindow::onStartupFiltersUpdateFinished(int status)
_gtkFavesShouldBeImported = askUserForGTKFavesImport();
}
buildFiltersTree();
ui->searchField->setFocus();
// Let the standalone version load an image, if necessary (not pretty)
if (GmicQt::HostApplicationName.isEmpty()) {
LayersExtentProxy::clearCache();
QSize extent = LayersExtentProxy::getExtent(ui->inOutSelector->inputMode());
ui->previewWidget->setFullImageSize(extent);
ui->previewWidget->update();
}
// Retrieve and select previously selected filter
QString hash = QSettings().value("SelectedFilter", QString()).toString();
if (_newSession || !_lastExecutionOK) {
@ -649,7 +656,6 @@ void MainWindow::onOkClicked()
void MainWindow::onCloseClicked()
{
ENTERING;
TIMING;
if (_processor.isProcessing() && confirmAbortProcessingOnCloseRequest()) {
if (_processor.isProcessing()) {
@ -963,7 +969,6 @@ void MainWindow::showEvent(QShowEvent * event)
if (_newSession) {
Logger::clear();
}
QObject::connect(Updater::getInstance(), SIGNAL(updateIsDone(int)), this, SLOT(onStartupFiltersUpdateFinished(int)));
int ageLimit;
{
@ -972,7 +977,7 @@ void MainWindow::showEvent(QShowEvent * event)
Updater::setOutputMessageMode(mode);
ageLimit = settings.value(INTERNET_UPDATE_PERIODICITY_KEY, INTERNET_DEFAULT_PERIODICITY).toInt();
}
const bool useNetwork = ageLimit != INTERNET_NEVER_UPDATE_PERIODICITY;
const bool useNetwork = (ageLimit != INTERNET_NEVER_UPDATE_PERIODICITY);
ui->progressInfoWidget->startFiltersUpdateAnimationAndShow();
Updater::getInstance()->startUpdate(ageLimit, 4, useNetwork);
}

View File

@ -137,7 +137,7 @@ void Updater::startUpdate(int ageLimit, int timeout, bool useNetwork)
}
}
if (_pendingReplies.isEmpty()) {
emit updateIsDone(UpdateNotNecessary);
QTimer::singleShot(0, this, SLOT(onUpdateNotNecessary())); // While GUI is Idle
_networkAccessManager->deleteLater();
} else {
QTimer::singleShot(timeout * 1000, this, SLOT(cancelAllPendingDownloads()));
@ -258,6 +258,11 @@ void Updater::cancelAllPendingDownloads()
}
}
void Updater::onUpdateNotNecessary()
{
emit updateIsDone(UpdateNotNecessary);
}
QByteArray Updater::cimgzDecompress(QByteArray array)
{
QTemporaryFile tmpZ(QDir::tempPath() + QDir::separator() + "gmic_qt_update_XXXXXX_cimgz");

View File

@ -87,6 +87,7 @@ public slots:
void onNetworkReplyFinished(QNetworkReply *);
void notifyAllDowloadsOK();
void cancelAllPendingDownloads();
void onUpdateNotNecessary();
protected:
void processReply(QNetworkReply * reply);

5
standalone.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>resources/gmicky.png</file>
</qresource>
</RCC>