Skip to content

Commit 444d9b2

Browse files
committed
fix(FluColorPicker): 修复多项颜色同步与输入问题
- 修复了 FluColorPicker 打开时滑块与 RGBA/HEX 数值未正确匹配当前颜色的问题。 - 修复了 FluColorPicker 设置 HEX 值时,RGBA 数值未同步更新的问题。 - 修复了 FluColorPicker HEX 输入框只能接受大写 A-F 字符的问题。
1 parent 1a8e3d5 commit 444d9b2

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

src/Qt5/imports/FluentUI/Controls/FluColorPicker.qml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ Button{
4747
implicitWidth: 326
4848
implicitHeight: 560
4949
closePolicy: Popup.CloseOnEscape
50+
onClosed: {
51+
text_box_r.focus = false;
52+
text_box_g.focus = false;
53+
text_box_b.focus = false;
54+
text_box_a.focus = false;
55+
text_box_color.focus = false;
56+
}
57+
onOpened: {
58+
layout_color_hue.updateColorText(current);
59+
text_box_color.textEdited();
60+
}
5061
Rectangle{
5162
id:layout_actions
5263
width: parent.width
@@ -148,7 +159,9 @@ Button{
148159
if(color.a===1){
149160
colorString = "FF"+colorString
150161
}
151-
text_box_color.text = colorString.toUpperCase()
162+
if (!text_box_color.activeFocus) {
163+
text_box_color.text = colorString.toUpperCase();
164+
}
152165
}
153166
property color blackColor: {
154167
var c = whiteColor
@@ -279,6 +292,11 @@ Button{
279292
preventStealing: true
280293
function handleMouse(mouse) {
281294
if (mouse.buttons & Qt.LeftButton) {
295+
text_box_r.focus = false;
296+
text_box_g.focus = false;
297+
text_box_b.focus = false;
298+
text_box_a.focus = false;
299+
text_box_color.focus = false;
282300
pickerCursor.x = Math.max(0,Math.min(mouse.x - colorHandleRadius,width-2*colorHandleRadius));
283301
pickerCursor.y = Math.max(0,Math.min(mouse.y - colorHandleRadius,height-2*colorHandleRadius));
284302
}
@@ -369,6 +387,11 @@ Button{
369387
preventStealing: true
370388
function handleMouse(mouse) {
371389
if (mouse.buttons & Qt.LeftButton) {
390+
text_box_r.focus = false;
391+
text_box_g.focus = false;
392+
text_box_b.focus = false;
393+
text_box_a.focus = false;
394+
text_box_color.focus = false;
372395
blackCursor.x = Math.max(0,Math.min(mouse.x - 6,width-2*6));
373396
blackCursor.y = 0
374397
}
@@ -438,6 +461,11 @@ Button{
438461
preventStealing: true
439462
function handleMouse(mouse) {
440463
if (mouse.buttons & Qt.LeftButton) {
464+
text_box_r.focus = false;
465+
text_box_g.focus = false;
466+
text_box_b.focus = false;
467+
text_box_a.focus = false;
468+
text_box_color.focus = false;
441469
opacityCursor.x = Math.max(0,Math.min(mouse.x - 6,width-2*6));
442470
opacityCursor.y = 0
443471
}
@@ -472,7 +500,7 @@ Button{
472500
id:text_box_color
473501
width: 136
474502
validator: RegularExpressionValidator {
475-
regularExpression: /^[0-9A-F]{8}$/
503+
regularExpression: /^[0-9A-Fa-f]{8}$/
476504
}
477505
anchors{
478506
right: parent.right
@@ -495,6 +523,11 @@ Button{
495523
parseInt(colorString.substring(6, 8), 16) / 255,
496524
parseInt(colorString.substring(0, 2), 16) / 255)
497525
layout_color_hue.colorValue = c
526+
layout_color_hue.updateColorText(c);
527+
text_box_r.textEdited();
528+
text_box_g.textEdited();
529+
text_box_b.textEdited();
530+
text_box_a.textEdited();
498531
}
499532
}
500533
}

src/Qt6/imports/FluentUI/Controls/FluColorPicker.qml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ Button{
4848
implicitWidth: 326
4949
implicitHeight: 560
5050
closePolicy: Popup.CloseOnEscape
51+
onClosed: {
52+
text_box_r.focus = false;
53+
text_box_g.focus = false;
54+
text_box_b.focus = false;
55+
text_box_a.focus = false;
56+
text_box_color.focus = false;
57+
}
58+
onOpened: {
59+
layout_color_hue.updateColorText(current);
60+
text_box_color.textEdited();
61+
}
5162
Rectangle{
5263
id:layout_actions
5364
width: parent.width
@@ -149,7 +160,9 @@ Button{
149160
if(color.a===1){
150161
colorString = "FF"+colorString
151162
}
152-
text_box_color.text = colorString.toUpperCase()
163+
if (!text_box_color.activeFocus) {
164+
text_box_color.text = colorString.toUpperCase();
165+
}
153166
}
154167
property color blackColor: {
155168
var c = whiteColor
@@ -280,6 +293,11 @@ Button{
280293
preventStealing: true
281294
function handleMouse(mouse) {
282295
if (mouse.buttons & Qt.LeftButton) {
296+
text_box_r.focus = false;
297+
text_box_g.focus = false;
298+
text_box_b.focus = false;
299+
text_box_a.focus = false;
300+
text_box_color.focus = false;
283301
pickerCursor.x = Math.max(0,Math.min(mouse.x - colorHandleRadius,width-2*colorHandleRadius));
284302
pickerCursor.y = Math.max(0,Math.min(mouse.y - colorHandleRadius,height-2*colorHandleRadius));
285303
}
@@ -370,6 +388,11 @@ Button{
370388
preventStealing: true
371389
function handleMouse(mouse) {
372390
if (mouse.buttons & Qt.LeftButton) {
391+
text_box_r.focus = false;
392+
text_box_g.focus = false;
393+
text_box_b.focus = false;
394+
text_box_a.focus = false;
395+
text_box_color.focus = false;
373396
blackCursor.x = Math.max(0,Math.min(mouse.x - 6,width-2*6));
374397
blackCursor.y = 0
375398
}
@@ -439,6 +462,11 @@ Button{
439462
preventStealing: true
440463
function handleMouse(mouse) {
441464
if (mouse.buttons & Qt.LeftButton) {
465+
text_box_r.focus = false;
466+
text_box_g.focus = false;
467+
text_box_b.focus = false;
468+
text_box_a.focus = false;
469+
text_box_color.focus = false;
442470
opacityCursor.x = Math.max(0,Math.min(mouse.x - 6,width-2*6));
443471
opacityCursor.y = 0
444472
}
@@ -473,7 +501,7 @@ Button{
473501
id:text_box_color
474502
width: 136
475503
validator: RegularExpressionValidator {
476-
regularExpression: /^[0-9A-F]{8}$/
504+
regularExpression: /^[0-9A-Fa-f]{8}$/
477505
}
478506
anchors{
479507
right: parent.right
@@ -496,6 +524,11 @@ Button{
496524
parseInt(colorString.substring(6, 8), 16) / 255,
497525
parseInt(colorString.substring(0, 2), 16) / 255)
498526
layout_color_hue.colorValue = c
527+
layout_color_hue.updateColorText(c);
528+
text_box_r.textEdited();
529+
text_box_g.textEdited();
530+
text_box_b.textEdited();
531+
text_box_a.textEdited();
499532
}
500533
}
501534
}

0 commit comments

Comments
 (0)