summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsModel.cpp
blob: 5a4fff9d4b5dcd14dc8e7370262e1fb484bc34a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "BasicObjectsModel.h"
#include "DropSource.h"
#include "Literals.h"
#include "StudioUtils.h"

#include <QCoreApplication>
#include <QDataStream>
#include <QMimeData>

BasicObjectsModel::BasicObjectsModel(QObject *parent) : QAbstractListModel(parent)
{
    initialize();
}

void BasicObjectsModel::initialize()
{
    m_ObjectItems = InitializeObjectModel();
}

const QVector<BasicObjectItem> BasicObjectsModel::InitializeObjectModel()
{
    return {
        {tr("Rectangle"), "Asset-Rectangle-Normal.png"_L1, OBJTYPE_MODEL, PRIMITIVETYPE_RECT},
        {tr("Sphere"), "Asset-Sphere-Normal.png"_L1, OBJTYPE_MODEL, PRIMITIVETYPE_SPHERE},
        {tr("Cube"), "Asset-Cube-Normal.png"_L1, OBJTYPE_MODEL, PRIMITIVETYPE_BOX},
        {tr("Cylinder"), "Asset-Cylinder-Normal.png"_L1, OBJTYPE_MODEL, PRIMITIVETYPE_CYLINDER},
        {tr("Cone"), "Asset-Cone-Normal.png"_L1, OBJTYPE_MODEL, PRIMITIVETYPE_CONE},
        {tr("Component"), "Asset-Component-Normal.png"_L1, OBJTYPE_COMPONENT, PRIMITIVETYPE_UNKNOWN},
        {tr("Group"), "Asset-Group-Normal.png"_L1, OBJTYPE_GROUP, PRIMITIVETYPE_UNKNOWN},
        {tr("Text"), "Asset-Text-Normal.png"_L1, OBJTYPE_TEXT, PRIMITIVETYPE_UNKNOWN},
        {tr("Camera"), "Asset-Camera-Normal.png"_L1, OBJTYPE_CAMERA, PRIMITIVETYPE_UNKNOWN},
        {tr("Light"), "Asset-Light-Normal.png"_L1, OBJTYPE_LIGHT, PRIMITIVETYPE_UNKNOWN},
        {tr("Alias"), "Asset-Alias-Normal.png"_L1, OBJTYPE_ALIAS, PRIMITIVETYPE_UNKNOWN},
    };
}

// Returns meshes part of basic objects
const QVector<BasicObjectItem> BasicObjectsModel::BasicMeshesModel()
{
    return InitializeObjectModel().mid(0, 5);
}

QVariant BasicObjectsModel::data(const QModelIndex &index, int role) const
{
    if (!hasIndex(index.row(), index.column(),index.parent()))
        return {};

    const auto row = index.row();

    switch (role) {
    case NameRole: return m_ObjectItems.at(row).name();
    case IconRole: return resourceImageUrl() +
                m_ObjectItems.at(row).icon();
    case ObjectTypeRole: return m_ObjectItems.at(row).objectType();
    case PrimitiveTypeRole: return m_ObjectItems.at(row).primitiveType();
    }

    return {};
}

int BasicObjectsModel::rowCount(const QModelIndex &parent) const
{
    if (parent.isValid())
        return 0;
    return m_ObjectItems.count();
}

QHash<int, QByteArray> BasicObjectsModel::roleNames() const
{
    auto names = QAbstractListModel::roleNames();
    names.insert(NameRole, "name");
    names.insert(IconRole, "icon");

    return names;
}

Qt::ItemFlags BasicObjectsModel::flags(const QModelIndex &index) const {
    if (index.isValid())
        return Qt::ItemIsDragEnabled;

    return QAbstractListModel::flags(index);
}

QStringList BasicObjectsModel::mimeTypes() const
{
    return { m_MimeType };
}

QMimeData *BasicObjectsModel::mimeData(const QModelIndexList &indexes) const
{

    const auto row = indexes.first().row(); // we support only one item for D&D
    auto object = m_ObjectItems.at(row);

    auto *data = CDropSourceFactory::Create(object.GetFlavor(), &object);
    return data;
}

BasicObjectItem::~BasicObjectItem()
{
}