Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private/gokay/impress grid #10147

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1a1bb24
draw: Added GridVisible and GridUse commands
hfiguiere Dec 5, 2023
4cc4c67
Move show-grid and use-grid commands to view tab.
gokaysatir Sep 24, 2024
4d4a643
Refactor documentStatus function.
gokaysatir Sep 30, 2024
76afef1
Add docstate functions for Calc.
gokaysatir Oct 1, 2024
e0f3e29
Use more docstate functions in Calc.
gokaysatir Oct 1, 2024
9629af6
Use status JSON instead of text.
gokaysatir Oct 1, 2024
7357db9
Fetch pagerectangles as array.
gokaysatir Oct 1, 2024
3926665
Writer: Use JSON instead of text message.
gokaysatir Oct 1, 2024
c96a8d3
Use statusJSON for Impress.
gokaysatir Oct 2, 2024
ce04800
Read initial state of grid visibility and snapping to grid features.
gokaysatir Oct 3, 2024
cffe785
Visually show the snapped grid point when grid-snapping is enabled.
gokaysatir Oct 5, 2024
86f1a0d
Various improvements.
gokaysatir Oct 7, 2024
b242574
Modify UnitInsertDelete test to use json objects instead of text.
gokaysatir Oct 7, 2024
850e4cc
Remove unnecessary update calls.
gokaysatir Oct 7, 2024
26b2373
Write mode into document status message before sending.
gokaysatir Oct 7, 2024
563d627
Refactor reading status and statusupdate message on ClientSession.
gokaysatir Oct 7, 2024
2f21fed
Update TileCacheTests for using Json object as status message.
gokaysatir Oct 7, 2024
fe1ea1d
Modify UnitLoadTorture.cpp for JSON.
gokaysatir Oct 7, 2024
9aaa9ac
Impress mobile: Ensure to get correct element on drag start.
gokaysatir Oct 9, 2024
810d230
Refactor snap-to-grid feature.
gokaysatir Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions browser/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,8 @@ button.leaflet-control-search-next
.w2ui-icon.freezepanescolumn{ background: url('images/lc_freezepanescolumn.svg') no-repeat center; }
.w2ui-icon.freezepanesrow{ background: url('images/lc_freezepanesrow.svg') no-repeat center; }
.w2ui-icon.navigator{ background: url('images/lc_navigator.svg') no-repeat center; }
.w2ui-icon.gridvisible{ background: url('images/lc_gridvisible.svg') no-repeat center; }
.w2ui-icon.griduse{ background: url('images/lc_griduse.svg') no-repeat center; }

.w2ui-icon.flipvertical { background: url('images/lc_flipvertical.svg') no-repeat center; }
.w2ui-icon.fliphorizontal { background: url('images/lc_fliphorizontal.svg') no-repeat center; }
Expand Down
1 change: 1 addition & 0 deletions browser/images/dark/lc_griduse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions browser/images/dark/lc_gridvisible.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions browser/images/lc_griduse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions browser/images/lc_gridvisible.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions browser/src/app/GraphicSelectionMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ class GraphicSelection {
// When a shape is selected, the rectangles of other shapes are also sent from the core side.
// They are in twips units.
static convertObjectRectangleTwipsToPixels() {
const correction = 0.567; // Correction for impress case.

if (this.extraInfo && this.extraInfo.ObjectRectangles) {
for (let i = 0; i < this.extraInfo.ObjectRectangles.length; i++) {
for (let j = 0; j < 4; j++)
this.extraInfo.ObjectRectangles[i][j] *=
app.twipsToPixels * correction;
app.twipsToPixels * app.impress.twipsCorrection;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion browser/src/canvas/sections/CellCursorSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CellCursorSection extends CanvasSectionObject {
}

let x: number = 0;
if (app.isCalcRTL()) {
if (app.calc.isRTL()) {
const rightMost = this.containerObject.getDocumentAnchor()[0] + this.containerObject.getDocumentAnchorSection().size[0];
x = rightMost - penX * 2 - app.calc.cellCursorRectangle.pWidth;
}
Expand Down
4 changes: 2 additions & 2 deletions browser/src/canvas/sections/CommentListSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
private adjustCommentFileBasedView (comment: any): void {
// Below calculations are the same with the ones we do while drawing tiles in fileBasedView.
var partHeightTwips = this.sectionProperties.docLayer._partHeightTwips + this.sectionProperties.docLayer._spaceBetweenParts;
var index = app.impress.partHashes.indexOf(String(comment.parthash));
var index = app.impress.getIndexFromSlideHash(comment.parthash);
var yAddition = index * partHeightTwips;
comment.yAddition = yAddition; // We'll use this while we save the new position of the comment.

Expand Down Expand Up @@ -1747,7 +1747,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {

if (selectedComment) {
const posX = (this.sectionProperties.showSelectedBigger ?
Math.round((document.getElementById('document-container').getBoundingClientRect().width - subList[i].sectionProperties.container.getBoundingClientRect().width)/2) :
Math.round((document.getElementById('document-container').getBoundingClientRect().width - subList[i].sectionProperties.container.getBoundingClientRect().width)/2) :
Math.round(actualPosition[0] / app.dpiScale) - this.sectionProperties.deflectionOfSelectedComment * (isRTL ? -1 : 1));
(new L.PosAnimation()).run(subList[i].sectionProperties.container, {x: posX, y: Math.round(lastY / app.dpiScale)}, this.getAnimationDuration());
}
Expand Down
4 changes: 2 additions & 2 deletions browser/src/canvas/sections/CommentSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Comment extends CanvasSectionObject {

if (this.sectionProperties.docLayer._docType === 'presentation' || this.sectionProperties.docLayer._docType === 'drawing') {
this.sectionProperties.parthash = this.sectionProperties.data.parthash;
this.sectionProperties.partIndex = app.impress.partHashes.indexOf(String(this.sectionProperties.parthash));
this.sectionProperties.partIndex = app.impress.getIndexFromSlideHash(this.sectionProperties.parthash);
}

this.sectionProperties.isHighlighted = false;
Expand Down Expand Up @@ -693,7 +693,7 @@ export class Comment extends CanvasSectionObject {
}),
draggable: true
});
if (app.impress.partHashes[this.sectionProperties.docLayer._selectedPart] === this.sectionProperties.data.parthash || app.file.fileBasedView)
if (app.impress.partList[this.sectionProperties.docLayer._selectedPart].hash === parseInt(this.sectionProperties.data.parthash) || app.file.fileBasedView)
this.map.addLayer(this.sectionProperties.annotationMarker);
}
if (this.sectionProperties.data.rectangle != null) {
Expand Down
5 changes: 4 additions & 1 deletion browser/src/canvas/sections/ShapeHandleScalingSubSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ class ShapeHandleScalingSubSection extends CanvasSectionObject {
e.stopPropagation();
this.sectionProperties.parentHandlerSection.sectionProperties.svg.style.opacity = 0.5;
this.moveHandlesOnDrag(point);
this.sectionProperties.parentHandlerSection.checkObjectsBoundaries([this.position[0]], [this.position[1]]);

// Here we are checking a point, so the size 0. dragDistance is also 0 because we already set the new position (moveHandlesOnDrag).
this.sectionProperties.parentHandlerSection.checkHelperLinesAndSnapPoints([0, 0], this.position, [0, 0]);

this.containerObject.requestReDraw();
this.sectionProperties.parentHandlerSection.showSVG();
}
Expand Down
108 changes: 102 additions & 6 deletions browser/src/canvas/sections/ShapeHandlesSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,108 @@ class ShapeHandlesSection extends CanvasSectionObject {
else this.sectionProperties.closestY = null;
}

private cloneSelectedPartInfoForGridSnap() {
const selectedPart = Object.assign({}, app.impress.partList[app.map._docLayer._selectedPart]);
selectedPart.leftBorder *= app.impress.twipsCorrection;
selectedPart.upperBorder *= app.impress.twipsCorrection;
selectedPart.rightBorder *= app.impress.twipsCorrection;
selectedPart.lowerBorder *= app.impress.twipsCorrection;
selectedPart.gridCoarseWidth *= app.impress.twipsCorrection;
selectedPart.gridCoarseHeight *= app.impress.twipsCorrection;

return selectedPart;
}

private getInnerRecrangleForGridSnap(selectedPart: any) {
return new cool.SimpleRectangle(
selectedPart.leftBorder,
selectedPart.upperBorder,
(selectedPart.width - selectedPart.leftBorder - selectedPart.rightBorder),
(selectedPart.height - selectedPart.upperBorder - selectedPart.lowerBorder)
);
}

private getCornerPointsForGridSnap(size: number[], position: number[], dragDistance: number[]) {
return [
new cool.SimplePoint((position[0] + dragDistance[0]) * app.pixelsToTwips, (position[1] + dragDistance[1]) * app.pixelsToTwips),
new cool.SimplePoint((size[0] + position[0] + dragDistance[0]) * app.pixelsToTwips, (position[1] + dragDistance[1]) * app.pixelsToTwips),
new cool.SimplePoint((position[0] + dragDistance[0]) * app.pixelsToTwips, (size[1] + position[1] + dragDistance[1]) * app.pixelsToTwips),
new cool.SimplePoint((size[0] + position[0] + dragDistance[0]) * app.pixelsToTwips, (size[1] + position[1] + dragDistance[1]) * app.pixelsToTwips),
];
}

private findClosestGridPoint(size: number[], position: number[], dragDistance: number[]) {
// First rule of snap-to-grid: If you enable snap-to-grid, you have to snap.

const selectedPart = this.cloneSelectedPartInfoForGridSnap();

// The 4 corners of selected object's rectangle.
const checkList = this.getCornerPointsForGridSnap(size, position, dragDistance);

// The rectangle that is shaped by the page margins.
const innerRectangle = this.getInnerRecrangleForGridSnap(selectedPart);

const gapX = selectedPart.gridCoarseWidth / (selectedPart.innerSpacesX > 0 ? selectedPart.innerSpacesX : 1);
const gapY = selectedPart.gridCoarseHeight / (selectedPart.innerSpacesY > 0 ? selectedPart.innerSpacesY : 1);

let minX = 100000;
let minY = 100000;
for (let i = 0; i < 1; i++) {
if (innerRectangle.containsPoint(checkList[i].toArray())) {

const countX = Math.round((checkList[i].x - innerRectangle.x1) / gapX);
const countY = Math.round((checkList[i].y - innerRectangle.y1) / gapY);

const diffX = Math.abs(checkList[i].x - innerRectangle.x1 - gapX * countX);
const diffY = Math.abs(checkList[i].y - innerRectangle.y1 - gapY * countY);

if (diffX < minX) {
minX = diffX;
this.sectionProperties.closestX = innerRectangle.x1 + (countX * gapX);
this.sectionProperties.pickedIndexX = [1, 3].includes(i) ? 0 : 1; // Do we substract width or not.
}
if (diffY < minY) {
minY = diffY;
this.sectionProperties.closestY = innerRectangle.y1 + (countY * gapY);
this.sectionProperties.pickedIndexY = [2, 3].includes(i) ? 0 : 1; // Do we substract height or not.
}
}
}

this.sectionProperties.closestX *= app.twipsToPixels;
this.sectionProperties.closestY *= app.twipsToPixels;
}

public checkObjectsBoundaries(xListToCheck: number[], yListToCheck: number[]) {
if (app.map._docLayer._docType === 'presentation') {
this.findClosestX(xListToCheck);
this.findClosestY(yListToCheck);
this.containerObject.requestReDraw();
}
}

public checkHelperLinesAndSnapPoints(size: number[], position: number[], dragDistance: number[]) {
/*
We will first check if grid-snap is enabled and if we are close to a grid point.
If there is a grid point to snap to, then we'll ignore helper lines.
Because core side doesn't know about our helper lines, and it'll ignore them if it can snap to a grid point.
*/

this.sectionProperties.closestX = null;
this.sectionProperties.closestY = null;

if (app.map.stateChangeHandler.getItemValue('.uno:GridUse') === 'true') {
this.findClosestGridPoint(size, position, dragDistance)
}
else {
this.checkObjectsBoundaries(
[position[0] + dragDistance[0], position[0] + dragDistance[0] + size[0]],
[position[1] + dragDistance[1], position[1] + dragDistance[1] + size[1]]
);
}

this.containerObject.requestReDraw();
}

onMouseMove(position: number[], dragDistance: number[]) {
if (this.containerObject.isDraggingSomething() && this.sectionProperties.svg) {
(window as any).IgnorePanning = true;
Expand All @@ -767,10 +861,7 @@ class ShapeHandlesSection extends CanvasSectionObject {
this.sectionProperties.svg.style.top = String((this.myTopLeft[1] + dragDistance[1]) / app.dpiScale) + 'px';
this.sectionProperties.svg.style.opacity = 0.5;
this.sectionProperties.lastDragDistance = [dragDistance[0], dragDistance[1]];
this.checkObjectsBoundaries(
[this.position[0] + dragDistance[0], this.position[0] + dragDistance[0] + this.size[0]],
[this.position[1] + dragDistance[1], this.position[1] + dragDistance[1] + this.size[1]]
);
this.checkHelperLinesAndSnapPoints(this.size, this.position, dragDistance);

this.showSVG();
}
Expand Down Expand Up @@ -874,10 +965,15 @@ class ShapeHandlesSection extends CanvasSectionObject {
this.context.restore();
}

private anythingToDraw(): boolean {
return this.sectionProperties.closestX !== null ||
this.sectionProperties.closestY !== null;
}

public onDraw() {
if (!this.showSection || !this.isVisible)
this.hideSVG();
else if (this.sectionProperties.closestX !== null || this.sectionProperties.closestY !== null) {
else if (this.anythingToDraw()) {
this.drawGuides();
}
}
Expand Down
10 changes: 8 additions & 2 deletions browser/src/control/Control.Menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ L.Control.Menubar = L.Control.extend({
{name: _UNO('.uno:ZoomMinus', 'presentation'), id: 'zoomout', type: 'action'},
{name: _('Reset zoom'), id: 'zoomreset', type: 'action'},
]).concat([
{type: 'separator'},
{uno: '.uno:GridVisible', name: _UNO('.uno:GridVisible')},
{uno: '.uno:GridUse', name: _UNO('.uno:GridUse')},
{type: 'separator'},
{name: _('Toggle UI Mode'), id: 'toggleuimode', type: 'action'},
{name: _('Show Ruler'), id: 'showruler', type: 'action'},
Expand Down Expand Up @@ -594,6 +597,9 @@ L.Control.Menubar = L.Control.extend({
{name: _UNO('.uno:ZoomMinus', 'presentation'), id: 'zoomout', type: 'action'},
{name: _('Reset zoom'), id: 'zoomreset', type: 'action'},
]).concat([
{type: 'separator'},
{uno: '.uno:GridVisible', name: _UNO('.uno:GridVisible')},
{uno: '.uno:GridUse', name: _UNO('.uno:GridUse')},
{type: 'separator'},
{name: _('Toggle UI Mode'), id: 'toggleuimode', type: 'action'},
{name: _('Dark Mode'), id: 'toggledarktheme', type: 'action'},
Expand Down Expand Up @@ -1789,12 +1795,12 @@ L.Control.Menubar = L.Control.extend({
$(aItem).text(_('Use Tabbed view'));
}
} else if (id === 'showslide') {
if (!self._map._docLayer.isHiddenSlide(self._map.getCurrentPartNumber()))
if (!app.impress.isSlideHidden(self._map.getCurrentPartNumber()))
$(aItem).hide();
else
$(aItem).show();
} else if (id === 'hideslide') {
if (self._map._docLayer.isHiddenSlide(self._map.getCurrentPartNumber()))
if (app.impress.isSlideHidden(self._map.getCurrentPartNumber()))
$(aItem).hide();
else
$(aItem).show();
Expand Down
4 changes: 2 additions & 2 deletions browser/src/control/Control.Notebookbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ L.Control.Notebookbar = L.Control.extend({
},

onSlideHideToggle: function() {
if (!this.map._docLayer.isHiddenSlide(this.map.getCurrentPartNumber()))
if (!app.impress.isSlideHidden(this.map.getCurrentPartNumber()))
$('#showslide').hide();
else
$('#showslide').show();

if (this.map._docLayer.isHiddenSlide(this.map.getCurrentPartNumber()))
if (app.impress.isSlideHidden(this.map.getCurrentPartNumber()))
$('#hideslide').hide();
else
$('#hideslide').show();
Expand Down
1 change: 0 additions & 1 deletion browser/src/control/Control.NotebookbarBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ L.Control.NotebookbarBuilder = L.Control.JSDialogBuilder.extend({

/*Draw Home Tab*/
this._toolitemHandlers['.uno:ObjectAlign'] = function() {};
this._toolitemHandlers['.uno:GridVisible'] = function() {};

/*Graphic Tab*/
this._toolitemHandlers['.uno:Crop'] = function() {};
Expand Down
20 changes: 20 additions & 0 deletions browser/src/control/Control.NotebookbarDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,26 @@ L.Control.NotebookbarDraw = L.Control.NotebookbarImpress.extend({
'text': _('Collapse Tabs'),
'accessibility': { focusBack: true, combination: 'CU', de: null }
},
{
'type': 'toolbox',
'children': [
{
'id': 'home-grid-visible',
'type': 'toolitem',
'text': _UNO('.uno:GridVisible'),
'command': '.uno:GridVisible',
'accessibility': { focusBack: true, combination: 'GV', de: null }
},
{
'id': 'home-grid-use',
'type': 'toolitem',
'text': _UNO('.uno:GridUse'),
'command': '.uno:GridUse',
'accessibility': { focusBack: true, combination: 'GU', de: null }
}
],
'vertical': 'true'
},
{
'id':'toggledarktheme',
'type': 'bigcustomtoolitem',
Expand Down
20 changes: 20 additions & 0 deletions browser/src/control/Control.NotebookbarImpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,26 @@ L.Control.NotebookbarImpress = L.Control.NotebookbarWriter.extend({
'command': '.uno:SlideMasterPage',
'accessibility': { focusBack: true, combination: 'MP', de: null }
},
{
'type': 'toolbox',
'children': [
{
'id': 'home-grid-visible',
'type': 'toolitem',
'text': _('Show Grid'),
'command': '.uno:GridVisible',
'accessibility': { focusBack: true, combination: 'GV', de: null }
},
{
'id': 'home-grid-use',
'type': 'toolitem',
'text': _('Snap to Grid'),
'command': '.uno:GridUse',
'accessibility': { focusBack: true, combination: 'GU', de: null }
}
],
'vertical': 'true'
},
{
'id':'toggledarktheme',
'class': 'unotoggledarktheme',
Expand Down
Loading
Loading