summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/dialogs/assocpage.cpp
blob: 63617a7dc34f0b098664a7950ef6b0979b2b4051 (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
/***************************************************************************
 *                                                                         *
 *   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-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#include "assocpage.h"
#include <tqlayout.h>
#include <tdelocale.h>
#include "assocpropdlg.h"

AssocPage::AssocPage(TQWidget *parent, UMLView * v, UMLObject * o) : TQWidget(parent) {
    m_pObject = o;
    m_pView = v;
    int margin = fontMetrics().height();

    TQHBoxLayout * mainLayout = new TQHBoxLayout(this);
    mainLayout -> setSpacing(10);

    m_pAssocGB = new TQGroupBox(i18n("Associations"), this);
    mainLayout -> addWidget(m_pAssocGB);

    TQHBoxLayout * layout = new TQHBoxLayout(m_pAssocGB);
    layout -> setSpacing(10);
    layout -> setMargin(margin);

    m_pAssocLB = new TQListBox(m_pAssocGB);
    layout -> addWidget(m_pAssocLB);
    setMinimumSize(310, 330);
    fillListBox();
    m_pMenu = 0;

    connect(m_pAssocLB, TQT_SIGNAL(doubleClicked(TQListBoxItem *)),
            this, TQT_SLOT(slotDoubleClick(TQListBoxItem *)));

    connect(m_pAssocLB, TQT_SIGNAL(rightButtonPressed(TQListBoxItem *, const TQPoint &)),
            this, TQT_SLOT(slotRightButtonPressed(TQListBoxItem *, const TQPoint &)));

    connect(m_pAssocLB, TQT_SIGNAL(rightButtonClicked(TQListBoxItem *, const TQPoint &)),
            this, TQT_SLOT(slotRightButtonClicked(TQListBoxItem *, const TQPoint &)));
}

AssocPage::~AssocPage() {
    disconnect(m_pAssocLB, TQT_SIGNAL(doubleClicked(TQListBoxItem *)),
               this, TQT_SLOT(slotDoubleClick(TQListBoxItem *)));

    disconnect(m_pAssocLB, TQT_SIGNAL(rightButtonPressed(TQListBoxItem *, const TQPoint &)),
               this, TQT_SLOT(slotRightButtonPressed(TQListBoxItem *, const TQPoint &)));

    disconnect(m_pAssocLB, TQT_SIGNAL(rightButtonClicked(TQListBoxItem *, const TQPoint &)),
               this, TQT_SLOT(slotRightButtonClicked(TQListBoxItem *, const TQPoint &)));
}

void AssocPage::slotDoubleClick(TQListBoxItem * i) {

    if(!i)
        return;

    int item = m_pAssocLB -> currentItem();

    AssociationWidget * a = m_List.at(item);

    if (a->showDialog())
        fillListBox();
}

void AssocPage::fillListBox() {
    m_List.clear();
    m_pAssocLB->clear();
    m_pView->getWidgetAssocs(m_pObject, m_List);
    AssociationWidgetListIt assoc_it(m_List);
    AssociationWidget* assocwidget = 0;
    int i = 0;
    while((assocwidget = assoc_it.current())) {
        if( assocwidget->getAssocType() != Uml::at_Anchor) {
            m_pAssocLB -> insertItem(assocwidget->toString(), i++);
        }
        ++assoc_it;
    }
}

void AssocPage::slotRightButtonClicked(TQListBoxItem */* item*/, const TQPoint &/* p*/) {
    if(m_pMenu) {
        m_pMenu -> hide();
        disconnect(m_pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotPopupMenuSel(int)));
        delete m_pMenu;
        m_pMenu = 0;
    }
}

void AssocPage::slotRightButtonPressed(TQListBoxItem * item, const TQPoint & p) {
    if(!item)
        return;
    if(m_pMenu) {
        m_pMenu -> hide();
        disconnect(m_pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotPopupMenuSel(int)));
        delete m_pMenu;
        m_pMenu = 0;
    }
    m_pMenu = new ListPopupMenu(this, ListPopupMenu::mt_Association_Selected);
    m_pMenu->popup(p);
    connect(m_pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotPopupMenuSel(int)));
}

void AssocPage::slotPopupMenuSel(int id) {
    AssociationWidget * a = m_List.at(m_pAssocLB -> currentItem());
    switch(id) {
    case ListPopupMenu::mt_Delete:
        m_pView->removeAssocInViewAndDoc(a);
        fillListBox();
        break;

    case ListPopupMenu::mt_Properties:
        slotDoubleClick(m_pAssocLB -> item(m_pAssocLB -> currentItem()));
        break;
    }
}




#include "assocpage.moc"