tahoma2d/toonz/sources/toonzqt/intfield.cpp
Jeremy Bullock af90cdedbe
UI update and Icons from Konero (#126)
* add multi arc mockup

* implement mutli arc

* add join and smooth option

* reset multiarc and arc when deactivated

* create self loop if the last point is the same as the first

* make join option in multiarc consistent with tape tool

* fix a bug where thickness don't affect mutliarc in vector level

* remove join option in geometric tool

* stop mutliarc after closing shape

* double click can also end multi arc

* fix a bug where multiArc will produce buggy stroke

* fix a bug where geometric tools is not deactivated

* add multiArc shortcut

* rewrite multiArc

* revert changes to tvectorimage

* add undo data for multiArc

* Paste as Copy Command for XSheet

* Remove unneeded code

* Bug fix

* prevent guide lines from jumping around in MultiArc

* make stroke color consistent in MultiArc

* remove color in MultiArc's undo data

* make color consistent in MultiArc with previous version

* Fix single image raster levels

* fix compilation error

* fix a bug where multiArc might generate bugged stroke

* Remove ICONV dep (#3304)

* fix crash on saving studio palette

* Move to Paste Special Menu

* Don't Set Fixed Width if Docking a Floating Panel

* Update how_to_build_win.md

New draft of pr for requested changes to windows build instructions.

* fix geometric tool multiarc smooth option

* fix level saving failure

* fix wrong warning after saving palette

* fix a bug where moving a control point while holding alt has unintended result

* fix travis-install (#3389)

* Fix assert debug crash in flipconsole.cpp

Fix crash when using the viewer controls in the console (debug)

* Redraw Audio Waveform

Fills the waveform rather than outlines it.

* Update .gitignore

* fix undo data when drawing arc and mutliarc

* fix overwriting raster drawing palette (#3387)

* mode sensitive fx settings

* Create New Style Command Button (#3394)

* Create New Style Command Button

This PR creates a new button in the pallette editor that creates a new style.  Button is large and easy access for a faster and easier workflow.  Original code developed by Turtletooth for Tahoma.  Given permission to develop within Openoonz.

Co-Authored-By: Jeremy Bullock <turtletooth@users.noreply.github.com>

* Update paletteviewergui.cpp

Made changes to the PR per request by Shun.

* Fixed a space within the code that wasn't suppose to be there.

Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com>

* tahoma license (#3396)

* new style button optional

* fix loading pegbars (removing updateKeyframes)

* periodic random expression

* add fx in linear color space
this commit is based on source for the ComposeAdd plugin fx by DWANGO Co., Ltd.
in dwango_opentoonz_plugins and opentoonz_plugin_utility repositories.

* fractal noise iwa fx

* skip unnecessary icon invalidation

* fix frame range fill with tablet

* stop function editor to open by dbl clicking key

* Expanding the radius of the rotation handle.

This just changes when the cursor transforms into the rotation tool.

(cherry picked from commit 7722ae989bbdc6aa5cb48df7a4c08bae1fe6ea39)

* fix vector img patern stroke style

* Update Stylesheets

- Support the new icon sizes
- XSheet and Timeline significantly redesigned
- Lots of margin fixes and refactoring
- Remove deprecated icons, as some icons are moved into binary
- New Light theme

* New Icons

- Redesigns almost every icon as symbolic
- Adds icons for most commands

* Add Option for Icon Themes

- Adds option for icon themes
- Removes useless label from Preferences category list

* Update Icon Functions

- Adds themePath() boolean
- Adds function for recoloring black pixels in pixmaps to any color
- Rebuilds createQIcon to use fromTheme() and recolorPixmap()
- Removes createQIconOnOff as it seemed to be a rarely used duplicate of createQIcon
- Removes a grey horizontal line drawn above the console play bar in the viewer

* Set Default Icon Theme and Paths

- Sets search paths for icons for use with QIcon::fromTheme()
- Sets default start icon theme on first install
- Sets flag for displaying icons in menus, so we can selectively hide them

* Set Icons for Commands

- Sets icons for the commands
- Hides icons being displayed in menus as most icons are 20x20, they will look blurry when shrunk to 16x16
- Selectively allows icons to display for Tools in menus

* Change Icon Sizes, General Fixes and Stylesheet Additions

- Change icon sizes to new size
- Remove margin around FX Editor window
- Remove white line under color sliders in Style Editor
- Make keyframe icons uniform and color stylable in the stylesheets
- Removes deprecated stylesheet strings
- Redesign GUI for palette list view
- Make tree list header sort row stylable
- Remove black lines from scrollbars in New Project window
- Remove margin around combobox in Level Strip
- Alter how some lines are drawn in the Timeline to fix some alpha issues
- Make conditional fixed onion skin and normal onion skin dots contrast more against a light background area to make sure they have good visibility
- Make text always viewable in the FPS field in console bar
- Increase size of radio buttons in Cleanup Settings
- Increase size of switches in motion path nodes
- Remove unessesary "Layer" label in Timeline and other rects
- Various colors made stylable in the stylesheets; palette numpad and selection frame, cleanup settings border, scene cast folder path, schematic lines, ruler, xsheet lines, keyframes, cell input box and more
- Moves some external stylesheet icons into binary

* Make TPanelTitleBar Icon States Stylable

- Makes icon states for TPanelTitleBar buttons stylable in stylesheets

* Travis Fixes

* Swap Startup Popup Logos

They were in the wrong folders

* Revert "Swap Startup Popup Logos"

This reverts commit 815908a9f3e725f48507dab8a2270bdfa045649d.

* Fix Startup Popup Logo

It wasn't switching

* Feedback Changes

- Change render visualization to clapboard
- Fix text contrast on levels in XSheet

* Make Cell Selection More Clear

* Darken Light Theme and Tint Empty Cell Selection

* Fix missing icons

* Fix memo button

* Bring back colors

* Hide Motion Tab

* Fix Play Range Area (Light)

Make play range area more visible

* Vector Column Color

Co-authored-by: pojienie <pojienie@gmail.com>
Co-authored-by: rim <11380091+rozhuk-im@users.noreply.github.com>
Co-authored-by: shun-iwasawa <shun.iwasawa@ghibli.jp>
Co-authored-by: Rodney <rodney.baker@gmail.com>
Co-authored-by: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com>
Co-authored-by: shun-iwasawa <shun-iwasawa@users.noreply.github.com>
Co-authored-by: Kite <konero@users.noreply.github.com>
Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com>
Co-authored-by: DoctorRyan <doctorryan1969.gmail.com>
2020-08-31 12:51:22 -06:00

498 lines
15 KiB
C++

#include "toonzqt/intfield.h"
#include "toonzqt/dvdialog.h"
#include "toonzqt/gutil.h"
#include <QIntValidator>
#include <QSlider>
#include <QHBoxLayout>
#include <QAction>
#include <QFocusEvent>
#include <QPainter>
namespace {
const int NonLinearSliderPrecision = 2;
}
using namespace DVGui;
//=============================================================================
// RollerField
//-----------------------------------------------------------------------------
RollerField::RollerField(QWidget *parent)
: QWidget(parent)
, m_value(0)
, m_minValue(-100000.0)
, m_maxValue(100000.0)
, m_xPos(0)
, m_step(1.0) {
setMinimumSize(43, 7);
}
//-----------------------------------------------------------------------------
void RollerField::setValue(double value) {
if (m_value == value) return;
if (value < m_minValue) m_value = m_minValue;
if (value > m_maxValue) m_value = m_maxValue;
m_value = value;
}
//-----------------------------------------------------------------------------
double RollerField::getValue() const { return m_value; }
//-----------------------------------------------------------------------------
void RollerField::setRange(double minValue, double maxValue) {
m_minValue = minValue;
m_maxValue = maxValue;
}
//-----------------------------------------------------------------------------
void RollerField::getRange(double &minValue, double &maxValue) {
minValue = m_minValue;
maxValue = m_maxValue;
}
//-----------------------------------------------------------------------------
void RollerField::paintEvent(QPaintEvent *e) {
QPainter p(this);
int w = width();
drawArrow(p, QPointF(3, 3), QPointF(5, 5), QPointF(5, 1), true, Qt::black,
Qt::black);
drawArrow(p, QPointF(w - 4, 3), QPointF(w - 6, 5), QPointF(w - 6, 1), true,
Qt::black, Qt::black);
p.drawLine(QPoint(3, 3), QPoint(w - 4, 3));
}
//-----------------------------------------------------------------------------
void RollerField::mousePressEvent(QMouseEvent *e) {
if (e->buttons() == Qt::LeftButton) {
m_xPos = e->pos().x();
e->accept();
}
}
//-----------------------------------------------------------------------------
void RollerField::mouseMoveEvent(QMouseEvent *e) {
if (e->buttons() == Qt::LeftButton) {
if (m_xPos < e->pos().x())
addValue(true);
else if (m_xPos > e->pos().x())
removeValue(true);
m_xPos = e->pos().x();
e->accept();
}
}
//-----------------------------------------------------------------------------
void RollerField::mouseReleaseEvent(QMouseEvent *e) {
e->accept();
emit valueChanged(false);
}
//-----------------------------------------------------------------------------
void RollerField::addValue(bool isDragging) {
double newValue = tcrop(m_value + m_step, m_minValue, m_maxValue);
if (newValue == m_value) return;
m_value = newValue;
emit valueChanged(isDragging);
}
//-----------------------------------------------------------------------------
void RollerField::removeValue(bool isDragging) {
double newValue = tcrop(m_value - m_step, m_minValue, m_maxValue);
if (newValue == m_value) return;
m_value = newValue;
emit valueChanged(isDragging);
}
//=============================================================================
// IntLineEdit
//-----------------------------------------------------------------------------
IntLineEdit::IntLineEdit(QWidget *parent, int value, int minValue, int maxValue,
int showedDigits)
: LineEdit(parent), m_showedDigits(showedDigits) {
setFixedWidth(54);
m_validator = new QIntValidator(this);
setValue(value);
setRange(minValue, maxValue);
setValidator(m_validator);
}
//-----------------------------------------------------------------------------
void IntLineEdit::setValue(int value) {
int minValue, maxValue;
getRange(minValue, maxValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
QString str;
str.setNum(value);
if (m_showedDigits > 0) {
while (str.length() < m_showedDigits) str.push_front("0");
while (str.length() > m_showedDigits) str.remove(0, 1);
}
setText(str);
// Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa da
// visualizzare
// e' piu' lunga del campo le cifre che vengono troncate sono le ultime e non
// le prime.
setCursorPosition(0);
}
//-----------------------------------------------------------------------------
int IntLineEdit::getValue() { return text().toInt(); }
//-----------------------------------------------------------------------------
void IntLineEdit::setRange(int minValue, int maxValue) {
m_validator->setRange(minValue, maxValue);
}
//-----------------------------------------------------------------------------
void IntLineEdit::getRange(int &minValue, int &maxValue) {
minValue = m_validator->bottom();
maxValue = m_validator->top();
}
//-----------------------------------------------------------------------------
void IntLineEdit::setBottomRange(int minValue) {
m_validator->setBottom(minValue);
}
//-----------------------------------------------------------------------------
void IntLineEdit::setTopRange(int maxValue) { m_validator->setTop(maxValue); }
//-----------------------------------------------------------------------------
void IntLineEdit::focusOutEvent(QFocusEvent *e) {
int value = getValue();
int minValue, maxValue;
getRange(minValue, maxValue);
if (e->lostFocus()) setValue(value);
QLineEdit::focusOutEvent(e);
m_isTyping = false;
}
//-----------------------------------------------------------------------------
// for fps edit in flip console
void IntLineEdit::setLineEditBackgroundColor(QColor color) {
// Set text color based on luminescence of bg color
int value = 0;
double luminescence = ((0.299 * color.red()) + (0.587 * color.green()) +
(0.114 * color.blue())) /
255;
if (luminescence > 0.5)
value = 0; // black
else
value = 255; // white
QString sheet =
QString("background-color: rgb(") + QString::number(color.red()) +
QString(",") + QString::number(color.green()) + QString(",") +
QString::number(color.blue()) + QString(",") +
QString::number(color.alpha()) +
QString(");" +
QString("color: rgb(" + QString::number(value) + QString(",") +
QString::number(value) + QString(",") +
QString::number(value) + QString(");")));
setStyleSheet(sheet);
}
//-----------------------------------------------------------------------------
void IntLineEdit::mousePressEvent(QMouseEvent *e) {
if (e->buttons() == Qt::MiddleButton) {
m_xMouse = e->x();
m_mouseDragEditing = true;
} else {
QLineEdit::mousePressEvent(e);
if (!m_isTyping) { // only the first click will select all
selectAll();
m_isTyping = true;
}
}
}
//-----------------------------------------------------------------------------
void IntLineEdit::mouseMoveEvent(QMouseEvent *e) {
if (e->buttons() == Qt::MiddleButton) {
setValue(getValue() + ((e->x() - m_xMouse) / 2));
m_xMouse = e->x();
} else
QLineEdit::mouseMoveEvent(e);
}
//-----------------------------------------------------------------------------
void IntLineEdit::mouseReleaseEvent(QMouseEvent *e) {
if (e->modifiers() & Qt::ControlModifier &&
e->modifiers() & Qt::AltModifier) {
emit(controlAltClickEvent());
clearFocus();
return;
} else if (e->modifiers() & Qt::ControlModifier) {
emit(controlClickEvent());
clearFocus();
return;
}
if ((e->buttons() == Qt::NoButton && m_mouseDragEditing)) {
m_mouseDragEditing = false;
clearFocus();
} else
QLineEdit::mouseReleaseEvent(e);
}
//=============================================================================
// IntField
//-----------------------------------------------------------------------------
IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide)
: QWidget(parent)
, m_lineEdit(0)
, m_slider(0)
, m_roller(0)
, m_isMaxRangeLimited(isMaxRangeLimited)
, m_isLinearSlider(true) {
setObjectName("IntField");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(5);
QWidget *field = new QWidget(this);
field->setMaximumWidth(43);
QVBoxLayout *vLayout = new QVBoxLayout(field);
vLayout->setMargin(0);
vLayout->setSpacing(0);
m_lineEdit = new DVGui::IntLineEdit(field);
bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this,
SLOT(onEditingFinished()));
vLayout->addWidget(m_lineEdit);
m_roller = new RollerField(field);
ret = ret && connect(m_roller, SIGNAL(valueChanged(bool)), this,
SLOT(onRollerValueChanged(bool)));
vLayout->addWidget(m_roller);
if (isRollerHide) enableRoller(false);
layout->addWidget(field);
m_slider = new QSlider(Qt::Horizontal, this);
ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this,
SLOT(onSliderChanged(int)));
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this,
SLOT(onSliderReleased()));
ret = ret && connect(m_lineEdit, SIGNAL(editingFinished()), this,
SIGNAL(valueEditedByHand()));
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this,
SIGNAL(valueEditedByHand()));
layout->addWidget(m_slider);
setValues(0, 0, 100);
setLayout(layout);
assert(ret);
}
//-----------------------------------------------------------------------------
void IntField::getRange(int &minValue, int &maxValue) {
double min, max;
m_roller->getRange(min, max);
minValue = tround(min);
maxValue = tround(max);
}
//-----------------------------------------------------------------------------
void IntField::setRange(int minValue, int maxValue) {
m_lineEdit->setRange(minValue, m_isMaxRangeLimited
? maxValue
: (std::numeric_limits<int>::max)());
if (m_isLinearSlider)
m_slider->setRange(minValue, maxValue);
else
m_slider->setRange(minValue * pow(10., NonLinearSliderPrecision),
maxValue * pow(10., NonLinearSliderPrecision));
m_roller->setRange(minValue, maxValue);
}
//-----------------------------------------------------------------------------
void IntField::setValue(int value) {
if (m_lineEdit->getValue() == value) return;
m_lineEdit->setValue(value);
m_slider->setSliderPosition(value2pos(value));
m_roller->setValue((double)value);
}
//-----------------------------------------------------------------------------
int IntField::getValue() { return (m_lineEdit->getValue()); }
//-----------------------------------------------------------------------------
void IntField::setValues(int value, int minValue, int maxValue) {
setRange(minValue, maxValue);
setValue(value);
}
//-----------------------------------------------------------------------------
void IntField::enableSlider(bool enable) {
m_slider->setEnabled(enable);
if (enable)
m_slider->show();
else
m_slider->hide();
}
//-----------------------------------------------------------------------------
bool IntField::sliderIsEnabled() { return m_slider->isEnabled(); }
//-----------------------------------------------------------------------------
void IntField::enableRoller(bool enable) {
m_roller->setEnabled(enable);
if (enable)
m_roller->show();
else
m_roller->hide();
}
//-----------------------------------------------------------------------------
bool IntField::rollerIsEnabled() { return m_roller->isEnabled(); }
//-----------------------------------------------------------------------------
void IntField::setLineEditBackgroundColor(QColor color) {
m_lineEdit->setLineEditBackgroundColor(color);
}
//-----------------------------------------------------------------------------
int IntField::pos2value(int x) const {
if (m_isLinearSlider) return x;
// nonlinear slider case
double rangeSize = (double)(m_slider->maximum() - m_slider->minimum());
double posRatio = (double)(x - m_slider->minimum()) / rangeSize;
double t;
if (posRatio <= 0.5)
t = 0.04 * posRatio;
else if (posRatio <= 0.75)
t = -0.02 + 0.08 * posRatio;
else if (posRatio <= 0.9)
t = -0.26 + 0.4 * posRatio;
else
t = -8.0 + 9.0 * posRatio;
double sliderVal = (double)m_slider->minimum() + rangeSize * t;
return (int)round(sliderVal * pow(0.1, NonLinearSliderPrecision));
}
//-----------------------------------------------------------------------------
int IntField::value2pos(int v) const {
if (m_isLinearSlider) return v;
// nonlinear slider case
double sliderVal = (double)v * pow(10., NonLinearSliderPrecision);
double rangeSize = (double)(m_slider->maximum() - m_slider->minimum());
double valueRatio = (double)(sliderVal - m_slider->minimum()) / rangeSize;
double t;
if (valueRatio <= 0.02)
t = valueRatio / 0.04;
else if (valueRatio <= 0.04)
t = (valueRatio + 0.02) / 0.08;
else if (valueRatio <= 0.1)
t = (valueRatio + 0.26) / 0.4;
else
t = (valueRatio + 8.0) / 9.0;
return m_slider->minimum() + (int)(t * rangeSize);
}
//-----------------------------------------------------------------------------
void IntField::onSliderChanged(int sliderPos) {
int value = pos2value(sliderPos);
// Controllo necessario per evitare che il segnale di cambiamento venga emesso
// piu' volte.
if (m_lineEdit->getValue() == value ||
((int)m_roller->getValue() == value && m_roller->isVisible()))
return;
m_lineEdit->setValue(value);
m_roller->setValue((double)value);
// Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa
// da visualizzare e' piu' lunga del campo le cifre che vengono troncate sono
// le ultime e non le prime (dovrebbero essere quelle dopo la virgola).
m_lineEdit->setCursorPosition(0);
emit valueChanged(true);
}
//-----------------------------------------------------------------------------
void IntField::onEditingFinished() {
double value = m_lineEdit->getValue();
// Controllo necessario per evitare che il segnale di cambiamento venga emesso
// piu' volte.
if ((pos2value(m_slider->value()) == value && m_slider->isVisible()) ||
((int)m_roller->getValue() == value && m_roller->isVisible()))
return;
m_slider->setValue(value2pos(value));
m_roller->setValue((double)value);
emit valueChanged(false);
}
//-----------------------------------------------------------------------------
void IntField::onRollerValueChanged(bool isDragging) {
int value = m_roller->getValue();
if (value == m_lineEdit->getValue()) {
assert(pos2value(m_slider->value()) == value || !m_slider->isVisible());
// Se isDragging e' falso e' giusto che venga emessa la notifica di
// cambiamento.
if (!isDragging) emit valueChanged(isDragging);
return;
}
m_slider->setValue(value2pos(value));
m_lineEdit->setValue(value);
// Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa
// da visualizzare e' piu' lunga del campo le cifre che vengono troncate sono
// le ultime e non le prime (dovrebbero essere quelle dopo la virgola).
m_lineEdit->setCursorPosition(0);
emit valueChanged(isDragging);
}