This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
color-picker.lisp
65 lines (54 loc) · 2.7 KB
/
color-picker.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#|
This file is a part of Qtools-UI
(c) 2015 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#
(in-package #:org.shirakumo.qtools.ui)
(in-readtable :qtools)
(define-widget color-picker (QDialog simple-input-dialog color-storing-input)
())
(defvar *color-picker-input-done* T)
(define-subwidget (color-picker color-triangle) (make-instance 'color-triangle :color (value color-picker)))
(define-subwidget (color-picker rgb-color-slider) (make-instance 'rgb-color-slider :color (value color-picker)))
(define-subwidget (color-picker hsv-color-slider) (make-instance 'hsv-color-slider :color (value color-picker)))
(define-subwidget (color-picker color-history) (make-instance 'color-history :color (value color-picker) :color-count 10))
(define-subwidget (color-picker layout) (q+:make-qvboxlayout color-picker)
(setf (q+:fixed-size color-picker) (values 590 350))
(let ((colors (q+:make-qhboxlayout)))
(q+:add-widget colors color-triangle)
(let ((sliders (q+:make-qvboxlayout)))
(q+:add-widget sliders rgb-color-slider)
(q+:add-widget sliders hsv-color-slider)
(q+:add-stretch sliders 1)
(q+:add-layout colors sliders))
(q+:add-layout layout colors))
(q+:add-widget layout color-history)
(q+:add-layout layout (slot-value color-picker 'dialog-buttons)))
(define-slot (color-picker input-updated-triangle) ()
(declare (connected color-triangle (input-updated)))
(let ((*color-picker-input-done* NIL))
(setf (value color-picker) (value color-triangle))))
(define-slot (color-picker input-updated-rgb) ()
(declare (connected rgb-color-slider (input-updated)))
(let ((*color-picker-input-done* NIL))
(setf (value color-picker) (value rgb-color-slider))))
(define-slot (color-picker input-updated-hsv) ()
(declare (connected hsv-color-slider (input-updated)))
(let ((*color-picker-input-done* NIL))
(setf (value color-picker) (value hsv-color-slider))))
(define-slot (color-picker input-updated-history) ()
(declare (connected color-history (input-updated)))
(setf (value color-picker) (value color-history)))
(define-slot (color-picker input-done) ()
(declare (connected color-triangle (input-done)))
(declare (connected rgb-color-slider (input-done)))
(declare (connected hsv-color-slider (input-done)))
(declare (connected color-history (input-done)))
(setf (value color-picker) (value color-picker)))
(defmethod (setf value) :after (value (color-picker color-picker))
(with-slots-bound (color-picker color-picker)
(setf (value color-triangle) value)
(setf (value rgb-color-slider) value)
(setf (value hsv-color-slider) value)
(when *color-picker-input-done*
(setf (value color-history) value))))