summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/dialogs/pkgcontentspage.cpp
blob: 84bb95b6060bda6caeb5b1a70ccf3749ef332d15 (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) 2003-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#include "pkgcontentspage.h"
#include <tqlayout.h>
#include <tdelocale.h>
#include "../umlobjectlist.h"
#include "../uml.h"
#include "../umldoc.h"
#include "classpropdlg.h"

PkgContentsPage::PkgContentsPage(TQWidget *parent, UMLPackage *pkg)
        : TQWidget(parent)
{
    m_pPackage = pkg;
    int margin = fontMetrics().height();

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

    m_pContentGB = new TQGroupBox(i18n("Contained Items"), this);
    mainLayout -> addWidget(m_pContentGB);

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

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

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

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

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

PkgContentsPage::~PkgContentsPage() {
    disconnect(m_pContentLB, TQT_SIGNAL(doubleClicked(TQListBoxItem *)),
               this, TQT_SLOT(slotDoubleClick(TQListBoxItem *)));

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

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

void PkgContentsPage::slotDoubleClick(TQListBoxItem * i) {
    if (!i)
        return;
    int item = m_pContentLB -> currentItem();
    UMLObjectList contents = m_pPackage->containedObjects();
    UMLObject *o = contents.at(item);
    ClassPropDlg dlg(this, o, item, true);
    dlg.exec();
}

void PkgContentsPage::fillListBox() {
    m_pContentLB->clear();
    UMLObjectList contents = m_pPackage->containedObjects();
    UMLObjectListIt objList_it(contents);
    UMLObject* umlo = NULL;
    int i = 0;
    while ((umlo = objList_it.current()) != NULL) {
        m_pContentLB->insertItem(umlo->getName(), i++);
        ++objList_it;
    }
}

void PkgContentsPage::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 PkgContentsPage::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 PkgContentsPage::slotPopupMenuSel(int id) {
    switch(id) {
    case ListPopupMenu::mt_Delete:
        {
            UMLObjectList contents = m_pPackage->containedObjects();
            UMLObject *o = contents.at( m_pContentLB->currentItem() );
            UMLApp::app()->getDocument()->removeUMLObject(o);
            fillListBox();
        }
        break;

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



#include "pkgcontentspage.moc"