Add external screenshotter support
for wayland!!
This commit is contained in:
parent
70bba2cbbb
commit
87f765245d
@ -8,11 +8,18 @@
|
||||
#include <platformbackend.hpp>
|
||||
#include <settings.hpp>
|
||||
|
||||
void screenshotter::area() {
|
||||
CropEditor *editor = new CropEditor(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
|
||||
void areaScreenshotCallback(QPixmap p) {
|
||||
CropEditor *editor = new CropEditor(p);
|
||||
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); });
|
||||
}
|
||||
|
||||
void screenshotter::area() {
|
||||
if (!settings::settings().value("command/fullscreenCommand", "").toString().isEmpty())
|
||||
utils::externalScreenshot(areaScreenshotCallback);
|
||||
else
|
||||
areaScreenshotCallback(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
|
||||
}
|
||||
|
||||
void screenshotter::fullscreen() {
|
||||
UploaderSingleton::inst().upload(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
|
||||
}
|
||||
@ -31,6 +38,9 @@ void screenshotter::activeDelayed() {
|
||||
|
||||
void screenshotter::active() {
|
||||
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||
UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID()));
|
||||
if (!settings::settings().value("command/activeCommand", "").toString().isEmpty())
|
||||
utils::externalScreenshotActive([](QPixmap p) { UploaderSingleton::inst().upload(p); });
|
||||
else
|
||||
UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID()));
|
||||
#endif
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
|
||||
ui->captureCursor->setText(tr("Capture cursor (disabled: implementation missing)"));
|
||||
#endif
|
||||
ui->fpsMax->setValue(settings::settings().value("recording/framerate", 30).toInt());
|
||||
ui->focusedCapture->setText(settings::settings().value("command/activeCommand", "").toString());
|
||||
ui->fullscreenCapture->setText(settings::settings().value("command/fullscreenCommand", 0).toString());
|
||||
}
|
||||
|
||||
void SettingsDialog::setScheme(QString scheme) {
|
||||
@ -173,6 +175,14 @@ void SettingsDialog::on_cropY_valueChanged(int arg1) {
|
||||
settings::settings().setValue("cropy", arg1);
|
||||
}
|
||||
|
||||
void SettingsDialog::on_focusedCapture_textChanged(QString arg1) {
|
||||
settings::settings().setValue("command/activeCommand", arg1);
|
||||
}
|
||||
|
||||
void SettingsDialog::on_fullscreenCapture_textChanged(QString arg1) {
|
||||
settings::settings().setValue("command/fullscreenCommand", arg1);
|
||||
}
|
||||
|
||||
void SettingsDialog::on_fpsMax_valueChanged(int arg1) {
|
||||
settings::settings().setValue("recording/framerate", arg1);
|
||||
}
|
||||
|
@ -33,13 +33,11 @@ private slots:
|
||||
void newUploader(Uploader *u);
|
||||
void uploaderChanged(QString newName);
|
||||
void on_saveLocation_currentIndexChanged(int index);
|
||||
|
||||
void on_cropX_valueChanged(int arg1);
|
||||
|
||||
void on_cropY_valueChanged(int arg1);
|
||||
|
||||
void on_fpsMax_valueChanged(int arg1);
|
||||
|
||||
void on_fullscreenCapture_textChanged(QString newVal);
|
||||
void on_focusedCapture_textChanged(QString newVal);
|
||||
private:
|
||||
Ui::SettingsDialog *ui;
|
||||
};
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>485</width>
|
||||
<height>655</height>
|
||||
<width>650</width>
|
||||
<height>759</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -17,19 +17,8 @@
|
||||
<item row="1" column="1">
|
||||
<widget class="QListWidget" name="uploaderList"/>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="quickMode">
|
||||
<property name="text">
|
||||
<string>Quick mode (mouse release screenshots)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Delay before taking a screenshot</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="12" column="2">
|
||||
<widget class="QComboBox" name="imageFormatBox"/>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QDoubleSpinBox" name="delay">
|
||||
@ -44,11 +33,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2" rowspan="7">
|
||||
<widget class="QListWidget" name="hotkeys"/>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="quickMode">
|
||||
<property name="text">
|
||||
<string>Quick mode (mouse release screenshots)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="2">
|
||||
<widget class="QComboBox" name="imageFormatBox"/>
|
||||
<item row="15" column="1">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Fullscreen capture command (save to %FILE_PATH or print to stdout)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
@ -64,6 +61,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2" rowspan="7">
|
||||
<widget class="QListWidget" name="hotkeys"/>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Delay before taking a screenshot</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
@ -109,20 +116,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<widget class="QPushButton" name="settingsButton">
|
||||
<property name="text">
|
||||
<string>Open settings directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Destination:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="saveLocation">
|
||||
<item>
|
||||
@ -137,7 +130,21 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1" colspan="2">
|
||||
<item row="8" column="2">
|
||||
<widget class="QPushButton" name="settingsButton">
|
||||
<property name="text">
|
||||
<string>Open settings directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Destination:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="1" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -154,7 +161,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="1" colspan="2">
|
||||
<item row="17" column="1" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Advanced</string>
|
||||
@ -223,6 +230,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="2">
|
||||
<widget class="QLineEdit" name="fullscreenCapture"/>
|
||||
</item>
|
||||
<item row="16" column="1">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Focused capture command (save to %FILE_PATH or print to stdout)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="2">
|
||||
<widget class="QLineEdit" name="focusedCapture"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -5,9 +5,10 @@
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QProcess>
|
||||
#include <QScreen>
|
||||
#include <platformbackend.hpp>
|
||||
|
||||
#include <settings.hpp>
|
||||
|
||||
QColor utils::invertColor(QColor color) {
|
||||
return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue());
|
||||
@ -113,3 +114,66 @@ QPixmap utils::renderText(QString toRender, int padding, QColor background, QCol
|
||||
painter.end();
|
||||
return renderred;
|
||||
}
|
||||
|
||||
QString utils::randomString(int length) {
|
||||
QString str;
|
||||
str.resize(length);
|
||||
for (int s = 0; s < length; s++) str[s] = QChar('A' + char(qrand() % ('Z' - 'A')));
|
||||
return str;
|
||||
}
|
||||
|
||||
void utils::externalScreenshot(std::function<void(QPixmap)> callback) {
|
||||
QString cmd = settings::settings().value("command/fullscreenCommand", "").toString();
|
||||
QStringList args = cmd.split(' ');
|
||||
QString tempPath;
|
||||
for (QString &arg : args) {
|
||||
if (arg == "%FILE_PATH") {
|
||||
if (tempPath.isEmpty()) tempPath = "KShare-Ext-Screenshot." + randomString(5);
|
||||
arg = tempPath;
|
||||
}
|
||||
}
|
||||
QProcess *process = new QProcess;
|
||||
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[callback, process, tempPath](int code, QProcess::ExitStatus) {
|
||||
if (code != 0) {
|
||||
qCritical().noquote() << "Failed to take external screenshot: \n"
|
||||
<< process->readAllStandardError();
|
||||
return;
|
||||
}
|
||||
QPixmap pixmap;
|
||||
if (!tempPath.isEmpty())
|
||||
pixmap.load(tempPath);
|
||||
else
|
||||
pixmap.loadFromData(process->readAllStandardOutput());
|
||||
callback(pixmap);
|
||||
});
|
||||
process->start(args.takeFirst(), args);
|
||||
}
|
||||
|
||||
void utils::externalScreenshotActive(std::function<void(QPixmap)> callback) {
|
||||
QString cmd = settings::settings().value("command/activeCommand", "").toString();
|
||||
QStringList args = cmd.split(' ');
|
||||
QString tempPath;
|
||||
for (QString &arg : args) {
|
||||
if (arg == "%FILE_PATH") {
|
||||
if (tempPath.isEmpty()) tempPath = "KShare-Ext-Screenshot." + randomString(5);
|
||||
arg = tempPath;
|
||||
}
|
||||
}
|
||||
QProcess *process = new QProcess;
|
||||
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[callback, process, tempPath](int code, QProcess::ExitStatus) {
|
||||
if (code != 0) {
|
||||
qCritical().noquote() << "Failed to take external screenshot: \n"
|
||||
<< process->readAllStandardError();
|
||||
return;
|
||||
}
|
||||
QPixmap pixmap;
|
||||
if (!tempPath.isEmpty())
|
||||
pixmap.load(tempPath);
|
||||
else
|
||||
pixmap.loadFromData(process->readAllStandardOutput());
|
||||
callback(pixmap);
|
||||
});
|
||||
process->start(args.takeFirst(), args);
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
#include <QScreen>
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
namespace utils {
|
||||
QColor invertColor(QColor color);
|
||||
@ -16,6 +17,9 @@ namespace utils {
|
||||
QPoint smallestScreenCoordinate();
|
||||
QPixmap
|
||||
renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont());
|
||||
void externalScreenshot(std::function<void(QPixmap)> callback);
|
||||
void externalScreenshotActive(std::function<void(QPixmap)> callback);
|
||||
QString randomString(int length);
|
||||
}
|
||||
|
||||
#endif // UTILS_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user