summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/wortdetoolbar.cpp
blob: 03fe2b186196010178c67dd1cc176bed5a490f10 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/***************************************************************************
 *                                                                         *
 *   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-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "wortdetoolbar.h"

// qt/kde include files
#include <tqmainwindow.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <tdetoolbarbutton.h>

// application specific includes
#include "uml.h"
#include "umldoc.h"
#include "umlview.h"
#include "wortdetoolbar.h"


WorkToolBar::WorkToolBar(TQMainWindow *parentWindow, const char*name)
        : TDEToolBar(parentWindow,TQt::DockRight,false,name) {
    m_CurrentButtonID = tbb_Undefined;
    loadPixmaps();
    m_Type = Uml::dt_Class; /* first time in just want it to load arrow,
                           needs anything but dt_Undefined  */
    setOrientation( Qt::Vertical );
    setVerticalStretchable( true );
    // initialize old tool map, everything starts with select tool (arrow)
    m_map.insert(Uml::dt_UseCase,tbb_Arrow);
    m_map.insert(Uml::dt_Collaboration,tbb_Arrow);
    m_map.insert(Uml::dt_Class,tbb_Arrow);
    m_map.insert(Uml::dt_Sequence,tbb_Arrow);
    m_map.insert(Uml::dt_State,tbb_Arrow);
    m_map.insert(Uml::dt_Activity,tbb_Arrow);
    m_map.insert(Uml::dt_Undefined,tbb_Arrow);

    slotCheckToolBar( Uml::dt_Undefined );
    connect( this, TQT_SIGNAL( released( int ) ), this, TQT_SLOT( buttonChanged (int ) ) );
}

WorkToolBar::~WorkToolBar() {
    disconnect(this, TQT_SIGNAL(released(int)),this,TQT_SLOT(buttonChanged(int)));
}

void WorkToolBar::insertHotBtn(ToolBar_Buttons tbb) {
    insertButton(m_ToolButtons[tbb].Symbol, tbb, true, m_ToolButtons[tbb].Label);
    setToggle(tbb, true);
}

void WorkToolBar::insertBasicAssociations()  {
    insertHotBtn(tbb_Association);
    if (m_Type == Uml::dt_Class || m_Type == Uml::dt_UseCase) {
        insertHotBtn(tbb_UniAssociation);
    }
    insertHotBtn(tbb_Dependency);
    insertHotBtn(tbb_Generalization);
}

void WorkToolBar::slotCheckToolBar(Uml::Diagram_Type dt) {
    if ( dt == m_Type )
        return;
    clear();
    m_Type = dt;

    if ( m_Type == Uml::dt_Undefined )
        return;

    //insert note, anchor and lines of text on all diagrams
    insertHotBtn(tbb_Arrow);
    toggleButton(tbb_Arrow);
    m_CurrentButtonID = tbb_Arrow;

    insertHotBtn(tbb_Note);
    insertHotBtn(tbb_Anchor);
    insertHotBtn(tbb_Text);
    insertHotBtn(tbb_Box);

    //insert diagram specific tools
    switch (m_Type) {
    case Uml::dt_UseCase:
        insertHotBtn(tbb_Actor);
        insertHotBtn(tbb_UseCase);
        insertBasicAssociations();
        break;

    case Uml::dt_Class:
        insertHotBtn(tbb_Class);
        insertHotBtn(tbb_Interface);
        insertHotBtn(tbb_Datatype);
        insertHotBtn(tbb_Enum);
        insertHotBtn(tbb_Package);
        insertBasicAssociations();
        insertHotBtn(tbb_Composition);
        insertHotBtn(tbb_Aggregation);
        insertHotBtn(tbb_Containment);
        break;

    case Uml::dt_Sequence:
        insertHotBtn(tbb_Object);
        insertHotBtn(tbb_Seq_Message_Synchronous);
        insertHotBtn(tbb_Seq_Message_Asynchronous);
        break;

    case Uml::dt_Collaboration:
        insertHotBtn(tbb_Object);
        insertHotBtn(tbb_Coll_Message);
        break;

    case Uml::dt_State:
        insertHotBtn(tbb_Initial_State);
        insertHotBtn(tbb_State);
        insertHotBtn(tbb_End_State);
        insertHotBtn(tbb_State_Transition);
        //insertHotBtn(tbb_DeepHistory);        //NotYetImplemented
        //insertHotBtn(tbb_ShallowHistory);     //NotYetImplemented
        //insertHotBtn(tbb_Join);               //NotYetImplemented
        insertHotBtn(tbb_StateFork);
        //insertHotBtn(tbb_Junction);           //NotYetImplemented
        //insertHotBtn(tbb_Choice);             //NotYetImplemented
        //insertHotBtn(tbb_Andline);            //NotYetImplemented
        break;

    case Uml::dt_Activity:
        insertHotBtn(tbb_Initial_Activity);
        insertHotBtn(tbb_Activity);
        insertHotBtn(tbb_End_Activity);
        insertHotBtn(tbb_Branch);
        insertHotBtn(tbb_Fork);
        insertHotBtn(tbb_Activity_Transition);
        break;

    case Uml::dt_Component:
        insertHotBtn(tbb_Interface);
        insertHotBtn(tbb_Component);
        insertHotBtn(tbb_Artifact);
        insertBasicAssociations();
        break;

    case Uml::dt_Deployment:
        insertHotBtn(tbb_Object);
        insertHotBtn(tbb_Interface);
        insertHotBtn(tbb_Component);
        insertHotBtn(tbb_Node);
        insertBasicAssociations();
        break;

    case Uml::dt_EntityRelationship:
        insertHotBtn(tbb_Entity);
        insertHotBtn(tbb_Relationship);
        break;

    default:
        kWarning() << "slotCheckToolBar() on unknown diagram type:"
        << m_Type << endl;
        break;
    }
}

void WorkToolBar::buttonChanged(int b) {
    UMLView* view = UMLApp::app()->getCurrentView();

    //if trying to turn off arrow - stop it
    ToolBar_Buttons tbb = (ToolBar_Buttons)b;
    if (tbb == tbb_Arrow && m_CurrentButtonID == tbb_Arrow) {
        toggleButton(tbb_Arrow);

        // signal needed, in the case ( when switching diagrams ) that
        // Arrow Button gets activated, but the toolBarState of the Views may be different
        emit sigButtonChanged( m_CurrentButtonID );

        view->setCursor( currentCursor() );
        return;
    }

    //if toggling off a button set to arrow
    if (tbb == m_CurrentButtonID) {
        m_map[m_Type] = m_CurrentButtonID;  // store old tool for this diagram type
        toggleButton(tbb_Arrow);
        m_CurrentButtonID = tbb_Arrow;
        emit sigButtonChanged(m_CurrentButtonID);
        view->setCursor( currentCursor() );
        return;
    }
    m_map[m_Type] = m_CurrentButtonID;
    toggleButton(m_CurrentButtonID);
    m_CurrentButtonID = tbb;
    emit sigButtonChanged(m_CurrentButtonID);
    view->setCursor( currentCursor() );
}

TQCursor WorkToolBar::currentCursor() {
    return m_ToolButtons[m_CurrentButtonID].Cursor;
}

void WorkToolBar::slotResetToolBar() {
    if (m_CurrentButtonID == tbb_Arrow)
        return;//really shouldn't occur
    toggleButton(m_CurrentButtonID);
    m_CurrentButtonID = tbb_Arrow;
    toggleButton(m_CurrentButtonID);
    emit sigButtonChanged(m_CurrentButtonID);

    TQCursor curs;
    curs.setShape(Qt::ArrowCursor);

    UMLView* view = UMLApp::app()->getCurrentView();
    if (view != NULL) {
        view -> setCursor(curs);
    }
}

void WorkToolBar::setOldTool() {
    TDEToolBarButton *b = (TDEToolBarButton*) getWidget(m_map[m_Type]);
    if (b)
        b -> animateClick();
}

void WorkToolBar::setDefaultTool() {
    TDEToolBarButton *b = (TDEToolBarButton*) getWidget(tbb_Arrow);
    if (b)
        b -> animateClick();
}

TQPixmap WorkToolBar::load(const TQString & fileName) {
    TQPixmap pxm;
    pxm.load(fileName);
    return pxm;
}

void WorkToolBar::loadPixmaps() {
    const struct ButtonInfo {
        const ToolBar_Buttons tbb;
        const TQString btnName;
        const char *pngName;
    } buttonInfo[] = {
        { tbb_Object, i18n("Object"), "object.png" },
        { tbb_Seq_Message_Synchronous, i18n("Synchronous Message"), "message-synchronous.png" },
        { tbb_Seq_Message_Asynchronous, i18n("Asynchronous Message"), "message-asynchronous.png" },
        { tbb_Association, i18n("Association"), "association.png" },
        { tbb_Containment, i18n("Containment"), "containment.png" },
        { tbb_Anchor, i18n("Anchor"), "anchor.png" },
        { tbb_Text, i18n("Label"), "text.png" },
        { tbb_Note, i18n("Note"), "note.png" },
        { tbb_Box, i18n("Box"), "box.png" },
        { tbb_Actor, i18n("Actor"), "actor.png" },
        { tbb_Dependency, i18n("Dependency"), "dependency.png" },
        { tbb_Aggregation, i18n("Aggregation"), "aggregation.png" },
        { tbb_Relationship, i18n("Relationship"), "relationship.png" },
        { tbb_UniAssociation, i18n("Directional Association"), "uniassociation.png" },
        { tbb_Generalization, i18n("Implements (Generalisation/Realisation)"), "generalisation.png" },
        { tbb_Composition, i18n("Composition"), "composition.png" },
        { tbb_UseCase, i18n("Use Case"), "usecase.png" },
        { tbb_Class, i18n("Class"), "class.png" },
        { tbb_Initial_State, i18n("Initial State"), "initial_state.png" },
        { tbb_End_State, i18n("End State"), "end_state.png" },
        { tbb_Branch, i18n("Branch/Merge"), "branch.png" },
        { tbb_Fork, i18n("Fork/Join"), "fork.png" },
        { tbb_Package, i18n("Package"), "package.png" },
        { tbb_Component, i18n("Component"), "component.png" },
        { tbb_Node, i18n("Node"), "node.png" },
        { tbb_Artifact, i18n("Artifact"), "artifact.png" },
        { tbb_Interface, i18n("Interface"), "interface.png" },
        { tbb_Datatype, i18n("Datatype"), "datatype.png" },
        { tbb_Enum, i18n("Enum"), "enum.png" },
        { tbb_Entity, i18n("Entity"), "entity.png" },
        { tbb_DeepHistory, i18n("Deep History"), "deep-history.png" },          //NotYetImplemented
        { tbb_ShallowHistory, i18n("Shallow History"), "shallow-history.png" }, //NotYetImplemented
        { tbb_Join, i18n("Join"), "join.png" },    //NotYetImplemented
        { tbb_StateFork, i18n("Fork"), "state-fork.png" },
        { tbb_Junction, i18n("Junction"), "junction.png" },    //NotYetImplemented
        { tbb_Choice, i18n("Choice"), "choice-round.png" },    //NotYetImplemented
    //:TODO: let the user decide which symbol he wants (setting an option)
    //    { tbb_Choice, i18n("Choice"), "choice-rhomb.png" },    //NotYetImplemented
        //{ tbb_Andline, i18n("And Line"), "andline.png" },    //NotYetImplemented
        { tbb_State_Transition, i18n("State Transition"), "uniassociation.png" },
        { tbb_Activity_Transition, i18n("Activity Transition"), "uniassociation.png" },
        { tbb_Activity, i18n("Activity"), "usecase.png" },
        { tbb_State, i18n("State"), "usecase.png" },
        { tbb_End_Activity, i18n("End Activity"), "end_state.png" },
        { tbb_Initial_Activity, i18n("Initial Activity"), "initial_state.png" },
        { tbb_Coll_Message, i18n("Message"), "message-asynchronous.png" }
    };
    TDEStandardDirs * dirs = TDEGlobal::dirs();
    TQString dataDir = dirs->findResourceDir( "data", "umbrello/pics/object.png" );
    dataDir += "/umbrello/pics/";
    const size_t n_buttonInfos = sizeof(buttonInfo) / sizeof(ButtonInfo);

    m_ToolButtons.insert(tbb_Undefined,
                         ToolButton(i18n("UNDEFINED"),
                                    0,
                                    TQCursor()) );
    m_ToolButtons.insert(tbb_Arrow,
                         ToolButton(i18n("Select"),
                                    load(dataDir + "arrow.png"),
                                    TQCursor()) );
    kDebug() << "WorkToolBar::loadPixmaps: n_buttonInfos = " << n_buttonInfos << endl;
    for (uint i = 0; i < n_buttonInfos; i++) {
        const ButtonInfo& info = buttonInfo[i];
        m_ToolButtons.insert(info.tbb,
            ToolButton(info.btnName,
                       load(dataDir + info.pngName),
                       TQCursor(load(dataDir + "cursor-" + info.pngName), 9, 9)));
    }
}

#include "wortdetoolbar.moc"