Commit 57ed30da authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Return canvas to main window if detached canvas window is closed

parent 5644a8de
......@@ -363,6 +363,7 @@ set(kritaui_LIB_SRCS
KisTemplateTree.cpp
KisUndoStackAction.cpp
KisView.cpp
KisCanvasWindow.cpp
thememanager.cpp
......
/*
* Copyright (c) 2018 Jouni Pentikäinen <joupent@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QHBoxLayout>
#include "KisCanvasWindow.h"
#include "KisMainWindow.h"
struct KisCanvasWindow::Private {
KisMainWindow *mainWindow;
Private(KisMainWindow *mainWindow)
: mainWindow(mainWindow)
{}
};
KisCanvasWindow::KisCanvasWindow(KisMainWindow *mainWindow)
: QWidget(mainWindow)
, d(new Private(mainWindow))
{
setWindowFlags(Qt::Window);
QLayout *layout = new QHBoxLayout(this);
setLayout(layout);
layout->addWidget(new QWidget(this));
}
KisCanvasWindow::~KisCanvasWindow() {}
void KisCanvasWindow::closeEvent(QCloseEvent *event)
{
d->mainWindow->setCanvasDetached(false);
QWidget::closeEvent(event);
}
QWidget * KisCanvasWindow::swapMainWidget(QWidget *newWidget)
{
QWidget *oldWidget = layout()->takeAt(0)->widget();
layout()->addWidget(newWidget);
return oldWidget;
}
/*
* Copyright (c) 2018 Jouni Pentikäinen <joupent@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISCANVASWINDOW_H
#define KISCANVASWINDOW_H
#include <QWidget>
class KisMainWindow;
/**
* Window for the canvas (mdi) area. Used when detached canvas mode is enabled.
*/
class KisCanvasWindow : public QWidget
{
public:
explicit KisCanvasWindow(KisMainWindow *mainWindow);
~KisCanvasWindow() override;
QWidget * swapMainWidget(QWidget *widget);
void closeEvent(QCloseEvent *event) override;
private:
struct Private;
QScopedPointer<Private> d;
};
#endif
......@@ -141,6 +141,7 @@
#include "dialogs/kis_dlg_import_image_sequence.h"
#include <KisUpdateSchedulerConfigNotifier.h>
#include "KisWindowLayoutManager.h"
#include "KisCanvasWindow.h"
#include <mutex>
......@@ -255,7 +256,7 @@ public:
QMdiSubWindow *activeSubWindow {0};
QSignalMapper *windowMapper;
QSignalMapper *documentMapper;
QWidget *canvasWindow {0};
KisCanvasWindow *canvasWindow {0};
QByteArray lastExportedFormat;
QScopedPointer<KisSignalCompressorWithParam<int> > tabSwitchCompressor;
......@@ -375,14 +376,9 @@ KisMainWindow::KisMainWindow(QUuid uuid)
connect(d->windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
connect(d->documentMapper, SIGNAL(mapped(QObject*)), this, SLOT(newView(QObject*)));
d->canvasWindow = new QWidget();
d->canvasWindow->setWindowFlags(Qt::Window);
d->canvasWindow = new KisCanvasWindow(this);
actionCollection()->addAssociatedWidget(d->canvasWindow);
QLayout *cwLayout = new QHBoxLayout(d->canvasWindow);
d->canvasWindow->setLayout(cwLayout);
cwLayout->addWidget(new QWidget(this));
createActions();
setAutoSaveSettings(d->windowStateConfig, false);
......@@ -683,10 +679,8 @@ void KisMainWindow::setCanvasDetached(bool detach)
if (detach == canvasDetached()) return;
QWidget *outgoingWidget = takeCentralWidget();
QWidget *incomingWidget = d->canvasWindow->layout()->takeAt(0)->widget();
QWidget *incomingWidget = d->canvasWindow->swapMainWidget(outgoingWidget);
setCentralWidget(incomingWidget);
d->canvasWindow->layout()->addWidget(outgoingWidget);
if (detach) {
KIS_SAFE_ASSERT_RECOVER_NOOP(outgoingWidget == d->mdiArea);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment