From f1eb315f20e0789aef09969ebd77b3e19f327720 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 28 Jun 2025 19:59:29 +0200 Subject: [PATCH] Sketcher: Use generic tool hints table for DrawSketchHandlerRectangle --- .../Sketcher/Gui/DrawSketchHandlerRectangle.h | 225 +++++++++--------- 1 file changed, 113 insertions(+), 112 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index 4060835542..9accc2e542 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -111,23 +111,122 @@ public: private: std::list getToolHints() const override { - return lookupRectangleHints(constructionMethod(), state()); + using State = std::pair; + using enum Gui::InputHint::UserInput; + + const Gui::InputHint switchHint {.message = QObject::tr("%1 switch mode"), + .sequences = {KeyM}}; + + return Gui::lookupHints( + {constructionMethod(), state()}, + { + // Diagonal method + {.state = {ConstructionMethod::Diagonal, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick first corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::Diagonal, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick opposite corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::Diagonal, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 set corner radius or frame thickness"), {MouseMove}}, + switchHint, + }}, + {.state = {ConstructionMethod::Diagonal, SelectMode::SeekFourth}, + .hints = + { + {QObject::tr("%1 set frame thickness"), {MouseMove}}, + switchHint, + }}, + + // CenterAndCorner method + {.state = {ConstructionMethod::CenterAndCorner, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick center"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAndCorner, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAndCorner, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 set corner radius or frame thickness"), {MouseMove}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAndCorner, SelectMode::SeekFourth}, + .hints = + { + {QObject::tr("%1 set frame thickness"), {MouseMove}}, + switchHint, + }}, + + // ThreePoints method + {.state = {ConstructionMethod::ThreePoints, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick first corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::ThreePoints, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick second corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::ThreePoints, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 pick third corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::ThreePoints, SelectMode::SeekFourth}, + .hints = + { + {QObject::tr("%1 set corner radius or frame thickness"), {MouseMove}}, + switchHint, + }}, + + // CenterAnd3Points method + {.state = {ConstructionMethod::CenterAnd3Points, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick center"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAnd3Points, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick first corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAnd3Points, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 pick second corner"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::CenterAnd3Points, SelectMode::SeekFourth}, + .hints = + { + {QObject::tr("%1 set corner radius or frame thickness"), {MouseMove}}, + switchHint, + }}, + }); } private: - struct HintEntry - { - ConstructionMethods::RectangleConstructionMethod method; - SelectMode state; - std::list hints; - }; - - using HintTable = std::vector; - - static Gui::InputHint switchModeHint(); - static HintTable getRectangleHintTable(); - static std::list - lookupRectangleHints(ConstructionMethods::RectangleConstructionMethod method, SelectMode state); void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { using std::numbers::pi; @@ -2675,104 +2774,6 @@ void DSHRectangleController::doConstructionMethodChanged() handler->updateHint(); } -Gui::InputHint DrawSketchHandlerRectangle::switchModeHint() -{ - return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; -} - -DrawSketchHandlerRectangle::HintTable DrawSketchHandlerRectangle::getRectangleHintTable() -{ - const auto switchHint = switchModeHint(); - return {// Structure: {ConstructionMethod, SelectMode, {hints...}} - - // Diagonal method - {ConstructionMethods::RectangleConstructionMethod::Diagonal, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::Diagonal, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick opposite corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::Diagonal, - SelectMode::SeekThird, - {{QObject::tr("%1 set corner radius or frame thickness"), - {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::Diagonal, - SelectMode::SeekFourth, - {{QObject::tr("%1 set frame thickness"), {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}, - - // CenterAndCorner method - {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick center"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick corner"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, - SelectMode::SeekThird, - {{QObject::tr("%1 set corner radius or frame thickness"), - {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, - SelectMode::SeekFourth, - {{QObject::tr("%1 set frame thickness"), {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}, - - // ThreePoints method - {ConstructionMethods::RectangleConstructionMethod::ThreePoints, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::ThreePoints, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick second corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::ThreePoints, - SelectMode::SeekThird, - {{QObject::tr("%1 pick third corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::ThreePoints, - SelectMode::SeekFourth, - {{QObject::tr("%1 set corner radius or frame thickness"), - {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}, - - // CenterAnd3Points method - {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick center"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, - SelectMode::SeekThird, - {{QObject::tr("%1 pick second corner"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, - SelectMode::SeekFourth, - {{QObject::tr("%1 set corner radius or frame thickness"), - {Gui::InputHint::UserInput::MouseMove}}, - switchHint}}}; -} - -std::list DrawSketchHandlerRectangle::lookupRectangleHints( - ConstructionMethods::RectangleConstructionMethod method, - SelectMode state) -{ - const auto rectangleHintTable = getRectangleHintTable(); - - auto it = std::find_if(rectangleHintTable.begin(), - rectangleHintTable.end(), - [method, state](const HintEntry& entry) { - return entry.method == method && entry.state == state; - }); - - return (it != rectangleHintTable.end()) ? it->hints : std::list {}; -} } // namespace SketcherGui