mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 17:59:25 +00:00
Added a gui --selection option to print out the geometry of the selection.
Fixes #425.
This commit is contained in:
committed by
borgmanJeremy
parent
8b51af2010
commit
05c2bc6ae7
@@ -95,12 +95,14 @@
|
||||
captureTaken:
|
||||
@id: identificator of the call.
|
||||
@rawImage: raw image in PNG format.
|
||||
@selection: QRect selection geometry.
|
||||
|
||||
Successful capture signal returning the image.
|
||||
-->
|
||||
<signal name="captureTaken">
|
||||
<arg name="id" type="u" direction="out"/>
|
||||
<arg name="rawImage" type="ay" direction="out"/>
|
||||
<arg name="selection" type="(iiii)" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<!--
|
||||
@@ -112,5 +114,6 @@
|
||||
<signal name="captureFailed">
|
||||
<arg name="id" type="u" direction="out"/>
|
||||
</signal>
|
||||
|
||||
</interface>
|
||||
</node>
|
||||
|
||||
@@ -170,7 +170,8 @@ void Controller::startScreenGrab(const uint id, const int screenNumber)
|
||||
}
|
||||
QPixmap p(ScreenGrabber().grabScreen(n, ok));
|
||||
if (ok) {
|
||||
emit captureTaken(id, p);
|
||||
QRect selection; // `flameshot screen` does not support --selection
|
||||
emit captureTaken(id, p, selection);
|
||||
} else {
|
||||
emit captureFailed(id);
|
||||
}
|
||||
@@ -325,13 +326,14 @@ void Controller::startFullscreenCapture(const uint id)
|
||||
bool ok = true;
|
||||
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
|
||||
if (ok) {
|
||||
emit captureTaken(id, p);
|
||||
QRect selection; // `flameshot full` does not support --selection
|
||||
emit captureTaken(id, p, selection);
|
||||
} else {
|
||||
emit captureFailed(id);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p)
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p, QRect selection)
|
||||
{
|
||||
auto it = m_requestMap.find(id);
|
||||
if (it != m_requestMap.end()) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void updateRecentScreenshots();
|
||||
|
||||
signals:
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureTaken(uint id, QPixmap p, QRect selection);
|
||||
void captureFailed(uint id);
|
||||
|
||||
public slots:
|
||||
@@ -74,7 +74,7 @@ private slots:
|
||||
const QString& forcedSavePath = QString());
|
||||
void startScreenGrab(const uint id = 0, const int screenNumber = -1);
|
||||
|
||||
void handleCaptureTaken(uint id, QPixmap p);
|
||||
void handleCaptureTaken(uint id, QPixmap p, QRect selection);
|
||||
void handleCaptureFailed(uint id);
|
||||
|
||||
private:
|
||||
|
||||
@@ -109,10 +109,12 @@ void FlameshotDBusAdapter::autostartEnabled(bool enabled)
|
||||
controller->updateConfigComponents();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap& p)
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id,
|
||||
const QPixmap& p,
|
||||
QRect selection)
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
p.save(&buffer, "PNG");
|
||||
emit captureTaken(id, byteArray);
|
||||
emit captureTaken(id, byteArray, selection);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
virtual ~FlameshotDBusAdapter();
|
||||
|
||||
signals:
|
||||
void captureTaken(uint id, QByteArray rawImage);
|
||||
void captureTaken(uint id, QByteArray rawImage, QRect selection);
|
||||
void captureFailed(uint id);
|
||||
|
||||
public slots:
|
||||
@@ -50,5 +50,5 @@ public slots:
|
||||
Q_NOREPLY void autostartEnabled(bool enabled);
|
||||
|
||||
private slots:
|
||||
void handleCaptureTaken(uint id, const QPixmap& p);
|
||||
void handleCaptureTaken(uint id, const QPixmap& p, QRect selection);
|
||||
};
|
||||
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -38,6 +38,16 @@
|
||||
#include <QDBusMessage>
|
||||
#endif
|
||||
|
||||
int waitAfterConnecting(int delay, QCoreApplication& app)
|
||||
{
|
||||
QTimer t;
|
||||
t.setInterval(delay + 1000 * 60 * 15); // 15 minutes timeout
|
||||
QObject::connect(&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
|
||||
t.start();
|
||||
// wait
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// required for the button serialization
|
||||
@@ -151,6 +161,10 @@ int main(int argc, char* argv[])
|
||||
QStringLiteral("color-code"));
|
||||
CommandOption rawImageOption({ "r", "raw" },
|
||||
QObject::tr("Print raw PNG capture"));
|
||||
CommandOption selectionOption(
|
||||
{ "g", "print-geometry" },
|
||||
QObject::tr("Print geometry of the selection in the format W H X Y. Does "
|
||||
"nothing if raw is specified"));
|
||||
CommandOption screenNumberOption(
|
||||
{ "n", "number" },
|
||||
QObject::tr("Define the screen to capture") + ",\n" +
|
||||
@@ -216,7 +230,9 @@ int main(int argc, char* argv[])
|
||||
parser.AddArgument(configArgument);
|
||||
auto helpOption = parser.addHelpOption();
|
||||
auto versionOption = parser.addVersionOption();
|
||||
parser.AddOptions({ pathOption, delayOption, rawImageOption }, guiArgument);
|
||||
parser.AddOptions(
|
||||
{ pathOption, delayOption, rawImageOption, selectionOption },
|
||||
guiArgument);
|
||||
parser.AddOptions({ screenNumberOption,
|
||||
clipboardOption,
|
||||
pathOption,
|
||||
@@ -257,6 +273,7 @@ int main(int argc, char* argv[])
|
||||
QString pathValue = parser.value(pathOption);
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool isRaw = parser.isSet(rawImageOption);
|
||||
bool isSelection = parser.isSet(selectionOption);
|
||||
DBusUtils dbusUtils;
|
||||
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, pathValue);
|
||||
uint id = req.id();
|
||||
@@ -274,13 +291,10 @@ int main(int argc, char* argv[])
|
||||
|
||||
if (isRaw) {
|
||||
dbusUtils.connectPrintCapture(sessionBus, id);
|
||||
QTimer t;
|
||||
t.setInterval(delay + 1000 * 60 * 15); // 15 minutes timeout
|
||||
QObject::connect(
|
||||
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
|
||||
t.start();
|
||||
// wait
|
||||
return app.exec();
|
||||
return waitAfterConnecting(delay, app);
|
||||
} else if (isSelection) {
|
||||
dbusUtils.connectSelectionCapture(sessionBus, id);
|
||||
return waitAfterConnecting(delay, app);
|
||||
}
|
||||
} else if (parser.isSet(fullArgument)) { // FULL
|
||||
QString pathValue = parser.value(pathOption);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QRect>
|
||||
#include <QTextStream>
|
||||
|
||||
DBusUtils::DBusUtils(QObject* parent)
|
||||
@@ -34,7 +35,26 @@ void DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
SLOT(captureTaken(uint, QByteArray, QRect)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
}
|
||||
|
||||
void DBusUtils::connectSelectionCapture(QDBusConnection& session, uint id)
|
||||
{
|
||||
m_id = id;
|
||||
// captureTaken
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(selectionTaken(uint, QByteArray, QRect)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
@@ -52,11 +72,12 @@ void DBusUtils::checkDBusConnection(const QDBusConnection& connection)
|
||||
}
|
||||
}
|
||||
|
||||
void DBusUtils::captureTaken(uint id, QByteArray rawImage)
|
||||
void DBusUtils::captureTaken(uint id, QByteArray rawImage, QRect selection)
|
||||
{
|
||||
if (m_id == id) {
|
||||
QFile file;
|
||||
file.open(stdout, QIODevice::WriteOnly);
|
||||
|
||||
file.write(rawImage);
|
||||
file.close();
|
||||
qApp->exit();
|
||||
@@ -70,3 +91,17 @@ void DBusUtils::captureFailed(uint id)
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void DBusUtils::selectionTaken(uint id, QByteArray rawImage, QRect selection)
|
||||
{
|
||||
if (m_id == id) {
|
||||
QFile file;
|
||||
file.open(stdout, QIODevice::WriteOnly);
|
||||
|
||||
QTextStream out(&file);
|
||||
out << selection.width() << " " << selection.height() << " "
|
||||
<< selection.x() << " " << selection.y();
|
||||
file.close();
|
||||
qApp->exit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@ public:
|
||||
|
||||
void connectPrintCapture(QDBusConnection& session, uint id);
|
||||
void checkDBusConnection(const QDBusConnection& connection);
|
||||
void connectSelectionCapture(QDBusConnection& session, uint id);
|
||||
|
||||
public slots:
|
||||
void captureTaken(uint id, QByteArray rawImage);
|
||||
void selectionTaken(uint id, QByteArray rawImage, QRect selection);
|
||||
void captureTaken(uint id, QByteArray rawImage, QRect selection);
|
||||
void captureFailed(uint id);
|
||||
|
||||
private:
|
||||
|
||||
@@ -160,7 +160,7 @@ CaptureWidget::CaptureWidget(const uint id,
|
||||
CaptureWidget::~CaptureWidget()
|
||||
{
|
||||
if (m_captureDone) {
|
||||
emit captureTaken(m_id, this->pixmap());
|
||||
emit captureTaken(m_id, this->pixmap(), m_context.selection);
|
||||
} else {
|
||||
emit captureFailed(m_id);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public slots:
|
||||
void deleteToolwidgetOrClose();
|
||||
|
||||
signals:
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureTaken(uint id, QPixmap p, QRect selection);
|
||||
void captureFailed(uint id);
|
||||
void colorChanged(const QColor& c);
|
||||
void thicknessChanged(const int thickness);
|
||||
|
||||
Reference in New Issue
Block a user