-
Notifications
You must be signed in to change notification settings - Fork 0
New Thumbnail Architecture
Thumbnail handling is currently quite complicated and scattered around many places. Board and Document keep their own thumbnails and it is a huge effort to synchronize them. This article describes the new architecture I'm currently implementing. The main ideas are:
- Use the same thumbnail items and the same thumbnail scene for Board and Document mode. Thumbnails are just rearranged depending on the mode.
- Create a
UBDocument
class for page handling. This class has functions for creating, deleting, moving and copying of pages. It takes care to call the proper functions on theUBPersistenceManager
and to manage the thumbnail items. All other code shall only use these functions. - Use a specific, concrete derived class of an abstract
UBThumbnailArranger
to handle the differences between Board and Document mode.
In the following I want to dig deeper into the architecture and structure of this effort.
The current implementation lacks a UBDocument
class. Therefore document handling is scattered around and often repeated at multiple places. We now create such a class, which lives in close companionship to the UBDocumentProxy
. The proxy however only keeps some information about the document, most important the path to the document folder. Proxies are lightweight and they exist for every document in the document
folder.
A UBDocument
instance is heavier and is created when a document is opened, i.e. either selected in Document mode or used as active document in Board mode.
- It provides functions to manipulate a document, i.e. to create or delete pages, to copy or move them. These functions use the
UBPersistenceMamnager
to do the necessary operations on disk, but also take care about the related thumbnails. - It owns a scene with the thumbnails of all pages of the document. See
UBThumbnailScene
below. - Instances of
UBDocument
can easily be created from theUBDocumentProxy
. - A caching mechanism outside of that class can be used to cache instances of this class, which makes switching between documents very fast.
This class is the scene on which all thumbnail items exist. It can create thumbnail items from the thumbnail files of a document or from a board scene. When creating a new UBDocument
instance, also the UBThumbnailScene
is created and loading of thumbnails from the files in the document is started in the background without blocking user interactions. This means that you can start working with (the first pages of) a document immediately, even if not all page thumbnails are loaded.
The same thumbnail scene can be attached to the Board thumbnail view and the Document thumbnail view, so both views share the same scene and thumbnails in both views are always synchronized.
The UBThumbnailScene
takes care of arranging the thumbnails depending on the currently visible view. See UBThumbnailArranger
below.
If UBDocument
is cached, then also the related thumbnail scene is cached allowing to switch to a cached document instantaneously.
The UBThumbnailItem
provides the graphic item representing a thumbnail. It is derived from QGraphicsRectItem
. The pixmap of the thumbnail and the caption text are attached as children of the thumbnail item. So to arrange thumbnails, we only have to take care of the rectangles and their position and spacing. The position of the pixmap and text within the thumbnail is handled within the thumbnail item.
This is an abstract class with two concrete derived classes for Document and Board mode. It provides information about the width of thumbnails, the margins and spacing and the arrangement in rows and columns. Instances of the concrete derived classes are attached to the UBBoardThumbnailsView
resp. UBDocumentThumbnailsView
.
When the UBThumbnailScene
is asked to arrange the thumbnails, it checks which view is currently visible and uses the thumbnail arranger attached to that class. Arranging 2000 thumbnails needs 50ms on my computer, so it is not a heavy task.
This tiny abstract class is now the base class for UBDocumentThumbnailsView
and UBBoardThumbnaisView
. It is responsible to hold an instance of the respective UBThumbnailArranger
for that view.