QTfrontend/ui/mouseoverfilter.cpp
author nemo
Mon, 13 May 2013 14:10:51 -0400
changeset 8982 0c0141cf851a
parent 8801 c38ce9cf4c3a
child 9577 9577634bd284
permissions -rw-r--r--
Needs to reset net button, not toggle it.
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>
8729
b19be476a2fa Call steps on focus instead. fix typo
nemo
parents: 8326
diff changeset
     8
#include <QListView>
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
     9
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 "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
    11
#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
    12
#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
    13
#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
    14
#include "gameuiconfig.h"
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6616
diff changeset
    15
#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
    16
#include "SDLInteraction.h"
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    17
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    18
MouseOverFilter::MouseOverFilter(QObject *parent) :
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    19
    QObject(parent)
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
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    23
bool MouseOverFilter::eventFilter( QObject *dist, QEvent *event )
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    24
{
8732
nemo
parents: 8729
diff changeset
    25
    if (event->type() == QEvent::Enter)
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    26
    {
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    27
        QWidget * widget = dynamic_cast<QWidget*>(dist);
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    28
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    29
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    30
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    31
        if (widget->whatsThis() != NULL)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    32
            abstractpage->setButtonDescription(widget->whatsThis());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    33
        else if (widget->toolTip() != NULL)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    34
            abstractpage->setButtonDescription(widget->toolTip());
8732
nemo
parents: 8729
diff changeset
    35
    }
nemo
parents: 8729
diff changeset
    36
    else if (event->type() == QEvent::FocusIn)
nemo
parents: 8729
diff changeset
    37
    {
nemo
parents: 8729
diff changeset
    38
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    39
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
    40
        // 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
    41
        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
    42
        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
    43
        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
    44
        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
    45
        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
    46
        QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
8729
b19be476a2fa Call steps on focus instead. fix typo
nemo
parents: 8326
diff changeset
    47
        QListView * listview = dynamic_cast<QListView*>(dist);
b19be476a2fa Call steps on focus instead. fix typo
nemo
parents: 8326
diff changeset
    48
        if (button || textfield || checkbox || droplist || slider || tab || listview)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6584
diff changeset
    49
        {
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 6930
diff changeset
    50
            SDLInteraction::instance().playSoundFile("/Sounds/steps.ogg");
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
    51
        }
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
    52
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    53
        return true;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    54
    }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    55
    else if (event->type() == QEvent::Leave)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    56
    {
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    57
        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    58
8729
b19be476a2fa Call steps on focus instead. fix typo
nemo
parents: 8326
diff changeset
    59
        if (abstractpage->getDefaultDescription() != NULL)
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    60
        {
8729
b19be476a2fa Call steps on focus instead. fix typo
nemo
parents: 8326
diff changeset
    61
            abstractpage->setButtonDescription( * abstractpage->getDefaultDescription());
6477
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    62
        }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    63
        else
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    64
            abstractpage->setButtonDescription("");
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    65
    }
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    66
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    67
    return false;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    68
}
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    69
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    70
void MouseOverFilter::setUi(Ui_HWForm *uiForm)
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    71
{
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    72
    ui = uiForm;
ad5741c252b9 GCI task: describez
Oranger
parents:
diff changeset
    73
}