|
| 1 | +/* |
| 2 | + * Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM) |
| 3 | + * |
| 4 | + * Copyright (C) 2013 Open Education Foundation |
| 5 | + * |
| 6 | + * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour |
| 7 | + * l'Education Numérique en Afrique (GIP ENA) |
| 8 | + * |
| 9 | + * This file is part of OpenBoard. |
| 10 | + * |
| 11 | + * OpenBoard is free software: you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation, version 3 of the License, |
| 14 | + * with a specific linking exception for the OpenSSL project's |
| 15 | + * "OpenSSL" library (or with modified versions of it that use the |
| 16 | + * same license as the "OpenSSL" library). |
| 17 | + * |
| 18 | + * OpenBoard is distributed in the hope that it will be useful, |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | + * GNU General Public License for more details. |
| 22 | + * |
| 23 | + * You should have received a copy of the GNU General Public License |
| 24 | + * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>. |
| 25 | + */ |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +#include "UBGraphicsItem.h" |
| 31 | + |
| 32 | +#include "core/memcheck.h" |
| 33 | + |
| 34 | +#include "domain/UBGraphicsPixmapItem.h" |
| 35 | +#include "domain/UBGraphicsTextItem.h" |
| 36 | +#include "domain/UBGraphicsSvgItem.h" |
| 37 | +#include "domain/UBGraphicsMediaItem.h" |
| 38 | +#include "domain/UBGraphicsStrokesGroup.h" |
| 39 | +#include "domain/UBGraphicsGroupContainerItem.h" |
| 40 | +#include "domain/UBGraphicsWidgetItem.h" |
| 41 | +#include "domain/UBGraphicsScene.h" |
| 42 | +#include "tools/UBGraphicsCurtainItem.h" |
| 43 | +#include "domain/UBGraphicsItemDelegate.h" |
| 44 | + |
| 45 | +UBGraphicsItem::~UBGraphicsItem() |
| 46 | +{ |
| 47 | + if (mDelegate!=NULL) |
| 48 | + delete mDelegate; |
| 49 | +} |
| 50 | + |
| 51 | +void UBGraphicsItem::setDelegate(UBGraphicsItemDelegate* delegate) |
| 52 | +{ |
| 53 | + Q_ASSERT(mDelegate==NULL); |
| 54 | + mDelegate = delegate; |
| 55 | +} |
| 56 | + |
| 57 | +UBGraphicsItemDelegate *UBGraphicsItem::Delegate() const |
| 58 | +{ |
| 59 | + return mDelegate; |
| 60 | +} |
| 61 | + |
| 62 | +void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value) |
| 63 | +{ |
| 64 | + item->setZValue(value); |
| 65 | + item->setData(UBGraphicsItemData::ItemOwnZValue, value); |
| 66 | +} |
| 67 | + |
| 68 | +bool UBGraphicsItem::isFlippable(QGraphicsItem *item) |
| 69 | +{ |
| 70 | + return item->data(UBGraphicsItemData::ItemFlippable).toBool(); |
| 71 | +} |
| 72 | + |
| 73 | +bool UBGraphicsItem::isRotatable(QGraphicsItem *item) |
| 74 | +{ |
| 75 | + return item->data(UBGraphicsItemData::ItemRotatable).toBool(); |
| 76 | +} |
| 77 | + |
| 78 | +bool UBGraphicsItem::isLocked(QGraphicsItem *item) |
| 79 | +{ |
| 80 | + return item->data(UBGraphicsItemData::ItemLocked).toBool(); |
| 81 | +} |
| 82 | + |
| 83 | +bool UBGraphicsItem::isHiddenOnDisplay(QGraphicsItem *item) |
| 84 | +{ |
| 85 | + return item->data(UBGraphicsItemData::ItemIsHiddenOnDisplay).toBool(); |
| 86 | +} |
| 87 | + |
| 88 | +void UBGraphicsItem::remove(bool canUndo) |
| 89 | +{ |
| 90 | + if (Delegate()) |
| 91 | + Delegate()->remove(canUndo); |
| 92 | +} |
| 93 | + |
| 94 | +UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) |
| 95 | +{ |
| 96 | + UBGraphicsItemDelegate *result = 0; |
| 97 | + |
| 98 | + switch (static_cast<int>(pItem->type())) { |
| 99 | + case UBGraphicsPixmapItem::Type : |
| 100 | + result = (static_cast<UBGraphicsPixmapItem*>(pItem))->Delegate(); |
| 101 | + break; |
| 102 | + case UBGraphicsTextItem::Type : |
| 103 | + result = (static_cast<UBGraphicsTextItem*>(pItem))->Delegate(); |
| 104 | + break; |
| 105 | + case UBGraphicsSvgItem::Type : |
| 106 | + result = (static_cast<UBGraphicsSvgItem*>(pItem))->Delegate(); |
| 107 | + break; |
| 108 | + case UBGraphicsMediaItem::Type: |
| 109 | + case UBGraphicsVideoItem::Type: |
| 110 | + case UBGraphicsAudioItem::Type: |
| 111 | + result = (static_cast<UBGraphicsMediaItem*>(pItem))->Delegate(); |
| 112 | + break; |
| 113 | + case UBGraphicsStrokesGroup::Type : |
| 114 | + result = (static_cast<UBGraphicsStrokesGroup*>(pItem))->Delegate(); |
| 115 | + break; |
| 116 | + case UBGraphicsGroupContainerItem::Type : |
| 117 | + result = (static_cast<UBGraphicsGroupContainerItem*>(pItem))->Delegate(); |
| 118 | + break; |
| 119 | + case UBGraphicsWidgetItem::Type : |
| 120 | + result = (static_cast<UBGraphicsWidgetItem*>(pItem))->Delegate(); |
| 121 | + break; |
| 122 | + case UBGraphicsCurtainItem::Type : |
| 123 | + result = (static_cast<UBGraphicsCurtainItem*>(pItem))->Delegate(); |
| 124 | + break; |
| 125 | + } |
| 126 | + |
| 127 | + return result; |
| 128 | +} |
0 commit comments