Use Native File Dialog
This commit is contained in:
@@ -113,7 +113,6 @@ SOURCES += src/main.cpp \
|
||||
src/cli/commandargument.cpp \
|
||||
src/capture/workers/screenshotsaver.cpp \
|
||||
src/capture/workers/imgur/imguruploader.cpp \
|
||||
src/capture/workers/graphicalscreenshotsaver.cpp \
|
||||
src/capture/workers/imgur/loadspinner.cpp \
|
||||
src/capture/workers/imgur/imagelabel.cpp \
|
||||
src/capture/workers/imgur/notificationwidget.cpp \
|
||||
@@ -170,7 +169,6 @@ HEADERS += src/capture/widget/buttonhandler.h \
|
||||
src/cli/commandargument.h \
|
||||
src/capture/workers/screenshotsaver.h \
|
||||
src/capture/workers/imgur/imguruploader.h \
|
||||
src/capture/workers/graphicalscreenshotsaver.h \
|
||||
src/capture/workers/imgur/loadspinner.h \
|
||||
src/capture/workers/imgur/imagelabel.h \
|
||||
src/capture/workers/imgur/notificationwidget.h \
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "graphicalscreenshotsaver.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QFileDialog>
|
||||
#include <QImageWriter>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
/*
|
||||
* Añadir la captura de pantalla a la derecha y boton de copiar
|
||||
*
|
||||
*/
|
||||
|
||||
GraphicalScreenshotSaver::GraphicalScreenshotSaver(const QPixmap &capture,
|
||||
QWidget *parent) :
|
||||
QWidget(parent), m_pixmap(capture)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowTitle(QObject::tr("Save As"));
|
||||
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_fileDialog = new QFileDialog();
|
||||
initFileDialog();
|
||||
m_layout->addWidget(m_fileDialog);
|
||||
|
||||
}
|
||||
|
||||
void GraphicalScreenshotSaver::initFileDialog() {
|
||||
m_fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
|
||||
m_fileDialog->setFileMode(QFileDialog::AnyFile);
|
||||
m_fileDialog->setAcceptMode(QFileDialog::AcceptSave);
|
||||
QString fileName, directory;
|
||||
FileNameHandler().absoluteSavePath(directory, fileName);
|
||||
m_fileDialog->selectFile(fileName);
|
||||
m_fileDialog->setDirectory(directory);
|
||||
|
||||
QStringList mimeTypes;
|
||||
for (const QByteArray &bf: QImageWriter::supportedMimeTypes())
|
||||
mimeTypes.append(QLatin1String(bf));
|
||||
m_fileDialog->setMimeTypeFilters(mimeTypes);
|
||||
m_fileDialog->selectMimeTypeFilter("image/png");
|
||||
m_fileDialog->setDefaultSuffix("png");
|
||||
|
||||
connect(m_fileDialog, &QFileDialog::rejected,
|
||||
this, &GraphicalScreenshotSaver::close);
|
||||
connect(m_fileDialog, &QFileDialog::accepted,
|
||||
this, &GraphicalScreenshotSaver::checkSaveAcepted);
|
||||
}
|
||||
|
||||
void GraphicalScreenshotSaver::showErrorMessage(const QString &msg) {
|
||||
QMessageBox saveErrBox(
|
||||
QMessageBox::Warning,
|
||||
QObject::tr("Save Error"),
|
||||
msg);
|
||||
saveErrBox.setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
saveErrBox.exec();
|
||||
}
|
||||
|
||||
void GraphicalScreenshotSaver::checkSaveAcepted() {
|
||||
m_fileDialog->show();
|
||||
QString path = m_fileDialog->selectedFiles().first();
|
||||
bool ok = m_pixmap.save(path);
|
||||
if (ok) {
|
||||
QString pathNoFile = path.left(path.lastIndexOf("/"));
|
||||
ConfigHandler().setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + path;
|
||||
SystemNotification().sendMessage(msg);
|
||||
close();
|
||||
} else {
|
||||
QString msg = QObject::tr("Error trying to save as ") + path;
|
||||
showErrorMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef GRAPHICALSCREENSHOTSAVER_H
|
||||
#define GRAPHICALSCREENSHOTSAVER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QFileDialog;
|
||||
class QVBoxLayout;
|
||||
|
||||
class GraphicalScreenshotSaver : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GraphicalScreenshotSaver(const QPixmap &capture,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QFileDialog *m_fileDialog;
|
||||
QVBoxLayout *m_layout;
|
||||
|
||||
void initFileDialog();
|
||||
void showErrorMessage(const QString &msg);
|
||||
void checkSaveAcepted();
|
||||
};
|
||||
|
||||
#endif // GRAPHICALSCREENSHOTSAVER_H
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QImageWriter>
|
||||
|
||||
ScreenshotSaver::ScreenshotSaver()
|
||||
{
|
||||
@@ -47,4 +49,33 @@ void ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
|
||||
SystemNotification().sendMessage(saveMessage);
|
||||
}
|
||||
|
||||
void ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
|
||||
bool ok = false;
|
||||
while (!ok) {
|
||||
QString savePath = QFileDialog::getSaveFileName(
|
||||
nullptr,
|
||||
QString(),
|
||||
FileNameHandler().absoluteSavePath() + ".png");
|
||||
|
||||
if (savePath.isNull()) {
|
||||
return;
|
||||
}
|
||||
ok = capture.save(savePath);
|
||||
if (ok) {
|
||||
QString pathNoFile = savePath.left(savePath.lastIndexOf("/"));
|
||||
ConfigHandler().setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + savePath;
|
||||
SystemNotification().sendMessage(msg);
|
||||
} else {
|
||||
QString msg = QObject::tr("Error trying to save as ") + savePath;
|
||||
QMessageBox saveErrBox(
|
||||
QMessageBox::Warning,
|
||||
QObject::tr("Save Error"),
|
||||
msg);
|
||||
saveErrBox.setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
saveErrBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
|
||||
void saveToClipboard(const QPixmap &capture);
|
||||
void saveToFilesystem(const QPixmap &capture, const QString &path);
|
||||
void saveToFilesystemGUI(const QPixmap &capture);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "resourceexporter.h"
|
||||
#include "src/capture/workers/imgur/imguruploader.h"
|
||||
#include "src/capture/workers/screenshotsaver.h"
|
||||
#include "src/capture/workers/graphicalscreenshotsaver.h"
|
||||
#include "src/capture/workers/launcher/openwithprogram.h"
|
||||
|
||||
ResourceExporter::ResourceExporter() {
|
||||
@@ -34,8 +33,7 @@ void ResourceExporter::captureToFile(const QPixmap &p, const QString &path) {
|
||||
}
|
||||
|
||||
void ResourceExporter::captureToFileUi(const QPixmap &p) {
|
||||
auto w = new GraphicalScreenshotSaver(p);
|
||||
w->show();
|
||||
ScreenshotSaver().saveToFilesystemGUI(p);
|
||||
}
|
||||
|
||||
void ResourceExporter::captureToImgur(const QPixmap &p) {
|
||||
|
||||
@@ -72,6 +72,11 @@ QString FileNameHandler::absoluteSavePath(QString &directory, QString &filename)
|
||||
return directory + filename;
|
||||
}
|
||||
|
||||
QString FileNameHandler::absoluteSavePath() {
|
||||
QString dir, file;
|
||||
return absoluteSavePath(dir, file);
|
||||
}
|
||||
|
||||
QString FileNameHandler::charArrToQString(const char *c) {
|
||||
return QString::fromLocal8Bit(c, MAX_CHARACTERS);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public:
|
||||
QString parseFilename(const QString &name);
|
||||
QString generateAbsolutePath(const QString &path);
|
||||
QString absoluteSavePath(QString &directory, QString &filename);
|
||||
QString absoluteSavePath();
|
||||
|
||||
|
||||
static const int MAX_CHARACTERS = 70;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user