-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
127 lines (101 loc) · 2.8 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(
ui->widget,
SIGNAL(glelement_added(QListWidgetItem* )),
this,
SLOT(add_item(QListWidgetItem* ))
);
connect(
this,
SIGNAL(glelement_selected(QListWidgetItem*)),
ui->widget,
SLOT(set_current(QListWidgetItem* ))
);
connect(
ui->widget,
SIGNAL(glelement_selected(QListWidgetItem*)),
this,
SLOT(set_current(QListWidgetItem*))
);
this->showMaximized();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::alert(QString s)
{
QMessageBox msgBox;
msgBox.setWindowTitle("CG");
msgBox.setText(s);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
void MainWindow::showMessage(QString s, int time)
{
ui->statusBar->showMessage(s,time);
}
QString MainWindow::new_file(QString filter,QString type)
{
QStringList fileNames;
QFileDialog dialog(0);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter(filter);
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec())
fileNames = dialog.selectedFiles();
//dialog maybe cancelled
if(fileNames.count()==0)
return NULL;
QString filename=fileNames.at(0);
if(!filename.endsWith(type,Qt::CaseInsensitive))
filename=filename+type;
return filename;
}
QString MainWindow::open_file(QString filter)
{
QStringList fileNames;
QFileDialog dialog(0);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(filter);
dialog.setAcceptMode(QFileDialog::AcceptOpen);
if (dialog.exec())
fileNames = dialog.selectedFiles();
//dialog maybe cancelled
if(fileNames.count()==0)
return NULL;
QString filename=fileNames.at(0);
return filename;
}
void MainWindow::try_close()
{
QMessageBox msgBox;
msgBox.setWindowTitle("Quit");
msgBox.setText("You are going to quit.");
msgBox.setStandardButtons(QMessageBox::Ok|QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret=msgBox.exec();
if(ret==QMessageBox::Ok)
close();
}
void MainWindow::add_item(QListWidgetItem *l)
{
ui->listWidget->insertItem(0,l);
ui->listWidget->setCurrentItem(l);
ui->statusBar->showMessage("ok",0);
}
void MainWindow::set_current(QListWidgetItem *l)
{
ui->listWidget->setCurrentItem(l);
}
void MainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *)
{
emit glelement_selected(current);
}