添加了mouseIn/mouseOut/mouseHover三种信号
This commit is contained in:
parent
7edb3aba43
commit
2ef64272f7
|
|
@ -1,17 +1,27 @@
|
||||||
#include "ActWorld.h"
|
#include "ActWorld.h"
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <MapPresent.h>
|
#include <MapPresent.h>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
//ActWorld window;
|
//ActWorld window;
|
||||||
//window.show();
|
//window.show();
|
||||||
|
|
||||||
MapPresent p;
|
MapPresent p;
|
||||||
p.show();
|
p.show();
|
||||||
|
|
||||||
|
//QObject::connect(&p, &MapPresent::mouseIn, [=]() {
|
||||||
|
// qDebug() << "Mouse Enter";
|
||||||
|
// });
|
||||||
|
//QObject::connect(&p, &MapPresent::mouseOut, [=]() {
|
||||||
|
// qDebug() << "Mouse Leave";
|
||||||
|
// });
|
||||||
|
//QObject::connect(&p, &MapPresent::mouseHover, [=](const PresentIndex &i) {
|
||||||
|
// qDebug() << "Mouse Hover" << i.row << i.col;
|
||||||
|
// });
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,18 @@
|
||||||
#include <QVector2D>
|
#include <QVector2D>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
#include <QEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
|
||||||
MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
||||||
:QWidget(parent)
|
:QWidget(parent)
|
||||||
{
|
{
|
||||||
_center_index.row = 0;
|
_center_index.row = 0;
|
||||||
_center_index.col = 0;
|
_center_index.col = 0;
|
||||||
|
|
||||||
|
this->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
||||||
|
|
@ -93,6 +98,31 @@ void MapPresent::resizeEvent(QResizeEvent* event)
|
||||||
visibleUnitsTidy();
|
visibleUnitsTidy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapPresent::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
QWidget::mouseMoveEvent(event);
|
||||||
|
event->accept();
|
||||||
|
|
||||||
|
auto index = indexGet(event->pos());
|
||||||
|
emit mouseHover(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPresent::enterEvent(QEvent* event)
|
||||||
|
{
|
||||||
|
QWidget::enterEvent(event);
|
||||||
|
event->accept();
|
||||||
|
|
||||||
|
emit mouseIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPresent::leaveEvent(QEvent* event)
|
||||||
|
{
|
||||||
|
QWidget::leaveEvent(event);
|
||||||
|
event->accept();
|
||||||
|
|
||||||
|
emit mouseOut();
|
||||||
|
}
|
||||||
|
|
||||||
PresentOption AssumeOpt(PresentIndex index, QRectF rf) {
|
PresentOption AssumeOpt(PresentIndex index, QRectF rf) {
|
||||||
PresentOption opt;
|
PresentOption opt;
|
||||||
opt.index = index;
|
opt.index = index;
|
||||||
|
|
|
||||||
|
|
@ -104,12 +104,16 @@ public:
|
||||||
QRectF outlineGet(const PresentIndex& idx) const;
|
QRectF outlineGet(const PresentIndex& idx) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mouseEnter();
|
void mouseIn();
|
||||||
void mouseOut();
|
void mouseOut();
|
||||||
void mouseHover();
|
void mouseHover(const PresentIndex &unit_index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* ev) override;
|
void paintEvent(QPaintEvent* ev) override;
|
||||||
void resizeEvent(QResizeEvent* event) override;
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
void enterEvent(QEvent* event) override;
|
||||||
|
void leaveEvent(QEvent* event) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue