[Kde-games-devel] Fix double-click bug in GameScene code of KMahjongg

Ian Wadham iandw.au at gmail.com
Sat Dec 19 22:26:29 UTC 2015


On 19/12/2015, at 9:28 PM, Frederik Schwarzer wrote:

> Am Samstag, 19. Dezember 2015, 15:20:13 schrieb Ian Wadham:
> 
> Hi Ian,
> 
>> There is a really nasty bug in the QGrapicsView code of KMahjongg,
>> in the GameScene class (frameworks branch).
>> 
>> If you double-click on a tile that cannot be removed (ie. it is half
>> under another tile or has a tile on each side), the forbidden tile
>> highlights.  It is then possible to remove that tile illegally by
>> clicking on a matching tile somewhere else.
> 
> Interesting easter egg. :D
> But seriously, I cannot reproduce this here and thought that main.cpp 
> would catch such a thing with this line:
> 63     // We don't use double-clicks. Set the interval to 0ms to 
> prevent them being triggered.
> 64     app.setDoubleClickInterval(0);

Remove those two lines from main.cpp and you will see your "egg".

> Don't you have that in your branch?

Hmmm… Yes, I do.  I had not noticed those lines before...

But they are clearly ineffective on Apple OS X (which does not use X11 any
more) and potentially dangerous on other platforms (they might eliminate
double clicks on ALL running apps).

The QApplication doco on this method is a bit ambiguous, see:
    Qt 4 - http://doc.qt.io/qt-4.8/qapplication.html#doubleClickInterval-prop
    Qt 5 - http://doc.qt.io/qt-5/qapplication.html#doubleClickInterval-prop

Those two lines in KMahjongg's main.cpp are part of a commit to the
qgraphic branch:
    https://quickgit.kde.org/?p=kmahjongg.git&a=history&h=08ff6c36e8385aa0f2d9d4e07a64614d7f935431&f=main.cpp
    https://quickgit.kde.org/?p=kmahjongg.git&a=commitdiff&h=e31e8942b72782fdbbd084021286353a0bf9dee6

As you will see in the second link, the commit deleted the existing code
for mouseDoubleClickEvent(), rather than fixing it…  My first stab at code
for that event was similar, but got the wrong result (select tile followed by
de-select tile, i.e. the normal effect of two separate clicks).

Swallowing the mouseDoubleClickEvent() is the way to go.  That way a
double-click or a shaky-handed bouncy click will always be treated as a
single click in KMahjongg.

So, please remove those two lines from main.cpp and use my patch for
KMahjongg's GameScene class files.

Cheers, Ian W.



More information about the kde-games-devel mailing list