-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstackpage.cpp
112 lines (103 loc) · 3.76 KB
/
stackpage.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
#include "stackpage.h"
StackPage::StackPage(QWidget* parent) : TabPage(parent)
{
this->setMouseTracking(true);
//this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QHBoxLayout* mainLayout = new QHBoxLayout;
mainLayout->setContentsMargins(0, 0, 0, 0);
this->setLayout(mainLayout);
QVBoxLayout* numLayout = new QVBoxLayout;
numLayout->setContentsMargins(0, 0, 0, 0);
QLabel* labNum = new QLabel;
QFont labFont("DengXian", 13);
labFont.setBold(true);
labNum->setText("Num Stack");
labNum->setFont(labFont);
labNum->setAlignment(Qt::AlignRight | Qt::AlignTop);
labNum->setStyleSheet("color:#E75E5E5E;");
labNum->setMaximumHeight(20);
numLayout->addWidget(labNum);
numStackScrollArea = new ScrollAreaCustom(this);
numLayout->addWidget(numStackScrollArea);
QVBoxLayout* opLayout = new QVBoxLayout;
opLayout->setContentsMargins(0, 0, 0, 0);
QLabel* labOp = new QLabel;
labFont.setBold(true);
labOp->setText("Op Stack");
labOp->setFont(labFont);
labOp->setAlignment(Qt::AlignRight | Qt::AlignTop);
labOp->setStyleSheet("color:#E75E5E5E;");
labOp->setMaximumHeight(20);
opLayout->addWidget(labOp);
opStackScrollArea = new ScrollAreaCustom(this);
opLayout->addWidget(opStackScrollArea);
mainLayout->addLayout(opLayout);
mainLayout->addLayout(numLayout);
//qDebug() << "StackPageWidth:[" << this->x() << "," << this->y() << "," << this->width() << "," << this->height() << "]\n";
}
void StackPage::RfrStack(const QString & numDif, const QString & opDif){
//qDebug() << "Rfr p1\n";
QString numDifCpy = numDif;
if(!numDif.isEmpty()){
QTextStream numStream(&numDifCpy);
if(numDif[0] == 'r'){
numStackScrollArea->clear();
numDifCpy.remove(0, 1);
}
while(!numStream.atEnd()){
char op;
numStream >> op;
if(op == 'o'){
numStackScrollArea->removeWidget();
}
else if(op == 'i'){
double num;
numStream >> num;
QLabel* newNum = new QLabel;
QFont font("DengXian", 20);
font.setBold(true);
newNum->setFont(font);
newNum->setAlignment(Qt::AlignRight);
newNum->resize(newNum->width(), 30);
newNum->setText(QString::asprintf("%g", num));
numStackScrollArea->addWidget(newNum);
}
}
}
QString opDifCpy = opDif;
opDifCpy.replace('*', "×").replace('/', "÷");
if(!opDif.isEmpty()){
QTextStream opStream(&opDifCpy);
if(opDif[0] == 'r'){
opStackScrollArea->clear();
opDifCpy.remove(0, 1);
}
while(!opStream.atEnd()){
//qDebug() << "opStream" << "\n";
char op;
opStream >> op;
//qDebug() << "op = " << op << "\n";
if(op == 'o'){
opStackScrollArea->removeWidget();
}
else if(op == 'i'){
char c;
opStream >> c;
//qDebug() << c << "\n";
QLabel* newChar = new QLabel;
QFont font("DengXian", 20);
font.setBold(false);
newChar->setFont(font);
newChar->setAlignment(Qt::AlignRight);
newChar->resize(newChar->width(), 30);
newChar->setText(QString::asprintf("%c%s", c, c == '(' ? " " : ""));
opStackScrollArea->addWidget(newChar);
}
}
}
}
void StackPage::paintEvent(QPaintEvent *event){
//newScrollArea->setMinimumWidth(this->width());
//newScrollArea->setMinimumHeight(this->height());
//newScrollArea->resize(this->size());
}