From 0b849e76b65751144720785e8656f985e01ea90b Mon Sep 17 00:00:00 2001 From: Julia Svinareva Date: Thu, 17 Oct 2019 12:00:35 +0300 Subject: [PATCH] Gradient slider (add new color) --- .../main/lib/component/MultiSliderGradient.js | 10 +++++++ apps/common/main/lib/component/Slider.js | 26 ++++++++++++++++--- .../main/app/view/ShapeSettings.js | 5 ++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/apps/common/main/lib/component/MultiSliderGradient.js b/apps/common/main/lib/component/MultiSliderGradient.js index 8ad11eaff..5f79042fb 100644 --- a/apps/common/main/lib/component/MultiSliderGradient.js +++ b/apps/common/main/lib/component/MultiSliderGradient.js @@ -159,6 +159,16 @@ define([ me.changeSliderStyle(); }, + addNewThumb: function(index, lastIndex, color) { + var me = this; + me.thumbs[index].thumb.on('dblclick', null, function() { + me.trigger('thumbdblclick', me); + }); + me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> div'); + (index>0) && this.setColorValue(this.getColorValue(lastIndex), index); + me.changeSliderStyle(); + }, + removeThumb: function(index) { if (index===undefined) index = this.thumbs.length-1; if (index>0) { diff --git a/apps/common/main/lib/component/Slider.js b/apps/common/main/lib/component/Slider.js index 0ee059b7e..ba49e37cd 100644 --- a/apps/common/main/lib/component/Slider.js +++ b/apps/common/main/lib/component/Slider.js @@ -403,7 +403,26 @@ define([ $(document).on('mousemove', null, e.data, me.binding.onMouseMove); }; - var onTrackMouseDown = function (e) { + var onTrackMouseUp = function (e) { + if ( me.disabled ) return; + + var pos = Math.max(0, Math.min(100, (Math.round((e.pageX*Common.Utils.zoom() - me.cmpEl.offset().left) / me.width * 100)))), + lastIndex = findThumb(pos), + thumbColor = me.thumbs[lastIndex].colorValue, + lastValue = me.thumbs[lastIndex].value, + value = pos/me.delta + me.minValue; + me.addThumb(); + var newIndex = me.thumbs.length - 1; + me.setThumbPosition(newIndex, pos); + me.thumbs[newIndex].value = value; + me.trigger('addthumb', me, newIndex, lastIndex, thumbColor); + + me.sortThumbs(); + + me.trigger('change', me); + }; + + /*var onTrackMouseDown = function (e) { if ( me.disabled ) return; var pos = Math.max(0, Math.min(100, (Math.round((e.pageX*Common.Utils.zoom() - me.cmpEl.offset().left) / me.width * 100)))), @@ -416,7 +435,7 @@ define([ me.trigger('change', me, value, lastValue); me.trigger('changecomplete', me, value, lastValue); - }; + };*/ var findThumb = function(pos) { var nearest = 100, @@ -462,7 +481,8 @@ define([ me.setActiveThumb(0, true); if (!me.rendered) { - el.on('mousedown', '.track', onTrackMouseDown); + /*el.on('mousedown', '.track', onTrackMouseDown);*/ + el.on('mouseup', '.track', onTrackMouseUp); } me.rendered = true; diff --git a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js index 2a5281b4a..a3f54b70c 100644 --- a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js +++ b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js @@ -1293,6 +1293,11 @@ define([ me.GradColor.colors = colors; me.GradColor.currentIdx = currentIdx; }); + this.sldrGradient.on('addthumb', function(cmp, index, lastIndex, color){ + me.GradColor.currentIdx = index; + + me.sldrGradient.addNewThumb(index, lastIndex, color); + }); this.fillControls.push(this.sldrGradient); this.cmbBorderSize = new Common.UI.ComboBorderSizeEditable({