From 66f8f1e50cda3129aff60e515639d71b9cd56d4b Mon Sep 17 00:00:00 2001 From: mfeemster Date: Sat, 20 Feb 2016 18:44:52 -0800 Subject: [PATCH] --User changes -Draw selection circles around all selected xforms plus the current one. --Bug fixes -Add control key as a modifier to increase the amount a spinbox is changed when using right mouse drag to edit. Previously only observed shift key to decrease the value. -Change the copy/paste selected xforms shortcuts to be Ctrl+X+C and Ctrl+X+V. --Code changes -Add function Fractorium::IsXformSelected() to determine if an xform has been selected with the checkboxes. --- Source/Fractorium/DoubleSpinBox.cpp | 41 +----------------- Source/Fractorium/Fractorium.cpp | 8 ++-- Source/Fractorium/Fractorium.h | 1 + Source/Fractorium/Fractorium.ui | 12 +++--- .../Fractorium/FractoriumEmberController.cpp | 4 +- Source/Fractorium/FractoriumXaos.cpp | 2 +- Source/Fractorium/FractoriumXforms.cpp | 2 +- Source/Fractorium/FractoriumXformsAffine.cpp | 2 +- Source/Fractorium/FractoriumXformsSelect.cpp | 19 ++++++-- .../Fractorium/FractoriumXformsVariations.cpp | 2 +- Source/Fractorium/GLWidget.cpp | 4 +- Source/Fractorium/SpinBox.cpp | 43 ++----------------- 12 files changed, 39 insertions(+), 101 deletions(-) diff --git a/Source/Fractorium/DoubleSpinBox.cpp b/Source/Fractorium/DoubleSpinBox.cpp index 5920b3d..08f1429 100644 --- a/Source/Fractorium/DoubleSpinBox.cpp +++ b/Source/Fractorium/DoubleSpinBox.cpp @@ -136,25 +136,18 @@ void DoubleSpinBox::OnTimeout() double scale, val; double d = value(); bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier); - //bool ctrl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); + bool ctrl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); double amount = (m_SmallStep + m_Step) * 0.5; if (shift) - { - //qDebug() << "Shift pressed"; scale = 0.0001; - } - /* else if (ctrl) - { - qDebug() << "Control pressed"; + else if (ctrl) scale = 0.01; - }*/ else scale = 0.001; val = d + (distance * amount * scale); setValue(val); - //qDebug() << "Timer on, orig val: " << d << ", new val: " << val << ", distance " << distance; } /// @@ -174,27 +167,6 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) { m_MouseDownPoint = m_MouseMovePoint = me->pos(); StartTimer(); - //qDebug() << "Right mouse down"; - // 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 (isEnabled() && me && @@ -203,7 +175,6 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) { StopTimer(); m_MouseDownPoint = m_MouseMovePoint = me->pos(); - //qDebug() << "Right mouse up"; } else if (isEnabled() && me && @@ -211,7 +182,6 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) QGuiApplication::mouseButtons() & Qt::RightButton) { m_MouseMovePoint = me->pos(); - qDebug() << "Mouse move while right down. Pt = " << me->pos() << ", global: " << mapToGlobal(me->pos()); } else if (m_DoubleClick && e->type() == QMouseEvent::MouseButtonDblClick && isEnabled()) { @@ -247,7 +217,6 @@ bool DoubleSpinBox::eventFilter(QObject* o, QEvent* e) /// The event void DoubleSpinBox::focusInEvent(QFocusEvent* e) { - //lineEdit()->setReadOnly(false); StopTimer(); QDoubleSpinBox::focusInEvent(e); } @@ -261,8 +230,6 @@ 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. StopTimer(); QDoubleSpinBox::focusOutEvent(e); } @@ -274,8 +241,6 @@ void DoubleSpinBox::focusOutEvent(QFocusEvent* e) /// The event void DoubleSpinBox::enterEvent(QEvent* e) { - //m_Select = true; - //setFocus(); StopTimer(); QDoubleSpinBox::enterEvent(e); } @@ -287,8 +252,6 @@ void DoubleSpinBox::enterEvent(QEvent* e) /// The event void DoubleSpinBox::leaveEvent(QEvent* e) { - //m_Select = false; - //clearFocus();. StopTimer(); QDoubleSpinBox::leaveEvent(e); } diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index b9710bd..912f792 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -783,7 +783,7 @@ void Fractorium::ToggleTableRow(QTableView* table, int logicalIndex) { for (int i = 0; i < cols; i++) { - if (auto* spinBox = qobject_cast(tableWidget->cellWidget(logicalIndex, i))) + if (auto spinBox = qobject_cast(tableWidget->cellWidget(logicalIndex, i))) { if (!IsNearZero(spinBox->value())) { @@ -799,7 +799,7 @@ void Fractorium::ToggleTableRow(QTableView* table, int logicalIndex) double val = allZero ? 1.0 : 0.0; for (int i = 0; i < cols; i++) - if (auto* spinBox = qobject_cast(tableWidget->cellWidget(logicalIndex, i))) + if (auto spinBox = qobject_cast(tableWidget->cellWidget(logicalIndex, i))) spinBox->setValue(val); } else @@ -844,7 +844,7 @@ void Fractorium::ToggleTableCol(QTableView* table, int logicalIndex) { for (int i = 0; i < rows; i++) { - if (auto* spinBox = qobject_cast(tableWidget->cellWidget(i, logicalIndex))) + if (auto spinBox = qobject_cast(tableWidget->cellWidget(i, logicalIndex))) { if (!IsNearZero(spinBox->value())) { @@ -860,7 +860,7 @@ void Fractorium::ToggleTableCol(QTableView* table, int logicalIndex) double val = allZero ? 1.0 : 0.0; for (int i = 0; i < rows; i++) - if (auto* spinBox = qobject_cast(tableWidget->cellWidget(i, logicalIndex))) + if (auto spinBox = qobject_cast(tableWidget->cellWidget(i, logicalIndex))) spinBox->setValue(val); } else diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index 9503eca..5c8e12a 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -262,6 +262,7 @@ public slots: //Xforms Selection. void OnXformsSelectAllButtonClicked(bool checked); void OnXformsSelectNoneButtonClicked(bool checked); + bool IsXformSelected(size_t i); //Xaos. void OnXaosChanged(double d); diff --git a/Source/Fractorium/Fractorium.ui b/Source/Fractorium/Fractorium.ui index d2a4e19..15536b0 100644 --- a/Source/Fractorium/Fractorium.ui +++ b/Source/Fractorium/Fractorium.ui @@ -3470,8 +3470,8 @@ 0 0 - 118 - 618 + 263 + 700 @@ -5485,8 +5485,8 @@ 0 0 - 133 - 52 + 259 + 652 @@ -7098,7 +7098,7 @@ Copy selected xforms to the clipboard - Ctrl+C, X + Ctrl+X, Ctrl+C @@ -7109,7 +7109,7 @@ Paste copied xforms into the current flame - Ctrl+V, X + Ctrl+X, Ctrl+V diff --git a/Source/Fractorium/FractoriumEmberController.cpp b/Source/Fractorium/FractoriumEmberController.cpp index 44f2ec6..c0ace11 100644 --- a/Source/Fractorium/FractoriumEmberController.cpp +++ b/Source/Fractorium/FractoriumEmberController.cpp @@ -252,7 +252,7 @@ void FractoriumEmberController::UpdateXform(std::function*)> fu { if (auto child = m_Fractorium->m_XformsSelectionLayout->itemAt(i)) { - if (auto* w = qobject_cast(child->widget())) + if (auto w = qobject_cast(child->widget())) { if (w->isChecked()) { @@ -281,7 +281,7 @@ void FractoriumEmberController::UpdateXform(std::function*)> fu { if (auto child = m_Fractorium->m_XformsSelectionLayout->itemAt(i)) { - if (auto* w = qobject_cast(child->widget())) + if (auto w = qobject_cast(child->widget())) { if (w->isChecked()) { diff --git a/Source/Fractorium/FractoriumXaos.cpp b/Source/Fractorium/FractoriumXaos.cpp index 3bb724b..37fa6a2 100644 --- a/Source/Fractorium/FractoriumXaos.cpp +++ b/Source/Fractorium/FractoriumXaos.cpp @@ -146,7 +146,7 @@ void FractoriumEmberController::RandomXaos() { for (size_t i = 0; i < m_Ember.XformCount(); i++) { - if (auto* xform = m_Ember.GetXform(i)) + if (auto xform = m_Ember.GetXform(i)) { for (size_t j = 0; j < m_Ember.XformCount(); j++) { diff --git a/Source/Fractorium/FractoriumXforms.cpp b/Source/Fractorium/FractoriumXforms.cpp index a144fee..7709a4a 100644 --- a/Source/Fractorium/FractoriumXforms.cpp +++ b/Source/Fractorium/FractoriumXforms.cpp @@ -143,7 +143,7 @@ void FractoriumEmberController::AddLinkedXform() //Set the xaos for all xforms pointing to the new one to zero. for (i = 0; i < count; i++) - if (auto* xf = m_Ember.GetXform(i)) + if (auto xf = m_Ember.GetXform(i)) xf->SetXaos(count - 1, 0); xform->SetXaos(count - 1, 1);//Set the xaos value for the previous xform pointing to the new one to one. diff --git a/Source/Fractorium/FractoriumXformsAffine.cpp b/Source/Fractorium/FractoriumXformsAffine.cpp index f13cc1f..bba961e 100644 --- a/Source/Fractorium/FractoriumXformsAffine.cpp +++ b/Source/Fractorium/FractoriumXformsAffine.cpp @@ -424,7 +424,7 @@ void FractoriumEmberController::MoveXforms(double x, double y, bool pre) { UpdateXform([&] (Xform* xform) { - auto* affine = pre ? &xform->m_Affine : &xform->m_Post; + auto affine = pre ? &xform->m_Affine : &xform->m_Post; affine->C(affine->C() + x); affine->F(affine->F() + y); }, eXformUpdate::UPDATE_SELECTED); diff --git a/Source/Fractorium/FractoriumXformsSelect.cpp b/Source/Fractorium/FractoriumXformsSelect.cpp index ae2d9ef..7164b7a 100644 --- a/Source/Fractorium/FractoriumXformsSelect.cpp +++ b/Source/Fractorium/FractoriumXformsSelect.cpp @@ -24,6 +24,19 @@ void Fractorium::OnXformsSelectAllButtonClicked(bool checked) { ForEachXformChec /// Ignored void Fractorium::OnXformsSelectNoneButtonClicked(bool checked) { ForEachXformCheckbox([&](int i, QCheckBox * w) { w->setChecked(false); }); } +/// +/// Return whether the checkbox at the specified index is checked. +/// +/// True if checked, else false. +bool Fractorium::IsXformSelected(size_t i) +{ + if (auto child = m_XformsSelectionLayout->itemAt(int(i))) + if (auto w = qobject_cast(child->widget())) + return w->isChecked(); + + return false; +} + /// /// Clear all of the dynamically created xform checkboxes. /// @@ -35,7 +48,7 @@ void Fractorium::ClearXformsSelections() while (m_XformsSelectionLayout->count() && (child = m_XformsSelectionLayout->takeAt(0))) { - auto* w = child->widget(); + auto w = child->widget(); delete child; delete w; } @@ -75,10 +88,8 @@ void Fractorium::ForEachXformCheckbox(std::function func) while (QLayoutItem* child = m_XformsSelectionLayout->itemAt(i)) { - if (auto* w = qobject_cast(child->widget())) - { + if (auto w = qobject_cast(child->widget())) func(i, w); - } i++; } diff --git a/Source/Fractorium/FractoriumXformsVariations.cpp b/Source/Fractorium/FractoriumXformsVariations.cpp index 8a9493e..a3b3ff3 100644 --- a/Source/Fractorium/FractoriumXformsVariations.cpp +++ b/Source/Fractorium/FractoriumXformsVariations.cpp @@ -176,7 +176,7 @@ void FractoriumEmberController::ClearVariationsTree() for (int i = 0; i < tree->topLevelItemCount(); i++) { auto item = tree->topLevelItem(i); - auto* spinBox = dynamic_cast(tree->itemWidget(item, 1)); + auto spinBox = dynamic_cast(tree->itemWidget(item, 1)); spinBox->SetValueStealth(0); for (int j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params. diff --git a/Source/Fractorium/GLWidget.cpp b/Source/Fractorium/GLWidget.cpp index 3a92c97..81c1dc4 100644 --- a/Source/Fractorium/GLWidget.cpp +++ b/Source/Fractorium/GLWidget.cpp @@ -307,7 +307,7 @@ void GLEmberController::DrawAffines(bool pre, bool post) for (size_t i = 0; i < ember->TotalXformCount(); i++) { auto xform = ember->GetTotalXform(i); - bool selected = dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform); + bool selected = m_Fractorium->IsXformSelected(i) || (dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform)); DrawAffine(xform, true, selected); } } @@ -321,7 +321,7 @@ void GLEmberController::DrawAffines(bool pre, bool post) for (size_t i = 0; i < ember->TotalXformCount(); i++) { auto xform = ember->GetTotalXform(i); - bool selected = dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform); + bool selected = m_Fractorium->IsXformSelected(i) || (dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform)); DrawAffine(xform, false, selected); } } diff --git a/Source/Fractorium/SpinBox.cpp b/Source/Fractorium/SpinBox.cpp index 8f98960..c74bfe1 100644 --- a/Source/Fractorium/SpinBox.cpp +++ b/Source/Fractorium/SpinBox.cpp @@ -112,25 +112,18 @@ void SpinBox::OnTimeout() double scale, val; int d = value(); bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier); - //bool ctrl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); + bool ctrl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); double amount = (m_SmallStep + m_Step) * 0.5; if (shift) - { - //qDebug() << "Shift pressed"; scale = 0.001; - } - /* else if (ctrl) - { - qDebug() << "Control pressed"; - scale = 0.01; - }*/ + else if (ctrl) + scale = 0.01; else scale = 0.01; val = d + (distance * amount * scale); setValue(int(val)); - //qDebug() << "Timer on, orig val: " << d << ", new val: " << val << ", distance " << distance; } /// @@ -150,27 +143,6 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) { m_MouseDownPoint = m_MouseMovePoint = me->pos(); StartTimer(); - //qDebug() << "Right mouse down"; - // 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 (isEnabled() && me && @@ -179,7 +151,6 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) { StopTimer(); m_MouseDownPoint = m_MouseMovePoint = me->pos(); - //qDebug() << "Right mouse up"; } else if (isEnabled() && me && @@ -187,7 +158,6 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) QGuiApplication::mouseButtons() & Qt::RightButton) { m_MouseMovePoint = me->pos(); - qDebug() << "Mouse move while right down. Pt = " << me->pos() << ", global: " << mapToGlobal(me->pos()); } else if (m_DoubleClick && e->type() == QMouseEvent::MouseButtonDblClick && isEnabled()) { @@ -223,7 +193,6 @@ bool SpinBox::eventFilter(QObject* o, QEvent* e) /// The event void SpinBox::focusInEvent(QFocusEvent* e) { - //lineEdit()->setReadOnly(false); StopTimer(); QSpinBox::focusInEvent(e); } @@ -237,8 +206,6 @@ 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. StopTimer(); QSpinBox::focusOutEvent(e); } @@ -250,8 +217,6 @@ void SpinBox::focusOutEvent(QFocusEvent* e) /// The event void SpinBox::enterEvent(QEvent* e) { - //m_Select = true; - //setFocus(); StopTimer(); QSpinBox::enterEvent(e); } @@ -263,8 +228,6 @@ void SpinBox::enterEvent(QEvent* e) /// The event void SpinBox::leaveEvent(QEvent* e) { - //m_Select = false; - //clearFocus(); StopTimer(); QSpinBox::leaveEvent(e); }