From 2a9a014c9d78b902da6332f081b37a830bb0541d Mon Sep 17 00:00:00 2001 From: Eike Ziller <eike.ziller@digia.com> Date: Tue, 12 Aug 2014 14:08:35 +0200 Subject: [PATCH] Editors: Extract class for external windows It will take over more responsibility in a later patch. Change-Id: I89ef61791ccbba3e42de2862d5d887099634bce4 Reviewed-by: Daniel Teske <daniel.teske@digia.com> --- src/plugins/coreplugin/coreplugin.pro | 2 + .../editormanager/editormanager.cpp | 17 ++--- .../coreplugin/editormanager/editorwindow.cpp | 66 +++++++++++++++++++ .../coreplugin/editormanager/editorwindow.h | 55 ++++++++++++++++ 4 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 src/plugins/coreplugin/editormanager/editorwindow.cpp create mode 100644 src/plugins/coreplugin/editormanager/editorwindow.h diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index e0183194d49..64c7acf5963 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -31,6 +31,7 @@ SOURCES += mainwindow.cpp \ editormanager/editorarea.cpp \ editormanager/editormanager.cpp \ editormanager/editorview.cpp \ + editormanager/editorwindow.cpp \ editormanager/documentmodel.cpp \ editormanager/openeditorsview.cpp \ editormanager/openeditorswindow.cpp \ @@ -122,6 +123,7 @@ HEADERS += mainwindow.h \ editormanager/editormanager.h \ editormanager/editormanager_p.h \ editormanager/editorview.h \ + editormanager/editorwindow.h \ editormanager/documentmodel.h \ editormanager/openeditorsview.h \ editormanager/openeditorswindow.h \ diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 040490ec48e..afffbd9f55d 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -29,6 +29,7 @@ #include "editormanager.h" #include "editormanager_p.h" +#include "editorwindow.h" #include "editorview.h" #include "openeditorswindow.h" @@ -1169,19 +1170,9 @@ void EditorManagerPrivate::splitNewWindow(EditorView *view) newEditor = EditorManagerPrivate::duplicateEditor(editor); else newEditor = editor; // move to the new view - auto area = new EditorArea; - QWidget *win = new QWidget; - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - win->setLayout(layout); - layout->addWidget(area); - win->setFocusProxy(area); - win->setAttribute(Qt::WA_DeleteOnClose); - win->setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing - win->resize(QSize(800, 600)); - static int windowId = 0; - ICore::registerWindow(win, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId))); + + auto win = new EditorWindow; + EditorArea *area = win->editorArea(); d->m_editorAreas.append(area); connect(area, SIGNAL(destroyed(QObject*)), d, SLOT(editorAreaDestroyed(QObject*))); win->show(); diff --git a/src/plugins/coreplugin/editormanager/editorwindow.cpp b/src/plugins/coreplugin/editormanager/editorwindow.cpp new file mode 100644 index 00000000000..a25e828101e --- /dev/null +++ b/src/plugins/coreplugin/editormanager/editorwindow.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "editorwindow.h" + +#include "editorarea.h" + +#include <coreplugin/icontext.h> +#include <coreplugin/icore.h> + +#include <QVBoxLayout> + +namespace Core { +namespace Internal { + +EditorWindow::EditorWindow(QWidget *parent) : + QWidget(parent) +{ + m_area = new EditorArea; + auto layout = new QVBoxLayout; + layout->setMargin(0); + layout->setSpacing(0); + setLayout(layout); + layout->addWidget(m_area); + setFocusProxy(m_area); + setAttribute(Qt::WA_DeleteOnClose); + setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing + resize(QSize(800, 600)); + + static int windowId = 0; + ICore::registerWindow(this, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId))); +} + +EditorArea *EditorWindow::editorArea() const +{ + return m_area; +} + +} // Internal +} // Core diff --git a/src/plugins/coreplugin/editormanager/editorwindow.h b/src/plugins/coreplugin/editormanager/editorwindow.h new file mode 100644 index 00000000000..0ab287ed8d2 --- /dev/null +++ b/src/plugins/coreplugin/editormanager/editorwindow.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef EDITORWINDOW_H +#define EDITORWINDOW_H + +#include <QWidget> + +namespace Core { +namespace Internal { + +class EditorArea; + +class EditorWindow : public QWidget +{ + Q_OBJECT +public: + explicit EditorWindow(QWidget *parent = 0); + + EditorArea *editorArea() const; + +private: + EditorArea *m_area; +}; + +} // Internal +} // Core + +#endif // EDITORWINDOW_H -- GitLab