RedPanda-CPP/RedPandaIDE/mainwindow.cpp

104 lines
2.5 KiB
C++
Raw Normal View History

2021-04-06 23:10:57 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2021-04-07 21:13:15 +08:00
#include "editorlist.h"
#include "editor.h"
2021-04-09 17:48:25 +08:00
#include <QCloseEvent>
#include <QLabel>
MainWindow* pMainWindow;
2021-04-06 23:10:57 +08:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
// status bar
mFileInfoStatus=new QLabel(this);
mFileEncodingStatus = new QLabel(this);
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
ui->statusbar->addWidget(mFileInfoStatus);
ui->statusbar->addWidget(mFileEncodingStatus);
2021-04-07 21:13:15 +08:00
mEditorList = new EditorList(ui->EditorTabsLeft,
ui->EditorTabsRight,
ui->EditorPanelSplitter,
ui->EditorPanel);
setupActions();
2021-04-07 22:44:08 +08:00
ui->EditorTabsRight->setVisible(false);
2021-04-06 23:10:57 +08:00
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateStatusBarForEncoding() {
Editor * editor = mEditorList->getEditor();
if (editor!=NULL) {
mFileEncodingStatus->setText(editor->fileEncoding());
}
2021-04-11 13:55:31 +08:00
}
void MainWindow::updateStatusBarForEditingInfo(int line,int col,int lines,int charCount)
{
Editor * editor = mEditorList->getEditor();
if (editor!=NULL) {
mFileInfoStatus->setText(
QString(tr("Line: %1 Col: %2 Lines: %3 Chars: %4")).arg(line)
.arg(col).arg(lines).arg(charCount));
}
}
2021-04-07 21:13:15 +08:00
void MainWindow::setupActions() {
}
void MainWindow::on_actionNew_triggered()
{
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
updateStatusBarForEncoding();
2021-04-07 21:13:15 +08:00
}
2021-04-07 22:44:08 +08:00
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
{
Editor* editor = mEditorList->getEditor(index);
mEditorList->closeEditor(editor);
}
void MainWindow::on_actionOpen_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
//editor->save();
}
2021-04-07 22:44:08 +08:00
}
2021-04-09 17:48:25 +08:00
void MainWindow::closeEvent(QCloseEvent *event) {
if (!mEditorList->closeAll(true)) {
event->ignore();
return ;
}
delete mEditorList;
event->accept();
return;
}
void MainWindow::on_actionSave_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
editor->save();
}
}
void MainWindow::on_actionSaveAs_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
editor->saveAs();
}
}