Ejemplo n.º 1
0
/* 初始化相应的信号与槽 */
void TextEditer::initConnection()
{
	/* menuFile里的信号与槽 */
	connect(actNew, SIGNAL(triggered()), this, SLOT(doNew()));
	connect(actOpen, SIGNAL(triggered()), this, SLOT(doOpen()));
	connect(actClose, SIGNAL(triggered()), this, SLOT(doClose()));
	connect(actSave, SIGNAL(triggered()), this, SLOT(doSave()));
	connect(actASave, SIGNAL(triggered()), this, SLOT(doASave()));
	connect(actExit, SIGNAL(triggered()), this, SLOT(doExit()));

	/* menuEdit里的信号与槽 */
	connect(actUndo, SIGNAL(triggered()), this, SLOT(doUndo()));
	connect(actRedo, SIGNAL(triggered()), this, SLOT(doRedo()));
	connect(actCut, SIGNAL(triggered()), this, SLOT(doCut()));
	connect(actCopy, SIGNAL(triggered()), this, SLOT(doCopy()));
	connect(actPast, SIGNAL(triggered()), this, SLOT(doPast()));
	connect(actAll, SIGNAL(triggered()), this, SLOT(doSelectAll()));

	/* menuTool里的信号与槽 */
	connect(actFont, SIGNAL(triggered()), this, SLOT(setFontForText()));

	/* 当当前文本内容改变后, 自动调用doModified() */
	connect(textEdit->document(), SIGNAL(contentsChanged()),
				this, SLOT(doModified()));

	/* 当文档修改后, 刷新光标所在的位置 */
	connect(textEdit->document(), SIGNAL(contentsChanged()),
			this, SLOT(doCursorChanged()));
}
Ejemplo n.º 2
0
void CMainWindow::iniConnect()
{
	connect(textEdit, SIGNAL(cursorPositionChanged()), 
		this, SLOT(doCursorChanged()));
	connect(actNew, SIGNAL(triggered()), 
		this, SLOT(doNew()));
	connect(actOpen, SIGNAL(triggered()), 
		this, SLOT(doOpen()));
	connect(actClose, SIGNAL(triggered()), 
		this, SLOT(doClose()));
	connect(actSave, SIGNAL(triggered()), 
		this, SLOT(doSave()));
	connect(actASave, SIGNAL(triggered()), 
		this, SLOT(doASave()));
	connect(actQuit, SIGNAL(triggered()),
		this, SLOT(doQuit()));
	connect(actUndo, SIGNAL(triggered()), 
		this, SLOT(doUndo()));
	connect(actCut, SIGNAL(triggered()), 
		this, SLOT(doCut()));
	connect(actCopy, SIGNAL(triggered()), 
		this, SLOT(doCopy()));
	connect(actPaste, SIGNAL(triggered()), 
		this, SLOT(doPast()));
	connect(actAll, SIGNAL(triggered()), 
		this, SLOT(doAll()));
	connect(actFind, SIGNAL(triggered()), 
		this, SLOT(doFind()));
	connect(textEdit->document(), SIGNAL(contentsChanged()), 
		this, SLOT(doModified()));
	separatorAct = menu_F->insertSeparator(actQuit);
	separatorAct->setVisible(false);
	for (int i = 0; i < MaxRecentFiles; ++i) 
	{
         recentFileActs[i] = new QAction(this);
		 menu_F->insertAction(separatorAct, recentFileActs[i]);
         recentFileActs[i]->setVisible(false);
         connect(recentFileActs[i], SIGNAL(triggered()),
                 this, SLOT(openRecentFile()));
     }	 
	 
	actPrint = menu_T->addAction(tr("打印文档"));
	connect(actPrint, SIGNAL(triggered()), this, SLOT(doPrint()));
}