Added "Mouse Position"-Label to Emulator.
This commit is contained in:
@@ -34,6 +34,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), image(DISPLAY_WID
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
image.fill(Qt::black);
|
image.fill(Qt::black);
|
||||||
currentScale = 1;
|
currentScale = 1;
|
||||||
|
ui->widgetDisplay->setMouseTracking(true);
|
||||||
|
ui->widgetDisplay->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||||
@@ -159,7 +161,28 @@ void MainWindow::mouseMoveEvent(QMouseEvent *evt)
|
|||||||
{
|
{
|
||||||
//qDebug() << "move" << evt->pos();
|
//qDebug() << "move" << evt->pos();
|
||||||
checkAndSendEvent(evt->pos(),true);
|
checkAndSendEvent(evt->pos(),true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject *obj, QEvent *evt)
|
||||||
|
{
|
||||||
|
if(obj==ui->widgetDisplay) {
|
||||||
|
switch(evt->type()) {
|
||||||
|
case QEvent::MouseMove:
|
||||||
|
{
|
||||||
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(evt);
|
||||||
|
QPoint p = (mouseEvent->pos()-QPoint(1,1))/currentScale;
|
||||||
|
if(p.x()<DISPLAY_WIDTH && p.y()<DISPLAY_HEIGHT) {
|
||||||
|
ui->txtMousePos->setText(QString("Mouse Position: (%1,%2)").arg(p.x()).arg(p.y()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
void draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c);
|
void draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool eventFilter(QObject * obj , QEvent * env);
|
||||||
void paintEvent(QPaintEvent * evt);
|
void paintEvent(QPaintEvent * evt);
|
||||||
void mousePressEvent(QMouseEvent* evt);
|
void mousePressEvent(QMouseEvent* evt);
|
||||||
void mouseReleaseEvent(QMouseEvent* evt);
|
void mouseReleaseEvent(QMouseEvent* evt);
|
||||||
|
|||||||
@@ -43,6 +43,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="txtMousePos">
|
||||||
|
<property name="text">
|
||||||
|
<string>Mouse Position: out of bounds</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
Reference in New Issue
Block a user