-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
FloatingTextField added #261
base: develop
Are you sure you want to change the base?
Changes from all commits
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,99 @@ | ||
import QtQuick 2.11 | ||
import QtQuick.Controls 2.4 | ||
import QtQuick.Controls.Material 2.4 | ||
import QtQuick.Templates 2.4 as T | ||
|
||
import Fluid.Controls 1.0 | ||
|
||
T.TextField { | ||
id: control | ||
|
||
implicitWidth: Math.max((background ? background.implicitWidth : 0), | ||
placeholderText ? | ||
placeholder.implicitWidth + | ||
leftPadding + rightPadding : 0) || | ||
(contentWidth + leftPadding + rightPadding) | ||
implicitHeight: Math.max(contentHeight + topPadding + bottomPadding, | ||
(background ? background.implicitHeight : 0), | ||
placeholder.implicitHeight + topPadding + bottomPadding) | ||
|
||
topPadding: contentHeight | ||
bottomPadding: Units.smallSpacing * 2 | ||
|
||
selectByMouse: true | ||
|
||
Label { | ||
id: placeholder | ||
|
||
anchors.top: parent.top | ||
x: control.leftPadding | ||
|
||
font: control.font | ||
text: control.placeholderText | ||
elide: Label.AlignRight | ||
width: control.width - (control.leftPadding + control.rightPadding) | ||
|
||
readonly property int offset: Qt.application.font.pixelSize | ||
|
||
|
||
states: [ | ||
State { | ||
name: "focused" | ||
when: control.focus | ||
PropertyChanges { | ||
target: placeholder | ||
|
||
color: enabled ? Material.accent : Material.hintTextColor | ||
font.pointSize: Qt.application.font.pointSize | ||
anchors.topMargin: 0 | ||
} | ||
}, | ||
State { | ||
name: "notFocusedNotEmpty" | ||
when: !control.focus && control.text != "" | ||
PropertyChanges { | ||
target: placeholder | ||
|
||
font.pointSize: Qt.application.font.pointSize | ||
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. using 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. This works on my linux and windows systems NumberAnimation {
properties: "anchors.topMargin,font.pointSize"
duration: Units.shortDuration
easing.type: Easing.InOutQuad
} |
||
anchors.topMargin: 0 | ||
color: Material.hintTextColor | ||
} | ||
}, | ||
State { | ||
name: "notFocusedEmpty" | ||
when: !control.focus && control.text == "" | ||
PropertyChanges { | ||
target: placeholder | ||
|
||
color: Material.hintTextColor | ||
anchors.topMargin: offset * 2 | ||
font.pointSize: Qt.application.font.pointSize + 2 | ||
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. Is this line needed ? Shouldn't we keep the font size the same as the textfield font size ? 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. according to guideline it's needed |
||
} | ||
} | ||
] | ||
|
||
transitions: [ | ||
Transition { | ||
NumberAnimation { | ||
properties: "anchors.topMargin,font.pointSize" | ||
duration: Units.shortDuration | ||
easing.type: Easing.InOutQuad | ||
} | ||
ColorAnimation { | ||
duration: Units.shortDuration | ||
} | ||
} | ||
] | ||
} | ||
|
||
background: Rectangle { | ||
y: control.height - height - control.bottomPadding + 8 | ||
implicitWidth: 120 | ||
height: control.activeFocus || control.hovered ? 2 : 1 | ||
color: control.activeFocus ? | ||
control.Material.accentColor : | ||
(control.hovered ? | ||
control.Material.primaryTextColor : | ||
control.Material.hintTextColor) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the import version compatible with Qt 5.10 ?
2.10 and 2.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't think about that, I'm using latest qt. I'm not sure it's necessary to support 5.10