summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/toolbarstatearrow.cpp
blob: 05e98734a75aec2d7e6513a7acd77474bc4dd639 (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
/***************************************************************************
 *                                                                         *
 *   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 "toolbarstatearrow.h"

// app includes
#include "associationwidget.h"
#include "uml.h"
#include "umlview.h"
#include "umlwidget.h"

ToolBarStateArrow::ToolBarStateArrow(UMLView *umlView): ToolBarState(umlView) {
    m_selectionRect.setAutoDelete(true);

    init();
}

ToolBarStateArrow::~ToolBarStateArrow() {
}

void ToolBarStateArrow::init() {
    ToolBarState::init();

    m_selectionRect.clear();
}

void ToolBarStateArrow::mousePressAssociation() {
    getCurrentAssociation()->mousePressEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mousePressWidget() {
    getCurrentWidget()->mousePressEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mousePressEmpty() {
    if (m_pMouseEvent->button() != Qt::LeftButton) {
        // Leave widgets selected upon RMB press on empty diagram area.
        // The popup menu is activated upon RMB release.
        return;
    }
    ToolBarState::mousePressEmpty();

    // Starts the selection rectangle
    if (m_selectionRect.count() == 0) {
        m_startPosition = m_pMouseEvent->pos();

        for (int i = 0; i < 4; i++) {
            TQCanvasLine* line = new TQCanvasLine(m_pUMLView->canvas());
            line->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(),
                            m_pMouseEvent->x(), m_pMouseEvent->y());
            line->setPen(TQPen(TQColor("grey"), 0, TQt::DotLine));
            line->tqsetVisible(true);
            line->setZ(100);
            m_selectionRect.append(line);
        }
    }
}

void ToolBarStateArrow::mouseReleaseAssociation() {
    getCurrentAssociation()->mouseReleaseEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseReleaseWidget() {
    getCurrentWidget()->mouseReleaseEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseReleaseEmpty() {
    if (m_selectionRect.count() == 4) {
        m_selectionRect.clear();
    } else if (m_pMouseEvent->button() == Qt::RightButton) {
        m_pUMLView->setMenu();
    }
}

void ToolBarStateArrow::mouseDoubleClickAssociation() {
    getCurrentAssociation()->mouseDoubleClickEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseDoubleClickWidget() {
    getCurrentWidget()->mouseDoubleClickEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseMoveAssociation() {
    getCurrentAssociation()->mouseMoveEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseMoveWidget() {
    getCurrentWidget()->mouseMoveEvent(m_pMouseEvent);
}

void ToolBarStateArrow::mouseMoveEmpty() {
    if (m_selectionRect.count() == 4) {
        TQCanvasLine* line = m_selectionRect.at(0);
        line->setPoints(m_startPosition.x(), m_startPosition.y(),
                        m_pMouseEvent->x(), m_startPosition.y());

        line = m_selectionRect.at(1);
        line->setPoints(m_pMouseEvent->x(), m_startPosition.y(),
                        m_pMouseEvent->x(), m_pMouseEvent->y());

        line = m_selectionRect.at(2);
        line->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(),
                        m_startPosition.x(), m_pMouseEvent->y());

        line = m_selectionRect.at(3);
        line->setPoints(m_startPosition.x(), m_pMouseEvent->y(),
                        m_startPosition.x(), m_startPosition.y());

        m_pUMLView->selectWidgets(m_startPosition.x(), m_startPosition.y(),
                                  m_pMouseEvent->x(), m_pMouseEvent->y());
    }
}

void ToolBarStateArrow::changeTool() {
}

void ToolBarStateArrow::setCurrentWidget(UMLWidget* currentWidget) {
    if (currentWidget != 0 && getCurrentWidget() != 0) {
        return;
    }

    ToolBarState::setCurrentWidget(currentWidget);
}

#include "toolbarstatearrow.moc"