基于QT的文本编辑器程序源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
附录
文本编辑器代码
textedit.pro
TEMPLATE = app
TARGET = textedit
CONFIG += qt warn_on
HEADERS = textedit.h
SOURCES = textedit.cpp \
main.cpp
RESOURCES += textedit.qrc
build_all:!build_pass {
CONFIG -= build_all
CONFIG += release
}
# install
target.path = $$[QT_INSTALL_DEMOS]/textedit
sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.doc images
sources.path = $$[QT_INSTALL_DEMOS]/textedit
INSTALLS += target sources
textedit.h
#ifndef TEXTEDIT_H
#define TEXTEDIT_H
#include
#include
#include
QT_FORW ARD_DECLARE_CLASS(QAction)
QT_FORW ARD_DECLARE_CLASS(QComboBox)
QT_FORW ARD_DECLARE_CLASS(QFontComboBox)
QT_FORW ARD_DECLARE_CLASS(QTextEdit)
QT_FORW ARD_DECLARE_CLASS(QTextCharFormat) QT_FORW ARD_DECLARE_CLASS(QMenu)
class TextEdit : public QMainWindow
{
Q_OBJECT
public:
TextEdit(QWidget *parent = 0);
protected:
virtual void closeEvent(QCloseEvent *e); private:
void setupFileActions();
void setupEditActions();
void setupTextActions();
bool load(const QString &f);
bool maybeSave();
void setCurrentFileName(const QString &fileName);
private slots:
void fileNew();
void fileOpen();
bool fileSave();
bool fileSaveAs();
void filePrint();
void filePrintPreview();
void filePrintPdf();
void textBold();
void textUnderline();
void textItalic();
void textFamily(const QString &f);
void textSize(const QString &p);
void textStyle(int styleIndex);
void textColor();
void textAlign(QAction *a);
void currentCharFormatChanged(const QTextCharFormat &format);
void cursorPositionChanged();
void clipboardDataChanged();
void about();
void printPreview(QPrinter *);
private:
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
void colorChanged(const QColor &c);
void alignmentChanged(Qt::Alignment a);
QAction *actionSave,
*actionTextBold,
*actionTextUnderline,
*actionTextItalic,
*actionTextColor,
*actionAlignLeft,
*actionAlignCenter,
*actionAlignRight,
*actionAlignJustify,
*actionUndo,
*actionRedo,
*actionCut,
*actionCopy,
*actionPaste;
QComboBox *comboStyle;
QFontComboBox *comboFont;
QComboBox *comboSize;