umbrello API Documentation

toolbarstateother.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "toolbarstateother.h"
00014 
00015 // kde includes
00016 #include <kdebug.h>
00017 #include <klocale.h>
00018 #include <kinputdialog.h>
00019 
00020 // app includes
00021 #include "activitywidget.h"
00022 #include "boxwidget.h"
00023 #include "dialog_utils.h"
00024 #include "floatingtextwidget.h"
00025 #include "forkjoinwidget.h"
00026 #include "notewidget.h"
00027 #include "object_factory.h"
00028 #include "statewidget.h"
00029 #include "uml.h"
00030 #include "umlview.h"
00031 #include "umldoc.h"
00032 
00033 using namespace Uml;
00034 
00035 ToolBarStateOther::ToolBarStateOther(UMLView *umlView) : ToolBarStatePool(umlView) {
00036 }
00037 
00038 ToolBarStateOther::~ToolBarStateOther() {
00039 }
00040 
00041 void ToolBarStateOther::setCurrentElement() {
00042 }
00043 
00044 void ToolBarStateOther::mouseReleaseEmpty() {
00045     if (m_pMouseEvent->button() == Qt::LeftButton) {
00046         if (!newWidget()) {
00047             // Is UMLObject?
00048 
00049             m_pUMLView->setCreateObject(true);
00050             Object_Factory::createUMLObject(getObjectType());
00051         }
00052 
00053         m_pUMLView->resizeCanvasToItems();
00054     }
00055 }
00056 
00057 Uml::Object_Type ToolBarStateOther::getObjectType() {
00058     Object_Type ot;
00059 
00060     switch(getButton()) {
00061         case WorkToolBar::tbb_Actor:        ot = ot_Actor;          break;
00062         case WorkToolBar::tbb_UseCase:      ot = ot_UseCase;        break;
00063         case WorkToolBar::tbb_Class:        ot = ot_Class;          break;
00064         case WorkToolBar::tbb_Object:       ot = ot_Class;          break;  // Object is a class.
00065         case WorkToolBar::tbb_Package:      ot = ot_Package;        break;
00066         case WorkToolBar::tbb_Component:    ot = ot_Component;      break;
00067         case WorkToolBar::tbb_Node:         ot = ot_Node;           break;
00068         case WorkToolBar::tbb_Artifact:     ot = ot_Artifact;       break;
00069         case WorkToolBar::tbb_Interface:    ot = ot_Interface;      break;
00070         case WorkToolBar::tbb_Enum:         ot = ot_Enum;           break;
00071         case WorkToolBar::tbb_Entity:       ot = ot_Entity;         break;
00072         case WorkToolBar::tbb_Datatype:     ot = ot_Datatype;       break;
00073 
00074         default:                            ot = ot_UMLObject;      break;
00075     }
00076 
00077     return ot;
00078 }
00079 
00080 // TODO: The name is a bit confusing.
00081 bool ToolBarStateOther::newWidget() {
00082     UMLWidget* umlWidget = NULL;
00083 
00084     switch (getButton()) {
00085         case WorkToolBar::tbb_Note:
00086             umlWidget = new NoteWidget(m_pUMLView);
00087             break;
00088 
00089         case WorkToolBar::tbb_Box:
00090             umlWidget = new BoxWidget(m_pUMLView);
00091             break;
00092 
00093         case WorkToolBar::tbb_Text:
00094             umlWidget = new FloatingTextWidget(m_pUMLView, tr_Floating, "");
00095             break;
00096 
00097         // Activity buttons
00098         case WorkToolBar::tbb_Initial_Activity:
00099             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Initial);
00100             break;
00101 
00102         case WorkToolBar::tbb_Activity:
00103             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Normal);
00104             break;
00105 
00106         case WorkToolBar::tbb_End_Activity:
00107             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::End);
00108             break;
00109 
00110         case WorkToolBar::tbb_Branch:
00111             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Branch);
00112             break;
00113 
00114         case WorkToolBar::tbb_Fork:
00115         case WorkToolBar::tbb_StateFork:
00116             umlWidget = new ForkJoinWidget(m_pUMLView);
00117             break;
00118 
00119         case WorkToolBar::tbb_Initial_State:
00120             umlWidget = new StateWidget(m_pUMLView, StateWidget::Initial);
00121             break;
00122 
00123         case WorkToolBar::tbb_State:
00124             umlWidget = new StateWidget(m_pUMLView, StateWidget::Normal);
00125             break;
00126 
00127         case WorkToolBar::tbb_End_State:
00128             umlWidget = new StateWidget(m_pUMLView, StateWidget::End);
00129             break;
00130 
00131         default:
00132             break;
00133     }
00134 
00135     // Return false if we didn't find a suitable widget.
00136     if (umlWidget == NULL) {
00137         return false;
00138     }
00139 
00140     // Special treatment for some buttons
00141     if (getButton() == WorkToolBar::tbb_Activity) {
00142         Dialog_Utils::askNameForWidget(
00143             umlWidget, i18n("Enter Activity Name"),
00144             i18n("Enter the name of the new activity:"), i18n("new activity"));
00145     } else if (getButton() == WorkToolBar::tbb_State) {
00146         Dialog_Utils::askNameForWidget(
00147             umlWidget, i18n("Enter State Name"),
00148             i18n("Enter the name of the new state:"), i18n("new state"));
00149     } else if (getButton() == WorkToolBar::tbb_Text) {
00150         // It is pretty invisible otherwise.
00151         FloatingTextWidget* ft = (FloatingTextWidget*) umlWidget;
00152         ft->changeTextDlg();
00153     }
00154 
00155     // Create the widget. Some setup functions can remove the widget.
00156     if (umlWidget != NULL) {
00157         m_pUMLView->setupNewWidget(umlWidget);
00158     }
00159 
00160     return true;
00161 }
00162 
00163 #include "toolbarstateother.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003