Stop special treatment of some buttons

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
Haris Gušić
2021-10-06 14:53:50 +02:00
parent 85352ff72f
commit 60d2d8c33d
10 changed files with 23 additions and 85 deletions

View File

@@ -62,7 +62,6 @@ void AcceptTool::pressed(const CaptureContext&)
}
}
#endif
emit requestAction(REQ_CLEAR_SELECTION);
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_HIDE_GUI);
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -3,6 +3,7 @@
#pragma once
#include "capturerequest.h"
#include <QPainter>
#include <QPixmap>
#include <QPoint>

View File

@@ -64,8 +64,6 @@ public:
REQ_REDO_MODIFICATION,
// Open the color picker under the mouse.
REQ_SHOW_COLOR_PICKER,
// Notify to redraw screenshot with tools without object selection.
REQ_CLEAR_SELECTION,
// Notify is the screenshot has been saved.
REQ_CAPTURE_DONE_OK,
// Instance this->widget()'s widget inside the editor under the mouse.

View File

@@ -41,7 +41,7 @@ CaptureTool* CopyTool::copy(QObject* parent)
void CopyTool::pressed(const CaptureContext& context)
{
emit requestAction(REQ_CLEAR_SELECTION);
emit requestAction(REQ_CAPTURE_DONE_OK);
ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -46,8 +46,8 @@ CaptureTool* ImgurUploaderTool::copy(QObject* parent)
void ImgurUploaderTool::pressed(const CaptureContext& context)
{
emit requestAction(REQ_CLEAR_SELECTION);
capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -48,4 +48,5 @@ void AppLauncher::pressed(const CaptureContext& context)
capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -72,10 +72,10 @@ CaptureTool* PinTool::copy(QObject* parent)
void PinTool::pressed(const CaptureContext& context)
{
emit requestAction(REQ_CLEAR_SELECTION);
emit requestAction(REQ_CAPTURE_DONE_OK);
m_geometry = context.selection;
m_geometry.setTopLeft(m_geometry.topLeft() + context.widgetOffset);
m_pixmap = context.selectedScreenshotArea();
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -3,6 +3,7 @@
#include "savetool.h"
#include "src/utils/screenshotsaver.h"
#include <QApplication> // TODO rm
#include <QPainter>
#if defined(Q_OS_MACOS)
#include "src/widgets/capture/capturewidget.h"
@@ -57,9 +58,9 @@ void SaveTool::pressed(const CaptureContext& context)
}
}
#endif
emit requestAction(REQ_CLEAR_SELECTION);
if (context.savePath.isEmpty()) {
emit requestAction(REQ_HIDE_GUI);
qApp->processEvents();
bool ok = ScreenshotSaver().saveToFilesystemGUI(
context.selectedScreenshotArea());
if (ok) {
@@ -72,4 +73,5 @@ void SaveTool::pressed(const CaptureContext& context)
emit requestAction(REQ_CAPTURE_DONE_OK);
}
}
emit requestAction(REQ_CLOSE_GUI);
}

View File

@@ -10,6 +10,7 @@
// <http://www.gnu.org/licenses/old-licenses/library.txt>
#include "capturewidget.h"
#include "copytool.h"
#include "src/core/controller.h"
#include "src/core/qguiappcurrentscreen.h"
#include "src/tools/toolfactory.h"
@@ -63,6 +64,7 @@ CaptureWidget::CaptureWidget(uint id,
, m_toolWidget(nullptr)
, m_colorPicker(nullptr)
, m_id(id)
, m_request(&*Controller::getInstance()->requests().find(id))
, m_lastMouseWheel(0)
, m_updateNotificationWidget(nullptr)
, m_activeToolIsMoved(false)
@@ -243,8 +245,8 @@ void CaptureWidget::initButtons()
{
auto allButtonTypes = CaptureToolButton::getIterableButtonTypes();
auto visibleButtonTypes = m_config.buttons();
auto& request = *Controller::getInstance()->requests().find(m_id);
if (request.tasks() == CaptureRequest::NO_TASK) {
if (m_request->tasks() == CaptureRequest::NO_TASK) {
allButtonTypes.removeOne(CaptureTool::TYPE_ACCEPT);
visibleButtonTypes.removeOne(CaptureTool::TYPE_ACCEPT);
}
QVector<CaptureToolButton*> vectorButtons;
@@ -263,10 +265,6 @@ void CaptureWidget::initButtons()
makeChild(b);
switch (t) {
case CaptureTool::TYPE_EXIT:
case CaptureTool::TYPE_SAVE:
case CaptureTool::TYPE_COPY:
case CaptureTool::TYPE_ACCEPT:
case CaptureTool::TYPE_UNDO:
case CaptureTool::TYPE_IMAGEUPLOADER:
case CaptureTool::TYPE_REDO:
@@ -314,6 +312,7 @@ QPixmap CaptureWidget::pixmap()
bool CaptureWidget::commitCurrentTool()
{
if (m_activeTool) {
processPixmapWithTool(&m_context.screenshot, m_activeTool);
if (m_activeTool->isValid() && !m_activeTool->editMode() &&
m_toolWidget) {
pushToolToStack();
@@ -566,7 +565,13 @@ void CaptureWidget::mouseDoubleClickEvent(QMouseEvent* event)
m_panel->setToolWidget(m_activeTool->configurationWidget());
}
} else if (m_selection->geometry().contains(event->pos())) {
copyScreenshot();
CopyTool copyTool;
connect(&copyTool,
&CopyTool::requestAction,
this,
&CaptureWidget::handleToolSignal);
copyTool.pressed(m_context);
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
}
}
@@ -950,6 +955,7 @@ void CaptureWidget::setState(CaptureToolButton* b)
return;
}
commitCurrentTool();
if (m_toolWidget && m_activeTool) {
if (m_activeTool->isValid()) {
pushToolToStack();
@@ -966,11 +972,6 @@ void CaptureWidget::setState(CaptureToolButton* b)
m_activeTool = backup;
}
// Only close activated from button
if (b->tool()->closeOnButtonPressed()) {
close();
}
if (b->tool()->isSelectable()) {
if (m_activeButton != b) {
QWidget* confW = b->tool()->configurationWidget();
@@ -1022,12 +1023,6 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r)
case CaptureTool::REQ_SHOW_COLOR_PICKER:
// TODO
break;
case CaptureTool::REQ_CLEAR_SELECTION:
if (m_panel->activeLayerIndex() >= 0) {
m_panel->setActiveLayer(-1);
drawToolsData();
}
break;
case CaptureTool::REQ_CAPTURE_DONE_OK:
m_captureDone = true;
break;
@@ -1173,24 +1168,6 @@ void CaptureWidget::setDrawThickness(int t)
void CaptureWidget::initShortcuts()
{
new QShortcut(
QKeySequence(ConfigHandler().shortcut("TYPE_EXIT")), this, SLOT(close()));
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_SAVE")),
this,
SLOT(saveScreenshot()));
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_COPY")),
this,
SLOT(copyScreenshot()));
auto& request = *Controller::getInstance()->requests().find(m_id);
if (request.tasks() != CaptureRequest::NO_TASK) {
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_ACCEPT")),
this,
SLOT(acceptCapture()));
}
new QShortcut(
QKeySequence(ConfigHandler().shortcut("TYPE_UNDO")), this, SLOT(undo()));
@@ -1438,43 +1415,6 @@ void CaptureWidget::childLeave()
updateToolMousePreview(activeButtonTool());
}
void CaptureWidget::copyScreenshot()
{
m_captureDone = true;
if (m_activeTool != nullptr) {
processPixmapWithTool(&m_context.screenshot, m_activeTool);
}
auto req = Controller::getInstance()->requests().find(m_id);
req->addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
close();
}
void CaptureWidget::saveScreenshot()
{
#if defined(Q_OS_MACOS)
showNormal();
#endif
m_captureDone = true;
if (m_activeTool != nullptr) {
processPixmapWithTool(&m_context.screenshot, m_activeTool);
}
hide();
if (m_context.savePath.isEmpty()) {
ScreenshotSaver(m_id).saveToFilesystemGUI(pixmap());
} else {
ScreenshotSaver(m_id).saveToFilesystem(pixmap(), m_context.savePath);
}
close();
}
void CaptureWidget::acceptCapture()
{
m_captureDone = true;
close();
}
void CaptureWidget::setCaptureToolObjects(
const CaptureToolObjects& captureToolObjects)
{

View File

@@ -62,10 +62,6 @@ signals:
void thicknessChanged(int thickness);
private slots:
// TODO replace with tools
void copyScreenshot();
void saveScreenshot();
void acceptCapture();
void undo();
void redo();
void togglePanel();
@@ -178,6 +174,7 @@ private:
SelectionWidget::SideType m_mouseOverHandle;
uint m_id;
CaptureRequest* m_request;
CaptureToolObjects m_captureToolObjects;
CaptureToolObjects m_captureToolObjectsBackup;