#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//各项菜单栏
fileMenu = new QMenu;
zoomMenu = new QMenu;
rotateMenu = new QMenu;
mirrorMenu = new QMenu;
showWidget = new ShowWidget;
//文件菜单
openFileAction =new QAction;
NewFileAction =new QAction;
PrintTextAction =new QAction;
PrintImageAction =new QAction;
exitAction = new QAction;
//缩放菜单
copyAction =new QAction;
cutAction =new QAction;
pasteAction =new QAction;
aboutAction =new QAction;
zoomInAction =new QAction;
zoomOutAction=new QAction;
//旋转菜单项
rotate90Action =new QAction;
rotate180Action=new QAction;
rotate270Action=new QAction;
//镜像菜单项
mirrorVerticalAction =new QAction;
mirrorHorizontalAction=new QAction;
undoAction =new QAction;
redoAction =new QAction;
//工具栏
fileTool = new QToolBar;
zoomTool = new QToolBar;
rotateTool = new QToolBar;
mirrorTool = new QToolBar;
doToolBar = new QToolBar;
setWindowTitle(tr("Easy Word")); //设置窗体标题
showWidget =new ShowWidget(this); //(a)
setCentralWidget(showWidget);
/*创建动作、菜单、工具栏的函数*/
createActions() ;
createMenus();
createToolBars();
if(img.load(":/src/PKQ.png"))
{
//在 imageLabel 对象中放置图片
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
}
MainWindow::~MainWindow()
{
}
void MainWindow::createActions()
{
//“打开”动作
openFileAction =new QAction(QIcon(":/src/open.png"),tr("打开"),this); //(a)
openFileAction->setShortcut (tr ("Ctrl+O")); //(b)
openFileAction->setStatusTip(tr("打开一个文件 ")); //(c)
connect(openFileAction,SIGNAL(triggered()),this,SLOT(ShowOpenFile()));
//"新建“动作
NewFileAction =new QAction(QIcon(":/src/new.png"),tr("新建"),this);
NewFileAction->setShortcut(tr("Ctrl+N"));
NewFileAction->setStatusTip(tr("新建一个文件"));
connect(NewFileAction, SIGNAL (triggered()) , this, SLOT (ShowNewFile())) ;
// "退出“动作
exitAction =new QAction(tr("退出"),this);
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("退出程序")) ;
connect (exitAction, SIGNAL (triggered()), this, SLOT (close()));
// "复制”动作
copyAction =new QAction(QIcon(":/src/copy.png"),tr("复制"),this);
copyAction->setShortcut(tr("Ctrl+C"));
copyAction->setStatusTip(tr(" 复制文件")) ;
connect(copyAction,SIGNAL( triggered ()), showWidget->text, SLOT(copy()));
//"剪切“动作
cutAction =new QAction(QIcon(":/src/cut.png"),tr("剪切"),this);
cutAction->setShortcut(tr("Ctrl+X"));
cutAction->setStatusTip(tr("剪切文件")) ;
connect(cutAction,SIGNAL( triggered ()), showWidget->text, SLOT (cut()));
//"粘贴“动作
pasteAction =new QAction(QIcon(":/src/paste.png"),tr("粘贴"),this);
pasteAction->setShortcut(tr("Ctrl+V"));
pasteAction->setStatusTip(tr("粘贴文件")) ;
connect(pasteAction,SIGNAL(triggered()),showWidget->text,SLOT (paste()));
//"关于“动作
aboutAction =new QAction(tr("关于"),this);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(QApplication::aboutQt()));
//"打印文本“动作
PrintTextAction =new QAction(QIcon(":/src/printText.png"),tr(" 打印文本"), this);
PrintTextAction->setStatusTip(tr("打印一个文本"));
connect (PrintTextAction, SIGNAL (triggered()), this, SLOT (ShowPrintText ()));
//"打印图片“动作
PrintImageAction =new QAction(QIcon (":/src/printimage.png" ), tr("打印图片"), this);
PrintImageAction->setStatusTip(tr("打印一幅图片"));
connect(PrintImageAction, SIGNAL (triggered()), this, SLOT (ShowPrintImage()));
//"放大“动作
zoomInAction =new QAction (QIcon(":/src/zoomin.png"),tr(" 放大 "),this);
zoomInAction->setStatusTip(tr("放大一幅图片"));
connect(zoomInAction,SIGNAL(triggered()),this,SLOT(ShowZoomIn()));
//"缩小“动作
zoomOutAction =new QAction(QIcon(":/src/zoomout.png"),tr("缩小 "),this);
zoomOutAction->setStatusTip(tr("缩小一幅图片 "));
connect (zoomOutAction, SIGNAL(triggered ()), this, SLOT (ShowZoomOut()));
//实现图片旋转的动作 (Action)
//旋转 90°
rotate90Action =new QAction (QIcon (":/src/rotate90.png"), tr("旋转 90°") ,this);
rotate90Action->setStatusTip(tr("将一幅图旋转90°"));
connect(rotate90Action, SIGNAL (triggered()), this, SLOT (ShowRotate90()));
//旋转180°
rotate180Action =new QAction (QIcon(":/src/rotate180.png"), tr("旋转 180°"), this);
rotate180Action->setStatusTip(tr("将一幅图旋转180°"));
connect(rotate180Action, SIGNAL (triggered()), this, SLOT (ShowRotate180()));
//旋转270°
rotate270Action =new QAction(QIcon (":/src/rotate270.png"), tr("旋转 270°"), this);
rotate270Action->setStatusTip(tr("将一幅图旋转 270°"));
connect(rotate270Action, SIGNAL (triggered()), this, SLOT (ShowRotate270()));
//实现图片镜像的动作(Action)
//纵向镜像
mirrorVerticalAction =new QAction(QIcon(":/src/mirrorVertical.png"),tr("纵向镜像"), this);
mirrorVerticalAction->setStatusTip(tr("对一幅图做纵向镜像")) ;
connect (mirrorVerticalAction, SIGNAL (triggered()), this, SLOT (ShowMirrorVertical()));
//横向镜像
mirrorHorizontalAction =new QAction(QIcon(":/src/mirrorHorizontal.png"),tr("横向镜像 "),this);
mirrorHorizontalAction->setStatusTip(tr("对一幅图做横向镜像")) ;
connect (mirrorHorizontalAction, SIGNAL (triggered()), this, SLOT (ShowMirrorHorizontal ()));
//实现撤销和重做的动作(ACtion)
//撤销和重做
undoAction =new QAction (QIcon(":/src/undo.png"),"撤销",this);
connect(undoAction,SIGNAL(triggered()),showWidget->text,SLOT(undo()));
redoAction =new QAction(QIcon(":/src/redo.png"),"重做",this);
connect(redoAction, SIGNAL(triggered()),showWidget->text,SLOT(redo()));
//在工具栏上嵌入控件
//设置字号
fontLabel1 =new QLabel (tr("字体:"));
fontComboBox =new QFontComboBox;
fontComboBox->setFontFilters(QFontComboBox::ScalableFonts);
fontLabel2 =new QLabel(tr("字号:"));
sizeComboBox =new QComboBox;
QFontDatabase db;
/***************文本编辑功能******************/
foreach(int size,db.standardSizes())
{
sizeComboBox->addItem(QString::number(size));
}
boldBtn =new QToolButton;
boldBtn->setIcon(QIcon(":/src/bold.png"));
boldBtn->setCheckable(true);
connect (boldBtn, SIGNAL (clicked()),this,SLOT (ShowBoldBtn()));
italicBtn =new QToolButton;
italicBtn->setIcon(QIcon(":/src/italic.png"));
italicBtn->setCheckable(true);
connect (italicBtn, SIGNAL (clicked()), this, SLOT (ShowItalicBtn ())) ;
underlineBtn =new QToolButton;
underlineBtn->setIcon(QIcon(":/src/underline.png"));
underlineBtn->setCheckable(true);
connect (underlineBtn, SIGNAL (clicked()), this, SLOT (ShowUnderlineBtn ()));
colorBtn =new QToolButton;
colorBtn->setIcon(QIcon(":/src/color.png"));
colorBtn->setCheckable(true);
connect(colorBtn,SIGNAL(clicked()),this,SLOT(ShowColorBtn()));
connect(fontComboBox,SIGNAL(activated(QString)),this,SLOT(ShowFontComboBox(QString)));
connect(sizeComboBox,SIGNAL(activated(QString)),this,SLOT(ShowSizeSpinBox(QString)));
connect(showWidget->text,SIGNAL(currentCharFormatChanged(QTextCharFormat&)) , this,SLOT(ShowCurrentFormatChanged(QTextCharFormat&)));
}
void MainWindow::create
评论0