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){
...
@@ -26,22 +26,16 @@ QString toName(Modules::ValueType t){
return
"wrong_type"
;
return
"wrong_type"
;
}
}
}
}
QString
toName
(
Modules
::
Property
::
Type
t
){
QString
toName
(
Modules
::
Property
::
Type
t
)
{
switch
(
t
)
{
switch
(
t
)
{
case
Modules
::
Property
::
Bool
:
case
Modules
::
Property
::
Bool
:
return
QStringLiteral
(
"bool"
);
return
"bool"
;
case
Modules
::
Property
::
Double
:
return
QStringLiteral
(
"double"
);
case
Modules
::
Property
::
Double
:
case
Modules
::
Property
::
Float
:
return
QStringLiteral
(
"float"
);
return
"double"
;
case
Modules
::
Property
::
Int
:
return
QStringLiteral
(
"int"
);
case
Modules
::
Property
::
Float
:
case
Modules
::
Property
::
Long
:
return
QStringLiteral
(
"long"
);
return
"float"
;
case
Modules
::
Property
::
String
:
return
QStringLiteral
(
"std::string"
);
case
Modules
::
Property
::
Int
:
case
Modules
::
Property
::
RGB
:
return
QStringLiteral
(
"rgb_t"
);
return
"int"
;
default:
return
QStringLiteral
(
"wrong_type"
);
case
Modules
::
Property
::
Long
:
return
"long"
;
case
Modules
::
Property
::
String
:
return
"std::string"
;
default:
return
"wrong_type"
;
}
}
}
}
...
@@ -892,12 +886,14 @@ void CodeHighlighter::highlightBlock(const QString &text)
...
@@ -892,12 +886,14 @@ void CodeHighlighter::highlightBlock(const QString &text)
QTextStream
&
writeDeclaration
(
QTextStream
&
out
,
const
Modules
::
detail
::
PropertyInformation
*
p
){
QTextStream
&
writeDeclaration
(
QTextStream
&
out
,
const
Modules
::
detail
::
PropertyInformation
*
p
){
using
namespace
Modules
;
using
namespace
Modules
;
if
(
p
->
getType
()
==
Property
::
Bool
){
if
(
p
->
getType
()
==
Property
::
Bool
)
{
out
<<
"BoolProperty _"
<<
p
->
getName
()
<<
';'
<<
endl
;
out
<<
"BoolProperty _"
<<
p
->
getName
()
<<
';'
<<
endl
;
}
else
if
(
p
->
getType
()
==
Property
::
String
){
}
else
if
(
p
->
getType
()
==
Property
::
String
)
{
out
<<
"StringProperty _"
<<
p
->
getName
()
<<
";"
<<
endl
;
out
<<
"StringProperty _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
else
{
}
else
if
(
p
->
getType
()
==
Property
::
RGB
)
{
out
<<
"NumericProperty<"
<<
toName
(
p
->
getType
())
<<
"> _"
<<
p
->
getName
()
<<
";"
<<
endl
;
out
<<
"RGBProperty _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
else
{
out
<<
"NumericProperty<"
<<
toName
(
p
->
getType
())
<<
"> _"
<<
p
->
getName
()
<<
";"
<<
endl
;
}
}
return
out
;
return
out
;
}
}
...
@@ -946,9 +942,7 @@ void replacePropertiesUsages(QString &code, const Modules::PropertiesVector & ve
...
@@ -946,9 +942,7 @@ void replacePropertiesUsages(QString &code, const Modules::PropertiesVector & ve
case
Modules
::
Property
::
String
:
case
Modules
::
Property
::
String
:
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asString()->getString()"
);
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asString()->getString()"
);
break
;
break
;
case
Modules
::
Property
::
RGB
:
case
Modules
::
Property
::
RGB
:
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asRGB()->getRGB()"
);
break
;
code
.
replace
(
regex
,
"_"
+
p
->
getName
()
+
".asRGB()"
);
break
;
}
}
}
}
}
}
...
...
src/gui/programblockeditor.cpp
View file @
5b9dc8f8
...
@@ -418,7 +418,6 @@ void transferData(GUI::detail::PropertyInformation *pi,Modules::Property * p){
...
@@ -418,7 +418,6 @@ void transferData(GUI::detail::PropertyInformation *pi,Modules::Property * p){
void
detail
::
PropertyInformation
::
updateValue
(){
void
detail
::
PropertyInformation
::
updateValue
(){
qDebug
()
<<
"set value"
;
using
namespace
Modules
;
using
namespace
Modules
;
if
(
named
){
if
(
named
){
auto
p
=
dynamic_cast
<
Program
*>
(
named
);
auto
p
=
dynamic_cast
<
Program
*>
(
named
);
...
@@ -443,11 +442,12 @@ void detail::PropertyInformation::updateValue(){
...
@@ -443,11 +442,12 @@ void detail::PropertyInformation::updateValue(){
case
Property
::
Int
:
transferData
<
int
>
(
this
,
property
);
case
Property
::
Int
:
transferData
<
int
>
(
this
,
property
);
break
;
break
;
case
Property
::
Long
:
transferData
<
int64_t
>
(
this
,
property
);
break
;
case
Property
::
Long
:
transferData
<
int64_t
>
(
this
,
property
);
break
;
case
Property
::
Bool
:
case
Property
::
Bool
:
property
->
asBool
()
->
setValue
(
getValue
().
toBool
());
break
;
property
->
asBool
()
->
setValue
(
getValue
().
toBool
());
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
;
break
;
case
Property
::
String
:
property
->
asString
()
->
setValue
(
getValue
().
toString
().
toStdString
());
}
}
}
}
...
@@ -613,8 +613,11 @@ void ProgramBlockEditor::mouseReleaseEvent(QMouseEvent *event){
...
@@ -613,8 +613,11 @@ void ProgramBlockEditor::mouseReleaseEvent(QMouseEvent *event){
tp
.
setMaxValue
(
1
);
tp
.
setMaxValue
(
1
);
tp
.
setValue
(
sp
.
asBool
()
->
getValue
());
tp
.
setValue
(
sp
.
asBool
()
->
getValue
());
break
;
break
;
case
Property
::
String
:
case
Property
::
String
:
tp
.
setValue
(
QString
::
fromStdString
(
sp
.
asString
()
->
getString
()));
break
;
tp
.
setValue
(
QString
::
fromStdString
(
sp
.
asString
()
->
getString
()));
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[]) {
...
@@ -237,7 +237,7 @@ int main(int argc, char *argv[]) {
valueTypeList
<<
QStringLiteral
(
"Brightness"
)
<<
QStringLiteral
(
"RGB"
)
;
valueTypeList
<<
QStringLiteral
(
"Brightness"
)
<<
QStringLiteral
(
"RGB"
)
;
QStringList
modolePropertyTypeList
;
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
// Does not work: do it manually
/*const QMetaObject &_momProp = Modules::detail::PropertyInformation::staticMetaObject;
/*const QMetaObject &_momProp = Modules::detail::PropertyInformation::staticMetaObject;
qDebug() << "Enum count" <<_momProp.enumeratorCount();
qDebug() << "Enum count" <<_momProp.enumeratorCount();
...
...
src/modules/types.h
View file @
5b9dc8f8
...
@@ -41,6 +41,7 @@ namespace Modules {
...
@@ -41,6 +41,7 @@ namespace Modules {
brightness_t
rgb
[
3
];
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
(
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
::
hsl_t
hsl
);
rgb_t
(
Modules
::
hsv_t
hsv
);
rgb_t
(
Modules
::
hsv_t
hsv
);
hsl_t
toHSL
()
const
;
hsl_t
toHSL
()
const
;
...
@@ -410,9 +411,10 @@ namespace Modules {
...
@@ -410,9 +411,10 @@ namespace Modules {
* Must be here, in the Property.hpp we have no rgb_t type
* 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
* @brief The RGBProperty class is a Property wrapper araoud the rgb_t type
*/
*/
class
RGBProperty
:
public
Property
{
class
RGBProperty
:
public
Property
{
private:
rgb_t
value
;
rgb_t
value
;
public:
RGBProperty
()
:
Property
(
Property
::
RGB
),
value
(
0
,
0
,
0
){}
RGBProperty
()
:
Property
(
Property
::
RGB
),
value
(
0
,
0
,
0
){}
void
save
(
SaveObject
&
o
)
const
override
{
void
save
(
SaveObject
&
o
)
const
override
{
...
...
src/qml/ModuleProgramView.qml
View file @
5b9dc8f8
...
@@ -3,6 +3,7 @@ import QtQuick.Controls 2.4
...
@@ -3,6 +3,7 @@ import QtQuick.Controls 2.4
import
QtQuick
.
Layouts
1.3
import
QtQuick
.
Layouts
1.3
import
custom
.
licht
1.0
import
custom
.
licht
1.0
import
QtQuick
.
Dialogs
1.2
import
QtQuick
.
Dialogs
1.2
import
QtQuick
.
Controls
.
Material
2.12
import
"
components
"
import
"
components
"
Item
{
Item
{
...
@@ -298,10 +299,13 @@ Item{
...
@@ -298,10 +299,13 @@ Item{
checkBox
.
checked
=
data
.
value
checkBox
.
checked
=
data
.
value
}
else
if
(
data
.
type
==
5
/*string*/
){
}
else
if
(
data
.
type
==
5
/*string*/
){
textInput
.
text
=
data
.
value
textInput
.
text
=
data
.
value
}
else
if
(
data
.
type
==
6
/*rgb*/
){
colorChooser
.
currentColor
=
data
.
value
;
}
}
spinBox
.
visible
=
data
.
type
<=
3
;
spinBox
.
visible
=
data
.
type
<=
3
;
checkBox
.
visible
=
data
.
type
==
4
;
checkBox
.
visible
=
data
.
type
==
4
;
textInput
.
visible
=
data
.
type
==
5
;
textInput
.
visible
=
data
.
type
==
5
;
colorButton
.
visible
=
data
.
type
==
6
;
}
}
}
}
...
@@ -332,6 +336,23 @@ Item{
...
@@ -332,6 +336,23 @@ Item{
CheckBox
{
CheckBox
{
id
:
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
{
TextInputField
{
Layout.margins
:
10
Layout.margins
:
10
id
:
textInput
id
:
textInput
...
...
src/qml/components/ColorDialog.qml
View file @
5b9dc8f8
...
@@ -11,15 +11,15 @@ Window {
...
@@ -11,15 +11,15 @@ Window {
Qt
.
WindowSystemMenuHint
|
Qt
.
WindowTitleHint
|
Qt
.
WindowCloseButtonHint
Qt
.
WindowSystemMenuHint
|
Qt
.
WindowTitleHint
|
Qt
.
WindowCloseButtonHint
property
color
currentColor
;
property
color
currentColor
;
property
color
startColor
;
property
color
startColor
;
onVisibleChanged
:
if
(
visible
)
swipeView
.
updateColorsAtCurrentPane
();
onVisibleChanged
:
{
if
(
visible
){
currentColor
=
startColor
;
swipeView
.
updateColorsAtCurrentPane
();
}
}
signal
colorSelected
(
color
selectedColor
);
signal
colorSelected
(
color
selectedColor
);
onClosing
:
colorSelected
(
currentColor
);
onClosing
:
colorSelected
(
currentColor
);
function
showDialog
(
startColor
){
currentColor
=
startColor
;
this
.
startColor
=
startColor
;
visible
=
true
;
}
ColumnLayout
{
ColumnLayout
{
anchors.fill
:
parent
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