summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/floatingtextwidgetcontroller.h
blob: 93c91d69b39904a178877aaca4e0ae12536b9a7c (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
/***************************************************************************
 *                                                                         *
 *   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) 2006-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#ifndef FLOATINGTEXTWIDGETCONTROLLER_H
#define FLOATINGTEXTWIDGETCONTROLLER_H

#include "umlwidgetcontroller.h"

class FloatingTextWidget;

/**
 * Controller for FloatingTextWidget.
 *
 * When moving a FloatingTextWidget, it is constrained using constrainTextPos
 * method from the LinkWidget, if any.
 * This applies both when moving as part of a selection and when constraining
 * the move of the selection because it's the receiver of mouse move events.
 * The only exception to this is that when moving the widget, if it's a sequence
 * message and the message widget is selected, the floating text widget isn't
 * moved itself, but automatically by the message widget.
 * If the sequence message wasn't part of the selection, the floating text
 * widget moves it.
 * When moving the floating text as part of a selection, if the position of
 * the floating text is constrained, it's kept at that position until it can
 * be moved to another valid position.
 * No resize is allowed for FloatingTextWidget.
 *
 * @author Umbrello UML Modeller Authors <uml-devel@lists.sourceforge.net>
 */
class FloatingTextWidgetController : public UMLWidgetController {
public:

    /**
     * Constructor for FloatingTextWidgetController.
     *
     * @param floatingTextWidget The floating text widget which uses the controller.
     */
    FloatingTextWidgetController(FloatingTextWidget *floatingTextWidget);

    /**
     * Destructor for MessageWidgetController.
     */
    ~FloatingTextWidgetController();

protected:

    /**
     * Overridden from UMLWidgetController.
     * Saves the values of the widget needed for move/resize.
     * Calls parent method and then saves the value of m_unconstrainedPositionX/Y
     * and m_movementDirectionX/Y.
     *
     * @param me The TQMouseEvent to get the offset from.
     */
    virtual void saveWidgetValues(TQMouseEvent *me);

    /**
     * Overridden from UMLWidgetController.
     * FloatingTextWidgets can't be resized, so this method always returns false.
     * Cursor isn't changed.
     *
     * @param me The TQMouseEVent to check.
     * @return true if the mouse is in resize area, false otherwise.
     */
    virtual bool isInResizeArea(TQMouseEvent *me);

    /**
     * Overridden from UMLWidgetController.
     * Moves the widget to a new position using the difference between the
     * current position and the new position.
     * If the floating text widget is part of a sequence message, and the
     * message widget is selected, it does nothing: the message widget will
     * update the text position when it's moved.
     * In any other case, the floating text widget constrains its move using
     * constrainPosition. When the position of the floating text is constrained,
     * it's kept at that position until it can be moved to another valid
     * position (m_unconstrainedPositionX/Y and m_movementDirectionX/Y are
     * used for that).
     * Moreover, if is part of a sequence message (and the message widget
     * isn't selected), it updates the position of the message widget.
     * @see constrainPosition
     *
     * @param diffX The difference between current X position and new X position.
     * @param diffY The difference between current Y position and new Y position.
     */
    virtual void moveWidgetBy(int diffX, int diffY);

    /**
     * Overridden from UMLWidgetController.
     * Modifies the value of the diffX and diffY variables used to move the
     * widgets.
     * The values are constrained using constrainPosition.
     * @see constrainPosition
     *
     * @param diffX The difference between current X position and new X position.
     * @param diffY The difference between current Y position and new Y position.
     */
    virtual void constrainMovementForAllWidgets(int &diffX, int &diffY);

private:

    /**
     * Returns a constrained position for the widget after applying the position
     * difference.
     * If no link widget exists, the position returned is the current widget
     * position with the difference applied. If there's a link, the position
     * to be returned is constrained using constrainTextPos method from the
     * LinkWidget, if any.
     *
     * @param diffX The difference between current X position and new X position.
     * @param diffY The difference between current Y position and new Y position.
     * @return A TQPoint with the constrained new position.
     */
    TQPoint constrainPosition(int diffX, int diffY);

    /**
     * The floating text widget which uses the controller.
     */
    FloatingTextWidget *m_floatingTextWidget;

    /**
     * The horizontal position the widget would have if its move wasn't constrained.
     */
    int m_unconstrainedPositionX;

    /**
     * The vertical position the widget would have if its move wasn't constrained.
     */
    int m_unconstrainedPositionY;

    /**
     * The X direction the widget was moved when the constrain was applied.
     * -1 means left, 1 means right.
     */
    int m_movementDirectionX;

    /**
     * The Y direction the widget was moved when the constrain was applied.
     * -1 means up, 1 means down.
     */
    int m_movementDirectionY;
};

#endif