一、头文件:
- #ifndef IMGPROCESSOR_H
- #define IMGPROCESSOR_H
-
- #if _MSC_VER >= 1600
- #pragma execution_character_set("utf-8")
- #endif
-
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include "showwidget.h"
-
- class ImgProcessor : public QMainWindow
- {
- Q_OBJECT
-
- public:
- ImgProcessor(QWidget *parent = nullptr);
- ~ImgProcessor();
- void createActions();
- void createMenus();
- void createToolBars();
- void loadFile(QString filename);
- void mergeFormat(QTextCharFormat);
-
- private:
- QMenu *fileMenu;
- QMenu *zoomMenu;
- QMenu *rotateMenu;
- QMenu *mirrorMenu;
- QImage img;
- QString fileName;
-
- ShowWidget *showWidget;
- QAction *openFileAction;
- QAction *newFileAction;
- QAction *printTextAction;
- QAction *printImageAction;
- QAction *exitAction;
- QAction *copyAction;
- QAction *cutAction;
- QAction *pasteAction;
- QAction *aboutAction;
- QAction *zoomInAction;
- QAction *zoomOutAction;
- QAction *rotate90Action;
- QAction *rotate180Action;
- QAction *rotate270Action;
-
- //镜像菜单项
- QAction *mirrorVerticalAction;
- QAction *mirrorHorizontalAction;
- QAction *undoAction;
- QAction *redoAction;
-
- //工具栏
- QToolBar *fileTool;
- QToolBar *zoomTool;
- QToolBar *rotateTool;
- QToolBar *mirrorTool;
- QToolBar *doToolBar;
-
- //字体设置项
- QLabel *fontLabel1;
- QFontComboBox *fontComboBox;
- QLabel *fontLabel2;
- QComboBox *sizeComboBox;
- QToolButton *boldBtn;
- QToolButton *italicBtn;
- QToolButton *underlineBtn;
- QToolButton *colorBtn;
-
- QToolBar *fontToolBar; //字体工具栏
- QToolBar *listToolBar; //排序工具栏
-
- //排序设置项
- QLabel *listLabel;
- QComboBox *listComboBox;
- QActionGroup *actGrp;
- QAction *leftAction;
- QAction *rightAction;
- QAction *centerAction;
- QAction *justifyAction;
-
-
- protected slots:
- void ShowNewFile();
- void ShowOpenFile();
- void ShowPrintText();
- void ShowPrintImage();
- void ShowZoomIn();
- void ShowZoomOut();
- void ShowRotate90();
- void ShowRotate180();
- void ShowRotate270();
- void ShowMirrorVertical();
- void ShowMirrorHorizontal();
- void ShowFontComboBox(QString comboStr);
- void ShowSizeSpinBox(QString spinValue);
- void ShowBoldBtn();
- void ShowItalicBtn();
- void ShowUnderlineBtn();
- void ShowColorBtn();
- void ShowCurrentFormatChanged(const QTextCharFormat &fmt);
- void ShowList(int);
- void ShowAlignment(QAction *act);
- void ShowCursorPositionChanged();
- };
- #endif // IMGPROCESSOR_H
二、源文件
- #include "imgprocessor.h"
-
- #include
-
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- ImgProcessor::ImgProcessor(QWidget *parent)
- : QMainWindow(parent)
- {
- setWindowTitle(tr("Easy Word")); //设置窗体标题
- showWidget = new ShowWidget(this);
- setCentralWidget(showWidget);
-
- //在工具栏上嵌入控件
- //设置字体
- 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("bold.png"));
- boldBtn->setCheckable(true);
-
- italicBtn = new QToolButton;
- italicBtn->setIcon(QIcon("italic.png"));
- italicBtn->setCheckable(true);
-
- underlineBtn = new QToolButton;
- underlineBtn->setIcon(QIcon("underline.png"));
- underlineBtn->setCheckable(true);
-
- colorBtn = new QToolButton;
- colorBtn->setIcon(QIcon("color.png"));
- colorBtn->setCheckable(true);
-
- //排序
- listLabel = new QLabel(tr("排序"));
- listComboBox = new QComboBox;
- listComboBox->addItem("Standard");
- listComboBox->addItem("QTextListFormat::ListDisc");
- listComboBox->addItem(