Recent

Author Topic: Zoom the content of a TsWorksheetGrid [SOLVED]  (Read 9738 times)

totya

  • Hero Member
  • *****
  • Posts: 720
Zoom the content of a TsWorksheetGrid [SOLVED]
« on: September 25, 2016, 05:27:16 pm »
Hi!

I'd like to zoom the  TsWorksheetGrid (like as excel), similar of this:

http://delphi.xcjc.net/viewthread.php?tid=44368

This code working partially here, because cells width and height changed, but font size doesn't.

Any idea?

Tahnks!
« Last Edit: September 27, 2016, 04:58:43 pm by totya »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid
« Reply #1 on: September 25, 2016, 06:11:39 pm »
The problem with this code is that the worksheet grid's main storage of column widths and row heights is in the worksheet; therefore, your grid-only changes are volatile and can be reverted on some unexpected occasions. A "true" zoom would only introduce a zoom factor in the worksheet, and the grid would calculate its column widths, row heights, font heights, image sizes etc from the values stored in the worksheet multiplied by this zoom factor. It will not be difficult but quite some work to get it running...

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid
« Reply #2 on: September 25, 2016, 07:12:32 pm »
Hi!

Thank you for the answer! :)

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid [MAYBE LATER]
« Reply #3 on: September 27, 2016, 12:43:27 am »
r5218 supports zooming of the worksheet grid. Just set a value to the new property ZoomFactor, unzoomed state has it at 1.0 (so, note that it's not a percentage scale!). Or run the demo in folder fpsctrls, here you can use the MouseWheel together with SHIFT+CTRL pressed (I had to use the combination because the grid ancestor already occupies the CTRL key for horizontal and the SHIFT key for vertical scrolling by the mousewheel).

There may still be some bugs there and here: One of them is that the header cells do not zoom, I could not yet find the knob to turn. And the focused cell moves out of the viewport in case of large zoom factors. If you find other bugs please report them.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [MAYBE LATER]
« Reply #4 on: September 27, 2016, 01:03:05 am »
Hi!

Very thanks for your job! :)

But I revert to the older revision, because when I opened my "top secret" :) file, the first few lines are disappear (first few rows height are 0 I think). I didn't use zoom factor, only I recompiled my app with latest revision of fps.

Luckily,  fpsgrid_no_install example works similar, the output is bad, as you can see.

Thank you!
« Last Edit: September 27, 2016, 01:08:18 am by totya »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid [UNDER DEVELOPING]
« Reply #5 on: September 27, 2016, 10:26:42 am »
The "top-secret file" is the one you posted in http://forum.lazarus.freepascal.org/index.php/topic,34150.msg223047.html#msg223047? It is loaded correctly here.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [UNDER DEVELOPING]
« Reply #6 on: September 27, 2016, 10:28:31 am »
The "top-secret file" is the one you posted in http://forum.lazarus.freepascal.org/index.php/topic,34150.msg223047.html#msg223047? It is loaded correctly here.

Hi!

See the  fpsgrid_no_install example as I wrote in my last message in this topic.

And I'm sorry, I'm wrong, I wrote my "top secret" file really, but this is the "real" top secret file, this is not the sample file.
« Last Edit: September 27, 2016, 11:21:47 am by totya »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid [UNDER DEVELOPING]
« Reply #7 on: September 27, 2016, 03:28:15 pm »
Which version was the last one which was working? I'd like to understand what went wrong here.

Anyway, the current r5221 should be correct.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #8 on: September 27, 2016, 05:01:21 pm »
Hi!

Now these files displayed correctly, and this function works perfectly as I tested.

Very thank you for this new function!

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #9 on: September 27, 2016, 05:56:57 pm »
Hi, I found a bug in this new function, very similar of the SST problem.

See sample file from here: http://forum.lazarus.freepascal.org/index.php/topic,34150.msg223047.html#msg223047

As you can see, the zoom only partial.

You can test it with fpsctrls examples (shift-ctrl and mouse scroll), or use new ZoomFactor property.

Thanks!

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #10 on: September 27, 2016, 08:09:10 pm »
Ah. Missed this font size in the rich-text cells... Fixed in r5224

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #11 on: September 27, 2016, 08:35:27 pm »
Confirmed, zoom is working now with files what I tested.

Thanks again for this new function!

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #12 on: September 28, 2016, 12:17:11 am »
Hi!

Small remark, ZoomFactor will reset if I open file from Grid.

I see this in the all load methods, for example:

Code: Pascal  [Select][+][-]
  1. procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
  2.   AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
  3. begin
  4.   ZoomFactor := 1.0;
  5.   GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormat, AWorksheetIndex);
  6. end;
  7.  

or

Code: Pascal  [Select][+][-]
  1. procedure TsCustomWorksheetGrid.LoadFromWorkbook(AWorkbook: TsWorkbook;
  2.   AWorksheetIndex: Integer = -1);
  3. begin
  4.   ZoomFactor := 1.0;
  5.   GetWorkbookSource.LoadFromWorkbook(AWorkbook, AWorksheetIndex);
  6.   Invalidate;
  7. end;
  8.  
  9.  

But if I store the ZoomFactor settings, after file loaded, I need to set ZoomFactor (again). But this is ugly and slow, because Grid appear two times with different ZoomFactor...

I suggest the KeepZoomFactorAfterLoad property... or ResetZoomFactorAfterLoad or similar solution...

Thanks! :)

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #13 on: September 28, 2016, 01:09:46 am »
For BIFF8 and BIFF5 files, the zoom factor is now read from the file and written back to it. XLSX and ODS will follow soon. I also commented the reset of the zoomfactor in the grid, it does not seem to be needed - let's see...

When writing your demo file (test_distorted_view, test_newfile) I get the warning that it contains 257 columns, but only 256 are supported; the file is written correctly, though. That's one of the things to be fixed... You said that they are created by Excel, didn't you?

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Zoom the content of a TsWorksheetGrid [SOLVED]
« Reply #14 on: September 28, 2016, 01:58:07 am »
Hi!

Thanks for the answer, and your job,  but now I need go to sleep :)

Yes these files created by the excel.

But I play with it. If I copy only the 3 column from the test_distorted_view.xls to the new file, name is test_distorted_view_copy.xls, then GetLastColIndex(true) +1 say, this file contain only three column, this is okay.

If I create new file with Excel 2003 with 3 column and 1 row, then GetLastColIndex(true) +1 say, this file contain only three column...

See attached files.

Elsewhere, I like it the new save load/zoom factor, but I want to use own zoom factor, which independent from the files, please don't ask me why. So, now I'd like to DoNotReadZoomFactorFromFile property really.


 

TinyPortal © 2005-2018