Skip to content

Commit ff442e0

Browse files
committed
update tools
1 parent 66b43b2 commit ff442e0

File tree

8 files changed

+401
-709
lines changed

8 files changed

+401
-709
lines changed

tools/CMakeLists.txt.user

Lines changed: 0 additions & 412 deletions
This file was deleted.

tools/codes/Terminal.cpp

Lines changed: 259 additions & 239 deletions
Large diffs are not rendered by default.

tools/codes/Terminal.h

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,12 @@ class Terminal;
1212
}
1313
QT_END_NAMESPACE
1414

15-
class MyEventFilter : public QObject
16-
{
17-
Q_OBJECT
18-
19-
protected:
20-
bool eventFilter(QObject *obj, QEvent *event) override
21-
{
22-
//qDebug() << "MyEventFilter::eventFilter";
23-
if (event->type() == QEvent::KeyPress)
24-
{
25-
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
26-
if (keyEvent->key() == Qt::Key_Return)
27-
{
28-
qDebug() << "MyEventFilter Enter key pressed!";
29-
// 执行回车键按下后的操作
30-
return true;
31-
}
32-
}
15+
class QProcess;
16+
class QTextEdit;
3317

34-
return QObject::eventFilter(obj, event);
35-
}
36-
};
18+
class QTextEdit;
3719

20+
extern QTextEdit *textEdit;
3821

3922
class Terminal : public QWidget
4023
{
@@ -46,29 +29,32 @@ class Terminal : public QWidget
4629
void resizeEvent(QResizeEvent *event) override;
4730
signals:
4831
private:
49-
void ReadOutput();
50-
void ReadStandardOutput();
51-
void FinishedProcess();
52-
void ErrorProcess();
32+
Ui::Terminal *ui;
33+
QProcess * procCmd = nullptr;
34+
private:
5335
void OnReturnKeyPressed();
54-
void OnStateChanged();
5536
void OnKeyBackPressed();
37+
void OnKeyUpPressed();
5638
void ProcessTabKey();
39+
40+
void Analysis( const QString & cmdString );
5741
QString GetCommandString();
5842
void CommandCompletion( const QString &str );
59-
private:
6043
QString FindCommonString(const QString &stra, const QString &strb);
6144
QString FindCommonString(const QStringList &strlist);
6245
bool InStringList(QChar a, int ipos, const QStringList &strlist);
6346
private:
64-
void Analysis( QString & cmdString );
65-
private:
66-
Ui::Terminal *ui;
67-
QProcess * procCmd = nullptr;
68-
QString currentPath;
47+
QString cmdStr;
6948
QString lastCommand;
70-
QStringList wordList;
49+
QStringList historyCmdList;
7150
int word_index=0;
51+
private:
52+
void OnStarted();
53+
void ReadOutput();
54+
void ReadStandardOutput();
55+
void FinishedProcess();
56+
void ErrorProcess();
57+
void OnStateChanged();
7258
};
7359

7460
#endif // TERMINAL_H

tools/codes/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ int main(int argc, char *argv[])
66
QApplication a(argc, argv);
77
MainWindow w;
88
w.setWindowTitle( "ModernCFD" );
9-
w.show();
9+
//w.show();
10+
w.showMaximized();
1011
return a.exec();
1112
}

tools/codes/mainwindow.cpp

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <QFileDialog>
44
#include <QProcess>
55
#include <QKeyEvent>
6-
#include <thread>
6+
#include <QSplitter>
7+
#include <QTextEdit>
78
#include <iostream>
89
#include "CfdThread.h"
910
#include "Terminal.h"
@@ -30,19 +31,45 @@ MainWindow::MainWindow(QWidget *parent)
3031
QObject::connect( this->actTerminal, &QAction::triggered, this, &MainWindow::runTerminal);
3132
this->cfdThread = new CfdThread();
3233
//this->terminal = new Terminal(this);
33-
this->terminal = new Terminal();
34-
//this->terminal->setWindowTitle("Terminal");
35-
//this->terminal->setGeometry( QRect(10, 50, 600, 400) );
36-
this->terminal->show();
37-
//this->terminal->setFocus();
34+
this->terminal = new Terminal(this);
35+
36+
//this->ui->statusbar->setStyleSheet("background-color: rgb(0, 255, 0);");
37+
this->ui->statusbar->setStyleSheet("background-color: rgb(0, 122, 204);");
3838
qDebug() << "MainWindow::MainWindow";
39+
40+
this->splitterH = new QSplitter(Qt::Horizontal, this);
41+
this->splitterH->setGeometry( QRect(0, 25, this->width(), this->height()) );
42+
int myWidth = this->width();
43+
double ratioL = 1.0/5.0;
44+
double ratioR = 1 - ratioL;
45+
int leftWidth = myWidth * ratioL;
46+
int rightWidth = myWidth * ratioR;
47+
QList<int> list;
48+
list.append(leftWidth);
49+
list.append(rightWidth);
50+
this->splitterH->setSizes(list);
51+
qDebug() << "list="<<list;
52+
this->splitterH->setStretchFactor(0, 1);
53+
this->splitterH->setStretchFactor(1, 4);
54+
55+
QTextEdit* pLeftEdt = new QTextEdit();
56+
pLeftEdt->setText(QObject::tr("LeftWindow1"));
57+
58+
this->splitterV = new QSplitter(Qt::Vertical, this->splitterH);
59+
60+
QTextEdit* pRightTopEdt = new QTextEdit(this->splitterV);
61+
pRightTopEdt->setText(QObject::tr("Right Top Window"));
62+
this->splitterV->addWidget(this->terminal);
63+
64+
this->splitterH->addWidget(pLeftEdt);
65+
this->splitterH->addWidget(this->splitterV);
66+
3967
}
4068

4169
MainWindow::~MainWindow()
4270
{
4371
delete ui;
4472
delete this->cfdThread;
45-
delete this->terminalProcess;
4673
}
4774

4875
void MainWindow::closeEvent( QCloseEvent * ev )
@@ -76,9 +103,36 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
76103
qDebug() << "MainWindow::keyPressEvent";
77104
}
78105

106+
void MainWindow::resizeEvent(QResizeEvent *event)
107+
{
108+
qDebug() << "MainWindow::resizeEvent event->size() = " << event->size();
109+
qDebug() << "MainWindow::resizeEvent this->ui->statusbar->size()=" << this->ui->statusbar->size();
110+
qDebug() << "MainWindow::resizeEvent this->ui->statusbar->pos()=" << this->ui->statusbar->pos();
111+
int ypos = this->ui->statusbar->pos().y();
112+
int width = event->size().width()-500;
113+
int height = ypos - 700;
114+
115+
116+
int splitterTop = 25;
117+
int splitterHeight = ypos - splitterTop;
118+
119+
this->splitterH->setGeometry( QRect(0, splitterTop, this->width(), splitterHeight) );
120+
qDebug() << "ypos=" << ypos;
121+
this->splitterH->setStretchFactor(0, 1);
122+
this->splitterH->setStretchFactor(1, 4);
123+
this->splitterH->setHandleWidth(0);
124+
}
125+
79126
void MainWindow::triggerNew()
80127
{
81-
QFileDialog::getOpenFileName(this,"haha",".","*.txt");
128+
//QFileDialog::getOpenFileName(this,"haha",".","*.txt");
129+
int width = this->size().width();
130+
int height = this->size().height();
131+
qDebug() << "MainWindow::triggerNew() this->size()=" << this->size();
132+
this->ui->statusbar->showMessage("hello",5000);
133+
qDebug() << "MainWindow::triggerNew() this->ui->statusbar->size()=" << this->ui->statusbar->size();
134+
qDebug() << "MainWindow::triggerNew() this->ui->statusbar->pos()=" << this->ui->statusbar->pos();
135+
82136
}
83137

84138
void MainWindow::runCFD()
@@ -113,10 +167,6 @@ void MainWindow::runMPI()
113167

114168
void MainWindow::runTerminal()
115169
{
116-
if ( !terminalProcess )
117-
{
118-
this->terminalProcess = new QProcess( this );
119-
}
120170
}
121171

122172

tools/codes/mainwindow.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class QAction;
88
class CfdThread;
99
class QProcess;
1010
class Terminal;
11+
class QSplitter;
1112

1213
QT_BEGIN_NAMESPACE
1314
namespace Ui {
@@ -28,6 +29,7 @@ class MainWindow : public QMainWindow
2829
protected:
2930
bool eventFilter(QObject *obj, QEvent *event) override;
3031
void keyPressEvent(QKeyEvent *event) override;
32+
void resizeEvent(QResizeEvent *event) override;
3133
private:
3234
void triggerNew();
3335
void runCFD();
@@ -42,7 +44,11 @@ class MainWindow : public QMainWindow
4244
QAction * actTerminal;
4345
private:
4446
CfdThread *cfdThread;
45-
QProcess * terminalProcess = nullptr;
4647
Terminal * terminal = nullptr;
48+
private:
49+
int terminal_x0;
50+
int terminal_y0;
51+
QSplitter *splitterH;
52+
QSplitter *splitterV;
4753
};
4854
#endif // MAINWINDOW_H

tools/codes/mainwindow.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>800</width>
10-
<height>600</height>
9+
<width>1024</width>
10+
<height>768</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -19,7 +19,7 @@
1919
<rect>
2020
<x>0</x>
2121
<y>0</y>
22-
<width>800</width>
22+
<width>1024</width>
2323
<height>21</height>
2424
</rect>
2525
</property>

tools/codes/terminal.ui

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,65 @@
1010
<height>475</height>
1111
</rect>
1212
</property>
13+
<property name="acceptDrops">
14+
<bool>true</bool>
15+
</property>
1316
<property name="windowTitle">
1417
<string>TerminalWindow</string>
1518
</property>
16-
<widget class="QTextEdit" name="textEdit">
19+
<widget class="QPushButton" name="pushButton">
1720
<property name="geometry">
1821
<rect>
1922
<x>10</x>
20-
<y>10</y>
21-
<width>571</width>
22-
<height>451</height>
23+
<y>0</y>
24+
<width>75</width>
25+
<height>25</height>
2326
</rect>
2427
</property>
25-
<property name="verticalScrollBarPolicy">
26-
<enum>Qt::ScrollBarAlwaysOn</enum>
28+
<property name="text">
29+
<string>OUTPUT</string>
30+
</property>
31+
<property name="flat">
32+
<bool>true</bool>
33+
</property>
34+
</widget>
35+
<widget class="QPushButton" name="pushButton_2">
36+
<property name="geometry">
37+
<rect>
38+
<x>110</x>
39+
<y>0</y>
40+
<width>75</width>
41+
<height>25</height>
42+
</rect>
2743
</property>
28-
<property name="horizontalScrollBarPolicy">
29-
<enum>Qt::ScrollBarAsNeeded</enum>
44+
<property name="text">
45+
<string>TERMINAL</string>
46+
</property>
47+
<property name="flat">
48+
<bool>true</bool>
49+
</property>
50+
</widget>
51+
<widget class="QWidget" name="verticalLayoutWidget">
52+
<property name="geometry">
53+
<rect>
54+
<x>30</x>
55+
<y>60</y>
56+
<width>641</width>
57+
<height>401</height>
58+
</rect>
3059
</property>
60+
<layout class="QVBoxLayout" name="verticalLayout">
61+
<item>
62+
<widget class="QTextEdit" name="textEdit">
63+
<property name="verticalScrollBarPolicy">
64+
<enum>Qt::ScrollBarAlwaysOn</enum>
65+
</property>
66+
<property name="horizontalScrollBarPolicy">
67+
<enum>Qt::ScrollBarAsNeeded</enum>
68+
</property>
69+
</widget>
70+
</item>
71+
</layout>
3172
</widget>
3273
</widget>
3374
<resources/>

0 commit comments

Comments
 (0)