#include "text_editor.h"
text_editor::text_editor(QWidget *parent)
: QMainWindow(parent)
{
/* 界面设计 */
this->resize(860,640);
stbar_state = true;
tb_state = true;
/* 状态栏 */
stbar = statusBar();
status_lab1 = new QLabel("text");
status_lab1->adjustSize();
status_lab2 = new QLabel();
status_lab1->adjustSize();
status_lab3 = new QLabel();
status_lab1->adjustSize();
status_lab4 = new QLabel();
status_lab1->adjustSize();
stbar->addPermanentWidget(status_lab1);
stbar->addWidget(status_lab2);
stbar->addWidget(status_lab3);
stbar->addWidget(status_lab4);
/* 标题栏 */
setWindowTitle("Text Editor");
setWindowIcon(QIcon(":/icon/title.jpg"));
/*菜单栏 */
/*菜单栏*/
QMenu *menu_file = menuBar()->addMenu("文件");
QMenu *menu_font = menuBar()->addMenu("字体");
QMenu *menu_edit = menuBar()->addMenu("编辑");
QMenu *menu_read = menuBar()->addMenu("查看");
help = menuBar()->addAction("帮助");
/*动作*/
file_open = new QAction(QIcon(":/icon/open.png"),"打开文件");
file_new = new QAction(QIcon(":/icon/add.png"),"新建");
file_save = new QAction(QIcon(":/icon/save.png"),"保存");
file_exit = new QAction(QIcon(":/icon/exit.png"),"退出");
font_color = new QAction(QIcon(":/icon/color.png"),"颜色");
font = new QAction(QIcon(":/icon/font.png"),"字体");
edit_copy = new QAction(QIcon(":/icon/copy.png"),"复制");
edit_paste = new QAction(QIcon(":/icon/paste.png"),"粘贴");
read_resize = new QAction(QIcon(":/icon/resize.png"),"工具栏");
read_stbar = new QAction(QIcon(":/icon/status.png"),"状态栏");
//添加动作
menu_file->addAction(file_open);
menu_file->addAction(file_new);
menu_file->addAction(file_save);
menu_file->addAction(file_exit);
menu_font->addAction(font_color);
menu_font->addAction(font);
menu_edit->addAction(edit_copy);
menu_edit->addAction(edit_paste);
menu_read->addAction(read_resize);
menu_read->addAction(read_stbar);
/*工具栏 */
tb = addToolBar("工具");
tb->addAction(file_open);
tb->addAction(file_new);
tb->addAction(file_save);
tb->addAction(file_exit);
tb->addAction(font_color);
tb->addAction(font);
tb->addAction(edit_copy);
tb->addAction(edit_paste);
tb->addAction(read_resize);
tb->addAction(read_stbar);
/*中央窗口 */
tabwdgt = new QTabWidget();
tabwdgt->setTabsClosable(true);
setCentralWidget(tabwdgt);
QTextEdit *te = new QTextEdit;
tabwdgt->addTab(te,"new.txt");
/* action connect */
connect(file_open,SIGNAL(triggered(bool)),this,SLOT(on_action_file_open()));
connect(file_new,SIGNAL(triggered(bool)),this,SLOT(on_action_file_new()));
connect(file_save,SIGNAL(triggered(bool)),this,SLOT(on_action_file_save()));
connect(file_exit,SIGNAL(triggered(bool)),this,SLOT(on_action_file_exit()));
connect(font,SIGNAL(triggered(bool)),this,SLOT(on_action_font()));
connect(font_color,SIGNAL(triggered(bool)),this,SLOT(on_action_font_color()));
connect(edit_copy,SIGNAL(triggered(bool)),this,SLOT(on_action_edit_copy()));
connect(edit_paste,SIGNAL(triggered(bool)),this,SLOT(on_action_edit_paste()));
connect(read_resize,SIGNAL(triggered(bool)),this,SLOT(on_action_read_resize()));
connect(read_stbar,SIGNAL(triggered(bool)),this,SLOT(on_action_read_stbar()));
connect(help,SIGNAL(triggered(bool)),this,SLOT(on_action_help()));
connect(tabwdgt,SIGNAL(tabCloseRequested(int)),this,SLOT(on_tabwdgt_tabCloseRequested(int)));
}
text_editor::~text_editor()
{
}
void text_editor::on_action_file_open()
{
QString pathname = QFileDialog::getOpenFileName(this,".");
if(pathname.isEmpty())
{
return ;
}
QList<QString> str_tmp = pathname.split("/");
QString filename = str_tmp.at(str_tmp.size()-1);
//open file
QTextEdit *te = new QTextEdit;
int index = tabwdgt->addTab(te,filename);
tabwdgt->setCurrentIndex(index);
}
void text_editor::on_action_file_save()
{
QString pathname = QFileDialog::getSaveFileName(this, "保存文件",".","Text (*.text)");
if(pathname.isEmpty())
{
return ;
}
QList<QString> str_tmp = pathname.split("/");
QString filename = str_tmp.at(str_tmp.size()-1);
//save file
tabwdgt->setTabText(tabwdgt->currentIndex(),filename);
}
void text_editor::on_action_file_exit()
{
int ret = QMessageBox::warning(this,"Save","是否保存所有文件至源文件夹、默认文件夹,未保存可能丢失数据",QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,QMessageBox::Yes);
if(QMessageBox::Yes == ret)
{
//save all
}
else if (QMessageBox::Cancel == ret) {
return;
}
this->close();
}
void text_editor::on_action_file_new()
{
QTextEdit *te = new QTextEdit;
int index = tabwdgt->addTab(te,"new.txt");
tabwdgt->setCurrentIndex(index);
}
void text_editor::on_action_font_color()
{
QColor color = QColorDialog::getColor();
if(color.isValid())
{
QTextEdit * tmp = dynamic_cast <QTextEdit*> (tabwdgt->currentWidget());
tmp->setTextColor(color);
}
}
void text_editor::on_action_font()
{
bool ok;
QFont font = QFontDialog::getFont(&ok);
if(ok)
{
QTextEdit * tmp = dynamic_cast <QTextEdit*> (tabwdgt->currentWidget());
tmp->setFont(font);
}
}
void text_editor::on_action_edit_copy()
{
QTextEdit * tmp = dynamic_cast <QTextEdit*> (tabwdgt->currentWidget());
tmp->copy();
}
void text_editor::on_action_edit_paste()
{
QTextEdit * tmp = dynamic_cast <QTextEdit*> (tabwdgt->currentWidget());
tmp->paste();
}
void text_editor::on_action_read_resize()
{
if(tb_state)
{
tb->hide();
tb_state = false;
}
else if(!tb_state)
{
tb->show();
tb_state = true;
}
}
void text_editor::on_action_read_stbar()
{
if(stbar_state)
{
stbar->hide();
stbar_state = false;
}
else if(!stbar_state)
{
stbar->show();
stbar_state = true;
}
}
void text_editor::on_action_help()
{
QTextEdit *te = new QTextEdit("Help me!!!!!");
int index = tabwdgt->addTab(te,"help");
tabwdgt->setCurrentIndex(index);
}
//缺乏文件操作
void text_editor::on_tabwdgt_tabCloseRequested(int index)
{
int ret = QMessageBox::warning(this,"Save","是否保存,未保存可能丢失数据",QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,QMessageBox::Yes);
if(QMessageBox::Yes == ret)
{
QString pathname = QFileDialog::getSaveFileName(this, "保存文件",".","Text (*.text)");
if(pathname.isEmpty())
{
return ;
}
QList<QString> str_tmp = pathname.split("/");
QString filename = str_tmp.at(str_tmp.size()-1);
//save
}
else if (QMessageBox::Cancel == ret) {
return;
}
tabwdgt->removeTab(index);
}
没有合适的资源?快使用搜索试试~ 我知道了~
qt简易文本编辑器_qt_bg.qm_QT_文本编辑器_TextEditor_
共77个文件
dll:23个
qm:21个
png:20个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 123 浏览量
2021-10-02
09:00:51
上传
评论 2
收藏 18.77MB ZIP 举报
温馨提示
用qt写的一个文本编辑器。类似windows自带的text。
资源推荐
资源详情
资源评论
收起资源包目录
qt简易文本编辑器.zip (77个子文件)
.exe
Qt5Svg.dll 352KB
libGLESV2.dll 2.68MB
Qt5Widgets.dll 5.96MB
iconengines
qsvgicon.dll 43KB
libwinpthread-1.dll 78KB
styles
qwindowsvistastyle.dll 192KB
Qt5Gui.dll 6.19MB
Qt5Core.dll 5.93MB
text_editor.exe 189KB
libgcc_s_dw2-1.dll 118KB
libEGL.dll 22KB
platforms
qwindows.dll 1.82MB
opengl32sw.dll 15.25MB
D3Dcompiler_47.dll 3.31MB
translations
qt_fi.qm 176KB
qt_cs.qm 171KB
qt_ca.qm 176KB
qt_es.qm 161KB
qt_gd.qm 185KB
qt_lv.qm 150KB
qt_uk.qm 155KB
qt_sk.qm 123KB
qt_pl.qm 159KB
qt_hu.qm 157KB
qt_ru.qm 173KB
qt_en.qm 23B
qt_it.qm 157KB
qt_da.qm 170KB
qt_ar.qm 156KB
qt_de.qm 188KB
qt_fr.qm 162KB
qt_he.qm 135KB
qt_bg.qm 161KB
qt_ja.qm 127KB
qt_ko.qm 128KB
libstdc++-6.dll 1.47MB
imageformats
qtga.dll 26KB
qgif.dll 33KB
qwebp.dll 445KB
qtiff.dll 496KB
qwbmp.dll 25KB
qsvg.dll 27KB
qicns.dll 45KB
qjpeg.dll 323KB
qico.dll 35KB
源码
text_editor.pro.user 23KB
text_editor.h 2KB
main.cpp 185B
text_editor.pro 1KB
text_editor.cpp 7KB
icon
edit_1.png 3KB
open.png 11KB
EditDoc.png 2KB
copy.png 3KB
title.jpg 5KB
icon_rec.qrc 38B
edit_3.png 2KB
smart_house.ico 9KB
resize.png 944B
font.png 11KB
close.png 9KB
saveas.png 20KB
play_button_72px_1236468_easyicon.net.ico 21KB
save.png 5KB
exit.png 600B
add.png 1KB
play.png 19KB
new.png 16KB
paste.png 5KB
warning.png 2KB
edit_2.png 2KB
status.png 691B
delete.png 1KB
color.png 21KB
res.qrc 38B
res.qrc 1KB
描述文件.docx 41KB
共 77 条
- 1
资源评论
- qq_26086942832023-07-02资源是宝藏资源,实用也是真的实用,感谢大佬分享~
- Y.517012021-11-01用户下载后在一定时间内未进行评价,系统默认好评。
- to_conquer2022-09-03资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
- 瘤子1352024-01-03资源内容详细全面,与描述一致,对我很有用,有一定的使用价值。
呼啸庄主
- 粉丝: 74
- 资源: 4702
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功