Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkdeclarative
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#362
  • Loading branch information
deepin-ci-robot committed Jul 24, 2024
1 parent c2d07b2 commit 3fcefa2
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 45 deletions.
22 changes: 22 additions & 0 deletions qt6/src/qml/ButtonBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QtQuick 2.11
import QtQuick.Layouts 1.11
import org.deepin.dtk 1.0 as D
import org.deepin.dtk.style 1.0 as DS
import org.deepin.dtk.private 1.0 as P

Control {
id: control
Expand All @@ -31,4 +32,25 @@ Control {
outsideBorderColor: null
color2: color1
}

ParallelAnimation {
running: btnGroup.checkedButton.x !== backgroundPanel.x
NumberAnimation { target: backgroundPanel; property: "x"; to: btnGroup.checkedButton.x; duration: 200 }
NumberAnimation { target: backgroundPanel; property: "y"; to: btnGroup.checkedButton.y; duration: 200 }
}

P.ButtonPanel {
id: backgroundPanel
visible: btnGroup.checkedButton
implicitWidth: btnGroup.checkedButton.width
implicitHeight: btnGroup.checkedButton.height
button: control
outsideBorderColor: null
color1: D.Palette {
normal {
common: Qt.rgba(0, 0, 0, 0.2)
}
}
color2: color1
}
}
4 changes: 2 additions & 2 deletions qt6/src/qml/FlowStyle.qml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ QtObject {

property QtObject radioButton: QtObject {
property int indicatorSize: 16
property int iconSize: 16
property int iconSize: 36
property int spacing: 8
property int topPadding: 12
property int bottomPadding: 12
Expand All @@ -397,7 +397,7 @@ QtObject {
property int indicatorWidth: 16
property int indicatorHeight: 16
property int padding: 2
property int iconSize: 16
property int iconSize: 36
property int focusRadius: 4
}

Expand Down
46 changes: 19 additions & 27 deletions qt6/src/qml/Switch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,32 @@ T.Switch {
bottomPadding: DS.Style.control.vPadding
spacing: DS.Style.control.spacing

indicator: Rectangle {
indicator: D.DciIcon {
id: handle
implicitWidth: DS.Style.switchButton.indicatorWidth
implicitHeight: DS.Style.switchButton.indicatorHeight

x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
y: control.topPadding + (control.availableHeight - height) / 2
radius: DS.Style.control.radius
color: control.D.ColorSelector.backgroundColor
opacity: control.D.ColorSelector.controlState === D.DTK.DisabledState ? 0.4 : 1

D.DciIcon {
id: handle
x: Math.max(0, Math.min(parent.width - width, control.visualPosition * parent.width - (width / 2)))
y: (parent.height - height) / 2
width: DS.Style.switchButton.handleWidth
height: DS.Style.switchButton.handleHeight
sourceSize: Qt.size(DS.Style.switchButton.handleWidth, DS.Style.switchButton.handleHeight)
name: DS.Style.switchButton.iconName
opacity: control.D.ColorSelector.controlState === D.DTK.DisabledState && control.checked ? 0.4 : 1
palette {
highlight: control.checked ? control.palette.highlight : control.D.ColorSelector.handleColor
highlightForeground: control.palette.highlightedText
foreground: control.palette.windowText
background: control.palette.window
}
mode: control.D.ColorSelector.controlState
theme: control.D.ColorSelector.controlTheme
fallbackToQIcon: false

Behavior on x {
enabled: !control.down
SmoothedAnimation { velocity: 200 }
}
width: DS.Style.switchButton.handleWidth
height: DS.Style.switchButton.handleHeight
sourceSize: Qt.size(DS.Style.switchButton.indicatorWidth, DS.Style.switchButton.indicatorWidth)
name: !control.checked ? "switch_on" : "switch_off"
opacity: control.D.ColorSelector.controlState === D.DTK.DisabledState && control.checked ? 0.4 : 1
palette {
highlight: control.checked ? control.palette.highlight : control.D.ColorSelector.handleColor
highlightForeground: control.palette.highlightedText
foreground: control.palette.windowText
background: control.palette.window
}
mode: control.D.ColorSelector.controlState
theme: control.D.ColorSelector.controlTheme
fallbackToQIcon: false
}

onCheckedChanged: {
handle.play(D.DTK.NormalState)
}

contentItem: Label {
Expand Down
32 changes: 31 additions & 1 deletion qt6/src/qml/ToolButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.deepin.dtk.private 1.0 as P

T.ToolButton {
id: control
property D.Palette textColor: checked ? DS.Style.checkedButton.text : (highlighted ? DS.Style.highlightedButton.text : DS.Style.button.text)
property D.Palette textColor: checked ? DS.Style.highlightedButton.text : (highlighted ? DS.Style.highlightedButton.text : DS.Style.button.text)

implicitWidth: DS.Style.control.implicitWidth(control)
implicitHeight: DS.Style.control.implicitHeight(control)
Expand Down Expand Up @@ -66,10 +66,40 @@ T.ToolButton {
}
}

states: [
State {
name: "hovered"
when: control.hovered && !control.checked
PropertyChanges {
target: contentItem
scale : 1.2
}
},
State {
name: "checked"
when: control.checked
PropertyChanges {
target: contentItem
scale : 1.0
}
}
]

transitions: Transition {
NumberAnimation { properties: "scale"; easing.type: Easing.InOutQuad }
}

background: P.ButtonPanel {
visible: control.state === "hovered"
implicitWidth: DS.Style.toolButton.width
implicitHeight: DS.Style.toolButton.height
button: control
outsideBorderColor: null
color1: D.Palette {
normal {
common: Qt.rgba(0, 0, 0, 0.1)
}
}
color2 : color1
}
}
3 changes: 2 additions & 1 deletion src/dtkdeclarative_assets.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
<file alias="built-in-icons/slider_point_left.dci">icons/bloom/slider_point_left.dci</file>
<file alias="built-in-icons/slider_round_hor.dci">icons/bloom/slider_round_hor.dci</file>
<file alias="built-in-icons/slider_round_ver.dci">icons/bloom/slider_round_ver.dci</file>
<file alias="built-in-icons/switch_button.dci">icons/bloom/switch_button.dci</file>
<file alias="built-in-icons/switch_on.dci">icons/bloom/switch_on.dci</file>
<file alias="built-in-icons/switch_off.dci">icons/bloom/switch_off.dci</file>
<file alias="built-in-icons/slider_point_up.dci">icons/bloom/slider_point_up.dci</file>
<file alias="built-in-icons/checkbox_mix.dci">icons/bloom/checkbox_mix.dci</file>
<file alias="built-in-icons/checkbox_checked.dci">icons/bloom/checkbox_checked.dci</file>
Expand Down
Binary file modified src/icons/bloom/checkbox_checked.dci
Binary file not shown.
Binary file modified src/icons/bloom/checkbox_unchecked.dci
Binary file not shown.
Binary file modified src/icons/bloom/radio_checked.dci
Binary file not shown.
Binary file modified src/icons/bloom/radio_unchecked.dci
Binary file not shown.
Binary file added src/icons/bloom/switch_off.dci
Binary file not shown.
Binary file added src/icons/bloom/switch_on.dci
Binary file not shown.
126 changes: 112 additions & 14 deletions src/private/dquickdciiconimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ static QString appIconThemeName()
return DGuiApplicationHelper::instance()->applicationTheme()->iconThemeName();
}

static QString findDciIconPath(const QString &iconName, const QString &themeName)
{
QString iconPath;
auto cached = DIconTheme::cached();

if (cached) {
iconPath = cached->findDciIconFile(iconName, themeName);
} else {
iconPath = DIconTheme::findDciIconFile(iconName, themeName);
}
return iconPath;
}

static DDciIcon::Mode controlState2DciMode(int state)
{
DDciIcon::Mode dcimode = DDciIcon::Normal;
switch (state) {
case DQMLGlobalObject::NormalState:
dcimode = DDciIcon::Normal;
break;
case DQMLGlobalObject::DisabledState:
dcimode = DDciIcon::Disabled;
break;
case DQMLGlobalObject::HoveredState:
dcimode = DDciIcon::Hover;
break;
case DQMLGlobalObject::PressedState:
dcimode = DDciIcon::Pressed;
break;
default:
break;
}

return dcimode;
}

static inline DDciIcon::Theme dciTheme(DGuiApplicationHelper::ColorType type)
{
return type == DGuiApplicationHelper::DarkType ? DDciIcon::Dark : DDciIcon::Light;
}

DQuickDciIconImageItemPrivate::DQuickDciIconImageItemPrivate(DQuickDciIconImagePrivate *pqq)
: parentPriv(pqq)
{
Expand All @@ -31,11 +72,23 @@ void DQuickDciIconImageItemPrivate::maybeUpdateUrl()
return DQuickIconImagePrivate::maybeUpdateUrl();
}

QUrl url;
url.setScheme(QLatin1String("image"));
url.setHost(QLatin1String("dtk.dci.icon"));
url.setQuery(getUrlQuery());
q->setSource(url);
updatePlayer();

if (player)
player->setMode(controlState2DciMode(parentPriv->mode));
}

void DQuickDciIconImageItemPrivate::play(int mode)
{
Q_Q(DQuickIconImage);
if (parentPriv->imageItem->name().isEmpty() || iconType != ThemeIconName) {
return;
}

updatePlayer();

if (player)
player->play(controlState2DciMode(mode));
}

QUrlQuery DQuickDciIconImageItemPrivate::getUrlQuery()
Expand All @@ -56,6 +109,47 @@ QUrlQuery DQuickDciIconImageItemPrivate::getUrlQuery()
return query;
}

void DQuickDciIconImageItemPrivate::updatePlayer()
{
if (!player) {
Q_Q(DQuickIconImage);
player = new DDciIconPlayer(parentPriv->imageItem);
QObject::connect(player, &DDciIconPlayer::updated, parentPriv->imageItem, [this](){
// qDebug() << "setimage" << player->mode() << "" << player->state();
parentPriv->imageItem->setImage(player->currentImage());
});
}

QString iconPath = findDciIconPath(parentPriv->imageItem->name(), appIconThemeName());

// 防止频繁构造 dciicon
if (player->property("_d_dci_icon_path").toString() != iconPath) {
DDciIcon dciIcon(iconPath);
if (!dciIcon.isNull()) {
player->setIcon(dciIcon);
player->setProperty("_d_dci_icon_path", iconPath);
}
}

player->setTheme(dciTheme(parentPriv->theme));

DDciIconPalette palette = parentPriv->palette;
if (!parentPriv->palette.foreground().isValid() && q_func()->color().isValid())
palette.setForeground(q_func()->color());

player->setPalette(palette);

int boundingSize = qMax(q_func()->sourceSize().width(), q_func()->sourceSize().height());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
#endif
boundingSize = qRound(boundingSize / devicePixelRatio);

player->setIconSize(boundingSize);

player->setDevicePixelRatio(devicePixelRatio);
}

DQuickDciIconImagePrivate::DQuickDciIconImagePrivate(DQuickDciIconImage *qq)
: DObjectPrivate(qq)
, imageItem(new DQuickIconImage(*new DQuickDciIconImageItemPrivate(this), qq))
Expand All @@ -76,6 +170,11 @@ void DQuickDciIconImagePrivate::updateImageSourceUrl()
imageItem->d_func()->maybeUpdateUrl();
}

void DQuickDciIconImagePrivate::play(DQMLGlobalObject::ControlState mode)
{
imageItem->d_func()->play(mode);
}

DQuickDciIconImage::DQuickDciIconImage(QQuickItem *parent)
: QQuickItem(parent)
, DObject(*new DQuickDciIconImagePrivate(this))
Expand Down Expand Up @@ -119,6 +218,13 @@ void DQuickDciIconImage::setMode(DQMLGlobalObject::ControlState mode)
Q_EMIT modeChanged();
}

void DQuickDciIconImage::play(DQMLGlobalObject::ControlState mode)
{
D_D(DQuickDciIconImage);
if (d->imageItem)
d->play(mode);
}

DGuiApplicationHelper::ColorType DQuickDciIconImage::theme() const
{
D_DC(DQuickDciIconImage);
Expand Down Expand Up @@ -226,15 +332,7 @@ Dtk::Quick::DQuickIconImage *DQuickDciIconImage::imageItem() const

bool DQuickDciIconImage::isNull(const QString &iconName)
{
QString iconPath;
auto cached = DIconTheme::cached();

if (cached) {
iconPath = cached->findDciIconFile(iconName, appIconThemeName());
} else {
iconPath = DIconTheme::findDciIconFile(iconName, appIconThemeName());
}
return iconPath.isEmpty();
return findDciIconPath(iconName, appIconThemeName()).isEmpty();
}

DQuickIconAttached *DQuickDciIconImage::qmlAttachedProperties(QObject *object)
Expand Down
1 change: 1 addition & 0 deletions src/private/dquickdciiconimage_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DQuickDciIconImage : public QQuickItem, DCORE_NAMESPACE::DObject

DQMLGlobalObject::ControlState mode() const;
void setMode(DQMLGlobalObject::ControlState mode);
Q_INVOKABLE void play(DQMLGlobalObject::ControlState mode);

DGuiApplicationHelper::ColorType theme() const;
void setTheme(DGuiApplicationHelper::ColorType theme);
Expand Down
5 changes: 5 additions & 0 deletions src/private/dquickdciiconimage_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <dobject_p.h>
#include <DDciIconPalette>
#include <DDciIconPlayer>

DQUICK_BEGIN_NAMESPACE
class DQuickDciIconImageItemPrivate;
Expand All @@ -22,10 +23,13 @@ class DQuickDciIconImageItemPrivate : public DQuickIconImagePrivate
public:
DQuickDciIconImageItemPrivate(DQuickDciIconImagePrivate *pqq);

Check warning on line 24 in src/private/dquickdciiconimage_p_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DQuickDciIconImageItemPrivate' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
void maybeUpdateUrl();
void play(int mode);
QUrlQuery getUrlQuery();

void updatePlayer();
private:
DQuickDciIconImagePrivate *parentPriv;
DDciIconPlayer *player = nullptr;
};

class DQuickDciIconImagePrivate : public DCORE_NAMESPACE::DObjectPrivate
Expand All @@ -36,6 +40,7 @@ class DQuickDciIconImagePrivate : public DCORE_NAMESPACE::DObjectPrivate
DQuickDciIconImagePrivate(DQuickDciIconImage *qq);

Check warning on line 40 in src/private/dquickdciiconimage_p_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DQuickDciIconImagePrivate' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
void layout();
void updateImageSourceUrl();
void play(DQMLGlobalObject::ControlState mode);

DDciIconPalette palette;
DQuickIconImage *imageItem;
Expand Down
Loading

0 comments on commit 3fcefa2

Please sign in to comment.