#include "myword.h"
#include <QtWidgets>
#include "mychild.h"
const QString rsrcPath = ":/images";
MyWord::MyWord(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()));
windowMapper = new QSignalMapper(this);
connect(windowMapper, SIGNAL(mapped(QWidget*)),this, SLOT(setActiveSubWindow(QWidget*)));
createActions();
createMenus();
createToolBars();
createStatusBar();
updateMenus();
move(200,150);
resize(800,500);
setWindowTitle(tr("Myself Word"));
setUnifiedTitleAndToolBarOnMac(true);
}
MyWord::~MyWord()
{
}
void MyWord::closeEvent(QCloseEvent *event)
{
mdiArea->closeAllSubWindows();
if (mdiArea->currentSubWindow()) {
event->ignore();
} else {
event->accept();
}
}
void MyWord::updateMenus()
{
//至少有一个子文档打开着的情况
bool hasMyChild = (activeMyChild()!=0);
saveAct->setEnabled(hasMyChild);
saveAsAct->setEnabled(hasMyChild);
printAct->setEnabled(hasMyChild);
printPreviewAct->setEnabled(hasMyChild);
pasteAct->setEnabled(hasMyChild);
closeAct->setEnabled(hasMyChild);
closeAllAct->setEnabled(hasMyChild);
tileAct->setEnabled(hasMyChild);
cascadeAct->setEnabled(hasMyChild);
nextAct->setEnabled(hasMyChild);
previousAct->setEnabled(hasMyChild);
separatorAct->setVisible(hasMyChild);
//文档打开着并且其中有内容被选中的情况
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);
}
void MyWord::updateWindowMenu()
{
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<QMdiSubWindow *> windows = mdiArea->subWindowList();
separatorAct->setVisible(!windows.isEmpty());
//显示当前打开着的文档子窗口项
for (int i = 0; i < windows.size(); ++i) {
MyChild *child = qobject_cast<MyChild *>(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());
}
QAction *action = windowMenu->addAction(text);
action->setCheckable(true);
action ->setChecked(child == activeMyChild());
connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
windowMapper->setMapping(action, windows.at(i));
}
enabledText(); //使得字体设置菜单可用
}
MyChild *MyWord::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 MyWord::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("打开已存在的文档"));
connect(openAct, SIGNAL(triggered()), this, SLOT(fileOpen()));
saveAct = new QAction(QIcon(rsrcPath + "/filesave.png"), tr("保存(&S)"), this);
saveAct->setShortcuts(QKeySequence::Save);
saveAct->setToolTip("保存");
saveAct->setStatusTip(tr("将当前文档存盘"));
connect(saveAct, SIGNAL(triggered()), this, SLOT(fileSave()));
saveAsAct = new QAction(tr("另存为(&A)..."), this);
saveAsAct->setShortcuts(QKeySequence::SaveAs);
saveAsAct->setStatusTip(tr("以一个新名字保存文档"));
connect(saveAsAct, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
printAct = new QAction(QIcon(rsrcPath + "/fileprint.png"), tr("打印(&P)..."), this);
printAct->setShortcuts(QKeySequence::Print);
printAct->setToolTip("打印");
printAct->setStatusTip(tr("打印文档"));
connect(printAct, SIGNAL(triggered()), this, SLOT(filePrint()));
printPreviewAct = new QAction(tr("打印预览..."), this);
printPreviewAct->setStatusTip(tr("预览打印效果"));
connect(printPreviewAct, SIGNAL(triggered()), this, SLOT(filePrintPreview()));
exitAct = new QAction(tr("退出(&X)"), this);
exitAct->setShortcuts(QKeySequence::Quit);
exitAct->setStatusTip(tr("退出应用程序"));
connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); //不用自己实现
/*【编辑】菜单动作集*/
undoAct = new QAction(QIcon(rsrcPath + "/editundo.png"),tr("撤销(&U)"), this);
undoAct->setShortcut(QKeySequence::Undo);
undoAct->setToolTip("撤销");
undoAct->setStatusTip(tr("撤销当前操作"));
connect(undoAct, SIGNAL(triggered()), this, SLOT(undo())); //不用子窗口类去实现
redoAct = new QAction(QIcon(rsrcPath + "/editredo.png"),tr("重做(&R)"), this);
redoAct->setShortcut(QKeySequence::Redo);
redoAct->setToolTip("重做");
redoAct->setStatusTip(tr("恢复之前操作"));
connect(redoAct, SIGNAL(triggered()), this, SLOT(redo())); //不用子窗口类去实现
cutAct = new QAction(QIcon(rsrcPath + "/editcut.png"),tr("剪切(&T)"), this);
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setToolTip("剪切");
cutAct->setStatusTip(tr("从文档中裁剪所选内容,并将其放入剪贴板"));
connect(cutAct, SIGNAL(triggered()), this, SLOT(cut())); //不用子窗口类去实现
copyAct = new QAction(QIcon(rsrcPath + "/editcopy.png"),tr("复制(&C)"), this);
copyAct->setShortcuts(QKeySequence::Copy);
copyAct->setToolTip("复制");
copyAct->setStatusTip(tr("拷贝所选内容,并将其放入剪贴板"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copy())); //不用子窗口类去实现
pasteAct = new QAction(QIcon(rsrcPath + "/editpaste.png"),tr("粘贴(&P)"), this);
pasteAct->setShortcuts(QKeySequence::Paste);
pasteAct->setToolTip("粘贴");
pasteAct->setStatusTip(tr("将剪贴板的内容粘贴到文档"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste())); //不用子窗口类去实现
/*【格式】菜单动作集*/
boldAct = new QAction(QIcon(rsrcPath + "/textbold.png"),tr("加粗(&B)"), this);
boldAct->setCheckable(true);
boldAct->setShortcut(Qt::CTRL + Qt::Key_B);
boldAct->setToolTip("加粗");
boldAct->setStatusTip(tr("将所选文字加粗"));
QFont
没有合适的资源?快使用搜索试试~ 我知道了~
QT5开发及实例配套源代码.zip
共393个文件
cpp:161个
h:93个
pro:71个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 46 浏览量
2024-05-28
20:09:15
上传
评论 1
收藏 578KB ZIP 举报
温馨提示
QT5开发及实例配套[源代码],Qt是诺基亚公司的C++可视化开发平台,本书以Qt 5作为平台,每个章节在简单介绍开发环境的基础上,用一个小实例,介绍Qt 5应用程序开发各个方面,然后系统介绍Qt 5应用程序的开发技术,一般均通过实例介绍和讲解内容。最后通过三个大实例,系统介绍Qt 5综合应用开发。光盘中包含本书教学课件和书中所有实例源代码及其相关文件。通过学习本书,结合实例上机练习,一般能够在比较短的时间内掌握Qt 5应用技术。本书既可作为Qt 5的学习和参考用书,也可作为大学教材或Qt 5培训用书。
资源推荐
资源详情
资源评论
收起资源包目录
QT5开发及实例配套源代码.zip (393个子文件)
myword.cpp 24KB
imgprocessor.cpp 18KB
widget.cpp 13KB
mainwidget.cpp 13KB
widget.cpp 9KB
mainwindow.cpp 9KB
mainwindow.cpp 7KB
editdialog.cpp 6KB
drawer.cpp 6KB
histogramview.cpp 6KB
mychild.cpp 5KB
palette.cpp 5KB
widget.cpp 5KB
eventfilter.cpp 4KB
dialog.cpp 4KB
connectdlg.cpp 4KB
fileinfo.cpp 4KB
mapwidget.cpp 4KB
server.cpp 4KB
drawer.cpp 4KB
mainwidget.cpp 4KB
geometry.cpp 4KB
main.cpp 4KB
msgboxdlg.cpp 4KB
tcpclient.cpp 4KB
inputdlg.cpp 3KB
timeclient.cpp 3KB
dialog.cpp 3KB
client.cpp 3KB
mainwindow.cpp 3KB
pieview.cpp 3KB
keyevent.cpp 3KB
extensiondlg.cpp 3KB
mainwindow.cpp 3KB
baseinfo.cpp 2KB
paintarea.cpp 2KB
progressdlg.cpp 2KB
networkinformation.cpp 2KB
main.cpp 2KB
fileview.cpp 2KB
mainwindow.cpp 2KB
modelex.cpp 2KB
dockwindows.cpp 2KB
drawwidget.cpp 2KB
main.cpp 1KB
butterfly.cpp 1KB
mouseevent.cpp 1KB
langswitch.cpp 1KB
udpserver.cpp 1KB
digiclock.cpp 1KB
contact.cpp 1KB
combodelegate.cpp 1KB
detail.cpp 1KB
udpclient.cpp 1KB
datedelegate.cpp 1KB
dialog.cpp 1KB
server.cpp 1KB
main.cpp 1KB
threaddlg.cpp 1KB
logindialog.cpp 1KB
main.cpp 1KB
main.cpp 1KB
mainwindow.cpp 1KB
tcpserver.cpp 1KB
spindelegate.cpp 1KB
tst_testqstring.cpp 1KB
main.cpp 1KB
svgwindow.cpp 1KB
shapewidget.cpp 1007B
dialog.cpp 994B
stackdlg.cpp 988B
main.cpp 985B
tst_testarea.cpp 913B
widget.cpp 912B
watcher.cpp 823B
dialog.cpp 816B
content.cpp 807B
flashitem.cpp 739B
timethread.cpp 711B
mainwindow.cpp 682B
main.cpp 665B
svgwidget.cpp 616B
main.cpp 602B
tcpclientsocket.cpp 580B
dialog.cpp 569B
main.cpp 536B
main.cpp 534B
main.cpp 525B
tst_testqstring2.cpp 491B
mywidget.cpp 488B
main.cpp 488B
timeserver.cpp 479B
main.cpp 476B
tst_testarea.cpp 428B
main.cpp 424B
main.cpp 404B
main.cpp 384B
pixitem.cpp 383B
main.cpp 382B
mainwindow.cpp 373B
共 393 条
- 1
- 2
- 3
- 4
资源评论
- 龙治宇2024-10-20感谢资源主分享的资源解决了我当下的问题,非常有用的资源。
GJZGRB
- 粉丝: 2939
- 资源: 7737
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功