umbrello API Documentation

pkgcontentspage.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2003-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 #include "pkgcontentspage.h"
00013 #include <qlayout.h>
00014 #include <klocale.h>
00015 #include "../umlobjectlist.h"
00016 #include "../uml.h"
00017 #include "../umldoc.h"
00018 #include "classpropdlg.h"
00019 
00020 PkgContentsPage::PkgContentsPage(QWidget *parent, UMLPackage *pkg)
00021         : QWidget(parent)
00022 {
00023     m_pPackage = pkg;
00024     int margin = fontMetrics().height();
00025 
00026     QHBoxLayout * mainLayout = new QHBoxLayout(this);
00027     mainLayout -> setSpacing(10);
00028 
00029     m_pContentGB = new QGroupBox(i18n("Contained Items"), this);
00030     mainLayout -> addWidget(m_pContentGB);
00031 
00032     QHBoxLayout * layout = new QHBoxLayout(m_pContentGB);
00033     layout -> setSpacing(10);
00034     layout -> setMargin(margin);
00035 
00036     m_pContentLB = new QListBox(m_pContentGB);
00037     layout -> addWidget(m_pContentLB);
00038     setMinimumSize(310, 330);
00039     fillListBox();
00040     m_pMenu = 0;
00041 
00042     connect(m_pContentLB, SIGNAL(doubleClicked(QListBoxItem *)),
00043             this, SLOT(slotDoubleClick(QListBoxItem *)));
00044 
00045     connect(m_pContentLB, SIGNAL(rightButtonPressed(QListBoxItem *, const QPoint &)),
00046             this, SLOT(slotRightButtonPressed(QListBoxItem *, const QPoint &)));
00047 
00048     connect(m_pContentLB, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
00049             this, SLOT(slotRightButtonClicked(QListBoxItem *, const QPoint &)));
00050 }
00051 
00052 PkgContentsPage::~PkgContentsPage() {
00053     disconnect(m_pContentLB, SIGNAL(doubleClicked(QListBoxItem *)),
00054                this, SLOT(slotDoubleClick(QListBoxItem *)));
00055 
00056     disconnect(m_pContentLB, SIGNAL(rightButtonPressed(QListBoxItem *, const QPoint &)),
00057                this, SLOT(slotRightButtonPressed(QListBoxItem *, const QPoint &)));
00058 
00059     disconnect(m_pContentLB, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
00060                this, SLOT(slotRightButtonClicked(QListBoxItem *, const QPoint &)));
00061 }
00062 
00063 void PkgContentsPage::slotDoubleClick(QListBoxItem * i) {
00064     if (!i)
00065         return;
00066     int item = m_pContentLB -> currentItem();
00067     UMLObjectList contents = m_pPackage->containedObjects();
00068     UMLObject *o = contents.at(item);
00069     ClassPropDlg dlg(this, o, item, true);
00070     dlg.exec();
00071 }
00072 
00073 void PkgContentsPage::fillListBox() {
00074     m_pContentLB->clear();
00075     UMLObjectList contents = m_pPackage->containedObjects();
00076     UMLObjectListIt objList_it(contents);
00077     UMLObject* umlo = NULL;
00078     int i = 0;
00079     while ((umlo = objList_it.current()) != NULL) {
00080         m_pContentLB->insertItem(umlo->getName(), i++);
00081         ++objList_it;
00082     }
00083 }
00084 
00085 void PkgContentsPage::slotRightButtonClicked(QListBoxItem */* item*/, const QPoint &/* p*/) {
00086     if(m_pMenu) {
00087         m_pMenu -> hide();
00088         disconnect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00089         delete m_pMenu;
00090         m_pMenu = 0;
00091     }
00092 }
00093 
00094 void PkgContentsPage::slotRightButtonPressed(QListBoxItem * item, const QPoint & p) {
00095     if(!item)
00096         return;
00097     if(m_pMenu) {
00098         m_pMenu -> hide();
00099         disconnect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00100         delete m_pMenu;
00101         m_pMenu = 0;
00102     }
00103     m_pMenu = new ListPopupMenu(this, ListPopupMenu::mt_Association_Selected);
00104     m_pMenu->popup(p);
00105     connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotPopupMenuSel(int)));
00106 }
00107 
00108 void PkgContentsPage::slotPopupMenuSel(int id) {
00109     switch(id) {
00110     case ListPopupMenu::mt_Delete:
00111         {
00112             UMLObjectList contents = m_pPackage->containedObjects();
00113             UMLObject *o = contents.at( m_pContentLB->currentItem() );
00114             UMLApp::app()->getDocument()->removeUMLObject(o);
00115             fillListBox();
00116         }
00117         break;
00118 
00119     case ListPopupMenu::mt_Properties:
00120         slotDoubleClick(m_pContentLB->item(m_pContentLB->currentItem()));
00121         break;
00122     }
00123 }
00124 
00125 
00126 
00127 #include "pkgcontentspage.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:59 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003