Files
flameshot/src/tools/abstracttwopointtool.cpp
lupoDharkael 5746a58582 Code refactor
More flexible tool API
Minor code format fixes
Clipboard freeze fixed(?)
Arrow correcly growing close to the start point
Improve maintainability
Add undo/redo stack
2018-04-10 15:33:08 +02:00

67 lines
1.9 KiB
C++

// 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 "abstracttwopointtool.h"
bool AbstractTwoPointTool::isValid() const {
return (m_points.first != m_points.second);
}
bool AbstractTwoPointTool::closeOnButtonPressed() const {
return false;
}
bool AbstractTwoPointTool::isSelectable() const {
return true;
}
bool AbstractTwoPointTool::showMousePreview() const {
return true;
}
QWidget *AbstractTwoPointTool::widget() {
return nullptr;
}
QWidget *AbstractTwoPointTool::configurationWidget() {
return nullptr;
}
void AbstractTwoPointTool::undo(QPixmap &pixmap) {
QPainter p(&pixmap);
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
}
void AbstractTwoPointTool::drawEnd(const QPoint &p) {
Q_UNUSED(p);
}
void AbstractTwoPointTool::drawMove(const QPoint &p) {
m_points.second = p;
}
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;
r += QMargins(val, val, val, val);
return r.intersected(limits);
}