⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cpp_bak

📁 porting scintilla to qt
💻 CPP_BAK
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 2004-2006 Trolltech ASA. All rights reserved.**** This file is part of the example classes of the Qt Toolkit.**** Licensees holding a valid Qt License Agreement may use this file in** accordance with the rights, responsibilities and obligations** contained therein.  Please consult your licensing agreement or** contact sales@trolltech.com if any conditions of this licensing** agreement are not clear to you.**** Further information about Qt licensing is available at:** http://www.trolltech.com/products/qt/licensing.html or by** contacting info@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <QtGui>#include <QTabBar>#include "qsteeditor.h"#include "stdlib.h"#include "mainwindow.h"MainWindow::MainWindow(){	global = new QSteGlobalProper("qsteglobal.properties","../data/");	tabwidget = new QTabWidget;	setCentralWidget(tabwidget);	createActions();	createMenus();	createToolBars();	createStatusBar();	readSettings();	connect(tabwidget,SIGNAL(currentChanged(int)),this,SLOT(textListChange(int)));	setCurrentFile("");	//	textEdit->setWhitespaceVisibility(QsciScintilla::WsVisible);}void MainWindow::closeEvent(QCloseEvent *event){	if (maybeSave()) {		writeSettings();		event->accept();	} else {		event->ignore();	}}void MainWindow::newFile(){	QSteEditor *editor = new QSteEditor(tabwidget);	editor->accept(global);	tabwidget->addTab(editor,"Untitled");	textEdit = editor;}void MainWindow::textListChange(QSteEditor *editor){}void MainWindow::textListChange(int index){}void MainWindow::textListRemove(QSteEditor *editro){}void MainWindow::textListRemove(const QString &text){}void MainWindow::open(){	if (maybeSave()) {		QString fileName = QFileDialog::getOpenFileName(this);		if (!fileName.isEmpty())			loadFile(fileName);	}}void MainWindow::closeFile(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	if (textEdit->isModified()) {		int ret = QMessageBox::warning(this, tr("Application"),				tr("The document has been modified.\n"					"Do you want to save your changes?"),				QMessageBox::Yes | QMessageBox::Default,				QMessageBox::No,				QMessageBox::Cancel | QMessageBox::Escape);		if (ret == QMessageBox::Yes)			save();		else if (ret == QMessageBox::Cancel)			return ;	}	tabwidget->removeTab(tabwidget->currentIndex());	return ;}bool MainWindow::save(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return false;	if (curFile.isEmpty()) {		return saveAs();	} else {		//        return saveFile(curFile);		return textEdit->saveFile(curFile);	}}void MainWindow::copy(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->copy();}void MainWindow::cut(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->cut();}void MainWindow::paste(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->paste();}void MainWindow::undo(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->undo();}void MainWindow::redo(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->redo();}void MainWindow::deletetext(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->deleteText();}void MainWindow::selectall(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->selectAll();}void MainWindow::inserttab(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->insertTab();}void MainWindow::removetab(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->removeTab();}void MainWindow::insertabbv(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->insertAbbreviation();}void MainWindow::expandabbv(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->expandAbbreviation();}//commentvoid MainWindow::boxcomment(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->boxComment();}void MainWindow::streamcomment(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->streamComment();}void MainWindow::blockcomment(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->blockComment();}//matchvoid MainWindow::gotomatch(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->gotoBraceMatch();}void MainWindow::selectmatch(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->selectBraceMatch();}//find & replacevoid MainWindow::findorreplace(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	FindDialog *dialog = new FindDialog(this);	connect(dialog,SIGNAL(findStr(string)),this,SLOT(find(string)));	connect(dialog,SIGNAL(replaceStr(string)),this,SLOT(replace(string)));	dialog->exec();}int MainWindow::find(string str){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return  -1;	textEdit->doFind(str.c_str());}int MainWindow::replace(string str){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return -1;	printf("str = %s\n",str.c_str());	textEdit->doReplace(str.c_str());}//printvoid MainWindow::print(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;#ifndef QT_NO_PRINTER	QPrinter printer(QPrinter::HighResolution);	printer.setFullPage(true);	QPrintDialog *dlg = new QPrintDialog(&printer, this);	dlg->setWindowTitle(tr("Print Document"));	if (dlg->exec() == QDialog::Accepted) {		printf("from page = %d\n",dlg->fromPage());		printf("page copies = %d\n",printer.numCopies());		printf("page orders= %d\n",printer.pageOrder());		textEdit->filePrint(&printer);	}	delete dlg;#endif}void MainWindow::printview(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;#ifndef QT_NO_PRINTER	QPrinter *printer = new QPrinter(QPrinter::HighResolution);	printer->setFullPage(true);#endif	//move to qt-4.4.0 QPrintPreviewDialog}//margin & showlinevoid MainWindow::showline(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->showLineNum(true);}//fold & envolevoid MainWindow::showfoldmargin(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->showFoldMargin(true);}void MainWindow::foldall(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	textEdit->foldAll();}bool MainWindow::saveAs(){	QString fileName = QFileDialog::getSaveFileName(this);	if (fileName.isEmpty())		return false;	return saveFile(fileName);}void MainWindow::about(){	QMessageBox::about(this, tr("About Application"),			tr("The <b>Application</b> example demonstrates how to "				"write modern GUI applications using Qt, with a menu bar, "				"toolbars, and a status bar."));}void MainWindow::documentWasModified(){	//    setWindowModified(textEdit->isModified());}void MainWindow::createActions(){	newAct = new QAction(QIcon(":/images/new.png"), "&New", this);	newAct->setShortcut(tr("Ctrl+N"));	newAct->setStatusTip(("Create a new file"));	connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));	openAct = new QAction(QIcon(":/images/open.png"), "&Open...", this);	openAct->setShortcut(tr("Ctrl+O"));	openAct->setStatusTip(("Open an existing file"));	connect(openAct, SIGNAL(triggered()), this, SLOT(open()));	saveAct = new QAction(QIcon(":/images/save.png"), "&Save", this);	saveAct->setShortcut(tr("Ctrl+S"));	saveAct->setStatusTip(("Save the document to disk"));	connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));	saveAsAct = new QAction(("Save &As..."), this);	saveAsAct->setStatusTip(("Save the document under a new name"));	connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));	exitAct = new QAction(("E&xit"), this);	exitAct->setShortcut(tr("Ctrl+Q"));	exitAct->setStatusTip(("Exit the application"));	connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));	closeAct = new QAction(("Close"),this);	closeAct->setStatusTip("Close current file");	connect(closeAct,SIGNAL(triggered()),this,SLOT(closeFile()));	cutAct = new QAction(QIcon(":/images/cut.png"), ("Cu&t"), this);	cutAct->setShortcut(tr("Ctrl+X"));	cutAct->setStatusTip(("Cut the current selection's contents to the "				"clipboard"));	connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -