tahoma2d/toonz/sources/tnztools/tooloptionscontrols.cpp

1628 lines
53 KiB
C++
Raw Normal View History

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