-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchesstipswidget.cpp
More file actions
58 lines (52 loc) · 1.66 KB
/
chesstipswidget.cpp
File metadata and controls
58 lines (52 loc) · 1.66 KB
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
#include "chesstipswidget.h"
#include "chesslog.h"
#include <QLabel>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QDateTime>
ChessTipsWidget * ChessTipsWidget::INSTANCE = 0;
ChessTipsWidget * ChessTipsWidget::instance()
{
if(!INSTANCE)
{
INSTANCE = new ChessTipsWidget;
}
return INSTANCE;
}
ChessTipsWidget::ChessTipsWidget(QWidget *parent) :
QWidget(parent)
{
// 系统信息
titleLabel = new QLabel(QString::fromUtf8("\xe7\xb3\xbb\xe7\xbb\x9f\xe4\xbf\xa1\xe6\x81\xaf"));
tipsTextEdit = new QTextEdit;
tipsTextEdit->setReadOnly(true);
tipsTextEdit->document()->setMaximumBlockCount(500);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(titleLabel);
layout->addWidget(tipsTextEdit);
setLayout(layout);
Chess_Trace(tr("new ChessTipsWidget"));
}
ChessTipsWidget::~ChessTipsWidget()
{
Chess_Trace(tr("delete ChessTipsWidget"));
}
void ChessTipsWidget::addTips(const QString &message, TipsLevel level)
{
QString msg = message.trimmed();
if(msg.isEmpty()) return;
QString color;
switch(level)
{
case(NormalLevel): color = QLatin1String("black"); break;
case(ImportantLevel): color = QLatin1String("blue"); break;
case(SeriousLevel): color = QLatin1String("red"); break;
default: color = QLatin1String("yellow"); break;
}
QString currentTime = QDateTime::currentDateTime()
.toString(QLatin1String("HH:mm:ss"));
tipsTextEdit->append(QString("<font color='%1'>%2 %3</font>")
.arg(color)
.arg(currentTime)
.arg(msg));
}