mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 04:20:06 +00:00
Add ability to install event handlers from mouse picking
This commit is contained in:
parent
ff882f5c06
commit
b3e035c53d
26 changed files with 222 additions and 76 deletions
|
|
@ -176,6 +176,7 @@ set(SRC_SETTINGS source/scwx/qt/settings/audio_settings.cpp
|
||||||
source/scwx/qt/settings/text_settings.cpp
|
source/scwx/qt/settings/text_settings.cpp
|
||||||
source/scwx/qt/settings/ui_settings.cpp)
|
source/scwx/qt/settings/ui_settings.cpp)
|
||||||
set(HDR_TYPES source/scwx/qt/types/alert_types.hpp
|
set(HDR_TYPES source/scwx/qt/types/alert_types.hpp
|
||||||
|
source/scwx/qt/types/event_types.hpp
|
||||||
source/scwx/qt/types/font_types.hpp
|
source/scwx/qt/types/font_types.hpp
|
||||||
source/scwx/qt/types/github_types.hpp
|
source/scwx/qt/types/github_types.hpp
|
||||||
source/scwx/qt/types/icon_types.hpp
|
source/scwx/qt/types/icon_types.hpp
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ bool DrawItem::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& /* mouseGlobalPos */,
|
const QPointF& /* mouseGlobalPos */,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& /* mouseCoords */,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
// By default, the draw item is not picked
|
// By default, the draw item is not picked
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/gl/gl.hpp>
|
#include <scwx/qt/gl/gl.hpp>
|
||||||
|
#include <scwx/qt/types/event_types.hpp>
|
||||||
#include <scwx/common/geographic.hpp>
|
#include <scwx/common/geographic.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -43,15 +44,17 @@ public:
|
||||||
* @param [in] mouseGlobalPos Mouse cursor screen position
|
* @param [in] mouseGlobalPos Mouse cursor screen position
|
||||||
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
|
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
|
||||||
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
|
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
|
||||||
|
* @param [out] eventHandler Event handler associated with picked draw item
|
||||||
*
|
*
|
||||||
* @return true if the draw item was picked, otherwise false
|
* @return true if the draw item was picked, otherwise false
|
||||||
*/
|
*/
|
||||||
virtual bool
|
virtual bool
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords);
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -736,7 +736,8 @@ bool GeoIcons::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
std::unique_lock lock {p->iconMutex_};
|
std::unique_lock lock {p->iconMutex_};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,13 @@ public:
|
||||||
bool textureAtlasChanged) override;
|
bool textureAtlasChanged) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
bool
|
||||||
const QPointF& mouseLocalPos,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const QPointF& mouseGlobalPos,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const glm::vec2& mouseCoords,
|
||||||
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the visibility of the geo icons.
|
* Sets the visibility of the geo icons.
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ static constexpr std::size_t kIconBufferLength =
|
||||||
static constexpr std::size_t kTextureBufferLength =
|
static constexpr std::size_t kTextureBufferLength =
|
||||||
kNumTriangles * kVerticesPerTriangle * kPointsPerTexCoord;
|
kNumTriangles * kVerticesPerTriangle * kPointsPerTexCoord;
|
||||||
|
|
||||||
struct IconDrawItem
|
struct IconDrawItem : types::EventHandler
|
||||||
{
|
{
|
||||||
boost::gil::rgba32f_pixel_t modulate_ {1.0f, 1.0f, 1.0f, 1.0f};
|
boost::gil::rgba32f_pixel_t modulate_ {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
double x_ {};
|
double x_ {};
|
||||||
|
|
@ -424,7 +424,7 @@ void Icons::Impl::UpdateBuffers()
|
||||||
x, y, lx, ty, mc0, mc1, mc2, mc3, a // TL
|
x, y, lx, ty, mc0, mc1, mc2, mc3, a // TL
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!di->hoverText_.empty())
|
if (!di->hoverText_.empty() || di->event_ != nullptr)
|
||||||
{
|
{
|
||||||
const units::angle::radians<double> radians = angle;
|
const units::angle::radians<double> radians = angle;
|
||||||
|
|
||||||
|
|
@ -579,7 +579,8 @@ bool Icons::RunMousePicking(
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& /* mouseCoords */,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler)
|
||||||
{
|
{
|
||||||
std::unique_lock lock {p->iconMutex_};
|
std::unique_lock lock {p->iconMutex_};
|
||||||
|
|
||||||
|
|
@ -617,12 +618,29 @@ bool Icons::RunMousePicking(
|
||||||
if (it != p->currentHoverIcons_.crend())
|
if (it != p->currentHoverIcons_.crend())
|
||||||
{
|
{
|
||||||
itemPicked = true;
|
itemPicked = true;
|
||||||
util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos);
|
|
||||||
|
if (!it->di_->hoverText_.empty())
|
||||||
|
{
|
||||||
|
// Show tooltip
|
||||||
|
util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos);
|
||||||
|
}
|
||||||
|
if (it->di_->event_ != nullptr)
|
||||||
|
{
|
||||||
|
// Register event handler
|
||||||
|
eventHandler = it->di_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemPicked;
|
return itemPicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Icons::RegisterEventHandler(
|
||||||
|
const std::shared_ptr<IconDrawItem>& di,
|
||||||
|
const std::function<void(QEvent*)>& eventHandler)
|
||||||
|
{
|
||||||
|
di->event_ = eventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace draw
|
} // namespace draw
|
||||||
} // namespace gl
|
} // namespace gl
|
||||||
} // namespace qt
|
} // namespace qt
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
#include <boost/gil.hpp>
|
#include <boost/gil.hpp>
|
||||||
#include <units/angle.h>
|
#include <units/angle.h>
|
||||||
|
|
||||||
|
class QEvent;
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace qt
|
namespace qt
|
||||||
|
|
@ -34,11 +36,13 @@ public:
|
||||||
bool textureAtlasChanged) override;
|
bool textureAtlasChanged) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
bool
|
||||||
const QPointF& mouseLocalPos,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const QPointF& mouseGlobalPos,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const glm::vec2& mouseCoords,
|
||||||
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the visibility of the icons.
|
* Sets the visibility of the icons.
|
||||||
|
|
@ -151,6 +155,16 @@ public:
|
||||||
*/
|
*/
|
||||||
void FinishIcons();
|
void FinishIcons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers an event handler for an icon.
|
||||||
|
*
|
||||||
|
* @param [in] di Icon draw item
|
||||||
|
* @param [in] eventHandler Event handler function
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
RegisterEventHandler(const std::shared_ptr<IconDrawItem>& di,
|
||||||
|
const std::function<void(QEvent*)>& eventHandler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,8 @@ bool PlacefileIcons::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
std::unique_lock lock {p->iconMutex_};
|
std::unique_lock lock {p->iconMutex_};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,13 @@ public:
|
||||||
bool textureAtlasChanged) override;
|
bool textureAtlasChanged) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
bool
|
||||||
const QPointF& mouseLocalPos,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const QPointF& mouseGlobalPos,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const glm::vec2& mouseCoords,
|
||||||
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets and prepares the draw item for adding a new set of icons.
|
* Resets and prepares the draw item for adding a new set of icons.
|
||||||
|
|
|
||||||
|
|
@ -500,7 +500,8 @@ bool PlacefileLines::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
std::unique_lock lock {p->lineMutex_};
|
std::unique_lock lock {p->lineMutex_};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,13 @@ public:
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
bool
|
||||||
const QPointF& mouseLocalPos,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const QPointF& mouseGlobalPos,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const glm::vec2& mouseCoords,
|
||||||
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets and prepares the draw item for adding a new set of lines.
|
* Resets and prepares the draw item for adding a new set of lines.
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,8 @@ bool PlacefileText::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& /* mouseCoords */,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
bool itemPicked = false;
|
bool itemPicked = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,13 @@ public:
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
bool
|
||||||
const QPointF& mouseLocalPos,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const QPointF& mouseGlobalPos,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const glm::vec2& mouseCoords,
|
||||||
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets and prepares the draw item for adding a new set of text.
|
* Resets and prepares the draw item for adding a new set of text.
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,8 @@ bool DrawLayer::RunMousePicking(
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords)
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler)
|
||||||
{
|
{
|
||||||
bool itemPicked = false;
|
bool itemPicked = false;
|
||||||
|
|
||||||
|
|
@ -93,7 +94,8 @@ bool DrawLayer::RunMousePicking(
|
||||||
mouseLocalPos,
|
mouseLocalPos,
|
||||||
mouseGlobalPos,
|
mouseGlobalPos,
|
||||||
mouseCoords,
|
mouseCoords,
|
||||||
mouseGeoCoords))
|
mouseGeoCoords,
|
||||||
|
eventHandler))
|
||||||
{
|
{
|
||||||
// If a draw item was picked, don't process additional items
|
// If a draw item was picked, don't process additional items
|
||||||
itemPicked = true;
|
itemPicked = true;
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,11 @@ public:
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem);
|
void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ bool GenericLayer::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& /* mouseGlobalPos */,
|
const QPointF& /* mouseGlobalPos */,
|
||||||
const glm::vec2& /* mousePos */,
|
const glm::vec2& /* mousePos */,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
// By default, the layer has nothing to pick
|
// By default, the layer has nothing to pick
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/map/map_context.hpp>
|
#include <scwx/qt/map/map_context.hpp>
|
||||||
|
#include <scwx/qt/types/event_types.hpp>
|
||||||
#include <scwx/common/geographic.hpp>
|
#include <scwx/common/geographic.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -38,15 +39,17 @@ public:
|
||||||
* @param [in] mouseGlobalPos Mouse cursor screen position
|
* @param [in] mouseGlobalPos Mouse cursor screen position
|
||||||
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
|
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
|
||||||
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
|
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
|
||||||
|
* @param [out] eventHandler Event handler associated with picked draw item
|
||||||
*
|
*
|
||||||
* @return true if a draw item was picked, otherwise false
|
* @return true if a draw item was picked, otherwise false
|
||||||
*/
|
*/
|
||||||
virtual bool
|
virtual bool
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords);
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void NeedsRendering();
|
void NeedsRendering();
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@ public:
|
||||||
|
|
||||||
// Initialize ImGui Qt backend
|
// Initialize ImGui Qt backend
|
||||||
ImGui_ImplQt_Init();
|
ImGui_ImplQt_Init();
|
||||||
ImGui_ImplQt_RegisterWidget(widget_);
|
|
||||||
|
|
||||||
// Set Map Provider Details
|
// Set Map Provider Details
|
||||||
mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue());
|
mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue());
|
||||||
|
|
@ -204,6 +203,8 @@ public:
|
||||||
const MapStyle* currentStyle_;
|
const MapStyle* currentStyle_;
|
||||||
std::string initialStyleName_ {};
|
std::string initialStyleName_ {};
|
||||||
|
|
||||||
|
std::shared_ptr<types::EventHandler> pickedEventHandler_ {nullptr};
|
||||||
|
|
||||||
uint64_t frameDraws_;
|
uint64_t frameDraws_;
|
||||||
|
|
||||||
double prevLatitude_;
|
double prevLatitude_;
|
||||||
|
|
@ -979,6 +980,17 @@ void MapWidgetImpl::AddLayer(const std::string& id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MapWidget::event(QEvent* e)
|
||||||
|
{
|
||||||
|
if (p->pickedEventHandler_ != nullptr &&
|
||||||
|
p->pickedEventHandler_->event_ != nullptr)
|
||||||
|
{
|
||||||
|
p->pickedEventHandler_->event_(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QOpenGLWidget::event(e);
|
||||||
|
}
|
||||||
|
|
||||||
void MapWidget::enterEvent(QEnterEvent* /* ev */)
|
void MapWidget::enterEvent(QEnterEvent* /* ev */)
|
||||||
{
|
{
|
||||||
p->hasMouse_ = true;
|
p->hasMouse_ = true;
|
||||||
|
|
@ -1083,6 +1095,7 @@ void MapWidget::initializeGL()
|
||||||
|
|
||||||
// Initialize ImGui OpenGL3 backend
|
// Initialize ImGui OpenGL3 backend
|
||||||
ImGui::SetCurrentContext(p->imGuiContext_);
|
ImGui::SetCurrentContext(p->imGuiContext_);
|
||||||
|
ImGui_ImplQt_RegisterWidget(this);
|
||||||
ImGui_ImplOpenGL3_Init();
|
ImGui_ImplOpenGL3_Init();
|
||||||
p->imGuiFontsBuildCount_ =
|
p->imGuiFontsBuildCount_ =
|
||||||
manager::FontManager::Instance().imgui_fonts_build_count();
|
manager::FontManager::Instance().imgui_fonts_build_count();
|
||||||
|
|
@ -1209,7 +1222,8 @@ void MapWidgetImpl::RunMousePicking()
|
||||||
util::maplibre::LatLongToScreenCoordinate(coordinate);
|
util::maplibre::LatLongToScreenCoordinate(coordinate);
|
||||||
|
|
||||||
// For each layer in reverse
|
// For each layer in reverse
|
||||||
bool itemPicked = false;
|
bool itemPicked = false;
|
||||||
|
std::shared_ptr<types::EventHandler> eventHandler = nullptr;
|
||||||
for (auto it = genericLayers_.rbegin(); it != genericLayers_.rend(); ++it)
|
for (auto it = genericLayers_.rbegin(); it != genericLayers_.rend(); ++it)
|
||||||
{
|
{
|
||||||
// Run mouse picking for each layer
|
// Run mouse picking for each layer
|
||||||
|
|
@ -1217,7 +1231,8 @@ void MapWidgetImpl::RunMousePicking()
|
||||||
lastPos_,
|
lastPos_,
|
||||||
lastGlobalPos_,
|
lastGlobalPos_,
|
||||||
mouseScreenCoordinate,
|
mouseScreenCoordinate,
|
||||||
{coordinate.first, coordinate.second}))
|
{coordinate.first, coordinate.second},
|
||||||
|
eventHandler))
|
||||||
{
|
{
|
||||||
// If a draw item was picked, don't process additional layers
|
// If a draw item was picked, don't process additional layers
|
||||||
itemPicked = true;
|
itemPicked = true;
|
||||||
|
|
@ -1229,6 +1244,43 @@ void MapWidgetImpl::RunMousePicking()
|
||||||
if (!itemPicked)
|
if (!itemPicked)
|
||||||
{
|
{
|
||||||
util::tooltip::Hide();
|
util::tooltip::Hide();
|
||||||
|
|
||||||
|
if (pickedEventHandler_ != nullptr)
|
||||||
|
{
|
||||||
|
// Send leave event to picked event handler
|
||||||
|
if (pickedEventHandler_->event_ != nullptr)
|
||||||
|
{
|
||||||
|
QEvent event(QEvent::Type::Leave);
|
||||||
|
pickedEventHandler_->event_(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset picked event handler
|
||||||
|
pickedEventHandler_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (eventHandler != nullptr)
|
||||||
|
{
|
||||||
|
// If the event handler changed
|
||||||
|
if (pickedEventHandler_ != eventHandler)
|
||||||
|
{
|
||||||
|
// Send leave event to old event handler
|
||||||
|
if (pickedEventHandler_ != nullptr &&
|
||||||
|
pickedEventHandler_->event_ != nullptr)
|
||||||
|
{
|
||||||
|
QEvent event(QEvent::Type::Leave);
|
||||||
|
pickedEventHandler_->event_(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send enter event to new event handler
|
||||||
|
if (eventHandler->event_ != nullptr)
|
||||||
|
{
|
||||||
|
QEvent event(QEvent::Type::Enter);
|
||||||
|
eventHandler->event_(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store picked event handler
|
||||||
|
pickedEventHandler_ = eventHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT widget_->MouseCoordinateChanged(
|
Q_EMIT widget_->MouseCoordinateChanged(
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ private:
|
||||||
qreal pixelRatio();
|
qreal pixelRatio();
|
||||||
|
|
||||||
// QWidget implementation.
|
// QWidget implementation.
|
||||||
|
bool event(QEvent* e) override;
|
||||||
void enterEvent(QEnterEvent* ev) override final;
|
void enterEvent(QEnterEvent* ev) override final;
|
||||||
void keyPressEvent(QKeyEvent* ev) override final;
|
void keyPressEvent(QKeyEvent* ev) override final;
|
||||||
void leaveEvent(QEvent* ev) override final;
|
void leaveEvent(QEvent* ev) override final;
|
||||||
|
|
|
||||||
|
|
@ -274,14 +274,25 @@ void OverlayLayer::Deinitialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OverlayLayer::RunMousePicking(
|
bool OverlayLayer::RunMousePicking(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& /* params */,
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& /* mouseGlobalPos */,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler)
|
||||||
{
|
{
|
||||||
// If sweep time was picked, don't process additional items
|
// If sweep time was picked, don't process additional items
|
||||||
return p->sweepTimePicked_;
|
if (p->sweepTimePicked_)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DrawLayer::RunMousePicking(params,
|
||||||
|
mouseLocalPos,
|
||||||
|
mouseGlobalPos,
|
||||||
|
mouseCoords,
|
||||||
|
mouseGeoCoords,
|
||||||
|
eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayLayer::UpdateSweepTimeNextFrame()
|
void OverlayLayer::UpdateSweepTimeNextFrame()
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,13 @@ public:
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
||||||
void Deinitialize() override final;
|
void Deinitialize() override final;
|
||||||
|
|
||||||
bool
|
bool RunMousePicking(
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords) override final;
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override final;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void UpdateSweepTimeNextFrame();
|
void UpdateSweepTimeNextFrame();
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,8 @@ bool RadarProductLayer::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& /* mouseCoords */,
|
||||||
const common::Coordinate& mouseGeoCoords)
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
bool itemPicked = false;
|
bool itemPicked = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ public:
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords) override;
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateColorTable();
|
void UpdateColorTable();
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,8 @@ bool RadarSiteLayer::RunMousePicking(
|
||||||
const QPointF& /* mouseLocalPos */,
|
const QPointF& /* mouseLocalPos */,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& /* mouseCoords */,
|
const glm::vec2& /* mouseCoords */,
|
||||||
const common::Coordinate& /* mouseGeoCoords */)
|
const common::Coordinate& /* mouseGeoCoords */,
|
||||||
|
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||||
{
|
{
|
||||||
if (!p->hoverText_.empty())
|
if (!p->hoverText_.empty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ public:
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
||||||
void Deinitialize() override final;
|
void Deinitialize() override final;
|
||||||
|
|
||||||
bool
|
bool RunMousePicking(
|
||||||
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const QPointF& mouseLocalPos,
|
const QPointF& mouseLocalPos,
|
||||||
const QPointF& mouseGlobalPos,
|
const QPointF& mouseGlobalPos,
|
||||||
const glm::vec2& mouseCoords,
|
const glm::vec2& mouseCoords,
|
||||||
const common::Coordinate& mouseGeoCoords) override final;
|
const common::Coordinate& mouseGeoCoords,
|
||||||
|
std::shared_ptr<types::EventHandler>& eventHandler) override final;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void RadarSiteSelected(const std::string& id);
|
void RadarSiteSelected(const std::string& id);
|
||||||
|
|
|
||||||
21
scwx-qt/source/scwx/qt/types/event_types.hpp
Normal file
21
scwx-qt/source/scwx/qt/types/event_types.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class QEvent;
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace qt
|
||||||
|
{
|
||||||
|
namespace types
|
||||||
|
{
|
||||||
|
|
||||||
|
struct EventHandler
|
||||||
|
{
|
||||||
|
std::function<void(QEvent*)> event_ {};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace types
|
||||||
|
} // namespace qt
|
||||||
|
} // namespace scwx
|
||||||
Loading…
Add table
Add a link
Reference in a new issue