66 lines
2.5 KiB
C++
66 lines
2.5 KiB
C++
#include "views/quartsbutton.h"
|
|
#include "quickhelper.h"
|
|
|
|
QuartsButton::QuartsButton(QQuickItem *root) : QObject(root), root(root) {
|
|
}
|
|
|
|
void QuartsButton::setButtonText(const QString &text)
|
|
{
|
|
if (textElement) {
|
|
textElement->setProperty("text", text);
|
|
}
|
|
}
|
|
|
|
void QuartsButton::setEnabled(bool value){
|
|
if(element) element->setEnabled(value);
|
|
|
|
if (value) {
|
|
if (typeFilled == Filled) {
|
|
if(textElement) textElement->setProperty("color", textColorEnabledBase);
|
|
} else {
|
|
if(textElement) textElement->setProperty("color", textColorEnabledEmpty);
|
|
}
|
|
} else {
|
|
if(textElement) textElement->setProperty("color", textColorDisabled);
|
|
}
|
|
}
|
|
|
|
void QuartsButton::init() {
|
|
element = QuickHelper::getQuickItem(root, name);
|
|
|
|
bool retCode = true;
|
|
if (!element) {
|
|
qWarning() << "Failed to get element:" << name;
|
|
retCode = false;
|
|
}
|
|
|
|
if( retCode == false) return;
|
|
|
|
textElement = QuickHelper::getQuickItem(root, textElementName);
|
|
|
|
QuickHelper::addMouseAreaElements(element,
|
|
[this] {if(element->isEnabled()) emit clicked();},
|
|
[this] {
|
|
if (element->isEnabled()) {
|
|
element->setProperty("color", focusedColor);
|
|
if(textElement) textElement->setProperty("color", textColorEnabledFocused);
|
|
}
|
|
}, [this] {
|
|
if (element->isEnabled()) {
|
|
if (typeFilled == Filled){
|
|
element->setProperty("color", baseColor);
|
|
if(textElement) textElement->setProperty("color", textColorEnabledBase);
|
|
} else {
|
|
element->setProperty("color", emptyColor);
|
|
if(textElement) textElement->setProperty("color", textColorEnabledEmpty);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (typeFilled == Filled) {
|
|
QuickHelper::updateColor(element, disabledColor, baseColor);
|
|
} else {
|
|
QuickHelper::updateColor(element, disabledColor, emptyColor);
|
|
}
|
|
}
|