Commit a2fd5368 authored by Alessandro Portale's avatar Alessandro Portale

ScxmlEditor: Inline the OutputPane ui creation

Change-Id: Ied1a671f8939c828461486bed020b992792c9819
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent 131659d0
......@@ -63,7 +63,7 @@ public:
QIcon icon() const override
{
return Utils::Icons::MAGNIFIER.icon();
return Utils::Icons::ZOOM_TOOLBAR.icon();
}
void setPaneFocus() override;
......
......@@ -14,6 +14,3 @@ SOURCES += \
$$PWD/outputtabwidget.cpp \
$$PWD/warningmodel.cpp \
$$PWD/warning.cpp
FORMS += \
$$PWD/outputtabwidget.ui
......@@ -28,13 +28,18 @@
#include <utils/qtcassert.h>
#include <QLayout>
#include <QPainter>
#include <QStackedWidget>
#include <QToolBar>
using namespace ScxmlEditor::OutputPane;
PanePushButton::PanePushButton(OutputPane *pane, QWidget *parent)
: QPushButton(parent)
PaneTitleButton::PaneTitleButton(OutputPane *pane, QWidget *parent)
: QToolButton(parent)
{
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
animator.setPropertyName("colorOpacity");
animator.setTargetObject(this);
......@@ -44,7 +49,7 @@ PanePushButton::PanePushButton(OutputPane *pane, QWidget *parent)
setText(pane->title());
setIcon(pane->icon());
connect(this, &PanePushButton::toggled, this, [this](bool toggled) {
connect(this, &PaneTitleButton::toggled, this, [this](bool toggled) {
if (toggled)
stopAlert();
});
......@@ -68,19 +73,19 @@ PanePushButton::PanePushButton(OutputPane *pane, QWidget *parent)
});
}
void PanePushButton::startAlert(const QColor &color)
void PaneTitleButton::startAlert(const QColor &color)
{
m_color = color;
m_animCounter = 0;
fadeIn();
}
void PanePushButton::stopAlert()
void PaneTitleButton::stopAlert()
{
animator.stop();
}
void PanePushButton::fadeIn()
void PaneTitleButton::fadeIn()
{
animator.stop();
animator.setDuration(300);
......@@ -89,7 +94,7 @@ void PanePushButton::fadeIn()
animator.start();
}
void PanePushButton::fadeOut()
void PaneTitleButton::fadeOut()
{
animator.stop();
animator.setDuration(300);
......@@ -98,15 +103,15 @@ void PanePushButton::fadeOut()
animator.start();
}
void PanePushButton::setColorOpacity(int value)
void PaneTitleButton::setColorOpacity(int value)
{
m_colorOpacity = value;
update();
}
void PanePushButton::paintEvent(QPaintEvent *e)
void PaneTitleButton::paintEvent(QPaintEvent *e)
{
QPushButton::paintEvent(e);
QToolButton::paintEvent(e);
QPainter p(this);
p.save();
......@@ -123,7 +128,7 @@ void PanePushButton::paintEvent(QPaintEvent *e)
OutputTabWidget::OutputTabWidget(QWidget *parent)
: QFrame(parent)
{
m_ui.setupUi(this);
createUi();
close();
}
......@@ -134,12 +139,12 @@ OutputTabWidget::~OutputTabWidget()
int OutputTabWidget::addPane(OutputPane *pane)
{
if (pane) {
auto button = new PanePushButton(pane, this);
connect(button, &PanePushButton::clicked, this, &OutputTabWidget::buttonClicked);
auto button = new PaneTitleButton(pane, this);
connect(button, &PaneTitleButton::clicked, this, &OutputTabWidget::buttonClicked);
connect(pane, &OutputPane::dataChanged, this, &OutputTabWidget::showAlert);
m_ui.m_buttonLayout->addWidget(button);
m_ui.m_stackedWidget->addWidget(pane);
m_toolBar->addWidget(button);
m_stackedWidget->addWidget(pane);
m_buttons << button;
m_pages << pane;
......@@ -154,23 +159,35 @@ void OutputTabWidget::showPane(OutputPane *pane)
{
QTC_ASSERT(pane, return);
m_ui.m_stackedWidget->setCurrentWidget(pane);
m_stackedWidget->setCurrentWidget(pane);
m_buttons[m_pages.indexOf(pane)]->setChecked(true);
pane->setPaneFocus();
if (!m_ui.m_stackedWidget->isVisible()) {
m_ui.m_stackedWidget->setVisible(true);
if (!m_stackedWidget->isVisible()) {
m_stackedWidget->setVisible(true);
emit visibilityChanged(true);
}
}
void OutputTabWidget::showPane(int index)
{
showPane(static_cast<OutputPane*>(m_ui.m_stackedWidget->widget(index)));
showPane(static_cast<OutputPane*>(m_stackedWidget->widget(index)));
}
void OutputTabWidget::createUi()
{
m_toolBar = new QToolBar;
m_stackedWidget = new QStackedWidget;
setLayout(new QVBoxLayout);
layout()->setSpacing(0);
layout()->setMargin(0);
layout()->addWidget(m_toolBar);
layout()->addWidget(m_stackedWidget);
}
void OutputTabWidget::close()
{
m_ui.m_stackedWidget->setVisible(false);
m_stackedWidget->setVisible(false);
emit visibilityChanged(false);
}
......@@ -183,7 +200,7 @@ void OutputTabWidget::showAlert()
void OutputTabWidget::buttonClicked(bool para)
{
int index = m_buttons.indexOf(qobject_cast<PanePushButton*>(sender()));
int index = m_buttons.indexOf(qobject_cast<PaneTitleButton*>(sender()));
if (index >= 0) {
if (para) {
for (int i = 0; i < m_buttons.count(); ++i) {
......
......@@ -25,13 +25,13 @@
#pragma once
#include "ui_outputtabwidget.h"
#include <QFrame>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QToolButton>
QT_FORWARD_DECLARE_CLASS(QPaintEvent)
QT_FORWARD_DECLARE_CLASS(QStackedWidget)
QT_FORWARD_DECLARE_CLASS(QToolBar)
namespace ScxmlEditor {
......@@ -39,13 +39,13 @@ namespace OutputPane {
class OutputPane;
class PanePushButton : public QPushButton
class PaneTitleButton : public QToolButton
{
Q_OBJECT
Q_PROPERTY(int colorOpacity READ colorOpacity WRITE setColorOpacity)
public:
PanePushButton(OutputPane *pane, QWidget *parent = nullptr);
PaneTitleButton(OutputPane *pane, QWidget *parent = nullptr);
int colorOpacity()
{
......@@ -85,13 +85,16 @@ signals:
void visibilityChanged(bool visible);
private:
void createUi();
void close();
void buttonClicked(bool para);
void showAlert();
QVector<OutputPane*> m_pages;
QVector<PanePushButton*> m_buttons;
Ui::OutputTabWidget m_ui;
QVector<PaneTitleButton*> m_buttons;
QToolBar *m_toolBar = nullptr;
QStackedWidget *m_stackedWidget = nullptr;
};
} // namespace OutputPane
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScxmlEditor::OutputPane::OutputTabWidget</class>
<widget class="QWidget" name="ScxmlEditor::OutputPane::OutputTabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</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="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::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<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="QWidget" name="m_buttonWidget" native="true">
<layout class="QHBoxLayout" name="m_buttonLayout">
<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>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>395</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="m_stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -94,8 +94,6 @@ QtcPlugin {
"tableview.cpp", "tableview.h",
"warning.cpp", "warning.h",
"warningmodel.cpp", "warningmodel.h",
"outputtabwidget.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