-
Notifications
You must be signed in to change notification settings - Fork 9
/
optiondialog.cpp
156 lines (132 loc) · 4.45 KB
/
optiondialog.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "optiondialog.h"
#include "ui_optiondialog.h"
OptionDialog::OptionDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::OptionDialog)
{
ui->setupUi(this);
this->materials = new QList<Material*>;
}
OptionDialog::~OptionDialog()
{
delete ui;
}
void OptionDialog::on_closeBtn_clicked()
{
emit newSize(QVector3D(ui->sizeX->value(),ui->sizeY->value(),ui->sizeZ->value()));
this->hide();
}
void OptionDialog::setSlicerDir(QString dir){
ui->slicerDir->setText(dir);
}
QString OptionDialog::getSlicerDir(){
return ui->slicerDir->text();
}
void OptionDialog::setConfigDir(QString dir){
ui->configDir->setText(dir);
}
QString OptionDialog::getConfigDir(){
return ui->configDir->text();
}
void OptionDialog::setOutputDir(QString dir){
ui->outputDir->setText(dir);
}
QString OptionDialog::getOutputDir(){
return ui->outputDir->text();
}
QVector3D OptionDialog::getSize(){
return QVector3D(ui->sizeX->value(),ui->sizeY->value(),ui->sizeZ->value());
}
void OptionDialog::setSize(QVector3D size){
ui->sizeX->setValue(size.x());
ui->sizeY->setValue(size.y());
ui->sizeZ->setValue(size.z());
}
void OptionDialog::on_slicerDirBtn_clicked()
{
QString fileName;
#if defined(Q_WS_MAC)
fileName = QFileDialog::getOpenFileName(this, tr("Find slicer"), ui->slicerDir->text(), tr("Slic3r.app (slic3r*)"));
#else
fileName = QFileDialog::getOpenFileName(this, tr("Find slicer"), ui->slicerDir->text(), tr("Slic3r-console (slic3r-console*)"));
#endif
ui->slicerDir->setText(fileName);
emit slicerPathChanged(fileName);
}
void OptionDialog::on_configDirBtn_clicked()
{
QString dirName = QFileDialog::getExistingDirectory(this,"Choose configs dir", ui->slicerDir->text());
ui->configDir->setText(dirName);
}
void OptionDialog::on_outputDirBtn_clicked()
{
QString dirName = QFileDialog::getExistingDirectory(this,"Choose output dir", ui->slicerDir->text());
ui->outputDir->setText(dirName);
emit outputPathChanged(dirName);
}
void OptionDialog::on_extruderNum_valueChanged(int arg1)
{
if(arg1>ui->tableWidget->rowCount()){
addExtruder(qMakePair(arg1-1,QString("#ff0000")));
}
else{
ui->tableWidget->setRowCount(arg1);
this->materials->takeLast();
emit newList(this->materials);
}
}
QList< QPair<int, QString > > OptionDialog::getExtruders(){
QList< QPair<int, QString > > out;
QLabel* label;
for(int i=0; i<ui->tableWidget->rowCount(); i++){
label = (QLabel*)ui->tableWidget->cellWidget(i,1);
out.append(qMakePair(i,label->text()));
}
return out;
}
void OptionDialog::addExtruder(QPair<int, QString> extruder){
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
QLabel* label = new QLabel();
QLabel* label2 = new QLabel();
label2->setText("T"+QString::number(extruder.first));
QColor color(extruder.second);
label->setStyleSheet("background-color: rgb("+QString::number(color.red())+","+QString::number(color.green())+","+QString::number(color.blue())+");");
label->setText(extruder.second);
ui->tableWidget->setCellWidget(ui->tableWidget->rowCount()-1,0,label2);
ui->tableWidget->setCellWidget(ui->tableWidget->rowCount()-1,1,label);
ui->extruderNum->blockSignals(true);
ui->extruderNum->setValue(ui->tableWidget->rowCount());
ui->extruderNum->blockSignals(false);
emit newList(this->materials);
this->materials->append(new Material(color,extruder.first));
}
void OptionDialog::on_tableWidget_cellDoubleClicked(int row, int column)
{
qDebug() << row << column;
if(column==1){
QLabel* label = (QLabel*)ui->tableWidget->cellWidget(row,column);
QColor color=QColorDialog::getColor(QColor(label->text()),this);
qDebug() << color;
label->setText(color.name());
label->setStyleSheet("background-color: rgb("+QString::number(color.red())+","+QString::number(color.green())+","+QString::number(color.blue())+");");
this->materials->at(row)->changeColor(color);
}
}
void OptionDialog::on_changeFontBtn_clicked()
{
bool ok;
QFont font=QFontDialog::getFont(&ok,this);
if(ok){
QApplication::setFont(font);
ui->currentFontLbl->setText(font.toString());
this->currentFont=font;
}
}
void OptionDialog::setCurrentFont(QString font){
qDebug() << font;
QFont newFont;
newFont.fromString(font);
this->currentFont=font;
ui->currentFontLbl->setText(font);
QApplication::setFont(newFont);
}