-
Notifications
You must be signed in to change notification settings - Fork 2
/
headergraphicsitem.cpp
82 lines (65 loc) · 3.23 KB
/
headergraphicsitem.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "headergraphicsitem.h"
#include <QBrush>
#include <QPainter>
#include <QApplication>
#include <QDesktopWidget>
#include <QStyleOptionGraphicsItem>
#include "defines.h"
namespace DJ {
namespace View {
HeaderGraphicsItem::HeaderGraphicsItem(double screenWidth, QGraphicsItem *parent)
: QObject(), QGraphicsItem(parent){
this->screenWidth = screenWidth;
QFont font("Courier new");
font.setPixelSize(16);
font.setItalic(true);
QFontMetrics fm(font);
this->setCacheMode(DeviceCoordinateCache);
this->rankTextItem = new QGraphicsSimpleTextItem("Rank", this);
this->rankTextItem->setPos(LEFT_MARGIN, HEADER_HEIGHT - fm.height());
this->rankTextItem->setPen(QPen(Qt::white));
this->rankTextItem->setBrush(QBrush(Qt::white));
this->rankTextItem->setFont(font);
this->nameTextItem = new QGraphicsSimpleTextItem("Name", this);
this->nameTextItem->setPos(LEFT_MARGIN + RANK_WIDTH, HEADER_HEIGHT - fm.height());
this->nameTextItem->setPen(QPen(Qt::white));
this->nameTextItem->setBrush(QBrush(Qt::white));
this->nameTextItem->setFont(font);
this->timeTextItem = new QGraphicsSimpleTextItem("Time", this);
this->timeTextItem->setPos(QApplication::desktop()->screenGeometry().width() - RIGHT_MARGIN - fm.width("Time"), HEADER_HEIGHT - fm.height());
this->timeTextItem->setPen(QPen(Qt::white));
this->timeTextItem->setBrush(QBrush(Qt::white));
this->timeTextItem->setFont(font);
this->solvedTextItem = new QGraphicsSimpleTextItem("Solved", this);
this->solvedTextItem->setPos(QApplication::desktop()->screenGeometry().width() - RIGHT_MARGIN - TIME_WIDTH - fm.width("Solved"), HEADER_HEIGHT - fm.height());
this->solvedTextItem->setPen(QPen(Qt::white));
this->solvedTextItem->setBrush(QBrush(Qt::white));
this->solvedTextItem->setFont(font);
}
QRectF HeaderGraphicsItem::boundingRect() const {
return QRectF(0, 0, screenWidth, HEADER_HEIGHT);
}
void HeaderGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) {
painter->setClipRect(option->exposedRect);
QFont font("Courier new");
font.setPixelSize(16);
font.setItalic(true);
QFontMetrics fm(font);
this->rankTextItem->setPos(LEFT_MARGIN, HEADER_HEIGHT - fm.height());
this->nameTextItem->setPos(LEFT_MARGIN + RANK_WIDTH, HEADER_HEIGHT - fm.height());
this->timeTextItem->setPos(QApplication::desktop()->screenGeometry().width() - RIGHT_MARGIN - fm.width("Time"), HEADER_HEIGHT - fm.height());
this->solvedTextItem->setPos(QApplication::desktop()->screenGeometry().width() - RIGHT_MARGIN - TIME_WIDTH - fm.width("Solved"), HEADER_HEIGHT - fm.height());
QLinearGradient gradient(0, 0, screenWidth, 0);
gradient.setColorAt(0, QColor(0, 0, 0));
gradient.setColorAt(0.5, QColor(56, 56, 56));
gradient.setColorAt(1, QColor(0, 0, 0));
QBrush brush(gradient);
brush.setStyle(Qt::LinearGradientPattern);
painter->setBrush(brush);
painter->setPen(Qt::NoPen);
painter->drawRect(0, 0, screenWidth, HEADER_HEIGHT);
painter->setPen(Qt::white);
painter->drawLine(0, HEADER_HEIGHT-1, screenWidth, HEADER_HEIGHT-1);
}
} // namespace View
} // namespace DJ