tab right menu add readonly
This commit is contained in:
parent
b78155a986
commit
88f2e4c79f
|
@ -1,11 +1,10 @@
|
|||
[Desktop Entry]
|
||||
Name=海天鹰编辑器
|
||||
Comment=Edit text files
|
||||
Comment=Media player
|
||||
Exec=/media/sonichy/job/HY/Linux/Qt/HTYEdit/HTYEdit %u
|
||||
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;
|
||||
Categories=TextEditor;
|
||||
|
|
|
@ -19,12 +19,20 @@
|
|||
#include <QPrintPreviewDialog>
|
||||
#include <QPainter>
|
||||
//#include <QRegExp>
|
||||
#include <QMdiSubWindow>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->action_new->setIcon(style()->standardIcon(QStyle::SP_FileDialogNewFolder));
|
||||
ui->action_open->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||
ui->action_save->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
|
||||
ui->action_quit->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
|
||||
ui->action_undo->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
|
||||
ui->action_quit->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
|
||||
ui->action_about->setIcon(style()->standardIcon(QStyle::SP_DialogHelpButton));
|
||||
move((QApplication::desktop()->width() - width())/2, (QApplication::desktop()->height() - height())/2);
|
||||
|
||||
lineEdit_command = new QLineEdit;
|
||||
|
@ -75,7 +83,7 @@ void MainWindow::on_action_aboutQt_triggered()
|
|||
|
||||
void MainWindow::on_action_about_triggered()
|
||||
{
|
||||
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰编辑器 1.5\n\n一款基于 Qt 的文本编辑程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页:https://github.com/sonichy\n参考文献:\n多文档编辑器:http://www.qter.org/?page_id=161\nQMdiArea基本用法:http://www.mamicode.com/info-detail-1607476.html\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\n行号:http://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html");
|
||||
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰编辑器 1.6\n\n一款基于 Qt 的文本编辑程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页:https://github.com/sonichy\n参考文献:\n多文档编辑器:http://www.qter.org/?page_id=161\nQMdiArea基本用法:http://www.mamicode.com/info-detail-1607476.html\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\n行号:http://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html");
|
||||
aboutMB.setIconPixmap(QPixmap(":/icon.png"));
|
||||
aboutMB.setWindowIcon(QIcon(":/icon.png"));
|
||||
aboutMB.exec();
|
||||
|
@ -83,7 +91,7 @@ void MainWindow::on_action_about_triggered()
|
|||
|
||||
void MainWindow::on_action_changelog_triggered()
|
||||
{
|
||||
QString s = "1.5\n2018-08\n增加行号\n增加java文件编译命令\n\n1.4\n2018-07\n设置QTextEdit的Tab跳过的空格数为4个空格\n\n1.3\n2018-06\n增加调试窗口。\n\n1.2\n2018-05\n增加c、cpp的OpenGL编译命令。\n2018-05\n解决右键打开方式无法打开文件问题。\n增加运行python。\n2018-04\n增加打印功能。\n\n1.1\n2017-10\n增加获取文本编码(使用 file --mime-encoding 命令返回),但是没有解决乱码问题。\n排版实验。\n用文本框代替消息框显示更新日志。\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制作主要菜单。";
|
||||
QString s = "1.6\n2018-09\n标签右键增加只读菜单。\n优化括号补全。\n\n1.5\n2018-08\n增加行号\n增加java文件编译命令\n\n1.4\n2018-07\n设置QTextEdit的Tab跳过的空格数为4个空格\n\n1.3\n2018-06\n增加调试窗口。\n\n1.2\n2018-05\n增加c、cpp的OpenGL编译命令。\n2018-05\n解决右键打开方式无法打开文件问题。\n增加运行python。\n2018-04\n增加打印功能。\n\n1.1\n2017-10\n增加获取文本编码(使用 file --mime-encoding 命令返回),但是没有解决乱码问题。\n排版实验。\n用文本框代替消息框显示更新日志。\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制作主要菜单。";
|
||||
QDialog *dialog = new QDialog;
|
||||
dialog->setWindowTitle("更新历史");
|
||||
dialog->setFixedSize(400,300);
|
||||
|
@ -131,7 +139,12 @@ void MainWindow::on_action_tile_triggered()
|
|||
void MainWindow::on_action_new_triggered()
|
||||
{
|
||||
MdiChild *child = new MdiChild(this);
|
||||
ui->mdiArea->addSubWindow(child);
|
||||
QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(child);
|
||||
QMenu *menu = subWindow->systemMenu();
|
||||
QAction *action_readonly = new QAction("只读",menu);
|
||||
action_readonly->setCheckable(true);
|
||||
menu->addAction(action_readonly);
|
||||
connect(action_readonly, SIGNAL(triggered(bool)), child, SLOT(setReadOnlyA(bool)));
|
||||
QPalette plt = palette();
|
||||
plt.setColor(QPalette::Text,QColor(Qt::white));
|
||||
plt.setBrush(QPalette::Base,QBrush(Qt::black));
|
||||
|
@ -161,7 +174,12 @@ void MainWindow::open(QString fileName)
|
|||
{
|
||||
MdiChild *child = new MdiChild(this);
|
||||
connect(child, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChange()));
|
||||
ui->mdiArea->addSubWindow(child);
|
||||
QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(child);
|
||||
QMenu *menu = subWindow->systemMenu();
|
||||
QAction *action_readonly = new QAction("只读",menu);
|
||||
action_readonly->setCheckable(true);
|
||||
menu->addAction(action_readonly);
|
||||
connect(action_readonly, SIGNAL(triggered(bool)), child, SLOT(setReadOnlyA(bool)));
|
||||
if (child->loadFile(fileName)) {
|
||||
path = fileName;
|
||||
LS1->setText("打开 " + fileName);
|
||||
|
@ -211,9 +229,9 @@ void MainWindow::on_action_saveas_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 filename1 = QFileInfo(path).fileName();
|
||||
QString suffix = QFileInfo(path).suffix().toLower();
|
||||
QString filepath = QFileInfo(path).absolutePath();
|
||||
|
||||
if (suffix == "md") {
|
||||
QString s = ((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->toPlainText();
|
||||
|
@ -234,13 +252,11 @@ void MainWindow::on_action_run_triggered()
|
|||
LS2->setText("行,列:1,0 ");
|
||||
} else if (suffix == "htm" || suffix == "html") {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||
} else if (suffix == "py") {
|
||||
on_action_save_triggered();
|
||||
//LS1->setText("python " + path);
|
||||
} else if (suffix == "py" || suffix == "sh") {
|
||||
if (((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->document()->isModified()) on_action_save_triggered();
|
||||
QProcess *process = new QProcess;
|
||||
process->setWorkingDirectory(filepath);
|
||||
//QString command = "python " + path;
|
||||
QString command = lineEdit_command->text().arg("./" + QFileInfo(path).fileName());
|
||||
QString command = lineEdit_command->text().arg(filename1);
|
||||
qDebug() << command;
|
||||
ui->textBrowser->setText("");
|
||||
ui->textBrowser->append(command);
|
||||
|
@ -272,8 +288,8 @@ void MainWindow::on_action_run_triggered()
|
|||
qDebug() << command;
|
||||
process_compile->start(command);
|
||||
} else if (suffix == "java") {
|
||||
on_action_save_triggered();
|
||||
QString command = lineEdit_command->text().arg(filename1).arg(QFileInfo(path).baseName());
|
||||
if (((QTextEdit*)(ui->mdiArea->currentSubWindow()->widget()))->document()->isModified()) on_action_save_triggered();
|
||||
QString command = lineEdit_command->text().arg(filename1);
|
||||
LS1->setText(command);
|
||||
ui->textBrowser->setText("");
|
||||
ui->textBrowser->append(command);
|
||||
|
@ -569,10 +585,13 @@ void MainWindow::updateCommand()
|
|||
lineEdit_command->setText(command);
|
||||
} else if (suffix == "py") {
|
||||
ui->textBrowser->show();
|
||||
lineEdit_command->setText("python %1");
|
||||
lineEdit_command->setText("python ./%1");
|
||||
} else if (suffix == "java") {
|
||||
ui->textBrowser->show();
|
||||
lineEdit_command->setText("javac %1");
|
||||
} else if (suffix == "sh") {
|
||||
ui->textBrowser->show();
|
||||
lineEdit_command->setText("./%1");
|
||||
} else {
|
||||
lineEdit_command->setText("");
|
||||
ui->textBrowser->hide();
|
||||
|
|
31
mdichild.cpp
31
mdichild.cpp
|
@ -102,25 +102,23 @@ void MdiChild::wheelEvent(QWheelEvent *e)
|
|||
|
||||
void MdiChild::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
// 自动补全
|
||||
if(e->key() == Qt::Key_ParenLeft){
|
||||
insertPlainText(" )");
|
||||
QTextCursor c = textCursor();
|
||||
c.movePosition(QTextCursor::Left,QTextCursor::MoveAnchor,2);
|
||||
insertPlainText("()");
|
||||
moveCursor(QTextCursor::Left, QTextCursor::MoveAnchor);
|
||||
}else if(e->key() == Qt::Key_BraceLeft){
|
||||
insertPlainText("{}");
|
||||
moveCursor(QTextCursor::Left, QTextCursor::MoveAnchor);
|
||||
}else if(e->key() == Qt::Key_BracketLeft){
|
||||
insertPlainText("[]");
|
||||
moveCursor(QTextCursor::Left, QTextCursor::MoveAnchor);
|
||||
}else{
|
||||
return QPlainTextEdit::keyPressEvent(e);
|
||||
}
|
||||
if(e->key() == Qt::Key_BraceLeft){
|
||||
insertPlainText(" }");
|
||||
QTextCursor c = textCursor();
|
||||
c.movePosition(QTextCursor::Left,QTextCursor::MoveAnchor,2);
|
||||
}
|
||||
if(e->key() == Qt::Key_BracketLeft){
|
||||
insertPlainText(" ]");
|
||||
QTextCursor c = textCursor();
|
||||
c.movePosition(QTextCursor::Left,QTextCursor::MoveAnchor,2);
|
||||
}
|
||||
return QPlainTextEdit::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
// 生成行号
|
||||
void MdiChild::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(lineNumberArea);
|
||||
|
@ -176,4 +174,9 @@ void MdiChild::updateLineNumberArea(const QRect &rect, int dy)
|
|||
void MdiChild::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||
{
|
||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||
}
|
||||
|
||||
void MdiChild::setReadOnlyA(bool ro)
|
||||
{
|
||||
setReadOnly(ro);
|
||||
}
|
|
@ -28,6 +28,7 @@ private slots:
|
|||
void contentsChange();
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
void updateLineNumberArea(const QRect &, int);
|
||||
void setReadOnlyA(bool ro);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue