diff --git a/WorldDemo/WorldDemo.pro b/WorldDemo/WorldDemo.pro
new file mode 100644
index 0000000000000000000000000000000000000000..ece86cab2836ec24ac7117b18c5a2b366f39d32e
--- /dev/null
+++ b/WorldDemo/WorldDemo.pro
@@ -0,0 +1,30 @@
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+ main.cpp \
+ mychild.cpp \
+ worddemo.cpp
+
+HEADERS += \
+ mychild.h \
+ worddemo.h
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
diff --git a/WorldDemo/WorldDemo.pro.user b/WorldDemo/WorldDemo.pro.user
new file mode 100644
index 0000000000000000000000000000000000000000..828650ac6ee34bd8b8cf8cfd8aa45ce1b6a36667
--- /dev/null
+++ b/WorldDemo/WorldDemo.pro.user
@@ -0,0 +1,320 @@
+
+
+
+
+
+ EnvironmentId
+ {cddfeb80-a183-4222-bfde-35fddd361409}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ -fno-delayed-template-parsing
+
+ true
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.14.0 MinGW 64-bit
+ Desktop Qt 5.14.0 MinGW 64-bit
+ qt.qt5.5140.win64_mingw73_kit
+ 0
+ 0
+ 0
+
+ F:/Qt/Example/build-WorldDemo-Desktop_Qt_5_14_0_MinGW_64_bit-Debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ false
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+
+
+ F:/Qt/Example/build-WorldDemo-Desktop_Qt_5_14_0_MinGW_64_bit-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ true
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+
+
+ F:/Qt/Example/build-WorldDemo-Desktop_Qt_5_14_0_MinGW_64_bit-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ true
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ dwarf
+
+ cpu-cycles
+
+
+ 250
+
+ -e
+ cpu-cycles
+ --call-graph
+ dwarf,4096
+ -F
+ 250
+
+ -F
+ true
+ 4096
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ kcachegrind
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ WorldDemo2
+ Qt4ProjectManager.Qt4RunConfiguration:F:/Qt/Example/qt_learning_demo/WorldDemo/WorldDemo.pro
+ F:/Qt/Example/qt_learning_demo/WorldDemo/WorldDemo.pro
+
+ false
+
+ false
+ true
+ true
+ false
+ false
+ true
+
+ F:/Qt/Example/build-WorldDemo-Desktop_Qt_5_14_0_MinGW_64_bit-Debug
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/WorldDemo/main.cpp b/WorldDemo/main.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3255846b7add1fc3c785336c4acdb7b61e465cc5
--- /dev/null
+++ b/WorldDemo/main.cpp
@@ -0,0 +1,15 @@
+#include "worddemo.h"
+
+#include
+
+QApplication* qpp;
+
+int main(int argc, char *argv[])
+{
+// QApplication a(argc, argv);
+ qpp = new QApplication(argc, argv);
+ WordDemo w;
+ w.show();
+// return a.exec();
+ return qpp->exec();
+}
diff --git a/WorldDemo/mychild.cpp b/WorldDemo/mychild.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cba201de0a1fe0470bc1ddece8a9838c4c9efbc3
--- /dev/null
+++ b/WorldDemo/mychild.cpp
@@ -0,0 +1,40 @@
+#include "mychild.h"
+#include
+#include
+
+MyChild::MyChild()
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ isUntitled = true;
+}
+
+void MyChild::newFile()
+{
+ static int sequenceNumber = 1;
+ isUntitled = true;
+ curFile = tr("doc %1").arg(sequenceNumber++);
+ setWindowTitle(curFile + "[*]" + tr(" - WordDemo"));
+
+ connect(document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
+}
+
+void MyChild::documentWasModified()
+{
+ setWindowModified(document()->isModified());
+}
+
+QString MyChild::userFriendlyCurrentFile()
+{
+ return strippedName(curFile);
+}
+
+QString MyChild::strippedName(const QString &fullFileName)
+{
+ return QFileInfo(fullFileName).fileName();
+}
+
+void MyChild::closeEvent(QCloseEvent *event)
+{
+ event->accept();
+}
diff --git a/WorldDemo/mychild.h b/WorldDemo/mychild.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b3e54f9fdfd6191648404528bc2b9e89da3b298
--- /dev/null
+++ b/WorldDemo/mychild.h
@@ -0,0 +1,29 @@
+#ifndef MYCHILD_H
+#define MYCHILD_H
+
+#include
+#include
+
+class MyChild : public QTextEdit
+{
+ Q_OBJECT
+public:
+ MyChild();
+ void newFile();
+ QString userFriendlyCurrentFile();
+ QString currentFile(){return curFile;}
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void documentWasModified();
+
+private:
+ QString strippedName(const QString &fullFileName);
+
+ QString curFile;
+ bool isUntitled;
+};
+
+#endif // MYCHILD_H
diff --git a/WorldDemo/worddemo.cpp b/WorldDemo/worddemo.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5a61687450de9f3f05be7581936448e7e866d586
--- /dev/null
+++ b/WorldDemo/worddemo.cpp
@@ -0,0 +1,462 @@
+#include "worddemo.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+extern QApplication *qpp;
+
+WordDemo::WordDemo(QWidget *parent)
+ : QMainWindow(parent)
+{
+ mdiArea = new QMdiArea;
+ mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ setCentralWidget(mdiArea);
+ connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(updateMenus()));
+
+
+ //create signal mapper
+ windowMapper = new QSignalMapper(this);
+ connect(windowMapper, SIGNAL(mapped(QWidget *)), this, SLOT(setActiveSubWindow(QWidget *)));
+
+ move(200, 150);
+ resize(800, 500);
+ setWindowTitle(tr("Word Demo"));
+
+ createActions();
+ createMenus();
+ updateMenus();
+ rsrcPath = ":/images";
+}
+
+WordDemo::~WordDemo()
+{
+}
+
+void WordDemo::createActions()
+{
+ newAct = new QAction(QIcon(rsrcPath + "/filenew.png"), tr("新建(&N)"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setToolTip("新建");
+ newAct->setStatusTip(tr("创建一个新文档"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(fileNew()));
+
+ openAct = new QAction(QIcon(rsrcPath + "/fileopen.png"), tr("打开(&O)"), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setToolTip("打开");
+ openAct->setStatusTip(tr("打开一个已存在的文档"));
+
+ saveAct = new QAction(QIcon(rsrcPath + "/filesave.png"), tr("保存(&S)"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("将当前文档存盘"));
+
+ saveAsAct = new QAction(tr("另存为(&A"), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("以新名字保存文档"));
+
+ printAct = new QAction(QIcon(rsrcPath + "/fileprint.png"), tr("打印(&P"), this);
+ printAct->setShortcuts(QKeySequence::Print);
+ printAct->setToolTip("打印");
+ printAct->setStatusTip(tr("打印文档"));
+
+ printPrevierewAct = new QAction(tr("打印预览"), this);
+ printPrevierewAct->setStatusTip(tr("打印预览效果"));
+
+ exitAct = new QAction(tr("退出(&X)"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ exitAct->setStatusTip(tr("退出应用程序"));
+ connect(exitAct, SIGNAL(triggered()), qpp, SLOT(closeAllWindows()));
+
+ //edit
+ undoAct = new QAction(QIcon(rsrcPath + "/editundo.png"), tr("撤销(&U)"), this);
+ undoAct->setShortcuts(QKeySequence::Undo);
+ undoAct->setToolTip("撤销");
+ undoAct->setStatusTip(tr("撤销当前操作"));
+
+ redoAct = new QAction(QIcon(rsrcPath + "/editredo.png"), tr("重做(&R)"), this);
+ redoAct->setShortcuts(QKeySequence::Redo);
+ redoAct->setToolTip("重做");
+ redoAct->setStatusTip(tr("恢复之前操作"));
+
+ cutAct = new QAction(QIcon(rsrcPath + "/editcut.png"), tr("剪切(&T)"), this);
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setToolTip("剪切");
+ cutAct->setStatusTip(tr("从文档中剪切所选内容,并将其放入剪贴板"));
+
+ copyAct = new QAction(QIcon(rsrcPath + "/editcopy.png"), tr("复制(&C)"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setToolTip("复制");
+ copyAct->setStatusTip(tr("复制所选内容,并将其放入剪贴板"));
+
+ pasteAct = new QAction(QIcon(rsrcPath + "/editpaste.png"), tr("粘贴(&P)"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setToolTip("粘贴");
+ pasteAct->setStatusTip(tr("将剪贴板的内容粘贴到文档中"));
+
+ //format
+ boldAct = new QAction(QIcon(rsrcPath + "/textbold.png"), tr("Bold(&B)"), this);
+ boldAct->setChecked(true);
+ boldAct->setShortcut(Qt::CTRL + Qt::Key_B);
+ boldAct->setToolTip("加粗");
+ boldAct->setStatusTip(tr("将所选文字加粗"));
+ QFont bold;
+ bold.setBold(true);
+ boldAct->setFont(bold);
+
+ italicAct = new QAction(QIcon(rsrcPath + "/textitalic.png"), tr("Italic(&I)"), this);
+ italicAct->setChecked(true);
+ italicAct->setShortcut(Qt::CTRL + Qt::Key_I);
+ italicAct->setToolTip("Italic");
+ italicAct->setStatusTip(tr("将所选文件用斜体显示"));
+ QFont italic;
+ italic.setItalic(true);
+ italicAct->setFont(italic);
+
+ underlineAct = new QAction(QIcon(rsrcPath + "/textunder.png"), tr("UnderLine(&U)"), this);
+ underlineAct->setChecked(true);
+ underlineAct->setShortcut(Qt::CTRL + Qt::Key_U);
+ underlineAct->setToolTip("UnderLine");
+ underlineAct->setStatusTip(tr("为所选文字加入下划线"));
+ QFont underline;
+ underline.setUnderline(true);
+ underlineAct->setFont(underline);
+
+ //group
+ QActionGroup *grp = new QActionGroup(this);
+ connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(textAlign(QAction *)));
+ if(QApplication::isLeftToRight())
+ {
+ leftAlignAct = new QAction(QIcon(rsrcPath + "/textleft.png"), tr("Left(&L"), grp);
+ centerAct = new QAction(QIcon(rsrcPath + "/textcenter.png"), tr("Center(&E)"), grp);
+ rightAlignAct = new QAction(QIcon(rsrcPath + "/textright.png"), tr("Right(&R)"), grp);
+ }
+ else{
+ rightAlignAct = new QAction(QIcon(rsrcPath + "/textright.png"), tr("Right(&R)"), grp);
+ centerAct = new QAction(QIcon(rsrcPath + "/textcenter.png"), tr("Center(&E)"), grp);
+ leftAlignAct = new QAction(QIcon(rsrcPath + "/textleft.png"), tr("Left(&L"), grp);
+ }
+
+ leftAlignAct->setShortcut(Qt::CTRL + Qt::Key_L);
+ leftAlignAct->setCheckable(true);
+ leftAlignAct->setToolTip("LeftAlign");
+ leftAlignAct->setStatusTip(tr("将文字左对齐"));
+
+ centerAct->setShortcut(Qt::CTRL + Qt::Key_E);
+ centerAct->setCheckable(true);
+ centerAct->setStatusTip(tr("将文字居中对齐"));
+
+ rightAlignAct->setShortcut(Qt::CTRL + Qt::Key_R);
+ rightAlignAct->setChecked(true);
+ rightAlignAct->setToolTip("RightAlign");
+ rightAlignAct->setStatusTip(tr("将文字右对齐"));
+
+ justifyAct = new QAction(QIcon(rsrcPath + "/textjustify.png"), tr("Justify(&J)"), grp);
+ justifyAct->setShortcut(Qt::CTRL + Qt::Key_J);
+ justifyAct->setCheckable(true);
+ justifyAct->setStatusTip(tr("将文字两端对齐"));
+
+ QPixmap pix(16, 16);
+ pix.fill(Qt::red);
+ colorAct = new QAction(pix, tr("Color(&C)"), this);
+ colorAct->setToolTip("Color");
+ colorAct->setStatusTip(tr("设置文字颜色"));
+
+ //window
+ closeAct = new QAction(tr("Close(&O)"), this);
+ closeAct->setStatusTip(tr("关闭活动文档子窗口"));
+ connect(closeAct, SIGNAL(triggered()), mdiArea, SLOT(closeActiveSubWindow()));
+
+ closeAllAct = new QAction(tr("CloseAll(&A)"), this);
+ closeAllAct->setStatusTip(tr("关闭所有子窗口"));
+ connect(closeAllAct, SIGNAL(triggered()), mdiArea, SLOT(closeAllSubWindows()));
+
+ tileAct = new QAction(tr("Tile(&T)"), this);
+ tileAct->setStatusTip(tr("平铺子窗口"));
+ connect(tileAct, SIGNAL(triggered()), mdiArea, SLOT(tileSubWindows()));
+
+ cascadeAct = new QAction(tr("Cascade(&C)"), this);
+ cascadeAct->setShortcuts(QKeySequence::NextChild);
+ cascadeAct->setStatusTip(tr("移动焦点到下一个子窗口"));
+ connect(cascadeAct, SIGNAL(triggered()), mdiArea, SLOT(cascadeSubWindows()));
+
+ nextAct = new QAction(tr("Next(&X)"), this);
+ nextAct->setShortcuts(QKeySequence::NextChild);
+ nextAct->setStatusTip(tr("移动焦点到下一个子窗口"));
+ connect(nextAct, SIGNAL(triggered()), mdiArea, SLOT(activateNextSubWindow()));
+
+ previousAct = new QAction(tr("Previous(&V)"), this);
+ previousAct->setShortcuts(QKeySequence::PreviousChild);
+ previousAct->setStatusTip(tr("移动焦点到前一个子窗口"));
+ connect(previousAct, SIGNAL(triggered()), mdiArea, SLOT(activatePreviousSubWindow()));
+
+ separatorAct = new QAction(this);
+ separatorAct->setSeparator(true);
+
+ //help
+ aboutAct = new QAction(tr("About(&A)"), this);
+ aboutAct->setStatusTip(tr("About Word Demo"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("AboutQt(&Q)"), this);
+ aboutQtAct->setStatusTip(tr("About Qt!"));
+ connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));
+
+
+}
+
+void WordDemo::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("文件(&F)"));
+ fileMenu->addAction(newAct);
+ fileMenu->addAction(openAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(printAct);
+ fileMenu->addAction(printPrevierewAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ //edit
+ editMenu = menuBar()->addMenu(tr("Edit(&E)"));
+ editMenu->addAction(undoAct);
+ editMenu->addAction(redoAct);
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+
+ //format
+ formatMenu = menuBar()->addMenu(tr("Format(&O)"));
+ fontMenu = formatMenu->addMenu(tr("Word(&D)"));
+ fontMenu->addAction(boldAct);
+ fontMenu->addAction(italicAct);
+ fontMenu->addAction(underlineAct);
+ alignMenu = formatMenu->addMenu(tr("Align"));
+ alignMenu->addAction(leftAlignAct);
+ alignMenu->addAction(centerAct);
+ alignMenu->addAction(rightAlignAct);
+ alignMenu->addAction(justifyAct);
+ formatMenu->addAction(colorAct);
+
+ //window
+ windowMenu = menuBar()->addMenu(tr("Window(&W)"));
+ updateWindowMenu();
+ connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowMenu()));
+ menuBar()->addSeparator();
+
+ //help
+ helpMenu = menuBar()->addMenu(tr("Help(&H)"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addSeparator();
+ helpMenu->addAction(aboutQtAct);
+
+
+}
+
+void WordDemo::createToolBars()
+{
+ //file toolbar
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newAct);
+ fileToolBar->addAction(openAct);
+ fileToolBar->addAction(saveAct);
+ fileToolBar->addSeparator();
+ fileToolBar->addAction(printAct);
+
+ //edit
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(undoAct);
+ editToolBar->addAction(redoAct);
+ editToolBar->addSeparator();
+ editToolBar->addAction(cutAct);
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+
+ //format
+ formatToolBar = addToolBar(tr("Format"));
+ formatToolBar->addAction(boldAct);
+ formatToolBar->addAction(italicAct);
+ formatToolBar->addAction(underlineAct);
+ formatMenu->addSeparator();
+ formatMenu->addAction(leftAlignAct);
+ formatToolBar->addAction(centerAct);
+ formatToolBar->addAction(rightAlignAct);
+ formatToolBar->addAction(justifyAct);
+ formatToolBar->addSeparator();
+ formatToolBar->addAction(colorAct);
+
+ //group toolbar
+ addToolBarBreak(Qt::TopToolBarArea);
+ comboToolBar = addToolBar(tr("ComboToolBar"));
+ comboStyle = new QComboBox();
+ comboToolBar->addWidget(comboStyle);
+ comboStyle->addItem("标准");
+ comboStyle->addItem("Project-1");
+ comboStyle->addItem("Project-2");
+ comboStyle->addItem("Project-3");
+ comboStyle->addItem("Number-123");
+ comboStyle->addItem("Number-abc");
+ comboStyle->addItem("Number-ABC");
+ comboStyle->addItem("Number-xxx");
+ comboStyle->addItem("Number-ccc");
+ comboStyle->setStatusTip("段落加标号或编号");
+
+ comboFont = new QFontComboBox();
+ comboToolBar->addWidget(comboFont);
+ comboFont->setStatusTip(tr("Change Font"));
+
+ comboSize = new QComboBox();
+ comboToolBar->addWidget(comboSize);
+ comboSize->setEditable(true);
+ comboSize->setStatusTip("Change Font Size");
+
+ QFontDatabase db;
+ foreach(int size, db.standardSizes())
+ comboSize->addItem(QString::number(size));
+
+}
+
+MyChild *WordDemo::createMyChild()
+{
+ MyChild *child = new MyChild;
+ mdiArea->addSubWindow(child);
+
+ connect(child, SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
+ connect(child, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
+
+ return child;
+}
+
+void WordDemo::fileNew()
+{
+ MyChild *child = createMyChild();
+ child->newFile();
+ child->show();
+ enabledText();
+}
+
+void WordDemo::enabledText()
+{
+ boldAct->setEnabled(true);
+ italicAct->setEnabled(true);
+ underlineAct->setEnabled(true);
+ leftAlignAct->setEnabled(true);
+ centerAct->setEnabled(true);
+ rightAlignAct->setEnabled(true);
+ justifyAct->setEnabled(true);
+ colorAct->setEnabled(true);
+}
+
+void WordDemo::updateMenus()
+{
+ //more than one child window opened
+ bool hasMychild = (activeMyChild() != 0);
+
+ saveAct->setEnabled(hasMychild);
+ saveAsAct->setEnabled(hasMychild);
+ printAct->setEnabled(hasMychild);
+ printPrevierewAct->setEnabled(hasMychild);
+ closeAct->setEnabled(hasMychild);
+ closeAllAct->setEnabled(hasMychild);
+ tileAct->setEnabled(hasMychild);
+ cascadeAct->setEnabled(hasMychild);
+ nextAct->setEnabled(hasMychild);
+ previousAct->setEnabled(hasMychild);
+
+ separatorAct->setVisible(hasMychild);
+
+ //open child window and select that
+ bool hasSelection = (activeMyChild() && activeMyChild()->textCursor().hasSelection());
+ cutAct->setEnabled(hasSelection);
+ copyAct->setEnabled(hasSelection);
+ boldAct->setEnabled(hasSelection);
+ italicAct->setEnabled(hasSelection);
+ underlineAct->setEnabled(hasSelection);
+ leftAlignAct->setEnabled(hasSelection);
+ centerAct->setEnabled(hasSelection);
+ rightAlignAct->setEnabled(hasSelection);
+ justifyAct->setEnabled(hasSelection);
+ colorAct->setEnabled(hasSelection);
+}
+
+MyChild *WordDemo::activeMyChild()
+{
+ if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
+ return qobject_cast(activeSubWindow->widget());
+
+ return 0;
+}
+
+void WordDemo::updateWindowMenu()
+{
+ //clear menu
+ windowMenu->clear();
+ windowMenu->addAction(closeAct);
+ windowMenu->addAction(closeAllAct);
+ windowMenu->addSeparator();
+ windowMenu->addAction(tileAct);
+ windowMenu->addAction(cascadeAct);
+ windowMenu->addSeparator();
+ windowMenu->addAction(nextAct);
+ windowMenu->addAction(previousAct);
+ windowMenu->addAction(separatorAct);
+
+ QList windows = mdiArea->subWindowList();
+ separatorAct->setVisible(!windows.isEmpty());
+ //display every child windows
+ for(int i = 0; i < windows.size(); ++i)
+ {
+ MyChild *child = qobject_cast(windows.at(i)->widget());
+ QString text;
+ if(i < 9)
+ {
+ text = tr("&%1 %2").arg(i + 1).arg(child->userFriendlyCurrentFile());
+ }
+ else
+ {
+ text = tr("%1 %2").arg(i + 1).arg(child->userFriendlyCurrentFile());
+ }
+
+ //add action to menus , set enable true
+ QAction *action = windowMenu->addAction(text);
+ action->setCheckable(true);
+ //set current window is selected
+ action->setChecked(child == activeMyChild());
+ //connect action and windowMapper
+ connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
+ windowMapper->setMapping(action, windows.at(i));
+ }
+
+ enabledText(); //enable font menu
+}
+
+void WordDemo::closeEvent(QCloseEvent *event)
+{
+ mdiArea->closeAllSubWindows();
+ if(mdiArea->currentSubWindow())
+ {
+ event->ignore();
+ }
+ else
+ {
+ event->accept();
+ }
+}
+
+void WordDemo::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This is a Qt Word Demo!"));
+}
+
+void WordDemo::aboutQt()
+{
+ QMessageBox::aboutQt(this);
+}
diff --git a/WorldDemo/worddemo.h b/WorldDemo/worddemo.h
new file mode 100644
index 0000000000000000000000000000000000000000..a263760ed72b6ffc4eda3387f039295659e90e3a
--- /dev/null
+++ b/WorldDemo/worddemo.h
@@ -0,0 +1,100 @@
+#ifndef WORDDEMO_H
+#define WORDDEMO_H
+
+#include
+#include
+#include
+#include "mychild.h"
+
+class QAction;
+class QMenu;
+class QComboBox;
+class QFontComboBox;
+class MyChild;
+class QMdiSubWindow;
+class QSignalMapper;
+
+class WordDemo : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ WordDemo(QWidget *parent = nullptr);
+ ~WordDemo();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void about();
+ void aboutQt();
+ void createToolBars();
+ void fileNew(); //new file opt
+ MyChild *createMyChild();
+ void updateMenus(); // update menus
+ void updateWindowMenu();
+
+private:
+ QString rsrcPath;
+
+ QMdiArea *mdiArea;
+ QMenu *fileMenu;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *printAct;
+ QAction *printPrevierewAct;
+ QAction *exitAct;
+
+ QMenu *editMenu;
+ QAction *undoAct;
+ QAction *redoAct;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+
+ QMenu *formatMenu;
+ QMenu *fontMenu;
+ QMenu *alignMenu;
+ QAction *boldAct;
+ QAction *italicAct;
+ QAction *underlineAct;
+ QAction *leftAlignAct;
+ QAction *centerAct;
+ QAction *rightAlignAct;
+ QAction *justifyAct;
+ QAction *colorAct;
+
+ QMenu *windowMenu;
+ QAction *closeAct;
+ QAction *closeAllAct;
+ QAction *tileAct;
+ QAction *cascadeAct;
+ QAction *nextAct;
+ QAction *previousAct;
+ QAction *separatorAct;
+
+ QMenu *helpMenu;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QToolBar *formatToolBar;
+ QToolBar *comboToolBar;
+ QComboBox *comboStyle;
+ QFontComboBox *comboFont;
+ QComboBox *comboSize;
+
+ QSignalMapper *windowMapper;
+
+private:
+ void createActions();
+ void createMenus();
+ void enabledText();
+ MyChild *activeMyChild(); //activity child window
+
+
+};
+#endif // WORDDEMO_H