Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Leander Schulten
Lichtsteuerung
Commits
5b9dc8f8
Commit
5b9dc8f8
authored
Sep 20, 2019
by
Leander Schulten
Browse files
Support RGB Properties in the UI. Closes
#46
parent
3f8014f0
Pipeline
#185692
passed with stage
in 3 minutes and 48 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/codeeditorhelper.cpp
View file @
5b9dc8f8
...
...
@@ -26,22 +26,16 @@ QString toName(Modules::ValueType t){
return
"wrong_type"
;
}
}
QString
toName
(
Modules
::
Property
::
Type
t
){
QString
toName
(
Modules
::
Property
::
Type
t
)
{
switch
(
t
)
{
case
Modules
::
Property
::
Bool
:
return
"bool"
;
case
Modules
::
Property
::
Double
:
return
"double"
;
case
Modules
::
Property
::
Float
:
return
"float"
;
case
Modules
::
Property
::
Int
:
return
"int"
;
case
Modules
::
Property
::
Long
:
return
"long"
;
case
Modules
::
Property
::
String
:
return
"std::string"
;
default:
return
"wrong_type"
;
case
Modules
::
Property
::
Bool
:
return
QStringLiteral
(
"bool"
);
case
Modules
::
Property
::
Double
:
return
QStringLiteral
(
"double"
);
case
Modules
::
Property
::
Float
:
return
QStringLiteral
(
"float"
);
case
Modules
::
Property
::
Int
:
return
QStringLiteral
(
"int"
);
case
Modules
::
Property
::
Long
:
return
QStringLiteral
(
"long"
);
case
Modules
::
Property
::
String
:
return
QStringLiteral
(
"std::string"
);
case
Modules
::
Property
::
RGB
:
return
QStringLiteral
(
"rgb_t"
);
default:
return
QStringLiteral
(
"wrong_type"
);
}
}
...
...
@@ -892,12 +886,14 @@ void CodeHighlighter::highlightBlock(const QString &text)
QTextStream
&
writeDeclaration
(
QTextStream
&
out
,
const
Modules
::
detail
::
PropertyInformation
*
p
){
using
namespace
Modules
;
if
(
p
->
getType
()
==
Property
::
Bool
){
out
<<
"BoolProperty _"
<<
p
->
getName
()
<<
';'
<<
endl
;
}
else
if
(
p
->
getType
()
==
Property
::
String
){
if
(
p
->
getType
()
==
Property
::
Bool
)
{
out
<<
"BoolProperty _"
<<
p
->
getName
()
<<
';'
<<
endl
;
}
else
if
(
p
->
getType
()
==
Property
::
String
)
{
out
<<
"StringProperty _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
else
{
out
<<
"NumericProperty<"
<<
toName
(
p
->
getType
())
<<
"> _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
else
if
(
p
->
getType
()
==
Property
::
RGB
)
{
out
<<
"RGBProperty _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
else
{
out
<<
"NumericProperty<"
<<
toName
(
p
->
getType
())
<<
"> _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
return
out
;
}
...
...
@@ -946,9 +942,7 @@ void replacePropertiesUsages(QString &code, const Modules::PropertiesVector & ve
case
Modules
::
Property
::
String
:
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asString()->getString()"
);
break
;
case
Modules
::
Property
::
RGB
:
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asRGB()"
);
break
;
case
Modules
::
Property
::
RGB
:
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asRGB()->getRGB()"
);
break
;
}
}
}
...
...
src/gui/programblockeditor.cpp
View file @
5b9dc8f8
...
...
@@ -418,7 +418,6 @@ void transferData(GUI::detail::PropertyInformation *pi,Modules::Property * p){
void
detail
::
PropertyInformation
::
updateValue
(){
qDebug
()
<<
"set value"
;
using
namespace
Modules
;
if
(
named
){
auto
p
=
dynamic_cast
<
Program
*>
(
named
);
...
...
@@ -443,11 +442,12 @@ void detail::PropertyInformation::updateValue(){
case
Property
::
Int
:
transferData
<
int
>
(
this
,
property
);
break
;
case
Property
::
Long
:
transferData
<
int64_t
>
(
this
,
property
);
break
;
case
Property
::
Bool
:
property
->
asBool
()
->
setValue
(
getValue
().
toBool
());
case
Property
::
Bool
:
property
->
asBool
()
->
setValue
(
getValue
().
toBool
());
break
;
case
Property
::
String
:
property
->
asString
()
->
setValue
(
getValue
().
toString
().
toStdString
());
break
;
case
Property
::
RGB
:
auto
c
=
getValue
().
value
<
QColor
>
();
property
->
asRGB
()
->
setRGB
(
rgb_t
{
c
.
red
(),
c
.
green
(),
c
.
blue
()});
break
;
case
Property
::
String
:
property
->
asString
()
->
setValue
(
getValue
().
toString
().
toStdString
());
}
}
...
...
@@ -613,8 +613,11 @@ void ProgramBlockEditor::mouseReleaseEvent(QMouseEvent *event){
tp
.
setMaxValue
(
1
);
tp
.
setValue
(
sp
.
asBool
()
->
getValue
());
break
;
case
Property
::
String
:
tp
.
setValue
(
QString
::
fromStdString
(
sp
.
asString
()
->
getString
()));
case
Property
::
String
:
tp
.
setValue
(
QString
::
fromStdString
(
sp
.
asString
()
->
getString
()));
break
;
case
Property
::
RGB
:
const
auto
rgb
=
sp
.
asRGB
()
->
getRGB
();
tp
.
setValue
(
QColor
(
rgb
.
r
,
rgb
.
g
,
rgb
.
b
));
break
;
}
}
...
...
src/main.cpp
View file @
5b9dc8f8
...
...
@@ -237,7 +237,7 @@ int main(int argc, char *argv[]) {
valueTypeList
<<
QStringLiteral
(
"Brightness"
)
<<
QStringLiteral
(
"RGB"
)
;
QStringList
modolePropertyTypeList
;
modolePropertyTypeList
<<
QStringLiteral
(
"Int"
)
<<
QStringLiteral
(
"Long"
)
<<
QStringLiteral
(
"Float"
)
<<
QStringLiteral
(
"Double"
)
<<
QStringLiteral
(
"Bool"
)
<<
QStringLiteral
(
"String"
);
modolePropertyTypeList
<<
QStringLiteral
(
"Int"
)
<<
QStringLiteral
(
"Long"
)
<<
QStringLiteral
(
"Float"
)
<<
QStringLiteral
(
"Double"
)
<<
QStringLiteral
(
"Bool"
)
<<
QStringLiteral
(
"String"
)
<<
QStringLiteral
(
"RGB Color"
)
;
// Does not work: do it manually
/*const QMetaObject &_momProp = Modules::detail::PropertyInformation::staticMetaObject;
qDebug() << "Enum count" <<_momProp.enumeratorCount();
...
...
src/modules/types.h
View file @
5b9dc8f8
...
...
@@ -41,6 +41,7 @@ namespace Modules {
brightness_t
rgb
[
3
];
};
rgb_t
(
brightness_t
r
=
0
,
brightness_t
g
=
0
,
brightness_t
b
=
0
)
:
r
(
r
),
g
(
g
),
b
(
b
)
{}
rgb_t
(
int
r
,
int
g
,
int
b
)
:
r
(
std
::
clamp
(
r
,
0
,
255
)),
g
(
std
::
clamp
(
g
,
0
,
255
)),
b
(
std
::
clamp
(
b
,
0
,
255
))
{}
rgb_t
(
Modules
::
hsl_t
hsl
);
rgb_t
(
Modules
::
hsv_t
hsv
);
hsl_t
toHSL
()
const
;
...
...
@@ -410,9 +411,10 @@ namespace Modules {
* Must be here, in the Property.hpp we have no rgb_t type
* @brief The RGBProperty class is a Property wrapper araoud the rgb_t type
*/
class
RGBProperty
:
public
Property
{
private:
class
RGBProperty
:
public
Property
{
rgb_t
value
;
public:
RGBProperty
()
:
Property
(
Property
::
RGB
),
value
(
0
,
0
,
0
){}
void
save
(
SaveObject
&
o
)
const
override
{
...
...
src/qml/ModuleProgramView.qml
View file @
5b9dc8f8
...
...
@@ -3,6 +3,7 @@ import QtQuick.Controls 2.4
import
QtQuick
.
Layouts
1.3
import
custom
.
licht
1.0
import
QtQuick
.
Dialogs
1.2
import
QtQuick
.
Controls
.
Material
2.12
import
"
components
"
Item
{
...
...
@@ -298,10 +299,13 @@ Item{
checkBox
.
checked
=
data
.
value
}
else
if
(
data
.
type
==
5
/*string*/
){
textInput
.
text
=
data
.
value
}
else
if
(
data
.
type
==
6
/*rgb*/
){
colorChooser
.
currentColor
=
data
.
value
;
}
spinBox
.
visible
=
data
.
type
<=
3
;
checkBox
.
visible
=
data
.
type
==
4
;
textInput
.
visible
=
data
.
type
==
5
;
colorButton
.
visible
=
data
.
type
==
6
;
}
}
...
...
@@ -332,6 +336,23 @@ Item{
CheckBox
{
id
:
checkBox
}
Button
{
Layout.fillWidth
:
true
Layout.margins
:
5
text
:
"
Select Color
"
id
:
colorButton
Material.background
:
colorChooser
.
currentColor
;
Material.foreground
:
colorChooser
.
currentColor
.
hslLightness
>
0.4
?
"
black
"
:
"
white
"
onClicked
:
{
colorChooser
.
startColor
=
colorChooser
.
currentColor
;
colorChooser
.
visible
=
true
;
}
ColorDialog
{
id
:
colorChooser
;
onCurrentColorChanged
:
propertiesView
.
currentModelData
.
value
=
currentColor
onColorSelected
:
colorChooser
.
currentColor
=
selectedColor
;
}
}
TextInputField
{
Layout.margins
:
10
id
:
textInput
...
...
src/qml/components/ColorDialog.qml
View file @
5b9dc8f8
...
...
@@ -11,15 +11,15 @@ Window {
Qt
.
WindowSystemMenuHint
|
Qt
.
WindowTitleHint
|
Qt
.
WindowCloseButtonHint
property
color
currentColor
;
property
color
startColor
;
onVisibleChanged
:
if
(
visible
)
swipeView
.
updateColorsAtCurrentPane
();
onVisibleChanged
:
{
if
(
visible
){
currentColor
=
startColor
;
swipeView
.
updateColorsAtCurrentPane
();
}
}
signal
colorSelected
(
color
selectedColor
);
onClosing
:
colorSelected
(
currentColor
);
function
showDialog
(
startColor
){
currentColor
=
startColor
;
this
.
startColor
=
startColor
;
visible
=
true
;
}
ColumnLayout
{
anchors.fill
:
parent
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment