Changed clang format to new agreement

This commit is contained in:
Jeremy Borgman
2020-09-23 20:39:30 -05:00
committed by borgmanJeremy
parent 2cbccc3d0a
commit 0d5386edd4
167 changed files with 8567 additions and 9081 deletions

View File

@@ -1,2 +1,6 @@
Language: Cpp Language: Cpp
BasedOnStyle: Mozilla BasedOnStyle: Mozilla
IndentWidth: 4
AccessModifierOffset: -4
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None

View File

@@ -14,4 +14,4 @@ jobs:
#exclude: './third_party ./external' #exclude: './third_party ./external'
extensions: 'h,cpp' extensions: 'h,cpp'
clangFormatVersion: 11 clangFormatVersion: 11
style: mozilla style: file

View File

@@ -24,8 +24,7 @@
namespace color_widgets { namespace color_widgets {
namespace detail { namespace detail {
QColor QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha)
color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha)
{ {
qreal h1 = hue * 6; qreal h1 = hue * 6;
qreal x = chroma * (1 - qAbs(std::fmod(h1, 2) - 1)); qreal x = chroma * (1 - qAbs(std::fmod(h1, 2) - 1));
@@ -51,8 +50,7 @@ color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha)
alpha); alpha);
} }
QColor QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha)
color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha)
{ {
qreal chroma = (1 - qAbs(2 * lig - 1)) * sat; qreal chroma = (1 - qAbs(2 * lig - 1)) * sat;
qreal h1 = hue * 6; qreal h1 = hue * 6;

View File

@@ -111,7 +111,10 @@ public:
for (int y = 0; y < width; ++y) { for (int y = 0; y < width; ++y) {
for (int x = 0; x < width; ++x) { for (int x = 0; x < width; ++x) {
inner_selector.setPixel( inner_selector.setPixel(
x, y, color_from(hue, double(x) / width, double(y) / width, 1).rgb()); x,
y,
color_from(hue, double(x) / width, double(y) / width, 1)
.rgb());
} }
} }
} }
@@ -137,7 +140,8 @@ public:
qreal ymin = ycenter - slice_h / 2; qreal ymin = ycenter - slice_h / 2;
qreal psat = qBound(0.0, (y - ymin) / slice_h, 1.0); qreal psat = qBound(0.0, (y - ymin) / slice_h, 1.0);
inner_selector.setPixel(x, y, color_from(hue, psat, pval, 1).rgb()); inner_selector.setPixel(
x, y, color_from(hue, psat, pval, 1).rgb());
} }
} }
} }
@@ -243,54 +247,46 @@ ColorWheel::~ColorWheel()
delete p; delete p;
} }
QColor QColor ColorWheel::color() const
ColorWheel::color() const
{ {
return p->color_from(p->hue, p->sat, p->val, 1); return p->color_from(p->hue, p->sat, p->val, 1);
} }
QSize QSize ColorWheel::sizeHint() const
ColorWheel::sizeHint() const
{ {
return QSize(p->wheel_width * 5, p->wheel_width * 5); return QSize(p->wheel_width * 5, p->wheel_width * 5);
} }
qreal qreal ColorWheel::hue() const
ColorWheel::hue() const
{ {
if ((p->display_flags & COLOR_LCH) && p->sat > 0.01) if ((p->display_flags & COLOR_LCH) && p->sat > 0.01)
return color().hueF(); return color().hueF();
return p->hue; return p->hue;
} }
qreal qreal ColorWheel::saturation() const
ColorWheel::saturation() const
{ {
return color().hsvSaturationF(); return color().hsvSaturationF();
} }
qreal qreal ColorWheel::value() const
ColorWheel::value() const
{ {
return color().valueF(); return color().valueF();
} }
unsigned int unsigned int ColorWheel::wheelWidth() const
ColorWheel::wheelWidth() const
{ {
return p->wheel_width; return p->wheel_width;
} }
void void ColorWheel::setWheelWidth(unsigned int w)
ColorWheel::setWheelWidth(unsigned int w)
{ {
p->wheel_width = w; p->wheel_width = w;
p->render_inner_selector(); p->render_inner_selector();
update(); update();
} }
void void ColorWheel::paintEvent(QPaintEvent*)
ColorWheel::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
@@ -361,8 +357,7 @@ ColorWheel::paintEvent(QPaintEvent*)
painter.drawEllipse(selector_position, selector_radius, selector_radius); painter.drawEllipse(selector_position, selector_radius, selector_radius);
} }
void void ColorWheel::mouseMoveEvent(QMouseEvent* ev)
ColorWheel::mouseMoveEvent(QMouseEvent* ev)
{ {
if (p->mouse_status == DragCircle) { if (p->mouse_status == DragCircle) {
p->hue = p->line_to_point(ev->pos()).angle() / 360.0; p->hue = p->line_to_point(ev->pos()).angle() / 360.0;
@@ -378,7 +373,8 @@ ColorWheel::mouseMoveEvent(QMouseEvent* ev)
center_mouse_ln.setAngle(center_mouse_ln.angle() + center_mouse_ln.setAngle(center_mouse_ln.angle() +
p->selector_image_angle()); p->selector_image_angle());
center_mouse_ln.setP2(center_mouse_ln.p2() - p->selector_image_offset()); center_mouse_ln.setP2(center_mouse_ln.p2() -
p->selector_image_offset());
if (p->display_flags & SHAPE_SQUARE) { if (p->display_flags & SHAPE_SQUARE) {
p->sat = qBound(0.0, center_mouse_ln.x2() / p->square_size(), 1.0); p->sat = qBound(0.0, center_mouse_ln.x2() / p->square_size(), 1.0);
@@ -403,8 +399,7 @@ ColorWheel::mouseMoveEvent(QMouseEvent* ev)
} }
} }
void void ColorWheel::mousePressEvent(QMouseEvent* ev)
ColorWheel::mousePressEvent(QMouseEvent* ev)
{ {
if (ev->buttons() & Qt::LeftButton) { if (ev->buttons() & Qt::LeftButton) {
setFocus(); setFocus();
@@ -419,23 +414,20 @@ ColorWheel::mousePressEvent(QMouseEvent* ev)
} }
} }
void void ColorWheel::mouseReleaseEvent(QMouseEvent* ev)
ColorWheel::mouseReleaseEvent(QMouseEvent* ev)
{ {
mouseMoveEvent(ev); mouseMoveEvent(ev);
p->mouse_status = Nothing; p->mouse_status = Nothing;
emit mouseReleaseOnColor(color()); emit mouseReleaseOnColor(color());
} }
void void ColorWheel::resizeEvent(QResizeEvent*)
ColorWheel::resizeEvent(QResizeEvent*)
{ {
p->render_ring(); p->render_ring();
p->render_inner_selector(); p->render_inner_selector();
} }
void void ColorWheel::setColor(QColor c)
ColorWheel::setColor(QColor c)
{ {
qreal oldh = p->hue; qreal oldh = p->hue;
p->set_color(c); p->set_color(c);
@@ -445,30 +437,26 @@ ColorWheel::setColor(QColor c)
emit colorChanged(c); emit colorChanged(c);
} }
void void ColorWheel::setHue(qreal h)
ColorWheel::setHue(qreal h)
{ {
p->hue = qBound(0.0, h, 1.0); p->hue = qBound(0.0, h, 1.0);
p->render_inner_selector(); p->render_inner_selector();
update(); update();
} }
void void ColorWheel::setSaturation(qreal s)
ColorWheel::setSaturation(qreal s)
{ {
p->sat = qBound(0.0, s, 1.0); p->sat = qBound(0.0, s, 1.0);
update(); update();
} }
void void ColorWheel::setValue(qreal v)
ColorWheel::setValue(qreal v)
{ {
p->val = qBound(0.0, v, 1.0); p->val = qBound(0.0, v, 1.0);
update(); update();
} }
void void ColorWheel::setDisplayFlags(DisplayFlags flags)
ColorWheel::setDisplayFlags(DisplayFlags flags)
{ {
if (!(flags & COLOR_FLAGS)) if (!(flags & COLOR_FLAGS))
flags |= default_flags & COLOR_FLAGS; flags |= default_flags & COLOR_FLAGS;
@@ -507,14 +495,12 @@ ColorWheel::setDisplayFlags(DisplayFlags flags)
emit displayFlagsChanged(flags); emit displayFlagsChanged(flags);
} }
ColorWheel::DisplayFlags ColorWheel::DisplayFlags ColorWheel::displayFlags(DisplayFlags mask) const
ColorWheel::displayFlags(DisplayFlags mask) const
{ {
return p->display_flags & mask; return p->display_flags & mask;
} }
void void ColorWheel::setDefaultDisplayFlags(DisplayFlags flags)
ColorWheel::setDefaultDisplayFlags(DisplayFlags flags)
{ {
if (!(flags & COLOR_FLAGS)) if (!(flags & COLOR_FLAGS))
flags |= hard_default_flags & COLOR_FLAGS; flags |= hard_default_flags & COLOR_FLAGS;
@@ -525,20 +511,17 @@ ColorWheel::setDefaultDisplayFlags(DisplayFlags flags)
default_flags = flags; default_flags = flags;
} }
ColorWheel::DisplayFlags ColorWheel::DisplayFlags ColorWheel::defaultDisplayFlags(DisplayFlags mask)
ColorWheel::defaultDisplayFlags(DisplayFlags mask)
{ {
return default_flags & mask; return default_flags & mask;
} }
void void ColorWheel::setDisplayFlag(DisplayFlags flag, DisplayFlags mask)
ColorWheel::setDisplayFlag(DisplayFlags flag, DisplayFlags mask)
{ {
setDisplayFlags((p->display_flags & ~mask) | flag); setDisplayFlags((p->display_flags & ~mask) | flag);
} }
void void ColorWheel::dragEnterEvent(QDragEnterEvent* event)
ColorWheel::dragEnterEvent(QDragEnterEvent* event)
{ {
if (event->mimeData()->hasColor() || if (event->mimeData()->hasColor() ||
(event->mimeData()->hasText() && (event->mimeData()->hasText() &&
@@ -546,8 +529,7 @@ ColorWheel::dragEnterEvent(QDragEnterEvent* event)
event->acceptProposedAction(); event->acceptProposedAction();
} }
void void ColorWheel::dropEvent(QDropEvent* event)
ColorWheel::dropEvent(QDropEvent* event)
{ {
if (event->mimeData()->hasColor()) { if (event->mimeData()->hasColor()) {
setColor(event->mimeData()->colorData().value<QColor>()); setColor(event->mimeData()->colorData().value<QColor>());

View File

@@ -73,8 +73,7 @@ SingleApplicationPrivate::~SingleApplicationPrivate()
delete memory; delete memory;
} }
void void SingleApplicationPrivate::genBlockServerName(int timeout)
SingleApplicationPrivate::genBlockServerName(int timeout)
{ {
QCryptographicHash appData(QCryptographicHash::Sha256); QCryptographicHash appData(QCryptographicHash::Sha256);
appData.addData("SingleApplication", 17); appData.addData("SingleApplication", 17);
@@ -83,7 +82,8 @@ SingleApplicationPrivate::genBlockServerName(int timeout)
appData.addData(SingleApplication::app_t::organizationDomain().toUtf8()); appData.addData(SingleApplication::app_t::organizationDomain().toUtf8());
if (!(options & SingleApplication::Mode::ExcludeAppVersion)) { if (!(options & SingleApplication::Mode::ExcludeAppVersion)) {
appData.addData(SingleApplication::app_t::applicationVersion().toUtf8()); appData.addData(
SingleApplication::app_t::applicationVersion().toUtf8());
} }
if (!(options & SingleApplication::Mode::ExcludeAppPath)) { if (!(options & SingleApplication::Mode::ExcludeAppPath)) {
@@ -91,7 +91,8 @@ SingleApplicationPrivate::genBlockServerName(int timeout)
appData.addData( appData.addData(
SingleApplication::app_t::applicationFilePath().toLower().toUtf8()); SingleApplication::app_t::applicationFilePath().toLower().toUtf8());
#else #else
appData.addData(SingleApplication::app_t::applicationFilePath().toUtf8()); appData.addData(
SingleApplication::app_t::applicationFilePath().toUtf8());
#endif #endif
} }
@@ -119,8 +120,8 @@ SingleApplicationPrivate::genBlockServerName(int timeout)
process.exitCode() == QProcess::NormalExit) { process.exitCode() == QProcess::NormalExit) {
appData.addData(process.readLine()); appData.addData(process.readLine());
} else { } else {
appData.addData( appData.addData(QDir(QStandardPaths::standardLocations(
QDir(QStandardPaths::standardLocations(QStandardPaths::HomeLocation) QStandardPaths::HomeLocation)
.first()) .first())
.absolutePath() .absolutePath()
.toUtf8()); .toUtf8());
@@ -133,8 +134,7 @@ SingleApplicationPrivate::genBlockServerName(int timeout)
blockServerName = appData.result().toBase64().replace("/", "_"); blockServerName = appData.result().toBase64().replace("/", "_");
} }
void void SingleApplicationPrivate::startPrimary(bool resetMemory)
SingleApplicationPrivate::startPrimary(bool resetMemory)
{ {
Q_Q(SingleApplication); Q_Q(SingleApplication);
@@ -178,8 +178,7 @@ SingleApplicationPrivate::startPrimary(bool resetMemory)
instanceNumber = 0; instanceNumber = 0;
} }
void void SingleApplicationPrivate::startSecondary()
SingleApplicationPrivate::startSecondary()
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
// Handle any further termination signals to ensure the // Handle any further termination signals to ensure the
@@ -188,8 +187,7 @@ SingleApplicationPrivate::startSecondary()
#endif #endif
} }
void void SingleApplicationPrivate::connectToPrimary(int msecs,
SingleApplicationPrivate::connectToPrimary(int msecs,
ConnectionType connectionType) ConnectionType connectionType)
{ {
// Connect to the Local Server of the Primary Instance if not already // Connect to the Local Server of the Primary Instance if not already
@@ -222,8 +220,8 @@ SingleApplicationPrivate::connectToPrimary(int msecs,
writeStream << blockServerName.toLatin1(); writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType); writeStream << static_cast<quint8>(connectionType);
writeStream << instanceNumber; writeStream << instanceNumber;
quint16 checksum = quint16 checksum = qChecksum(initMsg.constData(),
qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length())); static_cast<quint32>(initMsg.length()));
writeStream << checksum; writeStream << checksum;
socket->write(initMsg); socket->write(initMsg);
@@ -232,8 +230,7 @@ SingleApplicationPrivate::connectToPrimary(int msecs,
} }
} }
qint64 qint64 SingleApplicationPrivate::primaryPid()
SingleApplicationPrivate::primaryPid()
{ {
qint64 pid; qint64 pid;
@@ -246,8 +243,7 @@ SingleApplicationPrivate::primaryPid()
} }
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
void void SingleApplicationPrivate::crashHandler()
SingleApplicationPrivate::crashHandler()
{ {
// Handle any further termination signals to ensure the // Handle any further termination signals to ensure the
// QSharedMemory block is deleted even if the process crashes // QSharedMemory block is deleted even if the process crashes
@@ -267,8 +263,7 @@ SingleApplicationPrivate::crashHandler()
signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25 signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25
} }
void void SingleApplicationPrivate::terminate(int signum)
SingleApplicationPrivate::terminate(int signum)
{ {
delete ((SingleApplication*)QCoreApplication::instance())->d_ptr; delete ((SingleApplication*)QCoreApplication::instance())->d_ptr;
::exit(128 + signum); ::exit(128 + signum);
@@ -278,8 +273,7 @@ SingleApplicationPrivate::terminate(int signum)
/** /**
* @brief Executed when a connection has been made to the LocalServer * @brief Executed when a connection has been made to the LocalServer
*/ */
void void SingleApplicationPrivate::slotConnectionEstablished()
SingleApplicationPrivate::slotConnectionEstablished()
{ {
Q_Q(SingleApplication); Q_Q(SingleApplication);
@@ -289,8 +283,9 @@ SingleApplicationPrivate::slotConnectionEstablished()
ConnectionType connectionType = InvalidConnection; ConnectionType connectionType = InvalidConnection;
if (nextConnSocket->waitForReadyRead(100)) { if (nextConnSocket->waitForReadyRead(100)) {
// read all data from message in same order/format as written // read all data from message in same order/format as written
QByteArray msgBytes = nextConnSocket->read( QByteArray msgBytes =
nextConnSocket->bytesAvailable() - static_cast<qint64>(sizeof(quint16))); nextConnSocket->read(nextConnSocket->bytesAvailable() -
static_cast<qint64>(sizeof(quint16)));
QByteArray checksumBytes = nextConnSocket->read(sizeof(quint16)); QByteArray checksumBytes = nextConnSocket->read(sizeof(quint16));
QDataStream readStream(msgBytes); QDataStream readStream(msgBytes);
readStream.setVersion(QDataStream::Qt_5_2); readStream.setVersion(QDataStream::Qt_5_2);
@@ -310,8 +305,8 @@ SingleApplicationPrivate::slotConnectionEstablished()
checksumStream.setVersion(QDataStream::Qt_5_2); checksumStream.setVersion(QDataStream::Qt_5_2);
checksumStream >> msgChecksum; checksumStream >> msgChecksum;
const quint16 actualChecksum = const quint16 actualChecksum = qChecksum(
qChecksum(msgBytes.constData(), static_cast<quint32>(msgBytes.length())); msgBytes.constData(), static_cast<quint32>(msgBytes.length()));
if (readStream.status() != QDataStream::Ok || if (readStream.status() != QDataStream::Ok ||
QLatin1String(latin1Name) != blockServerName || QLatin1String(latin1Name) != blockServerName ||
@@ -338,7 +333,8 @@ SingleApplicationPrivate::slotConnectionEstablished()
&QLocalSocket::readyRead, &QLocalSocket::readyRead,
this, this,
[nextConnSocket, instanceId, this]() { [nextConnSocket, instanceId, this]() {
emit this->slotDataAvailable(nextConnSocket, instanceId); emit this->slotDataAvailable(nextConnSocket,
instanceId);
}); });
if (connectionType == NewInstance || if (connectionType == NewInstance ||
@@ -352,16 +348,15 @@ SingleApplicationPrivate::slotConnectionEstablished()
} }
} }
void void SingleApplicationPrivate::slotDataAvailable(QLocalSocket* dataSocket,
SingleApplicationPrivate::slotDataAvailable(QLocalSocket* dataSocket,
quint32 instanceId) quint32 instanceId)
{ {
Q_Q(SingleApplication); Q_Q(SingleApplication);
emit q->receivedMessage(instanceId, dataSocket->readAll()); emit q->receivedMessage(instanceId, dataSocket->readAll());
} }
void void SingleApplicationPrivate::slotClientConnectionClosed(
SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket* closedSocket, QLocalSocket* closedSocket,
quint32 instanceId) quint32 instanceId)
{ {
if (closedSocket->bytesAvailable() > 0) if (closedSocket->bytesAvailable() > 0)
@@ -411,7 +406,8 @@ SingleApplication::SingleApplication(int& argc,
// Attempt to attach to the memory segment // Attempt to attach to the memory segment
if (d->memory->attach()) { if (d->memory->attach()) {
d->memory->lock(); d->memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data()); InstancesInfo* inst =
static_cast<InstancesInfo*>(d->memory->data());
if (!inst->primary) { if (!inst->primary) {
d->startPrimary(false); d->startPrimary(false);
@@ -425,8 +421,8 @@ SingleApplication::SingleApplication(int& argc,
d->instanceNumber = inst->secondary; d->instanceNumber = inst->secondary;
d->startSecondary(); d->startSecondary();
if (d->options & Mode::SecondaryNotification) { if (d->options & Mode::SecondaryNotification) {
d->connectToPrimary(timeout, d->connectToPrimary(
SingleApplicationPrivate::SecondaryInstance); timeout, SingleApplicationPrivate::SecondaryInstance);
} }
d->memory->unlock(); d->memory->unlock();
return; return;
@@ -450,36 +446,31 @@ SingleApplication::~SingleApplication()
delete d; delete d;
} }
bool bool SingleApplication::isPrimary()
SingleApplication::isPrimary()
{ {
Q_D(SingleApplication); Q_D(SingleApplication);
return d->server != nullptr; return d->server != nullptr;
} }
bool bool SingleApplication::isSecondary()
SingleApplication::isSecondary()
{ {
Q_D(SingleApplication); Q_D(SingleApplication);
return d->server == nullptr; return d->server == nullptr;
} }
quint32 quint32 SingleApplication::instanceId()
SingleApplication::instanceId()
{ {
Q_D(SingleApplication); Q_D(SingleApplication);
return d->instanceNumber; return d->instanceNumber;
} }
qint64 qint64 SingleApplication::primaryPid()
SingleApplication::primaryPid()
{ {
Q_D(SingleApplication); Q_D(SingleApplication);
return d->primaryPid(); return d->primaryPid();
} }
bool bool SingleApplication::sendMessage(QByteArray message, int timeout)
SingleApplication::sendMessage(QByteArray message, int timeout)
{ {
Q_D(SingleApplication); Q_D(SingleApplication);

View File

@@ -25,38 +25,32 @@ CommandArgument::CommandArgument(const QString& name,
, m_description(description) , m_description(description)
{} {}
void void CommandArgument::setName(const QString& name)
CommandArgument::setName(const QString& name)
{ {
m_name = name; m_name = name;
} }
QString QString CommandArgument::name() const
CommandArgument::name() const
{ {
return m_name; return m_name;
} }
void void CommandArgument::setDescription(const QString& description)
CommandArgument::setDescription(const QString& description)
{ {
m_description = description; m_description = description;
} }
QString QString CommandArgument::description() const
CommandArgument::description() const
{ {
return m_description; return m_description;
} }
bool bool CommandArgument::isRoot() const
CommandArgument::isRoot() const
{ {
return m_name.isEmpty() && m_description.isEmpty(); return m_name.isEmpty() && m_description.isEmpty();
} }
bool bool CommandArgument::operator==(const CommandArgument& arg) const
CommandArgument::operator==(const CommandArgument& arg) const
{ {
return m_description == arg.m_description && m_name == arg.m_name; return m_description == arg.m_description && m_name == arg.m_name;
} }

View File

@@ -34,8 +34,7 @@ auto versionOption =
auto helpOption = auto helpOption =
CommandOption({ "h", "help" }, QStringLiteral("Displays this help")); CommandOption({ "h", "help" }, QStringLiteral("Displays this help"));
QString QString optionsToString(const QList<CommandOption>& options,
optionsToString(const QList<CommandOption>& options,
const QList<CommandArgument>& arguments) const QList<CommandArgument>& arguments)
{ {
int size = 0; // track the largest size int size = 0; // track the largest size
@@ -46,7 +45,8 @@ optionsToString(const QList<CommandOption>& options,
QStringList dashedOptions = option.dashedNames(); QStringList dashedOptions = option.dashedNames();
QString joinedDashedOptions = dashedOptions.join(QStringLiteral(", ")); QString joinedDashedOptions = dashedOptions.join(QStringLiteral(", "));
if (!option.valueName().isEmpty()) { if (!option.valueName().isEmpty()) {
joinedDashedOptions += QStringLiteral(" <%1>").arg(option.valueName()); joinedDashedOptions +=
QStringLiteral(" <%1>").arg(option.valueName());
} }
if (joinedDashedOptions.length() > size) { if (joinedDashedOptions.length() > size) {
size = joinedDashedOptions.length(); size = joinedDashedOptions.length();
@@ -62,12 +62,13 @@ optionsToString(const QList<CommandOption>& options,
QString result; QString result;
if (!dashedOptionList.isEmpty()) { if (!dashedOptionList.isEmpty()) {
result += QObject::tr("Options") + ":\n"; result += QObject::tr("Options") + ":\n";
QString linePadding = QStringLiteral(" ").repeated(size + 4).prepend("\n"); QString linePadding =
QStringLiteral(" ").repeated(size + 4).prepend("\n");
for (int i = 0; i < options.length(); ++i) { for (int i = 0; i < options.length(); ++i) {
result += QStringLiteral(" %1 %2\n") result += QStringLiteral(" %1 %2\n")
.arg(dashedOptionList.at(i).leftJustified(size, ' ')) .arg(dashedOptionList.at(i).leftJustified(size, ' '))
.arg(options.at(i).description().replace(QLatin1String("\n"), .arg(options.at(i).description().replace(
linePadding)); QLatin1String("\n"), linePadding));
} }
if (!arguments.isEmpty()) { if (!arguments.isEmpty()) {
result += QLatin1String("\n"); result += QLatin1String("\n");
@@ -86,8 +87,7 @@ optionsToString(const QList<CommandOption>& options,
} // unnamed namespace } // unnamed namespace
bool bool CommandLineParser::processArgs(const QStringList& args,
CommandLineParser::processArgs(const QStringList& args,
QStringList::const_iterator& actualIt, QStringList::const_iterator& actualIt,
Node*& actualNode) Node*& actualNode)
{ {
@@ -115,8 +115,7 @@ CommandLineParser::processArgs(const QStringList& args,
return ok; return ok;
} }
bool bool CommandLineParser::processOptions(const QStringList& args,
CommandLineParser::processOptions(const QStringList& args,
QStringList::const_iterator& actualIt, QStringList::const_iterator& actualIt,
Node* const actualNode) Node* const actualNode)
{ {
@@ -172,7 +171,8 @@ CommandLineParser::processOptions(const QStringList& args,
if (actualIt + 1 != args.cend()) { if (actualIt + 1 != args.cend()) {
++actualIt; ++actualIt;
} else { } else {
out << QStringLiteral("Expected value after the option '%1'.").arg(arg); out << QStringLiteral("Expected value after the option '%1'.")
.arg(arg);
ok = false; ok = false;
return ok; return ok;
} }
@@ -194,8 +194,7 @@ CommandLineParser::processOptions(const QStringList& args,
return ok; return ok;
} }
bool bool CommandLineParser::parse(const QStringList& args)
CommandLineParser::parse(const QStringList& args)
{ {
m_foundArgs.clear(); m_foundArgs.clear();
m_foundOptions.clear(); m_foundOptions.clear();
@@ -233,22 +232,19 @@ CommandLineParser::parse(const QStringList& args)
return ok; return ok;
} }
CommandOption CommandOption CommandLineParser::addVersionOption()
CommandLineParser::addVersionOption()
{ {
m_withVersion = true; m_withVersion = true;
return versionOption; return versionOption;
} }
CommandOption CommandOption CommandLineParser::addHelpOption()
CommandLineParser::addHelpOption()
{ {
m_withHelp = true; m_withHelp = true;
return helpOption; return helpOption;
} }
bool bool CommandLineParser::AddArgument(const CommandArgument& arg,
CommandLineParser::AddArgument(const CommandArgument& arg,
const CommandArgument& parent) const CommandArgument& parent)
{ {
bool res = true; bool res = true;
@@ -263,8 +259,7 @@ CommandLineParser::AddArgument(const CommandArgument& arg,
return res; return res;
} }
bool bool CommandLineParser::AddOption(const CommandOption& option,
CommandLineParser::AddOption(const CommandOption& option,
const CommandArgument& parent) const CommandArgument& parent)
{ {
bool res = true; bool res = true;
@@ -277,8 +272,7 @@ CommandLineParser::AddOption(const CommandOption& option,
return res; return res;
} }
bool bool CommandLineParser::AddOptions(const QList<CommandOption>& options,
CommandLineParser::AddOptions(const QList<CommandOption>& options,
const CommandArgument& parent) const CommandArgument& parent)
{ {
bool res = true; bool res = true;
@@ -291,32 +285,27 @@ CommandLineParser::AddOptions(const QList<CommandOption>& options,
return res; return res;
} }
void void CommandLineParser::setGeneralErrorMessage(const QString& msg)
CommandLineParser::setGeneralErrorMessage(const QString& msg)
{ {
m_generalErrorMessage = msg; m_generalErrorMessage = msg;
} }
void void CommandLineParser::setDescription(const QString& description)
CommandLineParser::setDescription(const QString& description)
{ {
m_description = description; m_description = description;
} }
bool bool CommandLineParser::isSet(const CommandArgument& arg) const
CommandLineParser::isSet(const CommandArgument& arg) const
{ {
return m_foundArgs.contains(arg); return m_foundArgs.contains(arg);
} }
bool bool CommandLineParser::isSet(const CommandOption& option) const
CommandLineParser::isSet(const CommandOption& option) const
{ {
return m_foundOptions.contains(option); return m_foundOptions.contains(option);
} }
QString QString CommandLineParser::value(const CommandOption& option) const
CommandLineParser::value(const CommandOption& option) const
{ {
QString value = option.value(); QString value = option.value();
for (const CommandOption& fOption : m_foundOptions) { for (const CommandOption& fOption : m_foundOptions) {
@@ -328,15 +317,13 @@ CommandLineParser::value(const CommandOption& option) const
return value; return value;
} }
void void CommandLineParser::printVersion()
CommandLineParser::printVersion()
{ {
out << "Flameshot " << qApp->applicationVersion() << "\nCompiled with Qt " out << "Flameshot " << qApp->applicationVersion() << "\nCompiled with Qt "
<< static_cast<QString>(QT_VERSION_STR) << "\n"; << static_cast<QString>(QT_VERSION_STR) << "\n";
} }
void void CommandLineParser::printHelp(QStringList args, const Node* node)
CommandLineParser::printHelp(QStringList args, const Node* node)
{ {
args.removeLast(); // remove the help, it's always the last args.removeLast(); // remove the help, it's always the last
QString helpText; QString helpText;
@@ -374,8 +361,8 @@ CommandLineParser::printHelp(QStringList args, const Node* node)
out << helpText; out << helpText;
} }
CommandLineParser::Node* CommandLineParser::Node* CommandLineParser::findParent(
CommandLineParser::findParent(const CommandArgument& parent) const CommandArgument& parent)
{ {
if (parent == CommandArgument()) { if (parent == CommandArgument()) {
return &m_parseTree; return &m_parseTree;
@@ -392,8 +379,8 @@ CommandLineParser::findParent(const CommandArgument& parent)
return res; return res;
} }
CommandLineParser::Node* CommandLineParser::Node* CommandLineParser::recursiveParentSearch(
CommandLineParser::recursiveParentSearch(const CommandArgument& parent, const CommandArgument& parent,
Node& node) const Node& node) const
{ {
Node* res = nullptr; Node* res = nullptr;
@@ -410,8 +397,8 @@ CommandLineParser::recursiveParentSearch(const CommandArgument& parent,
return res; return res;
} }
bool bool CommandLineParser::processIfOptionIsHelp(
CommandLineParser::processIfOptionIsHelp(const QStringList& args, const QStringList& args,
QStringList::const_iterator& actualIt, QStringList::const_iterator& actualIt,
Node*& actualNode) Node*& actualNode)
{ {

View File

@@ -79,7 +79,8 @@ private:
void printVersion(); void printVersion();
void printHelp(QStringList args, const Node* node); void printHelp(QStringList args, const Node* node);
Node* findParent(const CommandArgument& parent); Node* findParent(const CommandArgument& parent);
Node* recursiveParentSearch(const CommandArgument& parent, Node& node) const; Node* recursiveParentSearch(const CommandArgument& parent,
Node& node) const;
bool processIfOptionIsHelp(const QStringList& args, bool processIfOptionIsHelp(const QStringList& args,
QStringList::const_iterator& actualIt, QStringList::const_iterator& actualIt,
Node*& actualNode); Node*& actualNode);

View File

@@ -41,26 +41,22 @@ CommandOption::CommandOption(const QStringList& names,
m_checker = [](QString const&) -> bool { return true; }; m_checker = [](QString const&) -> bool { return true; };
} }
void void CommandOption::setName(const QString& name)
CommandOption::setName(const QString& name)
{ {
m_names = QStringList() << name; m_names = QStringList() << name;
} }
void void CommandOption::setNames(const QStringList& names)
CommandOption::setNames(const QStringList& names)
{ {
m_names = names; m_names = names;
} }
QStringList QStringList CommandOption::names() const
CommandOption::names() const
{ {
return m_names; return m_names;
} }
QStringList QStringList CommandOption::dashedNames() const
CommandOption::dashedNames() const
{ {
QStringList dashedNames; QStringList dashedNames;
for (const QString& name : m_names) { for (const QString& name : m_names) {
@@ -73,20 +69,17 @@ CommandOption::dashedNames() const
return dashedNames; return dashedNames;
} }
void void CommandOption::setValueName(const QString& name)
CommandOption::setValueName(const QString& name)
{ {
m_valueName = name; m_valueName = name;
} }
QString QString CommandOption::valueName() const
CommandOption::valueName() const
{ {
return m_valueName; return m_valueName;
} }
void void CommandOption::setValue(const QString& value)
CommandOption::setValue(const QString& value)
{ {
if (m_valueName.isEmpty()) { if (m_valueName.isEmpty()) {
m_valueName = QLatin1String("value"); m_valueName = QLatin1String("value");
@@ -94,46 +87,39 @@ CommandOption::setValue(const QString& value)
m_value = value; m_value = value;
} }
QString QString CommandOption::value() const
CommandOption::value() const
{ {
return m_value; return m_value;
} }
void void CommandOption::addChecker(const function<bool(const QString&)> checker,
CommandOption::addChecker(const function<bool(const QString&)> checker,
const QString& errMsg) const QString& errMsg)
{ {
m_checker = checker; m_checker = checker;
m_errorMsg = errMsg; m_errorMsg = errMsg;
} }
bool bool CommandOption::checkValue(const QString& value) const
CommandOption::checkValue(const QString& value) const
{ {
return m_checker(value); return m_checker(value);
} }
QString QString CommandOption::description() const
CommandOption::description() const
{ {
return m_description; return m_description;
} }
void void CommandOption::setDescription(const QString& description)
CommandOption::setDescription(const QString& description)
{ {
m_description = description; m_description = description;
} }
QString QString CommandOption::errorMsg() const
CommandOption::errorMsg() const
{ {
return m_errorMsg; return m_errorMsg;
} }
bool bool CommandOption::operator==(const CommandOption& option) const
CommandOption::operator==(const CommandOption& option) const
{ {
return m_description == option.m_description && m_names == option.m_names && return m_description == option.m_description && m_names == option.m_names &&
m_valueName == option.m_valueName; m_valueName == option.m_valueName;

View File

@@ -32,8 +32,7 @@ ButtonListView::ButtonListView(QWidget* parent)
this, &QListWidget::itemClicked, this, &ButtonListView::reverseItemCheck); this, &QListWidget::itemClicked, this, &ButtonListView::reverseItemCheck);
} }
void void ButtonListView::initButtonList()
ButtonListView::initButtonList()
{ {
ToolFactory factory; ToolFactory factory;
auto listTypes = CaptureToolButton::getIterableButtonTypes(); auto listTypes = CaptureToolButton::getIterableButtonTypes();
@@ -52,7 +51,8 @@ ButtonListView::initButtonList()
m_buttonItem->setIcon(tool->icon(bgColor, false)); m_buttonItem->setIcon(tool->icon(bgColor, false));
m_buttonItem->setFlags(Qt::ItemIsUserCheckable); m_buttonItem->setFlags(Qt::ItemIsUserCheckable);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole()); QColor foregroundColor =
this->palette().color(QWidget::foregroundRole());
m_buttonItem->setForeground(foregroundColor); m_buttonItem->setForeground(foregroundColor);
m_buttonItem->setText(tool->name()); m_buttonItem->setText(tool->name());
@@ -61,8 +61,7 @@ ButtonListView::initButtonList()
} }
} }
void void ButtonListView::updateActiveButtons(QListWidgetItem* item)
ButtonListView::updateActiveButtons(QListWidgetItem* item)
{ {
CaptureToolButton::ButtonType bType = m_buttonTypeByName[item->text()]; CaptureToolButton::ButtonType bType = m_buttonTypeByName[item->text()];
if (item->checkState() == Qt::Checked) { if (item->checkState() == Qt::Checked) {
@@ -79,8 +78,7 @@ ButtonListView::updateActiveButtons(QListWidgetItem* item)
ConfigHandler().setButtons(m_listButtons); ConfigHandler().setButtons(m_listButtons);
} }
void void ButtonListView::reverseItemCheck(QListWidgetItem* item)
ButtonListView::reverseItemCheck(QListWidgetItem* item)
{ {
if (item->checkState() == Qt::Checked) { if (item->checkState() == Qt::Checked) {
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
@@ -90,8 +88,7 @@ ButtonListView::reverseItemCheck(QListWidgetItem* item)
updateActiveButtons(item); updateActiveButtons(item);
} }
void void ButtonListView::selectAll()
ButtonListView::selectAll()
{ {
ConfigHandler().setAllTheButtons(); ConfigHandler().setAllTheButtons();
for (int i = 0; i < this->count(); ++i) { for (int i = 0; i < this->count(); ++i) {
@@ -100,8 +97,7 @@ ButtonListView::selectAll()
} }
} }
void void ButtonListView::updateComponents()
ButtonListView::updateComponents()
{ {
m_listButtons = ConfigHandler().getButtons(); m_listButtons = ConfigHandler().getButtons();
auto listTypes = CaptureToolButton::getIterableButtonTypes(); auto listTypes = CaptureToolButton::getIterableButtonTypes();

View File

@@ -27,8 +27,7 @@ ClickableLabel::ClickableLabel(QString s, QWidget* parent)
setText(s); setText(s);
} }
void void ClickableLabel::mousePressEvent(QMouseEvent*)
ClickableLabel::mousePressEvent(QMouseEvent*)
{ {
emit clicked(); emit clicked();
} }

View File

@@ -51,7 +51,8 @@ ConfigWindow::ConfigWindow(QWidget* parent)
}; };
m_configWatcher = new QFileSystemWatcher(this); m_configWatcher = new QFileSystemWatcher(this);
m_configWatcher->addPath(ConfigHandler().configFilePath()); m_configWatcher->addPath(ConfigHandler().configFilePath());
connect(m_configWatcher, &QFileSystemWatcher::fileChanged, this, changedSlot); connect(
m_configWatcher, &QFileSystemWatcher::fileChanged, this, changedSlot);
QColor background = this->palette().window().color(); QColor background = this->palette().window().color();
bool isDark = ColorUtils::colorIsDark(background); bool isDark = ColorUtils::colorIsDark(background);
@@ -87,8 +88,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
&GeneneralConf::updateComponents); &GeneneralConf::updateComponents);
} }
void void ConfigWindow::keyPressEvent(QKeyEvent* e)
ConfigWindow::keyPressEvent(QKeyEvent* e)
{ {
if (e->key() == Qt::Key_Escape) { if (e->key() == Qt::Key_Escape) {
close(); close();

View File

@@ -20,38 +20,37 @@
ExtendedSlider::ExtendedSlider(QWidget* parent) ExtendedSlider::ExtendedSlider(QWidget* parent)
: QSlider(parent) : QSlider(parent)
{ {
connect(this,
&ExtendedSlider::valueChanged,
this,
&ExtendedSlider::updateTooltip);
connect( connect(
this, &ExtendedSlider::valueChanged, this, &ExtendedSlider::updateTooltip); this, &ExtendedSlider::sliderMoved, this, &ExtendedSlider::fireTimer);
connect(this, &ExtendedSlider::sliderMoved, this, &ExtendedSlider::fireTimer);
m_timer.setSingleShot(true); m_timer.setSingleShot(true);
connect( connect(
&m_timer, &QTimer::timeout, this, &ExtendedSlider::modificationsEnded); &m_timer, &QTimer::timeout, this, &ExtendedSlider::modificationsEnded);
} }
int int ExtendedSlider::mappedValue(int min, int max)
ExtendedSlider::mappedValue(int min, int max)
{ {
qreal progress = qreal progress =
((value() - minimum())) / static_cast<qreal>(maximum() - minimum()); ((value() - minimum())) / static_cast<qreal>(maximum() - minimum());
return min + (max - min) * progress; return min + (max - min) * progress;
} }
void void ExtendedSlider::setMapedValue(int min, int val, int max)
ExtendedSlider::setMapedValue(int min, int val, int max)
{ {
qreal progress = ((val - min) + 1) / static_cast<qreal>(max - min); qreal progress = ((val - min) + 1) / static_cast<qreal>(max - min);
int value = minimum() + (maximum() - minimum()) * progress; int value = minimum() + (maximum() - minimum()) * progress;
setValue(value); setValue(value);
} }
void void ExtendedSlider::updateTooltip()
ExtendedSlider::updateTooltip()
{ {
setToolTip(QString::number(value()) + "%"); setToolTip(QString::number(value()) + "%");
} }
void void ExtendedSlider::fireTimer()
ExtendedSlider::fireTimer()
{ {
m_timer.start(500); m_timer.start(500);
} }

View File

@@ -32,8 +32,7 @@ FileNameEditor::FileNameEditor(QWidget* parent)
initLayout(); initLayout();
} }
void void FileNameEditor::initLayout()
FileNameEditor::initLayout()
{ {
m_layout = new QVBoxLayout(this); m_layout = new QVBoxLayout(this);
auto infoLabel = new QLabel(tr("Edit the name of your captures:"), this); auto infoLabel = new QLabel(tr("Edit the name of your captures:"), this);
@@ -52,8 +51,7 @@ FileNameEditor::initLayout()
m_layout->addLayout(horizLayout); m_layout->addLayout(horizLayout);
} }
void void FileNameEditor::initWidgets()
FileNameEditor::initWidgets()
{ {
m_nameHandler = new FileNameHandler(this); m_nameHandler = new FileNameHandler(this);
@@ -67,7 +65,8 @@ FileNameEditor::initWidgets()
QString foreground = this->palette().windowText().color().name(); QString foreground = this->palette().windowText().color().name();
m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground)); m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
QPalette pal = m_outputLabel->palette(); QPalette pal = m_outputLabel->palette();
QColor color = pal.color(QPalette::Disabled, m_outputLabel->backgroundRole()); QColor color =
pal.color(QPalette::Disabled, m_outputLabel->backgroundRole());
pal.setColor(QPalette::Active, m_outputLabel->backgroundRole(), color); pal.setColor(QPalette::Active, m_outputLabel->backgroundRole(), color);
m_outputLabel->setPalette(pal); m_outputLabel->setPalette(pal);
@@ -102,35 +101,30 @@ FileNameEditor::initWidgets()
m_clearButton->setToolTip(tr("Deletes the name")); m_clearButton->setToolTip(tr("Deletes the name"));
} }
void void FileNameEditor::savePattern()
FileNameEditor::savePattern()
{ {
QString pattern = m_nameEditor->text(); QString pattern = m_nameEditor->text();
m_nameHandler->setPattern(pattern); m_nameHandler->setPattern(pattern);
} }
void void FileNameEditor::showParsedPattern(const QString& p)
FileNameEditor::showParsedPattern(const QString& p)
{ {
QString output = m_nameHandler->parseFilename(p); QString output = m_nameHandler->parseFilename(p);
m_outputLabel->setText(output); m_outputLabel->setText(output);
} }
void void FileNameEditor::resetName()
FileNameEditor::resetName()
{ {
m_nameEditor->setText(ConfigHandler().filenamePatternValue()); m_nameEditor->setText(ConfigHandler().filenamePatternValue());
} }
void void FileNameEditor::addToNameEditor(QString s)
FileNameEditor::addToNameEditor(QString s)
{ {
m_nameEditor->setText(m_nameEditor->text() + s); m_nameEditor->setText(m_nameEditor->text() + s);
m_nameEditor->setFocus(); m_nameEditor->setFocus();
} }
void void FileNameEditor::updateComponents()
FileNameEditor::updateComponents()
{ {
m_nameEditor->setText(ConfigHandler().filenamePatternValue()); m_nameEditor->setText(ConfigHandler().filenamePatternValue());
m_outputLabel->setText(m_nameHandler->parsedPattern()); m_outputLabel->setText(m_nameHandler->parsedPattern());

View File

@@ -49,8 +49,7 @@ GeneneralConf::GeneneralConf(QWidget* parent)
updateComponents(); updateComponents();
} }
void void GeneneralConf::updateComponents()
GeneneralConf::updateComponents()
{ {
ConfigHandler config; ConfigHandler config;
m_helpMessage->setChecked(config.showHelpValue()); m_helpMessage->setChecked(config.showHelpValue());
@@ -74,26 +73,22 @@ GeneneralConf::updateComponents()
#endif #endif
} }
void void GeneneralConf::showHelpChanged(bool checked)
GeneneralConf::showHelpChanged(bool checked)
{ {
ConfigHandler().setShowHelp(checked); ConfigHandler().setShowHelp(checked);
} }
void void GeneneralConf::showSidePanelButtonChanged(bool checked)
GeneneralConf::showSidePanelButtonChanged(bool checked)
{ {
ConfigHandler().setShowSidePanelButton(checked); ConfigHandler().setShowSidePanelButton(checked);
} }
void void GeneneralConf::showDesktopNotificationChanged(bool checked)
GeneneralConf::showDesktopNotificationChanged(bool checked)
{ {
ConfigHandler().setDesktopNotification(checked); ConfigHandler().setDesktopNotification(checked);
} }
void void GeneneralConf::showTrayIconChanged(bool checked)
GeneneralConf::showTrayIconChanged(bool checked)
{ {
auto controller = Controller::getInstance(); auto controller = Controller::getInstance();
if (checked) { if (checked) {
@@ -103,20 +98,17 @@ GeneneralConf::showTrayIconChanged(bool checked)
} }
} }
void void GeneneralConf::autostartChanged(bool checked)
GeneneralConf::autostartChanged(bool checked)
{ {
ConfigHandler().setStartupLaunch(checked); ConfigHandler().setStartupLaunch(checked);
} }
void void GeneneralConf::closeAfterCaptureChanged(bool checked)
GeneneralConf::closeAfterCaptureChanged(bool checked)
{ {
ConfigHandler().setCloseAfterScreenshot(checked); ConfigHandler().setCloseAfterScreenshot(checked);
} }
void void GeneneralConf::importConfiguration()
GeneneralConf::importConfiguration()
{ {
QString fileName = QFileDialog::getOpenFileName(this, tr("Import")); QString fileName = QFileDialog::getOpenFileName(this, tr("Import"));
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
@@ -140,8 +132,7 @@ GeneneralConf::importConfiguration()
config.close(); config.close();
} }
void void GeneneralConf::exportFileConfiguration()
GeneneralConf::exportFileConfiguration()
{ {
QString fileName = QFileDialog::getSaveFileName( QString fileName = QFileDialog::getSaveFileName(
this, tr("Save File"), QStringLiteral("flameshot.conf")); this, tr("Save File"), QStringLiteral("flameshot.conf"));
@@ -161,8 +152,7 @@ GeneneralConf::exportFileConfiguration()
} }
} }
void void GeneneralConf::resetConfiguration()
GeneneralConf::resetConfiguration()
{ {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
reply = QMessageBox::question( reply = QMessageBox::question(
@@ -175,8 +165,7 @@ GeneneralConf::resetConfiguration()
} }
} }
void void GeneneralConf::initShowHelp()
GeneneralConf::initShowHelp()
{ {
m_helpMessage = new QCheckBox(tr("Show help message"), this); m_helpMessage = new QCheckBox(tr("Show help message"), this);
ConfigHandler config; ConfigHandler config;
@@ -186,12 +175,13 @@ GeneneralConf::initShowHelp()
"in the capture mode.")); "in the capture mode."));
m_layout->addWidget(m_helpMessage); m_layout->addWidget(m_helpMessage);
connect( connect(m_helpMessage,
m_helpMessage, &QCheckBox::clicked, this, &GeneneralConf::showHelpChanged); &QCheckBox::clicked,
this,
&GeneneralConf::showHelpChanged);
} }
void void GeneneralConf::initShowSidePanelButton()
GeneneralConf::initShowSidePanelButton()
{ {
m_sidePanelButton = new QCheckBox(tr("Show the side panel button"), this); m_sidePanelButton = new QCheckBox(tr("Show the side panel button"), this);
m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue()); m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue());
@@ -204,8 +194,7 @@ GeneneralConf::initShowSidePanelButton()
this, this,
&GeneneralConf::showSidePanelButtonChanged); &GeneneralConf::showSidePanelButtonChanged);
} }
void void GeneneralConf::initShowDesktopNotification()
GeneneralConf::initShowDesktopNotification()
{ {
m_sysNotifications = new QCheckBox(tr("Show desktop notifications"), this); m_sysNotifications = new QCheckBox(tr("Show desktop notifications"), this);
ConfigHandler config; ConfigHandler config;
@@ -220,8 +209,7 @@ GeneneralConf::initShowDesktopNotification()
&GeneneralConf::showDesktopNotificationChanged); &GeneneralConf::showDesktopNotificationChanged);
} }
void void GeneneralConf::initShowTrayIcon()
GeneneralConf::initShowTrayIcon()
{ {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
m_showTray = new QCheckBox(tr("Show tray icon"), this); m_showTray = new QCheckBox(tr("Show tray icon"), this);
@@ -238,8 +226,7 @@ GeneneralConf::initShowTrayIcon()
#endif #endif
} }
void void GeneneralConf::initConfingButtons()
GeneneralConf::initConfingButtons()
{ {
QHBoxLayout* buttonLayout = new QHBoxLayout(); QHBoxLayout* buttonLayout = new QHBoxLayout();
m_layout->addStretch(); m_layout->addStretch();
@@ -270,8 +257,7 @@ GeneneralConf::initConfingButtons()
&GeneneralConf::resetConfiguration); &GeneneralConf::resetConfiguration);
} }
void void GeneneralConf::initAutostart()
GeneneralConf::initAutostart()
{ {
m_autostart = new QCheckBox(tr("Launch at startup"), this); m_autostart = new QCheckBox(tr("Launch at startup"), this);
ConfigHandler config; ConfigHandler config;
@@ -284,8 +270,7 @@ GeneneralConf::initAutostart()
m_autostart, &QCheckBox::clicked, this, &GeneneralConf::autostartChanged); m_autostart, &QCheckBox::clicked, this, &GeneneralConf::autostartChanged);
} }
void void GeneneralConf::initCloseAfterCapture()
GeneneralConf::initCloseAfterCapture()
{ {
m_closeAfterCapture = new QCheckBox(tr("Close after capture"), this); m_closeAfterCapture = new QCheckBox(tr("Close after capture"), this);
ConfigHandler config; ConfigHandler config;
@@ -300,10 +285,10 @@ GeneneralConf::initCloseAfterCapture()
&GeneneralConf::closeAfterCaptureChanged); &GeneneralConf::closeAfterCaptureChanged);
} }
void void GeneneralConf::initCopyAndCloseAfterUpload()
GeneneralConf::initCopyAndCloseAfterUpload()
{ {
m_copyAndCloseAfterUpload = new QCheckBox(tr("Copy URL after upload"), this); m_copyAndCloseAfterUpload =
new QCheckBox(tr("Copy URL after upload"), this);
ConfigHandler config; ConfigHandler config;
m_copyAndCloseAfterUpload->setChecked( m_copyAndCloseAfterUpload->setChecked(
config.copyAndCloseAfterUploadEnabled()); config.copyAndCloseAfterUploadEnabled());
@@ -316,8 +301,7 @@ GeneneralConf::initCopyAndCloseAfterUpload()
}); });
} }
void void GeneneralConf::initSaveAfterCopy()
GeneneralConf::initSaveAfterCopy()
{ {
m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this); m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this);
m_saveAfterCopy->setToolTip(tr("Save image file after copying it")); m_saveAfterCopy->setToolTip(tr("Save image file after copying it"));
@@ -349,14 +333,12 @@ GeneneralConf::initSaveAfterCopy()
&GeneneralConf::changeSavePath); &GeneneralConf::changeSavePath);
} }
void void GeneneralConf::saveAfterCopyChanged(bool checked)
GeneneralConf::saveAfterCopyChanged(bool checked)
{ {
ConfigHandler().setSaveAfterCopy(checked); ConfigHandler().setSaveAfterCopy(checked);
} }
void void GeneneralConf::changeSavePath()
GeneneralConf::changeSavePath()
{ {
QString path = QFileDialog::getExistingDirectory( QString path = QFileDialog::getExistingDirectory(
this, this,
@@ -367,7 +349,8 @@ GeneneralConf::changeSavePath()
return; return;
} }
if (!QFileInfo(path).isWritable()) { if (!QFileInfo(path).isWritable()) {
QMessageBox::about(this, tr("Error"), tr("Unable to write to directory.")); QMessageBox::about(
this, tr("Error"), tr("Unable to write to directory."));
return; return;
} }
m_savePath->setText(path); m_savePath->setText(path);

View File

@@ -35,7 +35,8 @@ StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
QPushButton* button = new QPushButton(this); QPushButton* button = new QPushButton(this);
button->setText(tr(key.toStdString().data())); button->setText(tr(key.toStdString().data()));
button->setToolTip(variable); button->setToolTip(variable);
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); button->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
button->setMinimumHeight(25); button->setMinimumHeight(25);
layout->addWidget(button, j, i); layout->addWidget(button, j, i);
connect(button, &QPushButton::clicked, this, [variable, this]() { connect(button, &QPushButton::clicked, this, [variable, this]() {

View File

@@ -48,8 +48,7 @@ UIcolorEditor::UIcolorEditor(QWidget* parent)
updateComponents(); updateComponents();
} }
void void UIcolorEditor::updateComponents()
UIcolorEditor::updateComponents()
{ {
ConfigHandler config; ConfigHandler config;
m_uiColor = config.uiMainColorValue(); m_uiColor = config.uiMainColorValue();
@@ -64,8 +63,7 @@ UIcolorEditor::updateComponents()
} }
// updateUIcolor updates the appearance of the buttons // updateUIcolor updates the appearance of the buttons
void void UIcolorEditor::updateUIcolor()
UIcolorEditor::updateUIcolor()
{ {
ConfigHandler config; ConfigHandler config;
if (m_lastButtonPressed == m_buttonMainColor) { if (m_lastButtonPressed == m_buttonMainColor) {
@@ -76,8 +74,7 @@ UIcolorEditor::updateUIcolor()
} }
// updateLocalColor updates the local button // updateLocalColor updates the local button
void void UIcolorEditor::updateLocalColor(const QColor c)
UIcolorEditor::updateLocalColor(const QColor c)
{ {
if (m_lastButtonPressed == m_buttonMainColor) { if (m_lastButtonPressed == m_buttonMainColor) {
m_uiColor = c; m_uiColor = c;
@@ -87,8 +84,7 @@ UIcolorEditor::updateLocalColor(const QColor c)
m_lastButtonPressed->setColor(c); m_lastButtonPressed->setColor(c);
} }
void void UIcolorEditor::initColorWheel()
UIcolorEditor::initColorWheel()
{ {
m_colorWheel = new color_widgets::ColorWheel(this); m_colorWheel = new color_widgets::ColorWheel(this);
connect(m_colorWheel, connect(m_colorWheel,
@@ -110,8 +106,7 @@ UIcolorEditor::initColorWheel()
m_hLayout->addWidget(m_colorWheel); m_hLayout->addWidget(m_colorWheel);
} }
void void UIcolorEditor::initButtons()
UIcolorEditor::initButtons()
{ {
const int extraSize = GlobalValues::buttonBaseSize() / 3; const int extraSize = GlobalValues::buttonBaseSize() / 3;
int frameSize = GlobalValues::buttonBaseSize() + extraSize; int frameSize = GlobalValues::buttonBaseSize() + extraSize;
@@ -168,8 +163,7 @@ UIcolorEditor::initButtons()
} }
// visual update for the selected button // visual update for the selected button
void void UIcolorEditor::changeLastButton(CaptureToolButton* b)
UIcolorEditor::changeLastButton(CaptureToolButton* b)
{ {
if (m_lastButtonPressed != b) { if (m_lastButtonPressed != b) {
m_lastButtonPressed = b; m_lastButtonPressed = b;

View File

@@ -32,8 +32,7 @@ VisualsEditor::VisualsEditor(QWidget* parent)
initWidgets(); initWidgets();
} }
void void VisualsEditor::updateComponents()
VisualsEditor::updateComponents()
{ {
m_buttonList->updateComponents(); m_buttonList->updateComponents();
m_colorEditor->updateComponents(); m_colorEditor->updateComponents();
@@ -41,8 +40,7 @@ VisualsEditor::updateComponents()
m_opacitySlider->setMapedValue(0, opacity, 255); m_opacitySlider->setMapedValue(0, opacity, 255);
} }
void void VisualsEditor::initOpacitySlider()
VisualsEditor::initOpacitySlider()
{ {
m_opacitySlider = new ExtendedSlider(); m_opacitySlider = new ExtendedSlider();
m_opacitySlider->setFocusPolicy(Qt::NoFocus); m_opacitySlider->setFocusPolicy(Qt::NoFocus);
@@ -70,15 +68,13 @@ VisualsEditor::initOpacitySlider()
m_opacitySlider->setMapedValue(0, opacity, 255); m_opacitySlider->setMapedValue(0, opacity, 255);
} }
void void VisualsEditor::saveOpacity()
VisualsEditor::saveOpacity()
{ {
int value = m_opacitySlider->mappedValue(0, 255); int value = m_opacitySlider->mappedValue(0, 255);
ConfigHandler().setContrastOpacity(value); ConfigHandler().setContrastOpacity(value);
} }
void void VisualsEditor::initWidgets()
VisualsEditor::initWidgets()
{ {
m_colorEditor = new UIcolorEditor(); m_colorEditor = new UIcolorEditor();
m_layout->addWidget(m_colorEditor); m_layout->addWidget(m_colorEditor);

View File

@@ -34,15 +34,13 @@ CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode,
, m_id(0) , m_id(0)
{} {}
void void CaptureRequest::setStaticID(uint id)
CaptureRequest::setStaticID(uint id)
{ {
m_forcedID = true; m_forcedID = true;
m_id = id; m_id = id;
} }
uint uint CaptureRequest::id() const
CaptureRequest::id() const
{ {
if (m_forcedID) { if (m_forcedID) {
return m_id; return m_id;
@@ -58,38 +56,32 @@ CaptureRequest::id() const
return id; return id;
} }
CaptureRequest::CaptureMode CaptureRequest::CaptureMode CaptureRequest::captureMode() const
CaptureRequest::captureMode() const
{ {
return m_mode; return m_mode;
} }
uint uint CaptureRequest::delay() const
CaptureRequest::delay() const
{ {
return m_delay; return m_delay;
} }
QString QString CaptureRequest::path() const
CaptureRequest::path() const
{ {
return m_path; return m_path;
} }
QVariant QVariant CaptureRequest::data() const
CaptureRequest::data() const
{ {
return m_data; return m_data;
} }
void void CaptureRequest::addTask(CaptureRequest::ExportTask task)
CaptureRequest::addTask(CaptureRequest::ExportTask task)
{ {
m_tasks |= task; m_tasks |= task;
} }
void void CaptureRequest::exportCapture(const QPixmap& p)
CaptureRequest::exportCapture(const QPixmap& p)
{ {
if ((m_tasks & ExportTask::FILESYSTEM_SAVE_TASK) != ExportTask::NO_TASK) { if ((m_tasks & ExportTask::FILESYSTEM_SAVE_TASK) != ExportTask::NO_TASK) {
if (m_path.isEmpty()) { if (m_path.isEmpty()) {

View File

@@ -68,20 +68,17 @@ private:
using eTask = CaptureRequest::ExportTask; using eTask = CaptureRequest::ExportTask;
inline eTask inline eTask operator|(const eTask& a, const eTask& b)
operator|(const eTask& a, const eTask& b)
{ {
return static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b)); return static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
} }
inline eTask inline eTask operator&(const eTask& a, const eTask& b)
operator&(const eTask& a, const eTask& b)
{ {
return static_cast<eTask>(static_cast<int>(a) & static_cast<int>(b)); return static_cast<eTask>(static_cast<int>(a) & static_cast<int>(b));
} }
inline eTask& inline eTask& operator|=(eTask& a, const eTask& b)
operator|=(eTask& a, const eTask& b)
{ {
a = static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b)); a = static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
return a; return a;

View File

@@ -62,15 +62,13 @@ Controller::Controller()
qApp->setStyleSheet(StyleSheet); qApp->setStyleSheet(StyleSheet);
} }
Controller* Controller* Controller::getInstance()
Controller::getInstance()
{ {
static Controller c; static Controller c;
return &c; return &c;
} }
void void Controller::enableExports()
Controller::enableExports()
{ {
connect( connect(
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken); this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
@@ -78,8 +76,7 @@ Controller::enableExports()
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed); this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
} }
void void Controller::requestCapture(const CaptureRequest& request)
Controller::requestCapture(const CaptureRequest& request)
{ {
uint id = request.id(); uint id = request.id();
m_requestMap.insert(id, request); m_requestMap.insert(id, request);
@@ -90,8 +87,8 @@ Controller::requestCapture(const CaptureRequest& request)
this->startFullscreenCapture(id); this->startFullscreenCapture(id);
}); });
break; break;
// TODO: Figure out the code path that gets here so the deprated warning can // TODO: Figure out the code path that gets here so the deprated warning
// be fixed // can be fixed
case CaptureRequest::SCREEN_MODE: { case CaptureRequest::SCREEN_MODE: {
int&& number = request.data().toInt(); int&& number = request.data().toInt();
doLater(request.delay(), this, [this, id, number]() { doLater(request.delay(), this, [this, id, number]() {
@@ -113,8 +110,8 @@ Controller::requestCapture(const CaptureRequest& request)
} }
// creation of a new capture in GUI mode // creation of a new capture in GUI mode
void void Controller::startVisualCapture(const uint id,
Controller::startVisualCapture(const uint id, const QString& forcedSavePath) const QString& forcedSavePath)
{ {
if (!m_captureWindow) { if (!m_captureWindow) {
QWidget* modalWidget = nullptr; QWidget* modalWidget = nullptr;
@@ -127,7 +124,8 @@ Controller::startVisualCapture(const uint id, const QString& forcedSavePath)
} while (modalWidget); } while (modalWidget);
m_captureWindow = new CaptureWidget(id, forcedSavePath); m_captureWindow = new CaptureWidget(id, forcedSavePath);
// m_captureWindow = new CaptureWidget(id, forcedSavePath, false); // debug // m_captureWindow = new CaptureWidget(id, forcedSavePath, false); //
// debug
connect(m_captureWindow, connect(m_captureWindow,
&CaptureWidget::captureFailed, &CaptureWidget::captureFailed,
this, this,
@@ -148,8 +146,7 @@ Controller::startVisualCapture(const uint id, const QString& forcedSavePath)
} }
} }
void void Controller::startScreenGrab(const uint id, const int screenNumber)
Controller::startScreenGrab(const uint id, const int screenNumber)
{ {
bool ok = true; bool ok = true;
int n = screenNumber; int n = screenNumber;
@@ -167,8 +164,7 @@ Controller::startScreenGrab(const uint id, const int screenNumber)
} }
// creation of the configuration window // creation of the configuration window
void void Controller::openConfigWindow()
Controller::openConfigWindow()
{ {
if (!m_configWindow) { if (!m_configWindow) {
m_configWindow = new ConfigWindow(); m_configWindow = new ConfigWindow();
@@ -177,16 +173,14 @@ Controller::openConfigWindow()
} }
// creation of the window of information // creation of the window of information
void void Controller::openInfoWindow()
Controller::openInfoWindow()
{ {
if (!m_infoWindow) { if (!m_infoWindow) {
m_infoWindow = new InfoWindow(); m_infoWindow = new InfoWindow();
} }
} }
void void Controller::openLauncherWindow()
Controller::openLauncherWindow()
{ {
if (!m_launcherWindow) { if (!m_launcherWindow) {
m_launcherWindow = new CaptureLauncher(); m_launcherWindow = new CaptureLauncher();
@@ -194,8 +188,7 @@ Controller::openLauncherWindow()
m_launcherWindow->show(); m_launcherWindow->show();
} }
void void Controller::enableTrayIcon()
Controller::enableTrayIcon()
{ {
if (m_trayIcon) { if (m_trayIcon) {
return; return;
@@ -207,8 +200,10 @@ Controller::enableTrayIcon()
doLater(400, this, [this]() { this->startVisualCapture(); }); doLater(400, this, [this]() { this->startVisualCapture(); });
}); });
QAction* launcherAction = new QAction(tr("&Open Launcher"), this); QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
connect( connect(launcherAction,
launcherAction, &QAction::triggered, this, &Controller::openLauncherWindow); &QAction::triggered,
this,
&Controller::openLauncherWindow);
QAction* configAction = new QAction(tr("&Configuration"), this); QAction* configAction = new QAction(tr("&Configuration"), this);
connect( connect(
configAction, &QAction::triggered, this, &Controller::openConfigWindow); configAction, &QAction::triggered, this, &Controller::openConfigWindow);
@@ -242,8 +237,7 @@ Controller::enableTrayIcon()
m_trayIcon->show(); m_trayIcon->show();
} }
void void Controller::disableTrayIcon()
Controller::disableTrayIcon()
{ {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if (m_trayIcon) { if (m_trayIcon) {
@@ -253,26 +247,24 @@ Controller::disableTrayIcon()
#endif #endif
} }
void void Controller::sendTrayNotification(const QString& text,
Controller::sendTrayNotification(const QString& text,
const QString& title, const QString& title,
const int timeout) const int timeout)
{ {
if (m_trayIcon) { if (m_trayIcon) {
m_trayIcon->showMessage(title, text, QSystemTrayIcon::Information, timeout); m_trayIcon->showMessage(
title, text, QSystemTrayIcon::Information, timeout);
} }
} }
void void Controller::updateConfigComponents()
Controller::updateConfigComponents()
{ {
if (m_configWindow) { if (m_configWindow) {
m_configWindow->updateChildren(); m_configWindow->updateChildren();
} }
} }
void void Controller::startFullscreenCapture(const uint id)
Controller::startFullscreenCapture(const uint id)
{ {
bool ok = true; bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok)); QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
@@ -283,8 +275,7 @@ Controller::startFullscreenCapture(const uint id)
} }
} }
void void Controller::handleCaptureTaken(uint id, QPixmap p)
Controller::handleCaptureTaken(uint id, QPixmap p)
{ {
auto it = m_requestMap.find(id); auto it = m_requestMap.find(id);
if (it != m_requestMap.end()) { if (it != m_requestMap.end()) {
@@ -296,8 +287,7 @@ Controller::handleCaptureTaken(uint id, QPixmap p)
} }
} }
void void Controller::handleCaptureFailed(uint id)
Controller::handleCaptureFailed(uint id)
{ {
m_requestMap.remove(id); m_requestMap.remove(id);
@@ -306,8 +296,7 @@ Controller::handleCaptureFailed(uint id)
} }
} }
void void Controller::doLater(int msec, QObject* receiver, lambda func)
Controller::doLater(int msec, QObject* receiver, lambda func)
{ {
QTimer* timer = new QTimer(receiver); QTimer* timer = new QTimer(receiver);
QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() { QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() {

View File

@@ -38,8 +38,7 @@ FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent)
FlameshotDBusAdapter::~FlameshotDBusAdapter() {} FlameshotDBusAdapter::~FlameshotDBusAdapter() {}
void void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
{ {
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path); CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path);
// if (toClipboard) { // if (toClipboard) {
@@ -49,8 +48,7 @@ FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
Controller::getInstance()->requestCapture(req); Controller::getInstance()->requestCapture(req);
} }
void void FlameshotDBusAdapter::fullScreen(QString path,
FlameshotDBusAdapter::fullScreen(QString path,
bool toClipboard, bool toClipboard,
int delay, int delay,
uint id) uint id)
@@ -66,14 +64,12 @@ FlameshotDBusAdapter::fullScreen(QString path,
Controller::getInstance()->requestCapture(req); Controller::getInstance()->requestCapture(req);
} }
void void FlameshotDBusAdapter::openLauncher()
FlameshotDBusAdapter::openLauncher()
{ {
Controller::getInstance()->openLauncherWindow(); Controller::getInstance()->openLauncherWindow();
} }
void void FlameshotDBusAdapter::captureScreen(int number,
FlameshotDBusAdapter::captureScreen(int number,
QString path, QString path,
bool toClipboard, bool toClipboard,
int delay, int delay,
@@ -90,14 +86,12 @@ FlameshotDBusAdapter::captureScreen(int number,
Controller::getInstance()->requestCapture(req); Controller::getInstance()->requestCapture(req);
} }
void void FlameshotDBusAdapter::openConfig()
FlameshotDBusAdapter::openConfig()
{ {
Controller::getInstance()->openConfigWindow(); Controller::getInstance()->openConfigWindow();
} }
void void FlameshotDBusAdapter::trayIconEnabled(bool enabled)
FlameshotDBusAdapter::trayIconEnabled(bool enabled)
{ {
auto controller = Controller::getInstance(); auto controller = Controller::getInstance();
if (enabled) { if (enabled) {
@@ -107,8 +101,7 @@ FlameshotDBusAdapter::trayIconEnabled(bool enabled)
} }
} }
void void FlameshotDBusAdapter::autostartEnabled(bool enabled)
FlameshotDBusAdapter::autostartEnabled(bool enabled)
{ {
ConfigHandler().setStartupLaunch(enabled); ConfigHandler().setStartupLaunch(enabled);
auto controller = Controller::getInstance(); auto controller = Controller::getInstance();
@@ -116,8 +109,7 @@ FlameshotDBusAdapter::autostartEnabled(bool enabled)
controller->updateConfigComponents(); controller->updateConfigComponents();
} }
void void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap& p)
FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap& p)
{ {
QByteArray byteArray; QByteArray byteArray;
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);

View File

@@ -35,7 +35,10 @@ signals:
public slots: public slots:
Q_NOREPLY void graphicCapture(QString path, int delay, uint id); Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id); Q_NOREPLY void fullScreen(QString path,
bool toClipboard,
int delay,
uint id);
Q_NOREPLY void captureScreen(int number, Q_NOREPLY void captureScreen(int number,
QString path, QString path,
bool toClipboard, bool toClipboard,

View File

@@ -28,8 +28,7 @@ GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent)
} }
} }
bool bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
void* message, void* message,
long* result) long* result)
{ {

View File

@@ -37,8 +37,7 @@
#include <QDBusMessage> #include <QDBusMessage>
#endif #endif
int int main(int argc, char* argv[])
main(int argc, char* argv[])
{ {
// required for the button serialization // required for the button serialization
// TODO: change to QVector in v1.0 // TODO: change to QVector in v1.0
@@ -62,7 +61,8 @@ main(int argc, char* argv[])
} }
} }
qtTranslator.load(QLocale::system(), qtTranslator.load(
QLocale::system(),
"qt", "qt",
"_", "_",
QLibraryInfo::location(QLibraryInfo::TranslationsPath)); QLibraryInfo::location(QLibraryInfo::TranslationsPath));
@@ -109,14 +109,16 @@ main(int argc, char* argv[])
CommandArgument launcherArgument(QStringLiteral("launcher"), CommandArgument launcherArgument(QStringLiteral("launcher"),
QObject::tr("Open the capture launcher.")); QObject::tr("Open the capture launcher."));
CommandArgument guiArgument( CommandArgument guiArgument(
QStringLiteral("gui"), QObject::tr("Start a manual capture in GUI mode.")); QStringLiteral("gui"),
QObject::tr("Start a manual capture in GUI mode."));
CommandArgument configArgument(QStringLiteral("config"), CommandArgument configArgument(QStringLiteral("config"),
QObject::tr("Configure") + " flameshot."); QObject::tr("Configure") + " flameshot.");
CommandArgument screenArgument(QStringLiteral("screen"), CommandArgument screenArgument(QStringLiteral("screen"),
QObject::tr("Capture a single screen.")); QObject::tr("Capture a single screen."));
// Options // Options
CommandOption pathOption({ "p", "path" }, CommandOption pathOption(
{ "p", "path" },
QObject::tr("Path where the capture will be saved"), QObject::tr("Path where the capture will be saved"),
QStringLiteral("path")); QStringLiteral("path"));
CommandOption clipboardOption( CommandOption clipboardOption(
@@ -130,7 +132,8 @@ main(int argc, char* argv[])
CommandOption trayOption({ "t", "trayicon" }, CommandOption trayOption({ "t", "trayicon" },
QObject::tr("Enable or disable the trayicon"), QObject::tr("Enable or disable the trayicon"),
QStringLiteral("bool")); QStringLiteral("bool"));
CommandOption autostartOption({ "a", "autostart" }, CommandOption autostartOption(
{ "a", "autostart" },
QObject::tr("Enable or disable run at startup"), QObject::tr("Enable or disable run at startup"),
QStringLiteral("bool")); QStringLiteral("bool"));
CommandOption showHelpOption( CommandOption showHelpOption(
@@ -140,7 +143,8 @@ main(int argc, char* argv[])
CommandOption mainColorOption({ "m", "maincolor" }, CommandOption mainColorOption({ "m", "maincolor" },
QObject::tr("Define the main UI color"), QObject::tr("Define the main UI color"),
QStringLiteral("color-code")); QStringLiteral("color-code"));
CommandOption contrastColorOption({ "k", "contrastcolor" }, CommandOption contrastColorOption(
{ "k", "contrastcolor" },
QObject::tr("Define the contrast UI color"), QObject::tr("Define the contrast UI color"),
QStringLiteral("color-code")); QStringLiteral("color-code"));
CommandOption rawImageOption({ "r", "raw" }, CommandOption rawImageOption({ "r", "raw" },
@@ -180,7 +184,8 @@ main(int argc, char* argv[])
auto pathChecker = [pathErr](const QString& pathValue) -> bool { auto pathChecker = [pathErr](const QString& pathValue) -> bool {
bool res = QDir(pathValue).exists(); bool res = QDir(pathValue).exists();
if (!res) { if (!res) {
SystemNotification().sendMessage(QObject::tr(pathErr.toLatin1().data())); SystemNotification().sendMessage(
QObject::tr(pathErr.toLatin1().data()));
} }
return res; return res;
}; };
@@ -188,7 +193,8 @@ main(int argc, char* argv[])
const QString booleanErr = const QString booleanErr =
QObject::tr("Invalid value, it must be defined as 'true' or 'false'"); QObject::tr("Invalid value, it must be defined as 'true' or 'false'");
auto booleanChecker = [](const QString& value) -> bool { auto booleanChecker = [](const QString& value) -> bool {
return value == QLatin1String("true") || value == QLatin1String("false"); return value == QLatin1String("true") ||
value == QLatin1String("false");
}; };
contrastColorOption.addChecker(colorChecker, colorErr); contrastColorOption.addChecker(colorChecker, colorErr);
@@ -216,7 +222,8 @@ main(int argc, char* argv[])
rawImageOption }, rawImageOption },
screenArgument); screenArgument);
parser.AddOptions( parser.AddOptions(
{ pathOption, clipboardOption, delayOption, rawImageOption }, fullArgument); { pathOption, clipboardOption, delayOption, rawImageOption },
fullArgument);
parser.AddOptions({ autostartOption, parser.AddOptions({ autostartOption,
filenameOption, filenameOption,
trayOption, trayOption,
@@ -233,8 +240,8 @@ main(int argc, char* argv[])
//-------------- //--------------
if (parser.isSet(helpOption) || parser.isSet(versionOption)) { if (parser.isSet(helpOption) || parser.isSet(versionOption)) {
} else if (parser.isSet(launcherArgument)) { // LAUNCHER } else if (parser.isSet(launcherArgument)) { // LAUNCHER
QDBusMessage m = QDBusMessage m = QDBusMessage::createMethodCall(
QDBusMessage::createMethodCall(QStringLiteral("org.flameshot.Flameshot"), QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"), QStringLiteral("/"),
QLatin1String(""), QLatin1String(""),
QStringLiteral("openLauncher")); QStringLiteral("openLauncher"));
@@ -253,8 +260,8 @@ main(int argc, char* argv[])
uint id = req.id(); uint id = req.id();
// Send message // Send message
QDBusMessage m = QDBusMessage m = QDBusMessage::createMethodCall(
QDBusMessage::createMethodCall(QStringLiteral("org.flameshot.Flameshot"), QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"), QStringLiteral("/"),
QLatin1String(""), QLatin1String(""),
QStringLiteral("graphicCapture")); QStringLiteral("graphicCapture"));
@@ -267,7 +274,8 @@ main(int argc, char* argv[])
dbusUtils.connectPrintCapture(sessionBus, id); dbusUtils.connectPrintCapture(sessionBus, id);
QTimer t; QTimer t;
t.setInterval(delay + 1000 * 60 * 15); // 15 minutes timeout t.setInterval(delay + 1000 * 60 * 15); // 15 minutes timeout
QObject::connect(&t, &QTimer::timeout, qApp, &QCoreApplication::quit); QObject::connect(
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
t.start(); t.start();
// wait // wait
return app.exec(); return app.exec();
@@ -283,8 +291,10 @@ main(int argc, char* argv[])
out << "Invalid format, set where to save the content with one of " out << "Invalid format, set where to save the content with one of "
<< "the following flags:\n " << "the following flags:\n "
<< pathOption.dashedNames().join(QStringLiteral(", ")) << "\n " << pathOption.dashedNames().join(QStringLiteral(", ")) << "\n "
<< rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n " << rawImageOption.dashedNames().join(QStringLiteral(", "))
<< clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n"; << "\n "
<< clipboardOption.dashedNames().join(QStringLiteral(", "))
<< "\n\n";
parser.parse(QStringList() << argv[0] << QStringLiteral("full") parser.parse(QStringList() << argv[0] << QStringLiteral("full")
<< QStringLiteral("-h")); << QStringLiteral("-h"));
goto finish; goto finish;
@@ -301,8 +311,8 @@ main(int argc, char* argv[])
DBusUtils dbusUtils; DBusUtils dbusUtils;
// Send message // Send message
QDBusMessage m = QDBusMessage m = QDBusMessage::createMethodCall(
QDBusMessage::createMethodCall(QStringLiteral("org.flameshot.Flameshot"), QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"), QStringLiteral("/"),
QLatin1String(""), QLatin1String(""),
QStringLiteral("fullScreen")); QStringLiteral("fullScreen"));
@@ -316,7 +326,8 @@ main(int argc, char* argv[])
// timeout just in case // timeout just in case
QTimer t; QTimer t;
t.setInterval(delay + 2000); t.setInterval(delay + 2000);
QObject::connect(&t, &QTimer::timeout, qApp, &QCoreApplication::quit); QObject::connect(
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
t.start(); t.start();
// wait // wait
return app.exec(); return app.exec();
@@ -335,14 +346,17 @@ main(int argc, char* argv[])
out << "Invalid format, set where to save the content with one of " out << "Invalid format, set where to save the content with one of "
<< "the following flags:\n " << "the following flags:\n "
<< pathOption.dashedNames().join(QStringLiteral(", ")) << "\n " << pathOption.dashedNames().join(QStringLiteral(", ")) << "\n "
<< rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n " << rawImageOption.dashedNames().join(QStringLiteral(", "))
<< clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n"; << "\n "
<< clipboardOption.dashedNames().join(QStringLiteral(", "))
<< "\n\n";
parser.parse(QStringList() << argv[0] << QStringLiteral("screen") parser.parse(QStringList() << argv[0] << QStringLiteral("screen")
<< QStringLiteral("-h")); << QStringLiteral("-h"));
goto finish; goto finish;
} }
CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, pathValue, number); CaptureRequest req(
CaptureRequest::SCREEN_MODE, delay, pathValue, number);
if (toClipboard) { if (toClipboard) {
req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK); req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
} }
@@ -353,8 +367,8 @@ main(int argc, char* argv[])
DBusUtils dbusUtils; DBusUtils dbusUtils;
// Send message // Send message
QDBusMessage m = QDBusMessage m = QDBusMessage::createMethodCall(
QDBusMessage::createMethodCall(QStringLiteral("org.flameshot.Flameshot"), QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"), QStringLiteral("/"),
QLatin1String(""), QLatin1String(""),
QStringLiteral("captureScreen")); QStringLiteral("captureScreen"));
@@ -368,7 +382,8 @@ main(int argc, char* argv[])
// timeout just in case // timeout just in case
QTimer t; QTimer t;
t.setInterval(delay + 2000); t.setInterval(delay + 2000);
QObject::connect(&t, &QTimer::timeout, qApp, &QCoreApplication::quit); QObject::connect(
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
t.start(); t.start();
// wait // wait
return app.exec(); return app.exec();
@@ -380,7 +395,8 @@ main(int argc, char* argv[])
bool help = parser.isSet(showHelpOption); bool help = parser.isSet(showHelpOption);
bool mainColor = parser.isSet(mainColorOption); bool mainColor = parser.isSet(mainColorOption);
bool contrastColor = parser.isSet(contrastColorOption); bool contrastColor = parser.isSet(contrastColorOption);
bool someFlagSet = (filename || tray || help || mainColor || contrastColor); bool someFlagSet =
(filename || tray || help || mainColor || contrastColor);
ConfigHandler config; ConfigHandler config;
if (autostart) { if (autostart) {
QDBusMessage m = QDBusMessage::createMethodCall( QDBusMessage m = QDBusMessage::createMethodCall(
@@ -404,7 +420,8 @@ main(int argc, char* argv[])
QString newFilename(parser.value(filenameOption)); QString newFilename(parser.value(filenameOption));
config.setFilenamePattern(newFilename); config.setFilenamePattern(newFilename);
FileNameHandler fh; FileNameHandler fh;
QTextStream(stdout) << QStringLiteral("The new pattern is '%1'\n" QTextStream(stdout)
<< QStringLiteral("The new pattern is '%1'\n"
"Parsed pattern example: %2\n") "Parsed pattern example: %2\n")
.arg(newFilename) .arg(newFilename)
.arg(fh.parsedPattern()); .arg(fh.parsedPattern());

View File

@@ -21,32 +21,27 @@ AbstractActionTool::AbstractActionTool(QObject* parent)
: CaptureTool(parent) : CaptureTool(parent)
{} {}
bool bool AbstractActionTool::isValid() const
AbstractActionTool::isValid() const
{ {
return true; return true;
} }
bool bool AbstractActionTool::isSelectable() const
AbstractActionTool::isSelectable() const
{ {
return false; return false;
} }
bool bool AbstractActionTool::showMousePreview() const
AbstractActionTool::showMousePreview() const
{ {
return false; return false;
} }
void void AbstractActionTool::undo(QPixmap& pixmap)
AbstractActionTool::undo(QPixmap& pixmap)
{ {
Q_UNUSED(pixmap); Q_UNUSED(pixmap);
} }
void void AbstractActionTool::process(QPainter& painter,
AbstractActionTool::process(QPainter& painter,
const QPixmap& pixmap, const QPixmap& pixmap,
bool recordUndo) bool recordUndo)
{ {
@@ -55,40 +50,34 @@ AbstractActionTool::process(QPainter& painter,
Q_UNUSED(recordUndo); Q_UNUSED(recordUndo);
} }
void void AbstractActionTool::paintMousePreview(QPainter& painter,
AbstractActionTool::paintMousePreview(QPainter& painter,
const CaptureContext& context) const CaptureContext& context)
{ {
Q_UNUSED(painter); Q_UNUSED(painter);
Q_UNUSED(context); Q_UNUSED(context);
} }
void void AbstractActionTool::drawEnd(const QPoint& p)
AbstractActionTool::drawEnd(const QPoint& p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
} }
void void AbstractActionTool::drawMove(const QPoint& p)
AbstractActionTool::drawMove(const QPoint& p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
} }
void void AbstractActionTool::drawStart(const CaptureContext& context)
AbstractActionTool::drawStart(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }
void void AbstractActionTool::colorChanged(const QColor& c)
AbstractActionTool::colorChanged(const QColor& c)
{ {
Q_UNUSED(c); Q_UNUSED(c);
} }
void void AbstractActionTool::thicknessChanged(const int th)
AbstractActionTool::thicknessChanged(const int th)
{ {
Q_UNUSED(th); Q_UNUSED(th);
} }

View File

@@ -23,32 +23,27 @@ AbstractPathTool::AbstractPathTool(QObject* parent)
, m_padding(0) , m_padding(0)
{} {}
bool bool AbstractPathTool::isValid() const
AbstractPathTool::isValid() const
{ {
return m_points.length() > 1; return m_points.length() > 1;
} }
bool bool AbstractPathTool::closeOnButtonPressed() const
AbstractPathTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
bool bool AbstractPathTool::isSelectable() const
AbstractPathTool::isSelectable() const
{ {
return true; return true;
} }
bool bool AbstractPathTool::showMousePreview() const
AbstractPathTool::showMousePreview() const
{ {
return true; return true;
} }
void void AbstractPathTool::undo(QPixmap& pixmap)
AbstractPathTool::undo(QPixmap& pixmap)
{ {
QPainter p(&pixmap); QPainter p(&pixmap);
const int val = m_thickness + m_padding; const int val = m_thickness + m_padding;
@@ -56,40 +51,34 @@ AbstractPathTool::undo(QPixmap& pixmap)
p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup); p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup);
} }
void void AbstractPathTool::drawEnd(const QPoint& p)
AbstractPathTool::drawEnd(const QPoint& p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
} }
void void AbstractPathTool::drawMove(const QPoint& p)
AbstractPathTool::drawMove(const QPoint& p)
{ {
addPoint(p); addPoint(p);
} }
void void AbstractPathTool::colorChanged(const QColor& c)
AbstractPathTool::colorChanged(const QColor& c)
{ {
m_color = c; m_color = c;
} }
void void AbstractPathTool::thicknessChanged(const int th)
AbstractPathTool::thicknessChanged(const int th)
{ {
m_thickness = th; m_thickness = th;
} }
void void AbstractPathTool::updateBackup(const QPixmap& pixmap)
AbstractPathTool::updateBackup(const QPixmap& pixmap)
{ {
const int val = m_thickness + m_padding; const int val = m_thickness + m_padding;
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val); QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
m_pixmapBackup = pixmap.copy(area); m_pixmapBackup = pixmap.copy(area);
} }
void void AbstractPathTool::addPoint(const QPoint& point)
AbstractPathTool::addPoint(const QPoint& point)
{ {
if (m_backupArea.left() > point.x()) { if (m_backupArea.left() > point.x()) {
m_backupArea.setLeft(point.x()); m_backupArea.setLeft(point.x());

View File

@@ -48,32 +48,27 @@ AbstractTwoPointTool::AbstractTwoPointTool(QObject* parent)
, m_padding(0) , m_padding(0)
{} {}
bool bool AbstractTwoPointTool::isValid() const
AbstractTwoPointTool::isValid() const
{ {
return (m_points.first != m_points.second); return (m_points.first != m_points.second);
} }
bool bool AbstractTwoPointTool::closeOnButtonPressed() const
AbstractTwoPointTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
bool bool AbstractTwoPointTool::isSelectable() const
AbstractTwoPointTool::isSelectable() const
{ {
return true; return true;
} }
bool bool AbstractTwoPointTool::showMousePreview() const
AbstractTwoPointTool::showMousePreview() const
{ {
return true; return true;
} }
void void AbstractTwoPointTool::undo(QPixmap& pixmap)
AbstractTwoPointTool::undo(QPixmap& pixmap)
{ {
QPainter p(&pixmap); QPainter p(&pixmap);
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup); p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
@@ -82,44 +77,37 @@ AbstractTwoPointTool::undo(QPixmap& pixmap)
} }
} }
void void AbstractTwoPointTool::drawEnd(const QPoint& p)
AbstractTwoPointTool::drawEnd(const QPoint& p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
} }
void void AbstractTwoPointTool::drawMove(const QPoint& p)
AbstractTwoPointTool::drawMove(const QPoint& p)
{ {
m_points.second = p; m_points.second = p;
} }
void void AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint& p)
AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint& p)
{ {
m_points.second = m_points.first + adjustedVector(p - m_points.first); m_points.second = m_points.first + adjustedVector(p - m_points.first);
} }
void void AbstractTwoPointTool::colorChanged(const QColor& c)
AbstractTwoPointTool::colorChanged(const QColor& c)
{ {
m_color = c; m_color = c;
} }
void void AbstractTwoPointTool::thicknessChanged(const int th)
AbstractTwoPointTool::thicknessChanged(const int th)
{ {
m_thickness = th; m_thickness = th;
} }
void void AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
{ {
m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect())); m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
} }
QRect QRect AbstractTwoPointTool::backupRect(const QRect& limits) const
AbstractTwoPointTool::backupRect(const QRect& limits) const
{ {
QRect r = QRect(m_points.first, m_points.second).normalized(); QRect r = QRect(m_points.first, m_points.second).normalized();
const int val = m_thickness + m_padding; const int val = m_thickness + m_padding;
@@ -127,12 +115,11 @@ AbstractTwoPointTool::backupRect(const QRect& limits) const
return r.intersected(limits); return r.intersected(limits);
} }
QPoint QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const
AbstractTwoPointTool::adjustedVector(QPoint v) const
{ {
if (m_supportsOrthogonalAdj && m_supportsDiagonalAdj) { if (m_supportsOrthogonalAdj && m_supportsDiagonalAdj) {
int dir = int dir = (static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) +
(static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) + DIRS_NUMBER) % DIRS_NUMBER) %
DIRS_NUMBER; DIRS_NUMBER;
if (dir == UNIT::HORIZ_DIR) { if (dir == UNIT::HORIZ_DIR) {
v.setY(0); v.setY(0);
@@ -150,8 +137,9 @@ AbstractTwoPointTool::adjustedVector(QPoint v) const
v.setY(newY); v.setY(newY);
} }
} else if (m_supportsDiagonalAdj) { } else if (m_supportsDiagonalAdj) {
int dir = (static_cast<int>(round( int dir =
(atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) / ADJ_DIAG_UNIT)) + (static_cast<int>(round((atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) /
ADJ_DIAG_UNIT)) +
DIAG_DIRS_NUMBER) % DIAG_DIRS_NUMBER) %
DIAG_DIRS_NUMBER; DIAG_DIRS_NUMBER;
if (dir == DIAG_UNIT::DIR1) { if (dir == DIAG_UNIT::DIR1) {

View File

@@ -24,8 +24,7 @@ namespace {
const int ArrowWidth = 10; const int ArrowWidth = 10;
const int ArrowHeight = 18; const int ArrowHeight = 18;
QPainterPath QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness)
getArrowHead(QPoint p1, QPoint p2, const int thickness)
{ {
QLineF base(p1, p2); QLineF base(p1, p2);
// Create the vector for the position of the base of the arrowhead // Create the vector for the position of the base of the arrowhead
@@ -58,8 +57,7 @@ getArrowHead(QPoint p1, QPoint p2, const int thickness)
} }
// gets a shorter line to prevent overlap in the point of the arrow // gets a shorter line to prevent overlap in the point of the arrow
QLine QLine getShorterLine(QPoint p1, QPoint p2, const int thickness)
getShorterLine(QPoint p1, QPoint p2, const int thickness)
{ {
QLineF l(p1, p2); QLineF l(p1, p2);
int val = ArrowHeight + thickness * 4; int val = ArrowHeight + thickness * 4;
@@ -80,38 +78,34 @@ ArrowTool::ArrowTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
QIcon QIcon ArrowTool::icon(const QColor& background, bool inEditor) const
ArrowTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "arrow-bottom-left.svg"); return QIcon(iconPath(background) + "arrow-bottom-left.svg");
} }
QString QString ArrowTool::name() const
ArrowTool::name() const
{ {
return tr("Arrow"); return tr("Arrow");
} }
ToolType ToolType ArrowTool::nameID() const
ArrowTool::nameID() const
{ {
return ToolType::ARROW; return ToolType::ARROW;
} }
QString QString ArrowTool::description() const
ArrowTool::description() const
{ {
return tr("Set the Arrow as the paint tool"); return tr("Set the Arrow as the paint tool");
} }
CaptureTool* CaptureTool* ArrowTool::copy(QObject* parent)
ArrowTool::copy(QObject* parent)
{ {
return new ArrowTool(parent); return new ArrowTool(parent);
} }
void void ArrowTool::process(QPainter& painter,
ArrowTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
updateBackup(pixmap); updateBackup(pixmap);
@@ -123,15 +117,14 @@ ArrowTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
QBrush(m_color)); QBrush(m_color));
} }
void void ArrowTool::paintMousePreview(QPainter& painter,
ArrowTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness)); painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void ArrowTool::drawStart(const CaptureContext& context)
ArrowTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -139,8 +132,7 @@ ArrowTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void ArrowTool::pressed(const CaptureContext& context)
ArrowTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -17,8 +17,7 @@
#include "capturecontext.h" #include "capturecontext.h"
QPixmap QPixmap CaptureContext::selectedScreenshotArea() const
CaptureContext::selectedScreenshotArea() const
{ {
if (selection.isNull()) { if (selection.isNull()) {
return screenshot; return screenshot;

View File

@@ -28,38 +28,34 @@ CircleTool::CircleTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
QIcon QIcon CircleTool::icon(const QColor& background, bool inEditor) const
CircleTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "circle-outline.svg"); return QIcon(iconPath(background) + "circle-outline.svg");
} }
QString QString CircleTool::name() const
CircleTool::name() const
{ {
return tr("Circle"); return tr("Circle");
} }
ToolType ToolType CircleTool::nameID() const
CircleTool::nameID() const
{ {
return ToolType::CIRCLE; return ToolType::CIRCLE;
} }
QString QString CircleTool::description() const
CircleTool::description() const
{ {
return tr("Set the Circle as the paint tool"); return tr("Set the Circle as the paint tool");
} }
CaptureTool* CaptureTool* CircleTool::copy(QObject* parent)
CircleTool::copy(QObject* parent)
{ {
return new CircleTool(parent); return new CircleTool(parent);
} }
void void CircleTool::process(QPainter& painter,
CircleTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
updateBackup(pixmap); updateBackup(pixmap);
@@ -68,15 +64,14 @@ CircleTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
painter.drawEllipse(QRect(m_points.first, m_points.second)); painter.drawEllipse(QRect(m_points.first, m_points.second));
} }
void void CircleTool::paintMousePreview(QPainter& painter,
CircleTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness)); painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void CircleTool::drawStart(const CaptureContext& context)
CircleTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -84,8 +79,7 @@ CircleTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void CircleTool::pressed(const CaptureContext& context)
CircleTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -27,38 +27,32 @@ CircleCountTool::CircleCountTool(QObject* parent)
m_count = 0; m_count = 0;
} }
QIcon QIcon CircleCountTool::icon(const QColor& background, bool inEditor) const
CircleCountTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "circlecount-outline.svg"); return QIcon(iconPath(background) + "circlecount-outline.svg");
} }
QString QString CircleCountTool::name() const
CircleCountTool::name() const
{ {
return tr("Circle Counter"); return tr("Circle Counter");
} }
ToolType ToolType CircleCountTool::nameID() const
CircleCountTool::nameID() const
{ {
return ToolType::CIRCLECOUNT; return ToolType::CIRCLECOUNT;
} }
QString QString CircleCountTool::description() const
CircleCountTool::description() const
{ {
return tr("Add an autoincrementing counter bubble"); return tr("Add an autoincrementing counter bubble");
} }
CaptureTool* CaptureTool* CircleCountTool::copy(QObject* parent)
CircleCountTool::copy(QObject* parent)
{ {
return new CircleCountTool(parent); return new CircleCountTool(parent);
} }
void void CircleCountTool::process(QPainter& painter,
CircleCountTool::process(QPainter& painter,
const QPixmap& pixmap, const QPixmap& pixmap,
bool recordUndo) bool recordUndo)
{ {
@@ -91,8 +85,8 @@ CircleCountTool::process(QPainter& painter,
new_font.setPixelSize(fontSize); new_font.setPixelSize(fontSize);
painter.setFont(new_font); painter.setFont(new_font);
bRect = bRect = painter.boundingRect(
painter.boundingRect(textRect, Qt::AlignCenter, QString::number(m_count)); textRect, Qt::AlignCenter, QString::number(m_count));
} }
// Lightness value ranges from 0-255, we split at 75 as this looks best // Lightness value ranges from 0-255, we split at 75 as this looks best
@@ -106,8 +100,7 @@ CircleCountTool::process(QPainter& painter,
painter.setFont(orig_font); painter.setFont(orig_font);
} }
void void CircleCountTool::paintMousePreview(QPainter& painter,
CircleCountTool::paintMousePreview(QPainter& painter,
const CaptureContext& context) const CaptureContext& context)
{ {
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -123,8 +116,7 @@ CircleCountTool::paintMousePreview(QPainter& painter,
{ context.mousePos.x() + 1, context.mousePos.y() + 1 }); { context.mousePos.x() + 1, context.mousePos.y() + 1 });
} }
void void CircleCountTool::drawStart(const CaptureContext& context)
CircleCountTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -136,8 +128,7 @@ CircleCountTool::drawStart(const CaptureContext& context)
emit requestAction(REQ_INCREMENT_CIRCLE_COUNT); emit requestAction(REQ_INCREMENT_CIRCLE_COUNT);
} }
void void CircleCountTool::pressed(const CaptureContext& context)
CircleCountTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -23,44 +23,37 @@ CopyTool::CopyTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool CopyTool::closeOnButtonPressed() const
CopyTool::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon CopyTool::icon(const QColor& background, bool inEditor) const
CopyTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "content-copy.svg"); return QIcon(iconPath(background) + "content-copy.svg");
} }
QString QString CopyTool::name() const
CopyTool::name() const
{ {
return tr("Copy"); return tr("Copy");
} }
ToolType ToolType CopyTool::nameID() const
CopyTool::nameID() const
{ {
return ToolType::COPY; return ToolType::COPY;
} }
QString QString CopyTool::description() const
CopyTool::description() const
{ {
return tr("Copy the selection into the clipboard"); return tr("Copy the selection into the clipboard");
} }
CaptureTool* CaptureTool* CopyTool::copy(QObject* parent)
CopyTool::copy(QObject* parent)
{ {
return new CopyTool(parent); return new CopyTool(parent);
} }
void void CopyTool::pressed(const CaptureContext& context)
CopyTool::pressed(const CaptureContext& context)
{ {
emit requestAction(REQ_CAPTURE_DONE_OK); emit requestAction(REQ_CAPTURE_DONE_OK);
ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea()); ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());

View File

@@ -22,44 +22,37 @@ ExitTool::ExitTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool ExitTool::closeOnButtonPressed() const
ExitTool::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon ExitTool::icon(const QColor& background, bool inEditor) const
ExitTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "close.svg"); return QIcon(iconPath(background) + "close.svg");
} }
QString QString ExitTool::name() const
ExitTool::name() const
{ {
return tr("Exit"); return tr("Exit");
} }
ToolType ToolType ExitTool::nameID() const
ExitTool::nameID() const
{ {
return ToolType::EXIT; return ToolType::EXIT;
} }
QString QString ExitTool::description() const
ExitTool::description() const
{ {
return tr("Leave the capture screen"); return tr("Leave the capture screen");
} }
CaptureTool* CaptureTool* ExitTool::copy(QObject* parent)
ExitTool::copy(QObject* parent)
{ {
return new ExitTool(parent); return new ExitTool(parent);
} }
void void ExitTool::pressed(const CaptureContext& context)
ExitTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
emit requestAction(REQ_CLOSE_GUI); emit requestAction(REQ_CLOSE_GUI);

View File

@@ -71,8 +71,7 @@ ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent)
// QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing // QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing
} }
void void ImgurUploader::handleReply(QNetworkReply* reply)
ImgurUploader::handleReply(QNetworkReply* reply)
{ {
m_spinner->deleteLater(); m_spinner->deleteLater();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
@@ -85,7 +84,8 @@ ImgurUploader::handleReply(QNetworkReply* reply)
.arg(data[QStringLiteral("deletehash")].toString())); .arg(data[QStringLiteral("deletehash")].toString()));
if (ConfigHandler().copyAndCloseAfterUploadEnabled()) { if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
QApplication::clipboard()->setText(m_imageURL.toString()); QApplication::clipboard()->setText(m_imageURL.toString());
SystemNotification().sendMessage(QObject::tr("URL copied to clipboard.")); SystemNotification().sendMessage(
QObject::tr("URL copied to clipboard."));
close(); close();
} else { } else {
onUploadOk(); onUploadOk();
@@ -96,8 +96,7 @@ ImgurUploader::handleReply(QNetworkReply* reply)
new QShortcut(Qt::Key_Escape, this, SLOT(close())); new QShortcut(Qt::Key_Escape, this, SLOT(close()));
} }
void void ImgurUploader::startDrag()
ImgurUploader::startDrag()
{ {
QMimeData* mimeData = new QMimeData; QMimeData* mimeData = new QMimeData;
mimeData->setUrls(QList<QUrl>{ m_imageURL }); mimeData->setUrls(QList<QUrl>{ m_imageURL });
@@ -110,8 +109,7 @@ ImgurUploader::startDrag()
dragHandler->exec(); dragHandler->exec();
} }
void void ImgurUploader::upload()
ImgurUploader::upload()
{ {
QByteArray byteArray; QByteArray byteArray;
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
@@ -135,8 +133,7 @@ ImgurUploader::upload()
m_NetworkAM->post(request, byteArray); m_NetworkAM->post(request, byteArray);
} }
void void ImgurUploader::onUploadOk()
ImgurUploader::onUploadOk()
{ {
m_infoLabel->deleteLater(); m_infoLabel->deleteLater();
@@ -176,8 +173,7 @@ ImgurUploader::onUploadOk()
&ImgurUploader::copyImage); &ImgurUploader::copyImage);
} }
void void ImgurUploader::openURL()
ImgurUploader::openURL()
{ {
bool successful = QDesktopServices::openUrl(m_imageURL); bool successful = QDesktopServices::openUrl(m_imageURL);
if (!successful) { if (!successful) {
@@ -185,15 +181,13 @@ ImgurUploader::openURL()
} }
} }
void void ImgurUploader::copyURL()
ImgurUploader::copyURL()
{ {
QApplication::clipboard()->setText(m_imageURL.toString()); QApplication::clipboard()->setText(m_imageURL.toString());
m_notification->showMessage(tr("URL copied to clipboard.")); m_notification->showMessage(tr("URL copied to clipboard."));
} }
void void ImgurUploader::openDeleteURL()
ImgurUploader::openDeleteURL()
{ {
bool successful = QDesktopServices::openUrl(m_deleteImageURL); bool successful = QDesktopServices::openUrl(m_deleteImageURL);
if (!successful) { if (!successful) {
@@ -201,8 +195,7 @@ ImgurUploader::openDeleteURL()
} }
} }
void void ImgurUploader::copyImage()
ImgurUploader::copyImage()
{ {
QApplication::clipboard()->setPixmap(m_pixmap); QApplication::clipboard()->setPixmap(m_pixmap);
m_notification->showMessage(tr("Screenshot copied to clipboard.")); m_notification->showMessage(tr("Screenshot copied to clipboard."));

View File

@@ -23,50 +23,42 @@ ImgurUploaderTool::ImgurUploaderTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool ImgurUploaderTool::closeOnButtonPressed() const
ImgurUploaderTool::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cloud-upload.svg"); return QIcon(iconPath(background) + "cloud-upload.svg");
} }
QString QString ImgurUploaderTool::name() const
ImgurUploaderTool::name() const
{ {
return tr("Image Uploader"); return tr("Image Uploader");
} }
ToolType ToolType ImgurUploaderTool::nameID() const
ImgurUploaderTool::nameID() const
{ {
return ToolType::IMGUR; return ToolType::IMGUR;
} }
QString QString ImgurUploaderTool::description() const
ImgurUploaderTool::description() const
{ {
return tr("Upload the selection to Imgur"); return tr("Upload the selection to Imgur");
} }
QWidget* QWidget* ImgurUploaderTool::widget()
ImgurUploaderTool::widget()
{ {
return new ImgurUploader(capture); return new ImgurUploader(capture);
} }
CaptureTool* CaptureTool* ImgurUploaderTool::copy(QObject* parent)
ImgurUploaderTool::copy(QObject* parent)
{ {
return new ImgurUploaderTool(parent); return new ImgurUploaderTool(parent);
} }
void void ImgurUploaderTool::pressed(const CaptureContext& context)
ImgurUploaderTool::pressed(const CaptureContext& context)
{ {
capture = context.selectedScreenshotArea(); capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK); emit requestAction(REQ_CAPTURE_DONE_OK);

View File

@@ -22,50 +22,42 @@ AppLauncher::AppLauncher(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool AppLauncher::closeOnButtonPressed() const
AppLauncher::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon AppLauncher::icon(const QColor& background, bool inEditor) const
AppLauncher::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "open_with.svg"); return QIcon(iconPath(background) + "open_with.svg");
} }
QString QString AppLauncher::name() const
AppLauncher::name() const
{ {
return tr("App Launcher"); return tr("App Launcher");
} }
ToolType ToolType AppLauncher::nameID() const
AppLauncher::nameID() const
{ {
return ToolType::LAUNCHER; return ToolType::LAUNCHER;
} }
QString QString AppLauncher::description() const
AppLauncher::description() const
{ {
return tr("Choose an app to open the capture"); return tr("Choose an app to open the capture");
} }
QWidget* QWidget* AppLauncher::widget()
AppLauncher::widget()
{ {
return new AppLauncherWidget(capture); return new AppLauncherWidget(capture);
} }
CaptureTool* CaptureTool* AppLauncher::copy(QObject* parent)
AppLauncher::copy(QObject* parent)
{ {
return new AppLauncher(parent); return new AppLauncher(parent);
} }
void void AppLauncher::pressed(const CaptureContext& context)
AppLauncher::pressed(const CaptureContext& context)
{ {
capture = context.selectedScreenshotArea(); capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK); emit requestAction(REQ_CAPTURE_DONE_OK);

View File

@@ -97,8 +97,7 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap& p, QWidget* parent)
m_lineEdit->setFocus(); m_lineEdit->setFocus();
} }
void void AppLauncherWidget::launch(const QModelIndex& index)
AppLauncherWidget::launch(const QModelIndex& index)
{ {
if (!QFileInfo(m_tempFile).isReadable()) { if (!QFileInfo(m_tempFile).isReadable()) {
m_tempFile = m_tempFile =
@@ -131,16 +130,14 @@ AppLauncherWidget::launch(const QModelIndex& index)
} }
} }
void void AppLauncherWidget::checkboxClicked(const bool enabled)
AppLauncherWidget::checkboxClicked(const bool enabled)
{ {
m_keepOpen = enabled; m_keepOpen = enabled;
ConfigHandler().setKeepOpenAppLauncher(enabled); ConfigHandler().setKeepOpenAppLauncher(enabled);
m_keepOpenCheckbox->setChecked(enabled); m_keepOpenCheckbox->setChecked(enabled);
} }
void void AppLauncherWidget::searchChanged(const QString& text)
AppLauncherWidget::searchChanged(const QString& text)
{ {
if (text.isEmpty()) { if (text.isEmpty()) {
m_filterList->hide(); m_filterList->hide();
@@ -159,8 +156,8 @@ AppLauncherWidget::searchChanged(const QString& text)
} }
const QVector<DesktopAppData>& appList = m_appsMap[cat]; const QVector<DesktopAppData>& appList = m_appsMap[cat];
for (const DesktopAppData& app : appList) { for (const DesktopAppData& app : appList) {
if (!apps.contains(app) && if (!apps.contains(app) && (app.name.contains(regexp) ||
(app.name.contains(regexp) || app.description.contains(regexp))) { app.description.contains(regexp))) {
apps.append(app); apps.append(app);
} }
} }
@@ -169,8 +166,7 @@ AppLauncherWidget::searchChanged(const QString& text)
} }
} }
void void AppLauncherWidget::initListWidget()
AppLauncherWidget::initListWidget()
{ {
m_tabWidget = new QTabWidget; m_tabWidget = new QTabWidget;
const int size = GlobalValues::buttonBaseSize(); const int size = GlobalValues::buttonBaseSize();
@@ -199,8 +195,7 @@ AppLauncherWidget::initListWidget()
} }
} }
void void AppLauncherWidget::initAppMap()
AppLauncherWidget::initAppMap()
{ {
QStringList categories({ "AudioVideo", QStringList categories({ "AudioVideo",
"Audio", "Audio",
@@ -235,8 +230,7 @@ AppLauncherWidget::initAppMap()
m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList); m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList);
} }
void void AppLauncherWidget::configureListView(QListWidget* widget)
AppLauncherWidget::configureListView(QListWidget* widget)
{ {
widget->setItemDelegate(new LauncherItemDelegate()); widget->setItemDelegate(new LauncherItemDelegate());
widget->setViewMode(QListWidget::IconMode); widget->setViewMode(QListWidget::IconMode);
@@ -248,8 +242,8 @@ AppLauncherWidget::configureListView(QListWidget* widget)
connect(widget, &QListWidget::clicked, this, &AppLauncherWidget::launch); connect(widget, &QListWidget::clicked, this, &AppLauncherWidget::launch);
} }
void void AppLauncherWidget::addAppsToListWidget(
AppLauncherWidget::addAppsToListWidget(QListWidget* widget, QListWidget* widget,
const QVector<DesktopAppData>& appList) const QVector<DesktopAppData>& appList)
{ {
for (const DesktopAppData& app : appList) { for (const DesktopAppData& app : appList) {
@@ -258,7 +252,8 @@ AppLauncherWidget::addAppsToListWidget(QListWidget* widget,
buttonItem->setData(Qt::DisplayRole, app.name); buttonItem->setData(Qt::DisplayRole, app.name);
buttonItem->setData(Qt::UserRole, app.exec); buttonItem->setData(Qt::UserRole, app.exec);
buttonItem->setData(Qt::UserRole + 1, app.showInTerminal); buttonItem->setData(Qt::UserRole + 1, app.showInTerminal);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole()); QColor foregroundColor =
this->palette().color(QWidget::foregroundRole());
buttonItem->setForeground(foregroundColor); buttonItem->setForeground(foregroundColor);
buttonItem->setIcon(app.icon); buttonItem->setIcon(app.icon);

View File

@@ -23,8 +23,7 @@ LauncherItemDelegate::LauncherItemDelegate(QObject* parent)
: QStyledItemDelegate(parent) : QStyledItemDelegate(parent)
{} {}
void void LauncherItemDelegate::paint(QPainter* painter,
LauncherItemDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option, const QStyleOptionViewItem& option,
const QModelIndex& index) const const QModelIndex& index) const
{ {
@@ -33,7 +32,8 @@ LauncherItemDelegate::paint(QPainter* painter,
painter->save(); painter->save();
painter->setPen(Qt::transparent); painter->setPen(Qt::transparent);
painter->setBrush(QPalette().highlight()); painter->setBrush(QPalette().highlight());
painter->drawRect(rect.x(), rect.y(), rect.width() - 1, rect.height() - 1); painter->drawRect(
rect.x(), rect.y(), rect.width() - 1, rect.height() - 1);
painter->restore(); painter->restore();
} }
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
@@ -56,8 +56,7 @@ LauncherItemDelegate::paint(QPainter* painter,
index.data(Qt::DisplayRole).toString()); index.data(Qt::DisplayRole).toString());
} }
QSize QSize LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option,
LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const const QModelIndex& index) const
{ {
Q_UNUSED(option); Q_UNUSED(option);

View File

@@ -33,8 +33,7 @@
#include "src/tools/launcher/applauncherwidget.h" #include "src/tools/launcher/applauncherwidget.h"
#endif #endif
void void showOpenWithMenu(const QPixmap& capture)
showOpenWithMenu(const QPixmap& capture)
{ {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QString tempFile = QString tempFile =
@@ -43,7 +42,8 @@ showOpenWithMenu(const QPixmap& capture)
if (!ok) { if (!ok) {
QMessageBox::about(nullptr, QMessageBox::about(nullptr,
QObject::tr("Error"), QObject::tr("Error"),
QObject::tr("Unable to write in") + QDir::tempPath()); QObject::tr("Unable to write in") +
QDir::tempPath());
return; return;
} }

View File

@@ -19,5 +19,4 @@
#include <QPixmap> #include <QPixmap>
void void showOpenWithMenu(const QPixmap& capture);
showOpenWithMenu(const QPixmap& capture);

View File

@@ -42,8 +42,7 @@ TerminalLauncher::TerminalLauncher(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
TerminalApp TerminalApp TerminalLauncher::getPreferedTerminal()
TerminalLauncher::getPreferedTerminal()
{ {
TerminalApp res; TerminalApp res;
for (const TerminalApp& app : terminalApps) { for (const TerminalApp& app : terminalApps) {
@@ -56,8 +55,7 @@ TerminalLauncher::getPreferedTerminal()
return res; return res;
} }
bool bool TerminalLauncher::launchDetached(const QString& command)
TerminalLauncher::launchDetached(const QString& command)
{ {
TerminalApp app = getPreferedTerminal(); TerminalApp app = getPreferedTerminal();
QString s = app.name + " " + app.arg + " " + command; QString s = app.name + " " + app.arg + " " + command;

View File

@@ -31,38 +31,34 @@ LineTool::LineTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
QIcon QIcon LineTool::icon(const QColor& background, bool inEditor) const
LineTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "line.svg"); return QIcon(iconPath(background) + "line.svg");
} }
QString QString LineTool::name() const
LineTool::name() const
{ {
return tr("Line"); return tr("Line");
} }
ToolType ToolType LineTool::nameID() const
LineTool::nameID() const
{ {
return ToolType::LINE; return ToolType::LINE;
} }
QString QString LineTool::description() const
LineTool::description() const
{ {
return tr("Set the Line as the paint tool"); return tr("Set the Line as the paint tool");
} }
CaptureTool* CaptureTool* LineTool::copy(QObject* parent)
LineTool::copy(QObject* parent)
{ {
return new LineTool(parent); return new LineTool(parent);
} }
void void LineTool::process(QPainter& painter,
LineTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
updateBackup(pixmap); updateBackup(pixmap);
@@ -71,15 +67,14 @@ LineTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
painter.drawLine(m_points.first, m_points.second); painter.drawLine(m_points.first, m_points.second);
} }
void void LineTool::paintMousePreview(QPainter& painter,
LineTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness)); painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void LineTool::drawStart(const CaptureContext& context)
LineTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -87,8 +82,7 @@ LineTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void LineTool::pressed(const CaptureContext& context)
LineTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -31,38 +31,34 @@ MarkerTool::MarkerTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
QIcon QIcon MarkerTool::icon(const QColor& background, bool inEditor) const
MarkerTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "marker.svg"); return QIcon(iconPath(background) + "marker.svg");
} }
QString QString MarkerTool::name() const
MarkerTool::name() const
{ {
return tr("Marker"); return tr("Marker");
} }
ToolType ToolType MarkerTool::nameID() const
MarkerTool::nameID() const
{ {
return ToolType::MARKER; return ToolType::MARKER;
} }
QString QString MarkerTool::description() const
MarkerTool::description() const
{ {
return tr("Set the Marker as the paint tool"); return tr("Set the Marker as the paint tool");
} }
CaptureTool* CaptureTool* MarkerTool::copy(QObject* parent)
MarkerTool::copy(QObject* parent)
{ {
return new MarkerTool(parent); return new MarkerTool(parent);
} }
void void MarkerTool::process(QPainter& painter,
MarkerTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
updateBackup(pixmap); updateBackup(pixmap);
@@ -73,8 +69,8 @@ MarkerTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
painter.drawLine(m_points.first, m_points.second); painter.drawLine(m_points.first, m_points.second);
} }
void void MarkerTool::paintMousePreview(QPainter& painter,
MarkerTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
painter.setCompositionMode(QPainter::CompositionMode_Multiply); painter.setCompositionMode(QPainter::CompositionMode_Multiply);
painter.setOpacity(0.35); painter.setOpacity(0.35);
@@ -82,8 +78,7 @@ MarkerTool::paintMousePreview(QPainter& painter, const CaptureContext& context)
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void MarkerTool::drawStart(const CaptureContext& context)
MarkerTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -91,14 +86,12 @@ MarkerTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void MarkerTool::pressed(const CaptureContext& context)
MarkerTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }
void void MarkerTool::thicknessChanged(const int th)
MarkerTool::thicknessChanged(const int th)
{ {
m_thickness = th + PADDING_VALUE; m_thickness = th + PADDING_VALUE;
} }

View File

@@ -22,44 +22,37 @@ MoveTool::MoveTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool MoveTool::closeOnButtonPressed() const
MoveTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
QIcon QIcon MoveTool::icon(const QColor& background, bool inEditor) const
MoveTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cursor-move.svg"); return QIcon(iconPath(background) + "cursor-move.svg");
} }
QString QString MoveTool::name() const
MoveTool::name() const
{ {
return tr("Move"); return tr("Move");
} }
ToolType ToolType MoveTool::nameID() const
MoveTool::nameID() const
{ {
return ToolType::MOVE; return ToolType::MOVE;
} }
QString QString MoveTool::description() const
MoveTool::description() const
{ {
return tr("Move the selection area"); return tr("Move the selection area");
} }
CaptureTool* CaptureTool* MoveTool::copy(QObject* parent)
MoveTool::copy(QObject* parent)
{ {
return new MoveTool(parent); return new MoveTool(parent);
} }
void void MoveTool::pressed(const CaptureContext& context)
MoveTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
emit requestAction(REQ_MOVE_MODE); emit requestAction(REQ_MOVE_MODE);

View File

@@ -22,38 +22,34 @@ PencilTool::PencilTool(QObject* parent)
: AbstractPathTool(parent) : AbstractPathTool(parent)
{} {}
QIcon QIcon PencilTool::icon(const QColor& background, bool inEditor) const
PencilTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "pencil.svg"); return QIcon(iconPath(background) + "pencil.svg");
} }
QString QString PencilTool::name() const
PencilTool::name() const
{ {
return tr("Pencil"); return tr("Pencil");
} }
ToolType ToolType PencilTool::nameID() const
PencilTool::nameID() const
{ {
return ToolType::PENCIL; return ToolType::PENCIL;
} }
QString QString PencilTool::description() const
PencilTool::description() const
{ {
return tr("Set the Pencil as the paint tool"); return tr("Set the Pencil as the paint tool");
} }
CaptureTool* CaptureTool* PencilTool::copy(QObject* parent)
PencilTool::copy(QObject* parent)
{ {
return new PencilTool(parent); return new PencilTool(parent);
} }
void void PencilTool::process(QPainter& painter,
PencilTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
updateBackup(pixmap); updateBackup(pixmap);
@@ -62,15 +58,14 @@ PencilTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
painter.drawPolyline(m_points.data(), m_points.size()); painter.drawPolyline(m_points.data(), m_points.size());
} }
void void PencilTool::paintMousePreview(QPainter& painter,
PencilTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, context.thickness + 2)); painter.setPen(QPen(context.color, context.thickness + 2));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void PencilTool::drawStart(const CaptureContext& context)
PencilTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + 2; m_thickness = context.thickness + 2;
@@ -79,8 +74,7 @@ PencilTool::drawStart(const CaptureContext& context)
m_backupArea.setBottomRight(context.mousePos); m_backupArea.setBottomRight(context.mousePos);
} }
void void PencilTool::pressed(const CaptureContext& context)
PencilTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -22,38 +22,32 @@ PinTool::PinTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool PinTool::closeOnButtonPressed() const
PinTool::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon PinTool::icon(const QColor& background, bool inEditor) const
PinTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "pin.svg"); return QIcon(iconPath(background) + "pin.svg");
} }
QString QString PinTool::name() const
PinTool::name() const
{ {
return tr("Pin Tool"); return tr("Pin Tool");
} }
ToolType ToolType PinTool::nameID() const
PinTool::nameID() const
{ {
return ToolType::PIN; return ToolType::PIN;
} }
QString QString PinTool::description() const
PinTool::description() const
{ {
return tr("Pin image on the desktop"); return tr("Pin image on the desktop");
} }
QWidget* QWidget* PinTool::widget()
PinTool::widget()
{ {
PinWidget* w = new PinWidget(m_pixmap); PinWidget* w = new PinWidget(m_pixmap);
const int&& m = w->margin(); const int&& m = w->margin();
@@ -62,14 +56,12 @@ PinTool::widget()
return w; return w;
} }
CaptureTool* CaptureTool* PinTool::copy(QObject* parent)
PinTool::copy(QObject* parent)
{ {
return new PinTool(parent); return new PinTool(parent);
} }
void void PinTool::pressed(const CaptureContext& context)
PinTool::pressed(const CaptureContext& context)
{ {
emit requestAction(REQ_CAPTURE_DONE_OK); emit requestAction(REQ_CAPTURE_DONE_OK);
m_geometry = context.selection; m_geometry = context.selection;

View File

@@ -53,14 +53,12 @@ PinWidget::PinWidget(const QPixmap& pixmap, QWidget* parent)
new QShortcut(Qt::Key_Escape, this, SLOT(close())); new QShortcut(Qt::Key_Escape, this, SLOT(close()));
} }
int int PinWidget::margin() const
PinWidget::margin() const
{ {
return 7; return 7;
} }
void void PinWidget::wheelEvent(QWheelEvent* e)
PinWidget::wheelEvent(QWheelEvent* e)
{ {
int val = e->angleDelta().y() > 0 ? 15 : -15; int val = e->angleDelta().y() > 0 ? 15 : -15;
int newWidth = qBound(50, m_label->width() + val, maximumWidth()); int newWidth = qBound(50, m_label->width() + val, maximumWidth());
@@ -73,33 +71,28 @@ PinWidget::wheelEvent(QWheelEvent* e)
e->accept(); e->accept();
} }
void void PinWidget::enterEvent(QEvent*)
PinWidget::enterEvent(QEvent*)
{ {
m_shadowEffect->setColor(m_hoverColor); m_shadowEffect->setColor(m_hoverColor);
} }
void void PinWidget::leaveEvent(QEvent*)
PinWidget::leaveEvent(QEvent*)
{ {
m_shadowEffect->setColor(m_baseColor); m_shadowEffect->setColor(m_baseColor);
} }
void void PinWidget::mouseDoubleClickEvent(QMouseEvent*)
PinWidget::mouseDoubleClickEvent(QMouseEvent*)
{ {
close(); close();
} }
void void PinWidget::mousePressEvent(QMouseEvent* e)
PinWidget::mousePressEvent(QMouseEvent* e)
{ {
m_dragStart = e->globalPos(); m_dragStart = e->globalPos();
m_offsetX = e->localPos().x() / width(); m_offsetX = e->localPos().x() / width();
m_offsetY = e->localPos().y() / height(); m_offsetY = e->localPos().y() / height();
} }
void void PinWidget::mouseMoveEvent(QMouseEvent* e)
PinWidget::mouseMoveEvent(QMouseEvent* e)
{ {
const QPoint delta = e->globalPos() - m_dragStart; const QPoint delta = e->globalPos() - m_dragStart;
int offsetW = width() * m_offsetX; int offsetW = width() * m_offsetX;
@@ -108,8 +101,7 @@ PinWidget::mouseMoveEvent(QMouseEvent* e)
m_dragStart.y() + delta.y() - offsetH); m_dragStart.y() + delta.y() - offsetH);
} }
void void PinWidget::setScaledPixmap(const QSize& size)
PinWidget::setScaledPixmap(const QSize& size)
{ {
const qreal scale = qApp->devicePixelRatio(); const qreal scale = qApp->devicePixelRatio();
QPixmap scaledPixmap = m_pixmap.scaled( QPixmap scaledPixmap = m_pixmap.scaled(

View File

@@ -28,38 +28,34 @@ PixelateTool::PixelateTool(QObject* parent)
: AbstractTwoPointTool(parent) : AbstractTwoPointTool(parent)
{} {}
QIcon QIcon PixelateTool::icon(const QColor& background, bool inEditor) const
PixelateTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "pixelate.svg"); return QIcon(iconPath(background) + "pixelate.svg");
} }
QString QString PixelateTool::name() const
PixelateTool::name() const
{ {
return tr("Pixelate"); return tr("Pixelate");
} }
ToolType ToolType PixelateTool::nameID() const
PixelateTool::nameID() const
{ {
return ToolType::PIXELATE; return ToolType::PIXELATE;
} }
QString QString PixelateTool::description() const
PixelateTool::description() const
{ {
return tr("Set Pixelate as the paint tool"); return tr("Set Pixelate as the paint tool");
} }
CaptureTool* CaptureTool* PixelateTool::copy(QObject* parent)
PixelateTool::copy(QObject* parent)
{ {
return new PixelateTool(parent); return new PixelateTool(parent);
} }
void void PixelateTool::process(QPainter& painter,
PixelateTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (recordUndo) { if (recordUndo) {
@@ -99,24 +95,21 @@ PixelateTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
} }
} }
void void PixelateTool::paintMousePreview(QPainter& painter,
PixelateTool::paintMousePreview(QPainter& painter,
const CaptureContext& context) const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
Q_UNUSED(painter); Q_UNUSED(painter);
} }
void void PixelateTool::drawStart(const CaptureContext& context)
PixelateTool::drawStart(const CaptureContext& context)
{ {
m_thickness = context.thickness; m_thickness = context.thickness;
m_points.first = context.mousePos; m_points.first = context.mousePos;
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void PixelateTool::pressed(const CaptureContext& context)
PixelateTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -28,38 +28,32 @@ RectangleTool::RectangleTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
QIcon QIcon RectangleTool::icon(const QColor& background, bool inEditor) const
RectangleTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "square.svg"); return QIcon(iconPath(background) + "square.svg");
} }
QString QString RectangleTool::name() const
RectangleTool::name() const
{ {
return tr("Rectangle"); return tr("Rectangle");
} }
ToolType ToolType RectangleTool::nameID() const
RectangleTool::nameID() const
{ {
return ToolType::RECTANGLE; return ToolType::RECTANGLE;
} }
QString QString RectangleTool::description() const
RectangleTool::description() const
{ {
return tr("Set the Rectangle as the paint tool"); return tr("Set the Rectangle as the paint tool");
} }
CaptureTool* CaptureTool* RectangleTool::copy(QObject* parent)
RectangleTool::copy(QObject* parent)
{ {
return new RectangleTool(parent); return new RectangleTool(parent);
} }
void void RectangleTool::process(QPainter& painter,
RectangleTool::process(QPainter& painter,
const QPixmap& pixmap, const QPixmap& pixmap,
bool recordUndo) bool recordUndo)
{ {
@@ -71,16 +65,14 @@ RectangleTool::process(QPainter& painter,
painter.drawRect(QRect(m_points.first, m_points.second)); painter.drawRect(QRect(m_points.first, m_points.second));
} }
void void RectangleTool::paintMousePreview(QPainter& painter,
RectangleTool::paintMousePreview(QPainter& painter,
const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness)); painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void RectangleTool::drawStart(const CaptureContext& context)
RectangleTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -88,8 +80,7 @@ RectangleTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void RectangleTool::pressed(const CaptureContext& context)
RectangleTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -22,44 +22,37 @@ RedoTool::RedoTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool RedoTool::closeOnButtonPressed() const
RedoTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
QIcon QIcon RedoTool::icon(const QColor& background, bool inEditor) const
RedoTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "redo-variant.svg"); return QIcon(iconPath(background) + "redo-variant.svg");
} }
QString QString RedoTool::name() const
RedoTool::name() const
{ {
return tr("Redo"); return tr("Redo");
} }
ToolType ToolType RedoTool::nameID() const
RedoTool::nameID() const
{ {
return ToolType::REDO; return ToolType::REDO;
} }
QString QString RedoTool::description() const
RedoTool::description() const
{ {
return tr("Redo the next modification"); return tr("Redo the next modification");
} }
CaptureTool* CaptureTool* RedoTool::copy(QObject* parent)
RedoTool::copy(QObject* parent)
{ {
return new RedoTool(parent); return new RedoTool(parent);
} }
void void RedoTool::pressed(const CaptureContext& context)
RedoTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
emit requestAction(REQ_REDO_MODIFICATION); emit requestAction(REQ_REDO_MODIFICATION);

View File

@@ -23,49 +23,42 @@ SaveTool::SaveTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool SaveTool::closeOnButtonPressed() const
SaveTool::closeOnButtonPressed() const
{ {
return true; return true;
} }
QIcon QIcon SaveTool::icon(const QColor& background, bool inEditor) const
SaveTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "content-save.svg"); return QIcon(iconPath(background) + "content-save.svg");
} }
QString QString SaveTool::name() const
SaveTool::name() const
{ {
return tr("Save"); return tr("Save");
} }
ToolType ToolType SaveTool::nameID() const
SaveTool::nameID() const
{ {
return ToolType::SAVE; return ToolType::SAVE;
} }
QString QString SaveTool::description() const
SaveTool::description() const
{ {
return tr("Save the capture"); return tr("Save the capture");
} }
CaptureTool* CaptureTool* SaveTool::copy(QObject* parent)
SaveTool::copy(QObject* parent)
{ {
return new SaveTool(parent); return new SaveTool(parent);
} }
void void SaveTool::pressed(const CaptureContext& context)
SaveTool::pressed(const CaptureContext& context)
{ {
if (context.savePath.isEmpty()) { if (context.savePath.isEmpty()) {
emit requestAction(REQ_HIDE_GUI); emit requestAction(REQ_HIDE_GUI);
bool ok = bool ok = ScreenshotSaver().saveToFilesystemGUI(
ScreenshotSaver().saveToFilesystemGUI(context.selectedScreenshotArea()); context.selectedScreenshotArea());
if (ok) { if (ok) {
emit requestAction(REQ_CAPTURE_DONE_OK); emit requestAction(REQ_CAPTURE_DONE_OK);
} }

View File

@@ -28,44 +28,37 @@ SelectionTool::SelectionTool(QObject* parent)
m_supportsDiagonalAdj = true; m_supportsDiagonalAdj = true;
} }
bool bool SelectionTool::closeOnButtonPressed() const
SelectionTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
QIcon QIcon SelectionTool::icon(const QColor& background, bool inEditor) const
SelectionTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "square-outline.svg"); return QIcon(iconPath(background) + "square-outline.svg");
} }
QString QString SelectionTool::name() const
SelectionTool::name() const
{ {
return tr("Rectangular Selection"); return tr("Rectangular Selection");
} }
ToolType ToolType SelectionTool::nameID() const
SelectionTool::nameID() const
{ {
return ToolType::SELECTION; return ToolType::SELECTION;
} }
QString QString SelectionTool::description() const
SelectionTool::description() const
{ {
return tr("Set Selection as the paint tool"); return tr("Set Selection as the paint tool");
} }
CaptureTool* CaptureTool* SelectionTool::copy(QObject* parent)
SelectionTool::copy(QObject* parent)
{ {
return new SelectionTool(parent); return new SelectionTool(parent);
} }
void void SelectionTool::process(QPainter& painter,
SelectionTool::process(QPainter& painter,
const QPixmap& pixmap, const QPixmap& pixmap,
bool recordUndo) bool recordUndo)
{ {
@@ -76,16 +69,14 @@ SelectionTool::process(QPainter& painter,
painter.drawRect(QRect(m_points.first, m_points.second)); painter.drawRect(QRect(m_points.first, m_points.second));
} }
void void SelectionTool::paintMousePreview(QPainter& painter,
SelectionTool::paintMousePreview(QPainter& painter,
const CaptureContext& context) const CaptureContext& context)
{ {
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness)); painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
painter.drawLine(context.mousePos, context.mousePos); painter.drawLine(context.mousePos, context.mousePos);
} }
void void SelectionTool::drawStart(const CaptureContext& context)
SelectionTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_thickness = context.thickness + PADDING_VALUE; m_thickness = context.thickness + PADDING_VALUE;
@@ -93,8 +84,7 @@ SelectionTool::drawStart(const CaptureContext& context)
m_points.second = context.mousePos; m_points.second = context.mousePos;
} }
void void SelectionTool::pressed(const CaptureContext& context)
SelectionTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -22,44 +22,37 @@ SizeIndicatorTool::SizeIndicatorTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool SizeIndicatorTool::closeOnButtonPressed() const
SizeIndicatorTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
QIcon QIcon SizeIndicatorTool::icon(const QColor& background, bool inEditor) const
SizeIndicatorTool::icon(const QColor& background, bool inEditor) const
{ {
return inEditor ? QIcon() return inEditor ? QIcon()
: QIcon(iconPath(background) + "size_indicator.svg"); : QIcon(iconPath(background) + "size_indicator.svg");
} }
QString QString SizeIndicatorTool::name() const
SizeIndicatorTool::name() const
{ {
return tr("Selection Size Indicator"); return tr("Selection Size Indicator");
} }
ToolType ToolType SizeIndicatorTool::nameID() const
SizeIndicatorTool::nameID() const
{ {
return ToolType::SIZEINDICATOR; return ToolType::SIZEINDICATOR;
} }
QString QString SizeIndicatorTool::description() const
SizeIndicatorTool::description() const
{ {
return tr("Show the dimensions of the selection (X Y)"); return tr("Show the dimensions of the selection (X Y)");
} }
CaptureTool* CaptureTool* SizeIndicatorTool::copy(QObject* parent)
SizeIndicatorTool::copy(QObject* parent)
{ {
return new SizeIndicatorTool(parent); return new SizeIndicatorTool(parent);
} }
void void SizeIndicatorTool::pressed(const CaptureContext& context)
SizeIndicatorTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }

View File

@@ -71,8 +71,8 @@ TextConfig::TextConfig(QWidget* parent)
&TextConfig::weightButtonPressed); &TextConfig::weightButtonPressed);
m_weightButton->setToolTip(tr("Bold")); m_weightButton->setToolTip(tr("Bold"));
m_italicButton = m_italicButton = new QPushButton(QIcon(iconPrefix + "format_italic.svg"),
new QPushButton(QIcon(iconPrefix + "format_italic.svg"), QLatin1String("")); QLatin1String(""));
m_italicButton->setCheckable(true); m_italicButton->setCheckable(true);
connect(m_italicButton, connect(m_italicButton,
&QPushButton::clicked, &QPushButton::clicked,
@@ -89,32 +89,27 @@ TextConfig::TextConfig(QWidget* parent)
m_layout->addLayout(modifiersLayout); m_layout->addLayout(modifiersLayout);
} }
void void TextConfig::setUnderline(const bool u)
TextConfig::setUnderline(const bool u)
{ {
m_underlineButton->setChecked(u); m_underlineButton->setChecked(u);
} }
void void TextConfig::setStrikeOut(const bool s)
TextConfig::setStrikeOut(const bool s)
{ {
m_strikeOutButton->setChecked(s); m_strikeOutButton->setChecked(s);
} }
void void TextConfig::setWeight(const int w)
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 void TextConfig::setItalic(const bool i)
TextConfig::setItalic(const bool i)
{ {
m_italicButton->setChecked(i); m_italicButton->setChecked(i);
} }
void void TextConfig::weightButtonPressed(const bool w)
TextConfig::weightButtonPressed(const bool w)
{ {
if (w) { if (w) {
emit fontWeightChanged(QFont::Bold); emit fontWeightChanged(QFont::Bold);

View File

@@ -26,57 +26,48 @@ TextTool::TextTool(QObject* parent)
, m_size(1) , m_size(1)
{} {}
bool bool TextTool::isValid() const
TextTool::isValid() const
{ {
return !m_text.isEmpty(); return !m_text.isEmpty();
} }
bool bool TextTool::closeOnButtonPressed() const
TextTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
bool bool TextTool::isSelectable() const
TextTool::isSelectable() const
{ {
return true; return true;
} }
bool bool TextTool::showMousePreview() const
TextTool::showMousePreview() const
{ {
return false; return false;
} }
QIcon QIcon TextTool::icon(const QColor& background, bool inEditor) const
TextTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "text.svg"); return QIcon(iconPath(background) + "text.svg");
} }
QString QString TextTool::name() const
TextTool::name() const
{ {
return tr("Text"); return tr("Text");
} }
ToolType ToolType TextTool::nameID() const
TextTool::nameID() const
{ {
return ToolType::TEXT; return ToolType::TEXT;
} }
QString QString TextTool::description() const
TextTool::description() const
{ {
return tr("Add text to your capture"); return tr("Add text to your capture");
} }
QWidget* QWidget* TextTool::widget()
TextTool::widget()
{ {
TextWidget* w = new TextWidget(); TextWidget* w = new TextWidget();
w->setTextColor(m_color); w->setTextColor(m_color);
@@ -87,14 +78,15 @@ TextTool::widget()
return w; return w;
} }
QWidget* QWidget* TextTool::configurationWidget()
TextTool::configurationWidget()
{ {
m_confW = new TextConfig(); m_confW = new TextConfig();
connect( connect(
m_confW, &TextConfig::fontFamilyChanged, this, &TextTool::updateFamily); m_confW, &TextConfig::fontFamilyChanged, this, &TextTool::updateFamily);
connect( connect(m_confW,
m_confW, &TextConfig::fontItalicChanged, this, &TextTool::updateFontItalic); &TextConfig::fontItalicChanged,
this,
&TextTool::updateFontItalic);
connect(m_confW, connect(m_confW,
&TextConfig::fontStrikeOutChanged, &TextConfig::fontStrikeOutChanged,
this, this,
@@ -103,8 +95,10 @@ TextTool::configurationWidget()
&TextConfig::fontUnderlineChanged, &TextConfig::fontUnderlineChanged,
this, this,
&TextTool::updateFontUnderline); &TextTool::updateFontUnderline);
connect( connect(m_confW,
m_confW, &TextConfig::fontWeightChanged, this, &TextTool::updateFontWeight); &TextConfig::fontWeightChanged,
this,
&TextTool::updateFontWeight);
m_confW->setItalic(m_font.italic()); m_confW->setItalic(m_font.italic());
m_confW->setUnderline(m_font.underline()); m_confW->setUnderline(m_font.underline());
m_confW->setStrikeOut(m_font.strikeOut()); m_confW->setStrikeOut(m_font.strikeOut());
@@ -112,11 +106,11 @@ TextTool::configurationWidget()
return m_confW; return m_confW;
} }
CaptureTool* CaptureTool* TextTool::copy(QObject* parent)
TextTool::copy(QObject* parent)
{ {
TextTool* tt = new TextTool(parent); TextTool* tt = new TextTool(parent);
connect(m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily); connect(
m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);
connect( connect(
m_confW, &TextConfig::fontItalicChanged, tt, &TextTool::updateFontItalic); m_confW, &TextConfig::fontItalicChanged, tt, &TextTool::updateFontItalic);
connect(m_confW, connect(m_confW,
@@ -133,15 +127,15 @@ TextTool::copy(QObject* parent)
return tt; return tt;
} }
void void TextTool::undo(QPixmap& pixmap)
TextTool::undo(QPixmap& pixmap)
{ {
QPainter p(&pixmap); QPainter p(&pixmap);
p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup); p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup);
} }
void void TextTool::process(QPainter& painter,
TextTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo) const QPixmap& pixmap,
bool recordUndo)
{ {
if (m_text.isEmpty()) { if (m_text.isEmpty()) {
return; return;
@@ -158,41 +152,36 @@ TextTool::process(QPainter& painter, const QPixmap& pixmap, bool recordUndo)
painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text); painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text);
} }
void void TextTool::paintMousePreview(QPainter& painter,
TextTool::paintMousePreview(QPainter& painter, const CaptureContext& context) const CaptureContext& context)
{ {
Q_UNUSED(painter); Q_UNUSED(painter);
Q_UNUSED(context); Q_UNUSED(context);
} }
void void TextTool::drawEnd(const QPoint& p)
TextTool::drawEnd(const QPoint& p)
{ {
m_backupArea.moveTo(p); m_backupArea.moveTo(p);
} }
void void TextTool::drawMove(const QPoint& p)
TextTool::drawMove(const QPoint& p)
{ {
m_widget->move(p); m_widget->move(p);
} }
void void TextTool::drawStart(const CaptureContext& context)
TextTool::drawStart(const CaptureContext& context)
{ {
m_color = context.color; m_color = context.color;
m_size = context.thickness; m_size = context.thickness;
emit requestAction(REQ_ADD_CHILD_WIDGET); emit requestAction(REQ_ADD_CHILD_WIDGET);
} }
void void TextTool::pressed(const CaptureContext& context)
TextTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
} }
void void TextTool::colorChanged(const QColor& c)
TextTool::colorChanged(const QColor& c)
{ {
m_color = c; m_color = c;
if (m_widget) { if (m_widget) {
@@ -200,8 +189,7 @@ TextTool::colorChanged(const QColor& c)
} }
} }
void void TextTool::thicknessChanged(const int th)
TextTool::thicknessChanged(const int th)
{ {
m_size = th; m_size = th;
m_font.setPointSize(m_size + BASE_POINT_SIZE); m_font.setPointSize(m_size + BASE_POINT_SIZE);
@@ -210,14 +198,12 @@ TextTool::thicknessChanged(const int th)
} }
} }
void void TextTool::updateText(const QString& s)
TextTool::updateText(const QString& s)
{ {
m_text = s; m_text = s;
} }
void void TextTool::setFont(const QFont& f)
TextTool::setFont(const QFont& f)
{ {
m_font = f; m_font = f;
if (m_widget) { if (m_widget) {
@@ -225,8 +211,7 @@ TextTool::setFont(const QFont& f)
} }
} }
void void TextTool::updateFamily(const QString& s)
TextTool::updateFamily(const QString& s)
{ {
m_font.setFamily(s); m_font.setFamily(s);
if (m_widget) { if (m_widget) {
@@ -234,8 +219,7 @@ TextTool::updateFamily(const QString& s)
} }
} }
void void TextTool::updateFontUnderline(const bool underlined)
TextTool::updateFontUnderline(const bool underlined)
{ {
m_font.setUnderline(underlined); m_font.setUnderline(underlined);
if (m_widget) { if (m_widget) {
@@ -243,8 +227,7 @@ TextTool::updateFontUnderline(const bool underlined)
} }
} }
void void TextTool::updateFontStrikeOut(const bool s)
TextTool::updateFontStrikeOut(const bool s)
{ {
m_font.setStrikeOut(s); m_font.setStrikeOut(s);
if (m_widget) { if (m_widget) {
@@ -252,8 +235,7 @@ TextTool::updateFontStrikeOut(const bool s)
} }
} }
void void TextTool::updateFontWeight(const QFont::Weight w)
TextTool::updateFontWeight(const QFont::Weight w)
{ {
m_font.setWeight(w); m_font.setWeight(w);
if (m_widget) { if (m_widget) {
@@ -261,8 +243,7 @@ TextTool::updateFontWeight(const QFont::Weight w)
} }
} }
void void TextTool::updateFontItalic(const bool italic)
TextTool::updateFontItalic(const bool italic)
{ {
m_font.setItalic(italic); m_font.setItalic(italic);
if (m_widget) { if (m_widget) {

View File

@@ -28,8 +28,7 @@ TextWidget::TextWidget(QWidget* parent)
setContextMenuPolicy(Qt::NoContextMenu); setContextMenuPolicy(Qt::NoContextMenu);
} }
void void TextWidget::showEvent(QShowEvent* e)
TextWidget::showEvent(QShowEvent* e)
{ {
QFont font; QFont font;
QFontMetrics fm(font); QFontMetrics fm(font);
@@ -41,45 +40,39 @@ TextWidget::showEvent(QShowEvent* e)
adjustSize(); adjustSize();
} }
void void TextWidget::resizeEvent(QResizeEvent* e)
TextWidget::resizeEvent(QResizeEvent* e)
{ {
m_minSize.setHeight(qMin(m_baseSize.height(), height())); m_minSize.setHeight(qMin(m_baseSize.height(), height()));
m_minSize.setWidth(qMin(m_baseSize.width(), width())); m_minSize.setWidth(qMin(m_baseSize.width(), width()));
QTextEdit::resizeEvent(e); QTextEdit::resizeEvent(e);
} }
void void TextWidget::setFont(const QFont& f)
TextWidget::setFont(const QFont& f)
{ {
QTextEdit::setFont(f); QTextEdit::setFont(f);
adjustSize(); adjustSize();
} }
void void TextWidget::updateFont(const QFont& f)
TextWidget::updateFont(const QFont& f)
{ {
setFont(f); setFont(f);
} }
void void TextWidget::setFontPointSize(qreal s)
TextWidget::setFontPointSize(qreal s)
{ {
QFont f = font(); QFont f = font();
f.setPointSize(s); f.setPointSize(s);
setFont(f); setFont(f);
} }
void void TextWidget::setTextColor(const QColor& c)
TextWidget::setTextColor(const QColor& c)
{ {
QString s( QString s(
QStringLiteral("TextWidget { background: transparent; color: %1; }")); QStringLiteral("TextWidget { background: transparent; color: %1; }"));
setStyleSheet(s.arg(c.name())); setStyleSheet(s.arg(c.name()));
} }
void void TextWidget::adjustSize()
TextWidget::adjustSize()
{ {
QString&& text = this->toPlainText(); QString&& text = this->toPlainText();
@@ -97,8 +90,7 @@ TextWidget::adjustSize()
this->setFixedSize(pixelsWide, pixelsHigh); this->setFixedSize(pixelsWide, pixelsHigh);
} }
void void TextWidget::emitTextUpdated()
TextWidget::emitTextUpdated()
{ {
emit textUpdated(this->toPlainText()); emit textUpdated(this->toPlainText());
} }

View File

@@ -41,8 +41,8 @@ ToolFactory::ToolFactory(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
CaptureTool* CaptureTool* ToolFactory::CreateTool(CaptureToolButton::ButtonType t,
ToolFactory::CreateTool(CaptureToolButton::ButtonType t, QObject* parent) QObject* parent)
{ {
CaptureTool* tool; CaptureTool* tool;
switch (t) { switch (t) {

View File

@@ -22,44 +22,37 @@ UndoTool::UndoTool(QObject* parent)
: AbstractActionTool(parent) : AbstractActionTool(parent)
{} {}
bool bool UndoTool::closeOnButtonPressed() const
UndoTool::closeOnButtonPressed() const
{ {
return false; return false;
} }
QIcon QIcon UndoTool::icon(const QColor& background, bool inEditor) const
UndoTool::icon(const QColor& background, bool inEditor) const
{ {
Q_UNUSED(inEditor); Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "undo-variant.svg"); return QIcon(iconPath(background) + "undo-variant.svg");
} }
QString QString UndoTool::name() const
UndoTool::name() const
{ {
return tr("Undo"); return tr("Undo");
} }
ToolType ToolType UndoTool::nameID() const
UndoTool::nameID() const
{ {
return ToolType::UNDO; return ToolType::UNDO;
} }
QString QString UndoTool::description() const
UndoTool::description() const
{ {
return tr("Undo the last modification"); return tr("Undo the last modification");
} }
CaptureTool* CaptureTool* UndoTool::copy(QObject* parent)
UndoTool::copy(QObject* parent)
{ {
return new UndoTool(parent); return new UndoTool(parent);
} }
void void UndoTool::pressed(const CaptureContext& context)
UndoTool::pressed(const CaptureContext& context)
{ {
Q_UNUSED(context); Q_UNUSED(context);
emit requestAction(REQ_UNDO_MODIFICATION); emit requestAction(REQ_UNDO_MODIFICATION);

View File

@@ -17,14 +17,12 @@
#include "colorutils.h" #include "colorutils.h"
inline qreal inline qreal getColorLuma(const QColor& c)
getColorLuma(const QColor& c)
{ {
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF(); return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
} }
bool bool ColorUtils::colorIsDark(const QColor& c)
ColorUtils::colorIsDark(const QColor& c)
{ {
bool isWhite = false; bool isWhite = false;
if (getColorLuma(c) <= 0.60) { if (getColorLuma(c) <= 0.60) {
@@ -33,8 +31,7 @@ ColorUtils::colorIsDark(const QColor& c)
return isWhite; return isWhite;
} }
QColor QColor ColorUtils::contrastColor(const QColor& c)
ColorUtils::contrastColor(const QColor& c)
{ {
int change = colorIsDark(c) ? 30 : -45; int change = colorIsDark(c) ? 30 : -45;

View File

@@ -21,10 +21,8 @@
namespace ColorUtils { // namespace namespace ColorUtils { // namespace
bool bool colorIsDark(const QColor& c);
colorIsDark(const QColor& c);
QColor QColor contrastColor(const QColor& c);
contrastColor(const QColor& c);
} // namespace } // namespace

View File

@@ -26,8 +26,7 @@ ConfigHandler::ConfigHandler()
m_settings.setDefaultFormat(QSettings::IniFormat); m_settings.setDefaultFormat(QSettings::IniFormat);
} }
QVector<CaptureToolButton::ButtonType> QVector<CaptureToolButton::ButtonType> ConfigHandler::getButtons()
ConfigHandler::getButtons()
{ {
QVector<CaptureToolButton::ButtonType> buttons; QVector<CaptureToolButton::ButtonType> buttons;
if (m_settings.contains(QStringLiteral("buttons"))) { if (m_settings.contains(QStringLiteral("buttons"))) {
@@ -43,11 +42,13 @@ ConfigHandler::getButtons()
buttons = fromIntToButton(buttonsInt); buttons = fromIntToButton(buttonsInt);
} else { } else {
// Default tools // Default tools
buttons << CaptureToolButton::TYPE_PENCIL << CaptureToolButton::TYPE_DRAWER buttons << CaptureToolButton::TYPE_PENCIL
<< CaptureToolButton::TYPE_DRAWER
<< CaptureToolButton::TYPE_ARROW << CaptureToolButton::TYPE_ARROW
<< CaptureToolButton::TYPE_SELECTION << CaptureToolButton::TYPE_SELECTION
<< CaptureToolButton::TYPE_RECTANGLE << CaptureToolButton::TYPE_RECTANGLE
<< CaptureToolButton::TYPE_CIRCLE << CaptureToolButton::TYPE_MARKER << CaptureToolButton::TYPE_CIRCLE
<< CaptureToolButton::TYPE_MARKER
<< CaptureToolButton::TYPE_PIXELATE << CaptureToolButton::TYPE_PIXELATE
<< CaptureToolButton::TYPE_SELECTIONINDICATOR << CaptureToolButton::TYPE_SELECTIONINDICATOR
<< CaptureToolButton::TYPE_MOVESELECTION << CaptureToolButton::TYPE_MOVESELECTION
@@ -55,8 +56,8 @@ ConfigHandler::getButtons()
<< CaptureToolButton::TYPE_COPY << CaptureToolButton::TYPE_SAVE << CaptureToolButton::TYPE_COPY << CaptureToolButton::TYPE_SAVE
<< CaptureToolButton::TYPE_EXIT << CaptureToolButton::TYPE_EXIT
<< CaptureToolButton::TYPE_IMAGEUPLOADER << CaptureToolButton::TYPE_IMAGEUPLOADER
<< CaptureToolButton::TYPE_OPEN_APP << CaptureToolButton::TYPE_PIN << CaptureToolButton::TYPE_OPEN_APP
<< CaptureToolButton::TYPE_TEXT << CaptureToolButton::TYPE_PIN << CaptureToolButton::TYPE_TEXT
<< CaptureToolButton::TYPE_CIRCLECOUNT; << CaptureToolButton::TYPE_CIRCLECOUNT;
} }
@@ -68,8 +69,8 @@ ConfigHandler::getButtons()
return buttons; return buttons;
} }
void void ConfigHandler::setButtons(
ConfigHandler::setButtons(const QVector<CaptureToolButton::ButtonType>& buttons) const QVector<CaptureToolButton::ButtonType>& buttons)
{ {
QVector<int> l = fromButtonToInt(buttons); QVector<int> l = fromButtonToInt(buttons);
normalizeButtons(l); normalizeButtons(l);
@@ -78,8 +79,7 @@ ConfigHandler::setButtons(const QVector<CaptureToolButton::ButtonType>& buttons)
QVariant::fromValue(l.toList())); QVariant::fromValue(l.toList()));
} }
QVector<QColor> QVector<QColor> ConfigHandler::getUserColors()
ConfigHandler::getUserColors()
{ {
QVector<QColor> colors; QVector<QColor> colors;
const QVector<QColor>& defaultColors = { const QVector<QColor>& defaultColors = {
@@ -105,8 +105,7 @@ ConfigHandler::getUserColors()
return colors; return colors;
} }
void void ConfigHandler::setUserColors(const QVector<QColor>& l)
ConfigHandler::setUserColors(const QVector<QColor>& l)
{ {
QStringList hexColors; QStringList hexColors;
@@ -118,20 +117,17 @@ ConfigHandler::setUserColors(const QVector<QColor>& l)
QVariant::fromValue(hexColors)); QVariant::fromValue(hexColors));
} }
QString QString ConfigHandler::savePathValue()
ConfigHandler::savePathValue()
{ {
return m_settings.value(QStringLiteral("savePath")).toString(); return m_settings.value(QStringLiteral("savePath")).toString();
} }
void void ConfigHandler::setSavePath(const QString& savePath)
ConfigHandler::setSavePath(const QString& savePath)
{ {
m_settings.setValue(QStringLiteral("savePath"), savePath); m_settings.setValue(QStringLiteral("savePath"), savePath);
} }
QColor QColor ConfigHandler::uiMainColorValue()
ConfigHandler::uiMainColorValue()
{ {
QColor res = QColor(116, 0, 150); QColor res = QColor(116, 0, 150);
@@ -145,14 +141,12 @@ ConfigHandler::uiMainColorValue()
return res; return res;
} }
void void ConfigHandler::setUIMainColor(const QColor& c)
ConfigHandler::setUIMainColor(const QColor& c)
{ {
m_settings.setValue(QStringLiteral("uiColor"), c.name()); m_settings.setValue(QStringLiteral("uiColor"), c.name());
} }
QColor QColor ConfigHandler::uiContrastColorValue()
ConfigHandler::uiContrastColorValue()
{ {
QColor res = QColor(86, 0, 120); QColor res = QColor(86, 0, 120);
@@ -168,14 +162,12 @@ ConfigHandler::uiContrastColorValue()
return res; return res;
} }
void void ConfigHandler::setUIContrastColor(const QColor& c)
ConfigHandler::setUIContrastColor(const QColor& c)
{ {
m_settings.setValue(QStringLiteral("contrastUiColor"), c.name()); m_settings.setValue(QStringLiteral("contrastUiColor"), c.name());
} }
QColor QColor ConfigHandler::drawColorValue()
ConfigHandler::drawColorValue()
{ {
QColor res(Qt::red); QColor res(Qt::red);
@@ -190,14 +182,12 @@ ConfigHandler::drawColorValue()
return res; return res;
} }
void void ConfigHandler::setDrawColor(const QColor& c)
ConfigHandler::setDrawColor(const QColor& c)
{ {
m_settings.setValue(QStringLiteral("drawColor"), c.name()); m_settings.setValue(QStringLiteral("drawColor"), c.name());
} }
bool bool ConfigHandler::showHelpValue()
ConfigHandler::showHelpValue()
{ {
bool res = true; bool res = true;
if (m_settings.contains(QStringLiteral("showHelp"))) { if (m_settings.contains(QStringLiteral("showHelp"))) {
@@ -206,56 +196,50 @@ ConfigHandler::showHelpValue()
return res; return res;
} }
void void ConfigHandler::setShowHelp(const bool showHelp)
ConfigHandler::setShowHelp(const bool showHelp)
{ {
m_settings.setValue(QStringLiteral("showHelp"), showHelp); m_settings.setValue(QStringLiteral("showHelp"), showHelp);
} }
bool bool ConfigHandler::showSidePanelButtonValue()
ConfigHandler::showSidePanelButtonValue()
{ {
return m_settings.value(QStringLiteral("showSidePanelButton"), true).toBool(); return m_settings.value(QStringLiteral("showSidePanelButton"), true)
.toBool();
} }
void void ConfigHandler::setShowSidePanelButton(const bool showSidePanelButton)
ConfigHandler::setShowSidePanelButton(const bool showSidePanelButton)
{ {
m_settings.setValue(QStringLiteral("showSidePanelButton"), m_settings.setValue(QStringLiteral("showSidePanelButton"),
showSidePanelButton); showSidePanelButton);
} }
bool bool ConfigHandler::desktopNotificationValue()
ConfigHandler::desktopNotificationValue()
{ {
bool res = true; bool res = true;
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) { if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool(); res =
m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
} }
return res; return res;
} }
void void ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
{ {
m_settings.setValue(QStringLiteral("showDesktopNotification"), m_settings.setValue(QStringLiteral("showDesktopNotification"),
showDesktopNotification); showDesktopNotification);
} }
QString QString ConfigHandler::filenamePatternValue()
ConfigHandler::filenamePatternValue()
{ {
return m_settings.value(QStringLiteral("filenamePattern")).toString(); return m_settings.value(QStringLiteral("filenamePattern")).toString();
} }
void void ConfigHandler::setFilenamePattern(const QString& pattern)
ConfigHandler::setFilenamePattern(const QString& pattern)
{ {
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern); return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
} }
bool bool ConfigHandler::disabledTrayIconValue()
ConfigHandler::disabledTrayIconValue()
{ {
bool res = false; bool res = false;
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) { if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
@@ -264,14 +248,12 @@ ConfigHandler::disabledTrayIconValue()
return res; return res;
} }
void void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
{ {
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon); m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
} }
int int ConfigHandler::drawThicknessValue()
ConfigHandler::drawThicknessValue()
{ {
int res = 0; int res = 0;
if (m_settings.contains(QStringLiteral("drawThickness"))) { if (m_settings.contains(QStringLiteral("drawThickness"))) {
@@ -280,26 +262,22 @@ ConfigHandler::drawThicknessValue()
return res; return res;
} }
void void ConfigHandler::setdrawThickness(const int thickness)
ConfigHandler::setdrawThickness(const int thickness)
{ {
m_settings.setValue(QStringLiteral("drawThickness"), thickness); m_settings.setValue(QStringLiteral("drawThickness"), thickness);
} }
bool bool ConfigHandler::keepOpenAppLauncherValue()
ConfigHandler::keepOpenAppLauncherValue()
{ {
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool(); return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
} }
void void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
{ {
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen); m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
} }
bool bool ConfigHandler::startupLaunchValue()
ConfigHandler::startupLaunchValue()
{ {
bool res = false; bool res = false;
@@ -314,8 +292,7 @@ ConfigHandler::startupLaunchValue()
return res; return res;
} }
bool bool ConfigHandler::verifyLaunchFile()
ConfigHandler::verifyLaunchFile()
{ {
bool res = false; bool res = false;
@@ -332,8 +309,7 @@ ConfigHandler::verifyLaunchFile()
return res; return res;
} }
void void ConfigHandler::setStartupLaunch(const bool start)
ConfigHandler::setStartupLaunch(const bool start)
{ {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
QString path = QDir::homePath() + "/.config/autostart/"; QString path = QDir::homePath() + "/.config/autostart/";
@@ -368,8 +344,7 @@ ConfigHandler::setStartupLaunch(const bool start)
m_settings.setValue(QStringLiteral("startupLaunch"), start); m_settings.setValue(QStringLiteral("startupLaunch"), start);
} }
int int ConfigHandler::contrastOpacityValue()
ConfigHandler::contrastOpacityValue()
{ {
int opacity = 190; int opacity = 190;
if (m_settings.contains(QStringLiteral("contrastOpacity"))) { if (m_settings.contains(QStringLiteral("contrastOpacity"))) {
@@ -379,67 +354,56 @@ ConfigHandler::contrastOpacityValue()
return opacity; return opacity;
} }
void void ConfigHandler::setContrastOpacity(const int transparency)
ConfigHandler::setContrastOpacity(const int transparency)
{ {
m_settings.setValue(QStringLiteral("contrastOpacity"), transparency); m_settings.setValue(QStringLiteral("contrastOpacity"), transparency);
} }
bool bool ConfigHandler::closeAfterScreenshotValue()
ConfigHandler::closeAfterScreenshotValue()
{ {
return m_settings.value(QStringLiteral("closeAfterScreenshot")).toBool(); return m_settings.value(QStringLiteral("closeAfterScreenshot")).toBool();
} }
void void ConfigHandler::setCloseAfterScreenshot(const bool close)
ConfigHandler::setCloseAfterScreenshot(const bool close)
{ {
m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close); m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close);
} }
bool bool ConfigHandler::copyAndCloseAfterUploadEnabled()
ConfigHandler::copyAndCloseAfterUploadEnabled()
{ {
return m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool(); return m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
} }
void void ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value)
ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value)
{ {
m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value); m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value);
} }
bool bool ConfigHandler::saveAfterCopyValue()
ConfigHandler::saveAfterCopyValue()
{ {
return m_settings.value(QStringLiteral("saveAfterCopy")).toBool(); return m_settings.value(QStringLiteral("saveAfterCopy")).toBool();
} }
void void ConfigHandler::setSaveAfterCopy(const bool save)
ConfigHandler::setSaveAfterCopy(const bool save)
{ {
m_settings.setValue(QStringLiteral("saveAfterCopy"), save); m_settings.setValue(QStringLiteral("saveAfterCopy"), save);
} }
QString QString ConfigHandler::saveAfterCopyPathValue()
ConfigHandler::saveAfterCopyPathValue()
{ {
return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString(); return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString();
} }
void void ConfigHandler::setSaveAfterCopyPath(const QString& path)
ConfigHandler::setSaveAfterCopyPath(const QString& path)
{ {
m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path); m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path);
} }
void void ConfigHandler::setDefaults()
ConfigHandler::setDefaults()
{ {
m_settings.clear(); m_settings.clear();
} }
void void ConfigHandler::setAllTheButtons()
ConfigHandler::setAllTheButtons()
{ {
QVector<int> buttons; QVector<int> buttons;
auto listTypes = CaptureToolButton::getIterableButtonTypes(); auto listTypes = CaptureToolButton::getIterableButtonTypes();
@@ -451,14 +415,12 @@ ConfigHandler::setAllTheButtons()
QVariant::fromValue(buttons.toList())); QVariant::fromValue(buttons.toList()));
} }
QString QString ConfigHandler::configFilePath() const
ConfigHandler::configFilePath() const
{ {
return m_settings.fileName(); return m_settings.fileName();
} }
bool bool ConfigHandler::normalizeButtons(QVector<int>& buttons)
ConfigHandler::normalizeButtons(QVector<int>& buttons)
{ {
auto listTypes = CaptureToolButton::getIterableButtonTypes(); auto listTypes = CaptureToolButton::getIterableButtonTypes();
QVector<int> listTypesInt; QVector<int> listTypesInt;
@@ -475,8 +437,8 @@ ConfigHandler::normalizeButtons(QVector<int>& buttons)
return hasChanged; return hasChanged;
} }
QVector<CaptureToolButton::ButtonType> QVector<CaptureToolButton::ButtonType> ConfigHandler::fromIntToButton(
ConfigHandler::fromIntToButton(const QVector<int>& l) const QVector<int>& l)
{ {
QVector<CaptureToolButton::ButtonType> buttons; QVector<CaptureToolButton::ButtonType> buttons;
for (auto const i : l) for (auto const i : l)
@@ -484,8 +446,8 @@ ConfigHandler::fromIntToButton(const QVector<int>& l)
return buttons; return buttons;
} }
QVector<int> QVector<int> ConfigHandler::fromButtonToInt(
ConfigHandler::fromButtonToInt(const QVector<CaptureToolButton::ButtonType>& l) const QVector<CaptureToolButton::ButtonType>& l)
{ {
QVector<int> buttons; QVector<int> buttons;
for (auto const i : l) for (auto const i : l)

View File

@@ -93,6 +93,8 @@ private:
bool normalizeButtons(QVector<int>&); bool normalizeButtons(QVector<int>&);
QVector<CaptureToolButton::ButtonType> fromIntToButton(const QVector<int>& l); QVector<CaptureToolButton::ButtonType> fromIntToButton(
QVector<int> fromButtonToInt(const QVector<CaptureToolButton::ButtonType>& l); const QVector<int>& l);
QVector<int> fromButtonToInt(
const QVector<CaptureToolButton::ButtonType>& l);
}; };

View File

@@ -25,8 +25,7 @@ DBusUtils::DBusUtils(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
void void DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
{ {
m_id = id; m_id = id;
// captureTaken // captureTaken
@@ -45,8 +44,7 @@ DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
SLOT(captureFailed(uint))); SLOT(captureFailed(uint)));
} }
void void DBusUtils::checkDBusConnection(const QDBusConnection& connection)
DBusUtils::checkDBusConnection(const QDBusConnection& connection)
{ {
if (!connection.isConnected()) { if (!connection.isConnected()) {
SystemNotification().sendMessage(tr("Unable to connect via DBus")); SystemNotification().sendMessage(tr("Unable to connect via DBus"));
@@ -54,8 +52,7 @@ DBusUtils::checkDBusConnection(const QDBusConnection& connection)
} }
} }
void void DBusUtils::captureTaken(uint id, QByteArray rawImage)
DBusUtils::captureTaken(uint id, QByteArray rawImage)
{ {
if (m_id == id) { if (m_id == id) {
QFile file; QFile file;
@@ -66,8 +63,7 @@ DBusUtils::captureTaken(uint id, QByteArray rawImage)
} }
} }
void void DBusUtils::captureFailed(uint id)
DBusUtils::captureFailed(uint id)
{ {
if (m_id == id) { if (m_id == id) {
QTextStream(stdout) << "screenshot aborted\n"; QTextStream(stdout) << "screenshot aborted\n";

View File

@@ -30,11 +30,12 @@ DesktopFileParser::DesktopFileParser()
m_localeDescription = QStringLiteral("Comment[%1]").arg(locale); m_localeDescription = QStringLiteral("Comment[%1]").arg(locale);
m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort); m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort);
m_localeDescriptionShort = QStringLiteral("Comment[%1]").arg(localeShort); m_localeDescriptionShort = QStringLiteral("Comment[%1]").arg(localeShort);
m_defaultIcon = QIcon::fromTheme(QStringLiteral("application-x-executable")); m_defaultIcon =
QIcon::fromTheme(QStringLiteral("application-x-executable"));
} }
DesktopAppData DesktopAppData DesktopFileParser::parseDesktopFile(const QString& fileName,
DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const bool& ok) const
{ {
DesktopAppData res; DesktopAppData res;
ok = true; ok = true;
@@ -58,11 +59,14 @@ DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(), line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(),
m_defaultIcon); m_defaultIcon);
} else if (!nameLocaleSet && line.startsWith(QLatin1String("Name"))) { } else if (!nameLocaleSet && line.startsWith(QLatin1String("Name"))) {
if (line.startsWith(m_localeName) || line.startsWith(m_localeNameShort)) { if (line.startsWith(m_localeName) ||
res.name = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(); line.startsWith(m_localeNameShort)) {
res.name =
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
nameLocaleSet = true; nameLocaleSet = true;
} else if (line.startsWith(QLatin1String("Name="))) { } else if (line.startsWith(QLatin1String("Name="))) {
res.name = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(); res.name =
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
} }
} else if (!descriptionLocaleSet && } else if (!descriptionLocaleSet &&
line.startsWith(QLatin1String("Comment"))) { line.startsWith(QLatin1String("Comment"))) {
@@ -77,7 +81,8 @@ DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const
} }
} else if (line.startsWith(QLatin1String("Exec"))) { } else if (line.startsWith(QLatin1String("Exec"))) {
if (line.contains(QLatin1String("%"))) { if (line.contains(QLatin1String("%"))) {
res.exec = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(); res.exec =
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
} else { } else {
ok = false; ok = false;
break; break;
@@ -107,8 +112,7 @@ DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const
return res; return res;
} }
int int DesktopFileParser::processDirectory(const QDir& dir)
DesktopFileParser::processDirectory(const QDir& dir)
{ {
QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files); QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
bool ok; bool ok;
@@ -122,8 +126,8 @@ DesktopFileParser::processDirectory(const QDir& dir)
return m_appList.length() - length; return m_appList.length() - length;
} }
QVector<DesktopAppData> QVector<DesktopAppData> DesktopFileParser::getAppsByCategory(
DesktopFileParser::getAppsByCategory(const QString& category) const QString& category)
{ {
QVector<DesktopAppData> res; QVector<DesktopAppData> res;
for (const DesktopAppData& app : m_appList) { for (const DesktopAppData& app : m_appList) {
@@ -134,8 +138,8 @@ DesktopFileParser::getAppsByCategory(const QString& category)
return res; return res;
} }
QMap<QString, QVector<DesktopAppData>> QMap<QString, QVector<DesktopAppData>> DesktopFileParser::getAppsByCategory(
DesktopFileParser::getAppsByCategory(const QStringList& categories) const QStringList& categories)
{ {
QMap<QString, QVector<DesktopAppData>> res; QMap<QString, QVector<DesktopAppData>> res;
for (const DesktopAppData& app : m_appList) { for (const DesktopAppData& app : m_appList) {

View File

@@ -30,16 +30,14 @@ DesktopInfo::DesktopInfo()
DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION")); DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION"));
} }
bool bool DesktopInfo::waylandDectected()
DesktopInfo::waylandDectected()
{ {
return XDG_SESSION_TYPE == QLatin1String("wayland") || return XDG_SESSION_TYPE == QLatin1String("wayland") ||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"), WAYLAND_DISPLAY.contains(QLatin1String("wayland"),
Qt::CaseInsensitive); Qt::CaseInsensitive);
} }
DesktopInfo::WM DesktopInfo::WM DesktopInfo::windowManager()
DesktopInfo::windowManager()
{ {
DesktopInfo::WM res = DesktopInfo::OTHER; DesktopInfo::WM res = DesktopInfo::OTHER;
if (XDG_CURRENT_DESKTOP.contains(QLatin1String("GNOME"), if (XDG_CURRENT_DESKTOP.contains(QLatin1String("GNOME"),

View File

@@ -28,14 +28,12 @@ FileNameHandler::FileNameHandler(QObject* parent)
std::locale::global(std::locale("")); std::locale::global(std::locale(""));
} }
QString QString FileNameHandler::parsedPattern()
FileNameHandler::parsedPattern()
{ {
return parseFilename(ConfigHandler().filenamePatternValue()); return parseFilename(ConfigHandler().filenamePatternValue());
} }
QString QString FileNameHandler::parseFilename(const QString& name)
FileNameHandler::parseFilename(const QString& name)
{ {
QString res = name; QString res = name;
if (name.isEmpty()) { if (name.isEmpty()) {
@@ -55,8 +53,7 @@ FileNameHandler::parseFilename(const QString& name)
return res; return res;
} }
QString QString FileNameHandler::generateAbsolutePath(const QString& path)
FileNameHandler::generateAbsolutePath(const QString& path)
{ {
QString directory = path; QString directory = path;
QString filename = parsedPattern(); QString filename = parsedPattern();
@@ -64,14 +61,12 @@ FileNameHandler::generateAbsolutePath(const QString& path)
return directory + filename; return directory + filename;
} }
// path a images si no existe, add numeration // path a images si no existe, add numeration
void void FileNameHandler::setPattern(const QString& pattern)
FileNameHandler::setPattern(const QString& pattern)
{ {
ConfigHandler().setFilenamePattern(pattern); ConfigHandler().setFilenamePattern(pattern);
} }
QString QString FileNameHandler::absoluteSavePath(QString& directory, QString& filename)
FileNameHandler::absoluteSavePath(QString& directory, QString& filename)
{ {
ConfigHandler config; ConfigHandler config;
directory = config.savePathValue(); directory = config.savePathValue();
@@ -85,28 +80,24 @@ FileNameHandler::absoluteSavePath(QString& directory, QString& filename)
return directory + filename; return directory + filename;
} }
QString QString FileNameHandler::absoluteSavePath()
FileNameHandler::absoluteSavePath()
{ {
QString dir, file; QString dir, file;
return absoluteSavePath(dir, file); return absoluteSavePath(dir, file);
} }
QString QString FileNameHandler::charArrToQString(const char* c)
FileNameHandler::charArrToQString(const char* c)
{ {
return QString::fromLocal8Bit(c, MAX_CHARACTERS); return QString::fromLocal8Bit(c, MAX_CHARACTERS);
} }
char* char* FileNameHandler::QStringTocharArr(const QString& s)
FileNameHandler::QStringTocharArr(const QString& s)
{ {
QByteArray ba = s.toLocal8Bit(); QByteArray ba = s.toLocal8Bit();
return const_cast<char*>(strdup(ba.constData())); return const_cast<char*>(strdup(ba.constData()));
} }
void void FileNameHandler::fixPath(QString& directory, QString& filename)
FileNameHandler::fixPath(QString& directory, QString& filename)
{ {
// add '/' at the end of the directory // add '/' at the end of the directory
if (!directory.endsWith(QLatin1String("/"))) { if (!directory.endsWith(QLatin1String("/"))) {
@@ -119,7 +110,8 @@ FileNameHandler::fixPath(QString& directory, QString& filename)
filename += QLatin1String("_"); filename += QLatin1String("_");
int i = 1; int i = 1;
while (true) { while (true) {
checkFile.setFile(directory + filename + QString::number(i) + ".png"); checkFile.setFile(directory + filename + QString::number(i) +
".png");
if (!checkFile.exists()) { if (!checkFile.exists()) {
filename += QString::number(i); filename += QString::number(i);
break; break;

View File

@@ -19,8 +19,7 @@
#include <QApplication> #include <QApplication>
#include <QFontMetrics> #include <QFontMetrics>
int int GlobalValues::buttonBaseSize()
GlobalValues::buttonBaseSize()
{ {
return QApplication::fontMetrics().lineSpacing() * 2.2; return QApplication::fontMetrics().lineSpacing() * 2.2;
} }

View File

@@ -19,7 +19,6 @@
namespace GlobalValues { namespace GlobalValues {
int int buttonBaseSize();
buttonBaseSize();
} }

View File

@@ -20,22 +20,20 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
const QString const QString PathInfo::whiteIconPath()
PathInfo::whiteIconPath()
{ {
return QStringLiteral(":/img/material/white/"); return QStringLiteral(":/img/material/white/");
} }
const QString const QString PathInfo::blackIconPath()
PathInfo::blackIconPath()
{ {
return QStringLiteral(":/img/material/black/"); return QStringLiteral(":/img/material/black/");
} }
QStringList QStringList PathInfo::translationsPaths()
PathInfo::translationsPaths()
{ {
QString binaryPath = QFileInfo(qApp->applicationDirPath()).absoluteFilePath(); QString binaryPath =
QFileInfo(qApp->applicationDirPath()).absoluteFilePath();
QString trPath = QDir::toNativeSeparators(binaryPath + "/translations"); QString trPath = QDir::toNativeSeparators(binaryPath + "/translations");
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
return QStringList() return QStringList()

View File

@@ -21,13 +21,10 @@
namespace PathInfo { // namespace namespace PathInfo { // namespace
const QString const QString whiteIconPath();
whiteIconPath();
const QString const QString blackIconPath();
blackIconPath();
QStringList QStringList translationsPaths();
translationsPaths();
} // namespace } // namespace

View File

@@ -34,8 +34,7 @@ ScreenGrabber::ScreenGrabber(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
QPixmap QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
ScreenGrabber::grabEntireDesktop(bool& ok)
{ {
ok = true; ok = true;
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
@@ -46,13 +45,14 @@ ScreenGrabber::grabEntireDesktop(bool& ok)
case DesktopInfo::GNOME: { case DesktopInfo::GNOME: {
// https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/data/org.gnome.Shell.Screenshot.xml // https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/data/org.gnome.Shell.Screenshot.xml
QString path = QString path =
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png"; FileNameHandler().generateAbsolutePath(QDir::tempPath()) +
".png";
QDBusInterface gnomeInterface( QDBusInterface gnomeInterface(
QStringLiteral("org.gnome.Shell"), QStringLiteral("org.gnome.Shell"),
QStringLiteral("/org/gnome/Shell/Screenshot"), QStringLiteral("/org/gnome/Shell/Screenshot"),
QStringLiteral("org.gnome.Shell.Screenshot")); QStringLiteral("org.gnome.Shell.Screenshot"));
QDBusReply<bool> reply = QDBusReply<bool> reply = gnomeInterface.call(
gnomeInterface.call(QStringLiteral("Screenshot"), false, false, path); QStringLiteral("Screenshot"), false, false, path);
if (reply.value()) { if (reply.value()) {
res = QPixmap(path); res = QPixmap(path);
QFile dbusResult(path); QFile dbusResult(path);
@@ -64,7 +64,8 @@ ScreenGrabber::grabEntireDesktop(bool& ok)
} }
case DesktopInfo::KDE: { case DesktopInfo::KDE: {
// https://github.com/KDE/spectacle/blob/517a7baf46a4ca0a45f32fd3f2b1b7210b180134/src/PlatformBackends/KWinWaylandImageGrabber.cpp#L145 // https://github.com/KDE/spectacle/blob/517a7baf46a4ca0a45f32fd3f2b1b7210b180134/src/PlatformBackends/KWinWaylandImageGrabber.cpp#L145
QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"), QDBusInterface kwinInterface(
QStringLiteral("org.kde.KWin"),
QStringLiteral("/Screenshot"), QStringLiteral("/Screenshot"),
QStringLiteral("org.kde.kwin.Screenshot")); QStringLiteral("org.kde.kwin.Screenshot"));
QDBusReply<QString> reply = QDBusReply<QString> reply =
@@ -92,8 +93,8 @@ ScreenGrabber::grabEntireDesktop(bool& ok)
geometry = geometry.united(screen->geometry()); geometry = geometry.united(screen->geometry());
} }
QPixmap p( QPixmap p(QApplication::primaryScreen()->grabWindow(
QApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(), QApplication::desktop()->winId(),
geometry.x(), geometry.x(),
geometry.y(), geometry.y(),
geometry.width(), geometry.width(),
@@ -104,8 +105,7 @@ ScreenGrabber::grabEntireDesktop(bool& ok)
return p; return p;
} }
QPixmap QPixmap ScreenGrabber::grabScreen(int screenNumber, bool& ok)
ScreenGrabber::grabScreen(int screenNumber, bool& ok)
{ {
QPixmap p; QPixmap p;
bool isVirtual = QApplication::desktop()->isVirtualDesktop(); bool isVirtual = QApplication::desktop()->isVirtualDesktop();
@@ -122,7 +122,8 @@ ScreenGrabber::grabScreen(int screenNumber, bool& ok)
} }
} }
#endif #endif
QRect geometry = QApplication::desktop()->screenGeometry(screenNumber); QRect geometry =
QApplication::desktop()->screenGeometry(screenNumber);
geometry.moveTo(geometry.topLeft() - topLeft); geometry.moveTo(geometry.topLeft() - topLeft);
p = p.copy(geometry); p = p.copy(geometry);
} }

View File

@@ -29,8 +29,7 @@ ScreenshotSaver::ScreenshotSaver() {}
// TODO: If data is saved to the clipboard before the notification is sent via // TODO: If data is saved to the clipboard before the notification is sent via
// dbus, the application freezes. // dbus, the application freezes.
void void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
ScreenshotSaver::saveToClipboard(const QPixmap& capture)
{ {
// If we are able to properly save the file, save the file and copy to // If we are able to properly save the file, save the file and copy to
@@ -44,13 +43,13 @@ ScreenshotSaver::saveToClipboard(const QPixmap& capture)
} }
// Otherwise only save to clipboard // Otherwise only save to clipboard
else { else {
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard")); SystemNotification().sendMessage(
QObject::tr("Capture saved to clipboard"));
QApplication::clipboard()->setPixmap(capture); QApplication::clipboard()->setPixmap(capture);
} }
} }
bool bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
const QString& path, const QString& path,
const QString& messagePrefix) const QString& messagePrefix)
{ {
@@ -65,8 +64,8 @@ ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
saveMessage = saveMessage =
messagePrefix + QObject::tr("Capture saved as ") + completePath; messagePrefix + QObject::tr("Capture saved as ") + completePath;
} else { } else {
saveMessage = saveMessage = messagePrefix + QObject::tr("Error trying to save as ") +
messagePrefix + QObject::tr("Error trying to save as ") + completePath; completePath;
notificationPath = ""; notificationPath = "";
} }
@@ -74,8 +73,7 @@ ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
return ok; return ok;
} }
bool bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
{ {
bool ok = false; bool ok = false;

View File

@@ -30,14 +30,13 @@ SystemNotification::SystemNotification(QObject* parent)
} }
#endif #endif
void void SystemNotification::sendMessage(const QString& text,
SystemNotification::sendMessage(const QString& text, const QString& savePath) const QString& savePath)
{ {
sendMessage(text, tr("Flameshot Info"), savePath); sendMessage(text, tr("Flameshot Info"), savePath);
} }
void void SystemNotification::sendMessage(const QString& text,
SystemNotification::sendMessage(const QString& text,
const QString& title, const QString& title,
const QString& savePath, const QString& savePath,
const int timeout) const int timeout)

View File

@@ -2,6 +2,4 @@
WaylandUtils::WaylandUtils() {} WaylandUtils::WaylandUtils() {}
bool bool WaylandUtils::waylandDetected() {}
WaylandUtils::waylandDetected()
{}

View File

@@ -38,15 +38,13 @@ ButtonHandler::ButtonHandler(QObject* parent)
init(); init();
} }
void void ButtonHandler::hide()
ButtonHandler::hide()
{ {
for (CaptureToolButton* b : m_vectorButtons) for (CaptureToolButton* b : m_vectorButtons)
b->hide(); b->hide();
} }
void void ButtonHandler::show()
ButtonHandler::show()
{ {
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) { if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
return; return;
@@ -55,8 +53,7 @@ ButtonHandler::show()
b->animatedShow(); b->animatedShow();
} }
bool bool ButtonHandler::isVisible() const
ButtonHandler::isVisible() const
{ {
bool ret = true; bool ret = true;
for (const CaptureToolButton* b : m_vectorButtons) { for (const CaptureToolButton* b : m_vectorButtons) {
@@ -68,14 +65,12 @@ ButtonHandler::isVisible() const
return ret; return ret;
} }
bool bool ButtonHandler::buttonsAreInside() const
ButtonHandler::buttonsAreInside() const
{ {
return m_buttonsAreInside; return m_buttonsAreInside;
} }
size_t size_t ButtonHandler::size() const
ButtonHandler::size() const
{ {
return m_vectorButtons.size(); return m_vectorButtons.size();
} }
@@ -84,8 +79,7 @@ ButtonHandler::size() const
// selection area. Ignores the sides blocked by the end of the screen. // selection area. Ignores the sides blocked by the end of the screen.
// When the selection is too small it works on a virtual selection with // When the selection is too small it works on a virtual selection with
// the original in the center. // the original in the center.
void void ButtonHandler::updatePosition(const QRect& selection)
ButtonHandler::updatePosition(const QRect& selection)
{ {
resetRegionTrack(); resetRegionTrack();
const int vecLength = m_vectorButtons.size(); const int vecLength = m_vectorButtons.size();
@@ -131,13 +125,14 @@ ButtonHandler::updatePosition(const QRect& selection)
int addCounter = buttonsPerRow + elemCornersBotton; int addCounter = buttonsPerRow + elemCornersBotton;
// Don't add more than we have // Don't add more than we have
addCounter = qBound(0, addCounter, vecLength - elemIndicator); addCounter = qBound(0, addCounter, vecLength - elemIndicator);
QPoint center = QPoint center = QPoint(m_selection.center().x(),
QPoint(m_selection.center().x(), m_selection.bottom() + m_separator); m_selection.bottom() + m_separator);
if (addCounter > buttonsPerRow) { if (addCounter > buttonsPerRow) {
adjustHorizontalCenter(center); adjustHorizontalCenter(center);
} }
// ElemIndicator, elemsAtCorners // ElemIndicator, elemsAtCorners
QVector<QPoint> positions = horizontalPoints(center, addCounter, true); QVector<QPoint> positions =
horizontalPoints(center, addCounter, true);
moveButtonsToPoints(positions, elemIndicator); moveButtonsToPoints(positions, elemIndicator);
} }
// Add buttons at the right side of the seletion // Add buttons at the right side of the seletion
@@ -145,9 +140,10 @@ ButtonHandler::updatePosition(const QRect& selection)
int addCounter = buttonsPerCol; int addCounter = buttonsPerCol;
addCounter = qBound(0, addCounter, vecLength - elemIndicator); addCounter = qBound(0, addCounter, vecLength - elemIndicator);
QPoint center = QPoint center = QPoint(m_selection.right() + m_separator,
QPoint(m_selection.right() + m_separator, m_selection.center().y()); m_selection.center().y());
QVector<QPoint> positions = verticalPoints(center, addCounter, false); QVector<QPoint> positions =
verticalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator); moveButtonsToPoints(positions, elemIndicator);
} }
// Add buttons at the top of the seletion // Add buttons at the top of the seletion
@@ -159,7 +155,8 @@ ButtonHandler::updatePosition(const QRect& selection)
if (addCounter == 1 + buttonsPerRow) { if (addCounter == 1 + buttonsPerRow) {
adjustHorizontalCenter(center); adjustHorizontalCenter(center);
} }
QVector<QPoint> positions = horizontalPoints(center, addCounter, false); QVector<QPoint> positions =
horizontalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator); moveButtonsToPoints(positions, elemIndicator);
} }
// Add buttons at the left side of the seletion // Add buttons at the left side of the seletion
@@ -169,7 +166,8 @@ ButtonHandler::updatePosition(const QRect& selection)
QPoint center = QPoint(m_selection.left() - m_buttonExtendedSize, QPoint center = QPoint(m_selection.left() - m_buttonExtendedSize,
m_selection.center().y()); m_selection.center().y());
QVector<QPoint> positions = verticalPoints(center, addCounter, true); QVector<QPoint> positions =
verticalPoints(center, addCounter, true);
moveButtonsToPoints(positions, elemIndicator); moveButtonsToPoints(positions, elemIndicator);
} }
// If there are elements for the next cycle, increase the size of the // If there are elements for the next cycle, increase the size of the
@@ -184,8 +182,7 @@ ButtonHandler::updatePosition(const QRect& selection)
// horizontalPoints is an auxiliary method for the button position computation. // horizontalPoints is an auxiliary method for the button position computation.
// starts from a known center and keeps adding elements horizontally // starts from a known center and keeps adding elements horizontally
// and returns the computed positions. // and returns the computed positions.
QVector<QPoint> QVector<QPoint> ButtonHandler::horizontalPoints(const QPoint& center,
ButtonHandler::horizontalPoints(const QPoint& center,
const int elements, const int elements,
const bool leftToRight) const const bool leftToRight) const
{ {
@@ -195,7 +192,8 @@ ButtonHandler::horizontalPoints(const QPoint& center,
if (elements % 2 == 0) { if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2); shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else { } else {
shift = m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2; shift =
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
} }
if (!leftToRight) { if (!leftToRight) {
shift -= m_buttonBaseSize; shift -= m_buttonBaseSize;
@@ -213,8 +211,7 @@ ButtonHandler::horizontalPoints(const QPoint& center,
// verticalPoints is an auxiliary method for the button position computation. // verticalPoints is an auxiliary method for the button position computation.
// starts from a known center and keeps adding elements vertically // starts from a known center and keeps adding elements vertically
// and returns the computed positions. // and returns the computed positions.
QVector<QPoint> QVector<QPoint> ButtonHandler::verticalPoints(const QPoint& center,
ButtonHandler::verticalPoints(const QPoint& center,
const int elements, const int elements,
const bool upToDown) const const bool upToDown) const
{ {
@@ -224,7 +221,8 @@ ButtonHandler::verticalPoints(const QPoint& center,
if (elements % 2 == 0) { if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2); shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else { } else {
shift = m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2; shift =
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
} }
if (!upToDown) { if (!upToDown) {
shift -= m_buttonBaseSize; shift -= m_buttonBaseSize;
@@ -239,8 +237,7 @@ ButtonHandler::verticalPoints(const QPoint& center,
return res; return res;
} }
QRect QRect ButtonHandler::intersectWithAreas(const QRect& rect)
ButtonHandler::intersectWithAreas(const QRect& rect)
{ {
QRect res; QRect res;
for (const QRect& r : m_screenRegions) { for (const QRect& r : m_screenRegions) {
@@ -252,20 +249,17 @@ ButtonHandler::intersectWithAreas(const QRect& rect)
return res; return res;
} }
void void ButtonHandler::init()
ButtonHandler::init()
{ {
m_separator = GlobalValues::buttonBaseSize() / 4; m_separator = GlobalValues::buttonBaseSize() / 4;
} }
void void ButtonHandler::resetRegionTrack()
ButtonHandler::resetRegionTrack()
{ {
m_buttonsAreInside = false; m_buttonsAreInside = false;
} }
void void ButtonHandler::updateBlockedSides()
ButtonHandler::updateBlockedSides()
{ {
const int EXTENSION = m_separator * 2 + m_buttonBaseSize; const int EXTENSION = m_separator * 2 + m_buttonBaseSize;
// Right // Right
@@ -292,19 +286,18 @@ ButtonHandler::updateBlockedSides()
m_oneHorizontalBlocked = m_oneHorizontalBlocked =
(!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft); (!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft);
m_horizontalyBlocked = (m_blockedRight && m_blockedLeft); m_horizontalyBlocked = (m_blockedRight && m_blockedLeft);
m_allSidesBlocked = (m_blockedBotton && m_horizontalyBlocked && m_blockedTop); m_allSidesBlocked =
(m_blockedBotton && m_horizontalyBlocked && m_blockedTop);
} }
void void ButtonHandler::expandSelection()
ButtonHandler::expandSelection()
{ {
int& s = m_buttonExtendedSize; int& s = m_buttonExtendedSize;
m_selection = m_selection + QMargins(s, s, s, s); m_selection = m_selection + QMargins(s, s, s, s);
m_selection = intersectWithAreas(m_selection); m_selection = intersectWithAreas(m_selection);
} }
void void ButtonHandler::positionButtonsInside(int index)
ButtonHandler::positionButtonsInside(int index)
{ {
// Position the buttons in the botton-center of the main but inside of the // Position the buttons in the botton-center of the main but inside of the
// selection. // selection.
@@ -328,11 +321,11 @@ ButtonHandler::positionButtonsInside(int index)
m_buttonsAreInside = true; m_buttonsAreInside = true;
} }
void void ButtonHandler::ensureSelectionMinimunSize()
ButtonHandler::ensureSelectionMinimunSize()
{ {
// Detect if a side is smaller than a button in order to prevent collision // Detect if a side is smaller than a button in order to prevent collision
// and redimension the base area the the base size of a single button per side // and redimension the base area the the base size of a single button per
// side
if (m_selection.width() < m_buttonBaseSize) { if (m_selection.width() < m_buttonBaseSize) {
if (!m_blockedLeft) { if (!m_blockedLeft) {
m_selection.setX(m_selection.x() - m_selection.setX(m_selection.x() -
@@ -349,8 +342,8 @@ ButtonHandler::ensureSelectionMinimunSize()
} }
} }
void void ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points,
ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points, int& index) int& index)
{ {
for (const QPoint& p : points) { for (const QPoint& p : points) {
auto button = m_vectorButtons[index]; auto button = m_vectorButtons[index];
@@ -359,8 +352,7 @@ ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points, int& index)
} }
} }
void void ButtonHandler::adjustHorizontalCenter(QPoint& center)
ButtonHandler::adjustHorizontalCenter(QPoint& center)
{ {
if (m_blockedLeft) { if (m_blockedLeft) {
center.setX(center.x() + m_buttonExtendedSize / 2); center.setX(center.x() + m_buttonExtendedSize / 2);
@@ -370,8 +362,7 @@ ButtonHandler::adjustHorizontalCenter(QPoint& center)
} }
// setButtons redefines the buttons of the button handler // setButtons redefines the buttons of the button handler
void void ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
{ {
if (v.isEmpty()) if (v.isEmpty())
return; return;
@@ -383,8 +374,7 @@ ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
m_buttonExtendedSize = m_buttonBaseSize + m_separator; m_buttonExtendedSize = m_buttonBaseSize + m_separator;
} }
bool bool ButtonHandler::contains(const QPoint& p) const
ButtonHandler::contains(const QPoint& p) const
{ {
QPoint first(m_vectorButtons.first()->pos()); QPoint first(m_vectorButtons.first()->pos());
QPoint last(m_vectorButtons.last()->pos()); QPoint last(m_vectorButtons.last()->pos());
@@ -397,8 +387,7 @@ ButtonHandler::contains(const QPoint& p) const
return r.contains(p); return r.contains(p);
} }
void void ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
{ {
m_screenRegions = QRegion(); m_screenRegions = QRegion();
for (const QRect& rect : rects) { for (const QRect& rect : rects) {
@@ -406,8 +395,7 @@ ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
} }
} }
void void ButtonHandler::updateScreenRegions(const QRect& rect)
ButtonHandler::updateScreenRegions(const QRect& rect)
{ {
m_screenRegions = QRegion(rect); m_screenRegions = QRegion(rect);
} }

View File

@@ -30,7 +30,8 @@ class ButtonHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
ButtonHandler(const QVector<CaptureToolButton*>&, QObject* parent = nullptr); ButtonHandler(const QVector<CaptureToolButton*>&,
QObject* parent = nullptr);
explicit ButtonHandler(QObject* parent = nullptr); explicit ButtonHandler(QObject* parent = nullptr);
void hideSectionUnderMouse(const QPoint& p); void hideSectionUnderMouse(const QPoint& p);

View File

@@ -41,8 +41,7 @@ CaptureButton::CaptureButton(const QIcon& icon,
init(); init();
} }
void void CaptureButton::init()
CaptureButton::init()
{ {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
@@ -55,14 +54,12 @@ CaptureButton::init()
setGraphicsEffect(dsEffect); setGraphicsEffect(dsEffect);
} }
QString QString CaptureButton::globalStyleSheet()
CaptureButton::globalStyleSheet()
{ {
return CaptureButton(nullptr).styleSheet(); return CaptureButton(nullptr).styleSheet();
} }
QString QString CaptureButton::styleSheet() const
CaptureButton::styleSheet() const
{ {
QString baseSheet = "CaptureButton { border: none;" QString baseSheet = "CaptureButton { border: none;"
"padding: 3px 8px;" "padding: 3px 8px;"
@@ -83,8 +80,7 @@ CaptureButton::styleSheet() const
.arg(color.name()); .arg(color.name());
} }
void void CaptureButton::setColor(const QColor& c)
CaptureButton::setColor(const QColor& c)
{ {
m_mainColor = c; m_mainColor = c;
setStyleSheet(styleSheet()); setStyleSheet(styleSheet());

View File

@@ -44,8 +44,7 @@ CaptureToolButton::CaptureToolButton(const ButtonType t, QWidget* parent)
} }
} }
void void CaptureToolButton::initButton()
CaptureToolButton::initButton()
{ {
m_tool = ToolFactory().CreateTool(m_buttonType, this); m_tool = ToolFactory().CreateTool(m_buttonType, this);
@@ -66,8 +65,7 @@ CaptureToolButton::initButton()
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize())); QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
} }
void void CaptureToolButton::updateIcon()
CaptureToolButton::updateIcon()
{ {
setIcon(icon()); setIcon(icon());
setIconSize(size() * 0.6); setIconSize(size() * 0.6);
@@ -80,14 +78,12 @@ CaptureToolButton::getIterableButtonTypes()
} }
// get icon returns the icon for the type of button // get icon returns the icon for the type of button
QIcon QIcon CaptureToolButton::icon() const
CaptureToolButton::icon() const
{ {
return m_tool->icon(m_mainColor, true); return m_tool->icon(m_mainColor, true);
} }
void void CaptureToolButton::mousePressEvent(QMouseEvent* e)
CaptureToolButton::mousePressEvent(QMouseEvent* e)
{ {
if (e->button() == Qt::LeftButton) { if (e->button() == Qt::LeftButton) {
emit pressedButton(this); emit pressedButton(this);
@@ -95,24 +91,22 @@ CaptureToolButton::mousePressEvent(QMouseEvent* e)
} }
} }
void void CaptureToolButton::animatedShow()
CaptureToolButton::animatedShow()
{ {
if (!isVisible()) { if (!isVisible()) {
show(); show();
m_emergeAnimation->start(); m_emergeAnimation->start();
connect(m_emergeAnimation, &QPropertyAnimation::finished, this, []() {}); connect(
m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
} }
} }
CaptureTool* CaptureTool* CaptureToolButton::tool() const
CaptureToolButton::tool() const
{ {
return m_tool; return m_tool;
} }
void void CaptureToolButton::setColor(const QColor& c)
CaptureToolButton::setColor(const QColor& c)
{ {
CaptureButton::setColor(c); CaptureButton::setColor(c);
updateIcon(); updateIcon();
@@ -143,8 +137,7 @@ static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder{
{ CaptureToolButton::TYPE_PIN, 19 }, { CaptureToolButton::TYPE_PIN, 19 },
}; };
int int CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
{ {
auto it = buttonTypeOrder.find(b); auto it = buttonTypeOrder.find(b);
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size() return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size()

View File

@@ -107,7 +107,8 @@ CaptureWidget::CaptureWidget(const uint id,
for (QScreen* const screen : QGuiApplication::screens()) { for (QScreen* const screen : QGuiApplication::screens()) {
QPoint topLeftScreen = screen->geometry().topLeft(); QPoint topLeftScreen = screen->geometry().topLeft();
if (topLeft.x() > topLeftScreen.x() || topLeft.y() > topLeftScreen.y()) { if (topLeft.x() > topLeftScreen.x() ||
topLeft.y() > topLeftScreen.y()) {
topLeft = topLeftScreen; topLeft = topLeftScreen;
} }
} }
@@ -169,8 +170,7 @@ CaptureWidget::~CaptureWidget()
// redefineButtons retrieves the buttons configured to be shown with the // redefineButtons retrieves the buttons configured to be shown with the
// selection in the capture // selection in the capture
void void CaptureWidget::updateButtons()
CaptureWidget::updateButtons()
{ {
m_uiColor = m_config.uiMainColorValue(); m_uiColor = m_config.uiMainColorValue();
m_contrastUiColor = m_config.uiContrastColorValue(); m_contrastUiColor = m_config.uiContrastColorValue();
@@ -197,8 +197,7 @@ CaptureWidget::updateButtons()
m_buttonHandler->setButtons(vectorButtons); m_buttonHandler->setButtons(vectorButtons);
} }
QPixmap QPixmap CaptureWidget::pixmap()
CaptureWidget::pixmap()
{ {
QPixmap p; QPixmap p;
if (m_toolWidget && m_activeTool) { if (m_toolWidget && m_activeTool) {
@@ -211,8 +210,7 @@ CaptureWidget::pixmap()
return m_context.selectedScreenshotArea(); return m_context.selectedScreenshotArea();
} }
void void CaptureWidget::deleteToolwidgetOrClose()
CaptureWidget::deleteToolwidgetOrClose()
{ {
if (m_toolWidget) { if (m_toolWidget) {
m_toolWidget->deleteLater(); m_toolWidget->deleteLater();
@@ -222,8 +220,7 @@ CaptureWidget::deleteToolwidgetOrClose()
} }
} }
void void CaptureWidget::paintEvent(QPaintEvent*)
CaptureWidget::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
painter.drawPixmap(0, 0, m_context.screenshot); painter.drawPixmap(0, 0, m_context.screenshot);
@@ -264,7 +261,8 @@ CaptureWidget::paintEvent(QPaintEvent*)
"\nPress Space to open the side panel."); "\nPress Space to open the side panel.");
// We draw the white contrasting background for the text, using the // We draw the white contrasting background for the text, using the
// same text and options to get the boundingRect that the text will have. // same text and options to get the boundingRect that the text will
// have.
QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt); QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);
// These four calls provide padding for the rect // These four calls provide padding for the rect
@@ -297,8 +295,7 @@ CaptureWidget::paintEvent(QPaintEvent*)
} }
} }
void void CaptureWidget::mousePressEvent(QMouseEvent* e)
CaptureWidget::mousePressEvent(QMouseEvent* e)
{ {
if (e->button() == Qt::RightButton) { if (e->button() == Qt::RightButton) {
m_rightClick = true; m_rightClick = true;
@@ -356,8 +353,7 @@ CaptureWidget::mousePressEvent(QMouseEvent* e)
updateCursor(); updateCursor();
} }
void void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
CaptureWidget::mouseMoveEvent(QMouseEvent* e)
{ {
m_context.mousePos = e->pos(); m_context.mousePos = e->pos();
@@ -373,7 +369,8 @@ CaptureWidget::mouseMoveEvent(QMouseEvent* e)
} else if (m_mouseOverHandle == SelectionWidget::NO_SIDE) { } else if (m_mouseOverHandle == SelectionWidget::NO_SIDE) {
// Moving the whole selection // Moving the whole selection
QRect initialRect = m_selection->savedGeometry().normalized(); QRect initialRect = m_selection->savedGeometry().normalized();
QPoint newTopLeft = initialRect.topLeft() + (e->pos() - m_dragStartPoint); QPoint newTopLeft =
initialRect.topLeft() + (e->pos() - m_dragStartPoint);
QRect finalRect(newTopLeft, initialRect.size()); QRect finalRect(newTopLeft, initialRect.size());
if (finalRect.left() < rect().left()) { if (finalRect.left() < rect().left()) {
@@ -386,7 +383,8 @@ CaptureWidget::mouseMoveEvent(QMouseEvent* e)
} else if (finalRect.bottom() > rect().bottom()) { } else if (finalRect.bottom() > rect().bottom()) {
finalRect.setBottom(rect().bottom()); finalRect.setBottom(rect().bottom());
} }
m_selection->setGeometry(finalRect.normalized().intersected(rect())); m_selection->setGeometry(
finalRect.normalized().intersected(rect()));
update(); update();
} else { } else {
// Dragging a handle // Dragging a handle
@@ -442,9 +440,11 @@ CaptureWidget::mouseMoveEvent(QMouseEvent* e)
m_activeTool->drawMove(e->pos()); m_activeTool->drawMove(e->pos());
} }
update(); update();
// Hides the buttons under the mouse. If the mouse leaves, it shows them. // Hides the buttons under the mouse. If the mouse leaves, it shows
// them.
if (m_buttonHandler->buttonsAreInside()) { if (m_buttonHandler->buttonsAreInside()) {
const bool containsMouse = m_buttonHandler->contains(m_context.mousePos); const bool containsMouse =
m_buttonHandler->contains(m_context.mousePos);
if (containsMouse) { if (containsMouse) {
m_buttonHandler->hide(); m_buttonHandler->hide();
} else { } else {
@@ -462,8 +462,7 @@ CaptureWidget::mouseMoveEvent(QMouseEvent* e)
} }
} }
void void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
{ {
if (e->button() == Qt::RightButton) { if (e->button() == Qt::RightButton) {
m_colorPicker->hide(); m_colorPicker->hide();
@@ -509,8 +508,7 @@ CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
updateCursor(); updateCursor();
} }
void void CaptureWidget::keyPressEvent(QKeyEvent* e)
CaptureWidget::keyPressEvent(QKeyEvent* e)
{ {
if (!m_selection->isVisible()) { if (!m_selection->isVisible()) {
return; return;
@@ -545,16 +543,14 @@ CaptureWidget::keyPressEvent(QKeyEvent* e)
} }
} }
void void CaptureWidget::keyReleaseEvent(QKeyEvent* e)
CaptureWidget::keyReleaseEvent(QKeyEvent* e)
{ {
if (e->key() == Qt::Key_Control) { if (e->key() == Qt::Key_Control) {
m_adjustmentButtonPressed = false; m_adjustmentButtonPressed = false;
} }
} }
void void CaptureWidget::wheelEvent(QWheelEvent* e)
CaptureWidget::wheelEvent(QWheelEvent* e)
{ {
m_context.thickness += e->angleDelta().y() / 120; m_context.thickness += e->angleDelta().y() / 120;
m_context.thickness = qBound(0, m_context.thickness, 100); m_context.thickness = qBound(0, m_context.thickness, 100);
@@ -571,8 +567,7 @@ CaptureWidget::wheelEvent(QWheelEvent* e)
emit thicknessChanged(m_context.thickness); emit thicknessChanged(m_context.thickness);
} }
void void CaptureWidget::resizeEvent(QResizeEvent* e)
CaptureWidget::resizeEvent(QResizeEvent* e)
{ {
QWidget::resizeEvent(e); QWidget::resizeEvent(e);
m_context.widgetDimensions = rect(); m_context.widgetDimensions = rect();
@@ -583,15 +578,13 @@ CaptureWidget::resizeEvent(QResizeEvent* e)
} }
} }
void void CaptureWidget::moveEvent(QMoveEvent* e)
CaptureWidget::moveEvent(QMoveEvent* e)
{ {
QWidget::moveEvent(e); QWidget::moveEvent(e);
m_context.widgetOffset = mapToGlobal(QPoint(0, 0)); m_context.widgetOffset = mapToGlobal(QPoint(0, 0));
} }
void void CaptureWidget::initContext(const QString& savePath, bool fullscreen)
CaptureWidget::initContext(const QString& savePath, bool fullscreen)
{ {
m_context.widgetDimensions = rect(); m_context.widgetDimensions = rect();
m_context.color = m_config.drawColorValue(); m_context.color = m_config.drawColorValue();
@@ -602,8 +595,7 @@ CaptureWidget::initContext(const QString& savePath, bool fullscreen)
m_context.fullscreen = fullscreen; m_context.fullscreen = fullscreen;
} }
void void CaptureWidget::initPanel()
CaptureWidget::initPanel()
{ {
QRect panelRect = rect(); QRect panelRect = rect();
if (m_context.fullscreen) { if (m_context.fullscreen) {
@@ -660,8 +652,7 @@ CaptureWidget::initPanel()
m_panel->pushWidget(new QUndoView(&m_undoStack, this)); m_panel->pushWidget(new QUndoView(&m_undoStack, this));
} }
void void CaptureWidget::initSelection()
CaptureWidget::initSelection()
{ {
m_selection = new SelectionWidget(m_uiColor, this); m_selection = new SelectionWidget(m_uiColor, this);
connect(m_selection, &SelectionWidget::animationEnded, this, [this]() { connect(m_selection, &SelectionWidget::animationEnded, this, [this]() {
@@ -671,8 +662,7 @@ CaptureWidget::initSelection()
m_selection->setGeometry(QRect()); m_selection->setGeometry(QRect());
} }
void void CaptureWidget::setState(CaptureToolButton* b)
CaptureWidget::setState(CaptureToolButton* b)
{ {
if (!b) { if (!b) {
return; return;
@@ -709,8 +699,7 @@ CaptureWidget::setState(CaptureToolButton* b)
} }
} }
void void CaptureWidget::processTool(CaptureTool* t)
CaptureWidget::processTool(CaptureTool* t)
{ {
auto backup = m_activeTool; auto backup = m_activeTool;
// The tool is active during the pressed(). // The tool is active during the pressed().
@@ -719,8 +708,7 @@ CaptureWidget::processTool(CaptureTool* t)
m_activeTool = backup; m_activeTool = backup;
} }
void void CaptureWidget::handleButtonSignal(CaptureTool::Request r)
CaptureWidget::handleButtonSignal(CaptureTool::Request r)
{ {
switch (r) { switch (r) {
case CaptureTool::REQ_CLEAR_MODIFICATIONS: case CaptureTool::REQ_CLEAR_MODIFICATIONS:
@@ -794,7 +782,8 @@ CaptureWidget::handleButtonSignal(CaptureTool::Request r)
break; break;
} else { } else {
QWidget* w = m_activeTool->widget(); QWidget* w = m_activeTool->widget();
connect(this, &CaptureWidget::destroyed, w, &QWidget::deleteLater); connect(
this, &CaptureWidget::destroyed, w, &QWidget::deleteLater);
w->show(); w->show();
} }
break; break;
@@ -812,40 +801,36 @@ CaptureWidget::handleButtonSignal(CaptureTool::Request r)
} }
} }
void void CaptureWidget::setDrawColor(const QColor& c)
CaptureWidget::setDrawColor(const QColor& c)
{ {
m_context.color = c; m_context.color = c;
ConfigHandler().setDrawColor(m_context.color); ConfigHandler().setDrawColor(m_context.color);
emit colorChanged(c); emit colorChanged(c);
} }
void void CaptureWidget::incrementCircleCount()
CaptureWidget::incrementCircleCount()
{ {
m_context.circleCount++; m_context.circleCount++;
} }
void void CaptureWidget::decrementCircleCount()
CaptureWidget::decrementCircleCount()
{ {
m_context.circleCount--; m_context.circleCount--;
} }
void void CaptureWidget::setDrawThickness(const int& t)
CaptureWidget::setDrawThickness(const int& t)
{ {
m_context.thickness = qBound(0, t, 100); m_context.thickness = qBound(0, t, 100);
ConfigHandler().setdrawThickness(m_context.thickness); ConfigHandler().setdrawThickness(m_context.thickness);
emit thicknessChanged(m_context.thickness); emit thicknessChanged(m_context.thickness);
} }
void void CaptureWidget::leftResize()
CaptureWidget::leftResize()
{ {
if (m_selection->isVisible() && if (m_selection->isVisible() &&
m_selection->geometry().right() > m_selection->geometry().left()) { m_selection->geometry().right() > m_selection->geometry().left()) {
m_selection->setGeometry(m_selection->geometry() + QMargins(0, 0, -1, 0)); m_selection->setGeometry(m_selection->geometry() +
QMargins(0, 0, -1, 0));
QRect newGeometry = m_selection->geometry().intersected(rect()); QRect newGeometry = m_selection->geometry().intersected(rect());
m_context.selection = extendedRect(&newGeometry); m_context.selection = extendedRect(&newGeometry);
m_buttonHandler->updatePosition(m_selection->geometry()); m_buttonHandler->updatePosition(m_selection->geometry());
@@ -854,12 +839,12 @@ CaptureWidget::leftResize()
} }
} }
void void CaptureWidget::rightResize()
CaptureWidget::rightResize()
{ {
if (m_selection->isVisible() && if (m_selection->isVisible() &&
m_selection->geometry().right() < rect().right()) { m_selection->geometry().right() < rect().right()) {
m_selection->setGeometry(m_selection->geometry() + QMargins(0, 0, 1, 0)); m_selection->setGeometry(m_selection->geometry() +
QMargins(0, 0, 1, 0));
QRect newGeometry = m_selection->geometry().intersected(rect()); QRect newGeometry = m_selection->geometry().intersected(rect());
m_context.selection = extendedRect(&newGeometry); m_context.selection = extendedRect(&newGeometry);
m_buttonHandler->updatePosition(m_selection->geometry()); m_buttonHandler->updatePosition(m_selection->geometry());
@@ -868,12 +853,12 @@ CaptureWidget::rightResize()
} }
} }
void void CaptureWidget::upResize()
CaptureWidget::upResize()
{ {
if (m_selection->isVisible() && if (m_selection->isVisible() &&
m_selection->geometry().bottom() > m_selection->geometry().top()) { m_selection->geometry().bottom() > m_selection->geometry().top()) {
m_selection->setGeometry(m_selection->geometry() + QMargins(0, 0, 0, -1)); m_selection->setGeometry(m_selection->geometry() +
QMargins(0, 0, 0, -1));
QRect newGeometry = m_selection->geometry().intersected(rect()); QRect newGeometry = m_selection->geometry().intersected(rect());
m_context.selection = extendedRect(&newGeometry); m_context.selection = extendedRect(&newGeometry);
m_buttonHandler->updatePosition(m_selection->geometry()); m_buttonHandler->updatePosition(m_selection->geometry());
@@ -882,12 +867,12 @@ CaptureWidget::upResize()
} }
} }
void void CaptureWidget::downResize()
CaptureWidget::downResize()
{ {
if (m_selection->isVisible() && if (m_selection->isVisible() &&
m_selection->geometry().bottom() < rect().bottom()) { m_selection->geometry().bottom() < rect().bottom()) {
m_selection->setGeometry(m_selection->geometry() + QMargins(0, 0, 0, 1)); m_selection->setGeometry(m_selection->geometry() +
QMargins(0, 0, 0, 1));
QRect newGeometry = m_selection->geometry().intersected(rect()); QRect newGeometry = m_selection->geometry().intersected(rect());
m_context.selection = extendedRect(&newGeometry); m_context.selection = extendedRect(&newGeometry);
m_buttonHandler->updatePosition(m_selection->geometry()); m_buttonHandler->updatePosition(m_selection->geometry());
@@ -896,8 +881,7 @@ CaptureWidget::downResize()
} }
} }
void void CaptureWidget::initShortcuts()
CaptureWidget::initShortcuts()
{ {
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close())); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
new QShortcut( new QShortcut(
@@ -920,18 +904,17 @@ CaptureWidget::initShortcuts()
new QShortcut(Qt::Key_Enter, this, SLOT(copyScreenshot())); new QShortcut(Qt::Key_Enter, this, SLOT(copyScreenshot()));
} }
void void CaptureWidget::updateSizeIndicator()
CaptureWidget::updateSizeIndicator()
{ {
if (m_sizeIndButton) { if (m_sizeIndButton) {
const QRect& selection = extendedSelection(); const QRect& selection = extendedSelection();
m_sizeIndButton->setText( m_sizeIndButton->setText(QStringLiteral("%1\n%2")
QStringLiteral("%1\n%2").arg(selection.width()).arg(selection.height())); .arg(selection.width())
.arg(selection.height()));
} }
} }
void void CaptureWidget::updateCursor()
CaptureWidget::updateCursor()
{ {
if (m_rightClick) { if (m_rightClick) {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
@@ -972,8 +955,7 @@ CaptureWidget::updateCursor()
} }
} }
void void CaptureWidget::pushToolToStack()
CaptureWidget::pushToolToStack()
{ {
auto mod = new ModificationCommand(&m_context.screenshot, m_activeTool); auto mod = new ModificationCommand(&m_context.screenshot, m_activeTool);
disconnect(this, disconnect(this,
@@ -991,43 +973,37 @@ CaptureWidget::pushToolToStack()
m_activeTool = nullptr; m_activeTool = nullptr;
} }
void void CaptureWidget::makeChild(QWidget* w)
CaptureWidget::makeChild(QWidget* w)
{ {
w->setParent(this); w->setParent(this);
w->installEventFilter(m_eventFilter); w->installEventFilter(m_eventFilter);
} }
void void CaptureWidget::togglePanel()
CaptureWidget::togglePanel()
{ {
m_panel->toggle(); m_panel->toggle();
} }
void void CaptureWidget::childEnter()
CaptureWidget::childEnter()
{ {
m_previewEnabled = false; m_previewEnabled = false;
update(); update();
} }
void void CaptureWidget::childLeave()
CaptureWidget::childLeave()
{ {
m_previewEnabled = true; m_previewEnabled = true;
update(); update();
} }
void void CaptureWidget::copyScreenshot()
CaptureWidget::copyScreenshot()
{ {
m_captureDone = true; m_captureDone = true;
ScreenshotSaver().saveToClipboard(pixmap()); ScreenshotSaver().saveToClipboard(pixmap());
close(); close();
} }
void void CaptureWidget::saveScreenshot()
CaptureWidget::saveScreenshot()
{ {
m_captureDone = true; m_captureDone = true;
hide(); hide();
@@ -1039,20 +1015,17 @@ CaptureWidget::saveScreenshot()
close(); close();
} }
void void CaptureWidget::undo()
CaptureWidget::undo()
{ {
m_undoStack.undo(); m_undoStack.undo();
} }
void void CaptureWidget::redo()
CaptureWidget::redo()
{ {
m_undoStack.redo(); m_undoStack.redo();
} }
QRect QRect CaptureWidget::extendedSelection() const
CaptureWidget::extendedSelection() const
{ {
if (!m_selection->isVisible()) if (!m_selection->isVisible())
return QRect(); return QRect();
@@ -1060,8 +1033,7 @@ CaptureWidget::extendedSelection() const
return extendedRect(&r); return extendedRect(&r);
} }
QRect QRect CaptureWidget::extendedRect(QRect* r) const
CaptureWidget::extendedRect(QRect* r) const
{ {
auto devicePixelRatio = m_context.screenshot.devicePixelRatio(); auto devicePixelRatio = m_context.screenshot.devicePixelRatio();
return QRect(r->left() * devicePixelRatio, return QRect(r->left() * devicePixelRatio,

View File

@@ -46,35 +46,31 @@ ColorPicker::ColorPicker(QWidget* parent)
QPoint(radius * 2, radius)); QPoint(radius * 2, radius));
for (int i = 0; i < m_colorList.size(); ++i) { for (int i = 0; i < m_colorList.size(); ++i) {
m_colorAreaList.append( m_colorAreaList.append(QRect(
QRect(baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize)); baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize));
baseLine.setAngle(degreeAcum); baseLine.setAngle(degreeAcum);
degreeAcum += degree; degreeAcum += degree;
} }
} }
QColor QColor ColorPicker::drawColor()
ColorPicker::drawColor()
{ {
return m_drawColor; return m_drawColor;
} }
void void ColorPicker::show()
ColorPicker::show()
{ {
grabMouse(); grabMouse();
QWidget::show(); QWidget::show();
} }
void void ColorPicker::hide()
ColorPicker::hide()
{ {
releaseMouse(); releaseMouse();
QWidget::hide(); QWidget::hide();
} }
void void ColorPicker::paintEvent(QPaintEvent*)
ColorPicker::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
@@ -101,8 +97,7 @@ ColorPicker::paintEvent(QPaintEvent*)
} }
} }
void void ColorPicker::mouseMoveEvent(QMouseEvent* e)
ColorPicker::mouseMoveEvent(QMouseEvent* e)
{ {
for (int i = 0; i < m_colorList.size(); ++i) { for (int i = 0; i < m_colorList.size(); ++i) {
if (m_colorAreaList.at(i).contains(e->pos())) { if (m_colorAreaList.at(i).contains(e->pos())) {
@@ -114,8 +109,7 @@ ColorPicker::mouseMoveEvent(QMouseEvent* e)
} }
} }
QVector<QRect> QVector<QRect> ColorPicker::handleMask() const
ColorPicker::handleMask() const
{ {
QVector<QRect> areas; QVector<QRect> areas;
for (const QRect& rect : m_colorAreaList) { for (const QRect& rect : m_colorAreaList) {

View File

@@ -30,8 +30,7 @@ HoverEventFilter::HoverEventFilter(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
bool bool HoverEventFilter::eventFilter(QObject* watched, QEvent* event)
HoverEventFilter::eventFilter(QObject* watched, QEvent* event)
{ {
QEvent::Type t = event->type(); QEvent::Type t = event->type();
switch (t) { switch (t) {

View File

@@ -25,14 +25,12 @@ ModificationCommand::ModificationCommand(QPixmap* p, CaptureTool* t)
setText(t->name()); setText(t->name());
} }
void void ModificationCommand::undo()
ModificationCommand::undo()
{ {
m_tool->undo(*m_pixmap); m_tool->undo(*m_pixmap);
} }
void void ModificationCommand::redo()
ModificationCommand::redo()
{ {
QPainter p(m_pixmap); QPainter p(m_pixmap);
p.setRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::Antialiasing);

View File

@@ -40,14 +40,12 @@ NotifierBox::NotifierBox(QWidget* parent)
setFixedSize(QSize(size, size)); setFixedSize(QSize(size, size));
} }
void void NotifierBox::enterEvent(QEvent*)
NotifierBox::enterEvent(QEvent*)
{ {
hide(); hide();
} }
void void NotifierBox::paintEvent(QPaintEvent*)
NotifierBox::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
// draw Elipse // draw Elipse
@@ -60,8 +58,7 @@ NotifierBox::paintEvent(QPaintEvent*)
painter.drawText(rect(), Qt::AlignCenter, m_message); painter.drawText(rect(), Qt::AlignCenter, m_message);
} }
void void NotifierBox::showMessage(const QString& msg)
NotifierBox::showMessage(const QString& msg)
{ {
m_message = msg; m_message = msg;
update(); update();
@@ -69,8 +66,7 @@ NotifierBox::showMessage(const QString& msg)
m_timer->start(); m_timer->start();
} }
void void NotifierBox::showColor(const QColor& color)
NotifierBox::showColor(const QColor& color)
{ {
Q_UNUSED(color); Q_UNUSED(color);
m_message = QLatin1String(""); m_message = QLatin1String("");

View File

@@ -45,8 +45,8 @@ SelectionWidget::SelectionWidget(const QColor& c, QWidget* parent)
m_handleOffset = QPoint(-handleSide / 2, -handleSide / 2); m_handleOffset = QPoint(-handleSide / 2, -handleSide / 2);
} }
SelectionWidget::SideType SelectionWidget::SideType SelectionWidget::getMouseSide(
SelectionWidget::getMouseSide(const QPoint& point) const const QPoint& point) const
{ {
if (m_TLArea.contains(point)) { if (m_TLArea.contains(point)) {
return TOPLEFT_SIDE; return TOPLEFT_SIDE;
@@ -69,8 +69,7 @@ SelectionWidget::getMouseSide(const QPoint& point) const
} }
} }
QVector<QRect> QVector<QRect> SelectionWidget::handlerAreas()
SelectionWidget::handlerAreas()
{ {
QVector<QRect> areas; QVector<QRect> areas;
areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle << m_LHandle areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle << m_LHandle
@@ -78,8 +77,7 @@ SelectionWidget::handlerAreas()
return areas; return areas;
} }
void void SelectionWidget::setGeometryAnimated(const QRect& r)
SelectionWidget::setGeometryAnimated(const QRect& r)
{ {
if (isVisible()) { if (isVisible()) {
m_animation->setStartValue(geometry()); m_animation->setStartValue(geometry());
@@ -88,46 +86,39 @@ SelectionWidget::setGeometryAnimated(const QRect& r)
} }
} }
void void SelectionWidget::saveGeometry()
SelectionWidget::saveGeometry()
{ {
m_geometryBackup = geometry(); m_geometryBackup = geometry();
} }
QRect QRect SelectionWidget::savedGeometry()
SelectionWidget::savedGeometry()
{ {
return m_geometryBackup; return m_geometryBackup;
} }
void void SelectionWidget::paintEvent(QPaintEvent*)
SelectionWidget::paintEvent(QPaintEvent*)
{ {
QPainter p(this); QPainter p(this);
p.setPen(m_color); p.setPen(m_color);
p.drawRect(rect() + QMargins(0, 0, -1, -1)); p.drawRect(rect() + QMargins(0, 0, -1, -1));
} }
void void SelectionWidget::resizeEvent(QResizeEvent*)
SelectionWidget::resizeEvent(QResizeEvent*)
{ {
updateAreas(); updateAreas();
} }
void void SelectionWidget::moveEvent(QMoveEvent*)
SelectionWidget::moveEvent(QMoveEvent*)
{ {
updateAreas(); updateAreas();
} }
void void SelectionWidget::updateColor(const QColor& c)
SelectionWidget::updateColor(const QColor& c)
{ {
m_color = c; m_color = c;
} }
void void SelectionWidget::updateAreas()
SelectionWidget::updateAreas()
{ {
QRect r = rect(); QRect r = rect();
m_TLArea.moveTo(m_areaOffset + pos()); m_TLArea.moveTo(m_areaOffset + pos());

View File

@@ -118,8 +118,7 @@ CaptureLauncher::CaptureLauncher(QWidget* parent)
// HACK: // HACK:
// https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70 // https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
void void CaptureLauncher::startCapture()
CaptureLauncher::startCapture()
{ {
hide(); hide();
auto mode = static_cast<CaptureRequest::CaptureMode>( auto mode = static_cast<CaptureRequest::CaptureMode>(
@@ -129,8 +128,7 @@ CaptureLauncher::startCapture()
Controller::getInstance()->requestCapture(req); Controller::getInstance()->requestCapture(req);
} }
void void CaptureLauncher::startDrag()
CaptureLauncher::startDrag()
{ {
QDrag* dragHandler = new QDrag(this); QDrag* dragHandler = new QDrag(this);
QMimeData* mimeData = new QMimeData; QMimeData* mimeData = new QMimeData;
@@ -142,8 +140,7 @@ CaptureLauncher::startDrag()
dragHandler->exec(); dragHandler->exec();
} }
void void CaptureLauncher::captureTaken(uint id, QPixmap p)
CaptureLauncher::captureTaken(uint id, QPixmap p)
{ {
if (id == m_id) { if (id == m_id) {
m_id = 0; m_id = 0;
@@ -159,8 +156,7 @@ CaptureLauncher::captureTaken(uint id, QPixmap p)
} }
} }
void void CaptureLauncher::captureFailed(uint id)
CaptureLauncher::captureFailed(uint id)
{ {
if (id == m_id) { if (id == m_id) {
m_id = 0; m_id = 0;

View File

@@ -22,14 +22,12 @@ DraggableWidgetMaker::DraggableWidgetMaker(QObject* parent)
: QObject(parent) : QObject(parent)
{} {}
void void DraggableWidgetMaker::makeDraggable(QWidget* widget)
DraggableWidgetMaker::makeDraggable(QWidget* widget)
{ {
widget->installEventFilter(this); widget->installEventFilter(this);
} }
bool bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
{ {
auto widget = static_cast<QWidget*>(obj); auto widget = static_cast<QWidget*>(obj);

View File

@@ -36,8 +36,7 @@ ImageLabel::ImageLabel(QWidget* parent)
setMinimumSize(size()); setMinimumSize(size());
} }
void void ImageLabel::setScreenshot(const QPixmap& pixmap)
ImageLabel::setScreenshot(const QPixmap& pixmap)
{ {
m_pixmap = pixmap; m_pixmap = pixmap;
const QString tooltip = const QString tooltip =
@@ -46,8 +45,7 @@ ImageLabel::setScreenshot(const QPixmap& pixmap)
setScaledPixmap(); setScaledPixmap();
} }
void void ImageLabel::setScaledPixmap()
ImageLabel::setScaledPixmap()
{ {
const qreal scale = qApp->devicePixelRatio(); const qreal scale = qApp->devicePixelRatio();
QPixmap scaledPixmap = m_pixmap.scaled( QPixmap scaledPixmap = m_pixmap.scaled(
@@ -58,8 +56,7 @@ ImageLabel::setScaledPixmap()
// drag handlers // drag handlers
void void ImageLabel::mousePressEvent(QMouseEvent* event)
ImageLabel::mousePressEvent(QMouseEvent* event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
m_dragStartPosition = event->pos(); m_dragStartPosition = event->pos();
@@ -67,16 +64,14 @@ ImageLabel::mousePressEvent(QMouseEvent* event)
} }
} }
void void ImageLabel::mouseReleaseEvent(QMouseEvent* event)
ImageLabel::mouseReleaseEvent(QMouseEvent* event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }
} }
void void ImageLabel::mouseMoveEvent(QMouseEvent* event)
ImageLabel::mouseMoveEvent(QMouseEvent* event)
{ {
if (!(event->buttons() & Qt::LeftButton)) { if (!(event->buttons() & Qt::LeftButton)) {
return; return;
@@ -90,8 +85,7 @@ ImageLabel::mouseMoveEvent(QMouseEvent* event)
} }
// resize handler // resize handler
void void ImageLabel::resizeEvent(QResizeEvent* event)
ImageLabel::resizeEvent(QResizeEvent* event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
setScaledPixmap(); setScaledPixmap();

View File

@@ -70,13 +70,13 @@ QVector<const char*> InfoWindow::m_description = {
QT_TR_NOOP("Copy to clipboard"), QT_TR_NOOP("Copy to clipboard"),
QT_TR_NOOP("Save selection as a file"), QT_TR_NOOP("Save selection as a file"),
QT_TR_NOOP("Undo the last modification"), QT_TR_NOOP("Undo the last modification"),
QT_TR_NOOP("Toggle visibility of sidebar with options of the selected tool"), QT_TR_NOOP(
"Toggle visibility of sidebar with options of the selected tool"),
QT_TR_NOOP("Show color picker"), QT_TR_NOOP("Show color picker"),
QT_TR_NOOP("Change the tool's thickness") QT_TR_NOOP("Change the tool's thickness")
}; };
void void InfoWindow::initInfoTable()
InfoWindow::initInfoTable()
{ {
QTableWidget* table = new QTableWidget(this); QTableWidget* table = new QTableWidget(this);
table->setToolTip(tr("Available shortcuts in the screen capture mode.")); table->setToolTip(tr("Available shortcuts in the screen capture mode."));
@@ -119,8 +119,7 @@ InfoWindow::initInfoTable()
m_layout->addStretch(); m_layout->addStretch();
} }
void void InfoWindow::initLabels()
InfoWindow::initLabels()
{ {
m_layout->addStretch(); m_layout->addStretch();
QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this); QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
@@ -142,14 +141,14 @@ InfoWindow::initLabels()
m_layout->addWidget(versionLabel); m_layout->addWidget(versionLabel);
m_layout->addStretch(); m_layout->addStretch();
m_layout->addSpacing(10); m_layout->addSpacing(10);
QLabel* shortcutsTitleLabel = new QLabel(tr("<u><b>Shortcuts</b></u>"), this); QLabel* shortcutsTitleLabel =
new QLabel(tr("<u><b>Shortcuts</b></u>"), this);
shortcutsTitleLabel->setAlignment(Qt::AlignHCenter); shortcutsTitleLabel->setAlignment(Qt::AlignHCenter);
; ;
m_layout->addWidget(shortcutsTitleLabel); m_layout->addWidget(shortcutsTitleLabel);
} }
void void InfoWindow::keyPressEvent(QKeyEvent* e)
InfoWindow::keyPressEvent(QKeyEvent* e)
{ {
if (e->key() == Qt::Key_Escape) { if (e->key() == Qt::Key_Escape) {
close(); close();

View File

@@ -39,40 +39,34 @@ LoadSpinner::LoadSpinner(QWidget* parent)
m_timer->setInterval(30); m_timer->setInterval(30);
} }
void void LoadSpinner::setColor(const QColor& c)
LoadSpinner::setColor(const QColor& c)
{ {
m_color = c; m_color = c;
} }
void void LoadSpinner::setWidth(int w)
LoadSpinner::setWidth(int w)
{ {
setFixedSize(w, w); setFixedSize(w, w);
updateFrame(); updateFrame();
} }
void void LoadSpinner::setHeight(int h)
LoadSpinner::setHeight(int h)
{ {
setFixedSize(h, h); setFixedSize(h, h);
updateFrame(); updateFrame();
} }
void void LoadSpinner::start()
LoadSpinner::start()
{ {
m_timer->start(); m_timer->start();
} }
void void LoadSpinner::stop()
LoadSpinner::stop()
{ {
m_timer->stop(); m_timer->stop();
} }
void void LoadSpinner::paintEvent(QPaintEvent*)
LoadSpinner::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
@@ -86,8 +80,7 @@ LoadSpinner::paintEvent(QPaintEvent*)
painter.drawArc(m_frame, (m_startAngle * 16), (m_span * 16)); painter.drawArc(m_frame, (m_startAngle * 16), (m_span * 16));
} }
void void LoadSpinner::rotate()
LoadSpinner::rotate()
{ {
const int advance = 3; const int advance = 3;
const int grow = 8; const int grow = 8;
@@ -107,8 +100,8 @@ LoadSpinner::rotate()
update(); update();
} }
void void LoadSpinner::updateFrame()
LoadSpinner::updateFrame()
{ {
m_frame = QRect(OFFSET, OFFSET, width() - OFFSET * 2, height() - OFFSET * 2); m_frame =
QRect(OFFSET, OFFSET, width() - OFFSET * 2, height() - OFFSET * 2);
} }

View File

@@ -54,16 +54,14 @@ NotificationWidget::NotificationWidget(QWidget* parent)
setFixedHeight(40); setFixedHeight(40);
} }
void void NotificationWidget::showMessage(const QString& msg)
NotificationWidget::showMessage(const QString& msg)
{ {
m_label->setText(msg); m_label->setText(msg);
m_label->show(); m_label->show();
animatedShow(); animatedShow();
} }
void void NotificationWidget::animatedShow()
NotificationWidget::animatedShow()
{ {
m_showAnimation->setStartValue(QRect(0, 0, width(), 0)); m_showAnimation->setStartValue(QRect(0, 0, width(), 0));
m_showAnimation->setEndValue(QRect(0, 0, width(), height())); m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
@@ -71,8 +69,7 @@ NotificationWidget::animatedShow()
m_timer->start(); m_timer->start();
} }
void void NotificationWidget::animatedHide()
NotificationWidget::animatedHide()
{ {
m_hideAnimation->setStartValue(QRect(0, 0, width(), height())); m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(0, 0, width(), 0)); m_hideAnimation->setEndValue(QRect(0, 0, width(), 0));

View File

@@ -37,8 +37,7 @@ OrientablePushButton::OrientablePushButton(const QIcon& icon,
: CaptureButton(icon, text, parent) : CaptureButton(icon, text, parent)
{} {}
QSize QSize OrientablePushButton::sizeHint() const
OrientablePushButton::sizeHint() const
{ {
QSize sh = QPushButton::sizeHint(); QSize sh = QPushButton::sizeHint();
@@ -49,8 +48,7 @@ OrientablePushButton::sizeHint() const
return sh; return sh;
} }
void void OrientablePushButton::paintEvent(QPaintEvent* event)
OrientablePushButton::paintEvent(QPaintEvent* event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
@@ -73,14 +71,12 @@ OrientablePushButton::paintEvent(QPaintEvent* event)
painter.drawControl(QStyle::CE_PushButton, option); painter.drawControl(QStyle::CE_PushButton, option);
} }
OrientablePushButton::Orientation OrientablePushButton::Orientation OrientablePushButton::orientation() const
OrientablePushButton::orientation() const
{ {
return m_orientation; return m_orientation;
} }
void void OrientablePushButton::setOrientation(
OrientablePushButton::setOrientation(
const OrientablePushButton::Orientation& orientation) const OrientablePushButton::Orientation& orientation)
{ {
m_orientation = orientation; m_orientation = orientation;

View File

@@ -41,7 +41,8 @@ public:
case QEvent::MouseMove: case QEvent::MouseMove:
return m_pw->handleMouseMove(static_cast<QMouseEvent*>(event)); return m_pw->handleMouseMove(static_cast<QMouseEvent*>(event));
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
return m_pw->handleMouseButtonPressed(static_cast<QMouseEvent*>(event)); return m_pw->handleMouseButtonPressed(
static_cast<QMouseEvent*>(event));
case QEvent::KeyPress: case QEvent::KeyPress:
return m_pw->handleKeyPress(static_cast<QKeyEvent*>(event)); return m_pw->handleKeyPress(static_cast<QKeyEvent*>(event));
default: default:
@@ -107,8 +108,7 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
m_layout->addWidget(m_colorWheel); m_layout->addWidget(m_colorWheel);
} }
void void SidePanelWidget::updateColor(const QColor& c)
SidePanelWidget::updateColor(const QColor& c)
{ {
m_color = c; m_color = c;
m_colorLabel->setStyleSheet( m_colorLabel->setStyleSheet(
@@ -116,29 +116,25 @@ SidePanelWidget::updateColor(const QColor& c)
m_colorWheel->setColor(m_color); m_colorWheel->setColor(m_color);
} }
void void SidePanelWidget::updateThickness(const int& t)
SidePanelWidget::updateThickness(const int& t)
{ {
m_thickness = qBound(0, t, 100); m_thickness = qBound(0, t, 100);
m_thicknessSlider->setValue(m_thickness); m_thicknessSlider->setValue(m_thickness);
} }
void void SidePanelWidget::updateColorNoWheel(const QColor& c)
SidePanelWidget::updateColorNoWheel(const QColor& c)
{ {
m_color = c; m_color = c;
m_colorLabel->setStyleSheet( m_colorLabel->setStyleSheet(
QStringLiteral("QLabel { background-color : %1; }").arg(c.name())); QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
} }
void void SidePanelWidget::updateCurrentThickness()
SidePanelWidget::updateCurrentThickness()
{ {
emit thicknessChanged(m_thicknessSlider->value()); emit thicknessChanged(m_thicknessSlider->value());
} }
void void SidePanelWidget::colorGrabberActivated()
SidePanelWidget::colorGrabberActivated()
{ {
grabKeyboard(); grabKeyboard();
grabMouse(Qt::CrossCursor); grabMouse(Qt::CrossCursor);
@@ -151,8 +147,7 @@ SidePanelWidget::colorGrabberActivated()
updateGrabButton(true); updateGrabButton(true);
} }
void void SidePanelWidget::releaseColorGrab()
SidePanelWidget::releaseColorGrab()
{ {
setMouseTracking(false); setMouseTracking(false);
removeEventFilter(m_eventFilter); removeEventFilter(m_eventFilter);
@@ -162,8 +157,7 @@ SidePanelWidget::releaseColorGrab()
updateGrabButton(false); updateGrabButton(false);
} }
QColor QColor SidePanelWidget::grabPixmapColor(const QPoint& p)
SidePanelWidget::grabPixmapColor(const QPoint& p)
{ {
QColor c; QColor c;
if (m_pixmap) { if (m_pixmap) {
@@ -173,8 +167,7 @@ SidePanelWidget::grabPixmapColor(const QPoint& p)
return c; return c;
} }
bool bool SidePanelWidget::handleKeyPress(QKeyEvent* e)
SidePanelWidget::handleKeyPress(QKeyEvent* e)
{ {
if (e->key() == Qt::Key_Space) { if (e->key() == Qt::Key_Space) {
emit togglePanel(); emit togglePanel();
@@ -189,8 +182,7 @@ SidePanelWidget::handleKeyPress(QKeyEvent* e)
return true; return true;
} }
bool bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
{ {
if (m_colorGrabButton->geometry().contains(e->pos()) || if (m_colorGrabButton->geometry().contains(e->pos()) ||
e->button() == Qt::RightButton) { e->button() == Qt::RightButton) {
@@ -203,15 +195,13 @@ SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
return true; return true;
} }
bool bool SidePanelWidget::handleMouseMove(QMouseEvent* e)
SidePanelWidget::handleMouseMove(QMouseEvent* e)
{ {
updateColorNoWheel(grabPixmapColor(e->globalPos())); updateColorNoWheel(grabPixmapColor(e->globalPos()));
return true; return true;
} }
void void SidePanelWidget::updateGrabButton(const bool activated)
SidePanelWidget::updateGrabButton(const bool activated)
{ {
if (activated) { if (activated) {
m_colorGrabButton->setText(tr("Press ESC to cancel")); m_colorGrabButton->setText(tr("Press ESC to cancel"));

View File

@@ -44,41 +44,37 @@ UtilityPanel::UtilityPanel(QWidget* parent)
&QWidget::hide); &QWidget::hide);
} }
QWidget* QWidget* UtilityPanel::toolWidget() const
UtilityPanel::toolWidget() const
{ {
return m_toolWidget; return m_toolWidget;
} }
void void UtilityPanel::addToolWidget(QWidget* w)
UtilityPanel::addToolWidget(QWidget* w)
{ {
if (m_toolWidget) { if (m_toolWidget) {
m_toolWidget->deleteLater(); m_toolWidget->deleteLater();
} }
if (w) { if (w) {
m_toolWidget = w; m_toolWidget = w;
m_toolWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); m_toolWidget->setSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Preferred);
m_upLayout->addWidget(w); m_upLayout->addWidget(w);
} }
} }
void void UtilityPanel::clearToolWidget()
UtilityPanel::clearToolWidget()
{ {
if (m_toolWidget) { if (m_toolWidget) {
m_toolWidget->deleteLater(); m_toolWidget->deleteLater();
} }
} }
void void UtilityPanel::pushWidget(QWidget* w)
UtilityPanel::pushWidget(QWidget* w)
{ {
m_layout->insertWidget(m_layout->count() - 1, w); m_layout->insertWidget(m_layout->count() - 1, w);
} }
void void UtilityPanel::toggle()
UtilityPanel::toggle()
{ {
if (m_internalPanel->isHidden()) { if (m_internalPanel->isHidden()) {
setAttribute(Qt::WA_TransparentForMouseEvents, false); setAttribute(Qt::WA_TransparentForMouseEvents, false);
@@ -94,8 +90,7 @@ UtilityPanel::toggle()
} }
} }
void void UtilityPanel::initInternalPanel()
UtilityPanel::initInternalPanel()
{ {
m_internalPanel = new QScrollArea(this); m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation); m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);