summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/umlview.h
blob: 805c28afbfbb805e161db0bcaacf0b48f0e51fe2 (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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
/***************************************************************************
 *                                                                         *
 *   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>                  *
 ***************************************************************************/

#ifndef UMLVIEW_H
#define UMLVIEW_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// system includes
#include <kurl.h>
#include <tqdom.h>
#include <tqcanvas.h>

//local includes
#include "umlobjectlist.h"
#include "umlwidgetlist.h"
#include "associationwidgetlist.h"
#include "messagewidgetlist.h"
#include "optionstate.h"
#include "worktoolbar.h"

// forward declarations
class ClassOptionsPage;
class IDChangeLog;
class ListPopupMenu;
class FloatingTextWidget;
class ObjectWidget;
class UMLFolder;
class UMLApp;
class UMLDoc;
class UMLAttribute;
class UMLCanvasObject;
class UMLClassifier;
class UMLViewImageExporter;

class KPrinter;
class ToolBarState;
class ToolBarStateFactory;

/**
 * UMLView instances represent diagrams.
 * The UMLApp instance manages a TQWidgetStack of UMLView instances.
 * The visible diagram is at the top of stack.
 * The UMLView class inherits from TQCanvasView and it owns the
 * objects displayed on its related TQCanvas (see m_WidgetList.)
 *
 * @author Paul Hensgen <phensgen@techie.com>
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.kde.org
 */
class UMLView : public TQCanvasView {
    Q_OBJECT
  
public:
    friend class UMLViewImageExporterModel;

    /**
     * Constructor
     */
    UMLView(UMLFolder *parentFolder);

    /**
     * Destructor
     */
    virtual ~UMLView();

    // Accessors and other methods dealing with loaded/saved data

    /**
     * Return the UMLFolder in which this diagram lives.
     */
    UMLFolder *getFolder() {
        return m_pFolder;
    }

    /**
     * Set the UMLFolder in which this diagram lives.
     */
    void setFolder(UMLFolder *folder) {
        m_pFolder = folder;
    }

    /**
     * Return the documentation of the diagram.
     */
    TQString getDoc() const {
        return m_Documentation;
    }

    /**
     * Set the documentation of the diagram.
     */
    void setDoc( const TQString &doc ) {
        m_Documentation = doc;
    }

    /**
     * Return the name of the diagram.
     */
    TQString getName() const;

    /**
     * Set the name of the diagram.
     */
    void setName(const TQString &name);

    /**
     * Returns the type of the diagram.
     */
    Uml::Diagram_Type getType() const {
        return m_Type;
    }

    /**
     * Set the type of diagram.
     */
    void setType( Uml::Diagram_Type type ) {
        m_Type = type;
    }

    /**
     * Returns the fill color to use.
     */
    TQColor getFillColor() const;

    /**
     * Set the background color.
     *
     * @param color  The color to use.
     */
    void setFillColor( const TQColor &color );

    /**
     * Returns the line color to use.
     */
    TQColor getLineColor() const;

    /**
     * Sets the line color.
     *
     * @param color  The color to use.
     */
    void setLineColor( const TQColor &color );

    /**
     * Returns the line width to use.
     */
    uint getLineWidth() const;

    /**
     * Sets the line width.
     *
     * @param width  The width to use.
     */
    void setLineWidth( uint width );

    /**
     * Returns the ID of the diagram.
     */
    Uml::IDType getID() const {
        return m_nID;
    }

    /**
     * Sets the ID of the diagram.
     */
    void setID( Uml::IDType id ) {
        m_nID = id;
    }

    /**
     * Returns the zoom of the diagram.
     */
    int getZoom() const {
        return m_nZoom;
    }

    /**
     * Sets the zoom of the diagram.
     */
    void setZoom(int zoom);

    /**
     * Returns the height of the diagram.
     */
    int getCanvasHeight() const {
        return m_nCanvasHeight;
    }

    /**
     * Sets the height of the diagram.
     */
    void setCanvasHeight(int height) {
        m_nCanvasHeight = height;
    }

    /**
     * Returns the width of the diagram.
     */
    int getCanvasWidth() const {
        return m_nCanvasWidth;
    }

    /**
     * Sets the height of the diagram.
     */
    void setCanvasWidth(int width) {
        m_nCanvasWidth = width;
    }

    /**
     * Return whether to use snap to grid.
     */
    bool getSnapToGrid() const {
        return m_bUseSnapToGrid;
    }

    /**
     *  Sets whether to snap to grid.
     */
    void setSnapToGrid( bool bSnap );

    /**
     * Return whether to use snap to grid for component size.
     */
    bool getSnapComponentSizeToGrid() const {
        return m_bUseSnapComponentSizeToGrid;
    }

    /**
     * Returns the x grid size.
     */
    int getSnapX() const {
        return m_nSnapX;
    }

    /**
     * Returns the y grid size.
     */
    int getSnapY() const {
        return m_nSnapY;
    }

    /**
     * Returns the input coordinate with possible grid-snap applied.
     */
    int snappedX(int x);

    /**
     * Returns the input coordinate with possible grid-snap applied.
     */
    int snappedY(int y);

    /**
     *  Returns whether to show snap grid or not.
     */
    bool getShowSnapGrid() const;

    /**
     * Sets whether to show snap grid.
     */
    void setShowSnapGrid( bool bShow );

    /**
     * Sets whether to snap to grid for component size.
     */
    void setSnapComponentSizeToGrid( bool bSnap );

    /**
     * Returns whether to use the fill/background color
     */
    bool getUseFillColor() const;

    /**
     * Sets whether to use the fill/background color
     */
    void setUseFillColor(bool ufc);

    /**
     * Returns the font to use
     */
    TQFont getFont() const;

    /**
     * Sets the font for the view and optionally all the widgets on the view.
     */
    void setFont(TQFont font, bool changeAllWidgets = false);

    /**
     * Returns whether to show operation signatures.
     */
    bool getShowOpSig() const;

    /**
     * Sets whether to show operation signatures.
     */
    void setShowOpSig(bool bShowOpSig);

    /**
     * Returns the options being used.
     */
    const Settings::OptionState& getOptionState() const {
        return m_Options;
    }

    /**
     * Sets the options to be used.
     */
    void setOptionState( const Settings::OptionState& options) {
        m_Options = options;
    }

    /**
     * Returns a reference to the association list.
     */
    AssociationWidgetList& getAssociationList() {
        return m_AssociationList;
    }

    /**
     * Returns a reference to the widget list.
     */
    UMLWidgetList& getWidgetList() {
        return m_WidgetList;
    }

    /**
     * Returns a reference to the message list.
     */
    MessageWidgetList& getMessageList() {
        return m_MessageList;
    }

    // End of accessors and methods that only deal with loaded/saved data
    ////////////////////////////////////////////////////////////////////////

    /**
     * return the current zoom factor
     */
    int currentZoom();

    /**
     * contains the implementation for printing functionality
     */
    void print(KPrinter *pPrinter, TQPainter & pPainter);

    /**
     * Overrides the standard operation.
     */
    void hideEvent(TQHideEvent *he);

    /**
     * Overrides the standard operation.
     */
    void showEvent(TQShowEvent *se);

    /**
     * Sees if a message is relevant to the given widget.  If it does delete it.
     * @param w The widget to check messages against.
     */
    void checkMessages(ObjectWidget * w);

    /**
     * Finds a widget with the given ID.
     *
     * @param id The ID of the widget to find.
     *
     * @return Returns the widget found, returns 0 if no widget found.
     */
    UMLWidget * findWidget(Uml::IDType id);

    /**
     * Finds an association widget with the given ID.
     *
     * @param id The ID of the widget to find.
     *
     * @return Returns the widget found, returns 0 if no widget found.
     */
    AssociationWidget * findAssocWidget(Uml::IDType id);

    /**
     * Finds an association widget with the given type and widgets.
     *
     * @param at  The Association_Type of the widget to find.
     * @param pWidgetA Pointer to the UMLWidget of role A.
     * @param pWidgetB Pointer to the UMLWidget of role B.
     *
     * @return Returns the widget found, returns 0 if no widget found.
     */
    AssociationWidget * findAssocWidget(Uml::Association_Type at,
                                        UMLWidget *pWidgetA, UMLWidget *pWidgetB);

    /**
     * Finds an association widget with the given widgets and the given role B name.
     * Considers the following association types:
     *  at_Association, at_UniAssociation, at_Composition, at_Aggregation
     * This is used for seeking an attribute association.
     *
     * @param pWidgetA  Pointer to the UMLWidget of role A.
     * @param pWidgetB  Pointer to the UMLWidget of role B.
     * @param roleNameB Name at the B side of the association (the attribute name)
     *
     * @return Returns the widget found, returns 0 if no widget found.
     */
    AssociationWidget * findAssocWidget(UMLWidget *pWidgetA,
                                        UMLWidget *pWidgetB, const TQString& roleNameB);

    /**
     * Remove a widget from view.
     *
     * @param o  The widget to remove.
     */
    void removeWidget(UMLWidget * o);

    /**
     * Sets a widget to a selected state and adds it to a list of selected widgets.
     *
     * @param w The widget to set to selected.
     * @param me The mouse event containing the information about the selection.
     */
    void setSelected(UMLWidget * w, TQMouseEvent * me);

    /**
     *  Clear the selected widgets list.
     */
    void clearSelected();

    /**
     * Move all the selected widgets by a relative X and Y offset.
     *
     * @param dX The distance to move horizontally.
     * @param dY The distance to move vertically.
     */
    void moveSelectedBy(int dX, int dY);

    /**
     * Return the amount of widgets selected.
     *
     * @param filterText  When true, do NOT count floating text widgets that
     *                    belong to other widgets (i.e. only count tr_Floating.)
     *                    Default: Count all widgets.
     * @return  Number of widgets selected.
     */
    int getSelectCount(bool filterText = false) const;

    /**
     * Set the useFillColor variable to all selected widgets
     *
     * @param useFC The state to set the widget to.
     */
    void selectionUseFillColor(bool useFC);

    /**
     * Set the font for all the currently selected items.
     */
    void selectionSetFont( const TQFont &font );

    /**
     * Set the line color for all the currently selected items.
     */
    void selectionSetLineColor( const TQColor &color );

    /**
     * Set the line width for all the currently selected items.
     */
    void selectionSetLineWidth( uint width );

    /**
     * Set the fill color for all the currently selected items.
     */
    void selectionSetFillColor( const TQColor &color );

    /**
     * Toggles the show setting sel of all selected items.
     */
    void selectionToggleShow(int sel);

    /**
     * Delete the selected widgets list and the widgets in it.
     */
    void deleteSelection();

    /**
     * Selects all widgets
     */
    void selectAll();

    /**
     * Return a unique ID for the diagram.  Used by the @ref ObjectWidget class.
     *
     * @return Return a unique ID for the diagram.
     */
    Uml::IDType getLocalID();

    /**
     * Returns whether a widget is already on the diagram.
     *
     * @param id The id of the widget to check for.
     *
     * @return Returns true if the widget is already on the diagram, false if not.
     */
    bool widgetOnDiagram(Uml::IDType id);

    /**
     * Returns true if this diagram resides in an externalized folder.
     * CHECK: It is probably cleaner to move this to the UMLListViewItem.
     */
    bool isSavedInSeparateFile();

    /**
     * Get the pos variable.  Used internally to keep track of the cursor.
     */
    TQPoint & getPos() {
        return m_Pos;
    }

    /**
     * Set the pos variable.  Used internally to keep track of the cursor.
     *
     * @param _pos The position to set to.
     */
    void setPos(const TQPoint &_pos) {
        m_Pos = _pos;
    }

    /**
     * Sets the popup menu to use when clicking on a diagram background
     * (rather than a widget or listView).
     */
    void setMenu();

    /**
     * Reset the toolbar.
     */
    void resetToolbar() {
        emit sigResetToolBar();
    }

    /**
     * Returns the status on whether in a paste state.
     *
     * @return Returns the status on whether in a paste state.
     */
    bool getPaste() const {
        return m_bPaste;
    }

    /**
     * Sets the status on whether in a paste state.
     */
    void setPaste(bool paste) {
        m_bPaste = paste;
    }

    /**
     * Returns a List of all the UMLObjects(Use Cases, Concepts and Actors) in the View
     */
    UMLObjectList getUMLObjects();

    /**
     * Activate all the objects and associations after a load from the clipboard
     */
    void activate();

    /**
     * Returns a list with all the selected associations from the diagram
     */
    AssociationWidgetList getSelectedAssocs();

    /**
     * Fills the List with all the selected widgets from the diagram
     * The list can be filled with all the selected widgets, or be filtered to prevent
     * text widgets other than tr_Floating to be append.
     *
     * @param WidgetList The UMLWidgetList to fill.
     * @param filterText Don't append the text, unless their role is tr_Floating
     */
    bool getSelectedWidgets(UMLWidgetList& WidgetList, bool filterText = true);

    /**
     * Activate the view after a load a new file
     */
    void activateAfterLoad( bool bUseLog = false );

    void endPartialWidgetPaste();
    void beginPartialWidgetPaste();

    /**
     * Removes a AssociationWidget from a diagram
     * Physically deletes the AssociationWidget passed in.
     *
     * @param pAssoc  Pointer to the AssociationWidget.
     */
    void removeAssoc(AssociationWidget* pAssoc);

    /**
     * Removes all the associations related to Widget
     *
     * @param pWidget  Pointer to the widget to remove.
     */
    void removeAssociations(UMLWidget* pWidget);

    /**
     * Sets each association as selected if the widgets it associates are selected
     */
    void selectAssociations(bool bSelect);

    /**
     * Fills Associations with all the associations that includes a widget related to object
     */
    void getWidgetAssocs(UMLObject* Obj, AssociationWidgetList & Associations);

    /**
     * Removes All the associations of the diagram
     */
    void removeAllAssociations();

    /**
     * Removes All the widgets of the diagram
     */
    void removeAllWidgets();

    /**
     *  Calls the same method in the DocWindow.
     */
    void showDocumentation( UMLObject * object, bool overwrite );

    /**
     *  Calls the same method in the DocWindow.
     */
    void showDocumentation( UMLWidget * widget, bool overwrite );

    /**
    *  Calls the same method in the DocWindow.
    */
    void showDocumentation( AssociationWidget * widget, bool overwrite );

    /**
    *  Calls the same method in the DocWindow.
    */
    void updateDocumentation( bool clear );

    /**
     * Returns the PNG picture of the paste operation.
     *
     * @param rect the area of the diagram to copy
     * @param diagram the class to store PNG picture of the paste operation.
     */
    void getDiagram(const TQRect &rect, TQPixmap & diagram);

    /**
     * Paint diagram to the paint device
     */
    void  getDiagram(const TQRect &area, TQPainter & painter);

    /**
     * Returns the PNG picture of the paste operation.
     */
    void copyAsImage(TQPixmap*& pix);

    /**
     * Returns the imageExporter used to export the view.
     *
     * @return The imageExporter used to export the view.
     */
    UMLViewImageExporter* getImageExporter();

    /**
     * Adds an association to the view from the given data.
     * Use this method when pasting.
     */
    bool addAssociation( AssociationWidget* pAssoc , bool isPasteOperation = false);

    /**
     * Removes an AssociationWidget from the association list
     * and removes the corresponding UMLAssociation from the current UMLDoc.
     */
    void removeAssocInViewAndDoc(AssociationWidget* assoc);

    /**
     * Adds a widget to the view from the given data.
     * Use this method when pasting.
     */
    bool addWidget( UMLWidget * pWidget , bool isPasteOperation = false);

    /**
     * Returns the offset point at which to place the paste from clipboard.
     * Just add the amount to your co-ords.
     * Only call this straight after the event, the value won't stay valid.
     * Should only be called by Assoc widgets at the moment. no one else needs it.
     */
    TQPoint getPastePoint();

    /**
     * Reset the paste point.
     */
    void resetPastePoint();

    /**
     * Called by the view or any of its children when they start a cut
     * operation.
     */
    void setStartedCut() {
        m_bStartedCut = true;
    }

    /**
     * Creates automatically any Associations that the given @ref UMLWidget
     * may have on any diagram.  This method is used when you just add the UMLWidget
     * to a diagram.
     */
    void createAutoAssociations( UMLWidget * widget );

    /**
     * If the m_Type of the given widget is Uml::wt_Class then
     * iterate through the class' attributes and create an
     * association to each attribute type widget that is present
     * on the current diagram.
     */
    void createAutoAttributeAssociations(UMLWidget *widget);

    /**
     * Refreshes containment association, i.e. removes possible old
     * containment and adds new containment association if applicable.
     *
     * @param self  Pointer to the contained object for which
     *   the association to the containing object is
     *   recomputed.
     */
    void updateContainment(UMLCanvasObject *self);

    /**
     * Sets the x grid size.
     */
    void setSnapX( int x) {
        m_nSnapX = x;
        canvas() -> setAllChanged();
    }

    /**
     * Sets the y grid size.
     */
    void setSnapY( int y) {
        m_nSnapY = y;
        canvas() -> setAllChanged();
    }

    /**
     * Shows the properties dialog for the view.
     */
    bool showPropDialog();

    /**
     * Sets some options for all the @ref ClassifierWidget on the view.
     */
    void setClassWidgetOptions( ClassOptionsPage * page );

    /**
    * Call before copying/cutting selected widgets.  This will make sure
    * any associations/message selected will make sure both the widgets
    * widgets they are connected to are selected.
    */
    void checkSelections();

    /**
     * This function checks if the currently selected items have all the same
     * type (class, interface, ...). If true, the selection is unique and true
     * will be returned.
     * If there are no items selected, the function will return always true.
     */
    bool checkUniqueSelection();

    /**
     * Asks for confirmation and clears everything on the diagram.
     * Called from menus.
     */
    void clearDiagram();

    /**
     * Changes snap to grid boolean.
     * Called from menus.
     */
    void toggleSnapToGrid();

    /**
     * Changes snap to grid for component size boolean.
     * Called from menus.
     */
    void toggleSnapComponentSizeToGrid();

    /**
     *  Changes show grid boolean.
     * Called from menus.
     */
    void toggleShowGrid();

    /**
     * Changes the zoom to the currently set level (now loaded from file)
     * Called from UMLApp::slotUpdateViews()
     */
    void fileLoaded();

    /**
     * Sets the diagram width and height in pixels
     */
    void setCanvasSize(int width, int height);

    /**
     * Sets the size of the canvas to just fit on all the items
     */
    void resizeCanvasToItems();

    /**
     * The width and height of a diagram canvas in pixels.
     */
    static const int defaultCanvasSize;

    // Load/Save interface:

    /**
     * Creates the "diagram" tag and fills it with the contents of the diagram.
     */
    virtual void saveToXMI( TQDomDocument & qDoc, TQDomElement & qElement );

    /**
     * Loads the "diagram" tag.
     */
    virtual bool loadFromXMI( TQDomElement & qElement );

    /**
     * Loads the "UISDiagram" tag of Unisys.IntegratePlus.2 generated files.
     */
    bool loadUISDiagram(TQDomElement & qElement);

    /**
     * Loads a "widget" element from XMI, used by loadFromXMI() and the clipboard.
     */
    UMLWidget* loadWidgetFromXMI(TQDomElement& widgetElement);

    /**
     * Add an object to the application, and update the view.
     */
    void addObject(UMLObject *object);

    /**
     * Selects all the widgets within an internally kept rectangle.
     */
    void selectWidgets(int px, int py, int qx, int qy);

    /**
     * Determine whether on a sequence diagram we have clicked on a line
     * of an Object.
     *
     * @return The widget thats line was clicked on.
     *  Returns 0 if no line was clicked on.
     */
    ObjectWidget * onWidgetLine( const TQPoint &point );

    /**
     * Return pointer to the first selected widget (for multi-selection)
     */
    UMLWidget* getFirstMultiSelectedWidget() {
        return m_SelectedList.first();
    }

    /**
     * Tests the given point against all widgets and returns the
     * widget for which the point is within its bounding rectangle.
     * In case of multiple matches, returns the smallest widget.
     * Returns NULL if the point is not inside any widget.
     * Does not use or modify the m_pOnWidget member.
     */
    UMLWidget *getWidgetAt(const TQPoint& p);

    /**
     * Initialize and announce a newly created widget.
     * Auxiliary to contentsMouseReleaseEvent().
     */
    void setupNewWidget(UMLWidget *w);

    /**
     * Return whether we are currently creating an object.
     */
    bool getCreateObject() const {
        return m_bCreateObject;
    }

    /**
     * Set whether we are currently creating an object.
     */
    void setCreateObject(bool bCreate) {
        m_bCreateObject = bCreate;
    }

    /**
     * Emit the sigRemovePopupMenu TQt signal.
     */
    void emitRemovePopupMenu() {
        emit sigRemovePopupMenu();
    }

    /**
     * Used for creating unique name of collaboration messages.
     */
    int generateCollaborationId();

protected:

    // Methods and members related to loading/saving

    bool loadWidgetsFromXMI( TQDomElement & qElement );

    bool loadMessagesFromXMI( TQDomElement & qElement );

    bool loadAssociationsFromXMI( TQDomElement & qElement );

    bool loadUisDiagramPresentation(TQDomElement & qElement);

    /**
     * Contains the unique ID to allocate to a widget that needs an
     * ID for the view.  @ref ObjectWidget is an example of this.
     */
    Uml::IDType m_nLocalID;

    /**
     * The ID of the view.  Allocated by @ref UMLDoc
     */
    Uml::IDType m_nID;

    /**
     * The type of diagram to represent.
     */
    Uml::Diagram_Type m_Type;

    /**
     * The name of the diagram.
     */
    TQString m_Name;

    /**
     * The documentation of the diagram.
     */
    TQString m_Documentation;

    /**
     * Options used by view
     */
    Settings::OptionState m_Options;

    /**
     * Contains all the message widgets on the diagram.
     */
    MessageWidgetList m_MessageList;

    /**
     * Contains all the UMLWidgets on the diagram.
     */
    UMLWidgetList m_WidgetList;

    /**
     * Contains all the AssociationWidgets on the diagram.
     */
    AssociationWidgetList m_AssociationList;

    /**
     * The snap to grid x size.
     */
    int m_nSnapX;

    /**
     * The snap to grid y size.
     */
    int m_nSnapY;

    /**
     * Determines whether to use snap to grid.  The default is off.
     */
    bool m_bUseSnapToGrid;

    /**
     * Determines whether to use snap to grid for component
     * size.  The default is off.
     */
    bool m_bUseSnapComponentSizeToGrid;

    /**
     * Determines whether to show the snap grid.  The default will be on if the grid is on.
     */
    bool m_bShowSnapGrid;

    /**
     * The zoom level in percent, default 100
     */
    int m_nZoom;

    /**
     * Width of canvas in pixels
     */
    int m_nCanvasWidth;

    /**
     * Height of canvas in pixels
     */
    int m_nCanvasHeight;

    // End of methods and members related to loading/saving
    ////////////////////////////////////////////////////////////////////////

    /**
     * Override standard method.
     */
    void closeEvent ( TQCloseEvent * e );

    /**
     * Override standard method.
     */
    void contentsDragEnterEvent(TQDragEnterEvent* mouseEvent);

    /**
     * Override standard method.
     */
    void contentsDropEvent(TQDropEvent* mouseEvent);


    /**
     * Gets the smallest area to print.
     *
     * @return Returns the smallest area to print.
     */
    TQRect getDiagramRect();


    /**
     * Initializes key variables.
     */
    void init();

    /**
     * Overrides the standard operation.
     * Calls the same method in the current tool bar state.
     */
    void contentsMouseReleaseEvent(TQMouseEvent* mouseEvent);

    /**
     * Overrides the standard operation.
     * Calls the same method in the current tool bar state.
     */
    void contentsMouseMoveEvent(TQMouseEvent* mouseEvent);

    /**
     * Override standard method.
     * Calls the same method in the current tool bar state.
     */
    void contentsMouseDoubleClickEvent(TQMouseEvent* mouseEvent);

    /**
     * Override standard method.
     * Calls the same method in the current tool bar state.
     */
    void contentsMousePressEvent(TQMouseEvent* mouseEvent);


    /**
     * Selects all the widgets of the given association widget.
     */
    void selectWidgetsOfAssoc (AssociationWidget * a);

    /**
     * Calls setSelected on the given UMLWidget and enters
     * it into the m_SelectedList while making sure it is
     * there only once.
     */
    void makeSelected (UMLWidget * uw);

    /**
     * Updates the size of all components in this view.
     */
    void updateComponentSizes();

    /**
     * Find the maximum bounding rectangle of FloatingTextWidget widgets.
     * Auxiliary to copyAsImage().
     *
     * @param ft Pointer to the FloatingTextWidget widget to consider.
     * @param px  X coordinate of lower left corner. This value will be
     *            updated if the X coordinate of the lower left corner
     *            of ft is smaller than the px value passed in.
     * @param py  Y coordinate of lower left corner. This value will be
     *            updated if the Y coordinate of the lower left corner
     *            of ft is smaller than the py value passed in.
     * @param qx  X coordinate of upper right corner. This value will be
     *            updated if the X coordinate of the upper right corner
     *            of ft is larger than the qx value passed in.
     * @param qy  Y coordinate of upper right corner. This value will be
     *            updated if the Y coordinate of the upper right corner
     *            of ft is larger than the qy value passed in.
     */
    void findMaxBoundingRectangle(const FloatingTextWidget* ft,
                                  int& px, int& py, int& qx, int& qy);

    void forceUpdateWidgetFontMetrics(TQPainter *painter);

    /**
     * Used for creating unique name of collaboration messages.
     */
    int m_nCollaborationId;

    TQPoint m_Pos;
    bool m_bCreateObject, m_bDrawSelectedOnly, m_bPaste;
    ListPopupMenu * m_pMenu;
    UMLWidgetList m_SelectedList;

    /**
     *  Flag if view/children started cut operation.
     */
    bool m_bStartedCut;

private:
    /**
     * The folder in which this UMLView is contained
     */
    UMLFolder *m_pFolder;

    /**
     * set to true when a child has used the showDocumentation method,
     * thus when one clicks on a child widget.
     * Reset to false when clicking in an empty region of the view.
     */
    bool m_bChildDisplayedDoc;

    ToolBarStateFactory* m_pToolBarStateFactory;
    ToolBarState* m_pToolBarState;

    /**
     * LocalID Changes Log for paste actions
     */
    IDChangeLog * m_pIDChangesLog;

    /**
     *
     * True if the view was activated after the serialization(load)
     */
    bool m_bActivated;

    /**
     * Status of a popupmenu on view.
     * true - a popup is on view
     */
    bool m_bPopupShowing;

    /**
     * The offset at which to paste the clipboard.
     */
    TQPoint m_PastePoint;

    /**
     * Pointer to the UMLDoc
     */
    UMLDoc* m_pDoc;

    /**
     * The UMLViewImageExporter used to export the view.
     */
    UMLViewImageExporter* m_pImageExporter;

    /**
     * Create an association with the attribute attr associated with the UMLWidget
     * widget if the UMLClassifier type is present on the current diagram.
     */
    void createAutoAttributeAssociation(UMLClassifier *type,
                                        UMLAttribute *attr,
                                        UMLWidget *widget);

public slots:

    void zoomIn();
    void zoomOut();

    /**
     * Changes the current tool to the selected tool.
     * The current tool is cleaned and the selected tool initialized.
     */
    void slotToolBarChanged(int c);
    void slotObjectCreated(UMLObject * o);
    void slotObjectRemoved(UMLObject * o);

    /**
     * When a menu selection has been made on the menu
     * that this view created, this method gets called.
     */
    void slotMenuSelection(int sel);

    /**
     * This slot is entered when an event has occurred on the views display,
     * most likely a mouse event.  Before it sends out that mouse event everyone
     * that displays a menu on the views surface (widgets and this ) thould remove any
     * menu.  This stops more then one menu bieing displayed.
     */
    void slotRemovePopupMenu();

    /**
     * makes this view the active view by asking the document to show us
     */
    void slotActivate();

    /**
     * Connects to the signal that @ref UMLApp emits when a cut operation
     * is successful.
     * If the view or a child started the operation the flag m_bStartedCut will
     * be set and we can carry out any operation that is needed, like deleting the selected
     * widgets for the cut operation.
     */
    void slotCutSuccessful();

    /**
     * Called by menu when to show the instance of the view.
     */
    void slotShowView();

    /**
     * Overrides standard method from TQWidget to resize canvas when
     * it's shown.
     */
    void show();

signals:
    void sigResetToolBar();
    void sigColorChanged( Uml::IDType );
    void sigRemovePopupMenu();
    void sigClearAllSelected();
    void sigLineWidthChanged( Uml::IDType );
    void sigSnapToGridToggled(bool);
    void sigSnapComponentSizeToGridToggled(bool);
    void sigShowGridToggled(bool);

    /**
     * Emitted when an association is removed.
     */
    void sigAssociationRemoved(AssociationWidget*);

    /**
     * Emitted when a widget is removed.
     */
    void sigWidgetRemoved(UMLWidget*);
};

#endif // UMLVIEW_H