[KJots] Revive printing support
ClosedPublic

Authored by poboiko on Apr 21 2020, 11:01 AM.

Details

Summary

Removed custom code inside KJotsWidget::print, which did the pagination and painting:
QTextDocument::print() is quite capable of it on its own.
Make Qt also responsible for margins, document placement, etc.

Make QPrintPreviewDialog actually work: it requires to connect to paintRequested signal.
For this purpose, made KJotsWidget::print a slot.

Unify QPrinter creation code, add a setupPrinter method for this purpose.
Note: HighResolution property was removed, as it results in weird-looking bold fonts.

Test Plan
  1. Print Preview works again
  2. Try to select some text and press Print Preview -> it previews selection only
  3. Print also works (tried only virtual PDF printer though)

Diff Detail

Repository
R573 KJots
Branch
printing
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 25592
Build 25610: arc lint + arc unit
poboiko requested review of this revision.Apr 21 2020, 11:01 AM
poboiko created this revision.

By "weird-looking bold fonts" (HighResolution) I mean this:


It gets better as I zoom in:

Probably a Qt issue?

Printing this weird-looking stuff to PDF looks good though.
So I can probably use HighResolution for actual printing and ScreenResolution for a preview?

dvratil requested changes to this revision.Apr 21 2020, 11:28 AM
dvratil added inline comments.
src/kjotswidget.cpp
1119

If your intention is for the caller to own the QPrinter object, std::unique_ptr is a better choice.

This revision now requires changes to proceed.Apr 21 2020, 11:28 AM
poboiko updated this revision to Diff 80755.Apr 21 2020, 11:55 AM

Use unique_ptr instead of QSharedPointer.

Provide setupPrinter with QPrinter::PrinterMode, so HighResolution is used for printing and ScreenResolution is used for preview.

Restricted Application added a project: KDE PIM. · View Herald TranscriptApr 21 2020, 11:55 AM
poboiko updated this revision to Diff 80756.Apr 21 2020, 12:02 PM

Rebase on master

dvratil requested changes to this revision.Apr 21 2020, 2:26 PM
dvratil added inline comments.
src/kjotswidget.cpp
1121

You want to make this a unique_ptr already so the QPrinter gets destroyed in case an exception is thrown in one of the lines above (which it won't, Qt doesn't throw, but you know - good practices :)), or an early return is implemented in this method later on.

It's OK to bump required C++ to 14 or even 17 so you can use make_unique

auto printer = std::make_unique<QPrinter>(mode);

This revision now requires changes to proceed.Apr 21 2020, 2:26 PM
poboiko updated this revision to Diff 80786.Apr 21 2020, 4:30 PM

Use make_unique, bump CXX version to 14

dvratil accepted this revision.Apr 21 2020, 6:59 PM

Thanks!

This revision is now accepted and ready to land.Apr 21 2020, 6:59 PM
This revision was automatically updated to reflect the committed changes.