新文件: HTYEdit

新文件:   HTYEdit.desktop
	新文件:   HTYEdit.pro
	新文件:   README.md
	新文件:   dialogfind.cpp
	新文件:   dialogfind.h
	新文件:   dialogfind.ui
	新文件:   font.png
	新文件:   icon.png
	新文件:   main.cpp
	新文件:   mainwindow.cpp
	新文件:   mainwindow.h
	新文件:   mainwindow.ui
	新文件:   mdichild.cpp
	新文件:   mdichild.h
	新文件:   preview.png
	新文件:   qtrf.qrc
	新文件:   run.png
This commit is contained in:
sonichy 2017-06-15 12:39:01 +08:00
commit 30e9f77e99
21 changed files with 1101 additions and 0 deletions

BIN
HTYEdit Normal file

Binary file not shown.

11
HTYEdit.desktop Normal file
View File

@ -0,0 +1,11 @@
[Desktop Entry]
Name=海天鹰编辑器
Comment=Edit text files
Exec=/media/sonichy/job/HY/Linux/Qt/HTYEdit/HTYEdit
Icon=/media/sonichy/job/HY/Linux/Qt/HTYEdit/icon.png
Path=/media/sonichy/job/HY/Linux/Qt/HTYEdit
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Categories=GNOME;GTK;Utility;TextEditor;

28
HTYEdit.pro Normal file
View File

@ -0,0 +1,28 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-01-10T08:44:15
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = HTYEdit
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
mdichild.cpp \
dialogfind.cpp
HEADERS += mainwindow.h \
mdichild.h \
dialogfind.h
FORMS += mainwindow.ui \
dialogfind.ui
RESOURCES += \
qtrf.qrc

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# Qt 海天鹰编辑器
![alt](preview.png)
Linux 平台基于 Qt 的文字编辑程序。
已编译好的 HTYEdit 程序适用64位Linux系统Qt5环境双击运行其他版本请自行编译。

14
dialogfind.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "dialogfind.h"
#include "ui_dialogfind.h"
DialogFind::DialogFind(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogFind)
{
ui->setupUi(this);
}
DialogFind::~DialogFind()
{
delete ui;
}

20
dialogfind.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef DIALOGFIND_H
#define DIALOGFIND_H
#include <QDialog>
namespace Ui {
class DialogFind;
}
class DialogFind : public QDialog
{
Q_OBJECT
public:
explicit DialogFind(QWidget *parent = 0);
~DialogFind();
Ui::DialogFind *ui;
};
#endif // DIALOGFIND_H

105
dialogfind.ui Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogFind</class>
<widget class="QDialog" name="DialogFind">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>176</height>
</rect>
</property>
<property name="windowTitle">
<string>查找</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>48</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>查找:</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>48</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>替换:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditFind">
<property name="geometry">
<rect>
<x>80</x>
<y>20</y>
<width>300</width>
<height>30</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEditReplace">
<property name="geometry">
<rect>
<x>80</x>
<y>60</y>
<width>300</width>
<height>30</height>
</rect>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>381</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="btnFind">
<property name="text">
<string>查找</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnReplace">
<property name="text">
<string>替换</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnReplaceAll">
<property name="text">
<string>全部替换</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="text">
<string>取消</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

BIN
font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
mahua-logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

45
mahua.md Normal file
View File

@ -0,0 +1,45 @@
![mahua](mahua-logo.jpg)
##MaHua是什么?
一个在线编辑markdown文档的编辑器
向Mac下优秀的markdown编辑器mou致敬
##MaHua有哪些功能
* 方便的`导入导出`功能
* 直接把一个markdown的文本文件拖放到当前这个页面就可以了
* 导出为一个html格式的文件样式一点也不会丢失
* 编辑和预览`同步滚动`,所见即所得(右上角设置)
* `VIM快捷键`支持方便vim党们快速的操作 (右上角设置)
* 强大的`自定义CSS`功能,方便定制自己的展示
* 有数量也有质量的`主题`,编辑器和预览区域
* 完美兼容`Github`的markdown语法
* 预览区域`代码高亮`
* 所有选项自动记忆
##有问题反馈
在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流
* 邮件(dev.hubo#gmail.com, 把#换成@)
* QQ: 287759234
* weibo: [@草依山](http://weibo.com/ihubo)
* twitter: [@ihubo](http://twitter.com/ihubo)
##捐助开发者
在兴趣的驱动下,写一个`免费`的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。
当然有钱捧个钱场右上角的爱心标志支持支付宝和PayPal捐助没钱捧个人场谢谢各位。
##感激
感谢以下的项目,排名不分先后
* [mou](http://mouapp.com/)
* [ace](http://ace.ajax.org/)
* [jquery](http://jquery.com)
##关于作者
```javascript
var ihubo = {
nickName : "草依山",
site : "http://jser.me"
}

19
main.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
/* Qt5以下
QTextCodec *tc = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForTr(tc);
QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
*/
MainWindow w;
w.show();
return app.exec();
}

375
mainwindow.cpp Normal file
View File

@ -0,0 +1,375 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mdichild.h"
#include "dialogfind.h"
#include "ui_dialogfind.h"
#include <QDesktopWidget>
#include <QMessageBox>
#include <QTextEdit>
#include <QFileDialog>
#include <QTextStream>
#include <QDebug>
#include <QTextDocumentWriter>
#include <QMdiSubWindow>
//#include <QRegularExpression> //>=Qt5.0
#include <QLabel>
#include <QDesktopServices>
#include <QPushButton>
#include <QFontDialog>
QLabel *LS1,*LS2;
QString filename="",path="";
DialogFind *dialogFind;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
LS1=new QLabel("欢迎使用海天鹰编辑器!");
LS1->setMinimumSize(500,20);
LS1->setStyleSheet("padding:0px 3px;");
//LS1->setFrameShape(QFrame::WinPanel);
//LS1->setFrameShadow(QFrame::Sunken);
LS2=new QLabel("行,列:");
LS2->setMinimumSize(20,20);
LS2->setStyleSheet("padding:0px 3px;");
//LS2->setFrameShape(QFrame::WinPanel);
//LS2->setFrameShadow(QFrame::Sunken);
ui->statusBar->addWidget(LS1);
ui->statusBar->addWidget(LS2);
connect(ui->action_quit, SIGNAL(triggered()), qApp, SLOT(quit()));
dialogFind=new DialogFind(this);
connect(dialogFind->ui->btnCancel,SIGNAL(clicked(bool)),dialogFind,SLOT(close()));
connect(dialogFind->ui->btnFind,SIGNAL(clicked(bool)),this,SLOT(find()));
connect(dialogFind->ui->btnReplace,SIGNAL(clicked(bool)),this,SLOT(replace()));
connect(dialogFind->ui->btnReplaceAll,SIGNAL(clicked(bool)),this,SLOT(replaceAll()));
QStringList Largs=QApplication::arguments();
qDebug() << Largs;
if(Largs.length()>1){
open(Largs.at(1));
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_action_aboutQt_triggered()
{
QMessageBox::aboutQt(NULL, "关于 Qt");
}
void MainWindow::on_action_about_triggered()
{
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰编辑器 1.0\n一款基于Qt的文本编辑程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页sonichy.96.lt\n参考文献:\nQMdiArea基本用法http://www.mamicode.com/info-detail-1607476.html\nhttp://www.qter.org/?page_id=161多文档编辑器\n保存http://blog.csdn.net/neicole/article/details/7330234");
aboutMB.setIconPixmap(QPixmap(":/icon.png"));
aboutMB.exec();
}
void MainWindow::on_action_changelog_triggered()
{
QMessageBox aboutMB(QMessageBox::NoIcon, "更新历史", "1.0\n2017-06\n提取打开文件的相对路径使Markdown预览能够载入相对路径图片。\n2017-03\n支持命令行打开文件和打开方式打开文件。\n查找窗口填入选中文本。\n2017-02\n根据文件扩展名选择语法高亮方案。\nJS语法高亮实验成功\nHTML语法高亮实验成功\n增加设置字体。\n设置状态栏左右边距。\n2017-01\n实现全部替换。\n设置循环查找。\n增加查找替换窗体和功能。\n根据文件扩展名决定是否使用默认程序打开如htm。\n优化保存、另存为和文本修动标题标记逻辑。\n增加撤销,重做,子窗标题文本改动标识。\n增加子窗体类实现Ctrl+滚轮缩放和保存打开文件的路径。\n增加使用默认程序预览文件。\n把上一个打开或保存的路径设置为打开或保存对话框的默认路径和文件名。\n增加放大、缩小。\n增加文本光标变化信号,光标所在行列显示在状态栏第二栏。\n状态栏分为2栏\n修复没有子窗口时预览引起的崩溃。\n增加预览功能。\n保存成功。\n修改字体颜色,背景色成功。\n新建文件成功,打开文件载入成功。\n选用QMdiArea作为主控件增加窗口标签、平铺、层叠菜单。 \n制作主要菜单。");
aboutMB.exec();
}
void MainWindow::on_action_subWindowView_triggered()
{
ui->mdiArea->setViewMode(QMdiArea::SubWindowView);
}
void MainWindow::on_action_tabbedView_triggered()
{
ui->mdiArea->setViewMode(QMdiArea::TabbedView);
}
void MainWindow::on_action_cascade_triggered()
{
ui->mdiArea->setViewMode(QMdiArea::SubWindowView);
ui->mdiArea->cascadeSubWindows(); //重叠窗体
}
void MainWindow::on_action_tile_triggered()
{
ui->mdiArea->setViewMode(QMdiArea::SubWindowView);
ui->mdiArea->tileSubWindows(); //平铺窗体
}
void MainWindow::on_action_new_triggered()
{
MdiChild *child=new MdiChild;
ui->mdiArea->addSubWindow(child);
QPalette plt=palette();
plt.setColor(QPalette::Text,QColor(Qt::white));
plt.setBrush(QPalette::Base,QBrush(Qt::black));
child->setPalette(plt);
//child->selectAll();
//child->setFontPointSize(13);
child->show();
child->setWindowTitle("未命名[*]");
setWindowModified(false);
connect(child, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged()));
LS2->setText("行,列1,0");
}
void MainWindow::on_action_open_triggered()
{//,"文本文件(.txt .htm .c .cpp .md .desktop)"
if(filename==""){
filename = QFileDialog::getOpenFileName(this, "打开文本", ".");
}else{
filename = QFileDialog::getOpenFileName(this, "打开文本", path);
}
if(!filename.isEmpty())
{
open(filename);
}
}
void MainWindow::open(QString filename)
{
MdiChild *child=new MdiChild;
ui->mdiArea->addSubWindow(child);
if(child->loadFile(filename)){
path=child->path;
LS1->setText("打开 " + child->path);
LS2->setText("行,列1,0");
connect(child, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged()));
//SyntaxHighlight();
}
}
void MainWindow::on_action_close_triggered()
{
ui->mdiArea->closeActiveSubWindow();
}
void MainWindow::on_action_save_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
path=((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path;
if(path==""){
on_action_saveas_triggered();
}else{
if(((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->save()){
LS1->setText("保存 "+((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path);
}
}
}
}
void MainWindow::on_action_saveas_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
path=((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path;
if(path==""){
filename = QFileDialog::getSaveFileName(this, "保存文本", "./未命名");
}else{
filename = QFileDialog::getSaveFileName(this, "保存文本", path);
}
if(!filename.isEmpty())
{
((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path=filename;
on_action_save_triggered();
}
}
}
void MainWindow::on_action_run_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
QString filename1=QFileInfo(((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path).fileName();
QString suffix=QFileInfo(((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path).suffix().toLower();
QString filepath=QFileInfo(((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path).absolutePath()+"/";
QString s=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->toPlainText();
//md
s.replace("#","<h1>");
s.replace("\n","</h1>");
s.replace(" ","<br>");
//s.replace(QRegExp("!\[(.*)]\((.*)"),"<img src=\\2>");
s.replace("](", "<img src="+filepath);
s.replace(")", ">");
qDebug() << s;
MdiChild *child=new MdiChild;
ui->mdiArea->addSubWindow(child);
child->show();
child->setWindowTitle("预览 "+filename1);
child->setHtml(s);
connect(child, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged()));
LS2->setText("行,列1,0 ");
if(suffix=="htm" || suffix=="html"){
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
}
}
void MainWindow::onCursorPositionChanged()
{
QTextCursor cursor = ((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
LS2->setText(QString("行,列: %1,%2").arg(cursor.blockNumber()+1).arg(cursor.columnNumber()));
}
//菜单
void MainWindow::on_action_zoomin_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->zoomIn();
}
}
void MainWindow::on_action_zoomout_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->zoomOut();
}
}
void MainWindow::on_action_undo_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->undo();
}
}
void MainWindow::on_action_redo_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->redo();
}
}
void MainWindow::on_action_find_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
dialogFind->show();
dialogFind->ui->lineEditFind->setText(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor().selectedText());
}
}
void MainWindow::find(){
if(ui->mdiArea->currentSubWindow()!=0){
QString sfind=dialogFind->ui->lineEditFind->text();
if(!((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find(sfind)){
QMessageBox MB(QMessageBox::Question, "提示", QString("找不到\"%1\",是否从头查起。").arg(sfind));
MB.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
MB.setButtonText(QMessageBox::Yes,QString(""));
MB.setButtonText(QMessageBox::No,QString(""));
if(MB.exec() == QMessageBox::Yes){
QTextCursor cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
find();
}
}
}
}
void MainWindow::replace()
{
QString sfind=dialogFind->ui->lineEditFind->text();
QString sreplace=dialogFind->ui->lineEditReplace->text();
QTextCursor cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
if(cursor.selectedText()==sfind){
cursor.insertText(sreplace);
find();
}
}
void MainWindow::replaceAll()
{
QString sfind=dialogFind->ui->lineEditFind->text();
QString sreplace=dialogFind->ui->lineEditReplace->text();
QTextCursor cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find(sfind)){
cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
if(cursor.selectedText()==sfind){
cursor.insertText(sreplace);
}
}
}
void MainWindow::on_action_font_triggered()
{
if(ui->mdiArea->currentSubWindow()!=0){
bool ok;
qDebug() << ((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->currentFont();
QFont font = QFontDialog::getFont(&ok, ((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->currentFont(), this, "选择字体");
if(ok)
{
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setCurrentFont(font);
}
}
}
void MainWindow::SyntaxHighlight(){
QTextCursor cursor;
cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
QString suffix=QFileInfo(((MdiChild*)(ui->mdiArea->currentSubWindow()->widget()))->path).suffix().toLower();
if(suffix=="htm" || suffix=="html"){
//HTML
QString str="!DOCTYPE,html,link,head,meta,body,title,style,script,p,br,pre,table,tr,td,input,div,img,a,h1,h2,h3,h4,h6,select,option,ul,ol,li,canvas,fieldset,legend,input,button";
QStringList list=str.split(",");
for(int i=0;i<list.size();i++){
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find("<"+list[i]+">")){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(255,0,0));
}
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find("<"+list[i])){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(255,0,0));
}
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find("</"+list[i]+">")){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(255,0,0));
}
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find(">")){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(255,0,0));
}
}
//HTML属性
str="id=,name=,http-equiv=,content=,width=,height=,align=,onchange=,value=,type=";
list=str.split(",");
for(int i=0;i<list.size();i++){
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find(list[i])){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(255,255,0));
}
}
}
if(suffix=="js" || suffix=="htm" || suffix=="html"){
//JS
QString str="window,event,var,new,Array(),Image(),push,document,getElementById,createElement,appendChild,console,.log,.style,backgroundColor,for,if,textContent,innerHTML,function,.src,.load,.complete,.onload,.width,.height,.value,beginPath(),lineTo,moveTo,stroke(),strokeStyle,getContext,eval,translate,textAlign,Math,.cos,.sin,.pow,.random,fillText,addEventListener,length,drawImage,.top,.bottom,.left,.right,onmousemove,onmouseup,offsetLeft,offsetRight,offsetTop,offsetBottom,offsetWidth,offsetHeight,this,options,selectedIndex,.text,setInterval,clearInterval";
QStringList list=str.split(",");
for(int i=0;i<list.size();i++){
//cursor=((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->textCursor();
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
while(((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->find(list[i],QTextDocument::FindCaseSensitively)){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextColor(QColor(0,255,0));
}
}
}
cursor.setPosition(0,QTextCursor::MoveAnchor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setWindowModified(false);
}

49
mainwindow.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow *ui;
void SyntaxHighlight();
private:
void open(QString filename);
private slots:
void on_action_new_triggered();
void on_action_open_triggered();
void on_action_close_triggered();
void on_action_save_triggered();
void on_action_saveas_triggered();
void on_action_changelog_triggered();
void on_action_aboutQt_triggered();
void on_action_about_triggered();
void on_action_subWindowView_triggered();
void on_action_tabbedView_triggered();
void on_action_cascade_triggered();
void on_action_tile_triggered();
void on_action_run_triggered();
void on_action_zoomin_triggered();
void on_action_zoomout_triggered();
void on_action_undo_triggered();
void on_action_redo_triggered();
void on_action_find_triggered();
void on_action_font_triggered();
void find();
void replace();
void replaceAll();
void onCursorPositionChanged();
};
#endif // MAINWINDOW_H

322
mainwindow.ui Normal file
View File

@ -0,0 +1,322 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>海天鹰编辑器</string>
</property>
<property name="windowIcon">
<iconset resource="qtrf.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QMdiArea" name="mdiArea">
<property name="viewMode">
<enum>QMdiArea::TabbedView</enum>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<property name="tabsMovable">
<bool>true</bool>
</property>
<property name="tabShape">
<enum>QTabWidget::Triangular</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>文件</string>
</property>
<addaction name="action_new"/>
<addaction name="action_open"/>
<addaction name="action_close"/>
<addaction name="action_save"/>
<addaction name="action_saveas"/>
<addaction name="action_quit"/>
</widget>
<widget class="QMenu" name="menu_2">
<property name="title">
<string>编辑</string>
</property>
<addaction name="action_undo"/>
<addaction name="action_redo"/>
<addaction name="action_copy"/>
<addaction name="action_cut"/>
<addaction name="action_paste"/>
<addaction name="action_indent"/>
<addaction name="action_find"/>
<addaction name="action_replace"/>
</widget>
<widget class="QMenu" name="menu_3">
<property name="title">
<string>帮助</string>
</property>
<addaction name="action_changelog"/>
<addaction name="action_aboutQt"/>
<addaction name="action_about"/>
</widget>
<widget class="QMenu" name="menu_4">
<property name="title">
<string>视窗</string>
</property>
<addaction name="action_subWindowView"/>
<addaction name="action_tabbedView"/>
<addaction name="action_cascade"/>
<addaction name="action_tile"/>
</widget>
<widget class="QMenu" name="menu_5">
<property name="title">
<string>查看</string>
</property>
<addaction name="action_zoomin"/>
<addaction name="action_zoomout"/>
</widget>
<addaction name="menu"/>
<addaction name="menu_2"/>
<addaction name="menu_5"/>
<addaction name="menu_4"/>
<addaction name="menu_3"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_run"/>
<addaction name="action_font"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="action_new">
<property name="text">
<string>新建</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="action_open">
<property name="text">
<string>打开</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="action_close">
<property name="text">
<string>关闭</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
<action name="action_save">
<property name="text">
<string>保存</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="action_saveas">
<property name="text">
<string>另存为</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+S</string>
</property>
</action>
<action name="action_quit">
<property name="text">
<string>退出</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="action_undo">
<property name="text">
<string>撤销</string>
</property>
<property name="shortcut">
<string>Ctrl+Z</string>
</property>
</action>
<action name="action_redo">
<property name="text">
<string>重做</string>
</property>
<property name="shortcut">
<string>Ctrl+Y</string>
</property>
</action>
<action name="action_copy">
<property name="text">
<string>复制</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="action_cut">
<property name="text">
<string>剪切</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</action>
<action name="action_paste">
<property name="text">
<string>粘贴</string>
</property>
<property name="shortcut">
<string>Ctrl+V</string>
</property>
</action>
<action name="action_indent">
<property name="text">
<string>排版</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="action_find">
<property name="text">
<string>查找</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="action_replace">
<property name="text">
<string>替换</string>
</property>
<property name="shortcut">
<string>Ctrl+H</string>
</property>
</action>
<action name="action_aboutQt">
<property name="text">
<string>关于Qt</string>
</property>
</action>
<action name="action_about">
<property name="text">
<string>关于</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="action_subWindowView">
<property name="text">
<string>窗口模式</string>
</property>
</action>
<action name="action_tabbedView">
<property name="text">
<string>标签模式</string>
</property>
</action>
<action name="action_cascade">
<property name="text">
<string>层叠窗口</string>
</property>
</action>
<action name="action_tile">
<property name="text">
<string>平铺窗口</string>
</property>
</action>
<action name="action_changelog">
<property name="text">
<string>更新历史</string>
</property>
</action>
<action name="action_run">
<property name="icon">
<iconset resource="qtrf.qrc">
<normaloff>:/run.png</normaloff>:/run.png</iconset>
</property>
<property name="text">
<string>运行</string>
</property>
<property name="toolTip">
<string>运行</string>
</property>
</action>
<action name="action_zoomin">
<property name="text">
<string>放大</string>
</property>
<property name="shortcut">
<string>Ctrl++</string>
</property>
</action>
<action name="action_zoomout">
<property name="text">
<string>缩小</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
<action name="action_font">
<property name="icon">
<iconset resource="qtrf.qrc">
<normaloff>:/font.png</normaloff>:/font.png</iconset>
</property>
<property name="text">
<string>字体</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="qtrf.qrc"/>
</resources>
<connections/>
</ui>

79
mdichild.cpp Normal file
View File

@ -0,0 +1,79 @@
#include "mdichild.h"
#include <QWheelEvent>
#include <QTextStream>
#include <QApplication>
#include <QScrollBar>
#include <QMessageBox>
#include <QFileInfo>
#include <QDebug>
MdiChild::MdiChild()
{
connect(document(),SIGNAL(contentsChanged()),this,SLOT(onContentsChanged()));
}
void MdiChild::wheelEvent(QWheelEvent *e)
{
if(QApplication::keyboardModifiers() == Qt::ControlModifier){
if(e->delta() > 0){
zoomIn();
}else{
zoomOut();
}
}else{
if(e->delta() > 0){
verticalScrollBar()->setValue(verticalScrollBar()->value()-30);
}else{
verticalScrollBar()->setValue(verticalScrollBar()->value()+30);
}
}
}
bool MdiChild::loadFile(QString filename)
{
path=filename;
setWindowTitle(QFileInfo(filename).fileName()+"[*]");
QFile *file=new QFile;
file->setFileName(filename);
bool ok=file->open(QIODevice::ReadOnly);
if(ok){
QPalette plt = palette();
plt.setColor(QPalette::Text,QColor(Qt::white));
plt.setBrush(QPalette::Base,QBrush(Qt::black));
setPalette(plt);
QTextStream ts(file);
QString s=ts.readAll();
setVisible(true);
file->close();
delete file;
setPlainText(s);
showMaximized();
return true;
}else{
QMessageBox::warning(this,"错误", QString(" %1:\n%2").arg(path).arg(file->errorString()));
return false;
}
}
bool MdiChild::save()
{
QFile file(path);
if(file.open(QFile::WriteOnly))
{
QTextStream ts(&file);
QString s=toPlainText();
ts << s;
//ui->mdiArea->currentSubWindow()->setWindowTitle(QFileInfo(filename).fileName());
//LS1->setText("保存 "+filename);
setWindowTitle(QFileInfo(path).fileName()+"[*]");
setWindowModified(false);
return true;
}else{
QMessageBox::warning(this,"错误", QString(" %1:\n%2").arg(path).arg(file.errorString()));
return false;
}
}
void MdiChild::onContentsChanged()
{
setWindowModified(document()->isModified());
}

23
mdichild.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef MDICHILD_H
#define MDICHILD_H
#include <QTextEdit>
class MdiChild : public QTextEdit
{
Q_OBJECT
public:
MdiChild();
bool loadFile(QString);
bool save();
QString path;
protected:
void wheelEvent(QWheelEvent*);
private slots:
void onContentsChanged();
};
#endif // MDICHILD_H

BIN
preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

7
qtrf.qrc Normal file
View File

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>icon.png</file>
<file>run.png</file>
<file>font.png</file>
</qresource>
</RCC>

BIN
run.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
zxy.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB