QTfrontend/ui/mouseoverfilter.cpp
author sheepluva
Sat, 28 Apr 2012 09:25:30 +0200
changeset 6946 576c453822bf
parent 6930 d187ea93fc4f
child 8049 133e22b5c410
permissions -rw-r--r--
fix for issue #186 ("Screen gets messed up when selecting Hand Drawn Map")
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
     1
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
     2
#include <QEvent>
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
     3
#include <QWidget>
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
     4
#include <QStackedLayout>
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
     5
#include <QLabel>
6584
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
     6
#include <QLineEdit>
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
     7
#include <QCheckBox>
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
     8
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
     9
#include "mouseoverfilter.h"
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    10
#include "ui/page/AbstractPage.h"
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    11
#include "ui_hwform.h"
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    12
#include "hwform.h"
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    13
#include "gameuiconfig.h"
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6616
diff changeset
    14
#include "DataManager.h"
6584
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    15
#include "SDLInteraction.h"
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    16
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    17
MouseOverFilter::MouseOverFilter(QObject *parent) :
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    18
    QObject(parent)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    19
{
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    20
}
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    21
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    22
bool MouseOverFilter::eventFilter( QObject *dist, QEvent *event )
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    23
{
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    24
    if (event->type() == QEvent::Enter)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    25
    {
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    26
        QWidget * widget = dynamic_cast<QWidget*>(dist);
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    27
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    28
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    29
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    30
        if (widget->whatsThis() != NULL)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    31
            abstractpage->setButtonDescription(widget->whatsThis());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    32
        else if (widget->toolTip() != NULL)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    33
            abstractpage->setButtonDescription(widget->toolTip());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    34
6584
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    35
        // play a sound when mouse hovers certain ui elements
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    36
        QPushButton * button = dynamic_cast<QPushButton*>(dist);
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    37
        QLineEdit * textfield = dynamic_cast<QLineEdit*>(dist);
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    38
        QCheckBox * checkbox = dynamic_cast<QCheckBox*>(dist);
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    39
        QComboBox * droplist = dynamic_cast<QComboBox*>(dist);
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    40
        QSlider * slider = dynamic_cast<QSlider*>(dist);
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    41
        QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6584
diff changeset
    42
        if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6584
diff changeset
    43
        {
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6616
diff changeset
    44
            DataManager & dataMgr = DataManager::instance();
6584
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    45
            SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/steps.ogg"));
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    46
        }
5bb48450b978 simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
koda
parents: 6477
diff changeset
    47
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    48
        return true;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    49
    }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    50
    else if (event->type() == QEvent::Leave)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    51
    {
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    52
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    53
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    54
        if (abstractpage->getDefautDescription() != NULL)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    55
        {
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    56
            abstractpage->setButtonDescription( * abstractpage->getDefautDescription());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    57
        }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    58
        else
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    59
            abstractpage->setButtonDescription("");
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    60
    }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    61
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    62
    return false;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    63
}
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    64
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    65
void MouseOverFilter::setUi(Ui_HWForm *uiForm)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    66
{
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    67
    ui = uiForm;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    68
}