Add basic launcher panel

This commit is contained in:
lupoDharkael
2019-04-21 20:34:57 +02:00
parent cbb4727786
commit d4715750df
12 changed files with 238 additions and 14 deletions

View File

@@ -33,6 +33,15 @@
<arg name="id" type="i" direction="in"/>
</method>
<!--
openLauncher:
Opens the capture launcher.
-->
<method name="openLauncher">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<!--
captureScreen:
@number: number of the screen to be captured.

View File

@@ -7,13 +7,16 @@ _flameshot() {
prev="${COMP_WORDS[COMP_CWORD-1]}"
cur="${COMP_WORDS[COMP_CWORD]}"
cmd="gui full config screen"
cmd="gui full config launcher screen"
screen_opts="--number --path --delay --raw -p -d -r -n"
gui_opts="--path --delay --raw -p -d -r"
full_opts="--path --delay --clipboard --raw -p -d -c -r"
config_opts="--contrastcolor --filename --maincolor --showhelp --trayicon -k -f -m -s -t"
config_opts="--contrastcolor --filename --maincolor --showhelp --trayicon --autostart -k -f -m -s -t -a"
case "${prev}" in
launcher)
return 0
;;
screen)
COMPREPLY=( $(compgen -W "$screen_opts --help -h" -- ${cur}) )
return 0

View File

@@ -139,6 +139,7 @@ SOURCES += src/main.cpp \
src/widgets/capture/hovereventfilter.cpp \
src/widgets/capture/selectionwidget.cpp \
src/tools/pin/pinwidget.cpp \
src/widgets/capturelauncher.cpp \
src/tools/text/texttool.cpp \
src/tools/text/textwidget.cpp \
src/core/capturerequest.cpp \
@@ -211,6 +212,7 @@ HEADERS += src/widgets/capture/buttonhandler.h \
src/widgets/capture/hovereventfilter.h \
src/widgets/capture/selectionwidget.h \
src/tools/pin/pinwidget.h \
src/widgets/capturelauncher.h \
src/tools/text/texttool.h \
src/tools/text/textwidget.h \
src/core/capturerequest.h \

View File

@@ -21,6 +21,7 @@
#include "src/widgets/infowindow.h"
#include "src/config/configwindow.h"
#include "src/widgets/capture/capturebutton.h"
#include "src/widgets/capturelauncher.h"
#include "src/utils/systemnotification.h"
#include "src/utils/screengrabber.h"
#include <QFile>
@@ -161,6 +162,11 @@ void Controller::openInfoWindow() {
}
}
void Controller::openLauncherWindow() {
CaptureLauncher *w = new CaptureLauncher();
w->show();
}
void Controller::enableTrayIcon() {
if (m_trayIcon) {
return;
@@ -171,6 +177,9 @@ void Controller::enableTrayIcon() {
// Wait 400 ms to hide the QMenu
doLater(400, this, [this](){ this->startVisualCapture(); });
});
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
connect(launcherAction, &QAction::triggered, this,
&Controller::openLauncherWindow);
QAction *configAction = new QAction(tr("&Configuration"), this);
connect(configAction, &QAction::triggered, this,
&Controller::openConfigWindow);
@@ -183,6 +192,8 @@ void Controller::enableTrayIcon() {
QMenu *trayIconMenu = new QMenu();
trayIconMenu->addAction(captureAction);
trayIconMenu->addAction(launcherAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(configAction);
trayIconMenu->addAction(infoAction);
trayIconMenu->addSeparator();

View File

@@ -52,6 +52,7 @@ public slots:
void openConfigWindow();
void openInfoWindow();
void openLauncherWindow();
void enableTrayIcon();
void disableTrayIcon();
void sendTrayNotification(const QString &text,

View File

@@ -59,6 +59,10 @@ void FlameshotDBusAdapter::fullScreen(
Controller::getInstance()->requestCapture(req);
}
void FlameshotDBusAdapter::openLauncher() {
Controller::getInstance()->openLauncherWindow();
}
void FlameshotDBusAdapter::captureScreen(int number, QString path,
bool toClipboard, int delay, uint id)
{

View File

@@ -36,6 +36,7 @@ public slots:
Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id);
Q_NOREPLY void captureScreen(int number, QString path, bool toClipboard, int delay, uint id);
Q_NOREPLY void openLauncher();
Q_NOREPLY void openConfig();
Q_NOREPLY void trayIconEnabled(bool enabled);
Q_NOREPLY void autostartEnabled(bool enabled);

View File

@@ -100,6 +100,7 @@ int main(int argc, char *argv[]) {
parser.setGeneralErrorMessage(QStringLiteral("See 'flameshot --help'."));
// Arguments
CommandArgument fullArgument(QStringLiteral("full"), QStringLiteral("Capture the entire desktop."));
CommandArgument launcherArgument(QStringLiteral("launcher"), QStringLiteral("Open the capture launcher."));
CommandArgument guiArgument(QStringLiteral("gui"), QStringLiteral("Start a manual capture in GUI mode."));
CommandArgument configArgument(QStringLiteral("config"), QStringLiteral("Configure flameshot."));
CommandArgument screenArgument(QStringLiteral("screen"), QStringLiteral("Capture a single screen."));
@@ -195,6 +196,7 @@ int main(int argc, char *argv[]) {
parser.AddArgument(guiArgument);
parser.AddArgument(screenArgument);
parser.AddArgument(fullArgument);
parser.AddArgument(launcherArgument);
parser.AddArgument(configArgument);
auto helpOption = parser.addHelpOption();
auto versionOption = parser.addVersionOption();
@@ -216,6 +218,16 @@ int main(int argc, char *argv[]) {
//--------------
if (parser.isSet(helpOption) || parser.isSet(versionOption)) {
}
else if (parser.isSet(launcherArgument)) { // LAUNCHER
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
QStringLiteral("/"), QLatin1String(""), QStringLiteral("openLauncher"));
QDBusConnection sessionBus = QDBusConnection::sessionBus();
if (!sessionBus.isConnected()) {
SystemNotification().sendMessage(
QObject::tr("Unable to connect via DBus"));
}
sessionBus.call(m);
}
else if (parser.isSet(guiArgument)) { // GUI
QString pathValue = parser.value(pathOption);
int delay = parser.value(delayOption).toInt();

View File

@@ -0,0 +1,142 @@
// 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 "capturelauncher.h"
#include "src/core/controller.h"
#include "src/widgets/imagelabel.h"
#include "src/widgets/notificationwidget.h"
#include "src/utils/screengrabber.h"
#include <QCheckBox>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QSpinBox>
#include <QLabel>
#include <QComboBox>
#include <QMimeData>
#include <QDrag>
#include <QFormLayout>
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSWidget.cpp
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSMainWindow.cpp
CaptureLauncher::CaptureLauncher(QWidget *parent) :
QWidget(parent), m_id(0)
{
setAttribute(Qt::WA_DeleteOnClose);
connect(Controller::getInstance(), &Controller::captureTaken,
this, &CaptureLauncher::captureTaken);
connect(Controller::getInstance(), &Controller::captureFailed,
this, &CaptureLauncher::captureFailed);
m_imageLabel = new ImageLabel(this);
bool ok;
m_imageLabel->setScreenshot(ScreenGrabber().grabEntireDesktop(ok));
if (!ok) {
}
m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(m_imageLabel, &ImageLabel::dragInitiated,
this, &CaptureLauncher::startDrag);
QGridLayout *layout = new QGridLayout(this);
layout->addWidget(m_imageLabel, 0, 0);
m_CaptureModeLabel = new QLabel(tr("<b>Capture Mode</b>"));
m_captureType = new QComboBox();
m_captureType->setMinimumWidth(240);
// TODO remember number
m_captureType->insertItem(1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
m_captureType->insertItem(2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
//m_captureType->insertItem(3, tr("Single Screen"), CaptureRequest::SCREEN_MODE);
m_delaySpinBox = new QSpinBox();
m_delaySpinBox->setSingleStep(1.0);
m_delaySpinBox->setMinimum(0.0);
m_delaySpinBox->setMaximum(999.0);
m_delaySpinBox->setSpecialValueText(tr("No Delay"));
m_delaySpinBox->setMinimumWidth(160);
// with QT 5.7 qOverload<int>(&QSpinBox::valueChanged),
connect(m_delaySpinBox,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, [this](int val)
{
QString sufix = val == 1 ?tr(" second") : tr(" seconds");
this->m_delaySpinBox->setSuffix(sufix);
});
m_launchButton = new QPushButton(tr("Take new screenshot"));
m_launchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(m_launchButton, &QPushButton::pressed,
this, &CaptureLauncher::startCapture);
m_launchButton->setFocus();
QFormLayout *captureModeForm = new QFormLayout;
captureModeForm->addRow(tr("Area:"), m_captureType);
captureModeForm->addRow(tr("Delay:"), m_delaySpinBox);
captureModeForm->setContentsMargins(24, 0, 0, 0);
m_mainLayout = new QVBoxLayout();
m_mainLayout->addStretch(1);
m_mainLayout->addWidget(m_CaptureModeLabel);
m_mainLayout->addLayout(captureModeForm);
m_mainLayout->addStretch(10);
m_mainLayout->addWidget(m_launchButton, 1 , Qt::AlignCenter);
m_mainLayout->setContentsMargins(10, 0, 0, 10);
layout->addLayout(m_mainLayout, 0 ,1);
layout->setColumnMinimumWidth(0, 320);
layout->setColumnMinimumWidth(1, 320);
}
// HACK: https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
void CaptureLauncher::startCapture() {
hide();
auto mode = static_cast<CaptureRequest::CaptureMode>(
m_captureType->currentData().toInt());
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
m_id = req.id();
Controller::getInstance()->requestCapture(req);
}
void CaptureLauncher::startDrag() {
QDrag *dragHandler = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(m_imageLabel->pixmap());
dragHandler->setMimeData(mimeData);
dragHandler->setPixmap(m_imageLabel->pixmap()
->scaled(256, 256, Qt::KeepAspectRatioByExpanding,
Qt::SmoothTransformation));
dragHandler->exec();
}
void CaptureLauncher::captureTaken(uint id, QPixmap p) {
if (id == m_id) {
m_id = 0;
m_imageLabel->setScreenshot(p);
show();
}
}
void CaptureLauncher::captureFailed(uint id) {
if (id == m_id) {
m_id = 0;
show();
}
}

View File

@@ -0,0 +1,51 @@
// 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/>.
#pragma once
#include <QWidget>
class QCheckBox;
class QPushButton;
class QVBoxLayout;
class QComboBox;
class QSpinBox;
class QLabel;
class ImageLabel;
class CaptureLauncher : public QWidget
{
Q_OBJECT
public:
explicit CaptureLauncher(QWidget *parent = nullptr);
private slots:
void startCapture();
void startDrag();
void captureTaken(uint id, QPixmap p);
void captureFailed(uint id);
private:
QSpinBox *m_delaySpinBox;
QComboBox *m_captureType;
QVBoxLayout *m_mainLayout;
QPushButton *m_launchButton;
QLabel *m_CaptureModeLabel;
ImageLabel *m_imageLabel;
uint m_id;
};

View File

@@ -15,12 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <info@ckaiser.com.ar>
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <lucag@student.ethz.ch>
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
#include "utilitypanel.h"
#include <QPropertyAnimation>
#include <QVBoxLayout>

View File

@@ -15,12 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <info@ckaiser.com.ar>
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <lucag@student.ethz.ch>
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
#pragma once
#include <QWidget>