assocpage.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "assocpage.h"
00013 #include <qlayout.h>
00014 #include <klocale.h>
00015 #include "assocpropdlg.h"
00016
00017 AssocPage::AssocPage(QWidget *parent, UMLView * v, UMLObject * o) : QWidget(parent) {
00018 m_pObject = o;
00019 m_pView = v;
00020 int margin = fontMetrics().height();
00021
00022 QHBoxLayout * mainLayout = new QHBoxLayout(this);
00023 mainLayout -> setSpacing(10);
00024
00025 m_pAssocGB = new QGroupBox(i18n("Associations"), this);
00026 mainLayout -> addWidget(m_pAssocGB);
00027
00028 QHBoxLayout * layout = new QHBoxLayout(m_pAssocGB);
00029 layout -> setSpacing(10);
00030 layout -> setMargin(margin);
00031
00032 m_pAssocLB = new QListBox(m_pAssocGB);
00033 layout -> addWidget(m_pAssocLB);
00034 setMinimumSize(310, 330);
00035 fillListBox();
00036 m_pMenu = 0;
00037
00038 connect(m_pAssocLB, SIGNAL(doubleClicked(QListBoxItem *)),
00039 this, SLOT(slotDoubleClick(QListBoxItem *)));
00040
00041 connect(m_pAssocLB, SIGNAL(rightButtonPressed(QListBoxItem *, const QPoint &)),
00042 this, SLOT(slotRightButtonPressed(QListBoxItem *, const QPoint &)));
00043
00044 connect(m_pAssocLB, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
00045 this, SLOT(slotRightButtonClicked(QListBoxItem *, const QPoint &)));
00046 }
00047
00048 AssocPage::~AssocPage() {
00049 disconnect(m_pAssocLB, SIGNAL(doubleClicked(QListBoxItem *)),
00050 this, SLOT(slotDoubleClick(QListBoxItem *)));
00051
00052 disconnect(m_pAssocLB, SIGNAL(rightButtonPressed(QListBoxItem *, const QPoint &)),
00053 this, SLOT(slotRightButtonPressed(QListBoxItem *, const QPoint &)));
00054
00055 disconnect(m_pAssocLB, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
00056 this, SLOT(slotRightButtonClicked(QListBoxItem *, const QPoint &)));
00057 }
00058
00059 void AssocPage::slotDoubleClick(QListBoxItem * i) {
00060
00061 if(!i)
00062 return;
00063
00064 int item = m_pAssocLB -> currentItem();
00065
00066 AssociationWidget * a = m_List.at(item);
00067
00068 if (a->showDialog())
00069 fillListBox();
00070 }
00071
00072 void AssocPage::fillListBox() {
00073 m_List.clear();
00074 m_pAssocLB->clear();
00075 m_pView->getWidgetAssocs(m_pObject, m_List);
00076 AssociationWidgetListIt assoc_it(m_List);
00077 AssociationWidget* assocwidget = 0;
00078 int i = 0;
00079 while((assocwidget = assoc_it.current())) {
00080 if( assocwidget->getAssocType() != Uml::at_Anchor) {
00081 m_pAssocLB -> insertItem(assocwidget->toString(), i++);
00082 }
00083 ++assoc_it;
00084 }
00085 }
00086
00087 void AssocPage::slotRightButtonClicked(QListBoxItem *, const QPoint &) {
00088 if(m_pMenu) {
00089 m_pMenu -> hide();
00090 disconnect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00091 delete m_pMenu;
00092 m_pMenu = 0;
00093 }
00094 }
00095
00096 void AssocPage::slotRightButtonPressed(QListBoxItem * item, const QPoint & p) {
00097 if(!item)
00098 return;
00099 if(m_pMenu) {
00100 m_pMenu -> hide();
00101 disconnect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00102 delete m_pMenu;
00103 m_pMenu = 0;
00104 }
00105 m_pMenu = new ListPopupMenu(this, ListPopupMenu::mt_Association_Selected);
00106 m_pMenu->popup(p);
00107 connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00108 }
00109
00110 void AssocPage::slotPopupMenuSel(int id) {
00111 AssociationWidget * a = m_List.at(m_pAssocLB -> currentItem());
00112 switch(id) {
00113 case ListPopupMenu::mt_Delete:
00114 m_pView->removeAssocInViewAndDoc(a);
00115 fillListBox();
00116 break;
00117
00118 case ListPopupMenu::mt_Properties:
00119 slotDoubleClick(m_pAssocLB -> item(m_pAssocLB -> currentItem()));
00120 break;
00121 }
00122 }
00123
00124
00125
00126
00127 #include "assocpage.moc"
This file is part of the documentation for umbrello Version 3.1.0.