[PE] Add gridlines presets for inch metric

This commit is contained in:
Julia Radzhabova 2022-10-03 21:22:51 +03:00
parent b9d8d1ee8a
commit 621fe72930
6 changed files with 156 additions and 72 deletions

View file

@ -411,10 +411,11 @@ var metrics = new(function() {
return me.defaultMetric;
},
fnRecalcToMM: function(value) {
fnRecalcToMM: function(value, fromMetric) {
// value in pt/cm/inch. need to convert to mm
var metric = (fromMetric!==undefined) ? fromMetric : me.currentMetric;
if (value!==null && value!==undefined) {
switch (me.currentMetric) {
switch (metric) {
case me.c_MetricUnits.cm:
return value * 10;
case me.c_MetricUnits.pt:
@ -426,9 +427,10 @@ var metrics = new(function() {
return value;
},
fnRecalcFromMM: function(value) {
fnRecalcFromMM: function(value, toMetric) {
// value in mm. need to convert to pt/cm/inch
switch (me.currentMetric) {
var metric = (toMetric!==undefined) ? toMetric : me.currentMetric;
switch (metric) {
case me.c_MetricUnits.cm:
return parseFloat((value/10.).toFixed(4));
case me.c_MetricUnits.pt:

View file

@ -60,10 +60,12 @@ define([
onLaunch: function () {
this._state = {
zoom_type: undefined,
zoom_percent: undefined
zoom_percent: undefined,
unitsChanged: true
};
Common.NotificationCenter.on('uitheme:changed', this.onThemeChanged.bind(this));
Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this));
Common.NotificationCenter.on('settings:unitschanged', _.bind(this.unitsChanged, this));
},
setApi: function (api) {
@ -286,7 +288,9 @@ define([
},
onGridlinesSpacing: function(value) {
this.api.asc_setGridSpacing(value * 360000);
value = Common.Utils.Metric.fnRecalcToMM(value,
Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? Common.Utils.Metric.c_MetricUnits.inch : Common.Utils.Metric.c_MetricUnits.cm);
this.api.asc_setGridSpacing(value * 36000);
Common.NotificationCenter.trigger('edit:complete', this.view);
},
@ -297,7 +301,9 @@ define([
handler: function(dlg, result) {
if (result == 'ok') {
props = dlg.getSettings();
me.api.asc_setGridSpacing(props * 360000);
props = Common.Utils.Metric.fnRecalcToMM(props,
Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? Common.Utils.Metric.c_MetricUnits.inch : Common.Utils.Metric.c_MetricUnits.cm);
me.api.asc_setGridSpacing(props * 36000);
Common.NotificationCenter.trigger('edit:complete', me.view);
}
}
@ -308,12 +314,27 @@ define([
onGridlinesAfterShow: function() {
if (this.view) {
this.view.btnGridlines.menu.items[0].setChecked(this.api.asc_getShowGridlines(), true);
this.view.btnGridlines.menu.items[1].setChecked(this.api.asc_getSnapToGrid(), true);
var menu = this.view.btnGridlines.menu;
if (this._state.unitsChanged) {
for (var i = 3; i < menu.items.length-2; i++) {
menu.removeItem(menu.items[i]);
i--;
}
var arr = (Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch) ? this.view._arrGlidlinesInch : this.view._arrGlidlinesCm;
for (var i = 0; i < arr.length; i++) {
var menuItem = new Common.UI.MenuItem(arr[i]);
menu.insertItem(3+i, menuItem);
}
this._state.unitsChanged = false;
}
var value = this.api.asc_getGridSpacing()/360000,
items = this.view.btnGridlines.menu.items;
for (var i=3; i<14; i++) {
menu.items[0].setChecked(this.api.asc_getShowGridlines(), true);
menu.items[1].setChecked(this.api.asc_getSnapToGrid(), true);
var value = Common.Utils.Metric.fnRecalcFromMM(this.api.asc_getGridSpacing()/36000,
Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? Common.Utils.Metric.c_MetricUnits.inch : Common.Utils.Metric.c_MetricUnits.cm),
items = menu.items;
for (var i=3; i<items.length-2; i++) {
var item = items[i];
if (item.value<1 && Math.abs(item.value - value)<0.005)
item.setChecked(true);
@ -323,6 +344,10 @@ define([
item.setChecked(false);
}
}
},
unitsChanged: function(m) {
this._state.unitsChanged = true;
}
}, PE.Controllers.ViewTab || {}));

View file

@ -63,8 +63,10 @@ define([
me._currentParaObjDisabled = false;
me._currentSpellObj = undefined;
me._currLang = {};
me._state = {};
me._state = {unitsChanged: true};
me._isDisabled = false;
Common.NotificationCenter.on('settings:unitschanged', _.bind(this.unitsChanged, this));
},
render: function () {
@ -976,6 +978,33 @@ define([
})
});
me._arrGlidlinesCm = [
{ caption: '1/8 ' + me.textCm, value: 0.13, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/6 ' + me.textCm, value: 0.17, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/5 ' + me.textCm, value: 0.2, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/4 ' + me.textCm, value: 0.25, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/3 ' + me.textCm, value: 0.33, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/2 ' + me.textCm, value: 0.5, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1 ' + me.textCm, value: 1, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '2 ' + me.textCm, value: 2, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '3 ' + me.textCm, value: 3, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '4 ' + me.textCm, value: 4, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '5 ' + me.textCm, value: 5, checkable: true, toggleGroup: 'mnu-gridlines' }
];
me._arrGlidlinesInch = [
{ caption: '1/24 \"', value: 0.04, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/16 \"', value: 0.06, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/12 \"', value: 0.08, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/10 \"', value: 0.1, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/8 \"', value: 0.13, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/6 \"', value: 0.17, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/5 \"', value: 0.2, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/4 \"', value: 0.25, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/3 \"', value: 0.33, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1/2 \"', value: 0.5, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '1 \"', value: 1, checkable: true, toggleGroup: 'mnu-gridlines' },
{ caption: '2 \"', value: 2, checkable: true, toggleGroup: 'mnu-gridlines' }
];
me.mnuGridlines = new Common.UI.MenuItem({
caption : me.textGridlines,
menu : new Common.UI.Menu({
@ -984,17 +1013,6 @@ define([
{ caption: me.textShowGridlines, value: 'show', checkable: true },
{ caption: me.textSnapObjects, value: 'snap', checkable: true },
{ caption: '--'},
{ caption: Common.Utils.String.format(me.textManyGrids, 8), value: 0.13, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textManyGrids, 6), value: 0.17, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textManyGrids, 5), value: 0.2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 4), value: 0.25, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 3), value: 0.33, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 2), value: 0.5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1 ' + me.textCm, value: 1, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '2 ' + me.textCm, value: 2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '3 ' + me.textCm, value: 3, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '4 ' + me.textCm, value: 4, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '5 ' + me.textCm, value: 5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '--'},
{ caption: me.textCustom, value: 'custom' }
]
@ -1048,9 +1066,23 @@ define([
me.mnuGridlines.menu.items[0].setChecked(me.api.asc_getShowGridlines(), true);
me.mnuGridlines.menu.items[1].setChecked(me.api.asc_getSnapToGrid(), true);
var spacing = me.api.asc_getGridSpacing()/360000,
var spacing = Common.Utils.Metric.fnRecalcFromMM(me.api.asc_getGridSpacing()/36000,
Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? Common.Utils.Metric.c_MetricUnits.inch : Common.Utils.Metric.c_MetricUnits.cm),
items = me.mnuGridlines.menu.items;
for (var i=3; i<14; i++) {
if (me._state.unitsChanged) {
for (var i = 3; i < items.length-2; i++) {
me.mnuGridlines.menu.removeItem(items[i]);
i--;
}
var arr = (Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch) ? me._arrGlidlinesInch : me._arrGlidlinesCm;
for (var i = 0; i < arr.length; i++) {
var menuItem = new Common.UI.MenuItem(arr[i]);
me.mnuGridlines.menu.insertItem(3+i, menuItem);
}
me._state.unitsChanged = false;
}
for (var i=3; i<items.length-2; i++) {
var item = items[i];
if (item.value<1 && Math.abs(item.value - spacing)<0.005)
item.setChecked(true);
@ -2342,6 +2374,10 @@ define([
}
},
unitsChanged: function(m) {
this._state.unitsChanged = true;
},
SetDisabled: function(state) {
this._isDisabled = state;
},
@ -2541,8 +2577,6 @@ define([
textSnapObjects: 'Snap Object to Grid',
textCm: 'cm',
textCustom: 'Custom',
textManyGrids: '{0} grids per cm',
textFewGrids: '{0} grids per cm',
textRulers: 'Rulers',
textDeleteGuide: 'Delete Guide'

View file

@ -46,7 +46,7 @@ define([
PE.Views.GridSettings = Common.UI.Window.extend(_.extend({
options: {
width: 315,
width: 214,
header: true,
style: 'min-width: 315px;',
cls: 'modal-dlg',
@ -60,10 +60,12 @@ define([
}, options || {});
this.template = [
'<div class="box" style="height: 30px;">',
'<label class="input-label">' + this.textSpacing + '</label>',
'<div id="grid-spacing-combo" class="input-group-nr" style="display: inline-block;width:125px;margin-left: 5px;"></div>',
'<div id="grid-spacing-spin" style="display: inline-block;margin-left: 5px;"></div>',
'<div class="box" style="height: 55px;">',
'<div class="input-row">',
'<label class="text">' + this.textSpacing + '</label>',
'</div>',
'<div id="grid-spacing-combo" class="input-group-nr" style="display: inline-block;width:86px;"></div>',
'<div id="grid-spacing-spin" style="display: inline-block;margin-left: 10px;"></div>',
'</div>',
'<div class="separator horizontal"></div>'
].join('');
@ -77,13 +79,27 @@ define([
Common.UI.Window.prototype.render.call(this);
var $window = this.getChild();
this.arrSpacing = [
{ displayValue: Common.Utils.String.format(this.textManyGrids, 8), value: 0, spacing: 0.13 },
{ displayValue: Common.Utils.String.format(this.textManyGrids, 6), value: 1, spacing: 0.17 },
{ displayValue: Common.Utils.String.format(this.textManyGrids, 5), value: 2, spacing: 0.2 },
{ displayValue: Common.Utils.String.format(this.textFewGrids, 4), value: 3, spacing: 0.25 },
{ displayValue: Common.Utils.String.format(this.textFewGrids, 3), value: 4, spacing: 0.33 },
{ displayValue: Common.Utils.String.format(this.textFewGrids, 2), value: 5, spacing: 0.5 },
this.arrSpacing = (Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch) ? [
{ displayValue: '1/24 \"', value: 0, spacing: 0.04 },
{ displayValue: '1/16 \"', value: 1, spacing: 0.06 },
{ displayValue: '1/12 \"', value: 2, spacing: 0.08 },
{ displayValue: '1/10 \"', value: 3, spacing: 0.1 },
{ displayValue: '1/8 \"', value: 4, spacing: 0.13 },
{ displayValue: '1/6 \"', value: 5, spacing: 0.17 },
{ displayValue: '1/5 \"', value: 6, spacing: 0.2 },
{ displayValue: '1/4 \"', value: 7, spacing: 0.25 },
{ displayValue: '1/3 \"', value: 8, spacing: 0.33 },
{ displayValue: '1/2 \"', value: 9, spacing: 0.5 },
{ displayValue: '1 \"', value: 10, spacing: 1 },
{ displayValue: '2 \"', value: 11, spacing: 2 },
{ displayValue: this.textCustom, value: -1 }
] : [
{ displayValue: '1/8 ' + this.textCm, value: 0, spacing: 0.13 },
{ displayValue: '1/6 ' + this.textCm, value: 1, spacing: 0.17 },
{ displayValue: '1/5 ' + this.textCm, value: 2, spacing: 0.2 },
{ displayValue: '1/4 ' + this.textCm, value: 3, spacing: 0.25 },
{ displayValue: '1/3 ' + this.textCm, value: 4, spacing: 0.33 },
{ displayValue: '1/2 ' + this.textCm, value: 5, spacing: 0.5 },
{ displayValue: '1 ' + this.textCm, value: 6, spacing: 1 },
{ displayValue: '2 ' + this.textCm, value: 7, spacing: 2 },
{ displayValue: '3 ' + this.textCm, value: 8, spacing: 3 },
@ -95,7 +111,7 @@ define([
el: $window.find('#grid-spacing-combo'),
cls: 'input-group-nr',
style: 'width: 100%;',
menuStyle: 'min-width: 125px;max-height: 185px;',
menuStyle: 'min-width: 86px;max-height: 185px;',
editable: false,
takeFocusOnClose: true,
data: this.arrSpacing
@ -110,11 +126,11 @@ define([
this.spnSpacing = new Common.UI.MetricSpinner({
el: $window.find('#grid-spacing-spin'),
step: .01,
width: 70,
defaultUnit : "cm",
value: '1 cm',
maxValue: 5.08,
minValue: 0.1
width: 86,
defaultUnit : Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? "\"": "cm",
value: Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? "1 \"" : '1 cm',
maxValue: Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? 2 : 5.08,
minValue: Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? 0.04 : 0.1
});
this.spnSpacing.on('change', _.bind(function(field, newValue, oldValue, eOpts){
var value = this.spnSpacing.getNumberValue(),
@ -158,14 +174,15 @@ define([
},
setSettings: function (value) {
value = value/360000;
value = Common.Utils.Metric.fnRecalcFromMM(value/36000,
Common.Utils.Metric.getCurrentMetric() === Common.Utils.Metric.c_MetricUnits.inch ? Common.Utils.Metric.c_MetricUnits.inch : Common.Utils.Metric.c_MetricUnits.cm);
var idx = -1;
for (var i=0; i<this.arrSpacing.length; i++) {
var item = this.arrSpacing[i];
if (item.spacing<1 && Math.abs(item.spacing - value)<0.005 || item.spacing>=1 && Math.abs(item.spacing - value)<0.001)
idx = i;
}
this.cmbGridSpacing.setValue(idx, true);
this.cmbGridSpacing.setValue(idx, -1);
this.spnSpacing.setValue(value, true);
},
@ -176,8 +193,6 @@ define([
textTitle: 'Grid Settings',
textSpacing: 'Spacing',
textCm: 'cm',
textCustom: 'Custom',
textManyGrids: '{0} grids per cm',
textFewGrids: '{0} grids per cm'
textCustom: 'Custom'
}, PE.Views.GridSettings || {}))
});

View file

@ -355,23 +355,39 @@ define([
]
}));
me._arrGlidlinesCm = [
{ caption: '1/8 ' + me.textCm, value: 0.13, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/6 ' + me.textCm, value: 0.17, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/5 ' + me.textCm, value: 0.2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/4 ' + me.textCm, value: 0.25, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/3 ' + me.textCm, value: 0.33, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/2 ' + me.textCm, value: 0.5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1 ' + me.textCm, value: 1, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '2 ' + me.textCm, value: 2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '3 ' + me.textCm, value: 3, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '4 ' + me.textCm, value: 4, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '5 ' + me.textCm, value: 5, checkable: true, toggleGroup: 'tb-gridlines' }
];
me._arrGlidlinesInch = [
{ caption: '1/24 \"', value: 0.04, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/16 \"', value: 0.06, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/12 \"', value: 0.08, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/10 \"', value: 0.1, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/8 \"', value: 0.13, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/6 \"', value: 0.17, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/5 \"', value: 0.2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/4 \"', value: 0.25, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/3 \"', value: 0.33, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1/2 \"', value: 0.5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1 \"', value: 1, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '2 \"', value: 2, checkable: true, toggleGroup: 'tb-gridlines' }
];
me.btnGridlines.setMenu( new Common.UI.Menu({
restoreHeight: true,
items: [
{ caption: me.textShowGridlines, value: 'show', checkable: true },
{ caption: me.textSnapObjects, value: 'snap', checkable: true },
{ caption: '--'},
{ caption: Common.Utils.String.format(me.textManyGrids, 8), value: 0.13, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textManyGrids, 6), value: 0.17, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textManyGrids, 5), value: 0.2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 4), value: 0.25, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 3), value: 0.33, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: Common.Utils.String.format(me.textFewGrids, 2), value: 0.5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '1 ' + me.textCm, value: 1, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '2 ' + me.textCm, value: 2, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '3 ' + me.textCm, value: 3, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '4 ' + me.textCm, value: 4, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '5 ' + me.textCm, value: 5, checkable: true, toggleGroup: 'tb-gridlines' },
{ caption: '--'},
{ caption: me.textCustom, value: 'custom' }
]
@ -482,9 +498,7 @@ define([
textShowGridlines: 'Show Gridlines',
textSnapObjects: 'Snap Object to Grid',
textCm: 'cm',
textCustom: 'Custom',
textManyGrids: '{0} grids per cm',
textFewGrids: '{0} grids per cm'
textCustom: 'Custom'
}
}()), PE.Views.ViewTab || {}));

View file

@ -1625,8 +1625,6 @@
"PE.Views.DocumentHolder.textSnapObjects": "Snap Object to Grid",
"PE.Views.DocumentHolder.textCm": "cm",
"PE.Views.DocumentHolder.textCustom": "Custom",
"PE.Views.DocumentHolder.textManyGrids": "{0} grids per cm",
"PE.Views.DocumentHolder.textFewGrids": "{0} grids per cm",
"PE.Views.DocumentHolder.textRulers": "Rulers",
"PE.Views.DocumentHolder.textDeleteGuide": "Delete Guide",
"PE.Views.DocumentPreview.goToSlideText": "Go to Slide",
@ -1748,8 +1746,6 @@
"PE.Views.GridSettings.textSpacing": "Spacing",
"PE.Views.GridSettings.textCm": "cm",
"PE.Views.GridSettings.textCustom": "Custom",
"PE.Views.GridSettings.textManyGrids": "{0} grids per cm",
"PE.Views.GridSettings.textFewGrids": "{0} grids per cm",
"PE.Views.HeaderFooterDialog.applyAllText": "Apply to all",
"PE.Views.HeaderFooterDialog.applyText": "Apply",
"PE.Views.HeaderFooterDialog.diffLanguage": "You cant use a date format in a different language than the slide master.<br>To change the master, click 'Apply to all' instead of 'Apply'",
@ -2444,7 +2440,5 @@
"PE.Views.ViewTab.textShowGridlines": "Show Gridlines",
"PE.Views.ViewTab.textSnapObjects": "Snap Object to Grid",
"PE.Views.ViewTab.textCm": "cm",
"PE.Views.ViewTab.textCustom": "Custom",
"PE.Views.ViewTab.textManyGrids": "{0} grids per cm",
"PE.Views.ViewTab.textFewGrids": "{0} grids per cm"
"PE.Views.ViewTab.textCustom": "Custom"
}