mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-03-26 09:59:52 +00:00
resolving merge conflicts
This commit is contained in:
@@ -36,9 +36,6 @@ public:
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
virtual ToolType nameID() const = 0;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
|
||||
@@ -46,9 +46,16 @@ bool AbstractPathTool::showMousePreview() const
|
||||
void AbstractPathTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea + QMargins(val, val, val, val);
|
||||
p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
|
||||
// capture of different displays with different DPI, so let it be MacOS
|
||||
// specific only.
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup);
|
||||
#else
|
||||
p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AbstractPathTool::drawEnd(const QPoint& p)
|
||||
@@ -73,9 +80,30 @@ void AbstractPathTool::thicknessChanged(const int th)
|
||||
|
||||
void AbstractPathTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap));
|
||||
}
|
||||
|
||||
QRect AbstractPathTool::backupRect(const QPixmap& pixmap) const
|
||||
{
|
||||
const QRect& limits = pixmap.rect();
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
|
||||
// capture of different displays with different DPI, so let it be MacOS
|
||||
// specific only.
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
const int val = (m_thickness + m_padding) * pixelRatio;
|
||||
QRect r = m_backupArea.normalized();
|
||||
if (1 != pixelRatio) {
|
||||
r.moveTo(r.topLeft() * pixelRatio);
|
||||
r.setSize(r.size() * pixelRatio);
|
||||
}
|
||||
#else
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
|
||||
m_pixmapBackup = pixmap.copy(area);
|
||||
QRect r = m_backupArea.normalized();
|
||||
#endif
|
||||
r += QMargins(val, val, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
void AbstractPathTool::addPoint(const QPoint& point)
|
||||
|
||||
@@ -41,8 +41,7 @@ public slots:
|
||||
protected:
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
void addPoint(const QPoint& point);
|
||||
|
||||
virtual ToolType nameID() const = 0;
|
||||
QRect backupRect(const QPixmap& pixmap) const;
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "abstracttwopointtool.h"
|
||||
#include <QCursor>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <cmath>
|
||||
|
||||
namespace {
|
||||
@@ -71,7 +74,16 @@ bool AbstractTwoPointTool::showMousePreview() const
|
||||
void AbstractTwoPointTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
|
||||
// capture of different displays with different DPI, so let it be MacOS
|
||||
// specific only.
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup);
|
||||
#else
|
||||
p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup);
|
||||
#endif
|
||||
if (this->nameID() == ToolType::CIRCLECOUNT) {
|
||||
emit requestAction(REQ_DECREMENT_CIRCLE_COUNT);
|
||||
}
|
||||
@@ -104,13 +116,27 @@ void AbstractTwoPointTool::thicknessChanged(const int th)
|
||||
|
||||
void AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap));
|
||||
}
|
||||
|
||||
QRect AbstractTwoPointTool::backupRect(const QRect& limits) const
|
||||
QRect AbstractTwoPointTool::backupRect(const QPixmap& pixmap) const
|
||||
{
|
||||
const QRect& limits = pixmap.rect();
|
||||
QRect r = QRect(m_points.first, m_points.second).normalized();
|
||||
const int val = m_thickness + m_padding;
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
|
||||
// capture of different displays with different DPI, so let it be MacOS
|
||||
// specific only.
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
if (1 != pixelRatio) {
|
||||
r.moveTo(r.topLeft() * pixelRatio);
|
||||
r.setSize(r.size() * pixelRatio);
|
||||
}
|
||||
const int val = (m_thickness + m_padding) * pixelRatio;
|
||||
#else
|
||||
const int val = (m_thickness + m_padding);
|
||||
#endif
|
||||
r += QMargins(val, val, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public slots:
|
||||
|
||||
protected:
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
QRect backupRect(const QRect& limits) const;
|
||||
QRect backupRect(const QPixmap& pixmap) const;
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QPair<QPoint, QPoint> m_points;
|
||||
@@ -53,8 +53,6 @@ protected:
|
||||
bool m_supportsOrthogonalAdj = false;
|
||||
bool m_supportsDiagonalAdj = false;
|
||||
|
||||
virtual ToolType nameID() const = 0;
|
||||
|
||||
private:
|
||||
QPoint adjustedVector(QPoint v) const;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ class CopyTool : public AbstractActionTool
|
||||
public:
|
||||
explicit CopyTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class ExitTool : public AbstractActionTool
|
||||
public:
|
||||
explicit ExitTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class AppLauncher : public AbstractActionTool
|
||||
public:
|
||||
explicit AppLauncher(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class MoveTool : public AbstractActionTool
|
||||
public:
|
||||
explicit MoveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class PinTool : public AbstractActionTool
|
||||
public:
|
||||
explicit PinTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <cassert>
|
||||
|
||||
PixelateTool::PixelateTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
@@ -65,13 +64,12 @@ void PixelateTool::process(QPainter& painter,
|
||||
QPoint& p0 = m_points.first;
|
||||
QPoint& p1 = m_points.second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
auto pixelRatio = pixmap.devicePixelRatio();
|
||||
QRect selectionScaled =
|
||||
QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
|
||||
// If thickness is less than 1, use old blur process
|
||||
if (m_thickness <= 1) {
|
||||
auto pixelRatio = pixmap.devicePixelRatio();
|
||||
|
||||
QRect selectionScaled =
|
||||
QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
|
||||
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
|
||||
blur->setBlurRadius(10);
|
||||
@@ -92,7 +90,7 @@ void PixelateTool::process(QPainter& painter,
|
||||
int height = selection.height() * (0.5 / qMax(1, m_thickness));
|
||||
QSize size = QSize(qMax(width, 1), qMax(height, 1));
|
||||
|
||||
QPixmap t = pixmap.copy(selection);
|
||||
QPixmap t = pixmap.copy(selectionScaled);
|
||||
t = t.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
t = t.scaled(selection.width(), selection.height());
|
||||
painter.drawImage(selection, t.toImage());
|
||||
|
||||
@@ -25,7 +25,7 @@ class RedoTool : public AbstractActionTool
|
||||
public:
|
||||
explicit RedoTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
#include "savetool.h"
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include <QPainter>
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
#include "src/widgets/capture/capturewidget.h"
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#endif
|
||||
|
||||
SaveTool::SaveTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
@@ -55,6 +61,17 @@ CaptureTool* SaveTool::copy(QObject* parent)
|
||||
|
||||
void SaveTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
for (QWidget* widget : qApp->topLevelWidgets()) {
|
||||
QString className(widget->metaObject()->className());
|
||||
if (0 ==
|
||||
className.compare(CaptureWidget::staticMetaObject.className())) {
|
||||
widget->showNormal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (context.savePath.isEmpty()) {
|
||||
emit requestAction(REQ_HIDE_GUI);
|
||||
bool ok = ScreenshotSaver().saveToFilesystemGUI(
|
||||
|
||||
@@ -25,7 +25,7 @@ class SaveTool : public AbstractActionTool
|
||||
public:
|
||||
explicit SaveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class SelectionTool : public AbstractTwoPointTool
|
||||
public:
|
||||
explicit SelectionTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class SizeIndicatorTool : public AbstractActionTool
|
||||
public:
|
||||
explicit SizeIndicatorTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -130,7 +130,16 @@ CaptureTool* TextTool::copy(QObject* parent)
|
||||
void TextTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
// Not sure how will it work on 4k and fullHd on Linux or Windows with a
|
||||
// capture of different displays with different DPI, so let it be MacOS
|
||||
// specific only.
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup);
|
||||
#else
|
||||
p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextTool::process(QPainter& painter,
|
||||
@@ -144,12 +153,32 @@ void TextTool::process(QPainter& painter,
|
||||
QSize size(fm.boundingRect(QRect(), 0, m_text).size());
|
||||
m_backupArea.setSize(size);
|
||||
if (recordUndo) {
|
||||
m_pixmapBackup = pixmap.copy(m_backupArea + QMargins(0, 0, 5, 5));
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap));
|
||||
}
|
||||
// draw text
|
||||
painter.setFont(m_font);
|
||||
painter.setPen(m_color);
|
||||
painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text);
|
||||
const int val = 5;
|
||||
painter.drawText(m_backupArea + QMargins(-val, -val, val, val), m_text);
|
||||
}
|
||||
|
||||
QRect TextTool::backupRect(const QPixmap& pixmap) const
|
||||
{
|
||||
const QRect& limits = pixmap.rect();
|
||||
QRect r = m_backupArea.normalized();
|
||||
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
const qreal pixelRatio = pixmap.devicePixelRatio();
|
||||
const int val = 5 * pixelRatio;
|
||||
if (1 != pixelRatio) {
|
||||
r.moveTo(r.topLeft() * pixelRatio);
|
||||
r.setSize(r.size() * pixelRatio);
|
||||
}
|
||||
#else
|
||||
const int val = 5;
|
||||
#endif
|
||||
r += QMargins(0, 0, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
void TextTool::paintMousePreview(QPainter& painter,
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
QRect backupRect(const QPixmap& pixmap) const;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
|
||||
@@ -92,9 +92,12 @@ CaptureTool* ToolFactory::CreateTool(CaptureToolButton::ButtonType t,
|
||||
case CaptureToolButton::TYPE_REDO:
|
||||
tool = new RedoTool(parent);
|
||||
break;
|
||||
#if not(defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
|
||||
defined(Q_OS_MACX))
|
||||
case CaptureToolButton::TYPE_OPEN_APP:
|
||||
tool = new AppLauncher(parent);
|
||||
break;
|
||||
#endif
|
||||
case CaptureToolButton::TYPE_PIXELATE:
|
||||
tool = new PixelateTool(parent);
|
||||
break;
|
||||
@@ -107,7 +110,6 @@ CaptureTool* ToolFactory::CreateTool(CaptureToolButton::ButtonType t,
|
||||
case CaptureToolButton::TYPE_CIRCLECOUNT:
|
||||
tool = new CircleCountTool(parent);
|
||||
break;
|
||||
|
||||
default:
|
||||
tool = nullptr;
|
||||
break;
|
||||
|
||||
@@ -25,7 +25,7 @@ class UndoTool : public AbstractActionTool
|
||||
public:
|
||||
explicit UndoTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
|
||||
Reference in New Issue
Block a user