diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index b27d92c7..25f0beb0 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -24,6 +24,10 @@ #include "lc_colors.h" #include +#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0)) +#include +#endif + lcMainWindow* gMainWindow; #define LC_TAB_LAYOUT_VERSION 0x0001 @@ -81,6 +85,12 @@ lcMainWindow::lcMainWindow() for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++) mRecentFiles[FileIdx] = lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx)); +#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0)) + connect(&mGamepadTimer, &QTimer::timeout, this, &lcMainWindow::UpdateGamepads); + mLastGamepadUpdate = QDateTime::currentDateTime(); + mGamepadTimer.start(33); +#endif + gMainWindow = this; } @@ -777,6 +787,34 @@ QMenu* lcMainWindow::createPopupMenu() return Menu; } +void lcMainWindow::UpdateGamepads() +{ +#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0)) + QDateTime Now = QDateTime::currentDateTime(); + quint64 Elapsed = mLastGamepadUpdate.msecsTo(Now); + mLastGamepadUpdate = Now; + + if (!gMainWindow) + return; + + View* ActiveView = GetActiveView(); + if (!ActiveView) + return; + + const QList Gamepads = QGamepadManager::instance()->connectedGamepads(); + if (Gamepads.isEmpty()) + return; + + QGamepad Gamepad(Gamepads[0]); + + float Scale = (float)Elapsed / 20.0f; + lcVector3 Distance(Scale * Gamepad.axisLeftX(), 0.0f, -Scale * Gamepad.axisLeftY()); + + if (fabsf(Distance.LengthSquared()) > 0.01f) + ActiveView->MoveCamera(Distance); +#endif +} + void lcMainWindow::ModelTabContextMenuRequested(const QPoint& Point) { QMenu* Menu = new QMenu; diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 60c6dcab..2bb5eefb 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -327,6 +327,7 @@ public slots: void ProjectFileChanged(const QString& Path); protected slots: + void UpdateGamepads(); void ModelTabContextMenuRequested(const QPoint& Point); void ModelTabCloseOtherTabs(); void ModelTabResetViews(); @@ -368,6 +369,9 @@ protected: return nullptr; } + QTimer mGamepadTimer; + QDateTime mLastGamepadUpdate; + bool mAddKeys; lcTool mTool; lcTransformType mTransformType; diff --git a/leocad.pro b/leocad.pro index d60bcdb0..ace18ff8 100644 --- a/leocad.pro +++ b/leocad.pro @@ -1,11 +1,19 @@ QT += core gui opengl network xml TEMPLATE = app -greaterThan(QT_MAJOR_VERSION, 4) { +greaterThan(QT_MAJOR_VERSION, 4) +{ QT *= printsupport QT += concurrent } +greaterThan(QT_MAJOR_VERSION, 5) +{ + QT += gamepad +} + +equals(QT_MAJOR_VERSION, 5) : greaterThan(QT_MINOR_VERSION, 7): QT += gamepad + INCLUDEPATH += qt common CONFIG += precompile_header incremental c++11 win32 {