-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
106 lines (82 loc) · 3.33 KB
/
mainwindow.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "utils.h"
#include "characterdata.h"
#include <QDebug>
#include <set>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
_subDataController.SetMainWindow(this);
_docController.SetMainWindow(this);
connect(this, &MainWindow::OnFileNameReceived, &_subDataController, &CSubController::ExtractDataFromFile);
connect(this, &MainWindow::OnExportRequired, &_docController, &CDocController::ConvertSubDataToDoc);
}
MainWindow::~MainWindow()
{
disconnect(this, &MainWindow::OnFileNameReceived, &_subDataController, &CSubController::ExtractDataFromFile);
disconnect(this, &MainWindow::OnExportRequired, &_docController, &CDocController::ConvertSubDataToDoc);
delete ui;
}
CCharacterData *MainWindow::GetCharacter(QString name)
{
std::pair<std::set<CCharacterData>::iterator, bool> result = _characters.insert(CCharacterData(name));
return const_cast<CCharacterData *>(&(*result.first));
}
void MainWindow::UpdateTable()
{
ui->NamesTable->setColumnCount(3);
ui->NamesTable->setShowGrid(true);
ui->NamesTable->setHorizontalHeaderLabels(QStringList({"№", "Имя", "Гендер"}));
ui->NamesTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
QHeaderView* header = ui->NamesTable->horizontalHeader();
header->setSectionResizeMode(QHeaderView::Stretch);
quint8 row = 0;
for(auto& character : _characters)
{
qDebug() << "character._name " << character._name << Qt::endl;
ui->NamesTable->insertRow(row);
ui->NamesTable->setItem(row, 0, new QTableWidgetItem(QString::number(row)));
ui->NamesTable->setItem(row, 1, new QTableWidgetItem(character._name));
ui->NamesTable->setItem(row, 2, new QTableWidgetItem(character._gender == Gender::male ? "m" : "f"));
++row;
}
// Ресайзим колонки по содержимому
ui->NamesTable->resizeColumnsToContents();
}
void MainWindow::OnBrowseClicked()
{
const QString fileName = Utils::GetFileName(ui->BrowseLine->text());
if (!fileName.size())
return;
ui->BrowseLine->setText(fileName);
SubPauseInfo info(
ui->EnablePause->isChecked(),
ui->SmallPauseStart->text().toInt(),
ui->SmallPauseEnd->text().toInt(),
ui->BigPauseStart->text().toInt());
emit OnFileNameReceived(fileName, info);
}
void MainWindow::OnExportToDocClicked()
{
QString fileName = Utils::GetSaveFileName(ui->ExportToDocLine->text());
if (!fileName.size())
return;
ui->ExportToDocLine->setText(fileName);
FemaleLinesStyle style(
ui->FemaleLineBold->isChecked(),
ui->FemaleLineUnderLine->isChecked(),
ui->FemaleLineItalic->isChecked());
emit OnExportRequired(fileName, ui->DocNameLine->text(), _subDataController.GetSubData(), style, ui->TextUnderline->isChecked());
}
void MainWindow::OnNamesTableCellClicked(int row, int column)
{
if (column != 2)
return;
std::set<CCharacterData>::iterator it = _characters.begin();
std::advance(it, row);
it->_gender = (*it)._gender == Gender::male ? Gender::female : Gender::male;
ui->NamesTable->setItem(row, 2, new QTableWidgetItem(it->_gender == Gender::male ? "m" : "f"));
}