listpopupmenu.cpp 74.9 KB
Newer Older
1 2 3 4 5 6
/***************************************************************************
 *   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.                                   *
 *                                                                         *
Oliver Kellogg's avatar
Oliver Kellogg committed
7
 *   copyright (C) 2002-2014                                               *
Ralf Habacker's avatar
Ralf Habacker committed
8
 *   Umbrello UML Modeller Authors <umbrello-devel@kde.org>                *
9 10 11 12 13 14
 ***************************************************************************/

// own header
#include "listpopupmenu.h"

// app includes
15
#include "activitywidget.h"
16
#include "associationline.h"
17
#include "associationwidget.h"
18
#include "category.h"
19
#include "classifier.h"
20 21 22
#include "classifierwidget.h"
#include "combinedfragmentwidget.h"
#include "debug_utils.h"
23 24 25
#include "floatingtextwidget.h"
#include "folder.h"
#include "forkjoinwidget.h"
26
#include "layoutgenerator.h"
27 28
#include "model_utils.h"
#include "objectnodewidget.h"
29
#include "objectwidget.h"
Oliver Kellogg's avatar
Oliver Kellogg committed
30
#include "notewidget.h"
31
#include "pinportbase.h"
32 33 34 35 36
#include "preconditionwidget.h"
#include "signalwidget.h"
#include "statewidget.h"
#include "uml.h"
#include "umldoc.h"
37
#include "umlscene.h"
38
#include "umlview.h"
Oliver Kellogg's avatar
Oliver Kellogg committed
39 40
#include "umllistview.h"
#include "umllistviewitem.h"
41
#include "widget_utils.h"
42
#include "widgetbase.h"
43

44
// kde includes
45
#include <KLocalizedString>
46 47
#include <kactioncollection.h>

48 49
DEBUG_REGISTER_DISABLED(ListPopupMenu)

50 51
const bool CHECKABLE = true;

52 53 54 55 56
/**
 * Constructs the popup menu for a UMLView (diagram).
 *
 * @param parent   The parent to ListPopupMenu.
 * @param type     The type of menu to display.
57
 * @param view     The UMLView object
58
 */
59

Andi Fischer's avatar
Andi Fischer committed
60
ListPopupMenu::ListPopupMenu(QWidget *parent, MenuType type, UMLView * view)
61 62 63 64 65
#if QT_VERSION >= 0x050000
    : QMenu(parent),
#else
    : KMenu(parent),
#endif
66
    m_isListView(false)
67
{
Sharan Rao's avatar
Sharan Rao committed
68 69 70
    m_TriggerObject.m_View = view;
    m_TriggerObjectType = tot_View;
    setupMenu(type);
71
    setupActionsData();
72 73 74 75 76 77 78
}

/**
 * Constructs the popup menu for a WidgetBase with customized menu type.
 *
 * @param parent   The parent to ListPopupMenu.
 * @param type     The type of menu to display.
79
 * @param widget   The WidgetBase object.
80 81
 */
ListPopupMenu::ListPopupMenu(QWidget *parent, MenuType type, WidgetBase *widget)
82 83 84 85 86
#if QT_VERSION >= 0x050000
    : QMenu(parent),
#else
    : KMenu(parent),
#endif
87
    m_isListView(false)
88 89 90 91
{
    m_TriggerObject.m_Widget = widget;
    m_TriggerObjectType = tot_Widget;
    setupMenu(type);
92
    setupActionsData();
93 94
}

95 96 97 98 99 100 101
/**
 * Constructs the popup menu for a tree list view item.
 *
 * @param parent   The parent to ListPopupMenu.
 * @param type     The type of menu to display.
 * @param object   The UMLObject of the ListViewItem
 */
102
ListPopupMenu::ListPopupMenu(QWidget *parent, UMLListViewItem::ListViewType type, UMLObject* object)
103 104 105 106 107
#if QT_VERSION >= 0x050000
    : QMenu(parent),
#else
    : KMenu(parent),
#endif
108
    m_isListView(true)
109
{
Sharan Rao's avatar
Sharan Rao committed
110 111
    m_TriggerObject.m_Object = object;
    m_TriggerObjectType = tot_Object;
Andi Fischer's avatar
Andi Fischer committed
112
    MenuType mt = mt_Undefined;
113 114
    switch(type) {
    case UMLListViewItem::lvt_Logical_View:
115 116 117
        mt = mt_Logical_View;
        break;

118
    case UMLListViewItem::lvt_UseCase_View:
119 120 121
        mt = mt_UseCase_View;
        break;

122
    case UMLListViewItem::lvt_Component_View:
123 124 125
        mt = mt_Component_View;
        break;

126
    case UMLListViewItem::lvt_EntityRelationship_Model:
127 128 129
        mt = mt_EntityRelationship_Model;
        break;

130
    case UMLListViewItem::lvt_Deployment_View:
131 132 133
        mt = mt_Deployment_View;
        break;

134
    case UMLListViewItem::lvt_Logical_Folder:
135 136 137
        mt = mt_Logical_Folder;
        break;

138
    case UMLListViewItem::lvt_UseCase_Folder:
139 140 141
        mt = mt_UseCase_Folder;
        break;

142
    case UMLListViewItem::lvt_Component_Folder:
143 144 145
        mt = mt_Component_Folder;
        break;

146
    case UMLListViewItem::lvt_Deployment_Folder:
147 148 149
        mt = mt_Deployment_Folder;
        break;

150
    case UMLListViewItem::lvt_EntityRelationship_Folder:
151 152 153
        mt = mt_EntityRelationship_Folder;
        break;

154
    case UMLListViewItem::lvt_UseCase_Diagram:
155 156 157
        mt = mt_UseCase_Diagram;
        break;

158
    case UMLListViewItem::lvt_Class_Diagram:
159 160 161
        mt = mt_Class_Diagram;
        break;

162
    case UMLListViewItem::lvt_Collaboration_Diagram:
163 164 165
        mt = mt_Collaboration_Diagram;
        break;

166
    case UMLListViewItem::lvt_Sequence_Diagram:
167 168 169
        mt = mt_Sequence_Diagram;
        break;

170
    case UMLListViewItem::lvt_State_Diagram:
171 172 173
        mt = mt_State_Diagram;
        break;

174
    case UMLListViewItem::lvt_Activity_Diagram:
175 176 177
        mt = mt_Activity_Diagram;
        break;

178
    case UMLListViewItem::lvt_Component_Diagram:
179 180 181
        mt = mt_Component_Diagram;
        break;

182
    case UMLListViewItem::lvt_Deployment_Diagram:
183 184 185
        mt = mt_Deployment_Diagram;
        break;

186
    case UMLListViewItem::lvt_EntityRelationship_Diagram:
187 188 189
        mt = mt_EntityRelationship_Diagram;
        break;

190
    case UMLListViewItem::lvt_Actor:
191 192 193
        mt = mt_Actor;
        break;

194
    case UMLListViewItem::lvt_UseCase:
195 196 197
        mt = mt_UseCase;
        break;

198
    case UMLListViewItem::lvt_Class:
199 200 201
        mt = mt_Class;
        break;

202
    case UMLListViewItem::lvt_Package:
203 204 205
        mt = mt_Package;
        break;

206
    case UMLListViewItem::lvt_Subsystem:
207 208 209
        mt = mt_Subsystem;
        break;

210
    case UMLListViewItem::lvt_Component:
211 212 213
        mt = mt_Component;
        break;

Oliver Kellogg's avatar
Oliver Kellogg committed
214 215 216 217
    case UMLListViewItem::lvt_Port:
        mt = mt_Port;
        break;

218
    case UMLListViewItem::lvt_Node:
219 220 221
        mt = mt_Node;
        break;

222
    case UMLListViewItem::lvt_Artifact:
223 224 225
        mt = mt_Artifact;
        break;

226
    case UMLListViewItem::lvt_Interface:
227 228 229
        mt = mt_Interface;
        break;

230
    case UMLListViewItem::lvt_Enum:
231 232 233
        mt = mt_Enum;
        break;

234
    case UMLListViewItem::lvt_EnumLiteral:
235 236 237
        mt = mt_EnumLiteral;
        break;

238
    case UMLListViewItem::lvt_Datatype:
239 240 241
        mt = mt_Datatype;
        break;

242
    case UMLListViewItem::lvt_Datatype_Folder:
243 244 245
        // let it mt_Undefined
        break;

246
    case UMLListViewItem::lvt_Attribute:
247 248 249
        mt = mt_Attribute;
        break;

250
    case UMLListViewItem::lvt_Operation:
251 252 253
        mt = mt_Operation;
        break;

254
    case UMLListViewItem::lvt_Template:
255 256 257
        mt = mt_Template;
        break;

258
    case UMLListViewItem::lvt_Category:
259 260 261
        mt = mt_Category;
        break;

262
    case UMLListViewItem::lvt_Entity:
263 264 265
        mt = mt_Entity;
        break;

266
    case UMLListViewItem::lvt_EntityAttribute:
267 268 269
        mt = mt_EntityAttribute;
        break;

270
    case UMLListViewItem::lvt_UniqueConstraint:
271 272 273
        mt = mt_UniqueConstraint;
        break;

274
    case UMLListViewItem::lvt_PrimaryKeyConstraint:
275 276 277
        mt = mt_PrimaryKeyConstraint;
        break;

278
    case UMLListViewItem::lvt_ForeignKeyConstraint:
279 280 281
        mt = mt_ForeignKeyConstraint;
        break;

282
    case UMLListViewItem::lvt_CheckConstraint:
Sharan Rao's avatar
Sharan Rao committed
283 284 285
        mt = mt_CheckConstraint;
        break;

286
    case UMLListViewItem::lvt_Model:
287 288 289
        mt = mt_Model;
        break;

290 291 292 293
    case UMLListViewItem::lvt_Properties:
        mt = mt_Properties;
        break;

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    case UMLListViewItem::lvt_Properties_AutoLayout:
        mt = mt_Properties_AutoLayout;
        break;

    case UMLListViewItem::lvt_Properties_Class:
        mt = mt_Properties_Class;
        break;

    case UMLListViewItem::lvt_Properties_CodeImport:
        mt = mt_Properties_CodeImport;
        break;

    case UMLListViewItem::lvt_Properties_CodeGeneration:
        mt = mt_Properties_CodeGeneration;
        break;

    case UMLListViewItem::lvt_Properties_CodeViewer:
        mt = mt_Properties_CodeViewer;
        break;

    case UMLListViewItem::lvt_Properties_Font:
        mt = mt_Properties_Font;
        break;

    case UMLListViewItem::lvt_Properties_General:
        mt = mt_Properties_General;
        break;

    case UMLListViewItem::lvt_Properties_UserInterface:
        mt = mt_Properties_UserInterface;
        break;

326
    default:
327 328
        uWarning() << "unhandled ListViewType "
                   << UMLListViewItem::toString(type);
329
        break;
330 331
    }
    setupMenu(mt);
332
    setupActionsData();
333 334
}

335
/**
336
 * Constructs the popup menu for a scene widget.
337 338
 *
 * @param parent   The parent to ListPopupMenu.
339
 * @param object   The WidgetBase to represent a menu for.
340
 * @param multi    True if multiple items are selected.
341
 * @param uniqueType The type of widget shared by all selected widgets
342
 */
343
ListPopupMenu::ListPopupMenu(QWidget * parent, WidgetBase * object, bool multi, WidgetBase::WidgetType uniqueType)
344 345 346 347 348
#if QT_VERSION >= 0x050000
    : QMenu(parent),
#else
    : KMenu(parent),
#endif
349
    m_isListView(false)
350
{
Sharan Rao's avatar
Sharan Rao committed
351 352
    m_TriggerObject.m_Widget = object;
    m_TriggerObjectType = tot_Widget;
353

Andi Fischer's avatar
Andi Fischer committed
354
    if (!object)
355 356
        return;

Andi Fischer's avatar
Andi Fischer committed
357
    if (multi) {
358
        insertMultiSelectionMenu(uniqueType);
359 360 361
    } else {
        insertSingleSelectionMenu(object);
    }
362

363 364 365
    bool bCutState = UMLApp::app()->isCutCopyState();
    setActionEnabled(mt_Cut, bCutState);
    setActionEnabled(mt_Copy, bCutState);
Oliver Kellogg's avatar
Oliver Kellogg committed
366 367 368 369 370 371 372
    bool pasteAvailable = false;
    if (object->baseType() == WidgetBase::wt_Note &&
            UMLApp::app()->listView()->startedCopy()) {
        NoteWidget::s_pCurrentNote = static_cast<NoteWidget*>(object);
        pasteAvailable = true;
    }
    setActionEnabled(mt_Paste, pasteAvailable);
373 374 375 376 377 378 379 380 381 382
    setupActionsData();
}

/**
 * Standard destructor.
 */
ListPopupMenu::~ListPopupMenu()
{
    foreach (QAction* action, m_actions) {
        delete action;
383
    }
384 385
    m_actions.clear();
}
386

387 388 389 390 391 392 393 394
/**
 * Inserts the menu actions for a widget
 *
 * @param WidgetBase* object
 */
void ListPopupMenu::insertSingleSelectionMenu(WidgetBase* object)
{
    WidgetBase::WidgetType type = object->baseType();
Andi Fischer's avatar
Andi Fischer committed
395
    switch (type) {
396 397
    case WidgetBase::wt_Actor:
    case WidgetBase::wt_UseCase:
398
        insertSubMenuColor(object->useFillColor());
399
        insertStdItems(true, type);
400 401 402
        insert(mt_Rename);
        insert(mt_Change_Font);
        insert(mt_Properties);
403 404
        break;

405
    case WidgetBase::wt_Category:
Sharan Rao's avatar
Sharan Rao committed
406
       {
407 408 409
#if QT_VERSION >= 0x050000
         QMenu* m = makeCategoryTypeMenu(
#else
410
         KMenu* m = makeCategoryTypeMenu(
411
#endif
412
                        static_cast<UMLCategory*>(object->umlObject()));
413 414
         m->setTitle(i18n("Category Type"));
         addMenu(m);
415
         insertSubMenuColor(object->useFillColor());
Sharan Rao's avatar
Sharan Rao committed
416
         insertStdItems(true, type);
417 418
         insert(mt_Rename);
         insert(mt_Change_Font);
Sharan Rao's avatar
Sharan Rao committed
419 420
         break;
       }
421 422
    case WidgetBase::wt_Class:
    case WidgetBase::wt_Interface:
423 424 425
        makeClassifierPopup(static_cast<ClassifierWidget*>(object));
        break;

426
    case WidgetBase::wt_Enum:
427
        insertSubMenuNew(mt_Enum);
428
        insertSubMenuColor(object->useFillColor());
429
        insertStdItems(true, type);
430 431 432
        insert(mt_Rename);
        insert(mt_Change_Font);
        insert(mt_Properties);
433 434
        break;

435
    case WidgetBase::wt_Entity:
436
        insertSubMenuNew(mt_Entity);
437
        insertSubMenuColor(object->useFillColor());
438
        insertStdItems(true, type);
439 440 441
        insert(mt_Rename);
        insert(mt_Change_Font);
        insert(mt_Properties);
442 443
        break;

444 445 446 447 448
    case WidgetBase::wt_Datatype:
    case WidgetBase::wt_Package:
    case WidgetBase::wt_Component:
    case WidgetBase::wt_Node:
    case WidgetBase::wt_Artifact:
449
        insertSubMenuColor(object->useFillColor());
450
        insertStdItems(false, type);
451 452 453
        insert(mt_Rename);
        insert(mt_Change_Font);
        insert(mt_Properties);
454 455
        break;

Oliver Kellogg's avatar
Oliver Kellogg committed
456 457
    case WidgetBase::wt_Port:
        insertSubMenuColor(object->useFillColor());
458
        insertStdItems(false);
Oliver Kellogg's avatar
Oliver Kellogg committed
459
        insert(mt_NameAsTooltip, i18n("Name as Tooltip"), CHECKABLE);
460
        {
461 462
            PinPortBase *pW = static_cast<PinPortBase*>(object);
            FloatingTextWidget *ft = pW->floatingTextWidget();
463 464 465
            if (ft == NULL)
                m_actions[mt_NameAsTooltip]->setChecked(true);
        }
Oliver Kellogg's avatar
Oliver Kellogg committed
466 467 468
        insert(mt_Properties);
        break;

469
    case WidgetBase::wt_Object:
470 471
        {
            //Used for sequence diagram and collaboration diagram widgets
472
            insertSubMenuColor(object->useFillColor());
473 474
            if (object->umlScene() &&
                object->umlScene()->type() == Uml::DiagramType::Sequence) {
475
                addSeparator();
Andi Fischer's avatar
Andi Fischer committed
476
                MenuType tabUp = mt_Up;
477 478
                insert(mt_Up, Icon_Utils::SmallIcon(Icon_Utils::it_Arrow_Up), i18n("Move Up"));
                insert(mt_Down, Icon_Utils::SmallIcon(Icon_Utils::it_Arrow_Down), i18n("Move Down"));
479
                if (!(static_cast<ObjectWidget*>(object))->canTabUp()) {
480 481
                    setActionEnabled(tabUp, false);
                }
482
            }
483 484 485 486 487
            insertStdItems(true, type);
            insert(mt_Rename, i18n("Rename Class..."));
            insert(mt_Rename_Object, i18n("Rename Object..."));
            insert(mt_Change_Font);
            insert(mt_Properties);
488 489 490
        }
        break;

491
    case WidgetBase::wt_Message:
492
        insertStdItems(false, type);
493
        //insert(mt_Change_Font);
494
        //insert(mt_Operation, Icon_Utils::SmallIcon(Icon_Utils::it_Operation_New), i18n("New Operation..."));
495
        //insert(mt_Select_Operation, i18n("Select Operation..."));
496 497
        break;

498
    case WidgetBase::wt_Note:
499
        insertSubMenuColor(object->useFillColor());
500 501 502 503
        addSeparator();
        insert(mt_Cut);
        insert(mt_Copy);
        insert(mt_Paste);
504
        insert(mt_Clear, Icon_Utils::SmallIcon(Icon_Utils::it_Clear), i18nc("clear note", "Clear"));
505 506 507 508
        addSeparator();
        insert(mt_Rename, i18n("Change Text..."));
        insert(mt_Delete);
        insert(mt_Change_Font);
509 510
        break;

511
    case WidgetBase::wt_Box:
512
        insertStdItems(false, type);
513
        insert(mt_Line_Color);
514
        break;
515

516
    case WidgetBase::wt_State:
517
        {
518
            StateWidget* pState = static_cast< StateWidget *>(object);
519
            if (pState->stateType() == StateWidget::Normal) {
520 521
                insertSubMenuNew(mt_New_Activity);
            }
522
            insertSubMenuColor(object->useFillColor());
523
            insertStdItems(false, type);
Oliver Kellogg's avatar
Oliver Kellogg committed
524
            switch (pState->stateType()) {
525 526 527 528 529 530 531 532 533 534 535 536 537 538
            case StateWidget::Normal:
                insert(mt_Rename, i18n("Change State Name..."));
                insert(mt_Change_Font);
                insert(mt_Properties);
                break;
            case StateWidget::Fork:
            case StateWidget::Join:
                if (pState->drawVertical())
                    insert(mt_Flip, i18n("Flip Horizontal"));
                else
                    insert(mt_Flip, i18n("Flip Vertical"));
                break;
            default:
                break;
539
            }
540
    }
541 542
        break;

543
    case WidgetBase::wt_ForkJoin:
544 545
        {
            ForkJoinWidget *pForkJoin = static_cast<ForkJoinWidget*>(object);
Andi Fischer's avatar
Andi Fischer committed
546
            if (pForkJoin->orientation() == Qt::Vertical) {
547
                insert(mt_Flip, i18n("Flip Horizontal"));
548 549
            }
            else {
550
                insert(mt_Flip, i18n("Flip Vertical"));
551
            }
552 553
            m_actions[mt_Fill_Color] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Color_Fill),
                                                 i18n("Fill Color..."));
554 555
        }
        break;
556

557
    case WidgetBase::wt_Activity:
558 559
        {
            ActivityWidget* pActivity = static_cast<ActivityWidget *>(object);
560
            if(pActivity->activityType() == ActivityWidget::Normal
561 562
              || pActivity->activityType() == ActivityWidget::Invok
              || pActivity->activityType() == ActivityWidget::Param) {
563
                insertSubMenuColor(object->useFillColor());
564 565
            }
            insertStdItems(false, type);
566
            if(pActivity->activityType() == ActivityWidget::Normal
567 568
              || pActivity->activityType() == ActivityWidget::Invok
              || pActivity->activityType() == ActivityWidget::Param) {
569 570 571 572
                insert(mt_Rename, i18n("Change Activity Name..."));
                insert(mt_Change_Font);
                insert(mt_Properties);
            }
573 574 575
        }
        break;

576
    case WidgetBase::wt_ObjectNode:
577 578
        {
            ObjectNodeWidget* objWidget = static_cast<ObjectNodeWidget *>(object);
579 580 581
            if (objWidget->objectNodeType() == ObjectNodeWidget::Buffer
              || objWidget->objectNodeType() == ObjectNodeWidget::Data
              || objWidget->objectNodeType() == ObjectNodeWidget::Flow) {
582
                insertSubMenuColor(object->useFillColor());
583 584
            }
            insertStdItems(false, type);
585 586 587
            if (objWidget->objectNodeType() == ObjectNodeWidget::Buffer
                || objWidget->objectNodeType() == ObjectNodeWidget::Data
                || objWidget->objectNodeType() == ObjectNodeWidget::Flow) {
588 589 590 591
                insert(mt_Rename, i18n("Change Object Node Name..."));
                insert(mt_Change_Font);
                insert(mt_Properties);
            }
592 593
        }
        break;
594

595 596 597 598
    case WidgetBase::wt_Pin:
    case WidgetBase::wt_Signal:
    case WidgetBase::wt_FloatingDashLine:
    case WidgetBase::wt_Precondition:
599
        insertSubMenuColor(object->useFillColor());
600 601 602 603
        addSeparator();
        insert(mt_Cut);
        insert(mt_Copy);
        insert(mt_Paste);
604
        insert(mt_Clear, Icon_Utils::SmallIcon(Icon_Utils::it_Clear), i18nc("clear precondition", "Clear"));
605 606
        addSeparator();
        insert(mt_Rename, i18n("Change Text..."));
607 608 609 610 611 612 613
        if (type == WidgetBase::wt_Pin) {
            insert(mt_NameAsTooltip, i18n("Name as Tooltip"), CHECKABLE);
            PinPortBase *pW = static_cast<PinPortBase*>(object);
            FloatingTextWidget *ft = pW->floatingTextWidget();
            if (ft == NULL)
                m_actions[mt_NameAsTooltip]->setChecked(true);
        }
614 615
        insert(mt_Delete);
        insert(mt_Change_Font);
616 617
        break;

618
    case WidgetBase::wt_CombinedFragment:
619
        // for alternative and parallel combined fragments
620 621
        if ((static_cast<CombinedFragmentWidget*>(object))->combinedFragmentType() == CombinedFragmentWidget::Alt ||
            (static_cast<CombinedFragmentWidget*>(object))->combinedFragmentType() == CombinedFragmentWidget::Par) {
622 623
            insert(mt_AddInteractionOperand, i18n("Add Interaction Operand"));
            addSeparator();
624
        }
625
        insertSubMenuColor(object->useFillColor());
626 627 628 629
        addSeparator();
        insert(mt_Cut);
        insert(mt_Copy);
        insert(mt_Paste);
630
        insert(mt_Clear, Icon_Utils::SmallIcon(Icon_Utils::it_Clear), i18nc("clear combined fragment", "Clear"));
631 632 633 634
        addSeparator();
        insert(mt_Rename, i18n("Change Text..."));
        insert(mt_Delete);
        insert(mt_Change_Font);
635 636
        break;

637
    case WidgetBase::wt_Text:
638
        switch((static_cast<FloatingTextWidget*>(object))->textRole()) {
639
        case Uml::TextRole::MultiB:
Ralf Habacker's avatar
Ralf Habacker committed
640
            insertAssociationTextItem(i18n("Change Multiplicity..."), mt_Rename_MultiB);
641
            break;
642
        case Uml::TextRole::MultiA:
Ralf Habacker's avatar
Ralf Habacker committed
643
            insertAssociationTextItem(i18n("Change Multiplicity..."), mt_Rename_MultiA);
644
            break;
645
        case Uml::TextRole::Name:
Ralf Habacker's avatar
Ralf Habacker committed
646
            insertAssociationTextItem(i18n("Change Name"), mt_Rename_Name);
647
            break;
648
        case Uml::TextRole::RoleAName:
Ralf Habacker's avatar
Ralf Habacker committed
649
            insertAssociationTextItem(i18n("Change Role A Name..."), mt_Rename_RoleAName);
650
            break;
651
        case Uml::TextRole::RoleBName:
Ralf Habacker's avatar
Ralf Habacker committed
652
            insertAssociationTextItem(i18n("Change Role B Name..."), mt_Rename_RoleBName);
653
            break;
654 655
        case Uml::TextRole::ChangeA:
        case Uml::TextRole::ChangeB:
656 657 658
            insert(mt_Change_Font);
            insert(mt_Reset_Label_Positions);
            insert(mt_Properties);
659 660
            break;

661 662 663 664
        case Uml::TextRole::Coll_Message_Self:
        case Uml::TextRole::Coll_Message:
        case Uml::TextRole::Seq_Message_Self:
        case Uml::TextRole::Seq_Message:
665
            insert(mt_Change_Font);
666
            insert(mt_Operation, Icon_Utils::SmallIcon(Icon_Utils::it_Operation_New), i18n("New Operation..."));
667
            insert(mt_Select_Operation, i18n("Select Operation..."));
668 669
            break;

670
        case Uml::TextRole::Floating:
671 672
        default:
            insertStdItems(false, type);
673 674
            insert(mt_Rename, i18n("Change Text..."));
            insert(mt_Change_Font);
675 676 677 678
            break;
        }
        break;
    default:
679
        uWarning() << "unhandled WidgetType " << WidgetBase::toString(type);
680 681 682 683
        break;
    }//end switch
}

684
/**
685
 * Inserts the menu actions that work on the whole selection of widgets
686
 */
687
void ListPopupMenu::insertMultiSelectionMenu(WidgetBase::WidgetType uniqueType)
688
{
689 690
    insertSubMenuAlign();

691 692 693
#if QT_VERSION >= 0x050000
    QMenu* color = new QMenu(i18nc("color menu", "Color"), this);
#else
694
    KMenu* color = new KMenu(i18nc("color menu", "Color"), this);
695
#endif
696 697
    insert(mt_Line_Color_Selection, color, Icon_Utils::SmallIcon(Icon_Utils::it_Color_Line), i18n("Line Color..."));
    insert(mt_Fill_Color_Selection, color, Icon_Utils::SmallIcon(Icon_Utils::it_Color_Fill), i18n("Fill Color..."));
698 699 700
    insert(mt_Set_Use_Fill_Color_Selection, color, i18n("Use Fill Color"));
    insert(mt_Unset_Use_Fill_Color_Selection, color, i18n("No Fill Color"));

701 702 703 704 705 706
    // Add menu actions specific to classifiers
    if (uniqueType == WidgetBase::wt_Class ||
        uniqueType == WidgetBase::wt_Interface) {
        makeMultiClassifierShowPopup(uniqueType);
    }

707 708 709 710 711 712 713 714 715 716 717 718
    addMenu(color);

    addSeparator();
    insert(mt_Cut);
    insert(mt_Copy);

    addSeparator();
    insert(mt_Clone);
    insert(mt_Delete);
    insert(mt_Resize, i18n("Resize"));

    addSeparator();
719
    insert(mt_Change_Font_Selection, Icon_Utils::SmallIcon(Icon_Utils::it_Change_Font), i18n("Change Font..."));
720 721
}

722

723 724 725
/**
 * Shortcut for the frequently used addAction() calls.
 *
Andi Fischer's avatar
Andi Fischer committed
726
 * @param m   The MenuType for which to insert a menu item.
727
 */
Andi Fischer's avatar
Andi Fischer committed
728
void ListPopupMenu::insert(MenuType m)
729 730 731
{
    switch (m) {
    case mt_Properties:
732
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Properties), i18n("Properties"));
733 734
        break;
    case mt_Rename:
735
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Rename), i18n("Rename..."));
736
        break;
737 738 739
    case mt_Show:
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Show), i18n("Show"));
        break;
740
    case mt_Delete:
741
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Delete), i18n("Delete"));
742 743
        break;
    case mt_Cut:
744
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Cut), i18n("Cut"));
745 746
        break;
    case mt_Copy:
747
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Copy), i18n("Copy"));
748 749
        break;
    case mt_Paste:
750
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Paste), i18n("Paste"));
751 752
        break;
    case mt_Change_Font:
753
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Change_Font), i18n("Change Font..."));
754 755
        break;
    case mt_Line_Color:
756
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Color_Line), i18n("Line Color..."));
757 758
        break;
    case mt_Expand_All:
759
        m_actions[m] = addAction(i18n("Expand All"));
760 761
        break;
    case mt_Collapse_All:
762
        m_actions[m] = addAction(i18n("Collapse All"));
763 764
        break;
    case mt_Clone:
765
        m_actions[m] = addAction(i18nc("duplicate action", "Duplicate"));
766 767
        break;
    case mt_Externalize_Folder:
768
        m_actions[m] = addAction(i18n("Externalize Folder..."));
769 770
        break;
    case mt_Internalize_Folder:
771
        m_actions[m] = addAction(i18n("Internalize Folder"));
772
        break;
773 774 775 776
    case mt_Import_Class:
        m_actions[m] = addAction(Icon_Utils::BarIcon(Icon_Utils::it_Import_File), i18n("Import File(s)..."));
        break;
    case mt_Import_Project:
777
        m_actions[m] = addAction(Icon_Utils::BarIcon(Icon_Utils::it_Import_Project), i18n("Import from Directory..."));
778
        break;
779 780 781 782
    case mt_Reset_Label_Positions:
        m_actions[m] = addAction(i18n("Reset Label Positions"));
        break;
    case mt_New_Parameter:
783
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Parameter_New), i18n("New Parameter..."));
784 785
        break;
    case mt_New_Operation:
Ralf Habacker's avatar
Ralf Habacker committed
786
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Operation_Public_New), i18n("New Operation..."));
787 788
        break;
    case mt_New_Attribute:
789
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Attribute_New), i18n("New Attribute..."));
790 791
        break;
    case mt_New_Template:
792
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Template_New), i18n("New Template..."));
793 794
        break;
    case mt_New_EnumLiteral:
795
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Literal_New), i18n("New Literal..."));
796 797
        break;
    case mt_New_EntityAttribute:
798
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Entity_Attribute_New), i18n("New Entity Attribute..."));
799 800
        break;
    case mt_Export_Image:
801
        m_actions[m] = addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Export_Picture), i18n("Export as Picture..."));
802 803
        break;
    default:
Andi Fischer's avatar
Andi Fischer committed
804
        uWarning() << "called on unimplemented MenuType " << toString(m);
805 806 807 808
        break;
    }
}

809 810 811
/**
 * Shortcut for the frequently used addAction() calls.
 *
Andi Fischer's avatar
Andi Fischer committed
812
 * @param m      The MenuType for which to insert a menu item.
813 814
 * @param menu   The KMenu for which to insert a menu item.
 */
815 816 817
#if QT_VERSION >= 0x050000
void ListPopupMenu::insert(const MenuType m, QMenu* menu)
#else
Andi Fischer's avatar
Andi Fischer committed
818
void ListPopupMenu::insert(const MenuType m, KMenu* menu)
819
#endif
820 821 822
{
    Q_ASSERT(menu != NULL);
    switch (m) {
823
    case mt_Subsystem:
824
        m_actions[m] = menu->addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Subsystem), i18n("Subsystem"));
825 826
        break;
    case mt_Component:
827
        m_actions[m] = menu->addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Component), i18n("Component"));
828
        break;
Oliver Kellogg's avatar
Oliver Kellogg committed
829 830 831
    case mt_Port:
        m_actions[m] = menu->addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Port), i18n("Port"));
        break;
832
    case mt_Artifact:
833
        m_actions[m] = menu->addAction(Icon_Utils::SmallIcon(Icon_Utils::it_Artifact), i18n("Artifact"));
834 835
        break;
    case mt_Component_Diagram:
836
        {
Oliver Kellogg's avatar
Oliver Kellogg committed
837
            QAction* act = UMLApp::app()->actionCollection()->action(QLatin1String("new_component_diagram"));
838
            //don't keep a local copy of pointer which resides somewhere else (in this case - in actionCollection())
839
            //m_actions[m] = act;
840 841
            menu->addAction(act);
        }
842 843
        break;
    case mt_Node: