mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-01-21 13:10:04 -05:00
Bug fixes:
--Fix logic for showing context menu when the option for right click to toggle is true.
This commit is contained in:
parent
f9c1234291
commit
8f2218326a
@ -173,16 +173,18 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e)
|
||||
|
||||
if (isEnabled() && me)
|
||||
{
|
||||
bool isRight = me->button() == Qt::RightButton;
|
||||
|
||||
if (!m_Settings->ToggleType() &&//Ensure double click toggles, not right click.
|
||||
me->type() == QMouseEvent::MouseButtonPress &&
|
||||
me->button() == Qt::RightButton)
|
||||
isRight)
|
||||
{
|
||||
m_MouseDownPoint = m_MouseMovePoint = me->pos();
|
||||
StartTimer();
|
||||
}
|
||||
else if (!m_Settings->ToggleType() &&
|
||||
me->type() == QMouseEvent::MouseButtonRelease &&
|
||||
me->button() == Qt::RightButton)
|
||||
isRight)
|
||||
{
|
||||
StopTimer();
|
||||
m_MouseDownPoint = m_MouseMovePoint = me->pos();
|
||||
@ -195,12 +197,14 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e)
|
||||
}
|
||||
else if (m_DoubleClick &&
|
||||
((!m_Settings->ToggleType() && e->type() == QMouseEvent::MouseButtonDblClick && me->button() == Qt::LeftButton) ||
|
||||
(m_Settings->ToggleType() && me->type() == QMouseEvent::MouseButtonRelease && me->button() == Qt::RightButton)))
|
||||
(m_Settings->ToggleType() && me->type() == QMouseEvent::MouseButtonRelease && isRight)))
|
||||
{
|
||||
if (IsClose(m_DoubleClickLowVal, value()))
|
||||
setValue(m_DoubleClickZero);
|
||||
else
|
||||
setValue(m_DoubleClickNonZero);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -288,6 +292,54 @@ void DoubleSpinBox::StopTimer()
|
||||
disconnect(&s_Timer, SIGNAL(timeout()), this, SLOT(OnTimeout()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that does nothing but pass arguments to the base.
|
||||
/// </summary>
|
||||
/// <param name="p">The parent widget</param>
|
||||
/// <param name="h">The height of the spin box. Default: 16.</param>
|
||||
/// <param name="step">The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.05.</param>
|
||||
SpecialDoubleSpinBox::SpecialDoubleSpinBox(QWidget* p, int h, double step)
|
||||
: DoubleSpinBox(p, h, step)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event filter for taking special action on right click events.
|
||||
/// </summary>
|
||||
/// <param name="o">The object</param>
|
||||
/// <param name="e">The eevent</param>
|
||||
/// <returns>True to stop processing the event, else false./</returns>
|
||||
bool SpecialDoubleSpinBox::eventFilter(QObject* o, QEvent* e)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
auto me = dynamic_cast<QMouseEvent*>(e);
|
||||
auto cme = dynamic_cast<QContextMenuEvent*>(e);
|
||||
|
||||
if (m_DoubleClick && m_Settings->ToggleType())//If they use right click to toggle...
|
||||
{
|
||||
if (me)
|
||||
{
|
||||
if (me->type() == QMouseEvent::MouseButtonRelease && me->button() == Qt::RightButton)
|
||||
{
|
||||
if (me->modifiers().testFlag(Qt::ShiftModifier))//...then do not take the action if shift was pressed.
|
||||
return false;//Shift was pressed, so continue normal event processing to show the menu, but do not call the base to toggle the value.
|
||||
}
|
||||
}
|
||||
else if (cme)//Context menu.
|
||||
{
|
||||
if (!cme->modifiers().testFlag(Qt::ShiftModifier))//If they are not holding shift, call the base to toggle, and do not process further which suppresses showing the menu.
|
||||
{
|
||||
DoubleSpinBox::eventFilter(o, e);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DoubleSpinBox::eventFilter(o, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that passes agruments to the base and assigns the m_Param and m_Variation members.
|
||||
/// It also sets up the context menu for special numerical values.
|
||||
@ -299,7 +351,7 @@ void DoubleSpinBox::StopTimer()
|
||||
/// <param name="h">The height of the spin box. Default: 16.</param>
|
||||
/// <param name="step">The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.05.</param>
|
||||
VariationTreeDoubleSpinBox::VariationTreeDoubleSpinBox(QWidget* p, VariationTreeWidgetItem* widgetItem, eVariationId id, const string& param, int h, double step)
|
||||
: DoubleSpinBox(p, h, step)
|
||||
: SpecialDoubleSpinBox(p, h, step)
|
||||
{
|
||||
m_WidgetItem = widgetItem;
|
||||
m_Param = param;
|
||||
@ -377,7 +429,7 @@ void VariationTreeDoubleSpinBox::SqrtThreeActionTriggered(bool checked) { setVal
|
||||
/// <param name="h">The height of the spin box. Default: 20.</param>
|
||||
/// <param name="step">The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.01.</param>
|
||||
AffineDoubleSpinBox::AffineDoubleSpinBox(QWidget* p, int h, double step)
|
||||
: DoubleSpinBox(p, h, step)
|
||||
: SpecialDoubleSpinBox(p, h, step)
|
||||
{
|
||||
//-1
|
||||
auto neg1Action = new QAction("-1", this);
|
||||
@ -407,4 +459,4 @@ void AffineDoubleSpinBox::NegOneActionTriggered(bool checked) { setValue(-1); }
|
||||
void AffineDoubleSpinBox::ZeroActionTriggered(bool checked) { setValue(0); }
|
||||
void AffineDoubleSpinBox::OneActionTriggered(bool checked) { setValue(1); }
|
||||
void AffineDoubleSpinBox::FortyFiveActionTriggered(bool checked) { setValue(0.707107); }
|
||||
void AffineDoubleSpinBox::NegFortyFiveActionTriggered(bool checked) { setValue(-0.707107); }
|
||||
void AffineDoubleSpinBox::NegFortyFiveActionTriggered(bool checked) { setValue(-0.707107); }
|
@ -43,11 +43,13 @@ protected:
|
||||
virtual void enterEvent(QEvent* e);
|
||||
virtual void leaveEvent(QEvent* e);
|
||||
|
||||
bool m_DoubleClick;
|
||||
shared_ptr<FractoriumSettings> m_Settings;
|
||||
|
||||
private:
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
|
||||
bool m_DoubleClick;
|
||||
double m_DoubleClickLowVal;
|
||||
double m_DoubleClickNonZero;
|
||||
double m_DoubleClickZero;
|
||||
@ -55,10 +57,26 @@ private:
|
||||
double m_SmallStep;
|
||||
QPoint m_MouseDownPoint;
|
||||
QPoint m_MouseMovePoint;
|
||||
shared_ptr<FractoriumSettings> m_Settings;
|
||||
static QTimer s_Timer;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Thin derivation to implement the eventFilter() override which subsequently derived
|
||||
/// classes will use to suppress showing the context menu when right clicking is used for toggling,
|
||||
/// unless shift is pressed.
|
||||
/// </summary>
|
||||
class SpecialDoubleSpinBox : public DoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SpecialDoubleSpinBox(QWidget* p = nullptr, int h = 16, double step = 0.05);
|
||||
virtual ~SpecialDoubleSpinBox() { }
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* o, QEvent* e) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// VariationTreeWidgetItem and VariationTreeDoubleSpinBox need each other, but each can't include the other.
|
||||
/// So VariationTreeWidgetItem includes this file, and use a forward declaration here.
|
||||
@ -69,7 +87,7 @@ class VariationTreeWidgetItem;
|
||||
/// Derivation for the double spin boxes that are in the
|
||||
/// variations tree.
|
||||
/// </summary>
|
||||
class VariationTreeDoubleSpinBox : public DoubleSpinBox
|
||||
class VariationTreeDoubleSpinBox : public SpecialDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -105,7 +123,7 @@ private:
|
||||
/// Derivation for the double spin boxes that are in the
|
||||
/// affine controls.
|
||||
/// </summary>
|
||||
class AffineDoubleSpinBox : public DoubleSpinBox
|
||||
class AffineDoubleSpinBox : public SpecialDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user