-
Notifications
You must be signed in to change notification settings - Fork 90
Storybook: generic, unified theme handling #19596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6363f92
2a28069
aad768c
64f74e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import QtCore | ||
| import QtQuick | ||
| import QtQuick.Layouts | ||
| import QtQuick.Controls | ||
|
|
||
| import StatusQ.Core.Theme | ||
|
|
||
| Loader { | ||
| id: root | ||
|
|
||
| function setPage(pageName: string, pageItem: Item) { | ||
| active = false | ||
| d.currentPage = pageName | ||
| d.currentPageItem = pageItem | ||
| active = true | ||
| } | ||
|
|
||
| function clear() { | ||
| root.active = false | ||
| } | ||
|
|
||
| QtObject { | ||
| id: d | ||
|
|
||
| property string currentPage | ||
| property Item currentPageItem | ||
| } | ||
|
|
||
| active: false | ||
|
|
||
| sourceComponent: Item { | ||
| RoundButton { | ||
| id: openPopupButton | ||
|
|
||
| anchors.right: parent.right | ||
| anchors.top: parent.top | ||
| anchors.margins: 5 | ||
|
|
||
| text: "🎨📏" | ||
| font.pixelSize: 20 | ||
|
|
||
| checkable: true | ||
| checked: popup.visible | ||
|
|
||
| onClicked: { | ||
| if (!popup.visible) | ||
| popup.open() | ||
| else | ||
| popup.close() | ||
| } | ||
| } | ||
|
|
||
| Popup { | ||
| id: popup | ||
|
|
||
| parent: openPopupButton | ||
|
|
||
| x: -width + parent.width | ||
| y: parent.height + 5 | ||
|
|
||
| closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent | ||
|
|
||
| PageOverlayPanel { | ||
| style: d.currentPageItem.Theme.style | ||
| themePadding: d.currentPageItem.Theme.padding | ||
| fontSizeOffset: d.currentPageItem.Theme.fontSizeOffset | ||
|
|
||
| onStyleRequested: style => { | ||
| d.currentPageItem.Theme.style = style | ||
| } | ||
|
|
||
| onPaddingRequested: padding => { | ||
| d.currentPageItem.Theme.padding = padding | ||
| } | ||
|
|
||
| onPaddingFactorRequested: paddingFactor => { | ||
| ThemeUtils.setPaddingFactor(d.currentPageItem, paddingFactor) | ||
| } | ||
|
|
||
| onFontSizeOffsetRequested: fontSizeOffset => { | ||
| d.currentPageItem.Theme.fontSizeOffset = fontSizeOffset | ||
| } | ||
|
|
||
| onFontSizeRequested: fontSize => { | ||
| ThemeUtils.setFontSize(d.currentPageItem, fontSize) | ||
| } | ||
|
|
||
| onResetRequested: { | ||
| d.currentPageItem.Theme.style = undefined | ||
| d.currentPageItem.Theme.padding = undefined | ||
| d.currentPageItem.Theme.fontSizeOffset = undefined | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Component.onCompleted: { | ||
| if (!settings.initialized) { | ||
| settings.initialized = true | ||
| } else { | ||
| d.currentPageItem.Theme.style = settings.style | ||
| d.currentPageItem.Theme.padding = settings.padding | ||
| d.currentPageItem.Theme.fontSizeOffset = settings.fontSizeOffset | ||
| } | ||
|
|
||
| settings.style | ||
| = Qt.binding(() => d.currentPageItem.Theme.style) | ||
| settings.padding | ||
| = Qt.binding(() => d.currentPageItem.Theme.padding) | ||
| settings.fontSizeOffset | ||
| = Qt.binding(() => d.currentPageItem.Theme.fontSizeOffset) | ||
| } | ||
|
|
||
| Settings { | ||
| id: settings | ||
|
|
||
| category: "page_" + d.currentPage | ||
|
|
||
| property bool initialized | ||
| property int style | ||
| property real padding | ||
| property int fontSizeOffset | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| import QtQuick | ||
| import QtQuick.Layouts | ||
| import QtQuick.Controls | ||
|
|
||
| import StatusQ.Core.Theme | ||
|
|
||
| Control { | ||
| id: root | ||
|
|
||
| property int style // Theme.Style | ||
| property int fontSizeOffset | ||
| property real themePadding | ||
|
|
||
| signal styleRequested(int style) // Theme.Style | ||
|
|
||
| signal paddingRequested(int padding) | ||
caybro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| signal paddingFactorRequested(int paddingFactor) // ThemeUtils.PaddingFactor | ||
|
|
||
| signal fontSizeOffsetRequested(int fontSizeOffset) | ||
| signal fontSizeRequested(int fontSize) // ThemeUtils.FontSize | ||
|
|
||
| signal resetRequested | ||
|
|
||
| contentItem: ColumnLayout { | ||
| RowLayout { | ||
|
|
||
| Label { | ||
| text: "Theme:" | ||
| } | ||
|
|
||
| Flow { | ||
| Layout.fillWidth: true | ||
| spacing: 2 | ||
|
|
||
| RoundButton { | ||
| text: "Light" | ||
| checked: root.style === Theme.Style.Light | ||
|
|
||
| onClicked: root.styleRequested(Theme.Style.Light) | ||
| } | ||
|
|
||
| RoundButton { | ||
| text: "Dark" | ||
| checked: root.style === Theme.Style.Dark | ||
|
|
||
| onClicked: root.styleRequested(Theme.Style.Dark) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ToolSeparator { | ||
| orientation: Qt.Horizontal | ||
| Layout.fillWidth: true | ||
| } | ||
|
|
||
| RowLayout { | ||
| Label { | ||
| text: "Padding:" | ||
| } | ||
|
|
||
| Slider { | ||
| id: paddingSlider | ||
|
|
||
| Layout.fillWidth: true | ||
|
|
||
| from: 0 | ||
| to: 40 | ||
| stepSize: 1 | ||
|
|
||
| value: root.themePadding | ||
|
|
||
| onValueChanged: { | ||
| if (value !== root.themePadding) | ||
| root.paddingRequested(value) | ||
| } | ||
| } | ||
| Label { | ||
| text: root.themePadding | ||
| } | ||
| } | ||
|
|
||
| Flow { | ||
| Layout.fillWidth: true | ||
|
|
||
| spacing: 2 | ||
|
|
||
| Repeater { | ||
| model: [ | ||
| "XXS", "XS", "S", "M", "L" | ||
| ] | ||
|
|
||
| RoundButton { | ||
| required property string modelData | ||
|
|
||
| checked: root.themePadding === Theme.defaultPadding * ThemeUtils["paddingFactor" + modelData] | ||
|
|
||
| text: modelData | ||
|
|
||
| onClicked: root.paddingFactorRequested( | ||
| ThemeUtils["Padding" + modelData]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, does that work? 🤯 (converting a string to enum value)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just js. If sth can be accessed as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha... right... reminds me of the famous C array surprise 😆 int p[3] = {1, 2, 3};
assert(p[1] == 1[p]); // OK; exactly the same |
||
| } | ||
| } | ||
| } | ||
|
|
||
| ToolSeparator { | ||
| orientation: Qt.Horizontal | ||
| Layout.fillWidth: true | ||
| } | ||
|
|
||
| RowLayout { | ||
| Label { | ||
| text: "Font size offset:" | ||
| } | ||
|
|
||
| Slider { | ||
| id: fontSizeOffsetSlider | ||
|
|
||
| Layout.fillWidth: true | ||
|
|
||
| from: -4 | ||
| to: 6 | ||
| stepSize: 1 | ||
|
|
||
| value: root.fontSizeOffset | ||
|
|
||
|
|
||
| onValueChanged: { | ||
| if (root.fontSizeOffset !== value) | ||
| root.fontSizeOffsetRequested(value) | ||
| } | ||
| } | ||
|
|
||
| Label { | ||
| text: root.fontSizeOffset | ||
| } | ||
| } | ||
|
|
||
| Flow { | ||
| spacing: 2 | ||
|
|
||
| Layout.fillWidth: true | ||
|
|
||
| Repeater { | ||
| model: [ | ||
| "XS", "S", "M", "L", "XL", "XXL" | ||
| ] | ||
|
|
||
| RoundButton { | ||
| required property string modelData | ||
|
|
||
| checked: root.fontSizeOffset === | ||
| ThemeUtils["fontSizeOffset" + modelData] | ||
|
|
||
| text: modelData | ||
|
|
||
| onClicked: root.fontSizeRequested(ThemeUtils["FontSize" + modelData]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ToolSeparator { | ||
| orientation: Qt.Horizontal | ||
| Layout.fillWidth: true | ||
| } | ||
|
|
||
| RoundButton { | ||
| Layout.alignment: Qt.AlignHCenter | ||
| text: "Reset" | ||
|
|
||
| onClicked: root.resetRequested() | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.