Changed clang format to new agreement
This commit is contained in:
committed by
borgmanJeremy
parent
2cbccc3d0a
commit
0d5386edd4
@@ -21,74 +21,63 @@ AbstractActionTool::AbstractActionTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
AbstractActionTool::isValid() const
|
||||
bool AbstractActionTool::isValid() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractActionTool::isSelectable() const
|
||||
bool AbstractActionTool::isSelectable() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractActionTool::showMousePreview() const
|
||||
bool AbstractActionTool::showMousePreview() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::undo(QPixmap& pixmap)
|
||||
void AbstractActionTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
Q_UNUSED(pixmap);
|
||||
Q_UNUSED(pixmap);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
void AbstractActionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(pixmap);
|
||||
Q_UNUSED(recordUndo);
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(pixmap);
|
||||
Q_UNUSED(recordUndo);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
void AbstractActionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::drawEnd(const QPoint& p)
|
||||
void AbstractActionTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::drawMove(const QPoint& p)
|
||||
void AbstractActionTool::drawMove(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::drawStart(const CaptureContext& context)
|
||||
void AbstractActionTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::colorChanged(const QColor& c)
|
||||
void AbstractActionTool::colorChanged(const QColor& c)
|
||||
{
|
||||
Q_UNUSED(c);
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractActionTool::thicknessChanged(const int th)
|
||||
void AbstractActionTool::thicknessChanged(const int th)
|
||||
{
|
||||
Q_UNUSED(th);
|
||||
Q_UNUSED(th);
|
||||
}
|
||||
|
||||
@@ -21,28 +21,28 @@
|
||||
|
||||
class AbstractActionTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractActionTool(QObject* parent = nullptr);
|
||||
explicit AbstractActionTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
bool isValid() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
virtual ToolType nameID() const = 0;
|
||||
virtual ToolType nameID() const = 0;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
};
|
||||
|
||||
@@ -23,83 +23,72 @@ AbstractPathTool::AbstractPathTool(QObject* parent)
|
||||
, m_padding(0)
|
||||
{}
|
||||
|
||||
bool
|
||||
AbstractPathTool::isValid() const
|
||||
bool AbstractPathTool::isValid() const
|
||||
{
|
||||
return m_points.length() > 1;
|
||||
return m_points.length() > 1;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractPathTool::closeOnButtonPressed() const
|
||||
bool AbstractPathTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractPathTool::isSelectable() const
|
||||
bool AbstractPathTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractPathTool::showMousePreview() const
|
||||
bool AbstractPathTool::showMousePreview() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::undo(QPixmap& pixmap)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::drawEnd(const QPoint& p)
|
||||
void AbstractPathTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::drawMove(const QPoint& p)
|
||||
void AbstractPathTool::drawMove(const QPoint& p)
|
||||
{
|
||||
addPoint(p);
|
||||
addPoint(p);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::colorChanged(const QColor& c)
|
||||
void AbstractPathTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::thicknessChanged(const int th)
|
||||
void AbstractPathTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th;
|
||||
m_thickness = th;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::updateBackup(const QPixmap& pixmap)
|
||||
void AbstractPathTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
|
||||
m_pixmapBackup = pixmap.copy(area);
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
|
||||
m_pixmapBackup = pixmap.copy(area);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractPathTool::addPoint(const QPoint& point)
|
||||
void AbstractPathTool::addPoint(const QPoint& point)
|
||||
{
|
||||
if (m_backupArea.left() > point.x()) {
|
||||
m_backupArea.setLeft(point.x());
|
||||
} else if (m_backupArea.right() < point.x()) {
|
||||
m_backupArea.setRight(point.x());
|
||||
}
|
||||
if (m_backupArea.top() > point.y()) {
|
||||
m_backupArea.setTop(point.y());
|
||||
} else if (m_backupArea.bottom() < point.y()) {
|
||||
m_backupArea.setBottom(point.y());
|
||||
}
|
||||
m_points.append(point);
|
||||
if (m_backupArea.left() > point.x()) {
|
||||
m_backupArea.setLeft(point.x());
|
||||
} else if (m_backupArea.right() < point.x()) {
|
||||
m_backupArea.setRight(point.x());
|
||||
}
|
||||
if (m_backupArea.top() > point.y()) {
|
||||
m_backupArea.setTop(point.y());
|
||||
} else if (m_backupArea.bottom() < point.y()) {
|
||||
m_backupArea.setBottom(point.y());
|
||||
}
|
||||
m_points.append(point);
|
||||
}
|
||||
|
||||
@@ -21,34 +21,34 @@
|
||||
|
||||
class AbstractPathTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractPathTool(QObject* parent = nullptr);
|
||||
explicit AbstractPathTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
protected:
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
void addPoint(const QPoint& point);
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
void addPoint(const QPoint& point);
|
||||
|
||||
virtual ToolType nameID() const = 0;
|
||||
virtual ToolType nameID() const = 0;
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
QColor m_color;
|
||||
QVector<QPoint> m_points;
|
||||
int m_thickness;
|
||||
// use m_padding to extend the area of the backup
|
||||
int m_padding;
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
QColor m_color;
|
||||
QVector<QPoint> m_points;
|
||||
int m_thickness;
|
||||
// use m_padding to extend the area of the backup
|
||||
int m_padding;
|
||||
};
|
||||
|
||||
@@ -25,10 +25,10 @@ const int DIRS_NUMBER = 4;
|
||||
|
||||
enum UNIT
|
||||
{
|
||||
HORIZ_DIR = 0,
|
||||
DIAG1_DIR = 1,
|
||||
VERT_DIR = 2,
|
||||
DIAG2_DIR = 3
|
||||
HORIZ_DIR = 0,
|
||||
DIAG1_DIR = 1,
|
||||
VERT_DIR = 2,
|
||||
DIAG2_DIR = 3
|
||||
};
|
||||
|
||||
const double ADJ_DIAG_UNIT = 2 * ADJ_UNIT;
|
||||
@@ -36,8 +36,8 @@ const int DIAG_DIRS_NUMBER = 2;
|
||||
|
||||
enum DIAG_UNIT
|
||||
{
|
||||
DIR1 = 0,
|
||||
DIR2 = 1
|
||||
DIR1 = 0,
|
||||
DIR2 = 1
|
||||
};
|
||||
|
||||
}
|
||||
@@ -48,123 +48,111 @@ AbstractTwoPointTool::AbstractTwoPointTool(QObject* parent)
|
||||
, m_padding(0)
|
||||
{}
|
||||
|
||||
bool
|
||||
AbstractTwoPointTool::isValid() const
|
||||
bool AbstractTwoPointTool::isValid() const
|
||||
{
|
||||
return (m_points.first != m_points.second);
|
||||
return (m_points.first != m_points.second);
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractTwoPointTool::closeOnButtonPressed() const
|
||||
bool AbstractTwoPointTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractTwoPointTool::isSelectable() const
|
||||
bool AbstractTwoPointTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractTwoPointTool::showMousePreview() const
|
||||
bool AbstractTwoPointTool::showMousePreview() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::undo(QPixmap& pixmap)
|
||||
void AbstractTwoPointTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
if (this->nameID() == ToolType::CIRCLECOUNT) {
|
||||
emit requestAction(REQ_DECREMENT_CIRCLE_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::drawMove(const QPoint& p)
|
||||
{
|
||||
m_points.second = p;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint& p)
|
||||
{
|
||||
m_points.second = m_points.first + adjustedVector(p - m_points.first);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
|
||||
}
|
||||
|
||||
QRect
|
||||
AbstractTwoPointTool::backupRect(const QRect& limits) const
|
||||
{
|
||||
QRect r = QRect(m_points.first, m_points.second).normalized();
|
||||
const int val = m_thickness + m_padding;
|
||||
r += QMargins(val, val, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
QPoint
|
||||
AbstractTwoPointTool::adjustedVector(QPoint v) const
|
||||
{
|
||||
if (m_supportsOrthogonalAdj && m_supportsDiagonalAdj) {
|
||||
int dir =
|
||||
(static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) + DIRS_NUMBER) %
|
||||
DIRS_NUMBER;
|
||||
if (dir == UNIT::HORIZ_DIR) {
|
||||
v.setY(0);
|
||||
} else if (dir == UNIT::VERT_DIR) {
|
||||
v.setX(0);
|
||||
} else if (dir == UNIT::DIAG1_DIR) {
|
||||
int newX = (v.x() - v.y()) / 2;
|
||||
int newY = -newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
} else {
|
||||
int newX = (v.x() + v.y()) / 2;
|
||||
int newY = newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
if (this->nameID() == ToolType::CIRCLECOUNT) {
|
||||
emit requestAction(REQ_DECREMENT_CIRCLE_COUNT);
|
||||
}
|
||||
} else if (m_supportsDiagonalAdj) {
|
||||
int dir = (static_cast<int>(round(
|
||||
(atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) / ADJ_DIAG_UNIT)) +
|
||||
DIAG_DIRS_NUMBER) %
|
||||
DIAG_DIRS_NUMBER;
|
||||
if (dir == DIAG_UNIT::DIR1) {
|
||||
int newX = (v.x() - v.y()) / 2;
|
||||
int newY = -newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
} else {
|
||||
int newX = (v.x() + v.y()) / 2;
|
||||
int newY = newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawMove(const QPoint& p)
|
||||
{
|
||||
m_points.second = p;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint& p)
|
||||
{
|
||||
m_points.second = m_points.first + adjustedVector(p - m_points.first);
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
|
||||
}
|
||||
|
||||
QRect AbstractTwoPointTool::backupRect(const QRect& limits) const
|
||||
{
|
||||
QRect r = QRect(m_points.first, m_points.second).normalized();
|
||||
const int val = m_thickness + m_padding;
|
||||
r += QMargins(val, val, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const
|
||||
{
|
||||
if (m_supportsOrthogonalAdj && m_supportsDiagonalAdj) {
|
||||
int dir = (static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) +
|
||||
DIRS_NUMBER) %
|
||||
DIRS_NUMBER;
|
||||
if (dir == UNIT::HORIZ_DIR) {
|
||||
v.setY(0);
|
||||
} else if (dir == UNIT::VERT_DIR) {
|
||||
v.setX(0);
|
||||
} else if (dir == UNIT::DIAG1_DIR) {
|
||||
int newX = (v.x() - v.y()) / 2;
|
||||
int newY = -newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
} else {
|
||||
int newX = (v.x() + v.y()) / 2;
|
||||
int newY = newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
}
|
||||
} else if (m_supportsDiagonalAdj) {
|
||||
int dir =
|
||||
(static_cast<int>(round((atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) /
|
||||
ADJ_DIAG_UNIT)) +
|
||||
DIAG_DIRS_NUMBER) %
|
||||
DIAG_DIRS_NUMBER;
|
||||
if (dir == DIAG_UNIT::DIR1) {
|
||||
int newX = (v.x() - v.y()) / 2;
|
||||
int newY = -newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
} else {
|
||||
int newX = (v.x() + v.y()) / 2;
|
||||
int newY = newX;
|
||||
v.setX(newX);
|
||||
v.setY(newY);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -21,40 +21,40 @@
|
||||
|
||||
class AbstractTwoPointTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractTwoPointTool(QObject* parent = nullptr);
|
||||
explicit AbstractTwoPointTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawMoveWithAdjustment(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawMoveWithAdjustment(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
protected:
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
QRect backupRect(const QRect& limits) const;
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
QRect backupRect(const QRect& limits) const;
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QPair<QPoint, QPoint> m_points;
|
||||
QColor m_color;
|
||||
int m_thickness;
|
||||
// use m_padding to extend the area of the backup
|
||||
int m_padding;
|
||||
QPixmap m_pixmapBackup;
|
||||
QPair<QPoint, QPoint> m_points;
|
||||
QColor m_color;
|
||||
int m_thickness;
|
||||
// use m_padding to extend the area of the backup
|
||||
int m_padding;
|
||||
|
||||
bool m_supportsOrthogonalAdj = false;
|
||||
bool m_supportsDiagonalAdj = false;
|
||||
bool m_supportsOrthogonalAdj = false;
|
||||
bool m_supportsDiagonalAdj = false;
|
||||
|
||||
virtual ToolType nameID() const = 0;
|
||||
virtual ToolType nameID() const = 0;
|
||||
|
||||
private:
|
||||
QPoint adjustedVector(QPoint v) const;
|
||||
QPoint adjustedVector(QPoint v) const;
|
||||
};
|
||||
|
||||
@@ -24,50 +24,48 @@ namespace {
|
||||
const int ArrowWidth = 10;
|
||||
const int ArrowHeight = 18;
|
||||
|
||||
QPainterPath
|
||||
getArrowHead(QPoint p1, QPoint p2, const int thickness)
|
||||
QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness)
|
||||
{
|
||||
QLineF base(p1, p2);
|
||||
// Create the vector for the position of the base of the arrowhead
|
||||
QLineF temp(QPoint(0, 0), p2 - p1);
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (base.length() < val) {
|
||||
val = (base.length() + thickness * 2);
|
||||
}
|
||||
temp.setLength(base.length() + thickness * 2 - val);
|
||||
// Move across the line up to the head
|
||||
QPointF bottonTranslation(temp.p2());
|
||||
QLineF base(p1, p2);
|
||||
// Create the vector for the position of the base of the arrowhead
|
||||
QLineF temp(QPoint(0, 0), p2 - p1);
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (base.length() < val) {
|
||||
val = (base.length() + thickness * 2);
|
||||
}
|
||||
temp.setLength(base.length() + thickness * 2 - val);
|
||||
// Move across the line up to the head
|
||||
QPointF bottonTranslation(temp.p2());
|
||||
|
||||
// Rotate base of the arrowhead
|
||||
base.setLength(ArrowWidth + thickness * 2);
|
||||
base.setAngle(base.angle() + 90);
|
||||
// Move to the correct point
|
||||
QPointF temp2 = p1 - base.p2();
|
||||
// Center it
|
||||
QPointF centerTranslation((temp2.x() / 2), (temp2.y() / 2));
|
||||
// Rotate base of the arrowhead
|
||||
base.setLength(ArrowWidth + thickness * 2);
|
||||
base.setAngle(base.angle() + 90);
|
||||
// Move to the correct point
|
||||
QPointF temp2 = p1 - base.p2();
|
||||
// Center it
|
||||
QPointF centerTranslation((temp2.x() / 2), (temp2.y() / 2));
|
||||
|
||||
base.translate(bottonTranslation);
|
||||
base.translate(centerTranslation);
|
||||
base.translate(bottonTranslation);
|
||||
base.translate(centerTranslation);
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(p2);
|
||||
path.lineTo(base.p1());
|
||||
path.lineTo(base.p2());
|
||||
path.lineTo(p2);
|
||||
return path;
|
||||
QPainterPath path;
|
||||
path.moveTo(p2);
|
||||
path.lineTo(base.p1());
|
||||
path.lineTo(base.p2());
|
||||
path.lineTo(p2);
|
||||
return path;
|
||||
}
|
||||
|
||||
// gets a shorter line to prevent overlap in the point of the arrow
|
||||
QLine
|
||||
getShorterLine(QPoint p1, QPoint p2, const int thickness)
|
||||
QLine getShorterLine(QPoint p1, QPoint p2, const int thickness)
|
||||
{
|
||||
QLineF l(p1, p2);
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (l.length() < val) {
|
||||
val = (l.length() + thickness * 2);
|
||||
}
|
||||
l.setLength(l.length() + thickness * 2 - val);
|
||||
return l.toLine();
|
||||
QLineF l(p1, p2);
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (l.length() < val) {
|
||||
val = (l.length() + thickness * 2);
|
||||
}
|
||||
l.setLength(l.length() + thickness * 2 - val);
|
||||
return l.toLine();
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
@@ -75,72 +73,66 @@ getShorterLine(QPoint p1, QPoint p2, const int thickness)
|
||||
ArrowTool::ArrowTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_padding = ArrowWidth / 2;
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_padding = ArrowWidth / 2;
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
ArrowTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon ArrowTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "arrow-bottom-left.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "arrow-bottom-left.svg");
|
||||
}
|
||||
QString
|
||||
ArrowTool::name() const
|
||||
QString ArrowTool::name() const
|
||||
{
|
||||
return tr("Arrow");
|
||||
return tr("Arrow");
|
||||
}
|
||||
|
||||
ToolType
|
||||
ArrowTool::nameID() const
|
||||
ToolType ArrowTool::nameID() const
|
||||
{
|
||||
return ToolType::ARROW;
|
||||
return ToolType::ARROW;
|
||||
}
|
||||
|
||||
QString
|
||||
ArrowTool::description() const
|
||||
QString ArrowTool::description() const
|
||||
{
|
||||
return tr("Set the Arrow as the paint tool");
|
||||
return tr("Set the Arrow as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
ArrowTool::copy(QObject* parent)
|
||||
CaptureTool* ArrowTool::copy(QObject* parent)
|
||||
{
|
||||
return new ArrowTool(parent);
|
||||
return new ArrowTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
ArrowTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void ArrowTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(
|
||||
getShorterLine(m_points.first, m_points.second, m_thickness));
|
||||
painter.fillPath(getArrowHead(m_points.first, m_points.second, m_thickness),
|
||||
QBrush(m_color));
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(
|
||||
getShorterLine(m_points.first, m_points.second, m_thickness));
|
||||
painter.fillPath(getArrowHead(m_points.first, m_points.second, m_thickness),
|
||||
QBrush(m_color));
|
||||
}
|
||||
|
||||
void
|
||||
ArrowTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void ArrowTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
ArrowTool::drawStart(const CaptureContext& context)
|
||||
void ArrowTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
ArrowTool::pressed(const CaptureContext& context)
|
||||
void ArrowTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -23,25 +23,25 @@
|
||||
|
||||
class ArrowTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArrowTool(QObject* parent = nullptr);
|
||||
explicit ArrowTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
|
||||
#include "capturecontext.h"
|
||||
|
||||
QPixmap
|
||||
CaptureContext::selectedScreenshotArea() const
|
||||
QPixmap CaptureContext::selectedScreenshotArea() const
|
||||
{
|
||||
if (selection.isNull()) {
|
||||
return screenshot;
|
||||
} else {
|
||||
return screenshot.copy(selection);
|
||||
}
|
||||
if (selection.isNull()) {
|
||||
return screenshot;
|
||||
} else {
|
||||
return screenshot.copy(selection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,27 +24,27 @@
|
||||
|
||||
struct CaptureContext
|
||||
{
|
||||
// screenshot with modifications
|
||||
QPixmap screenshot;
|
||||
// unmodified screenshot
|
||||
QPixmap origScreenshot;
|
||||
// Selection area
|
||||
QRect selection;
|
||||
// Widget dimensions
|
||||
QRect widgetDimensions;
|
||||
// Selected tool color
|
||||
QColor color;
|
||||
// Path where the content has to be saved
|
||||
QString savePath;
|
||||
// Ofset of the capture widget based on the system's screen (top-left)
|
||||
QPoint widgetOffset;
|
||||
// Mouse position inside the widget
|
||||
QPoint mousePos;
|
||||
// Value of the desired thickness
|
||||
int thickness;
|
||||
int circleCount;
|
||||
// Mode of the capture widget
|
||||
bool fullscreen;
|
||||
// screenshot with modifications
|
||||
QPixmap screenshot;
|
||||
// unmodified screenshot
|
||||
QPixmap origScreenshot;
|
||||
// Selection area
|
||||
QRect selection;
|
||||
// Widget dimensions
|
||||
QRect widgetDimensions;
|
||||
// Selected tool color
|
||||
QColor color;
|
||||
// Path where the content has to be saved
|
||||
QString savePath;
|
||||
// Ofset of the capture widget based on the system's screen (top-left)
|
||||
QPoint widgetOffset;
|
||||
// Mouse position inside the widget
|
||||
QPoint mousePos;
|
||||
// Value of the desired thickness
|
||||
int thickness;
|
||||
int circleCount;
|
||||
// Mode of the capture widget
|
||||
bool fullscreen;
|
||||
|
||||
QPixmap selectedScreenshotArea() const;
|
||||
QPixmap selectedScreenshotArea() const;
|
||||
};
|
||||
|
||||
@@ -25,152 +25,152 @@
|
||||
|
||||
enum class ToolType
|
||||
{
|
||||
ARROW,
|
||||
CIRCLE,
|
||||
CIRCLECOUNT,
|
||||
COPY,
|
||||
EXIT,
|
||||
IMGUR,
|
||||
LAUNCHER,
|
||||
LINE,
|
||||
MARKER,
|
||||
MOVE,
|
||||
PENCIL,
|
||||
PIN,
|
||||
PIXELATE,
|
||||
RECTANGLE,
|
||||
REDO,
|
||||
SAVE,
|
||||
SELECTION,
|
||||
SIZEINDICATOR,
|
||||
TEXT,
|
||||
UNDO
|
||||
ARROW,
|
||||
CIRCLE,
|
||||
CIRCLECOUNT,
|
||||
COPY,
|
||||
EXIT,
|
||||
IMGUR,
|
||||
LAUNCHER,
|
||||
LINE,
|
||||
MARKER,
|
||||
MOVE,
|
||||
PENCIL,
|
||||
PIN,
|
||||
PIXELATE,
|
||||
RECTANGLE,
|
||||
REDO,
|
||||
SAVE,
|
||||
SELECTION,
|
||||
SIZEINDICATOR,
|
||||
TEXT,
|
||||
UNDO
|
||||
};
|
||||
|
||||
class CaptureTool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Request actions on the main widget
|
||||
enum Request
|
||||
{
|
||||
// Call close() in the editor.
|
||||
REQ_CLOSE_GUI,
|
||||
// Call hide() in the editor.
|
||||
REQ_HIDE_GUI,
|
||||
// Select the whole screen.
|
||||
REQ_SELECT_ALL,
|
||||
// Disable the selection.
|
||||
REQ_HIDE_SELECTION,
|
||||
// Undo the last active modification in the stack.
|
||||
REQ_UNDO_MODIFICATION,
|
||||
// Redo the next modification in the stack.
|
||||
REQ_REDO_MODIFICATION,
|
||||
// Remove all the modifications.
|
||||
REQ_CLEAR_MODIFICATIONS,
|
||||
// Disable the active tool.
|
||||
REQ_MOVE_MODE,
|
||||
// Open the color picker under the mouse.
|
||||
REQ_SHOW_COLOR_PICKER,
|
||||
// Open/Close the side-panel.
|
||||
REQ_TOGGLE_SIDEBAR,
|
||||
// Call update() in the editor.
|
||||
REQ_REDRAW,
|
||||
// Append this tool to the undo/redo stack
|
||||
REQ_APPEND_TO_STACK,
|
||||
// Notify is the screenshot has been saved.
|
||||
REQ_CAPTURE_DONE_OK,
|
||||
// Instance this->widget()'s widget inside the editor under the mouse.
|
||||
REQ_ADD_CHILD_WIDGET,
|
||||
// Instance this->widget()'s widget as a window which closes after
|
||||
// closing the editor.
|
||||
REQ_ADD_CHILD_WINDOW,
|
||||
// Instance this->widget()'s widget which handles its own lifetime.
|
||||
REQ_ADD_EXTERNAL_WIDGETS,
|
||||
// Request actions on the main widget
|
||||
enum Request
|
||||
{
|
||||
// Call close() in the editor.
|
||||
REQ_CLOSE_GUI,
|
||||
// Call hide() in the editor.
|
||||
REQ_HIDE_GUI,
|
||||
// Select the whole screen.
|
||||
REQ_SELECT_ALL,
|
||||
// Disable the selection.
|
||||
REQ_HIDE_SELECTION,
|
||||
// Undo the last active modification in the stack.
|
||||
REQ_UNDO_MODIFICATION,
|
||||
// Redo the next modification in the stack.
|
||||
REQ_REDO_MODIFICATION,
|
||||
// Remove all the modifications.
|
||||
REQ_CLEAR_MODIFICATIONS,
|
||||
// Disable the active tool.
|
||||
REQ_MOVE_MODE,
|
||||
// Open the color picker under the mouse.
|
||||
REQ_SHOW_COLOR_PICKER,
|
||||
// Open/Close the side-panel.
|
||||
REQ_TOGGLE_SIDEBAR,
|
||||
// Call update() in the editor.
|
||||
REQ_REDRAW,
|
||||
// Append this tool to the undo/redo stack
|
||||
REQ_APPEND_TO_STACK,
|
||||
// Notify is the screenshot has been saved.
|
||||
REQ_CAPTURE_DONE_OK,
|
||||
// Instance this->widget()'s widget inside the editor under the mouse.
|
||||
REQ_ADD_CHILD_WIDGET,
|
||||
// Instance this->widget()'s widget as a window which closes after
|
||||
// closing the editor.
|
||||
REQ_ADD_CHILD_WINDOW,
|
||||
// Instance this->widget()'s widget which handles its own lifetime.
|
||||
REQ_ADD_EXTERNAL_WIDGETS,
|
||||
|
||||
REQ_INCREMENT_CIRCLE_COUNT,
|
||||
REQ_INCREMENT_CIRCLE_COUNT,
|
||||
|
||||
REQ_DECREMENT_CIRCLE_COUNT,
|
||||
};
|
||||
REQ_DECREMENT_CIRCLE_COUNT,
|
||||
};
|
||||
|
||||
explicit CaptureTool(QObject* parent = nullptr)
|
||||
: QObject(parent)
|
||||
{}
|
||||
explicit CaptureTool(QObject* parent = nullptr)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
// Returns false when the tool is in an inconsistent state and shouldn't
|
||||
// be included in the tool undo/redo stack.
|
||||
virtual bool isValid() const = 0;
|
||||
// Close the capture after the process() call if the tool was activated
|
||||
// from a button press.
|
||||
virtual bool closeOnButtonPressed() const = 0;
|
||||
// If the tool keeps active after the selection.
|
||||
virtual bool isSelectable() const = 0;
|
||||
// Enable mouse preview.
|
||||
virtual bool showMousePreview() const = 0;
|
||||
// Returns false when the tool is in an inconsistent state and shouldn't
|
||||
// be included in the tool undo/redo stack.
|
||||
virtual bool isValid() const = 0;
|
||||
// Close the capture after the process() call if the tool was activated
|
||||
// from a button press.
|
||||
virtual bool closeOnButtonPressed() const = 0;
|
||||
// If the tool keeps active after the selection.
|
||||
virtual bool isSelectable() const = 0;
|
||||
// Enable mouse preview.
|
||||
virtual bool showMousePreview() const = 0;
|
||||
|
||||
// The icon of the tool.
|
||||
// inEditor is true when the icon is requested inside the editor
|
||||
// and false otherwise.
|
||||
virtual QIcon icon(const QColor& background, bool inEditor) const = 0;
|
||||
// Name displayed for the tool, this could be translated with tr()
|
||||
virtual QString name() const = 0;
|
||||
// Codename for the tool, this hsouldn't change as it is used as ID
|
||||
// for the tool in the internals of Flameshot
|
||||
virtual ToolType nameID() const = 0;
|
||||
// Short description of the tool.
|
||||
virtual QString description() const = 0;
|
||||
// The icon of the tool.
|
||||
// inEditor is true when the icon is requested inside the editor
|
||||
// and false otherwise.
|
||||
virtual QIcon icon(const QColor& background, bool inEditor) const = 0;
|
||||
// Name displayed for the tool, this could be translated with tr()
|
||||
virtual QString name() const = 0;
|
||||
// Codename for the tool, this hsouldn't change as it is used as ID
|
||||
// for the tool in the internals of Flameshot
|
||||
virtual ToolType nameID() const = 0;
|
||||
// Short description of the tool.
|
||||
virtual QString description() const = 0;
|
||||
|
||||
// if the type is TYPE_WIDGET the widget is loaded in the main widget.
|
||||
// If the type is TYPE_EXTERNAL_WIDGET it is created outside as an
|
||||
// individual widget.
|
||||
virtual QWidget* widget() { return nullptr; }
|
||||
// When the tool is selected this method is called and the widget is added
|
||||
// to the configuration panel inside the main widget.
|
||||
virtual QWidget* configurationWidget() { return nullptr; }
|
||||
// Permanent configuration used in the configuration outside of the
|
||||
// capture.
|
||||
virtual QWidget* permanentConfigurationWidget() { return nullptr; }
|
||||
// Return a copy of the tool
|
||||
virtual CaptureTool* copy(QObject* parent = nullptr) = 0;
|
||||
// if the type is TYPE_WIDGET the widget is loaded in the main widget.
|
||||
// If the type is TYPE_EXTERNAL_WIDGET it is created outside as an
|
||||
// individual widget.
|
||||
virtual QWidget* widget() { return nullptr; }
|
||||
// When the tool is selected this method is called and the widget is added
|
||||
// to the configuration panel inside the main widget.
|
||||
virtual QWidget* configurationWidget() { return nullptr; }
|
||||
// Permanent configuration used in the configuration outside of the
|
||||
// capture.
|
||||
virtual QWidget* permanentConfigurationWidget() { return nullptr; }
|
||||
// Return a copy of the tool
|
||||
virtual CaptureTool* copy(QObject* parent = nullptr) = 0;
|
||||
|
||||
// revert changes
|
||||
virtual void undo(QPixmap& pixmap) = 0;
|
||||
// Called every time the tool has to draw
|
||||
// recordUndo indicates when the tool should save the information
|
||||
// for the undo(), if the value is false calling undo() after
|
||||
// that process should not modify revert the changes.
|
||||
virtual void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) = 0;
|
||||
// When the tool is selected, this is called when the mouse moves
|
||||
virtual void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) = 0;
|
||||
// revert changes
|
||||
virtual void undo(QPixmap& pixmap) = 0;
|
||||
// Called every time the tool has to draw
|
||||
// recordUndo indicates when the tool should save the information
|
||||
// for the undo(), if the value is false calling undo() after
|
||||
// that process should not modify revert the changes.
|
||||
virtual void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) = 0;
|
||||
// When the tool is selected, this is called when the mouse moves
|
||||
virtual void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) = 0;
|
||||
|
||||
signals:
|
||||
void requestAction(Request r);
|
||||
void requestAction(Request r);
|
||||
|
||||
protected:
|
||||
QString iconPath(const QColor& c) const
|
||||
{
|
||||
return ColorUtils::colorIsDark(c) ? PathInfo::whiteIconPath()
|
||||
: PathInfo::blackIconPath();
|
||||
}
|
||||
QString iconPath(const QColor& c) const
|
||||
{
|
||||
return ColorUtils::colorIsDark(c) ? PathInfo::whiteIconPath()
|
||||
: PathInfo::blackIconPath();
|
||||
}
|
||||
|
||||
public slots:
|
||||
// On mouse release.
|
||||
virtual void drawEnd(const QPoint& p) = 0;
|
||||
// Mouse pressed and moving, called once a pixel.
|
||||
virtual void drawMove(const QPoint& p) = 0;
|
||||
// Called when drawMove is needed with an adjustment;
|
||||
// should be overridden in case an adjustment is applicable.
|
||||
virtual void drawMoveWithAdjustment(const QPoint& p) { drawMove(p); }
|
||||
// Called when the tool is activated.
|
||||
virtual void drawStart(const CaptureContext& context) = 0;
|
||||
// Called right after pressign the button which activates the tool.
|
||||
virtual void pressed(const CaptureContext& context) = 0;
|
||||
// Called when the color is changed in the editor.
|
||||
virtual void colorChanged(const QColor& c) = 0;
|
||||
// Called when the thickness of the tool is updated in the editor.
|
||||
virtual void thicknessChanged(const int th) = 0;
|
||||
// On mouse release.
|
||||
virtual void drawEnd(const QPoint& p) = 0;
|
||||
// Mouse pressed and moving, called once a pixel.
|
||||
virtual void drawMove(const QPoint& p) = 0;
|
||||
// Called when drawMove is needed with an adjustment;
|
||||
// should be overridden in case an adjustment is applicable.
|
||||
virtual void drawMoveWithAdjustment(const QPoint& p) { drawMove(p); }
|
||||
// Called when the tool is activated.
|
||||
virtual void drawStart(const CaptureContext& context) = 0;
|
||||
// Called right after pressign the button which activates the tool.
|
||||
virtual void pressed(const CaptureContext& context) = 0;
|
||||
// Called when the color is changed in the editor.
|
||||
virtual void colorChanged(const QColor& c) = 0;
|
||||
// Called when the thickness of the tool is updated in the editor.
|
||||
virtual void thicknessChanged(const int th) = 0;
|
||||
};
|
||||
|
||||
@@ -25,67 +25,61 @@ namespace {
|
||||
CircleTool::CircleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
CircleTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon CircleTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "circle-outline.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "circle-outline.svg");
|
||||
}
|
||||
QString
|
||||
CircleTool::name() const
|
||||
QString CircleTool::name() const
|
||||
{
|
||||
return tr("Circle");
|
||||
return tr("Circle");
|
||||
}
|
||||
|
||||
ToolType
|
||||
CircleTool::nameID() const
|
||||
ToolType CircleTool::nameID() const
|
||||
{
|
||||
return ToolType::CIRCLE;
|
||||
return ToolType::CIRCLE;
|
||||
}
|
||||
|
||||
QString
|
||||
CircleTool::description() const
|
||||
QString CircleTool::description() const
|
||||
{
|
||||
return tr("Set the Circle as the paint tool");
|
||||
return tr("Set the Circle as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
CircleTool::copy(QObject* parent)
|
||||
CaptureTool* CircleTool::copy(QObject* parent)
|
||||
{
|
||||
return new CircleTool(parent);
|
||||
return new CircleTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
CircleTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void CircleTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawEllipse(QRect(m_points.first, m_points.second));
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawEllipse(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void
|
||||
CircleTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void CircleTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
CircleTool::drawStart(const CaptureContext& context)
|
||||
void CircleTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
CircleTool::pressed(const CaptureContext& context)
|
||||
void CircleTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
|
||||
class CircleTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CircleTool(QObject* parent = nullptr);
|
||||
explicit CircleTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -24,120 +24,111 @@ namespace {
|
||||
CircleCountTool::CircleCountTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_count = 0;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
QIcon
|
||||
CircleCountTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon CircleCountTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "circlecount-outline.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "circlecount-outline.svg");
|
||||
}
|
||||
QString
|
||||
CircleCountTool::name() const
|
||||
QString CircleCountTool::name() const
|
||||
{
|
||||
return tr("Circle Counter");
|
||||
return tr("Circle Counter");
|
||||
}
|
||||
|
||||
ToolType
|
||||
CircleCountTool::nameID() const
|
||||
ToolType CircleCountTool::nameID() const
|
||||
{
|
||||
return ToolType::CIRCLECOUNT;
|
||||
return ToolType::CIRCLECOUNT;
|
||||
}
|
||||
|
||||
QString
|
||||
CircleCountTool::description() const
|
||||
QString CircleCountTool::description() const
|
||||
{
|
||||
return tr("Add an autoincrementing counter bubble");
|
||||
return tr("Add an autoincrementing counter bubble");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
CircleCountTool::copy(QObject* parent)
|
||||
CaptureTool* CircleCountTool::copy(QObject* parent)
|
||||
{
|
||||
return new CircleCountTool(parent);
|
||||
return new CircleCountTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
CircleCountTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
void CircleCountTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setBrush(m_color);
|
||||
|
||||
int bubble_size = m_thickness;
|
||||
// Decrease by 1px so the border is properly ereased when doing undo
|
||||
painter.drawEllipse(m_points.first, bubble_size - 1, bubble_size - 1);
|
||||
QRect textRect = QRect(m_points.first.x() - bubble_size / 2,
|
||||
m_points.first.y() - bubble_size / 2,
|
||||
bubble_size,
|
||||
bubble_size);
|
||||
auto orig_font = painter.font();
|
||||
auto new_font = orig_font;
|
||||
auto fontSize = bubble_size;
|
||||
new_font.setPixelSize(fontSize);
|
||||
painter.setFont(new_font);
|
||||
|
||||
QRect bRect =
|
||||
painter.boundingRect(textRect, Qt::AlignCenter, QString::number(m_count));
|
||||
|
||||
while (bRect.width() > textRect.width()) {
|
||||
fontSize--;
|
||||
if (fontSize == 0) {
|
||||
break;
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setBrush(m_color);
|
||||
|
||||
int bubble_size = m_thickness;
|
||||
// Decrease by 1px so the border is properly ereased when doing undo
|
||||
painter.drawEllipse(m_points.first, bubble_size - 1, bubble_size - 1);
|
||||
QRect textRect = QRect(m_points.first.x() - bubble_size / 2,
|
||||
m_points.first.y() - bubble_size / 2,
|
||||
bubble_size,
|
||||
bubble_size);
|
||||
auto orig_font = painter.font();
|
||||
auto new_font = orig_font;
|
||||
auto fontSize = bubble_size;
|
||||
new_font.setPixelSize(fontSize);
|
||||
painter.setFont(new_font);
|
||||
|
||||
bRect =
|
||||
QRect bRect =
|
||||
painter.boundingRect(textRect, Qt::AlignCenter, QString::number(m_count));
|
||||
}
|
||||
|
||||
// Lightness value ranges from 0-255, we split at 75 as this looks best
|
||||
if (m_color.lightness() <= 75) {
|
||||
painter.setPen(Qt::white);
|
||||
} else {
|
||||
painter.setPen(Qt::black);
|
||||
}
|
||||
while (bRect.width() > textRect.width()) {
|
||||
fontSize--;
|
||||
if (fontSize == 0) {
|
||||
break;
|
||||
}
|
||||
new_font.setPixelSize(fontSize);
|
||||
painter.setFont(new_font);
|
||||
|
||||
painter.drawText(textRect, Qt::AlignCenter, QString::number(m_count));
|
||||
painter.setFont(orig_font);
|
||||
bRect = painter.boundingRect(
|
||||
textRect, Qt::AlignCenter, QString::number(m_count));
|
||||
}
|
||||
|
||||
// Lightness value ranges from 0-255, we split at 75 as this looks best
|
||||
if (m_color.lightness() <= 75) {
|
||||
painter.setPen(Qt::white);
|
||||
} else {
|
||||
painter.setPen(Qt::black);
|
||||
}
|
||||
|
||||
painter.drawText(textRect, Qt::AlignCenter, QString::number(m_count));
|
||||
painter.setFont(orig_font);
|
||||
}
|
||||
|
||||
void
|
||||
CircleCountTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
void CircleCountTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
if (m_thickness < 15) {
|
||||
m_thickness = 15;
|
||||
}
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
if (m_thickness < 15) {
|
||||
m_thickness = 15;
|
||||
}
|
||||
|
||||
// Thickness for pen is *2 to range from radius to diameter to match the
|
||||
// ellipse draw function
|
||||
painter.setPen(
|
||||
QPen(context.color, m_thickness * 2, Qt::SolidLine, Qt::RoundCap));
|
||||
painter.drawLine(context.mousePos,
|
||||
{ context.mousePos.x() + 1, context.mousePos.y() + 1 });
|
||||
// Thickness for pen is *2 to range from radius to diameter to match the
|
||||
// ellipse draw function
|
||||
painter.setPen(
|
||||
QPen(context.color, m_thickness * 2, Qt::SolidLine, Qt::RoundCap));
|
||||
painter.drawLine(context.mousePos,
|
||||
{ context.mousePos.x() + 1, context.mousePos.y() + 1 });
|
||||
}
|
||||
|
||||
void
|
||||
CircleCountTool::drawStart(const CaptureContext& context)
|
||||
void CircleCountTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
if (m_thickness < 15) {
|
||||
m_thickness = 15;
|
||||
}
|
||||
m_points.first = context.mousePos;
|
||||
m_count = context.circleCount;
|
||||
emit requestAction(REQ_INCREMENT_CIRCLE_COUNT);
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
if (m_thickness < 15) {
|
||||
m_thickness = 15;
|
||||
}
|
||||
m_points.first = context.mousePos;
|
||||
m_count = context.circleCount;
|
||||
emit requestAction(REQ_INCREMENT_CIRCLE_COUNT);
|
||||
}
|
||||
|
||||
void
|
||||
CircleCountTool::pressed(const CaptureContext& context)
|
||||
void CircleCountTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,27 +21,27 @@
|
||||
|
||||
class CircleCountTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CircleCountTool(QObject* parent = nullptr);
|
||||
explicit CircleCountTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
private:
|
||||
unsigned int m_count;
|
||||
unsigned int m_count;
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -23,45 +23,38 @@ CopyTool::CopyTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
CopyTool::closeOnButtonPressed() const
|
||||
bool CopyTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
CopyTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon CopyTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-copy.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-copy.svg");
|
||||
}
|
||||
QString
|
||||
CopyTool::name() const
|
||||
QString CopyTool::name() const
|
||||
{
|
||||
return tr("Copy");
|
||||
return tr("Copy");
|
||||
}
|
||||
|
||||
ToolType
|
||||
CopyTool::nameID() const
|
||||
ToolType CopyTool::nameID() const
|
||||
{
|
||||
return ToolType::COPY;
|
||||
return ToolType::COPY;
|
||||
}
|
||||
|
||||
QString
|
||||
CopyTool::description() const
|
||||
QString CopyTool::description() const
|
||||
{
|
||||
return tr("Copy the selection into the clipboard");
|
||||
return tr("Copy the selection into the clipboard");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
CopyTool::copy(QObject* parent)
|
||||
CaptureTool* CopyTool::copy(QObject* parent)
|
||||
{
|
||||
return new CopyTool(parent);
|
||||
return new CopyTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
CopyTool::pressed(const CaptureContext& context)
|
||||
void CopyTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class CopyTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CopyTool(QObject* parent = nullptr);
|
||||
explicit CopyTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,45 +22,38 @@ ExitTool::ExitTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
ExitTool::closeOnButtonPressed() const
|
||||
bool ExitTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
ExitTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon ExitTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "close.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "close.svg");
|
||||
}
|
||||
QString
|
||||
ExitTool::name() const
|
||||
QString ExitTool::name() const
|
||||
{
|
||||
return tr("Exit");
|
||||
return tr("Exit");
|
||||
}
|
||||
|
||||
ToolType
|
||||
ExitTool::nameID() const
|
||||
ToolType ExitTool::nameID() const
|
||||
{
|
||||
return ToolType::EXIT;
|
||||
return ToolType::EXIT;
|
||||
}
|
||||
|
||||
QString
|
||||
ExitTool::description() const
|
||||
QString ExitTool::description() const
|
||||
{
|
||||
return tr("Leave the capture screen");
|
||||
return tr("Leave the capture screen");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
ExitTool::copy(QObject* parent)
|
||||
CaptureTool* ExitTool::copy(QObject* parent)
|
||||
{
|
||||
return new ExitTool(parent);
|
||||
return new ExitTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
ExitTool::pressed(const CaptureContext& context)
|
||||
void ExitTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_CLOSE_GUI);
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_CLOSE_GUI);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class ExitTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ExitTool(QObject* parent = nullptr);
|
||||
explicit ExitTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -45,165 +45,158 @@ ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_pixmap(capture)
|
||||
{
|
||||
setWindowTitle(tr("Upload to Imgur"));
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("Upload to Imgur"));
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
|
||||
m_spinner = new LoadSpinner(this);
|
||||
m_spinner->setColor(ConfigHandler().uiMainColorValue());
|
||||
m_spinner->start();
|
||||
m_spinner = new LoadSpinner(this);
|
||||
m_spinner->setColor(ConfigHandler().uiMainColorValue());
|
||||
m_spinner->start();
|
||||
|
||||
m_infoLabel = new QLabel(tr("Uploading Image"));
|
||||
m_infoLabel = new QLabel(tr("Uploading Image"));
|
||||
|
||||
m_vLayout = new QVBoxLayout();
|
||||
setLayout(m_vLayout);
|
||||
m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
|
||||
m_vLayout->addWidget(m_infoLabel);
|
||||
m_vLayout = new QVBoxLayout();
|
||||
setLayout(m_vLayout);
|
||||
m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
|
||||
m_vLayout->addWidget(m_infoLabel);
|
||||
|
||||
m_NetworkAM = new QNetworkAccessManager(this);
|
||||
connect(m_NetworkAM,
|
||||
&QNetworkAccessManager::finished,
|
||||
this,
|
||||
&ImgurUploader::handleReply);
|
||||
m_NetworkAM = new QNetworkAccessManager(this);
|
||||
connect(m_NetworkAM,
|
||||
&QNetworkAccessManager::finished,
|
||||
this,
|
||||
&ImgurUploader::handleReply);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
upload();
|
||||
// QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing
|
||||
upload();
|
||||
// QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::handleReply(QNetworkReply* reply)
|
||||
void ImgurUploader::handleReply(QNetworkReply* reply)
|
||||
{
|
||||
m_spinner->deleteLater();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
|
||||
QJsonObject json = response.object();
|
||||
QJsonObject data = json[QStringLiteral("data")].toObject();
|
||||
m_imageURL.setUrl(data[QStringLiteral("link")].toString());
|
||||
m_deleteImageURL.setUrl(
|
||||
QStringLiteral("https://imgur.com/delete/%1")
|
||||
.arg(data[QStringLiteral("deletehash")].toString()));
|
||||
if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
|
||||
QApplication::clipboard()->setText(m_imageURL.toString());
|
||||
SystemNotification().sendMessage(QObject::tr("URL copied to clipboard."));
|
||||
close();
|
||||
m_spinner->deleteLater();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
|
||||
QJsonObject json = response.object();
|
||||
QJsonObject data = json[QStringLiteral("data")].toObject();
|
||||
m_imageURL.setUrl(data[QStringLiteral("link")].toString());
|
||||
m_deleteImageURL.setUrl(
|
||||
QStringLiteral("https://imgur.com/delete/%1")
|
||||
.arg(data[QStringLiteral("deletehash")].toString()));
|
||||
if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
|
||||
QApplication::clipboard()->setText(m_imageURL.toString());
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("URL copied to clipboard."));
|
||||
close();
|
||||
} else {
|
||||
onUploadOk();
|
||||
}
|
||||
} else {
|
||||
onUploadOk();
|
||||
m_infoLabel->setText(reply->errorString());
|
||||
}
|
||||
} else {
|
||||
m_infoLabel->setText(reply->errorString());
|
||||
}
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::startDrag()
|
||||
void ImgurUploader::startDrag()
|
||||
{
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
mimeData->setUrls(QList<QUrl>{ m_imageURL });
|
||||
mimeData->setImageData(m_pixmap);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
mimeData->setUrls(QList<QUrl>{ m_imageURL });
|
||||
mimeData->setImageData(m_pixmap);
|
||||
|
||||
QDrag* dragHandler = new QDrag(this);
|
||||
dragHandler->setMimeData(mimeData);
|
||||
dragHandler->setPixmap(m_pixmap.scaled(
|
||||
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
||||
dragHandler->exec();
|
||||
QDrag* dragHandler = new QDrag(this);
|
||||
dragHandler->setMimeData(mimeData);
|
||||
dragHandler->setPixmap(m_pixmap.scaled(
|
||||
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
||||
dragHandler->exec();
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::upload()
|
||||
void ImgurUploader::upload()
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
m_pixmap.save(&buffer, "PNG");
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
m_pixmap.save(&buffer, "PNG");
|
||||
|
||||
QUrlQuery urlQuery;
|
||||
urlQuery.addQueryItem(QStringLiteral("title"),
|
||||
QStringLiteral("flameshot_screenshot"));
|
||||
QString description = FileNameHandler().parsedPattern();
|
||||
urlQuery.addQueryItem(QStringLiteral("description"), description);
|
||||
QUrlQuery urlQuery;
|
||||
urlQuery.addQueryItem(QStringLiteral("title"),
|
||||
QStringLiteral("flameshot_screenshot"));
|
||||
QString description = FileNameHandler().parsedPattern();
|
||||
urlQuery.addQueryItem(QStringLiteral("description"), description);
|
||||
|
||||
QUrl url(QStringLiteral("https://api.imgur.com/3/image"));
|
||||
url.setQuery(urlQuery);
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
"application/application/x-www-form-urlencoded");
|
||||
request.setRawHeader(
|
||||
"Authorization",
|
||||
QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8());
|
||||
QUrl url(QStringLiteral("https://api.imgur.com/3/image"));
|
||||
url.setQuery(urlQuery);
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
"application/application/x-www-form-urlencoded");
|
||||
request.setRawHeader(
|
||||
"Authorization",
|
||||
QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8());
|
||||
|
||||
m_NetworkAM->post(request, byteArray);
|
||||
m_NetworkAM->post(request, byteArray);
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::onUploadOk()
|
||||
void ImgurUploader::onUploadOk()
|
||||
{
|
||||
m_infoLabel->deleteLater();
|
||||
m_infoLabel->deleteLater();
|
||||
|
||||
m_notification = new NotificationWidget();
|
||||
m_vLayout->addWidget(m_notification);
|
||||
m_notification = new NotificationWidget();
|
||||
m_vLayout->addWidget(m_notification);
|
||||
|
||||
ImageLabel* imageLabel = new ImageLabel();
|
||||
imageLabel->setScreenshot(m_pixmap);
|
||||
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
connect(
|
||||
imageLabel, &ImageLabel::dragInitiated, this, &ImgurUploader::startDrag);
|
||||
m_vLayout->addWidget(imageLabel);
|
||||
ImageLabel* imageLabel = new ImageLabel();
|
||||
imageLabel->setScreenshot(m_pixmap);
|
||||
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
connect(
|
||||
imageLabel, &ImageLabel::dragInitiated, this, &ImgurUploader::startDrag);
|
||||
m_vLayout->addWidget(imageLabel);
|
||||
|
||||
m_hLayout = new QHBoxLayout();
|
||||
m_vLayout->addLayout(m_hLayout);
|
||||
m_hLayout = new QHBoxLayout();
|
||||
m_vLayout->addLayout(m_hLayout);
|
||||
|
||||
m_copyUrlButton = new QPushButton(tr("Copy URL"));
|
||||
m_openUrlButton = new QPushButton(tr("Open URL"));
|
||||
m_openDeleteUrlButton = new QPushButton(tr("Delete image"));
|
||||
m_toClipboardButton = new QPushButton(tr("Image to Clipboard."));
|
||||
m_hLayout->addWidget(m_copyUrlButton);
|
||||
m_hLayout->addWidget(m_openUrlButton);
|
||||
m_hLayout->addWidget(m_openDeleteUrlButton);
|
||||
m_hLayout->addWidget(m_toClipboardButton);
|
||||
m_copyUrlButton = new QPushButton(tr("Copy URL"));
|
||||
m_openUrlButton = new QPushButton(tr("Open URL"));
|
||||
m_openDeleteUrlButton = new QPushButton(tr("Delete image"));
|
||||
m_toClipboardButton = new QPushButton(tr("Image to Clipboard."));
|
||||
m_hLayout->addWidget(m_copyUrlButton);
|
||||
m_hLayout->addWidget(m_openUrlButton);
|
||||
m_hLayout->addWidget(m_openDeleteUrlButton);
|
||||
m_hLayout->addWidget(m_toClipboardButton);
|
||||
|
||||
connect(
|
||||
m_copyUrlButton, &QPushButton::clicked, this, &ImgurUploader::copyURL);
|
||||
connect(
|
||||
m_openUrlButton, &QPushButton::clicked, this, &ImgurUploader::openURL);
|
||||
connect(m_openDeleteUrlButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&ImgurUploader::openDeleteURL);
|
||||
connect(m_toClipboardButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&ImgurUploader::copyImage);
|
||||
connect(
|
||||
m_copyUrlButton, &QPushButton::clicked, this, &ImgurUploader::copyURL);
|
||||
connect(
|
||||
m_openUrlButton, &QPushButton::clicked, this, &ImgurUploader::openURL);
|
||||
connect(m_openDeleteUrlButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&ImgurUploader::openDeleteURL);
|
||||
connect(m_toClipboardButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&ImgurUploader::copyImage);
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::openURL()
|
||||
void ImgurUploader::openURL()
|
||||
{
|
||||
bool successful = QDesktopServices::openUrl(m_imageURL);
|
||||
if (!successful) {
|
||||
m_notification->showMessage(tr("Unable to open the URL."));
|
||||
}
|
||||
bool successful = QDesktopServices::openUrl(m_imageURL);
|
||||
if (!successful) {
|
||||
m_notification->showMessage(tr("Unable to open the URL."));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::copyURL()
|
||||
void ImgurUploader::copyURL()
|
||||
{
|
||||
QApplication::clipboard()->setText(m_imageURL.toString());
|
||||
m_notification->showMessage(tr("URL copied to clipboard."));
|
||||
QApplication::clipboard()->setText(m_imageURL.toString());
|
||||
m_notification->showMessage(tr("URL copied to clipboard."));
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::openDeleteURL()
|
||||
void ImgurUploader::openDeleteURL()
|
||||
{
|
||||
bool successful = QDesktopServices::openUrl(m_deleteImageURL);
|
||||
if (!successful) {
|
||||
m_notification->showMessage(tr("Unable to open the URL."));
|
||||
}
|
||||
bool successful = QDesktopServices::openUrl(m_deleteImageURL);
|
||||
if (!successful) {
|
||||
m_notification->showMessage(tr("Unable to open the URL."));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploader::copyImage()
|
||||
void ImgurUploader::copyImage()
|
||||
{
|
||||
QApplication::clipboard()->setPixmap(m_pixmap);
|
||||
m_notification->showMessage(tr("Screenshot copied to clipboard."));
|
||||
QApplication::clipboard()->setPixmap(m_pixmap);
|
||||
m_notification->showMessage(tr("Screenshot copied to clipboard."));
|
||||
}
|
||||
|
||||
@@ -32,37 +32,37 @@ class NotificationWidget;
|
||||
|
||||
class ImgurUploader : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImgurUploader(const QPixmap& capture, QWidget* parent = nullptr);
|
||||
explicit ImgurUploader(const QPixmap& capture, QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void handleReply(QNetworkReply* reply);
|
||||
void startDrag();
|
||||
void handleReply(QNetworkReply* reply);
|
||||
void startDrag();
|
||||
|
||||
void openURL();
|
||||
void copyURL();
|
||||
void openDeleteURL();
|
||||
void copyImage();
|
||||
void openURL();
|
||||
void copyURL();
|
||||
void openDeleteURL();
|
||||
void copyImage();
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QNetworkAccessManager* m_NetworkAM;
|
||||
QPixmap m_pixmap;
|
||||
QNetworkAccessManager* m_NetworkAM;
|
||||
|
||||
QVBoxLayout* m_vLayout;
|
||||
QHBoxLayout* m_hLayout;
|
||||
// loading
|
||||
QLabel* m_infoLabel;
|
||||
LoadSpinner* m_spinner;
|
||||
// uploaded
|
||||
QPushButton* m_openUrlButton;
|
||||
QPushButton* m_openDeleteUrlButton;
|
||||
QPushButton* m_copyUrlButton;
|
||||
QPushButton* m_toClipboardButton;
|
||||
QUrl m_imageURL;
|
||||
QUrl m_deleteImageURL;
|
||||
NotificationWidget* m_notification;
|
||||
QVBoxLayout* m_vLayout;
|
||||
QHBoxLayout* m_hLayout;
|
||||
// loading
|
||||
QLabel* m_infoLabel;
|
||||
LoadSpinner* m_spinner;
|
||||
// uploaded
|
||||
QPushButton* m_openUrlButton;
|
||||
QPushButton* m_openDeleteUrlButton;
|
||||
QPushButton* m_copyUrlButton;
|
||||
QPushButton* m_toClipboardButton;
|
||||
QUrl m_imageURL;
|
||||
QUrl m_deleteImageURL;
|
||||
NotificationWidget* m_notification;
|
||||
|
||||
void upload();
|
||||
void onUploadOk();
|
||||
void upload();
|
||||
void onUploadOk();
|
||||
};
|
||||
|
||||
@@ -23,52 +23,44 @@ ImgurUploaderTool::ImgurUploaderTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
ImgurUploaderTool::closeOnButtonPressed() const
|
||||
bool ImgurUploaderTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
}
|
||||
QString
|
||||
ImgurUploaderTool::name() const
|
||||
QString ImgurUploaderTool::name() const
|
||||
{
|
||||
return tr("Image Uploader");
|
||||
return tr("Image Uploader");
|
||||
}
|
||||
|
||||
ToolType
|
||||
ImgurUploaderTool::nameID() const
|
||||
ToolType ImgurUploaderTool::nameID() const
|
||||
{
|
||||
return ToolType::IMGUR;
|
||||
return ToolType::IMGUR;
|
||||
}
|
||||
|
||||
QString
|
||||
ImgurUploaderTool::description() const
|
||||
QString ImgurUploaderTool::description() const
|
||||
{
|
||||
return tr("Upload the selection to Imgur");
|
||||
return tr("Upload the selection to Imgur");
|
||||
}
|
||||
|
||||
QWidget*
|
||||
ImgurUploaderTool::widget()
|
||||
QWidget* ImgurUploaderTool::widget()
|
||||
{
|
||||
return new ImgurUploader(capture);
|
||||
return new ImgurUploader(capture);
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
ImgurUploaderTool::copy(QObject* parent)
|
||||
CaptureTool* ImgurUploaderTool::copy(QObject* parent)
|
||||
{
|
||||
return new ImgurUploaderTool(parent);
|
||||
return new ImgurUploaderTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
ImgurUploaderTool::pressed(const CaptureContext& context)
|
||||
void ImgurUploaderTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
@@ -21,26 +21,26 @@
|
||||
|
||||
class ImgurUploaderTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImgurUploaderTool(QObject* parent = nullptr);
|
||||
explicit ImgurUploaderTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap capture;
|
||||
QPixmap capture;
|
||||
};
|
||||
|
||||
@@ -22,52 +22,44 @@ AppLauncher::AppLauncher(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
AppLauncher::closeOnButtonPressed() const
|
||||
bool AppLauncher::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
AppLauncher::icon(const QColor& background, bool inEditor) const
|
||||
QIcon AppLauncher::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "open_with.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "open_with.svg");
|
||||
}
|
||||
QString
|
||||
AppLauncher::name() const
|
||||
QString AppLauncher::name() const
|
||||
{
|
||||
return tr("App Launcher");
|
||||
return tr("App Launcher");
|
||||
}
|
||||
|
||||
ToolType
|
||||
AppLauncher::nameID() const
|
||||
ToolType AppLauncher::nameID() const
|
||||
{
|
||||
return ToolType::LAUNCHER;
|
||||
return ToolType::LAUNCHER;
|
||||
}
|
||||
|
||||
QString
|
||||
AppLauncher::description() const
|
||||
QString AppLauncher::description() const
|
||||
{
|
||||
return tr("Choose an app to open the capture");
|
||||
return tr("Choose an app to open the capture");
|
||||
}
|
||||
|
||||
QWidget*
|
||||
AppLauncher::widget()
|
||||
QWidget* AppLauncher::widget()
|
||||
{
|
||||
return new AppLauncherWidget(capture);
|
||||
return new AppLauncherWidget(capture);
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
AppLauncher::copy(QObject* parent)
|
||||
CaptureTool* AppLauncher::copy(QObject* parent)
|
||||
{
|
||||
return new AppLauncher(parent);
|
||||
return new AppLauncher(parent);
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncher::pressed(const CaptureContext& context)
|
||||
void AppLauncher::pressed(const CaptureContext& context)
|
||||
{
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
@@ -21,26 +21,26 @@
|
||||
|
||||
class AppLauncher : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncher(QObject* parent = nullptr);
|
||||
explicit AppLauncher(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap capture;
|
||||
QPixmap capture;
|
||||
};
|
||||
|
||||
@@ -51,218 +51,213 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap& p, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_pixmap(p)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("Open With"));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("Open With"));
|
||||
|
||||
m_keepOpen = ConfigHandler().keepOpenAppLauncherValue();
|
||||
m_keepOpen = ConfigHandler().keepOpenAppLauncherValue();
|
||||
|
||||
QString dirLocal = QDir::homePath() + "/.local/share/applications/";
|
||||
QDir appsDirLocal(dirLocal);
|
||||
m_parser.processDirectory(appsDirLocal);
|
||||
QString dirLocal = QDir::homePath() + "/.local/share/applications/";
|
||||
QDir appsDirLocal(dirLocal);
|
||||
m_parser.processDirectory(appsDirLocal);
|
||||
|
||||
QString dir = QStringLiteral("/usr/share/applications/");
|
||||
QDir appsDir(dir);
|
||||
m_parser.processDirectory(appsDir);
|
||||
QString dir = QStringLiteral("/usr/share/applications/");
|
||||
QDir appsDir(dir);
|
||||
m_parser.processDirectory(appsDir);
|
||||
|
||||
initAppMap();
|
||||
initListWidget();
|
||||
initAppMap();
|
||||
initListWidget();
|
||||
|
||||
m_terminalCheckbox = new QCheckBox(tr("Launch in terminal"), this);
|
||||
m_keepOpenCheckbox = new QCheckBox(tr("Keep open after selection"), this);
|
||||
m_keepOpenCheckbox->setChecked(ConfigHandler().keepOpenAppLauncherValue());
|
||||
connect(m_keepOpenCheckbox,
|
||||
&QCheckBox::clicked,
|
||||
this,
|
||||
&AppLauncherWidget::checkboxClicked);
|
||||
m_terminalCheckbox = new QCheckBox(tr("Launch in terminal"), this);
|
||||
m_keepOpenCheckbox = new QCheckBox(tr("Keep open after selection"), this);
|
||||
m_keepOpenCheckbox->setChecked(ConfigHandler().keepOpenAppLauncherValue());
|
||||
connect(m_keepOpenCheckbox,
|
||||
&QCheckBox::clicked,
|
||||
this,
|
||||
&AppLauncherWidget::checkboxClicked);
|
||||
|
||||
// search items
|
||||
m_lineEdit = new QLineEdit;
|
||||
connect(m_lineEdit,
|
||||
&QLineEdit::textChanged,
|
||||
this,
|
||||
&AppLauncherWidget::searchChanged);
|
||||
m_filterList = new QListWidget;
|
||||
m_filterList->hide();
|
||||
configureListView(m_filterList);
|
||||
connect(
|
||||
m_filterList, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->addWidget(m_filterList);
|
||||
m_layout->addWidget(m_tabWidget);
|
||||
m_layout->addWidget(m_lineEdit);
|
||||
m_layout->addWidget(m_keepOpenCheckbox);
|
||||
m_layout->addWidget(m_terminalCheckbox);
|
||||
m_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::launch(const QModelIndex& index)
|
||||
{
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
m_tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to write in") + QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
QString command = index.data(Qt::UserRole)
|
||||
.toString()
|
||||
.replace(QRegExp("(\\%.)"), '"' + m_tempFile + '"');
|
||||
|
||||
QString app_name = index.data(Qt::UserRole).toString().split(" ").at(0);
|
||||
bool inTerminal =
|
||||
index.data(Qt::UserRole + 1).toBool() || m_terminalCheckbox->isChecked();
|
||||
if (inTerminal) {
|
||||
bool ok = TerminalLauncher::launchDetached(command);
|
||||
if (!ok) {
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to launch in terminal."));
|
||||
}
|
||||
} else {
|
||||
QProcess::startDetached(app_name, { m_tempFile });
|
||||
}
|
||||
if (!m_keepOpen) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::checkboxClicked(const bool enabled)
|
||||
{
|
||||
m_keepOpen = enabled;
|
||||
ConfigHandler().setKeepOpenAppLauncher(enabled);
|
||||
m_keepOpenCheckbox->setChecked(enabled);
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::searchChanged(const QString& text)
|
||||
{
|
||||
if (text.isEmpty()) {
|
||||
// search items
|
||||
m_lineEdit = new QLineEdit;
|
||||
connect(m_lineEdit,
|
||||
&QLineEdit::textChanged,
|
||||
this,
|
||||
&AppLauncherWidget::searchChanged);
|
||||
m_filterList = new QListWidget;
|
||||
m_filterList->hide();
|
||||
m_tabWidget->show();
|
||||
} else {
|
||||
m_tabWidget->hide();
|
||||
m_filterList->show();
|
||||
m_filterList->clear();
|
||||
QRegExp regexp(text, Qt::CaseInsensitive, QRegExp::Wildcard);
|
||||
QVector<DesktopAppData> apps;
|
||||
configureListView(m_filterList);
|
||||
connect(
|
||||
m_filterList, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->addWidget(m_filterList);
|
||||
m_layout->addWidget(m_tabWidget);
|
||||
m_layout->addWidget(m_lineEdit);
|
||||
m_layout->addWidget(m_keepOpenCheckbox);
|
||||
m_layout->addWidget(m_terminalCheckbox);
|
||||
m_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void AppLauncherWidget::launch(const QModelIndex& index)
|
||||
{
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
m_tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to write in") + QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
QString command = index.data(Qt::UserRole)
|
||||
.toString()
|
||||
.replace(QRegExp("(\\%.)"), '"' + m_tempFile + '"');
|
||||
|
||||
QString app_name = index.data(Qt::UserRole).toString().split(" ").at(0);
|
||||
bool inTerminal =
|
||||
index.data(Qt::UserRole + 1).toBool() || m_terminalCheckbox->isChecked();
|
||||
if (inTerminal) {
|
||||
bool ok = TerminalLauncher::launchDetached(command);
|
||||
if (!ok) {
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to launch in terminal."));
|
||||
}
|
||||
} else {
|
||||
QProcess::startDetached(app_name, { m_tempFile });
|
||||
}
|
||||
if (!m_keepOpen) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::checkboxClicked(const bool enabled)
|
||||
{
|
||||
m_keepOpen = enabled;
|
||||
ConfigHandler().setKeepOpenAppLauncher(enabled);
|
||||
m_keepOpenCheckbox->setChecked(enabled);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::searchChanged(const QString& text)
|
||||
{
|
||||
if (text.isEmpty()) {
|
||||
m_filterList->hide();
|
||||
m_tabWidget->show();
|
||||
} else {
|
||||
m_tabWidget->hide();
|
||||
m_filterList->show();
|
||||
m_filterList->clear();
|
||||
QRegExp regexp(text, Qt::CaseInsensitive, QRegExp::Wildcard);
|
||||
QVector<DesktopAppData> apps;
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString& cat = i.first;
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
for (const DesktopAppData& app : appList) {
|
||||
if (!apps.contains(app) && (app.name.contains(regexp) ||
|
||||
app.description.contains(regexp))) {
|
||||
apps.append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
addAppsToListWidget(m_filterList, apps);
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::initListWidget()
|
||||
{
|
||||
m_tabWidget = new QTabWidget;
|
||||
const int size = GlobalValues::buttonBaseSize();
|
||||
m_tabWidget->setIconSize(QSize(size, size));
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString& cat = i.first;
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
for (const DesktopAppData& app : appList) {
|
||||
if (!apps.contains(app) &&
|
||||
(app.name.contains(regexp) || app.description.contains(regexp))) {
|
||||
apps.append(app);
|
||||
const QString& cat = i.first;
|
||||
const QString& iconName = i.second;
|
||||
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QListWidget* itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
addAppsToListWidget(itemsWidget, appList);
|
||||
|
||||
m_tabWidget->addTab(
|
||||
itemsWidget, QIcon::fromTheme(iconName), QLatin1String(""));
|
||||
m_tabWidget->setTabToolTip(m_tabWidget->count(), cat);
|
||||
if (cat == QLatin1String("Graphics")) {
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
addAppsToListWidget(m_filterList, apps);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::initListWidget()
|
||||
void AppLauncherWidget::initAppMap()
|
||||
{
|
||||
m_tabWidget = new QTabWidget;
|
||||
const int size = GlobalValues::buttonBaseSize();
|
||||
m_tabWidget->setIconSize(QSize(size, size));
|
||||
QStringList categories({ "AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
"Graphics",
|
||||
"Network",
|
||||
"Office",
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility" });
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString& cat = i.first;
|
||||
const QString& iconName = i.second;
|
||||
m_appsMap = m_parser.getAppsByCategory(categories);
|
||||
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
// Unify multimedia.
|
||||
QVector<DesktopAppData> multimediaList;
|
||||
QStringList multimediaNames;
|
||||
multimediaNames << QStringLiteral("AudioVideo") << QStringLiteral("Audio")
|
||||
<< QStringLiteral("Video");
|
||||
for (const QString& name : multimediaNames) {
|
||||
if (!m_appsMap.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : m_appsMap[name]) {
|
||||
if (!multimediaList.contains(i)) {
|
||||
multimediaList.append(i);
|
||||
}
|
||||
}
|
||||
m_appsMap.remove(name);
|
||||
}
|
||||
|
||||
QListWidget* itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
addAppsToListWidget(itemsWidget, appList);
|
||||
|
||||
m_tabWidget->addTab(
|
||||
itemsWidget, QIcon::fromTheme(iconName), QLatin1String(""));
|
||||
m_tabWidget->setTabToolTip(m_tabWidget->count(), cat);
|
||||
if (cat == QLatin1String("Graphics")) {
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
|
||||
}
|
||||
}
|
||||
m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList);
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::initAppMap()
|
||||
void AppLauncherWidget::configureListView(QListWidget* widget)
|
||||
{
|
||||
QStringList categories({ "AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
"Graphics",
|
||||
"Network",
|
||||
"Office",
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility" });
|
||||
|
||||
m_appsMap = m_parser.getAppsByCategory(categories);
|
||||
|
||||
// Unify multimedia.
|
||||
QVector<DesktopAppData> multimediaList;
|
||||
QStringList multimediaNames;
|
||||
multimediaNames << QStringLiteral("AudioVideo") << QStringLiteral("Audio")
|
||||
<< QStringLiteral("Video");
|
||||
for (const QString& name : multimediaNames) {
|
||||
if (!m_appsMap.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : m_appsMap[name]) {
|
||||
if (!multimediaList.contains(i)) {
|
||||
multimediaList.append(i);
|
||||
}
|
||||
}
|
||||
m_appsMap.remove(name);
|
||||
}
|
||||
m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList);
|
||||
widget->setItemDelegate(new LauncherItemDelegate());
|
||||
widget->setViewMode(QListWidget::IconMode);
|
||||
widget->setResizeMode(QListView::Adjust);
|
||||
widget->setSpacing(4);
|
||||
widget->setFlow(QListView::LeftToRight);
|
||||
widget->setDragEnabled(false);
|
||||
widget->setMinimumWidth(GlobalValues::buttonBaseSize() * 11);
|
||||
connect(widget, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
}
|
||||
|
||||
void
|
||||
AppLauncherWidget::configureListView(QListWidget* widget)
|
||||
void AppLauncherWidget::addAppsToListWidget(
|
||||
QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList)
|
||||
{
|
||||
widget->setItemDelegate(new LauncherItemDelegate());
|
||||
widget->setViewMode(QListWidget::IconMode);
|
||||
widget->setResizeMode(QListView::Adjust);
|
||||
widget->setSpacing(4);
|
||||
widget->setFlow(QListView::LeftToRight);
|
||||
widget->setDragEnabled(false);
|
||||
widget->setMinimumWidth(GlobalValues::buttonBaseSize() * 11);
|
||||
connect(widget, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
}
|
||||
for (const DesktopAppData& app : appList) {
|
||||
QListWidgetItem* buttonItem = new QListWidgetItem(widget);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole + 1, app.showInTerminal);
|
||||
QColor foregroundColor =
|
||||
this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
void
|
||||
AppLauncherWidget::addAppsToListWidget(QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList)
|
||||
{
|
||||
for (const DesktopAppData& app : appList) {
|
||||
QListWidgetItem* buttonItem = new QListWidgetItem(widget);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole + 1, app.showInTerminal);
|
||||
QColor foregroundColor = this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
buttonItem->setIcon(app.icon);
|
||||
buttonItem->setText(app.name);
|
||||
buttonItem->setToolTip(app.description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,31 +29,31 @@ class QListWidget;
|
||||
|
||||
class AppLauncherWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncherWidget(const QPixmap& p, QWidget* parent = nullptr);
|
||||
explicit AppLauncherWidget(const QPixmap& p, QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void launch(const QModelIndex& index);
|
||||
void checkboxClicked(const bool enabled);
|
||||
void searchChanged(const QString& text);
|
||||
void launch(const QModelIndex& index);
|
||||
void checkboxClicked(const bool enabled);
|
||||
void searchChanged(const QString& text);
|
||||
|
||||
private:
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget* widget);
|
||||
void addAppsToListWidget(QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList);
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget* widget);
|
||||
void addAppsToListWidget(QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList);
|
||||
|
||||
DesktopFileParser m_parser;
|
||||
QPixmap m_pixmap;
|
||||
QString m_tempFile;
|
||||
bool m_keepOpen;
|
||||
QMap<QString, QVector<DesktopAppData>> m_appsMap;
|
||||
QCheckBox* m_keepOpenCheckbox;
|
||||
QCheckBox* m_terminalCheckbox;
|
||||
QVBoxLayout* m_layout;
|
||||
QLineEdit* m_lineEdit;
|
||||
QListWidget* m_filterList;
|
||||
QTabWidget* m_tabWidget;
|
||||
DesktopFileParser m_parser;
|
||||
QPixmap m_pixmap;
|
||||
QString m_tempFile;
|
||||
bool m_keepOpen;
|
||||
QMap<QString, QVector<DesktopAppData>> m_appsMap;
|
||||
QCheckBox* m_keepOpenCheckbox;
|
||||
QCheckBox* m_terminalCheckbox;
|
||||
QVBoxLayout* m_layout;
|
||||
QLineEdit* m_lineEdit;
|
||||
QListWidget* m_filterList;
|
||||
QTabWidget* m_tabWidget;
|
||||
};
|
||||
|
||||
@@ -23,45 +23,44 @@ LauncherItemDelegate::LauncherItemDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{}
|
||||
|
||||
void
|
||||
LauncherItemDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
void LauncherItemDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
const QRect& rect = option.rect;
|
||||
if (option.state & (QStyle::State_Selected | QStyle::State_MouseOver)) {
|
||||
painter->save();
|
||||
painter->setPen(Qt::transparent);
|
||||
painter->setBrush(QPalette().highlight());
|
||||
painter->drawRect(rect.x(), rect.y(), rect.width() - 1, rect.height() - 1);
|
||||
painter->restore();
|
||||
}
|
||||
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
const QRect& rect = option.rect;
|
||||
if (option.state & (QStyle::State_Selected | QStyle::State_MouseOver)) {
|
||||
painter->save();
|
||||
painter->setPen(Qt::transparent);
|
||||
painter->setBrush(QPalette().highlight());
|
||||
painter->drawRect(
|
||||
rect.x(), rect.y(), rect.width() - 1, rect.height() - 1);
|
||||
painter->restore();
|
||||
}
|
||||
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
|
||||
const int iconSide = GlobalValues::buttonBaseSize() * 1.3;
|
||||
const int halfIcon = iconSide / 2;
|
||||
const int halfWidth = rect.width() / 2;
|
||||
const int halfHeight = rect.height() / 2;
|
||||
QSize size(iconSide, iconSide);
|
||||
QPixmap pixIcon = icon.pixmap(size).scaled(size, Qt::KeepAspectRatio);
|
||||
painter->drawPixmap(rect.x() + (halfWidth - halfIcon),
|
||||
rect.y() + (halfHeight / 2 - halfIcon),
|
||||
iconSide,
|
||||
iconSide,
|
||||
pixIcon);
|
||||
const QRect textRect(
|
||||
rect.x(), rect.y() + halfHeight, rect.width(), halfHeight);
|
||||
painter->drawText(textRect,
|
||||
Qt::TextWordWrap | Qt::AlignHCenter,
|
||||
index.data(Qt::DisplayRole).toString());
|
||||
const int iconSide = GlobalValues::buttonBaseSize() * 1.3;
|
||||
const int halfIcon = iconSide / 2;
|
||||
const int halfWidth = rect.width() / 2;
|
||||
const int halfHeight = rect.height() / 2;
|
||||
QSize size(iconSide, iconSide);
|
||||
QPixmap pixIcon = icon.pixmap(size).scaled(size, Qt::KeepAspectRatio);
|
||||
painter->drawPixmap(rect.x() + (halfWidth - halfIcon),
|
||||
rect.y() + (halfHeight / 2 - halfIcon),
|
||||
iconSide,
|
||||
iconSide,
|
||||
pixIcon);
|
||||
const QRect textRect(
|
||||
rect.x(), rect.y() + halfHeight, rect.width(), halfHeight);
|
||||
painter->drawText(textRect,
|
||||
Qt::TextWordWrap | Qt::AlignHCenter,
|
||||
index.data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
QSize
|
||||
LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
QSize LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
const int size = GlobalValues::buttonBaseSize();
|
||||
return QSize(size * 3.2, size * 3.7);
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
const int size = GlobalValues::buttonBaseSize();
|
||||
return QSize(size * 3.2, size * 3.7);
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
|
||||
class LauncherItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LauncherItemDelegate(QObject* parent = nullptr);
|
||||
explicit LauncherItemDelegate(QObject* parent = nullptr);
|
||||
|
||||
void paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
void paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
@@ -33,28 +33,28 @@
|
||||
#include "src/tools/launcher/applauncherwidget.h"
|
||||
#endif
|
||||
|
||||
void
|
||||
showOpenWithMenu(const QPixmap& capture)
|
||||
void showOpenWithMenu(const QPixmap& capture)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
QString tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = capture.save(tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(nullptr,
|
||||
QObject::tr("Error"),
|
||||
QObject::tr("Unable to write in") + QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
QString tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = capture.save(tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(nullptr,
|
||||
QObject::tr("Error"),
|
||||
QObject::tr("Unable to write in") +
|
||||
QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
|
||||
OPENASINFO info;
|
||||
auto wStringFile = tempFile.replace("/", "\\").toStdWString();
|
||||
info.pcszFile = wStringFile.c_str();
|
||||
info.pcszClass = nullptr;
|
||||
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
|
||||
SHOpenWithDialog(nullptr, &info);
|
||||
OPENASINFO info;
|
||||
auto wStringFile = tempFile.replace("/", "\\").toStdWString();
|
||||
info.pcszFile = wStringFile.c_str();
|
||||
info.pcszClass = nullptr;
|
||||
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
|
||||
SHOpenWithDialog(nullptr, &info);
|
||||
#else
|
||||
auto w = new AppLauncherWidget(capture);
|
||||
w->show();
|
||||
auto w = new AppLauncherWidget(capture);
|
||||
w->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -19,5 +19,4 @@
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
void
|
||||
showOpenWithMenu(const QPixmap& capture);
|
||||
void showOpenWithMenu(const QPixmap& capture);
|
||||
|
||||
@@ -23,18 +23,18 @@
|
||||
|
||||
namespace {
|
||||
static const TerminalApp terminalApps[] = {
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
{ "gnome-terminal", "--" },
|
||||
{ "terminator", "-e" },
|
||||
{ "terminology", "-e" },
|
||||
{ "tilix", "-e" },
|
||||
{ "xterm", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
{ "gnome-terminal", "--" },
|
||||
{ "terminator", "-e" },
|
||||
{ "terminology", "-e" },
|
||||
{ "tilix", "-e" },
|
||||
{ "xterm", "-e" },
|
||||
{ "aterm", "-e" },
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,24 +42,22 @@ TerminalLauncher::TerminalLauncher(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
TerminalApp
|
||||
TerminalLauncher::getPreferedTerminal()
|
||||
TerminalApp TerminalLauncher::getPreferedTerminal()
|
||||
{
|
||||
TerminalApp res;
|
||||
for (const TerminalApp& app : terminalApps) {
|
||||
QString path = QStandardPaths::findExecutable(app.name);
|
||||
if (!path.isEmpty()) {
|
||||
res = app;
|
||||
break;
|
||||
TerminalApp res;
|
||||
for (const TerminalApp& app : terminalApps) {
|
||||
QString path = QStandardPaths::findExecutable(app.name);
|
||||
if (!path.isEmpty()) {
|
||||
res = app;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
TerminalLauncher::launchDetached(const QString& command)
|
||||
bool TerminalLauncher::launchDetached(const QString& command)
|
||||
{
|
||||
TerminalApp app = getPreferedTerminal();
|
||||
QString s = app.name + " " + app.arg + " " + command;
|
||||
return QProcess::startDetached(app.name, { app.arg, command });
|
||||
TerminalApp app = getPreferedTerminal();
|
||||
QString s = app.name + " " + app.arg + " " + command;
|
||||
return QProcess::startDetached(app.name, { app.arg, command });
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@
|
||||
|
||||
struct TerminalApp
|
||||
{
|
||||
QString name;
|
||||
QString arg;
|
||||
QString name;
|
||||
QString arg;
|
||||
};
|
||||
|
||||
class TerminalLauncher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TerminalLauncher(QObject* parent = nullptr);
|
||||
explicit TerminalLauncher(QObject* parent = nullptr);
|
||||
|
||||
static bool launchDetached(const QString& command);
|
||||
static bool launchDetached(const QString& command);
|
||||
|
||||
private:
|
||||
static TerminalApp getPreferedTerminal();
|
||||
static TerminalApp getPreferedTerminal();
|
||||
};
|
||||
|
||||
@@ -27,68 +27,62 @@ namespace {
|
||||
LineTool::LineTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
LineTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon LineTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "line.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "line.svg");
|
||||
}
|
||||
QString
|
||||
LineTool::name() const
|
||||
QString LineTool::name() const
|
||||
{
|
||||
return tr("Line");
|
||||
return tr("Line");
|
||||
}
|
||||
|
||||
ToolType
|
||||
LineTool::nameID() const
|
||||
ToolType LineTool::nameID() const
|
||||
{
|
||||
return ToolType::LINE;
|
||||
return ToolType::LINE;
|
||||
}
|
||||
|
||||
QString
|
||||
LineTool::description() const
|
||||
QString LineTool::description() const
|
||||
{
|
||||
return tr("Set the Line as the paint tool");
|
||||
return tr("Set the Line as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
LineTool::copy(QObject* parent)
|
||||
CaptureTool* LineTool::copy(QObject* parent)
|
||||
{
|
||||
return new LineTool(parent);
|
||||
return new LineTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
LineTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void LineTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
}
|
||||
|
||||
void
|
||||
LineTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void LineTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
LineTool::drawStart(const CaptureContext& context)
|
||||
void LineTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
LineTool::pressed(const CaptureContext& context)
|
||||
void LineTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
|
||||
class LineTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LineTool(QObject* parent = nullptr);
|
||||
explicit LineTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -27,78 +27,71 @@ namespace {
|
||||
MarkerTool::MarkerTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
MarkerTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon MarkerTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "marker.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "marker.svg");
|
||||
}
|
||||
QString
|
||||
MarkerTool::name() const
|
||||
QString MarkerTool::name() const
|
||||
{
|
||||
return tr("Marker");
|
||||
return tr("Marker");
|
||||
}
|
||||
|
||||
ToolType
|
||||
MarkerTool::nameID() const
|
||||
ToolType MarkerTool::nameID() const
|
||||
{
|
||||
return ToolType::MARKER;
|
||||
return ToolType::MARKER;
|
||||
}
|
||||
|
||||
QString
|
||||
MarkerTool::description() const
|
||||
QString MarkerTool::description() const
|
||||
{
|
||||
return tr("Set the Marker as the paint tool");
|
||||
return tr("Set the Marker as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
MarkerTool::copy(QObject* parent)
|
||||
CaptureTool* MarkerTool::copy(QObject* parent)
|
||||
{
|
||||
return new MarkerTool(parent);
|
||||
return new MarkerTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
MarkerTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void MarkerTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
||||
painter.setOpacity(0.35);
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
||||
painter.setOpacity(0.35);
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
}
|
||||
|
||||
void
|
||||
MarkerTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void MarkerTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
||||
painter.setOpacity(0.35);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
||||
painter.setOpacity(0.35);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
MarkerTool::drawStart(const CaptureContext& context)
|
||||
void MarkerTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
MarkerTool::pressed(const CaptureContext& context)
|
||||
void MarkerTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void
|
||||
MarkerTool::thicknessChanged(const int th)
|
||||
void MarkerTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th + PADDING_VALUE;
|
||||
m_thickness = th + PADDING_VALUE;
|
||||
}
|
||||
|
||||
@@ -21,26 +21,26 @@
|
||||
|
||||
class MarkerTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MarkerTool(QObject* parent = nullptr);
|
||||
explicit MarkerTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
};
|
||||
|
||||
@@ -22,45 +22,38 @@ MoveTool::MoveTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
MoveTool::closeOnButtonPressed() const
|
||||
bool MoveTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
MoveTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon MoveTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cursor-move.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cursor-move.svg");
|
||||
}
|
||||
QString
|
||||
MoveTool::name() const
|
||||
QString MoveTool::name() const
|
||||
{
|
||||
return tr("Move");
|
||||
return tr("Move");
|
||||
}
|
||||
|
||||
ToolType
|
||||
MoveTool::nameID() const
|
||||
ToolType MoveTool::nameID() const
|
||||
{
|
||||
return ToolType::MOVE;
|
||||
return ToolType::MOVE;
|
||||
}
|
||||
|
||||
QString
|
||||
MoveTool::description() const
|
||||
QString MoveTool::description() const
|
||||
{
|
||||
return tr("Move the selection area");
|
||||
return tr("Move the selection area");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
MoveTool::copy(QObject* parent)
|
||||
CaptureTool* MoveTool::copy(QObject* parent)
|
||||
{
|
||||
return new MoveTool(parent);
|
||||
return new MoveTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
MoveTool::pressed(const CaptureContext& context)
|
||||
void MoveTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_MOVE_MODE);
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_MOVE_MODE);
|
||||
}
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
|
||||
class MoveTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MoveTool(QObject* parent = nullptr);
|
||||
explicit MoveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
ToolType nameID() const override;
|
||||
QString description() const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
ToolType nameID() const override;
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,65 +22,59 @@ PencilTool::PencilTool(QObject* parent)
|
||||
: AbstractPathTool(parent)
|
||||
{}
|
||||
|
||||
QIcon
|
||||
PencilTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon PencilTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pencil.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pencil.svg");
|
||||
}
|
||||
QString
|
||||
PencilTool::name() const
|
||||
QString PencilTool::name() const
|
||||
{
|
||||
return tr("Pencil");
|
||||
return tr("Pencil");
|
||||
}
|
||||
|
||||
ToolType
|
||||
PencilTool::nameID() const
|
||||
ToolType PencilTool::nameID() const
|
||||
{
|
||||
return ToolType::PENCIL;
|
||||
return ToolType::PENCIL;
|
||||
}
|
||||
|
||||
QString
|
||||
PencilTool::description() const
|
||||
QString PencilTool::description() const
|
||||
{
|
||||
return tr("Set the Pencil as the paint tool");
|
||||
return tr("Set the Pencil as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
PencilTool::copy(QObject* parent)
|
||||
CaptureTool* PencilTool::copy(QObject* parent)
|
||||
{
|
||||
return new PencilTool(parent);
|
||||
return new PencilTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
PencilTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void PencilTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawPolyline(m_points.data(), m_points.size());
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawPolyline(m_points.data(), m_points.size());
|
||||
}
|
||||
|
||||
void
|
||||
PencilTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void PencilTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, context.thickness + 2));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, context.thickness + 2));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
PencilTool::drawStart(const CaptureContext& context)
|
||||
void PencilTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + 2;
|
||||
m_points.append(context.mousePos);
|
||||
m_backupArea.setTopLeft(context.mousePos);
|
||||
m_backupArea.setBottomRight(context.mousePos);
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + 2;
|
||||
m_points.append(context.mousePos);
|
||||
m_backupArea.setTopLeft(context.mousePos);
|
||||
m_backupArea.setBottomRight(context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
PencilTool::pressed(const CaptureContext& context)
|
||||
void PencilTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,26 +21,26 @@
|
||||
|
||||
class PencilTool : public AbstractPathTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PencilTool(QObject* parent = nullptr);
|
||||
explicit PencilTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,58 +22,50 @@ PinTool::PinTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
PinTool::closeOnButtonPressed() const
|
||||
bool PinTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
PinTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon PinTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pin.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pin.svg");
|
||||
}
|
||||
QString
|
||||
PinTool::name() const
|
||||
QString PinTool::name() const
|
||||
{
|
||||
return tr("Pin Tool");
|
||||
return tr("Pin Tool");
|
||||
}
|
||||
|
||||
ToolType
|
||||
PinTool::nameID() const
|
||||
ToolType PinTool::nameID() const
|
||||
{
|
||||
return ToolType::PIN;
|
||||
return ToolType::PIN;
|
||||
}
|
||||
|
||||
QString
|
||||
PinTool::description() const
|
||||
QString PinTool::description() const
|
||||
{
|
||||
return tr("Pin image on the desktop");
|
||||
return tr("Pin image on the desktop");
|
||||
}
|
||||
|
||||
QWidget*
|
||||
PinTool::widget()
|
||||
QWidget* PinTool::widget()
|
||||
{
|
||||
PinWidget* w = new PinWidget(m_pixmap);
|
||||
const int&& m = w->margin();
|
||||
QRect adjusted_pos = m_geometry + QMargins(m, m, m, m);
|
||||
w->setGeometry(adjusted_pos);
|
||||
return w;
|
||||
PinWidget* w = new PinWidget(m_pixmap);
|
||||
const int&& m = w->margin();
|
||||
QRect adjusted_pos = m_geometry + QMargins(m, m, m, m);
|
||||
w->setGeometry(adjusted_pos);
|
||||
return w;
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
PinTool::copy(QObject* parent)
|
||||
CaptureTool* PinTool::copy(QObject* parent)
|
||||
{
|
||||
return new PinTool(parent);
|
||||
return new PinTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
PinTool::pressed(const CaptureContext& context)
|
||||
void PinTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
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_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);
|
||||
}
|
||||
|
||||
@@ -21,27 +21,27 @@
|
||||
|
||||
class PinTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinTool(QObject* parent = nullptr);
|
||||
explicit PinTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QRect m_geometry;
|
||||
QPixmap m_pixmap;
|
||||
QRect m_geometry;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
@@ -27,93 +27,85 @@ PinWidget::PinWidget(const QPixmap& pixmap, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_pixmap(pixmap)
|
||||
{
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
// set the bottom widget background transparent
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
// set the bottom widget background transparent
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
ConfigHandler conf;
|
||||
m_baseColor = conf.uiMainColorValue();
|
||||
m_hoverColor = conf.uiContrastColorValue();
|
||||
ConfigHandler conf;
|
||||
m_baseColor = conf.uiMainColorValue();
|
||||
m_hoverColor = conf.uiContrastColorValue();
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
const int margin = this->margin();
|
||||
m_layout->setContentsMargins(margin, margin, margin, margin);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
const int margin = this->margin();
|
||||
m_layout->setContentsMargins(margin, margin, margin, margin);
|
||||
|
||||
m_shadowEffect = new QGraphicsDropShadowEffect(this);
|
||||
m_shadowEffect->setColor(m_baseColor);
|
||||
m_shadowEffect->setBlurRadius(2 * margin);
|
||||
m_shadowEffect->setOffset(0, 0);
|
||||
setGraphicsEffect(m_shadowEffect);
|
||||
m_shadowEffect = new QGraphicsDropShadowEffect(this);
|
||||
m_shadowEffect->setColor(m_baseColor);
|
||||
m_shadowEffect->setBlurRadius(2 * margin);
|
||||
m_shadowEffect->setOffset(0, 0);
|
||||
setGraphicsEffect(m_shadowEffect);
|
||||
|
||||
m_label = new QLabel();
|
||||
m_label->setPixmap(m_pixmap);
|
||||
m_layout->addWidget(m_label);
|
||||
m_label = new QLabel();
|
||||
m_label->setPixmap(m_pixmap);
|
||||
m_layout->addWidget(m_label);
|
||||
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
}
|
||||
|
||||
int
|
||||
PinWidget::margin() const
|
||||
int PinWidget::margin() const
|
||||
{
|
||||
return 7;
|
||||
return 7;
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::wheelEvent(QWheelEvent* e)
|
||||
void PinWidget::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
int val = e->angleDelta().y() > 0 ? 15 : -15;
|
||||
int newWidth = qBound(50, m_label->width() + val, maximumWidth());
|
||||
int newHeight = qBound(50, m_label->height() + val, maximumHeight());
|
||||
int val = e->angleDelta().y() > 0 ? 15 : -15;
|
||||
int newWidth = qBound(50, m_label->width() + val, maximumWidth());
|
||||
int newHeight = qBound(50, m_label->height() + val, maximumHeight());
|
||||
|
||||
QSize size(newWidth, newHeight);
|
||||
setScaledPixmap(size);
|
||||
adjustSize();
|
||||
QSize size(newWidth, newHeight);
|
||||
setScaledPixmap(size);
|
||||
adjustSize();
|
||||
|
||||
e->accept();
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::enterEvent(QEvent*)
|
||||
void PinWidget::enterEvent(QEvent*)
|
||||
{
|
||||
m_shadowEffect->setColor(m_hoverColor);
|
||||
m_shadowEffect->setColor(m_hoverColor);
|
||||
}
|
||||
void
|
||||
PinWidget::leaveEvent(QEvent*)
|
||||
void PinWidget::leaveEvent(QEvent*)
|
||||
{
|
||||
m_shadowEffect->setColor(m_baseColor);
|
||||
m_shadowEffect->setColor(m_baseColor);
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::mouseDoubleClickEvent(QMouseEvent*)
|
||||
void PinWidget::mouseDoubleClickEvent(QMouseEvent*)
|
||||
{
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::mousePressEvent(QMouseEvent* e)
|
||||
void PinWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
m_dragStart = e->globalPos();
|
||||
m_offsetX = e->localPos().x() / width();
|
||||
m_offsetY = e->localPos().y() / height();
|
||||
m_dragStart = e->globalPos();
|
||||
m_offsetX = e->localPos().x() / width();
|
||||
m_offsetY = e->localPos().y() / height();
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
void PinWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
const QPoint delta = e->globalPos() - m_dragStart;
|
||||
int offsetW = width() * m_offsetX;
|
||||
int offsetH = height() * m_offsetY;
|
||||
move(m_dragStart.x() + delta.x() - offsetW,
|
||||
m_dragStart.y() + delta.y() - offsetH);
|
||||
const QPoint delta = e->globalPos() - m_dragStart;
|
||||
int offsetW = width() * m_offsetX;
|
||||
int offsetH = height() * m_offsetY;
|
||||
move(m_dragStart.x() + delta.x() - offsetW,
|
||||
m_dragStart.y() + delta.y() - offsetH);
|
||||
}
|
||||
|
||||
void
|
||||
PinWidget::setScaledPixmap(const QSize& size)
|
||||
void PinWidget::setScaledPixmap(const QSize& size)
|
||||
{
|
||||
const qreal scale = qApp->devicePixelRatio();
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(
|
||||
size * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
scaledPixmap.setDevicePixelRatio(scale);
|
||||
m_label->setPixmap(scaledPixmap);
|
||||
const qreal scale = qApp->devicePixelRatio();
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(
|
||||
size * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
scaledPixmap.setDevicePixelRatio(scale);
|
||||
m_label->setPixmap(scaledPixmap);
|
||||
}
|
||||
|
||||
@@ -25,28 +25,28 @@ class QLabel;
|
||||
|
||||
class PinWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinWidget(const QPixmap& pixmap, QWidget* parent = nullptr);
|
||||
explicit PinWidget(const QPixmap& pixmap, QWidget* parent = nullptr);
|
||||
|
||||
int margin() const;
|
||||
int margin() const;
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void mouseDoubleClickEvent(QMouseEvent*);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void enterEvent(QEvent*);
|
||||
void leaveEvent(QEvent*);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void mouseDoubleClickEvent(QMouseEvent*);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void enterEvent(QEvent*);
|
||||
void leaveEvent(QEvent*);
|
||||
|
||||
private:
|
||||
void setScaledPixmap(const QSize& size);
|
||||
void setScaledPixmap(const QSize& size);
|
||||
|
||||
QPixmap m_pixmap;
|
||||
QVBoxLayout* m_layout;
|
||||
QLabel* m_label;
|
||||
QPoint m_dragStart;
|
||||
qreal m_offsetX, m_offsetY;
|
||||
QGraphicsDropShadowEffect* m_shadowEffect;
|
||||
QColor m_baseColor, m_hoverColor;
|
||||
QPixmap m_pixmap;
|
||||
QVBoxLayout* m_layout;
|
||||
QLabel* m_label;
|
||||
QPoint m_dragStart;
|
||||
qreal m_offsetX, m_offsetY;
|
||||
QGraphicsDropShadowEffect* m_shadowEffect;
|
||||
QColor m_baseColor, m_hoverColor;
|
||||
};
|
||||
|
||||
@@ -28,95 +28,88 @@ PixelateTool::PixelateTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{}
|
||||
|
||||
QIcon
|
||||
PixelateTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon PixelateTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pixelate.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pixelate.svg");
|
||||
}
|
||||
QString
|
||||
PixelateTool::name() const
|
||||
QString PixelateTool::name() const
|
||||
{
|
||||
return tr("Pixelate");
|
||||
return tr("Pixelate");
|
||||
}
|
||||
|
||||
ToolType
|
||||
PixelateTool::nameID() const
|
||||
ToolType PixelateTool::nameID() const
|
||||
{
|
||||
return ToolType::PIXELATE;
|
||||
return ToolType::PIXELATE;
|
||||
}
|
||||
|
||||
QString
|
||||
PixelateTool::description() const
|
||||
QString PixelateTool::description() const
|
||||
{
|
||||
return tr("Set Pixelate as the paint tool");
|
||||
return tr("Set Pixelate as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
PixelateTool::copy(QObject* parent)
|
||||
CaptureTool* PixelateTool::copy(QObject* parent)
|
||||
{
|
||||
return new PixelateTool(parent);
|
||||
return new PixelateTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
PixelateTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void PixelateTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
|
||||
QPoint& p0 = m_points.first;
|
||||
QPoint& p1 = m_points.second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
QPoint& p0 = m_points.first;
|
||||
QPoint& p1 = m_points.second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
|
||||
// If thickness is less than 1, use old blur process
|
||||
if (m_thickness <= 1) {
|
||||
auto pixelRatio = pixmap.devicePixelRatio();
|
||||
// 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();
|
||||
QRect selectionScaled =
|
||||
QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
|
||||
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
|
||||
blur->setBlurRadius(10);
|
||||
QGraphicsPixmapItem* item =
|
||||
new QGraphicsPixmapItem(pixmap.copy(selectionScaled));
|
||||
item->setGraphicsEffect(blur);
|
||||
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
|
||||
blur->setBlurRadius(10);
|
||||
QGraphicsPixmapItem* item =
|
||||
new QGraphicsPixmapItem(pixmap.copy(selectionScaled));
|
||||
item->setGraphicsEffect(blur);
|
||||
|
||||
QGraphicsScene scene;
|
||||
scene.addItem(item);
|
||||
QGraphicsScene scene;
|
||||
scene.addItem(item);
|
||||
|
||||
scene.render(&painter, selection, QRectF());
|
||||
blur->setBlurRadius(12);
|
||||
scene.render(&painter, selection, QRectF());
|
||||
} else {
|
||||
int width = selection.width() * (0.5 / qMax(1, m_thickness));
|
||||
scene.render(&painter, selection, QRectF());
|
||||
blur->setBlurRadius(12);
|
||||
scene.render(&painter, selection, QRectF());
|
||||
} else {
|
||||
int width = selection.width() * (0.5 / qMax(1, m_thickness));
|
||||
|
||||
QPixmap t = pixmap.copy(selection);
|
||||
t = t.scaledToWidth(qMax(width, 10), Qt::SmoothTransformation);
|
||||
t = t.scaledToWidth(selection.width());
|
||||
painter.drawImage(selection, t.toImage());
|
||||
}
|
||||
QPixmap t = pixmap.copy(selection);
|
||||
t = t.scaledToWidth(qMax(width, 10), Qt::SmoothTransformation);
|
||||
t = t.scaledToWidth(selection.width());
|
||||
painter.drawImage(selection, t.toImage());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PixelateTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
void PixelateTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(painter);
|
||||
}
|
||||
|
||||
void
|
||||
PixelateTool::drawStart(const CaptureContext& context)
|
||||
void PixelateTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_thickness = context.thickness;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_thickness = context.thickness;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
PixelateTool::pressed(const CaptureContext& context)
|
||||
void PixelateTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
|
||||
class PixelateTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PixelateTool(QObject* parent = nullptr);
|
||||
explicit PixelateTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -25,71 +25,62 @@ namespace {
|
||||
RectangleTool::RectangleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
RectangleTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon RectangleTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square.svg");
|
||||
}
|
||||
QString
|
||||
RectangleTool::name() const
|
||||
QString RectangleTool::name() const
|
||||
{
|
||||
return tr("Rectangle");
|
||||
return tr("Rectangle");
|
||||
}
|
||||
|
||||
ToolType
|
||||
RectangleTool::nameID() const
|
||||
ToolType RectangleTool::nameID() const
|
||||
{
|
||||
return ToolType::RECTANGLE;
|
||||
return ToolType::RECTANGLE;
|
||||
}
|
||||
|
||||
QString
|
||||
RectangleTool::description() const
|
||||
QString RectangleTool::description() const
|
||||
{
|
||||
return tr("Set the Rectangle as the paint tool");
|
||||
return tr("Set the Rectangle as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
RectangleTool::copy(QObject* parent)
|
||||
CaptureTool* RectangleTool::copy(QObject* parent)
|
||||
{
|
||||
return new RectangleTool(parent);
|
||||
return new RectangleTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
RectangleTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
void RectangleTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.setBrush(QBrush(m_color));
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.setBrush(QBrush(m_color));
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void
|
||||
RectangleTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
void RectangleTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
RectangleTool::drawStart(const CaptureContext& context)
|
||||
void RectangleTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
RectangleTool::pressed(const CaptureContext& context)
|
||||
void RectangleTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
|
||||
class RectangleTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RectangleTool(QObject* parent = nullptr);
|
||||
explicit RectangleTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,45 +22,38 @@ RedoTool::RedoTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
RedoTool::closeOnButtonPressed() const
|
||||
bool RedoTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
RedoTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon RedoTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "redo-variant.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "redo-variant.svg");
|
||||
}
|
||||
QString
|
||||
RedoTool::name() const
|
||||
QString RedoTool::name() const
|
||||
{
|
||||
return tr("Redo");
|
||||
return tr("Redo");
|
||||
}
|
||||
|
||||
ToolType
|
||||
RedoTool::nameID() const
|
||||
ToolType RedoTool::nameID() const
|
||||
{
|
||||
return ToolType::REDO;
|
||||
return ToolType::REDO;
|
||||
}
|
||||
|
||||
QString
|
||||
RedoTool::description() const
|
||||
QString RedoTool::description() const
|
||||
{
|
||||
return tr("Redo the next modification");
|
||||
return tr("Redo the next modification");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
RedoTool::copy(QObject* parent)
|
||||
CaptureTool* RedoTool::copy(QObject* parent)
|
||||
{
|
||||
return new RedoTool(parent);
|
||||
return new RedoTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
RedoTool::pressed(const CaptureContext& context)
|
||||
void RedoTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_REDO_MODIFICATION);
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_REDO_MODIFICATION);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class RedoTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RedoTool(QObject* parent = nullptr);
|
||||
explicit RedoTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -23,57 +23,50 @@ SaveTool::SaveTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
SaveTool::closeOnButtonPressed() const
|
||||
bool SaveTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon
|
||||
SaveTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon SaveTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-save.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-save.svg");
|
||||
}
|
||||
QString
|
||||
SaveTool::name() const
|
||||
QString SaveTool::name() const
|
||||
{
|
||||
return tr("Save");
|
||||
return tr("Save");
|
||||
}
|
||||
|
||||
ToolType
|
||||
SaveTool::nameID() const
|
||||
ToolType SaveTool::nameID() const
|
||||
{
|
||||
return ToolType::SAVE;
|
||||
return ToolType::SAVE;
|
||||
}
|
||||
|
||||
QString
|
||||
SaveTool::description() const
|
||||
QString SaveTool::description() const
|
||||
{
|
||||
return tr("Save the capture");
|
||||
return tr("Save the capture");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
SaveTool::copy(QObject* parent)
|
||||
CaptureTool* SaveTool::copy(QObject* parent)
|
||||
{
|
||||
return new SaveTool(parent);
|
||||
return new SaveTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
SaveTool::pressed(const CaptureContext& context)
|
||||
void SaveTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
if (context.savePath.isEmpty()) {
|
||||
emit requestAction(REQ_HIDE_GUI);
|
||||
bool ok =
|
||||
ScreenshotSaver().saveToFilesystemGUI(context.selectedScreenshotArea());
|
||||
if (ok) {
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
if (context.savePath.isEmpty()) {
|
||||
emit requestAction(REQ_HIDE_GUI);
|
||||
bool ok = ScreenshotSaver().saveToFilesystemGUI(
|
||||
context.selectedScreenshotArea());
|
||||
if (ok) {
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
}
|
||||
} else {
|
||||
bool ok = ScreenshotSaver().saveToFilesystem(
|
||||
context.selectedScreenshotArea(), context.savePath, "");
|
||||
if (ok) {
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool ok = ScreenshotSaver().saveToFilesystem(
|
||||
context.selectedScreenshotArea(), context.savePath, "");
|
||||
if (ok) {
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class SaveTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SaveTool(QObject* parent = nullptr);
|
||||
explicit SaveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -25,76 +25,66 @@ namespace {
|
||||
SelectionTool::SelectionTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
bool
|
||||
SelectionTool::closeOnButtonPressed() const
|
||||
bool SelectionTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
SelectionTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon SelectionTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square-outline.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square-outline.svg");
|
||||
}
|
||||
QString
|
||||
SelectionTool::name() const
|
||||
QString SelectionTool::name() const
|
||||
{
|
||||
return tr("Rectangular Selection");
|
||||
return tr("Rectangular Selection");
|
||||
}
|
||||
|
||||
ToolType
|
||||
SelectionTool::nameID() const
|
||||
ToolType SelectionTool::nameID() const
|
||||
{
|
||||
return ToolType::SELECTION;
|
||||
return ToolType::SELECTION;
|
||||
}
|
||||
|
||||
QString
|
||||
SelectionTool::description() const
|
||||
QString SelectionTool::description() const
|
||||
{
|
||||
return tr("Set Selection as the paint tool");
|
||||
return tr("Set Selection as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
SelectionTool::copy(QObject* parent)
|
||||
CaptureTool* SelectionTool::copy(QObject* parent)
|
||||
{
|
||||
return new SelectionTool(parent);
|
||||
return new SelectionTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
SelectionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
void SelectionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void
|
||||
SelectionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
void SelectionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void
|
||||
SelectionTool::drawStart(const CaptureContext& context)
|
||||
void SelectionTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void
|
||||
SelectionTool::pressed(const CaptureContext& context)
|
||||
void SelectionTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,27 +21,27 @@
|
||||
|
||||
class SelectionTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SelectionTool(QObject* parent = nullptr);
|
||||
explicit SelectionTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,44 +22,37 @@ SizeIndicatorTool::SizeIndicatorTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
SizeIndicatorTool::closeOnButtonPressed() const
|
||||
bool SizeIndicatorTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
SizeIndicatorTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon SizeIndicatorTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
return inEditor ? QIcon()
|
||||
: QIcon(iconPath(background) + "size_indicator.svg");
|
||||
return inEditor ? QIcon()
|
||||
: QIcon(iconPath(background) + "size_indicator.svg");
|
||||
}
|
||||
QString
|
||||
SizeIndicatorTool::name() const
|
||||
QString SizeIndicatorTool::name() const
|
||||
{
|
||||
return tr("Selection Size Indicator");
|
||||
return tr("Selection Size Indicator");
|
||||
}
|
||||
|
||||
ToolType
|
||||
SizeIndicatorTool::nameID() const
|
||||
ToolType SizeIndicatorTool::nameID() const
|
||||
{
|
||||
return ToolType::SIZEINDICATOR;
|
||||
return ToolType::SIZEINDICATOR;
|
||||
}
|
||||
|
||||
QString
|
||||
SizeIndicatorTool::description() const
|
||||
QString SizeIndicatorTool::description() const
|
||||
{
|
||||
return tr("Show the dimensions of the selection (X Y)");
|
||||
return tr("Show the dimensions of the selection (X Y)");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
SizeIndicatorTool::copy(QObject* parent)
|
||||
CaptureTool* SizeIndicatorTool::copy(QObject* parent)
|
||||
{
|
||||
return new SizeIndicatorTool(parent);
|
||||
return new SizeIndicatorTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
SizeIndicatorTool::pressed(const CaptureContext& context)
|
||||
void SizeIndicatorTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class SizeIndicatorTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SizeIndicatorTool(QObject* parent = nullptr);
|
||||
explicit SizeIndicatorTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -27,98 +27,93 @@
|
||||
TextConfig::TextConfig(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
|
||||
QFontDatabase fontDB;
|
||||
QComboBox* fontsCB = new QComboBox();
|
||||
connect(fontsCB,
|
||||
&QComboBox::currentTextChanged,
|
||||
this,
|
||||
&TextConfig::fontFamilyChanged);
|
||||
fontsCB->addItems(fontDB.families());
|
||||
// TODO save family in config
|
||||
int index = fontsCB->findText(font().family());
|
||||
fontsCB->setCurrentIndex(index);
|
||||
QFontDatabase fontDB;
|
||||
QComboBox* fontsCB = new QComboBox();
|
||||
connect(fontsCB,
|
||||
&QComboBox::currentTextChanged,
|
||||
this,
|
||||
&TextConfig::fontFamilyChanged);
|
||||
fontsCB->addItems(fontDB.families());
|
||||
// TODO save family in config
|
||||
int index = fontsCB->findText(font().family());
|
||||
fontsCB->setCurrentIndex(index);
|
||||
|
||||
QString iconPrefix = ColorUtils::colorIsDark(palette().windowText().color())
|
||||
? PathInfo::blackIconPath()
|
||||
: PathInfo::whiteIconPath();
|
||||
QString iconPrefix = ColorUtils::colorIsDark(palette().windowText().color())
|
||||
? PathInfo::blackIconPath()
|
||||
: PathInfo::whiteIconPath();
|
||||
|
||||
m_strikeOutButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_strikethrough.svg"), QLatin1String(""));
|
||||
m_strikeOutButton->setCheckable(true);
|
||||
connect(m_strikeOutButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontStrikeOutChanged);
|
||||
m_strikeOutButton->setToolTip(tr("StrikeOut"));
|
||||
m_strikeOutButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_strikethrough.svg"), QLatin1String(""));
|
||||
m_strikeOutButton->setCheckable(true);
|
||||
connect(m_strikeOutButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontStrikeOutChanged);
|
||||
m_strikeOutButton->setToolTip(tr("StrikeOut"));
|
||||
|
||||
m_underlineButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_underlined.svg"), QLatin1String(""));
|
||||
m_underlineButton->setCheckable(true);
|
||||
connect(m_underlineButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontUnderlineChanged);
|
||||
m_underlineButton->setToolTip(tr("Underline"));
|
||||
m_underlineButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_underlined.svg"), QLatin1String(""));
|
||||
m_underlineButton->setCheckable(true);
|
||||
connect(m_underlineButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontUnderlineChanged);
|
||||
m_underlineButton->setToolTip(tr("Underline"));
|
||||
|
||||
m_weightButton =
|
||||
new QPushButton(QIcon(iconPrefix + "format_bold.svg"), QLatin1String(""));
|
||||
m_weightButton->setCheckable(true);
|
||||
connect(m_weightButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::weightButtonPressed);
|
||||
m_weightButton->setToolTip(tr("Bold"));
|
||||
m_weightButton =
|
||||
new QPushButton(QIcon(iconPrefix + "format_bold.svg"), QLatin1String(""));
|
||||
m_weightButton->setCheckable(true);
|
||||
connect(m_weightButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::weightButtonPressed);
|
||||
m_weightButton->setToolTip(tr("Bold"));
|
||||
|
||||
m_italicButton =
|
||||
new QPushButton(QIcon(iconPrefix + "format_italic.svg"), QLatin1String(""));
|
||||
m_italicButton->setCheckable(true);
|
||||
connect(m_italicButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontItalicChanged);
|
||||
m_italicButton->setToolTip(tr("Italic"));
|
||||
QHBoxLayout* modifiersLayout = new QHBoxLayout();
|
||||
m_italicButton = new QPushButton(QIcon(iconPrefix + "format_italic.svg"),
|
||||
QLatin1String(""));
|
||||
m_italicButton->setCheckable(true);
|
||||
connect(m_italicButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontItalicChanged);
|
||||
m_italicButton->setToolTip(tr("Italic"));
|
||||
QHBoxLayout* modifiersLayout = new QHBoxLayout();
|
||||
|
||||
m_layout->addWidget(fontsCB);
|
||||
modifiersLayout->addWidget(m_strikeOutButton);
|
||||
modifiersLayout->addWidget(m_underlineButton);
|
||||
modifiersLayout->addWidget(m_weightButton);
|
||||
modifiersLayout->addWidget(m_italicButton);
|
||||
m_layout->addLayout(modifiersLayout);
|
||||
m_layout->addWidget(fontsCB);
|
||||
modifiersLayout->addWidget(m_strikeOutButton);
|
||||
modifiersLayout->addWidget(m_underlineButton);
|
||||
modifiersLayout->addWidget(m_weightButton);
|
||||
modifiersLayout->addWidget(m_italicButton);
|
||||
m_layout->addLayout(modifiersLayout);
|
||||
}
|
||||
|
||||
void
|
||||
TextConfig::setUnderline(const bool u)
|
||||
void TextConfig::setUnderline(const bool u)
|
||||
{
|
||||
m_underlineButton->setChecked(u);
|
||||
m_underlineButton->setChecked(u);
|
||||
}
|
||||
|
||||
void
|
||||
TextConfig::setStrikeOut(const bool s)
|
||||
void TextConfig::setStrikeOut(const bool s)
|
||||
{
|
||||
m_strikeOutButton->setChecked(s);
|
||||
m_strikeOutButton->setChecked(s);
|
||||
}
|
||||
|
||||
void
|
||||
TextConfig::setWeight(const int w)
|
||||
void TextConfig::setWeight(const int w)
|
||||
{
|
||||
m_weightButton->setChecked(static_cast<QFont::Weight>(w) == QFont::Bold);
|
||||
m_weightButton->setChecked(static_cast<QFont::Weight>(w) == QFont::Bold);
|
||||
}
|
||||
|
||||
void
|
||||
TextConfig::setItalic(const bool i)
|
||||
void TextConfig::setItalic(const bool i)
|
||||
{
|
||||
m_italicButton->setChecked(i);
|
||||
m_italicButton->setChecked(i);
|
||||
}
|
||||
|
||||
void
|
||||
TextConfig::weightButtonPressed(const bool w)
|
||||
void TextConfig::weightButtonPressed(const bool w)
|
||||
{
|
||||
if (w) {
|
||||
emit fontWeightChanged(QFont::Bold);
|
||||
} else {
|
||||
emit fontWeightChanged(QFont::Normal);
|
||||
}
|
||||
if (w) {
|
||||
emit fontWeightChanged(QFont::Bold);
|
||||
} else {
|
||||
emit fontWeightChanged(QFont::Normal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,31 +24,31 @@ class QPushButton;
|
||||
|
||||
class TextConfig : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextConfig(QWidget* parent = nullptr);
|
||||
explicit TextConfig(QWidget* parent = nullptr);
|
||||
|
||||
void setUnderline(const bool u);
|
||||
void setStrikeOut(const bool s);
|
||||
void setWeight(const int w);
|
||||
void setItalic(const bool i);
|
||||
void setUnderline(const bool u);
|
||||
void setStrikeOut(const bool s);
|
||||
void setWeight(const int w);
|
||||
void setItalic(const bool i);
|
||||
|
||||
signals:
|
||||
void fontFamilyChanged(const QString& f);
|
||||
void fontUnderlineChanged(const bool underlined);
|
||||
void fontStrikeOutChanged(const bool dashed);
|
||||
void fontWeightChanged(const QFont::Weight w);
|
||||
void fontItalicChanged(const bool italic);
|
||||
void fontFamilyChanged(const QString& f);
|
||||
void fontUnderlineChanged(const bool underlined);
|
||||
void fontStrikeOutChanged(const bool dashed);
|
||||
void fontWeightChanged(const QFont::Weight w);
|
||||
void fontItalicChanged(const bool italic);
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void weightButtonPressed(const bool w);
|
||||
void weightButtonPressed(const bool w);
|
||||
|
||||
private:
|
||||
QVBoxLayout* m_layout;
|
||||
QPushButton* m_strikeOutButton;
|
||||
QPushButton* m_underlineButton;
|
||||
QPushButton* m_weightButton;
|
||||
QPushButton* m_italicButton;
|
||||
QVBoxLayout* m_layout;
|
||||
QPushButton* m_strikeOutButton;
|
||||
QPushButton* m_underlineButton;
|
||||
QPushButton* m_weightButton;
|
||||
QPushButton* m_italicButton;
|
||||
};
|
||||
|
||||
@@ -26,246 +26,227 @@ TextTool::TextTool(QObject* parent)
|
||||
, m_size(1)
|
||||
{}
|
||||
|
||||
bool
|
||||
TextTool::isValid() const
|
||||
bool TextTool::isValid() const
|
||||
{
|
||||
return !m_text.isEmpty();
|
||||
return !m_text.isEmpty();
|
||||
}
|
||||
|
||||
bool
|
||||
TextTool::closeOnButtonPressed() const
|
||||
bool TextTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
TextTool::isSelectable() const
|
||||
bool TextTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
TextTool::showMousePreview() const
|
||||
bool TextTool::showMousePreview() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
TextTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon TextTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "text.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "text.svg");
|
||||
}
|
||||
|
||||
QString
|
||||
TextTool::name() const
|
||||
QString TextTool::name() const
|
||||
{
|
||||
return tr("Text");
|
||||
return tr("Text");
|
||||
}
|
||||
|
||||
ToolType
|
||||
TextTool::nameID() const
|
||||
ToolType TextTool::nameID() const
|
||||
{
|
||||
return ToolType::TEXT;
|
||||
return ToolType::TEXT;
|
||||
}
|
||||
|
||||
QString
|
||||
TextTool::description() const
|
||||
QString TextTool::description() const
|
||||
{
|
||||
return tr("Add text to your capture");
|
||||
return tr("Add text to your capture");
|
||||
}
|
||||
|
||||
QWidget*
|
||||
TextTool::widget()
|
||||
QWidget* TextTool::widget()
|
||||
{
|
||||
TextWidget* w = new TextWidget();
|
||||
w->setTextColor(m_color);
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
w->setFont(m_font);
|
||||
connect(w, &TextWidget::textUpdated, this, &TextTool::updateText);
|
||||
m_widget = w;
|
||||
return w;
|
||||
TextWidget* w = new TextWidget();
|
||||
w->setTextColor(m_color);
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
w->setFont(m_font);
|
||||
connect(w, &TextWidget::textUpdated, this, &TextTool::updateText);
|
||||
m_widget = w;
|
||||
return w;
|
||||
}
|
||||
|
||||
QWidget*
|
||||
TextTool::configurationWidget()
|
||||
QWidget* TextTool::configurationWidget()
|
||||
{
|
||||
m_confW = new TextConfig();
|
||||
connect(
|
||||
m_confW, &TextConfig::fontFamilyChanged, this, &TextTool::updateFamily);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontItalicChanged, this, &TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
this,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
this,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontWeightChanged, this, &TextTool::updateFontWeight);
|
||||
m_confW->setItalic(m_font.italic());
|
||||
m_confW->setUnderline(m_font.underline());
|
||||
m_confW->setStrikeOut(m_font.strikeOut());
|
||||
m_confW->setWeight(m_font.weight());
|
||||
return m_confW;
|
||||
m_confW = new TextConfig();
|
||||
connect(
|
||||
m_confW, &TextConfig::fontFamilyChanged, this, &TextTool::updateFamily);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontItalicChanged,
|
||||
this,
|
||||
&TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
this,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
this,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontWeightChanged,
|
||||
this,
|
||||
&TextTool::updateFontWeight);
|
||||
m_confW->setItalic(m_font.italic());
|
||||
m_confW->setUnderline(m_font.underline());
|
||||
m_confW->setStrikeOut(m_font.strikeOut());
|
||||
m_confW->setWeight(m_font.weight());
|
||||
return m_confW;
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
TextTool::copy(QObject* parent)
|
||||
CaptureTool* TextTool::copy(QObject* parent)
|
||||
{
|
||||
TextTool* tt = new TextTool(parent);
|
||||
connect(m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontItalicChanged, tt, &TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
tt,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
tt,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontWeightChanged, tt, &TextTool::updateFontWeight);
|
||||
tt->m_font = m_font;
|
||||
return tt;
|
||||
TextTool* tt = new TextTool(parent);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontItalicChanged, tt, &TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
tt,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
tt,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontWeightChanged, tt, &TextTool::updateFontWeight);
|
||||
tt->m_font = m_font;
|
||||
return tt;
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::undo(QPixmap& pixmap)
|
||||
void TextTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup);
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
|
||||
void TextTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (m_text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QFontMetrics fm(m_font);
|
||||
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));
|
||||
}
|
||||
// draw text
|
||||
painter.setFont(m_font);
|
||||
painter.setPen(m_color);
|
||||
painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text);
|
||||
if (m_text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QFontMetrics fm(m_font);
|
||||
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));
|
||||
}
|
||||
// draw text
|
||||
painter.setFont(m_font);
|
||||
painter.setPen(m_color);
|
||||
painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
|
||||
void TextTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::drawEnd(const QPoint& p)
|
||||
void TextTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
m_backupArea.moveTo(p);
|
||||
m_backupArea.moveTo(p);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::drawMove(const QPoint& p)
|
||||
void TextTool::drawMove(const QPoint& p)
|
||||
{
|
||||
m_widget->move(p);
|
||||
m_widget->move(p);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::drawStart(const CaptureContext& context)
|
||||
void TextTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_size = context.thickness;
|
||||
emit requestAction(REQ_ADD_CHILD_WIDGET);
|
||||
m_color = context.color;
|
||||
m_size = context.thickness;
|
||||
emit requestAction(REQ_ADD_CHILD_WIDGET);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::pressed(const CaptureContext& context)
|
||||
void TextTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::colorChanged(const QColor& c)
|
||||
void TextTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
if (m_widget) {
|
||||
m_widget->setTextColor(c);
|
||||
}
|
||||
m_color = c;
|
||||
if (m_widget) {
|
||||
m_widget->setTextColor(c);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::thicknessChanged(const int th)
|
||||
void TextTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_size = th;
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_size = th;
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateText(const QString& s)
|
||||
void TextTool::updateText(const QString& s)
|
||||
{
|
||||
m_text = s;
|
||||
m_text = s;
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::setFont(const QFont& f)
|
||||
void TextTool::setFont(const QFont& f)
|
||||
{
|
||||
m_font = f;
|
||||
if (m_widget) {
|
||||
m_widget->setFont(f);
|
||||
}
|
||||
m_font = f;
|
||||
if (m_widget) {
|
||||
m_widget->setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateFamily(const QString& s)
|
||||
void TextTool::updateFamily(const QString& s)
|
||||
{
|
||||
m_font.setFamily(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_font.setFamily(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateFontUnderline(const bool underlined)
|
||||
void TextTool::updateFontUnderline(const bool underlined)
|
||||
{
|
||||
m_font.setUnderline(underlined);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_font.setUnderline(underlined);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateFontStrikeOut(const bool s)
|
||||
void TextTool::updateFontStrikeOut(const bool s)
|
||||
{
|
||||
m_font.setStrikeOut(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_font.setStrikeOut(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateFontWeight(const QFont::Weight w)
|
||||
void TextTool::updateFontWeight(const QFont::Weight w)
|
||||
{
|
||||
m_font.setWeight(w);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_font.setWeight(w);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTool::updateFontItalic(const bool italic)
|
||||
void TextTool::updateFontItalic(const bool italic)
|
||||
{
|
||||
m_font.setItalic(italic);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
m_font.setItalic(italic);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,57 +25,57 @@ class TextConfig;
|
||||
|
||||
class TextTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextTool(QObject* parent = nullptr);
|
||||
explicit TextTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
QWidget* configurationWidget() override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
QWidget* widget() override;
|
||||
QWidget* configurationWidget() override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
private slots:
|
||||
void updateText(const QString& s);
|
||||
void setFont(const QFont& f);
|
||||
void updateFamily(const QString& s);
|
||||
void updateFontUnderline(const bool underlined);
|
||||
void updateFontStrikeOut(const bool s);
|
||||
void updateFontWeight(const QFont::Weight w);
|
||||
void updateFontItalic(const bool italic);
|
||||
void updateText(const QString& s);
|
||||
void setFont(const QFont& f);
|
||||
void updateFamily(const QString& s);
|
||||
void updateFontUnderline(const bool underlined);
|
||||
void updateFontStrikeOut(const bool s);
|
||||
void updateFontWeight(const QFont::Weight w);
|
||||
void updateFontItalic(const bool italic);
|
||||
|
||||
private:
|
||||
QFont m_font;
|
||||
QString m_text;
|
||||
int m_size;
|
||||
QColor m_color;
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
QPointer<TextWidget> m_widget;
|
||||
QPointer<TextConfig> m_confW;
|
||||
QFont m_font;
|
||||
QString m_text;
|
||||
int m_size;
|
||||
QColor m_color;
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
QPointer<TextWidget> m_widget;
|
||||
QPointer<TextConfig> m_confW;
|
||||
};
|
||||
|
||||
@@ -20,85 +20,77 @@
|
||||
TextWidget::TextWidget(QWidget* parent)
|
||||
: QTextEdit(parent)
|
||||
{
|
||||
setStyleSheet(QStringLiteral("TextWidget { background: transparent; }"));
|
||||
connect(this, &TextWidget::textChanged, this, &TextWidget::adjustSize);
|
||||
connect(this, &TextWidget::textChanged, this, &TextWidget::emitTextUpdated);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setContextMenuPolicy(Qt::NoContextMenu);
|
||||
setStyleSheet(QStringLiteral("TextWidget { background: transparent; }"));
|
||||
connect(this, &TextWidget::textChanged, this, &TextWidget::adjustSize);
|
||||
connect(this, &TextWidget::textChanged, this, &TextWidget::emitTextUpdated);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setContextMenuPolicy(Qt::NoContextMenu);
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::showEvent(QShowEvent* e)
|
||||
void TextWidget::showEvent(QShowEvent* e)
|
||||
{
|
||||
QFont font;
|
||||
QFontMetrics fm(font);
|
||||
setFixedWidth(fm.lineSpacing() * 6);
|
||||
setFixedHeight(fm.lineSpacing() * 2.5);
|
||||
m_baseSize = size();
|
||||
m_minSize = m_baseSize;
|
||||
QTextEdit::showEvent(e);
|
||||
adjustSize();
|
||||
QFont font;
|
||||
QFontMetrics fm(font);
|
||||
setFixedWidth(fm.lineSpacing() * 6);
|
||||
setFixedHeight(fm.lineSpacing() * 2.5);
|
||||
m_baseSize = size();
|
||||
m_minSize = m_baseSize;
|
||||
QTextEdit::showEvent(e);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::resizeEvent(QResizeEvent* e)
|
||||
void TextWidget::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
m_minSize.setHeight(qMin(m_baseSize.height(), height()));
|
||||
m_minSize.setWidth(qMin(m_baseSize.width(), width()));
|
||||
QTextEdit::resizeEvent(e);
|
||||
m_minSize.setHeight(qMin(m_baseSize.height(), height()));
|
||||
m_minSize.setWidth(qMin(m_baseSize.width(), width()));
|
||||
QTextEdit::resizeEvent(e);
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::setFont(const QFont& f)
|
||||
void TextWidget::setFont(const QFont& f)
|
||||
{
|
||||
QTextEdit::setFont(f);
|
||||
adjustSize();
|
||||
QTextEdit::setFont(f);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::updateFont(const QFont& f)
|
||||
void TextWidget::updateFont(const QFont& f)
|
||||
{
|
||||
setFont(f);
|
||||
setFont(f);
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::setFontPointSize(qreal s)
|
||||
void TextWidget::setFontPointSize(qreal s)
|
||||
{
|
||||
QFont f = font();
|
||||
f.setPointSize(s);
|
||||
setFont(f);
|
||||
QFont f = font();
|
||||
f.setPointSize(s);
|
||||
setFont(f);
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::setTextColor(const QColor& c)
|
||||
void TextWidget::setTextColor(const QColor& c)
|
||||
{
|
||||
QString s(
|
||||
QStringLiteral("TextWidget { background: transparent; color: %1; }"));
|
||||
setStyleSheet(s.arg(c.name()));
|
||||
QString s(
|
||||
QStringLiteral("TextWidget { background: transparent; color: %1; }"));
|
||||
setStyleSheet(s.arg(c.name()));
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::adjustSize()
|
||||
void TextWidget::adjustSize()
|
||||
{
|
||||
QString&& text = this->toPlainText();
|
||||
QString&& text = this->toPlainText();
|
||||
|
||||
QFontMetrics fm(font());
|
||||
QRect bounds = fm.boundingRect(QRect(), 0, text);
|
||||
int pixelsWide = bounds.width() + fm.lineSpacing();
|
||||
int pixelsHigh = bounds.height() * 1.15 + fm.lineSpacing();
|
||||
if (pixelsWide < m_minSize.width()) {
|
||||
pixelsWide = m_minSize.width();
|
||||
}
|
||||
if (pixelsHigh < m_minSize.height()) {
|
||||
pixelsHigh = m_minSize.height();
|
||||
}
|
||||
QFontMetrics fm(font());
|
||||
QRect bounds = fm.boundingRect(QRect(), 0, text);
|
||||
int pixelsWide = bounds.width() + fm.lineSpacing();
|
||||
int pixelsHigh = bounds.height() * 1.15 + fm.lineSpacing();
|
||||
if (pixelsWide < m_minSize.width()) {
|
||||
pixelsWide = m_minSize.width();
|
||||
}
|
||||
if (pixelsHigh < m_minSize.height()) {
|
||||
pixelsHigh = m_minSize.height();
|
||||
}
|
||||
|
||||
this->setFixedSize(pixelsWide, pixelsHigh);
|
||||
this->setFixedSize(pixelsWide, pixelsHigh);
|
||||
}
|
||||
|
||||
void
|
||||
TextWidget::emitTextUpdated()
|
||||
void TextWidget::emitTextUpdated()
|
||||
{
|
||||
emit textUpdated(this->toPlainText());
|
||||
emit textUpdated(this->toPlainText());
|
||||
}
|
||||
|
||||
@@ -21,29 +21,29 @@
|
||||
|
||||
class TextWidget : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextWidget(QWidget* parent = nullptr);
|
||||
explicit TextWidget(QWidget* parent = nullptr);
|
||||
|
||||
void adjustSize();
|
||||
void setFont(const QFont& f);
|
||||
void adjustSize();
|
||||
void setFont(const QFont& f);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* e);
|
||||
void resizeEvent(QResizeEvent* e);
|
||||
void showEvent(QShowEvent* e);
|
||||
void resizeEvent(QResizeEvent* e);
|
||||
|
||||
signals:
|
||||
void textUpdated(const QString& s);
|
||||
void textUpdated(const QString& s);
|
||||
|
||||
public slots:
|
||||
void updateFont(const QFont& f);
|
||||
void setTextColor(const QColor& c);
|
||||
void setFontPointSize(qreal s);
|
||||
void updateFont(const QFont& f);
|
||||
void setTextColor(const QColor& c);
|
||||
void setFontPointSize(qreal s);
|
||||
|
||||
private slots:
|
||||
void emitTextUpdated();
|
||||
void emitTextUpdated();
|
||||
|
||||
private:
|
||||
QSize m_baseSize;
|
||||
QSize m_minSize;
|
||||
QSize m_baseSize;
|
||||
QSize m_minSize;
|
||||
};
|
||||
|
||||
@@ -41,75 +41,75 @@ ToolFactory::ToolFactory(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
CaptureTool*
|
||||
ToolFactory::CreateTool(CaptureToolButton::ButtonType t, QObject* parent)
|
||||
CaptureTool* ToolFactory::CreateTool(CaptureToolButton::ButtonType t,
|
||||
QObject* parent)
|
||||
{
|
||||
CaptureTool* tool;
|
||||
switch (t) {
|
||||
case CaptureToolButton::TYPE_ARROW:
|
||||
tool = new ArrowTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_CIRCLE:
|
||||
tool = new CircleTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_COPY:
|
||||
tool = new CopyTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_EXIT:
|
||||
tool = new ExitTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_IMAGEUPLOADER:
|
||||
tool = new ImgurUploaderTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_DRAWER:
|
||||
tool = new LineTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_MARKER:
|
||||
tool = new MarkerTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_MOVESELECTION:
|
||||
tool = new MoveTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PENCIL:
|
||||
tool = new PencilTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_RECTANGLE:
|
||||
tool = new RectangleTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SAVE:
|
||||
tool = new SaveTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SELECTION:
|
||||
tool = new SelectionTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SELECTIONINDICATOR:
|
||||
tool = new SizeIndicatorTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_UNDO:
|
||||
tool = new UndoTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_REDO:
|
||||
tool = new RedoTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_OPEN_APP:
|
||||
tool = new AppLauncher(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PIXELATE:
|
||||
tool = new PixelateTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PIN:
|
||||
tool = new PinTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_TEXT:
|
||||
tool = new TextTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_CIRCLECOUNT:
|
||||
tool = new CircleCountTool(parent);
|
||||
break;
|
||||
CaptureTool* tool;
|
||||
switch (t) {
|
||||
case CaptureToolButton::TYPE_ARROW:
|
||||
tool = new ArrowTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_CIRCLE:
|
||||
tool = new CircleTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_COPY:
|
||||
tool = new CopyTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_EXIT:
|
||||
tool = new ExitTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_IMAGEUPLOADER:
|
||||
tool = new ImgurUploaderTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_DRAWER:
|
||||
tool = new LineTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_MARKER:
|
||||
tool = new MarkerTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_MOVESELECTION:
|
||||
tool = new MoveTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PENCIL:
|
||||
tool = new PencilTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_RECTANGLE:
|
||||
tool = new RectangleTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SAVE:
|
||||
tool = new SaveTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SELECTION:
|
||||
tool = new SelectionTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SELECTIONINDICATOR:
|
||||
tool = new SizeIndicatorTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_UNDO:
|
||||
tool = new UndoTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_REDO:
|
||||
tool = new RedoTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_OPEN_APP:
|
||||
tool = new AppLauncher(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PIXELATE:
|
||||
tool = new PixelateTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_PIN:
|
||||
tool = new PinTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_TEXT:
|
||||
tool = new TextTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_CIRCLECOUNT:
|
||||
tool = new CircleCountTool(parent);
|
||||
break;
|
||||
|
||||
default:
|
||||
tool = nullptr;
|
||||
break;
|
||||
}
|
||||
return tool;
|
||||
default:
|
||||
tool = nullptr;
|
||||
break;
|
||||
}
|
||||
return tool;
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ class CaptureTool;
|
||||
|
||||
class ToolFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ToolFactory(QObject* parent = nullptr);
|
||||
explicit ToolFactory(QObject* parent = nullptr);
|
||||
|
||||
ToolFactory(const ToolFactory&) = delete;
|
||||
ToolFactory& operator=(const ToolFactory&) = delete;
|
||||
ToolFactory(const ToolFactory&) = delete;
|
||||
ToolFactory& operator=(const ToolFactory&) = delete;
|
||||
|
||||
CaptureTool* CreateTool(CaptureToolButton::ButtonType t,
|
||||
QObject* parent = nullptr);
|
||||
CaptureTool* CreateTool(CaptureToolButton::ButtonType t,
|
||||
QObject* parent = nullptr);
|
||||
};
|
||||
|
||||
@@ -22,45 +22,38 @@ UndoTool::UndoTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
UndoTool::closeOnButtonPressed() const
|
||||
bool UndoTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon
|
||||
UndoTool::icon(const QColor& background, bool inEditor) const
|
||||
QIcon UndoTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "undo-variant.svg");
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "undo-variant.svg");
|
||||
}
|
||||
QString
|
||||
UndoTool::name() const
|
||||
QString UndoTool::name() const
|
||||
{
|
||||
return tr("Undo");
|
||||
return tr("Undo");
|
||||
}
|
||||
|
||||
ToolType
|
||||
UndoTool::nameID() const
|
||||
ToolType UndoTool::nameID() const
|
||||
{
|
||||
return ToolType::UNDO;
|
||||
return ToolType::UNDO;
|
||||
}
|
||||
|
||||
QString
|
||||
UndoTool::description() const
|
||||
QString UndoTool::description() const
|
||||
{
|
||||
return tr("Undo the last modification");
|
||||
return tr("Undo the last modification");
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
UndoTool::copy(QObject* parent)
|
||||
CaptureTool* UndoTool::copy(QObject* parent)
|
||||
{
|
||||
return new UndoTool(parent);
|
||||
return new UndoTool(parent);
|
||||
}
|
||||
|
||||
void
|
||||
UndoTool::pressed(const CaptureContext& context)
|
||||
void UndoTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_UNDO_MODIFICATION);
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_UNDO_MODIFICATION);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
|
||||
class UndoTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UndoTool(QObject* parent = nullptr);
|
||||
explicit UndoTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() 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;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
protected:
|
||||
ToolType nameID() const override;
|
||||
ToolType nameID() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user