-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
130 lines (117 loc) · 3.46 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QToolButton>
#include <QSpinBox>
#include <QLabel>
#include <QTextEdit>
#include <QMdiSubWindow>
#include "qtform.h"
#include "showdialog.h"
#include "viewform.h"
#include "cmdaction.h"
#include <QDebug>
#include "testform.h"
#include "singleimageform.h"
#include "command.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setToolBar();
setAction();
addStatusBar();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setToolBar()
{
QToolButton* toolBtn = new QToolButton(this);
toolBtn->setText("Color");
QMenu* colorMenu = new QMenu(this);
colorMenu->addAction("Red");
colorMenu->addAction("Green");
toolBtn->setMenu(colorMenu);
toolBtn->setPopupMode(QToolButton::MenuButtonPopup);
ui->toolBar->addWidget(toolBtn);
QSpinBox* spinBox = new QSpinBox(this);
ui->toolBar->addWidget(spinBox);
}
void MainWindow::addStatusBar()
{
ui->statusbar->showMessage("welcome to use mainwindow", 2000);
QLabel* permanent = new QLabel(this);
permanent->setFrameStyle(QFrame::Box | QFrame::Sunken);
permanent->setText("yauyimsing");
ui->statusbar->addPermanentWidget(permanent);
}
void MainWindow::setAction()
{
CmdAction *action = new CmdAction;
QMenu *editMenu = ui->menubar->addMenu("Command");
editMenu->addAction(action);
connect(action, SIGNAL(getText(const QString&)), this, SLOT(getCommand(const QString&)));
}
void MainWindow::on_actionNew_N_triggered()
{
QTextEdit* edit = new QTextEdit(this);
QMdiSubWindow* child = ui->mdiArea->addSubWindow(edit);
child->setWindowTitle("multi-document sub-window");
child->show();
}
void MainWindow::on_actionShow_triggered()
{
QtForm* qtForm = new QtForm(this);
int height = qtForm->height();
int width = qtForm->width();
QMdiSubWindow* child = ui->mdiArea->addSubWindow(qtForm);
child->setWindowTitle("picture sub-window");
child->resize(width + 100, height + 100);
child->show();
}
void MainWindow::on_actionDialog_triggered()
{
ShowDialog* dialog = new ShowDialog(this);
dialog->show();
}
void MainWindow::on_actionViewForm_triggered()
{
cout << "on_actionViewForm_triggered" << endl;
ViewForm* viewForm = new ViewForm(this);
cout << "ViewForm";
viewForm->imageRead("ee.jpg");
qDebug() << "imageRead";
int height = viewForm->height();
int width = viewForm->width();
QMdiSubWindow* child = ui->mdiArea->addSubWindow(viewForm);
child->setWindowTitle("picture sub-window");
child->resize(width + 100, height + 100);
child->show();
}
void MainWindow::getCommand(const QString &string)
{
char* ch;
QByteArray ba = string.toLatin1(); // must
ch=ba.data();
cout << ch << endl;
Command cmd;
cmd.Task(this);
}
void MainWindow::on_actionTestForm_triggered()
{
TestForm *form = new TestForm(this);
QSize size = form->size();
QMdiSubWindow* child = ui->mdiArea->addSubWindow(form);
child->setWindowTitle("picture sub-window");
child->resize(size.width() + 100, size.height() + 100);
child->show();
}
void MainWindow::on_actionSingleImageForm_triggered()
{
SingleImageForm *form = new SingleImageForm(this);
QSize size = form->size();
QMdiSubWindow* child = ui->mdiArea->addSubWindow(form);
child->setWindowTitle("picture sub-window");
child->resize(size.width() + 100, size.height() + 100);
child->showMaximized();
}