• 基于Qt实现文本编辑器功能


    一、头文件:

    1. #ifndef IMGPROCESSOR_H
    2. #define IMGPROCESSOR_H
    3. #if _MSC_VER >= 1600
    4. #pragma execution_character_set("utf-8")
    5. #endif
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. #include
    13. #include
    14. #include
    15. #include
    16. #include
    17. #include
    18. #include "showwidget.h"
    19. class ImgProcessor : public QMainWindow
    20. {
    21. Q_OBJECT
    22. public:
    23. ImgProcessor(QWidget *parent = nullptr);
    24. ~ImgProcessor();
    25. void createActions();
    26. void createMenus();
    27. void createToolBars();
    28. void loadFile(QString filename);
    29. void mergeFormat(QTextCharFormat);
    30. private:
    31. QMenu *fileMenu;
    32. QMenu *zoomMenu;
    33. QMenu *rotateMenu;
    34. QMenu *mirrorMenu;
    35. QImage img;
    36. QString fileName;
    37. ShowWidget *showWidget;
    38. QAction *openFileAction;
    39. QAction *newFileAction;
    40. QAction *printTextAction;
    41. QAction *printImageAction;
    42. QAction *exitAction;
    43. QAction *copyAction;
    44. QAction *cutAction;
    45. QAction *pasteAction;
    46. QAction *aboutAction;
    47. QAction *zoomInAction;
    48. QAction *zoomOutAction;
    49. QAction *rotate90Action;
    50. QAction *rotate180Action;
    51. QAction *rotate270Action;
    52. //镜像菜单项
    53. QAction *mirrorVerticalAction;
    54. QAction *mirrorHorizontalAction;
    55. QAction *undoAction;
    56. QAction *redoAction;
    57. //工具栏
    58. QToolBar *fileTool;
    59. QToolBar *zoomTool;
    60. QToolBar *rotateTool;
    61. QToolBar *mirrorTool;
    62. QToolBar *doToolBar;
    63. //字体设置项
    64. QLabel *fontLabel1;
    65. QFontComboBox *fontComboBox;
    66. QLabel *fontLabel2;
    67. QComboBox *sizeComboBox;
    68. QToolButton *boldBtn;
    69. QToolButton *italicBtn;
    70. QToolButton *underlineBtn;
    71. QToolButton *colorBtn;
    72. QToolBar *fontToolBar; //字体工具栏
    73. QToolBar *listToolBar; //排序工具栏
    74. //排序设置项
    75. QLabel *listLabel;
    76. QComboBox *listComboBox;
    77. QActionGroup *actGrp;
    78. QAction *leftAction;
    79. QAction *rightAction;
    80. QAction *centerAction;
    81. QAction *justifyAction;
    82. protected slots:
    83. void ShowNewFile();
    84. void ShowOpenFile();
    85. void ShowPrintText();
    86. void ShowPrintImage();
    87. void ShowZoomIn();
    88. void ShowZoomOut();
    89. void ShowRotate90();
    90. void ShowRotate180();
    91. void ShowRotate270();
    92. void ShowMirrorVertical();
    93. void ShowMirrorHorizontal();
    94. void ShowFontComboBox(QString comboStr);
    95. void ShowSizeSpinBox(QString spinValue);
    96. void ShowBoldBtn();
    97. void ShowItalicBtn();
    98. void ShowUnderlineBtn();
    99. void ShowColorBtn();
    100. void ShowCurrentFormatChanged(const QTextCharFormat &fmt);
    101. void ShowList(int);
    102. void ShowAlignment(QAction *act);
    103. void ShowCursorPositionChanged();
    104. };
    105. #endif // IMGPROCESSOR_H

    二、源文件

    1. #include "imgprocessor.h"
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. ImgProcessor::ImgProcessor(QWidget *parent)
    13. : QMainWindow(parent)
    14. {
    15. setWindowTitle(tr("Easy Word")); //设置窗体标题
    16. showWidget = new ShowWidget(this);
    17. setCentralWidget(showWidget);
    18. //在工具栏上嵌入控件
    19. //设置字体
    20. fontLabel1 = new QLabel(tr("字体:"));
    21. fontComboBox = new QFontComboBox;
    22. fontComboBox->setFontFilters(QFontComboBox::ScalableFonts);
    23. fontLabel2 = new QLabel(tr("字号:"));
    24. sizeComboBox = new QComboBox;
    25. QFontDatabase db;
    26. foreach (int size, db.standardSizes()) {
    27. sizeComboBox->addItem(QString::number(size));
    28. }
    29. boldBtn = new QToolButton;
    30. boldBtn->setIcon(QIcon("bold.png"));
    31. boldBtn->setCheckable(true);
    32. italicBtn = new QToolButton;
    33. italicBtn->setIcon(QIcon("italic.png"));
    34. italicBtn->setCheckable(true);
    35. underlineBtn = new QToolButton;
    36. underlineBtn->setIcon(QIcon("underline.png"));
    37. underlineBtn->setCheckable(true);
    38. colorBtn = new QToolButton;
    39. colorBtn->setIcon(QIcon("color.png"));
    40. colorBtn->setCheckable(true);
    41. //排序
    42. listLabel = new QLabel(tr("排序"));
    43. listComboBox = new QComboBox;
    44. listComboBox->addItem("Standard");
    45. listComboBox->addItem("QTextListFormat::ListDisc");
    46. listComboBox->addItem(&#
  • 相关阅读:
    Unity中Shader的Lambert光照的实现
    Linux内核中竞态学习过程的问题
    『忘了再学』Shell基础 — 16、位置参数变量
    正则表达式
    小黑受到了封校的恐惧,秋招结束该何去何从的日常积累:进程初步
    重新定义分析 - EventBridge 实时事件分析平台发布
    Python基础(6-1)函数
    Scrapy设置代理IP方法(超详细)
    【深度学习 & 推荐系统 & 基础知识篇】基于内容的推荐,基于协同过滤的推荐;余弦相似度:定义、在科研中的应用。传统的推荐方法 | 校招题目:UML中的动态视图有:...
    Mysql 查询表参考
  • 原文地址:https://blog.csdn.net/navymei10220214/article/details/127438567