umbrello API Documentation

forkjoinwidget.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) 2005-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "forkjoinwidget.h"
00014 //qt includes
00015 #include <qdom.h>
00016 //kde includes
00017 #include <kcursor.h>
00018 #include <kdebug.h>
00019 //app includes
00020 #include "umlview.h"
00021 #include "listpopupmenu.h"
00022 
00023 ForkJoinWidget::ForkJoinWidget(UMLView * view, bool drawVertical, Uml::IDType id)
00024   : BoxWidget(view, id), m_drawVertical(drawVertical) {
00025     init();
00026 }
00027 
00028 void ForkJoinWidget::init() {
00029     WidgetBase::setBaseType( Uml::wt_ForkJoin );
00030     UMLWidget::updateComponentSize();
00031 }
00032 
00033 ForkJoinWidget::~ForkJoinWidget() {
00034 }
00035 
00036 QSize ForkJoinWidget::calculateSize() {
00037     if (m_drawVertical) {
00038         return QSize(4, 40);
00039     } else {
00040         return QSize(40, 4);
00041     }
00042 }
00043 
00044 void ForkJoinWidget::draw(QPainter& p, int offsetX, int offsetY) {
00045     p.fillRect( offsetX, offsetY, width(), height(), QBrush( Qt::black ));
00046 
00047     if (m_bSelected) {
00048         drawSelected(&p, offsetX, offsetY);
00049     }
00050 }
00051 
00052 void ForkJoinWidget::drawSelected(QPainter *, int /*offsetX*/, int /*offsetY*/) {
00053 }
00054 
00055 void ForkJoinWidget::constrain(int& width, int& height) {
00056     if (m_drawVertical) {
00057         if (width < 4)
00058             width = 4;
00059         else if (width > 10)
00060             width = 10;
00061         if (height < 40)
00062             height = 40;
00063         else if (height > 100)
00064             height = 100;
00065     } else {
00066         if (height < 4)
00067             height = 4;
00068         else if (height > 10)
00069             height = 10;
00070         if (width < 40)
00071             width = 40;
00072         else if (width > 100)
00073             width = 100;
00074     }
00075 }
00076 
00077 void ForkJoinWidget::slotMenuSelection(int sel) {
00078     switch (sel) {
00079     case ListPopupMenu::mt_Flip:
00080         setDrawVertical(!m_drawVertical);
00081         break;
00082     default:
00083         break;
00084     }
00085 }
00086 
00087 void ForkJoinWidget::setDrawVertical(bool to) {
00088     m_drawVertical = to;
00089     updateComponentSize();
00090     UMLWidget::adjustAssocs( getX(), getY() );
00091 }
00092 
00093 bool ForkJoinWidget::getDrawVertical() const {
00094     return m_drawVertical;
00095 }
00096 
00097 void ForkJoinWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement) {
00098     QDomElement fjElement = qDoc.createElement("forkjoin");
00099     UMLWidget::saveToXMI(qDoc, fjElement);
00100     fjElement.setAttribute("drawvertical", m_drawVertical);
00101     qElement.appendChild(fjElement);
00102 }
00103 
00104 bool ForkJoinWidget::loadFromXMI(QDomElement& qElement) {
00105     if ( !UMLWidget::loadFromXMI(qElement) ) {
00106         return false;
00107     }
00108     QString drawVertical = qElement.attribute("drawvertical", "0");
00109     setDrawVertical( (bool)drawVertical.toInt() );
00110     return true;
00111 }
00112 
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:57 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003