summaryrefslogtreecommitdiff
path: root/src/plugins/qnx/bardescriptoreditorwidget.cpp
blob: 0d3ceb65afc30f39e42e3af395bc685c16879440 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/**************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "bardescriptoreditorwidget.h"

#include "qnxconstants.h"
#include "bardescriptoreditor.h"
#include "bardescriptoreditorassetswidget.h"
#include "bardescriptoreditorauthorinformationwidget.h"
#include "bardescriptoreditorentrypointwidget.h"
#include "bardescriptoreditorenvironmentwidget.h"
#include "bardescriptoreditorgeneralwidget.h"
#include "bardescriptoreditorpackageinformationwidget.h"
#include "bardescriptoreditorpermissionswidget.h"

#include <coreplugin/icore.h>
#include <projectexplorer/iprojectproperties.h>
#include <projectexplorer/projectwindow.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>

using namespace Qnx;
using namespace Qnx::Internal;

BarDescriptorEditorWidget::BarDescriptorEditorWidget(QWidget *parent)
    : QStackedWidget(parent)
    , m_editor(0)
    , m_dirty(false)
{
    Core::IContext *myContext = new Core::IContext(this);
    myContext->setWidget(this);
    myContext->setContext(Core::Context(Constants::QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT, TextEditor::Constants::C_TEXTEDITOR));
    Core::ICore::addContextObject(myContext);

    initGeneralPage();
    initApplicationPage();
    initAssetsPage();
    initSourcePage();

    setCurrentIndex(0);
}

void BarDescriptorEditorWidget::initGeneralPage()
{
    ProjectExplorer::PanelsWidget *generalPanel = new ProjectExplorer::PanelsWidget(this);
    initPanelSize(generalPanel);
    addWidget(generalPanel);

    // Entry-Point Text and Images
    ProjectExplorer::PropertiesPanel *entryPointPanel = new ProjectExplorer::PropertiesPanel;
    m_entryPointWidget = new BarDescriptorEditorEntryPointWidget;
    entryPointPanel->setDisplayName(tr("Entry-Point Text and Images"));
    entryPointPanel->setWidget(m_entryPointWidget);
    generalPanel->addPropertiesPanel(entryPointPanel);

    // Package Information
    ProjectExplorer::PropertiesPanel *packageInformationPanel = new ProjectExplorer::PropertiesPanel;
    m_packageInformationWidget = new BarDescriptorEditorPackageInformationWidget;
    packageInformationPanel->setDisplayName(tr("Package Information"));
    packageInformationPanel->setWidget(m_packageInformationWidget);
    generalPanel->addPropertiesPanel(packageInformationPanel);

    // Author information
    ProjectExplorer::PropertiesPanel *authorInformationPanel = new ProjectExplorer::PropertiesPanel;
    m_authorInformationWidget = new BarDescriptorEditorAuthorInformationWidget;
    authorInformationPanel->setDisplayName(tr("Author Information"));
    authorInformationPanel->setWidget(m_authorInformationWidget);
    generalPanel->addPropertiesPanel(authorInformationPanel);

    connect(m_entryPointWidget, SIGNAL(changed()), this, SLOT(setDirty()));
    connect(m_packageInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
    connect(m_authorInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
}

void BarDescriptorEditorWidget::initApplicationPage()
{
    ProjectExplorer::PanelsWidget *applicationPanel = new ProjectExplorer::PanelsWidget(this);
    initPanelSize(applicationPanel);
    addWidget(applicationPanel);

    // General
    ProjectExplorer::PropertiesPanel *generalPanel = new ProjectExplorer::PropertiesPanel;
    m_generalWidget = new BarDescriptorEditorGeneralWidget;
    generalPanel->setDisplayName(tr("General"));
    generalPanel->setWidget(m_generalWidget);
    applicationPanel->addPropertiesPanel(generalPanel);

    //Permissions
    ProjectExplorer::PropertiesPanel *permissionsPanel = new ProjectExplorer::PropertiesPanel;
    m_permissionsWidget = new BarDescriptorEditorPermissionsWidget;
    permissionsPanel->setDisplayName(tr("Permissions"));
    permissionsPanel->setWidget(m_permissionsWidget);
    applicationPanel->addPropertiesPanel(permissionsPanel);

    // Environment
    ProjectExplorer::PropertiesPanel *environmentPanel = new ProjectExplorer::PropertiesPanel;
    m_environmentWidget = new BarDescriptorEditorEnvironmentWidget;
    environmentPanel->setDisplayName(tr("Environment"));
    environmentPanel->setWidget(m_environmentWidget);
    applicationPanel->addPropertiesPanel(environmentPanel);

    connect(m_generalWidget, SIGNAL(changed()), this, SLOT(setDirty()));
    connect(m_permissionsWidget, SIGNAL(changed()), this, SLOT(setDirty()));
    connect(m_environmentWidget, SIGNAL(changed()), this, SLOT(setDirty()));
}

void BarDescriptorEditorWidget::initAssetsPage()
{
    ProjectExplorer::PanelsWidget *assetsPanel = new ProjectExplorer::PanelsWidget(this);
    initPanelSize(assetsPanel);
    addWidget(assetsPanel);

    ProjectExplorer::PropertiesPanel *assetsPropertiesPanel = new ProjectExplorer::PropertiesPanel;
    m_assetsWidget = new BarDescriptorEditorAssetsWidget;
    assetsPropertiesPanel->setDisplayName(tr("Assets"));
    assetsPropertiesPanel->setWidget(m_assetsWidget);
    assetsPanel->addPropertiesPanel(assetsPropertiesPanel);

    connect(m_assetsWidget, SIGNAL(changed()), this, SLOT(setDirty()));

    m_entryPointWidget->setAssetsModel(m_assetsWidget->assetsModel());
    connect(m_entryPointWidget, SIGNAL(imageAdded(QString)), m_assetsWidget, SLOT(addAsset(QString)));
    connect(m_entryPointWidget, SIGNAL(imageRemoved(QString)), m_assetsWidget, SLOT(removeAsset(QString)));
}

void BarDescriptorEditorWidget::initSourcePage()
{
    m_xmlSourceWidget = new TextEditor::PlainTextEditorWidget(this);
    addWidget(m_xmlSourceWidget);

    TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
    m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
    connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty()));
}

void BarDescriptorEditorWidget::initPanelSize(ProjectExplorer::PanelsWidget *panelsWidget)
{
    panelsWidget->widget()->setMaximumWidth(900);
    panelsWidget->widget()->setMinimumWidth(0);
}

Core::IEditor *BarDescriptorEditorWidget::editor() const
{
    if (!m_editor) {
        m_editor = const_cast<BarDescriptorEditorWidget *>(this)->createEditor();
        connect(this, SIGNAL(changed()), m_editor->document(), SIGNAL(changed()));
    }

    return m_editor;
}

BarDescriptorEditorPackageInformationWidget *BarDescriptorEditorWidget::packageInformationWidget() const
{
    return m_packageInformationWidget;
}

BarDescriptorEditorAuthorInformationWidget *BarDescriptorEditorWidget::authorInformationWidget() const
{
    return m_authorInformationWidget;
}

BarDescriptorEditorEntryPointWidget *BarDescriptorEditorWidget::entryPointWidget() const
{
    return m_entryPointWidget;
}

BarDescriptorEditorGeneralWidget *BarDescriptorEditorWidget::generalWidget() const
{
    return m_generalWidget;
}

BarDescriptorEditorPermissionsWidget *BarDescriptorEditorWidget::permissionsWidget() const
{
    return m_permissionsWidget;
}

BarDescriptorEditorEnvironmentWidget *BarDescriptorEditorWidget::environmentWidget() const
{
    return m_environmentWidget;
}

BarDescriptorEditorAssetsWidget *BarDescriptorEditorWidget::assetsWidget() const
{
    return m_assetsWidget;
}

TextEditor::BaseTextEditorWidget *BarDescriptorEditorWidget::sourceWidget() const
{
    return m_xmlSourceWidget;
}

void BarDescriptorEditorWidget::setFilePath(const QString &filePath)
{
    Core::IDocument *doc = m_xmlSourceWidget->baseTextDocument();
    if (doc) {
        doc->setFilePath(filePath);
        // setFilePath() call leads to a textChanged() signal emitted
        // and therefore having this editor-widget to become dirty
        // therefore we have to explicitly unset the dirty flag
        setDirty(false);
    }
}

QString BarDescriptorEditorWidget::xmlSource() const
{
    return m_xmlSourceWidget->toPlainText();
}

void BarDescriptorEditorWidget::setXmlSource(const QString &xmlSource)
{
    bool blocked = m_xmlSourceWidget->blockSignals(true);
    m_xmlSourceWidget->setPlainText(xmlSource);
    m_xmlSourceWidget->blockSignals(blocked);
}

bool BarDescriptorEditorWidget::isDirty() const
{
    return m_dirty;
}

void BarDescriptorEditorWidget::clear()
{
    m_entryPointWidget->clear();
    m_packageInformationWidget->clear();
    m_authorInformationWidget->clear();

    m_generalWidget->clear();
    m_permissionsWidget->clear();
    m_environmentWidget->clear();

    m_assetsWidget->clear();

    bool blocked = m_xmlSourceWidget->blockSignals(true);
    m_xmlSourceWidget->clear();
    m_xmlSourceWidget->blockSignals(blocked);
}

void BarDescriptorEditorWidget::setDirty(bool dirty)
{
    m_dirty = dirty;
    emit changed();
}

BarDescriptorEditor *BarDescriptorEditorWidget::createEditor()
{
    return new BarDescriptorEditor(this);
}