forked from Haroooold/motaGroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsgboard.cpp
47 lines (38 loc) · 1.02 KB
/
Msgboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* File: Msgboard.cpp
* ------------------
* This file implements Msgboard.h interface.
*/
#include "Msgboard.h"
#include "Game.h"
#include <unistd.h>
#include <QDebug>
#include <QTimer>
extern Game* game;
MsgBoard::MsgBoard(QString name, int x, int y, int width, int height, QGraphicsItem* parent): QGraphicsRectItem (parent)
{
// draw the message board
setRect(x, y, width, height);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::darkCyan);
setBrush(brush);
// TO DO: set focus to avoid mis-operate?
// draw the text
text = new QGraphicsTextItem(name, this);
text->setPos(150,150);
QTimer::singleShot(400, this, SLOT(deleteAndFocusBack())); // remove after 400
}
/*
* Implementation notes: deleteAndFocusBack()
* ------------------------------------------
* Delete message box and focus back to hero.
*/
void MsgBoard::deleteAndFocusBack()
{
// delete
game->scene->removeItem(this);
delete this;
// focus back
game->hero->setFocusToSelf();
}