~michael-sheldon/ubuntu-keyboard/fix-oxide-dismiss-test

« back to all changes in this revision

Viewing changes to src/lib/logic/state-machines/viewmachine.cpp

  • Committer: Thomas Moenicke
  • Date: 2013-07-19 12:05:07 UTC
  • Revision ID: thomas.moenicke@canonical.com-20130719120507-lzw5oq50xm567x0j
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; c-file-offsets: ((innamespace . 0)); -*-
 
2
/*
 
3
 * This file is part of Maliit Plugins
 
4
 *
 
5
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 
6
 *
 
7
 * Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
 
8
 *
 
9
 * Redistribution and use in source and binary forms, with or without modification,
 
10
 * are permitted provided that the following conditions are met:
 
11
 *
 
12
 * Redistributions of source code must retain the above copyright notice, this list
 
13
 * of conditions and the following disclaimer.
 
14
 * Redistributions in binary form must reproduce the above copyright notice, this list
 
15
 * of conditions and the following disclaimer in the documentation and/or other materials
 
16
 * provided with the distribution.
 
17
 * Neither the name of Nokia Corporation nor the names of its contributors may be
 
18
 * used to endorse or promote products derived from this software without specific
 
19
 * prior written permission.
 
20
 *
 
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 
22
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
23
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 
24
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
26
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
27
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
28
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
30
 *
 
31
 */
 
32
 
 
33
#include "viewmachine.h"
 
34
#include "logic/layoutupdater.h"
 
35
 
 
36
namespace MaliitKeyboard {
 
37
namespace Logic {
 
38
 
 
39
const char *const ViewMachine::main_state = "main";
 
40
const char *const ViewMachine::symbols0_state = "symbols0";
 
41
const char *const ViewMachine::symbols1_state = "symbols1";
 
42
 
 
43
ViewMachine::ViewMachine(QObject *parent)
 
44
    : QStateMachine(parent)
 
45
{}
 
46
 
 
47
ViewMachine::~ViewMachine()
 
48
{}
 
49
 
 
50
void ViewMachine::setup(LayoutUpdater *updater)
 
51
{
 
52
    if (not updater) {
 
53
        qCritical() << __PRETTY_FUNCTION__
 
54
                    << "No updater specified. Aborting setup.";
 
55
        return;
 
56
    }
 
57
 
 
58
    setChildMode(QState::ExclusiveStates);
 
59
 
 
60
    QState *main = 0;
 
61
    QState *symbols0 = 0;
 
62
    QState *symbols1 = 0;
 
63
 
 
64
    // addState makes state machine to be a parent of passed state,
 
65
    // so we don't have to care about deleting states explicitly.
 
66
    addState(main = new QState);
 
67
    addState(symbols0 = new QState);
 
68
    addState(symbols1 = new QState);
 
69
    setInitialState(main);
 
70
 
 
71
    main->setObjectName(main_state);
 
72
    symbols0->setObjectName(symbols0_state);
 
73
    symbols1->setObjectName(symbols1_state);
 
74
 
 
75
    main->addTransition(updater, SIGNAL(symKeyReleased()), symbols0);
 
76
    connect(main,    SIGNAL(entered()),
 
77
            updater, SLOT(switchToMainView()));
 
78
 
 
79
    symbols0->addTransition(updater, SIGNAL(symKeyReleased()), main);
 
80
    symbols0->addTransition(updater, SIGNAL(symSwitcherReleased()), symbols1);
 
81
    connect(symbols0, SIGNAL(entered()),
 
82
            updater,  SLOT(switchToPrimarySymView()));
 
83
 
 
84
    symbols1->addTransition(updater, SIGNAL(symKeyReleased()), main);
 
85
    symbols1->addTransition(updater, SIGNAL(symSwitcherReleased()), symbols0);
 
86
    connect(symbols1, SIGNAL(entered()),
 
87
            updater,  SLOT(switchToSecondarySymView()));
 
88
 
 
89
    // Defer to first main loop iteration:
 
90
    QTimer::singleShot(0, this, SLOT(start()));
 
91
}
 
92
 
 
93
}} // namespace Logic, MaliitKeyboard