Skip to content

Commit

Permalink
修改图像处理的demo
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminyangguang520 committed Jan 5, 2016
1 parent 70c6c33 commit e7c76df
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 34 deletions.
3 changes: 3 additions & 0 deletions ImageProcessorDemo/ImageProcessorDemo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 21,6 @@ HEADERS = imgprocessor.h \
showwidget.h

FORMS = imgprocessor.ui

RESOURCES = \
res.qrc
Binary file added ImageProcessorDemo/images/bold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/cut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/italic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/justify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/paste.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/printImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/printText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/redo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/rotate180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/rotate270.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/rotate90.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/underline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/undo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/zoomin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ImageProcessorDemo/images/zoomout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 25 additions & 25 deletions ImageProcessorDemo/imgprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 36,18 @@ ImgProcessor::ImgProcessor(QWidget *parent)
}

boldBtn = new QToolButton;
boldBtn->setIcon(QIcon("bold.png"));
boldBtn->setIcon(QIcon(":/images/bold.png"));
boldBtn->setCheckable(true);
italicBtn = new QToolButton;
italicBtn->setIcon(QIcon("italic.png"));
italicBtn->setIcon(QIcon(":/images/italic.png"));
italicBtn->setCheckable(true);

underlineBtn = new QToolButton;
underlineBtn->setIcon(QIcon("underline.png"));
underlineBtn->setIcon(QIcon(":/images/underline.png"));
underlineBtn->setCheckable(true);

colorBtn = new QToolButton;
colorBtn->setIcon(QIcon("color.png"));
colorBtn->setIcon(QIcon(":/images/color.png"));
colorBtn->setCheckable(true);

//排序
Expand All @@ -67,7 67,7 @@ ImgProcessor::ImgProcessor(QWidget *parent)
createMenus();
createToolBars();

if(img.load("image.png"))
if(img.load(":/images/image.png"))
{
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
Expand Down Expand Up @@ -96,13 96,13 @@ ImgProcessor::~ImgProcessor()
void ImgProcessor::createActions()
{
//"打开"动作
openFileAction = new QAction(QIcon("open.png"),QStringLiteral("打开"),this);
openFileAction = new QAction(QIcon(":/images/open.png"),QStringLiteral("打开"),this);
openFileAction->setShortcut(QStringLiteral("Ctrl O"));
openFileAction->setStatusTip(QStringLiteral("打开一个文件"));
connect(openFileAction,SIGNAL(triggered()),this,SLOT(ShowOpenFile()));

//"新建"动作
NewFileAction = new QAction(QIcon("new.png"),QStringLiteral("新建"),this);
NewFileAction = new QAction(QIcon(":/images/new.png"),QStringLiteral("新建"),this);
NewFileAction->setShortcut(QStringLiteral("Ctrl N"));
NewFileAction->setStatusTip(QStringLiteral("新建一个文件"));
connect(NewFileAction,SIGNAL(triggered()),this,SLOT(ShowNewFile()));
Expand All @@ -114,19 114,19 @@ void ImgProcessor::createActions()
connect(exitAction,SIGNAL(triggered()),this,SLOT(close()));

//"复制"动作
copyAction = new QAction(QIcon("copy.png"),QStringLiteral("复制"),this);
copyAction = new QAction(QIcon(":/images/copy.png"),QStringLiteral("复制"),this);
copyAction->setShortcut(QStringLiteral("Ctrl C"));
copyAction->setStatusTip(QStringLiteral("复制文件"));
connect(copyAction,SIGNAL(triggered()),showWidget->text,SLOT(copy()));

//"剪切"动作
cutAction = new QAction(QIcon("cut.png"),QStringLiteral("剪切"),this);
cutAction = new QAction(QIcon(":/images/cut.png"),QStringLiteral("剪切"),this);
cutAction->setShortcut(QStringLiteral("Ctrl X"));
cutAction->setStatusTip(QStringLiteral("剪切文件"));
connect(cutAction,SIGNAL(triggered()),showWidget->text,SLOT(cut()));

//"粘贴"动作
pasteAction = new QAction(QIcon("paste.png"),QStringLiteral("粘贴"),this);
pasteAction = new QAction(QIcon(":/images/paste.png"),QStringLiteral("粘贴"),this);
pasteAction->setShortcut(QStringLiteral("Ctrl V"));
pasteAction->setStatusTip(QStringLiteral("粘贴文件"));
connect(pasteAction,SIGNAL(triggered()),showWidget->text,SLOT(paste()));
Expand All @@ -136,38 136,38 @@ void ImgProcessor::createActions()
connect(aboutAction,SIGNAL(triggered()),this,SLOT(QApplication::aboutQt()));

//"打印文本"动作
PrintTextAction = new QAction(QIcon("printText.png"),QStringLiteral("打印文本"), this);
PrintTextAction = new QAction(QIcon(":/images/printText.png"),QStringLiteral("打印文本"), this);
PrintTextAction->setStatusTip(QStringLiteral("打印一个文本"));
connect(PrintTextAction,SIGNAL(triggered()),this,SLOT(ShowPrintText()));

//"打印图像"动作
PrintImageAction = new QAction(QIcon("printImage.png"),QStringLiteral("打印图像"), this);
PrintImageAction = new QAction(QIcon(":/images/printImage.png"),QStringLiteral("打印图像"), this);
PrintImageAction->setStatusTip(QStringLiteral("打印一幅图像"));
connect(PrintImageAction,SIGNAL(triggered()),this,SLOT(ShowPrintImage()));

//"放大"动作
zoomInAction = new QAction(QIcon("zoomin.png"),QStringLiteral("放大"),this);
zoomInAction = new QAction(QIcon(":/images/zoomin.png"),QStringLiteral("放大"),this);
zoomInAction->setStatusTip(QStringLiteral("放大一张图片"));
connect(zoomInAction,SIGNAL(triggered()),this,SLOT(ShowZoomIn()));

//"缩小"动作
zoomOutAction = new QAction(QIcon("zoomout.png"),QStringLiteral("缩小"),this);
zoomOutAction = new QAction(QIcon(":/images/zoomout.png"),QStringLiteral("缩小"),this);
zoomOutAction->setStatusTip(QStringLiteral("缩小一张图片"));
connect(zoomOutAction,SIGNAL(triggered()),this,SLOT(ShowZoomOut()));

//实现图像旋转的动作(Action)
//旋转90°
rotate90Action = new QAction(QIcon("rotate90.png"),QStringLiteral("旋转90°"),this);
rotate90Action = new QAction(QIcon(":/images/rotate90.png"),QStringLiteral("旋转90°"),this);
rotate90Action->setStatusTip(QStringLiteral("将一幅图旋转90°"));
connect(rotate90Action,SIGNAL(triggered()),this,SLOT(ShowRotate90()));

//旋转180°
rotate180Action = new QAction(QIcon("rotate180.png"),QStringLiteral("旋转180°"), this);
rotate180Action = new QAction(QIcon(":/images/rotate180.png"),QStringLiteral("旋转180°"), this);
rotate180Action->setStatusTip(QStringLiteral("将一幅图旋转180°"));
connect(rotate180Action,SIGNAL(triggered()),this,SLOT(ShowRotate180()));

//旋转270°
rotate270Action = new QAction(QIcon("rotate270.png"),QStringLiteral("旋转270°"), this);
rotate270Action = new QAction(QIcon(":/images/rotate270.png"),QStringLiteral("旋转270°"), this);
rotate270Action->setStatusTip(QStringLiteral("将一幅图旋转270°"));
connect(rotate270Action,SIGNAL(triggered()),this,SLOT(ShowRotate270()));

Expand All @@ -185,25 185,25 @@ void ImgProcessor::createActions()
//排序:左对齐、右对齐、居中和两端对齐
actGrp = new QActionGroup(this);

leftAction = new QAction(QIcon("left.png"),"左对齐",actGrp);
leftAction = new QAction(QIcon(":/images/left.png"),"左对齐",actGrp);
leftAction->setCheckable(true);

rightAction = new QAction(QIcon("right.png"),"右对齐",actGrp);
rightAction = new QAction(QIcon(":/images/right.png"),"右对齐",actGrp);
rightAction->setCheckable(true);

centerAction = new QAction(QIcon("center.png"),"居中",actGrp);
centerAction = new QAction(QIcon(":/images/center.png"),"居中",actGrp);
centerAction->setCheckable(true);

justifyAction = new QAction(QIcon("justify.png"),"两端对齐",actGrp);
justifyAction = new QAction(QIcon(":/images/justify.png"),"两端对齐",actGrp);
justifyAction->setCheckable(true);

connect(actGrp,SIGNAL(triggered(QAction*)),this,SLOT(ShowAlignment(QAction*)));

//实现撤销和重做的动作(Action)
//撤销和重做
undoAction = new QAction(QIcon("undo.png"),"撤销",this);
undoAction = new QAction(QIcon(":/images/undo.png"),"撤销",this);
connect(undoAction,SIGNAL(triggered()),showWidget->text,SLOT(undo()));
redoAction = new QAction(QIcon("redo.png"),"重做",this);
redoAction = new QAction(QIcon(":/images/redo.png"),"重做",this);
connect(redoAction,SIGNAL(triggered()),showWidget->text,SLOT(redo()));
}

Expand Down Expand Up @@ -425,11 425,11 @@ void ImgProcessor::ShowMirrorHorizontal()
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}

void ImgProcessor::ShowFontComboBox(QString comboStr) //设置字体
void ImgProcessor::ShowFontComboBox(QString comboStr) //设置字体
{
QTextCharFormat fmt;
fmt.setFontFamily(comboStr);
mergeFormat(fmt); //把新的格式应用到光标选区内的字符
mergeFormat(fmt); //把新的格式应用到光标选区内的字符
}

void ImgProcessor::mergeFormat(QTextCharFormat format)
Expand Down
18 changes: 9 additions & 9 deletions ImageProcessorDemo/imgprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 27,17 @@ class ImgProcessor : public QMainWindow
explicit ImgProcessor(QWidget *parent = 0);
~ImgProcessor();

void createActions(); //눼쉔땡鱗
void createMenus(); //눼쉔꽉데
void createToolBars(); //눼쉔묏야으
void createActions(); //눼쉔땡鱗
void createMenus(); //눼쉔꽉데
void createToolBars(); //눼쉔묏야으

void loadFile(QString filename);
void mergeFormat(QTextCharFormat);

private:
Ui::ImgProcessor *ui;

QMenu *fileMenu; //몹淃꽉데으
QMenu *fileMenu; //몹淃꽉데으
QMenu *zoomMenu;
QMenu *rotateMenu;
QMenu *mirrorMenu;
Expand All @@ -46,30 46,30 @@ class ImgProcessor : public QMainWindow
QString fileName;
ShowWidget *showWidget;

QAction *openFileAction; //匡숭꽉데淃
QAction *openFileAction; //匡숭꽉데淃
QAction *NewFileAction;
QAction *PrintTextAction;
QAction *PrintImageAction;
QAction *exitAction;

QAction *copyAction; //긍서꽉데淃
QAction *copyAction; //긍서꽉데淃
QAction *cutAction;
QAction *pasteAction;
QAction *aboutAction;
QAction *zoomInAction;
QAction *zoomOutAction;

QAction *rotate90Action; //旗瘻꽉데淃
QAction *rotate90Action; //旗瘻꽉데淃
QAction *rotate180Action;
QAction *rotate270Action;

QAction *mirrorVerticalAction; //쓸獗꽉데淃
QAction *mirrorVerticalAction; //쓸獗꽉데淃
QAction *mirrorHorizontalAction;

QAction *undoAction;
QAction *redoAction;

QToolBar *fileTool; //묏야으
QToolBar *fileTool; //묏야으
QToolBar *zoomTool;
QToolBar *rotateTool;
QToolBar *mirrorTool;
Expand Down
1 change: 1 addition & 0 deletions ImageProcessorDemo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ImgProcessor w;
w.resize(1430, 320);
w.show();

return a.exec();
Expand Down
27 changes: 27 additions & 0 deletions ImageProcessorDemo/res.qrc
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
<RCC>
<qresource prefix="/">
<file>images/bold.png</file>
<file>images/center.png</file>
<file>images/color.png</file>
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/image.png</file>
<file>images/italic.png</file>
<file>images/justify.png</file>
<file>images/left.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/printImage.png</file>
<file>images/printText.png</file>
<file>images/redo.png</file>
<file>images/right.png</file>
<file>images/rotate90.png</file>
<file>images/rotate180.png</file>
<file>images/rotate270.png</file>
<file>images/underline.png</file>
<file>images/undo.png</file>
<file>images/zoomin.png</file>
<file>images/zoomout.png</file>
</qresource>
</RCC>

0 comments on commit e7c76df

Please sign in to comment.