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