mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-01-05 16:45:52 +00:00
Add basic code for the Pin tool
This commit is contained in:
@@ -113,6 +113,7 @@ SOURCES += src/main.cpp \
|
||||
src/utils/desktopfileparse.cpp \
|
||||
src/tools/launcher/launcheritemdelegate.cpp \
|
||||
src/tools/blur/blurtool.cpp \
|
||||
src/tools/pin/pintool.cpp \
|
||||
src/tools/launcher/terminallauncher.cpp \
|
||||
src/config/visualseditor.cpp \
|
||||
src/config/extendedslider.cpp \
|
||||
@@ -128,7 +129,8 @@ SOURCES += src/main.cpp \
|
||||
src/utils/globalvalues.cpp \
|
||||
src/widgets/capture/utilitypanel.cpp \
|
||||
src/widgets/capture/hovereventfilter.cpp \
|
||||
src/widgets/capture/selectionwidget.cpp
|
||||
src/widgets/capture/selectionwidget.cpp \
|
||||
src/tools/pin/pinwidget.cpp
|
||||
|
||||
HEADERS += src/widgets/capture/buttonhandler.h \
|
||||
src/widgets/infowindow.h \
|
||||
@@ -178,6 +180,7 @@ HEADERS += src/widgets/capture/buttonhandler.h \
|
||||
src/utils/desktopfileparse.h \
|
||||
src/tools/launcher/launcheritemdelegate.h \
|
||||
src/tools/blur/blurtool.h \
|
||||
src/tools/pin/pintool.h \
|
||||
src/tools/launcher/terminallauncher.h \
|
||||
src/config/visualseditor.h \
|
||||
src/config/extendedslider.h \
|
||||
@@ -193,7 +196,8 @@ HEADERS += src/widgets/capture/buttonhandler.h \
|
||||
src/tools/abstractactiontool.h \
|
||||
src/widgets/capture/utilitypanel.h \
|
||||
src/widgets/capture/hovereventfilter.h \
|
||||
src/widgets/capture/selectionwidget.h
|
||||
src/widgets/capture/selectionwidget.h \
|
||||
src/tools/pin/pinwidget.h
|
||||
|
||||
unix:!macx {
|
||||
SOURCES += src/core/flameshotdbusadapter.cpp \
|
||||
|
||||
@@ -45,5 +45,7 @@
|
||||
<file>img/buttonIconsWhite/blur.png</file>
|
||||
<file>img/buttonIconsBlack/redo-variant.png</file>
|
||||
<file>img/buttonIconsWhite/redo-variant.png</file>
|
||||
<file>img/buttonIconsBlack/pin.png</file>
|
||||
<file>img/buttonIconsWhite/pin.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
img/buttonIconsBlack/pin.png
Normal file
BIN
img/buttonIconsBlack/pin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 218 B |
5
img/buttonIconsBlack/pin.svg
Normal file
5
img/buttonIconsBlack/pin.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="24" height="24" viewBox="0 0 24.00 24.00" enable-background="new 0 0 24.00 24.00" xml:space="preserve">
|
||||
<path fill="#000000" fill-opacity="1" stroke-width="0.2" stroke-linejoin="round" d="M 15.9994,11.9981L 15.9994,3.99807L 16.9994,3.99807L 16.9994,1.99807L 6.99939,1.99807L 6.99939,3.99807L 7.99939,3.99807L 7.99939,11.9981L 5.99939,13.9981L 5.99939,15.9981L 11.1994,15.9981L 11.1994,21.9981L 12.7994,21.9981L 12.7994,15.9981L 17.9994,15.9981L 17.9994,13.9981L 15.9994,11.9981 Z "/>
|
||||
</svg>
|
||||
BIN
img/buttonIconsWhite/pin.png
Normal file
BIN
img/buttonIconsWhite/pin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 230 B |
48
img/buttonIconsWhite/pin.svg
Normal file
48
img/buttonIconsWhite/pin.svg
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24.00 24.00"
|
||||
enable-background="new 0 0 24.00 24.00"
|
||||
xml:space="preserve"
|
||||
id="svg4"
|
||||
sodipodi:docname="pin.svg"
|
||||
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"><metadata
|
||||
id="metadata10"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="640"
|
||||
inkscape:window-height="480"
|
||||
id="namedview6"
|
||||
showgrid="false"
|
||||
inkscape:zoom="9.8333333"
|
||||
inkscape:cx="12"
|
||||
inkscape:cy="12"
|
||||
inkscape:window-x="36"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="svg4" /><path
|
||||
fill="#000000"
|
||||
fill-opacity="1"
|
||||
stroke-width="0.2"
|
||||
stroke-linejoin="round"
|
||||
d="M 15.9994,11.9981L 15.9994,3.99807L 16.9994,3.99807L 16.9994,1.99807L 6.99939,1.99807L 6.99939,3.99807L 7.99939,3.99807L 7.99939,11.9981L 5.99939,13.9981L 5.99939,15.9981L 11.1994,15.9981L 11.1994,21.9981L 12.7994,21.9981L 12.7994,15.9981L 17.9994,15.9981L 17.9994,13.9981L 15.9994,11.9981 Z "
|
||||
id="path2"
|
||||
style="fill:#ffffff" /></svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
62
src/tools/pin/pintool.cpp
Executable file
62
src/tools/pin/pintool.cpp
Executable file
@@ -0,0 +1,62 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pintool.h"
|
||||
#include "src/tools/pin/pinwidget.h"
|
||||
|
||||
PinTool::PinTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
|
||||
}
|
||||
|
||||
bool PinTool::closeOnButtonPressed() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon PinTool::icon(const QColor &background, bool inEditor) const {
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pin.png");
|
||||
}
|
||||
QString PinTool::name() const {
|
||||
return tr("Pin Tool");
|
||||
}
|
||||
|
||||
QString PinTool::nameID() {
|
||||
return "";
|
||||
}
|
||||
|
||||
QString PinTool::description() const {
|
||||
return tr("Pin image on the desktop");
|
||||
}
|
||||
|
||||
QWidget* PinTool::widget() {
|
||||
PinWidget *w = new PinWidget(m_pixmap);
|
||||
w->setGeometry(m_geometry);
|
||||
return w;
|
||||
}
|
||||
|
||||
CaptureTool* PinTool::copy(QObject *parent) {
|
||||
return new PinTool(parent);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
44
src/tools/pin/pintool.h
Executable file
44
src/tools/pin/pintool.h
Executable file
@@ -0,0 +1,44 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class PinTool : public AbstractActionTool {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinTool(QObject *parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
|
||||
private:
|
||||
QRect m_geometry;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
75
src/tools/pin/pinwidget.cpp
Normal file
75
src/tools/pin/pinwidget.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pinwidget.h"
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#include <QShortcut>
|
||||
|
||||
PinWidget::PinWidget(const QPixmap &pixmap, QWidget *parent) :
|
||||
QWidget(parent), m_pixmap(pixmap)
|
||||
{
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint
|
||||
| Qt::FramelessWindowHint);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void PinWidget::wheelEvent(QWheelEvent *e) {
|
||||
int val = e->delta() > 0 ? 5 : -5;
|
||||
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();
|
||||
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void PinWidget::mouseDoubleClickEvent(QMouseEvent *) {
|
||||
close();
|
||||
}
|
||||
|
||||
void PinWidget::mousePressEvent(QMouseEvent *e) {
|
||||
m_dragStart = e->globalPos();
|
||||
m_offsetX = e->localPos().x() / width();
|
||||
m_offsetY = e->localPos().y() / height();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
44
src/tools/pin/pinwidget.h
Normal file
44
src/tools/pin/pinwidget.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
class QLabel;
|
||||
|
||||
class PinWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinWidget(const QPixmap &pixmap, QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void mouseDoubleClickEvent(QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
|
||||
private:
|
||||
void setScaledPixmap(const QSize &size);
|
||||
|
||||
QPixmap m_pixmap;
|
||||
QVBoxLayout *m_layout;
|
||||
QLabel *m_label;
|
||||
QPoint m_dragStart;
|
||||
qreal m_offsetX, m_offsetY;
|
||||
};
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "launcher/applaunchertool.h"
|
||||
#include "blur/blurtool.h"
|
||||
#include "redo/redotool.h"
|
||||
#include "pin/pintool.h"
|
||||
|
||||
ToolFactory::ToolFactory(QObject *parent) : QObject(parent) {
|
||||
|
||||
@@ -95,6 +96,9 @@ CaptureTool* ToolFactory::CreateTool(
|
||||
case CaptureButton::TYPE_BLUR:
|
||||
tool = new BlurTool(parent);
|
||||
break;
|
||||
case CaptureButton::TYPE_PIN:
|
||||
tool = new PinTool(parent);
|
||||
break;
|
||||
default:
|
||||
tool = nullptr;
|
||||
break;
|
||||
|
||||
@@ -166,6 +166,7 @@ static std::map<CaptureButton::ButtonType, int> buttonTypeOrder {
|
||||
{ CaptureButton::TYPE_EXIT, 14 },
|
||||
{ CaptureButton::TYPE_IMAGEUPLOADER, 15 },
|
||||
{ CaptureButton::TYPE_OPEN_APP, 16 },
|
||||
{ CaptureButton::TYPE_PIN, 17 },
|
||||
{ CaptureButton::TYPE_BLUR, 7 },
|
||||
{ CaptureButton::TYPE_REDO, 11 },
|
||||
};
|
||||
@@ -193,4 +194,5 @@ QVector<CaptureButton::ButtonType> CaptureButton::iterableButtonTypes = {
|
||||
CaptureButton::TYPE_EXIT,
|
||||
CaptureButton::TYPE_IMAGEUPLOADER,
|
||||
CaptureButton::TYPE_OPEN_APP,
|
||||
CaptureButton::TYPE_PIN,
|
||||
};
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_BLUR = 15,
|
||||
TYPE_REDO = 16,
|
||||
TYPE_PIN = 17,
|
||||
};
|
||||
|
||||
CaptureButton() = delete;
|
||||
|
||||
Reference in New Issue
Block a user