-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordListWidget.cpp
More file actions
59 lines (48 loc) · 1.41 KB
/
Copy pathWordListWidget.cpp
File metadata and controls
59 lines (48 loc) · 1.41 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
#include "WordListWidget.h"
#include "WordTable.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QTableView>
#include <QtDebug>
WordListWidget::WordListWidget(QWidget *parent, QString label) : QWidget(parent)
{
score = 0;
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *headLayout = new QHBoxLayout();
QLabel *nameLabel = new QLabel(this);
scoreLabel = new QLabel(this);
QFont font = nameLabel->font();
font.setPointSize(20);
nameLabel->setFont(font);
scoreLabel->setFont(font);
nameLabel->setText(label);
scoreLabel->setText(QString::number(score));
headLayout->addWidget(nameLabel, 0, Qt::AlignmentFlag::AlignLeft);
headLayout->addWidget(scoreLabel, 0, Qt::AlignmentFlag::AlignRight);
layout->addLayout(headLayout);
QFrame *hline = new QFrame();
hline->setFrameShape(QFrame::HLine);
hline->setFrameShadow(QFrame::Sunken);
layout->addWidget(hline);
wordTable = new WordTable();
layout->addWidget(wordTable);
reset();
setLayout(layout);
}
void WordListWidget::addScore(int s)
{
this->score += s;
this->scoreLabel->setText(QString::number(score));
}
void WordListWidget::addWord(QString word)
{
this->words.append(word);
this->wordTable->addWord(word);
}
void WordListWidget::reset()
{
this->score = 0;
this->scoreLabel->setText(QString::number(score));
this->words.clear();
this->wordTable->reset();
}