56
connect( m_pObject, SIGNAL(modified()), this, SLOT(updateWidget()) );
59
connect(m_pObject, SIGNAL(modified()), this, SLOT(updateWidget()));
57
60
m_nId = m_pObject->getID();
61
64
UMLWidget::UMLWidget(UMLView * view, Uml::IDType id /* = Uml::id_None */, UMLWidgetController *widgetController /* = 0*/)
62
: WidgetBase(view), QCanvasRectangle( view->canvas() ),
65
: WidgetBase(view), Q3CanvasRectangle(view->canvas()),
65
68
if (widgetController) {
140
146
// if(getBaseType() != wt_Text) // DON'T do this for floatingtext widgets, an infinite loop will result
142
AssociationWidgetListIt assoc_it( m_Assocs );
143
AssociationWidgetListIt assoc_it2( other.m_Assocs );
148
AssociationWidgetListIt assoc_it(m_Assocs);
149
AssociationWidgetListIt assoc_it2(other.m_Assocs);
144
150
AssociationWidget * assoc = 0, *assoc2 = 0;
145
while ( ((assoc=assoc_it.current()) != 0) && ((assoc2=assoc_it2.current()) != 0)) {
148
if(!(*assoc == *assoc2)) {
151
while (assoc_it.hasNext() && assoc_it2.hasNext()) {
152
assoc = assoc_it.next();
153
assoc2 = assoc_it2.next();
155
if (!(*assoc == *assoc2)) {
170
void UMLWidget::mouseMoveEvent(QMouseEvent* me) {
177
void UMLWidget::mouseMoveEvent(QMouseEvent* me)
171
179
m_widgetController->mouseMoveEvent(me);
174
void UMLWidget::mousePressEvent(QMouseEvent *me) {
182
void UMLWidget::mousePressEvent(QMouseEvent *me)
175
184
m_widgetController->mousePressEvent(me);
178
187
void UMLWidget::updateWidget()
180
189
updateComponentSize();
181
adjustAssocs( getX(), getY() ); //adjust assoc lines.
182
if (m_Type == Uml::wt_Class) {
190
adjustAssocs(getX(), getY()); //adjust assoc lines.
183
193
m_pView->createAutoAttributeAssociations(this);
196
m_pView->createAutoConstraintAssociations(this);
189
QSize UMLWidget::calculateSize() {
206
QSize UMLWidget::calculateSize()
190
208
return QSize(20, 20);
193
void UMLWidget::constrain(int& width, int& height) {
211
void UMLWidget::constrain(int& width, int& height)
194
213
const QSize minSize = calculateSize();
195
214
if (width < minSize.width())
196
215
width = minSize.width();
235
256
m_pDoc = UMLApp::app()->getDocument();
237
connect( m_pView, SIGNAL( sigRemovePopupMenu() ), this, SLOT( slotRemovePopupMenu() ) );
238
connect( m_pView, SIGNAL( sigClearAllSelected() ), this, SLOT( slotClearAllSelected() ) );
258
connect(m_pView, SIGNAL(sigRemovePopupMenu()), this, SLOT(slotRemovePopupMenu()));
259
connect(m_pView, SIGNAL(sigClearAllSelected()), this, SLOT(slotClearAllSelected()));
240
connect( m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
241
connect( m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
261
connect(m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
262
connect(m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
244
265
// connect( m_pView, SIGNAL(sigColorChanged(int)), this, SLOT(slotColorChanged(int)));
263
285
m_pView -> removeWidget(this);
266
//UMLWidgetController::doMouseDoubleClick relies on this implementation
288
//UMLWidgetController::doMouseDoubleClick relies on this implementation
267
289
case ListPopupMenu::mt_Properties:
268
290
if (wt == wt_Actor || wt == wt_UseCase ||
269
291
wt == wt_Package || wt == wt_Interface || wt == wt_Datatype ||
270
292
wt == wt_Component || wt == wt_Artifact ||
271
293
wt == wt_Node || wt == wt_Enum || wt == wt_Entity ||
272
294
(wt == wt_Class && m_pView -> getType() == dt_Class)) {
295
UMLApp::app()->BeginMacro("Change Properties");
273
296
showProperties();
297
UMLApp::app()->EndMacro();
274
298
} else if (wt == wt_Object) {
299
UMLApp::app()->BeginMacro("Change Properties");
275
300
m_pObject->showProperties();
301
UMLApp::app()->EndMacro();
277
kWarning() << "making properties dialog for unknown widget type" << endl;
303
uWarning() << "making properties dialog for unknown widget type";
279
305
// adjustAssocs( getX(), getY() );//adjust assoc lines
282
308
case ListPopupMenu::mt_Line_Color:
283
case ListPopupMenu::mt_Line_Color_Selection:
284
309
widget = m_pView->getFirstMultiSelectedWidget();
285
if (widget) { newColour = widget->getLineColor(); }
286
if( KColorDialog::getColor(newColour) ) {
287
m_pView -> selectionSetLineColor( newColour );
311
newColour = widget->getLineColor();
313
if (KColorDialog::getColor(newColour)) {
314
m_pView -> selectionSetLineColor(newColour);
288
315
m_pDoc -> setModified(true);
292
320
case ListPopupMenu::mt_Fill_Color:
293
case ListPopupMenu::mt_Fill_Color_Selection:
294
321
widget = m_pView->getFirstMultiSelectedWidget();
295
if (widget) { newColour = widget->getFillColour(); }
296
if ( KColorDialog::getColor(newColour) ) {
297
m_pView -> selectionSetFillColor( newColour );
323
newColour = widget->getFillColour();
325
if (KColorDialog::getColor(newColour)) {
326
m_pView -> selectionSetFillColor(newColour);
298
327
m_pDoc -> setModified(true);
320
349
case ListPopupMenu::mt_ViewCode: {
321
UMLClassifier *c = dynamic_cast<UMLClassifier*>(m_pObject);
324
UMLApp::app()->viewCodeDocument(c);
350
UMLClassifier *c = dynamic_cast<UMLClassifier*>(m_pObject);
352
UMLApp::app()->viewCodeDocument(c);
329
357
case ListPopupMenu::mt_Delete_Selection:
330
358
m_pView -> deleteSelection();
333
361
case ListPopupMenu::mt_Change_Font:
335
if( KFontDialog::getFont( font, false, m_pView ) )
338
m_pDoc->setModified(true);
342
case ListPopupMenu::mt_Change_Font_Selection:
344
if( KFontDialog::getFont( font, false, m_pView ) )
346
m_pView -> selectionSetFont( font );
347
m_pDoc->setModified(true);
362
case ListPopupMenu::mt_Change_Font_Selection: {
363
QFont font = getFont();
364
if (KFontDialog::getFont(font, false, m_pView)) {
365
UMLApp::app()->executeCommand(new cmdChangeFontSelection(m_pDoc, m_pView, font));
351
370
case ListPopupMenu::mt_Cut:
352
371
m_pView -> setStartedCut();
364
383
case ListPopupMenu::mt_Refactoring:
365
384
//check if we are operating on a classifier, or some other kind of UMLObject
366
if(dynamic_cast<UMLClassifier*>(m_pObject))
385
if (dynamic_cast<UMLClassifier*>(m_pObject)) {
368
386
UMLApp::app()->refactor(static_cast<UMLClassifier*>(m_pObject));
372
390
case ListPopupMenu::mt_Clone:
373
391
// In principle we clone all the uml objects.
375
UMLObject *pClone = m_pObject->clone();
376
m_pView->addObject(pClone);
393
UMLObject *pClone = m_pObject->clone();
394
m_pView->addObject(pClone);
380
398
case ListPopupMenu::mt_Rename_MultiA:
381
399
case ListPopupMenu::mt_Rename_MultiB:
382
400
case ListPopupMenu::mt_Rename_Name:
383
401
case ListPopupMenu::mt_Rename_RoleAName:
384
case ListPopupMenu::mt_Rename_RoleBName:
386
FloatingTextWidget *ft = static_cast<FloatingTextWidget*>(this);
402
case ListPopupMenu::mt_Rename_RoleBName: {
403
FloatingTextWidget *ft = static_cast<FloatingTextWidget*>(this);
409
uDebug() << "Menu_Type " << sel << " not implemented" << endl;
393
413
void UMLWidget::slotWidgetMoved(Uml::IDType /*id*/) {}
395
void UMLWidget::slotColorChanged(Uml::IDType viewID) {
415
void UMLWidget::slotColorChanged(Uml::IDType viewID)
396
417
//only change if on the diagram concerned
397
if(m_pView->getID() != viewID) {
418
if (m_pView->getID() != viewID) {
400
if ( m_bUsesDiagramFillColour ) {
421
if (m_bUsesDiagramFillColour) {
401
422
m_FillColour = m_pView->getFillColor();
403
if ( m_bUsesDiagramLineColour ) {
424
if (m_bUsesDiagramLineColour) {
404
425
m_LineColour = m_pView->getLineColor();
406
if ( m_bUsesDiagramUseFillColour ) {
427
if (m_bUsesDiagramUseFillColour) {
407
428
m_bUseFillColour = m_pView->getUseFillColor();
412
void UMLWidget::slotLineWidthChanged(Uml::IDType viewID) {
433
void UMLWidget::slotLineWidthChanged(Uml::IDType viewID)
413
435
//only change if on the diagram concerned
414
if(m_pView->getID() != viewID) {
436
if (m_pView->getID() != viewID) {
417
if ( m_bUsesDiagramLineWidth ) {
439
if (m_bUsesDiagramLineWidth) {
418
440
m_LineWidth = m_pView->getLineWidth();
423
void UMLWidget::mouseDoubleClickEvent( QMouseEvent * me ) {
445
void UMLWidget::mouseDoubleClickEvent(QMouseEvent * me)
424
447
m_widgetController->mouseDoubleClickEvent(me);
427
void UMLWidget::setUseFillColour(bool fc) {
450
void UMLWidget::setUseFillColour(bool fc)
428
452
m_bUseFillColour = fc;
429
453
m_bUsesDiagramUseFillColour = false;
433
void UMLWidget::setLineColor(const QColor &colour) {
457
void UMLWidget::setLineColorcmd(const QColor &colour)
434
459
WidgetBase::setLineColor(colour);
438
void UMLWidget::setLineWidth(uint width) {
463
void UMLWidget::setLineColor(const QColor &colour)
465
UMLApp::app()->executeCommand(new cmdChangeLineColor(this, colour));
468
void UMLWidget::setLineWidth(uint width)
439
470
WidgetBase::setLineWidth(width);
443
void UMLWidget::setFillColour(const QColor &colour) {
474
void UMLWidget::setFillColour(const QColor &colour)
476
UMLApp::app()->executeCommand(new cmdChangeFillColor(this, colour));
479
void UMLWidget::setFillColourcmd(const QColor &colour)
444
481
m_FillColour = colour;
445
482
m_bUsesDiagramFillColour = false;
449
void UMLWidget::drawSelected(QPainter * p, int offsetX, int offsetY) {
486
QColor UMLWidget::getFillColor()
491
void UMLWidget::drawSelected(QPainter * p, int offsetX, int offsetY)
451
494
int h = height();
461
504
const int right = offsetX + w;
462
505
const int bottom = offsetY + h;
463
506
p->drawLine(right - s, offsetY + h - 1, offsetX + w - 1, offsetY + h - s);
464
p->drawLine(right - (s*2), bottom - 1, right - 1, bottom - (s*2) );
465
p->drawLine(right - (s*3), bottom - 1, right - 1, bottom - (s*3) );
467
p->fillRect(offsetX + w - s, offsetY + h - s, s, s, brush);
507
p->drawLine(right - (s*2), bottom - 1, right - 1, bottom - (s*2));
508
p->drawLine(right - (s*3), bottom - 1, right - 1, bottom - (s*3));
510
p->fillRect(offsetX + w - s, offsetY + h - s, s, s, brush);
471
bool UMLWidget::activate(IDChangeLog* /*ChangeLog = 0 */) {
514
bool UMLWidget::activate(IDChangeLog* /*ChangeLog = 0 */)
472
516
if (widgetHasUMLObject(m_Type) && m_pObject == NULL) {
473
517
m_pObject = m_pDoc->findObjectById(m_nId);
474
518
if (m_pObject == NULL) {
475
kError() << "UMLWidget::activate: cannot find UMLObject with id="
476
<< ID2STR(m_nId) << endl;
519
uError() << "cannot find UMLObject with id=" << ID2STR(m_nId) << endl;
486
529
QPoint point = m_pView -> getPastePoint();
487
530
int x = point.x() + getX();
488
531
int y = point.y() + getY();
491
if( m_pView -> getType() == dt_Sequence ) {
492
switch( getBaseType() ) {
534
if (m_pView -> getType() == dt_Sequence) {
535
switch (getBaseType()) {
537
case wt_Precondition :
500
ft = static_cast<FloatingTextWidget *>( this );
548
ft = static_cast<FloatingTextWidget *>(this);
501
549
if (ft->getRole() == tr_Seq_Message) {
513
561
}//end switch base type
514
562
}//end if sequence
519
567
}//end if pastepoint
524
if ( m_pView -> getPaste() )
525
m_pView -> createAutoAssociations( this );
572
if (m_pView -> getPaste())
573
m_pView -> createAutoAssociations(this);
526
574
updateComponentSize();
530
578
/** Read property of bool m_bActivated. */
531
bool UMLWidget::isActivated() {
579
bool UMLWidget::isActivated()
532
581
return m_bActivated;
535
void UMLWidget::setActivated(bool Active /*=true*/) {
584
void UMLWidget::setActivated(bool Active /*=true*/)
536
586
m_bActivated = Active;
539
void UMLWidget::addAssoc(AssociationWidget* pAssoc) {
589
void UMLWidget::addAssoc(AssociationWidget* pAssoc)
540
591
if (pAssoc && !m_Assocs.contains(pAssoc)) {
541
592
m_Assocs.append(pAssoc);
545
void UMLWidget::removeAssoc(AssociationWidget* pAssoc) {
547
m_Assocs.remove(pAssoc);
596
void UMLWidget::removeAssoc(AssociationWidget* pAssoc)
599
m_Assocs.removeAll(pAssoc);
558
610
// as file is only partly loaded -> reposition
559
611
// could be misguided )
560
612
/// @todo avoid trigger of this event during load
561
if ( m_pDoc->loading() ) {
613
if (m_pDoc->loading()) {
562
614
// don't recalculate the assocs during load of XMI
563
615
// -> return immediately without action
566
618
AssociationWidgetListIt assoc_it(m_Assocs);
567
AssociationWidget* assocwidget = 0;
568
while ((assocwidget = assoc_it.current())) {
620
foreach(AssociationWidget* assocwidget , m_Assocs) {
570
621
assocwidget->saveIdealTextPositions();
573
while ((assocwidget = assoc_it.current())) {
624
foreach(AssociationWidget* assocwidget , m_Assocs) {
575
625
assocwidget->widgetMoved(this, x, y);
579
629
void UMLWidget::adjustUnselectedAssocs(int x, int y)
581
AssociationWidgetListIt assoc_it(m_Assocs);
582
AssociationWidget* assocwidget = 0;
583
while ((assocwidget = assoc_it.current())) {
585
if(!assocwidget->getSelected())
632
foreach(AssociationWidget* assocwidget , m_Assocs) {
634
if (!assocwidget->getSelected())
586
635
assocwidget->saveIdealTextPositions();
589
while ((assocwidget = assoc_it.current())) {
591
if(!assocwidget->getSelected())
638
foreach(AssociationWidget* assocwidget , m_Assocs) {
639
if (!assocwidget->getSelected())
592
640
assocwidget->widgetMoved(this, x, y);
596
void UMLWidget::showProperties() {
644
void UMLWidget::showProperties()
597
646
// will already be selected so make sure docWindow updates the doc
598
647
// back it the widget
599
648
DocWindow *docwindow = UMLApp::app()->getDocWindow();
600
docwindow->updateDocumentation( false );
649
docwindow->updateDocumentation(false);
601
650
ClassPropDlg *dlg = new ClassPropDlg((QWidget*)UMLApp::app(), this);
603
652
if (dlg->exec()) {
604
docwindow->showDocumentation( getUMLObject() , true );
653
docwindow->showDocumentation(getUMLObject() , true);
605
654
m_pDoc->setModified(true);
607
dlg->close(true); //wipe from memory
656
dlg->close(); //wipe from memory
610
void UMLWidget::startPopupMenu( const QPoint &At) {
659
ListPopupMenu* UMLWidget::setupPopupMenu()
611
661
slotRemovePopupMenu();
613
663
//if in a multi- selection to a specific m_pMenu for that
633
683
// disable the "view code" menu for simple code generators
634
684
CodeGenerator * currentCG = UMLApp::app()->getGenerator();
635
if(currentCG && dynamic_cast<SimpleCodeGenerator*>(currentCG))
636
m_pMenu->setItemEnabled(ListPopupMenu::mt_ViewCode, false);
640
connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotMenuSelection(int)));
685
if (currentCG && dynamic_cast<SimpleCodeGenerator*>(currentCG))
686
m_pMenu->setActionEnabled(ListPopupMenu::mt_ViewCode, false);
688
connect(m_pMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotMenuSelection(QAction*)));
643
void UMLWidget::slotRemovePopupMenu() {
645
disconnect(m_pMenu, SIGNAL(activated(int)), this, SLOT(slotMenuSelection(int)));
693
void UMLWidget::slotRemovePopupMenu()
696
disconnect(m_pMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotMenuSelection(QAction*)));
651
int UMLWidget::onWidget(const QPoint & p) {
702
int UMLWidget::onWidget(const QPoint & p)
652
704
const int w = width();
653
705
const int h = height();
654
706
const int left = getX();
656
708
const int top = getY();
657
709
const int bottom = top + h;
658
710
if (p.x() < left || p.x() > right ||
659
p.y() < top || p.y() > bottom) // Qt coord.sys. origin in top left corner
711
p.y() < top || p.y() > bottom) // Qt coord.sys. origin in top left corner
661
713
return (w + h) / 2;
664
void UMLWidget::moveBy(int dx, int dy) {
716
void UMLWidget::moveByLocal(int dx, int dy)
665
718
int newX = getX() + dx;
666
719
int newY = getY() + dy;
722
// uDebug() << "********** x=" << newX << " / y=" << newY;
669
723
adjustAssocs(newX, newY);
672
void UMLWidget::setPen(QPainter & p) {
673
p.setPen( QPen(m_LineColour, m_LineWidth) );
676
void UMLWidget::drawShape(QPainter &p ) {
677
draw( p, getX(), getY() );
680
void UMLWidget::setSelected(bool _select) {
726
void UMLWidget::setPenFromSettings(QPainter & p)
728
p.setPen(QPen(m_LineColour, m_LineWidth));
731
void UMLWidget::drawShape(QPainter &p)
733
draw(p, getX(), getY());
736
void UMLWidget::setSelected(bool _select)
681
738
const Uml::Widget_Type wt = m_Type;
683
if( m_pView -> getSelectCount() == 0 ) {
684
if ( widgetHasUMLObject(wt) ) {
740
if (m_pView -> getSelectCount() == 0) {
741
if (widgetHasUMLObject(wt)) {
685
742
m_pView->showDocumentation(m_pObject, false);
687
744
m_pView->showDocumentation(this, false);
694
751
/* if (wt != wt_Text && wt != wt_Box) {
698
m_pView -> updateDocumentation( true );
755
m_pView -> updateDocumentation(true);
700
757
m_bSelected = _select;
702
759
const QPoint pos(getX(), getY());
703
760
UMLWidget *bkgnd = m_pView->getWidgetAt(pos);
704
761
if (bkgnd && bkgnd != this && _select) {
705
kDebug() << "UMLWidget::setSelected: setting Z to "
706
<< bkgnd->getZ() + 1 << ", SelectState: " << _select << endl;
707
setZ( bkgnd->getZ() + 1 );
762
uDebug() << "setting Z to " << bkgnd->getZ() + 1 << ", SelectState: " << _select << endl;
763
setZ(bkgnd->getZ() + 1);
719
775
void UMLWidget::slotClearAllSelected()
721
setSelected( false );
724
void UMLWidget::setView(UMLView * v) {
780
void UMLWidget::setView(UMLView * v)
725
782
//remove signals from old view - was probably 0 anyway
726
disconnect( m_pView, SIGNAL( sigRemovePopupMenu() ), this, SLOT( slotRemovePopupMenu() ) );
727
disconnect( m_pView, SIGNAL( sigClearAllSelected() ), this, SLOT( slotClearAllSelected() ) );
728
disconnect( m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
729
disconnect( m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
783
disconnect(m_pView, SIGNAL(sigRemovePopupMenu()), this, SLOT(slotRemovePopupMenu()));
784
disconnect(m_pView, SIGNAL(sigClearAllSelected()), this, SLOT(slotClearAllSelected()));
785
disconnect(m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
786
disconnect(m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
731
connect( m_pView, SIGNAL( sigRemovePopupMenu() ), this, SLOT( slotRemovePopupMenu() ) );
732
connect( m_pView, SIGNAL( sigClearAllSelected() ), this, SLOT( slotClearAllSelected() ) );
733
connect( m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
734
connect( m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
788
connect(m_pView, SIGNAL(sigRemovePopupMenu()), this, SLOT(slotRemovePopupMenu()));
789
connect(m_pView, SIGNAL(sigClearAllSelected()), this, SLOT(slotClearAllSelected()));
790
connect(m_pView, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotColorChanged(Uml::IDType)));
791
connect(m_pView, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType)));
737
void UMLWidget::setX( int x ) {
794
void UMLWidget::setX(int x)
738
796
if (!m_bIgnoreSnapToGrid) {
739
797
x = m_pView->snappedX(x);
741
QCanvasItem::setX( (double)x );
799
Q3CanvasItem::setX(x);
744
void UMLWidget::setY( int y ) {
745
if (!m_bIgnoreSnapToGrid){
802
void UMLWidget::setY(int y)
804
if (!m_bIgnoreSnapToGrid) {
746
805
y = m_pView->snappedX(y);
748
QCanvasItem::setY( (double)y );
807
Q3CanvasItem::setY(y);
751
void UMLWidget::setZ(int z) {
810
void UMLWidget::setZ(int z)
752
812
m_origZ = getZ();
753
QCanvasItem::setZ(z);
813
Q3CanvasItem::setZ(z);
756
void UMLWidget::setName(const QString &strName) {
816
void UMLWidget::setName(const QString &strName)
758
819
m_pObject->setName(strName);
760
821
m_Text = strName;
761
822
updateComponentSize();
762
adjustAssocs( getX(), getY() );
823
adjustAssocs(getX(), getY());
765
QString UMLWidget::getName() const {
826
QString UMLWidget::getName() const
767
829
return m_pObject->getName();
771
void UMLWidget::cleanup() {
774
void UMLWidget::slotSnapToGrid( ) {
779
bool UMLWidget::widgetHasUMLObject(Uml::Widget_Type type) {
833
void UMLWidget::cleanup()
837
void UMLWidget::slotSnapToGrid()
843
bool UMLWidget::widgetHasUMLObject(Uml::Widget_Type type)
780
845
if (type == wt_Actor ||
781
846
type == wt_UseCase ||
782
847
type == wt_Class ||
797
void UMLWidget::setIgnoreSnapToGrid(bool to) {
862
void UMLWidget::setIgnoreSnapToGrid(bool to)
798
864
m_bIgnoreSnapToGrid = to;
801
bool UMLWidget::getIgnoreSnapToGrid() const {
867
bool UMLWidget::getIgnoreSnapToGrid() const
802
869
return m_bIgnoreSnapToGrid;
805
void UMLWidget::setSize(int width,int height) {
872
void UMLWidget::setSize(int width, int height)
806
874
// snap to the next larger size that is a multiple of the grid
807
875
if (!m_bIgnoreSnapComponentSizeToGrid
808
&& m_pView -> getSnapComponentSizeToGrid() )
876
&& m_pView -> getSnapComponentSizeToGrid()) {
810
877
// integer divisions
811
878
int numX = width / m_pView->getSnapX();
812
879
int numY = height / m_pView->getSnapY();
817
884
height = (numY + 1) * m_pView->getSnapY();
820
QCanvasRectangle::setSize(width,height);
887
Q3CanvasRectangle::setSize(width, height);
823
void UMLWidget::updateComponentSize() {
890
void UMLWidget::updateComponentSize()
824
892
if (m_pDoc->loading())
826
894
const QSize minSize = calculateSize();
827
895
const int w = minSize.width();
828
896
const int h = minSize.height();
830
adjustAssocs( getX(), getY() ); // adjust assoc lines
898
adjustAssocs(getX(), getY()); // adjust assoc lines
833
void UMLWidget::setDefaultFontMetrics(UMLWidget::FontType fontType) {
901
void UMLWidget::setDefaultFontMetrics(UMLWidget::FontType fontType)
834
903
setupFontType(m_Font, fontType);
835
904
setFontMetrics(fontType, QFontMetrics(m_Font));
838
void UMLWidget::setupFontType(QFont &font, UMLWidget::FontType fontType) {
907
void UMLWidget::setupFontType(QFont &font, UMLWidget::FontType fontType)
841
911
font.setBold(false);
842
912
font.setItalic(false);
884
void UMLWidget::setDefaultFontMetrics(UMLWidget::FontType fontType, QPainter &painter) {
954
void UMLWidget::setDefaultFontMetrics(UMLWidget::FontType fontType, QPainter &painter)
885
956
setupFontType(m_Font, fontType);
886
957
painter.setFont(m_Font);
887
958
setFontMetrics(fontType, painter.fontMetrics());
890
961
//FIXME this is probably the source of problems with widgets not being wide enough
891
QFontMetrics &UMLWidget::getFontMetrics(UMLWidget::FontType fontType) {
962
QFontMetrics &UMLWidget::getFontMetrics(UMLWidget::FontType fontType)
892
964
if (m_pFontMetrics[fontType] == 0) {
893
965
setDefaultFontMetrics(fontType);
895
967
return *m_pFontMetrics[fontType];
898
void UMLWidget::setFontMetrics(UMLWidget::FontType fontType, QFontMetrics fm) {
970
void UMLWidget::setFontMetrics(UMLWidget::FontType fontType, QFontMetrics fm)
899
972
delete m_pFontMetrics[fontType];
900
973
m_pFontMetrics[fontType] = new QFontMetrics(fm);
903
QFont UMLWidget::getFont() const {
976
QFont UMLWidget::getFont() const
907
void UMLWidget::setFont( QFont font ) {
981
void UMLWidget::setFont(QFont font)
909
984
forceUpdateFontMetrics(0);
910
985
if (m_pDoc->loading())
915
void UMLWidget::forceUpdateFontMetrics(QPainter *painter) {
990
void UMLWidget::forceUpdateFontMetrics(QPainter *painter)
916
992
if (painter == 0) {
917
993
for (int i = 0; i < (int)UMLWidget::FT_INVALID; ++i) {
918
if (m_pFontMetrics[(UMLWidget::FontType)i]!=0)
994
if (m_pFontMetrics[(UMLWidget::FontType)i] != 0)
919
995
setDefaultFontMetrics((UMLWidget::FontType)i);
922
998
for (int i2 = 0; i2 < (int)UMLWidget::FT_INVALID; ++i2) {
923
if (m_pFontMetrics[(UMLWidget::FontType)i2]!=0)
924
setDefaultFontMetrics((UMLWidget::FontType)i2,*painter);
999
if (m_pFontMetrics[(UMLWidget::FontType)i2] != 0)
1000
setDefaultFontMetrics((UMLWidget::FontType)i2, *painter);
927
1003
// calculate the size, based on the new font metric
928
1004
updateComponentSize();
931
void UMLWidget::setShowStereotype(bool _status) {
1007
void UMLWidget::setShowStereotype(bool _status)
932
1009
m_bShowStereotype = _status;
933
1010
updateComponentSize();
937
bool UMLWidget::getShowStereotype() const {
1014
bool UMLWidget::getShowStereotype() const
938
1016
return m_bShowStereotype;
941
void UMLWidget::moveEvent(QMoveEvent* /*me*/) {
1019
void UMLWidget::moveEvent(QMoveEvent* /*me*/)
944
void UMLWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
1023
void UMLWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
946
1026
Call after required actions in child class.
947
1027
Type must be set in the child class.
949
1029
WidgetBase::saveToXMI(qDoc, qElement);
950
qElement.setAttribute( "xmi.id", ID2STR(getID()) );
951
qElement.setAttribute( "font", m_Font.toString() );
952
qElement.setAttribute( "usefillcolor", m_bUseFillColour );
953
qElement.setAttribute( "x", getX() );
954
qElement.setAttribute( "y", getY() );
955
qElement.setAttribute( "width", getWidth() );
956
qElement.setAttribute( "height", getHeight() );
1030
qElement.setAttribute("xmi.id", ID2STR(getID()));
1031
qElement.setAttribute("font", m_Font.toString());
1032
qElement.setAttribute("usefillcolor", m_bUseFillColour);
1033
qElement.setAttribute("x", getX());
1034
qElement.setAttribute("y", getY());
1035
qElement.setAttribute("width", getWidth());
1036
qElement.setAttribute("height", getHeight());
957
1037
// for consistency the following attributes now use american spelling for "color"
958
qElement.setAttribute( "usesdiagramfillcolor", m_bUsesDiagramFillColour );
959
qElement.setAttribute( "usesdiagramusefillcolor", m_bUsesDiagramUseFillColour );
1038
qElement.setAttribute("usesdiagramfillcolor", m_bUsesDiagramFillColour);
1039
qElement.setAttribute("usesdiagramusefillcolor", m_bUsesDiagramUseFillColour);
960
1040
if (m_bUsesDiagramFillColour) {
961
qElement.setAttribute( "fillcolor", "none" );
1041
qElement.setAttribute("fillcolor", "none");
963
qElement.setAttribute( "fillcolor", m_FillColour.name() );
1043
qElement.setAttribute("fillcolor", m_FillColour.name());
965
1045
qElement.setAttribute("isinstance", m_bIsInstance);
966
1046
if (!m_instanceName.isEmpty())
969
1049
qElement.setAttribute("showstereotype", m_bShowStereotype);
972
bool UMLWidget::loadFromXMI( QDomElement & qElement ) {
1052
bool UMLWidget::loadFromXMI(QDomElement & qElement)
973
1054
WidgetBase::loadFromXMI(qElement);
974
QString id = qElement.attribute( "xmi.id", "-1" );
975
QString font = qElement.attribute( "font", "" );
976
QString usefillcolor = qElement.attribute( "usefillcolor", "1" );
977
QString x = qElement.attribute( "x", "0" );
978
QString y = qElement.attribute( "y", "0" );
979
QString h = qElement.attribute( "height", "0" );
980
QString w = qElement.attribute( "width", "0" );
1055
QString id = qElement.attribute("xmi.id", "-1");
1056
QString font = qElement.attribute("font", "");
1057
QString usefillcolor = qElement.attribute("usefillcolor", "1");
1058
QString x = qElement.attribute("x", "0");
1059
QString y = qElement.attribute("y", "0");
1060
QString h = qElement.attribute("height", "0");
1061
QString w = qElement.attribute("width", "0");
982
1063
For the next three *color attributes, there was a mixup of american and english spelling for "color".
983
1064
So first we need to keep backward compatibility and try to retrieve the *colour attribute.
984
1065
Next we overwrite this value if we find a *color, otherwise the former *colour is kept.
986
QString fillColour = qElement.attribute( "fillcolour", "none" );
987
fillColour = qElement.attribute( "fillcolor", fillColour );
988
QString usesDiagramFillColour = qElement.attribute( "usesdiagramfillcolour", "1" );
989
usesDiagramFillColour = qElement.attribute( "usesdiagramfillcolor", usesDiagramFillColour );
990
QString usesDiagramUseFillColour = qElement.attribute( "usesdiagramusefillcolour", "1" );
991
usesDiagramUseFillColour = qElement.attribute( "usesdiagramusefillcolor", usesDiagramUseFillColour );
1067
QString fillColour = qElement.attribute("fillcolour", "none");
1068
fillColour = qElement.attribute("fillcolor", fillColour);
1069
QString usesDiagramFillColour = qElement.attribute("usesdiagramfillcolour", "1");
1070
usesDiagramFillColour = qElement.attribute("usesdiagramfillcolor", usesDiagramFillColour);
1071
QString usesDiagramUseFillColour = qElement.attribute("usesdiagramusefillcolour", "1");
1072
usesDiagramUseFillColour = qElement.attribute("usesdiagramusefillcolor", usesDiagramUseFillColour);
993
1074
m_nId = STR2ID(id);
995
if( !font.isEmpty() ) {
1076
if (!font.isEmpty()) {
996
1077
//QFont newFont;
997
1078
m_Font.fromString(font);
998
1079
//setFont(newFont);
1000
kWarning() << "Using default font " << m_Font.toString()
1081
uWarning() << "Using default font " << m_Font.toString()
1001
1082
<< " for widget with xmi.id " << ID2STR(m_nId) << endl;
1002
1083
//setFont( m_Font );
1004
1085
m_bUseFillColour = (bool)usefillcolor.toInt();
1005
1086
m_bUsesDiagramFillColour = (bool)usesDiagramFillColour.toInt();
1006
1087
m_bUsesDiagramUseFillColour = (bool)usesDiagramUseFillColour.toInt();
1007
setSize( w.toInt(), h.toInt() );
1088
setSize(w.toInt(), h.toInt());
1010
1091
if (fillColour != "none") {
1011
1092
m_FillColour = QColor(fillColour);