aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/annotationeditor/globalannotationdialog.cpp
blob: 1432e090df3a3b07b62d29f8cfb9d55ccef2a3ca (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "globalannotationdialog.h"
#include "annotation.h"
#include "annotationcommenttab.h"
#include "defaultannotations.h"
#include "annotationeditorwidget.h"
#include "annotationlistwidget.h"

#include <timelineicons.h>
#include <utils/qtcassert.h>

#include <QAction>
#include <QMessageBox>
#include <QObject>
#include <QToolBar>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QAbstractButton>

namespace QmlDesigner {

GlobalAnnotationDialog::GlobalAnnotationDialog(ModelNode rootNode, QWidget *parent)
    : QDialog(parent)
    , m_statusIsActive(false)
    , m_defaults(std::make_unique<DefaultAnnotationsModel>())
    , m_editorWidget(new AnnotationEditorWidget(this))
    , m_annotationListWidget(new AnnotationListWidget(rootNode, this))
{
    setupUI();

    setStatus(m_globalStatus);
    m_editorWidget->setGlobal(true);

    connect(this, &QDialog::accepted,
            this, &GlobalAnnotationDialog::acceptedClicked);
    connect(m_buttonBox, &QDialogButtonBox::accepted,
            this, &GlobalAnnotationDialog::acceptedClicked);

    connect(m_buttonBox, &QDialogButtonBox::clicked,
            this, &GlobalAnnotationDialog::buttonClicked);

    connect(m_buttonBox, &QDialogButtonBox::rejected,
            this, &QDialog::close);
}

GlobalAnnotationDialog::~GlobalAnnotationDialog() = default;

void GlobalAnnotationDialog::setStatus(GlobalAnnotationStatus status)
{
    m_editorWidget->setStatus(status);
}

GlobalAnnotationStatus GlobalAnnotationDialog::globalStatus() const
{
    return m_editorWidget->globalStatus();
}

GlobalAnnotationDialog::ViewMode GlobalAnnotationDialog::viewMode() const
{
    if (!m_tabWidget)
        return ViewMode::GlobalAnnotation;

    return (m_tabWidget->currentIndex() == 0)
            ? ViewMode::GlobalAnnotation
            : ViewMode::List;
}

void GlobalAnnotationDialog::saveAnnotationListChanges()
{
    m_annotationListWidget->saveAllChanges();
}

void GlobalAnnotationDialog::buttonClicked(QAbstractButton *button)
{
    if (button) {
        const QDialogButtonBox::StandardButton buttonType = m_buttonBox->standardButton(button);
        if (buttonType == QDialogButtonBox::Apply) {
            appliedClicked();
        }
    }
}

void GlobalAnnotationDialog::acceptedClicked()
{
    updateAnnotation();
    emit GlobalAnnotationDialog::acceptedDialog();
}

void GlobalAnnotationDialog::appliedClicked()
{
    updateAnnotation();
    emit GlobalAnnotationDialog::appliedDialog();
}

void GlobalAnnotationDialog::updateAnnotation()
{
    m_editorWidget->updateAnnotation();
    m_annotation = m_editorWidget->annotation();

    m_statusIsActive = (m_editorWidget->globalStatus().status() != GlobalAnnotationStatus::NoStatus);
    m_globalStatus = m_editorWidget->globalStatus();
}

void GlobalAnnotationDialog::setupUI()
{
    setWindowFlag(Qt::Tool, true);
    setWindowTitle(tr("Global Annotation Editor"));
    setModal(true);

    if (!QWidget::layout())
        new QVBoxLayout(this);

    m_tabWidget = new QTabWidget(this);
    m_tabWidget->setTabsClosable(false);
    m_tabWidget->setMovable(false);
    QWidget::layout()->addWidget(m_tabWidget);

    m_tabWidget->addTab(m_editorWidget, tr("Global Annotation"));
    m_tabWidget->addTab(m_annotationListWidget, tr("All Annotations"));

    const QDialogButtonBox::StandardButtons buttonsToCreate =
            QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply;

    m_buttonBox = new QDialogButtonBox(buttonsToCreate, this);
    QWidget::layout()->addWidget(m_buttonBox);
}

const Annotation &GlobalAnnotationDialog::annotation() const
{
    return m_annotation;
}

void GlobalAnnotationDialog::setAnnotation(const Annotation &annotation)
{
    m_annotation = annotation;

    m_editorWidget->setAnnotation(m_annotation);
}

void GlobalAnnotationDialog::loadDefaultAnnotations(const QString &filename)
{
    m_editorWidget->loadDefaultAnnotations(filename);
}

DefaultAnnotationsModel *GlobalAnnotationDialog::defaultAnnotations() const
{
    return m_editorWidget->defaultAnnotations();
}


} //namespace QmlDesigner