2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "toonzqt/intfield.h"
|
|
|
|
#include "toonzqt/dvdialog.h"
|
|
|
|
#include "toonzqt/gutil.h"
|
|
|
|
|
|
|
|
#include <QIntValidator>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QFocusEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
namespace {
|
|
|
|
const int NonLinearSliderPrecision = 2;
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
using namespace DVGui;
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// RollerField
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
RollerField::RollerField(QWidget *parent)
|
2016-06-15 18:43:10 +12:00
|
|
|
: QWidget(parent)
|
|
|
|
, m_value(0)
|
|
|
|
, m_minValue(-100000.0)
|
|
|
|
, m_maxValue(100000.0)
|
|
|
|
, m_xPos(0)
|
|
|
|
, m_step(1.0) {
|
|
|
|
setMinimumSize(43, 7);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_value = value;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
double RollerField::getValue() const { return m_value; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void RollerField::setRange(double minValue, double maxValue) {
|
|
|
|
m_minValue = minValue;
|
|
|
|
m_maxValue = maxValue;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void RollerField::getRange(double &minValue, double &maxValue) {
|
|
|
|
minValue = m_minValue;
|
|
|
|
maxValue = m_maxValue;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void RollerField::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int w = width();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
p.drawLine(QPoint(3, 3), QPoint(w - 4, 3));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void RollerField::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (e->buttons() == Qt::LeftButton) {
|
|
|
|
m_xPos = e->pos().x();
|
|
|
|
e->accept();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void RollerField::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
e->accept();
|
|
|
|
emit valueChanged(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// IntLineEdit
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
IntLineEdit::IntLineEdit(QWidget *parent, int value, int minValue, int maxValue,
|
|
|
|
int showedDigits)
|
|
|
|
: LineEdit(parent), m_showedDigits(showedDigits) {
|
|
|
|
setFixedWidth(54);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_validator = new QIntValidator(this);
|
|
|
|
setValue(value);
|
|
|
|
setRange(minValue, maxValue);
|
|
|
|
setValidator(m_validator);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
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);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int IntLineEdit::getValue() { return text().toInt(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::setRange(int minValue, int maxValue) {
|
|
|
|
m_validator->setRange(minValue, maxValue);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::getRange(int &minValue, int &maxValue) {
|
|
|
|
minValue = m_validator->bottom();
|
|
|
|
maxValue = m_validator->top();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::setBottomRange(int minValue) {
|
|
|
|
m_validator->setBottom(minValue);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::setTopRange(int maxValue) { m_validator->setTop(maxValue); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::focusOutEvent(QFocusEvent *e) {
|
|
|
|
int value = getValue();
|
|
|
|
int minValue, maxValue;
|
|
|
|
getRange(minValue, maxValue);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (e->lostFocus()) setValue(value);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QLineEdit::focusOutEvent(e);
|
2017-11-25 01:13:52 +13:00
|
|
|
m_isTyping = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for fps edit in flip console
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntLineEdit::setLineEditBackgroundColor(QColor color) {
|
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-09-01 06:51:22 +12:00
|
|
|
// 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 =
|
2021-12-21 18:13:22 +13:00
|
|
|
QString("background-color: rgba(") + QString::number(color.red()) +
|
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-09-01 06:51:22 +12:00
|
|
|
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(");")));
|
2016-06-15 18:43:10 +12:00
|
|
|
setStyleSheet(sheet);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2017-11-20 20:28:59 +13:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void IntLineEdit::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (e->buttons() == Qt::MiddleButton) {
|
|
|
|
m_xMouse = e->x();
|
|
|
|
m_mouseDragEditing = true;
|
2017-11-25 01:13:52 +13:00
|
|
|
} else {
|
2017-11-20 20:28:59 +13:00
|
|
|
QLineEdit::mousePressEvent(e);
|
2017-11-25 01:13:52 +13:00
|
|
|
if (!m_isTyping) { // only the first click will select all
|
|
|
|
selectAll();
|
|
|
|
m_isTyping = true;
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 20:28:59 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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) {
|
2020-06-02 16:55:58 +12:00
|
|
|
if (e->modifiers() & Qt::ControlModifier &&
|
|
|
|
e->modifiers() & Qt::AltModifier) {
|
|
|
|
emit(controlAltClickEvent());
|
|
|
|
clearFocus();
|
|
|
|
return;
|
|
|
|
} else if (e->modifiers() & Qt::ControlModifier) {
|
|
|
|
emit(controlClickEvent());
|
|
|
|
clearFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-20 20:28:59 +13:00
|
|
|
if ((e->buttons() == Qt::NoButton && m_mouseDragEditing)) {
|
|
|
|
m_mouseDragEditing = false;
|
|
|
|
clearFocus();
|
2017-11-25 01:13:52 +13:00
|
|
|
} else
|
2017-11-20 20:28:59 +13:00
|
|
|
QLineEdit::mouseReleaseEvent(e);
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
//=============================================================================
|
|
|
|
// IntField
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide)
|
2016-06-15 18:43:10 +12:00
|
|
|
: QWidget(parent)
|
|
|
|
, m_lineEdit(0)
|
|
|
|
, m_slider(0)
|
|
|
|
, m_roller(0)
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_isMaxRangeLimited(isMaxRangeLimited)
|
|
|
|
, m_isLinearSlider(true) {
|
2016-06-15 18:43:10 +12:00
|
|
|
setObjectName("IntField");
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(5);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QWidget *field = new QWidget(this);
|
|
|
|
field->setMaximumWidth(43);
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout(field);
|
|
|
|
vLayout->setMargin(0);
|
|
|
|
vLayout->setSpacing(0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_lineEdit = new DVGui::IntLineEdit(field);
|
|
|
|
bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this,
|
|
|
|
SLOT(onEditingFinished()));
|
|
|
|
vLayout->addWidget(m_lineEdit);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_roller = new RollerField(field);
|
|
|
|
ret = ret && connect(m_roller, SIGNAL(valueChanged(bool)), this,
|
|
|
|
SLOT(onRollerValueChanged(bool)));
|
|
|
|
vLayout->addWidget(m_roller);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (isRollerHide) enableRoller(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
layout->addWidget(field);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_slider = new QSlider(Qt::Horizontal, this);
|
|
|
|
ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this,
|
|
|
|
SLOT(onSliderChanged(int)));
|
2021-12-21 18:13:22 +13:00
|
|
|
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this,
|
2016-06-15 18:43:10 +12:00
|
|
|
SLOT(onSliderReleased()));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ret = ret && connect(m_lineEdit, SIGNAL(editingFinished()), this,
|
|
|
|
SIGNAL(valueEditedByHand()));
|
|
|
|
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this,
|
|
|
|
SIGNAL(valueEditedByHand()));
|
|
|
|
layout->addWidget(m_slider);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
setValues(0, 0, 100);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
setLayout(layout);
|
|
|
|
assert(ret);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::getRange(int &minValue, int &maxValue) {
|
|
|
|
double min, max;
|
|
|
|
m_roller->getRange(min, max);
|
|
|
|
minValue = tround(min);
|
|
|
|
maxValue = tround(max);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::setRange(int minValue, int maxValue) {
|
|
|
|
m_lineEdit->setRange(minValue, m_isMaxRangeLimited
|
|
|
|
? maxValue
|
|
|
|
: (std::numeric_limits<int>::max)());
|
2019-10-11 16:13:41 +13:00
|
|
|
if (m_isLinearSlider)
|
|
|
|
m_slider->setRange(minValue, maxValue);
|
|
|
|
else
|
|
|
|
m_slider->setRange(minValue * pow(10., NonLinearSliderPrecision),
|
|
|
|
maxValue * pow(10., NonLinearSliderPrecision));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_roller->setRange(minValue, maxValue);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::setValue(int value) {
|
|
|
|
if (m_lineEdit->getValue() == value) return;
|
|
|
|
m_lineEdit->setValue(value);
|
2019-10-11 16:13:41 +13:00
|
|
|
m_slider->setSliderPosition(value2pos(value));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_roller->setValue((double)value);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int IntField::getValue() { return (m_lineEdit->getValue()); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::setValues(int value, int minValue, int maxValue) {
|
|
|
|
setRange(minValue, maxValue);
|
|
|
|
setValue(value);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::enableSlider(bool enable) {
|
|
|
|
m_slider->setEnabled(enable);
|
|
|
|
if (enable)
|
|
|
|
m_slider->show();
|
|
|
|
else
|
|
|
|
m_slider->hide();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool IntField::sliderIsEnabled() { return m_slider->isEnabled(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::enableRoller(bool enable) {
|
|
|
|
m_roller->setEnabled(enable);
|
|
|
|
if (enable)
|
|
|
|
m_roller->show();
|
|
|
|
else
|
|
|
|
m_roller->hide();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool IntField::rollerIsEnabled() { return m_roller->isEnabled(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::setLineEditBackgroundColor(QColor color) {
|
|
|
|
m_lineEdit->setLineEditBackgroundColor(color);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
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
|
2021-12-21 18:13:22 +13:00
|
|
|
t = -8.0 + 9.0 * posRatio;
|
2019-10-11 16:13:41 +13:00
|
|
|
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);
|
2016-06-15 18:43:10 +12:00
|
|
|
// 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);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::onEditingFinished() {
|
|
|
|
double value = m_lineEdit->getValue();
|
|
|
|
// Controllo necessario per evitare che il segnale di cambiamento venga emesso
|
|
|
|
// piu' volte.
|
2019-10-11 16:13:41 +13:00
|
|
|
if ((pos2value(m_slider->value()) == value && m_slider->isVisible()) ||
|
2020-04-12 17:19:20 +12:00
|
|
|
((int)m_roller->getValue() == value && m_roller->isVisible()))
|
2016-06-15 18:43:10 +12:00
|
|
|
return;
|
2019-10-11 16:13:41 +13:00
|
|
|
m_slider->setValue(value2pos(value));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_roller->setValue((double)value);
|
|
|
|
emit valueChanged(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void IntField::onRollerValueChanged(bool isDragging) {
|
|
|
|
int value = m_roller->getValue();
|
|
|
|
if (value == m_lineEdit->getValue()) {
|
2019-10-11 16:13:41 +13:00
|
|
|
assert(pos2value(m_slider->value()) == value || !m_slider->isVisible());
|
2016-06-15 18:43:10 +12:00
|
|
|
// Se isDragging e' falso e' giusto che venga emessa la notifica di
|
|
|
|
// cambiamento.
|
|
|
|
if (!isDragging) emit valueChanged(isDragging);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-11 16:13:41 +13:00
|
|
|
m_slider->setValue(value2pos(value));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_lineEdit->setValue(value);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// 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);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
emit valueChanged(isDragging);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|