[Kde-games-devel] KMahjongg frameworks branch
Ian Wadham
iandw.au at gmail.com
Mon Nov 30 03:57:13 UTC 2015
Hi Frederik,
On 30/11/2015, at 11:36 AM, Frederik Schwarzer wrote:
> since you are familiar with the QGraphics stuff...
> When I removed KDELibs4Support (some functionality just commented out
> so not ready for business) QGraphicsScene broke.
> itemAt(qreal, qreal)
> is now deprecated, so I had to use
> itemAt(qreal, qreal, const QTransform&)
> and I do not know how to use this properly.
The doco makes no sense to me. What "view" is "the" view? In
principle, QGraphicsScene can have any number of views… But
AFAIK each KDE Game has only one QGraphicsView per
QGraphicsScene, even Palapeli, which can have multiple
scenes but each has its own (single) view --- so the point is moot.
> Now I just added QTransform() as the third parameter and it seems to
> work.
I think the view and the scene in KMahjongg are using the same (pixel-based)
co-ordinates and 1:1 scale. A lot of the games do. Some qDebug()'s in
GameScene::mousePressEvent() indicate that KMahjongg does too.
QTransform() gets you the Identity transform and matrix (i.e. no change in scale,
orientation, etc.), so it should be harmless in KMahjongg.
> Although, if this had been a no-brainer for the Qt devs, it
> would have become a default parameter, I guess.
Perhaps, but not all apps would use 1:1 scale between the view and scene. At one
stage, a few years ago, I had KGoldrunner's scene using four co-ordinate points
per tile (as in the model and game engine) versus ~20 pixels per tile in the view,
but it all came unstuck when I started to put text items in the view.
> So I would like to hear your opinion on this. This overload exists in Qt 4.8
> so you should be able to play around with it.
>
> diff --git a/GameScene.cpp b/GameScene.cpp
> index 39d7743..f1cf2dd 100644
> --- a/GameScene.cpp
> +++ b/GameScene.cpp
> @@ -191,7 +191,7 @@ bool GameScene::isSelectable(const GameItem *
> const pGameItem) const
> void GameScene::mousePressEvent(QGraphicsSceneMouseEvent *
> pMouseEvent)
> {
> GameItem * pGameItem = dynamic_cast <GameItem
> *>(itemAt(pMouseEvent->scenePos().x(),
> - pMouseEvent->scenePos().y()));
> + pMouseEvent->scenePos().y(), QTransform()));
>
> // No item was clicked.
> if (pGameItem != NULL) {
> @@ -200,7 +200,7 @@ void
> GameScene::mousePressEvent(QGraphicsSceneMouseEvent * pMouseEvent)
> if (pGameItem->isShadow(pMouseEvent->scenePos() - pGameItem-
>> pos())) {
> pGameItem = dynamic_cast <GameItem *>(itemAt(pMouseEvent-
>> scenePos().x() +
> pGameItem->getShadowDeltaX(), pMouseEvent-
>> scenePos().y() +
> - pGameItem->getShadowDeltaY()));
> + pGameItem->getShadowDeltaY(), QTransform()));
> }
> }
The above code works for me --- in KDE 4.14 and Qt 4.8.
The acid test is whether pointing with the mouse and clicking on tiles
(or shadows next to tiles), using the above code, will always select the
right tile to move.
Cheers, Ian W.
More information about the kde-games-devel
mailing list