The Good, The Bad, And The Ugly

I promised an update on printing and here it is.

The Good

Just to recap, the branch at http://qt.gitorious.org/~odysseus/qt/odysseus-clone/commits/advanced-page-selection contains the Advanced Page Selection features such as Current Page, Odd/Even Pages, Server Side page selection, and non-continuous Page Ranges.  The status of this is that it's API complete with just some polishing work required in the Unix dialog, although there are a couple of implementation details I'm reconsidering as being too ugly.

My next step was to add in support for file printing which you can find at http://qt.gitorious.org/~odysseus/qt/odysseus-clone/commits/print-from-file.  This is useful for applications such as Okular where they have a high quality source file and don't want to paint it onto a QPainter (and possibly reduce the quality in the process) before printing it.  This is a simple API where the application passes in the name of the source file to be printed, and if the filetype is supported by the print system the file gets printed using the settings from the QPrinter (and thus anything the user selected in QPrintDialog).  Under CUPS you can print PDF, PS, TXT and various image formats while lpr will support just PS and TXT.  It's still a little hacky in places, such as the filetype detection, but it works.  And for the more observant of you, yes this will make a new kprinter utility a lot easier for someone to implement.

I've also made a start on adding all the available CUPS options into the Unix QPrintDialog.  At the moment KDE adds these as extra aplication-level tabs on the dialog, but they are poorly integrated, e.g. choosing 'Print to File' doesn't disable them.  The code for this is still very rough and so still rather ugly, but I've attached screenies below showing some options in a new Pages tab in the main dialog, with others in a new Job tab in the Properties dialog.  Yes it looks just like the current KDE stuff as I've recycled the code I wrote for that.  I must confess the more I try to mess with the QPrintDialog, the more tempted I am to re-write it from scratch, it shows obvious signs of cruft building up over years of having bits bolted on by several different people.

Qt Cups Options 1

Qt Cups Options 2

The Bad

Last time I mentioned that the Qt 4.6 feature freeze was looming.  Well in fact it had already long gone whizzing past with no-one much noticing, so sorry but these changes won't be in Qt 4.6 or KDE 4.4.  This whole open Qt development thing is very new and the processes aren't really in place for contributing features (as opposed to bug-fixes) and I guess there's a few lessons to be learnt along the way.  I should have been more pro-active in talking to the Trolls about the how and when, so lesson one is if you have a new feature grab your nearest passing troll and don't let go until they let you cross the bridge to graze in the summer pasture, er I mean until your stuff gets merged.  From the Qt side I guess there needs to be more structure and documentation around the steps developers need to follow to propose, design and develop new features, who do you talk to first, what are the release schedules and milestones you need to meet, and what you need to include (unit tests, cross-platform support, documentation, etc).

It has been suggested that my patches could be packaged into Qt4.6 by some distros, but this is not going to be possible as I cannot guarantee that the API/ABI will remain unchaged through the Qt review process, or even that they will be merged for Qt 4.7.

The Ugly

However all is not lost as I have been able to re-use some of what I've done to add Odd/Even pages and Server Side page selection for KDE 4.4 using CUPS.  Using a very very ugly hack, I've added the Odd/Even selection combo into the QPrintDialog and this gets passed through to CUPS if selected.  A less ugly hack has also added Server Side page selection where CUPS will select the page range when the application can't, i.e. Kate and Khtml and all apps that embed them (KMail, Konqi, KWrite, etc) can now print page ranges!  The main drawback is this only works under CUPS, and it doesn't intergate well, i.e. the Odd/Even combo doesn't disable when you choose 'Print to File' so we'll get plenty of bug reports that it doesn't work with 'Print to PDF'.  However I think the users need for this outways the shortcomings.  Also be warned that using them in conjunction with n-up will get unexpected results due to a quirk in CUPS where it applies the page selection to the sheets of paper and not the document pages.  Screenie below showing KWrite with Odd/Even selection added and Page Ranges restored.

KDE 4.4 Print Dialog

As an aside, I've been thinking about how to make kate and khtml support page ranges properly.  At the moment they just paint the whole document as they don't know where the page breaks will be until after they have actually painted the content onto each page.  Trying to calculate this in advance and to pick up the painting mid-stroke is I believe a very tricky proposition.  Instead, I was thinking we could have two identical QPrinter's, a dummy QPrinter onto which the first few unwanted pages are painted, then once the first required page is reached a second 'real' QPrinter onto which only the required pages are painted.  Not sure if it's feasible, but worth a crack? 

Of course, the obvious perfect cross-platform solution would be if QPrinter itself directly supported page selection, i.e. you paint all the pages onto QPrinter then tell it which ones to keep and it deletes the rest internally before passing the document to the native print system.  Something else to look into.

[Edit: fixed references to QPainter to be QPrinter] 

Exit

So, where to from here?  There's obviously going to be a bit of time now before these possibly make it into Qt 4.7 (whenever that may be), so I'm going to re-arrange my priorities.  We have the KDE 4.4 feature freeze coming up next month, so I'm going to focus for a bit on doing some Calendar and Locale related hacking for that.  Then for the Qt 4.6 release I need to work on some bug fixes for the current printing code.  After that, and depending on when 4.7 is rumoured to be released, I'll get back onto finishing off all the above and also trying to sort out the situation with saving settings between jobs.  And in-between all that, I need to get back in touch with the OpenPrinting guys to work out how KDE can help them in their quest to completely re-architect the way we do printing.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks!

John,
I just wanted to say: thanks for working on this!
In their enthousiasm to create new markets and bling-bling, companies and also the kde project sometimes forgets that it is the normal, day to day, mundane stuff that needs to work, and work reliably for people to be able to actually use their computer in a meaningful way.
Your work really helps!

Perhaps 2010 will become the year of the kde desktop, with complete printing options, (hopefully) network management, supported video cards and FINALLY a decent standard browser.

I can live with most of the

I can live with most of the missing special case stuff but I'm really getting desperate for the ability to save the settings.
Every time I go to print I have to change the margins and select duplex mode - if I forget I just have to visit re-print the job after making the changes.

Great work

Hi, thanks for working on this. The print dialogue definitely needs some love.
One option which I have missed recently is the option to print without scaling. That is, print at the actual 100% zoom level even if this means part of the image is clipped. The application for this is for printing technical drawings such as building plans which are marked as a certain scale eg. 1:500. If you print it out and the page is scaled to fit on the paper, then the drawing is no longer at 1:500.
Autocad etc. offer this. It would be cool if you could do it straight from okular!
Cheers,
Scott.

Thanks for the news, at

Thanks for the news, at least someone cares about it. However its still weird that this is not a priority for the qt guys.

Thanks!

Thank you John, great work!

QPrinter based page selection

Hej John,

shouldn't QPrinter support page selection and not QPainter?
The painting code looks something like that:

QPrinter printer;
QPainter p(&printer);

while (!document.atEnd()) {
p.draw(....);
max++;

// insert page break every 600px
if ((max%600) == 0)
printer.newPage();
}

So if you setup the page range via QPrintDialog before,
QPrinter knows which pages to skip on every newPage() call.

Yep, you'd be right there,

Yep, you'd be right there, QPrinter not QPainter, that's what you get for posting so late at night Embarassed

One more thank you note

As noted by the previous posters, thanks a lot for working on something that seems to be forgotten these days, as it doesn't include javascript, css, graphicsview, plasma, opengl, social networking or other cutting-edge attractive things :)
So, here's another big thank you, and keep up the good work, you can bet it won't go unnoticed, especially by normal users.

Thanks!

Finally a blog post about something really useful being done in KDE. Thank you for your work.

Saving settings

This is an extremely important part of KDE and deserves all the resources that can be thrown at it
I can live with most of the missing special case stuff but I'm really getting desperate for the ability to save the settings.
Every time I go to print I have to change the margins and select duplex mode - if I forget I just have to re-print the job after making the changes.
Is there a config file somewhere I can set these things by hand until there's a Save settings option?
Alan

Perfect

I really don't know why the Qt/KDE have so many super features when it is not able to print. It should be high priority for developers to do this. I hope that it will be in KDE as soon as possible. Thanks

very interesting

In case I fail to find some film or music, I use torrent search engines, because in torrents format one can find rather rare film

Tips for contributors

John,
I would love it if you posted some tips on what you've learned about contributing to QT. I would love to try and fix http://bugreports.qt.nokia.com/browse/QTBUG-6471 but it isn't clear what the best way to go about doing this would be. I suspect that the fix shouldn't be that hard but trying to figure out the process needed in order to take the right steps to contribute effectively seems daunting.

State of it

What is the state of the code? Any news about the time it gets integrated into Qt?

I can live with most of the

I can live with most of the missing special case stuff but I'm really getting desperate for the ability to save the settings.
Every time I go to print I have to change the margins and select duplex mode - if I forget I just have to re-print the link job after making the changes.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.