summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/toolbarstateother.cpp
blob: 718ac4561c48659c7dd7d273195d203e57d81f11 (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
/***************************************************************************
 *                                                                         *
 *   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) 2004-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "toolbarstateother.h"

// kde includes
#include <kdebug.h>
#include <tdelocale.h>
#include <kinputdialog.h>

// app includes
#include "activitywidget.h"
#include "boxwidget.h"
#include "dialog_utils.h"
#include "floatingtextwidget.h"
#include "forkjoinwidget.h"
#include "notewidget.h"
#include "object_factory.h"
#include "statewidget.h"
#include "uml.h"
#include "umlview.h"
#include "umldoc.h"

using namespace Uml;

ToolBarStateOther::ToolBarStateOther(UMLView *umlView) : ToolBarStatePool(umlView) {
}

ToolBarStateOther::~ToolBarStateOther() {
}

void ToolBarStateOther::setCurrentElement() {
}

void ToolBarStateOther::mouseReleaseEmpty() {
    if (m_pMouseEvent->button() == Qt::LeftButton) {
        if (!newWidget()) {
            // Is UMLObject?

            m_pUMLView->setCreateObject(true);
            Object_Factory::createUMLObject(getObjectType());
        }

        m_pUMLView->resizeCanvasToItems();
    }
}

Uml::Object_Type ToolBarStateOther::getObjectType() {
    Object_Type ot;

    switch(getButton()) {
        case WorkToolBar::tbb_Actor:        ot = ot_Actor;          break;
        case WorkToolBar::tbb_UseCase:      ot = ot_UseCase;        break;
        case WorkToolBar::tbb_Class:        ot = ot_Class;          break;
        case WorkToolBar::tbb_Object:       ot = ot_Class;          break;  // Object is a class.
        case WorkToolBar::tbb_Package:      ot = ot_Package;        break;
        case WorkToolBar::tbb_Component:    ot = ot_Component;      break;
        case WorkToolBar::tbb_Node:         ot = ot_Node;           break;
        case WorkToolBar::tbb_Artifact:     ot = ot_Artifact;       break;
        case WorkToolBar::tbb_Interface:    ot = ot_Interface;      break;
        case WorkToolBar::tbb_Enum:         ot = ot_Enum;           break;
        case WorkToolBar::tbb_Entity:       ot = ot_Entity;         break;
        case WorkToolBar::tbb_Datatype:     ot = ot_Datatype;       break;

        default:                            ot = ot_UMLObject;      break;
    }

    return ot;
}

// TODO: The name is a bit confusing.
bool ToolBarStateOther::newWidget() {
    UMLWidget* umlWidget = NULL;

    switch (getButton()) {
        case WorkToolBar::tbb_Note:
            umlWidget = new NoteWidget(m_pUMLView);
            break;

        case WorkToolBar::tbb_Box:
            umlWidget = new BoxWidget(m_pUMLView);
            break;

        case WorkToolBar::tbb_Text:
            umlWidget = new FloatingTextWidget(m_pUMLView, tr_Floating, "");
            break;

        // Activity buttons
        case WorkToolBar::tbb_Initial_Activity:
            umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Initial);
            break;

        case WorkToolBar::tbb_Activity:
            umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Normal);
            break;

        case WorkToolBar::tbb_End_Activity:
            umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::End);
            break;

        case WorkToolBar::tbb_Branch:
            umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Branch);
            break;

        case WorkToolBar::tbb_Fork:
        case WorkToolBar::tbb_StateFork:
            umlWidget = new ForkJoinWidget(m_pUMLView);
            break;

        case WorkToolBar::tbb_Initial_State:
            umlWidget = new StateWidget(m_pUMLView, StateWidget::Initial);
            break;

        case WorkToolBar::tbb_State:
            umlWidget = new StateWidget(m_pUMLView, StateWidget::Normal);
            break;

        case WorkToolBar::tbb_End_State:
            umlWidget = new StateWidget(m_pUMLView, StateWidget::End);
            break;

        default:
            break;
    }

    // Return false if we didn't find a suitable widget.
    if (umlWidget == NULL) {
        return false;
    }

    // Special treatment for some buttons
    if (getButton() == WorkToolBar::tbb_Activity) {
        Dialog_Utils::askNameForWidget(
            umlWidget, i18n("Enter Activity Name"),
            i18n("Enter the name of the new activity:"), i18n("new activity"));
    } else if (getButton() == WorkToolBar::tbb_State) {
        Dialog_Utils::askNameForWidget(
            umlWidget, i18n("Enter State Name"),
            i18n("Enter the name of the new state:"), i18n("new state"));
    } else if (getButton() == WorkToolBar::tbb_Text) {
        // It is pretty invisible otherwise.
        FloatingTextWidget* ft = (FloatingTextWidget*) umlWidget;
        ft->changeTextDlg();
    }

    // Create the widget. Some setup functions can remove the widget.
    if (umlWidget != NULL) {
        m_pUMLView->setupNewWidget(umlWidget);
    }

    return true;
}

#include "toolbarstateother.moc"