123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 | #include "mainwindow.h" #include "ui_mainwindow.h" #include <stdlib.h> #include <qfiledialog> #include <qmessagebox> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui( new Ui::MainWindow) {
ui->setupUi( this );
te= new QTextEdit;
QFont font;
ointSize( 10 );
te->setFont(font);
this ->setCentralWidget(te);
file= new QMenu( "file" );
this ->menuBar()->addMenu(file);
edit= new QMenu( "edit" );
this ->menuBar()->addMenu(edit);
build= new QMenu( "build" );
this ->menuBar()->addMenu(build);
open= new QAction( "open" );
open->setShortcut(tr( "ctrl+o" ));
file->addAction(open);
save= new QAction( "save" );
save->setShortcut(tr( "ctrl+s" ));
file->addAction(save);
exit_= new QAction( "eixt" );
exit_->setShortcut(tr( "ctrl+q" ));
file->addAction(exit_);
connect(open,SIGNAL(triggered()), this ,SLOT(on_open_click()));
connect(save,SIGNAL(triggered()), this ,SLOT(on_save_click()));
connect(exit_,SIGNAL(triggered()), this ,SLOT(on_exit_click()));
copy= new QAction( "copy" );
copy->setShortcut(tr( "ctrl+c" ));
edit->addAction(copy);
paste= new QAction( "paste" );
paste->setShortcut(tr( "ctrl+v" ));
edit->addAction(paste);
cut= new QAction( "cut" );
cut->setShortcut(tr( "ctrl+x" ));
edit->addAction(cut);
connect(copy,SIGNAL(triggered()), this ,SLOT(on_copy_click()));
connect(paste,SIGNAL(triggered()), this ,SLOT(on_paste_click()));
connect(cut,SIGNAL(triggered()), this ,SLOT(on_cut_click()));
buildc= new QAction( "buildc" );
buildc->setShortcut(tr( "ctrl+m" ));
build->addAction(buildc);
run= new QAction( "run" );
run->setShortcut(tr( "ctrl+r" ));
build->addAction(run);
connect(buildc,SIGNAL(triggered()), this ,SLOT(on_buildc_click()));
connect(run,SIGNAL(triggered()), this ,SLOT(on_run_click())); } MainWindow::~MainWindow() {
ui;
te;
file;
edit;
build;
open;
save;
exit_;
copy;
paste;
cut;
buildc;
run; } void MainWindow::on_open_click() {
file_path=QFileDialog::getOpenFileName();
if (file_pty())
return ;
FILE *p =fopen(file_dString()(), "r" );
if (p==NULL)
{
QMessageBox::information( this , "notify" , "open file failure." );
return ;
}
QString content;
char buf[ 1024 ]={ 0 };
while (!feof(p)){
content+= fgets(buf,sizeof(buf),p);
}
fclose(p);
te->setText(content); } void MainWindow::on_save_click() {
file_path=QFileDialog::getSaveFileName();
if (file_path==NULL) return ;
FILE *p=fopen(file_dString()(), "w" );
fputs(te->toPlainText()dString()(),p);
fclose(p); } void MainWindow::on_exit_click() {
exit( 0 ); } void MainWindow::on_copy_click() {
te->copy(); } void MainWindow::on_paste_click() {
te->paste(); } void MainWindow::on_cut_click() {
te->cut(); } void MainWindow::on_buildc_click() {
QString dest=file_path;
ace( ".c" , "" );
system(( "gcc -o " + dest + " " + file_path)dString()());
QMessageBox::information( this , "notify" , "build success!" ); } void MainWindow::on_run_click() {
QString dest=file_path;
ace( ".c" , "" );
system(dString()()); } </qmessagebox></qfiledialog></stdlib.h> |