Skip to content

Commit d471575

Browse files
committed
Add basic launcher panel
1 parent cbb4727 commit d471575

12 files changed

+238
-14
lines changed

dbus/org.dharkael.Flameshot.xml

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
<arg name="id" type="i" direction="in"/>
3434
</method>
3535

36+
<!--
37+
openLauncher:
38+
39+
Opens the capture launcher.
40+
-->
41+
<method name="openLauncher">
42+
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
43+
</method>
44+
3645
<!--
3746
captureScreen:
3847
@number: number of the screen to be captured.

docs/bash-completion/flameshot

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ _flameshot() {
77

88
prev="${COMP_WORDS[COMP_CWORD-1]}"
99
cur="${COMP_WORDS[COMP_CWORD]}"
10-
cmd="gui full config screen"
10+
cmd="gui full config launcher screen"
1111
screen_opts="--number --path --delay --raw -p -d -r -n"
1212
gui_opts="--path --delay --raw -p -d -r"
1313
full_opts="--path --delay --clipboard --raw -p -d -c -r"
14-
config_opts="--contrastcolor --filename --maincolor --showhelp --trayicon -k -f -m -s -t"
14+
config_opts="--contrastcolor --filename --maincolor --showhelp --trayicon --autostart -k -f -m -s -t -a"
1515

1616
case "${prev}" in
17+
launcher)
18+
return 0
19+
;;
1720
screen)
1821
COMPREPLY=( $(compgen -W "$screen_opts --help -h" -- ${cur}) )
1922
return 0

flameshot.pro

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ SOURCES += src/main.cpp \
139139
src/widgets/capture/hovereventfilter.cpp \
140140
src/widgets/capture/selectionwidget.cpp \
141141
src/tools/pin/pinwidget.cpp \
142+
src/widgets/capturelauncher.cpp \
142143
src/tools/text/texttool.cpp \
143144
src/tools/text/textwidget.cpp \
144145
src/core/capturerequest.cpp \
@@ -211,6 +212,7 @@ HEADERS += src/widgets/capture/buttonhandler.h \
211212
src/widgets/capture/hovereventfilter.h \
212213
src/widgets/capture/selectionwidget.h \
213214
src/tools/pin/pinwidget.h \
215+
src/widgets/capturelauncher.h \
214216
src/tools/text/texttool.h \
215217
src/tools/text/textwidget.h \
216218
src/core/capturerequest.h \

src/core/controller.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "src/widgets/infowindow.h"
2222
#include "src/config/configwindow.h"
2323
#include "src/widgets/capture/capturebutton.h"
24+
#include "src/widgets/capturelauncher.h"
2425
#include "src/utils/systemnotification.h"
2526
#include "src/utils/screengrabber.h"
2627
#include <QFile>
@@ -161,6 +162,11 @@ void Controller::openInfoWindow() {
161162
}
162163
}
163164

165+
void Controller::openLauncherWindow() {
166+
CaptureLauncher *w = new CaptureLauncher();
167+
w->show();
168+
}
169+
164170
void Controller::enableTrayIcon() {
165171
if (m_trayIcon) {
166172
return;
@@ -171,6 +177,9 @@ void Controller::enableTrayIcon() {
171177
// Wait 400 ms to hide the QMenu
172178
doLater(400, this, [this](){ this->startVisualCapture(); });
173179
});
180+
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
181+
connect(launcherAction, &QAction::triggered, this,
182+
&Controller::openLauncherWindow);
174183
QAction *configAction = new QAction(tr("&Configuration"), this);
175184
connect(configAction, &QAction::triggered, this,
176185
&Controller::openConfigWindow);
@@ -183,6 +192,8 @@ void Controller::enableTrayIcon() {
183192

184193
QMenu *trayIconMenu = new QMenu();
185194
trayIconMenu->addAction(captureAction);
195+
trayIconMenu->addAction(launcherAction);
196+
trayIconMenu->addSeparator();
186197
trayIconMenu->addAction(configAction);
187198
trayIconMenu->addAction(infoAction);
188199
trayIconMenu->addSeparator();

src/core/controller.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public slots:
5252

5353
void openConfigWindow();
5454
void openInfoWindow();
55+
void openLauncherWindow();
5556
void enableTrayIcon();
5657
void disableTrayIcon();
5758
void sendTrayNotification(const QString &text,

src/core/flameshotdbusadapter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ void FlameshotDBusAdapter::fullScreen(
5959
Controller::getInstance()->requestCapture(req);
6060
}
6161

62+
void FlameshotDBusAdapter::openLauncher() {
63+
Controller::getInstance()->openLauncherWindow();
64+
}
65+
6266
void FlameshotDBusAdapter::captureScreen(int number, QString path,
6367
bool toClipboard, int delay, uint id)
6468
{

src/core/flameshotdbusadapter.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public slots:
3636
Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
3737
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id);
3838
Q_NOREPLY void captureScreen(int number, QString path, bool toClipboard, int delay, uint id);
39+
Q_NOREPLY void openLauncher();
3940
Q_NOREPLY void openConfig();
4041
Q_NOREPLY void trayIconEnabled(bool enabled);
4142
Q_NOREPLY void autostartEnabled(bool enabled);

src/main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ int main(int argc, char *argv[]) {
100100
parser.setGeneralErrorMessage(QStringLiteral("See 'flameshot --help'."));
101101
// Arguments
102102
CommandArgument fullArgument(QStringLiteral("full"), QStringLiteral("Capture the entire desktop."));
103+
CommandArgument launcherArgument(QStringLiteral("launcher"), QStringLiteral("Open the capture launcher."));
103104
CommandArgument guiArgument(QStringLiteral("gui"), QStringLiteral("Start a manual capture in GUI mode."));
104105
CommandArgument configArgument(QStringLiteral("config"), QStringLiteral("Configure flameshot."));
105106
CommandArgument screenArgument(QStringLiteral("screen"), QStringLiteral("Capture a single screen."));
@@ -195,6 +196,7 @@ int main(int argc, char *argv[]) {
195196
parser.AddArgument(guiArgument);
196197
parser.AddArgument(screenArgument);
197198
parser.AddArgument(fullArgument);
199+
parser.AddArgument(launcherArgument);
198200
parser.AddArgument(configArgument);
199201
auto helpOption = parser.addHelpOption();
200202
auto versionOption = parser.addVersionOption();
@@ -216,6 +218,16 @@ int main(int argc, char *argv[]) {
216218
//--------------
217219
if (parser.isSet(helpOption) || parser.isSet(versionOption)) {
218220
}
221+
else if (parser.isSet(launcherArgument)) { // LAUNCHER
222+
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
223+
QStringLiteral("/"), QLatin1String(""), QStringLiteral("openLauncher"));
224+
QDBusConnection sessionBus = QDBusConnection::sessionBus();
225+
if (!sessionBus.isConnected()) {
226+
SystemNotification().sendMessage(
227+
QObject::tr("Unable to connect via DBus"));
228+
}
229+
sessionBus.call(m);
230+
}
219231
else if (parser.isSet(guiArgument)) { // GUI
220232
QString pathValue = parser.value(pathOption);
221233
int delay = parser.value(delayOption).toInt();

src/widgets/capturelauncher.cpp

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
2+
//
3+
// This file is part of Flameshot.
4+
//
5+
// Flameshot is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Flameshot is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#include "capturelauncher.h"
19+
#include "src/core/controller.h"
20+
#include "src/widgets/imagelabel.h"
21+
#include "src/widgets/notificationwidget.h"
22+
#include "src/utils/screengrabber.h"
23+
#include <QCheckBox>
24+
#include <QPushButton>
25+
#include <QGridLayout>
26+
#include <QVBoxLayout>
27+
#include <QSpinBox>
28+
#include <QLabel>
29+
#include <QComboBox>
30+
#include <QMimeData>
31+
#include <QDrag>
32+
#include <QFormLayout>
33+
34+
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSWidget.cpp
35+
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSMainWindow.cpp
36+
37+
CaptureLauncher::CaptureLauncher(QWidget *parent) :
38+
QWidget(parent), m_id(0)
39+
{
40+
setAttribute(Qt::WA_DeleteOnClose);
41+
connect(Controller::getInstance(), &Controller::captureTaken,
42+
this, &CaptureLauncher::captureTaken);
43+
connect(Controller::getInstance(), &Controller::captureFailed,
44+
this, &CaptureLauncher::captureFailed);
45+
46+
m_imageLabel = new ImageLabel(this);
47+
bool ok;
48+
m_imageLabel->setScreenshot(ScreenGrabber().grabEntireDesktop(ok));
49+
if (!ok) {
50+
51+
}
52+
m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
53+
connect(m_imageLabel, &ImageLabel::dragInitiated,
54+
this, &CaptureLauncher::startDrag);
55+
56+
QGridLayout *layout = new QGridLayout(this);
57+
layout->addWidget(m_imageLabel, 0, 0);
58+
59+
m_CaptureModeLabel = new QLabel(tr("<b>Capture Mode</b>"));
60+
61+
m_captureType = new QComboBox();
62+
m_captureType->setMinimumWidth(240);
63+
// TODO remember number
64+
m_captureType->insertItem(1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
65+
m_captureType->insertItem(2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
66+
//m_captureType->insertItem(3, tr("Single Screen"), CaptureRequest::SCREEN_MODE);
67+
68+
m_delaySpinBox = new QSpinBox();
69+
m_delaySpinBox->setSingleStep(1.0);
70+
m_delaySpinBox->setMinimum(0.0);
71+
m_delaySpinBox->setMaximum(999.0);
72+
m_delaySpinBox->setSpecialValueText(tr("No Delay"));
73+
m_delaySpinBox->setMinimumWidth(160);
74+
// with QT 5.7 qOverload<int>(&QSpinBox::valueChanged),
75+
connect(m_delaySpinBox,
76+
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
77+
this, [this](int val)
78+
{
79+
QString sufix = val == 1 ?tr(" second") : tr(" seconds");
80+
this->m_delaySpinBox->setSuffix(sufix);
81+
});
82+
83+
m_launchButton = new QPushButton(tr("Take new screenshot"));
84+
m_launchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
85+
connect(m_launchButton, &QPushButton::pressed,
86+
this, &CaptureLauncher::startCapture);
87+
m_launchButton->setFocus();
88+
89+
QFormLayout *captureModeForm = new QFormLayout;
90+
captureModeForm->addRow(tr("Area:"), m_captureType);
91+
captureModeForm->addRow(tr("Delay:"), m_delaySpinBox);
92+
captureModeForm->setContentsMargins(24, 0, 0, 0);
93+
94+
m_mainLayout = new QVBoxLayout();
95+
m_mainLayout->addStretch(1);
96+
m_mainLayout->addWidget(m_CaptureModeLabel);
97+
m_mainLayout->addLayout(captureModeForm);
98+
m_mainLayout->addStretch(10);
99+
m_mainLayout->addWidget(m_launchButton, 1 , Qt::AlignCenter);
100+
m_mainLayout->setContentsMargins(10, 0, 0, 10);
101+
layout->addLayout(m_mainLayout, 0 ,1);
102+
layout->setColumnMinimumWidth(0, 320);
103+
layout->setColumnMinimumWidth(1, 320);
104+
105+
}
106+
107+
// HACK: https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
108+
void CaptureLauncher::startCapture() {
109+
hide();
110+
auto mode = static_cast<CaptureRequest::CaptureMode>(
111+
m_captureType->currentData().toInt());
112+
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
113+
m_id = req.id();
114+
Controller::getInstance()->requestCapture(req);
115+
}
116+
117+
void CaptureLauncher::startDrag() {
118+
QDrag *dragHandler = new QDrag(this);
119+
QMimeData *mimeData = new QMimeData;
120+
mimeData->setImageData(m_imageLabel->pixmap());
121+
dragHandler->setMimeData(mimeData);
122+
123+
dragHandler->setPixmap(m_imageLabel->pixmap()
124+
->scaled(256, 256, Qt::KeepAspectRatioByExpanding,
125+
Qt::SmoothTransformation));
126+
dragHandler->exec();
127+
}
128+
129+
void CaptureLauncher::captureTaken(uint id, QPixmap p) {
130+
if (id == m_id) {
131+
m_id = 0;
132+
m_imageLabel->setScreenshot(p);
133+
show();
134+
}
135+
}
136+
137+
void CaptureLauncher::captureFailed(uint id) {
138+
if (id == m_id) {
139+
m_id = 0;
140+
show();
141+
}
142+
}

src/widgets/capturelauncher.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
2+
//
3+
// This file is part of Flameshot.
4+
//
5+
// Flameshot is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Flameshot is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#pragma once
19+
20+
#include <QWidget>
21+
22+
class QCheckBox;
23+
class QPushButton;
24+
class QVBoxLayout;
25+
class QComboBox;
26+
class QSpinBox;
27+
class QLabel;
28+
class ImageLabel;
29+
30+
class CaptureLauncher : public QWidget
31+
{
32+
Q_OBJECT
33+
public:
34+
explicit CaptureLauncher(QWidget *parent = nullptr);
35+
36+
private slots:
37+
void startCapture();
38+
void startDrag();
39+
void captureTaken(uint id, QPixmap p);
40+
void captureFailed(uint id);
41+
42+
private:
43+
44+
QSpinBox *m_delaySpinBox;
45+
QComboBox *m_captureType;
46+
QVBoxLayout *m_mainLayout;
47+
QPushButton *m_launchButton;
48+
QLabel *m_CaptureModeLabel;
49+
ImageLabel *m_imageLabel;
50+
uint m_id;
51+
};

src/widgets/panel/utilitypanel.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
1717

18-
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <[email protected]>
19-
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
20-
21-
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <[email protected]>
22-
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
23-
2418
#include "utilitypanel.h"
2519
#include <QPropertyAnimation>
2620
#include <QVBoxLayout>

src/widgets/panel/utilitypanel.h

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
1717

18-
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <[email protected]>
19-
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
20-
21-
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <[email protected]>
22-
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
23-
2418
#pragma once
2519

2620
#include <QWidget>

0 commit comments

Comments
 (0)