Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicgroupeditor.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicscene.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/stageschematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/stageschematicscene.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxcommand.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectcmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobject.h"
Toshihiro Shimizu 890ddd
#include "tfxattributes.h"
Toshihiro Shimizu 890ddd
#include "tmacrofx.h"
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Toshihiro Shimizu 890ddd
#include <qgraphicsscenecontextmenuevent></qgraphicsscenecontextmenuevent>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//SchematicGroupEditor
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SchematicWindowEditor::SchematicWindowEditor(const QList<schematicnode *=""> &groupedNode, SchematicScene *scene)</schematicnode>
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Toshihiro Shimizu 890ddd
	: QGraphicsItem()
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	: QGraphicsItem(0, scene)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_groupedNode(groupedNode), m_scene(scene), m_lastPos(), m_button(Qt::NoButton), m_isMacroEditor(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Toshihiro Shimizu 890ddd
	scene->addItem(this);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	m_nameItem = new SchematicName(this, 67, 14);
Toshihiro Shimizu 890ddd
	m_nameItem->setPos(-2, -2);
Toshihiro Shimizu 890ddd
	m_nameItem->setZValue(1);
Toshihiro Shimizu 890ddd
	m_nameItem->hide();
Toshihiro Shimizu 890ddd
	connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SchematicWindowEditor::~SchematicWindowEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QRectF SchematicWindowEditor::boundingRect() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF rect = boundingSceneRect();
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(QPointF(0, 0));
Toshihiro Shimizu 890ddd
	rect.adjust(-1, -1, 1, 1);
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	painter->setPen(QColor(0, 0, 0, 255));
Toshihiro Shimizu 890ddd
	if (m_isMacroEditor)
Toshihiro Shimizu 890ddd
		painter->setBrush(QColor(132, 86, 123, 255));
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		painter->setBrush(QColor(76, 148, 177, 255));
Toshihiro Shimizu 890ddd
	QRectF bRect = boundingRect();
Toshihiro Shimizu 890ddd
	QRectF rect(0, 0, bRect.width(), 15);
Toshihiro Shimizu 890ddd
	painter->drawRect(rect);
Toshihiro Shimizu 890ddd
	rect = QRectF(0, 15, bRect.width(), bRect.height() - 15);
Toshihiro Shimizu 890ddd
	painter->setBrush(QColor(180, 180, 180, 125));
Toshihiro Shimizu 890ddd
	painter->drawRect(rect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//draw the topRight cross
Toshihiro Shimizu 890ddd
	rect = QRectF(0, 0, 11, 11);
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(QPointF(bRect.width() - 13, 2));
Toshihiro Shimizu 890ddd
	painter->drawRoundedRect(rect, 2, 2);
Toshihiro Shimizu 890ddd
	painter->setPen(Qt::black);
Toshihiro Shimizu 890ddd
	painter->drawLine(QPointF(rect.left() + 2, rect.top() + 2), QPointF(rect.right() - 2, rect.bottom() - 2));
Toshihiro Shimizu 890ddd
	painter->drawLine(QPointF(rect.left() + 2, rect.bottom() - 2), QPointF(rect.right() - 2, rect.top() + 2));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_nameItem->isVisible()) {
Toshihiro Shimizu 890ddd
		painter->setPen(Qt::white);
Toshihiro Shimizu 890ddd
		QFont font("Verdana", 7);
Toshihiro Shimizu 890ddd
		painter->setFont(font);
Toshihiro Shimizu 890ddd
		QRectF rect = QRectF(2, 1, bRect.width() - 15, 13);
Toshihiro Shimizu 890ddd
		QString elidedName = elideText(m_groupName, font, rect.width());
Toshihiro Shimizu 890ddd
		painter->drawText(rect, elidedName);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::resizeNodes(bool maximizeNodes)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	prepareGeometryChange();
Toshihiro Shimizu 890ddd
	doResizeNodes(maximizeNodes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::mousePressEvent(QGraphicsSceneMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF bRect = boundingRect();
Toshihiro Shimizu 890ddd
	QRectF rect = QRectF(0, 0, 11, 11);
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(QPointF(bRect.width() - 13, 2));
Toshihiro Shimizu 890ddd
	if (rect.contains(e->pos())) {
Toshihiro Shimizu 890ddd
		closeEditor();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rect = QRectF(0, 0, bRect.width(), 15);
Toshihiro Shimizu 890ddd
	if (rect.contains(e->pos())) {
Toshihiro Shimizu 890ddd
		m_button = e->button();
Toshihiro Shimizu 890ddd
		m_lastPos = e->scenePos();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_button == Qt::LeftButton) {
Toshihiro Shimizu 890ddd
		QPointF delta = e->scenePos() - m_lastPos;
Toshihiro Shimizu 890ddd
		setPos(scenePos() + delta);
Toshihiro Shimizu 890ddd
		m_lastPos = e->scenePos();
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
			SchematicNode *node = m_groupedNode[i];
Toshihiro Shimizu 890ddd
			node->setPosition(node->scenePos() + delta);
Toshihiro Shimizu 890ddd
			node->setSchematicNodePos(node->scenePos());
Toshihiro Shimizu 890ddd
			node->updateLinksGeometry();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		e->ignore();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_button = Qt::NoButton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF bRect = boundingRect();
Toshihiro Shimizu 890ddd
	QRectF rect = QRectF(2, 0, bRect.width() - 15, 15);
Toshihiro Shimizu 890ddd
	if (rect.contains(e->pos())) {
Toshihiro Shimizu 890ddd
		m_nameItem->setPlainText(m_groupName);
Toshihiro Shimizu 890ddd
		m_nameItem->show();
Toshihiro Shimizu 890ddd
		m_nameItem->setFocus();
Toshihiro Shimizu 890ddd
		setFlag(QGraphicsItem::ItemIsSelectable, false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SchematicWindowEditor::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF bRect = boundingRect();
Toshihiro Shimizu 890ddd
	QRectF rect(0, 0, bRect.width(), 15);
Toshihiro Shimizu 890ddd
	if (!rect.contains(e->pos())) {
Toshihiro Shimizu 890ddd
		e->ignore();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QMenu menu(scene()->views()[0]);
Toshihiro Shimizu 890ddd
	QAction *close = new QAction(tr("&Close Editor"), &menu);
Toshihiro Shimizu 890ddd
	connect(close, SIGNAL(triggered()), this, SLOT(closeEditor()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	menu.addAction(close);
Toshihiro Shimizu 890ddd
	menu.exec(e->screenPos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//FxSchematicGroupEditor
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxSchematicGroupEditor::FxSchematicGroupEditor(int groupId, const QList<schematicnode *=""> &groupedNode, SchematicScene *scene)</schematicnode>
Toshihiro Shimizu 890ddd
	: SchematicWindowEditor(groupedNode, scene), m_groupId(groupId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	initializeEditor();
Toshihiro Shimizu 890ddd
	setPos(boundingSceneRect().topLeft());
Toshihiro Shimizu 890ddd
	m_nameItem->setName(m_groupName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxSchematicGroupEditor::~FxSchematicGroupEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicGroupEditor::initializeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[0]);</fxschematicnode>
Toshihiro Shimizu 890ddd
	assert(node);
Toshihiro Shimizu 890ddd
	TFx *fx = node->getFx();
Toshihiro Shimizu 890ddd
	assert(fx);
Toshihiro Shimizu 890ddd
	assert(m_groupId == fx->getAttributes()->getEditingGroupId());
Toshihiro Shimizu 890ddd
	m_groupName = QString::fromStdWString(fx->getAttributes()->getEditingGroupName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicGroupEditor::closeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Ptrebbero esserci delle macro aperte per edit nel gruppo...
Toshihiro Shimizu 890ddd
	//devo chiedere alla scena di chiuderle per me... da qui non posso farlo!
Toshihiro Shimizu 890ddd
	FxSchematicScene *fxScene = dynamic_cast<fxschematicscene *="">(scene());</fxschematicscene>
Toshihiro Shimizu 890ddd
	assert(fxScene);
Toshihiro Shimizu 890ddd
	fxScene->closeInnerMacroEditor(m_groupId);
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		if (!node)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		FxGroupNode *groupNode = dynamic_cast<fxgroupnode *="">(node);</fxgroupnode>
Toshihiro Shimizu 890ddd
		if (groupNode) {
Toshihiro Shimizu 890ddd
			QList<tfxp> fxs = groupNode->getGroupedFxs();</tfxp>
Toshihiro Shimizu 890ddd
			assert(!fxs.isEmpty());
Toshihiro Shimizu 890ddd
			int j;
Toshihiro Shimizu 890ddd
			for (j = 0; j < fxs.size(); j++) {
Toshihiro Shimizu 890ddd
				fxs[j]->getAttributes()->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
				TMacroFx *macro = dynamic_cast<tmacrofx *="">(fxs[j].getPointer());</tmacrofx>
Toshihiro Shimizu 890ddd
				if (macro) {
Shinya Kitaoka 3bfa54
					std::vector<tfxp> macroFxs = macro->getFxs();</tfxp>
Toshihiro Shimizu 890ddd
					int j;
Toshihiro Shimizu 890ddd
					for (j = 0; j < (int)macroFxs.size(); j++)
Toshihiro Shimizu 890ddd
						macroFxs[j]->getAttributes()->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			TFx *fx = node->getFx();
Toshihiro Shimizu 890ddd
			assert(fx);
Toshihiro Shimizu 890ddd
			fx->getAttributes()->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
			TMacroFx *macro = dynamic_cast<tmacrofx *="">(fx);</tmacrofx>
Toshihiro Shimizu 890ddd
			if (macro) {
Shinya Kitaoka 3bfa54
				std::vector<tfxp> macroFxs = macro->getFxs();</tfxp>
Toshihiro Shimizu 890ddd
				int j;
Toshihiro Shimizu 890ddd
				for (j = 0; j < (int)macroFxs.size(); j++)
Toshihiro Shimizu 890ddd
					macroFxs[j]->getAttributes()->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_scene->updateScene();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicGroupEditor::onNameChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	QList<tfxp> fxs;</tfxp>
Toshihiro Shimizu 890ddd
	m_nameItem->hide();
Toshihiro Shimizu 890ddd
	m_groupName = m_nameItem->toPlainText();
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		FxGroupNode *groupNode = dynamic_cast<fxgroupnode *="">(m_groupedNode[i]);</fxgroupnode>
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		if (groupNode)
Toshihiro Shimizu 890ddd
			fxs.append(groupNode->getGroupedFxs());
Toshihiro Shimizu 890ddd
		else if (node)
Toshihiro Shimizu 890ddd
			fxs.append(node->getFx());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setFlag(QGraphicsItem::ItemIsSelectable, true);
Toshihiro Shimizu 890ddd
	FxSchematicScene *fxScene = dynamic_cast<fxschematicscene *="">(scene());</fxschematicscene>
Toshihiro Shimizu 890ddd
	if (!fxScene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFxCommand::renameGroup(fxs.toStdList(), m_groupName.toStdWString(), true, fxScene->getXsheetHandle());
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QRectF FxSchematicGroupEditor::boundingSceneRect() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF rect = m_groupedNode[0]->boundingRect();
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(m_groupedNode[0]->scenePos() - rect.topLeft());
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		assert(node);
Toshihiro Shimizu 890ddd
		TFx *fx = node->getFx();
Toshihiro Shimizu 890ddd
		assert(fx);
Toshihiro Shimizu 890ddd
		QRectF app = node->boundingRect();
Toshihiro Shimizu 890ddd
		app.moveTopLeft(node->scenePos() - app.topLeft());
Toshihiro Shimizu 890ddd
		bool isASubgroupedNode = fx->getAttributes()->getEditingGroupId() != m_groupId;
Toshihiro Shimizu 890ddd
		if (isASubgroupedNode) {
Toshihiro Shimizu 890ddd
			QStack<int> idStack = fx->getAttributes()->getGroupIdStack();</int>
Toshihiro Shimizu 890ddd
			int start = idStack.indexOf(fx->getAttributes()->getEditingGroupId());
Toshihiro Shimizu 890ddd
			int k = idStack.indexOf(m_groupId, start) + 1;
Toshihiro Shimizu 890ddd
			int factor = k * 30;
Toshihiro Shimizu 890ddd
			app.adjust(-factor, -factor, factor, factor);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Toshihiro Shimizu 890ddd
		rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
		rect = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rect.adjust(-20, -35, 0, 20);
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicGroupEditor::setGroupedNodeZValue(int zValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i, size = m_groupedNode.size();
Toshihiro Shimizu 890ddd
	for (i = 0; i < size; i++) {
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		if (!node)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if (node->getFx()->getAttributes()->getEditingGroupId() == m_groupId)
Toshihiro Shimizu 890ddd
			node->setZValue(zValue);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicGroupEditor::doResizeNodes(bool maximizeNodes)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//FxSchematicMacroEditor
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxSchematicMacroEditor::FxSchematicMacroEditor(TMacroFx *macro,
Toshihiro Shimizu 890ddd
											   const QList<schematicnode *=""> &groupedNode,</schematicnode>
Toshihiro Shimizu 890ddd
											   SchematicScene *scene)
Toshihiro Shimizu 890ddd
	: SchematicWindowEditor(groupedNode, scene), m_macro(macro)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_isMacroEditor = true;
Toshihiro Shimizu 890ddd
	initializeEditor();
Toshihiro Shimizu 890ddd
	setPos(boundingSceneRect().topLeft());
Toshihiro Shimizu 890ddd
	m_nameItem->setName(m_groupName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxSchematicMacroEditor::~FxSchematicMacroEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::initializeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_groupName = QString::fromStdWString(m_macro->getName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::closeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_macro->editMacro(false);
Toshihiro Shimizu 890ddd
	m_scene->updateScene();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::onNameChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QList<tfxp> fxs;</tfxp>
Toshihiro Shimizu 890ddd
	m_nameItem->hide();
Toshihiro Shimizu 890ddd
	m_groupName = m_nameItem->toPlainText();
Toshihiro Shimizu 890ddd
	setFlag(QGraphicsItem::ItemIsSelectable, true);
Toshihiro Shimizu 890ddd
	FxSchematicScene *fxScene = dynamic_cast<fxschematicscene *="">(scene());</fxschematicscene>
Toshihiro Shimizu 890ddd
	if (!fxScene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFxCommand::renameFx(m_macro, m_groupName.toStdWString(), fxScene->getXsheetHandle());
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QRectF FxSchematicMacroEditor::boundingSceneRect() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF rect = m_groupedNode[0]->boundingRect();
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(m_groupedNode[0]->scenePos() - rect.topLeft());
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		assert(node);
Toshihiro Shimizu 890ddd
		TFx *fx = node->getFx();
Toshihiro Shimizu 890ddd
		assert(fx);
Toshihiro Shimizu 890ddd
		QRectF app = node->boundingRect();
Toshihiro Shimizu 890ddd
		app.moveTopLeft(node->scenePos() - app.topLeft());
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Toshihiro Shimizu 890ddd
		rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
		rect = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rect.adjust(-20, -35, 0, 20);
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::setGroupedNodeZValue(int zValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i, size = m_groupedNode.size();
Toshihiro Shimizu 890ddd
	for (i = 0; i < size; i++) {
Toshihiro Shimizu 890ddd
		FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(m_groupedNode[i]);</fxschematicnode>
Toshihiro Shimizu 890ddd
		if (!node)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		node->setZValue(zValue);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	SchematicWindowEditor::mouseMoveEvent(e);
Toshihiro Shimizu 890ddd
	if (m_button == Qt::LeftButton) {
Toshihiro Shimizu 890ddd
		TFx *root = m_macro->getRoot();
Toshihiro Shimizu 890ddd
		TPointD pos = root->getAttributes()->getDagNodePos();
Toshihiro Shimizu 890ddd
		m_macro->getAttributes()->setDagNodePos(pos);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxSchematicMacroEditor::doResizeNodes(bool maximizeNodes)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_macro->getAttributes()->setIsOpened(maximizeNodes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//StageSchematicGroupEditor
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//=====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StageSchematicGroupEditor::StageSchematicGroupEditor(int groupId, const QList<schematicnode *=""> &groupedNode,</schematicnode>
Toshihiro Shimizu 890ddd
													 SchematicScene *scene)
Toshihiro Shimizu 890ddd
	: SchematicWindowEditor(groupedNode, scene), m_groupId(groupId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	initializeEditor();
Toshihiro Shimizu 890ddd
	setPos(boundingSceneRect().topLeft());
Toshihiro Shimizu 890ddd
	m_nameItem->setName(m_groupName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StageSchematicGroupEditor::~StageSchematicGroupEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QRectF StageSchematicGroupEditor::boundingSceneRect() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRectF rect = m_groupedNode[0]->boundingRect();
Toshihiro Shimizu 890ddd
	rect.moveTopLeft(m_groupedNode[0]->scenePos() - rect.topLeft());
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[i]);</stageschematicnode>
Toshihiro Shimizu 890ddd
		assert(node);
Toshihiro Shimizu 890ddd
		TStageObject *obj = node->getStageObject();
Toshihiro Shimizu 890ddd
		assert(obj);
Toshihiro Shimizu 890ddd
		QRectF app = node->boundingRect();
Toshihiro Shimizu 890ddd
		app.moveTopLeft(node->scenePos() - app.topLeft());
Toshihiro Shimizu 890ddd
		bool isASubgroupedNode = obj->getEditingGroupId() != m_groupId;
Toshihiro Shimizu 890ddd
		if (isASubgroupedNode)
Toshihiro Shimizu 890ddd
			app.adjust(-30, -30, 30, 30);
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Toshihiro Shimizu 890ddd
		rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
		rect = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rect.adjust(-20, -35, 0, 0);
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StageSchematicGroupEditor::setGroupedNodeZValue(int zValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i, size = m_groupedNode.size();
Toshihiro Shimizu 890ddd
	for (i = 0; i < size; i++) {
Toshihiro Shimizu 890ddd
		StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[i]);</stageschematicnode>
Toshihiro Shimizu 890ddd
		if (!node)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if (node->getStageObject()->getEditingGroupId() == m_groupId)
Toshihiro Shimizu 890ddd
			node->setZValue(zValue);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StageSchematicGroupEditor::closeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[i]);</stageschematicnode>
Toshihiro Shimizu 890ddd
		if (!node)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		StageSchematicGroupNode *groupNode = dynamic_cast<stageschematicgroupnode *="">(node);</stageschematicgroupnode>
Toshihiro Shimizu 890ddd
		if (groupNode) {
Toshihiro Shimizu 890ddd
			QList<tstageobject *=""> objs = groupNode->getGroupedObjects();</tstageobject>
Toshihiro Shimizu 890ddd
			assert(!objs.isEmpty());
Toshihiro Shimizu 890ddd
			int j;
Toshihiro Shimizu 890ddd
			for (j = 0; j < objs.size(); j++)
Toshihiro Shimizu 890ddd
				objs[j]->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			TStageObject *obj = node->getStageObject();
Toshihiro Shimizu 890ddd
			assert(obj);
Toshihiro Shimizu 890ddd
			obj->closeEditingGroup(m_groupId);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_scene->updateScene();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StageSchematicGroupEditor::onNameChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	QList<tstageobject *=""> objs;</tstageobject>
Toshihiro Shimizu 890ddd
	m_nameItem->hide();
Toshihiro Shimizu 890ddd
	m_groupName = m_nameItem->toPlainText();
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		StageSchematicGroupNode *groupNode = dynamic_cast<stageschematicgroupnode *="">(m_groupedNode[i]);</stageschematicgroupnode>
Toshihiro Shimizu 890ddd
		StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[i]);</stageschematicnode>
Toshihiro Shimizu 890ddd
		if (groupNode)
Toshihiro Shimizu 890ddd
			objs.append(groupNode->getGroupedObjects());
Toshihiro Shimizu 890ddd
		else if (node)
Toshihiro Shimizu 890ddd
			objs.append(node->getStageObject());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setFlag(QGraphicsItem::ItemIsSelectable, true);
Toshihiro Shimizu 890ddd
	StageSchematicScene *stageScene = dynamic_cast<stageschematicscene *="">(scene());</stageschematicscene>
Toshihiro Shimizu 890ddd
	if (!stageScene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TStageObjectCmd::renameGroup(objs, m_groupName.toStdWString(), true, stageScene->getXsheetHandle());
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StageSchematicGroupEditor::initializeEditor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[0]);</stageschematicnode>
Toshihiro Shimizu 890ddd
	assert(node);
Toshihiro Shimizu 890ddd
	TStageObject *obj = node->getStageObject();
Toshihiro Shimizu 890ddd
	assert(obj);
Toshihiro Shimizu 890ddd
	assert(m_groupId == obj->getEditingGroupId());
Toshihiro Shimizu 890ddd
	m_groupName = QString::fromStdWString(obj->getEditingGroupName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StageSchematicGroupEditor::doResizeNodes(bool maximizeNodes)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_groupedNode.size(); i++) {
Toshihiro Shimizu 890ddd
		StageSchematicNode *node = dynamic_cast<stageschematicnode *="">(m_groupedNode[i]);</stageschematicnode>
Toshihiro Shimizu 890ddd
		assert(node);
Toshihiro Shimizu 890ddd
		node->getStageObject()->setIsOpened(maximizeNodes);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}