Commit 9d32a7de authored by Alessandro Portale's avatar Alessandro Portale

ScxmlEditor: Inline the StateProperties ui creation

Change-Id: Idaf89aaf2472e41d429181b2472035a4167f463b
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent 386925b4
......@@ -66,7 +66,6 @@ FORMS += \
$$PWD/search.ui \
$$PWD/shapegroupwidget.ui \
$$PWD/shapestoolbox.ui \
$$PWD/stateproperties.ui \
$$PWD/stateview.ui \
$$PWD/statistics.ui \
$$PWD/statisticsdialog.ui
......
......@@ -24,7 +24,6 @@
<file>images/navigator.png</file>
<file>images/parallel.png</file>
<file>images/parallel_icon.png</file>
<file>images/properties.png</file>
<file>images/screenshot.png</file>
<file>images/state.png</file>
<file>images/state_color.png</file>
......
......@@ -29,26 +29,35 @@
#include "scxmleditorconstants.h"
#include "scxmluifactory.h"
#include <coreplugin/minisplitter.h>
#include <QHeaderView>
#include <QLabel>
#include <QLayout>
#include <QPlainTextEdit>
#include <QTableView>
#include <QToolBar>
using namespace ScxmlEditor::PluginInterface;
using namespace ScxmlEditor::Common;
StateProperties::StateProperties(QWidget *parent)
: QFrame(parent)
{
m_ui.setupUi(this);
m_ui.m_contentFrame->setVisible(false);
m_ui.m_currentTagName->setText(QString());
createUi();
m_contentFrame->setVisible(false);
m_contentTimer.setInterval(500);
m_contentTimer.setSingleShot(true);
connect(m_ui.m_contentEdit, &QTextEdit::textChanged, &m_contentTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
connect(m_contentEdit, &QPlainTextEdit::textChanged, &m_contentTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
connect(&m_contentTimer, &QTimer::timeout, this, &StateProperties::timerTimeout);
}
void StateProperties::setCurrentTagName(const QString &tagName)
{
QFontMetrics fontMetrics(font());
m_ui.m_currentTagName->setText(fontMetrics.elidedText(tagName, Qt::ElideRight, 100));
m_currentTagName->setText(fontMetrics.elidedText(tagName, Qt::ElideRight, 100));
}
void StateProperties::updateName()
......@@ -104,11 +113,52 @@ void StateProperties::setUIFactory(ScxmlUiFactory *factory)
m_attributeModel = static_cast<AttributeItemModel*>(m_uiFactory->object("attributeItemModel"));
m_attributeDelegate = static_cast<AttributeItemDelegate*>(m_uiFactory->object("attributeItemDelegate"));
m_ui.m_tableView->setItemDelegate(m_attributeDelegate);
m_ui.m_tableView->setModel(m_attributeModel);
m_tableView->setItemDelegate(m_attributeDelegate);
m_tableView->setModel(m_attributeModel);
}
}
void StateProperties::createUi()
{
auto titleLabel = new QLabel(tr("Attributes"));
titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_currentTagName = new QLabel;
auto propertiesToolBar = new QToolBar;
propertiesToolBar->setMinimumHeight(24);
propertiesToolBar->addWidget(titleLabel);
propertiesToolBar->addWidget(m_currentTagName);
m_tableView = new QTableView;
m_tableView->setEditTriggers(QAbstractItemView::CurrentChanged
| QAbstractItemView::DoubleClicked
| QAbstractItemView::SelectedClicked
| QAbstractItemView::EditKeyPressed
| QAbstractItemView::AnyKeyPressed);
m_tableView->setFrameShape(QFrame::NoFrame);
m_tableView->setAlternatingRowColors(true);
m_tableView->horizontalHeader()->setStretchLastSection(true);
m_contentEdit = new QPlainTextEdit;
m_contentFrame = new QWidget;
m_contentFrame->setLayout(new QVBoxLayout);
m_contentFrame->layout()->addWidget(new QLabel(tr("Content")));
m_contentFrame->layout()->addWidget(m_contentEdit);
auto splitter = new Core::MiniSplitter;
splitter->setOrientation(Qt::Vertical);
splitter->addWidget(m_tableView);
splitter->addWidget(m_contentFrame);
setLayout(new QVBoxLayout);
layout()->setMargin(0);
layout()->setSpacing(0);
layout()->addWidget(propertiesToolBar);
layout()->addWidget(splitter);
}
void StateProperties::setTag(ScxmlTag *tag)
{
m_tag = tag;
......@@ -120,8 +170,8 @@ void StateProperties::setTag(ScxmlTag *tag)
void StateProperties::timerTimeout()
{
if (m_tag && m_document && m_tag->info()->canIncludeContent && m_tag->content() != m_ui.m_contentEdit->toPlainText())
m_document->setContent(m_tag, m_ui.m_contentEdit->toPlainText());
if (m_tag && m_document && m_tag->info()->canIncludeContent && m_tag->content() != m_contentEdit->toPlainText())
m_document->setContent(m_tag, m_contentEdit->toPlainText());
}
QString StateProperties::content() const
......@@ -134,15 +184,15 @@ QString StateProperties::content() const
void StateProperties::setContentVisibility(bool visible)
{
m_ui.m_contentFrame->setVisible(visible);
m_contentFrame->setVisible(visible);
updateContent();
}
void StateProperties::updateContent()
{
if (!m_ui.m_contentEdit->hasFocus()) {
m_ui.m_contentEdit->blockSignals(true);
m_ui.m_contentEdit->setPlainText(content());
m_ui.m_contentEdit->blockSignals(false);
if (!m_contentEdit->hasFocus()) {
m_contentEdit->blockSignals(true);
m_contentEdit->setPlainText(content());
m_contentEdit->blockSignals(false);
}
}
......@@ -27,11 +27,14 @@
#include "scxmldocument.h"
#include "scxmltag.h"
#include "ui_stateproperties.h"
#include <QFrame>
#include <QTimer>
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit)
QT_FORWARD_DECLARE_CLASS(QTableView)
namespace ScxmlEditor {
namespace PluginInterface {
......@@ -56,6 +59,7 @@ public:
void setUIFactory(PluginInterface::ScxmlUiFactory *factory);
private:
void createUi();
void setCurrentTagName(const QString &state);
void tagChange(PluginInterface::ScxmlDocument::TagChange change, PluginInterface::ScxmlTag *tag, const QVariant &value);
void timerTimeout();
......@@ -71,7 +75,11 @@ private:
PluginInterface::ScxmlTag *m_tag = nullptr;
QTimer m_contentTimer;
QPointer<PluginInterface::ScxmlUiFactory> m_uiFactory;
Ui::StateProperties m_ui;
QWidget *m_contentFrame = nullptr;
QLabel *m_currentTagName = nullptr;
QPlainTextEdit *m_contentEdit = nullptr;
QTableView *m_tableView = nullptr;
};
} // namespace Common
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScxmlEditor::Common::StateProperties</class>
<widget class="QFrame" name="ScxmlEditor::Common::StateProperties">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>383</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>55</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="mainLayout">
<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="QFrame" name="m_titleFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0">
<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="m_icon">
<property name="minimumSize">
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="common.qrc">:/scxmleditor/images/properties.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_title">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Attributes</string>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_currentTagName">
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="m_paneInnerFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>1</height>
</size>
</property>
<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="QSplitter" name="splitter">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTableView" name="m_tableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="gridStyle">
<enum>Qt::NoPen</enum>
</property>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>40</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>25</number>
</attribute>
<attribute name="verticalHeaderMinimumSectionSize">
<number>25</number>
</attribute>
</widget>
<widget class="QFrame" name="m_contentFrame">
<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>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Content</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="m_contentEdit">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="common.qrc"/>
</resources>
<connections/>
</ui>
......@@ -77,7 +77,6 @@ QtcPlugin {
"search.ui",
"shapegroupwidget.ui",
"shapestoolbox.ui",
"stateproperties.ui",
"stateview.ui",
"statistics.ui",
"statisticsdialog.ui",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment