Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/palettecontroller.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/stageobjectutil.h"
Toshihiro Shimizu 890ddd
#include "toonz/doubleparamcmd.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzTools includes
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "rasterselectiontool.h"
Toshihiro Shimizu 890ddd
#include "vectorselectiontool.h"
Toshihiro Shimizu 890ddd
// to enable the increase/decrease shortcuts while hiding the tool option
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
// to enable shortcuts only when the viewer is focused
Toshihiro Shimizu 890ddd
#include "tools/tooloptions.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qmainwindow></qmainwindow>
Toshihiro Shimizu 890ddd
#include <qbuttongroup></qbuttongroup>
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tooloptionscontrols.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***********************************************************************************
Toshihiro Shimizu 890ddd
//    ToolOptionControl  implementation
Toshihiro Shimizu 890ddd
//***********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionControl::ToolOptionControl(TTool *tool, string propertyName, ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: m_tool(tool), m_propertyName(propertyName), m_toolHandle(toolHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionControl::notifyTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_tool->onPropertyChanged(m_propertyName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! return true if the control is belonging to the visible combo viewer. very dirty implementation.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
bool ToolOptionControl::isInVisibleViewer(QWidget *widget)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!widget)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (widget->isVisible())
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToolOptionsBox *parentTOB = dynamic_cast<tooloptionsbox *="">(widget->parentWidget());</tooloptionsbox>
Toshihiro Shimizu 890ddd
	if (!parentTOB)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToolOptions *grandParentTO = dynamic_cast<tooloptions *="">(parentTOB->parentWidget());</tooloptions>
Toshihiro Shimizu 890ddd
	if (!grandParentTO)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//There must be a QFrame between a ComboViewerPanel and a ToolOptions
Toshihiro Shimizu 890ddd
	QFrame *greatGrandParentFrame = dynamic_cast<qframe *="">(grandParentTO->parentWidget());</qframe>
Toshihiro Shimizu 890ddd
	if (!greatGrandParentFrame)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return greatGrandParentFrame->isVisible();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***********************************************************************************
Toshihiro Shimizu 890ddd
//    ToolOptionControl derivative  implementations
Toshihiro Shimizu 890ddd
//***********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionCheckbox::ToolOptionCheckbox(TTool *tool, TBoolProperty *property, ToolHandle *toolHandle,
Toshihiro Shimizu 890ddd
									   QWidget *parent)
Toshihiro Shimizu 890ddd
	: CheckBox(parent), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setText(property->getQStringName());
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (toolHandle)
Toshihiro Shimizu 890ddd
		connect(this, SIGNAL(clicked(bool)), toolHandle, SIGNAL(toolChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCheckbox::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool check = m_property->getValue();
Toshihiro Shimizu 890ddd
	if (isChecked() == check)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setCheckState(check ? Qt::Checked : Qt::Unchecked);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCheckbox::nextCheckState()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QAbstractButton::nextCheckState();
Toshihiro Shimizu 890ddd
	m_property->setValue(checkState() == Qt::Checked);
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCheckbox::doClick()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	click();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionSlider::ToolOptionSlider(TTool *tool, TDoubleProperty *property, ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: DoubleField(), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	TDoubleProperty::Range range = property->getRange();
Toshihiro Shimizu 890ddd
	setRange(range.first, range.second);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(valueChanged(bool)), SLOT(onValueChanged(bool)));
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (toolHandle)
Toshihiro Shimizu 890ddd
		connect(this, SIGNAL(valueEditedByHand()), toolHandle, SIGNAL(toolChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionSlider::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double v = m_property->getValue();
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionSlider::onValueChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionSlider::increase()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double value = getValue();
Toshihiro Shimizu 890ddd
	double minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value += 1;
Toshihiro Shimizu 890ddd
	if (value > maxValue)
Toshihiro Shimizu 890ddd
		value = maxValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionSlider::decrease()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double value = getValue();
Toshihiro Shimizu 890ddd
	double minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value -= 1;
Toshihiro Shimizu 890ddd
	if (value < minValue)
Toshihiro Shimizu 890ddd
		value = minValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionPairSlider::ToolOptionPairSlider(TTool *tool, TDoublePairProperty *property,
Toshihiro Shimizu 890ddd
										   const QString &leftName, const QString &rightName,
Toshihiro Shimizu 890ddd
										   ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: DoublePairField(0, property->isMaxRangeLimited()), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setLeftText(leftName);
Toshihiro Shimizu 890ddd
	setRightText(rightName);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	TDoublePairProperty::Value value = property->getValue();
Toshihiro Shimizu 890ddd
	TDoublePairProperty::Range range = property->getRange();
Toshihiro Shimizu 890ddd
	setRange(range.first, range.second);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(valuesChanged(bool)), SLOT(onValuesChanged(bool)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDoublePairProperty::Value value = m_property->getValue();
Toshihiro Shimizu 890ddd
	setValues(value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::onValuesChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (m_toolHandle)
Toshihiro Shimizu 890ddd
		m_toolHandle->notifyToolChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::increaseMaxValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> values = getValues();</double,>
Toshihiro Shimizu 890ddd
	double minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	values.second += 1;
Toshihiro Shimizu 890ddd
	if (values.second > maxValue)
Toshihiro Shimizu 890ddd
		values.second = maxValue;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::decreaseMaxValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> values = getValues();</double,>
Toshihiro Shimizu 890ddd
	values.second -= 1;
Toshihiro Shimizu 890ddd
	if (values.second < values.first)
Toshihiro Shimizu 890ddd
		values.second = values.first;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::increaseMinValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> values = getValues();</double,>
Toshihiro Shimizu 890ddd
	values.first += 1;
Toshihiro Shimizu 890ddd
	if (values.first > values.second)
Toshihiro Shimizu 890ddd
		values.first = values.second;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPairSlider::decreaseMinValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> values = getValues();</double,>
Toshihiro Shimizu 890ddd
	double minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	values.first -= 1;
Toshihiro Shimizu 890ddd
	if (values.first < minValue)
Toshihiro Shimizu 890ddd
		values.first = minValue;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionIntPairSlider::ToolOptionIntPairSlider(TTool *tool, TIntPairProperty *property,
Toshihiro Shimizu 890ddd
												 const QString &leftName, const QString &rightName,
Toshihiro Shimizu 890ddd
												 ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: IntPairField(0, property->isMaxRangeLimited()), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setLeftText(leftName);
Toshihiro Shimizu 890ddd
	setRightText(rightName);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	TIntPairProperty::Value value = property->getValue();
Toshihiro Shimizu 890ddd
	TIntPairProperty::Range range = property->getRange();
Toshihiro Shimizu 890ddd
	setRange(range.first, range.second);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(valuesChanged(bool)), SLOT(onValuesChanged(bool)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TIntPairProperty::Value value = m_property->getValue();
Toshihiro Shimizu 890ddd
	setValues(value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::onValuesChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (m_toolHandle)
Toshihiro Shimizu 890ddd
		m_toolHandle->notifyToolChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::increaseMaxValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> values = getValues();</int,>
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	values.second += 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// a "cross-like shape" of the brush size = 3 is hard to use. so skip it
Toshihiro Shimizu 890ddd
	if (values.second == 3 && m_tool->isPencilModeActive())
Toshihiro Shimizu 890ddd
		values.second += 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (values.second > maxValue)
Toshihiro Shimizu 890ddd
		values.second = maxValue;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::decreaseMaxValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> values = getValues();</int,>
Toshihiro Shimizu 890ddd
	values.second -= 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// a "cross-like shape" of the brush size = 3 is hard to use. so skip it
Toshihiro Shimizu 890ddd
	if (values.second == 3 && m_tool->isPencilModeActive())
Toshihiro Shimizu 890ddd
		values.second -= 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (values.second < values.first)
Toshihiro Shimizu 890ddd
		values.second = values.first;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::increaseMinValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> values = getValues();</int,>
Toshihiro Shimizu 890ddd
	values.first += 1;
Toshihiro Shimizu 890ddd
	if (values.first > values.second)
Toshihiro Shimizu 890ddd
		values.first = values.second;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntPairSlider::decreaseMinValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> values = getValues();</int,>
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	values.first -= 1;
Toshihiro Shimizu 890ddd
	if (values.first < minValue)
Toshihiro Shimizu 890ddd
		values.first = minValue;
Toshihiro Shimizu 890ddd
	setValues(values);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValues());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionIntSlider::ToolOptionIntSlider(TTool *tool, TIntProperty *property,
Toshihiro Shimizu 890ddd
										 ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: IntField(0, property->isMaxRangeLimited()), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	TIntProperty::Range range = property->getRange();
Toshihiro Shimizu 890ddd
	setRange(range.first, range.second);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(valueChanged(bool)), SLOT(onValueChanged(bool)));
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (toolHandle)
Toshihiro Shimizu 890ddd
		connect(this, SIGNAL(valueEditedByHand()), toolHandle, SIGNAL(toolChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntSlider::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int v = m_property->getValue();
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntSlider::increase()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int value = getValue();
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	value += 1;
Toshihiro Shimizu 890ddd
	// a "cross-like shape" of the brush size = 3 is hard to use. so skip it
Toshihiro Shimizu 890ddd
	if (value == 3 && m_tool->isPencilModeActive())
Toshihiro Shimizu 890ddd
		value += 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (value > maxValue)
Toshihiro Shimizu 890ddd
		value = maxValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntSlider::decrease()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int value = getValue();
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	value -= 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// a "cross-like shape" of the brush size = 3 is hard to use. so skip it
Toshihiro Shimizu 890ddd
	if (value == 3 && m_tool->isPencilModeActive())
Toshihiro Shimizu 890ddd
		value -= 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (value < minValue)
Toshihiro Shimizu 890ddd
		value = minValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	//update the interface
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionIntSlider::onValueChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->setValue(getValue());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionCombo::ToolOptionCombo(TTool *tool, TEnumProperty *property, ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: QComboBox(), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setMinimumWidth(65);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
	loadEntries();
Toshihiro Shimizu 890ddd
	setSizeAdjustPolicy(QComboBox::AdjustToContents);
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int)));
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (toolHandle)
Toshihiro Shimizu 890ddd
		connect(this, SIGNAL(activated(int)), toolHandle, SIGNAL(toolChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCombo::loadEntries()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TEnumProperty::Range range = m_property->getRange();
Toshihiro Shimizu 890ddd
	TEnumProperty::Range::iterator it;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	clear();
Toshihiro Shimizu 890ddd
	for (it = range.begin(); it != range.end(); ++it)
Toshihiro Shimizu 890ddd
		addItem(QString::fromStdWString(*it));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCombo::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString value = QString::fromStdWString(m_property->getValue());
Toshihiro Shimizu 890ddd
	int index = findText(value);
Toshihiro Shimizu 890ddd
	if (index >= 0 && index != currentIndex())
Toshihiro Shimizu 890ddd
		setCurrentIndex(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCombo::onActivated(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const TEnumProperty::Range &range = m_property->getRange();
Toshihiro Shimizu 890ddd
	if (index < 0 || index >= (int)range.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	wstring item = range[index];
Toshihiro Shimizu 890ddd
	m_property->setValue(item);
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCombo::doShowPopup()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isVisible())
Toshihiro Shimizu 890ddd
		showPopup();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionCombo::doOnActivated(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolHandle && m_toolHandle->getTool() != m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	// active only if the belonging combo-viewer is visible
Toshihiro Shimizu 890ddd
	if (!isInVisibleViewer(this))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Just move the index if the first item is not "Normal"
Toshihiro Shimizu 890ddd
	if (itemText(0) != "Normal") {
Toshihiro Shimizu 890ddd
		onActivated(index);
Toshihiro Shimizu 890ddd
		setCurrentIndex(index);
Toshihiro Shimizu 890ddd
		//for updating the cursor
Toshihiro Shimizu 890ddd
		m_toolHandle->notifyToolChanged();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// If the first item of this combo box is "Normal", enable shortcut key toggle can "back and forth" behavior.
Toshihiro Shimizu 890ddd
	if (currentIndex() == index) {
Toshihiro Shimizu 890ddd
		// estimating that the "Normal" option is located at the index 0
Toshihiro Shimizu 890ddd
		onActivated(0);
Toshihiro Shimizu 890ddd
		setCurrentIndex(0);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		onActivated(index);
Toshihiro Shimizu 890ddd
		setCurrentIndex(index);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// for updating a cursor without any effect to the tool options
Toshihiro Shimizu 890ddd
	m_toolHandle->notifyToolCursorTypeChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionPopupButton::ToolOptionPopupButton(TTool *tool, TEnumProperty *property)
Toshihiro Shimizu 890ddd
	: PopupButton(), ToolOptionControl(tool, property->getName()), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setObjectName(QString::fromStdString(property->getName()));
Toshihiro Shimizu 890ddd
	setFixedHeight(20);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEnumProperty::Range range = property->getRange();
Toshihiro Shimizu 890ddd
	TEnumProperty::Range::iterator it;
Toshihiro Shimizu 890ddd
	for (it = range.begin(); it != range.end(); ++it)
Toshihiro Shimizu 890ddd
		addItem(createQIconPNG(QString::fromStdWString(*it).toUtf8()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setCurrentIndex(0);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPopupButton::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int index = m_property->getIndex();
Toshihiro Shimizu 890ddd
	if (index >= 0 && index != currentIndex())
Toshihiro Shimizu 890ddd
		setCurrentIndex(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPopupButton::onActivated(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const TEnumProperty::Range &range = m_property->getRange();
Toshihiro Shimizu 890ddd
	if (index < 0 || index >= (int)range.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	wstring item = range[index];
Toshihiro Shimizu 890ddd
	m_property->setValue(item);
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPopupButton::doShowPopup()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isVisible())
Toshihiro Shimizu 890ddd
		showMenu();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPopupButton::doSetCurrentIndex(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isVisible())
Toshihiro Shimizu 890ddd
		setCurrentIndex(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionPopupButton::doOnActivated(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isVisible())
Toshihiro Shimizu 890ddd
		onActivated(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionTextField::ToolOptionTextField(TTool *tool, TStringProperty *property)
Toshihiro Shimizu 890ddd
	: LineEdit(), ToolOptionControl(tool, property->getName()), m_property(property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFixedSize(100, 23);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(editingFinished()), SLOT(onValueChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionTextField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString newText = QString::fromStdWString(m_property->getValue());
Toshihiro Shimizu 890ddd
	if (newText == text())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setText(newText);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionTextField::onValueChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->setValue(text().toStdWString());
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (m_toolHandle)
Toshihiro Shimizu 890ddd
		m_toolHandle->notifyToolChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StyleIndexFieldAndChip::StyleIndexFieldAndChip(TTool *tool, TStyleIndexProperty *property, TPaletteHandle *pltHandle,
Toshihiro Shimizu 890ddd
											   ToolHandle *toolHandle)
Toshihiro Shimizu 890ddd
	: StyleIndexLineEdit(), ToolOptionControl(tool, property->getName(), toolHandle), m_property(property), m_pltHandle(pltHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(textChanged(const QString &)), SLOT(onValueChanged(const QString &)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setPaletteHandle(pltHandle);
Toshihiro Shimizu 890ddd
	connect(pltHandle, SIGNAL(colorStyleSwitched()), SLOT(updateColor()));
Toshihiro Shimizu 890ddd
	connect(pltHandle, SIGNAL(colorStyleChanged()), SLOT(updateColor()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StyleIndexFieldAndChip::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString newText = QString::fromStdWString(m_property->getValue());
Toshihiro Shimizu 890ddd
	if (newText == text())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setText(newText);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StyleIndexFieldAndChip::onValueChanged(const QString &changedText)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString style;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!QString("current").contains(changedText)) {
Toshihiro Shimizu 890ddd
		int index = changedText.toInt();
Toshihiro Shimizu 890ddd
		TPalette *plt = m_pltHandle->getPalette();
Toshihiro Shimizu 890ddd
		int indexCount = plt->getStyleCount();
Toshihiro Shimizu 890ddd
		if (index > indexCount)
Toshihiro Shimizu 890ddd
			style = QString::number(indexCount - 1);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			style = text();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_property->setValue(style.toStdWString());
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
	// synchronize the state with the same widgets in other tool option bars
Toshihiro Shimizu 890ddd
	if (m_toolHandle)
Toshihiro Shimizu 890ddd
		m_toolHandle->notifyToolChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StyleIndexFieldAndChip::updateColor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	repaint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionParamRelayField::ToolOptionParamRelayField(
Toshihiro Shimizu 890ddd
	TTool *tool, TDoubleParamRelayProperty *property, int decimals)
Toshihiro Shimizu 890ddd
	: MeasuredDoubleLineEdit(), ToolOptionControl(tool, property->getName()), m_param(), m_measure(), m_property(property), m_globalKey(), m_globalGroup()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFixedSize(70, 20);
Toshihiro Shimizu 890ddd
	m_property->addListener(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setDecimals(decimals);
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(valueChanged()), SLOT(onValueChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionParamRelayField::setGlobalKey(TBoolProperty *globalKey, TPropertyGroup *globalGroup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_globalKey = globalKey, m_globalGroup = globalGroup;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionParamRelayField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDoubleParamP param(m_property->getParam());
Toshihiro Shimizu 890ddd
	if (param != m_param) {
Toshihiro Shimizu 890ddd
		// Initialize param referencing
Toshihiro Shimizu 890ddd
		m_param = param.getPointer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (param) {
Toshihiro Shimizu 890ddd
			m_measure = param->getMeasure();
Toshihiro Shimizu 890ddd
			setMeasure(m_measure ? m_measure->getName() : "");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			setValue(m_property->getValue());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!param) {
Toshihiro Shimizu 890ddd
		setEnabled(false);
Toshihiro Shimizu 890ddd
		m_measure = 0;
Toshihiro Shimizu 890ddd
		setText("");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setEnabled(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasure *measure = param->getMeasure();
Toshihiro Shimizu 890ddd
	if (measure != m_measure) {
Toshihiro Shimizu 890ddd
		// Update measure if needed
Toshihiro Shimizu 890ddd
		m_measure = measure;
Toshihiro Shimizu 890ddd
		setMeasure(measure ? measure->getName() : "");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = m_property->getValue();
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Update value if needed
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolOptionParamRelayField::onValueChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	struct locals {
Toshihiro Shimizu 890ddd
		static inline void setKeyframe(TDoubleParamRelayProperty *prop)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if (!prop)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TDoubleParam *param = prop->getParam().getPointer();
Toshihiro Shimizu 890ddd
			if (!param)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			double frame = prop->frame();
Toshihiro Shimizu 890ddd
			if (!param->isKeyframe(frame)) {
Toshihiro Shimizu 890ddd
				KeyframeSetter setter(param, -1, true);
Toshihiro Shimizu 890ddd
				setter.createKeyframe(frame);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		struct SetValueUndo : public TUndo {
Toshihiro Shimizu 890ddd
			TDoubleParamP m_param;	 //!< The referenced param
Toshihiro Shimizu 890ddd
			double m_oldVal, m_newVal; //!< Values before and after the set action...
Toshihiro Shimizu 890ddd
			double m_frame;			   //!< ... at this frame
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		public:
Toshihiro Shimizu 890ddd
			SetValueUndo(const TDoubleParamP ¶m, double oldVal, double newVal, double frame)
Toshihiro Shimizu 890ddd
				: m_param(param), m_oldVal(oldVal), m_newVal(newVal), m_frame(frame) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			int getSize() const { return sizeof(SetValueUndo) + sizeof(TDoubleParam); }
Toshihiro Shimizu 890ddd
			void undo() const { m_param->setValue(m_frame, m_oldVal); }
Toshihiro Shimizu 890ddd
			void redo() const { m_param->setValue(m_frame, m_newVal); }
Toshihiro Shimizu 890ddd
		};
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// NOTE: Values are extracted upon entry, since setting a keyframe reverts the lineEdit
Toshihiro Shimizu 890ddd
	// field value back to the original value (due to feedback from the param itself)...
Toshihiro Shimizu 890ddd
	double oldVal = m_property->getValue(), newVal = getValue(), frame = m_property->frame();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP param = m_property->getParam();
Toshihiro Shimizu 890ddd
	if (!param)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager *manager = TUndoManager::manager();
Toshihiro Shimizu 890ddd
	manager->beginBlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_globalKey && m_globalGroup && m_globalKey->getValue()) {
Toshihiro Shimizu 890ddd
		// Set a keyframe for each of the TDoubleParam relayed in the globalGroup
Toshihiro Shimizu 890ddd
		int p, pCount = m_globalGroup->getPropertyCount();
Toshihiro Shimizu 890ddd
		for (p = 0; p != pCount; ++p) {
Toshihiro Shimizu 890ddd
			TProperty *prop = m_globalGroup->getProperty(p);
Toshihiro Shimizu 890ddd
			if (TDoubleParamRelayProperty *relProp = dynamic_cast<tdoubleparamrelayproperty *="">(prop))</tdoubleparamrelayproperty>
Toshihiro Shimizu 890ddd
				locals::setKeyframe(relProp);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		// Set a keyframe just for our param
Toshihiro Shimizu 890ddd
		locals::setKeyframe(m_property);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Assign the edited value to the relayed param
Toshihiro Shimizu 890ddd
	m_property->setValue(newVal);
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	manager->add(new locals::SetValueUndo(param, oldVal, newVal, frame));
Toshihiro Shimizu 890ddd
	manager->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Widget specifici di ArrowTool (derivati da ToolOptionControl)
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// SPOSTA in un file a parte!
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
MeasuredValueField::MeasuredValueField(QWidget *parent, QString name)
Toshihiro Shimizu 890ddd
	: LineEdit(name, parent), m_isGlobalKeyframe(false), m_modified(false), m_errorHighlighting(false), m_precision(2)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setObjectName("MeasuredValueField");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_value = new TMeasuredValue("length");
Toshihiro Shimizu 890ddd
	setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(onTextChanged(const QString &)));
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(editingFinished()), SLOT(commit()));
Toshihiro Shimizu 890ddd
	connect(&m_errorHighlightingTimer, SIGNAL(timeout()), this, SLOT(errorHighlightingTick()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
MeasuredValueField::~MeasuredValueField()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::setMeasure(string name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// for reproducing the precision
Toshihiro Shimizu 890ddd
	int oldPrec = -1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	delete m_value;
Toshihiro Shimizu 890ddd
	m_value = new TMeasuredValue(name != "" ? name : "dummy");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::commit()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_modified && !isReturnPressed())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int err = 1;
Toshihiro Shimizu 890ddd
	bool isSet = m_value->setValue(text().toStdWString(), &err);
Toshihiro Shimizu 890ddd
	m_modified = false;
Toshihiro Shimizu 890ddd
	if (err != 0) {
Toshihiro Shimizu 890ddd
		setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
		m_errorHighlighting = 1;
Toshihiro Shimizu 890ddd
		if (!m_errorHighlightingTimer.isActive())
Toshihiro Shimizu 890ddd
			m_errorHighlightingTimer.start(40);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (m_errorHighlightingTimer.isActive())
Toshihiro Shimizu 890ddd
			m_errorHighlightingTimer.stop();
Toshihiro Shimizu 890ddd
		m_errorHighlighting = 0;
Toshihiro Shimizu 890ddd
		setStyleSheet("");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!isSet && !isReturnPressed())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
	m_modified = false;
Toshihiro Shimizu 890ddd
	emit measuredValueChanged(m_value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::onTextChanged(const QString &)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_modified = true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::setValue(double v)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_value->setValue(TMeasuredValue::MainUnit, v);
Toshihiro Shimizu 890ddd
	setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double MeasuredValueField::getValue() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_value->getValue(TMeasuredValue::MainUnit);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::errorHighlightingTick()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_errorHighlighting < 0.01) {
Toshihiro Shimizu 890ddd
		if (m_errorHighlightingTimer.isActive())
Toshihiro Shimizu 890ddd
			m_errorHighlightingTimer.stop();
Toshihiro Shimizu 890ddd
		m_errorHighlighting = 0;
Toshihiro Shimizu 890ddd
		setStyleSheet("");
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int v = 255 - (int)(m_errorHighlighting * 255);
Toshihiro Shimizu 890ddd
		m_errorHighlighting = m_errorHighlighting * 0.8;
Toshihiro Shimizu 890ddd
		int c = 255 << 16 | v << 8 | v;
Toshihiro Shimizu 890ddd
		setStyleSheet(QString("#MeasuredValueField {background-color:#%1}").arg(c, 6, 16, QLatin1Char('0')));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeasuredValueField::setPrecision(int precision)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_precision = precision;
Toshihiro Shimizu 890ddd
	setText(QString::fromStdWString(m_value->toWideString(m_precision)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PegbarChannelField::PegbarChannelField(TTool *tool, enum TStageObject::Channel actionId, QString name,
Toshihiro Shimizu 890ddd
									   TFrameHandle *frameHandle, TObjectHandle *objHandle, TXsheetHandle *xshHandle,
Toshihiro Shimizu 890ddd
									   QWidget *parent)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(parent, name), ToolOptionControl(tool, ""), m_actionId(actionId), m_frameHandle(frameHandle), m_objHandle(objHandle), m_xshHandle(xshHandle), m_scaleType(eNone)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)),
Toshihiro Shimizu 890ddd
					   SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
	// NOTA: per le unita' di misura controlla anche tpegbar.cpp
Toshihiro Shimizu 890ddd
	switch (actionId) {
Toshihiro Shimizu 890ddd
	case TStageObject::T_X:
Toshihiro Shimizu 890ddd
		setMeasure("length.x");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_Y:
Toshihiro Shimizu 890ddd
		setMeasure("length.y");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_Z:
Toshihiro Shimizu 890ddd
		setMeasure("zdepth");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_Path:
Toshihiro Shimizu 890ddd
		setMeasure("percentage2");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_ShearX:
Toshihiro Shimizu 890ddd
	case TStageObject::T_ShearY:
Toshihiro Shimizu 890ddd
		setMeasure("shear");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_Angle:
Toshihiro Shimizu 890ddd
		setMeasure("angle");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TStageObject::T_ScaleX:
Toshihiro Shimizu 890ddd
	case TStageObject::T_ScaleY:
Toshihiro Shimizu 890ddd
	case TStageObject::T_Scale:
Toshihiro Shimizu 890ddd
		setMeasure("scale");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	default:
Toshihiro Shimizu 890ddd
		setMeasure("dummy");
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PegbarChannelField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool->isEnabled())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
	TStageObjectValues before;
Toshihiro Shimizu 890ddd
	before.setFrameHandle(m_frameHandle);
Toshihiro Shimizu 890ddd
	before.setObjectHandle(m_objHandle);
Toshihiro Shimizu 890ddd
	before.setXsheetHandle(m_xshHandle);
Toshihiro Shimizu 890ddd
	before.add(m_actionId);
Toshihiro Shimizu 890ddd
	bool modifyConnectedActionId = false;
Toshihiro Shimizu 890ddd
	if (m_scaleType != eNone) {
Toshihiro Shimizu 890ddd
		modifyConnectedActionId = true;
Toshihiro Shimizu 890ddd
		if (m_actionId == TStageObject::T_ScaleX)
Toshihiro Shimizu 890ddd
			before.add(TStageObject::T_ScaleY);
Toshihiro Shimizu 890ddd
		else if (m_actionId == TStageObject::T_ScaleY)
Toshihiro Shimizu 890ddd
			before.add(TStageObject::T_ScaleX);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			modifyConnectedActionId = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_isGlobalKeyframe) {
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_Angle);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_X);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_Y);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_Z);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_SO);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_ScaleX);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_ScaleY);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_Scale);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_Path);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_ShearX);
Toshihiro Shimizu 890ddd
		before.add(TStageObject::T_ShearY);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	before.updateValues();
Toshihiro Shimizu 890ddd
	TStageObjectValues after;
Toshihiro Shimizu 890ddd
	after = before;
Toshihiro Shimizu 890ddd
	double v = fld->getValue(TMeasuredValue::MainUnit);
Toshihiro Shimizu 890ddd
	if (modifyConnectedActionId) {
Toshihiro Shimizu 890ddd
		double oldv1 = after.getValue(0);
Toshihiro Shimizu 890ddd
		double oldv2 = after.getValue(1);
Toshihiro Shimizu 890ddd
		double newV;
Toshihiro Shimizu 890ddd
		if (m_scaleType == eAR)
Toshihiro Shimizu 890ddd
			newV = (v / oldv1) * oldv2;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			newV = (v == 0) ? 10000 : (1 / v) * (oldv1 * oldv2);
Toshihiro Shimizu 890ddd
		after.setValues(v, newV);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		after.setValue(v);
Toshihiro Shimizu 890ddd
	after.applyValues();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool::Viewer *viewer = m_tool->getViewer();
Toshihiro Shimizu 890ddd
	if (viewer)
Toshihiro Shimizu 890ddd
		m_tool->invalidate();
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoStageObjectMove *undo = new UndoStageObjectMove(before, after);
Toshihiro Shimizu 890ddd
	undo->setObjectHandle(m_objHandle);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
	m_objHandle->notifyObjectIdChanged(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PegbarChannelField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_tool->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_tool->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	if (m_actionId == TStageObject::T_Z)
Toshihiro Shimizu 890ddd
		setMeasure(objId.isCamera() ? "zdepth.cam" : "zdepth");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = xsh->getStageObject(objId)->getParam(m_actionId, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PegbarChannelField::onScaleTypeChanged(int type)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_scaleType = (ScaleType)type;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PegbarCenterField::PegbarCenterField(TTool *tool, int index, QString name, TObjectHandle *objHandle, TXsheetHandle *xshHandle,
Toshihiro Shimizu 890ddd
									 QWidget *parent)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(parent, name), ToolOptionControl(tool, ""), m_index(index), m_objHandle(objHandle), m_xshHandle(xshHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	setMeasure(m_index == 0 ? "length.x" : "length.y");
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)), SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PegbarCenterField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool->isEnabled())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_tool->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_tool->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObject *obj = xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = fld->getValue(TMeasuredValue::MainUnit);
Toshihiro Shimizu 890ddd
	TPointD center = obj->getCenter(frame);
Toshihiro Shimizu 890ddd
	TPointD oldCenter = center;
Toshihiro Shimizu 890ddd
	if (m_index == 0)
Toshihiro Shimizu 890ddd
		center.x = v;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		center.y = v;
Toshihiro Shimizu 890ddd
	obj->setCenter(frame, center);
Toshihiro Shimizu 890ddd
	m_tool->invalidate();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoStageObjectCenterMove *undo = new UndoStageObjectCenterMove(objId, frame, oldCenter, center);
Toshihiro Shimizu 890ddd
	undo->setObjectHandle(m_objHandle);
Toshihiro Shimizu 890ddd
	undo->setXsheetHandle(m_xshHandle);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_objHandle->notifyObjectIdChanged(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PegbarCenterField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_tool->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_tool->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *obj = xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
	TPointD center = obj->getCenter(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = m_index == 0 ? center.x : center.y;
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
NoScaleField::NoScaleField(TTool *tool, QString name)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(0, name), ToolOptionControl(tool, "")
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	setMeasure("zdepth");
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)),
Toshihiro Shimizu 890ddd
			SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void NoScaleField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool->isEnabled())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_tool->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_tool->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *obj = xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_isGlobalKeyframe)
Toshihiro Shimizu 890ddd
		xsh->getStageObject(objId)->setKeyframeWithoutUndo(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = fld->getValue(TMeasuredValue::MainUnit);
Toshihiro Shimizu 890ddd
	obj->setNoScaleZ(v);
Toshihiro Shimizu 890ddd
	m_tool->invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void NoScaleField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_tool->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_tool->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = m_tool->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *obj = xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double v = obj->getNoScaleZ();
Toshihiro Shimizu 890ddd
	if (getValue() == v)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	setValue(v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PropertyMenuButton::PropertyMenuButton(QWidget *parent, TTool *tool,
Toshihiro Shimizu 890ddd
									   QList<tboolproperty *=""> properties,</tboolproperty>
Toshihiro Shimizu 890ddd
									   QIcon icon, QString tooltip)
Toshihiro Shimizu 890ddd
	: QToolButton(parent), ToolOptionControl(tool, ""), m_properties(properties)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setPopupMode(QToolButton::InstantPopup);
Toshihiro Shimizu 890ddd
	setIcon(icon);
Toshihiro Shimizu 890ddd
	setToolTip(tooltip);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QMenu *menu = new QMenu(tooltip, this);
Toshihiro Shimizu 890ddd
	if (!tooltip.isEmpty())
Toshihiro Shimizu 890ddd
		tooltip = tooltip + " ";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QActionGroup *actiongroup = new QActionGroup(this);
Toshihiro Shimizu 890ddd
	actiongroup->setExclusive(false);
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_properties.count(); i++) {
Toshihiro Shimizu 890ddd
		TBoolProperty *prop = m_properties.at(i);
Toshihiro Shimizu 890ddd
		QString propertyName = prop->getQStringName();
Toshihiro Shimizu 890ddd
		//Se il tooltip essagnato e' contenuto nel nome della proprieta' lo levo dalla stringa dell'azione
Toshihiro Shimizu 890ddd
		if (propertyName.contains(tooltip))
Toshihiro Shimizu 890ddd
			propertyName.remove(tooltip);
Toshihiro Shimizu 890ddd
		QAction *action = menu->addAction(propertyName);
Toshihiro Shimizu 890ddd
		action->setCheckable(true);
Toshihiro Shimizu 890ddd
		action->setChecked(prop->getValue());
Toshihiro Shimizu 890ddd
		action->setData(QVariant(i));
Toshihiro Shimizu 890ddd
		actiongroup->addAction(action);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool ret = connect(actiongroup, SIGNAL(triggered(QAction *)), SLOT(onActionTriggered(QAction *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setMenu(menu);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PropertyMenuButton::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QMenu *m = menu();
Toshihiro Shimizu 890ddd
	assert(m);
Toshihiro Shimizu 890ddd
	QList<qaction *=""> actionList = m->actions();</qaction>
Toshihiro Shimizu 890ddd
	assert(actionList.count() == m_properties.count());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_properties.count(); i++) {
Toshihiro Shimizu 890ddd
		TBoolProperty *prop = m_properties.at(i);
Toshihiro Shimizu 890ddd
		QAction *action = actionList.at(i);
Toshihiro Shimizu 890ddd
		bool isPropertyLocked = prop->getValue();
Toshihiro Shimizu 890ddd
		if (action->isChecked() != isPropertyLocked)
Toshihiro Shimizu 890ddd
			action->setChecked(isPropertyLocked);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PropertyMenuButton::onActionTriggered(QAction *action)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int currentPropertyIndex = action->data().toInt();
Toshihiro Shimizu 890ddd
	TBoolProperty *prop = m_properties.at(currentPropertyIndex);
Toshihiro Shimizu 890ddd
	bool isChecked = action->isChecked();
Toshihiro Shimizu 890ddd
	if (isChecked == prop->getValue())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	prop->setValue(isChecked);
Toshihiro Shimizu 890ddd
	notifyTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	emit onPropertyChanged(QString(prop->getName().c_str()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//id == 0 Scale X
Toshihiro Shimizu 890ddd
//id == 0 Scale Y
Toshihiro Shimizu 890ddd
SelectionScaleField::SelectionScaleField(SelectionTool *tool, int id, QString name)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(0, name), m_tool(tool), m_id(id)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)), SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
	setMeasure("scale");
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool SelectionScaleField::applyChange()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType()))
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	DragSelectionTool::DragTool *scaleTool = createNewScaleTool(m_tool, 0);
Toshihiro Shimizu 890ddd
	double p = getValue();
Toshihiro Shimizu 890ddd
	if (p == 0)
Toshihiro Shimizu 890ddd
		p = 0.00001;
Toshihiro Shimizu 890ddd
	DragSelectionTool::FourPoints points = m_tool->getBBox();
Toshihiro Shimizu 890ddd
	TPointD center = m_tool->getCenter();
Toshihiro Shimizu 890ddd
	TPointD p0M = points.getPoint(7);
Toshihiro Shimizu 890ddd
	TPointD p1M = points.getPoint(5);
Toshihiro Shimizu 890ddd
	TPointD pM1 = points.getPoint(6);
Toshihiro Shimizu 890ddd
	TPointD pM0 = points.getPoint(4);
Toshihiro Shimizu 890ddd
	int pointIndex;
Toshihiro Shimizu 890ddd
	TPointD sign(1, 1);
Toshihiro Shimizu 890ddd
	TPointD scaleFactor = m_tool->m_deformValues.m_scaleValue;
Toshihiro Shimizu 890ddd
	TPointD newPos;
Toshihiro Shimizu 890ddd
	if (m_id == 0) {
Toshihiro Shimizu 890ddd
		if (p1M == p0M)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		pointIndex = 7;
Toshihiro Shimizu 890ddd
		TPointD v = normalize(p1M - p0M);
Toshihiro Shimizu 890ddd
		double currentD = tdistance(p1M, p0M);
Toshihiro Shimizu 890ddd
		double startD = currentD / scaleFactor.x;
Toshihiro Shimizu 890ddd
		double d = (currentD - startD * p) * tdistance(center, p0M) / currentD;
Toshihiro Shimizu 890ddd
		newPos = TPointD(p0M.x + d * v.x, p0M.y + d * v.y);
Toshihiro Shimizu 890ddd
		scaleFactor.x = p;
Toshihiro Shimizu 890ddd
	} else if (m_id == 1) {
Toshihiro Shimizu 890ddd
		if (pM1 == pM0)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		pointIndex = 4;
Toshihiro Shimizu 890ddd
		TPointD v = normalize(pM1 - pM0);
Toshihiro Shimizu 890ddd
		double currentD = tdistance(pM1, pM0);
Toshihiro Shimizu 890ddd
		double startD = currentD / scaleFactor.y;
Toshihiro Shimizu 890ddd
		double d = (currentD - startD * p) * tdistance(center, pM0) / currentD;
Toshihiro Shimizu 890ddd
		newPos = TPointD(pM0.x + d * v.x, pM0.y + d * v.y);
Toshihiro Shimizu 890ddd
		scaleFactor.y = p;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_tool->m_deformValues.m_scaleValue = scaleFactor; // Instruction order is relevant
Toshihiro Shimizu 890ddd
	scaleTool->transform(pointIndex, newPos);		   // This line invokes GUI update using the
Toshihiro Shimizu 890ddd
													   // value set above
Toshihiro Shimizu 890ddd
	if (!m_tool->isLevelType())
Toshihiro Shimizu 890ddd
		scaleTool->addTransformUndo();
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionScaleField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool->isEnabled())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (!applyChange())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	emit valueChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionScaleField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) {
Toshihiro Shimizu 890ddd
		setValue(0);
Toshihiro Shimizu 890ddd
		setDisabled(true);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setDisabled(false);
Toshihiro Shimizu 890ddd
	if (m_id == 0)
Toshihiro Shimizu 890ddd
		setValue(m_tool->m_deformValues.m_scaleValue.x);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		setValue(m_tool->m_deformValues.m_scaleValue.y);
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SelectionRotationField::SelectionRotationField(SelectionTool *tool, QString name)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(0, name), m_tool(tool)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)), SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
	setMeasure("angle");
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionRotationField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || !m_tool->isEnabled() || (m_tool->isSelectionEmpty() && !m_tool->isLevelType()))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragSelectionTool::DragTool *rotationTool = createNewRotationTool(m_tool);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragSelectionTool::DeformValues &deformValues = m_tool->m_deformValues;
Toshihiro Shimizu 890ddd
	double p = getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine aff = TRotation(m_tool->getCenter(), p - deformValues.m_rotationAngle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	deformValues.m_rotationAngle = p;								// Instruction order is relevant here
Toshihiro Shimizu 890ddd
	rotationTool->transform(aff, p - deformValues.m_rotationAngle); //
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_tool->isLevelType())
Toshihiro Shimizu 890ddd
		rotationTool->addTransformUndo();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionRotationField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) {
Toshihiro Shimizu 890ddd
		setValue(0);
Toshihiro Shimizu 890ddd
		setDisabled(true);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setDisabled(false);
Toshihiro Shimizu 890ddd
	setValue(m_tool->m_deformValues.m_rotationAngle);
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//id == 0 Move X
Toshihiro Shimizu 890ddd
//id == 0 Move Y
Toshihiro Shimizu 890ddd
SelectionMoveField::SelectionMoveField(SelectionTool *tool, int id, QString name)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(0, name), m_tool(tool), m_id(id)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)), SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
	if (m_id == 0)
Toshihiro Shimizu 890ddd
		setMeasure("length.x");
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		setMeasure("length.y");
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionMoveField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || !m_tool->isEnabled() || (m_tool->isSelectionEmpty() && !m_tool->isLevelType()))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragSelectionTool::DragTool *moveTool = createNewMoveSelectionTool(m_tool);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double p = getValue() * Stage::inch;
Toshihiro Shimizu 890ddd
	TPointD delta = (m_id == 0) ? TPointD(p, 1) : TPointD(1, p),
Toshihiro Shimizu 890ddd
			oldMove = Stage::inch * m_tool->m_deformValues.m_moveValue,
Toshihiro Shimizu 890ddd
			oldDelta = (m_id == 0) ? TPointD(oldMove.x, 1) : TPointD(1, oldMove.y),
Toshihiro Shimizu 890ddd
			newMove = (m_id == 0) ? TPointD(delta.x, oldMove.y) : TPointD(oldMove.x, delta.y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine aff = TTranslation(-oldDelta) * TTranslation(delta);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_tool->m_deformValues.m_moveValue = 1 / Stage::inch * newMove; // Instruction order relevant here
Toshihiro Shimizu 890ddd
	moveTool->transform(aff);										//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_tool->isLevelType())
Toshihiro Shimizu 890ddd
		moveTool->addTransformUndo();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionMoveField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) {
Toshihiro Shimizu 890ddd
		setValue(0);
Toshihiro Shimizu 890ddd
		setDisabled(true);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setDisabled(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_id == 0)
Toshihiro Shimizu 890ddd
		setValue(m_tool->m_deformValues.m_moveValue.x);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		setValue(m_tool->m_deformValues.m_moveValue.y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ThickChangeField::ThickChangeField(SelectionTool *tool, QString name)
Toshihiro Shimizu 890ddd
	: MeasuredValueField(0, name), m_tool(tool)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = connect(this, SIGNAL(measuredValueChanged(TMeasuredValue *)), SLOT(onChange(TMeasuredValue *)));
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
	setMeasure("");
Toshihiro Shimizu 890ddd
	updateStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ThickChangeField::onChange(TMeasuredValue *fld)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType()))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragSelectionTool::VectorChangeThicknessTool *changeThickTool = new DragSelectionTool::VectorChangeThicknessTool((VectorSelectionTool *)m_tool);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TVectorImageP vi = (TVectorImageP)m_tool->getImage(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double p = 0.5 * getValue();
Toshihiro Shimizu 890ddd
	double newThickness = p - m_tool->m_deformValues.m_maxSelectionThickness;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	changeThickTool->setThicknessChange(newThickness);
Toshihiro Shimizu 890ddd
	changeThickTool->changeImageThickness(*vi, newThickness);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//DragSelectionTool::DeformValues deformValues = m_tool->m_deformValues;          // Like when I found it - it's a noop.
Toshihiro Shimizu 890ddd
	//deformValues.m_maxSelectionThickness = p;                                       // Seems that the actual update is performed inside
Toshihiro Shimizu 890ddd
	// the above change..() instruction...   >_<
Toshihiro Shimizu 890ddd
	changeThickTool->addUndo();
Toshihiro Shimizu 890ddd
	m_tool->computeBBox();
Toshihiro Shimizu 890ddd
	m_tool->invalidate();
Toshihiro Shimizu 890ddd
	m_tool->notifyImageChanged(m_tool->getCurrentFid());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ThickChangeField::updateStatus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_tool || m_tool->m_deformValues.m_isSelectionModified || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) {
Toshihiro Shimizu 890ddd
		setValue(0);
Toshihiro Shimizu 890ddd
		setDisabled(true);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setDisabled(false);
Toshihiro Shimizu 890ddd
	setValue(2 * m_tool->m_deformValues.m_maxSelectionThickness);
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}