QTfrontend/ui/mouseoverfilter.cpp
author unc0rr
Thu, 01 Nov 2012 14:31:53 +0400
branch0.9.18
changeset 7916 be11c26a3a0b
parent 6930 d187ea93fc4f
child 8049 133e22b5c410
permissions -rw-r--r--
Fix 0.9.18 desync: CreateNetGame() slot creates signal-slot connections from hwnet to hwgame. The problem is that this slot is called asynchronously using queued connection, and hwnet could send some signals to hwgame before hwgame object is created and connected. Changed this to direct connection. Also changed connections to hwgame object to queued, but this is unrelated. Sorry, it is frontend patch. Maybe a little delay on server side could help, but not much, as tcp packets could get glued on client's side, and that greately depends on pc and internet connection performance. Frontend should be reworked to be safe for queued connections, as it is extemely dangerous to have a mix of queued/direct connections.


#include <QEvent>
#include <QWidget>
#include <QStackedLayout>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>

#include "mouseoverfilter.h"
#include "ui/page/AbstractPage.h"
#include "ui_hwform.h"
#include "hwform.h"
#include "gameuiconfig.h"
#include "DataManager.h"
#include "SDLInteraction.h"

MouseOverFilter::MouseOverFilter(QObject *parent) :
    QObject(parent)
{
}

bool MouseOverFilter::eventFilter( QObject *dist, QEvent *event )
{
    if (event->type() == QEvent::Enter)
    {
        QWidget * widget = dynamic_cast<QWidget*>(dist);

        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());

        if (widget->whatsThis() != NULL)
            abstractpage->setButtonDescription(widget->whatsThis());
        else if (widget->toolTip() != NULL)
            abstractpage->setButtonDescription(widget->toolTip());

        // play a sound when mouse hovers certain ui elements
        QPushButton * button = dynamic_cast<QPushButton*>(dist);
        QLineEdit * textfield = dynamic_cast<QLineEdit*>(dist);
        QCheckBox * checkbox = dynamic_cast<QCheckBox*>(dist);
        QComboBox * droplist = dynamic_cast<QComboBox*>(dist);
        QSlider * slider = dynamic_cast<QSlider*>(dist);
        QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
        if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab))
        {
            DataManager & dataMgr = DataManager::instance();
            SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/steps.ogg"));
        }

        return true;
    }
    else if (event->type() == QEvent::Leave)
    {
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());

        if (abstractpage->getDefautDescription() != NULL)
        {
            abstractpage->setButtonDescription( * abstractpage->getDefautDescription());
        }
        else
            abstractpage->setButtonDescription("");
    }

    return false;
}

void MouseOverFilter::setUi(Ui_HWForm *uiForm)
{
    ui = uiForm;
}