1 /*
2 	Actiona
3 	Copyright (C) 2005 Jonathan Mercier-Ganady
4 
5 	Actiona is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	Actiona is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 	Contact : jmgr@jmgr.info
19 */
20 
21 #pragma once
22 
23 #include "actiondefinition.h"
24 #include "pixelcolorinstance.h"
25 #include "colorpositionparameterdefinition.h"
26 #include "listparameterdefinition.h"
27 #include "numberparameterdefinition.h"
28 #include "variableparameterdefinition.h"
29 #include "ifactionparameterdefinition.h"
30 #include "positionparameterdefinition.h"
31 
32 namespace ActionTools
33 {
34 	class ActionPack;
35 	class ActionInstance;
36 }
37 
38 namespace Actions
39 {
40 	class PixelColorDefinition : public ActionTools::ActionDefinition
41 	{
42 	   Q_OBJECT
43 
44 	public:
PixelColorDefinition(ActionTools::ActionPack * pack)45 		explicit PixelColorDefinition(ActionTools::ActionPack *pack)
46 		: ActionDefinition(pack)
47 		{
48 			translateItems("PixelColorInstance::comparisons", PixelColorInstance::comparisons);
49 
50             auto &pixel = addParameter<ActionTools::ColorPositionParameterDefinition>({QStringLiteral("pixel"), tr("Pixel")});
51             pixel.setTooltip(tr("The pixel position and color to check"));
52 
53             auto &comparison = addParameter<ActionTools::ListParameterDefinition>({QStringLiteral("comparison"), tr("Comparison")});
54             comparison.setTooltip(tr("The comparison"));
55             comparison.setItems(PixelColorInstance::comparisons);
56             comparison.setDefaultValue(PixelColorInstance::comparisons.second.at(PixelColorInstance::Equal));
57 
58             auto &ifTrue = addParameter<ActionTools::IfActionParameterDefinition>({QStringLiteral("ifTrue"), tr("If true")});
59             ifTrue.setTooltip(tr("What to to if the pixel comparison is true"));
60 
61             auto &ifFalse = addParameter<ActionTools::IfActionParameterDefinition>({QStringLiteral("ifFalse"), tr("If false")});
62             ifFalse.setTooltip(tr("What to to if the pixel comparison is false"));
63             ifFalse.setAllowWait(true);
64 
65             auto &variable = addParameter<ActionTools::VariableParameterDefinition>({QStringLiteral("variable"), tr("Pixel color variable")}, 1);
66             variable.setTooltip(tr("Variable name where to store the pixel color"));
67 
68             auto &redTolerance = addParameter<ActionTools::NumberParameterDefinition>({QStringLiteral("redTolerance"), tr("Red tolerance")}, 1);
69             redTolerance.setTooltip(tr("The tolerance percentage for the red color component"));
70             redTolerance.setMinimum(0);
71             redTolerance.setMaximum(100);
72             redTolerance.setDefaultValue(QStringLiteral("0"));
73 
74             auto &greenTolerance = addParameter<ActionTools::NumberParameterDefinition>({QStringLiteral("greenTolerance"), tr("Green tolerance")}, 1);
75             greenTolerance.setTooltip(tr("The tolerance percentage for the green color component"));
76             greenTolerance.setMinimum(0);
77             greenTolerance.setMaximum(100);
78             greenTolerance.setDefaultValue(QStringLiteral("0"));
79 
80             auto &blueTolerance = addParameter<ActionTools::NumberParameterDefinition>({QStringLiteral("blueTolerance"), tr("Blue tolerance")}, 1);
81             blueTolerance.setTooltip(tr("The tolerance percentage for the blue color component"));
82             blueTolerance.setMinimum(0);
83             blueTolerance.setMaximum(100);
84             blueTolerance.setDefaultValue(QStringLiteral("0"));
85 
86             auto &positionOffset = addParameter<ActionTools::PositionParameterDefinition>({QStringLiteral("positionOffset"), tr("Offset")}, 1);
87             positionOffset.setTooltip(tr("The offset to apply to the pixel position"));
88 		}
89 
name()90 		QString name() const override													{ return QObject::tr("Pixel color"); }
id()91 		QString id() const override														{ return QStringLiteral("ActionPixelColor"); }
flags()92 		ActionTools::Flag flags() const override											{ return ActionDefinition::flags() | ActionTools::Official; }
description()93 		QString description() const override												{ return QObject::tr("Check a pixel color on the screen"); }
newActionInstance()94 		ActionTools::ActionInstance *newActionInstance() const override					{ return new PixelColorInstance(this); }
category()95 		ActionTools::ActionCategory category() const override							{ return ActionTools::System; }
icon()96 		QPixmap icon() const override													{ return QPixmap(QStringLiteral(":/icons/pixelcolor.png")); }
tabs()97 		QStringList tabs() const override												{ return ActionDefinition::StandardTabs; }
98 
99 	private:
100 		Q_DISABLE_COPY(PixelColorDefinition)
101 	};
102 }
103 
104