When QGraphicsView is not flexible enough
April 5, 2010
Last week, when I added rubberband selection to Palapeli, I sacrificed the “Clicking with left mouse button moves viewport” option because it conflicts with the rubberband. Knowing that more mouse actions are yet to be added, I needed a scalable solution. I found inspiration in Plasma’s ContainmentActions:
The idea for Palapeli: Separate the triggers (mouse buttons or mouse wheel orientations, and keyboard modifiers) from the actions (e.g. move piece, zoom viewport, resize scene). This was essentially what I have implemented over the last two days. This is not visible because there is no nice configuration interface such as the one shown above yet, but you can already change the hard-coded triggers in src/engine/interactormanager.cpp.
The only problem with this new approach is that I have to bypass QGraphicsView’s mouse event handlers nearly completely.
Besides that, I have greatly improved the speed of puzzle loading, and the rendering performance for big puzzles. When pieces snap together, their pixmaps are combined into one, so only one pixmap needs to be drawn. Again, this change is not visible, though I hope you notice it. 🙂
The only visible change is the new look of what is called “ConstraintVisualizer” internally: The size of the puzzle table can be changed by dragging its edges. In Palapeli 1.0, the only way to discover this feature is to notice that the mouse cursor changes into double-headed arrows near the puzzle table edges. The area where this interaction is possible is now visible as a transparent dark shade.