Files
flameshot/src/widgets/capture/capturewidget.h
Haris Gušić 233c765b1f Reduce dependence on D-Bus (#2003)
* Handle captures without sigslots

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Set {app,organization}Name and version consistently

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make 'full' dbus-free

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Move CaptureRequest::exportCapture to Controller

We need to wait until the upload widget (or similar widgets) have
finished before exiting. This must be done using a signal. The problem
is that CaptureRequest can't be guaranteed to survive until the widget
has finished what it's doing.

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Use QApplication with the 'full' subcommand

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Do unto 'screen' as we did to 'full'

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add FlameshotDaemon singleton class

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Support clipboard hosting for both pixmaps and text

* Fix upload handling

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Do not show tray icon if not daemon

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Clean up handling of pin task

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove annoying Qt warning messages

The messages were caused by the color wheel.

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix small bug in Controller::exportCapture

* Fix --raw output

* Make 'gui' dbus-independent

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix accept on select bug

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix compile error on Windows

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make it work on Windows

* Remove obsolete function in main.cpp

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make 'launcher' work without dbus

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* clang-format, sigh

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Enable CLI parsing on MacOS

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make 'config' work without dbus

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Small refactor of capture request handling

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove obsolete DBusUtils

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove unused D-Bus sigslots

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove D-Bus methods openConfig, autostartEnabled and trayIconEnabled

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove D-Bus method requestCapture

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Remove CaptureRequest id mechanism

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix 'launcher' crash

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Handle clipboard notifications properly

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add 'autoCloseIdleDaemon' option

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Document FlameshotDaemon class

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make 'flameshot gui' run in single-application mode

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add `allowmultipleGuiInstances` config option

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix endless loop with multiple GUI instances

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Move upload confirmation dialog where it belongs

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add the new config options to the GUI as well

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix failing build on Windows

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Handle persistence on MacOS

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* fixed notifications on macos

* Fixed display on macos

* Reformat tests/action_options.sh

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix infinite recursion in tests/action_options.sh

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

Co-authored-by: Dearsh Oberoi <59907159+deo002@users.noreply.github.com>
Co-authored-by: Jeremy Borgman <borgman.jeremy@pm.me>
2021-12-08 22:18:39 +01:00

199 lines
5.8 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
// 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 "buttonhandler.h"
#include "capturetoolbutton.h"
#include "capturetoolobjects.h"
#include "src/tools/capturecontext.h"
#include "src/tools/capturetool.h"
#include "src/utils/confighandler.h"
#include "src/widgets/capture/selectionwidget.h"
#include <QPointer>
#include <QUndoStack>
#include <QWidget>
class QLabel;
class QPaintEvent;
class QResizeEvent;
class QMouseEvent;
class QShortcut;
class QNetworkAccessManager;
class QNetworkReply;
class ColorPicker;
class NotifierBox;
class HoverEventFilter;
class UpdateNotificationWidget;
class UtilityPanel;
class SidePanelWidget;
class CaptureWidget : public QWidget
{
Q_OBJECT
public:
explicit CaptureWidget(const CaptureRequest& req,
bool fullScreen = true,
QWidget* parent = nullptr);
~CaptureWidget();
QPixmap pixmap();
void showAppUpdateNotification(const QString& appLatestVersion,
const QString& appLatestUrl);
void setCaptureToolObjects(const CaptureToolObjects& captureToolObjects);
public slots:
bool commitCurrentTool();
void deleteToolWidgetOrClose();
signals:
void colorChanged(const QColor& c);
void toolSizeChanged(int size);
private slots:
void undo();
void redo();
void togglePanel();
void childEnter();
void childLeave();
void deleteCurrentTool();
void setState(CaptureToolButton* b);
void handleToolSignal(CaptureTool::Request r);
void handleButtonLeftClick(CaptureToolButton* b);
void handleButtonRightClick(CaptureToolButton* b);
void setDrawColor(const QColor& c);
void onToolSizeChanged(int size);
void onToolSizeSettled(int size);
void updateActiveLayer(int layer);
void selectAll();
public:
void removeToolObject(int index = -1);
protected:
void paintEvent(QPaintEvent* paintEvent) override;
void mousePressEvent(QMouseEvent* mouseEvent) override;
void mouseMoveEvent(QMouseEvent* mouseEvent) override;
void mouseReleaseEvent(QMouseEvent* mouseEvent) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
void keyPressEvent(QKeyEvent* keyEvent) override;
void keyReleaseEvent(QKeyEvent* keyEvent) override;
void wheelEvent(QWheelEvent* wheelEvent) override;
void resizeEvent(QResizeEvent* resizeEvent) override;
void moveEvent(QMoveEvent* moveEvent) override;
void changeEvent(QEvent* changeEvent) override;
private:
void pushObjectsStateToUndoStack();
void releaseActiveTool();
void uncheckActiveTool();
int selectToolItemAtPos(const QPoint& pos);
void showColorPicker(const QPoint& pos);
bool startDrawObjectTool(const QPoint& pos);
QPointer<CaptureTool> activeToolObject();
void initContext(bool fullscreen, const CaptureRequest& req);
void initPanel();
void initSelection();
void initShortcuts();
void initButtons();
void initHelpMessage();
void updateSizeIndicator();
void updateCursor();
void updateSelectionState();
void updateTool(CaptureTool* tool);
void updateLayersPanel();
void pushToolToStack();
void makeChild(QWidget* w);
QList<QShortcut*> newShortcut(const QKeySequence& key,
QWidget* parent,
const char* slot);
void setToolSize(int size);
QRect extendedSelection() const;
QRect extendedRect(const QRect& r) const;
QRect paddedUpdateRect(const QRect& r) const;
void drawErrorMessage(const QString& msg, QPainter* painter);
void drawInactiveRegion(QPainter* painter);
void drawToolsData();
void drawObjectSelection();
void processPixmapWithTool(QPixmap* pixmap, CaptureTool* tool);
CaptureTool* activeButtonTool() const;
CaptureTool::Type activeButtonToolType() const;
////////////////////////////////////////
// Class members
// Context information
CaptureContext m_context;
// Main ui color
QColor m_uiColor;
// Secondary ui color
QColor m_contrastUiColor;
// Outside selection opacity
int m_opacity;
int m_toolSizeByKeyboard;
// utility flags
bool m_mouseIsClicked;
bool m_newSelection;
bool m_movingSelection;
bool m_captureDone;
bool m_previewEnabled;
bool m_adjustmentButtonPressed;
bool m_configError;
bool m_configErrorResolved;
UpdateNotificationWidget* m_updateNotificationWidget;
quint64 m_lastMouseWheel;
QPointer<CaptureToolButton> m_sizeIndButton;
// Last pressed button
QPointer<CaptureToolButton> m_activeButton;
QPointer<CaptureTool> m_activeTool;
bool m_activeToolIsMoved;
QPointer<QWidget> m_toolWidget;
ButtonHandler* m_buttonHandler;
UtilityPanel* m_panel;
SidePanelWidget* m_sidePanel;
ColorPicker* m_colorPicker;
ConfigHandler m_config;
NotifierBox* m_notifierBox;
HoverEventFilter* m_eventFilter;
SelectionWidget* m_selection;
QString m_helpMessage;
SelectionWidget::SideType m_mouseOverHandle;
QMap<CaptureTool::Type, CaptureTool*> m_tools;
CaptureToolObjects m_captureToolObjects;
CaptureToolObjects m_captureToolObjectsBackup;
QPoint m_mousePressedPos;
QPoint m_activeToolOffsetToMouseOnStart;
QUndoStack m_undoStack;
bool m_existingObjectIsChanged;
// For start moving after more than X offset
QPoint m_startMovePos;
bool m_startMove;
};