mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Code refactoring - change code style to the new clang-format rules
This commit is contained in:
@@ -17,38 +17,40 @@
|
||||
|
||||
#include "commandargument.h"
|
||||
|
||||
CommandArgument::CommandArgument() {
|
||||
CommandArgument::CommandArgument() {}
|
||||
|
||||
}
|
||||
CommandArgument::CommandArgument(const QString& name,
|
||||
const QString& description)
|
||||
: m_name(name)
|
||||
, m_description(description)
|
||||
{}
|
||||
|
||||
CommandArgument::CommandArgument(const QString &name,
|
||||
const QString &description) :
|
||||
m_name(name), m_description(description)
|
||||
void CommandArgument::setName(const QString& name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CommandArgument::setName(const QString &name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString CommandArgument::name() const {
|
||||
QString CommandArgument::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void CommandArgument::setDescription(const QString &description) {
|
||||
void CommandArgument::setDescription(const QString& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
QString CommandArgument::description() const {
|
||||
QString CommandArgument::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
bool CommandArgument::isRoot() const {
|
||||
bool CommandArgument::isRoot() const
|
||||
{
|
||||
return m_name.isEmpty() && m_description.isEmpty();
|
||||
}
|
||||
|
||||
bool CommandArgument::operator ==(const CommandArgument &arg) const {
|
||||
return m_description == arg.m_description
|
||||
&& m_name == arg.m_name;
|
||||
bool CommandArgument::operator==(const CommandArgument& arg) const
|
||||
{
|
||||
return m_description == arg.m_description && m_name == arg.m_name;
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
class CommandArgument {
|
||||
class CommandArgument
|
||||
{
|
||||
public:
|
||||
CommandArgument();
|
||||
explicit CommandArgument(const QString &name, const QString &description);
|
||||
explicit CommandArgument(const QString& name, const QString& description);
|
||||
|
||||
void setName(const QString &name);
|
||||
void setName(const QString& name);
|
||||
QString name() const;
|
||||
|
||||
void setDescription(const QString &description);
|
||||
void setDescription(const QString& description);
|
||||
QString description() const;
|
||||
|
||||
bool isRoot() const;
|
||||
|
||||
bool operator ==(const CommandArgument &arg) const;
|
||||
bool operator==(const CommandArgument& arg) const;
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
|
||||
@@ -19,34 +19,34 @@
|
||||
#include <QApplication>
|
||||
#include <QTextStream>
|
||||
|
||||
CommandLineParser::CommandLineParser() :
|
||||
m_description(qApp->applicationName())
|
||||
{
|
||||
|
||||
}
|
||||
CommandLineParser::CommandLineParser()
|
||||
: m_description(qApp->applicationName())
|
||||
{}
|
||||
|
||||
namespace {
|
||||
|
||||
QTextStream out(stdout);
|
||||
QTextStream err(stderr);
|
||||
|
||||
auto versionOption = CommandOption({"v", "version"},
|
||||
auto versionOption =
|
||||
CommandOption({ "v", "version" },
|
||||
QStringLiteral("Displays version information"));
|
||||
auto helpOption = CommandOption({"h", "help"},
|
||||
QStringLiteral("Displays this help"));
|
||||
auto helpOption =
|
||||
CommandOption({ "h", "help" }, QStringLiteral("Displays this help"));
|
||||
|
||||
QString optionsToString(const QList<CommandOption> &options,
|
||||
const QList<CommandArgument> &arguments) {
|
||||
QString optionsToString(const QList<CommandOption>& options,
|
||||
const QList<CommandArgument>& arguments)
|
||||
{
|
||||
int size = 0; // track the largest size
|
||||
QStringList dashedOptionList;
|
||||
// save the dashed options and its size in order to print the description
|
||||
// of every option at the same horizontal character position.
|
||||
for (auto const &option: options) {
|
||||
for (auto const& option : options) {
|
||||
QStringList dashedOptions = option.dashedNames();
|
||||
QString joinedDashedOptions = dashedOptions.join(QStringLiteral(", "));
|
||||
if (!option.valueName().isEmpty()) {
|
||||
joinedDashedOptions += QStringLiteral(" <%1>")
|
||||
.arg(option.valueName());
|
||||
joinedDashedOptions +=
|
||||
QStringLiteral(" <%1>").arg(option.valueName());
|
||||
}
|
||||
if (joinedDashedOptions.length() > size) {
|
||||
size = joinedDashedOptions.length();
|
||||
@@ -54,20 +54,21 @@ QString optionsToString(const QList<CommandOption> &options,
|
||||
dashedOptionList << joinedDashedOptions;
|
||||
}
|
||||
// check the length of the arguments
|
||||
for (auto const &arg: arguments) {
|
||||
if(arg.name().length() > size)
|
||||
for (auto const& arg : arguments) {
|
||||
if (arg.name().length() > size)
|
||||
size = arg.name().length();
|
||||
}
|
||||
// generate the text
|
||||
QString result;
|
||||
if(!dashedOptionList.isEmpty()) {
|
||||
if (!dashedOptionList.isEmpty()) {
|
||||
result += QLatin1String("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) {
|
||||
result += QStringLiteral(" %1 %2\n")
|
||||
.arg(dashedOptionList.at(i).leftJustified(size, ' '))
|
||||
.arg(options.at(i).description()
|
||||
.replace(QLatin1String("\n"), linePadding));
|
||||
.arg(options.at(i).description().replace(
|
||||
QLatin1String("\n"), linePadding));
|
||||
}
|
||||
if (!arguments.isEmpty()) {
|
||||
result += QLatin1String("\n");
|
||||
@@ -86,14 +87,14 @@ QString optionsToString(const QList<CommandOption> &options,
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
bool CommandLineParser::processArgs(const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node * &actualNode)
|
||||
bool CommandLineParser::processArgs(const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node*& actualNode)
|
||||
{
|
||||
QString argument = *actualIt;
|
||||
bool ok = true;
|
||||
bool isValidArg = false;
|
||||
for (Node &n: actualNode->subNodes) {
|
||||
for (Node& n : actualNode->subNodes) {
|
||||
if (n.argument.name() == argument) {
|
||||
actualNode = &n;
|
||||
isValidArg = true;
|
||||
@@ -114,9 +115,9 @@ bool CommandLineParser::processArgs(const QStringList &args,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool CommandLineParser::processOptions(const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node *const actualNode)
|
||||
bool CommandLineParser::processOptions(const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node* const actualNode)
|
||||
{
|
||||
QString arg = *actualIt;
|
||||
bool ok = true;
|
||||
@@ -124,20 +125,17 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
int equalsPos = arg.indexOf(QLatin1String("="));
|
||||
QString valueStr;
|
||||
if (equalsPos != -1) {
|
||||
valueStr = arg.mid(equalsPos +1); // right
|
||||
valueStr = arg.mid(equalsPos + 1); // right
|
||||
arg = arg.mid(0, equalsPos); // left
|
||||
}
|
||||
// check format -x --xx...
|
||||
bool isDoubleDashed = arg.startsWith(QLatin1String("--"));
|
||||
ok = isDoubleDashed ? arg.length() > 3 :
|
||||
arg.length() == 2;
|
||||
ok = isDoubleDashed ? arg.length() > 3 : arg.length() == 2;
|
||||
if (!ok) {
|
||||
out << QStringLiteral("the option %1 has a wrong format.").arg(arg);
|
||||
return ok;
|
||||
}
|
||||
arg = isDoubleDashed ?
|
||||
arg.remove(0, 2) :
|
||||
arg.remove(0, 1);
|
||||
arg = isDoubleDashed ? arg.remove(0, 2) : arg.remove(0, 1);
|
||||
// get option
|
||||
auto endIt = actualNode->options.cend();
|
||||
auto optionIt = endIt;
|
||||
@@ -153,7 +151,8 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
argName = qApp->applicationName();
|
||||
}
|
||||
out << QStringLiteral("the option '%1' is not a valid option "
|
||||
"for the argument '%2'.").arg(arg)
|
||||
"for the argument '%2'.")
|
||||
.arg(arg)
|
||||
.arg(argName);
|
||||
ok = false;
|
||||
return ok;
|
||||
@@ -163,15 +162,17 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
bool requiresValue = !(option.valueName().isEmpty());
|
||||
if (!requiresValue && equalsPos != -1) {
|
||||
out << QStringLiteral("the option '%1' contains a '=' and it doesn't "
|
||||
"require a value.").arg(arg);
|
||||
"require a value.")
|
||||
.arg(arg);
|
||||
ok = false;
|
||||
return ok;
|
||||
} else if (requiresValue && valueStr.isEmpty()) {
|
||||
// find in the next
|
||||
if (actualIt+1 != args.cend()) {
|
||||
if (actualIt + 1 != args.cend()) {
|
||||
++actualIt;
|
||||
} else {
|
||||
out << QStringLiteral("Expected value after the option '%1'.").arg(arg);
|
||||
out << QStringLiteral("Expected value after the option '%1'.")
|
||||
.arg(arg);
|
||||
ok = false;
|
||||
return ok;
|
||||
}
|
||||
@@ -193,17 +194,17 @@ bool CommandLineParser::processOptions(const QStringList &args,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool CommandLineParser::parse(const QStringList &args) {
|
||||
bool CommandLineParser::parse(const QStringList& args)
|
||||
{
|
||||
m_foundArgs.clear();
|
||||
m_foundOptions.clear();
|
||||
bool ok = true;
|
||||
Node *actualNode = &m_parseTree;
|
||||
Node* actualNode = &m_parseTree;
|
||||
auto it = ++args.cbegin();
|
||||
// check version option
|
||||
QStringList dashedVersion = versionOption.dashedNames();
|
||||
if (m_withVersion && args.length() > 1 &&
|
||||
dashedVersion.contains(args.at(1)))
|
||||
{
|
||||
dashedVersion.contains(args.at(1))) {
|
||||
if (args.length() == 2) {
|
||||
printVersion();
|
||||
m_foundOptions << versionOption;
|
||||
@@ -212,13 +213,12 @@ bool CommandLineParser::parse(const QStringList &args) {
|
||||
ok = false;
|
||||
}
|
||||
return ok;
|
||||
|
||||
}
|
||||
// check help option
|
||||
ok = processIfOptionIsHelp(args, it, actualNode);
|
||||
// process the other args
|
||||
for (; it != args.cend() && ok; ++it) {
|
||||
const QString &value = *it;
|
||||
const QString& value = *it;
|
||||
if (value.startsWith(QLatin1String("-"))) {
|
||||
ok = processOptions(args, it, actualNode);
|
||||
|
||||
@@ -232,21 +232,23 @@ bool CommandLineParser::parse(const QStringList &args) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
CommandOption CommandLineParser::addVersionOption() {
|
||||
CommandOption CommandLineParser::addVersionOption()
|
||||
{
|
||||
m_withVersion = true;
|
||||
return versionOption;
|
||||
}
|
||||
|
||||
CommandOption CommandLineParser::addHelpOption() {
|
||||
CommandOption CommandLineParser::addHelpOption()
|
||||
{
|
||||
m_withHelp = true;
|
||||
return helpOption;
|
||||
}
|
||||
|
||||
bool CommandLineParser::AddArgument(const CommandArgument &arg,
|
||||
const CommandArgument &parent)
|
||||
bool CommandLineParser::AddArgument(const CommandArgument& arg,
|
||||
const CommandArgument& parent)
|
||||
{
|
||||
bool res = true;
|
||||
Node *n = findParent(parent);
|
||||
Node* n = findParent(parent);
|
||||
if (n == nullptr) {
|
||||
res = false;
|
||||
} else {
|
||||
@@ -257,11 +259,11 @@ bool CommandLineParser::AddArgument(const CommandArgument &arg,
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CommandLineParser::AddOption(const CommandOption &option,
|
||||
const CommandArgument &parent)
|
||||
bool CommandLineParser::AddOption(const CommandOption& option,
|
||||
const CommandArgument& parent)
|
||||
{
|
||||
bool res = true;
|
||||
Node *n = findParent(parent);
|
||||
Node* n = findParent(parent);
|
||||
if (n == nullptr) {
|
||||
res = false;
|
||||
} else {
|
||||
@@ -270,11 +272,11 @@ bool CommandLineParser::AddOption(const CommandOption &option,
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CommandLineParser::AddOptions(const QList<CommandOption> &options,
|
||||
const CommandArgument &parent)
|
||||
bool CommandLineParser::AddOptions(const QList<CommandOption>& options,
|
||||
const CommandArgument& parent)
|
||||
{
|
||||
bool res = true;
|
||||
for (auto const &option: options) {
|
||||
for (auto const& option : options) {
|
||||
if (!AddOption(option, parent)) {
|
||||
res = false;
|
||||
break;
|
||||
@@ -283,26 +285,30 @@ bool CommandLineParser::AddOptions(const QList<CommandOption> &options,
|
||||
return res;
|
||||
}
|
||||
|
||||
void CommandLineParser::setGeneralErrorMessage(const QString &msg) {
|
||||
void CommandLineParser::setGeneralErrorMessage(const QString& msg)
|
||||
{
|
||||
m_generalErrorMessage = msg;
|
||||
}
|
||||
|
||||
void CommandLineParser::setDescription(const QString &description) {
|
||||
void CommandLineParser::setDescription(const QString& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
bool CommandLineParser::isSet(const CommandArgument &arg) const {
|
||||
bool CommandLineParser::isSet(const CommandArgument& arg) const
|
||||
{
|
||||
return m_foundArgs.contains(arg);
|
||||
}
|
||||
|
||||
|
||||
bool CommandLineParser::isSet(const CommandOption &option) const {
|
||||
bool CommandLineParser::isSet(const CommandOption& option) const
|
||||
{
|
||||
return m_foundOptions.contains(option);
|
||||
}
|
||||
|
||||
QString CommandLineParser::value(const CommandOption &option) const {
|
||||
QString CommandLineParser::value(const CommandOption& option) const
|
||||
{
|
||||
QString value = option.value();
|
||||
for (const CommandOption &fOption: m_foundOptions) {
|
||||
for (const CommandOption& fOption : m_foundOptions) {
|
||||
if (option == fOption) {
|
||||
value = fOption.value();
|
||||
break;
|
||||
@@ -311,12 +317,14 @@ QString CommandLineParser::value(const CommandOption &option) const {
|
||||
return value;
|
||||
}
|
||||
|
||||
void CommandLineParser::printVersion() {
|
||||
void CommandLineParser::printVersion()
|
||||
{
|
||||
out << "Flameshot " << qApp->applicationVersion() << "\nCompiled with Qt "
|
||||
<< static_cast<QString>(QT_VERSION_STR) << "\n";
|
||||
}
|
||||
|
||||
void CommandLineParser::printHelp(QStringList args, const Node *node) {
|
||||
void CommandLineParser::printHelp(QStringList args, const Node* node)
|
||||
{
|
||||
args.removeLast(); // remove the help, it's always the last
|
||||
QString helpText;
|
||||
// add usage info
|
||||
@@ -327,10 +335,11 @@ void CommandLineParser::printHelp(QStringList args, const Node *node) {
|
||||
QString argText = node->subNodes.isEmpty() ? "" : "[arguments]";
|
||||
helpText += QStringLiteral("Usage: %1 [%2-options] %3\n\n")
|
||||
.arg(args.join(QStringLiteral(" ")))
|
||||
.arg(argName).arg(argText);
|
||||
.arg(argName)
|
||||
.arg(argText);
|
||||
// add command options and subarguments
|
||||
QList<CommandArgument> subArgs;
|
||||
for (const Node &n: node->subNodes)
|
||||
for (const Node& n : node->subNodes)
|
||||
subArgs.append(n.argument);
|
||||
auto modifiedOptions = node->options;
|
||||
if (m_withHelp)
|
||||
@@ -344,16 +353,15 @@ void CommandLineParser::printHelp(QStringList args, const Node *node) {
|
||||
}
|
||||
|
||||
CommandLineParser::Node* CommandLineParser::findParent(
|
||||
const CommandArgument &parent)
|
||||
const CommandArgument& parent)
|
||||
{
|
||||
if (parent == CommandArgument()) {
|
||||
return &m_parseTree;
|
||||
}
|
||||
//find the parent in the subNodes recursively
|
||||
Node *res = nullptr;
|
||||
for (auto i = m_parseTree.subNodes.begin();
|
||||
i != m_parseTree.subNodes.end(); ++i)
|
||||
{
|
||||
// find the parent in the subNodes recursively
|
||||
Node* res = nullptr;
|
||||
for (auto i = m_parseTree.subNodes.begin(); i != m_parseTree.subNodes.end();
|
||||
++i) {
|
||||
res = recursiveParentSearch(parent, *i);
|
||||
if (res != nullptr) {
|
||||
break;
|
||||
@@ -363,13 +371,14 @@ CommandLineParser::Node* CommandLineParser::findParent(
|
||||
}
|
||||
|
||||
CommandLineParser::Node* CommandLineParser::recursiveParentSearch(
|
||||
const CommandArgument &parent, Node &node) const
|
||||
const CommandArgument& parent,
|
||||
Node& node) const
|
||||
{
|
||||
Node * res = nullptr;
|
||||
Node* res = nullptr;
|
||||
if (node.argument == parent) {
|
||||
res = &node;
|
||||
} else {
|
||||
for (auto i = node.subNodes.begin(); i != node.subNodes.end(); ++i){
|
||||
for (auto i = node.subNodes.begin(); i != node.subNodes.end(); ++i) {
|
||||
res = recursiveParentSearch(parent, *i);
|
||||
if (res != nullptr) {
|
||||
break;
|
||||
@@ -380,16 +389,15 @@ CommandLineParser::Node* CommandLineParser::recursiveParentSearch(
|
||||
}
|
||||
|
||||
bool CommandLineParser::processIfOptionIsHelp(
|
||||
const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node * &actualNode)
|
||||
const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node*& actualNode)
|
||||
{
|
||||
bool ok = true;
|
||||
auto dashedHelpNames = helpOption.dashedNames();
|
||||
if (m_withHelp && actualIt != args.cend() &&
|
||||
dashedHelpNames.contains(*actualIt))
|
||||
{
|
||||
if (actualIt+1 == args.cend()) {
|
||||
dashedHelpNames.contains(*actualIt)) {
|
||||
if (actualIt + 1 == args.cend()) {
|
||||
m_foundOptions << helpOption;
|
||||
printHelp(args, actualNode);
|
||||
actualIt++;
|
||||
|
||||
@@ -21,32 +21,33 @@
|
||||
#include "src/cli/commandoption.h"
|
||||
#include <QMap>
|
||||
|
||||
class CommandLineParser {
|
||||
class CommandLineParser
|
||||
{
|
||||
public:
|
||||
CommandLineParser();
|
||||
|
||||
bool parse(const QStringList &args);
|
||||
bool parse(const QStringList& args);
|
||||
|
||||
CommandArgument rootArgument() const { return CommandArgument(); }
|
||||
|
||||
CommandOption addVersionOption();
|
||||
CommandOption addHelpOption();
|
||||
|
||||
bool AddArgument(const CommandArgument &arg,
|
||||
const CommandArgument &parent = CommandArgument());
|
||||
bool AddArgument(const CommandArgument& arg,
|
||||
const CommandArgument& parent = CommandArgument());
|
||||
|
||||
bool AddOption(const CommandOption &option,
|
||||
const CommandArgument &parent = CommandArgument());
|
||||
bool AddOption(const CommandOption& option,
|
||||
const CommandArgument& parent = CommandArgument());
|
||||
|
||||
bool AddOptions(const QList<CommandOption> &options,
|
||||
const CommandArgument &parent = CommandArgument());
|
||||
bool AddOptions(const QList<CommandOption>& options,
|
||||
const CommandArgument& parent = CommandArgument());
|
||||
|
||||
void setGeneralErrorMessage(const QString &msg);
|
||||
void setDescription(const QString &description);
|
||||
void setGeneralErrorMessage(const QString& msg);
|
||||
void setDescription(const QString& description);
|
||||
|
||||
bool isSet(const CommandArgument &arg) const;
|
||||
bool isSet(const CommandOption &option) const;
|
||||
QString value(const CommandOption &option) const;
|
||||
bool isSet(const CommandArgument& arg) const;
|
||||
bool isSet(const CommandOption& option) const;
|
||||
QString value(const CommandOption& option) const;
|
||||
|
||||
private:
|
||||
bool m_withHelp = false;
|
||||
@@ -54,12 +55,15 @@ private:
|
||||
QString m_description;
|
||||
QString m_generalErrorMessage;
|
||||
|
||||
struct Node {
|
||||
explicit Node(const CommandArgument &arg) : argument(arg) {}
|
||||
struct Node
|
||||
{
|
||||
explicit Node(const CommandArgument& arg)
|
||||
: argument(arg)
|
||||
{}
|
||||
Node() {}
|
||||
bool operator==(const Node &n) const {
|
||||
return argument == n.argument &&
|
||||
options == n.options &&
|
||||
bool operator==(const Node& n) const
|
||||
{
|
||||
return argument == n.argument && options == n.options &&
|
||||
subNodes == n.subNodes;
|
||||
}
|
||||
CommandArgument argument;
|
||||
@@ -73,17 +77,17 @@ private:
|
||||
|
||||
// helper functions
|
||||
void printVersion();
|
||||
void printHelp(QStringList args, const Node *node);
|
||||
Node* findParent(const CommandArgument &parent);
|
||||
Node* recursiveParentSearch(const CommandArgument &parent,
|
||||
Node &node) const;
|
||||
bool processIfOptionIsHelp(const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node * &actualNode);
|
||||
bool processArgs(const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node * &actualNode);
|
||||
bool processOptions(const QStringList &args,
|
||||
QStringList::const_iterator &actualIt,
|
||||
Node *const actualNode);
|
||||
void printHelp(QStringList args, const Node* node);
|
||||
Node* findParent(const CommandArgument& parent);
|
||||
Node* recursiveParentSearch(const CommandArgument& parent,
|
||||
Node& node) const;
|
||||
bool processIfOptionIsHelp(const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node*& actualNode);
|
||||
bool processArgs(const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node*& actualNode);
|
||||
bool processOptions(const QStringList& args,
|
||||
QStringList::const_iterator& actualIt,
|
||||
Node* const actualNode);
|
||||
};
|
||||
|
||||
@@ -17,76 +17,90 @@
|
||||
|
||||
#include "commandoption.h"
|
||||
|
||||
CommandOption::CommandOption(const QString &name, const QString &description,
|
||||
const QString &valueName,
|
||||
const QString &defaultValue) :
|
||||
m_names(name), m_description(description), m_valueName(valueName),
|
||||
m_value(defaultValue)
|
||||
CommandOption::CommandOption(const QString& name,
|
||||
const QString& description,
|
||||
const QString& valueName,
|
||||
const QString& defaultValue)
|
||||
: m_names(name)
|
||||
, m_description(description)
|
||||
, m_valueName(valueName)
|
||||
, m_value(defaultValue)
|
||||
{
|
||||
m_checker = [](QString const&){ return true; };
|
||||
m_checker = [](QString const&) { return true; };
|
||||
}
|
||||
|
||||
CommandOption::CommandOption(const QStringList &names,
|
||||
const QString &description,
|
||||
const QString &valueName,
|
||||
const QString &defaultValue) :
|
||||
m_names(names), m_description(description), m_valueName(valueName),
|
||||
m_value(defaultValue)
|
||||
CommandOption::CommandOption(const QStringList& names,
|
||||
const QString& description,
|
||||
const QString& valueName,
|
||||
const QString& defaultValue)
|
||||
: m_names(names)
|
||||
, m_description(description)
|
||||
, m_valueName(valueName)
|
||||
, m_value(defaultValue)
|
||||
{
|
||||
m_checker = [](QString const&) -> bool { return true; };
|
||||
}
|
||||
|
||||
void CommandOption::setName(const QString &name) {
|
||||
void CommandOption::setName(const QString& name)
|
||||
{
|
||||
m_names = QStringList() << name;
|
||||
}
|
||||
|
||||
void CommandOption::setNames(const QStringList &names) {
|
||||
void CommandOption::setNames(const QStringList& names)
|
||||
{
|
||||
m_names = names;
|
||||
}
|
||||
|
||||
QStringList CommandOption::names() const {
|
||||
QStringList CommandOption::names() const
|
||||
{
|
||||
return m_names;
|
||||
}
|
||||
|
||||
QStringList CommandOption::dashedNames() const {
|
||||
QStringList CommandOption::dashedNames() const
|
||||
{
|
||||
QStringList dashedNames;
|
||||
for (const QString &name: m_names) {
|
||||
for (const QString& name : m_names) {
|
||||
// prepend "-" to single character options, and "--" to the others
|
||||
QString dashedName = (name.length() == 1) ?
|
||||
QStringLiteral("-%1").arg(name) :
|
||||
QStringLiteral("--%1").arg(name);
|
||||
QString dashedName = (name.length() == 1)
|
||||
? QStringLiteral("-%1").arg(name)
|
||||
: QStringLiteral("--%1").arg(name);
|
||||
dashedNames << dashedName;
|
||||
}
|
||||
return dashedNames;
|
||||
}
|
||||
|
||||
void CommandOption::setValueName(const QString &name) {
|
||||
void CommandOption::setValueName(const QString& name)
|
||||
{
|
||||
m_valueName = name;
|
||||
}
|
||||
|
||||
QString CommandOption::valueName() const {
|
||||
QString CommandOption::valueName() const
|
||||
{
|
||||
return m_valueName;
|
||||
}
|
||||
|
||||
void CommandOption::setValue(const QString &value) {
|
||||
void CommandOption::setValue(const QString& value)
|
||||
{
|
||||
if (m_valueName.isEmpty()) {
|
||||
m_valueName = QLatin1String("value");
|
||||
}
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
QString CommandOption::value() const {
|
||||
QString CommandOption::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void CommandOption::addChecker(const function<bool (const QString &)> checker,
|
||||
const QString &errMsg)
|
||||
void CommandOption::addChecker(const function<bool(const QString&)> checker,
|
||||
const QString& errMsg)
|
||||
{
|
||||
m_checker = checker;
|
||||
m_errorMsg = errMsg;
|
||||
}
|
||||
|
||||
bool CommandOption::checkValue(const QString &value) const {
|
||||
bool CommandOption::checkValue(const QString& value) const
|
||||
{
|
||||
return m_checker(value);
|
||||
}
|
||||
|
||||
@@ -95,18 +109,18 @@ QString CommandOption::description() const
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void CommandOption::setDescription(const QString &description)
|
||||
void CommandOption::setDescription(const QString& description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
QString CommandOption::errorMsg() const {
|
||||
QString CommandOption::errorMsg() const
|
||||
{
|
||||
return m_errorMsg;
|
||||
}
|
||||
|
||||
bool CommandOption::operator ==(const CommandOption &option) const
|
||||
bool CommandOption::operator==(const CommandOption& option) const
|
||||
{
|
||||
return m_description == option.m_description
|
||||
&& m_names == option.m_names
|
||||
&& m_valueName == option.m_valueName;
|
||||
return m_description == option.m_description && m_names == option.m_names &&
|
||||
m_valueName == option.m_valueName;
|
||||
}
|
||||
|
||||
@@ -22,36 +22,40 @@
|
||||
|
||||
using std::function;
|
||||
|
||||
class CommandOption {
|
||||
class CommandOption
|
||||
{
|
||||
public:
|
||||
CommandOption(const QString &name, const QString &description,
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString());
|
||||
CommandOption(const QString& name,
|
||||
const QString& description,
|
||||
const QString& valueName = QString(),
|
||||
const QString& defaultValue = QString());
|
||||
|
||||
CommandOption(const QStringList &names, const QString &description,
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString());
|
||||
CommandOption(const QStringList& names,
|
||||
const QString& description,
|
||||
const QString& valueName = QString(),
|
||||
const QString& defaultValue = QString());
|
||||
|
||||
void setName(const QString &name);
|
||||
void setNames(const QStringList &names);
|
||||
void setName(const QString& name);
|
||||
void setNames(const QStringList& names);
|
||||
QStringList names() const;
|
||||
QStringList dashedNames() const;
|
||||
|
||||
void setValueName(const QString &name);
|
||||
void setValueName(const QString& name);
|
||||
QString valueName() const;
|
||||
|
||||
void setValue(const QString &value);
|
||||
void setValue(const QString& value);
|
||||
QString value() const;
|
||||
|
||||
void addChecker(const function<bool(QString const&)> checker, const QString &errMsg);
|
||||
bool checkValue(const QString &value) const;
|
||||
void addChecker(const function<bool(QString const&)> checker,
|
||||
const QString& errMsg);
|
||||
bool checkValue(const QString& value) const;
|
||||
|
||||
QString description() const;
|
||||
void setDescription(const QString &description);
|
||||
void setDescription(const QString& description);
|
||||
|
||||
QString errorMsg() const;
|
||||
|
||||
bool operator==(const CommandOption &option) const;
|
||||
bool operator==(const CommandOption& option) const;
|
||||
|
||||
private:
|
||||
QStringList m_names;
|
||||
|
||||
@@ -21,34 +21,38 @@
|
||||
#include <QListWidgetItem>
|
||||
#include <algorithm>
|
||||
|
||||
ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
|
||||
ButtonListView::ButtonListView(QWidget* parent)
|
||||
: QListWidget(parent)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
setFlow(QListWidget::TopToBottom);
|
||||
initButtonList();
|
||||
updateComponents();
|
||||
connect(this, &QListWidget::itemClicked, this,
|
||||
&ButtonListView::reverseItemCheck);
|
||||
connect(
|
||||
this, &QListWidget::itemClicked, this, &ButtonListView::reverseItemCheck);
|
||||
}
|
||||
|
||||
void ButtonListView::initButtonList() {
|
||||
void ButtonListView::initButtonList()
|
||||
{
|
||||
ToolFactory factory;
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
|
||||
for (const CaptureButton::ButtonType t: listTypes) {
|
||||
CaptureTool *tool = factory.CreateTool(t);
|
||||
for (const CaptureButton::ButtonType t : listTypes) {
|
||||
CaptureTool* tool = factory.CreateTool(t);
|
||||
|
||||
// add element to the local map
|
||||
m_buttonTypeByName.insert(tool->name(), t);
|
||||
|
||||
// init the menu option
|
||||
QListWidgetItem *m_buttonItem = new QListWidgetItem(this);
|
||||
QListWidgetItem* m_buttonItem = new QListWidgetItem(this);
|
||||
|
||||
// when the background is lighter than gray, it uses the white icons
|
||||
QColor bgColor = this->palette().color(QWidget::backgroundRole());
|
||||
m_buttonItem->setIcon(tool->icon(bgColor, false));
|
||||
|
||||
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->setText(tool->name());
|
||||
@@ -57,13 +61,14 @@ void ButtonListView::initButtonList() {
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
|
||||
void ButtonListView::updateActiveButtons(QListWidgetItem* item)
|
||||
{
|
||||
CaptureButton::ButtonType bType = m_buttonTypeByName[item->text()];
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
m_listButtons.append(bType);
|
||||
// TODO refactor so we don't need external sorts
|
||||
using bt = CaptureButton::ButtonType;
|
||||
std::sort(m_listButtons.begin(), m_listButtons.end(), [](bt a, bt b){
|
||||
std::sort(m_listButtons.begin(), m_listButtons.end(), [](bt a, bt b) {
|
||||
return CaptureButton::getPriorityByButton(a) <
|
||||
CaptureButton::getPriorityByButton(b);
|
||||
});
|
||||
@@ -73,7 +78,8 @@ void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
|
||||
ConfigHandler().setButtons(m_listButtons);
|
||||
}
|
||||
|
||||
void ButtonListView::reverseItemCheck(QListWidgetItem *item){
|
||||
void ButtonListView::reverseItemCheck(QListWidgetItem* item)
|
||||
{
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
} else {
|
||||
@@ -82,18 +88,20 @@ void ButtonListView::reverseItemCheck(QListWidgetItem *item){
|
||||
updateActiveButtons(item);
|
||||
}
|
||||
|
||||
void ButtonListView::selectAll() {
|
||||
void ButtonListView::selectAll()
|
||||
{
|
||||
ConfigHandler().setAllTheButtons();
|
||||
for(int i = 0; i < this->count(); ++i) {
|
||||
for (int i = 0; i < this->count(); ++i) {
|
||||
QListWidgetItem* item = this->item(i);
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonListView::updateComponents() {
|
||||
void ButtonListView::updateComponents()
|
||||
{
|
||||
m_listButtons = ConfigHandler().getButtons();
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
for(int i = 0; i < this->count(); ++i) {
|
||||
for (int i = 0; i < this->count(); ++i) {
|
||||
QListWidgetItem* item = this->item(i);
|
||||
auto elem = static_cast<CaptureButton::ButtonType>(listTypes.at(i));
|
||||
if (m_listButtons.contains(elem)) {
|
||||
|
||||
@@ -20,16 +20,17 @@
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include <QListWidget>
|
||||
|
||||
class ButtonListView : public QListWidget {
|
||||
class ButtonListView : public QListWidget
|
||||
{
|
||||
public:
|
||||
explicit ButtonListView(QWidget *parent= nullptr);
|
||||
explicit ButtonListView(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void selectAll();
|
||||
void updateComponents();
|
||||
|
||||
private slots:
|
||||
void reverseItemCheck(QListWidgetItem *);
|
||||
void reverseItemCheck(QListWidgetItem*);
|
||||
|
||||
protected:
|
||||
void initButtonList();
|
||||
@@ -38,5 +39,5 @@ private:
|
||||
QVector<CaptureButton::ButtonType> m_listButtons;
|
||||
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
|
||||
|
||||
void updateActiveButtons(QListWidgetItem *);
|
||||
void updateActiveButtons(QListWidgetItem*);
|
||||
};
|
||||
|
||||
@@ -17,14 +17,17 @@
|
||||
|
||||
#include "clickablelabel.h"
|
||||
|
||||
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) {
|
||||
ClickableLabel::ClickableLabel(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) {
|
||||
ClickableLabel::ClickableLabel(QString s, QWidget* parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setText(s);
|
||||
}
|
||||
|
||||
void ClickableLabel::mousePressEvent(QMouseEvent *) {
|
||||
void ClickableLabel::mousePressEvent(QMouseEvent*)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class ClickableLabel : public QLabel {
|
||||
class ClickableLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClickableLabel(QWidget *parent = nullptr);
|
||||
ClickableLabel(QString s, QWidget *parent = nullptr);
|
||||
explicit ClickableLabel(QWidget* parent = nullptr);
|
||||
ClickableLabel(QString s, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
private:
|
||||
void mousePressEvent (QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
};
|
||||
|
||||
@@ -17,34 +17,40 @@
|
||||
|
||||
#include "extendedslider.h"
|
||||
|
||||
ExtendedSlider::ExtendedSlider(QWidget *parent)
|
||||
ExtendedSlider::ExtendedSlider(QWidget* parent)
|
||||
: QSlider(parent)
|
||||
{
|
||||
connect(this, &ExtendedSlider::valueChanged,
|
||||
this, &ExtendedSlider::updateTooltip);
|
||||
connect(this, &ExtendedSlider::sliderMoved,
|
||||
this, &ExtendedSlider::fireTimer);
|
||||
connect(this,
|
||||
&ExtendedSlider::valueChanged,
|
||||
this,
|
||||
&ExtendedSlider::updateTooltip);
|
||||
connect(
|
||||
this, &ExtendedSlider::sliderMoved, this, &ExtendedSlider::fireTimer);
|
||||
m_timer.setSingleShot(true);
|
||||
connect(&m_timer, &QTimer::timeout,
|
||||
this, &ExtendedSlider::modificationsEnded);
|
||||
connect(
|
||||
&m_timer, &QTimer::timeout, this, &ExtendedSlider::modificationsEnded);
|
||||
}
|
||||
|
||||
int ExtendedSlider::mappedValue(int min, int max) {
|
||||
int ExtendedSlider::mappedValue(int min, int max)
|
||||
{
|
||||
qreal progress =
|
||||
((value() - minimum())) / static_cast<qreal>(maximum() - minimum());
|
||||
return min + (max - min) * progress;
|
||||
}
|
||||
|
||||
void ExtendedSlider::setMapedValue(int min, int val, int max) {
|
||||
void ExtendedSlider::setMapedValue(int min, int val, int max)
|
||||
{
|
||||
qreal progress = ((val - min) + 1) / static_cast<qreal>(max - min);
|
||||
int value = minimum() + (maximum() - minimum()) * progress;
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
void ExtendedSlider::updateTooltip() {
|
||||
setToolTip(QString::number(value())+"%");
|
||||
void ExtendedSlider::updateTooltip()
|
||||
{
|
||||
setToolTip(QString::number(value()) + "%");
|
||||
}
|
||||
|
||||
void ExtendedSlider::fireTimer() {
|
||||
void ExtendedSlider::fireTimer()
|
||||
{
|
||||
m_timer.start(500);
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
#include <QSlider>
|
||||
#include <QTimer>
|
||||
|
||||
class ExtendedSlider : public QSlider {
|
||||
class ExtendedSlider : public QSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ExtendedSlider(QWidget *parent = nullptr);
|
||||
explicit ExtendedSlider(QWidget* parent = nullptr);
|
||||
|
||||
int mappedValue(int min, int max);
|
||||
void setMapedValue(int min, int val, int max);
|
||||
|
||||
@@ -16,21 +16,24 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "filenameeditor.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/config/strftimechooserwidget.h"
|
||||
#include <QVBoxLayout>
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
FileNameEditor::FileNameEditor(QWidget *parent) : QWidget(parent) {
|
||||
FileNameEditor::FileNameEditor(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
initWidgets();
|
||||
initLayout();
|
||||
}
|
||||
|
||||
void FileNameEditor::initLayout() {
|
||||
void FileNameEditor::initLayout()
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
auto infoLabel = new QLabel(tr("Edit the name of your captures:"), this);
|
||||
infoLabel->setFixedHeight(20);
|
||||
@@ -41,14 +44,15 @@ void FileNameEditor::initLayout() {
|
||||
m_layout->addWidget(new QLabel(tr("Preview:")));
|
||||
m_layout->addWidget(m_outputLabel);
|
||||
|
||||
QHBoxLayout *horizLayout = new QHBoxLayout();
|
||||
QHBoxLayout* horizLayout = new QHBoxLayout();
|
||||
horizLayout->addWidget(m_saveButton);
|
||||
horizLayout->addWidget(m_resetButton);
|
||||
horizLayout->addWidget(m_clearButton);
|
||||
m_layout->addLayout(horizLayout);
|
||||
}
|
||||
|
||||
void FileNameEditor::initWidgets() {
|
||||
void FileNameEditor::initWidgets()
|
||||
{
|
||||
m_nameHandler = new FileNameHandler(this);
|
||||
|
||||
// editor
|
||||
@@ -61,55 +65,67 @@ void FileNameEditor::initWidgets() {
|
||||
QString foreground = this->palette().foreground().color().name();
|
||||
m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
|
||||
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);
|
||||
m_outputLabel->setPalette(pal);
|
||||
|
||||
connect(m_nameEditor, &QLineEdit::textChanged, this,
|
||||
connect(m_nameEditor,
|
||||
&QLineEdit::textChanged,
|
||||
this,
|
||||
&FileNameEditor::showParsedPattern);
|
||||
updateComponents();
|
||||
|
||||
// helper buttons
|
||||
m_helperButtons = new StrftimeChooserWidget(this);
|
||||
connect(m_helperButtons, &StrftimeChooserWidget::variableEmitted,
|
||||
this, &FileNameEditor::addToNameEditor);
|
||||
connect(m_helperButtons,
|
||||
&StrftimeChooserWidget::variableEmitted,
|
||||
this,
|
||||
&FileNameEditor::addToNameEditor);
|
||||
|
||||
// save
|
||||
m_saveButton = new QPushButton(tr("Save"), this);
|
||||
connect(m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
|
||||
connect(
|
||||
m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
|
||||
m_saveButton->setToolTip(tr("Saves the pattern"));
|
||||
// reset
|
||||
m_resetButton = new QPushButton(tr("Reset"), this);
|
||||
connect(m_resetButton, &QPushButton::clicked,
|
||||
this, &FileNameEditor::resetName);
|
||||
connect(
|
||||
m_resetButton, &QPushButton::clicked, this, &FileNameEditor::resetName);
|
||||
m_resetButton->setToolTip(tr("Restores the saved pattern"));
|
||||
// clear
|
||||
m_clearButton = new QPushButton(tr("Clear"), this);
|
||||
connect(m_clearButton, &QPushButton::clicked, this,
|
||||
[this](){ m_nameEditor->setText(QString());
|
||||
connect(m_clearButton, &QPushButton::clicked, this, [this]() {
|
||||
m_nameEditor->setText(QString());
|
||||
});
|
||||
m_clearButton->setToolTip(tr("Deletes the name"));}
|
||||
m_clearButton->setToolTip(tr("Deletes the name"));
|
||||
}
|
||||
|
||||
void FileNameEditor::savePattern() {
|
||||
void FileNameEditor::savePattern()
|
||||
{
|
||||
QString pattern = m_nameEditor->text();
|
||||
m_nameHandler->setPattern(pattern);
|
||||
}
|
||||
|
||||
void FileNameEditor::showParsedPattern(const QString &p) {
|
||||
void FileNameEditor::showParsedPattern(const QString& p)
|
||||
{
|
||||
QString output = m_nameHandler->parseFilename(p);
|
||||
m_outputLabel->setText(output);
|
||||
}
|
||||
|
||||
void FileNameEditor::resetName() {
|
||||
void FileNameEditor::resetName()
|
||||
{
|
||||
m_nameEditor->setText(ConfigHandler().filenamePatternValue());
|
||||
}
|
||||
|
||||
void FileNameEditor::addToNameEditor(QString s) {
|
||||
void FileNameEditor::addToNameEditor(QString s)
|
||||
{
|
||||
m_nameEditor->setText(m_nameEditor->text() + s);
|
||||
m_nameEditor->setFocus();
|
||||
}
|
||||
|
||||
void FileNameEditor::updateComponents() {
|
||||
void FileNameEditor::updateComponents()
|
||||
{
|
||||
m_nameEditor->setText(ConfigHandler().filenamePatternValue());
|
||||
m_outputLabel->setText(m_nameHandler->parsedPattern());
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
class QLineEdit;
|
||||
@@ -26,20 +26,21 @@ class FileNameHandler;
|
||||
class QPushButton;
|
||||
class StrftimeChooserWidget;
|
||||
|
||||
class FileNameEditor : public QWidget {
|
||||
class FileNameEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileNameEditor(QWidget *parent = nullptr);
|
||||
explicit FileNameEditor(QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QLineEdit *m_outputLabel;
|
||||
QLineEdit *m_nameEditor;
|
||||
FileNameHandler *m_nameHandler;
|
||||
StrftimeChooserWidget *m_helperButtons;
|
||||
QPushButton *m_saveButton;
|
||||
QPushButton *m_resetButton;
|
||||
QPushButton *m_clearButton;
|
||||
QVBoxLayout* m_layout;
|
||||
QLineEdit* m_outputLabel;
|
||||
QLineEdit* m_nameEditor;
|
||||
FileNameHandler* m_nameHandler;
|
||||
StrftimeChooserWidget* m_helperButtons;
|
||||
QPushButton* m_saveButton;
|
||||
QPushButton* m_resetButton;
|
||||
QPushButton* m_clearButton;
|
||||
|
||||
void initLayout();
|
||||
void initWidgets();
|
||||
@@ -50,6 +51,6 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void savePattern();
|
||||
void showParsedPattern(const QString &);
|
||||
void showParsedPattern(const QString&);
|
||||
void resetName();
|
||||
};
|
||||
|
||||
@@ -1,56 +1,69 @@
|
||||
#include "filepathconfiguration.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/config/strftimechooserwidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QCheckBox>
|
||||
#include <QFileDialog>
|
||||
#include <QDir>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
FilePathConfiguration::FilePathConfiguration(QWidget *parent) : QWidget(parent) {
|
||||
FilePathConfiguration::FilePathConfiguration(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
initWidgets();
|
||||
initLayout();
|
||||
}
|
||||
|
||||
void FilePathConfiguration::initLayout() {
|
||||
void FilePathConfiguration::initLayout()
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
|
||||
m_layout->addWidget(new QLabel(tr("Screenshot path default:")));
|
||||
m_layout->addWidget(m_screenshotPathFixed);
|
||||
m_layout->addWidget(m_screenshotPathFixedDefault);
|
||||
m_layout->addStretch();
|
||||
QHBoxLayout *horizScreenshotButtonsLayout = new QHBoxLayout();
|
||||
QHBoxLayout* horizScreenshotButtonsLayout = new QHBoxLayout();
|
||||
horizScreenshotButtonsLayout->addStretch();
|
||||
horizScreenshotButtonsLayout->addWidget(m_screenshotPathFixedClear);
|
||||
horizScreenshotButtonsLayout->addWidget(m_screenshotPathFixedBrowse);
|
||||
m_layout->addLayout(horizScreenshotButtonsLayout);
|
||||
}
|
||||
|
||||
void FilePathConfiguration::initWidgets() {
|
||||
void FilePathConfiguration::initWidgets()
|
||||
{
|
||||
ConfigHandler config;
|
||||
|
||||
// Screenshot path default
|
||||
m_screenshotPathFixed = new QCheckBox(tr("Use fixed path for screenshots to save"), this);
|
||||
m_screenshotPathFixed =
|
||||
new QCheckBox(tr("Use fixed path for screenshots to save"), this);
|
||||
m_screenshotPathFixed->setChecked(!config.savePathFixed().isEmpty());
|
||||
connect(m_screenshotPathFixed, SIGNAL(toggled(bool)), this, SLOT(sreenshotPathFixed()));
|
||||
connect(m_screenshotPathFixed,
|
||||
SIGNAL(toggled(bool)),
|
||||
this,
|
||||
SLOT(sreenshotPathFixed()));
|
||||
m_screenshotPathFixedDefault = new QLineEdit(this);
|
||||
m_screenshotPathFixedDefault->setText(config.savePathFixed());
|
||||
m_screenshotPathFixedDefault->setDisabled(config.savePathFixed().isEmpty());
|
||||
m_screenshotPathFixedBrowse = new QPushButton(tr("Browse"), this);
|
||||
m_screenshotPathFixedBrowse->setDisabled(config.savePathFixed().isEmpty());
|
||||
connect(m_screenshotPathFixedBrowse, SIGNAL(released()),this, SLOT (screenshotPathFixedSet()));
|
||||
connect(m_screenshotPathFixedBrowse,
|
||||
SIGNAL(released()),
|
||||
this,
|
||||
SLOT(screenshotPathFixedSet()));
|
||||
m_screenshotPathFixedClear = new QPushButton(tr("Clear"), this);
|
||||
m_screenshotPathFixedClear->setDisabled(config.savePathFixed().isEmpty());
|
||||
connect(m_screenshotPathFixedClear, SIGNAL(released()),this, SLOT (screenshotPathFixedClear()));
|
||||
connect(m_screenshotPathFixedClear,
|
||||
SIGNAL(released()),
|
||||
this,
|
||||
SLOT(screenshotPathFixedClear()));
|
||||
}
|
||||
|
||||
void FilePathConfiguration::sreenshotPathFixed() {
|
||||
void FilePathConfiguration::sreenshotPathFixed()
|
||||
{
|
||||
bool status = m_screenshotPathFixedDefault->isEnabled();
|
||||
m_screenshotPathFixedDefault->setEnabled(!status);
|
||||
m_screenshotPathFixedBrowse->setEnabled(!status);
|
||||
@@ -58,8 +71,10 @@ void FilePathConfiguration::sreenshotPathFixed() {
|
||||
screenshotPathFixedClear();
|
||||
}
|
||||
|
||||
void FilePathConfiguration::screenshotPathFixedSet() {
|
||||
QFileDialog *dirDialog = new QFileDialog(this, tr("Select default path for Screenshots"));
|
||||
void FilePathConfiguration::screenshotPathFixedSet()
|
||||
{
|
||||
QFileDialog* dirDialog =
|
||||
new QFileDialog(this, tr("Select default path for Screenshots"));
|
||||
dirDialog->setFileMode(QFileDialog::DirectoryOnly);
|
||||
dirDialog->setOption(QFileDialog::ShowDirsOnly, true);
|
||||
if (dirDialog->exec()) {
|
||||
@@ -71,7 +86,8 @@ void FilePathConfiguration::screenshotPathFixedSet() {
|
||||
}
|
||||
}
|
||||
|
||||
void FilePathConfiguration::screenshotPathFixedClear() {
|
||||
void FilePathConfiguration::screenshotPathFixedClear()
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_screenshotPathFixedDefault->setText("");
|
||||
config.setSavePathFixed(m_screenshotPathFixedDefault->text());
|
||||
|
||||
@@ -9,17 +9,18 @@ class QCheckBox;
|
||||
class FileNameHandler;
|
||||
class QPushButton;
|
||||
|
||||
class FilePathConfiguration : public QWidget {
|
||||
class FilePathConfiguration : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilePathConfiguration(QWidget *parent = nullptr);
|
||||
explicit FilePathConfiguration(QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QCheckBox *m_screenshotPathFixed;
|
||||
QLineEdit *m_screenshotPathFixedDefault;
|
||||
QPushButton *m_screenshotPathFixedBrowse;
|
||||
QPushButton *m_screenshotPathFixedClear;
|
||||
QVBoxLayout* m_layout;
|
||||
QCheckBox* m_screenshotPathFixed;
|
||||
QLineEdit* m_screenshotPathFixedDefault;
|
||||
QPushButton* m_screenshotPathFixedBrowse;
|
||||
QPushButton* m_screenshotPathFixedClear;
|
||||
|
||||
void initLayout();
|
||||
void initWidgets();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "setshortcutwidget.h"
|
||||
#include <QKeyEvent>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QPixmap>
|
||||
|
||||
SetShortcutDialog::SetShortcutDialog(QDialog *parent) : QDialog(parent)
|
||||
SetShortcutDialog::SetShortcutDialog(QDialog* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
@@ -15,29 +16,32 @@ SetShortcutDialog::SetShortcutDialog(QDialog *parent) : QDialog(parent)
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
QLabel *infoTop = new QLabel(tr("Enter new shortcut to change "));
|
||||
QLabel* infoTop = new QLabel(tr("Enter new shortcut to change "));
|
||||
infoTop->setMargin(10);
|
||||
infoTop->setAlignment(Qt::AlignCenter);
|
||||
m_layout->addWidget(infoTop);
|
||||
|
||||
QLabel *infoIcon = new QLabel();
|
||||
QLabel* infoIcon = new QLabel();
|
||||
infoIcon->setAlignment(Qt::AlignCenter);
|
||||
infoIcon->setPixmap(QPixmap(":/img/app/keyboard.svg"));
|
||||
m_layout->addWidget(infoIcon);
|
||||
|
||||
m_layout->addWidget(infoIcon);
|
||||
|
||||
QLabel *infoBottom = new QLabel(tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
|
||||
QLabel* infoBottom = new QLabel(
|
||||
tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
|
||||
infoBottom->setMargin(10);
|
||||
infoBottom->setAlignment(Qt::AlignCenter);
|
||||
m_layout->addWidget(infoBottom);
|
||||
}
|
||||
|
||||
const QKeySequence& SetShortcutDialog::shortcut() {
|
||||
const QKeySequence& SetShortcutDialog::shortcut()
|
||||
{
|
||||
return m_ks;
|
||||
}
|
||||
|
||||
void SetShortcutDialog::keyPressEvent(QKeyEvent *ke) {
|
||||
void SetShortcutDialog::keyPressEvent(QKeyEvent* ke)
|
||||
{
|
||||
if (ke->modifiers() & Qt::ShiftModifier)
|
||||
m_modifier += "Shift+";
|
||||
if (ke->modifiers() & Qt::ControlModifier)
|
||||
@@ -51,7 +55,8 @@ void SetShortcutDialog::keyPressEvent(QKeyEvent *ke) {
|
||||
m_ks = QKeySequence(m_modifier + key);
|
||||
}
|
||||
|
||||
void SetShortcutDialog::keyReleaseEvent(QKeyEvent *event) {
|
||||
void SetShortcutDialog::keyReleaseEvent(QKeyEvent* event)
|
||||
{
|
||||
if (m_ks == QKeySequence(Qt::Key_Escape)) {
|
||||
reject();
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#ifndef SETSHORTCUTWIDGET_H
|
||||
#define SETSHORTCUTWIDGET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QKeySequence>
|
||||
#include <QObject>
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
|
||||
class SetShortcutDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SetShortcutDialog(QDialog *parent = nullptr);
|
||||
explicit SetShortcutDialog(QDialog* parent = nullptr);
|
||||
const QKeySequence& shortcut();
|
||||
|
||||
public:
|
||||
void keyPressEvent(QKeyEvent *);
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
void keyReleaseEvent(QKeyEvent* event);
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QVBoxLayout* m_layout;
|
||||
QString m_modifier;
|
||||
QKeySequence m_ks;
|
||||
};
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
#include "shortcutswidget.h"
|
||||
#include "setshortcutwidget.h"
|
||||
#include <QIcon>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QStringList>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVector>
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
#include <QCursor>
|
||||
#include <QGuiApplication>
|
||||
#include <QRect>
|
||||
#include <QScreen>
|
||||
#include <QGuiApplication>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
ShortcutsWidget::ShortcutsWidget(QWidget *parent) : QWidget(parent) {
|
||||
ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("Hot Keys"));
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
QRect position = frameGeometry();
|
||||
QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
QScreen* screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
position.moveCenter(screen->availableGeometry().center());
|
||||
move(position.topLeft());
|
||||
#endif
|
||||
@@ -39,11 +40,13 @@ ShortcutsWidget::ShortcutsWidget(QWidget *parent) : QWidget(parent) {
|
||||
show();
|
||||
}
|
||||
|
||||
const QVector<QStringList> &ShortcutsWidget::shortcuts() {
|
||||
const QVector<QStringList>& ShortcutsWidget::shortcuts()
|
||||
{
|
||||
return m_shortcuts;
|
||||
}
|
||||
|
||||
void ShortcutsWidget::initInfoTable() {
|
||||
void ShortcutsWidget::initInfoTable()
|
||||
{
|
||||
m_table = new QTableWidget(this);
|
||||
m_table->setToolTip(tr("Available shortcuts in the screen capture mode."));
|
||||
|
||||
@@ -59,17 +62,20 @@ void ShortcutsWidget::initInfoTable() {
|
||||
QStringList names;
|
||||
names << tr("Description") << tr("Key");
|
||||
m_table->setHorizontalHeaderLabels(names);
|
||||
connect(m_table, SIGNAL(cellClicked(int, int)), this, SLOT(slotShortcutCellClicked(int, int)));
|
||||
connect(m_table,
|
||||
SIGNAL(cellClicked(int, int)),
|
||||
this,
|
||||
SLOT(slotShortcutCellClicked(int, int)));
|
||||
|
||||
//add content
|
||||
for (int i= 0; i < shortcuts().size(); ++i){
|
||||
// add content
|
||||
for (int i = 0; i < shortcuts().size(); ++i) {
|
||||
m_table->setItem(i, 0, new QTableWidgetItem(m_shortcuts.at(i).at(1)));
|
||||
|
||||
QTableWidgetItem* item = new QTableWidgetItem(m_shortcuts.at(i).at(2));
|
||||
item->setTextAlignment( Qt::AlignCenter );
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
m_table->setItem(i, 1, item);
|
||||
|
||||
if( m_shortcuts.at(i).at(0).isEmpty() ) {
|
||||
if (m_shortcuts.at(i).at(0).isEmpty()) {
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
item->setFont(font);
|
||||
@@ -81,7 +87,7 @@ void ShortcutsWidget::initInfoTable() {
|
||||
// Read-only table items
|
||||
for (int x = 0; x < m_table->rowCount(); ++x) {
|
||||
for (int y = 0; y < m_table->columnCount(); ++y) {
|
||||
QTableWidgetItem *item = m_table->item(x, y);
|
||||
QTableWidgetItem* item = m_table->item(x, y);
|
||||
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
|
||||
}
|
||||
}
|
||||
@@ -97,14 +103,16 @@ void ShortcutsWidget::initInfoTable() {
|
||||
QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void ShortcutsWidget::slotShortcutCellClicked(int row, int col) {
|
||||
void ShortcutsWidget::slotShortcutCellClicked(int row, int col)
|
||||
{
|
||||
if (col == 1) {
|
||||
// Ignore non-changable shortcuts
|
||||
if( Qt::ItemIsEnabled != (Qt::ItemIsEnabled & m_table->item(row, col)->flags()) ) {
|
||||
if (Qt::ItemIsEnabled !=
|
||||
(Qt::ItemIsEnabled & m_table->item(row, col)->flags())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetShortcutDialog *setShortcutDialog = new SetShortcutDialog();
|
||||
SetShortcutDialog* setShortcutDialog = new SetShortcutDialog();
|
||||
if (0 != setShortcutDialog->exec()) {
|
||||
QString shortcutName = m_shortcuts.at(row).at(0);
|
||||
QKeySequence shortcutValue = setShortcutDialog->shortcut();
|
||||
@@ -115,8 +123,9 @@ void ShortcutsWidget::slotShortcutCellClicked(int row, int col) {
|
||||
}
|
||||
|
||||
if (m_config.setShortcut(shortcutName, shortcutValue.toString())) {
|
||||
QTableWidgetItem* item = new QTableWidgetItem(shortcutValue.toString());
|
||||
item->setTextAlignment( Qt::AlignCenter );
|
||||
QTableWidgetItem* item =
|
||||
new QTableWidgetItem(shortcutValue.toString());
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
|
||||
m_table->setItem(row, col, item);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
#define HOTKEYSCONFIG_H
|
||||
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QWidget>
|
||||
#include <QVector>
|
||||
#include <QStringList>
|
||||
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
class SetShortcutDialog;
|
||||
class QTableWidget;
|
||||
@@ -15,8 +14,8 @@ class ShortcutsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ShortcutsWidget(QWidget *parent = nullptr);
|
||||
const QVector<QStringList> &shortcuts();
|
||||
explicit ShortcutsWidget(QWidget* parent = nullptr);
|
||||
const QVector<QStringList>& shortcuts();
|
||||
|
||||
private:
|
||||
void initInfoTable();
|
||||
@@ -26,8 +25,8 @@ private slots:
|
||||
|
||||
private:
|
||||
ConfigHandler m_config;
|
||||
QTableWidget *m_table;
|
||||
QVBoxLayout *m_layout;
|
||||
QTableWidget* m_table;
|
||||
QVBoxLayout* m_layout;
|
||||
QVector<QStringList> m_shortcuts;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,53 +16,57 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "strftimechooserwidget.h"
|
||||
#include <QMap>
|
||||
#include <QGridLayout>
|
||||
#include <QMap>
|
||||
#include <QPushButton>
|
||||
|
||||
StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) {
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
QGridLayout* layout = new QGridLayout(this);
|
||||
auto k = m_buttonData.keys();
|
||||
int middle = k.length()/2;
|
||||
int middle = k.length() / 2;
|
||||
// add the buttons in 2 columns (they need to be even)
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < middle; j++) {
|
||||
QString key = k.last();
|
||||
k.pop_back();
|
||||
QString variable = m_buttonData.value(key);
|
||||
QPushButton *button = new QPushButton(this);
|
||||
QPushButton* button = new QPushButton(this);
|
||||
button->setText(tr(key.toStdString().data()));
|
||||
button->setToolTip(variable);
|
||||
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
button->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Expanding);
|
||||
button->setMinimumHeight(25);
|
||||
layout->addWidget(button, j, i);
|
||||
connect(button, &QPushButton::clicked,
|
||||
this, [variable, this](){emit variableEmitted(variable);});
|
||||
connect(button, &QPushButton::clicked, this, [variable, this]() {
|
||||
emit variableEmitted(variable);
|
||||
});
|
||||
}
|
||||
}
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
QMap<QString, QString> StrftimeChooserWidget::m_buttonData {
|
||||
{ QT_TR_NOOP("Century (00-99)"), "%C"},
|
||||
{ QT_TR_NOOP("Year (00-99)"), "%y"},
|
||||
{ QT_TR_NOOP("Year (2000)"), "%Y"},
|
||||
{ QT_TR_NOOP("Month Name (jan)"), "%b"},
|
||||
{ QT_TR_NOOP("Month Name (january)"), "%B"},
|
||||
{ QT_TR_NOOP("Month (01-12)"), "%m"},
|
||||
{ QT_TR_NOOP("Week Day (1-7)"), "%u"},
|
||||
{ QT_TR_NOOP("Week (01-53)"), "%V"},
|
||||
{ QT_TR_NOOP("Day Name (mon)"), "%a"},
|
||||
{ QT_TR_NOOP("Day Name (monday)"), "%A"},
|
||||
{ QT_TR_NOOP("Day (01-31)"), "%d"},
|
||||
{ QT_TR_NOOP("Day of Month (1-31)"), "%e"},
|
||||
{ QT_TR_NOOP("Day (001-366)"), "%j"},
|
||||
{ QT_TR_NOOP("Time (%H-%M-%S)"), "%T"},
|
||||
{ QT_TR_NOOP("Time (%H-%M)"), "%R"},
|
||||
{ QT_TR_NOOP("Hour (00-23)"), "%H"},
|
||||
{ QT_TR_NOOP("Hour (01-12)"), "%I"},
|
||||
{ QT_TR_NOOP("Minute (00-59)"), "%M"},
|
||||
{ QT_TR_NOOP("Second (00-59)"), "%S"},
|
||||
{ QT_TR_NOOP("Full Date (%m/%d/%y)"), "%D"},
|
||||
{ QT_TR_NOOP("Full Date (%Y-%m-%d)"), "%F"},
|
||||
QMap<QString, QString> StrftimeChooserWidget::m_buttonData{
|
||||
{ QT_TR_NOOP("Century (00-99)"), "%C" },
|
||||
{ QT_TR_NOOP("Year (00-99)"), "%y" },
|
||||
{ QT_TR_NOOP("Year (2000)"), "%Y" },
|
||||
{ QT_TR_NOOP("Month Name (jan)"), "%b" },
|
||||
{ QT_TR_NOOP("Month Name (january)"), "%B" },
|
||||
{ QT_TR_NOOP("Month (01-12)"), "%m" },
|
||||
{ QT_TR_NOOP("Week Day (1-7)"), "%u" },
|
||||
{ QT_TR_NOOP("Week (01-53)"), "%V" },
|
||||
{ QT_TR_NOOP("Day Name (mon)"), "%a" },
|
||||
{ QT_TR_NOOP("Day Name (monday)"), "%A" },
|
||||
{ QT_TR_NOOP("Day (01-31)"), "%d" },
|
||||
{ QT_TR_NOOP("Day of Month (1-31)"), "%e" },
|
||||
{ QT_TR_NOOP("Day (001-366)"), "%j" },
|
||||
{ QT_TR_NOOP("Time (%H-%M-%S)"), "%T" },
|
||||
{ QT_TR_NOOP("Time (%H-%M)"), "%R" },
|
||||
{ QT_TR_NOOP("Hour (00-23)"), "%H" },
|
||||
{ QT_TR_NOOP("Hour (01-12)"), "%I" },
|
||||
{ QT_TR_NOOP("Minute (00-59)"), "%M" },
|
||||
{ QT_TR_NOOP("Second (00-59)"), "%S" },
|
||||
{ QT_TR_NOOP("Full Date (%m/%d/%y)"), "%D" },
|
||||
{ QT_TR_NOOP("Full Date (%Y-%m-%d)"), "%F" },
|
||||
};
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class StrftimeChooserWidget : public QWidget {
|
||||
class StrftimeChooserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StrftimeChooserWidget(QWidget *parent = nullptr);
|
||||
explicit StrftimeChooserWidget(QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void variableEmitted(const QString &);
|
||||
void variableEmitted(const QString&);
|
||||
|
||||
private:
|
||||
static QMap<QString, QString> m_buttonData;
|
||||
|
||||
@@ -15,18 +15,20 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "uicoloreditor.h"
|
||||
#include "clickablelabel.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/globalvalues.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMap>
|
||||
#include <QSpacerItem>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
UIcolorEditor::UIcolorEditor(QWidget *parent) : QGroupBox(parent) {
|
||||
UIcolorEditor::UIcolorEditor(QWidget* parent)
|
||||
: QGroupBox(parent)
|
||||
{
|
||||
setTitle(tr("UI Color Editor"));
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_hLayout = new QHBoxLayout;
|
||||
@@ -46,7 +48,8 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QGroupBox(parent) {
|
||||
updateComponents();
|
||||
}
|
||||
|
||||
void UIcolorEditor::updateComponents() {
|
||||
void UIcolorEditor::updateComponents()
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_uiColor = config.uiMainColorValue();
|
||||
m_contrastColor = config.uiContrastColorValue();
|
||||
@@ -60,7 +63,8 @@ void UIcolorEditor::updateComponents() {
|
||||
}
|
||||
|
||||
// updateUIcolor updates the appearance of the buttons
|
||||
void UIcolorEditor::updateUIcolor() {
|
||||
void UIcolorEditor::updateUIcolor()
|
||||
{
|
||||
ConfigHandler config;
|
||||
if (m_lastButtonPressed == m_buttonMainColor) {
|
||||
config.setUIMainColor(m_uiColor);
|
||||
@@ -70,7 +74,8 @@ void UIcolorEditor::updateUIcolor() {
|
||||
}
|
||||
|
||||
// updateLocalColor updates the local button
|
||||
void UIcolorEditor::updateLocalColor(const QColor c) {
|
||||
void UIcolorEditor::updateLocalColor(const QColor c)
|
||||
{
|
||||
if (m_lastButtonPressed == m_buttonMainColor) {
|
||||
m_uiColor = c;
|
||||
} else {
|
||||
@@ -79,16 +84,21 @@ void UIcolorEditor::updateLocalColor(const QColor c) {
|
||||
m_lastButtonPressed->setColor(c);
|
||||
}
|
||||
|
||||
void UIcolorEditor::initColorWheel() {
|
||||
void UIcolorEditor::initColorWheel()
|
||||
{
|
||||
m_colorWheel = new color_widgets::ColorWheel(this);
|
||||
connect(m_colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this,
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::mouseReleaseOnColor,
|
||||
this,
|
||||
&UIcolorEditor::updateUIcolor);
|
||||
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::colorChanged,
|
||||
this,
|
||||
&UIcolorEditor::updateLocalColor);
|
||||
|
||||
const int size = GlobalValues::buttonBaseSize() * 3;
|
||||
m_colorWheel->setMinimumSize(size, size);
|
||||
m_colorWheel->setMaximumSize(size*2, size*2);
|
||||
m_colorWheel->setMaximumSize(size * 2, size * 2);
|
||||
m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_colorWheel->setToolTip(tr("Change the color moving the selectors and see"
|
||||
" the changes in the preview buttons."));
|
||||
@@ -96,18 +106,20 @@ void UIcolorEditor::initColorWheel() {
|
||||
m_hLayout->addWidget(m_colorWheel);
|
||||
}
|
||||
|
||||
void UIcolorEditor::initButtons() {
|
||||
void UIcolorEditor::initButtons()
|
||||
{
|
||||
const int extraSize = GlobalValues::buttonBaseSize() / 3;
|
||||
int frameSize = GlobalValues::buttonBaseSize() + extraSize;
|
||||
|
||||
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));
|
||||
|
||||
QGroupBox *frame = new QGroupBox();
|
||||
QGroupBox* frame = new QGroupBox();
|
||||
frame->setFixedSize(frameSize, frameSize);
|
||||
|
||||
m_buttonMainColor = new CaptureButton(m_buttonIconType, frame);
|
||||
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2);
|
||||
QHBoxLayout *h1 = new QHBoxLayout();
|
||||
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize / 2,
|
||||
m_buttonMainColor->y() + extraSize / 2);
|
||||
QHBoxLayout* h1 = new QHBoxLayout();
|
||||
h1->addWidget(frame);
|
||||
m_labelMain = new ClickableLabel(tr("Main Color"), this);
|
||||
h1->addWidget(m_labelMain);
|
||||
@@ -116,12 +128,12 @@ void UIcolorEditor::initButtons() {
|
||||
m_buttonMainColor->setToolTip(tr("Click on this button to set the edition"
|
||||
" mode of the main color."));
|
||||
|
||||
QGroupBox *frame2 = new QGroupBox();
|
||||
QGroupBox* frame2 = new QGroupBox();
|
||||
m_buttonContrast = new CaptureButton(m_buttonIconType, frame2);
|
||||
m_buttonContrast->move(m_buttonContrast->x() + extraSize/2,
|
||||
m_buttonContrast->y() + extraSize/2);
|
||||
m_buttonContrast->move(m_buttonContrast->x() + extraSize / 2,
|
||||
m_buttonContrast->y() + extraSize / 2);
|
||||
|
||||
QHBoxLayout *h2 = new QHBoxLayout();
|
||||
QHBoxLayout* h2 = new QHBoxLayout();
|
||||
h2->addWidget(frame2);
|
||||
frame2->setFixedSize(frameSize, frameSize);
|
||||
m_labelContrast = new ClickableLabel(tr("Contrast Color"), this);
|
||||
@@ -132,20 +144,27 @@ void UIcolorEditor::initButtons() {
|
||||
m_buttonContrast->setToolTip(tr("Click on this button to set the edition"
|
||||
" mode of the contrast color."));
|
||||
|
||||
connect(m_buttonMainColor, &CaptureButton::pressedButton,
|
||||
this, &UIcolorEditor::changeLastButton);
|
||||
connect(m_buttonContrast, &CaptureButton::pressedButton,
|
||||
this, &UIcolorEditor::changeLastButton);
|
||||
connect(m_buttonMainColor,
|
||||
&CaptureButton::pressedButton,
|
||||
this,
|
||||
&UIcolorEditor::changeLastButton);
|
||||
connect(m_buttonContrast,
|
||||
&CaptureButton::pressedButton,
|
||||
this,
|
||||
&UIcolorEditor::changeLastButton);
|
||||
// clicking the labels changes the button too
|
||||
connect(m_labelMain, &ClickableLabel::clicked,
|
||||
this, [this]{ changeLastButton(m_buttonMainColor); });
|
||||
connect(m_labelContrast, &ClickableLabel::clicked,
|
||||
this, [this]{ changeLastButton(m_buttonContrast); });
|
||||
connect(m_labelMain, &ClickableLabel::clicked, this, [this] {
|
||||
changeLastButton(m_buttonMainColor);
|
||||
});
|
||||
connect(m_labelContrast, &ClickableLabel::clicked, this, [this] {
|
||||
changeLastButton(m_buttonContrast);
|
||||
});
|
||||
m_lastButtonPressed = m_buttonMainColor;
|
||||
}
|
||||
|
||||
// visual update for the selected button
|
||||
void UIcolorEditor::changeLastButton(CaptureButton *b) {
|
||||
void UIcolorEditor::changeLastButton(CaptureButton* b)
|
||||
{
|
||||
if (m_lastButtonPressed != b) {
|
||||
m_lastButtonPressed = b;
|
||||
|
||||
|
||||
@@ -26,10 +26,11 @@ class QHBoxLayout;
|
||||
class CaptureButton;
|
||||
class ClickableLabel;
|
||||
|
||||
class UIcolorEditor : public QGroupBox {
|
||||
class UIcolorEditor : public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UIcolorEditor(QWidget *parent = nullptr);
|
||||
explicit UIcolorEditor(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void updateComponents();
|
||||
@@ -37,21 +38,22 @@ public slots:
|
||||
private slots:
|
||||
void updateUIcolor();
|
||||
void updateLocalColor(const QColor);
|
||||
void changeLastButton(CaptureButton *);
|
||||
void changeLastButton(CaptureButton*);
|
||||
|
||||
private:
|
||||
QColor m_uiColor, m_contrastColor;
|
||||
CaptureButton *m_buttonMainColor;
|
||||
ClickableLabel *m_labelMain;
|
||||
CaptureButton *m_buttonContrast;
|
||||
ClickableLabel *m_labelContrast;
|
||||
CaptureButton *m_lastButtonPressed;
|
||||
color_widgets::ColorWheel *m_colorWheel;
|
||||
CaptureButton* m_buttonMainColor;
|
||||
ClickableLabel* m_labelMain;
|
||||
CaptureButton* m_buttonContrast;
|
||||
ClickableLabel* m_labelContrast;
|
||||
CaptureButton* m_lastButtonPressed;
|
||||
color_widgets::ColorWheel* m_colorWheel;
|
||||
|
||||
static const CaptureButton::ButtonType m_buttonIconType = CaptureButton::TYPE_CIRCLE;
|
||||
static const CaptureButton::ButtonType m_buttonIconType =
|
||||
CaptureButton::TYPE_CIRCLE;
|
||||
|
||||
QHBoxLayout *m_hLayout;
|
||||
QVBoxLayout *m_vLayout;
|
||||
QHBoxLayout* m_hLayout;
|
||||
QVBoxLayout* m_vLayout;
|
||||
|
||||
void initColorWheel();
|
||||
void initButtons();
|
||||
|
||||
@@ -17,44 +17,50 @@
|
||||
|
||||
#include "visualseditor.h"
|
||||
#include "src/config/buttonlistview.h"
|
||||
#include "src/config/extendedslider.h"
|
||||
#include "src/config/uicoloreditor.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/config/extendedslider.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) {
|
||||
m_layout= new QVBoxLayout();
|
||||
VisualsEditor::VisualsEditor(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_layout = new QVBoxLayout();
|
||||
setLayout(m_layout);
|
||||
initWidgets();
|
||||
}
|
||||
|
||||
void VisualsEditor::updateComponents() {
|
||||
void VisualsEditor::updateComponents()
|
||||
{
|
||||
m_buttonList->updateComponents();
|
||||
m_colorEditor->updateComponents();
|
||||
int opacity = ConfigHandler().contrastOpacityValue();
|
||||
m_opacitySlider->setMapedValue(0, opacity, 255);
|
||||
}
|
||||
|
||||
void VisualsEditor::initOpacitySlider() {
|
||||
void VisualsEditor::initOpacitySlider()
|
||||
{
|
||||
m_opacitySlider = new ExtendedSlider();
|
||||
m_opacitySlider->setFocusPolicy(Qt::NoFocus);
|
||||
m_opacitySlider->setOrientation(Qt::Horizontal);
|
||||
m_opacitySlider->setRange(0, 100);
|
||||
connect(m_opacitySlider, &ExtendedSlider::modificationsEnded,
|
||||
this, &VisualsEditor::saveOpacity);
|
||||
QHBoxLayout *localLayout = new QHBoxLayout();
|
||||
connect(m_opacitySlider,
|
||||
&ExtendedSlider::modificationsEnded,
|
||||
this,
|
||||
&VisualsEditor::saveOpacity);
|
||||
QHBoxLayout* localLayout = new QHBoxLayout();
|
||||
localLayout->addWidget(new QLabel(QStringLiteral("0%")));
|
||||
localLayout->addWidget(m_opacitySlider);
|
||||
localLayout->addWidget(new QLabel(QStringLiteral("100%")));
|
||||
|
||||
QLabel *label = new QLabel();
|
||||
QLabel* label = new QLabel();
|
||||
QString labelMsg = tr("Opacity of area outside selection:") + " %1%";
|
||||
connect(m_opacitySlider, &ExtendedSlider::valueChanged,
|
||||
this, [labelMsg, label](int val){
|
||||
label->setText(labelMsg.arg(val));
|
||||
});
|
||||
connect(m_opacitySlider,
|
||||
&ExtendedSlider::valueChanged,
|
||||
this,
|
||||
[labelMsg, label](int val) { label->setText(labelMsg.arg(val)); });
|
||||
m_layout->addWidget(label);
|
||||
m_layout->addLayout(localLayout);
|
||||
|
||||
@@ -62,12 +68,14 @@ void VisualsEditor::initOpacitySlider() {
|
||||
m_opacitySlider->setMapedValue(0, opacity, 255);
|
||||
}
|
||||
|
||||
void VisualsEditor::saveOpacity() {
|
||||
void VisualsEditor::saveOpacity()
|
||||
{
|
||||
int value = m_opacitySlider->mappedValue(0, 255);
|
||||
ConfigHandler().setContrastOpacity(value);
|
||||
}
|
||||
|
||||
void VisualsEditor::initWidgets() {
|
||||
void VisualsEditor::initWidgets()
|
||||
{
|
||||
m_colorEditor = new UIcolorEditor();
|
||||
m_layout->addWidget(m_colorEditor);
|
||||
|
||||
@@ -81,7 +89,9 @@ void VisualsEditor::initWidgets() {
|
||||
listLayout->addWidget(m_buttonList);
|
||||
|
||||
QPushButton* setAllButtons = new QPushButton(tr("Select All"));
|
||||
connect(setAllButtons, &QPushButton::clicked,
|
||||
m_buttonList, &ButtonListView::selectAll);
|
||||
connect(setAllButtons,
|
||||
&QPushButton::clicked,
|
||||
m_buttonList,
|
||||
&ButtonListView::selectAll);
|
||||
listLayout->addWidget(setAllButtons);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,11 @@ class QVBoxLayout;
|
||||
class ButtonListView;
|
||||
class UIcolorEditor;
|
||||
|
||||
class VisualsEditor : public QWidget {
|
||||
class VisualsEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VisualsEditor(QWidget *parent = nullptr);
|
||||
explicit VisualsEditor(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void updateComponents();
|
||||
@@ -36,10 +37,10 @@ private slots:
|
||||
void saveOpacity();
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
ButtonListView *m_buttonList;
|
||||
UIcolorEditor *m_colorEditor;
|
||||
ExtendedSlider *m_opacitySlider;
|
||||
QVBoxLayout* m_layout;
|
||||
ButtonListView* m_buttonList;
|
||||
UIcolorEditor* m_colorEditor;
|
||||
ExtendedSlider* m_opacitySlider;
|
||||
|
||||
void initWidgets();
|
||||
void initOpacitySlider();
|
||||
|
||||
@@ -17,60 +17,72 @@
|
||||
|
||||
#include "capturerequest.h"
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include <QVector>
|
||||
#include <QDateTime>
|
||||
#include <QVector>
|
||||
|
||||
CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode,
|
||||
const uint delay, const QString &path,
|
||||
const QVariant &data,
|
||||
CaptureRequest::ExportTask tasks) :
|
||||
m_mode(mode), m_delay(delay), m_path(path), m_tasks(tasks),
|
||||
m_data(data), m_forcedID(false), m_id(0)
|
||||
const uint delay,
|
||||
const QString& path,
|
||||
const QVariant& data,
|
||||
CaptureRequest::ExportTask tasks)
|
||||
: m_mode(mode)
|
||||
, m_delay(delay)
|
||||
, m_path(path)
|
||||
, m_tasks(tasks)
|
||||
, m_data(data)
|
||||
, m_forcedID(false)
|
||||
, m_id(0)
|
||||
{}
|
||||
|
||||
void CaptureRequest::setStaticID(uint id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CaptureRequest::setStaticID(uint id) {
|
||||
m_forcedID = true;
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
uint CaptureRequest::id() const {
|
||||
uint CaptureRequest::id() const
|
||||
{
|
||||
if (m_forcedID) {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
uint id = 0;
|
||||
QVector<uint>v;
|
||||
QVector<uint> v;
|
||||
v << qHash(m_mode) << qHash(m_delay * QDateTime::currentMSecsSinceEpoch())
|
||||
<< qHash(m_path) << qHash(m_tasks) << m_data.toInt();
|
||||
for(uint i : v) {
|
||||
for (uint i : v) {
|
||||
id ^= i + 0x9e3779b9 + (id << 6) + (id >> 2);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
CaptureRequest::CaptureMode CaptureRequest::captureMode() const {
|
||||
CaptureRequest::CaptureMode CaptureRequest::captureMode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
uint CaptureRequest::delay() const {
|
||||
uint CaptureRequest::delay() const
|
||||
{
|
||||
return m_delay;
|
||||
}
|
||||
|
||||
QString CaptureRequest::path() const {
|
||||
QString CaptureRequest::path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
QVariant CaptureRequest::data() const {
|
||||
QVariant CaptureRequest::data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void CaptureRequest::addTask(CaptureRequest::ExportTask task) {
|
||||
void CaptureRequest::addTask(CaptureRequest::ExportTask task)
|
||||
{
|
||||
m_tasks |= task;
|
||||
}
|
||||
|
||||
void CaptureRequest::exportCapture(const QPixmap &p) {
|
||||
void CaptureRequest::exportCapture(const QPixmap& p)
|
||||
{
|
||||
if ((m_tasks & ExportTask::FILESYSTEM_SAVE_TASK) != ExportTask::NO_TASK) {
|
||||
if (m_path.isEmpty()) {
|
||||
ScreenshotSaver().saveToFilesystemGUI(p);
|
||||
@@ -82,5 +94,4 @@ void CaptureRequest::exportCapture(const QPixmap &p) {
|
||||
if ((m_tasks & ExportTask::CLIPBOARD_SAVE_TASK) != ExportTask::NO_TASK) {
|
||||
ScreenshotSaver().saveToClipboard(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,19 +17,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
class CaptureRequest {
|
||||
class CaptureRequest
|
||||
{
|
||||
public:
|
||||
enum CaptureMode {
|
||||
enum CaptureMode
|
||||
{
|
||||
FULLSCREEN_MODE,
|
||||
GRAPHICAL_MODE,
|
||||
SCREEN_MODE,
|
||||
};
|
||||
|
||||
enum ExportTask {
|
||||
enum ExportTask
|
||||
{
|
||||
NO_TASK = 0,
|
||||
CLIPBOARD_SAVE_TASK = 1,
|
||||
FILESYSTEM_SAVE_TASK = 2,
|
||||
@@ -37,8 +40,8 @@ public:
|
||||
|
||||
CaptureRequest(CaptureMode mode,
|
||||
const uint delay = 0,
|
||||
const QString &path = QLatin1String(""),
|
||||
const QVariant &data = QVariant(),
|
||||
const QString& path = QLatin1String(""),
|
||||
const QVariant& data = QVariant(),
|
||||
ExportTask tasks = NO_TASK);
|
||||
|
||||
void setStaticID(uint id);
|
||||
@@ -50,7 +53,7 @@ public:
|
||||
CaptureMode captureMode() const;
|
||||
|
||||
void addTask(ExportTask task);
|
||||
void exportCapture(const QPixmap &p);
|
||||
void exportCapture(const QPixmap& p);
|
||||
|
||||
private:
|
||||
CaptureMode m_mode;
|
||||
@@ -65,16 +68,18 @@ private:
|
||||
|
||||
using eTask = CaptureRequest::ExportTask;
|
||||
|
||||
inline eTask operator|(const eTask &a, const eTask &b) {
|
||||
inline eTask operator|(const eTask& a, const eTask& b)
|
||||
{
|
||||
return static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline eTask operator&(const eTask &a, const eTask &b) {
|
||||
inline eTask operator&(const eTask& a, const eTask& b)
|
||||
{
|
||||
return static_cast<eTask>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline eTask& operator|=(eTask &a, const eTask &b) {
|
||||
inline eTask& operator|=(eTask& a, const eTask& b)
|
||||
{
|
||||
a = static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,25 +16,25 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "controller.h"
|
||||
#include "src/widgets/capture/capturewidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/widgets/infowindow.h"
|
||||
#include "src/config/configwindow.h"
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include "src/widgets/capturelauncher.h"
|
||||
#include "src/widgets/notificationwidget.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/configenterprise.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include "src/widgets/capture/capturewidget.h"
|
||||
#include "src/widgets/capturelauncher.h"
|
||||
#include "src/widgets/historywidget.h"
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QSystemTrayIcon>
|
||||
#include "src/widgets/infowindow.h"
|
||||
#include "src/widgets/notificationwidget.h"
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFile>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "src/core/globalshortcutfilter.h"
|
||||
@@ -43,7 +43,9 @@
|
||||
// Controller is the core component of Flameshot, creates the trayIcon and
|
||||
// launches the capture widget
|
||||
|
||||
Controller::Controller() : m_captureWindow(nullptr) {
|
||||
Controller::Controller()
|
||||
: m_captureWindow(nullptr)
|
||||
{
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// set default shortcusts if not set yet
|
||||
@@ -57,10 +59,9 @@ Controller::Controller() : m_captureWindow(nullptr) {
|
||||
#elif defined(Q_OS_WIN)
|
||||
enableTrayIcon();
|
||||
|
||||
GlobalShortcutFilter *nativeFilter = new GlobalShortcutFilter(this);
|
||||
GlobalShortcutFilter* nativeFilter = new GlobalShortcutFilter(this);
|
||||
qApp->installNativeEventFilter(nativeFilter);
|
||||
connect(nativeFilter, &GlobalShortcutFilter::printPressed,
|
||||
this, [this](){
|
||||
connect(nativeFilter, &GlobalShortcutFilter::printPressed, this, [this]() {
|
||||
this->requestCapture(CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
|
||||
});
|
||||
#endif
|
||||
@@ -69,50 +70,57 @@ Controller::Controller() : m_captureWindow(nullptr) {
|
||||
qApp->setStyleSheet(StyleSheet);
|
||||
}
|
||||
|
||||
Controller *Controller::getInstance() {
|
||||
Controller* Controller::getInstance()
|
||||
{
|
||||
static Controller c;
|
||||
return &c;
|
||||
}
|
||||
|
||||
void Controller::enableExports() {
|
||||
connect(this, &Controller::captureTaken,
|
||||
this, &Controller::handleCaptureTaken);
|
||||
connect(this, &Controller::captureFailed,
|
||||
this, &Controller::handleCaptureFailed);
|
||||
void Controller::enableExports()
|
||||
{
|
||||
connect(
|
||||
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
|
||||
connect(
|
||||
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
|
||||
}
|
||||
|
||||
void Controller::requestCapture(const CaptureRequest &request) {
|
||||
void Controller::requestCapture(const CaptureRequest& request)
|
||||
{
|
||||
uint id = request.id();
|
||||
m_requestMap.insert(id, request);
|
||||
|
||||
switch (request.captureMode()) {
|
||||
case CaptureRequest::FULLSCREEN_MODE:
|
||||
doLater(request.delay(), this, [this, id](){
|
||||
doLater(request.delay(), this, [this, id]() {
|
||||
this->startFullscreenCapture(id);
|
||||
});
|
||||
break;
|
||||
case CaptureRequest::SCREEN_MODE: {
|
||||
int &&number = request.data().toInt();
|
||||
doLater(request.delay(), this, [this, id, number](){
|
||||
int&& number = request.data().toInt();
|
||||
doLater(request.delay(), this, [this, id, number]() {
|
||||
this->startScreenGrab(id, number);
|
||||
});
|
||||
break;
|
||||
} case CaptureRequest::GRAPHICAL_MODE: {
|
||||
QString &&path = request.path();
|
||||
doLater(request.delay(), this, [this, id, path](){
|
||||
}
|
||||
case CaptureRequest::GRAPHICAL_MODE: {
|
||||
QString&& path = request.path();
|
||||
doLater(request.delay(), this, [this, id, path]() {
|
||||
this->startVisualCapture(id, path);
|
||||
});
|
||||
break;
|
||||
} default:
|
||||
}
|
||||
default:
|
||||
emit captureFailed(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// creation of a new capture in GUI mode
|
||||
void Controller::startVisualCapture(const uint id, const QString &forcedSavePath) {
|
||||
void Controller::startVisualCapture(const uint id,
|
||||
const QString& forcedSavePath)
|
||||
{
|
||||
if (!m_captureWindow) {
|
||||
QWidget *modalWidget = nullptr;
|
||||
QWidget* modalWidget = nullptr;
|
||||
do {
|
||||
modalWidget = qApp->activeModalWidget();
|
||||
if (modalWidget) {
|
||||
@@ -122,24 +130,30 @@ void Controller::startVisualCapture(const uint id, const QString &forcedSavePath
|
||||
} while (modalWidget);
|
||||
|
||||
m_captureWindow = new CaptureWidget(id, forcedSavePath);
|
||||
//m_captureWindow = new CaptureWidget(id, forcedSavePath, false); // debug
|
||||
connect(m_captureWindow, &CaptureWidget::captureFailed,
|
||||
this, &Controller::captureFailed);
|
||||
connect(m_captureWindow, &CaptureWidget::captureTaken,
|
||||
this, &Controller::captureTaken);
|
||||
// m_captureWindow = new CaptureWidget(id, forcedSavePath, false); //
|
||||
// debug
|
||||
connect(m_captureWindow,
|
||||
&CaptureWidget::captureFailed,
|
||||
this,
|
||||
&Controller::captureFailed);
|
||||
connect(m_captureWindow,
|
||||
&CaptureWidget::captureTaken,
|
||||
this,
|
||||
&Controller::captureTaken);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
m_captureWindow->show();
|
||||
#else
|
||||
m_captureWindow->showFullScreen();
|
||||
//m_captureWindow->show(); // Debug
|
||||
// m_captureWindow->show(); // Debug
|
||||
#endif
|
||||
} else {
|
||||
emit captureFailed(id);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::startScreenGrab(const uint id, const int screenNumber) {
|
||||
void Controller::startScreenGrab(const uint id, const int screenNumber)
|
||||
{
|
||||
bool ok = true;
|
||||
int n = screenNumber;
|
||||
|
||||
@@ -156,7 +170,8 @@ void Controller::startScreenGrab(const uint id, const int screenNumber) {
|
||||
}
|
||||
|
||||
// creation of the configuration window
|
||||
void Controller::openConfigWindow() {
|
||||
void Controller::openConfigWindow()
|
||||
{
|
||||
if (!m_configWindow) {
|
||||
m_configWindow = new ConfigWindow();
|
||||
m_configWindow->show();
|
||||
@@ -164,46 +179,50 @@ void Controller::openConfigWindow() {
|
||||
}
|
||||
|
||||
// creation of the window of information
|
||||
void Controller::openInfoWindow() {
|
||||
void Controller::openInfoWindow()
|
||||
{
|
||||
if (!m_infoWindow) {
|
||||
m_infoWindow = new InfoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::openLauncherWindow() {
|
||||
CaptureLauncher *w = new CaptureLauncher();
|
||||
void Controller::openLauncherWindow()
|
||||
{
|
||||
CaptureLauncher* w = new CaptureLauncher();
|
||||
w->show();
|
||||
}
|
||||
|
||||
void Controller::enableTrayIcon() {
|
||||
void Controller::enableTrayIcon()
|
||||
{
|
||||
if (m_trayIcon) {
|
||||
return;
|
||||
}
|
||||
QMenu *trayIconMenu = new QMenu();
|
||||
QMenu* trayIconMenu = new QMenu();
|
||||
|
||||
ConfigHandler().setDisabledTrayIcon(false);
|
||||
QAction *captureAction = new QAction(tr("&Take Screenshot"), this);
|
||||
connect(captureAction, &QAction::triggered, this, [this](){
|
||||
QAction* captureAction = new QAction(tr("&Take Screenshot"), this);
|
||||
connect(captureAction, &QAction::triggered, this, [this]() {
|
||||
// Wait 400 ms to hide the QMenu
|
||||
doLater(400, this, [this](){ this->startVisualCapture(); });
|
||||
doLater(400, this, [this]() { this->startVisualCapture(); });
|
||||
});
|
||||
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
|
||||
connect(launcherAction, &QAction::triggered, this,
|
||||
QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
|
||||
connect(launcherAction,
|
||||
&QAction::triggered,
|
||||
this,
|
||||
&Controller::openLauncherWindow);
|
||||
|
||||
QAction *configAction = new QAction(tr("&Configuration"), this);
|
||||
connect(configAction, &QAction::triggered, this,
|
||||
&Controller::openConfigWindow);
|
||||
QAction *infoAction = new QAction(tr("&Information"), this);
|
||||
connect(infoAction, &QAction::triggered, this,
|
||||
&Controller::openInfoWindow);
|
||||
QAction *quitAction = new QAction(tr("&Quit"), this);
|
||||
connect(quitAction, &QAction::triggered, qApp,
|
||||
&QCoreApplication::quit);
|
||||
QAction* configAction = new QAction(tr("&Configuration"), this);
|
||||
connect(
|
||||
configAction, &QAction::triggered, this, &Controller::openConfigWindow);
|
||||
QAction* infoAction = new QAction(tr("&Information"), this);
|
||||
connect(infoAction, &QAction::triggered, this, &Controller::openInfoWindow);
|
||||
QAction* quitAction = new QAction(tr("&Quit"), this);
|
||||
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
|
||||
// recent screenshots
|
||||
QAction *recentAction = new QAction(tr("&Latest Uploads"), this);
|
||||
connect(recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
|
||||
QAction* recentAction = new QAction(tr("&Latest Uploads"), this);
|
||||
connect(
|
||||
recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
|
||||
|
||||
// generate menu
|
||||
trayIconMenu->addAction(captureAction);
|
||||
@@ -219,10 +238,11 @@ void Controller::enableTrayIcon() {
|
||||
m_trayIcon = new QSystemTrayIcon();
|
||||
m_trayIcon->setToolTip(QStringLiteral("Flameshot"));
|
||||
m_trayIcon->setContextMenu(trayIconMenu);
|
||||
QIcon trayicon = QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
|
||||
QIcon trayicon =
|
||||
QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
|
||||
m_trayIcon->setIcon(trayicon);
|
||||
|
||||
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r){
|
||||
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
|
||||
if (r == QSystemTrayIcon::Trigger) {
|
||||
startVisualCapture();
|
||||
}
|
||||
@@ -230,14 +250,18 @@ void Controller::enableTrayIcon() {
|
||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
|
||||
m_trayIcon->show();
|
||||
if (ConfigHandler().showStartupLaunchMessage()) {
|
||||
m_trayIcon->showMessage("Flameshot",
|
||||
QObject::tr("Hello, I'm here! Click icon in the tray to take a screenshot or click with a right button to see more options."),
|
||||
m_trayIcon->showMessage(
|
||||
"Flameshot",
|
||||
QObject::tr(
|
||||
"Hello, I'm here! Click icon in the tray to take a screenshot or "
|
||||
"click with a right button to see more options."),
|
||||
QSystemTrayIcon::Information,
|
||||
3000);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::disableTrayIcon() {
|
||||
void Controller::disableTrayIcon()
|
||||
{
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->deleteLater();
|
||||
@@ -246,28 +270,31 @@ void Controller::disableTrayIcon() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Controller::sendTrayNotification(
|
||||
const QString &text,
|
||||
const QString &title,
|
||||
void Controller::sendTrayNotification(const QString& text,
|
||||
const QString& title,
|
||||
const int timeout)
|
||||
{
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->showMessage(title, text, QSystemTrayIcon::Information, timeout);
|
||||
m_trayIcon->showMessage(
|
||||
title, text, QSystemTrayIcon::Information, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::updateConfigComponents() {
|
||||
void Controller::updateConfigComponents()
|
||||
{
|
||||
if (m_configWindow) {
|
||||
m_configWindow->updateChildren();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::showRecentScreenshots() {
|
||||
HistoryWidget *pHistory = new HistoryWidget();
|
||||
void Controller::showRecentScreenshots()
|
||||
{
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->exec();
|
||||
}
|
||||
|
||||
void Controller::startFullscreenCapture(const uint id) {
|
||||
void Controller::startFullscreenCapture(const uint id)
|
||||
{
|
||||
bool ok = true;
|
||||
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
|
||||
if (ok) {
|
||||
@@ -277,7 +304,8 @@ void Controller::startFullscreenCapture(const uint id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p) {
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p)
|
||||
{
|
||||
auto it = m_requestMap.find(id);
|
||||
if (it != m_requestMap.end()) {
|
||||
it.value().exportCapture(p);
|
||||
@@ -288,7 +316,8 @@ void Controller::handleCaptureTaken(uint id, QPixmap p) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleCaptureFailed(uint id) {
|
||||
void Controller::handleCaptureFailed(uint id)
|
||||
{
|
||||
m_requestMap.remove(id);
|
||||
|
||||
if (ConfigHandler().closeAfterScreenshotValue()) {
|
||||
@@ -296,10 +325,13 @@ void Controller::handleCaptureFailed(uint id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::doLater(int msec, QObject *receiver, lambda func) {
|
||||
QTimer *timer = new QTimer(receiver);
|
||||
QObject::connect(timer, &QTimer::timeout, receiver,
|
||||
[timer, func](){ func(); timer->deleteLater(); });
|
||||
void Controller::doLater(int msec, QObject* receiver, lambda func)
|
||||
{
|
||||
QTimer* timer = new QTimer(receiver);
|
||||
QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() {
|
||||
func();
|
||||
timer->deleteLater();
|
||||
});
|
||||
timer->setInterval(msec);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/core/capturerequest.h"
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
#include <functional>
|
||||
|
||||
@@ -32,14 +32,15 @@ class QSystemTrayIcon;
|
||||
|
||||
using lambda = std::function<void(void)>;
|
||||
|
||||
class Controller : public QObject {
|
||||
class Controller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Controller* getInstance();
|
||||
|
||||
Controller(const Controller&) = delete;
|
||||
void operator =(const Controller&) = delete;
|
||||
void operator=(const Controller&) = delete;
|
||||
|
||||
void enableExports();
|
||||
|
||||
@@ -48,15 +49,16 @@ signals:
|
||||
void captureFailed(uint id);
|
||||
|
||||
public slots:
|
||||
void requestCapture(const CaptureRequest &request);
|
||||
void requestCapture(const CaptureRequest& request);
|
||||
|
||||
void openConfigWindow();
|
||||
void openInfoWindow();
|
||||
void openLauncherWindow();
|
||||
void enableTrayIcon();
|
||||
void disableTrayIcon();
|
||||
void sendTrayNotification(const QString &text,
|
||||
const QString &title = QStringLiteral("Flameshot Info"),
|
||||
void sendTrayNotification(
|
||||
const QString& text,
|
||||
const QString& title = QStringLiteral("Flameshot Info"),
|
||||
const int timeout = 5000);
|
||||
|
||||
void updateConfigComponents();
|
||||
@@ -66,7 +68,7 @@ public slots:
|
||||
private slots:
|
||||
void startFullscreenCapture(const uint id = 0);
|
||||
void startVisualCapture(const uint id = 0,
|
||||
const QString &forcedSavePath = QString());
|
||||
const QString& forcedSavePath = QString());
|
||||
void startScreenGrab(const uint id = 0, const int screenNumber = -1);
|
||||
|
||||
void handleCaptureTaken(uint id, QPixmap p);
|
||||
@@ -77,7 +79,7 @@ private:
|
||||
|
||||
// replace QTimer::singleShot introduced in Qt 5.4
|
||||
// the actual target Qt version is 5.3
|
||||
void doLater(int msec, QObject *receiver, lambda func);
|
||||
void doLater(int msec, QObject* receiver, lambda func);
|
||||
|
||||
QMap<uint, CaptureRequest> m_requestMap;
|
||||
QPointer<CaptureWidget> m_captureWindow;
|
||||
|
||||
@@ -16,37 +16,42 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "flameshotdbusadapter.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QBuffer>
|
||||
FlameshotDBusAdapter::FlameshotDBusAdapter(QObject *parent)
|
||||
FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
auto controller = Controller::getInstance();
|
||||
connect(controller, &Controller::captureFailed,
|
||||
this, &FlameshotDBusAdapter::captureFailed);
|
||||
connect(controller, &Controller::captureTaken,
|
||||
this, &FlameshotDBusAdapter::handleCaptureTaken);
|
||||
connect(controller,
|
||||
&Controller::captureFailed,
|
||||
this,
|
||||
&FlameshotDBusAdapter::captureFailed);
|
||||
connect(controller,
|
||||
&Controller::captureTaken,
|
||||
this,
|
||||
&FlameshotDBusAdapter::handleCaptureTaken);
|
||||
}
|
||||
|
||||
FlameshotDBusAdapter::~FlameshotDBusAdapter() {
|
||||
FlameshotDBusAdapter::~FlameshotDBusAdapter() {}
|
||||
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id) {
|
||||
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path);
|
||||
// if (toClipboard) {
|
||||
// req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
|
||||
// }
|
||||
// if (toClipboard) {
|
||||
// req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
|
||||
// }
|
||||
req.setStaticID(id);
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::fullScreen(
|
||||
QString path, bool toClipboard, int delay, uint id)
|
||||
void FlameshotDBusAdapter::fullScreen(QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::FULLSCREEN_MODE, delay, path);
|
||||
if (toClipboard) {
|
||||
@@ -59,12 +64,16 @@ void FlameshotDBusAdapter::fullScreen(
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::openLauncher() {
|
||||
void FlameshotDBusAdapter::openLauncher()
|
||||
{
|
||||
Controller::getInstance()->openLauncherWindow();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::captureScreen(int number, QString path,
|
||||
bool toClipboard, int delay, uint id)
|
||||
void FlameshotDBusAdapter::captureScreen(int number,
|
||||
QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, path, number);
|
||||
if (toClipboard) {
|
||||
@@ -77,11 +86,13 @@ void FlameshotDBusAdapter::captureScreen(int number, QString path,
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::openConfig() {
|
||||
void FlameshotDBusAdapter::openConfig()
|
||||
{
|
||||
Controller::getInstance()->openConfigWindow();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
|
||||
void FlameshotDBusAdapter::trayIconEnabled(bool enabled)
|
||||
{
|
||||
auto controller = Controller::getInstance();
|
||||
if (enabled) {
|
||||
controller->enableTrayIcon();
|
||||
@@ -90,14 +101,16 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::autostartEnabled(bool enabled) {
|
||||
void FlameshotDBusAdapter::autostartEnabled(bool enabled)
|
||||
{
|
||||
ConfigHandler().setStartupLaunch(enabled);
|
||||
auto controller = Controller::getInstance();
|
||||
// Autostart is not saved in a .ini file, requires manual update
|
||||
controller->updateConfigComponents();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap &p) {
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap& p)
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
p.save(&buffer, "PNG");
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtDBus/QDBusAbstractAdaptor>
|
||||
#include "src/core/controller.h"
|
||||
#include <QtDBus/QDBusAbstractAdaptor>
|
||||
|
||||
class FlameshotDBusAdapter : public QDBusAbstractAdaptor {
|
||||
class FlameshotDBusAdapter : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot")
|
||||
|
||||
public:
|
||||
explicit FlameshotDBusAdapter(QObject *parent = nullptr);
|
||||
explicit FlameshotDBusAdapter(QObject* parent = nullptr);
|
||||
virtual ~FlameshotDBusAdapter();
|
||||
|
||||
signals:
|
||||
@@ -34,13 +35,20 @@ signals:
|
||||
|
||||
public slots:
|
||||
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 captureScreen(int number, 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,
|
||||
QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id);
|
||||
Q_NOREPLY void openLauncher();
|
||||
Q_NOREPLY void openConfig();
|
||||
Q_NOREPLY void trayIconEnabled(bool enabled);
|
||||
Q_NOREPLY void autostartEnabled(bool enabled);
|
||||
|
||||
private slots:
|
||||
void handleCaptureTaken(uint id, const QPixmap &p);
|
||||
void handleCaptureTaken(uint id, const QPixmap& p);
|
||||
};
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "src/widgets/historywidget.h"
|
||||
#include <qt_windows.h>
|
||||
|
||||
GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) :
|
||||
QObject(parent)
|
||||
GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// Forced Print Screen
|
||||
if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) {
|
||||
@@ -33,10 +33,9 @@ GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) :
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalShortcutFilter::nativeEventFilter(
|
||||
const QByteArray &eventType,
|
||||
void *message,
|
||||
long *result)
|
||||
bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
long* result)
|
||||
{
|
||||
Q_UNUSED(eventType);
|
||||
Q_UNUSED(result);
|
||||
@@ -49,13 +48,13 @@ bool GlobalShortcutFilter::nativeEventFilter(
|
||||
const quint32 modifiers = LOWORD(msg->lParam);
|
||||
|
||||
// Show screenshots history
|
||||
if(VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
|
||||
HistoryWidget *pHistory = new HistoryWidget();
|
||||
if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->show();
|
||||
}
|
||||
|
||||
// Capture screen
|
||||
if(VK_SNAPSHOT == keycode && 0 == modifiers) {
|
||||
if (VK_SNAPSHOT == keycode && 0 == modifiers) {
|
||||
Controller::getInstance()->requestCapture(
|
||||
CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
|
||||
}
|
||||
|
||||
@@ -17,15 +17,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QObject>
|
||||
|
||||
class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter {
|
||||
class GlobalShortcutFilter
|
||||
: public QObject
|
||||
, public QAbstractNativeEventFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GlobalShortcutFilter(QObject *parent = nullptr);
|
||||
explicit GlobalShortcutFilter(QObject* parent = nullptr);
|
||||
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
|
||||
bool nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
long* result);
|
||||
|
||||
signals:
|
||||
void printPressed();
|
||||
|
||||
232
src/main.cpp
232
src/main.cpp
@@ -15,32 +15,33 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "src/core/controller.h"
|
||||
#include "singleapplication.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/cli/commandlineparser.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/pathinfo.h"
|
||||
#include "src/core/capturerequest.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/pathinfo.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QLibraryInfo>
|
||||
#include <QTranslator>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QTranslator>
|
||||
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
#include "src/core/flameshotdbusadapter.h"
|
||||
#include "src/utils/dbusutils.h"
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// required for the button serialization
|
||||
// TODO: change to QVector in v1.0
|
||||
qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
|
||||
qRegisterMetaTypeStreamOperators<QList<int>>("QList<int>");
|
||||
qApp->setApplicationVersion(static_cast<QString>(APP_VERSION));
|
||||
|
||||
// no arguments, just launch Flameshot
|
||||
@@ -50,16 +51,20 @@ int main(int argc, char *argv[]) {
|
||||
QTranslator translator, qtTranslator;
|
||||
QStringList trPaths = PathInfo::translationsPaths();
|
||||
|
||||
for (const QString &path: trPaths) {
|
||||
for (const QString& path : trPaths) {
|
||||
bool match = translator.load(QLocale(),
|
||||
QStringLiteral("Internationalization"), QStringLiteral("_"),
|
||||
QStringLiteral("Internationalization"),
|
||||
QStringLiteral("_"),
|
||||
path);
|
||||
if (match) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qtTranslator.load(QLocale::system(), "qt", "_",
|
||||
qtTranslator.load(
|
||||
QLocale::system(),
|
||||
"qt",
|
||||
"_",
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
|
||||
app.installTranslator(&translator);
|
||||
@@ -99,58 +104,61 @@ int main(int argc, char *argv[]) {
|
||||
QStringLiteral("Powerful yet simple to use screenshot software."));
|
||||
parser.setGeneralErrorMessage(QStringLiteral("See 'flameshot --help'."));
|
||||
// Arguments
|
||||
CommandArgument fullArgument(QStringLiteral("full"), QStringLiteral("Capture the entire desktop."));
|
||||
CommandArgument launcherArgument(QStringLiteral("launcher"), QStringLiteral("Open the capture launcher."));
|
||||
CommandArgument guiArgument(QStringLiteral("gui"), QStringLiteral("Start a manual capture in GUI mode."));
|
||||
CommandArgument configArgument(QStringLiteral("config"), QStringLiteral("Configure flameshot."));
|
||||
CommandArgument screenArgument(QStringLiteral("screen"), QStringLiteral("Capture a single screen."));
|
||||
CommandArgument fullArgument(QStringLiteral("full"),
|
||||
QStringLiteral("Capture the entire desktop."));
|
||||
CommandArgument launcherArgument(
|
||||
QStringLiteral("launcher"), QStringLiteral("Open the capture launcher."));
|
||||
CommandArgument guiArgument(
|
||||
QStringLiteral("gui"),
|
||||
QStringLiteral("Start a manual capture in GUI mode."));
|
||||
CommandArgument configArgument(QStringLiteral("config"),
|
||||
QStringLiteral("Configure flameshot."));
|
||||
CommandArgument screenArgument(QStringLiteral("screen"),
|
||||
QStringLiteral("Capture a single screen."));
|
||||
|
||||
// Options
|
||||
CommandOption pathOption(
|
||||
{"p", "path"},
|
||||
{ "p", "path" },
|
||||
QStringLiteral("Path where the capture will be saved"),
|
||||
QStringLiteral("path"));
|
||||
CommandOption clipboardOption(
|
||||
{"c", "clipboard"},
|
||||
{ "c", "clipboard" },
|
||||
QStringLiteral("Save the capture to the clipboard"));
|
||||
CommandOption delayOption(
|
||||
{"d", "delay"},
|
||||
CommandOption delayOption({ "d", "delay" },
|
||||
QStringLiteral("Delay time in milliseconds"),
|
||||
QStringLiteral("milliseconds"));
|
||||
CommandOption filenameOption(
|
||||
{"f", "filename"},
|
||||
CommandOption filenameOption({ "f", "filename" },
|
||||
QStringLiteral("Set the filename pattern"),
|
||||
QStringLiteral("pattern"));
|
||||
CommandOption trayOption(
|
||||
{"t", "trayicon"},
|
||||
CommandOption trayOption({ "t", "trayicon" },
|
||||
QStringLiteral("Enable or disable the trayicon"),
|
||||
QStringLiteral("bool"));
|
||||
CommandOption autostartOption(
|
||||
{"a", "autostart"},
|
||||
{ "a", "autostart" },
|
||||
QStringLiteral("Enable or disable run at startup"),
|
||||
QStringLiteral("bool"));
|
||||
CommandOption showHelpOption(
|
||||
{"s", "showhelp"},
|
||||
{ "s", "showhelp" },
|
||||
QStringLiteral("Show the help message in the capture mode"),
|
||||
QStringLiteral("bool"));
|
||||
CommandOption mainColorOption(
|
||||
{"m", "maincolor"},
|
||||
CommandOption mainColorOption({ "m", "maincolor" },
|
||||
QStringLiteral("Define the main UI color"),
|
||||
QStringLiteral("color-code"));
|
||||
CommandOption contrastColorOption(
|
||||
{"k", "contrastcolor"},
|
||||
{ "k", "contrastcolor" },
|
||||
QStringLiteral("Define the contrast UI color"),
|
||||
QStringLiteral("color-code"));
|
||||
CommandOption rawImageOption(
|
||||
{"r", "raw"},
|
||||
CommandOption rawImageOption({ "r", "raw" },
|
||||
QStringLiteral("Print raw PNG capture"));
|
||||
CommandOption screenNumberOption(
|
||||
{"n", "number"},
|
||||
QStringLiteral("Define the screen to capture,\ndefault: screen containing the cursor"),
|
||||
QStringLiteral("Screen number"), QStringLiteral("-1"));
|
||||
{ "n", "number" },
|
||||
QStringLiteral(
|
||||
"Define the screen to capture,\ndefault: screen containing the cursor"),
|
||||
QStringLiteral("Screen number"),
|
||||
QStringLiteral("-1"));
|
||||
|
||||
// Add checkers
|
||||
auto colorChecker = [](const QString &colorCode) -> bool {
|
||||
auto colorChecker = [](const QString& colorCode) -> bool {
|
||||
QColor parsedColor(colorCode);
|
||||
return parsedColor.isValid() && parsedColor.alphaF() == 1.0;
|
||||
};
|
||||
@@ -162,25 +170,31 @@ int main(int argc, char *argv[]) {
|
||||
"- Named colors like 'blue' or 'red'\n"
|
||||
"You may need to escape the '#' sign as in '\\#FFF'";
|
||||
|
||||
const QString delayErr = QStringLiteral("Invalid delay, it must be higher than 0");
|
||||
const QString numberErr = QStringLiteral("Invalid screen number, it must be non negative");
|
||||
auto numericChecker = [](const QString &delayValue) -> bool {
|
||||
const QString delayErr =
|
||||
QStringLiteral("Invalid delay, it must be higher than 0");
|
||||
const QString numberErr =
|
||||
QStringLiteral("Invalid screen number, it must be non negative");
|
||||
auto numericChecker = [](const QString& delayValue) -> bool {
|
||||
int value = delayValue.toInt();
|
||||
return value >= 0;
|
||||
};
|
||||
|
||||
const QString pathErr = QStringLiteral("Invalid path, it must be a real path in the system");
|
||||
auto pathChecker = [pathErr](const QString &pathValue) -> bool {
|
||||
const QString pathErr =
|
||||
QStringLiteral("Invalid path, it must be a real path in the system");
|
||||
auto pathChecker = [pathErr](const QString& pathValue) -> bool {
|
||||
bool res = QDir(pathValue).exists();
|
||||
if (!res) {
|
||||
SystemNotification().sendMessage(QObject::tr(pathErr.toLatin1().data()));
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr(pathErr.toLatin1().data()));
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
const QString booleanErr = QStringLiteral("Invalid value, it must be defined as 'true' or 'false'");
|
||||
auto booleanChecker = [](const QString &value) -> bool {
|
||||
return value == QLatin1String("true") || value == QLatin1String("false");
|
||||
const QString booleanErr =
|
||||
QStringLiteral("Invalid value, it must be defined as 'true' or 'false'");
|
||||
auto booleanChecker = [](const QString& value) -> bool {
|
||||
return value == QLatin1String("true") ||
|
||||
value == QLatin1String("false");
|
||||
};
|
||||
|
||||
contrastColorOption.addChecker(colorChecker, colorErr);
|
||||
@@ -201,13 +215,21 @@ int main(int argc, char *argv[]) {
|
||||
auto helpOption = parser.addHelpOption();
|
||||
auto versionOption = parser.addVersionOption();
|
||||
parser.AddOptions({ pathOption, delayOption, rawImageOption }, guiArgument);
|
||||
parser.AddOptions({ screenNumberOption, clipboardOption, pathOption,
|
||||
delayOption, rawImageOption },
|
||||
parser.AddOptions({ screenNumberOption,
|
||||
clipboardOption,
|
||||
pathOption,
|
||||
delayOption,
|
||||
rawImageOption },
|
||||
screenArgument);
|
||||
parser.AddOptions({ pathOption, clipboardOption, delayOption, rawImageOption },
|
||||
parser.AddOptions(
|
||||
{ pathOption, clipboardOption, delayOption, rawImageOption },
|
||||
fullArgument);
|
||||
parser.AddOptions({ autostartOption, filenameOption, trayOption,
|
||||
showHelpOption, mainColorOption, contrastColorOption },
|
||||
parser.AddOptions({ autostartOption,
|
||||
filenameOption,
|
||||
trayOption,
|
||||
showHelpOption,
|
||||
mainColorOption,
|
||||
contrastColorOption },
|
||||
configArgument);
|
||||
// Parse
|
||||
if (!parser.parse(app.arguments())) {
|
||||
@@ -217,18 +239,19 @@ int main(int argc, char *argv[]) {
|
||||
// PROCESS DATA
|
||||
//--------------
|
||||
if (parser.isSet(helpOption) || parser.isSet(versionOption)) {
|
||||
}
|
||||
else if (parser.isSet(launcherArgument)) { // LAUNCHER
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("openLauncher"));
|
||||
} else if (parser.isSet(launcherArgument)) { // LAUNCHER
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("openLauncher"));
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
if (!sessionBus.isConnected()) {
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Unable to connect via DBus"));
|
||||
}
|
||||
sessionBus.call(m);
|
||||
}
|
||||
else if (parser.isSet(guiArgument)) { // GUI
|
||||
} else if (parser.isSet(guiArgument)) { // GUI
|
||||
QString pathValue = parser.value(pathOption);
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool isRaw = parser.isSet(rawImageOption);
|
||||
@@ -237,8 +260,11 @@ int main(int argc, char *argv[]) {
|
||||
uint id = req.id();
|
||||
|
||||
// Send message
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("graphicCapture"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("graphicCapture"));
|
||||
m << pathValue << delay << id;
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
dbusUtils.checkDBusConnection(sessionBus);
|
||||
@@ -248,14 +274,13 @@ int main(int argc, char *argv[]) {
|
||||
dbusUtils.connectPrintCapture(sessionBus, id);
|
||||
QTimer t;
|
||||
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();
|
||||
// wait
|
||||
return app.exec();
|
||||
}
|
||||
}
|
||||
else if (parser.isSet(fullArgument)) { // FULL
|
||||
} else if (parser.isSet(fullArgument)) { // FULL
|
||||
QString pathValue = parser.value(pathOption);
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool toClipboard = parser.isSet(clipboardOption);
|
||||
@@ -266,9 +291,12 @@ int main(int argc, char *argv[]) {
|
||||
out << "Invalid format, set where to save the content with one of "
|
||||
<< "the following flags:\n "
|
||||
<< pathOption.dashedNames().join(QStringLiteral(", ")) << "\n "
|
||||
<< rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n "
|
||||
<< clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n";
|
||||
parser.parse(QStringList() << argv[0] << QStringLiteral("full") << QStringLiteral("-h"));
|
||||
<< rawImageOption.dashedNames().join(QStringLiteral(", "))
|
||||
<< "\n "
|
||||
<< clipboardOption.dashedNames().join(QStringLiteral(", "))
|
||||
<< "\n\n";
|
||||
parser.parse(QStringList() << argv[0] << QStringLiteral("full")
|
||||
<< QStringLiteral("-h"));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@@ -283,8 +311,11 @@ int main(int argc, char *argv[]) {
|
||||
DBusUtils dbusUtils;
|
||||
|
||||
// Send message
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("fullScreen"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("fullScreen"));
|
||||
m << pathValue << toClipboard << delay << id;
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
dbusUtils.checkDBusConnection(sessionBus);
|
||||
@@ -295,16 +326,16 @@ int main(int argc, char *argv[]) {
|
||||
// timeout just in case
|
||||
QTimer t;
|
||||
t.setInterval(delay + 2000);
|
||||
QObject::connect(&t, &QTimer::timeout, qApp,
|
||||
&QCoreApplication::quit);
|
||||
QObject::connect(
|
||||
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
|
||||
t.start();
|
||||
// wait
|
||||
return app.exec();
|
||||
}
|
||||
}
|
||||
else if (parser.isSet(screenArgument)) { // SCREEN
|
||||
} else if (parser.isSet(screenArgument)) { // SCREEN
|
||||
QString numberStr = parser.value(screenNumberOption);
|
||||
int number = numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt();
|
||||
int number =
|
||||
numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt();
|
||||
QString pathValue = parser.value(pathOption);
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool toClipboard = parser.isSet(clipboardOption);
|
||||
@@ -315,14 +346,17 @@ int main(int argc, char *argv[]) {
|
||||
out << "Invalid format, set where to save the content with one of "
|
||||
<< "the following flags:\n "
|
||||
<< pathOption.dashedNames().join(QStringLiteral(", ")) << "\n "
|
||||
<< rawImageOption.dashedNames().join(QStringLiteral(", ")) << "\n "
|
||||
<< clipboardOption.dashedNames().join(QStringLiteral(", ")) << "\n\n";
|
||||
parser.parse(QStringList() << argv[0] << QStringLiteral("screen") << QStringLiteral("-h"));
|
||||
<< rawImageOption.dashedNames().join(QStringLiteral(", "))
|
||||
<< "\n "
|
||||
<< clipboardOption.dashedNames().join(QStringLiteral(", "))
|
||||
<< "\n\n";
|
||||
parser.parse(QStringList() << argv[0] << QStringLiteral("screen")
|
||||
<< QStringLiteral("-h"));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
CaptureRequest req(CaptureRequest::SCREEN_MODE,
|
||||
delay, pathValue, number);
|
||||
CaptureRequest req(
|
||||
CaptureRequest::SCREEN_MODE, delay, pathValue, number);
|
||||
if (toClipboard) {
|
||||
req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
|
||||
}
|
||||
@@ -333,8 +367,11 @@ int main(int argc, char *argv[]) {
|
||||
DBusUtils dbusUtils;
|
||||
|
||||
// Send message
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureScreen"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureScreen"));
|
||||
m << number << pathValue << toClipboard << delay << id;
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
dbusUtils.checkDBusConnection(sessionBus);
|
||||
@@ -345,26 +382,28 @@ int main(int argc, char *argv[]) {
|
||||
// timeout just in case
|
||||
QTimer t;
|
||||
t.setInterval(delay + 2000);
|
||||
QObject::connect(&t, &QTimer::timeout, qApp,
|
||||
&QCoreApplication::quit);
|
||||
QObject::connect(
|
||||
&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
|
||||
t.start();
|
||||
// wait
|
||||
return app.exec();
|
||||
}
|
||||
}
|
||||
else if (parser.isSet(configArgument)) { // CONFIG
|
||||
} else if (parser.isSet(configArgument)) { // CONFIG
|
||||
bool autostart = parser.isSet(autostartOption);
|
||||
bool filename = parser.isSet(filenameOption);
|
||||
bool tray = parser.isSet(trayOption);
|
||||
bool help = parser.isSet(showHelpOption);
|
||||
bool mainColor = parser.isSet(mainColorOption);
|
||||
bool contrastColor = parser.isSet(contrastColorOption);
|
||||
bool someFlagSet = (filename || tray || help ||
|
||||
mainColor || contrastColor);
|
||||
bool someFlagSet =
|
||||
(filename || tray || help || mainColor || contrastColor);
|
||||
ConfigHandler config;
|
||||
if (autostart) {
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("autostartEnabled"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("autostartEnabled"));
|
||||
if (parser.value(autostartOption) == QLatin1String("false")) {
|
||||
m << false;
|
||||
} else if (parser.value(autostartOption) == QLatin1String("true")) {
|
||||
@@ -383,12 +422,16 @@ int main(int argc, char *argv[]) {
|
||||
FileNameHandler fh;
|
||||
QTextStream(stdout)
|
||||
<< QStringLiteral("The new pattern is '%1'\n"
|
||||
"Parsed pattern example: %2\n").arg(newFilename)
|
||||
"Parsed pattern example: %2\n")
|
||||
.arg(newFilename)
|
||||
.arg(fh.parsedPattern());
|
||||
}
|
||||
if (tray) {
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("trayIconEnabled"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("trayIconEnabled"));
|
||||
if (parser.value(trayOption) == QLatin1String("false")) {
|
||||
m << false;
|
||||
} else if (parser.value(trayOption) == QLatin1String("true")) {
|
||||
@@ -421,8 +464,11 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Open gui when no options
|
||||
if (!someFlagSet) {
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("openConfig"));
|
||||
QDBusMessage m = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("openConfig"));
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
if (!sessionBus.isConnected()) {
|
||||
SystemNotification().sendMessage(
|
||||
|
||||
@@ -24,58 +24,56 @@
|
||||
namespace color_widgets {
|
||||
namespace detail {
|
||||
|
||||
QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha )
|
||||
QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha)
|
||||
{
|
||||
qreal h1 = hue*6;
|
||||
qreal x = chroma*(1-qAbs(std::fmod(h1,2)-1));
|
||||
qreal h1 = hue * 6;
|
||||
qreal x = chroma * (1 - qAbs(std::fmod(h1, 2) - 1));
|
||||
QColor col;
|
||||
if ( h1 >= 0 && h1 < 1 )
|
||||
col = QColor::fromRgbF(chroma,x,0);
|
||||
else if ( h1 < 2 )
|
||||
col = QColor::fromRgbF(x,chroma,0);
|
||||
else if ( h1 < 3 )
|
||||
col = QColor::fromRgbF(0,chroma,x);
|
||||
else if ( h1 < 4 )
|
||||
col = QColor::fromRgbF(0,x,chroma);
|
||||
else if ( h1 < 5 )
|
||||
col = QColor::fromRgbF(x,0,chroma);
|
||||
else if ( h1 < 6 )
|
||||
col = QColor::fromRgbF(chroma,0,x);
|
||||
if (h1 >= 0 && h1 < 1)
|
||||
col = QColor::fromRgbF(chroma, x, 0);
|
||||
else if (h1 < 2)
|
||||
col = QColor::fromRgbF(x, chroma, 0);
|
||||
else if (h1 < 3)
|
||||
col = QColor::fromRgbF(0, chroma, x);
|
||||
else if (h1 < 4)
|
||||
col = QColor::fromRgbF(0, x, chroma);
|
||||
else if (h1 < 5)
|
||||
col = QColor::fromRgbF(x, 0, chroma);
|
||||
else if (h1 < 6)
|
||||
col = QColor::fromRgbF(chroma, 0, x);
|
||||
|
||||
qreal m = luma - color_lumaF(col);
|
||||
|
||||
return QColor::fromRgbF(
|
||||
qBound(0.0,col.redF()+m,1.0),
|
||||
qBound(0.0,col.greenF()+m,1.0),
|
||||
qBound(0.0,col.blueF()+m,1.0),
|
||||
return QColor::fromRgbF(qBound(0.0, col.redF() + m, 1.0),
|
||||
qBound(0.0, col.greenF() + m, 1.0),
|
||||
qBound(0.0, col.blueF() + m, 1.0),
|
||||
alpha);
|
||||
}
|
||||
|
||||
QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha )
|
||||
QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha)
|
||||
{
|
||||
qreal chroma = (1 - qAbs(2*lig-1))*sat;
|
||||
qreal h1 = hue*6;
|
||||
qreal x = chroma*(1-qAbs(std::fmod(h1,2)-1));
|
||||
qreal chroma = (1 - qAbs(2 * lig - 1)) * sat;
|
||||
qreal h1 = hue * 6;
|
||||
qreal x = chroma * (1 - qAbs(std::fmod(h1, 2) - 1));
|
||||
QColor col;
|
||||
if ( h1 >= 0 && h1 < 1 )
|
||||
col = QColor::fromRgbF(chroma,x,0);
|
||||
else if ( h1 < 2 )
|
||||
col = QColor::fromRgbF(x,chroma,0);
|
||||
else if ( h1 < 3 )
|
||||
col = QColor::fromRgbF(0,chroma,x);
|
||||
else if ( h1 < 4 )
|
||||
col = QColor::fromRgbF(0,x,chroma);
|
||||
else if ( h1 < 5 )
|
||||
col = QColor::fromRgbF(x,0,chroma);
|
||||
else if ( h1 < 6 )
|
||||
col = QColor::fromRgbF(chroma,0,x);
|
||||
if (h1 >= 0 && h1 < 1)
|
||||
col = QColor::fromRgbF(chroma, x, 0);
|
||||
else if (h1 < 2)
|
||||
col = QColor::fromRgbF(x, chroma, 0);
|
||||
else if (h1 < 3)
|
||||
col = QColor::fromRgbF(0, chroma, x);
|
||||
else if (h1 < 4)
|
||||
col = QColor::fromRgbF(0, x, chroma);
|
||||
else if (h1 < 5)
|
||||
col = QColor::fromRgbF(x, 0, chroma);
|
||||
else if (h1 < 6)
|
||||
col = QColor::fromRgbF(chroma, 0, x);
|
||||
|
||||
qreal m = lig-chroma/2;
|
||||
qreal m = lig - chroma / 2;
|
||||
|
||||
return QColor::fromRgbF(
|
||||
qBound(0.0,col.redF()+m,1.0),
|
||||
qBound(0.0,col.greenF()+m,1.0),
|
||||
qBound(0.0,col.blueF()+m,1.0),
|
||||
return QColor::fromRgbF(qBound(0.0, col.redF() + m, 1.0),
|
||||
qBound(0.0, col.greenF() + m, 1.0),
|
||||
qBound(0.0, col.blueF() + m, 1.0),
|
||||
alpha);
|
||||
}
|
||||
|
||||
|
||||
304
src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
vendored
304
src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
vendored
@@ -21,13 +21,13 @@
|
||||
*/
|
||||
#include "color_wheel.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include "color_utils.hpp"
|
||||
#include <QDragEnterEvent>
|
||||
#include <QLineF>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QLineF>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include "color_utils.hpp"
|
||||
#include <cmath>
|
||||
|
||||
namespace color_widgets {
|
||||
|
||||
@@ -38,14 +38,16 @@ enum MouseStatus
|
||||
DragSquare
|
||||
};
|
||||
|
||||
static const ColorWheel::DisplayFlags hard_default_flags = ColorWheel::SHAPE_TRIANGLE|ColorWheel::ANGLE_ROTATING|ColorWheel::COLOR_HSV;
|
||||
static const ColorWheel::DisplayFlags hard_default_flags =
|
||||
ColorWheel::SHAPE_TRIANGLE | ColorWheel::ANGLE_ROTATING |
|
||||
ColorWheel::COLOR_HSV;
|
||||
static ColorWheel::DisplayFlags default_flags = hard_default_flags;
|
||||
static const double selector_radius = 6;
|
||||
|
||||
class ColorWheel::Private
|
||||
{
|
||||
private:
|
||||
ColorWheel * const w;
|
||||
ColorWheel* const w;
|
||||
|
||||
public:
|
||||
qreal hue, sat, val;
|
||||
@@ -55,15 +57,20 @@ public:
|
||||
QPixmap hue_ring;
|
||||
QImage inner_selector;
|
||||
DisplayFlags display_flags;
|
||||
QColor (*color_from)(qreal,qreal,qreal,qreal);
|
||||
QColor (*color_from)(qreal, qreal, qreal, qreal);
|
||||
QColor (*rainbow_from_hue)(qreal);
|
||||
int max_size = 128;
|
||||
|
||||
explicit Private(ColorWheel *widget)
|
||||
: w(widget), hue(0), sat(0), val(0),
|
||||
wheel_width(20), mouse_status(Nothing),
|
||||
display_flags(FLAGS_DEFAULT),
|
||||
color_from(&QColor::fromHsvF), rainbow_from_hue(&detail::rainbow_hsv)
|
||||
explicit Private(ColorWheel* widget)
|
||||
: w(widget)
|
||||
, hue(0)
|
||||
, sat(0)
|
||||
, val(0)
|
||||
, wheel_width(20)
|
||||
, mouse_status(Nothing)
|
||||
, display_flags(FLAGS_DEFAULT)
|
||||
, color_from(&QColor::fromHsvF)
|
||||
, rainbow_from_hue(&detail::rainbow_hsv)
|
||||
{
|
||||
QColor bgColor = widget->palette().background().color();
|
||||
bgBrightness = color_widgets::detail::color_lumaF(bgColor);
|
||||
@@ -72,37 +79,26 @@ public:
|
||||
/// Calculate outer wheel radius from idget center
|
||||
qreal outer_radius() const
|
||||
{
|
||||
return qMin(w->geometry().width(), w->geometry().height())/2;
|
||||
return qMin(w->geometry().width(), w->geometry().height()) / 2;
|
||||
}
|
||||
|
||||
/// Calculate inner wheel radius from idget center
|
||||
qreal inner_radius() const
|
||||
{
|
||||
return outer_radius()-wheel_width;
|
||||
}
|
||||
qreal inner_radius() const { return outer_radius() - wheel_width; }
|
||||
|
||||
/// Calculate the edge length of the inner square
|
||||
qreal square_size() const
|
||||
{
|
||||
return inner_radius()*qSqrt(2);
|
||||
}
|
||||
qreal square_size() const { return inner_radius() * qSqrt(2); }
|
||||
|
||||
/// Calculate the height of the inner triangle
|
||||
qreal triangle_height() const
|
||||
{
|
||||
return inner_radius()*3/2;
|
||||
}
|
||||
qreal triangle_height() const { return inner_radius() * 3 / 2; }
|
||||
|
||||
/// Calculate the side of the inner triangle
|
||||
qreal triangle_side() const
|
||||
{
|
||||
return inner_radius()*qSqrt(3);
|
||||
}
|
||||
qreal triangle_side() const { return inner_radius() * qSqrt(3); }
|
||||
|
||||
/// return line from center to given point
|
||||
QLineF line_to_point(const QPoint &p) const
|
||||
QLineF line_to_point(const QPoint& p) const
|
||||
{
|
||||
return QLineF (w->geometry().width()/2, w->geometry().height()/2, p.x(), p.y());
|
||||
return QLineF(
|
||||
w->geometry().width() / 2, w->geometry().height() / 2, p.x(), p.y());
|
||||
}
|
||||
|
||||
void render_square()
|
||||
@@ -111,39 +107,40 @@ public:
|
||||
QSize size(width, width);
|
||||
inner_selector = QImage(size, QImage::Format_RGB32);
|
||||
|
||||
for ( int y = 0; y < width; ++y )
|
||||
{
|
||||
for ( int x = 0; x < width; ++x )
|
||||
{
|
||||
inner_selector.setPixel( x, y,
|
||||
color_from(hue,double(x)/width,double(y)/width,1).rgb());
|
||||
for (int y = 0; y < width; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
inner_selector.setPixel(
|
||||
x,
|
||||
y,
|
||||
color_from(hue, double(x) / width, double(y) / width, 1)
|
||||
.rgb());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief renders the selector as a triangle
|
||||
* \note It's the same as a square with the edge with value=0 collapsed to a single point
|
||||
* \note It's the same as a square with the edge with value=0 collapsed to a
|
||||
* single point
|
||||
*/
|
||||
void render_triangle()
|
||||
{
|
||||
QSizeF size = selector_size();
|
||||
if ( size.height() > max_size )
|
||||
if (size.height() > max_size)
|
||||
size *= max_size / size.height();
|
||||
|
||||
qreal ycenter = size.height()/2;
|
||||
qreal ycenter = size.height() / 2;
|
||||
inner_selector = QImage(size.toSize(), QImage::Format_RGB32);
|
||||
|
||||
for (int x = 0; x < inner_selector.width(); x++ )
|
||||
{
|
||||
for (int x = 0; x < inner_selector.width(); x++) {
|
||||
qreal pval = x / size.height();
|
||||
qreal slice_h = size.height() * pval;
|
||||
for (int y = 0; y < inner_selector.height(); y++ )
|
||||
{
|
||||
qreal ymin = ycenter-slice_h/2;
|
||||
qreal psat = qBound(0.0,(y-ymin)/slice_h,1.0);
|
||||
for (int y = 0; y < inner_selector.height(); y++) {
|
||||
qreal ymin = ycenter - slice_h / 2;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +148,7 @@ public:
|
||||
/// Updates the inner image that displays the saturation-value selector
|
||||
void render_inner_selector()
|
||||
{
|
||||
if ( display_flags & ColorWheel::SHAPE_TRIANGLE )
|
||||
if (display_flags & ColorWheel::SHAPE_TRIANGLE)
|
||||
render_triangle();
|
||||
else
|
||||
render_square();
|
||||
@@ -160,9 +157,9 @@ public:
|
||||
/// Offset of the selector image
|
||||
QPointF selector_image_offset()
|
||||
{
|
||||
if ( display_flags & SHAPE_TRIANGLE )
|
||||
return QPointF(-inner_radius(),-triangle_side()/2);
|
||||
return QPointF(-square_size()/2,-square_size()/2);
|
||||
if (display_flags & SHAPE_TRIANGLE)
|
||||
return QPointF(-inner_radius(), -triangle_side() / 2);
|
||||
return QPointF(-square_size() / 2, -square_size() / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,25 +167,21 @@ public:
|
||||
*/
|
||||
QSizeF selector_size()
|
||||
{
|
||||
if ( display_flags & SHAPE_TRIANGLE )
|
||||
if (display_flags & SHAPE_TRIANGLE)
|
||||
return QSizeF(triangle_height(), triangle_side());
|
||||
return QSizeF(square_size(), square_size());
|
||||
}
|
||||
|
||||
|
||||
/// Rotation of the selector image
|
||||
qreal selector_image_angle()
|
||||
{
|
||||
if ( display_flags & SHAPE_TRIANGLE )
|
||||
{
|
||||
if ( display_flags & ANGLE_ROTATING )
|
||||
return -hue*360-60;
|
||||
if (display_flags & SHAPE_TRIANGLE) {
|
||||
if (display_flags & ANGLE_ROTATING)
|
||||
return -hue * 360 - 60;
|
||||
return -150;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( display_flags & ANGLE_ROTATING )
|
||||
return -hue*360-45;
|
||||
} else {
|
||||
if (display_flags & ANGLE_ROTATING)
|
||||
return -hue * 360 - 45;
|
||||
else
|
||||
return 180;
|
||||
}
|
||||
@@ -197,50 +190,42 @@ public:
|
||||
/// Updates the outer ring that displays the hue selector
|
||||
void render_ring()
|
||||
{
|
||||
hue_ring = QPixmap(outer_radius()*2,outer_radius()*2);
|
||||
hue_ring = QPixmap(outer_radius() * 2, outer_radius() * 2);
|
||||
hue_ring.fill(Qt::transparent);
|
||||
QPainter painter(&hue_ring);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
|
||||
|
||||
const int hue_stops = 24;
|
||||
QConicalGradient gradient_hue(0, 0, 0);
|
||||
if ( gradient_hue.stops().size() < hue_stops )
|
||||
{
|
||||
for ( double a = 0; a < 1.0; a+=1.0/(hue_stops-1) )
|
||||
{
|
||||
gradient_hue.setColorAt(a,rainbow_from_hue(a));
|
||||
if (gradient_hue.stops().size() < hue_stops) {
|
||||
for (double a = 0; a < 1.0; a += 1.0 / (hue_stops - 1)) {
|
||||
gradient_hue.setColorAt(a, rainbow_from_hue(a));
|
||||
}
|
||||
gradient_hue.setColorAt(1,rainbow_from_hue(0));
|
||||
gradient_hue.setColorAt(1, rainbow_from_hue(0));
|
||||
}
|
||||
|
||||
painter.translate(outer_radius(),outer_radius());
|
||||
painter.translate(outer_radius(), outer_radius());
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QBrush(gradient_hue));
|
||||
painter.drawEllipse(QPointF(0,0),outer_radius(),outer_radius());
|
||||
painter.drawEllipse(QPointF(0, 0), outer_radius(), outer_radius());
|
||||
|
||||
painter.setBrush(Qt::transparent);//palette().background());
|
||||
painter.drawEllipse(QPointF(0,0),inner_radius(),inner_radius());
|
||||
painter.setBrush(Qt::transparent); // palette().background());
|
||||
painter.drawEllipse(QPointF(0, 0), inner_radius(), inner_radius());
|
||||
}
|
||||
|
||||
void set_color(const QColor& c)
|
||||
{
|
||||
if ( display_flags & ColorWheel::COLOR_HSV )
|
||||
{
|
||||
if (display_flags & ColorWheel::COLOR_HSV) {
|
||||
hue = qMax(0.0, c.hsvHueF());
|
||||
sat = c.hsvSaturationF();
|
||||
val = c.valueF();
|
||||
}
|
||||
else if ( display_flags & ColorWheel::COLOR_HSL )
|
||||
{
|
||||
} else if (display_flags & ColorWheel::COLOR_HSL) {
|
||||
hue = qMax(0.0, c.hueF());
|
||||
sat = detail::color_HSL_saturationF(c);
|
||||
val = detail::color_lightnessF(c);
|
||||
}
|
||||
else if ( display_flags & ColorWheel::COLOR_LCH )
|
||||
{
|
||||
} else if (display_flags & ColorWheel::COLOR_LCH) {
|
||||
hue = qMax(0.0, c.hsvHueF());
|
||||
sat = detail::color_chromaF(c);
|
||||
val = detail::color_lumaF(c);
|
||||
@@ -248,8 +233,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
ColorWheel::ColorWheel(QWidget *parent) :
|
||||
QWidget(parent), p(new Private(this))
|
||||
ColorWheel::ColorWheel(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, p(new Private(this))
|
||||
{
|
||||
setDisplayFlags(FLAGS_DEFAULT);
|
||||
setAcceptDrops(true);
|
||||
@@ -267,12 +253,12 @@ QColor ColorWheel::color() const
|
||||
|
||||
QSize ColorWheel::sizeHint() const
|
||||
{
|
||||
return QSize(p->wheel_width*5, p->wheel_width*5);
|
||||
return QSize(p->wheel_width * 5, p->wheel_width * 5);
|
||||
}
|
||||
|
||||
qreal 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 p->hue;
|
||||
}
|
||||
@@ -299,119 +285,111 @@ void ColorWheel::setWheelWidth(unsigned int w)
|
||||
update();
|
||||
}
|
||||
|
||||
void ColorWheel::paintEvent(QPaintEvent * )
|
||||
void ColorWheel::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.translate(geometry().width()/2,geometry().height()/2);
|
||||
painter.translate(geometry().width() / 2, geometry().height() / 2);
|
||||
|
||||
// hue wheel
|
||||
if(p->hue_ring.isNull())
|
||||
if (p->hue_ring.isNull())
|
||||
p->render_ring();
|
||||
|
||||
painter.drawPixmap(-p->outer_radius(), -p->outer_radius(), p->hue_ring);
|
||||
|
||||
// hue selector
|
||||
QColor penColor = p->bgBrightness < 0.6 ? Qt::white : Qt::black;
|
||||
painter.setPen(QPen(penColor,3));
|
||||
painter.setPen(QPen(penColor, 3));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
QLineF ray(0, 0, p->outer_radius(), 0);
|
||||
ray.setAngle(p->hue*360);
|
||||
ray.setAngle(p->hue * 360);
|
||||
QPointF h1 = ray.p2();
|
||||
ray.setLength(p->inner_radius());
|
||||
QPointF h2 = ray.p2();
|
||||
painter.drawLine(h1,h2);
|
||||
painter.drawLine(h1, h2);
|
||||
|
||||
// lum-sat square
|
||||
if(p->inner_selector.isNull())
|
||||
if (p->inner_selector.isNull())
|
||||
p->render_inner_selector();
|
||||
|
||||
painter.rotate(p->selector_image_angle());
|
||||
painter.translate(p->selector_image_offset());
|
||||
|
||||
QPointF selector_position;
|
||||
if ( p->display_flags & SHAPE_SQUARE )
|
||||
{
|
||||
if (p->display_flags & SHAPE_SQUARE) {
|
||||
qreal side = p->square_size();
|
||||
selector_position = QPointF(p->sat*side, p->val*side);
|
||||
}
|
||||
else if ( p->display_flags & SHAPE_TRIANGLE )
|
||||
{
|
||||
selector_position = QPointF(p->sat * side, p->val * side);
|
||||
} else if (p->display_flags & SHAPE_TRIANGLE) {
|
||||
qreal side = p->triangle_side();
|
||||
qreal height = p->triangle_height();
|
||||
qreal slice_h = side * p->val;
|
||||
qreal ymin = side/2-slice_h/2;
|
||||
qreal ymin = side / 2 - slice_h / 2;
|
||||
|
||||
selector_position = QPointF(p->val*height, ymin + p->sat*slice_h);
|
||||
selector_position = QPointF(p->val * height, ymin + p->sat * slice_h);
|
||||
QPolygonF triangle;
|
||||
triangle.append(QPointF(0,side/2));
|
||||
triangle.append(QPointF(height,0));
|
||||
triangle.append(QPointF(height,side));
|
||||
triangle.append(QPointF(0, side / 2));
|
||||
triangle.append(QPointF(height, 0));
|
||||
triangle.append(QPointF(height, side));
|
||||
QPainterPath clip;
|
||||
clip.addPolygon(triangle);
|
||||
painter.setClipPath(clip);
|
||||
}
|
||||
|
||||
painter.drawImage(QRectF(QPointF(0, 0), p->selector_size()), p->inner_selector);
|
||||
painter.drawImage(QRectF(QPointF(0, 0), p->selector_size()),
|
||||
p->inner_selector);
|
||||
painter.setClipping(false);
|
||||
|
||||
// lum-sat selector
|
||||
// we define the color of the selecto based on the background color of the widget
|
||||
// in order to improve the contrast
|
||||
// we define the color of the selecto based on the background color of the
|
||||
// widget in order to improve the contrast
|
||||
qreal colorBrightness = color_widgets::detail::color_lumaF(color());
|
||||
if (p->bgBrightness < 0.6) // dark theme
|
||||
{
|
||||
bool isWhite = (colorBrightness < 0.7);
|
||||
painter.setPen(QPen(isWhite ? Qt::white : Qt::black, 3));
|
||||
}
|
||||
else // light theme
|
||||
} else // light theme
|
||||
{
|
||||
bool isWhite = (colorBrightness < 0.4 && p->val < 0.3);
|
||||
painter.setPen(QPen(isWhite ? Qt::white : Qt::black, 3));
|
||||
}
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawEllipse(selector_position, selector_radius, selector_radius);
|
||||
|
||||
}
|
||||
|
||||
void ColorWheel::mouseMoveEvent(QMouseEvent *ev)
|
||||
void ColorWheel::mouseMoveEvent(QMouseEvent* ev)
|
||||
{
|
||||
if (p->mouse_status == DragCircle )
|
||||
{
|
||||
p->hue = p->line_to_point(ev->pos()).angle()/360.0;
|
||||
if (p->mouse_status == DragCircle) {
|
||||
p->hue = p->line_to_point(ev->pos()).angle() / 360.0;
|
||||
p->render_inner_selector();
|
||||
|
||||
emit colorSelected(color());
|
||||
emit colorChanged(color());
|
||||
update();
|
||||
}
|
||||
else if(p->mouse_status == DragSquare)
|
||||
{
|
||||
} else if (p->mouse_status == DragSquare) {
|
||||
QLineF glob_mouse_ln = p->line_to_point(ev->pos());
|
||||
QLineF center_mouse_ln ( QPointF(0,0),
|
||||
glob_mouse_ln.p2() - glob_mouse_ln.p1() );
|
||||
QLineF center_mouse_ln(QPointF(0, 0),
|
||||
glob_mouse_ln.p2() - glob_mouse_ln.p1());
|
||||
|
||||
center_mouse_ln.setAngle(center_mouse_ln.angle()+p->selector_image_angle());
|
||||
center_mouse_ln.setP2(center_mouse_ln.p2()-p->selector_image_offset());
|
||||
center_mouse_ln.setAngle(center_mouse_ln.angle() +
|
||||
p->selector_image_angle());
|
||||
center_mouse_ln.setP2(center_mouse_ln.p2() -
|
||||
p->selector_image_offset());
|
||||
|
||||
if ( p->display_flags & SHAPE_SQUARE )
|
||||
{
|
||||
p->sat = qBound(0.0, center_mouse_ln.x2()/p->square_size(), 1.0);
|
||||
p->val = qBound(0.0, center_mouse_ln.y2()/p->square_size(), 1.0);
|
||||
}
|
||||
else if ( p->display_flags & SHAPE_TRIANGLE )
|
||||
{
|
||||
if (p->display_flags & SHAPE_SQUARE) {
|
||||
p->sat = qBound(0.0, center_mouse_ln.x2() / p->square_size(), 1.0);
|
||||
p->val = qBound(0.0, center_mouse_ln.y2() / p->square_size(), 1.0);
|
||||
} else if (p->display_flags & SHAPE_TRIANGLE) {
|
||||
QPointF pt = center_mouse_ln.p2();
|
||||
|
||||
qreal side = p->triangle_side();
|
||||
p->val = qBound(0.0, pt.x() / p->triangle_height(), 1.0);
|
||||
qreal slice_h = side * p->val;
|
||||
|
||||
qreal ycenter = side/2;
|
||||
qreal ymin = ycenter-slice_h/2;
|
||||
qreal ycenter = side / 2;
|
||||
qreal ymin = ycenter - slice_h / 2;
|
||||
|
||||
if ( slice_h > 0 )
|
||||
p->sat = qBound(0.0, (pt.y()-ymin)/slice_h, 1.0);
|
||||
if (slice_h > 0)
|
||||
p->sat = qBound(0.0, (pt.y() - ymin) / slice_h, 1.0);
|
||||
}
|
||||
|
||||
emit colorSelected(color());
|
||||
@@ -420,15 +398,14 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *ev)
|
||||
}
|
||||
}
|
||||
|
||||
void ColorWheel::mousePressEvent(QMouseEvent *ev)
|
||||
void ColorWheel::mousePressEvent(QMouseEvent* ev)
|
||||
{
|
||||
if ( ev->buttons() & Qt::LeftButton )
|
||||
{
|
||||
if (ev->buttons() & Qt::LeftButton) {
|
||||
setFocus();
|
||||
QLineF ray = p->line_to_point(ev->pos());
|
||||
if ( ray.length() <= p->inner_radius() )
|
||||
if (ray.length() <= p->inner_radius())
|
||||
p->mouse_status = DragSquare;
|
||||
else if ( ray.length() <= p->outer_radius() )
|
||||
else if (ray.length() <= p->outer_radius())
|
||||
p->mouse_status = DragCircle;
|
||||
|
||||
// Update the color
|
||||
@@ -436,15 +413,14 @@ void ColorWheel::mousePressEvent(QMouseEvent *ev)
|
||||
}
|
||||
}
|
||||
|
||||
void ColorWheel::mouseReleaseEvent(QMouseEvent *ev)
|
||||
void ColorWheel::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
mouseMoveEvent(ev);
|
||||
p->mouse_status = Nothing;
|
||||
emit mouseReleaseOnColor(color());
|
||||
|
||||
}
|
||||
|
||||
void ColorWheel::resizeEvent(QResizeEvent *)
|
||||
void ColorWheel::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
p->render_ring();
|
||||
p->render_inner_selector();
|
||||
@@ -454,7 +430,7 @@ void ColorWheel::setColor(QColor c)
|
||||
{
|
||||
qreal oldh = p->hue;
|
||||
p->set_color(c);
|
||||
if (!qFuzzyCompare(oldh+1, p->hue+1))
|
||||
if (!qFuzzyCompare(oldh + 1, p->hue + 1))
|
||||
p->render_inner_selector();
|
||||
update();
|
||||
emit colorChanged(c);
|
||||
@@ -479,37 +455,30 @@ void ColorWheel::setValue(qreal v)
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void ColorWheel::setDisplayFlags(DisplayFlags flags)
|
||||
{
|
||||
if ( ! (flags & COLOR_FLAGS) )
|
||||
if (!(flags & COLOR_FLAGS))
|
||||
flags |= default_flags & COLOR_FLAGS;
|
||||
if ( ! (flags & ANGLE_FLAGS) )
|
||||
if (!(flags & ANGLE_FLAGS))
|
||||
flags |= default_flags & ANGLE_FLAGS;
|
||||
if ( ! (flags & SHAPE_FLAGS) )
|
||||
if (!(flags & SHAPE_FLAGS))
|
||||
flags |= default_flags & SHAPE_FLAGS;
|
||||
|
||||
if ( (flags & COLOR_FLAGS) != (p->display_flags & COLOR_FLAGS) )
|
||||
{
|
||||
if ((flags & COLOR_FLAGS) != (p->display_flags & COLOR_FLAGS)) {
|
||||
QColor old_col = color();
|
||||
if ( flags & ColorWheel::COLOR_HSL )
|
||||
{
|
||||
if (flags & ColorWheel::COLOR_HSL) {
|
||||
p->hue = old_col.hueF();
|
||||
p->sat = detail::color_HSL_saturationF(old_col);
|
||||
p->val = detail::color_lightnessF(old_col);
|
||||
p->color_from = &detail::color_from_hsl;
|
||||
p->rainbow_from_hue = &detail::rainbow_hsv;
|
||||
}
|
||||
else if ( flags & ColorWheel::COLOR_LCH )
|
||||
{
|
||||
} else if (flags & ColorWheel::COLOR_LCH) {
|
||||
p->hue = old_col.hueF();
|
||||
p->sat = detail::color_chromaF(old_col);
|
||||
p->val = detail::color_lumaF(old_col);
|
||||
p->color_from = &detail::color_from_lch;
|
||||
p->rainbow_from_hue = &detail::rainbow_lch;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
p->hue = old_col.hsvHueF();
|
||||
p->sat = old_col.hsvSaturationF();
|
||||
p->val = old_col.valueF();
|
||||
@@ -532,11 +501,11 @@ ColorWheel::DisplayFlags ColorWheel::displayFlags(DisplayFlags mask) const
|
||||
|
||||
void ColorWheel::setDefaultDisplayFlags(DisplayFlags flags)
|
||||
{
|
||||
if ( !(flags & COLOR_FLAGS) )
|
||||
if (!(flags & COLOR_FLAGS))
|
||||
flags |= hard_default_flags & COLOR_FLAGS;
|
||||
if ( !(flags & ANGLE_FLAGS) )
|
||||
if (!(flags & ANGLE_FLAGS))
|
||||
flags |= hard_default_flags & ANGLE_FLAGS;
|
||||
if ( !(flags & SHAPE_FLAGS) )
|
||||
if (!(flags & SHAPE_FLAGS))
|
||||
flags |= hard_default_flags & SHAPE_FLAGS;
|
||||
default_flags = flags;
|
||||
}
|
||||
@@ -548,28 +517,25 @@ ColorWheel::DisplayFlags ColorWheel::defaultDisplayFlags(DisplayFlags mask)
|
||||
|
||||
void ColorWheel::setDisplayFlag(DisplayFlags flag, DisplayFlags mask)
|
||||
{
|
||||
setDisplayFlags((p->display_flags&~mask)|flag);
|
||||
setDisplayFlags((p->display_flags & ~mask) | flag);
|
||||
}
|
||||
|
||||
void ColorWheel::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if ( event->mimeData()->hasColor() ||
|
||||
( event->mimeData()->hasText() && QColor(event->mimeData()->text()).isValid() ) )
|
||||
if (event->mimeData()->hasColor() ||
|
||||
(event->mimeData()->hasText() &&
|
||||
QColor(event->mimeData()->text()).isValid()))
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void ColorWheel::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if ( event->mimeData()->hasColor() )
|
||||
{
|
||||
if (event->mimeData()->hasColor()) {
|
||||
setColor(event->mimeData()->colorData().value<QColor>());
|
||||
event->accept();
|
||||
}
|
||||
else if ( event->mimeData()->hasText() )
|
||||
{
|
||||
} else if (event->mimeData()->hasText()) {
|
||||
QColor col(event->mimeData()->text());
|
||||
if ( col.isValid() )
|
||||
{
|
||||
if (col.isValid()) {
|
||||
setColor(col);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
@@ -22,48 +22,49 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QCryptographicHash>
|
||||
#include <QtCore/QDataStream>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QSemaphore>
|
||||
#include <QtCore/QSharedMemory>
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QCryptographicHash>
|
||||
#include <QtCore/QDataStream>
|
||||
#include <QtNetwork/QLocalServer>
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#include <lmcons.h>
|
||||
#include <lmcons.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "singleapplication.h"
|
||||
#include "singleapplication_p.h"
|
||||
|
||||
|
||||
SingleApplicationPrivate::SingleApplicationPrivate( SingleApplication *q_ptr ) : q_ptr( q_ptr ) {
|
||||
SingleApplicationPrivate::SingleApplicationPrivate(SingleApplication* q_ptr)
|
||||
: q_ptr(q_ptr)
|
||||
{
|
||||
server = nullptr;
|
||||
socket = nullptr;
|
||||
}
|
||||
|
||||
SingleApplicationPrivate::~SingleApplicationPrivate()
|
||||
{
|
||||
if( socket != nullptr ) {
|
||||
if (socket != nullptr) {
|
||||
socket->close();
|
||||
delete socket;
|
||||
}
|
||||
|
||||
memory->lock();
|
||||
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
|
||||
if( server != nullptr ) {
|
||||
if (server != nullptr) {
|
||||
server->close();
|
||||
delete server;
|
||||
inst->primary = false;
|
||||
@@ -74,51 +75,57 @@ SingleApplicationPrivate::~SingleApplicationPrivate()
|
||||
delete memory;
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::genBlockServerName( int timeout )
|
||||
void SingleApplicationPrivate::genBlockServerName(int timeout)
|
||||
{
|
||||
QCryptographicHash appData( QCryptographicHash::Sha256 );
|
||||
appData.addData( "SingleApplication", 17 );
|
||||
appData.addData( SingleApplication::app_t::applicationName().toUtf8() );
|
||||
appData.addData( SingleApplication::app_t::organizationName().toUtf8() );
|
||||
appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() );
|
||||
QCryptographicHash appData(QCryptographicHash::Sha256);
|
||||
appData.addData("SingleApplication", 17);
|
||||
appData.addData(SingleApplication::app_t::applicationName().toUtf8());
|
||||
appData.addData(SingleApplication::app_t::organizationName().toUtf8());
|
||||
appData.addData(SingleApplication::app_t::organizationDomain().toUtf8());
|
||||
|
||||
if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) {
|
||||
appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
|
||||
if (!(options & SingleApplication::Mode::ExcludeAppVersion)) {
|
||||
appData.addData(
|
||||
SingleApplication::app_t::applicationVersion().toUtf8());
|
||||
}
|
||||
|
||||
if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) {
|
||||
if (!(options & SingleApplication::Mode::ExcludeAppPath)) {
|
||||
#ifdef Q_OS_WIN
|
||||
appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() );
|
||||
appData.addData(
|
||||
SingleApplication::app_t::applicationFilePath().toLower().toUtf8());
|
||||
#else
|
||||
appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
|
||||
appData.addData(
|
||||
SingleApplication::app_t::applicationFilePath().toUtf8());
|
||||
#endif
|
||||
}
|
||||
|
||||
// User level block requires a user specific data in the hash
|
||||
if( options & SingleApplication::Mode::User ) {
|
||||
if (options & SingleApplication::Mode::User) {
|
||||
#ifdef Q_OS_WIN
|
||||
Q_UNUSED(timeout);
|
||||
wchar_t username [ UNLEN + 1 ];
|
||||
wchar_t username[UNLEN + 1];
|
||||
// Specifies size of the buffer on input
|
||||
DWORD usernameLength = UNLEN + 1;
|
||||
if( GetUserNameW( username, &usernameLength ) ) {
|
||||
appData.addData( QString::fromWCharArray(username).toUtf8() );
|
||||
if (GetUserNameW(username, &usernameLength)) {
|
||||
appData.addData(QString::fromWCharArray(username).toUtf8());
|
||||
} else {
|
||||
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
|
||||
appData.addData(
|
||||
QStandardPaths::standardLocations(QStandardPaths::HomeLocation)
|
||||
.join("")
|
||||
.toUtf8());
|
||||
}
|
||||
#endif
|
||||
#ifdef Q_OS_UNIX
|
||||
QProcess process;
|
||||
process.start( QStringLiteral("whoami") );
|
||||
if( process.waitForFinished( timeout ) &&
|
||||
process.start(QStringLiteral("whoami"));
|
||||
if (process.waitForFinished(timeout) &&
|
||||
process.exitCode() == QProcess::NormalExit) {
|
||||
appData.addData( process.readLine() );
|
||||
appData.addData(process.readLine());
|
||||
} else {
|
||||
appData.addData(
|
||||
QDir(
|
||||
QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first()
|
||||
).absolutePath().toUtf8()
|
||||
);
|
||||
appData.addData(QDir(QStandardPaths::standardLocations(
|
||||
QStandardPaths::HomeLocation)
|
||||
.first())
|
||||
.absolutePath()
|
||||
.toUtf8());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -128,7 +135,7 @@ void SingleApplicationPrivate::genBlockServerName( int timeout )
|
||||
blockServerName = appData.result().toBase64().replace("/", "_");
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::startPrimary( bool resetMemory )
|
||||
void SingleApplicationPrivate::startPrimary(bool resetMemory)
|
||||
{
|
||||
Q_Q(SingleApplication);
|
||||
|
||||
@@ -139,30 +146,28 @@ void SingleApplicationPrivate::startPrimary( bool resetMemory )
|
||||
#endif
|
||||
// Successful creation means that no main process exists
|
||||
// So we start a QLocalServer to listen for connections
|
||||
QLocalServer::removeServer( blockServerName );
|
||||
QLocalServer::removeServer(blockServerName);
|
||||
server = new QLocalServer();
|
||||
|
||||
// Restrict access to the socket according to the
|
||||
// SingleApplication::Mode::User flag on User level or no restrictions
|
||||
if( options & SingleApplication::Mode::User ) {
|
||||
server->setSocketOptions( QLocalServer::UserAccessOption );
|
||||
if (options & SingleApplication::Mode::User) {
|
||||
server->setSocketOptions(QLocalServer::UserAccessOption);
|
||||
} else {
|
||||
server->setSocketOptions( QLocalServer::WorldAccessOption );
|
||||
server->setSocketOptions(QLocalServer::WorldAccessOption);
|
||||
}
|
||||
|
||||
server->listen( blockServerName );
|
||||
QObject::connect(
|
||||
server,
|
||||
server->listen(blockServerName);
|
||||
QObject::connect(server,
|
||||
&QLocalServer::newConnection,
|
||||
this,
|
||||
&SingleApplicationPrivate::slotConnectionEstablished
|
||||
);
|
||||
&SingleApplicationPrivate::slotConnectionEstablished);
|
||||
|
||||
// Reset the number of connections
|
||||
memory->lock();
|
||||
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
|
||||
|
||||
if( resetMemory ) {
|
||||
if (resetMemory) {
|
||||
inst->secondary = 0;
|
||||
}
|
||||
|
||||
@@ -183,31 +188,32 @@ void SingleApplicationPrivate::startSecondary()
|
||||
#endif
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
|
||||
void SingleApplicationPrivate::connectToPrimary(int msecs,
|
||||
ConnectionType connectionType)
|
||||
{
|
||||
// Connect to the Local Server of the Primary Instance if not already
|
||||
// connected.
|
||||
if( socket == nullptr ) {
|
||||
if (socket == nullptr) {
|
||||
socket = new QLocalSocket();
|
||||
}
|
||||
|
||||
// If already connected - we are done;
|
||||
if( socket->state() == QLocalSocket::ConnectedState )
|
||||
if (socket->state() == QLocalSocket::ConnectedState)
|
||||
return;
|
||||
|
||||
// If not connect
|
||||
if( socket->state() == QLocalSocket::UnconnectedState ||
|
||||
socket->state() == QLocalSocket::ClosingState ) {
|
||||
socket->connectToServer( blockServerName );
|
||||
if (socket->state() == QLocalSocket::UnconnectedState ||
|
||||
socket->state() == QLocalSocket::ClosingState) {
|
||||
socket->connectToServer(blockServerName);
|
||||
}
|
||||
|
||||
// Wait for being connected
|
||||
if( socket->state() == QLocalSocket::ConnectingState ) {
|
||||
socket->waitForConnected( msecs );
|
||||
if (socket->state() == QLocalSocket::ConnectingState) {
|
||||
socket->waitForConnected(msecs);
|
||||
}
|
||||
|
||||
// Initialisation message according to the SingleApplication protocol
|
||||
if( socket->state() == QLocalSocket::ConnectedState ) {
|
||||
if (socket->state() == QLocalSocket::ConnectedState) {
|
||||
// Notify the parent that a new instance had been started;
|
||||
QByteArray initMsg;
|
||||
QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
|
||||
@@ -215,12 +221,13 @@ void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType conne
|
||||
writeStream << blockServerName.toLatin1();
|
||||
writeStream << static_cast<quint8>(connectionType);
|
||||
writeStream << instanceNumber;
|
||||
quint16 checksum = qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length()));
|
||||
quint16 checksum = qChecksum(initMsg.constData(),
|
||||
static_cast<quint32>(initMsg.length()));
|
||||
writeStream << checksum;
|
||||
|
||||
socket->write( initMsg );
|
||||
socket->write(initMsg);
|
||||
socket->flush();
|
||||
socket->waitForBytesWritten( msecs );
|
||||
socket->waitForBytesWritten(msecs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,31 +244,31 @@ qint64 SingleApplicationPrivate::primaryPid()
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void SingleApplicationPrivate::crashHandler()
|
||||
{
|
||||
void SingleApplicationPrivate::crashHandler()
|
||||
{
|
||||
// Handle any further termination signals to ensure the
|
||||
// QSharedMemory block is deleted even if the process crashes
|
||||
signal( SIGHUP, SingleApplicationPrivate::terminate ); // 1
|
||||
signal( SIGINT, SingleApplicationPrivate::terminate ); // 2
|
||||
signal( SIGQUIT, SingleApplicationPrivate::terminate ); // 3
|
||||
signal( SIGILL, SingleApplicationPrivate::terminate ); // 4
|
||||
signal( SIGABRT, SingleApplicationPrivate::terminate ); // 6
|
||||
signal( SIGFPE, SingleApplicationPrivate::terminate ); // 8
|
||||
signal( SIGBUS, SingleApplicationPrivate::terminate ); // 10
|
||||
signal( SIGSEGV, SingleApplicationPrivate::terminate ); // 11
|
||||
signal( SIGSYS, SingleApplicationPrivate::terminate ); // 12
|
||||
signal( SIGPIPE, SingleApplicationPrivate::terminate ); // 13
|
||||
signal( SIGALRM, SingleApplicationPrivate::terminate ); // 14
|
||||
signal( SIGTERM, SingleApplicationPrivate::terminate ); // 15
|
||||
signal( SIGXCPU, SingleApplicationPrivate::terminate ); // 24
|
||||
signal( SIGXFSZ, SingleApplicationPrivate::terminate ); // 25
|
||||
}
|
||||
signal(SIGHUP, SingleApplicationPrivate::terminate); // 1
|
||||
signal(SIGINT, SingleApplicationPrivate::terminate); // 2
|
||||
signal(SIGQUIT, SingleApplicationPrivate::terminate); // 3
|
||||
signal(SIGILL, SingleApplicationPrivate::terminate); // 4
|
||||
signal(SIGABRT, SingleApplicationPrivate::terminate); // 6
|
||||
signal(SIGFPE, SingleApplicationPrivate::terminate); // 8
|
||||
signal(SIGBUS, SingleApplicationPrivate::terminate); // 10
|
||||
signal(SIGSEGV, SingleApplicationPrivate::terminate); // 11
|
||||
signal(SIGSYS, SingleApplicationPrivate::terminate); // 12
|
||||
signal(SIGPIPE, SingleApplicationPrivate::terminate); // 13
|
||||
signal(SIGALRM, SingleApplicationPrivate::terminate); // 14
|
||||
signal(SIGTERM, SingleApplicationPrivate::terminate); // 15
|
||||
signal(SIGXCPU, SingleApplicationPrivate::terminate); // 24
|
||||
signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::terminate( int signum )
|
||||
{
|
||||
void SingleApplicationPrivate::terminate(int signum)
|
||||
{
|
||||
delete ((SingleApplication*)QCoreApplication::instance())->d_ptr;
|
||||
::exit( 128 + signum );
|
||||
}
|
||||
::exit(128 + signum);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -271,13 +278,15 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
||||
{
|
||||
Q_Q(SingleApplication);
|
||||
|
||||
QLocalSocket *nextConnSocket = server->nextPendingConnection();
|
||||
QLocalSocket* nextConnSocket = server->nextPendingConnection();
|
||||
|
||||
quint32 instanceId = 0;
|
||||
ConnectionType connectionType = InvalidConnection;
|
||||
if( nextConnSocket->waitForReadyRead( 100 ) ) {
|
||||
if (nextConnSocket->waitForReadyRead(100)) {
|
||||
// read all data from message in same order/format as written
|
||||
QByteArray msgBytes = nextConnSocket->read(nextConnSocket->bytesAvailable() - static_cast<qint64>(sizeof(quint16)));
|
||||
QByteArray msgBytes =
|
||||
nextConnSocket->read(nextConnSocket->bytesAvailable() -
|
||||
static_cast<qint64>(sizeof(quint16)));
|
||||
QByteArray checksumBytes = nextConnSocket->read(sizeof(quint16));
|
||||
QDataStream readStream(msgBytes);
|
||||
readStream.setVersion(QDataStream::Qt_5_2);
|
||||
@@ -297,60 +306,62 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
||||
checksumStream.setVersion(QDataStream::Qt_5_2);
|
||||
checksumStream >> msgChecksum;
|
||||
|
||||
const quint16 actualChecksum = qChecksum(msgBytes.constData(), static_cast<quint32>(msgBytes.length()));
|
||||
const quint16 actualChecksum = qChecksum(
|
||||
msgBytes.constData(), static_cast<quint32>(msgBytes.length()));
|
||||
|
||||
if (readStream.status() != QDataStream::Ok || QLatin1String(latin1Name) != blockServerName || msgChecksum != actualChecksum) {
|
||||
if (readStream.status() != QDataStream::Ok ||
|
||||
QLatin1String(latin1Name) != blockServerName ||
|
||||
msgChecksum != actualChecksum) {
|
||||
connectionType = InvalidConnection;
|
||||
}
|
||||
}
|
||||
|
||||
if( connectionType == InvalidConnection ) {
|
||||
if (connectionType == InvalidConnection) {
|
||||
nextConnSocket->close();
|
||||
delete nextConnSocket;
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
nextConnSocket,
|
||||
QObject::connect(nextConnSocket,
|
||||
&QLocalSocket::aboutToClose,
|
||||
this,
|
||||
[nextConnSocket, instanceId, this]() {
|
||||
emit this->slotClientConnectionClosed( nextConnSocket, instanceId );
|
||||
}
|
||||
);
|
||||
emit this->slotClientConnectionClosed(nextConnSocket,
|
||||
instanceId);
|
||||
});
|
||||
|
||||
QObject::connect(
|
||||
nextConnSocket,
|
||||
QObject::connect(nextConnSocket,
|
||||
&QLocalSocket::readyRead,
|
||||
this,
|
||||
[nextConnSocket, instanceId, this]() {
|
||||
emit this->slotDataAvailable( nextConnSocket, instanceId );
|
||||
}
|
||||
);
|
||||
emit this->slotDataAvailable(nextConnSocket,
|
||||
instanceId);
|
||||
});
|
||||
|
||||
if( connectionType == NewInstance || (
|
||||
connectionType == SecondaryInstance &&
|
||||
options & SingleApplication::Mode::SecondaryNotification
|
||||
)
|
||||
) {
|
||||
if (connectionType == NewInstance ||
|
||||
(connectionType == SecondaryInstance &&
|
||||
options & SingleApplication::Mode::SecondaryNotification)) {
|
||||
emit q->instanceStarted();
|
||||
}
|
||||
|
||||
if( nextConnSocket->bytesAvailable() > 0 ) {
|
||||
emit this->slotDataAvailable( nextConnSocket, instanceId );
|
||||
if (nextConnSocket->bytesAvailable() > 0) {
|
||||
emit this->slotDataAvailable(nextConnSocket, instanceId);
|
||||
}
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
|
||||
void SingleApplicationPrivate::slotDataAvailable(QLocalSocket* dataSocket,
|
||||
quint32 instanceId)
|
||||
{
|
||||
Q_Q(SingleApplication);
|
||||
emit q->receivedMessage( instanceId, dataSocket->readAll() );
|
||||
emit q->receivedMessage(instanceId, dataSocket->readAll());
|
||||
}
|
||||
|
||||
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
|
||||
void SingleApplicationPrivate::slotClientConnectionClosed(
|
||||
QLocalSocket* closedSocket,
|
||||
quint32 instanceId)
|
||||
{
|
||||
if( closedSocket->bytesAvailable() > 0 )
|
||||
emit slotDataAvailable( closedSocket, instanceId );
|
||||
if (closedSocket->bytesAvailable() > 0)
|
||||
emit slotDataAvailable(closedSocket, instanceId);
|
||||
closedSocket->deleteLater();
|
||||
}
|
||||
|
||||
@@ -361,8 +372,13 @@ void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedS
|
||||
* @param argv
|
||||
* @param {bool} allowSecondaryInstances
|
||||
*/
|
||||
SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSecondary, Options options, int timeout )
|
||||
: app_t( argc, argv ), d_ptr( new SingleApplicationPrivate( this ) )
|
||||
SingleApplication::SingleApplication(int& argc,
|
||||
char* argv[],
|
||||
bool allowSecondary,
|
||||
Options options,
|
||||
int timeout)
|
||||
: app_t(argc, argv)
|
||||
, d_ptr(new SingleApplicationPrivate(this))
|
||||
{
|
||||
Q_D(SingleApplication);
|
||||
|
||||
@@ -371,41 +387,43 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
||||
|
||||
// Generating an application ID used for identifying the shared memory
|
||||
// block and QLocalServer
|
||||
d->genBlockServerName( timeout );
|
||||
d->genBlockServerName(timeout);
|
||||
|
||||
// Guarantee thread safe behaviour with a shared memory block. Also by
|
||||
// explicitly attaching it and then deleting it we make sure that the
|
||||
// memory is deleted even if the process had crashed on Unix.
|
||||
#ifdef Q_OS_UNIX
|
||||
d->memory = new QSharedMemory( d->blockServerName );
|
||||
d->memory = new QSharedMemory(d->blockServerName);
|
||||
d->memory->attach();
|
||||
delete d->memory;
|
||||
#endif
|
||||
d->memory = new QSharedMemory( d->blockServerName );
|
||||
d->memory = new QSharedMemory(d->blockServerName);
|
||||
|
||||
// Create a shared memory block
|
||||
if( d->memory->create( sizeof( InstancesInfo ) ) ) {
|
||||
d->startPrimary( true );
|
||||
if (d->memory->create(sizeof(InstancesInfo))) {
|
||||
d->startPrimary(true);
|
||||
return;
|
||||
} else {
|
||||
// Attempt to attach to the memory segment
|
||||
if( d->memory->attach() ) {
|
||||
if (d->memory->attach()) {
|
||||
d->memory->lock();
|
||||
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data());
|
||||
InstancesInfo* inst =
|
||||
static_cast<InstancesInfo*>(d->memory->data());
|
||||
|
||||
if( ! inst->primary ) {
|
||||
d->startPrimary( false );
|
||||
if (!inst->primary) {
|
||||
d->startPrimary(false);
|
||||
d->memory->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if another instance can be started
|
||||
if( allowSecondary ) {
|
||||
if (allowSecondary) {
|
||||
inst->secondary += 1;
|
||||
d->instanceNumber = inst->secondary;
|
||||
d->startSecondary();
|
||||
if( d->options & Mode::SecondaryNotification ) {
|
||||
d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance );
|
||||
if (d->options & Mode::SecondaryNotification) {
|
||||
d->connectToPrimary(
|
||||
timeout, SingleApplicationPrivate::SecondaryInstance);
|
||||
}
|
||||
d->memory->unlock();
|
||||
return;
|
||||
@@ -415,19 +433,18 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
||||
}
|
||||
}
|
||||
|
||||
d->connectToPrimary( timeout, SingleApplicationPrivate::NewInstance );
|
||||
d->connectToPrimary(timeout, SingleApplicationPrivate::NewInstance);
|
||||
delete d;
|
||||
|
||||
// show message box with inforation that Flameshot is already launched
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QObject::tr("Hi, I'm already running!\nYou can find me in the system tray."));
|
||||
msgBox.setText(QObject::tr(
|
||||
"Hi, I'm already running!\nYou can find me in the system tray."));
|
||||
int cnt = 3;
|
||||
QTimer cntDown;
|
||||
QObject::connect(
|
||||
&cntDown,
|
||||
&QTimer::timeout,
|
||||
[&msgBox,&cnt, &cntDown]()->void{
|
||||
if(--cnt < 0){
|
||||
&cntDown, &QTimer::timeout, [&msgBox, &cnt, &cntDown]() -> void {
|
||||
if (--cnt < 0) {
|
||||
cntDown.stop();
|
||||
msgBox.close();
|
||||
} else {
|
||||
@@ -437,7 +454,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
||||
cntDown.start(1000);
|
||||
msgBox.exec();
|
||||
|
||||
::exit( EXIT_SUCCESS );
|
||||
::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,18 +490,19 @@ qint64 SingleApplication::primaryPid()
|
||||
return d->primaryPid();
|
||||
}
|
||||
|
||||
bool SingleApplication::sendMessage( QByteArray message, int timeout )
|
||||
bool SingleApplication::sendMessage(QByteArray message, int timeout)
|
||||
{
|
||||
Q_D(SingleApplication);
|
||||
|
||||
// Nobody to connect to
|
||||
if( isPrimary() ) return false;
|
||||
if (isPrimary())
|
||||
return false;
|
||||
|
||||
// Make sure the socket is connected
|
||||
d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect );
|
||||
d->connectToPrimary(timeout, SingleApplicationPrivate::Reconnect);
|
||||
|
||||
d->socket->write( message );
|
||||
d->socket->write(message);
|
||||
bool dataWritten = d->socket->flush();
|
||||
d->socket->waitForBytesWritten( timeout );
|
||||
d->socket->waitForBytesWritten(timeout);
|
||||
return dataWritten;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
|
||||
#ifndef QAPPLICATION_CLASS
|
||||
#define QAPPLICATION_CLASS QCoreApplication
|
||||
#define QAPPLICATION_CLASS QCoreApplication
|
||||
#endif
|
||||
|
||||
#include QT_STRINGIFY(QAPPLICATION_CLASS)
|
||||
@@ -56,7 +56,8 @@ public:
|
||||
* block will be user wide.
|
||||
* @enum
|
||||
*/
|
||||
enum Mode {
|
||||
enum Mode
|
||||
{
|
||||
User = 1 << 0,
|
||||
System = 1 << 1,
|
||||
SecondaryNotification = 1 << 2,
|
||||
@@ -85,7 +86,11 @@ public:
|
||||
* Usually 4*timeout would be the worst case (fail) scenario.
|
||||
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
|
||||
*/
|
||||
explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 100 );
|
||||
explicit SingleApplication(int& argc,
|
||||
char* argv[],
|
||||
bool allowSecondary = false,
|
||||
Options options = Mode::User,
|
||||
int timeout = 100);
|
||||
~SingleApplication();
|
||||
|
||||
/**
|
||||
@@ -119,14 +124,14 @@ public:
|
||||
* @note sendMessage() will return false if invoked from the primary
|
||||
* instance.
|
||||
*/
|
||||
bool sendMessage( QByteArray message, int timeout = 100 );
|
||||
bool sendMessage(QByteArray message, int timeout = 100);
|
||||
|
||||
Q_SIGNALS:
|
||||
void instanceStarted();
|
||||
void receivedMessage( quint32 instanceId, QByteArray message );
|
||||
void receivedMessage(quint32 instanceId, QByteArray message);
|
||||
|
||||
private:
|
||||
SingleApplicationPrivate *d_ptr;
|
||||
SingleApplicationPrivate* d_ptr;
|
||||
Q_DECLARE_PRIVATE(SingleApplication)
|
||||
};
|
||||
|
||||
|
||||
@@ -32,21 +32,24 @@
|
||||
#ifndef SINGLEAPPLICATION_P_H
|
||||
#define SINGLEAPPLICATION_P_H
|
||||
|
||||
#include "singleapplication.h"
|
||||
#include <QtCore/QSharedMemory>
|
||||
#include <QtNetwork/QLocalServer>
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
#include "singleapplication.h"
|
||||
|
||||
struct InstancesInfo {
|
||||
struct InstancesInfo
|
||||
{
|
||||
bool primary;
|
||||
quint32 secondary;
|
||||
qint64 primaryPid;
|
||||
};
|
||||
|
||||
class SingleApplicationPrivate : public QObject {
|
||||
Q_OBJECT
|
||||
class SingleApplicationPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ConnectionType : quint8 {
|
||||
enum ConnectionType : quint8
|
||||
{
|
||||
InvalidConnection = 0,
|
||||
NewInstance = 1,
|
||||
SecondaryInstance = 2,
|
||||
@@ -54,32 +57,32 @@ public:
|
||||
};
|
||||
Q_DECLARE_PUBLIC(SingleApplication)
|
||||
|
||||
SingleApplicationPrivate( SingleApplication *q_ptr );
|
||||
SingleApplicationPrivate(SingleApplication* q_ptr);
|
||||
~SingleApplicationPrivate();
|
||||
|
||||
void genBlockServerName( int msecs );
|
||||
void startPrimary( bool resetMemory );
|
||||
void genBlockServerName(int msecs);
|
||||
void startPrimary(bool resetMemory);
|
||||
void startSecondary();
|
||||
void connectToPrimary(int msecs, ConnectionType connectionType );
|
||||
void connectToPrimary(int msecs, ConnectionType connectionType);
|
||||
qint64 primaryPid();
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void crashHandler();
|
||||
static void terminate( int signum );
|
||||
static void terminate(int signum);
|
||||
#endif
|
||||
|
||||
QSharedMemory *memory;
|
||||
SingleApplication *q_ptr;
|
||||
QLocalSocket *socket;
|
||||
QLocalServer *server;
|
||||
QSharedMemory* memory;
|
||||
SingleApplication* q_ptr;
|
||||
QLocalSocket* socket;
|
||||
QLocalServer* server;
|
||||
quint32 instanceNumber;
|
||||
QString blockServerName;
|
||||
SingleApplication::Options options;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotConnectionEstablished();
|
||||
void slotDataAvailable( QLocalSocket*, quint32 );
|
||||
void slotClientConnectionClosed( QLocalSocket*, quint32 );
|
||||
void slotDataAvailable(QLocalSocket*, quint32);
|
||||
void slotClientConnectionClosed(QLocalSocket*, quint32);
|
||||
};
|
||||
|
||||
#endif // SINGLEAPPLICATION_P_H
|
||||
|
||||
@@ -17,55 +17,67 @@
|
||||
|
||||
#include "abstractactiontool.h"
|
||||
|
||||
AbstractActionTool::AbstractActionTool(QObject *parent) : CaptureTool(parent) {
|
||||
AbstractActionTool::AbstractActionTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool AbstractActionTool::isValid() const {
|
||||
bool AbstractActionTool::isValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbstractActionTool::isSelectable() const {
|
||||
bool AbstractActionTool::isSelectable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractActionTool::showMousePreview() const {
|
||||
bool AbstractActionTool::showMousePreview() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbstractActionTool::undo(QPixmap &pixmap) {
|
||||
void AbstractActionTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
Q_UNUSED(pixmap);
|
||||
}
|
||||
|
||||
void AbstractActionTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void AbstractActionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(pixmap);
|
||||
Q_UNUSED(recordUndo);
|
||||
}
|
||||
|
||||
void AbstractActionTool::paintMousePreview(
|
||||
QPainter &painter, const CaptureContext &context)
|
||||
void AbstractActionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void AbstractActionTool::drawEnd(const QPoint &p) {
|
||||
void AbstractActionTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void AbstractActionTool::drawMove(const QPoint &p) {
|
||||
void AbstractActionTool::drawMove(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void AbstractActionTool::drawStart(const CaptureContext &context) {
|
||||
void AbstractActionTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void AbstractActionTool::colorChanged(const QColor &c) {
|
||||
void AbstractActionTool::colorChanged(const QColor& c)
|
||||
{
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
void AbstractActionTool::thicknessChanged(const int th) {
|
||||
void AbstractActionTool::thicknessChanged(const int th)
|
||||
{
|
||||
Q_UNUSED(th);
|
||||
}
|
||||
|
||||
@@ -19,23 +19,27 @@
|
||||
|
||||
#include "capturetool.h"
|
||||
|
||||
class AbstractActionTool : public CaptureTool {
|
||||
class AbstractActionTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractActionTool(QObject *parent = nullptr);
|
||||
explicit AbstractActionTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap &pixmap) override;
|
||||
void process(QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint &p) override;
|
||||
void drawMove(const QPoint &p) override;
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void colorChanged(const QColor &c) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
};
|
||||
|
||||
@@ -17,59 +17,69 @@
|
||||
|
||||
#include "abstractpathtool.h"
|
||||
|
||||
AbstractPathTool::AbstractPathTool(QObject *parent) :
|
||||
CaptureTool(parent), m_thickness(0), m_padding(0)
|
||||
AbstractPathTool::AbstractPathTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
, m_thickness(0)
|
||||
, m_padding(0)
|
||||
{}
|
||||
|
||||
bool AbstractPathTool::isValid() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool AbstractPathTool::isValid() const {
|
||||
return m_points.length() > 1;
|
||||
}
|
||||
|
||||
bool AbstractPathTool::closeOnButtonPressed() const {
|
||||
bool AbstractPathTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractPathTool::isSelectable() const {
|
||||
bool AbstractPathTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbstractPathTool::showMousePreview() const {
|
||||
bool AbstractPathTool::showMousePreview() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractPathTool::undo(QPixmap &pixmap) {
|
||||
void AbstractPathTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea + QMargins(val, val, val, val);
|
||||
p.drawPixmap(area.intersected(pixmap.rect())
|
||||
.topLeft(), m_pixmapBackup);
|
||||
p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
}
|
||||
|
||||
void AbstractPathTool::drawEnd(const QPoint &p) {
|
||||
void AbstractPathTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void AbstractPathTool::drawMove(const QPoint &p) {
|
||||
void AbstractPathTool::drawMove(const QPoint& p)
|
||||
{
|
||||
addPoint(p);
|
||||
}
|
||||
|
||||
void AbstractPathTool::colorChanged(const QColor &c) {
|
||||
void AbstractPathTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void AbstractPathTool::thicknessChanged(const int th) {
|
||||
void AbstractPathTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th;
|
||||
}
|
||||
|
||||
void AbstractPathTool::updateBackup(const QPixmap &pixmap) {
|
||||
void AbstractPathTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
const int val = m_thickness + m_padding;
|
||||
QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
|
||||
m_pixmapBackup = pixmap.copy(area);
|
||||
}
|
||||
|
||||
void AbstractPathTool::addPoint(const QPoint &point) {
|
||||
void AbstractPathTool::addPoint(const QPoint& point)
|
||||
{
|
||||
if (m_backupArea.left() > point.x()) {
|
||||
m_backupArea.setLeft(point.x());
|
||||
} else if (m_backupArea.right() < point.x()) {
|
||||
|
||||
@@ -19,27 +19,28 @@
|
||||
|
||||
#include "capturetool.h"
|
||||
|
||||
class AbstractPathTool : public CaptureTool {
|
||||
class AbstractPathTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractPathTool(QObject *parent = nullptr);
|
||||
explicit AbstractPathTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap &pixmap) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint &p) override;
|
||||
void drawMove(const QPoint &p) override;
|
||||
void colorChanged(const QColor &c) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
protected:
|
||||
void updateBackup(const QPixmap &pixmap);
|
||||
void addPoint(const QPoint &point);
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
void addPoint(const QPoint& point);
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QRect m_backupArea;
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace {
|
||||
const double ADJ_UNIT = std::atan(1.0);
|
||||
const int DIRS_NUMBER = 4;
|
||||
|
||||
enum UNIT {
|
||||
enum UNIT
|
||||
{
|
||||
HORIZ_DIR = 0,
|
||||
DIAG1_DIR = 1,
|
||||
VERT_DIR = 2,
|
||||
@@ -33,74 +34,90 @@ enum UNIT {
|
||||
const double ADJ_DIAG_UNIT = 2 * ADJ_UNIT;
|
||||
const int DIAG_DIRS_NUMBER = 2;
|
||||
|
||||
enum DIAG_UNIT {
|
||||
enum DIAG_UNIT
|
||||
{
|
||||
DIR1 = 0,
|
||||
DIR2 = 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
AbstractTwoPointTool::AbstractTwoPointTool(QObject *parent) :
|
||||
CaptureTool(parent), m_thickness(0), m_padding(0)
|
||||
AbstractTwoPointTool::AbstractTwoPointTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
, m_thickness(0)
|
||||
, m_padding(0)
|
||||
{}
|
||||
|
||||
bool AbstractTwoPointTool::isValid() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool AbstractTwoPointTool::isValid() const {
|
||||
return (m_points.first != m_points.second);
|
||||
}
|
||||
|
||||
bool AbstractTwoPointTool::closeOnButtonPressed() const {
|
||||
bool AbstractTwoPointTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractTwoPointTool::isSelectable() const {
|
||||
bool AbstractTwoPointTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbstractTwoPointTool::showMousePreview() const {
|
||||
bool AbstractTwoPointTool::showMousePreview() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::undo(QPixmap &pixmap) {
|
||||
void AbstractTwoPointTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawEnd(const QPoint &p) {
|
||||
void AbstractTwoPointTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawMove(const QPoint &p) {
|
||||
void AbstractTwoPointTool::drawMove(const QPoint& p)
|
||||
{
|
||||
m_points.second = p;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint &p) {
|
||||
void AbstractTwoPointTool::drawMoveWithAdjustment(const QPoint& p)
|
||||
{
|
||||
m_points.second = m_points.first + adjustedVector(p - m_points.first);
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::colorChanged(const QColor &c) {
|
||||
void AbstractTwoPointTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::thicknessChanged(const int th) {
|
||||
void AbstractTwoPointTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th;
|
||||
}
|
||||
|
||||
void AbstractTwoPointTool::updateBackup(const QPixmap &pixmap) {
|
||||
void AbstractTwoPointTool::updateBackup(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
|
||||
}
|
||||
|
||||
QRect AbstractTwoPointTool::backupRect(const QRect &limits) const {
|
||||
QRect AbstractTwoPointTool::backupRect(const QRect& limits) const
|
||||
{
|
||||
QRect r = QRect(m_points.first, m_points.second).normalized();
|
||||
const int val = m_thickness + m_padding;
|
||||
r += QMargins(val, val, val, val);
|
||||
return r.intersected(limits);
|
||||
}
|
||||
|
||||
QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const {
|
||||
QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const
|
||||
{
|
||||
if (m_supportsOrthogonalAdj && m_supportsDiagonalAdj) {
|
||||
int dir = ( static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) + DIRS_NUMBER ) % DIRS_NUMBER;
|
||||
int dir = (static_cast<int>(round(atan2(-v.y(), v.x()) / ADJ_UNIT)) +
|
||||
DIRS_NUMBER) %
|
||||
DIRS_NUMBER;
|
||||
if (dir == UNIT::HORIZ_DIR) {
|
||||
v.setY(0);
|
||||
} else if (dir == UNIT::VERT_DIR) {
|
||||
@@ -117,8 +134,11 @@ QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const {
|
||||
v.setY(newY);
|
||||
}
|
||||
} else if (m_supportsDiagonalAdj) {
|
||||
int dir = ( static_cast<int>(round((atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) / ADJ_DIAG_UNIT))
|
||||
+ DIAG_DIRS_NUMBER ) % DIAG_DIRS_NUMBER;
|
||||
int dir =
|
||||
(static_cast<int>(round((atan2(-v.y(), v.x()) - ADJ_DIAG_UNIT / 2) /
|
||||
ADJ_DIAG_UNIT)) +
|
||||
DIAG_DIRS_NUMBER) %
|
||||
DIAG_DIRS_NUMBER;
|
||||
if (dir == DIAG_UNIT::DIR1) {
|
||||
int newX = (v.x() - v.y()) / 2;
|
||||
int newY = -newX;
|
||||
|
||||
@@ -19,28 +19,29 @@
|
||||
|
||||
#include "capturetool.h"
|
||||
|
||||
class AbstractTwoPointTool : public CaptureTool {
|
||||
class AbstractTwoPointTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AbstractTwoPointTool(QObject *parent = nullptr);
|
||||
explicit AbstractTwoPointTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
void undo(QPixmap &pixmap) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint &p) override;
|
||||
void drawMove(const QPoint &p) override;
|
||||
void drawMoveWithAdjustment(const QPoint &p) override;
|
||||
void colorChanged(const QColor &c) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawMoveWithAdjustment(const QPoint& p) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
protected:
|
||||
void updateBackup(const QPixmap &pixmap);
|
||||
QRect backupRect(const QRect &limits) const;
|
||||
void updateBackup(const QPixmap& pixmap);
|
||||
QRect backupRect(const QRect& limits) const;
|
||||
|
||||
QPixmap m_pixmapBackup;
|
||||
QPair<QPoint, QPoint> m_points;
|
||||
|
||||
@@ -24,25 +24,26 @@ namespace {
|
||||
const int ArrowWidth = 10;
|
||||
const int ArrowHeight = 18;
|
||||
|
||||
QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
|
||||
QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness)
|
||||
{
|
||||
QLineF base(p1, p2);
|
||||
// Create the vector for the position of the base of the arrowhead
|
||||
QLineF temp(QPoint(0,0), p2-p1);
|
||||
int val = ArrowHeight + thickness*4;
|
||||
QLineF temp(QPoint(0, 0), p2 - p1);
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (base.length() < val) {
|
||||
val = (base.length() + thickness*2);
|
||||
val = (base.length() + thickness * 2);
|
||||
}
|
||||
temp.setLength(base.length() + thickness*2 - val);
|
||||
temp.setLength(base.length() + thickness * 2 - val);
|
||||
// Move across the line up to the head
|
||||
QPointF bottonTranslation(temp.p2());
|
||||
|
||||
// Rotate base of the arrowhead
|
||||
base.setLength(ArrowWidth + thickness*2);
|
||||
base.setLength(ArrowWidth + thickness * 2);
|
||||
base.setAngle(base.angle() + 90);
|
||||
// Move to the correct point
|
||||
QPointF temp2 = p1 - base.p2();
|
||||
// Center it
|
||||
QPointF centerTranslation((temp2.x()/2), (temp2.y()/2));
|
||||
QPointF centerTranslation((temp2.x() / 2), (temp2.y() / 2));
|
||||
|
||||
base.translate(bottonTranslation);
|
||||
base.translate(centerTranslation);
|
||||
@@ -56,65 +57,82 @@ QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
|
||||
}
|
||||
|
||||
// gets a shorter line to prevent overlap in the point of the arrow
|
||||
QLine getShorterLine(QPoint p1, QPoint p2, const int thickness) {
|
||||
QLine getShorterLine(QPoint p1, QPoint p2, const int thickness)
|
||||
{
|
||||
QLineF l(p1, p2);
|
||||
int val = ArrowHeight + thickness*4;
|
||||
int val = ArrowHeight + thickness * 4;
|
||||
if (l.length() < val) {
|
||||
val = (l.length() + thickness*2);
|
||||
val = (l.length() + thickness * 2);
|
||||
}
|
||||
l.setLength(l.length() + thickness*2 - val);
|
||||
l.setLength(l.length() + thickness * 2 - val);
|
||||
return l.toLine();
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
ArrowTool::ArrowTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
ArrowTool::ArrowTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_padding = ArrowWidth / 2;
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon ArrowTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon ArrowTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "arrow-bottom-left.svg");
|
||||
}
|
||||
QString ArrowTool::name() const {
|
||||
QString ArrowTool::name() const
|
||||
{
|
||||
return tr("Arrow");
|
||||
}
|
||||
|
||||
QString ArrowTool::nameID() {
|
||||
QString ArrowTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString ArrowTool::description() const {
|
||||
QString ArrowTool::description() const
|
||||
{
|
||||
return tr("Set the Arrow as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* ArrowTool::copy(QObject *parent) {
|
||||
CaptureTool* ArrowTool::copy(QObject* parent)
|
||||
{
|
||||
return new ArrowTool(parent);
|
||||
}
|
||||
|
||||
void ArrowTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void ArrowTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
painter.setPen(QPen(m_color, m_thickness));
|
||||
painter.drawLine(getShorterLine(m_points.first, m_points.second, m_thickness));
|
||||
painter.fillPath(getArrowHead(m_points.first, m_points.second, m_thickness), QBrush(m_color));
|
||||
painter.drawLine(
|
||||
getShorterLine(m_points.first, m_points.second, m_thickness));
|
||||
painter.fillPath(getArrowHead(m_points.first, m_points.second, m_thickness),
|
||||
QBrush(m_color));
|
||||
}
|
||||
|
||||
void ArrowTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void ArrowTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void ArrowTool::drawStart(const CaptureContext &context) {
|
||||
void ArrowTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void ArrowTool::pressed(const CaptureContext &context) {
|
||||
void ArrowTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -20,22 +20,25 @@
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
#include <QPainter>
|
||||
|
||||
class ArrowTool : public AbstractTwoPointTool {
|
||||
class ArrowTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArrowTool(QObject *parent = nullptr);
|
||||
explicit ArrowTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -16,51 +16,60 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "blurtool.h"
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsScene>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
BlurTool::BlurTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
BlurTool::BlurTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
QIcon BlurTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon BlurTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "blur.svg");
|
||||
}
|
||||
QString BlurTool::name() const {
|
||||
QString BlurTool::name() const
|
||||
{
|
||||
return tr("Blur");
|
||||
}
|
||||
|
||||
QString BlurTool::nameID() {
|
||||
QString BlurTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString BlurTool::description() const {
|
||||
QString BlurTool::description() const
|
||||
{
|
||||
return tr("Set Blur as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* BlurTool::copy(QObject *parent) {
|
||||
CaptureTool* BlurTool::copy(QObject* parent)
|
||||
{
|
||||
return new BlurTool(parent);
|
||||
}
|
||||
|
||||
void BlurTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void BlurTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
QPoint &p0 = m_points.first;
|
||||
QPoint &p1 = m_points.second;
|
||||
QPoint& p0 = m_points.first;
|
||||
QPoint& p1 = m_points.second;
|
||||
auto pixelRatio = pixmap.devicePixelRatio();
|
||||
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
QRect selectionScaled = QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
QRect selectionScaled =
|
||||
QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
|
||||
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect;
|
||||
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
|
||||
blur->setBlurRadius(10);
|
||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem (
|
||||
pixmap.copy(selectionScaled));
|
||||
QGraphicsPixmapItem* item =
|
||||
new QGraphicsPixmapItem(pixmap.copy(selectionScaled));
|
||||
item->setGraphicsEffect(blur);
|
||||
|
||||
QGraphicsScene scene;
|
||||
@@ -68,22 +77,26 @@ void BlurTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo
|
||||
|
||||
scene.render(&painter, selection, QRectF());
|
||||
blur->setBlurRadius(12);
|
||||
for(int cnt = 100; cnt > 0; cnt--){
|
||||
for (int cnt = 100; cnt > 0; cnt--) {
|
||||
scene.render(&painter, selection, QRectF());
|
||||
}
|
||||
}
|
||||
|
||||
void BlurTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void BlurTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Q_UNUSED(painter);
|
||||
}
|
||||
|
||||
void BlurTool::drawStart(const CaptureContext &context) {
|
||||
void BlurTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_thickness = context.thickness;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void BlurTool::pressed(const CaptureContext &context) {
|
||||
void BlurTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,22 +19,25 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class BlurTool : public AbstractTwoPointTool {
|
||||
class BlurTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BlurTool(QObject *parent = nullptr);
|
||||
explicit BlurTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
#include "capturecontext.h"
|
||||
|
||||
QPixmap CaptureContext::selectedScreenshotArea() const {
|
||||
QPixmap CaptureContext::selectedScreenshotArea() const
|
||||
{
|
||||
if (selection.isNull()) {
|
||||
return screenshot;
|
||||
} else {
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QRect>
|
||||
#include <QPoint>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
|
||||
struct CaptureContext {
|
||||
struct CaptureContext
|
||||
{
|
||||
// screenshot with modifications
|
||||
QPixmap screenshot;
|
||||
// unmodified screenshot
|
||||
@@ -44,5 +45,5 @@ struct CaptureContext {
|
||||
// Mode of the capture widget
|
||||
bool fullscreen;
|
||||
|
||||
QPixmap selectedScreenshotArea() const ;
|
||||
QPixmap selectedScreenshotArea() const;
|
||||
};
|
||||
|
||||
@@ -23,12 +23,14 @@
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
|
||||
class CaptureTool : public QObject {
|
||||
class CaptureTool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Request actions on the main widget
|
||||
enum Request {
|
||||
enum Request
|
||||
{
|
||||
// Call close() in the editor.
|
||||
REQ_CLOSE_GUI,
|
||||
// Call hide() in the editor.
|
||||
@@ -64,9 +66,11 @@ public:
|
||||
REQ_ADD_EXTERNAL_WIDGETS,
|
||||
};
|
||||
|
||||
explicit CaptureTool(QObject *parent = nullptr) : QObject(parent){}
|
||||
explicit CaptureTool(QObject* parent = nullptr)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
virtual void setCapture(const QPixmap &pixmap) {};
|
||||
virtual void setCapture(const QPixmap& pixmap){};
|
||||
|
||||
// Returns false when the tool is in an inconsistent state and shouldn't
|
||||
// be included in the tool undo/redo stack.
|
||||
@@ -82,8 +86,7 @@ public:
|
||||
// The icon of the tool.
|
||||
// inEditor is true when the icon is requested inside the editor
|
||||
// and false otherwise.
|
||||
virtual QIcon icon(const QColor &background,
|
||||
bool inEditor) const = 0;
|
||||
virtual QIcon icon(const QColor& background, bool inEditor) const = 0;
|
||||
// Name displayed for the tool, this could be translated with tr()
|
||||
virtual QString name() const = 0;
|
||||
// Codename for the tool, this hsouldn't change as it is used as ID
|
||||
@@ -95,59 +98,53 @@ public:
|
||||
// if the type is TYPE_WIDGET the widget is loaded in the main widget.
|
||||
// If the type is TYPE_EXTERNAL_WIDGET it is created outside as an
|
||||
// individual widget.
|
||||
virtual QWidget* widget() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual QWidget* widget() { return nullptr; }
|
||||
// When the tool is selected this method is called and the widget is added
|
||||
// to the configuration panel inside the main widget.
|
||||
virtual QWidget* configurationWidget() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual QWidget* configurationWidget() { return nullptr; }
|
||||
// Permanent configuration used in the configuration outside of the
|
||||
// capture.
|
||||
virtual QWidget* permanentConfigurationWidget() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual QWidget* permanentConfigurationWidget() { return nullptr; }
|
||||
// Return a copy of the tool
|
||||
virtual CaptureTool* copy(QObject *parent = nullptr) = 0;
|
||||
virtual CaptureTool* copy(QObject* parent = nullptr) = 0;
|
||||
|
||||
// revert changes
|
||||
virtual void undo(QPixmap &pixmap) = 0;
|
||||
virtual void undo(QPixmap& pixmap) = 0;
|
||||
// Called every time the tool has to draw
|
||||
// recordUndo indicates when the tool should save the information
|
||||
// for the undo(), if the value is false calling undo() after
|
||||
// that process should not modify revert the changes.
|
||||
virtual void process(QPainter &painter,
|
||||
const QPixmap &pixmap,
|
||||
virtual void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) = 0;
|
||||
// When the tool is selected, this is called when the mouse moves
|
||||
virtual void paintMousePreview(QPainter &painter, const CaptureContext &context) = 0;
|
||||
virtual void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) = 0;
|
||||
|
||||
signals:
|
||||
void requestAction(Request r);
|
||||
|
||||
protected:
|
||||
QString iconPath(const QColor &c) const {
|
||||
return ColorUtils::colorIsDark(c) ?
|
||||
PathInfo::whiteIconPath() : PathInfo::blackIconPath();
|
||||
QString iconPath(const QColor& c) const
|
||||
{
|
||||
return ColorUtils::colorIsDark(c) ? PathInfo::whiteIconPath()
|
||||
: PathInfo::blackIconPath();
|
||||
}
|
||||
|
||||
public slots:
|
||||
// On mouse release.
|
||||
virtual void drawEnd(const QPoint &p) = 0;
|
||||
virtual void drawEnd(const QPoint& p) = 0;
|
||||
// Mouse pressed and moving, called once a pixel.
|
||||
virtual void drawMove(const QPoint &p) = 0;
|
||||
virtual void drawMove(const QPoint& p) = 0;
|
||||
// Called when drawMove is needed with an adjustment;
|
||||
// should be overridden in case an adjustment is applicable.
|
||||
virtual void drawMoveWithAdjustment(const QPoint &p) {
|
||||
drawMove(p);
|
||||
}
|
||||
virtual void drawMoveWithAdjustment(const QPoint& p) { drawMove(p); }
|
||||
// Called when the tool is activated.
|
||||
virtual void drawStart(const CaptureContext &context) = 0;
|
||||
virtual void drawStart(const CaptureContext& context) = 0;
|
||||
// Called right after pressign the button which activates the tool.
|
||||
virtual void pressed(const CaptureContext &context) = 0;
|
||||
virtual void pressed(const CaptureContext& context) = 0;
|
||||
// Called when the color is changed in the editor.
|
||||
virtual void colorChanged(const QColor &c) = 0;
|
||||
virtual void colorChanged(const QColor& c) = 0;
|
||||
// Called when the thickness of the tool is updated in the editor.
|
||||
virtual void thicknessChanged(const int th) = 0;
|
||||
};
|
||||
|
||||
@@ -22,31 +22,41 @@ namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
CircleTool::CircleTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
CircleTool::CircleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon CircleTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon CircleTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "circle-outline.svg");
|
||||
}
|
||||
QString CircleTool::name() const {
|
||||
QString CircleTool::name() const
|
||||
{
|
||||
return tr("Circle");
|
||||
}
|
||||
|
||||
QString CircleTool::nameID() {
|
||||
QString CircleTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString CircleTool::description() const {
|
||||
QString CircleTool::description() const
|
||||
{
|
||||
return tr("Set the Circle as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* CircleTool::copy(QObject *parent) {
|
||||
CaptureTool* CircleTool::copy(QObject* parent)
|
||||
{
|
||||
return new CircleTool(parent);
|
||||
}
|
||||
|
||||
void CircleTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void CircleTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -54,18 +64,22 @@ void CircleTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUn
|
||||
painter.drawEllipse(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void CircleTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void CircleTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void CircleTool::drawStart(const CaptureContext &context) {
|
||||
void CircleTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void CircleTool::pressed(const CaptureContext &context) {
|
||||
void CircleTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,22 +19,25 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class CircleTool : public AbstractTwoPointTool {
|
||||
class CircleTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CircleTool(QObject *parent = nullptr);
|
||||
explicit CircleTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -19,35 +19,42 @@
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include <QPainter>
|
||||
|
||||
CopyTool::CopyTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
CopyTool::CopyTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool CopyTool::closeOnButtonPressed() const {
|
||||
bool CopyTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon CopyTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon CopyTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-copy.svg");
|
||||
}
|
||||
QString CopyTool::name() const {
|
||||
QString CopyTool::name() const
|
||||
{
|
||||
return tr("Copy");
|
||||
}
|
||||
|
||||
QString CopyTool::nameID() {
|
||||
QString CopyTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString CopyTool::description() const {
|
||||
QString CopyTool::description() const
|
||||
{
|
||||
return tr("Copy the selection into the clipboard");
|
||||
}
|
||||
|
||||
CaptureTool* CopyTool::copy(QObject *parent) {
|
||||
CaptureTool* CopyTool::copy(QObject* parent)
|
||||
{
|
||||
return new CopyTool(parent);
|
||||
}
|
||||
|
||||
void CopyTool::pressed(const CaptureContext &context) {
|
||||
void CopyTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class CopyTool : public AbstractActionTool {
|
||||
class CopyTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CopyTool(QObject *parent = nullptr);
|
||||
explicit CopyTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,35 +18,42 @@
|
||||
#include "exittool.h"
|
||||
#include <QPainter>
|
||||
|
||||
ExitTool::ExitTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
ExitTool::ExitTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool ExitTool::closeOnButtonPressed() const {
|
||||
bool ExitTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon ExitTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon ExitTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "close.svg");
|
||||
}
|
||||
QString ExitTool::name() const {
|
||||
QString ExitTool::name() const
|
||||
{
|
||||
return tr("Exit");
|
||||
}
|
||||
|
||||
QString ExitTool::nameID() {
|
||||
QString ExitTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString ExitTool::description() const {
|
||||
QString ExitTool::description() const
|
||||
{
|
||||
return tr("Leave the capture screen");
|
||||
}
|
||||
|
||||
CaptureTool* ExitTool::copy(QObject *parent) {
|
||||
CaptureTool* ExitTool::copy(QObject* parent)
|
||||
{
|
||||
return new ExitTool(parent);
|
||||
}
|
||||
|
||||
void ExitTool::pressed(const CaptureContext &context) {
|
||||
void ExitTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_CLOSE_GUI);
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class ExitTool : public AbstractActionTool {
|
||||
class ExitTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ExitTool(QObject *parent = nullptr);
|
||||
explicit ExitTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,39 +18,47 @@
|
||||
#include "applaunchertool.h"
|
||||
#include "applauncherwidget.h"
|
||||
|
||||
AppLauncher::AppLauncher(QObject *parent) : AbstractActionTool(parent) {
|
||||
AppLauncher::AppLauncher(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool AppLauncher::closeOnButtonPressed() const {
|
||||
bool AppLauncher::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon AppLauncher::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon AppLauncher::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "open_with.svg");
|
||||
}
|
||||
QString AppLauncher::name() const {
|
||||
QString AppLauncher::name() const
|
||||
{
|
||||
return tr("App Launcher");
|
||||
}
|
||||
|
||||
QString AppLauncher::nameID() {
|
||||
QString AppLauncher::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString AppLauncher::description() const {
|
||||
QString AppLauncher::description() const
|
||||
{
|
||||
return tr("Choose an app to open the capture");
|
||||
}
|
||||
|
||||
QWidget* AppLauncher::widget() {
|
||||
QWidget* AppLauncher::widget()
|
||||
{
|
||||
return new AppLauncherWidget(capture);
|
||||
}
|
||||
|
||||
CaptureTool* AppLauncher::copy(QObject *parent) {
|
||||
CaptureTool* AppLauncher::copy(QObject* parent)
|
||||
{
|
||||
return new AppLauncher(parent);
|
||||
}
|
||||
|
||||
void AppLauncher::pressed(const CaptureContext &context) {
|
||||
void AppLauncher::pressed(const CaptureContext& context)
|
||||
{
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
|
||||
@@ -19,24 +19,25 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class AppLauncher : public AbstractActionTool {
|
||||
class AppLauncher : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncher(QObject *parent = nullptr);
|
||||
explicit AppLauncher(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap capture;
|
||||
|
||||
@@ -16,40 +16,40 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "applauncherwidget.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/tools/launcher/launcheritemdelegate.h"
|
||||
#include "src/utils/globalvalues.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/globalvalues.h"
|
||||
#include "terminallauncher.h"
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QProcess>
|
||||
#include <QPixmap>
|
||||
#include <QListView>
|
||||
#include <QTabWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QHBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QDir>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QList>
|
||||
#include <QListView>
|
||||
#include <QListWidgetItem>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
#include <QProcess>
|
||||
#include <QTabWidget>
|
||||
|
||||
namespace {
|
||||
|
||||
QMap<QString, QString> catIconNames({
|
||||
{ "Multimedia", "applications-multimedia" },
|
||||
{ "Development","applications-development" },
|
||||
QMap<QString, QString> catIconNames(
|
||||
{ { "Multimedia", "applications-multimedia" },
|
||||
{ "Development", "applications-development" },
|
||||
{ "Graphics", "applications-graphics" },
|
||||
{ "Network", "preferences-system-network" },
|
||||
{ "Office", "applications-office" },
|
||||
{ "Science", "applications-science" },
|
||||
{ "Settings", "preferences-desktop" },
|
||||
{ "System", "preferences-system" },
|
||||
{ "Utility", "applications-utilities" }
|
||||
});
|
||||
{ "Utility", "applications-utilities" } });
|
||||
}
|
||||
|
||||
AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
QWidget(parent), m_pixmap(p)
|
||||
AppLauncherWidget::AppLauncherWidget(const QPixmap& p, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_pixmap(p)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
@@ -71,16 +71,22 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
m_terminalCheckbox = new QCheckBox(tr("Launch in terminal"), this);
|
||||
m_keepOpenCheckbox = new QCheckBox(tr("Keep open after selection"), this);
|
||||
m_keepOpenCheckbox->setChecked(ConfigHandler().keepOpenAppLauncherValue());
|
||||
connect(m_keepOpenCheckbox, &QCheckBox::clicked, this, &AppLauncherWidget::checkboxClicked);
|
||||
connect(m_keepOpenCheckbox,
|
||||
&QCheckBox::clicked,
|
||||
this,
|
||||
&AppLauncherWidget::checkboxClicked);
|
||||
|
||||
// search items
|
||||
m_lineEdit = new QLineEdit;
|
||||
connect(m_lineEdit, &QLineEdit::textChanged,
|
||||
this, &AppLauncherWidget::searchChanged);
|
||||
connect(m_lineEdit,
|
||||
&QLineEdit::textChanged,
|
||||
this,
|
||||
&AppLauncherWidget::searchChanged);
|
||||
m_filterList = new QListWidget;
|
||||
m_filterList->hide();
|
||||
configureListView(m_filterList);
|
||||
connect(m_filterList, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
connect(
|
||||
m_filterList, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->addWidget(m_filterList);
|
||||
@@ -91,25 +97,28 @@ AppLauncherWidget::AppLauncherWidget(const QPixmap &p, QWidget *parent):
|
||||
m_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
void AppLauncherWidget::launch(const QModelIndex &index) {
|
||||
void AppLauncherWidget::launch(const QModelIndex& index)
|
||||
{
|
||||
if (!QFileInfo(m_tempFile).isReadable()) {
|
||||
m_tempFile = FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
m_tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = m_pixmap.save(m_tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(this, tr("Error"), tr("Unable to write in")
|
||||
+ QDir::tempPath());
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to write in") + QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
QString command = index.data(Qt::UserRole).toString().replace(
|
||||
QRegExp("(\\%.)"), '"' + m_tempFile + '"');
|
||||
bool inTerminal = index.data(Qt::UserRole+1).toBool() ||
|
||||
m_terminalCheckbox->isChecked();
|
||||
QString command = index.data(Qt::UserRole)
|
||||
.toString()
|
||||
.replace(QRegExp("(\\%.)"), '"' + m_tempFile + '"');
|
||||
bool inTerminal =
|
||||
index.data(Qt::UserRole + 1).toBool() || m_terminalCheckbox->isChecked();
|
||||
if (inTerminal) {
|
||||
bool ok = TerminalLauncher::launchDetached(command);
|
||||
if (!ok) {
|
||||
QMessageBox::about(this, tr("Error"),
|
||||
tr("Unable to launch in terminal."));
|
||||
QMessageBox::about(
|
||||
this, tr("Error"), tr("Unable to launch in terminal."));
|
||||
}
|
||||
} else {
|
||||
QProcess::startDetached(command);
|
||||
@@ -119,13 +128,15 @@ void AppLauncherWidget::launch(const QModelIndex &index) {
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::checkboxClicked(const bool enabled) {
|
||||
void AppLauncherWidget::checkboxClicked(const bool enabled)
|
||||
{
|
||||
m_keepOpen = enabled;
|
||||
ConfigHandler().setKeepOpenAppLauncher(enabled);
|
||||
m_keepOpenCheckbox->setChecked(enabled);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::searchChanged(const QString &text) {
|
||||
void AppLauncherWidget::searchChanged(const QString& text)
|
||||
{
|
||||
if (text.isEmpty()) {
|
||||
m_filterList->hide();
|
||||
m_tabWidget->show();
|
||||
@@ -137,15 +148,14 @@ void AppLauncherWidget::searchChanged(const QString &text) {
|
||||
QVector<DesktopAppData> apps;
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString& cat = i.first;
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
const QVector<DesktopAppData> &appList = m_appsMap[cat];
|
||||
for (const DesktopAppData &app: appList) {
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
for (const DesktopAppData& app : appList) {
|
||||
if (!apps.contains(app) && (app.name.contains(regexp) ||
|
||||
app.description.contains(regexp) ))
|
||||
{
|
||||
app.description.contains(regexp))) {
|
||||
apps.append(app);
|
||||
}
|
||||
}
|
||||
@@ -154,35 +164,38 @@ void AppLauncherWidget::searchChanged(const QString &text) {
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::initListWidget() {
|
||||
void AppLauncherWidget::initListWidget()
|
||||
{
|
||||
m_tabWidget = new QTabWidget;
|
||||
const int size = GlobalValues::buttonBaseSize();
|
||||
m_tabWidget->setIconSize(QSize(size, size));
|
||||
|
||||
for (auto const& i : catIconNames.toStdMap()) {
|
||||
const QString &cat = i.first;
|
||||
const QString &iconName = i.second;
|
||||
const QString& cat = i.first;
|
||||
const QString& iconName = i.second;
|
||||
|
||||
if (!m_appsMap.contains(cat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QListWidget *itemsWidget = new QListWidget();
|
||||
QListWidget* itemsWidget = new QListWidget();
|
||||
configureListView(itemsWidget);
|
||||
|
||||
const QVector<DesktopAppData> &appList = m_appsMap[cat];
|
||||
const QVector<DesktopAppData>& appList = m_appsMap[cat];
|
||||
addAppsToListWidget(itemsWidget, appList);
|
||||
|
||||
m_tabWidget->addTab(itemsWidget, QIcon::fromTheme(iconName), QLatin1String(""));
|
||||
m_tabWidget->addTab(
|
||||
itemsWidget, QIcon::fromTheme(iconName), QLatin1String(""));
|
||||
m_tabWidget->setTabToolTip(m_tabWidget->count(), cat);
|
||||
if (cat == QLatin1String("Graphics")) {
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->count() -1);
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppLauncherWidget::initAppMap() {
|
||||
QStringList categories({"AudioVideo",
|
||||
void AppLauncherWidget::initAppMap()
|
||||
{
|
||||
QStringList categories({ "AudioVideo",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Development",
|
||||
@@ -192,16 +205,17 @@ void AppLauncherWidget::initAppMap() {
|
||||
"Science",
|
||||
"Settings",
|
||||
"System",
|
||||
"Utility"});
|
||||
"Utility" });
|
||||
|
||||
m_appsMap = m_parser.getAppsByCategory(categories);
|
||||
|
||||
// Unify multimedia.
|
||||
QVector<DesktopAppData> multimediaList;
|
||||
QStringList multimediaNames;
|
||||
multimediaNames << QStringLiteral("AudioVideo") << QStringLiteral("Audio") << QStringLiteral("Video");
|
||||
for (const QString &name : multimediaNames) {
|
||||
if(!m_appsMap.contains(name)) {
|
||||
multimediaNames << QStringLiteral("AudioVideo") << QStringLiteral("Audio")
|
||||
<< QStringLiteral("Video");
|
||||
for (const QString& name : multimediaNames) {
|
||||
if (!m_appsMap.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : m_appsMap[name]) {
|
||||
@@ -214,7 +228,8 @@ void AppLauncherWidget::initAppMap() {
|
||||
m_appsMap.insert(QStringLiteral("Multimedia"), multimediaList);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::configureListView(QListWidget *widget) {
|
||||
void AppLauncherWidget::configureListView(QListWidget* widget)
|
||||
{
|
||||
widget->setItemDelegate(new LauncherItemDelegate());
|
||||
widget->setViewMode(QListWidget::IconMode);
|
||||
widget->setResizeMode(QListView::Adjust);
|
||||
@@ -222,19 +237,19 @@ void AppLauncherWidget::configureListView(QListWidget *widget) {
|
||||
widget->setFlow(QListView::LeftToRight);
|
||||
widget->setDragEnabled(false);
|
||||
widget->setMinimumWidth(GlobalValues::buttonBaseSize() * 11);
|
||||
connect(widget, &QListWidget::clicked,
|
||||
this, &AppLauncherWidget::launch);
|
||||
connect(widget, &QListWidget::clicked, this, &AppLauncherWidget::launch);
|
||||
}
|
||||
|
||||
void AppLauncherWidget::addAppsToListWidget(
|
||||
QListWidget *widget, const QVector<DesktopAppData> &appList)
|
||||
QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList)
|
||||
{
|
||||
for (const DesktopAppData &app: appList) {
|
||||
QListWidgetItem *buttonItem = new QListWidgetItem(widget);
|
||||
for (const DesktopAppData& app : appList) {
|
||||
QListWidgetItem* buttonItem = new QListWidgetItem(widget);
|
||||
buttonItem->setData(Qt::DecorationRole, app.icon);
|
||||
buttonItem->setData(Qt::DisplayRole, app.name);
|
||||
buttonItem->setData(Qt::UserRole, app.exec);
|
||||
buttonItem->setData(Qt::UserRole+1, app.showInTerminal);
|
||||
buttonItem->setData(Qt::UserRole + 1, app.showInTerminal);
|
||||
QColor foregroundColor =
|
||||
this->palette().color(QWidget::foregroundRole());
|
||||
buttonItem->setForeground(foregroundColor);
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include <QWidget>
|
||||
|
||||
class QTabWidget;
|
||||
class QCheckBox;
|
||||
@@ -27,32 +27,33 @@ class QVBoxLayout;
|
||||
class QLineEdit;
|
||||
class QListWidget;
|
||||
|
||||
class AppLauncherWidget: public QWidget {
|
||||
class AppLauncherWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppLauncherWidget(const QPixmap &p, QWidget *parent = nullptr);
|
||||
explicit AppLauncherWidget(const QPixmap& p, QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void launch(const QModelIndex &index);
|
||||
void launch(const QModelIndex& index);
|
||||
void checkboxClicked(const bool enabled);
|
||||
void searchChanged(const QString &text);
|
||||
void searchChanged(const QString& text);
|
||||
|
||||
private:
|
||||
void initListWidget();
|
||||
void initAppMap();
|
||||
void configureListView(QListWidget *widget);
|
||||
void addAppsToListWidget(QListWidget *widget,
|
||||
const QVector<DesktopAppData> &appList);
|
||||
void configureListView(QListWidget* widget);
|
||||
void addAppsToListWidget(QListWidget* widget,
|
||||
const QVector<DesktopAppData>& appList);
|
||||
|
||||
DesktopFileParser m_parser;
|
||||
QPixmap m_pixmap;
|
||||
QString m_tempFile;
|
||||
bool m_keepOpen;
|
||||
QMap<QString, QVector<DesktopAppData>> m_appsMap;
|
||||
QCheckBox *m_keepOpenCheckbox;
|
||||
QCheckBox *m_terminalCheckbox;
|
||||
QVBoxLayout *m_layout;
|
||||
QLineEdit *m_lineEdit;
|
||||
QListWidget *m_filterList;
|
||||
QTabWidget *m_tabWidget;
|
||||
QCheckBox* m_keepOpenCheckbox;
|
||||
QCheckBox* m_terminalCheckbox;
|
||||
QVBoxLayout* m_layout;
|
||||
QLineEdit* m_lineEdit;
|
||||
QListWidget* m_filterList;
|
||||
QTabWidget* m_tabWidget;
|
||||
};
|
||||
|
||||
@@ -19,45 +19,45 @@
|
||||
#include "src/utils/globalvalues.h"
|
||||
#include <QPainter>
|
||||
|
||||
LauncherItemDelegate::LauncherItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
LauncherItemDelegate::LauncherItemDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{}
|
||||
|
||||
void LauncherItemDelegate::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
void LauncherItemDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
const QRect &rect = option.rect;
|
||||
const QRect& rect = option.rect;
|
||||
if (option.state & (QStyle::State_Selected | QStyle::State_MouseOver)) {
|
||||
painter->save();
|
||||
painter->setPen(Qt::transparent);
|
||||
painter->setBrush(QPalette().highlight());
|
||||
painter->drawRect(rect.x(), rect.y(),
|
||||
rect.width() -1, rect.height() -1);
|
||||
painter->drawRect(
|
||||
rect.x(), rect.y(), rect.width() - 1, rect.height() - 1);
|
||||
painter->restore();
|
||||
}
|
||||
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
|
||||
const int iconSide = GlobalValues::buttonBaseSize() * 1.3;
|
||||
const int halfIcon = iconSide/2;
|
||||
const int halfWidth = rect.width()/2;
|
||||
const int halfHeight = rect.height()/2;
|
||||
const int halfIcon = iconSide / 2;
|
||||
const int halfWidth = rect.width() / 2;
|
||||
const int halfHeight = rect.height() / 2;
|
||||
QSize size(iconSide, iconSide);
|
||||
QPixmap pixIcon = icon.pixmap(size).scaled(size, Qt::KeepAspectRatio);
|
||||
painter->drawPixmap(rect.x() + (halfWidth - halfIcon),
|
||||
rect.y()+ (halfHeight/2 - halfIcon),
|
||||
iconSide, iconSide, pixIcon);
|
||||
const QRect textRect(rect.x(), rect.y() + halfHeight,
|
||||
rect.width(), halfHeight);
|
||||
painter->drawText(textRect, Qt::TextWordWrap | Qt::AlignHCenter,
|
||||
rect.y() + (halfHeight / 2 - halfIcon),
|
||||
iconSide,
|
||||
iconSide,
|
||||
pixIcon);
|
||||
const QRect textRect(
|
||||
rect.x(), rect.y() + halfHeight, rect.width(), halfHeight);
|
||||
painter->drawText(textRect,
|
||||
Qt::TextWordWrap | Qt::AlignHCenter,
|
||||
index.data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
QSize LauncherItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
QSize LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
|
||||
@@ -20,14 +20,16 @@
|
||||
#include "src/utils/desktopfileparse.h"
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class LauncherItemDelegate : public QStyledItemDelegate {
|
||||
class LauncherItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LauncherItemDelegate(QObject *parent = nullptr);
|
||||
explicit LauncherItemDelegate(QObject* parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
void paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
@@ -15,29 +15,31 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "openwithprogram.h"
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <windows.h>
|
||||
#include <Shlobj.h>
|
||||
#include <windows.h>
|
||||
|
||||
#pragma comment(lib, "Shell32.lib")
|
||||
#else
|
||||
#include "src/tools/launcher/applauncherwidget.h"
|
||||
#endif
|
||||
|
||||
void showOpenWithMenu(const QPixmap &capture) {
|
||||
void showOpenWithMenu(const QPixmap& capture)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
QString tempFile =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
bool ok = capture.save(tempFile);
|
||||
if (!ok) {
|
||||
QMessageBox::about(nullptr, QObject::tr("Error"),
|
||||
QObject::tr("Unable to write in") + QDir::tempPath());
|
||||
QMessageBox::about(nullptr,
|
||||
QObject::tr("Error"),
|
||||
QObject::tr("Unable to write in") +
|
||||
QDir::tempPath());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,4 @@
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
void showOpenWithMenu(const QPixmap &capture);
|
||||
void showOpenWithMenu(const QPixmap& capture);
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "terminallauncher.h"
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace {
|
||||
static const TerminalApp terminalApps[] = {
|
||||
static const TerminalApp terminalApps[] = {
|
||||
{ "x-terminal-emulator", "-e" },
|
||||
{ "xfce4-terminal", "-x" },
|
||||
{ "konsole", "-e" },
|
||||
@@ -35,15 +35,17 @@ namespace {
|
||||
{ "Eterm", "-e" },
|
||||
{ "rxvt", "-e" },
|
||||
{ "urxvt", "-e" },
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
TerminalLauncher::TerminalLauncher(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
TerminalLauncher::TerminalLauncher(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
TerminalApp TerminalLauncher::getPreferedTerminal() {
|
||||
TerminalApp TerminalLauncher::getPreferedTerminal()
|
||||
{
|
||||
TerminalApp res;
|
||||
for (const TerminalApp &app : terminalApps) {
|
||||
for (const TerminalApp& app : terminalApps) {
|
||||
QString path = QStandardPaths::findExecutable(app.name);
|
||||
if (!path.isEmpty()) {
|
||||
res = app;
|
||||
@@ -53,7 +55,8 @@ TerminalApp TerminalLauncher::getPreferedTerminal() {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool TerminalLauncher::launchDetached(const QString &command) {
|
||||
bool TerminalLauncher::launchDetached(const QString& command)
|
||||
{
|
||||
TerminalApp app = getPreferedTerminal();
|
||||
QString s = app.name + " " + app.arg + " " + command;
|
||||
return QProcess::startDetached(s);
|
||||
|
||||
@@ -19,17 +19,20 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
struct TerminalApp {
|
||||
struct TerminalApp
|
||||
{
|
||||
QString name;
|
||||
QString arg;
|
||||
};
|
||||
|
||||
class TerminalLauncher : public QObject {
|
||||
class TerminalLauncher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TerminalLauncher(QObject *parent = nullptr);
|
||||
explicit TerminalLauncher(QObject* parent = nullptr);
|
||||
|
||||
static bool launchDetached(const QString& command);
|
||||
|
||||
static bool launchDetached(const QString &command);
|
||||
private:
|
||||
static TerminalApp getPreferedTerminal();
|
||||
};
|
||||
|
||||
@@ -24,32 +24,42 @@ namespace {
|
||||
|
||||
}
|
||||
|
||||
LineTool::LineTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
LineTool::LineTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon LineTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon LineTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "line.svg");
|
||||
}
|
||||
QString LineTool::name() const {
|
||||
QString LineTool::name() const
|
||||
{
|
||||
return tr("Line");
|
||||
}
|
||||
|
||||
QString LineTool::nameID() {
|
||||
QString LineTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString LineTool::description() const {
|
||||
QString LineTool::description() const
|
||||
{
|
||||
return tr("Set the Line as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* LineTool::copy(QObject *parent) {
|
||||
CaptureTool* LineTool::copy(QObject* parent)
|
||||
{
|
||||
return new LineTool(parent);
|
||||
}
|
||||
|
||||
void LineTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void LineTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -57,18 +67,22 @@ void LineTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
}
|
||||
|
||||
void LineTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void LineTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void LineTool::drawStart(const CaptureContext &context) {
|
||||
void LineTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void LineTool::pressed(const CaptureContext &context) {
|
||||
void LineTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,22 +19,25 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class LineTool : public AbstractTwoPointTool {
|
||||
class LineTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LineTool(QObject *parent = nullptr);
|
||||
explicit LineTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -24,32 +24,42 @@ namespace {
|
||||
|
||||
}
|
||||
|
||||
MarkerTool::MarkerTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
MarkerTool::MarkerTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsOrthogonalAdj = true;
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon MarkerTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon MarkerTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "marker.svg");
|
||||
}
|
||||
QString MarkerTool::name() const {
|
||||
QString MarkerTool::name() const
|
||||
{
|
||||
return tr("Marker");
|
||||
}
|
||||
|
||||
QString MarkerTool::nameID() {
|
||||
QString MarkerTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString MarkerTool::description() const {
|
||||
QString MarkerTool::description() const
|
||||
{
|
||||
return tr("Set the Marker as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* MarkerTool::copy(QObject *parent) {
|
||||
CaptureTool* MarkerTool::copy(QObject* parent)
|
||||
{
|
||||
return new MarkerTool(parent);
|
||||
}
|
||||
|
||||
void MarkerTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void MarkerTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -59,24 +69,29 @@ void MarkerTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUn
|
||||
painter.drawLine(m_points.first, m_points.second);
|
||||
}
|
||||
|
||||
void MarkerTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void MarkerTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
||||
painter.setOpacity(0.35);
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void MarkerTool::drawStart(const CaptureContext &context) {
|
||||
void MarkerTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void MarkerTool::pressed(const CaptureContext &context) {
|
||||
void MarkerTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void MarkerTool::thicknessChanged(const int th) {
|
||||
void MarkerTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_thickness = th + PADDING_VALUE;
|
||||
}
|
||||
|
||||
@@ -19,23 +19,26 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class MarkerTool : public AbstractTwoPointTool {
|
||||
class MarkerTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MarkerTool(QObject *parent = nullptr);
|
||||
explicit MarkerTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
};
|
||||
|
||||
@@ -18,35 +18,42 @@
|
||||
#include "movetool.h"
|
||||
#include <QPainter>
|
||||
|
||||
MoveTool::MoveTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
MoveTool::MoveTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool MoveTool::closeOnButtonPressed() const {
|
||||
bool MoveTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon MoveTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon MoveTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cursor-move.svg");
|
||||
}
|
||||
QString MoveTool::name() const {
|
||||
QString MoveTool::name() const
|
||||
{
|
||||
return tr("Move");
|
||||
}
|
||||
|
||||
QString MoveTool::nameID() {
|
||||
QString MoveTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString MoveTool::description() const {
|
||||
QString MoveTool::description() const
|
||||
{
|
||||
return tr("Move the selection area");
|
||||
}
|
||||
|
||||
CaptureTool* MoveTool::copy(QObject *parent) {
|
||||
CaptureTool* MoveTool::copy(QObject* parent)
|
||||
{
|
||||
return new MoveTool(parent);
|
||||
}
|
||||
|
||||
void MoveTool::pressed(const CaptureContext &context) {
|
||||
void MoveTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_MOVE_MODE);
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class MoveTool : public AbstractActionTool {
|
||||
class MoveTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MoveTool(QObject *parent = nullptr);
|
||||
explicit MoveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,31 +18,39 @@
|
||||
#include "penciltool.h"
|
||||
#include <QPainter>
|
||||
|
||||
PencilTool::PencilTool(QObject *parent) : AbstractPathTool(parent) {
|
||||
PencilTool::PencilTool(QObject* parent)
|
||||
: AbstractPathTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
QIcon PencilTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon PencilTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pencil.svg");
|
||||
}
|
||||
QString PencilTool::name() const {
|
||||
QString PencilTool::name() const
|
||||
{
|
||||
return tr("Pencil");
|
||||
}
|
||||
|
||||
QString PencilTool::nameID() {
|
||||
QString PencilTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString PencilTool::description() const {
|
||||
QString PencilTool::description() const
|
||||
{
|
||||
return tr("Set the Pencil as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* PencilTool::copy(QObject *parent) {
|
||||
CaptureTool* PencilTool::copy(QObject* parent)
|
||||
{
|
||||
return new PencilTool(parent);
|
||||
}
|
||||
|
||||
void PencilTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void PencilTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -50,12 +58,15 @@ void PencilTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUn
|
||||
painter.drawPolyline(m_points.data(), m_points.size());
|
||||
}
|
||||
|
||||
void PencilTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void PencilTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, context.thickness + 2));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void PencilTool::drawStart(const CaptureContext &context) {
|
||||
void PencilTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + 2;
|
||||
m_points.append(context.mousePos);
|
||||
@@ -63,6 +74,7 @@ void PencilTool::drawStart(const CaptureContext &context) {
|
||||
m_backupArea.setBottomRight(context.mousePos);
|
||||
}
|
||||
|
||||
void PencilTool::pressed(const CaptureContext &context) {
|
||||
void PencilTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,23 +19,26 @@
|
||||
|
||||
#include "src/tools/abstractpathtool.h"
|
||||
|
||||
class PencilTool : public AbstractPathTool {
|
||||
class PencilTool : public AbstractPathTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PencilTool(QObject *parent = nullptr);
|
||||
explicit PencilTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,47 +18,54 @@
|
||||
#include "pintool.h"
|
||||
#include "src/tools/pin/pinwidget.h"
|
||||
|
||||
PinTool::PinTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
PinTool::PinTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool PinTool::closeOnButtonPressed() const {
|
||||
bool PinTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon PinTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon PinTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "pin.svg");
|
||||
}
|
||||
QString PinTool::name() const {
|
||||
QString PinTool::name() const
|
||||
{
|
||||
return tr("Pin Tool");
|
||||
}
|
||||
|
||||
QString PinTool::nameID() {
|
||||
QString PinTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString PinTool::description() const {
|
||||
QString PinTool::description() const
|
||||
{
|
||||
return tr("Pin image on the desktop");
|
||||
}
|
||||
|
||||
QWidget* PinTool::widget() {
|
||||
PinWidget *w = new PinWidget(m_pixmap);
|
||||
const int &&m = w->margin();
|
||||
QWidget* PinTool::widget()
|
||||
{
|
||||
PinWidget* w = new PinWidget(m_pixmap);
|
||||
const int&& m = w->margin();
|
||||
QRect adjusted_pos = m_geometry + QMargins(m, m, m, m);
|
||||
w->setGeometry(adjusted_pos);
|
||||
return w;
|
||||
}
|
||||
|
||||
CaptureTool* PinTool::copy(QObject *parent) {
|
||||
CaptureTool* PinTool::copy(QObject* parent)
|
||||
{
|
||||
return new PinTool(parent);
|
||||
}
|
||||
|
||||
void PinTool::pressed(const CaptureContext &context) {
|
||||
void PinTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
m_geometry = context.selection;
|
||||
m_geometry.setTopLeft(m_geometry.topLeft() + context.widgetOffset);
|
||||
m_pixmap = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
|
||||
}
|
||||
|
||||
11
src/tools/pin/pintool.h
Executable file → Normal file
11
src/tools/pin/pintool.h
Executable file → Normal file
@@ -19,24 +19,25 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class PinTool : public AbstractActionTool {
|
||||
class PinTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinTool(QObject *parent = nullptr);
|
||||
explicit PinTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QRect m_geometry;
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
|
||||
#include "pinwidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#include <QShortcut>
|
||||
|
||||
PinWidget::PinWidget(const QPixmap &pixmap, QWidget *parent) :
|
||||
QWidget(parent), m_pixmap(pixmap)
|
||||
PinWidget::PinWidget(const QPixmap& pixmap, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_pixmap(pixmap)
|
||||
{
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint
|
||||
| Qt::FramelessWindowHint);
|
||||
//set the bottom widget background transparent
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
// set the bottom widget background transparent
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
ConfigHandler conf;
|
||||
@@ -53,11 +53,13 @@ PinWidget::PinWidget(const QPixmap &pixmap, QWidget *parent) :
|
||||
new QShortcut(Qt::Key_Escape, this, SLOT(close()));
|
||||
}
|
||||
|
||||
int PinWidget::margin() const {
|
||||
int PinWidget::margin() const
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
void PinWidget::wheelEvent(QWheelEvent *e) {
|
||||
void PinWidget::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
int val = e->delta() > 0 ? 15 : -15;
|
||||
int newWidth = qBound(50, m_label->width() + val, maximumWidth());
|
||||
int newHeight = qBound(50, m_label->height() + val, maximumHeight());
|
||||
@@ -69,34 +71,41 @@ void PinWidget::wheelEvent(QWheelEvent *e) {
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void PinWidget::enterEvent(QEvent *) {
|
||||
void PinWidget::enterEvent(QEvent*)
|
||||
{
|
||||
m_shadowEffect->setColor(m_hoverColor);
|
||||
}
|
||||
void PinWidget::leaveEvent(QEvent *) {
|
||||
void PinWidget::leaveEvent(QEvent*)
|
||||
{
|
||||
m_shadowEffect->setColor(m_baseColor);
|
||||
}
|
||||
|
||||
void PinWidget::mouseDoubleClickEvent(QMouseEvent *) {
|
||||
void PinWidget::mouseDoubleClickEvent(QMouseEvent*)
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void PinWidget::mousePressEvent(QMouseEvent *e) {
|
||||
void PinWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
m_dragStart = e->globalPos();
|
||||
m_offsetX = e->localPos().x() / width();
|
||||
m_offsetY = e->localPos().y() / height();
|
||||
}
|
||||
|
||||
void PinWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
void PinWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
const QPoint delta = e->globalPos() - m_dragStart;
|
||||
int offsetW = width() * m_offsetX;
|
||||
int offsetH = height() * m_offsetY;
|
||||
move(m_dragStart.x() + delta.x() - offsetW, m_dragStart.y() + delta.y() - offsetH);
|
||||
move(m_dragStart.x() + delta.x() - offsetW,
|
||||
m_dragStart.y() + delta.y() - offsetH);
|
||||
}
|
||||
|
||||
void PinWidget::setScaledPixmap(const QSize &size) {
|
||||
void PinWidget::setScaledPixmap(const QSize& size)
|
||||
{
|
||||
const qreal scale = qApp->devicePixelRatio();
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(size * scale, Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(
|
||||
size * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
scaledPixmap.setDevicePixelRatio(scale);
|
||||
m_label->setPixmap(scaledPixmap);
|
||||
}
|
||||
|
||||
@@ -17,35 +17,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
class QLabel;
|
||||
|
||||
class PinWidget : public QWidget {
|
||||
class PinWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PinWidget(const QPixmap &pixmap, QWidget *parent = nullptr);
|
||||
explicit PinWidget(const QPixmap& pixmap, QWidget* parent = nullptr);
|
||||
|
||||
int margin() const;
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void mouseDoubleClickEvent(QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void mouseDoubleClickEvent(QMouseEvent*);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void enterEvent(QEvent*);
|
||||
void leaveEvent(QEvent*);
|
||||
|
||||
private:
|
||||
void setScaledPixmap(const QSize &size);
|
||||
void setScaledPixmap(const QSize& size);
|
||||
|
||||
QPixmap m_pixmap;
|
||||
QVBoxLayout *m_layout;
|
||||
QLabel *m_label;
|
||||
QVBoxLayout* m_layout;
|
||||
QLabel* m_label;
|
||||
QPoint m_dragStart;
|
||||
qreal m_offsetX, m_offsetY;
|
||||
QGraphicsDropShadowEffect *m_shadowEffect;
|
||||
QGraphicsDropShadowEffect* m_shadowEffect;
|
||||
QColor m_baseColor, m_hoverColor;
|
||||
};
|
||||
|
||||
@@ -22,31 +22,41 @@ namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
RectangleTool::RectangleTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
RectangleTool::RectangleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
QIcon RectangleTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon RectangleTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square.svg");
|
||||
}
|
||||
QString RectangleTool::name() const {
|
||||
QString RectangleTool::name() const
|
||||
{
|
||||
return tr("Rectangle");
|
||||
}
|
||||
|
||||
QString RectangleTool::nameID() {
|
||||
QString RectangleTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString RectangleTool::description() const {
|
||||
QString RectangleTool::description() const
|
||||
{
|
||||
return tr("Set the Rectangle as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* RectangleTool::copy(QObject *parent) {
|
||||
CaptureTool* RectangleTool::copy(QObject* parent)
|
||||
{
|
||||
return new RectangleTool(parent);
|
||||
}
|
||||
|
||||
void RectangleTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void RectangleTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -55,18 +65,22 @@ void RectangleTool::process(QPainter &painter, const QPixmap &pixmap, bool recor
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void RectangleTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void RectangleTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void RectangleTool::drawStart(const CaptureContext &context) {
|
||||
void RectangleTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void RectangleTool::pressed(const CaptureContext &context) {
|
||||
void RectangleTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,22 +19,25 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class RectangleTool : public AbstractTwoPointTool {
|
||||
class RectangleTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RectangleTool(QObject *parent = nullptr);
|
||||
explicit RectangleTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,35 +18,42 @@
|
||||
#include "redotool.h"
|
||||
#include <QPainter>
|
||||
|
||||
RedoTool::RedoTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
RedoTool::RedoTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool RedoTool::closeOnButtonPressed() const {
|
||||
bool RedoTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon RedoTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon RedoTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "redo-variant.svg");
|
||||
}
|
||||
QString RedoTool::name() const {
|
||||
QString RedoTool::name() const
|
||||
{
|
||||
return tr("Redo");
|
||||
}
|
||||
|
||||
QString RedoTool::nameID() {
|
||||
QString RedoTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString RedoTool::description() const {
|
||||
QString RedoTool::description() const
|
||||
{
|
||||
return tr("Redo the next modification");
|
||||
}
|
||||
|
||||
CaptureTool* RedoTool::copy(QObject *parent) {
|
||||
CaptureTool* RedoTool::copy(QObject* parent)
|
||||
{
|
||||
return new RedoTool(parent);
|
||||
}
|
||||
|
||||
void RedoTool::pressed(const CaptureContext &context) {
|
||||
void RedoTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
emit requestAction(REQ_REDO_MODIFICATION);
|
||||
}
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class RedoTool : public AbstractActionTool {
|
||||
class RedoTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RedoTool(QObject *parent = nullptr);
|
||||
explicit RedoTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -19,35 +19,42 @@
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include <QPainter>
|
||||
|
||||
SaveTool::SaveTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
SaveTool::SaveTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool SaveTool::closeOnButtonPressed() const {
|
||||
bool SaveTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon SaveTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon SaveTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "content-save.svg");
|
||||
}
|
||||
QString SaveTool::name() const {
|
||||
QString SaveTool::name() const
|
||||
{
|
||||
return tr("Save");
|
||||
}
|
||||
|
||||
QString SaveTool::nameID() {
|
||||
QString SaveTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString SaveTool::description() const {
|
||||
QString SaveTool::description() const
|
||||
{
|
||||
return tr("Save the capture");
|
||||
}
|
||||
|
||||
CaptureTool* SaveTool::copy(QObject *parent) {
|
||||
CaptureTool* SaveTool::copy(QObject* parent)
|
||||
{
|
||||
return new SaveTool(parent);
|
||||
}
|
||||
|
||||
void SaveTool::pressed(const CaptureContext &context) {
|
||||
void SaveTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
if (context.savePath.isEmpty()) {
|
||||
emit requestAction(REQ_HIDE_GUI);
|
||||
bool ok = ScreenshotSaver().saveToFilesystemGUI(
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class SaveTool : public AbstractActionTool {
|
||||
class SaveTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SaveTool(QObject *parent = nullptr);
|
||||
explicit SaveTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -22,35 +22,46 @@ namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
SelectionTool::SelectionTool(QObject *parent) : AbstractTwoPointTool(parent) {
|
||||
SelectionTool::SelectionTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
m_supportsDiagonalAdj = true;
|
||||
}
|
||||
|
||||
bool SelectionTool::closeOnButtonPressed() const {
|
||||
bool SelectionTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon SelectionTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon SelectionTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "square-outline.svg");
|
||||
}
|
||||
QString SelectionTool::name() const {
|
||||
QString SelectionTool::name() const
|
||||
{
|
||||
return tr("Rectangular Selection");
|
||||
}
|
||||
|
||||
QString SelectionTool::nameID() {
|
||||
QString SelectionTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString SelectionTool::description() const {
|
||||
QString SelectionTool::description() const
|
||||
{
|
||||
return tr("Set Selection as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* SelectionTool::copy(QObject *parent) {
|
||||
CaptureTool* SelectionTool::copy(QObject* parent)
|
||||
{
|
||||
return new SelectionTool(parent);
|
||||
}
|
||||
|
||||
void SelectionTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void SelectionTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (recordUndo) {
|
||||
updateBackup(pixmap);
|
||||
}
|
||||
@@ -58,18 +69,22 @@ void SelectionTool::process(QPainter &painter, const QPixmap &pixmap, bool recor
|
||||
painter.drawRect(QRect(m_points.first, m_points.second));
|
||||
}
|
||||
|
||||
void SelectionTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void SelectionTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
void SelectionTool::drawStart(const CaptureContext &context) {
|
||||
void SelectionTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_thickness = context.thickness + PADDING_VALUE;
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
}
|
||||
|
||||
void SelectionTool::pressed(const CaptureContext &context) {
|
||||
void SelectionTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,24 +19,27 @@
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class SelectionTool : public AbstractTwoPointTool {
|
||||
class SelectionTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SelectionTool(QObject *parent = nullptr);
|
||||
explicit SelectionTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -18,34 +18,41 @@
|
||||
#include "sizeindicatortool.h"
|
||||
#include <QPainter>
|
||||
|
||||
SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : AbstractActionTool(parent) {
|
||||
SizeIndicatorTool::SizeIndicatorTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
bool SizeIndicatorTool::closeOnButtonPressed() const {
|
||||
bool SizeIndicatorTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon SizeIndicatorTool::icon(const QColor &background, bool inEditor) const {
|
||||
return inEditor ? QIcon() :
|
||||
QIcon(iconPath(background) + "size_indicator.svg");
|
||||
QIcon SizeIndicatorTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
return inEditor ? QIcon()
|
||||
: QIcon(iconPath(background) + "size_indicator.svg");
|
||||
}
|
||||
QString SizeIndicatorTool::name() const {
|
||||
QString SizeIndicatorTool::name() const
|
||||
{
|
||||
return tr("Selection Size Indicator");
|
||||
}
|
||||
|
||||
QString SizeIndicatorTool::nameID() {
|
||||
QString SizeIndicatorTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString SizeIndicatorTool::description() const {
|
||||
QString SizeIndicatorTool::description() const
|
||||
{
|
||||
return tr("Show the dimensions of the selection (X Y)");
|
||||
}
|
||||
|
||||
CaptureTool* SizeIndicatorTool::copy(QObject *parent) {
|
||||
CaptureTool* SizeIndicatorTool::copy(QObject* parent)
|
||||
{
|
||||
return new SizeIndicatorTool(parent);
|
||||
}
|
||||
|
||||
void SizeIndicatorTool::pressed(const CaptureContext &context) {
|
||||
void SizeIndicatorTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
class SizeIndicatorTool : public AbstractActionTool {
|
||||
class SizeIndicatorTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SizeIndicatorTool(QObject *parent = nullptr);
|
||||
explicit SizeIndicatorTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor &background, bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
|
||||
@@ -203,7 +203,7 @@ const QUrl& ImgUploader::imageUrl()
|
||||
return m_imageURL;
|
||||
}
|
||||
|
||||
void ImgUploader::showNotificationMessage(const QString& notificationMessage) {
|
||||
void ImgUploader::showNotificationMessage(const QString& notificationMessage)
|
||||
{
|
||||
m_notification->showMessage(notificationMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
ImgUploaderTool::ImgUploaderTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
void ImgUploaderTool::setCapture(const QPixmap& pixmap)
|
||||
{
|
||||
@@ -18,7 +16,8 @@ void ImgUploaderTool::pressed(const CaptureContext& context)
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
const QPixmap& ImgUploaderTool::capture() {
|
||||
const QPixmap& ImgUploaderTool::capture()
|
||||
{
|
||||
return m_capture;
|
||||
}
|
||||
|
||||
@@ -28,9 +27,7 @@ QIcon ImgUploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
}
|
||||
|
||||
|
||||
bool ImgUploaderTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
|
||||
class ImgUploaderTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "imgur/imguruploadertool.h"
|
||||
#include "s3/imgs3uploader.h"
|
||||
#include "s3/imgs3uploadertool.h"
|
||||
#include "src/tools/storage/s3/imgs3settings.h"
|
||||
#include "src/tools/capturetool.h"
|
||||
#include "src/tools/storage/s3/imgs3settings.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
@@ -22,7 +22,8 @@ CaptureTool* StorageManager::imgUploaderTool(const QString& imgUploaderType,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const QString& StorageManager::storageUrl(const QString& imgUploaderType) {
|
||||
const QString& StorageManager::storageUrl(const QString& imgUploaderType)
|
||||
{
|
||||
if (imgUploaderType == SCREENSHOT_STORAGE_TYPE_S3) {
|
||||
ImgS3Settings s3Settings;
|
||||
m_qstr = s3Settings.url();
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
QObject* parent = nullptr);
|
||||
const QString& storageUrl(const QString& imgUploaderType);
|
||||
|
||||
// class members
|
||||
// class members
|
||||
private:
|
||||
QString m_qstr;
|
||||
};
|
||||
|
||||
@@ -18,57 +18,69 @@
|
||||
#include "textconfig.h"
|
||||
#include "src/utils/colorutils.h"
|
||||
#include "src/utils/pathinfo.h"
|
||||
#include <QFontDatabase>
|
||||
#include <QComboBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFontDatabase>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
TextConfig::TextConfig(QWidget *parent) : QWidget(parent) {
|
||||
TextConfig::TextConfig(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
|
||||
QFontDatabase fontDB;
|
||||
QComboBox *fontsCB = new QComboBox();
|
||||
connect(fontsCB, &QComboBox::currentTextChanged,
|
||||
this, &TextConfig::fontFamilyChanged);
|
||||
QComboBox* fontsCB = new QComboBox();
|
||||
connect(fontsCB,
|
||||
&QComboBox::currentTextChanged,
|
||||
this,
|
||||
&TextConfig::fontFamilyChanged);
|
||||
fontsCB->addItems(fontDB.families());
|
||||
// TODO save family in config
|
||||
int index = fontsCB->findText(font().family());
|
||||
fontsCB->setCurrentIndex(index);
|
||||
|
||||
QColor bgColor(palette().background().color());
|
||||
QString iconPrefix = ColorUtils::colorIsDark(bgColor) ?
|
||||
PathInfo::whiteIconPath() :
|
||||
PathInfo::blackIconPath();
|
||||
QString iconPrefix = ColorUtils::colorIsDark(bgColor)
|
||||
? PathInfo::whiteIconPath()
|
||||
: PathInfo::blackIconPath();
|
||||
|
||||
m_strikeOutButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_strikethrough.svg"), QLatin1String(""));
|
||||
m_strikeOutButton->setCheckable(true);
|
||||
connect(m_strikeOutButton, &QPushButton::clicked,
|
||||
this, &TextConfig::fontStrikeOutChanged);
|
||||
connect(m_strikeOutButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontStrikeOutChanged);
|
||||
m_strikeOutButton->setToolTip(tr("StrikeOut"));
|
||||
|
||||
m_underlineButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_underlined.svg"), QLatin1String(""));
|
||||
m_underlineButton->setCheckable(true);
|
||||
connect(m_underlineButton, &QPushButton::clicked,
|
||||
this, &TextConfig::fontUnderlineChanged);
|
||||
connect(m_underlineButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontUnderlineChanged);
|
||||
m_underlineButton->setToolTip(tr("Underline"));
|
||||
|
||||
m_weightButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_bold.svg"), QLatin1String(""));
|
||||
m_weightButton =
|
||||
new QPushButton(QIcon(iconPrefix + "format_bold.svg"), QLatin1String(""));
|
||||
m_weightButton->setCheckable(true);
|
||||
connect(m_weightButton, &QPushButton::clicked,
|
||||
this, &TextConfig::weightButtonPressed);
|
||||
connect(m_weightButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::weightButtonPressed);
|
||||
m_weightButton->setToolTip(tr("Bold"));
|
||||
|
||||
m_italicButton = new QPushButton(
|
||||
QIcon(iconPrefix + "format_italic.svg"), QLatin1String(""));
|
||||
m_italicButton = new QPushButton(QIcon(iconPrefix + "format_italic.svg"),
|
||||
QLatin1String(""));
|
||||
m_italicButton->setCheckable(true);
|
||||
connect(m_italicButton, &QPushButton::clicked,
|
||||
this, &TextConfig::fontItalicChanged);
|
||||
connect(m_italicButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&TextConfig::fontItalicChanged);
|
||||
m_italicButton->setToolTip(tr("Italic"));
|
||||
QHBoxLayout *modifiersLayout = new QHBoxLayout();
|
||||
QHBoxLayout* modifiersLayout = new QHBoxLayout();
|
||||
|
||||
m_layout->addWidget(fontsCB);
|
||||
modifiersLayout->addWidget(m_strikeOutButton);
|
||||
@@ -78,23 +90,28 @@ TextConfig::TextConfig(QWidget *parent) : QWidget(parent) {
|
||||
m_layout->addLayout(modifiersLayout);
|
||||
}
|
||||
|
||||
void TextConfig::setUnderline(const bool u) {
|
||||
void TextConfig::setUnderline(const bool u)
|
||||
{
|
||||
m_underlineButton->setChecked(u);
|
||||
}
|
||||
|
||||
void TextConfig::setStrikeOut(const bool s) {
|
||||
void TextConfig::setStrikeOut(const bool s)
|
||||
{
|
||||
m_strikeOutButton->setChecked(s);
|
||||
}
|
||||
|
||||
void TextConfig::setWeight(const int w) {
|
||||
void TextConfig::setWeight(const int w)
|
||||
{
|
||||
m_weightButton->setChecked(static_cast<QFont::Weight>(w) == QFont::Bold);
|
||||
}
|
||||
|
||||
void TextConfig::setItalic(const bool i) {
|
||||
void TextConfig::setItalic(const bool i)
|
||||
{
|
||||
m_italicButton->setChecked(i);
|
||||
}
|
||||
|
||||
void TextConfig::weightButtonPressed(const bool w) {
|
||||
void TextConfig::weightButtonPressed(const bool w)
|
||||
{
|
||||
if (w) {
|
||||
emit fontWeightChanged(QFont::Bold);
|
||||
} else {
|
||||
|
||||
@@ -22,10 +22,11 @@
|
||||
class QVBoxLayout;
|
||||
class QPushButton;
|
||||
|
||||
class TextConfig : public QWidget {
|
||||
class TextConfig : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextConfig(QWidget *parent = nullptr);
|
||||
explicit TextConfig(QWidget* parent = nullptr);
|
||||
|
||||
void setUnderline(const bool u);
|
||||
void setStrikeOut(const bool s);
|
||||
@@ -33,7 +34,7 @@ public:
|
||||
void setItalic(const bool i);
|
||||
|
||||
signals:
|
||||
void fontFamilyChanged(const QString &f);
|
||||
void fontFamilyChanged(const QString& f);
|
||||
void fontUnderlineChanged(const bool underlined);
|
||||
void fontStrikeOutChanged(const bool dashed);
|
||||
void fontWeightChanged(const QFont::Weight w);
|
||||
@@ -45,9 +46,9 @@ private slots:
|
||||
void weightButtonPressed(const bool w);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QPushButton *m_strikeOutButton;
|
||||
QPushButton *m_underlineButton;
|
||||
QPushButton *m_weightButton;
|
||||
QPushButton *m_italicButton;
|
||||
QVBoxLayout* m_layout;
|
||||
QPushButton* m_strikeOutButton;
|
||||
QPushButton* m_underlineButton;
|
||||
QPushButton* m_weightButton;
|
||||
QPushButton* m_italicButton;
|
||||
};
|
||||
|
||||
@@ -16,71 +16,89 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "texttool.h"
|
||||
#include "textwidget.h"
|
||||
#include "textconfig.h"
|
||||
#include "textwidget.h"
|
||||
|
||||
#define BASE_POINT_SIZE 8
|
||||
|
||||
TextTool::TextTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
, m_size(1)
|
||||
{}
|
||||
|
||||
TextTool::TextTool(QObject *parent) : CaptureTool(parent), m_size(1) {
|
||||
}
|
||||
|
||||
bool TextTool::isValid() const {
|
||||
bool TextTool::isValid() const
|
||||
{
|
||||
return !m_text.isEmpty();
|
||||
}
|
||||
|
||||
bool TextTool::closeOnButtonPressed() const {
|
||||
bool TextTool::closeOnButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TextTool::isSelectable() const {
|
||||
bool TextTool::isSelectable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextTool::showMousePreview() const {
|
||||
bool TextTool::showMousePreview() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QIcon TextTool::icon(const QColor &background, bool inEditor) const {
|
||||
QIcon TextTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "text.svg");
|
||||
}
|
||||
|
||||
QString TextTool::name() const {
|
||||
QString TextTool::name() const
|
||||
{
|
||||
return tr("Text");
|
||||
}
|
||||
|
||||
QString TextTool::nameID() {
|
||||
QString TextTool::nameID()
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString TextTool::description() const {
|
||||
QString TextTool::description() const
|
||||
{
|
||||
return tr("Add text to your capture");
|
||||
}
|
||||
|
||||
QWidget *TextTool::widget() {
|
||||
TextWidget *w = new TextWidget();
|
||||
QWidget* TextTool::widget()
|
||||
{
|
||||
TextWidget* w = new TextWidget();
|
||||
w->setTextColor(m_color);
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
w->setFont(m_font);
|
||||
connect(w, &TextWidget::textUpdated,
|
||||
this, &TextTool::updateText);
|
||||
connect(w, &TextWidget::textUpdated, this, &TextTool::updateText);
|
||||
m_widget = w;
|
||||
return w;
|
||||
}
|
||||
|
||||
QWidget *TextTool::configurationWidget() {
|
||||
QWidget* TextTool::configurationWidget()
|
||||
{
|
||||
m_confW = new TextConfig();
|
||||
connect(m_confW, &TextConfig::fontFamilyChanged,
|
||||
this, &TextTool::updateFamily);
|
||||
connect(m_confW, &TextConfig::fontItalicChanged,
|
||||
this, &TextTool::updateFontItalic);
|
||||
connect(m_confW, &TextConfig::fontStrikeOutChanged,
|
||||
this, &TextTool::updateFontStrikeOut);
|
||||
connect(m_confW, &TextConfig::fontUnderlineChanged,
|
||||
this, &TextTool::updateFontUnderline);
|
||||
connect(m_confW, &TextConfig::fontWeightChanged,
|
||||
this, &TextTool::updateFontWeight);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontFamilyChanged, this, &TextTool::updateFamily);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontItalicChanged,
|
||||
this,
|
||||
&TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
this,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
this,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontWeightChanged,
|
||||
this,
|
||||
&TextTool::updateFontWeight);
|
||||
m_confW->setItalic(m_font.italic());
|
||||
m_confW->setUnderline(m_font.underline());
|
||||
m_confW->setStrikeOut(m_font.strikeOut());
|
||||
@@ -88,28 +106,37 @@ QWidget *TextTool::configurationWidget() {
|
||||
return m_confW;
|
||||
}
|
||||
|
||||
CaptureTool *TextTool::copy(QObject *parent) {
|
||||
TextTool *tt = new TextTool(parent);
|
||||
connect(m_confW, &TextConfig::fontFamilyChanged,
|
||||
tt, &TextTool::updateFamily);
|
||||
connect(m_confW, &TextConfig::fontItalicChanged,
|
||||
tt, &TextTool::updateFontItalic);
|
||||
connect(m_confW, &TextConfig::fontStrikeOutChanged,
|
||||
tt, &TextTool::updateFontStrikeOut);
|
||||
connect(m_confW, &TextConfig::fontUnderlineChanged,
|
||||
tt, &TextTool::updateFontUnderline);
|
||||
connect(m_confW, &TextConfig::fontWeightChanged,
|
||||
tt, &TextTool::updateFontWeight);
|
||||
CaptureTool* TextTool::copy(QObject* parent)
|
||||
{
|
||||
TextTool* tt = new TextTool(parent);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontItalicChanged, tt, &TextTool::updateFontItalic);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontStrikeOutChanged,
|
||||
tt,
|
||||
&TextTool::updateFontStrikeOut);
|
||||
connect(m_confW,
|
||||
&TextConfig::fontUnderlineChanged,
|
||||
tt,
|
||||
&TextTool::updateFontUnderline);
|
||||
connect(
|
||||
m_confW, &TextConfig::fontWeightChanged, tt, &TextTool::updateFontWeight);
|
||||
tt->m_font = m_font;
|
||||
return tt;
|
||||
}
|
||||
|
||||
void TextTool::undo(QPixmap &pixmap) {
|
||||
void TextTool::undo(QPixmap& pixmap)
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawPixmap(m_backupArea.topLeft(), m_pixmapBackup);
|
||||
}
|
||||
|
||||
void TextTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
|
||||
void TextTool::process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo)
|
||||
{
|
||||
if (m_text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -125,37 +152,45 @@ void TextTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo
|
||||
painter.drawText(m_backupArea + QMargins(-5, -5, 5, 5), m_text);
|
||||
}
|
||||
|
||||
void TextTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
|
||||
void TextTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void TextTool::drawEnd(const QPoint &p) {
|
||||
void TextTool::drawEnd(const QPoint& p)
|
||||
{
|
||||
m_backupArea.moveTo(p);
|
||||
}
|
||||
|
||||
void TextTool::drawMove(const QPoint &p) {
|
||||
void TextTool::drawMove(const QPoint& p)
|
||||
{
|
||||
m_widget->move(p);
|
||||
}
|
||||
|
||||
void TextTool::drawStart(const CaptureContext &context) {
|
||||
void TextTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
m_size = context.thickness;
|
||||
emit requestAction(REQ_ADD_CHILD_WIDGET);
|
||||
}
|
||||
|
||||
void TextTool::pressed(const CaptureContext &context) {
|
||||
void TextTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
}
|
||||
|
||||
void TextTool::colorChanged(const QColor &c) {
|
||||
void TextTool::colorChanged(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
if (m_widget) {
|
||||
m_widget->setTextColor(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::thicknessChanged(const int th) {
|
||||
void TextTool::thicknessChanged(const int th)
|
||||
{
|
||||
m_size = th;
|
||||
m_font.setPointSize(m_size + BASE_POINT_SIZE);
|
||||
if (m_widget) {
|
||||
@@ -163,46 +198,53 @@ void TextTool::thicknessChanged(const int th) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateText(const QString &s) {
|
||||
void TextTool::updateText(const QString& s)
|
||||
{
|
||||
m_text = s;
|
||||
}
|
||||
|
||||
void TextTool::setFont(const QFont &f) {
|
||||
void TextTool::setFont(const QFont& f)
|
||||
{
|
||||
m_font = f;
|
||||
if (m_widget) {
|
||||
m_widget->setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateFamily(const QString &s) {
|
||||
void TextTool::updateFamily(const QString& s)
|
||||
{
|
||||
m_font.setFamily(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateFontUnderline(const bool underlined) {
|
||||
void TextTool::updateFontUnderline(const bool underlined)
|
||||
{
|
||||
m_font.setUnderline(underlined);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateFontStrikeOut(const bool s) {
|
||||
void TextTool::updateFontStrikeOut(const bool s)
|
||||
{
|
||||
m_font.setStrikeOut(s);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateFontWeight(const QFont::Weight w) {
|
||||
void TextTool::updateFontWeight(const QFont::Weight w)
|
||||
{
|
||||
m_font.setWeight(w);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTool::updateFontItalic(const bool italic) {
|
||||
void TextTool::updateFontItalic(const bool italic)
|
||||
{
|
||||
m_font.setItalic(italic);
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
|
||||
@@ -23,43 +23,45 @@
|
||||
class TextWidget;
|
||||
class TextConfig;
|
||||
|
||||
class TextTool : public CaptureTool {
|
||||
class TextTool : public CaptureTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextTool(QObject *parent = nullptr);
|
||||
explicit TextTool(QObject* parent = nullptr);
|
||||
|
||||
bool isValid() const override;
|
||||
bool closeOnButtonPressed() const override;
|
||||
bool isSelectable() const override;
|
||||
bool showMousePreview() const override;
|
||||
|
||||
QIcon icon(const QColor &background,
|
||||
bool inEditor) const override;
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
|
||||
QWidget* widget() override;
|
||||
QWidget* configurationWidget() override;
|
||||
CaptureTool* copy(QObject *parent = nullptr) override;
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
|
||||
void undo(QPixmap &pixmap) override;
|
||||
void process(
|
||||
QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
|
||||
void undo(QPixmap& pixmap) override;
|
||||
void process(QPainter& painter,
|
||||
const QPixmap& pixmap,
|
||||
bool recordUndo = false) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
|
||||
public slots:
|
||||
void drawEnd(const QPoint &p) override;
|
||||
void drawMove(const QPoint &p) override;
|
||||
void drawStart(const CaptureContext &context) override;
|
||||
void pressed(const CaptureContext &context) override;
|
||||
void colorChanged(const QColor &c) override;
|
||||
void drawEnd(const QPoint& p) override;
|
||||
void drawMove(const QPoint& p) override;
|
||||
void drawStart(const CaptureContext& context) override;
|
||||
void pressed(const CaptureContext& context) override;
|
||||
void colorChanged(const QColor& c) override;
|
||||
void thicknessChanged(const int th) override;
|
||||
|
||||
private slots:
|
||||
void updateText(const QString &s);
|
||||
void setFont(const QFont &f);
|
||||
void updateFamily(const QString &s);
|
||||
void updateText(const QString& s);
|
||||
void setFont(const QFont& f);
|
||||
void updateFamily(const QString& s);
|
||||
void updateFontUnderline(const bool underlined);
|
||||
void updateFontStrikeOut(const bool s);
|
||||
void updateFontWeight(const QFont::Weight w);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user