00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "worktoolbar.h"
00014
00015
00016 #include <qmainwindow.h>
00017 #include <kdebug.h>
00018 #include <klocale.h>
00019 #include <kstandarddirs.h>
00020 #include <ktoolbarbutton.h>
00021
00022
00023 #include "uml.h"
00024 #include "umldoc.h"
00025 #include "umlview.h"
00026 #include "worktoolbar.h"
00027
00028
00029 WorkToolBar::WorkToolBar(QMainWindow *parentWindow, const char*name)
00030 : KToolBar(parentWindow,Qt::DockRight,false,name) {
00031 m_CurrentButtonID = tbb_Undefined;
00032 loadPixmaps();
00033 m_Type = Uml::dt_Class;
00034
00035 setOrientation( Qt::Vertical );
00036 setVerticalStretchable( true );
00037
00038 m_map.insert(Uml::dt_UseCase,tbb_Arrow);
00039 m_map.insert(Uml::dt_Collaboration,tbb_Arrow);
00040 m_map.insert(Uml::dt_Class,tbb_Arrow);
00041 m_map.insert(Uml::dt_Sequence,tbb_Arrow);
00042 m_map.insert(Uml::dt_State,tbb_Arrow);
00043 m_map.insert(Uml::dt_Activity,tbb_Arrow);
00044 m_map.insert(Uml::dt_Undefined,tbb_Arrow);
00045
00046 slotCheckToolBar( Uml::dt_Undefined );
00047 connect( this, SIGNAL( released( int ) ), this, SLOT( buttonChanged (int ) ) );
00048 }
00049
00050 WorkToolBar::~WorkToolBar() {
00051 disconnect(this, SIGNAL(released(int)),this,SLOT(buttonChanged(int)));
00052 }
00053
00054 void WorkToolBar::insertHotBtn(ToolBar_Buttons tbb) {
00055 insertButton(m_ToolButtons[tbb].Symbol, tbb, true, m_ToolButtons[tbb].Label);
00056 setToggle(tbb, true);
00057 }
00058
00059 void WorkToolBar::insertBasicAssociations() {
00060 insertHotBtn(tbb_Association);
00061 if (m_Type == Uml::dt_Class || m_Type == Uml::dt_UseCase) {
00062 insertHotBtn(tbb_UniAssociation);
00063 }
00064 insertHotBtn(tbb_Dependency);
00065 insertHotBtn(tbb_Generalization);
00066 }
00067
00068 void WorkToolBar::slotCheckToolBar(Uml::Diagram_Type dt) {
00069 if ( dt == m_Type )
00070 return;
00071 clear();
00072 m_Type = dt;
00073
00074 if ( m_Type == Uml::dt_Undefined )
00075 return;
00076
00077
00078 insertHotBtn(tbb_Arrow);
00079 toggleButton(tbb_Arrow);
00080 m_CurrentButtonID = tbb_Arrow;
00081
00082 insertHotBtn(tbb_Note);
00083 insertHotBtn(tbb_Anchor);
00084 insertHotBtn(tbb_Text);
00085 insertHotBtn(tbb_Box);
00086
00087
00088 switch (m_Type) {
00089 case Uml::dt_UseCase:
00090 insertHotBtn(tbb_Actor);
00091 insertHotBtn(tbb_UseCase);
00092 insertBasicAssociations();
00093 break;
00094
00095 case Uml::dt_Class:
00096 insertHotBtn(tbb_Class);
00097 insertHotBtn(tbb_Interface);
00098 insertHotBtn(tbb_Datatype);
00099 insertHotBtn(tbb_Enum);
00100 insertHotBtn(tbb_Package);
00101 insertBasicAssociations();
00102 insertHotBtn(tbb_Composition);
00103 insertHotBtn(tbb_Aggregation);
00104 insertHotBtn(tbb_Containment);
00105 break;
00106
00107 case Uml::dt_Sequence:
00108 insertHotBtn(tbb_Object);
00109 insertHotBtn(tbb_Seq_Message_Synchronous);
00110 insertHotBtn(tbb_Seq_Message_Asynchronous);
00111 break;
00112
00113 case Uml::dt_Collaboration:
00114 insertHotBtn(tbb_Object);
00115 insertHotBtn(tbb_Coll_Message);
00116 break;
00117
00118 case Uml::dt_State:
00119 insertHotBtn(tbb_Initial_State);
00120 insertHotBtn(tbb_State);
00121 insertHotBtn(tbb_End_State);
00122 insertHotBtn(tbb_State_Transition);
00123
00124
00125
00126 insertHotBtn(tbb_StateFork);
00127
00128
00129
00130 break;
00131
00132 case Uml::dt_Activity:
00133 insertHotBtn(tbb_Initial_Activity);
00134 insertHotBtn(tbb_Activity);
00135 insertHotBtn(tbb_End_Activity);
00136 insertHotBtn(tbb_Branch);
00137 insertHotBtn(tbb_Fork);
00138 insertHotBtn(tbb_Activity_Transition);
00139 break;
00140
00141 case Uml::dt_Component:
00142 insertHotBtn(tbb_Interface);
00143 insertHotBtn(tbb_Component);
00144 insertHotBtn(tbb_Artifact);
00145 insertBasicAssociations();
00146 break;
00147
00148 case Uml::dt_Deployment:
00149 insertHotBtn(tbb_Object);
00150 insertHotBtn(tbb_Interface);
00151 insertHotBtn(tbb_Component);
00152 insertHotBtn(tbb_Node);
00153 insertBasicAssociations();
00154 break;
00155
00156 case Uml::dt_EntityRelationship:
00157 insertHotBtn(tbb_Entity);
00158 insertHotBtn(tbb_Relationship);
00159 break;
00160
00161 default:
00162 kWarning() << "slotCheckToolBar() on unknown diagram type:"
00163 << m_Type << endl;
00164 break;
00165 }
00166 }
00167
00168 void WorkToolBar::buttonChanged(int b) {
00169 UMLView* view = UMLApp::app()->getCurrentView();
00170
00171
00172 ToolBar_Buttons tbb = (ToolBar_Buttons)b;
00173 if (tbb == tbb_Arrow && m_CurrentButtonID == tbb_Arrow) {
00174 toggleButton(tbb_Arrow);
00175
00176
00177
00178 emit sigButtonChanged( m_CurrentButtonID );
00179
00180 view->setCursor( currentCursor() );
00181 return;
00182 }
00183
00184
00185 if (tbb == m_CurrentButtonID) {
00186 m_map[m_Type] = m_CurrentButtonID;
00187 toggleButton(tbb_Arrow);
00188 m_CurrentButtonID = tbb_Arrow;
00189 emit sigButtonChanged(m_CurrentButtonID);
00190 view->setCursor( currentCursor() );
00191 return;
00192 }
00193 m_map[m_Type] = m_CurrentButtonID;
00194 toggleButton(m_CurrentButtonID);
00195 m_CurrentButtonID = tbb;
00196 emit sigButtonChanged(m_CurrentButtonID);
00197 view->setCursor( currentCursor() );
00198 }
00199
00200 QCursor WorkToolBar::currentCursor() {
00201 return m_ToolButtons[m_CurrentButtonID].Cursor;
00202 }
00203
00204 void WorkToolBar::slotResetToolBar() {
00205 if (m_CurrentButtonID == tbb_Arrow)
00206 return;
00207 toggleButton(m_CurrentButtonID);
00208 m_CurrentButtonID = tbb_Arrow;
00209 toggleButton(m_CurrentButtonID);
00210 emit sigButtonChanged(m_CurrentButtonID);
00211
00212 QCursor curs;
00213 curs.setShape(Qt::ArrowCursor);
00214
00215 UMLView* view = UMLApp::app()->getCurrentView();
00216 if (view != NULL) {
00217 view -> setCursor(curs);
00218 }
00219 }
00220
00221 void WorkToolBar::setOldTool() {
00222 KToolBarButton *b = (KToolBarButton*) getWidget(m_map[m_Type]);
00223 if (b)
00224 b -> animateClick();
00225 }
00226
00227 void WorkToolBar::setDefaultTool() {
00228 KToolBarButton *b = (KToolBarButton*) getWidget(tbb_Arrow);
00229 if (b)
00230 b -> animateClick();
00231 }
00232
00233 QPixmap WorkToolBar::load(const QString & fileName) {
00234 QPixmap pxm;
00235 pxm.load(fileName);
00236 return pxm;
00237 }
00238
00239 void WorkToolBar::loadPixmaps() {
00240 const struct ButtonInfo {
00241 const ToolBar_Buttons tbb;
00242 const QString btnName;
00243 const char *pngName;
00244 } buttonInfo[] = {
00245 { tbb_Object, i18n("Object"), "object.png" },
00246 { tbb_Seq_Message_Synchronous, i18n("Synchronous Message"), "message-synchronous.png" },
00247 { tbb_Seq_Message_Asynchronous, i18n("Asynchronous Message"), "message-asynchronous.png" },
00248 { tbb_Association, i18n("Association"), "association.png" },
00249 { tbb_Containment, i18n("Containment"), "containment.png" },
00250 { tbb_Anchor, i18n("Anchor"), "anchor.png" },
00251 { tbb_Text, i18n("Label"), "text.png" },
00252 { tbb_Note, i18n("Note"), "note.png" },
00253 { tbb_Box, i18n("Box"), "box.png" },
00254 { tbb_Actor, i18n("Actor"), "actor.png" },
00255 { tbb_Dependency, i18n("Dependency"), "dependency.png" },
00256 { tbb_Aggregation, i18n("Aggregation"), "aggregation.png" },
00257 { tbb_Relationship, i18n("Relationship"), "relationship.png" },
00258 { tbb_UniAssociation, i18n("Directional Association"), "uniassociation.png" },
00259 { tbb_Generalization, i18n("Implements (Generalisation/Realisation)"), "generalisation.png" },
00260 { tbb_Composition, i18n("Composition"), "composition.png" },
00261 { tbb_UseCase, i18n("Use Case"), "usecase.png" },
00262 { tbb_Class, i18n("Class"), "class.png" },
00263 { tbb_Initial_State, i18n("Initial State"), "initial_state.png" },
00264 { tbb_End_State, i18n("End State"), "end_state.png" },
00265 { tbb_Branch, i18n("Branch/Merge"), "branch.png" },
00266 { tbb_Fork, i18n("Fork/Join"), "fork.png" },
00267 { tbb_Package, i18n("Package"), "package.png" },
00268 { tbb_Component, i18n("Component"), "component.png" },
00269 { tbb_Node, i18n("Node"), "node.png" },
00270 { tbb_Artifact, i18n("Artifact"), "artifact.png" },
00271 { tbb_Interface, i18n("Interface"), "interface.png" },
00272 { tbb_Datatype, i18n("Datatype"), "datatype.png" },
00273 { tbb_Enum, i18n("Enum"), "enum.png" },
00274 { tbb_Entity, i18n("Entity"), "entity.png" },
00275 { tbb_DeepHistory, i18n("Deep History"), "deep-history.png" },
00276 { tbb_ShallowHistory, i18n("Shallow History"), "shallow-history.png" },
00277 { tbb_Join, i18n("Join"), "join.png" },
00278 { tbb_StateFork, i18n("Fork"), "state-fork.png" },
00279 { tbb_Junction, i18n("Junction"), "junction.png" },
00280 { tbb_Choice, i18n("Choice"), "choice-round.png" },
00281
00282
00283
00284 { tbb_State_Transition, i18n("State Transition"), "uniassociation.png" },
00285 { tbb_Activity_Transition, i18n("Activity Transition"), "uniassociation.png" },
00286 { tbb_Activity, i18n("Activity"), "usecase.png" },
00287 { tbb_State, i18n("State"), "usecase.png" },
00288 { tbb_End_Activity, i18n("End Activity"), "end_state.png" },
00289 { tbb_Initial_Activity, i18n("Initial Activity"), "initial_state.png" },
00290 { tbb_Coll_Message, i18n("Message"), "message-asynchronous.png" }
00291 };
00292 KStandardDirs * dirs = KGlobal::dirs();
00293 QString dataDir = dirs->findResourceDir( "data", "umbrello/pics/object.png" );
00294 dataDir += "/umbrello/pics/";
00295 const size_t n_buttonInfos = sizeof(buttonInfo) / sizeof(ButtonInfo);
00296
00297 m_ToolButtons.insert(tbb_Undefined,
00298 ToolButton(i18n("UNDEFINED"),
00299 0,
00300 QCursor()) );
00301 m_ToolButtons.insert(tbb_Arrow,
00302 ToolButton(i18n("Select"),
00303 load(dataDir + "arrow.png"),
00304 QCursor()) );
00305 kDebug() << "WorkToolBar::loadPixmaps: n_buttonInfos = " << n_buttonInfos << endl;
00306 for (uint i = 0; i < n_buttonInfos; i++) {
00307 const ButtonInfo& info = buttonInfo[i];
00308 m_ToolButtons.insert(info.tbb,
00309 ToolButton(info.btnName,
00310 load(dataDir + info.pngName),
00311 QCursor(load(dataDir + "cursor-" + info.pngName), 9, 9)));
00312 }
00313 }
00314
00315 #include "worktoolbar.moc"