/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
Ext.define("PE.view.ShapeSettingsAdvanced", {
extend: "Ext.window.Window",
alias: "widget.peshapesettingsadvanced",
requires: ["Ext.form.field.ComboBox", "Ext.window.Window", "Ext.data.Model", "Ext.data.Store", "Ext.Array", "Ext.button.Button"],
cls: "asc-advanced-settings-window",
modal: true,
resizable: false,
plain: true,
constrain: true,
height: 340,
width: 516,
layout: {
type: "vbox",
align: "stretch"
},
initComponent: function () {
var me = this;
this.addEvents("onmodalresult");
this._originalProps = null;
this._changedProps = null;
this._beginSizeIdx = 0;
this._endSizeIdx = 0;
this._nRatio = 1;
this._spnWidth = Ext.create("Common.component.MetricSpinner", {
id: "shape-advanced-spin-width",
readOnly: false,
maxValue: 55.88,
minValue: 0,
step: 0.1,
defaultUnit: "cm",
value: "3 cm",
width: 100,
listeners: {
change: Ext.bind(function (field, newValue, oldValue, eOpts) {
if (this._btnRatio.pressed) {
var w = field.getNumberValue();
var h = w / this._nRatio;
if (h > this._spnHeight.maxValue) {
h = this._spnHeight.maxValue;
w = h * this._nRatio;
this._spnWidth.suspendEvents(false);
this._spnWidth.setValue(w);
this._spnWidth.resumeEvents();
}
this._spnHeight.suspendEvents(false);
this._spnHeight.setValue(h);
this._spnHeight.resumeEvents();
}
if (this._changedProps) {
this._changedProps.put_Width(Common.MetricSettings.fnRecalcToMM(field.getNumberValue()));
this._changedProps.put_Height(Common.MetricSettings.fnRecalcToMM(this._spnHeight.getNumberValue()));
}
},
this)
}
});
this._spnHeight = Ext.create("Common.component.MetricSpinner", {
id: "shape-advanced-span-height",
readOnly: false,
maxValue: 55.88,
minValue: 0,
step: 0.1,
defaultUnit: "cm",
value: "3 cm",
width: 100,
listeners: {
change: Ext.bind(function (field, newValue, oldValue, eOpts) {
var h = field.getNumberValue(),
w = null;
if (this._btnRatio.pressed) {
w = h * this._nRatio;
if (w > this._spnWidth.maxValue) {
w = this._spnWidth.maxValue;
h = w / this._nRatio;
this._spnHeight.suspendEvents(false);
this._spnHeight.setValue(h);
this._spnHeight.resumeEvents();
}
this._spnWidth.suspendEvents(false);
this._spnWidth.setValue(w);
this._spnWidth.resumeEvents();
}
if (this._changedProps) {
this._changedProps.put_Height(Common.MetricSettings.fnRecalcToMM(field.getNumberValue()));
this._changedProps.put_Width(Common.MetricSettings.fnRecalcToMM(this._spnWidth.getNumberValue()));
}
},
this)
}
});
this._btnRatio = Ext.create("Ext.Button", {
id: "shape-advanced-button-ratio",
iconCls: "advanced-btn-ratio",
enableToggle: true,
width: 22,
height: 22,
style: "margin: 0 0 0 6px;",
tooltip: this.textKeepRatio,
toggleHandler: Ext.bind(function (btn) {
if (btn.pressed && this._spnHeight.getNumberValue() > 0) {
this._nRatio = this._spnWidth.getNumberValue() / this._spnHeight.getNumberValue();
}
},
this)
});
this._arrCapType = [[c_oAscLineCapType.Flat, this.textFlat], [c_oAscLineCapType.Round, this.textRound], [c_oAscLineCapType.Square, this.textSquare]];
this.cmbCapType = Ext.create("Ext.form.field.ComboBox", {
id: "shape-advanced-cap-type",
width: 100,
editable: false,
store: this._arrCapType,
queryMode: "local",
triggerAction: "all",
listeners: {
select: Ext.bind(function (combo, records, eOpts) {
if (this._changedProps) {
if (this._changedProps.get_stroke() === null) {
this._changedProps.put_stroke(new CAscStroke());
}
this._changedProps.get_stroke().put_linecap(me._arrCapType[records[0].index][0]);
}
},
this)
}
});
this.cmbCapType.setValue(this._arrCapType[0][1]);
this._arrJoinType = [[c_oAscLineJoinType.Round, this.textRound], [c_oAscLineJoinType.Bevel, this.textBevel], [c_oAscLineJoinType.Miter, this.textMiter]];
this.cmbJoinType = Ext.create("Ext.form.field.ComboBox", {
id: "shape-advanced-join-type",
width: 100,
editable: false,
store: this._arrJoinType,
queryMode: "local",
triggerAction: "all",
listeners: {
select: Ext.bind(function (combo, records, eOpts) {
if (this._changedProps) {
if (this._changedProps.get_stroke() === null) {
this._changedProps.put_stroke(new CAscStroke());
}
this._changedProps.get_stroke().put_linejoin(me._arrJoinType[records[0].index][0]);
}
},
this)
}
});
this.cmbJoinType.setValue(this._arrJoinType[0][1]);
this.styleURL = "resources/img/right-panels/Begin-EndStyle.png";
this.styleURL2x = "resources/img/right-panels/Begin-EndStyle@2x.png";
var _arrStyles = [],
_arrSize = [];
var _styleTypes = [c_oAscLineBeginType.None, c_oAscLineBeginType.Triangle, c_oAscLineBeginType.Arrow, c_oAscLineBeginType.Stealth, c_oAscLineBeginType.Diamond, c_oAscLineBeginType.Oval];
var _sizeTypes = [c_oAscLineBeginSize.small_small, c_oAscLineBeginSize.small_mid, c_oAscLineBeginSize.small_large, c_oAscLineBeginSize.mid_small, c_oAscLineBeginSize.mid_mid, c_oAscLineBeginSize.mid_large, c_oAscLineBeginSize.large_small, c_oAscLineBeginSize.large_mid, c_oAscLineBeginSize.large_large];
for (var i = 0; i < 6; i++) {
var item = {
value: i,
imagewidth: 44,
imageheight: 20,
offsetx: 80 * i + 10,
offsety: 0
};
item.borderstyle = Ext.String.format("background:url({0}) {3}px {4}px; width:{1}px; height:{2}px; background-image: -webkit-image-set(url({0}) 1x, url({5}) 2x);", this.styleURL, item.imagewidth, item.imageheight, -item.offsetx, -item.offsety, this.styleURL2x);
_arrStyles.push(item);
}
_arrStyles[0].type = c_oAscLineBeginType.None;
_arrStyles[1].type = c_oAscLineBeginType.Triangle;
_arrStyles[2].type = c_oAscLineBeginType.Arrow;
_arrStyles[3].type = c_oAscLineBeginType.Stealth;
_arrStyles[4].type = c_oAscLineBeginType.Diamond;
_arrStyles[5].type = c_oAscLineBeginType.Oval;
for (i = 0; i < 9; i++) {
var item = {
value: i,
imagewidth: 44,
imageheight: 20,
offsetx: 80 + 10,
offsety: 20 * (i + 1)
};
item.borderstyle = Ext.String.format("background:url({0}) {3}px {4}px; width:{1}px; height:{2}px; background-image: -webkit-image-set(url({0}) 1x, url({5}) 2x);", this.styleURL, item.imagewidth, item.imageheight, -item.offsetx, -item.offsety, this.styleURL2x);
_arrSize.push(item);
}
_arrSize[0].type = c_oAscLineBeginSize.small_small;
_arrSize[1].type = c_oAscLineBeginSize.small_mid;
_arrSize[2].type = c_oAscLineBeginSize.small_large;
_arrSize[3].type = c_oAscLineBeginSize.mid_small;
_arrSize[4].type = c_oAscLineBeginSize.mid_mid;
_arrSize[5].type = c_oAscLineBeginSize.mid_large;
_arrSize[6].type = c_oAscLineBeginSize.large_small;
_arrSize[7].type = c_oAscLineBeginSize.large_mid;
_arrSize[8].type = c_oAscLineBeginSize.large_large;
var beginStyleStore = Ext.create("Ext.data.Store", {
model: "PE.model.ModelBorders",
data: _arrStyles
});
var beginSizeStore = Ext.create("Ext.data.Store", {
model: "PE.model.ModelBorders",
data: _arrSize
});
for (i = 0; i < _arrStyles.length; i++) {
var item = _arrStyles[i];
item.borderstyle = Ext.String.format("background:url({0}) {3}px {4}px; width:{1}px; height:{2}px; background-image: -webkit-image-set(url({0}) 1x, url({5}) 2x);", this.styleURL, item.imagewidth, item.imageheight, -item.offsetx, -(item.offsety + 200), this.styleURL2x);
}
for (i = 0; i < _arrSize.length; i++) {
var item = _arrSize[i];
item.borderstyle = Ext.String.format("background:url({0}) {3}px {4}px; width:{1}px; height:{2}px; background-image: -webkit-image-set(url({0}) 1x, url({5}) 2x);", this.styleURL, item.imagewidth, item.imageheight, -item.offsetx, -(item.offsety + 200), this.styleURL2x);
}
var endStyleStore = Ext.create("Ext.data.Store", {
model: "PE.model.ModelBorders",
data: _arrStyles
});
var endSizeStore = Ext.create("Ext.data.Store", {
model: "PE.model.ModelBorders",
data: _arrSize
});
this._updateSizeArr = function (sizecombo, record, type, sizeidx) {
var style = Ext.String.format("background:url({0}) repeat scroll 0 -1px", "resources/img/controls/text-bg.gif");
if (record.data.value > 0) {
for (var i = 0; i < _arrSize.length; i++) {
_arrSize[i].offsetx = record.data.value * 80 + 10;
_arrSize[i].borderstyle = Ext.String.format("background:url({0}) {3}px {4}px; width:{1}px; height:{2}px; background-image: -webkit-image-set(url({0}) 1x, url({5}) 2x);", me.styleURL, _arrSize[i].imagewidth, _arrSize[i].imageheight, -_arrSize[i].offsetx, -(_arrSize[i].offsety + 200 * type), this.styleURL2x);
}
sizecombo.menu.picker.store.loadData(_arrSize);
sizecombo.setDisabled(false);
if (sizeidx !== null) {
sizecombo.menu.picker.selectByIndex(sizeidx, true);
me._selectStyleItem(sizecombo, sizecombo.menu.picker.store.getAt(sizeidx), type);
} else {
Ext.DomHelper.applyStyles(sizecombo.btnEl, style);
}
} else {
Ext.DomHelper.applyStyles(sizecombo.btnEl, style);
sizecombo.setDisabled(true);
}
};
this._selectStyleItem = function (stylecombo, record, type) {
var style;
if (stylecombo.btnEl) {
style = Ext.String.format("background:url({0}) repeat scroll {1}px {2}px, url({3}) repeat scroll 0 -1px;", me.styleURL, -(record.data.offsetx - 20), -(record.data.offsety + 200 * type), "resources/img/controls/text-bg.gif");
style += Ext.String.format("background-image: -webkit-image-set(url({0}) 1x, url({1}) 2x), -webkit-image-set(url({2}) 1x, url({3}) 2x);", me.styleURL, me.styleURL2x, "resources/img/controls/text-bg.gif", "resources/img/controls/text-bg@2x.gif");
Ext.DomHelper.applyStyles(stylecombo.btnEl, style);
}
};
var endStyleTpl = Ext.create("Ext.XTemplate", '