修改: HTYEdit

修改:     highlighter.cpp
	修改:     mainwindow.cpp
	修改:     mainwindow.h
	修改:     mainwindow.ui
	修改:     mdichild.cpp
This commit is contained in:
sonichy 2017-07-11 23:20:50 +08:00
parent c61e6327b6
commit 7a9dc8fe75
6 changed files with 51 additions and 14 deletions

BIN
HTYEdit

Binary file not shown.

View File

@ -5,7 +5,7 @@ Highlighter::Highlighter(QTextDocument *parent)
{
HighlightingRule rule;
keywordFormat.setForeground(QColor("#D33D6D"));
keywordFormat.setForeground(QColor("#FFFF00"));
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns;
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
@ -36,13 +36,13 @@ Highlighter::Highlighter(QTextDocument *parent)
multiLineCommentFormat.setForeground(QColor("#5C5D55"));
quotationFormat.setForeground(QColor("#DCB98D"));
quotationFormat.setForeground(QColor("#FFFF00"));
rule.pattern = QRegularExpression("\".*\"");
rule.format = quotationFormat;
highlightingRules.append(rule);
//functionFormat.setFontItalic(true);
functionFormat.setForeground(QColor("#F385F3"));
functionFormat.setFontItalic(true);
functionFormat.setForeground(QColor("#00FF00"));
rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()");
rule.format = functionFormat;
highlightingRules.append(rule);
@ -74,8 +74,7 @@ void Highlighter::highlightBlock(const QString &text)
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ match.capturedLength();
commentLength = endIndex - startIndex + match.capturedLength();
}
setFormat(startIndex, commentLength, multiLineCommentFormat);
startIndex = text.indexOf(commentStartExpression, startIndex + commentLength);

View File

@ -1,8 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mdichild.h"
#include "dialogfind.h"
#include "ui_dialogfind.h"
#include <QDesktopWidget>
#include <QMessageBox>
#include <QTextEdit>
@ -16,10 +14,7 @@
#include <QDesktopServices>
#include <QPushButton>
#include <QFontDialog>
QLabel *LS1,*LS2;
QString filename="",path="";
DialogFind *dialogFind;
#include <QMimeData>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@ -67,14 +62,14 @@ void MainWindow::on_action_aboutQt_triggered()
void MainWindow::on_action_about_triggered()
{
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰编辑器 1.1\n一款基于 Qt 的文本编辑程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页sonichy.96.lt\n参考文献:\nQMdiArea基本用法http://www.mamicode.com/info-detail-1607476.html\n多文档编辑器http://www.qter.org/?page_id=161\n保存文本http://blog.csdn.net/neicole/article/details/7330234\n语法高亮http://www.cnblogs.com/lenxvp/p/5475931.html");
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰编辑器 1.1\n一款基于 Qt 的文本编辑程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页sonichy.96.lt\n参考文献:\nQMdiArea基本用法http://www.mamicode.com/info-detail-1607476.html\n多文档编辑器http://www.qter.org/?page_id=161\n保存文本http://blog.csdn.net/neicole/article/details/7330234\n语法高亮http://www.cnblogs.com/lenxvp/p/5475931.html\n拖放打开文件http://blog.csdn.net/rl529014/article/details/53057577");
aboutMB.setIconPixmap(QPixmap(":/icon.png"));
aboutMB.exec();
}
void MainWindow::on_action_changelog_triggered()
{
QMessageBox aboutMB(QMessageBox::NoIcon, "更新历史", "1.1\n2017-06\n增加语法高亮。\n提取打开文件的相对路径使Markdown预览能够载入相对路径图片。\n\n1.0\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制作主要菜单。");
QMessageBox aboutMB(QMessageBox::NoIcon, "更新历史", "1.1\n2017-07\n增加拖放打开文件。\n2017-06\n增加语法高亮。\n提取打开文件的相对路径使Markdown预览能够载入相对路径图片。\n\n1.0\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();
}
@ -373,3 +368,29 @@ void MainWindow::SyntaxHighlight(){
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setTextCursor(cursor);
((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->setWindowModified(false);
}
void MainWindow::dragEnterEvent(QDragEnterEvent *e)
{
qDebug() << e->mimeData()->formats().at(0);
//if(e->mimeData()->hasFormat("text/uri-list")) //只能打开文本文件
e->acceptProposedAction(); //可以在这个窗口部件上拖放对象
}
void MainWindow::dropEvent(QDropEvent *e) //释放对方时,执行的操作
{
QList<QUrl> urls = e->mimeData()->urls();
if(urls.isEmpty())
return ;
QString fileName = urls.first().toLocalFile();
foreach (QUrl u, urls) {
qDebug() << u.toString();
}
qDebug() << urls.size();
if(fileName.isEmpty())
return;
open(fileName);
}

View File

@ -1,7 +1,10 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "dialogfind.h"
#include "ui_dialogfind.h"
#include <QMainWindow>
#include <QDragEnterEvent>
namespace Ui {
class MainWindow;
@ -19,6 +22,13 @@ public:
private:
void open(QString filename);
QLabel *LS1,*LS2;
QString filename,path;
DialogFind *dialogFind;
protected:
void dragEnterEvent(QDragEnterEvent *e);
void dropEvent(QDropEvent *e);
private slots:
void on_action_new_triggered();

View File

@ -10,6 +10,9 @@
<height>600</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>海天鹰编辑器</string>
</property>

View File

@ -50,6 +50,10 @@ bool MdiChild::loadFile(QString filename)
setPlainText(s);
Highlighter *highlighter = new Highlighter(document());
showMaximized();
zoomIn();
zoomIn();
zoomIn();
zoomIn();
return true;
}else{
QMessageBox::warning(this,"错误", QString(" %1:\n%2").arg(path).arg(file->errorString()));