* can close now

This commit is contained in:
Roy Qu 2021-04-07 22:44:08 +08:00 committed by royqh1979@gmail.com
parent a42654dea8
commit 950aaadc73
7 changed files with 94 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include "editor.h"
#include <QtCore/QFileInfo>
#include <QVariant>
#include <memory>
using namespace std;
@ -31,7 +32,12 @@ Editor::Editor(QObject *parent, const QString& filename,
else
mFileEncoding = mEncodingType;
}
mTextEdit->setProperty("editor",QVariant::fromValue<intptr_t>((intptr_t)this));
}
Editor::~Editor() {
int index = mParentPageControl->indexOf(mTextEdit);
mParentPageControl->removeTab(index);
}
void Editor::loadFile() {

View File

@ -15,6 +15,8 @@ public:
bool inProject, bool isNew,
QTabWidget* parentPageControl);
~Editor();
FileEncodingType encodingType() const;
void setFileEncodingType(FileEncodingType type);
FileEncodingType fileEncoding() const;

View File

@ -1,5 +1,6 @@
#include "editorlist.h"
#include "editor.h"
#include <QVariant>
EditorList::EditorList(QTabWidget* leftPageWidget,
QTabWidget* rightPageWidget,
@ -31,3 +32,25 @@ QTabWidget* EditorList::GetNewEditorPageControl() {
return mLeftPageWidget;
}
Editor* EditorList::GetEditor(int index, QTabWidget* tabsWidget) const {
QTabWidget* selectedWidget;
if (tabsWidget == NULL) {
selectedWidget = mLeftPageWidget; // todo: get focused widget
} else {
selectedWidget = tabsWidget;
}
QWidget* textEdit;
if (index == -1) {
textEdit = selectedWidget->currentWidget();
} else {
textEdit =selectedWidget->widget(index);
}
QVariant pop = textEdit->property("editor");
Editor *editor = (Editor*)pop.value<intptr_t>();
return editor;
}
bool EditorList::CloseEditor(Editor* editor, bool transferFocus, bool force) {
delete editor;
return true;
}

View File

@ -26,6 +26,10 @@ public:
bool inProject, bool newFile,
QTabWidget* page=NULL);
Editor* GetEditor(int index=-1, QTabWidget* tabsWidget=NULL) const;
bool CloseEditor(Editor* editor, bool transferFocus=true, bool force=false);
private:
QTabWidget* GetNewEditorPageControl();

View File

@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->EditorPanelSplitter,
ui->EditorPanel);
setupActions();
ui->EditorTabsRight->setVisible(false);
}
MainWindow::~MainWindow()
@ -28,3 +29,9 @@ void MainWindow::on_actionNew_triggered()
{
mEditorList->NewEditor("",etAuto,false,true);
}
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
{
Editor* editor = mEditorList->GetEditor(index,ui->EditorTabsLeft);
mEditorList->CloseEditor(editor);
}

View File

@ -20,6 +20,8 @@ public:
private slots:
void on_actionNew_triggered();
void on_EditorTabsLeft_tabCloseRequested(int index);
private:
void setupActions();

View File

@ -15,6 +15,18 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<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="QSplitter" name="splitter">
<property name="orientation">
@ -28,6 +40,18 @@
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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="QSplitter" name="splitter_2">
<property name="orientation">
@ -62,6 +86,21 @@
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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="QSplitter" name="EditorPanelSplitter">
<property name="orientation">
@ -71,8 +110,18 @@
<property name="currentIndex">
<number>-1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
<widget class="QTabWidget" name="EditorTabsRight">
<property name="enabled">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
<widget class="QTabWidget" name="EditorTabsRight"/>
</widget>
</item>
</layout>