Sketcher: New flexible DSH Architecture

=======================================

Rewrite of the architecture to accomodate on-view parameters and to enable code reuse
between the default widget and custom widgets.
This commit is contained in:
Abdullah Tahiri
2023-10-20 20:29:05 +02:00
committed by abdullahtahiriyo
parent a5b5d01c22
commit 82fed5bbfc
10 changed files with 1392 additions and 1414 deletions

View File

@@ -27,8 +27,6 @@
#include <Inventor/events/SoKeyboardEvent.h>
#include <QApplication>
#include <QEvent>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#endif
#include "ui_SketcherToolDefaultWidget.h"
@@ -37,8 +35,6 @@
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/PrefWidgets.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
@@ -53,70 +49,6 @@ using namespace SketcherGui;
using namespace Gui::TaskView;
SketcherToolDefaultWidget::KeyboardManager::KeyboardManager()
: keyMode(SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode::Widget)
{
// get the active viewer, so that we can send it key events
auto doc = Gui::Application::Instance->activeDocument();
if (doc) {
auto temp = dynamic_cast<Gui::View3DInventor*>(doc->getActiveView());
if (temp) {
vpViewer = temp->getViewer();
keyMode = KeyboardEventHandlingMode::ViewProvider;
}
}
timer.setSingleShot(true);
QObject::connect(&timer, &QTimer::timeout, [this]() {
onTimeOut();
});
}
bool SketcherToolDefaultWidget::KeyboardManager::isMode(
SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode mode)
{
return mode == keyMode;
}
SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode
SketcherToolDefaultWidget::KeyboardManager::getMode()
{
return keyMode;
}
bool SketcherToolDefaultWidget::KeyboardManager::handleKeyEvent(QKeyEvent* keyEvent)
{
detectKeyboardEventHandlingMode(keyEvent); // determine the handler
if (vpViewer && isMode(KeyboardEventHandlingMode::ViewProvider)) {
return QApplication::sendEvent(vpViewer, keyEvent);
}
return false; // do not intercept the event and feed it to the widget
}
void SketcherToolDefaultWidget::KeyboardManager::detectKeyboardEventHandlingMode(
QKeyEvent* keyEvent)
{
QRegularExpression rx(QStringLiteral("^[0-9]$"));
auto match = rx.match(keyEvent->text());
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return
|| keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab
|| keyEvent->key() == Qt::Key_Backspace || keyEvent->key() == Qt::Key_Delete
|| keyEvent->key() == Qt::Key_Minus || keyEvent->key() == Qt::Key_Period
|| keyEvent->key() == Qt::Key_Comma || match.hasMatch()) {
keyMode = KeyboardEventHandlingMode::Widget;
timer.start(timeOut);
}
}
void SketcherToolDefaultWidget::KeyboardManager::onTimeOut()
{
keyMode = KeyboardEventHandlingMode::ViewProvider;
}
SketcherToolDefaultWidget::SketcherToolDefaultWidget(QWidget* parent)
: QWidget(parent)
, ui(new Ui_SketcherToolDefaultWidget)
@@ -224,16 +156,6 @@ bool SketcherToolDefaultWidget::eventFilter(QObject* object, QEvent* event)
}
}
}
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
/*If a key shortcut is required to work on sketcher when a tool using Tool Setting widget
is being used, then you have to add this key to the below section such that the spinbox
doesn't keep the keypress event for itself. Note if you want the event to be handled by
the spinbox too, you can return false.*/
auto keyEvent = static_cast<QKeyEvent*>(event);
return keymanager.handleKeyEvent(keyEvent);
}
return false;
}