Feat: 实现QML主题框架支持RoundButton

This commit is contained in:
yan wang 2023-01-10 09:08:12 +08:00 committed by 谭静
parent 02f4d8e361
commit 7f4ae43169
3 changed files with 59 additions and 5 deletions

View File

@ -1475,16 +1475,18 @@ void KyQuickStyleItem::paint(QPainter *painter)
switch (m_itemType) {
case Button:{
QWidget wid;
if(m_buttonType=="MaxButton" || m_buttonType=="MinButton" ){
if(m_buttonType == "MaxButton" || m_buttonType == "MinButton") {
wid.setProperty("isWindowButton", QVariant(0x01));
}
if(m_buttonType=="CloseButton"){
if(m_buttonType == "CloseButton") {
wid.setProperty("isWindowButton", QVariant(0x02));
}
if(m_buttonType=="blueButton"){
wid.setProperty("isImportant",true);
if(m_buttonType == "blueButton") {
wid.setProperty("isImportant", true);
}
if(m_roundButton == "RoundButton") {
wid.setProperty("isRoundButton", true);
}
KyQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter,&wid);
}
break;

View File

@ -66,6 +66,7 @@ class KyQuickStyleItem: public QQuickItem
Q_PROPERTY( int bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged)
Q_PROPERTY( QString buttonType READ buttonType WRITE setbuttonType NOTIFY buttonTypeChanged)
Q_PROPERTY( QString roundButton READ roundButton WRITE setroundButton NOTIFY roundButtonChanged)
Q_PROPERTY( QQuickItem *control READ control WRITE setControl NOTIFY controlChanged)
@ -199,6 +200,12 @@ public:
emit buttonTypeChanged();
}
QString roundButton() const { return m_roundButton;}
void setroundButton(QString roundButton) {
m_roundButton = roundButton ;
emit roundButtonChanged();
}
public Q_SLOTS:
int pixelMetric(const QString&);
QVariant styleHint(const QString&);
@ -248,6 +255,7 @@ Q_SIGNALS:
void bottomPaddingChanged();
void buttonTypeChanged();
void roundButtonChanged();
protected:
bool event(QEvent *) override;
@ -305,6 +313,7 @@ protected:
static QStyle *s_style;
QString m_buttonType;
QString m_roundButton;
};
#endif // KYQUICKSTYLEITEM_H

View File

@ -0,0 +1,43 @@
import QtQuick 2.6
import QtQuick.Templates 2.5 as T
import org.ukui.qqc2style.private 1.0 as StylePrivate
T.RoundButton {
id: controlRoot
palette: StylePrivate.StyleHelper.palette
/* The value type of buttonType are "CloseButton","MaxButton","MinButton","blueButton","Default". */
StylePrivate.StyleHelper.buttonType: "Default"
implicitWidth: background.implicitWidth
implicitHeight: background.implicitHeight
hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7?
contentItem: Item {}
background: StylePrivate.StyleItem {
id: styleitem
anchors.fill: parent
buttonType: controlRoot.StylePrivate.StyleHelper.buttonType
control: controlRoot
elementType: "button"
roundButton:"RoundButton"
sunken: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
raised: !(controlRoot.pressed || (controlRoot.checkable && controlRoot.checked))
hover: controlRoot.hovered
text: controlRoot.text
hasFocus: controlRoot.activeFocus
activeControl: controlRoot.isDefault ? "default" : "f"
properties: {
"icon": controlRoot.icon && controlRoot.display !== T.AbstractButton.TextOnly ? (controlRoot.icon.name || controlRoot.icon.source) : "",
"iconWidth": controlRoot.icon && controlRoot.icon.width ? controlRoot.icon.width : 0,
"iconHeight": controlRoot.icon && controlRoot.icon.height ? controlRoot.icon.height : 0,
"flat": controlRoot.flat
}
}
}