From f5a707ea63ccba03cef963b4e9ebc0be96ec8d59 Mon Sep 17 00:00:00 2001 From: mfeemster Date: Thu, 16 Oct 2014 23:05:08 -0700 Subject: [PATCH] Remove focus handling code from spin boxes. It was originally done to compensate for a bug in Qt, but required the user to make very precise mouse movements. This is no longer needed since the bug has been fixed. Prevent spatial and density filters from returning empty filters. Another attempt at properly setting the locale for the affine rotate/move/scale combo boxes. --- Source/Ember/DensityFilter.h | 6 ++ Source/Ember/Renderer.cpp | 2 + Source/Ember/SpatialFilter.h | 72 +++++++++++--------- Source/Fractorium/DoubleSpinBox.cpp | 54 +++++++-------- Source/Fractorium/FractoriumXformsAffine.cpp | 20 ++++-- Source/Fractorium/SpinBox.cpp | 56 +++++++-------- 6 files changed, 116 insertions(+), 94 deletions(-) diff --git a/Source/Ember/DensityFilter.h b/Source/Ember/DensityFilter.h index ec6436e..d0a006e 100644 --- a/Source/Ember/DensityFilter.h +++ b/Source/Ember/DensityFilter.h @@ -56,6 +56,12 @@ public: if (m_MaxRad < m_MinRad) m_MaxRad = m_MinRad + 1; + + //Ensure it's valid. + while (!Valid()) + { + m_Curve += T(0.1); + } } /// diff --git a/Source/Ember/Renderer.cpp b/Source/Ember/Renderer.cpp index f81b1bd..361eca3 100644 --- a/Source/Ember/Renderer.cpp +++ b/Source/Ember/Renderer.cpp @@ -244,6 +244,8 @@ bool Renderer::CreateSpatialFilter(bool& newAlloc) { m_SpatialFilter = unique_ptr>( SpatialFilterCreator::Create(m_Ember.m_SpatialFilterType, m_Ember.m_SpatialFilterRadius, m_Ember.m_Supersample, m_PixelAspectRatio)); + + m_Ember.m_SpatialFilterRadius = m_SpatialFilter->FilterRadius();//It may have been changed internally if it was too small, so ensure they're synced. newAlloc = true; } diff --git a/Source/Ember/SpatialFilter.h b/Source/Ember/SpatialFilter.h index d21082b..5e4b421 100644 --- a/Source/Ember/SpatialFilter.h +++ b/Source/Ember/SpatialFilter.h @@ -105,45 +105,51 @@ public: /// void Create() { - T fw = T(2.0) * m_Support * m_Supersample * m_FilterRadius / m_PixelAspectRatio; - T adjust, ii, jj; - - int fwidth = ((int)fw) + 1; - int i, j; - - //Make sure the filter kernel has same parity as oversample. - if ((fwidth ^ m_Supersample) & 1) - fwidth++; - - //Calculate the coordinate scaling factor for the kernel values. - if (fw > 0.0) - adjust = m_Support * fwidth / fw; - else - adjust = T(1.0); - - m_Filter.resize(fwidth * fwidth); - - //Fill in the coefs. - for (i = 0; i < fwidth; i++) + do { - for (j = 0; j < fwidth; j++) + T fw = T(2.0) * m_Support * m_Supersample * m_FilterRadius / m_PixelAspectRatio; + T adjust, ii, jj; + + int fwidth = ((int)fw) + 1; + int i, j; + + //Make sure the filter kernel has same parity as oversample. + if ((fwidth ^ m_Supersample) & 1) + fwidth++; + + //Calculate the coordinate scaling factor for the kernel values. + if (fw > 0.0) + adjust = m_Support * fwidth / fw; + else + adjust = T(1.0); + + m_Filter.resize(fwidth * fwidth); + + //Fill in the coefs. + for (i = 0; i < fwidth; i++) { - //Calculate the function inputs for the kernel function. - ii = ((T(2.0) * i + T(1.0)) / T(fwidth) - T(1.0)) * adjust; - jj = ((T(2.0) * j + T(1.0)) / T(fwidth) - T(1.0)) * adjust; + for (j = 0; j < fwidth; j++) + { + //Calculate the function inputs for the kernel function. + ii = ((T(2.0) * i + T(1.0)) / T(fwidth) - T(1.0)) * adjust; + jj = ((T(2.0) * j + T(1.0)) / T(fwidth) - T(1.0)) * adjust; - //Adjust for aspect ratio. - jj /= m_PixelAspectRatio; + //Adjust for aspect ratio. + jj /= m_PixelAspectRatio; - m_Filter[i + j * fwidth] = Filter(ii) * Filter(jj);//Call virtual Filter(), implemented in specific derived filter classes. + m_Filter[i + j * fwidth] = Filter(ii) * Filter(jj);//Call virtual Filter(), implemented in specific derived filter classes. + } } - } - //Normalize, and return a bad value if the values were too small. - if (!Normalize()) - m_FinalFilterWidth = -1; - else - m_FinalFilterWidth = fwidth; + //Attempt to normalize, and increase the filter width if the values were too small. + if (!Normalize()) + { + m_FinalFilterWidth = fwidth; + break; + } + + m_FilterRadius += T(0.01);//Values were too small. + } while (1); } /// diff --git a/Source/Fractorium/DoubleSpinBox.cpp b/Source/Fractorium/DoubleSpinBox.cpp index c062898..ec41eb5 100644 --- a/Source/Fractorium/DoubleSpinBox.cpp +++ b/Source/Fractorium/DoubleSpinBox.cpp @@ -117,26 +117,26 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) { if (e->type() == QMouseEvent::MouseButtonPress && isEnabled()) { - QPoint pt; - - if (QMouseEvent* me = (QMouseEvent*)e) - pt = me->localPos().toPoint(); - - int pos = lineEdit()->cursorPositionAt(pt); - - if (lineEdit()->selectedText() != "") - { - lineEdit()->deselect(); - lineEdit()->setCursorPosition(pos); - return true; - } - else if (m_Select) - { - lineEdit()->setCursorPosition(pos); - selectAll(); - m_Select = false; - return true; - } + // QPoint pt; + // + // if (QMouseEvent* me = (QMouseEvent*)e) + // pt = me->localPos().toPoint(); + // + // int pos = lineEdit()->cursorPositionAt(pt); + // + // if (lineEdit()->selectedText() != "") + // { + // lineEdit()->deselect(); + // lineEdit()->setCursorPosition(pos); + // return true; + // } + // else if (m_Select) + // { + // lineEdit()->setCursorPosition(pos); + // selectAll(); + // m_Select = false; + // return true; + // } } else if (m_DoubleClick && e->type() == QMouseEvent::MouseButtonDblClick && isEnabled()) { @@ -172,7 +172,7 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) /// The event void DoubleSpinBox::focusInEvent(QFocusEvent* e) { - lineEdit()->setReadOnly(false); + //lineEdit()->setReadOnly(false); QDoubleSpinBox::focusInEvent(e); } @@ -185,8 +185,8 @@ void DoubleSpinBox::focusInEvent(QFocusEvent* e) /// The event void DoubleSpinBox::focusOutEvent(QFocusEvent* e) { - lineEdit()->deselect();//Clear selection when leaving. - lineEdit()->setReadOnly(true);//Clever hack to clear the cursor when leaving. + //lineEdit()->deselect();//Clear selection when leaving. + //lineEdit()->setReadOnly(true);//Clever hack to clear the cursor when leaving. QDoubleSpinBox::focusOutEvent(e); } @@ -197,8 +197,8 @@ void DoubleSpinBox::focusOutEvent(QFocusEvent* e) /// The event void DoubleSpinBox::enterEvent(QEvent* e) { - m_Select = true; - setFocus(); + //m_Select = true; + //setFocus(); QDoubleSpinBox::enterEvent(e); } @@ -209,7 +209,7 @@ void DoubleSpinBox::enterEvent(QEvent* e) /// The event void DoubleSpinBox::leaveEvent(QEvent* e) { - m_Select = false; - clearFocus(); + //m_Select = false; + //clearFocus(); QDoubleSpinBox::leaveEvent(e); } diff --git a/Source/Fractorium/FractoriumXformsAffine.cpp b/Source/Fractorium/FractoriumXformsAffine.cpp index 4403960..2b8207a 100644 --- a/Source/Fractorium/FractoriumXformsAffine.cpp +++ b/Source/Fractorium/FractoriumXformsAffine.cpp @@ -33,13 +33,21 @@ void Fractorium::InitXformsAffineUI() SetupAffineSpinner(table, this, 2, 0, m_PostO1Spin, spinHeight, affineMin, affineMax, affineStep, affinePrec, SIGNAL(valueChanged(double)), SLOT(OnO1Changed(double))); SetupAffineSpinner(table, this, 2, 1, m_PostO2Spin, spinHeight, affineMin, affineMax, affineStep, affinePrec, SIGNAL(valueChanged(double)), SLOT(OnO2Changed(double))); - ui.PreRotateCombo->setValidator(new QDoubleValidator(ui.PreRotateCombo)); - ui.PreMoveCombo->setValidator( new QDoubleValidator(ui.PreMoveCombo)); - ui.PreScaleCombo->setValidator( new QDoubleValidator(ui.PreScaleCombo)); + QDoubleValidator* preRotateVal = new QDoubleValidator(ui.PreRotateCombo); preRotateVal->setLocale(QLocale::system()); + QDoubleValidator* preMoveVal = new QDoubleValidator(ui.PreMoveCombo); preMoveVal->setLocale(QLocale::system()); + QDoubleValidator* preScaleVal = new QDoubleValidator(ui.PreScaleCombo); preScaleVal->setLocale(QLocale::system()); - ui.PostRotateCombo->setValidator(new QDoubleValidator(ui.PostRotateCombo)); - ui.PostMoveCombo->setValidator( new QDoubleValidator(ui.PostMoveCombo)); - ui.PostScaleCombo->setValidator( new QDoubleValidator(ui.PostScaleCombo)); + QDoubleValidator* postRotateVal = new QDoubleValidator(ui.PostRotateCombo); postRotateVal->setLocale(QLocale::system()); + QDoubleValidator* postMoveVal = new QDoubleValidator(ui.PostMoveCombo); postMoveVal->setLocale(QLocale::system()); + QDoubleValidator* postScaleVal = new QDoubleValidator(ui.PostScaleCombo); postScaleVal->setLocale(QLocale::system()); + + ui.PreRotateCombo->setValidator(preRotateVal); + ui.PreMoveCombo->setValidator(preMoveVal); + ui.PreScaleCombo->setValidator(preScaleVal); + + ui.PostRotateCombo->setValidator(postRotateVal); + ui.PostMoveCombo->setValidator(postMoveVal); + ui.PostScaleCombo->setValidator(postScaleVal); connect(ui.PreFlipHorizontalButton, SIGNAL(clicked(bool)), this, SLOT(OnFlipHorizontalButtonClicked(bool)), Qt::QueuedConnection); connect(ui.PreFlipVerticalButton, SIGNAL(clicked(bool)), this, SLOT(OnFlipVerticalButtonClicked(bool)), Qt::QueuedConnection); diff --git a/Source/Fractorium/SpinBox.cpp b/Source/Fractorium/SpinBox.cpp index 761fb87..6e4177a 100644 --- a/Source/Fractorium/SpinBox.cpp +++ b/Source/Fractorium/SpinBox.cpp @@ -107,26 +107,26 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) { if (e->type() == QMouseEvent::MouseButtonPress && isEnabled()) { - QPoint pt; - - if (QMouseEvent* me = (QMouseEvent*)e) - pt = me->localPos().toPoint(); - - int pos = lineEdit()->cursorPositionAt(pt); - - if (lineEdit()->selectedText() != "") - { - lineEdit()->deselect(); - lineEdit()->setCursorPosition(pos); - return true; - } - else if (m_Select) - { - lineEdit()->setCursorPosition(pos); - selectAll(); - m_Select = false; - return true; - } + //QPoint pt; + // + //if (QMouseEvent* me = (QMouseEvent*)e) + // pt = me->localPos().toPoint(); + // + //int pos = lineEdit()->cursorPositionAt(pt); + // + //if (lineEdit()->selectedText() != "") + //{ + // lineEdit()->deselect(); + // lineEdit()->setCursorPosition(pos); + // return true; + //} + //else if (m_Select) + //{ + // lineEdit()->setCursorPosition(pos); + // selectAll(); + // m_Select = false; + // return true; + //} } else if (m_DoubleClick && e->type() == QMouseEvent::MouseButtonDblClick && isEnabled()) { @@ -153,7 +153,7 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) } } - return false; + return QSpinBox::eventFilter(o, e); } /// @@ -162,7 +162,7 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) /// The event void SpinBox::focusInEvent(QFocusEvent* e) { - lineEdit()->setReadOnly(false); + //lineEdit()->setReadOnly(false); QSpinBox::focusInEvent(e); } @@ -175,8 +175,8 @@ void SpinBox::focusInEvent(QFocusEvent* e) /// The event void SpinBox::focusOutEvent(QFocusEvent* e) { - lineEdit()->deselect();//Clear selection when leaving. - lineEdit()->setReadOnly(true);//Clever hack to clear the cursor when leaving. + //lineEdit()->deselect();//Clear selection when leaving. + //lineEdit()->setReadOnly(true);//Clever hack to clear the cursor when leaving. QSpinBox::focusOutEvent(e); } @@ -187,8 +187,8 @@ void SpinBox::focusOutEvent(QFocusEvent* e) /// The event void SpinBox::enterEvent(QEvent* e) { - m_Select = true; - setFocus(); + //m_Select = true; + //setFocus(); QSpinBox::enterEvent(e); } @@ -199,7 +199,7 @@ void SpinBox::enterEvent(QEvent* e) /// The event void SpinBox::leaveEvent(QEvent* e) { - m_Select = false; - clearFocus(); + //m_Select = false; + //clearFocus(); QSpinBox::leaveEvent(e); }