forked from flameshot-org/flameshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
crackcat
committed
Aug 28, 2021
1 parent
814bdd2
commit c4d2a56
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors | ||
|
||
#include "inverttool.h" | ||
#include "src/utils/screenshotsaver.h" | ||
#include <QPainter> | ||
#include <QPixmap> | ||
#include <QImage> | ||
#if defined(Q_OS_MACOS) | ||
#include "src/widgets/capture/capturewidget.h" | ||
#include <QApplication> | ||
#include <QWidget> | ||
#endif | ||
|
||
InvertTool::InvertTool(QObject* parent) | ||
: AbstractActionTool(parent) | ||
{} | ||
|
||
bool InvertTool::closeOnButtonPressed() const | ||
{ | ||
return true; | ||
} | ||
|
||
QIcon InvertTool::icon(const QColor& background, bool inEditor) const | ||
{ | ||
Q_UNUSED(inEditor) | ||
return QIcon(iconPath(background) + "invert.svg"); | ||
} | ||
|
||
QString InvertTool::name() const | ||
{ | ||
return tr("Invert"); | ||
} | ||
|
||
ToolType InvertTool::type() const | ||
{ | ||
return ToolType::INVERT; | ||
} | ||
|
||
QString InvertTool::description() const | ||
{ | ||
return tr("Save the inverted capture"); | ||
} | ||
|
||
CaptureTool* InvertTool::copy(QObject* parent) | ||
{ | ||
return new InvertTool(parent); | ||
} | ||
|
||
void InvertTool::pressed(const CaptureContext& context) | ||
{ | ||
#if defined(Q_OS_MACOS) | ||
for (QWidget* widget : qApp->topLevelWidgets()) { | ||
QString className(widget->metaObject()->className()); | ||
if (0 == | ||
className.compare(CaptureWidget::staticMetaObject.className())) { | ||
widget->showNormal(); | ||
widget->hide(); | ||
break; | ||
} | ||
} | ||
#endif | ||
emit requestAction(REQ_CLEAR_SELECTION); | ||
|
||
QPixmap inverted = context.selectedScreenshotArea(); | ||
QImage img = inverted.toImage(); | ||
img.invertPixels(); | ||
inverted.convertFromImage(img); | ||
|
||
if (context.savePath.isEmpty()) { | ||
emit requestAction(REQ_HIDE_GUI); | ||
bool ok = ScreenshotSaver().saveToFilesystemGUI( | ||
inverted); | ||
if (ok) { | ||
emit requestAction(REQ_CAPTURE_DONE_OK); | ||
} | ||
} else { | ||
bool ok = ScreenshotSaver().saveToFilesystem( | ||
inverted, context.savePath); | ||
if (ok) { | ||
emit requestAction(REQ_CAPTURE_DONE_OK); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors | ||
|
||
#pragma once | ||
|
||
#include "src/tools/abstractactiontool.h" | ||
|
||
class InvertTool : public AbstractActionTool | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit InvertTool(QObject* parent = nullptr); | ||
|
||
bool closeOnButtonPressed() const override; | ||
|
||
QIcon icon(const QColor& background, bool inEditor) const override; | ||
QString name() const override; | ||
QString description() const override; | ||
|
||
CaptureTool* copy(QObject* parent = nullptr) override; | ||
|
||
protected: | ||
ToolType type() const override; | ||
|
||
public slots: | ||
void pressed(const CaptureContext& context) override; | ||
}; |