summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/statewidget.h
blob: f4a8008a755e3fe5088e3d2b5422631d2f68519a (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   copyright (C) 2002-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
***************************************************************************/

#ifndef STATEWIDGET_H
#define STATEWIDGET_H
#include <tqpainter.h>
#include <tqstringlist.h>
#include "umlwidget.h"
#include "worktoolbar.h"

#define STATE_MARGIN 5
#define STATE_WIDTH 30
#define STATE_HEIGHT 10

/**
 * This class is the graphical version of a UML State.
 *
 * A StateWidget is created by a @ref UMLView.  A StateWidget belongs to
 * only one @ref UMLView instance.
 * When the @ref UMLView instance that this class belongs to is destroyed,
 * it will be automatically deleted.
 *
 * The StateWidget class inherits from the @ref UMLWidget class which adds
 * most of the functionality to this class.
 *
 * @short  A graphical version of a UML State.
 * @author Paul Hensgen <phensgen@techie.com>
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.kde.org
 */
class StateWidget : public UMLWidget {
    Q_OBJECT
  
public:

    /// Enumeration that codes the different types of state.
    enum StateType
    {
        Initial = 0,
        Normal,
        End
    };

    /**
     * Creates a State widget.
     *
     * @param view              The parent of the widget.
     * @param stateType The type of state.
     * @param id                The ID to assign (-1 will prompt a new ID.)
     */
    explicit StateWidget( UMLView * view, StateType stateType = Normal, Uml::IDType id = Uml::id_None );

    /**
     * destructor
     */
    virtual ~StateWidget();

    /**
     * Overrides the standard paint event.
     */
    void draw(TQPainter & p, int offsetX, int offsetY);

    /**
     * Sets the name of the State.
     */
    virtual void setName(const TQString &strName);

    /**
     * Returns the name of the State.
     */
    virtual TQString getName() const;

    /**
     * Returns the type of state.
     */
    StateType getStateType() const;

    /**
     * Sets the type of state.
     */
    void setStateType( StateType stateType );

    /**
     * Adds the given activity to the state.
     */
    bool addActivity( const TQString &activity );

    /**
     * Removes the given activity from the state.
     */
    bool removeActivity( const TQString &activity );

    /**
     * Renames the given activity.
     */
    bool renameActivity( const TQString &activity, const TQString &newName );

    /**
     * Sets the states activities to the ones given.
     */
    void setActivities( TQStringList & list );

    /**
     * Returns the list of activities.
     */
    TQStringList & getActivityList();

    /**
     * Show a properties dialog for a StateWidget.
     */
    void showProperties();

    /**
     * Returns true if the given toolbar button represents a State.
     *
     * @param tbb               Input value of type WorkToolBar::ToolBar_Buttons.
     * @param resultType        Output value, the StateType that corresponds to tbb.
     *                  Only set if the method returns true.
     */
    static bool isState( WorkToolBar::ToolBar_Buttons tbb,
                         StateType& resultType );

    /**
     * Creates the "statewidget" XMI element.
     */
    void saveToXMI( TQDomDocument & qDoc, TQDomElement & qElement );

    /**
     * Loads a "statewidget" XMI element.
     */
    bool loadFromXMI( TQDomElement & qElement );

protected:
    /**
     * Overrides method from UMLWidget
     */
    TQSize calculateSize();

    /**
     * Type of state.
     */
    StateType m_StateType;

    /**
     * List of activities for the state.
     */
    TQStringList m_Activities;

public slots:

    /**
     * Captures any popup menu signals for menus it created.
     */
    void slotMenuSelection(int sel);
};

#endif