').hide(),
23 | $modal = $('
\
24 |
\
25 |
\
26 |
\
27 |
').hide(),
28 | $el = $(o.html)
29 | $children = $el.children();
30 |
31 | $modal.find('.tinymodal-content').append($children);
32 |
33 | if (o.buttons.length) {
34 | $modal.find('.inner').append('
');
35 | }
36 |
37 | function show() {
38 | $('body').width($('body').width()).css('overflow', 'hidden');
39 | $overlay.fadeIn('fast', function() {
40 | $modal.fadeIn('fast', o.onOpen);
41 | });
42 | $modal.css({
43 | marginLeft: -($modal.width()/2) +'px',
44 | });
45 | }
46 |
47 | function hide(callback) {
48 | $modal.fadeOut('fast', function() {
49 | $('body').css({ width: 'auto', overflow: 'auto' });
50 | $overlay.fadeOut('fast');
51 | if (typeof callback == 'function') callback();
52 | $el.append($children);
53 | });
54 | }
55 |
56 | $modal.find('.tinymodal-buttons button, .tinymodal-close').on('click', function(e) {
57 | var callback = $(this).text();
58 | hide(o[callback]);
59 | });
60 |
61 | $modal.find('.tinymodal-close').click(o.onClose);
62 |
63 | $tip = $modal.find('.tip');
64 | $tip.on('click',function(e){
65 | hide();
66 | // $hash = $(this).attr('href');
67 | // window.location.hash = $hash;
68 | // window.location.reload();
69 | });
70 |
71 | $modal.on('click', function(e){ e.stopPropagation(); });
72 |
73 | if (o.clickOutside) $overlay.on('click', hide);
74 |
75 | $('body').prepend($overlay.append($modal));
76 | show();
77 | };
78 |
79 | }(jQuery));
80 |
--------------------------------------------------------------------------------
/src/html/texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/html/texture.png
--------------------------------------------------------------------------------
/src/html/toastr/toastr.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Note that this is toastr v2.1.3, the "latest" version in url has no more maintenance,
3 | * please go to https://cdnjs.com/libraries/toastr.js and pick a certain version you want to use,
4 | * make sure you copy the url from the website since the url may change between versions.
5 | * */
6 | !function(e){e(["jquery"],function(e){return function(){function t(e,t,n){return g({type:O.error,iconClass:m().iconClasses.error,message:e,optionsOverride:n,title:t})}function n(t,n){return t||(t=m()),v=e("#"+t.containerId),v.length?v:(n&&(v=d(t)),v)}function o(e,t,n){return g({type:O.info,iconClass:m().iconClasses.info,message:e,optionsOverride:n,title:t})}function s(e){C=e}function i(e,t,n){return g({type:O.success,iconClass:m().iconClasses.success,message:e,optionsOverride:n,title:t})}function a(e,t,n){return g({type:O.warning,iconClass:m().iconClasses.warning,message:e,optionsOverride:n,title:t})}function r(e,t){var o=m();v||n(o),u(e,o,t)||l(o)}function c(t){var o=m();return v||n(o),t&&0===e(":focus",t).length?void h(t):void(v.children().length&&v.remove())}function l(t){for(var n=v.children(),o=n.length-1;o>=0;o--)u(e(n[o]),t)}function u(t,n,o){var s=!(!o||!o.force)&&o.force;return!(!t||!s&&0!==e(":focus",t).length)&&(t[n.hideMethod]({duration:n.hideDuration,easing:n.hideEasing,complete:function(){h(t)}}),!0)}function d(t){return v=e("
").attr("id",t.containerId).addClass(t.positionClass),v.appendTo(e(t.target)),v}function p(){return{tapToDismiss:!0,toastClass:"toast",containerId:"toast-container",debug:!1,showMethod:"fadeIn",showDuration:300,showEasing:"swing",onShown:void 0,hideMethod:"fadeOut",hideDuration:1e3,hideEasing:"swing",onHidden:void 0,closeMethod:!1,closeDuration:!1,closeEasing:!1,closeOnHover:!0,extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},iconClass:"toast-info",positionClass:"toast-top-right",timeOut:5e3,titleClass:"toast-title",messageClass:"toast-message",escapeHtml:!1,target:"body",closeHtml:'
',closeClass:"toast-close-button",newestOnTop:!0,preventDuplicates:!1,progressBar:!1,progressClass:"toast-progress",rtl:!1}}function f(e){C&&C(e)}function g(t){function o(e){return null==e&&(e=""),e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}function s(){c(),u(),d(),p(),g(),C(),l(),i()}function i(){var e="";switch(t.iconClass){case"toast-success":case"toast-info":e="polite";break;default:e="assertive"}I.attr("aria-live",e)}function a(){E.closeOnHover&&I.hover(H,D),!E.onclick&&E.tapToDismiss&&I.click(b),E.closeButton&&j&&j.click(function(e){e.stopPropagation?e.stopPropagation():void 0!==e.cancelBubble&&e.cancelBubble!==!0&&(e.cancelBubble=!0),E.onCloseClick&&E.onCloseClick(e),b(!0)}),E.onclick&&I.click(function(e){E.onclick(e),b()})}function r(){I.hide(),I[E.showMethod]({duration:E.showDuration,easing:E.showEasing,complete:E.onShown}),E.timeOut>0&&(k=setTimeout(b,E.timeOut),F.maxHideTime=parseFloat(E.timeOut),F.hideEta=(new Date).getTime()+F.maxHideTime,E.progressBar&&(F.intervalId=setInterval(x,10)))}function c(){t.iconClass&&I.addClass(E.toastClass).addClass(y)}function l(){E.newestOnTop?v.prepend(I):v.append(I)}function u(){if(t.title){var e=t.title;E.escapeHtml&&(e=o(t.title)),M.append(e).addClass(E.titleClass),I.append(M)}}function d(){if(t.message){var e=t.message;E.escapeHtml&&(e=o(t.message)),B.append(e).addClass(E.messageClass),I.append(B)}}function p(){E.closeButton&&(j.addClass(E.closeClass).attr("role","button"),I.prepend(j))}function g(){E.progressBar&&(q.addClass(E.progressClass),I.prepend(q))}function C(){E.rtl&&I.addClass("rtl")}function O(e,t){if(e.preventDuplicates){if(t.message===w)return!0;w=t.message}return!1}function b(t){var n=t&&E.closeMethod!==!1?E.closeMethod:E.hideMethod,o=t&&E.closeDuration!==!1?E.closeDuration:E.hideDuration,s=t&&E.closeEasing!==!1?E.closeEasing:E.hideEasing;if(!e(":focus",I).length||t)return clearTimeout(F.intervalId),I[n]({duration:o,easing:s,complete:function(){h(I),clearTimeout(k),E.onHidden&&"hidden"!==P.state&&E.onHidden(),P.state="hidden",P.endTime=new Date,f(P)}})}function D(){(E.timeOut>0||E.extendedTimeOut>0)&&(k=setTimeout(b,E.extendedTimeOut),F.maxHideTime=parseFloat(E.extendedTimeOut),F.hideEta=(new Date).getTime()+F.maxHideTime)}function H(){clearTimeout(k),F.hideEta=0,I.stop(!0,!0)[E.showMethod]({duration:E.showDuration,easing:E.showEasing})}function x(){var e=(F.hideEta-(new Date).getTime())/F.maxHideTime*100;q.width(e+"%")}var E=m(),y=t.iconClass||E.iconClass;if("undefined"!=typeof t.optionsOverride&&(E=e.extend(E,t.optionsOverride),y=t.optionsOverride.iconClass||y),!O(E,t)){T++,v=n(E,!0);var k=null,I=e("
"),M=e("
"),B=e("
"),q=e("
"),j=e(E.closeHtml),F={intervalId:null,hideEta:null,maxHideTime:null},P={toastId:T,state:"visible",startTime:new Date,options:E,map:t};return s(),r(),a(),f(P),E.debug&&console&&console.log(P),I}}function m(){return e.extend({},p(),b.options)}function h(e){v||(v=n()),e.is(":visible")||(e.remove(),e=null,0===v.children().length&&(v.remove(),w=void 0))}var v,C,w,T=0,O={error:"error",info:"info",success:"success",warning:"warning"},b={clear:r,remove:c,error:t,getContainer:n,info:o,options:{},subscribe:s,success:i,version:"2.1.3",warning:a};return b}()})}("function"==typeof define&&define.amd?define:function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):window.toastr=t(window.jQuery)});
7 | //# sourceMappingURL=toastr.js.map
8 |
--------------------------------------------------------------------------------
/src/html/v2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/html/v2/app.0f8e8639.js:
--------------------------------------------------------------------------------
1 | (function(t){function o(o){for(var r,s,l=o[0],a=o[1],c=o[2],p=0,f=[];p
20},style:{"background-color":"#"+t.inputColor.hex6},attrs:{id:"color-line"}},[t.isFalse?t._e():e("p",[t._v("#"+t._s(t.inputColor.hex6))]),t.isFalse?e("h2",{attrs:{id:"list-detect"}},[t._v(" No color identified ")]):e("h2",[t._v(t._s(t.OuterColor["format"])+": "+t._s(t.OuterColor["color"]))])]),t._m(0),t._l(Object.keys(t.inputColor),(function(o){return e("div",{key:o,staticClass:"color-element",attrs:{id:"list-"+o}},[e("div",{staticClass:"input-group"},["html"==o?e("div",{staticClass:"color-line",class:{hidden:t.isFalse},style:{"background-color":t.OuterColor.htmlref}}):t._e(),e("div",{staticClass:"input-group mb-3 input-group-sm"},[e("span",{staticClass:"input-group-text"},[t._v(t._s(o))]),e("input",{staticClass:"form-control",attrs:{type:"text",id:o,autocomplete:"off"},domProps:{value:t.inputFormat(t.inputColor[o])},on:{keyup:function(o){return t.inputUpdate(o)}}})]),e("p","color"==o?[t._v(" dotColor = { sanitized:"+t._s(t.formatColor(t.OuterColor["color"]))+" , format:"+t._s(t.formatColor(t.OuterColor["format"]))+" } ")]:[t._v("dotColor."+t._s(o)+"="+t._s(t.formatColor(t.OuterColor[o])))])])])})),e("h1",[t._v(t._s(t.OuterColor.invert))])],2)},l=[function(){var t=this,o=t.$createElement,e=t._self._c||o;return e("div",{staticClass:"color-element color-title"},[e("h1",[t._v("[apptitle] "),e("a",{attrs:{href:""}},[e("span",{staticClass:"badge bg-danger badge-super"},[t._v("NPM")])])])])}],a=(e("4de4"),e("d3b7"),e("ac1f"),e("5319"),e("ddb0"),e("b85c")),c=e("53ca"),u=e("1e72"),p=e.n(u),f=e("c603"),d=e.n(f),h=new d.a("#00a"),v=(new p.a).keys,m={name:"colorTest",data:function(){return{inputColor:{hex6:"#00a",color:"#00a"},OuterColor:h,isFalse:!1}},methods:{formatColor:function(t){return!!t&&("string"===typeof t?'"'+t+'"':t)},inputFormat:function(t){return"object"===Object(c["a"])(t)?JSON.stringify(t).replace(/"|{|}|/g,"").replace(/,/g,", ").replace(/:/g,": "):t},updateColors:function(t){var o,e=Object(a["a"])(v);try{for(e.s();!(o=e.n()).done;){var r=o.value;this.inputColor[r]=h[r]}}catch(n){e.e(n)}finally{e.f()}"color"!==t&&(this.inputColor.color=t),document.title=this.OuterColor.sanitizedColor+" | "+this.OuterColor.format+ (this.OuterColor.format!="hex6"?" >> "+this.OuterColor.hex6:"")},falseUpdate:function(t){var o,e=Object(a["a"])(v.filter((function(o){return o!==t})));try{for(e.s();!(o=e.n()).done;){var r=o.value;this.inputColor[r]=""}}catch(n){e.e(n)}finally{e.f()}"color"!==t&&(this.inputColor.color=""),document.title="No color identified"},inputUpdate:function(t){var o=t.target.id,e=t.target.value;h[o]=e,h[o]?(this.updateColors(e),this.inputColor[o]=e,this.isFalse=!1):(this.falseUpdate(o),this.inputColor[o]=e,this.isFalse=!0)}},mounted:function(){this.updateColors(this.inputColor.color)}},b=m,C=(e("1077"),e("2877")),g=Object(C["a"])(b,s,l,!1,null,null,null),y=g.exports,_={name:"App",components:{colorView:y}},O=_,w=(e("034f"),Object(C["a"])(O,n,i,!1,null,null,null)),j=w.exports;r["a"].config.productionTip=!1,new r["a"]({render:function(t){return t(j)}}).$mount("#app")},"85ec":function(t,o,e){},c11e:function(t,o,e){}});
2 |
--------------------------------------------------------------------------------
/src/html/v2/app.9d39357a.css:
--------------------------------------------------------------------------------
1 | .color-element p{display:none !important;} .color-element:nth-child(2):not(:last-child){padding-top:0px !important;} #list-color{display:none !important} .color-element:not(:last-child){padding-top:10px ;padding-bottom: 0px !important;} .color-element h1{display:none !important;} .hidden{opacity:0}.badge-super{vertical-align:super;font-size:30%;transform:translateY(-10px)}#color-box{display:grid;padding-left:400px}@media screen and (max-width:800px){#color-box{padding-left:0}}.input-group{margin-bottom:0!important}.color-title{padding-top:50px;padding-bottom:50px}#color-line{min-height:200px;padding:50px;color:#000;position:fixed;left:0;top:0;bottom:0;width:400px;box-sizing:border-box}#color-line,#color-line h2{font-weight:bold}#color-line.light{color:#fff}#color-line p{margin-bottom:0}@media screen and (max-width:800px){#color-line{position:static;width:100%;margin-bottom:0px}}.color-false{background-color:#d3d3d3!important}.color-element{padding-left:10px;padding-right:10px}.color-element p{margin-top:5px;margin-bottom:5px;width:100%;text-align:right;opacity:.2}.color-element:hover p{opacity:1}.color-element.color-title p{text-align:left;opacity:1}#list-color{grid-row:2;padding-bottom:50px}@media screen and (max-width:800px){#list-color{grid-row:3}}#list-color .input-group{opacity:1}#list-color .input-group input,#list-color .input-group span{font-size:1.5rem;padding:.5rem 1rem}body{background-color:#eff0f1; margin:0}
2 |
--------------------------------------------------------------------------------
/src/icons/icon-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-128.png
--------------------------------------------------------------------------------
/src/icons/icon-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-16.png
--------------------------------------------------------------------------------
/src/icons/icon-256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-256.png
--------------------------------------------------------------------------------
/src/icons/icon-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-32.png
--------------------------------------------------------------------------------
/src/icons/icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-512.png
--------------------------------------------------------------------------------
/src/icons/icon-64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/icon-64.png
--------------------------------------------------------------------------------
/src/icons/others/close-fill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/close-fill.png
--------------------------------------------------------------------------------
/src/icons/others/delete-bin-5-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/delete-bin-5-line.png
--------------------------------------------------------------------------------
/src/icons/others/error-warning-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/error-warning-line.png
--------------------------------------------------------------------------------
/src/icons/others/eye-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/eye-line.png
--------------------------------------------------------------------------------
/src/icons/others/file-copy-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/file-copy-line.png
--------------------------------------------------------------------------------
/src/icons/others/file-text-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/file-text-line.png
--------------------------------------------------------------------------------
/src/icons/others/file-unknow-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/file-unknow-line.png
--------------------------------------------------------------------------------
/src/icons/others/folder-open-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/folder-open-line.png
--------------------------------------------------------------------------------
/src/icons/others/information-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/information-line.png
--------------------------------------------------------------------------------
/src/icons/others/link-unlink-m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/link-unlink-m.png
--------------------------------------------------------------------------------
/src/icons/others/links-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/links-line.png
--------------------------------------------------------------------------------
/src/icons/others/paypal-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/paypal-line.png
--------------------------------------------------------------------------------
/src/icons/others/star-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/icons/others/star-line.png
--------------------------------------------------------------------------------
/src/icons/resize.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Edit the settings below:
4 |
5 | # Output sizes -
6 | # Please note the format: each size is wrapped with quotes, width and height are separated with space.
7 | output=("16 16" "32 32" "64 64" "128 128" "512 512" )
8 |
9 | # If you frequently use the same source file (f.e. "~/Desktop/src.jpg"),
10 | # set it in "default_src"
11 | default_src="";
12 |
13 | # If you frequently use the same destination
14 | # (f.e. "~/Desktop/Some_folder/%.jpg"), set it in "default_dst"
15 | # Destination must include "%", it will be replaced by output size, f.e. "800x600"
16 | default_dst="%.png";
17 |
18 | # Add signature?
19 | default_sign='n'
20 |
21 | # If you frequently use the same signature file (f.e. "~/Desktop/sig.png"),
22 | # set it in "default_sig"
23 | default_sig="";
24 |
25 | # Gravity is for cropping left/right edges for different proportions (center, east, west)
26 | default_gravity="center"
27 |
28 | # Output JPG quality: maximum is 100 (recommended)
29 | quality=100
30 |
31 | # ======
32 | # Do not edit below.
33 | # ======
34 | # Welcome to Smashing resizer!
35 | # Written by Vlad Gerasimov from http://www.vladstudio.com
36 | #
37 | # This script takes one "source" image and saves it in different sizes.
38 | #
39 | # Requires:
40 | # * imagemagick - http://www.imagemagick.org/
41 | # * python - I'm sure your PC already has it!
42 |
43 |
44 |
45 | # Unfortunately, bash is awful at math operations.
46 | # We'll create a simple function that handles math for us.
47 | # Example: $(math 2 * 2)
48 |
49 | function math(){
50 | echo $(python -c "from __future__ import division; print $@")
51 | }
52 |
53 |
54 |
55 | # To make our script short and nice, here is the "save()" function.
56 | # We'll use it to save each size.
57 |
58 | function save(){
59 |
60 | # read target width and height from function parameters
61 | local dst_w=${1}
62 | local dst_h=${2}
63 |
64 | # calculate ratio
65 | local ratio=$(math $dst_w/$dst_h);
66 |
67 | # calculate "intermediate" width and height
68 | local inter_w=$(math "int(round($src_h*$ratio))")
69 | local inter_h=${src_h}
70 |
71 | # which size we're saving now
72 | #local size="${dst_w}x${dst_h}"
73 | local size="${dst_w}"
74 | echo "Saving ${size}..."
75 |
76 | #crop intermediate image (with target ratio)
77 | convert ${src} -gravity ${gravity} -crop ${inter_w}x${inter_h}+0+0 +repage temp.psd
78 |
79 | # apply signature
80 | if [ "${sign}" == "y" ]; then
81 | convert temp.psd ${sig} -gravity southeast -geometry ${sig_w}x${sig_h}+24+48 -composite temp.psd
82 | fi
83 |
84 | ## For best quality, I resize image 80%, sharpen 3 times, then repeat.
85 |
86 | # setup resize filter and unsharp parameters (calculated through trial and error)
87 | local arguments="-interpolate bicubic -filter Lagrange"
88 | local unsharp="-unsharp 0.4x0.4+0.4+0.008"
89 |
90 | # scale 80%, sharpen, repeat until less than 150% of target size
91 | local current_w=${dst_w}
92 |
93 | # pardon moi for such ugly while condition!
94 | while [ $(math "${current_w}/${dst_w} > 1.5") = "True" ]; do
95 | current_w=$(math ${current_w}\*0\.80)
96 | current_w=$(math "int(round(${current_w}))")
97 | arguments="${arguments} -resize 80% +repage ${unsharp} ${unsharp} ${unsharp} "
98 | done
99 |
100 | # final resize
101 | arguments="${arguments} -resize ${dst_w}x${dst_h}! +repage ${unsharp} ${unsharp} ${unsharp} -density 72x72 +repage"
102 |
103 | # final convert! resize, sharpen, save
104 | convert temp.psd ${arguments} -quality ${quality} ${dst/\%/${size}}
105 |
106 | }
107 |
108 | # Ask for source image, or use default value
109 | echo "Enter path to source image, or hit Enter to keep default value (${default_src}): "
110 | read src
111 | src=${src:-${default_src}}
112 |
113 | # ask for destination path, or use default value
114 | echo "Enter destination path, or hit Enter to keep default value (${default_dst})."
115 | echo "must include % symbol, it will be replaced by output size, f.e. '800x600'"
116 | read dst
117 | dst=${dst:-${default_dst}}
118 |
119 | # Ask for signature image, or use default value
120 | echo "Apply signature? (hit Enter for 'yes' or type 'n' for 'no') "
121 | read sign
122 | sign=${sign:-${default_sign}}
123 |
124 | # Ask for signature image, or use default value
125 | echo "Enter path to signature image, or hit Enter to keep default value (${default_sig}): "
126 | read sig
127 | sig=${sig:-${default_sig}}
128 |
129 | # ask for gravity, or use default value
130 | echo "Enter gravity for cropping left/right edges (center, east, west), or hit Enter to keep default value (${default_gravity}): "
131 | read gravity
132 | gravity=${gravity:-${default_gravity}}
133 |
134 |
135 | # detect source image width and height
136 | src_w=$(identify -format "%w" "${src}")
137 | src_h=$(identify -format "%h" "${src}")
138 |
139 | # detect signature width and height
140 | if [ "${sign}" == "y" ]; then
141 | sig_w=$(identify -format "%w" "${sig}")
142 | sig_h=$(identify -format "%h" "${sig}")
143 | fi
144 |
145 | # loop throught output sizes and save each size
146 | for i in "${output[@]}"
147 | do
148 | save ${i}
149 | done
150 |
151 | # Delete temporary file
152 | rm temp.psd
153 |
154 | # Done!
155 | echo "Done!"
156 |
--------------------------------------------------------------------------------
/src/lib/color_widgets.pri:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2013-2019 Mattia Basaglia
2 | #
3 | #
4 | # This software is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU Lesser General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This software is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU Lesser General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU Lesser General Public License
15 | # along with Color Widgets. If not, see .
16 |
17 | CONFIG += c++11
18 |
19 | INCLUDEPATH += $$PWD/src $$PWD/include
20 |
21 | SOURCES += \
22 | $$PWD/src/QtColorWidgets/abstract_widget_list.cpp \
23 | $$PWD/src/QtColorWidgets/bound_color_selector.cpp \
24 | $$PWD/src/QtColorWidgets/color_2d_slider.cpp \
25 | $$PWD/src/QtColorWidgets/color_delegate.cpp \
26 | $$PWD/src/QtColorWidgets/color_dialog.cpp \
27 | $$PWD/src/QtColorWidgets/color_line_edit.cpp \
28 | $$PWD/src/QtColorWidgets/color_list_widget.cpp \
29 | $$PWD/src/QtColorWidgets/color_names.cpp \
30 | $$PWD/src/QtColorWidgets/color_palette.cpp \
31 | $$PWD/src/QtColorWidgets/color_palette_model.cpp \
32 | $$PWD/src/QtColorWidgets/color_palette_widget.cpp \
33 | $$PWD/src/QtColorWidgets/color_preview.cpp \
34 | $$PWD/src/QtColorWidgets/color_selector.cpp \
35 | $$PWD/src/QtColorWidgets/color_utils.cpp \
36 | $$PWD/src/QtColorWidgets/color_wheel.cpp \
37 | $$PWD/src/QtColorWidgets/gradient_editor.cpp \
38 | $$PWD/src/QtColorWidgets/gradient_list_model.cpp \
39 | $$PWD/src/QtColorWidgets/gradient_slider.cpp \
40 | $$PWD/src/QtColorWidgets/harmony_color_wheel.cpp \
41 | $$PWD/src/QtColorWidgets/hue_slider.cpp \
42 | $$PWD/src/QtColorWidgets/swatch.cpp
43 |
44 | HEADERS += \
45 | $$PWD/include/QtColorWidgets/abstract_widget_list.hpp \
46 | $$PWD/include/QtColorWidgets/bound_color_selector.hpp \
47 | $$PWD/include/QtColorWidgets/color_2d_slider.hpp \
48 | $$PWD/include/QtColorWidgets/color_delegate.hpp \
49 | $$PWD/include/QtColorWidgets/color_dialog.hpp \
50 | $$PWD/include/QtColorWidgets/color_line_edit.hpp \
51 | $$PWD/include/QtColorWidgets/color_list_widget.hpp \
52 | $$PWD/include/QtColorWidgets/color_names.hpp \
53 | $$PWD/include/QtColorWidgets/color_palette.hpp \
54 | $$PWD/include/QtColorWidgets/color_palette_model.hpp \
55 | $$PWD/include/QtColorWidgets/color_palette_widget.hpp \
56 | $$PWD/include/QtColorWidgets/color_preview.hpp \
57 | $$PWD/include/QtColorWidgets/color_selector.hpp \
58 | $$PWD/include/QtColorWidgets/color_utils.hpp \
59 | $$PWD/include/QtColorWidgets/color_wheel.hpp \
60 | $$PWD/include/QtColorWidgets/color_wheel_private.hpp \
61 | $$PWD/include/QtColorWidgets/colorwidgets_global.hpp \
62 | $$PWD/include/QtColorWidgets/gradient_delegate.hpp \
63 | $$PWD/include/QtColorWidgets/gradient_editor.hpp \
64 | $$PWD/include/QtColorWidgets/gradient_helper.hpp \
65 | $$PWD/include/QtColorWidgets/gradient_list_model.hpp \
66 | $$PWD/include/QtColorWidgets/gradient_slider.hpp \
67 | $$PWD/include/QtColorWidgets/harmony_color_wheel.hpp \
68 | $$PWD/include/QtColorWidgets/hue_slider.hpp \
69 | $$PWD/include/QtColorWidgets/swatch.hpp
70 |
71 | FORMS += \
72 | $$PWD/src/QtColorWidgets/color_dialog.ui \
73 | $$PWD/src/QtColorWidgets/color_palette_widget.ui
74 |
75 | RESOURCES += \
76 | $$PWD/resources/QtColorWidgets/color_widgets.qrc
77 |
78 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/AbstractWidgetList:
--------------------------------------------------------------------------------
1 | #include "abstract_widget_list.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/BoundColorSelector:
--------------------------------------------------------------------------------
1 | #include "bound_color_selector.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set (HEADERS
2 | abstract_widget_list.hpp
3 | bound_color_selector.hpp
4 | color_2d_slider.hpp
5 | color_delegate.hpp
6 | color_dialog.hpp
7 | color_line_edit.hpp
8 | color_list_widget.hpp
9 | color_names.hpp
10 | color_palette.hpp
11 | color_palette_model.hpp
12 | color_palette_widget.hpp
13 | color_preview.hpp
14 | color_selector.hpp
15 | color_wheel.hpp
16 | colorwidgets_global.hpp
17 | gradient_slider.hpp
18 | hue_slider.hpp
19 | swatch.hpp
20 | gradient_editor.hpp
21 | harmony_color_wheel.hpp
22 | gradient_list_model.hpp
23 | gradient_delegate.hpp
24 | )
25 |
26 | file(RELATIVE_PATH
27 | PREFIX
28 | ${PROJECT_SOURCE_DIR}
29 | ${CMAKE_CURRENT_LIST_DIR})
30 |
31 |
32 | foreach (HEADER IN LISTS HEADERS)
33 | target_sources (${TARGET_NAME}
34 | PRIVATE
35 | $
36 | $)
37 | endforeach (HEADER IN HEADERS)
38 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorDelegate:
--------------------------------------------------------------------------------
1 | #include "color_delegate.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorDialog:
--------------------------------------------------------------------------------
1 | #include "color_dialog.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorListWidget:
--------------------------------------------------------------------------------
1 | #include "color_list_widget.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorPreview:
--------------------------------------------------------------------------------
1 | #include "color_preview.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorSelector:
--------------------------------------------------------------------------------
1 | #include "color_selector.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/ColorWheel:
--------------------------------------------------------------------------------
1 | #include "color_wheel.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/GradientEditor:
--------------------------------------------------------------------------------
1 | #include "gradient_editor.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/GradientListModel:
--------------------------------------------------------------------------------
1 | #include "gradient_list_model.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/GradientSlider:
--------------------------------------------------------------------------------
1 | #include "gradient_slider.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/HarmonyColorWheel:
--------------------------------------------------------------------------------
1 | #include "harmony_color_wheel.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/HueSlider:
--------------------------------------------------------------------------------
1 | #include "hue_slider.hpp"
2 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/abstract_widget_list.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef ABSTRACT_WIDGET_LIST_HPP
23 | #define ABSTRACT_WIDGET_LIST_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 |
27 | #include
28 | #include
29 |
30 | class QCP_EXPORT AbstractWidgetList : public QWidget
31 | {
32 | Q_OBJECT
33 | public:
34 | explicit AbstractWidgetList(QWidget *parent = 0);
35 | ~AbstractWidgetList();
36 |
37 | /**
38 | * \brief Get the number of items
39 | */
40 | int count() const;
41 |
42 | /**
43 | * \brief Swap row a and row b
44 | */
45 | virtual void swap(int a, int b) = 0;
46 |
47 |
48 | /// Whether the given row index is valid
49 | bool isValidRow(int i) const { return i >= 0 && i < count(); }
50 |
51 | void setRowHeight(int row, int height);
52 |
53 |
54 | public Q_SLOTS:
55 | /**
56 | * \brief Remove row i
57 | */
58 | void remove(int i);
59 |
60 | /**
61 | * \brief append a default row
62 | */
63 | virtual void append() = 0;
64 |
65 | Q_SIGNALS:
66 | void removed(int i);
67 |
68 | protected:
69 |
70 | /**
71 | * \brief Create a new row with the given widget
72 | *
73 | * Must be called by implementations of append()
74 | */
75 | void appendWidget(QWidget* w);
76 |
77 | /**
78 | * \brief get the widget found at the given row
79 | */
80 | QWidget* widget(int i);
81 |
82 |
83 | /**
84 | * \brief get the widget found at the given row
85 | */
86 | template
87 | T* widget_cast(int i) { return qobject_cast(widget(i)); }
88 |
89 | /**
90 | * \brief clear all rows without emitting signals
91 | *
92 | * May be useful when implementation want to set all values at once
93 | */
94 | void clear();
95 |
96 | private Q_SLOTS:
97 | void remove_clicked(QWidget* w);
98 | void up_clicked(QWidget* w);
99 | void down_clicked(QWidget* w);
100 |
101 | private:
102 | class Private;
103 | Private * const p;
104 |
105 | QWidget* create_button(QWidget* data, QSignalMapper*mapper,
106 | QString icon_name, QString text,
107 | QString tooltip = QString()) const;
108 | };
109 |
110 | #endif // ABSTRACT_WIDGET_LIST_HPP
111 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/bound_color_selector.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef BOUND_COLOR_SELECTOR_HPP
23 | #define BOUND_COLOR_SELECTOR_HPP
24 |
25 | #include "color_selector.hpp"
26 |
27 | namespace color_widgets {
28 | /**
29 | * \brief A color selector bound to a color reference
30 | * \todo Maybe this can be removed
31 | */
32 | class QCP_EXPORT BoundColorSelector : public ColorSelector
33 | {
34 | Q_OBJECT
35 | private:
36 | QColor* ref;
37 | public:
38 | explicit BoundColorSelector(QColor* reference, QWidget *parent = 0);
39 |
40 | private Q_SLOTS:
41 | void update_reference(QColor);
42 | };
43 | } // namespace color_widgets
44 | #endif // BOUND_COLOR_SELECTOR_HPP
45 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_2d_slider.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
23 | #define COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 | #include
27 |
28 | namespace color_widgets {
29 |
30 | /**
31 | * \brief A 2D slider that edits 2 color components
32 | */
33 | class QCP_EXPORT Color2DSlider : public QWidget
34 | {
35 | Q_OBJECT
36 |
37 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true STORED false )
38 | Q_PROPERTY(qreal hue READ hue WRITE setHue DESIGNABLE false )
39 | Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation DESIGNABLE false )
40 | Q_PROPERTY(qreal value READ value WRITE setValue DESIGNABLE false )
41 | /**
42 | * \brief Which color component is used on the x axis
43 | */
44 | Q_PROPERTY(Component componentX READ componentX WRITE setComponentX NOTIFY componentXChanged)
45 | /**
46 | * \brief Which color component is used on the y axis
47 | */
48 | Q_PROPERTY(Component componentY READ componentY WRITE setComponentY NOTIFY componentYChanged)
49 |
50 |
51 | public:
52 | enum Component {
53 | Hue, Saturation, Value
54 | };
55 | Q_ENUMS(Component)
56 |
57 | explicit Color2DSlider(QWidget *parent = nullptr);
58 | ~Color2DSlider();
59 |
60 | /// Get current color
61 | QColor color() const;
62 |
63 | QSize sizeHint() const Q_DECL_OVERRIDE;
64 |
65 | /// Get current hue in the range [0-1]
66 | qreal hue() const;
67 |
68 | /// Get current saturation in the range [0-1]
69 | qreal saturation() const;
70 |
71 | /// Get current value in the range [0-1]
72 | qreal value() const;
73 |
74 | Component componentX() const;
75 | Component componentY() const;
76 |
77 | public Q_SLOTS:
78 |
79 | /// Set current color
80 | void setColor(const QColor& c);
81 |
82 | /**
83 | * @param h Hue [0-1]
84 | */
85 | void setHue(qreal h);
86 |
87 | /**
88 | * @param s Saturation [0-1]
89 | */
90 | void setSaturation(qreal s);
91 |
92 | /**
93 | * @param v Value [0-1]
94 | */
95 | void setValue(qreal v);
96 |
97 | void setComponentX(Component componentX);
98 | void setComponentY(Component componentY);
99 |
100 | Q_SIGNALS:
101 | /**
102 | * Emitted when the user selects a color or setColor is called
103 | */
104 | void colorChanged(QColor);
105 |
106 | /**
107 | * Emitted when the user selects a color
108 | */
109 | void colorSelected(QColor);
110 |
111 | void componentXChanged(Component componentX);
112 | void componentYChanged(Component componentY);
113 |
114 | protected:
115 | void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
116 | void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
117 | void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
118 | void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
119 | void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
120 |
121 | private:
122 | class Private;
123 | Private * const p;
124 | };
125 |
126 | } // namespace color_widgets
127 |
128 | #endif // COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
129 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_delegate.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_DELEGATE_HPP
23 | #define COLOR_DELEGATE_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 |
27 | #include
28 |
29 | namespace color_widgets {
30 |
31 |
32 | class QCP_EXPORT ReadOnlyColorDelegate : public QStyledItemDelegate
33 | {
34 | Q_OBJECT
35 | public:
36 | using QStyledItemDelegate::QStyledItemDelegate;
37 |
38 | void paint(QPainter *painter, const QStyleOptionViewItem &option,
39 | const QModelIndex &index) const Q_DECL_OVERRIDE;
40 |
41 | QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
42 | };
43 |
44 | /**
45 | Delegate to use a ColorSelector in a color list
46 | */
47 | class QCP_EXPORT ColorDelegate : public ReadOnlyColorDelegate
48 | {
49 | Q_OBJECT
50 | public:
51 | using ReadOnlyColorDelegate::ReadOnlyColorDelegate;
52 |
53 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
54 | const QModelIndex &index) const Q_DECL_OVERRIDE;
55 |
56 | void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
57 |
58 | void setModelData(QWidget *editor, QAbstractItemModel *model,
59 | const QModelIndex &index) const Q_DECL_OVERRIDE;
60 |
61 | void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
62 | const QModelIndex &index) const Q_DECL_OVERRIDE;
63 |
64 | protected:
65 | bool eventFilter(QObject * watched, QEvent * event) Q_DECL_OVERRIDE;
66 |
67 | private slots:
68 | void close_editor();
69 | void color_changed();
70 | };
71 |
72 | } // namespace color_widgets
73 |
74 | #endif // COLOR_DELEGATE_HPP
75 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_dialog.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_DIALOG_HPP
23 | #define COLOR_DIALOG_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 | #include "color_preview.hpp"
27 | #include "color_wheel.hpp"
28 |
29 | #include
30 |
31 | class QAbstractButton;
32 |
33 | namespace color_widgets {
34 |
35 | class QCP_EXPORT ColorDialog : public QDialog
36 | {
37 | Q_OBJECT
38 | Q_ENUMS(ButtonMode)
39 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true)
40 | Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
41 | Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
42 | Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
43 | /**
44 | * \brief whether the color alpha channel can be edited.
45 | *
46 | * If alpha is disabled, the selected color's alpha will always be 255.
47 | */
48 | Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled NOTIFY alphaEnabledChanged)
49 |
50 | public:
51 | enum ButtonMode {
52 | OkCancel,
53 | OkApplyCancel,
54 | Close,
55 | NoButton
56 | };
57 |
58 | explicit ColorDialog(QWidget *parent = 0, Qt::WindowFlags f = {});
59 |
60 | ~ColorDialog();
61 |
62 | /**
63 | * Get currently selected color
64 | */
65 | QColor color() const;
66 |
67 | /**
68 | * Set the display mode for the color preview
69 | */
70 | void setPreviewDisplayMode(ColorPreview::DisplayMode mode);
71 |
72 | /**
73 | * Get the color preview diplay mode
74 | */
75 | ColorPreview::DisplayMode previewDisplayMode() const;
76 |
77 | bool alphaEnabled() const;
78 |
79 | /**
80 | * Select which dialog buttons to show
81 | *
82 | * There are three predefined modes:
83 | * OkCancel - this is useful when the dialog is modal and we just want to return a color
84 | * OkCancelApply - this is for non-modal dialogs
85 | * Close - for non-modal dialogs with direct color updates via colorChanged signal
86 | */
87 | void setButtonMode(ButtonMode mode);
88 | ButtonMode buttonMode() const;
89 |
90 | QSize sizeHint() const;
91 |
92 | ColorWheel::ShapeEnum wheelShape() const;
93 | ColorWheel::ColorSpaceEnum colorSpace() const;
94 | bool wheelRotating() const;
95 |
96 | public Q_SLOTS:
97 |
98 | /**
99 | * Change color
100 | */
101 | void setColor(const QColor &c);
102 |
103 | /**
104 | * Set the current color and show the dialog
105 | */
106 | void showColor(const QColor &oldcolor);
107 |
108 | void setWheelShape(ColorWheel::ShapeEnum shape);
109 | void setColorSpace(ColorWheel::ColorSpaceEnum space);
110 | void setWheelRotating(bool rotating);
111 |
112 | /**
113 | * Set whether the color alpha channel can be edited.
114 | * If alpha is disabled, the selected color's alpha will always be 255.
115 | */
116 | void setAlphaEnabled(bool a);
117 |
118 | Q_SIGNALS:
119 | /**
120 | * The current color was changed
121 | */
122 | void colorChanged(QColor);
123 |
124 | /**
125 | * The user selected the new color by pressing Ok/Apply
126 | */
127 | void colorSelected(QColor);
128 |
129 | void wheelShapeChanged(ColorWheel::ShapeEnum shape);
130 | void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
131 | void wheelRotatingChanged(bool rotating);
132 |
133 | void alphaEnabledChanged(bool alphaEnabled);
134 |
135 | private Q_SLOTS:
136 | /// Update all the Ui elements to match the selected color
137 | void setColorInternal(const QColor &color);
138 | /// Update from HSV sliders
139 | void set_hsv();
140 | /// Update from RGB sliders
141 | void set_rgb();
142 | /// Update from Alpha slider
143 | void set_alpha();
144 |
145 | void on_edit_hex_colorChanged(const QColor& color);
146 | void on_edit_hex_colorEditingFinished(const QColor& color);
147 |
148 | void on_buttonBox_clicked(QAbstractButton*);
149 |
150 | protected:
151 | void dragEnterEvent(QDragEnterEvent *event);
152 | void dropEvent(QDropEvent * event);
153 | void mouseReleaseEvent(QMouseEvent *event);
154 | void mouseMoveEvent(QMouseEvent *event);
155 |
156 | private:
157 | class Private;
158 | Private * const p;
159 | };
160 |
161 | } // namespace color_widgets
162 |
163 | #endif // COLOR_DIALOG_HPP
164 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_line_edit.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_WIDGETS_COLOR_LINE_EDIT_HPP
23 | #define COLOR_WIDGETS_COLOR_LINE_EDIT_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 | #include
27 | #include
28 |
29 | namespace color_widgets {
30 |
31 | /**
32 | * \brief A line edit used to define a color name
33 | *
34 | * Supported string formats:
35 | * * Short hex strings #f00
36 | * * Long hex strings #ff0000
37 | * * Color names red
38 | * * Function-like rgb(255,0,0)
39 | *
40 | * Additional string formats supported when showAlpha is true:
41 | * * Long hex strings #ff0000ff
42 | * * Function like rgba(255,0,0,255)
43 | */
44 | class QCP_EXPORT ColorLineEdit : public QLineEdit
45 | {
46 | Q_OBJECT
47 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
48 | /**
49 | * \brief Whether the widget displays and edits the alpha channel
50 | */
51 | Q_PROPERTY(bool showAlpha READ showAlpha WRITE setShowAlpha NOTIFY showAlphaChanged)
52 | /**
53 | * \brief If \b true, the background of the widget is changed to show the color
54 | */
55 | Q_PROPERTY(bool previewColor READ previewColor WRITE setPreviewColor NOTIFY previewColorChanged)
56 |
57 | public:
58 | explicit ColorLineEdit(QWidget* parent = nullptr);
59 | ~ColorLineEdit();
60 |
61 | QColor color() const;
62 | bool showAlpha() const;
63 | bool previewColor() const;
64 |
65 | public Q_SLOTS:
66 | void setColor(const QColor& color);
67 | void setShowAlpha(bool showAlpha);
68 | void setPreviewColor(bool previewColor);
69 |
70 | Q_SIGNALS:
71 | /**
72 | * \brief Emitted when the color is changed by any means
73 | */
74 | void colorChanged(const QColor& color);
75 | /**
76 | * \brief Emitted when the user is typing a color but has not finished yet
77 | */
78 | void colorEdited(const QColor& color);
79 | /**
80 | * \brief Emitted when the user finished to edit a string
81 | */
82 | void colorEditingFinished(const QColor& color);
83 |
84 | void showAlphaChanged(bool showAlpha);
85 | void previewColorChanged(bool previewColor);
86 |
87 | protected:
88 | void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
89 | void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
90 | void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
91 |
92 | private:
93 | class Private;
94 | Private* p;
95 | };
96 |
97 | } // namespace color_widgets
98 | #endif // COLOR_WIDGETS_COLOR_LINE_EDIT_HPP
99 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_list_widget.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_LIST_WIDGET_HPP
23 | #define COLOR_LIST_WIDGET_HPP
24 |
25 | #include "abstract_widget_list.hpp"
26 | #include "color_wheel.hpp"
27 |
28 | namespace color_widgets {
29 |
30 | class QCP_EXPORT ColorListWidget : public AbstractWidgetList
31 | {
32 | Q_OBJECT
33 |
34 | Q_PROPERTY(QList colors READ colors WRITE setColors NOTIFY colorsChanged )
35 | Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
36 | Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
37 | Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
38 |
39 | public:
40 | explicit ColorListWidget(QWidget *parent = 0);
41 | ~ColorListWidget();
42 |
43 | QList colors() const;
44 | void setColors(const QList& colors);
45 |
46 | void swap(int a, int b);
47 |
48 | void append();
49 |
50 | void setColor(const QColor& color);
51 |
52 | ColorWheel::ShapeEnum wheelShape() const;
53 | ColorWheel::ColorSpaceEnum colorSpace() const;
54 | bool wheelRotating() const;
55 |
56 | Q_SIGNALS:
57 | void colorsChanged(const QList&);
58 | void wheelShapeChanged(ColorWheel::ShapeEnum shape);
59 | void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
60 | void wheelRotatingChanged(bool rotating);
61 |
62 | public Q_SLOTS:
63 | void setWheelShape(ColorWheel::ShapeEnum shape);
64 | void setColorSpace(ColorWheel::ColorSpaceEnum space);
65 | void setWheelRotating(bool rotating);
66 |
67 | private Q_SLOTS:
68 | void emit_changed();
69 | void handle_removed(int);
70 | void color_changed(int row);
71 |
72 | private:
73 | class Private;
74 | Private * const p;
75 | void append_widget(int col);
76 | };
77 |
78 | } // namespace color_widgets
79 |
80 | #endif // COLOR_LIST_WIDGET_HPP
81 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_names.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_WIDGETS_COLOR_NAMES_HPP
23 | #define COLOR_WIDGETS_COLOR_NAMES_HPP
24 |
25 | #include
26 | #include
27 |
28 | #include
29 |
30 | namespace color_widgets {
31 |
32 | /**
33 | * \brief Convert a string into a color
34 | *
35 | * Supported string formats:
36 | * * Short hex strings #f00
37 | * * Long hex strings #ff0000
38 | * * Color names red
39 | * * Function-like rgb(255,0,0)
40 | *
41 | * Additional string formats supported only when \p alpha is true:
42 | * * Long hex strings #ff0000ff
43 | * * Function like rgba(255,0,0,255)
44 | */
45 | QCP_EXPORT QColor colorFromString(const QString& string, bool alpha = true);
46 |
47 | /**
48 | * \brief Convert a color into a string
49 | *
50 | * Format:
51 | * * If the color has full alpha: #ff0000
52 | * * If alpha is true and the color has non-full alpha: #ff000088
53 | */
54 | QCP_EXPORT QString stringFromColor(const QColor& color, bool alpha = true);
55 |
56 | } // namespace color_widgets
57 | #endif // COLOR_WIDGETS_COLOR_NAMES_HPP
58 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_palette_model.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP
23 | #define COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP
24 |
25 | #include
26 | #include "color_palette.hpp"
27 |
28 | namespace color_widgets {
29 |
30 | class QCP_EXPORT ColorPaletteModel : public QAbstractListModel
31 | {
32 | Q_OBJECT
33 | /**
34 | * \brief List of directories to be scanned for palette files
35 | */
36 | Q_PROPERTY(QStringList searchPaths READ searchPaths WRITE setSearchPaths NOTIFY searchPathsChanged)
37 |
38 | /**
39 | * \brief Default directory to be used when saving a palette
40 | */
41 | Q_PROPERTY(QString savePath READ savePath WRITE setSavePath NOTIFY savePathChanged)
42 |
43 | /**
44 | * \brief Size of the icon used for the palette previews
45 | */
46 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
47 |
48 |
49 | public:
50 | ColorPaletteModel();
51 | ~ColorPaletteModel();
52 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
53 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
54 | bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()) Q_DECL_OVERRIDE;
55 |
56 | QString savePath() const;
57 | QStringList searchPaths() const;
58 | QSize iconSize() const;
59 |
60 | /**
61 | * \brief Number of palettes
62 | */
63 | int count() const;
64 |
65 | /**
66 | * \brief Returns a reference to the first palette with the given name
67 | * \pre hasPalette(name)
68 | */
69 | const ColorPalette& palette(const QString& name) const;
70 |
71 | /**
72 | * \brief Whether a palette with the given name exists in the model
73 | */
74 | bool hasPalette(const QString& name) const;
75 |
76 | /**
77 | * \brief Get the palette at the given index (row)
78 | * \pre 0 <= index < count()
79 | */
80 | const ColorPalette& palette(int index) const;
81 |
82 | /**
83 | * \brief Updates an existing palette
84 | * \param index Palette index
85 | * \param palette New palette
86 | * \param save Whether to save the palette to the filesystem
87 | *
88 | * Saving will try: (in this order)
89 | * * To overwrite the file pointed by the old palette
90 | * * To write to the new palette file name
91 | * * To create a file in the save path
92 | * If all of the above fail, the palette will be replaced interally
93 | * but not on the filesystem
94 | *
95 | * \returns \b true if the palette has been successfully updated (and saved)
96 | */
97 | bool updatePalette(int index, const ColorPalette& palette, bool save = true);
98 |
99 | /**
100 | * \brief Remove a palette from the model and optionally from the filesystem
101 | * \returns \b true if the palette has been successfully removed
102 | */
103 | bool removePalette(int index, bool remove_file = true);
104 |
105 | /**
106 | * \brief Remove a palette to the model and optionally to the filesystem
107 | * \returns \b true if the palette has been successfully added
108 | */
109 | bool addPalette(const ColorPalette& palette, bool save = true);
110 |
111 | /**
112 | * \brief The index of the palette with the given file name
113 | * \returns -1 if none is found
114 | */
115 | int indexFromFile(const QString& filename) const;
116 |
117 | public Q_SLOTS:
118 | void setSavePath(const QString& savePath);
119 | void setSearchPaths(const QStringList& searchPaths);
120 | void addSearchPath(const QString& path);
121 | void setIconSize(const QSize& iconSize);
122 |
123 | /**
124 | * \brief Load palettes files found in the search paths
125 | */
126 | void load();
127 |
128 | Q_SIGNALS:
129 | void savePathChanged(const QString& savePath);
130 | void searchPathsChanged(const QStringList& searchPaths);
131 | void iconSizeChanged(const QSize& iconSize);
132 |
133 | private:
134 | class Private;
135 | Private* p;
136 | };
137 |
138 | } // namespace color_widgets
139 |
140 | #endif // COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP
141 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_preview.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | * \copyright Copyright (C) 2014 Calle Laakkonen
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Lesser General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with this program. If not, see .
21 | *
22 | */
23 | #ifndef COLOR_PREVIEW_HPP
24 | #define COLOR_PREVIEW_HPP
25 |
26 | #include "colorwidgets_global.hpp"
27 |
28 | #include
29 |
30 | namespace color_widgets {
31 |
32 | /**
33 | * Simple widget that shows a preview of a color
34 | */
35 | class QCP_EXPORT ColorPreview : public QWidget
36 | {
37 | Q_OBJECT
38 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true)
39 | Q_PROPERTY(QColor comparisonColor READ comparisonColor WRITE setComparisonColor NOTIFY comparisonColorChanged DESIGNABLE true)
40 | Q_PROPERTY(DisplayMode display_mode READ displayMode WRITE setDisplayMode NOTIFY displayModeChanged DESIGNABLE true)
41 | Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged DESIGNABLE true)
42 | Q_PROPERTY(bool drawFrame READ drawFrame WRITE setDrawFrame NOTIFY drawFrameChanged DESIGNABLE true)
43 | Q_ENUMS(DisplayMode)
44 | public:
45 | enum DisplayMode
46 | {
47 | NoAlpha, ///< Show current color with no transparency
48 | AllAlpha, ///< show current color with transparency
49 | SplitAlpha, ///< Show both solid and transparent side by side
50 | SplitColor, ///< Show current and comparison colors side by side
51 | SplitColorReverse, ///< Like Split color but swapped
52 | };
53 | Q_ENUMS(DisplayMode)
54 |
55 | explicit ColorPreview(QWidget *parent = 0);
56 | ~ColorPreview();
57 |
58 | /// Get the background visible under transparent colors
59 | QBrush background() const;
60 |
61 | /// Change the background visible under transparent colors
62 | void setBackground(const QBrush &bk);
63 |
64 | /// Get color display mode
65 | DisplayMode displayMode() const;
66 |
67 | /// Set how transparent colors are handled
68 | void setDisplayMode(DisplayMode dm);
69 |
70 | /// Get current color
71 | QColor color() const;
72 |
73 | /// Get the comparison color
74 | QColor comparisonColor() const;
75 |
76 | QSize sizeHint () const;
77 |
78 | void paint(QPainter &painter, QRect rect) const;
79 |
80 | /// Whether to draw a frame around the color
81 | bool drawFrame() const;
82 | void setDrawFrame(bool);
83 |
84 | public Q_SLOTS:
85 | /// Set current color
86 | void setColor(const QColor &c);
87 |
88 | /// Set the comparison color
89 | void setComparisonColor(const QColor &c);
90 |
91 | Q_SIGNALS:
92 | /// Emitted when the user clicks on the widget
93 | void clicked();
94 |
95 | /// Emitted on setColor
96 | void colorChanged(QColor);
97 |
98 | void comparisonColorChanged(QColor);
99 | void displayModeChanged(DisplayMode);
100 | void backgroundChanged(const QBrush&);
101 | void drawFrameChanged(bool);
102 | protected:
103 | void paintEvent(QPaintEvent *);
104 | void resizeEvent(QResizeEvent *);
105 | void mouseReleaseEvent(QMouseEvent *ev);
106 | void mouseMoveEvent(QMouseEvent *ev);
107 |
108 | private:
109 | class Private;
110 | Private * const p;
111 | };
112 |
113 | } // namespace color_widgets
114 | Q_DECLARE_METATYPE(color_widgets::ColorPreview::DisplayMode)
115 |
116 | #endif // COLOR_PREVIEW_HPP
117 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_selector.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_SELECTOR_HPP
23 | #define COLOR_SELECTOR_HPP
24 |
25 | #include "color_preview.hpp"
26 | #include "color_wheel.hpp"
27 |
28 | namespace color_widgets {
29 |
30 | /**
31 | * Color preview that opens a color dialog
32 | */
33 | class QCP_EXPORT ColorSelector : public ColorPreview
34 | {
35 | Q_OBJECT
36 | Q_ENUMS(UpdateMode)
37 | Q_PROPERTY(UpdateMode updateMode READ updateMode WRITE setUpdateMode NOTIFY updateModeChanged)
38 | Q_PROPERTY(Qt::WindowModality dialogModality READ dialogModality WRITE setDialogModality NOTIFY dialogModalityChanged)
39 | Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
40 | Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
41 | Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
42 |
43 | public:
44 | enum UpdateMode {
45 | Confirm, ///< Update color only after the dialog has been accepted
46 | Continuous ///< Update color as it's being modified in the dialog
47 | };
48 |
49 | explicit ColorSelector(QWidget *parent = 0);
50 | ~ColorSelector();
51 |
52 | void setUpdateMode(UpdateMode m);
53 | UpdateMode updateMode() const;
54 |
55 | Qt::WindowModality dialogModality() const;
56 | void setDialogModality(Qt::WindowModality m);
57 |
58 | ColorWheel::ShapeEnum wheelShape() const;
59 | ColorWheel::ColorSpaceEnum colorSpace() const;
60 | bool wheelRotating() const;
61 |
62 | Q_SIGNALS:
63 | void wheelShapeChanged(ColorWheel::ShapeEnum shape);
64 | void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
65 | void wheelRotatingChanged(bool rotating);
66 | void updateModeChanged(UpdateMode);
67 | void dialogModalityChanged(Qt::WindowModality);
68 | /// Emitted when a color is selected by the user
69 | void colorSelected(const QColor& c);
70 |
71 | public Q_SLOTS:
72 | void showDialog();
73 | void setWheelShape(ColorWheel::ShapeEnum shape);
74 | void setColorSpace(ColorWheel::ColorSpaceEnum space);
75 | void setWheelRotating(bool rotating);
76 |
77 | private Q_SLOTS:
78 | void accept_dialog();
79 | void reject_dialog();
80 | void update_old_color(const QColor &c);
81 |
82 | protected:
83 | void dragEnterEvent(QDragEnterEvent *event);
84 | void dropEvent(QDropEvent * event);
85 |
86 | private:
87 | /// Connect/Disconnect colorChanged based on UpdateMode
88 | void connect_dialog();
89 |
90 | /// Disconnect from dialog update
91 | void disconnect_dialog();
92 |
93 | class Private;
94 | Private * const p;
95 | };
96 |
97 | } // namespace color_widgets
98 |
99 | #endif // COLOR_SELECTOR_HPP
100 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/color_utils.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_UTILS_HPP
23 | #define COLOR_UTILS_HPP
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include "QtColorWidgets/colorwidgets_global.hpp"
30 |
31 | namespace color_widgets {
32 | namespace utils {
33 |
34 |
35 | QCP_EXPORT inline qreal color_chromaF(const QColor& c)
36 | {
37 | qreal max = qMax(c.redF(), qMax(c.greenF(), c.blueF()));
38 | qreal min = qMin(c.redF(), qMin(c.greenF(), c.blueF()));
39 | return max - min;
40 | }
41 |
42 | QCP_EXPORT inline qreal color_lumaF(const QColor& c)
43 | {
44 | return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
45 | }
46 |
47 | QCP_EXPORT QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 );
48 |
49 | QCP_EXPORT inline QColor rainbow_lch(qreal hue)
50 | {
51 | return color_from_lch(hue,1,1);
52 | }
53 |
54 | QCP_EXPORT inline QColor rainbow_hsv(qreal hue)
55 | {
56 | return QColor::fromHsvF(hue,1,1);
57 | }
58 |
59 | QCP_EXPORT inline qreal color_lightnessF(const QColor& c)
60 | {
61 | return ( qMax(c.redF(),qMax(c.greenF(),c.blueF())) +
62 | qMin(c.redF(),qMin(c.greenF(),c.blueF())) ) / 2;
63 | }
64 |
65 | QCP_EXPORT inline qreal color_HSL_saturationF(const QColor& col)
66 | {
67 | qreal c = color_chromaF(col);
68 | qreal l = color_lightnessF(col);
69 | if ( qFuzzyCompare(l+1,1) || qFuzzyCompare(l+1,2) )
70 | return 0;
71 | return c / (1-qAbs(2*l-1));
72 | }
73 |
74 |
75 | QCP_EXPORT QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 );
76 |
77 | QCP_EXPORT QColor get_screen_color(const QPoint &global_pos);
78 |
79 | } // namespace utils
80 | } // namespace color_widgets
81 |
82 | #endif // COLOR_UTILS_HPP
83 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/colorwidgets_global.hpp:
--------------------------------------------------------------------------------
1 | #ifndef QT_COLOR_WIDGETS_GLOBAL_H
2 | #define QT_COLOR_WIDGETS_GLOBAL_H
3 |
4 | #include
5 |
6 | #if defined(QTCOLORWIDGETS_STATICALLY_LINKED)
7 | # define QCP_EXPORT
8 | #elif defined(QTCOLORWIDGETS_LIBRARY)
9 | # define QCP_EXPORT Q_DECL_EXPORT
10 | #else
11 | # define QCP_EXPORT Q_DECL_IMPORT
12 | #endif
13 |
14 | #endif // QT_COLOR_WIDGETS_GLOBAL_H
15 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/gradient_delegate.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 |
23 | #ifndef COLOR_WIDGETS_GRADIENT_DELEGATE_HPP
24 | #define COLOR_WIDGETS_GRADIENT_DELEGATE_HPP
25 |
26 |
27 | #include
28 | #include
29 |
30 | #include "QtColorWidgets/gradient_editor.hpp"
31 |
32 | namespace color_widgets {
33 |
34 | /**
35 | * \brief Item delegate to edits gradients
36 | *
37 | * In order to make it work, return as edit data from the model a QBrush with a gradient
38 | */
39 | class QCP_EXPORT GradientDelegate : public QStyledItemDelegate
40 | {
41 | Q_OBJECT
42 |
43 | public:
44 | QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const Q_DECL_OVERRIDE
45 | {
46 | QVariant data = index.data(Qt::EditRole);
47 | if ( data.canConvert() )
48 | {
49 | QBrush brush = data.value();
50 | if ( brush.gradient() )
51 | {
52 | GradientEditor* editor = new GradientEditor(parent);
53 | editor->setStops(brush.gradient()->stops());
54 | return editor;
55 | }
56 | }
57 |
58 | return QStyledItemDelegate::createEditor(parent, option, index);
59 | }
60 |
61 | void setModelData(QWidget * widget, QAbstractItemModel * model, const QModelIndex & index) const Q_DECL_OVERRIDE
62 | {
63 | if ( GradientEditor* editor = qobject_cast(widget) )
64 | model->setData(index, QBrush(editor->gradient()), Qt::EditRole);
65 | else
66 | QStyledItemDelegate::setModelData(widget, model, index);
67 | }
68 |
69 | void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const Q_DECL_OVERRIDE
70 | {
71 | QVariant display_data = index.data(Qt::DisplayRole);
72 | QVariant gradient_data = display_data.isValid() ? display_data : index.data(Qt::EditRole);
73 | if ( gradient_data.canConvert() )
74 | {
75 | QBrush brush = gradient_data.value();
76 | if ( brush.gradient() )
77 | {
78 | QBrush background;
79 | background.setTexture(QPixmap(QStringLiteral(":/color_widgets/alphaback.png")));
80 | painter->fillRect(option.rect, background);
81 |
82 | QLinearGradient g(option.rect.topLeft(), option.rect.topRight());
83 | g.setStops(brush.gradient()->stops());
84 | painter->fillRect(option.rect, g);
85 |
86 | if ( option.state & QStyle::State_Selected )
87 | {
88 | int border = 2;
89 | painter->setBrush(Qt::transparent);
90 | painter->setPen(QPen(option.palette.highlight(), border));
91 | painter->drawRect(option.rect.adjusted(border/2, border/2, -border/2, -border/2));
92 | }
93 | return;
94 | }
95 | }
96 |
97 | QStyledItemDelegate::paint(painter, option, index);
98 | }
99 | };
100 |
101 | } // namespace color_widgets
102 |
103 | #endif // COLOR_WIDGETS_GRADIENT_DELEGATE_HPP
104 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/gradient_editor.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file gradient_editor.hpp
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef GRADIENT_EDITOR_HPP
23 | #define GRADIENT_EDITOR_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 |
27 | #include
28 | #include
29 |
30 | namespace color_widgets {
31 |
32 | class ColorDialog;
33 |
34 | /**
35 | * \brief A slider that moves on top of a gradient
36 | */
37 | class QCP_EXPORT GradientEditor : public QWidget
38 | {
39 | Q_OBJECT
40 | Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged)
41 | Q_PROPERTY(QGradientStops stops READ stops WRITE setStops NOTIFY stopsChanged)
42 | Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
43 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
44 | Q_PROPERTY(int selectedStop READ selectedStop WRITE setSelectedStop NOTIFY selectedStopChanged)
45 | Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
46 |
47 | public:
48 | explicit GradientEditor(QWidget *parent = 0);
49 | explicit GradientEditor(Qt::Orientation orientation, QWidget *parent = 0);
50 | ~GradientEditor();
51 |
52 | QSize sizeHint() const override;
53 |
54 | /// Get the background, it's visible for transparent gradient stops
55 | QBrush background() const;
56 | /// Set the background, it's visible for transparent gradient stops
57 | void setBackground(const QBrush &bg);
58 |
59 | /// Get the colors that make up the gradient
60 | QGradientStops stops() const;
61 | /// Set the colors that make up the gradient
62 | void setStops(const QGradientStops &colors);
63 |
64 | /// Get the gradient
65 | QLinearGradient gradient() const;
66 | /// Set the gradient
67 | void setGradient(const QLinearGradient &gradient);
68 |
69 | Qt::Orientation orientation() const;
70 |
71 | /**
72 | * \brief Dialog shown when double clicking a stop
73 | */
74 | ColorDialog* dialog() const;
75 |
76 | /**
77 | * \brief Index of the currently selected gradient stop (or -1 if there is no selection)
78 | */
79 | int selectedStop() const;
80 |
81 | /**
82 | * \brief Color of the selected stop
83 | */
84 | QColor selectedColor() const;
85 |
86 | public Q_SLOTS:
87 | void setOrientation(Qt::Orientation);
88 | void setSelectedStop(int stop);
89 | void setSelectedColor(const QColor& color);
90 | void addStop();
91 | void removeStop();
92 |
93 | Q_SIGNALS:
94 | void backgroundChanged(const QBrush&);
95 | void stopsChanged(const QGradientStops&);
96 | void selectedStopChanged(int);
97 |
98 | protected:
99 | void paintEvent(QPaintEvent *ev) override;
100 |
101 | void mousePressEvent(QMouseEvent *ev) override;
102 | void mouseMoveEvent(QMouseEvent *ev) override;
103 | void mouseReleaseEvent(QMouseEvent *ev) override;
104 | void leaveEvent(QEvent * event) override;
105 | void mouseDoubleClickEvent(QMouseEvent *event) override;
106 |
107 | void dragEnterEvent(QDragEnterEvent *event) override;
108 | void dragMoveEvent(QDragMoveEvent* event) override;
109 | void dragLeaveEvent(QDragLeaveEvent *event) override;
110 | void dropEvent(QDropEvent* event) override;
111 |
112 | private Q_SLOTS:
113 | void dialogUpdate(const QColor& c);
114 |
115 | private:
116 | class Private;
117 | Private * const p;
118 | };
119 |
120 | } // namespace color_widgets
121 |
122 | #endif // GRADIENT_EDITOR_HPP
123 |
124 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/gradient_helper.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef GRADIENT_HELPER_HPP
23 | #define GRADIENT_HELPER_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 |
27 | #include
28 |
29 | namespace color_widgets {
30 |
31 | inline QColor blendColors(const QColor& a, const QColor& b, qreal ratio)
32 | {
33 | return QColor::fromRgbF(
34 | a.redF() * (1-ratio) + b.redF() * ratio,
35 | a.greenF() * (1-ratio) + b.greenF() * ratio,
36 | a.blueF() * (1-ratio) + b.blueF() * ratio,
37 | a.alphaF() * (1-ratio) + b.alphaF() * ratio
38 | );
39 | }
40 |
41 |
42 | /**
43 | * \brief Get an insertion point in the gradient
44 | * \param gradient Gradient stops to look into (must be properly set up)
45 | * \param factor Value in [0, 1] to get the color for
46 | * \return A pair whose first element is the index to insert the new value at, and a GradientStop
47 | */
48 | inline QPair Q_DECL_EXPORT gradientBlendedColorInsert(const QGradientStops& gradient, qreal factor)
49 | {
50 | if ( gradient.empty() )
51 | return {0, {0, QColor()}};
52 |
53 | if ( gradient.size() == 1 || factor <= 0 )
54 | return {0, gradient.front()};
55 |
56 | int i = 0;
57 | QGradientStop s1;
58 | for ( auto s2 : gradient )
59 | {
60 | if ( factor < s2.first )
61 | {
62 | qreal ratio = (factor - s1.first) / (s2.first - s1.first);
63 | return {i, {factor, blendColors(s1.second, s2.second, ratio)}};
64 | }
65 | s1 = s2;
66 | ++i;
67 | }
68 |
69 | return {gradient.size(), gradient.back()};
70 | }
71 |
72 | /**
73 | * \brief Returns a color in the gradient
74 | * \param gradient Gradient stops to look into (must be properly set up)
75 | * \param factor Value in [0, 1] to get the color for
76 | */
77 | inline QColor Q_DECL_EXPORT gradientBlendedColor(const QGradientStops& gradient, qreal factor)
78 | {
79 | return gradientBlendedColorInsert(gradient, factor).second.second;
80 | }
81 |
82 | /**
83 | * \brief Returns a color in the gradient
84 | * \param gradient Gradient to look into
85 | * \param factor Value in [0, 1] to get the color for
86 | */
87 | inline QColor Q_DECL_EXPORT gradientBlendedColor(const QGradient& gradient, qreal factor)
88 | {
89 | return gradientBlendedColor(gradient.stops(), factor);
90 | }
91 |
92 | } // namespace color_widgets
93 |
94 |
95 |
96 |
97 | #endif // GRADIENT_HELPER_HPP
98 |
99 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/gradient_list_model.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #ifndef COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP
23 | #define COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP
24 |
25 | #include "colorwidgets_global.hpp"
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace color_widgets {
32 |
33 | class QCP_EXPORT GradientListModel : public QAbstractListModel
34 | {
35 | Q_OBJECT
36 |
37 | /**
38 | * \brief Size of the icon used for the gradient previews
39 | */
40 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
41 |
42 | Q_PROPERTY(ItemEditMode editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
43 |
44 | public:
45 | enum ItemEditMode
46 | {
47 | EditNone = 0,
48 | EditName,
49 | EditGradient,
50 | };
51 |
52 | Q_ENUM(ItemEditMode);
53 |
54 | GradientListModel(QObject *parent = nullptr);
55 | ~GradientListModel();
56 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
57 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
58 | Qt::ItemFlags flags(const QModelIndex & index) const Q_DECL_OVERRIDE;
59 | bool setData(const QModelIndex & index, const QVariant & value, int role) Q_DECL_OVERRIDE;
60 |
61 | QSize iconSize() const;
62 |
63 | /**
64 | * \brief Number of gradients
65 | */
66 | int count() const;
67 |
68 | /**
69 | * \brief Remove all gradients
70 | */
71 | void clear();
72 |
73 | /**
74 | * \brief Returns a reference to the first gradient with the given name
75 | * \pre hasGradient(name)
76 | */
77 | const QLinearGradient& gradient(const QString& name) const;
78 |
79 | /**
80 | * \brief Returns a reference to the first gradient with the given name
81 | * \pre hasGradient(name)
82 | */
83 | QGradientStops gradientStops(const QString& name) const;
84 |
85 | /**
86 | * \brief Whether a gradient with the given name exists in the model
87 | */
88 | bool hasGradient(const QString& name) const;
89 |
90 | /**
91 | * \brief Get the gradient at the given index (row)
92 | * \pre 0 <= index < count()
93 | */
94 | const QLinearGradient& gradient(int index) const;
95 |
96 | /**
97 | * \brief Get the gradient stops at the given index (row)
98 | * \pre 0 <= index < count()
99 | */
100 | QGradientStops gradientStops(int index) const;
101 |
102 | /**
103 | * \brief Inserts or updates a gradient
104 | * \returns The index for the new gradient
105 | */
106 | int setGradient(const QString& name, const QGradient& gradient);
107 |
108 | int setGradient(const QString& name, const QGradientStops& gradient);
109 |
110 | /**
111 | * \brief Updates the gradient at \p index
112 | */
113 | bool setGradient(int index, const QGradient& gradient);
114 |
115 | bool setGradient(int index, const QGradientStops& gradient);
116 |
117 | /**
118 | * \brief Renames the gradient at \p index
119 | * \returns \b true on success
120 | */
121 | bool rename(int index, const QString& new_name);
122 |
123 | /**
124 | * \brief Renames a gradient
125 | * \returns \b true on success
126 | */
127 | bool rename(const QString& old_name, const QString& new_name);
128 |
129 | /**
130 | * \brief Remove a gradient from the model
131 | * \returns \b true if the gradient has been successfully removed
132 | */
133 | bool removeGradient(const QString& name);
134 |
135 |
136 | bool removeGradient(int index);
137 |
138 | /**
139 | * \brief The index of the gradient with the given name
140 | * \returns -1 if none is found
141 | */
142 | int indexFromName(const QString& name) const;
143 |
144 | /**
145 | * \brief Name of the gradient at index
146 | */
147 | QString nameFromIndex(int index) const;
148 |
149 | ItemEditMode editMode() const;
150 |
151 | /**
152 | * \brief Brush for a gradient
153 | * \pre 0 <= \p index < count()
154 | */
155 | QBrush gradientBrush(int index) const;
156 |
157 | public Q_SLOTS:
158 | void setIconSize(const QSize& iconSize);
159 | void setEditMode(ItemEditMode mode);
160 |
161 | Q_SIGNALS:
162 | void iconSizeChanged(const QSize& iconSize);
163 | void editModeChanged(ItemEditMode mode);
164 |
165 | private:
166 | class Private;
167 | std::unique_ptr d;
168 | };
169 |
170 | } // namespace color_widgets
171 |
172 | #endif // COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP
173 |
174 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/gradient_slider.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file gradient_slider.hpp
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | * \copyright Copyright (C) 2014 Calle Laakkonen
8 | * \copyright Copyright (C) 2017 caryoscelus
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU Lesser General Public License
21 | * along with this program. If not, see .
22 | *
23 | */
24 | #ifndef GRADIENT_SLIDER_HPP
25 | #define GRADIENT_SLIDER_HPP
26 |
27 | #include "colorwidgets_global.hpp"
28 |
29 | #include
30 | #include
31 |
32 | namespace color_widgets {
33 |
34 | /**
35 | * \brief A slider that moves on top of a gradient
36 | */
37 | class QCP_EXPORT GradientSlider : public QSlider
38 | {
39 | Q_OBJECT
40 | Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged)
41 | Q_PROPERTY(QGradientStops colors READ colors WRITE setColors DESIGNABLE false)
42 | Q_PROPERTY(QColor firstColor READ firstColor WRITE setFirstColor STORED false)
43 | Q_PROPERTY(QColor lastColor READ lastColor WRITE setLastColor STORED false)
44 | Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
45 |
46 | public:
47 | explicit GradientSlider(QWidget *parent = 0);
48 | explicit GradientSlider(Qt::Orientation orientation, QWidget *parent = 0);
49 | ~GradientSlider();
50 |
51 | /// Get the background, it's visible for transparent gradient stops
52 | QBrush background() const;
53 | /// Set the background, it's visible for transparent gradient stops
54 | void setBackground(const QBrush &bg);
55 |
56 | /// Get the colors that make up the gradient
57 | QGradientStops colors() const;
58 | /// Set the colors that make up the gradient
59 | void setColors(const QGradientStops &colors);
60 |
61 | /// Get the gradient
62 | QLinearGradient gradient() const;
63 | /// Set the gradient
64 | void setGradient(const QLinearGradient &gradient);
65 |
66 | /**
67 | * Overload: create an evenly distributed gradient of the given colors
68 | */
69 | void setColors(const QVector &colors);
70 |
71 | /**
72 | * \brief Set the first color of the gradient
73 | *
74 | * If the gradient is currently empty it will create a stop with the given color
75 | */
76 | void setFirstColor(const QColor &c);
77 |
78 | /**
79 | * \brief Set the last color of the gradient
80 | *
81 | * If the gradient is has less than two colors,
82 | * it will create a stop with the given color
83 | */
84 | void setLastColor(const QColor &c);
85 |
86 | /**
87 | * \brief Get the first color
88 | *
89 | * \returns QColor() con empty gradient
90 | */
91 | QColor firstColor() const;
92 |
93 | /**
94 | * \brief Get the last color
95 | *
96 | * \returns QColor() con empty gradient
97 | */
98 | QColor lastColor() const;
99 |
100 | Q_SIGNALS:
101 | void backgroundChanged(const QBrush&);
102 |
103 | protected:
104 | void paintEvent(QPaintEvent *ev) override;
105 |
106 | void mousePressEvent(QMouseEvent *ev) override;
107 | void mouseMoveEvent(QMouseEvent *ev) override;
108 | void mouseReleaseEvent(QMouseEvent *ev) override;
109 |
110 | private:
111 | class Private;
112 | Private * const p;
113 | };
114 |
115 | } // namespace color_widgets
116 |
117 | #endif // GRADIENT_SLIDER_HPP
118 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/harmony_color_wheel.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | * \copyright Copyright (C) 2017 caryoscelus
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Lesser General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with this program. If not, see .
21 | *
22 | */
23 | #ifndef HARMONY_COLOR_WHEEL_HPP
24 | #define HARMONY_COLOR_WHEEL_HPP
25 |
26 |
27 | #include "color_wheel.hpp"
28 |
29 | namespace color_widgets {
30 |
31 | /**
32 | * \brief ColorWheel with color harmonies
33 | */
34 | class QCP_EXPORT HarmonyColorWheel : public ColorWheel
35 | {
36 | Q_OBJECT
37 |
38 | public:
39 | explicit HarmonyColorWheel(QWidget *parent = 0);
40 | ~HarmonyColorWheel();
41 |
42 | /// Get all harmony colors (including main)
43 | QList harmonyColors() const;
44 |
45 | /// Get number of harmony colors (including main)
46 | unsigned int harmonyCount() const;
47 |
48 | /// Clear harmony color scheme
49 | void clearHarmonies();
50 |
51 | /**
52 | * @brief Add harmony color
53 | * @param hue_diff Initial hue difference (in [0-1) range)
54 | * @param editable Whether this harmony should be editable
55 | * @returns Index of newly added harmony
56 | */
57 | unsigned addHarmony(double hue_diff, bool editable);
58 |
59 | /**
60 | * @brief Add symmetric harmony color
61 | * @param relative_to Index of other harmony that should be symmetric relative to main hue
62 | * @returns Index of newly added harmony
63 | * Editability is inherited from symmetric editor
64 | */
65 | unsigned addSymmetricHarmony(unsigned relative_to);
66 |
67 | /**
68 | * @brief Add opposite harmony color
69 | * @param relative_to Index of other harmony that should be opposite to this
70 | * @returns Index of newly added harmony
71 | * Editability is inherited from opposite editor
72 | */
73 | unsigned addOppositeHarmony(unsigned relative_to);
74 |
75 | Q_SIGNALS:
76 | /**
77 | * Emitted when harmony settings or harmony colors are changed (including due to main hue change)
78 | */
79 | void harmonyChanged();
80 |
81 | protected:
82 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
83 | void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
84 | void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
85 | void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
86 |
87 | private:
88 | class Private;
89 | Private * p;
90 | };
91 |
92 | } // namespace color_widgets
93 |
94 | #endif // COLOR_WHEEL_HPP
95 |
96 |
--------------------------------------------------------------------------------
/src/lib/include/QtColorWidgets/hue_slider.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2014 Calle Laakkonen
7 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Lesser General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with this program. If not, see .
21 | *
22 | */
23 | #ifndef HUE_SLIDER_HPP
24 | #define HUE_SLIDER_HPP
25 |
26 | #include "gradient_slider.hpp"
27 |
28 | namespace color_widgets {
29 |
30 | /**
31 | * \brief A slider for selecting a hue value
32 | */
33 | class QCP_EXPORT HueSlider : public GradientSlider
34 | {
35 | Q_OBJECT
36 | /**
37 | * \brief Saturation used in the rainbow gradient, as a [0-1] float
38 | */
39 | Q_PROPERTY(qreal colorSaturation READ colorSaturation WRITE setColorSaturation NOTIFY colorSaturationChanged)
40 | /**
41 | * \brief Value used in the rainbow gradient, as a [0-1] float
42 | */
43 | Q_PROPERTY(qreal colorValue READ colorValue WRITE setColorValue NOTIFY colorValueChanged)
44 | /**
45 | * \brief Alpha used in the rainbow gradient, as a [0-1] float
46 | */
47 | Q_PROPERTY(qreal colorAlpha READ colorAlpha WRITE setColorAlpha NOTIFY colorAlphaChanged)
48 |
49 | /**
50 | * \brief Color with corresponding color* components
51 | */
52 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
53 |
54 | /**
55 | * \brief Normalized Hue, as indicated from the slider
56 | */
57 | Q_PROPERTY(qreal colorHue READ colorHue WRITE setColorHue NOTIFY colorHueChanged)
58 |
59 |
60 | public:
61 | explicit HueSlider(QWidget *parent = nullptr);
62 | explicit HueSlider(Qt::Orientation orientation, QWidget *parent = nullptr);
63 | ~HueSlider();
64 |
65 | qreal colorSaturation() const;
66 | qreal colorValue() const;
67 | qreal colorAlpha() const;
68 | QColor color() const;
69 | qreal colorHue() const;
70 |
71 | public Q_SLOTS:
72 | void setColorValue(qreal value);
73 | void setColorSaturation(qreal value);
74 | void setColorAlpha(qreal alpha);
75 | void setColorHue(qreal colorHue);
76 | /**
77 | * \brief Set Hue Saturation and ColorValue, ignoring alpha
78 | */
79 | void setColor(const QColor& color);
80 | /**
81 | * \brief Set Hue Saturation, ColorValue and Alpha
82 | */
83 | void setFullColor(const QColor& color);
84 |
85 | Q_SIGNALS:
86 | void colorHueChanged(qreal colorHue);
87 | void colorChanged(QColor);
88 | void colorAlphaChanged(qreal v);
89 | void colorSaturationChanged(qreal v);
90 | void colorValueChanged(qreal v);
91 |
92 | private:
93 | class Private;
94 | Private * const p;
95 | };
96 |
97 | } // namespace color_widgets
98 |
99 | #endif // HUE_SLIDER_HPP
100 |
101 |
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set (SOURCES
2 | alphaback.png
3 | color_widgets.qrc
4 | )
5 |
6 | file(RELATIVE_PATH
7 | PREFIX
8 | ${PROJECT_SOURCE_DIR}
9 | ${CMAKE_CURRENT_LIST_DIR})
10 |
11 |
12 | foreach (SOURCE IN LISTS SOURCES)
13 | target_sources (${TARGET_NAME}
14 | PRIVATE
15 | $)
16 | endforeach (SOURCE IN SOURCES)
17 |
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/alphaback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/alphaback.png
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/arrow-down-s-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/arrow-down-s-line.png
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/arrow-up-s-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/arrow-up-s-line.png
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/color_widgets.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | alphaback.png
4 | drop-fill.png
5 | drop-line.png
6 | delete-bin-7-line.png
7 | arrow-down-s-line.png
8 | arrow-up-s-line.png
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/delete-bin-7-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/delete-bin-7-line.png
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/drop-fill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/drop-fill.png
--------------------------------------------------------------------------------
/src/lib/resources/QtColorWidgets/drop-line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keshavbhatt/ColorPie/aa5541b7ca91fec9ab67d5607038d58d3a372d61/src/lib/resources/QtColorWidgets/drop-line.png
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set (SOURCES
2 | abstract_widget_list.cpp
3 | bound_color_selector.cpp
4 | color_2d_slider.cpp
5 | color_delegate.cpp
6 | color_dialog.cpp
7 | color_dialog.ui
8 | color_line_edit.cpp
9 | color_list_widget.cpp
10 | color_names.cpp
11 | color_palette.cpp
12 | color_palette_model.cpp
13 | color_palette_widget.cpp
14 | color_palette_widget.ui
15 | color_preview.cpp
16 | color_selector.cpp
17 | color_utils.cpp
18 | color_wheel.cpp
19 | gradient_slider.cpp
20 | hue_slider.cpp
21 | swatch.cpp
22 | gradient_editor.cpp
23 | harmony_color_wheel.cpp
24 | gradient_list_model.cpp
25 | )
26 |
27 | file(RELATIVE_PATH
28 | PREFIX
29 | ${PROJECT_SOURCE_DIR}
30 | ${CMAKE_CURRENT_LIST_DIR})
31 |
32 |
33 | foreach (SOURCE IN LISTS SOURCES)
34 | target_sources (${TARGET_NAME}
35 | PRIVATE
36 | $)
37 | endforeach (SOURCE IN SOURCES)
38 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/bound_color_selector.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #include "QtColorWidgets/bound_color_selector.hpp"
23 |
24 | namespace color_widgets {
25 |
26 | BoundColorSelector::BoundColorSelector(QColor* reference, QWidget *parent) :
27 | ColorSelector(parent), ref(reference)
28 | {
29 | setColor(*reference);
30 | connect(this,&ColorPreview::colorChanged,this, &BoundColorSelector::update_reference);
31 | }
32 |
33 | void BoundColorSelector::update_reference(QColor c)
34 | {
35 | *ref = c;
36 | }
37 |
38 | } // namespace color_widgets
39 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/color_list_widget.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #include "QtColorWidgets/color_list_widget.hpp"
23 | #include "QtColorWidgets/color_selector.hpp"
24 |
25 | namespace color_widgets {
26 |
27 | class ColorListWidget::Private
28 | {
29 | public:
30 | QColor currentColor;
31 | QList colors;
32 | QSignalMapper mapper;
33 | ColorWheel::ShapeEnum wheel_shape = ColorWheel::ShapeTriangle;
34 | ColorWheel::ColorSpaceEnum color_space = ColorWheel::ColorHSV;
35 | bool wheel_rotating = true;
36 | };
37 |
38 | ColorListWidget::ColorListWidget(QWidget *parent)
39 | : AbstractWidgetList(parent), p(new Private)
40 | {
41 | connect(this, &AbstractWidgetList::removed, this, &ColorListWidget::handle_removed);
42 | connect(&p->mapper, SIGNAL(mapped(int)), SLOT(color_changed(int)));
43 | }
44 |
45 | ColorListWidget::~ColorListWidget()
46 | {
47 | delete p;
48 | }
49 |
50 | QList ColorListWidget::colors() const
51 | {
52 | return p->colors;
53 | }
54 |
55 | void ColorListWidget::setColor(const QColor &color)
56 | {
57 | p->currentColor = color;
58 | }
59 |
60 | void ColorListWidget::setColors(const QList &colors)
61 | {
62 | clear();
63 | p->colors = colors;
64 | for(int i = 0;i < colors.size();i++ )
65 | append_widget(i);
66 | Q_EMIT colorsChanged(colors);
67 | }
68 |
69 | void ColorListWidget::swap(int a, int b)
70 | {
71 | ColorSelector* sa = widget_cast(a);
72 | ColorSelector* sb = widget_cast(b);
73 | if ( sa && sb )
74 | {
75 | QColor ca = sa->color();
76 | sa->setColor(sb->color());
77 | sb->setColor(ca);
78 | Q_EMIT colorsChanged(p->colors);
79 | }
80 | }
81 |
82 | void ColorListWidget::append()
83 | {
84 | p->colors.push_back(p->currentColor);
85 | append_widget(p->colors.size()-1);
86 | Q_EMIT colorsChanged(p->colors);
87 | }
88 |
89 | void ColorListWidget::emit_changed()
90 | {
91 | Q_EMIT colorsChanged(p->colors);
92 | }
93 |
94 | void ColorListWidget::handle_removed(int i)
95 | {
96 | p->colors.removeAt(i);
97 | Q_EMIT colorsChanged(p->colors);
98 | }
99 |
100 | void ColorListWidget::color_changed(int row)
101 | {
102 | ColorSelector *cs = widget_cast(row);
103 | if ( cs )
104 | {
105 | p->colors[row] = cs->color();
106 | Q_EMIT colorsChanged(p->colors);
107 | }
108 | }
109 |
110 | void ColorListWidget::append_widget(int col)
111 | {
112 | ColorSelector* cbs = new ColorSelector;
113 | cbs->setDisplayMode(ColorPreview::AllAlpha);
114 | cbs->setColor(p->colors[col]);
115 | //connect(cbs,SIGNAL(colorChanged(QColor)),SLOT(emit_changed()));
116 | p->mapper.setMapping(cbs,col);
117 | connect(cbs,SIGNAL(colorChanged(QColor)),&p->mapper,SLOT(map()));
118 | connect(this, &ColorListWidget::wheelRotatingChanged, cbs, &ColorSelector::setWheelRotating);
119 | connect(this, &ColorListWidget::wheelShapeChanged, cbs, &ColorSelector::setWheelShape);
120 | connect(this, &ColorListWidget::colorSpaceChanged, cbs, &ColorSelector::setColorSpace);
121 | appendWidget(cbs);
122 | //setRowHeight(count()-1,22);
123 | }
124 |
125 | void ColorListWidget::setWheelShape(ColorWheel::ShapeEnum shape)
126 | {
127 | Q_EMIT wheelShapeChanged(p->wheel_shape = shape);
128 | }
129 |
130 | ColorWheel::ShapeEnum ColorListWidget::wheelShape() const
131 | {
132 | return p->wheel_shape;
133 | }
134 |
135 | void ColorListWidget::setColorSpace(ColorWheel::ColorSpaceEnum space)
136 | {
137 | Q_EMIT colorSpaceChanged(p->color_space = space);
138 | }
139 |
140 | ColorWheel::ColorSpaceEnum ColorListWidget::colorSpace() const
141 | {
142 | return p->color_space;
143 | }
144 |
145 | void ColorListWidget::setWheelRotating(bool rotating)
146 | {
147 | Q_EMIT wheelRotatingChanged(p->wheel_rotating = rotating);
148 | }
149 |
150 | bool ColorListWidget::wheelRotating() const
151 | {
152 | return p->wheel_rotating;
153 | }
154 |
155 | } // namespace color_widgets
156 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/color_names.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #include "QtColorWidgets/color_names.hpp"
23 | #include
24 |
25 | static QRegularExpression regex_qcolor (QStringLiteral("^(?:(?:#[[:xdigit:]]{3})|(?:#[[:xdigit:]]{6})|(?:[[:alpha:]]+))$"));
26 | static QRegularExpression regex_func_rgb (QStringLiteral(R"(^rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)$)"));
27 | static QRegularExpression regex_hex_rgba (QStringLiteral("^#[[:xdigit:]]{8}$"));
28 | static QRegularExpression regex_func_rgba (QStringLiteral(R"(^rgba?\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)$)"));
29 |
30 | namespace color_widgets {
31 |
32 |
33 | QString stringFromColor(const QColor& color, bool alpha)
34 | {
35 | if ( !alpha || color.alpha() == 255 )
36 | return color.name();
37 | return color.name()+QStringLiteral("%1").arg(color.alpha(), 2, 16, QChar('0'));
38 | }
39 |
40 | QColor colorFromString(const QString& string, bool alpha)
41 | {
42 | QString xs = string.trimmed();
43 | QRegularExpressionMatch match;
44 |
45 | match = regex_qcolor.match(xs);
46 | if ( match.hasMatch() )
47 | {
48 | return QColor(xs);
49 | }
50 |
51 | match = regex_func_rgb.match(xs);
52 | if ( match.hasMatch() )
53 | {
54 | return QColor(
55 | match.captured(1).toInt(),
56 | match.captured(2).toInt(),
57 | match.captured(3).toInt()
58 | );
59 | }
60 |
61 | if ( alpha )
62 | {
63 | match = regex_hex_rgba.match(xs);
64 | if ( match.hasMatch() )
65 | {
66 | return QColor(
67 | xs.mid(1,2).toInt(nullptr,16),
68 | xs.mid(3,2).toInt(nullptr,16),
69 | xs.mid(5,2).toInt(nullptr,16),
70 | xs.mid(7,2).toInt(nullptr,16)
71 | );
72 | }
73 |
74 | match = regex_func_rgba.match(xs);
75 | if ( match.hasMatch() )
76 | {
77 | return QColor(
78 | match.captured(1).toInt(),
79 | match.captured(2).toInt(),
80 | match.captured(3).toInt(),
81 | match.captured(4).toInt()
82 | );
83 | }
84 | }
85 |
86 | return QColor();
87 | }
88 |
89 | } // namespace color_widgets
90 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/color_selector.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #include "QtColorWidgets/color_selector.hpp"
23 | #include "QtColorWidgets/color_dialog.hpp"
24 | #include
25 | #include
26 | #include
27 |
28 | namespace color_widgets {
29 |
30 | class ColorSelector::Private
31 | {
32 | public:
33 | UpdateMode update_mode;
34 | ColorDialog *dialog;
35 | QColor old_color;
36 |
37 | Private(QWidget *widget) : dialog(new ColorDialog(widget))
38 | {
39 | dialog->setButtonMode(ColorDialog::OkCancel);
40 | }
41 | };
42 |
43 | ColorSelector::ColorSelector(QWidget *parent) :
44 | ColorPreview(parent), p(new Private(this))
45 | {
46 | setUpdateMode(Continuous);
47 | p->old_color = color();
48 |
49 | connect(this,&ColorPreview::clicked,this,&ColorSelector::showDialog);
50 | connect(this,SIGNAL(colorChanged(QColor)),this,SLOT(update_old_color(QColor)));
51 | connect(p->dialog,&QDialog::rejected,this,&ColorSelector::reject_dialog);
52 | connect(p->dialog,&ColorDialog::colorSelected, this, &ColorSelector::accept_dialog);
53 |
54 | connect(p->dialog, &ColorDialog::wheelRotatingChanged, this, &ColorSelector::wheelRotatingChanged);
55 | connect(p->dialog, &ColorDialog::wheelShapeChanged, this, &ColorSelector::wheelShapeChanged);
56 | connect(p->dialog, &ColorDialog::colorSpaceChanged, this, &ColorSelector::colorSpaceChanged);
57 |
58 | setAcceptDrops(true);
59 | }
60 |
61 | ColorSelector::~ColorSelector()
62 | {
63 | delete p;
64 | }
65 |
66 | ColorSelector::UpdateMode ColorSelector::updateMode() const
67 | {
68 | return p->update_mode;
69 | }
70 |
71 | void ColorSelector::setUpdateMode(UpdateMode m)
72 | {
73 | p->update_mode = m;
74 | Q_EMIT updateModeChanged(m);
75 | }
76 |
77 | Qt::WindowModality ColorSelector::dialogModality() const
78 | {
79 | return p->dialog->windowModality();
80 | }
81 |
82 | void ColorSelector::setDialogModality(Qt::WindowModality m)
83 | {
84 | p->dialog->setWindowModality(m);
85 | Q_EMIT dialogModalityChanged(m);
86 | }
87 |
88 | void ColorSelector::setWheelShape(ColorWheel::ShapeEnum shape)
89 | {
90 | p->dialog->setWheelShape(shape);
91 | }
92 |
93 | ColorWheel::ShapeEnum ColorSelector::wheelShape() const
94 | {
95 | return p->dialog->wheelShape();
96 | }
97 |
98 | void ColorSelector::setColorSpace(ColorWheel::ColorSpaceEnum space)
99 | {
100 | p->dialog->setColorSpace(space);
101 | }
102 |
103 | ColorWheel::ColorSpaceEnum ColorSelector::colorSpace() const
104 | {
105 | return p->dialog->colorSpace();
106 | }
107 |
108 | void ColorSelector::setWheelRotating(bool rotating)
109 | {
110 | p->dialog->setWheelRotating(rotating);
111 | }
112 |
113 | bool ColorSelector::wheelRotating() const
114 | {
115 | return p->dialog->wheelRotating();
116 | }
117 |
118 | void ColorSelector::showDialog()
119 | {
120 | p->old_color = color();
121 | p->dialog->setColor(color());
122 | connect_dialog();
123 | p->dialog->show();
124 | }
125 |
126 |
127 | void ColorSelector::connect_dialog()
128 | {
129 | if (p->update_mode == Continuous)
130 | connect(p->dialog, SIGNAL(colorChanged(QColor)), this, SLOT(setColor(QColor)), Qt::UniqueConnection);
131 | else
132 | disconnect_dialog();
133 | }
134 |
135 | void ColorSelector::disconnect_dialog()
136 | {
137 | disconnect(p->dialog, SIGNAL(colorChanged(QColor)), this, SLOT(setColor(QColor)));
138 | }
139 |
140 | void ColorSelector::accept_dialog()
141 | {
142 | setColor(p->dialog->color());
143 | p->old_color = color();
144 | Q_EMIT colorSelected(color());
145 | }
146 |
147 | void ColorSelector::reject_dialog()
148 | {
149 | setColor(p->old_color);
150 | }
151 |
152 | void ColorSelector::update_old_color(const QColor &c)
153 | {
154 | if (!p->dialog->isVisible())
155 | p->old_color = c;
156 | }
157 |
158 | void ColorSelector::dragEnterEvent(QDragEnterEvent *event)
159 | {
160 | if ( event->mimeData()->hasColor() ||
161 | ( event->mimeData()->hasText() && QColor(event->mimeData()->text()).isValid() ) )
162 | event->acceptProposedAction();
163 | }
164 |
165 |
166 | void ColorSelector::dropEvent(QDropEvent *event)
167 | {
168 | if ( event->mimeData()->hasColor() )
169 | {
170 | setColor(event->mimeData()->colorData().value());
171 | event->accept();
172 | }
173 | else if ( event->mimeData()->hasText() )
174 | {
175 | QColor col(event->mimeData()->text());
176 | if ( col.isValid() )
177 | {
178 | setColor(col);
179 | event->accept();
180 | }
181 | }
182 | }
183 |
184 | } // namespace color_widgets
185 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/color_utils.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program. If not, see .
20 | *
21 | */
22 | #include "QtColorWidgets/color_utils.hpp"
23 |
24 | #include
25 | #include
26 | #include
27 |
28 |
29 | QColor color_widgets::utils::color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha )
30 | {
31 | qreal h1 = hue*6;
32 | qreal x = chroma*(1-qAbs(std::fmod(h1,2)-1));
33 | QColor col;
34 | if ( h1 >= 0 && h1 < 1 )
35 | col = QColor::fromRgbF(chroma,x,0);
36 | else if ( h1 < 2 )
37 | col = QColor::fromRgbF(x,chroma,0);
38 | else if ( h1 < 3 )
39 | col = QColor::fromRgbF(0,chroma,x);
40 | else if ( h1 < 4 )
41 | col = QColor::fromRgbF(0,x,chroma);
42 | else if ( h1 < 5 )
43 | col = QColor::fromRgbF(x,0,chroma);
44 | else if ( h1 < 6 )
45 | col = QColor::fromRgbF(chroma,0,x);
46 |
47 | qreal m = luma - color_lumaF(col);
48 |
49 | return QColor::fromRgbF(
50 | qBound(0.0,col.redF()+m,1.0),
51 | qBound(0.0,col.greenF()+m,1.0),
52 | qBound(0.0,col.blueF()+m,1.0),
53 | alpha);
54 | }
55 |
56 | QColor color_widgets::utils::color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha )
57 | {
58 | qreal chroma = (1 - qAbs(2*lig-1))*sat;
59 | qreal h1 = hue*6;
60 | qreal x = chroma*(1-qAbs(std::fmod(h1,2)-1));
61 | QColor col;
62 | if ( h1 >= 0 && h1 < 1 )
63 | col = QColor::fromRgbF(chroma,x,0);
64 | else if ( h1 < 2 )
65 | col = QColor::fromRgbF(x,chroma,0);
66 | else if ( h1 < 3 )
67 | col = QColor::fromRgbF(0,chroma,x);
68 | else if ( h1 < 4 )
69 | col = QColor::fromRgbF(0,x,chroma);
70 | else if ( h1 < 5 )
71 | col = QColor::fromRgbF(x,0,chroma);
72 | else if ( h1 < 6 )
73 | col = QColor::fromRgbF(chroma,0,x);
74 |
75 | qreal m = lig-chroma/2;
76 |
77 | return QColor::fromRgbF(
78 | qBound(0.0,col.redF()+m,1.0),
79 | qBound(0.0,col.greenF()+m,1.0),
80 | qBound(0.0,col.blueF()+m,1.0),
81 | alpha);
82 | }
83 |
84 |
85 | QColor color_widgets::utils::get_screen_color(const QPoint &global_pos)
86 | {
87 | QScreen *screen = QApplication::screenAt(global_pos);
88 |
89 | WId wid = QApplication::desktop()->winId();
90 | QImage img = screen->grabWindow(wid, global_pos.x(), global_pos.y(), 1, 1).toImage();
91 |
92 | return img.pixel(0,0);
93 | }
94 |
--------------------------------------------------------------------------------
/src/lib/src/QtColorWidgets/hue_slider.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file
3 | *
4 | * \author Mattia Basaglia
5 | *
6 | * \copyright Copyright (C) 2014 Calle Laakkonen
7 | * \copyright Copyright (C) 2013-2020 Mattia Basaglia
8 | * \copyright Copyright (C) 2017 caryoscelus
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU Lesser General Public License
21 | * along with this program. If not, see .
22 | *
23 | */
24 | #include "QtColorWidgets/hue_slider.hpp"
25 |
26 | namespace color_widgets {
27 |
28 | class HueSlider::Private
29 | {
30 | private:
31 | HueSlider *w;
32 |
33 | public:
34 | qreal saturation = 1;
35 | qreal value = 1;
36 | qreal alpha = 1;
37 |
38 | Private(HueSlider *widget)
39 | : w(widget)
40 | {
41 | w->setRange(0, 359);
42 | connect(w, &QSlider::valueChanged, [this]{
43 | Q_EMIT w->colorHueChanged(w->colorHue());
44 | Q_EMIT w->colorChanged(w->color());
45 | });
46 | updateGradient();
47 | }
48 |
49 | void updateGradient()
50 | {
51 | static const double n_colors = 6;
52 | QGradientStops colors;
53 | colors.reserve(n_colors+1);
54 | for ( int i = 0; i <= n_colors; ++i )
55 | colors.append(QGradientStop(i/n_colors, QColor::fromHsvF(i/n_colors, saturation, value)));
56 | w->setColors(colors);
57 | }
58 | };
59 |
60 | HueSlider::HueSlider(QWidget *parent) :
61 | GradientSlider(parent), p(new Private(this))
62 | {
63 | }
64 |
65 | HueSlider::HueSlider(Qt::Orientation orientation, QWidget *parent) :
66 | GradientSlider(orientation, parent), p(new Private(this))
67 | {
68 | }
69 |
70 | HueSlider::~HueSlider()
71 | {
72 | delete p;
73 | }
74 |
75 | qreal HueSlider::colorSaturation() const
76 | {
77 | return p->saturation;
78 | }
79 |
80 | void HueSlider::setColorSaturation(qreal s)
81 | {
82 | p->saturation = qBound(0.0, s, 1.0);
83 | p->updateGradient();
84 | Q_EMIT colorSaturationChanged(s);
85 | }
86 |
87 | qreal HueSlider::colorValue() const
88 | {
89 | return p->value;
90 | }
91 |
92 | void HueSlider::setColorValue(qreal v)
93 | {
94 | p->value = qBound(0.0, v, 1.0);
95 | p->updateGradient();
96 | Q_EMIT colorValueChanged(v);
97 | }
98 |
99 | qreal HueSlider::colorAlpha() const
100 | {
101 | return p->alpha;
102 | }
103 |
104 | void HueSlider::setColorAlpha(qreal alpha)
105 | {
106 | p->alpha = alpha;
107 | p->updateGradient();
108 | Q_EMIT colorAlphaChanged(alpha);
109 | }
110 |
111 | QColor HueSlider::color() const
112 | {
113 | return QColor::fromHsvF(colorHue(), p->saturation, p->value, p->alpha);
114 | }
115 |
116 | void HueSlider::setColor(const QColor& color)
117 | {
118 | p->saturation = color.saturationF();
119 | p->value = color.valueF();
120 | p->updateGradient();
121 | setColorHue(color.hueF());
122 | Q_EMIT colorValueChanged(p->alpha);
123 | Q_EMIT colorSaturationChanged(p->alpha);
124 | }
125 |
126 | void HueSlider::setFullColor(const QColor& color)
127 | {
128 | p->alpha = color.alphaF();
129 | setColor(color);
130 | Q_EMIT colorAlphaChanged(p->alpha);
131 | }
132 |
133 | qreal HueSlider::colorHue() const
134 | {
135 | if (maximum() == minimum())
136 | return 0;
137 | auto hue = qreal(value() - minimum()) / (maximum() - minimum());
138 | if (orientation() == Qt::Vertical)
139 | hue = 1 - hue;
140 | return hue;
141 | }
142 |
143 | void HueSlider::setColorHue(qreal colorHue)
144 | {
145 | // TODO: consider supporting invertedAppearance?
146 | if (orientation() == Qt::Vertical)
147 | colorHue = 1 - colorHue;
148 | setValue(minimum()+colorHue*(maximum()-minimum()));
149 | Q_EMIT colorHueChanged(colorHue);
150 | Q_EMIT colorChanged(color());
151 | }
152 |
153 | } // namespace color_widgets
154 |
--------------------------------------------------------------------------------
/src/light/branch_closed-on.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/branch_closed.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/branch_open-on.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/branch_open.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/checkbox_checked-hover.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/checkbox_checked.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/checkbox_checked_disabled.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/checkbox_indeterminate-hover.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/light/checkbox_indeterminate.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/light/checkbox_indeterminate_disabled.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/light/checkbox_unchecked-hover.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/checkbox_unchecked_disabled.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/close-hover.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/close-pressed.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/close.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/down_arrow-hover.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/down_arrow.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/down_arrow_disabled.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/hmovetoolbar.svg:
--------------------------------------------------------------------------------
1 |
5 |
6 |
--------------------------------------------------------------------------------
/src/light/hsepartoolbar.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/left_arrow.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/left_arrow_disabled.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/radio_checked-hover.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/radio_checked.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/radio_checked_disabled.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/radio_unchecked-hover.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/radio_unchecked_disabled.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/right_arrow.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/right_arrow_disabled.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/sizegrip.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/spinup_disabled.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/stylesheet-branch-end.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/stylesheet-branch-more.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/light/stylesheet-vline.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/transparent.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/light/undock-hover.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/light/undock.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/up_arrow-hover.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/up_arrow.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/up_arrow_disabled.svg:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/light/vmovetoolbar.svg:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/src/light/vsepartoolbars.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 |
10 |
11 | //NOTE: DISABLE Qt Quick Compiler in Project sttings if resources not loading in Release mode
12 |
13 | static inline QString host(const QHttpServerRequest &request)
14 | {
15 | return request.headers()[QStringLiteral("Host")].toString();
16 | }
17 |
18 | int main(int argc, char *argv[])
19 | {
20 | QApplication a(argc, argv);
21 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
22 | QApplication::setApplicationName("ColorPie");
23 | QApplication::setOrganizationName("org.keshavnrj.ubuntu");
24 | QCoreApplication::setApplicationVersion("1");
25 |
26 | qputenv("QTWEBENGINE_CHROMIUM_FLAGS","--single-process");
27 | #ifdef QT_DEBUG
28 | qputenv("QTWEBENGINE_CHROMIUM_FLAGS","--remote-debugging-port=9421");
29 | #endif
30 | qputenv("QTWEBENGINE_CHROMIUM_FLAGS","--no-sandbox");
31 |
32 | static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
33 | if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
34 | && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
35 | && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
36 | && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
37 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
38 | }
39 |
40 | QHttpServer httpServer;
41 |
42 | httpServer.route("/", [] (const QUrl &url) {
43 | if(url.isEmpty()){
44 | return QHttpServerResponse::fromFile(QStringLiteral(":/html/%1").arg("v2.html"));
45 | }else{
46 | //qDebug()<", [] (const QUrl &url) {
52 | //qDebug()<
5 | #include
6 | #include
7 |
8 | MainWindow::MainWindow(QWidget *parent,QString serverBase) :
9 | QMainWindow(parent),
10 | ui(new Ui::MainWindow)
11 | {
12 | ui->setupUi(this);
13 | initColor = QColor("#00a");
14 | home = serverBase;
15 | this->setWindowIcon(QIcon(":/icons/icon-256.png"));
16 | this->setWindowTitle(qApp->applicationName()+" v"+qApp->applicationVersion());
17 |
18 | connect(ui->webView,&QWebEngineView::loadFinished,[=](const bool loaded){
19 | if(loaded && !app_init){
20 | loadColor(initColor.name());
21 | managerWidget->setFromHex6(initColor.name());
22 | app_init = true;
23 | }
24 | });
25 |
26 | QWebEngineProfile *weProfile = new QWebEngineProfile(QApplication::applicationName(),this);
27 |
28 | QWebEnginePage *webenginepage = new QWebEnginePage(weProfile, this);
29 | webenginepage->setBackgroundColor(QColor("#EFF0F1"));
30 |
31 | connect(webenginepage,&QWebEnginePage::titleChanged,[=](const QString titleStr){
32 | this->setWindowTitle(QApplication::applicationName()+" | "+QString(titleStr));
33 | QString hex6 = QString(titleStr).split(">>").last().simplified().trimmed();
34 | QColor color("#"+hex6);
35 | if(color.isValid())
36 | managerWidget->setFromHex6("#"+hex6);
37 | });
38 |
39 | webenginepage->settings()->setAttribute(QWebEngineSettings::ShowScrollBars,false);
40 |
41 | //page should be set parent of profile to prevent
42 | //Release of profile requested but WebEnginePage still not deleted. Expect troubles !
43 | weProfile->setParent(webenginepage);
44 |
45 | ui->webView->setPage(webenginepage);
46 | setStyle(":/light.qss");
47 |
48 | ui->webView->setMinimumSize(500,500);
49 |
50 | managerWidget = new Manager(this);
51 | managerWidget->setMinimumSize(350,managerWidget->minimumSizeHint().height());
52 |
53 | managerWidget->initialize(initColor);
54 | connect(managerWidget,&Manager::colorChanged,[=](QString colorName){
55 | loadColor(colorName);
56 | });
57 |
58 | QSplitter *split1 = new QSplitter;
59 | split1->setObjectName("split1");
60 | split1->setOrientation(Qt::Horizontal);
61 | split1->addWidget(managerWidget);
62 | split1->addWidget(ui->webviewWidget);
63 | split1->setStretchFactor(0,2);
64 | split1->setStretchFactor(1,2);
65 | ui->centralWidget->layout()->addWidget(split1);
66 | if(settings.value("geometry").isValid()){
67 | restoreGeometry(settings.value("geometry").toByteArray());
68 | restoreState(settings.value("windowState").toByteArray());
69 | }
70 | ui->webviewWidget->layout()->setContentsMargins(9,0,0,0);
71 | ui->webView->load(QUrl(serverBase));
72 | }
73 | void MainWindow::loadColor(QString colorStr)
74 | {
75 | QString js = "document.getElementById('color').value = '"+colorStr+"';"
76 | "var event = new Event('keyup');"
77 | "document.getElementById('color').dispatchEvent(event);"
78 | "delete event;";
79 | ui->webView->page()->runJavaScript(js);
80 | }
81 |
82 | void MainWindow::closeEvent(QCloseEvent *event)
83 | {
84 | settings.setValue("geometry",saveGeometry());
85 | settings.setValue("windowState", saveState());
86 | managerWidget->saveColors();
87 | QMainWindow::closeEvent(event);
88 | }
89 |
90 | void MainWindow::setStyle(QString fname)
91 | {
92 | QFile styleSheet(fname);
93 | if (!styleSheet.open(QIODevice::ReadOnly)) {
94 | qWarning("Unable to open file");
95 | return; }
96 | qApp->setStyleSheet(styleSheet.readAll());
97 | styleSheet.close();
98 | }
99 |
100 | MainWindow::~MainWindow()
101 | {
102 | delete ui;
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/src/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | #include "manager.h"
16 |
17 | namespace Ui {
18 | class MainWindow;
19 | }
20 |
21 | class MainWindow : public QMainWindow
22 | {
23 | Q_OBJECT
24 |
25 | public:
26 | explicit MainWindow(QWidget *parent = nullptr,QString serverBase="");
27 | ~MainWindow();
28 |
29 | protected slots:
30 | void closeEvent(QCloseEvent *event);
31 | private slots:
32 | void setStyle(QString fname);
33 | void loadColor(QString colorStr);
34 | private:
35 | Ui::MainWindow *ui;
36 | QString home;
37 | QSettings settings;
38 | bool app_init = false;
39 | Manager * managerWidget = nullptr;
40 | QColor initColor;
41 |
42 | };
43 |
44 | #endif // MAINWINDOW_H
45 |
--------------------------------------------------------------------------------
/src/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 | 0
20 |
21 |
22 | 0
23 |
24 |
25 | 0
26 |
27 |
28 | 0
29 |
30 | -
31 |
32 |
33 |
34 | 0
35 |
36 |
37 | 0
38 |
39 |
40 | 0
41 |
42 |
43 | 0
44 |
45 |
-
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | QWebEngineView
62 | QWidget
63 | QtWebEngineWidgets/QWebEngineView
64 | 1
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/manager.cpp:
--------------------------------------------------------------------------------
1 | #include "manager.h"
2 | #include "ui_manager.h"
3 |
4 | using namespace color_widgets;
5 |
6 | Manager::Manager(QWidget *parent) :
7 | QWidget(parent),
8 | ui(new Ui::Manager)
9 | {
10 | ui->setupUi(this);
11 |
12 | colorDialog = new ColorDialog(this);
13 | colorListWidget = new ColorListWidget(this);
14 |
15 | connect(colorListWidget,&ColorListWidget::colorsChanged,[=](const QList&colorList){
16 | colorCollection = colorList;
17 | });
18 |
19 | colorDialog->layout()->setContentsMargins(0,0,0,0);
20 | colorDialog->setButtonMode(ColorDialog::NoButton);
21 | colorDialog->setPreviewDisplayMode(ColorPreview::AllAlpha);
22 |
23 | //gridLayout modifications
24 | QGridLayout *gridLayout = colorDialog->findChild("gridLayout");
25 | gridLayout->setContentsMargins(0,0,0,0);
26 | gridLayout->setSpacing(0);
27 | for (int i = 0; i < gridLayout->count(); ++i) {
28 | setLayoutVisible(gridLayout->itemAt(i),false);
29 | }
30 |
31 | connect(colorDialog,&ColorDialog::colorChanged,[=](const QColor color){
32 | Q_EMIT colorChanged(color.name());
33 | colorListWidget->setColor(color);
34 | });
35 |
36 | ui->colorBoxLayout->addWidget(colorDialog);
37 | ui->savedColorsBoxLayout->addWidget(colorListWidget);
38 |
39 | loadColors();
40 | }
41 |
42 | //helper
43 | void Manager::setLayoutVisible(QLayoutItem *item, bool visible)
44 | {
45 | if (auto widget = item->widget())
46 | return widget->setVisible(visible);
47 | if (auto layout = item->layout())
48 | for (int i = 0; i < layout->count(); ++i)
49 | setLayoutVisible(layout->itemAt(i), visible);
50 | }
51 |
52 | void Manager::setFromHex6(QString hex6)
53 | {
54 | colorDialog->blockSignals(true);
55 | colorDialog->setColor(QColor(hex6));
56 | colorListWidget->setColor(QColor(hex6));
57 | colorDialog->blockSignals(false);
58 | }
59 |
60 | void Manager::initialize(QColor color)
61 | {
62 | ui->colorControl->setText(color.name());
63 | }
64 |
65 | Manager::~Manager()
66 | {
67 | delete ui;
68 | }
69 |
70 | void Manager::on_colorControl_textChanged(const QString &arg1)
71 | {
72 | Q_EMIT colorChanged(arg1);
73 | if(arg1.length()==7){
74 | QColor color(arg1);
75 | if(color.isValid()){
76 | colorDialog->setColor(color);
77 | }
78 | }
79 | }
80 |
81 | void Manager::on_supportedInputs_clicked()
82 | {
83 | SupportedInputs *sup = new SupportedInputs(this);
84 | sup->setWindowTitle(QApplication::applicationName()+" | "+"Supported Input");
85 | sup->setAttribute(Qt::WA_DeleteOnClose);
86 | sup->show();
87 | }
88 |
89 | void Manager::saveColors()
90 | {
91 | QJsonArray dataArray;
92 | foreach (auto color, colorCollection) {
93 | dataArray.append(QJsonValue(color.name()));
94 | }
95 | QJsonDocument doc(dataArray);
96 | QString filepath = utils::returnPath("savedColors")+QDir::separator()+"colors.json";
97 | utils::saveJson(doc,filepath);
98 | }
99 |
100 | void Manager::loadColors()
101 | {
102 | QString filepath = utils::returnPath("savedColors")+QDir::separator()+"colors.json";
103 | QJsonDocument doc = utils::loadJson(filepath);
104 | if(doc.isNull()==false){
105 | QJsonArray dataArray = doc.array();
106 | foreach (auto color, dataArray) {
107 | colorCollection.append(QColor(color.toString()));
108 | }
109 | }
110 | colorListWidget->setColors(colorCollection);
111 | }
112 |
--------------------------------------------------------------------------------
/src/manager.h:
--------------------------------------------------------------------------------
1 | #ifndef MANAGER_H
2 | #define MANAGER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include "QtColorWidgets/color_line_edit.hpp"
15 | #include "QtColorWidgets/ColorPreview"
16 | #include "QtColorWidgets/ColorDialog"
17 | #include "QtColorWidgets/ColorListWidget"
18 |
19 | #include "utils.h"
20 | #include "supportedinputs.h"
21 |
22 | namespace Ui {
23 | class Manager;
24 | }
25 |
26 | class Manager : public QWidget
27 | {
28 | Q_OBJECT
29 |
30 | signals:
31 | void colorChanged(QString colorName);
32 |
33 | public:
34 | explicit Manager(QWidget *parent = nullptr);
35 | ~Manager();
36 |
37 | public slots:
38 | void initialize(QColor color);
39 | void setFromHex6(QString hex6);
40 | void saveColors();
41 |
42 | private slots:
43 | void on_colorControl_textChanged(const QString &arg1);
44 |
45 | void on_supportedInputs_clicked();
46 |
47 | void setLayoutVisible(QLayoutItem *item, bool visible);
48 | void loadColors();
49 | private:
50 | Ui::Manager *ui;
51 |
52 |
53 | color_widgets::ColorLineEdit *colorLineEdit = nullptr;
54 | color_widgets::ColorDialog * colorDialog = nullptr;
55 | color_widgets::ColorListWidget * colorListWidget = nullptr;
56 |
57 | QList colorCollection;
58 | QSettings settings;
59 |
60 | };
61 |
62 | #endif // MANAGER_H
63 |
--------------------------------------------------------------------------------
/src/manager.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Manager
4 |
5 |
6 |
7 | 0
8 | 0
9 | 449
10 | 363
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 |
20 | -
21 |
22 |
23 |
24 | 0
25 | 280
26 |
27 |
28 |
29 | Color chooser
30 |
31 |
32 |
-
33 |
34 |
-
35 |
36 |
37 | Input color name or code
38 |
39 |
40 |
41 | -
42 |
43 |
44 | Supported inputs
45 |
46 |
47 |
48 |
49 |
50 | -
51 |
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 | Saved Colors
60 |
61 |
62 |
-
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | icons/icon-16.png
4 | icons/icon-32.png
5 | icons/icon-64.png
6 | icons/icon-128.png
7 | icons/icon-512.png
8 | icons/others/close-fill.png
9 | icons/others/delete-bin-5-line.png
10 | icons/others/error-warning-line.png
11 | icons/others/eye-line.png
12 | icons/others/file-copy-line.png
13 | icons/others/file-text-line.png
14 | icons/others/file-unknow-line.png
15 | icons/others/folder-open-line.png
16 | icons/others/information-line.png
17 | icons/others/links-line.png
18 | icons/others/link-unlink-m.png
19 | icons/others/paypal-line.png
20 | icons/others/star-line.png
21 | html/jtm/jquery.tinymodal.css
22 | html/jtm/jquery.tinymodal.js
23 | html/toastr/toastr.min.css
24 | html/toastr/toastr.min.js
25 | html/favicon.ico
26 | html/icon-128.png
27 | html/icon-64.png
28 | html/index.js
29 | html/jquery-3.5.1.min.js
30 | html/texture.png
31 | html/v2/app.0f8e8639.js
32 | html/v2/app.9d39357a.css
33 | html/v2/bootstrap.min.css
34 | html/v2/chunk-vendors.4a7ab7d0.js
35 | html/v2.html
36 | icons/icon-256.png
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/supportedinputs.cpp:
--------------------------------------------------------------------------------
1 | #include "supportedinputs.h"
2 | #include "ui_supportedinputs.h"
3 |
4 | SupportedInputs::SupportedInputs(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::SupportedInputs)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | SupportedInputs::~SupportedInputs()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/src/supportedinputs.h:
--------------------------------------------------------------------------------
1 | #ifndef SUPPORTEDINPUTS_H
2 | #define SUPPORTEDINPUTS_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class SupportedInputs;
8 | }
9 |
10 | class SupportedInputs : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit SupportedInputs(QWidget *parent = nullptr);
16 | ~SupportedInputs();
17 |
18 | private:
19 | Ui::SupportedInputs *ui;
20 | };
21 |
22 | #endif // SUPPORTEDINPUTS_H
23 |
--------------------------------------------------------------------------------
/src/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILS_H
2 | #define UTILS_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 |
13 | class utils : public QObject
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | utils(QObject* parent=0);
19 | virtual ~utils();
20 | public slots:
21 | static bool splitString(const QString &str, int m, QStringList &list);
22 | static QString refreshCacheSize(const QString cache_dir);
23 | bool delete_cache(const QString cache_dir);
24 | static QString toCamelCase(const QString &s);
25 | static QString upperFirstChar(const QString &s);
26 | static QString generateRandomId(int length);
27 | static QString convertSectoDay(qint64 secs);
28 | static QString returnPath(QString pathname);
29 | static QString randomIpV6();
30 |
31 |
32 | static QString EncodeXML ( const QString& encodeMe ){
33 |
34 | QString temp;
35 | int length = encodeMe.size();
36 | for (int index = 0; index < length; index++)
37 | {
38 | QChar character(encodeMe.at(index));
39 |
40 | switch (character.unicode())
41 | {
42 | case '&':
43 | temp += "&"; break;
44 |
45 | case '\'':
46 | temp += "'"; break;
47 |
48 | case '"':
49 | temp += """; break;
50 |
51 | case '<':
52 | temp += "<"; break;
53 |
54 | case '>':
55 | temp += ">"; break;
56 |
57 | default:
58 | temp += character;
59 | break;
60 | }
61 | }
62 |
63 | return temp;
64 | }
65 |
66 | static QString DecodeXML ( const QString& decodeMe ) {
67 |
68 | QString temp(decodeMe);
69 |
70 | temp.replace("&", "&");
71 | temp.replace("'", "'");
72 | temp.replace(""", "\"");
73 | temp.replace("<", "<");
74 | temp.replace(">", ">");
75 |
76 | return temp;
77 | }
78 |
79 | static QString htmlToPlainText(QString str);
80 | static QString removeNodeColor(QString input);
81 | static QString humanReadableSize(double bytes);
82 | static bool isMedia(QString filename); //both video or audio
83 | static bool isVideo(QString filename);
84 | static bool isAudio(QString filename);
85 | static bool isImage(QString filename);
86 | static QString cleanString(QString input);
87 | static QString genRand(int length);
88 | static void saveJson(QJsonDocument document, QString fileName);
89 | static QJsonDocument loadJson(QString fileName);
90 |
91 |
92 |
93 | private slots:
94 | //use refreshCacheSize
95 | static quint64 dir_size(const QString &directory);
96 |
97 | };
98 |
99 | #endif // UTILS_H
100 |
--------------------------------------------------------------------------------