Skip to content

Commit be7728f

Browse files
committed
Further QColor work
1 parent 6566132 commit be7728f

File tree

6 files changed

+46
-37
lines changed

6 files changed

+46
-37
lines changed

dev/components/form/color-picker.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
<div>
99
<q-color v-model="model" />
10+
11+
<q-color v-model="model" readonly />
12+
13+
<q-color v-model="model" disable />
1014
</div>
1115
</div>
1216
</div>

src/components/color/QColor.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ export default {
4343
return !this.disable && !this.readonly
4444
}
4545
},
46-
data: () => ({ view: 'hex' }),
46+
data: () => ({
47+
view: 'hex'
48+
}),
4749
created () {
4850
this.__saturationChange = throttle(this.__saturationChange, 20)
4951
},
5052
render (h) {
5153
return h('div', {
52-
staticClass: 'q-color'
54+
staticClass: 'q-color',
55+
'class': { disabled: this.disable }
5356
}, [
5457
this.__getSaturation(h),
5558
this.__getSliders(h),
@@ -62,13 +65,16 @@ export default {
6265
ref: 'saturation',
6366
staticClass: 'q-color-saturation non-selectable relative-position overflow-hidden cursor-pointer',
6467
style: this.saturationStyle,
65-
on: {
66-
click: this.__saturationClick
67-
},
68-
directives: [{
69-
name: 'touch-pan',
70-
value: this.__saturationPan
71-
}]
68+
'class': { readonly: this.readonly },
69+
on: this.editable
70+
? { click: this.__saturationClick }
71+
: null,
72+
directives: this.editable
73+
? [{
74+
name: 'touch-pan',
75+
value: this.__saturationPan
76+
}]
77+
: null
7278
}, [
7379
h('div', { staticClass: 'q-color-saturation-white absolute-full' }),
7480
h('div', { staticClass: 'q-color-saturation-black absolute-full' }),
@@ -96,7 +102,8 @@ export default {
96102
color: 'none',
97103
min: 0,
98104
max: 360,
99-
fillHandleAlways: true
105+
fillHandleAlways: true,
106+
readonly: !this.editable
100107
},
101108
style: {
102109
color: this.value.hex
@@ -113,7 +120,8 @@ export default {
113120
color: 'none',
114121
min: 0,
115122
max: 100,
116-
fillHandleAlways: true
123+
fillHandleAlways: true,
124+
readonly: this.readonly
117125
},
118126
style: {
119127
color: this.value.hex
@@ -136,10 +144,13 @@ export default {
136144
attrs: {
137145
type: 'number',
138146
min: 0,
139-
max
147+
max,
148+
readonly: !this.editable
140149
},
141150
staticClass: 'full-width text-center',
142-
domProps: { value: (type === 'a' ? 100 : 1) * this.value[type] },
151+
domProps: {
152+
value: (type === 'a' ? 100 : 1) * this.value[type]
153+
},
143154
on: {
144155
input: evt => {
145156
this.__onPropChange(evt, type, max)
@@ -158,9 +169,8 @@ export default {
158169
h('div', { staticClass: 'col' }, [
159170
h('input', {
160171
domProps: { value: this.value.hex },
161-
on: {
162-
input: this.__onHexChange
163-
},
172+
attrs: { readonly: this.readonly },
173+
on: { input: this.__onHexChange },
164174
staticClass: 'full-width text-center uppercase'
165175
}),
166176
h('div', { staticClass: 'q-color-label text-center' }, [
@@ -246,10 +256,6 @@ export default {
246256
},
247257

248258
__saturationPan (evt) {
249-
if (!this.editable) {
250-
return
251-
}
252-
253259
if (evt.isFinal) {
254260
this.__dragStop(evt)
255261
}
@@ -261,18 +267,14 @@ export default {
261267
}
262268
},
263269
__dragStart (event) {
264-
if (!this.editable) {
265-
return
266-
}
267-
268270
event.evt.stopPropagation()
269271
event.evt.preventDefault()
270272

271273
this.saturationDragging = true
272274
this.__saturationChange(event)
273275
},
274276
__dragMove (event) {
275-
if (!this.saturationDragging || !this.editable) {
277+
if (!this.saturationDragging) {
276278
return
277279
}
278280
event.evt.stopPropagation()
@@ -281,10 +283,6 @@ export default {
281283
this.__saturationChange(event)
282284
},
283285
__dragStop (event) {
284-
if (!this.editable) {
285-
return
286-
}
287-
288286
event.evt.stopPropagation()
289287
event.evt.preventDefault()
290288
this.saturationDragging = false

src/components/slider/slider-utils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,22 @@ export let mixin = {
5757
color: String,
5858
fillHandleAlways: Boolean,
5959
error: Boolean,
60+
readonly: Boolean,
6061
disable: Boolean
6162
},
63+
data () {
64+
return {
65+
clickDisabled: false
66+
}
67+
},
6268
computed: {
63-
data () {
64-
return {
65-
clickDisabled: false
66-
}
69+
editable () {
70+
return !this.disable && !this.readonly
6771
},
6872
classes () {
6973
const cls = {
7074
disabled: this.disable,
75+
readonly: this.readonly,
7176
'label-always': this.labelAlways,
7277
'has-error': this.error
7378
}
@@ -86,7 +91,7 @@ export let mixin = {
8691
},
8792
methods: {
8893
__pan (event) {
89-
if (this.disable) {
94+
if (!this.editable) {
9095
return
9196
}
9297
if (event.isFinal) {
@@ -104,7 +109,7 @@ export let mixin = {
104109
}
105110
},
106111
__click (event) {
107-
if (this.disable || this.clickDisabled) {
112+
if (!this.editable || this.clickDisabled) {
108113
return
109114
}
110115
this.__setActive(event)

src/components/slider/slider.mat.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ $slider-label-transform = translateX(-50%) translateY(-139%) scale(1)
9090
transition all .2s ease-in
9191
background currentColor
9292

93-
.q-slider:not(.disabled)
93+
.q-slider:not(.disabled):not(.readonly)
9494
&:focus, &:hover
9595
.q-slider-ring
9696
opacity .4

src/css/core/visibility.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
&-3-lines
2424
-webkit-line-clamp 3
2525

26+
.readonly
27+
cursor default !important
2628
.disabled, [disabled]
2729
&, * // @stylint ignore
2830
cursor not-allowed !important

src/utils/colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export function hsvToRgb (h, s, v) {
9494

9595
export function rgbToHsv (r, g, b) {
9696
if (arguments.length === 1) {
97+
r = r.r
9798
g = r.g
9899
b = r.b
99-
r = r.r
100100
}
101101

102102
let

0 commit comments

Comments
 (0)