Commit 4ea332b0 authored by Alessandro Portale's avatar Alessandro Portale

ScxmlEditor: Initial import

Change-Id: I4701b77ebd4e2520f2616c42206ac17be3a12b60
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Ulf Hermann's avatarUlf Hermann <ulf.hermann@qt.io>
parent 1a9919a2
......@@ -57,6 +57,7 @@ SUBDIRS = \
winrt \
qmlprofiler \
updateinfo \
scxmleditor \
welcome
DO_NOT_BUILD_QMLDESIGNER = $$(DO_NOT_BUILD_QMLDESIGNER)
......
......@@ -57,6 +57,7 @@ Project {
"qtsupport/qtsupport.qbs",
"remotelinux/remotelinux.qbs",
"resourceeditor/resourceeditor.qbs",
"scxmleditor/scxmleditor.qbs",
"subversion/subversion.qbs",
"tasklist/tasklist.qbs",
"texteditor/texteditor.qbs",
......
{
\"Name\" : \"ScxmlEditor\",
\"Version\" : \"$$QTCREATOR_VERSION\",
\"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
\"Vendor\" : \"The Qt Company Ltd\",
\"Copyright\" : \"(C) 2016 The Qt Company Ltd\",
\"License\" : [ \"Commercial Usage\",
\"\",
\"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\",
\"\",
\"GNU General Public License Usage\",
\"\",
\"Alternatively, this plugin 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 plugin. 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.\"
],
\"Category\" : \"Modeling\",
\"Description\" : \"Visual Editor for SCXML (State Chart XML) files.\",
\"Url\" : \"http://www.qt.io\",
\"Experimental\" : true,
$$dependencyList
}
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/scxml+xml">
<sub-class-of type="text/xml"/>
<comment>SCXML file</comment>
<glob pattern="*.scxml"/>
</mime-type>
</mime-info>
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 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.
**
****************************************************************************/
#include "colorpicker.h"
#include "scxmleditorconstants.h"
#include <QToolButton>
#include <coreplugin/icore.h>
using namespace ScxmlEditor::Common;
const char C_SETTINGS_COLORPICKER_LASTUSEDCOLORS[] = "ScxmlEditor/ColorPickerLastUsedColors_%1";
ColorPicker::ColorPicker(const QString &key, QWidget *parent)
: QFrame(parent)
, m_key(key)
{
m_ui.setupUi(this);
const QVector<QRgb> colors = {
qRgb(0xed, 0xf7, 0xf2), qRgb(0xdf, 0xd3, 0xb6), qRgb(0x89, 0x72, 0x5b), qRgb(0xff, 0xd3, 0x93), qRgb(0xff, 0x97, 0x4f),
qRgb(0xff, 0x85, 0x0d), qRgb(0xf7, 0xe9, 0x67), qRgb(0xef, 0xc9, 0x4c), qRgb(0xff, 0xe1, 0x1a), qRgb(0xc2, 0xe0, 0x78),
qRgb(0xa2, 0xd7, 0x00), qRgb(0x45, 0xbf, 0x08), qRgb(0x91, 0xe3, 0xd8), qRgb(0x3c, 0xb3, 0xfd), qRgb(0x34, 0x67, 0xba),
qRgb(0xc5, 0xba, 0xfc), qRgb(0xb6, 0x65, 0xfc), qRgb(0xa5, 0x08, 0xd0), qRgb(0xcc, 0x56, 0x64), qRgb(0x96, 0x2d, 0x3e)
};
auto vBoxLayout = new QVBoxLayout;
vBoxLayout->setContentsMargins(0, 0, 0, 0);
vBoxLayout->setMargin(0);
vBoxLayout->setSpacing(0);
const int buttonRowsCount = 4;
const int buttonColumnsCount = 5;
for (int r = 0; r < buttonRowsCount; ++r) {
auto hBoxLayout = new QHBoxLayout;
hBoxLayout->setContentsMargins(0, 0, 0, 0);
hBoxLayout->setMargin(0);
hBoxLayout->setSpacing(0);
for (int c = 0; c < buttonColumnsCount; ++c)
hBoxLayout->addWidget(createButton(colors[r * buttonColumnsCount + c]));
hBoxLayout->addStretch();
vBoxLayout->addLayout(hBoxLayout);
}
m_ui.basicColorContentFrame->setLayout(vBoxLayout);
const QStringList lastColors = Core::ICore::settings()->value(
QString::fromLatin1(C_SETTINGS_COLORPICKER_LASTUSEDCOLORS).arg(m_key), QStringList()).toStringList();
for (int i = lastColors.count(); i--;)
setLastUsedColor(lastColors[i]);
}
ColorPicker::~ColorPicker()
{
Core::ICore::settings()->setValue(QString::fromLatin1(C_SETTINGS_COLORPICKER_LASTUSEDCOLORS).arg(m_key),
m_lastUsedColorNames);
}
void ColorPicker::setLastUsedColor(const QString &colorName)
{
if (colorName.isEmpty())
return;
if (m_lastUsedColorNames.contains(colorName))
return;
m_lastUsedColorNames.insert(0, colorName);
m_lastUsedColorButtons.insert(0, createButton(colorName));
while (m_lastUsedColorButtons.count() > 5) {
m_lastUsedColorButtons.takeLast()->deleteLater();
m_lastUsedColorNames.takeLast();
}
m_ui.lastUsedColorLayout->insertWidget(0, m_lastUsedColorButtons.first());
}
QToolButton *ColorPicker::createButton(const QColor &color)
{
auto button = new QToolButton;
button->setObjectName("colorPickerButton");
QPixmap pixmap(15, 15);
pixmap.fill(color);
button->setIcon(QIcon(pixmap));
connect(button, &QToolButton::clicked, this, [this, color] {
emit colorSelected(QColor(color).name());
});
return button;
}
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 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.
**
****************************************************************************/
#pragma once
#include "ui_colorpicker.h"
#include <QFrame>
QT_FORWARD_DECLARE_CLASS(QToolButton)
namespace ScxmlEditor {
namespace Common {
class ColorPicker : public QFrame
{
Q_OBJECT
public:
explicit ColorPicker(const QString &key, QWidget *parent = nullptr);
~ColorPicker() override;
void setLastUsedColor(const QString &colorName);
signals:
void colorSelected(const QString &colorName);
private:
QToolButton *createButton(const QColor &color);
QStringList m_lastUsedColorNames;
QVector<QToolButton*> m_lastUsedColorButtons;
QString m_key;
Ui::ColorPicker m_ui;
};
} // namespace Common
} // namespace ScxmlEditor
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScxmlEditor::Common::ColorPicker</class>
<widget class="QFrame" name="ScxmlEditor::Common::ColorPicker">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>79</width>
<height>183</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="basicColorFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="basicColorTitle">
<property name="text">
<string>Basic Colors</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="basicColorContentFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="lastUsedColorFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lastUsedColorTitle">
<property name="text">
<string>Last used colors</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="lastUsedColorContentFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="lastUsedColorLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 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.
**
****************************************************************************/
#include "colorsettings.h"
#include "scxmleditorconstants.h"
#include <QInputDialog>
#include <QMessageBox>
#include <coreplugin/icore.h>
using namespace ScxmlEditor::Common;
ColorSettings::ColorSettings(QWidget *parent)
: QFrame(parent)
{
m_ui.setupUi(this);
m_ui.m_colorThemeView->setEnabled(false);
connect(m_ui.m_comboColorThemes, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this, &ColorSettings::selectTheme);
connect(m_ui.m_colorThemeView, &ColorThemeView::colorChanged, this, &ColorSettings::updateCurrentColors);
connect(m_ui.m_addColorTheme, &QToolButton::clicked, this, &ColorSettings::createTheme);
connect(m_ui.m_removeColorTheme, &QToolButton::clicked, this, &ColorSettings::removeTheme);
const QSettings *s = Core::ICore::settings();
m_colorThemes = s->value(Constants::C_SETTINGS_COLORSETTINGS_COLORTHEMES).toMap();
m_ui.m_comboColorThemes->clear();
foreach (const QString &key, m_colorThemes.keys())
m_ui.m_comboColorThemes->addItem(key);
m_ui.m_comboColorThemes->setCurrentText(s->value(Constants::C_SETTINGS_COLORSETTINGS_CURRENTCOLORTHEME).toString());
}
void ColorSettings::save()
{
QSettings *s = Core::ICore::settings();
s->setValue(Constants::C_SETTINGS_COLORSETTINGS_COLORTHEMES, m_colorThemes);
s->setValue(Constants::C_SETTINGS_COLORSETTINGS_CURRENTCOLORTHEME, m_ui.m_comboColorThemes->currentText());
}
void ColorSettings::updateCurrentColors()
{
m_colorThemes[m_ui.m_comboColorThemes->currentText()] = m_ui.m_colorThemeView->colorData();
}
void ColorSettings::selectTheme(const QString &name)
{
m_ui.m_colorThemeView->reset();
if (!name.isEmpty() && m_colorThemes.contains(name)) {
m_ui.m_colorThemeView->setEnabled(true);
QVariantMap colordata = m_colorThemes[name].toMap();
foreach (const QString &index, colordata.keys())
m_ui.m_colorThemeView->setColor(index.toInt(), QColor(colordata[index].toString()));
} else {
m_ui.m_colorThemeView->setEnabled(false);
}
}
void ColorSettings::createTheme()
{
QString name = QInputDialog::getText(this, tr("Create New Color Theme"), tr("Theme ID"));
if (!name.isEmpty()) {
if (m_colorThemes.keys().contains(name)) {
QMessageBox::warning(this, tr("Cannot Create Theme"), tr("Theme %1 is already available.").arg(name));
} else {
m_ui.m_colorThemeView->reset();
m_colorThemes[name] = QVariantMap();
m_ui.m_comboColorThemes->addItem(name);
m_ui.m_comboColorThemes->setCurrentText(name);
}
}
}
void ColorSettings::removeTheme()
{
const QString name = m_ui.m_comboColorThemes->currentText();
const QMessageBox::StandardButton result = QMessageBox::question(this, tr("Remove Color Theme"),
tr("Are you sure you want to delete color theme %1?").arg(name),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (result == QMessageBox::Yes) {
m_ui.m_comboColorThemes->removeItem(m_ui.m_comboColorThemes->currentIndex());
m_colorThemes.remove(name);
m_ui.m_comboColorThemes->setCurrentIndex(0);
if (m_colorThemes.isEmpty())
m_ui.m_colorThemeView->setEnabled(false);
}
}
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 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.
**
****************************************************************************/
#pragma once
#include "ui_colorsettings.h"
#include <QFrame>
namespace ScxmlEditor {
namespace Common {
class ColorSettings : public QFrame
{
Q_OBJECT
public:
explicit ColorSettings(QWidget *parent = nullptr);
void save();
void updateCurrentColors();
void selectTheme(const QString &name);
void createTheme();
void removeTheme();