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

📄 mainwindow.cpp

📁 porting scintilla to qt
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	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()));	copyAct = new QAction(QIcon(":/images/copy.png"), ("&Copy"), this);	copyAct->setShortcut(tr("Ctrl+C"));	copyAct->setStatusTip(("Copy the current selection's contents to the "				"clipboard"));	connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));	pasteAct = new QAction(QIcon(":/images/paste.png"), ("&Paste"), this);	pasteAct->setShortcut(tr("Ctrl+V"));	pasteAct->setStatusTip(("Paste the clipboard's contents into the current "				"selection"));	connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));	undoAct = new QAction(QIcon(":/images/paste.png"), ("undo"), this);	undoAct->setStatusTip(tr("undo"));	connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));	redoAct = new QAction(QIcon(":/images/paste.png"), ("redo"), this);	redoAct->setStatusTip(("redo"));	connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));	deleteAct = new QAction(QIcon(":/images/paste.png"), ("delete"), this);	deleteAct->setStatusTip("delete text");	connect(deleteAct,SIGNAL(triggered()),this,SLOT(deletetext()));	selectAllAct = new QAction(QIcon(":/images/paste.png"), ("select all text"), this);	selectAllAct->setStatusTip("select all text");	connect(selectAllAct,SIGNAL(triggered()),this,SLOT(selectall()));	tabAct = new QAction(QIcon(":/images/paste.png"), ("insert tab"), this);	tabAct->setStatusTip("before selection insert tab");	connect(tabAct,SIGNAL(triggered()),this,SLOT(inserttab()));	untabAct= new QAction(QIcon(":/images/paste.png"), ("remove tab"), this);	untabAct->setStatusTip("remove tab before selection");	connect(untabAct,SIGNAL(triggered()),this,SLOT(removetab()));	//abbv	insertAbbvAct = new QAction(QIcon(":/images/paste.png"), ("insert abbv"), this);	insertAbbvAct->setStatusTip("insert abbv");	connect(insertAbbvAct,SIGNAL(triggered()),this,SLOT(insertabbv()));	expandAbbvAct = new QAction(QIcon(":/images/paste.png"), ("expand abbv"), this);	expandAbbvAct->setStatusTip("expand abbv");	connect(expandAbbvAct,SIGNAL(triggered()),this,SLOT(expandabbv()));	//comment	boxAct = new QAction(QIcon(":/images/paste.png"), ("box comment"), this);	connect(boxAct,SIGNAL(triggered()),this,SLOT(boxcomment()));	blockAct = new QAction(QIcon(":/images/paste.png"), ("block comment"), this);	connect(blockAct,SIGNAL(triggered()),this,SLOT(blockcomment()));	streamAct = new QAction(QIcon(":/images/paste.png"), ("stream comment"), this);	connect(streamAct,SIGNAL(triggered()),this,SLOT(streamcomment()));	//brace match		gotoMatchAct = new QAction(QIcon(":/images/paste.png"), ("goto match"), this);	connect(gotoMatchAct,SIGNAL(triggered()),this,SLOT(gotomatch()));	selectMatchAct = new QAction(QIcon(":/images/paste.png"), ("select match"), this);	connect(selectMatchAct,SIGNAL(triggered()),this,SLOT(selectmatch()));	//find or replace	findAct = new QAction(QIcon(":/images/paste.png"), ("find and replace"), this);	connect(findAct,SIGNAL(triggered()),this,SLOT(findorreplace()));	//print	printAct = new QAction(QIcon(":/images/paste.png"), ("print"), this);	connect(printAct,SIGNAL(triggered()),this,SLOT(print()));	printViewAct = new QAction(QIcon(":/images/paste.png"), ("print preview"), this);	connect(printViewAct,SIGNAL(triggered()),this,SLOT(printview()));	//margin showlinenum	showLineAct = new QAction(QIcon(":/images/paste.png"), ("show line num"), this);	connect(showLineAct,SIGNAL(triggered()),this,SLOT(showline()));	//fold & envole	showFoldMarginAct = new QAction(QIcon(":/images/paste.png"), ("show fold margin"), this);	connect(showFoldMarginAct,SIGNAL(triggered()),this,SLOT(showfoldmargin()));	foldAllAct = new QAction(QIcon(":/images/paste.png"), ("fold all"), this);	connect(foldAllAct,SIGNAL(triggered()),this,SLOT(foldall()));}void MainWindow::setMarginsBackgroundColor(){#if 0	QColor col(255,0,0,0);	//margin	textEdit->setMarginsBackgroundColor(col);	QColor coll(0,255,0,0);	textEdit->setMarginsForegroundColor(coll);	QFont font("Times",130);	textEdit->setMarginsFont(font);	//marksymbol	int mnr= -1;	textEdit->markerDefine(QsciScintilla::Rectangle,mnr);	printf("mnr = %d\n",mnr);#endif}void MainWindow::createMenus(){	fileMenu = menuBar()->addMenu(("&File"));	fileMenu->addAction(newAct);	fileMenu->addAction(openAct);	fileMenu->addAction(saveAct);	fileMenu->addAction(saveAsAct);	fileMenu->addSeparator();	//print	fileMenu->addAction(printAct);	fileMenu->addAction(printViewAct);	fileMenu->addAction(closeAct);	fileMenu->addSeparator();	fileMenu->addAction(exitAct);	editMenu = menuBar()->addMenu(("&Edit"));	editMenu->addAction(cutAct);	editMenu->addAction(copyAct);	editMenu->addAction(pasteAct);	editMenu->addSeparator();	editMenu->addAction(deleteAct);	editMenu->addAction(selectAllAct);	editMenu->addSeparator();	editMenu->addAction(undoAct);	editMenu->addAction(redoAct);	editMenu->addSeparator();	editMenu->addAction(tabAct);	editMenu->addAction(untabAct);	editMenu->addSeparator();	editMenu->addAction(insertAbbvAct);	editMenu->addAction(expandAbbvAct);	//comment	editMenu->addSeparator();	editMenu->addAction(boxAct);	editMenu->addAction(blockAct);	editMenu->addAction(streamAct);	//match	editMenu->addSeparator();	editMenu->addAction(gotoMatchAct);	editMenu->addAction(selectMatchAct);	editMenu->addSeparator();	editMenu->addAction(findAct);	//margin & showline	editMenu->addSeparator();	editMenu->addAction(showLineAct);	//fold * envole	editMenu->addSeparator();	editMenu->addAction(showFoldMarginAct);	editMenu->addAction(foldAllAct);	//////////////////	codingMenu = menuBar()->addMenu("&Encoding");    foreach (QTextCodec *codec, m_codeclist) {        QString text = tr("%1...").arg(QString(codec->name()));        QAction *action = new QAction(text, this);		action->setData(codec->name());        connect(action, SIGNAL(triggered()), this, SLOT(reload()));		codingMenu->addAction(action);    }	/////////////////////////////////////	menuBar()->addSeparator();	helpMenu = menuBar()->addMenu(("&Help"));	//helpMenu->addAction(aboutAct);	//helpMenu->addAction(aboutQtAct);}void MainWindow::createToolBars(){	fileToolBar = addToolBar(("File"));	fileToolBar->addAction(newAct);	fileToolBar->addAction(openAct);	fileToolBar->addAction(saveAct);	editToolBar = addToolBar(("Edit"));	//editToolBar->addAction(cutAct);	//editToolBar->addAction(copyAct);	//editToolBar->addAction(pasteAct);}void MainWindow::createStatusBar(){	statusBar()->showMessage(("Ready"));}void MainWindow::readSettings(){	QSettings settings("Trolltech", "Application Example");	QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();	QSize size = settings.value("size", QSize(400, 400)).toSize();	resize(size);	move(pos);}void MainWindow::writeSettings(){	QSettings settings("Trolltech", "Application Example");	settings.setValue("pos", pos());	settings.setValue("size", size());}bool MainWindow::maybeSave(){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return true;	if (textEdit->isModified()) {		int ret = QMessageBox::warning(this, ("Application"),				("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)			return save();		else if (ret == QMessageBox::Cancel)			return false;	}	return true;}void MainWindow::loadFile(const QString &fileName){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return;	QFile file(fileName);	if (!file.open(QFile::ReadOnly)) {		QMessageBox::warning(this, ("Application"),				tr("Cannot read file %1:\n%2.")				.arg(fileName)				.arg(file.errorString()));		return;	}	QTextStream in(&file);//	in.setAutoDetectUnicode(true);	in.setCodec(codec);	QApplication::setOverrideCursor(Qt::WaitCursor);//	textEdit->setText(codec->fromUnicode(in.readAll()));	if(in.codec() == NULL)		printf("no codec\n");	else{		printf("use codec\n");		printf("codec = %s\n",in.codec()->name().data());	}	textEdit->setText((in.readAll()));	QApplication::restoreOverrideCursor();	if(global){		lexer = global->getLexFromPostfix(fileName.toStdString().c_str());		textEdit->accept(lexer);	}	textEdit->setFileName(fileName);	setCurrentFile(fileName);	statusBar()->showMessage(("File loaded"), 2000);}bool MainWindow::saveFile(const QString &fileName){	textEdit = static_cast<QSteEditor*>(tabwidget->currentWidget());	if(textEdit == NULL)		return false;	QFile file(fileName);	if (!file.open(QFile::WriteOnly)) {		QMessageBox::warning(this, tr("Application"),				tr("Cannot write file %1:\n%2.")				.arg(fileName)				.arg(file.errorString()));		return false;	}	QTextCodec *codec;	codec = QTextCodec::codecForName("GB18030");	QTextStream out(&file);//	out.setCodec(codec);	QApplication::setOverrideCursor(Qt::WaitCursor);	out << textEdit->getText();	QApplication::restoreOverrideCursor();	setCurrentFile(fileName);	statusBar()->showMessage(("File saved"), 2000);	return true;}void MainWindow::setCurrentFile(const QString &fileName){#if 0	curFile = fileName;	textEdit->setModified(false);	setWindowModified(false);	QString shownName;	if (curFile.isEmpty())		shownName = "untitled.txt";	else		shownName = strippedName(curFile);	setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(("Application")));#endif}QString MainWindow::strippedName(const QString &fullFileName){	return QFileInfo(fullFileName).fileName();}	FindDialog::FindDialog(QWidget *parent): QDialog(parent){	label = new QLabel(tr("Find &what:"));	lineEdit = new QLineEdit;	label->setBuddy(lineEdit);	replaceLabel = new QLabel(tr("replace  :"));	replaceEdit = new QLineEdit;	replaceLabel->setBuddy(replaceEdit);	caseCheckBox = new QCheckBox(tr("Match &case"));	fromStartCheckBox = new QCheckBox(tr("Search from &start"));	fromStartCheckBox->setChecked(true);	findButton = new QPushButton(tr("&Find"));	findButton->setDefault(true);	replaceButton = new QPushButton(tr("&replace"));	replaceButton->setDefault(false);	moreButton = new QPushButton(tr("&More"));	moreButton->setCheckable(true);	moreButton->setAutoDefault(false);	buttonBox = new QDialogButtonBox(Qt::Vertical);	buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);	buttonBox->addButton(replaceButton, QDialogButtonBox::ActionRole);	buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);	extension = new QWidget;	wholeWordsCheckBox = new QCheckBox(tr("&Whole words"));	backwardCheckBox = new QCheckBox(tr("Search &backward"));	searchSelectionCheckBox = new QCheckBox(tr("Search se&lection"));	connect(moreButton, SIGNAL(toggled(bool)), extension, SLOT(setVisible(bool)));	connect(findButton,SIGNAL(clicked()),this,SLOT(find()));	connect(replaceButton,SIGNAL(clicked()),this,SLOT(replace()));	QVBoxLayout *extensionLayout = new QVBoxLayout;	extensionLayout->setMargin(0);	extensionLayout->addWidget(wholeWordsCheckBox);	extensionLayout->addWidget(backwardCheckBox);	extensionLayout->addWidget(searchSelectionCheckBox);	extension->setLayout(extensionLayout);	QHBoxLayout *topLeftLayout = new QHBoxLayout;	topLeftLayout->addWidget(label);	topLeftLayout->addWidget(lineEdit);	QHBoxLayout *topLeftLayout1 = new QHBoxLayout;	topLeftLayout1->addWidget(replaceLabel);	topLeftLayout1->addWidget(replaceEdit);	QVBoxLayout *leftLayout = new QVBoxLayout;	leftLayout->addLayout(topLeftLayout);	leftLayout->addLayout(topLeftLayout1);	leftLayout->addWidget(caseCheckBox);	leftLayout->addWidget(fromStartCheckBox);	leftLayout->addStretch(1);	QGridLayout *mainLayout = new QGridLayout;	mainLayout->setSizeConstraint(QLayout::SetFixedSize);	mainLayout->addLayout(leftLayout, 0, 0);	mainLayout->addWidget(buttonBox, 0, 1);	mainLayout->addWidget(extension, 1, 0, 1, 2);	setLayout(mainLayout);	setWindowTitle(tr("Extension"));	extension->hide();}void FindDialog::find(){	if(lineEdit->text().length() != 0)		emit findStr(lineEdit->text().toStdString()); }void FindDialog::replace(){	if(replaceEdit->text().length() != 0)		emit replaceStr(replaceEdit->text().toStdString()); }

⌨️ 快捷键说明

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