Sketcher: change DSH framework so that tab cycle through OVP and widget parameters.
This commit is contained in:
@@ -123,7 +123,8 @@ protected:
|
||||
std::vector<std::unique_ptr<Gui::EditableDatumLabel>> onViewParameters;
|
||||
// NOLINTEND
|
||||
|
||||
bool init = false; // true if the controls have been initialised.
|
||||
bool init = false; // true if the controls have been initialised.
|
||||
int parameterWithFocus = 0; // track the index of the parameter having the focus
|
||||
|
||||
/** @name Named indices for controlling on-view controls */
|
||||
//@{
|
||||
@@ -147,7 +148,6 @@ private:
|
||||
Base::Vector2d prevCursorPosition;
|
||||
Base::Vector2d lastControlEnforcedPosition;
|
||||
|
||||
int onViewIndexWithFocus = 0; // track the index of the on-view parameter having the focus
|
||||
int nOnViewParameter = OnViewParametersT::defaultMethodSize();
|
||||
|
||||
/// Class to keep track of colors used by the on-view parameters
|
||||
@@ -520,8 +520,8 @@ protected:
|
||||
virtual void afterEnforceControlParameters()
|
||||
{
|
||||
// Give focus to current on-view parameter. In case user interacted outside of 3dview.
|
||||
if (onViewIndexWithFocus >= 0) {
|
||||
setFocusToOnViewParameter(onViewIndexWithFocus);
|
||||
if (parameterWithFocus >= 0) {
|
||||
setFocusToOnViewParameter(parameterWithFocus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ protected:
|
||||
double val,
|
||||
const Base::Unit& unit = Base::Unit::Length)
|
||||
{
|
||||
bool visible = ovpVisibilityManager.isVisible(onViewParameters[index].get());
|
||||
bool visible = isOnViewParameterVisible(index);
|
||||
|
||||
if (visible) {
|
||||
onViewParameters[index]->setSpinboxValue(val, unit);
|
||||
@@ -620,7 +620,7 @@ protected:
|
||||
ovpVisibilityManager.resetDynamicOverride();
|
||||
|
||||
bool firstOfMode = true;
|
||||
onViewIndexWithFocus = -1;
|
||||
parameterWithFocus = -1;
|
||||
|
||||
for (size_t i = 0; i < onViewParameters.size(); i++) {
|
||||
|
||||
@@ -633,11 +633,11 @@ protected:
|
||||
else {
|
||||
|
||||
if (firstOfMode) {
|
||||
onViewIndexWithFocus = static_cast<int>(i);
|
||||
parameterWithFocus = static_cast<int>(i);
|
||||
firstOfMode = false;
|
||||
}
|
||||
|
||||
bool visible = ovpVisibilityManager.isVisible(onViewParameters[i].get());
|
||||
bool visible = isOnViewParameterVisible(i);
|
||||
|
||||
if (visible) {
|
||||
onViewParameters[i]->activate();
|
||||
@@ -652,52 +652,46 @@ protected:
|
||||
}
|
||||
|
||||
/// This function gives the focus to a spinbox and tracks the focus.
|
||||
void setFocusToOnViewParameter(unsigned int onviewparameterindex)
|
||||
bool setFocusToOnViewParameter(unsigned int onviewparameterindex)
|
||||
{
|
||||
if (onviewparameterindex < onViewParameters.size()) {
|
||||
|
||||
bool visible =
|
||||
ovpVisibilityManager.isVisible(onViewParameters[onviewparameterindex].get());
|
||||
bool visible = isOnViewParameterVisible(onviewparameterindex);
|
||||
|
||||
if (visible) {
|
||||
onViewParameters[onviewparameterindex]->setFocusToSpinbox();
|
||||
parameterWithFocus = static_cast<int>(onviewparameterindex);
|
||||
return true;
|
||||
}
|
||||
|
||||
onViewIndexWithFocus = static_cast<int>(onviewparameterindex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Switches focus to the next parameter in the current state machine.
|
||||
void passFocusToNextOnViewParameter()
|
||||
{
|
||||
unsigned int index = onViewIndexWithFocus + 1;
|
||||
unsigned int index = parameterWithFocus + 1;
|
||||
|
||||
if (index >= onViewParameters.size()) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
bool visible = ovpVisibilityManager.isVisible(onViewParameters[index].get());
|
||||
|
||||
while (index < onViewParameters.size()) {
|
||||
if (isOnViewParameterOfCurrentMode(index)) {
|
||||
|
||||
if (visible) {
|
||||
setFocusToOnViewParameter(index);
|
||||
auto trySetFocus = [this](unsigned int& idx) -> bool {
|
||||
while (idx < onViewParameters.size()) {
|
||||
if (isOnViewParameterOfCurrentMode(idx) && isOnViewParameterVisible(idx)) {
|
||||
setFocusToOnViewParameter(idx);
|
||||
return true;
|
||||
}
|
||||
return;
|
||||
idx++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
// There is no more onViewParameter after onViewIndexWithFocus + 1 in this mode
|
||||
return false;
|
||||
};
|
||||
|
||||
// So we go back to start.
|
||||
index = 0;
|
||||
while (index < onViewParameters.size()) {
|
||||
if (isOnViewParameterOfCurrentMode(index)) {
|
||||
setFocusToOnViewParameter(index);
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
if (!trySetFocus(index)) {
|
||||
// We have not found a parameter in this mode after current.
|
||||
// So we go back to start and retry.
|
||||
index = 0;
|
||||
trySetFocus(index);
|
||||
}
|
||||
|
||||
// At that point if no onViewParameter is found, there is none.
|
||||
@@ -719,12 +713,17 @@ protected:
|
||||
&& getState(onviewparameterindex) < handler->state();
|
||||
}
|
||||
|
||||
bool isOnViewParameterVisible(unsigned int onviewparameterindex)
|
||||
{
|
||||
return ovpVisibilityManager.isVisible(onViewParameters[onviewparameterindex].get());
|
||||
}
|
||||
|
||||
/** Resets the on-view parameter controls */
|
||||
void resetOnViewParameters()
|
||||
{
|
||||
nOnViewParameter = OnViewParametersT::size(handler->constructionMethod());
|
||||
initNOnViewParameters(nOnViewParameter);
|
||||
onViewIndexWithFocus = 0;
|
||||
parameterWithFocus = 0;
|
||||
|
||||
configureOnViewParameters();
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ private:
|
||||
|
||||
using Connection = boost::signals2::connection;
|
||||
|
||||
Connection connectionParameterFocusOut;
|
||||
Connection connectionParameterValueChanged;
|
||||
Connection connectionCheckboxCheckedChanged;
|
||||
Connection connectionComboboxSelectionChanged;
|
||||
@@ -127,6 +128,7 @@ public:
|
||||
|
||||
~DrawSketchDefaultWidgetController() override
|
||||
{
|
||||
connectionParameterFocusOut.disconnect();
|
||||
connectionParameterValueChanged.disconnect();
|
||||
connectionCheckboxCheckedChanged.disconnect();
|
||||
connectionComboboxSelectionChanged.disconnect();
|
||||
@@ -148,6 +150,12 @@ public:
|
||||
ControllerBase::finishControlsChanged();
|
||||
}
|
||||
|
||||
void parameterFocusOut(int parameterindex)
|
||||
{
|
||||
Q_UNUSED(parameterindex);
|
||||
passFocusToNextParameter();
|
||||
}
|
||||
|
||||
/** boost slot triggering when a checkbox has changed in the widget
|
||||
* It is intended to remote control the DrawSketchDefaultWidgetHandler
|
||||
*/
|
||||
@@ -260,6 +268,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** on tab, we cycle through OVP and widget parameters */
|
||||
void tabShortcut() override
|
||||
{
|
||||
passFocusToNextParameter();
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
protected:
|
||||
@@ -282,6 +296,57 @@ protected:
|
||||
/// Automatic default method update in combobox
|
||||
void doConstructionMethodChanged() override
|
||||
{}
|
||||
|
||||
/// here we can pass focus to either OVP or widget parameters.
|
||||
void setFocusToParameter(unsigned int parameterindex)
|
||||
{
|
||||
// To be able to cycle through OVP and widget, we use a parameter index that goes from
|
||||
// 0 to (onViewParameters.size() + nParameter)
|
||||
if (!ControllerBase::setFocusToOnViewParameter(parameterindex)) {
|
||||
parameterindex = parameterindex - ControllerBase::onViewParameters.size();
|
||||
|
||||
if (parameterindex < static_cast<unsigned int>(nParameter)) {
|
||||
toolWidget->setParameterFocus(parameterindex);
|
||||
ControllerBase::parameterWithFocus =
|
||||
ControllerBase::onViewParameters.size() + parameterindex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Here we can pass focus to either OVP or widget parameters.
|
||||
void passFocusToNextParameter()
|
||||
{
|
||||
unsigned int index = ControllerBase::parameterWithFocus + 1;
|
||||
|
||||
if (index >= ControllerBase::onViewParameters.size() + nParameter) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
auto trySetFocus = [this](unsigned int& idx) -> bool {
|
||||
while (idx < ControllerBase::onViewParameters.size()) {
|
||||
if (ControllerBase::isOnViewParameterOfCurrentMode(idx)
|
||||
&& ControllerBase::isOnViewParameterVisible(idx)) {
|
||||
setFocusToParameter(idx);
|
||||
return true;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (idx < ControllerBase::onViewParameters.size() + nParameter) {
|
||||
setFocusToParameter(idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!trySetFocus(index)) {
|
||||
// We have not found a parameter in this mode after current.
|
||||
// So we go back to start and retry.
|
||||
index = 0;
|
||||
trySetFocus(index);
|
||||
}
|
||||
|
||||
// At that point if no onViewParameter is found, there is none.
|
||||
}
|
||||
//@}
|
||||
|
||||
private:
|
||||
@@ -290,6 +355,9 @@ private:
|
||||
{
|
||||
toolWidget = static_cast<SketcherToolDefaultWidget*>(widget); // NOLINT
|
||||
|
||||
connectionParameterFocusOut = toolWidget->registerParameterFocusOut(
|
||||
std::bind(&DrawSketchDefaultWidgetController::parameterFocusOut, this, sp::_1));
|
||||
|
||||
connectionParameterValueChanged = toolWidget->registerParameterValueChanged(
|
||||
std::bind(&DrawSketchDefaultWidgetController::parameterValueChanged,
|
||||
this,
|
||||
@@ -312,6 +380,7 @@ private:
|
||||
/// Resets the widget
|
||||
void resetDefaultWidget()
|
||||
{
|
||||
boost::signals2::shared_connection_block parameter_focus_block(connectionParameterFocusOut);
|
||||
boost::signals2::shared_connection_block parameter_block(connectionParameterValueChanged);
|
||||
boost::signals2::shared_connection_block checkbox_block(connectionCheckboxCheckedChanged);
|
||||
boost::signals2::shared_connection_block combobox_block(connectionComboboxSelectionChanged);
|
||||
|
||||
@@ -157,6 +157,16 @@ bool SketcherToolDefaultWidget::eventFilter(QObject* object, QEvent* event)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::FocusOut) {
|
||||
for (int i = 0; i < nParameters; i++) {
|
||||
auto parameterSpinBox = getParameterSpinBox(i);
|
||||
|
||||
if (object == parameterSpinBox) {
|
||||
signalParameterFocusOut(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -200,10 +210,10 @@ void SketcherToolDefaultWidget::parameterOne_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::First] = true;
|
||||
setParameterFontStyle(Parameter::First, FontStyle::Bold);
|
||||
/*setParameterFontStyle(Parameter::First, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Second);
|
||||
}
|
||||
}*/
|
||||
signalParameterValueChanged(Parameter::First, val);
|
||||
}
|
||||
}
|
||||
@@ -211,10 +221,6 @@ void SketcherToolDefaultWidget::parameterTwo_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Second] = true;
|
||||
setParameterFontStyle(Parameter::Second, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Third);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Second, val);
|
||||
}
|
||||
}
|
||||
@@ -222,10 +228,6 @@ void SketcherToolDefaultWidget::parameterThree_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Third] = true;
|
||||
setParameterFontStyle(Parameter::Third, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Fourth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Third, val);
|
||||
}
|
||||
}
|
||||
@@ -233,10 +235,6 @@ void SketcherToolDefaultWidget::parameterFour_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Fourth] = true;
|
||||
setParameterFontStyle(Parameter::Fourth, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Fifth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Fourth, val);
|
||||
}
|
||||
}
|
||||
@@ -244,10 +242,6 @@ void SketcherToolDefaultWidget::parameterFive_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Fifth] = true;
|
||||
setParameterFontStyle(Parameter::Fifth, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Sixth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Fifth, val);
|
||||
}
|
||||
}
|
||||
@@ -255,10 +249,6 @@ void SketcherToolDefaultWidget::parameterSix_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Sixth] = true;
|
||||
setParameterFontStyle(Parameter::Sixth, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Seventh);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Sixth, val);
|
||||
}
|
||||
}
|
||||
@@ -266,10 +256,6 @@ void SketcherToolDefaultWidget::parameterSeven_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Seventh] = true;
|
||||
setParameterFontStyle(Parameter::Seventh, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Eighth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Seventh, val);
|
||||
}
|
||||
}
|
||||
@@ -277,10 +263,6 @@ void SketcherToolDefaultWidget::parameterEight_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Eighth] = true;
|
||||
setParameterFontStyle(Parameter::Eighth, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Ninth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Eighth, val);
|
||||
}
|
||||
}
|
||||
@@ -288,10 +270,6 @@ void SketcherToolDefaultWidget::parameterNine_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Ninth] = true;
|
||||
setParameterFontStyle(Parameter::Ninth, FontStyle::Bold);
|
||||
if (!blockParameterFocusPassing) {
|
||||
setParameterFocus(Parameter::Tenth);
|
||||
}
|
||||
signalParameterValueChanged(Parameter::Ninth, val);
|
||||
}
|
||||
}
|
||||
@@ -299,7 +277,6 @@ void SketcherToolDefaultWidget::parameterTen_valueChanged(double val)
|
||||
{
|
||||
if (!blockParameterSlots) {
|
||||
isSet[Parameter::Tenth] = true;
|
||||
setParameterFontStyle(Parameter::Tenth, FontStyle::Bold);
|
||||
signalParameterValueChanged(Parameter::Tenth, val);
|
||||
}
|
||||
}
|
||||
@@ -316,7 +293,7 @@ void SketcherToolDefaultWidget::initNParameters(int nparameters, QObject* filter
|
||||
setParameterVisible(i, (i < nparameters));
|
||||
setParameter(i, 0.F);
|
||||
setParameterFilteringObject(i, filteringObject);
|
||||
setParameterFontStyle(i, FontStyle::Italic);
|
||||
// setParameterFontStyle(i, FontStyle::Italic);
|
||||
}
|
||||
|
||||
setParameterFocus(Parameter::First);
|
||||
|
||||
@@ -154,6 +154,12 @@ public:
|
||||
void setComboboxPrefEntry(int comboboxindex, const std::string& prefEntry);
|
||||
void restoreComboboxPref(int comboboxindex);
|
||||
|
||||
template<typename F>
|
||||
boost::signals2::connection registerParameterFocusOut(F&& fn)
|
||||
{
|
||||
return signalParameterFocusOut.connect(std::forward<F>(fn));
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
boost::signals2::connection registerParameterValueChanged(F&& fn)
|
||||
{
|
||||
@@ -211,6 +217,7 @@ private:
|
||||
private:
|
||||
std::unique_ptr<Ui_SketcherToolDefaultWidget> ui;
|
||||
|
||||
boost::signals2::signal<void(int parameterindex)> signalParameterFocusOut;
|
||||
boost::signals2::signal<void(int parameterindex, double value)> signalParameterValueChanged;
|
||||
boost::signals2::signal<void(int checkboxindex, bool value)> signalCheckboxCheckedChanged;
|
||||
boost::signals2::signal<void(int comboindex, int value)> signalComboboxSelectionChanged;
|
||||
|
||||
Reference in New Issue
Block a user