board: fix: place tile no longer drawn when mouse is outside board
Dieser Commit ist enthalten in:
Ursprung
848b942610
Commit
3648b7d084
@ -139,6 +139,15 @@ TileLocation BoardAreaWidget::pointToTileLocation(const QPoint& p)
|
|||||||
return TileLocation{static_cast<int16_t>(p.x() / pxPerTile), static_cast<int16_t>(p.y() / pxPerTile)};
|
return TileLocation{static_cast<int16_t>(p.x() / pxPerTile), static_cast<int16_t>(p.y() / pxPerTile)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoardAreaWidget::leaveEvent(QEvent* event)
|
||||||
|
{
|
||||||
|
m_mouseMoveTileLocation = TileLocation::invalid;
|
||||||
|
emit mouseTileLocationChanged(m_mouseMoveTileLocation.x, m_mouseMoveTileLocation.y);
|
||||||
|
if(m_mouseMoveTileId != TileId::None)
|
||||||
|
update();
|
||||||
|
QWidget::leaveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void BoardAreaWidget::keyPressEvent(QKeyEvent* event)
|
void BoardAreaWidget::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
if(event->key() == Qt::Key_G && event->modifiers() == Qt::ControlModifier)
|
if(event->key() == Qt::Key_G && event->modifiers() == Qt::ControlModifier)
|
||||||
@ -313,7 +322,7 @@ void BoardAreaWidget::paintEvent(QPaintEvent* event)
|
|||||||
|
|
||||||
painter.restore();
|
painter.restore();
|
||||||
|
|
||||||
if(m_mouseMoveTileId != TileId::None)
|
if(m_mouseMoveTileId != TileId::None && m_mouseMoveTileLocation.isValid())
|
||||||
{
|
{
|
||||||
const QRectF r = tileRect(m_mouseMoveTileLocation, 1, 1, tileSize);
|
const QRectF r = tileRect(m_mouseMoveTileLocation, 1, 1, tileSize);
|
||||||
painter.fillRect(r, backgroundColor50);
|
painter.fillRect(r, backgroundColor50);
|
||||||
|
|||||||
@ -63,6 +63,7 @@ class BoardAreaWidget : public QWidget
|
|||||||
SignalAspect getSignalAspect(const TileLocation& l) const;
|
SignalAspect getSignalAspect(const TileLocation& l) const;
|
||||||
TileLocation pointToTileLocation(const QPoint& p);
|
TileLocation pointToTileLocation(const QPoint& p);
|
||||||
|
|
||||||
|
void leaveEvent(QEvent *event) final;
|
||||||
void keyPressEvent(QKeyEvent* event) final;
|
void keyPressEvent(QKeyEvent* event) final;
|
||||||
void mousePressEvent(QMouseEvent* event) final;
|
void mousePressEvent(QMouseEvent* event) final;
|
||||||
void mouseReleaseEvent(QMouseEvent* event) final;
|
void mouseReleaseEvent(QMouseEvent* event) final;
|
||||||
|
|||||||
@ -262,7 +262,10 @@ BoardWidget::BoardWidget(std::shared_ptr<Board> object, QWidget* parent) :
|
|||||||
connect(m_boardArea, &BoardAreaWidget::mouseTileLocationChanged, this,
|
connect(m_boardArea, &BoardAreaWidget::mouseTileLocationChanged, this,
|
||||||
[this](int16_t x, int16_t y)
|
[this](int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
m_statusBarCoords->setText(QString::number(x) + ", " + QString::number(y));
|
if(TileLocation{x, y}.isValid())
|
||||||
|
m_statusBarCoords->setText(QString::number(x) + ", " + QString::number(y));
|
||||||
|
else
|
||||||
|
m_statusBarCoords->setText("");
|
||||||
});
|
});
|
||||||
|
|
||||||
gridChanged(m_boardArea->grid());
|
gridChanged(m_boardArea->grid());
|
||||||
|
|||||||
@ -24,12 +24,20 @@
|
|||||||
#define TRAINTASTIC_SHARED_TRAINTASTIC_BOARD_TILELOCATION_HPP
|
#define TRAINTASTIC_SHARED_TRAINTASTIC_BOARD_TILELOCATION_HPP
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
struct TileLocation
|
struct TileLocation
|
||||||
{
|
{
|
||||||
|
static const TileLocation invalid;
|
||||||
|
|
||||||
int16_t x;
|
int16_t x;
|
||||||
int16_t y;
|
int16_t y;
|
||||||
|
|
||||||
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return *this != invalid;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator ==(const TileLocation& other) const
|
bool operator ==(const TileLocation& other) const
|
||||||
{
|
{
|
||||||
return x == other.x && y == other.y;
|
return x == other.x && y == other.y;
|
||||||
@ -41,6 +49,8 @@ struct TileLocation
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const TileLocation TileLocation::invalid{std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::min()};
|
||||||
|
|
||||||
struct TileLocationHash
|
struct TileLocationHash
|
||||||
{
|
{
|
||||||
std::size_t operator()(const TileLocation& key) const
|
std::size_t operator()(const TileLocation& key) const
|
||||||
|
|||||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren