2021-04-06 23:10:57 +08:00
|
|
|
#include "editorlist.h"
|
2021-04-07 21:13:15 +08:00
|
|
|
#include "editor.h"
|
2021-04-07 22:44:08 +08:00
|
|
|
#include <QVariant>
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2021-04-07 21:13:15 +08:00
|
|
|
EditorList::EditorList(QTabWidget* leftPageWidget,
|
|
|
|
QTabWidget* rightPageWidget,
|
|
|
|
QSplitter* splitter,
|
|
|
|
QWidget* panel):
|
|
|
|
mLeftPageWidget(leftPageWidget),
|
|
|
|
mRightPageWidget(rightPageWidget),
|
|
|
|
mSplitter(splitter),
|
|
|
|
mPanel(panel),
|
|
|
|
mUpdateCount(0)
|
2021-04-06 23:10:57 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2021-04-07 21:13:15 +08:00
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
Editor* EditorList::newEditor(const QString& filename, const QByteArray& encoding,
|
2021-04-07 21:13:15 +08:00
|
|
|
bool inProject, bool newFile,
|
|
|
|
QTabWidget* page) {
|
|
|
|
QTabWidget * parentPageControl = NULL;
|
|
|
|
if (page == NULL)
|
2021-04-08 10:29:21 +08:00
|
|
|
parentPageControl = getNewEditorPageControl();
|
2021-04-07 21:13:15 +08:00
|
|
|
else
|
|
|
|
parentPageControl = page;
|
|
|
|
return new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl);
|
|
|
|
//UpdateLayout;
|
|
|
|
}
|
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
QTabWidget* EditorList::getNewEditorPageControl() {
|
2021-04-07 21:13:15 +08:00
|
|
|
//todo: return widget depends on layout
|
|
|
|
return mLeftPageWidget;
|
|
|
|
}
|
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const {
|
2021-04-07 22:44:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
|
2021-04-07 22:44:08 +08:00
|
|
|
delete editor;
|
|
|
|
return true;
|
|
|
|
}
|