summaryrefslogtreecommitdiffstats
path: root/src/control/controlpushbutton.cpp
blob: 6fe0486d56b8fa467fe72b2223a282bff9c7d15a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
                          controlpushbutton.cpp  -  description
                             -------------------
    begin                : Wed Feb 20 2002
    copyright            : (C) 2002 by Tue and Ken Haste Andersen
    email                :
***************************************************************************/

/***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#include "control/controlpushbutton.h"

/* -------- ------------------------------------------------------
   Purpose: Creates a new simulated latching push-button.
   Input:   key - Key for the configuration file
   -------- ------------------------------------------------------ */
ControlPushButton::ControlPushButton(ConfigKey key, bool bPersist, double defaultValue)
        : ControlObject(key, false, false, bPersist, defaultValue),
          m_buttonMode(PUSH),
          m_iNoStates(2) {
    if (m_pControl) {
        m_pControl->setBehavior(
                new ControlPushButtonBehavior(
                        static_cast<ControlPushButtonBehavior::ButtonMode>(m_buttonMode),
                        m_iNoStates));
    }
}

ControlPushButton::~ControlPushButton() {
}

// Tell this PushButton how to act on rising and falling edges
void ControlPushButton::setButtonMode(enum ButtonMode mode) {
    //qDebug() << "Setting " << m_Key.group << m_Key.item << "as toggle";
    m_buttonMode = mode;

    if (m_pControl) {
        m_pControl->setBehavior(
                new ControlPushButtonBehavior(
                        static_cast<ControlPushButtonBehavior::ButtonMode>(m_buttonMode),
                        m_iNoStates));
    }
}

void ControlPushButton::setStates(int num_states) {
    m_iNoStates = num_states;

    if (m_pControl) {
            m_pControl->setBehavior(
                    new ControlPushButtonBehavior(
                            static_cast<ControlPushButtonBehavior::ButtonMode>(m_buttonMode),
                            m_iNoStates));
    }
}