Commit 01e3e1bf authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Refactor how views access their main window

Code in KisCanvasControllerWidget assumed that they are children of the
main window. This assumption will be broken by the detached canvas mode.
Instead, the access is now routed through KisViewManager.

To ensure that KisView knows of KisViewManager early enough, its
construction has been refactored as well.
parent b4b3f9af
...@@ -136,15 +136,9 @@ void KoCanvasControllerWidget::Private::emitPointerPositionChangedSignals(QEvent ...@@ -136,15 +136,9 @@ void KoCanvasControllerWidget::Private::emitPointerPositionChangedSignals(QEvent
void KoCanvasControllerWidget::Private::activate() void KoCanvasControllerWidget::Private::activate()
{ {
QWidget *parent = q;
while (parent->parentWidget()) {
parent = parent->parentWidget();
}
KoCanvasSupervisor *observerProvider = dynamic_cast<KoCanvasSupervisor*>(parent);
if (!observerProvider) { if (!observerProvider) {
return; return;
} }
KoCanvasBase *canvas = q->canvas(); KoCanvasBase *canvas = q->canvas();
Q_FOREACH (KoCanvasObserverBase *docker, observerProvider->canvasObservers()) { Q_FOREACH (KoCanvasObserverBase *docker, observerProvider->canvasObservers()) {
KoCanvasObserverBase *observer = dynamic_cast<KoCanvasObserverBase*>(docker); KoCanvasObserverBase *observer = dynamic_cast<KoCanvasObserverBase*>(docker);
...@@ -157,11 +151,6 @@ void KoCanvasControllerWidget::Private::activate() ...@@ -157,11 +151,6 @@ void KoCanvasControllerWidget::Private::activate()
void KoCanvasControllerWidget::Private::unsetCanvas() void KoCanvasControllerWidget::Private::unsetCanvas()
{ {
QWidget *parent = q;
while (parent->parentWidget()) {
parent = parent->parentWidget();
}
KoCanvasSupervisor *observerProvider = dynamic_cast<KoCanvasSupervisor*>(parent);
if (!observerProvider) { if (!observerProvider) {
return; return;
} }
...@@ -176,10 +165,10 @@ void KoCanvasControllerWidget::Private::unsetCanvas() ...@@ -176,10 +165,10 @@ void KoCanvasControllerWidget::Private::unsetCanvas()
} }
//////////// ////////////
KoCanvasControllerWidget::KoCanvasControllerWidget(KActionCollection * actionCollection, QWidget *parent) KoCanvasControllerWidget::KoCanvasControllerWidget(KActionCollection * actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent)
: QAbstractScrollArea(parent) : QAbstractScrollArea(parent)
, KoCanvasController(actionCollection) , KoCanvasController(actionCollection)
, d(new Private(this)) , d(new Private(this, observerProvider))
{ {
// We need to set this as QDeclarativeView sets them a bit different from QAbstractScrollArea // We need to set this as QDeclarativeView sets them a bit different from QAbstractScrollArea
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class KoShape; class KoShape;
class KoCanvasBase; class KoCanvasBase;
class KoCanvasSupervisor;
/** /**
* KoCanvasController implementation for QWidget based canvases * KoCanvasController implementation for QWidget based canvases
*/ */
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
* Constructor. * Constructor.
* @param parent the parent this widget will belong to * @param parent the parent this widget will belong to
*/ */
explicit KoCanvasControllerWidget(KActionCollection * actionCollection, QWidget *parent = 0); explicit KoCanvasControllerWidget(KActionCollection * actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent = 0);
~KoCanvasControllerWidget() override; ~KoCanvasControllerWidget() override;
/** /**
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <FlakeDebug.h> #include <FlakeDebug.h>
#include <KoConfig.h> #include <KoConfig.h>
#include "KoCanvasSupervisor.h"
class KoCanvasControllerWidget; class KoCanvasControllerWidget;
class Viewport; class Viewport;
...@@ -37,8 +38,9 @@ class Q_DECL_HIDDEN KoCanvasControllerWidget::Private ...@@ -37,8 +38,9 @@ class Q_DECL_HIDDEN KoCanvasControllerWidget::Private
{ {
public: public:
Private(KoCanvasControllerWidget *qq) Private(KoCanvasControllerWidget *qq, KoCanvasSupervisor *observerProvider)
: q(qq) : q(qq)
, observerProvider(observerProvider)
, canvas(0) , canvas(0)
, ignoreScrollSignals(false) , ignoreScrollSignals(false)
, zoomWithWheel(false) , zoomWithWheel(false)
...@@ -58,6 +60,7 @@ public: ...@@ -58,6 +60,7 @@ public:
void unsetCanvas(); void unsetCanvas();
KoCanvasControllerWidget *q; KoCanvasControllerWidget *q;
KoCanvasSupervisor *observerProvider;
QPointer<KoCanvasBase> canvas; QPointer<KoCanvasBase> canvas;
Viewport *viewportWidget; Viewport *viewportWidget;
bool ignoreScrollSignals; bool ignoreScrollSignals;
......
...@@ -303,10 +303,7 @@ void KisSketchView::documentChanged() ...@@ -303,10 +303,7 @@ void KisSketchView::documentChanged()
connect(d->doc, SIGNAL(modified(bool)), SIGNAL(modifiedChanged())); connect(d->doc, SIGNAL(modified(bool)), SIGNAL(modifiedChanged()));
QPointer<KisView> view = qobject_cast<KisView*>(KisPart::instance()->createView(d->doc, QPointer<KisView> view = KisPart::instance()->createView(d->doc, d->viewManager, QApplication::activeWindow());
d->viewManager->resourceProvider()->resourceManager(),
d->viewManager->actionCollection(),
QApplication::activeWindow()));
view->setViewManager(d->viewManager); view->setViewManager(d->viewManager);
view->canvasBase()->setFavoriteResourceManager(d->viewManager->paintOpBox()->favoriteResourcesManager()); view->canvasBase()->setFavoriteResourceManager(d->viewManager->paintOpBox()->favoriteResourcesManager());
view->slotLoadingFinished(); view->slotLoadingFinished();
......
...@@ -879,7 +879,7 @@ void KisMainWindow::showDocument(KisDocument *document) { ...@@ -879,7 +879,7 @@ void KisMainWindow::showDocument(KisDocument *document) {
KisView* KisMainWindow::addViewAndNotifyLoadingCompleted(KisDocument *document) KisView* KisMainWindow::addViewAndNotifyLoadingCompleted(KisDocument *document)
{ {
KisView *view = KisPart::instance()->createView(document, resourceManager(), actionCollection(), this); KisView *view = KisPart::instance()->createView(document, d->viewManager, this);
addView(view); addView(view);
emit guiLoadingFinished(); emit guiLoadingFinished();
......
...@@ -228,10 +228,7 @@ KisMainWindow *KisPart::createMainWindow(QUuid id) ...@@ -228,10 +228,7 @@ KisMainWindow *KisPart::createMainWindow(QUuid id)
return mw; return mw;
} }
KisView *KisPart::createView(KisDocument *document, KisView *KisPart::createView(KisDocument *document, KisViewManager *viewManager, QWidget *parent)
KoCanvasResourceManager *resourceManager,
KActionCollection *actionCollection,
QWidget *parent)
{ {
// If creating the canvas fails, record this and disable OpenGL next time // If creating the canvas fails, record this and disable OpenGL next time
KisConfig cfg; KisConfig cfg;
...@@ -246,7 +243,7 @@ KisView *KisPart::createView(KisDocument *document, ...@@ -246,7 +243,7 @@ KisView *KisPart::createView(KisDocument *document,
grp.sync(); grp.sync();
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
KisView *view = new KisView(document, resourceManager, actionCollection, parent); KisView *view = new KisView(document, viewManager, parent);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
// Record successful canvas creation // Record successful canvas creation
......
...@@ -206,10 +206,7 @@ public: ...@@ -206,10 +206,7 @@ public:
* Create a new view for the document. The view is added to the list of * Create a new view for the document. The view is added to the list of
* views, and if the document wasn't known yet, it's registered as well. * views, and if the document wasn't known yet, it's registered as well.
*/ */
KisView *createView(KisDocument *document, KisView *createView(KisDocument *document, KisViewManager *viewManager, QWidget *parent);
KoCanvasResourceManager *resourceManager,
KActionCollection *actionCollection,
QWidget *parent);
/** /**
* Adds a view to the document. If the part doesn't know yet about * Adds a view to the document. If the part doesn't know yet about
......
...@@ -108,12 +108,12 @@ class Q_DECL_HIDDEN KisView::Private ...@@ -108,12 +108,12 @@ class Q_DECL_HIDDEN KisView::Private
public: public:
Private(KisView *_q, Private(KisView *_q,
KisDocument *document, KisDocument *document,
KoCanvasResourceManager *resourceManager, KisViewManager *viewManager)
KActionCollection *actionCollection) : actionCollection(viewManager->actionCollection())
: actionCollection(actionCollection) , viewManager(viewManager)
, viewConverter() , viewConverter()
, canvasController(_q, actionCollection) , canvasController(_q, viewManager->mainWindow(), viewManager->actionCollection())
, canvas(&viewConverter, resourceManager, _q, document->shapeController()) , canvas(&viewConverter, viewManager->resourceProvider()->resourceManager(), viewManager->mainWindow(), _q, document->shapeController())
, zoomManager(_q, &this->viewConverter, &this->canvasController) , zoomManager(_q, &this->viewConverter, &this->canvasController)
, paintingAssistantsDecoration(new KisPaintingAssistantsDecoration(_q)) , paintingAssistantsDecoration(new KisPaintingAssistantsDecoration(_q))
, referenceImagesDecoration(new KisReferenceImagesDecoration(_q)) , referenceImagesDecoration(new KisReferenceImagesDecoration(_q))
...@@ -213,9 +213,9 @@ public: ...@@ -213,9 +213,9 @@ public:
}; };
KisView::KisView(KisDocument *document, KoCanvasResourceManager *resourceManager, KActionCollection *actionCollection, QWidget *parent) KisView::KisView(KisDocument *document, KisViewManager *viewManager, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, d(new Private(this, document, resourceManager, actionCollection)) , d(new Private(this, document, viewManager))
{ {
Q_ASSERT(document); Q_ASSERT(document);
connect(document, SIGNAL(titleModified(QString,bool)), this, SIGNAL(titleModified(QString,bool))); connect(document, SIGNAL(titleModified(QString,bool)), this, SIGNAL(titleModified(QString,bool)));
...@@ -653,7 +653,7 @@ QPrintDialog *KisView::createPrintDialog(KisPrintJob *printJob, QWidget *parent) ...@@ -653,7 +653,7 @@ QPrintDialog *KisView::createPrintDialog(KisPrintJob *printJob, QWidget *parent)
KisMainWindow * KisView::mainWindow() const KisMainWindow * KisView::mainWindow() const
{ {
return dynamic_cast<KisMainWindow *>(window()); return d->viewManager->mainWindow();
} }
void KisView::setSubWindow(QMdiSubWindow *subWindow) void KisView::setSubWindow(QMdiSubWindow *subWindow)
......
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
/** /**
* Creates a new view for the document. * Creates a new view for the document.
*/ */
KisView(KisDocument *document, KoCanvasResourceManager *resourceManager, KActionCollection *actionCollection, QWidget *parent = 0); KisView(KisDocument *document, KisViewManager *viewManager, QWidget *parent = 0);
~KisView() override; ~KisView() override;
QAction *undoAction() const; QAction *undoAction() const;
......
...@@ -169,7 +169,7 @@ KoShapeManager* fetchShapeManagerFromNode(KisNodeSP node) ...@@ -169,7 +169,7 @@ KoShapeManager* fetchShapeManagerFromNode(KisNodeSP node)
} }
} }
KisCanvas2::KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResourceManager *resourceManager, KisView *view, KoShapeBasedDocumentBase *sc) KisCanvas2::KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResourceManager *resourceManager, KisMainWindow *mainWindow, KisView *view, KoShapeBasedDocumentBase *sc)
: KoCanvasBase(sc, resourceManager) : KoCanvasBase(sc, resourceManager)
, m_d(new KisCanvas2Private(this, coordConverter, view, resourceManager)) , m_d(new KisCanvas2Private(this, coordConverter, view, resourceManager))
{ {
...@@ -179,7 +179,7 @@ KisCanvas2::KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResource ...@@ -179,7 +179,7 @@ KisCanvas2::KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResource
* light. * light.
*/ */
m_d->bootstrapLodBlocked = true; m_d->bootstrapLodBlocked = true;
connect(view->mainWindow(), SIGNAL(guiLoadingFinished()), SLOT(bootstrapFinished())); connect(mainWindow, SIGNAL(guiLoadingFinished()), SLOT(bootstrapFinished()));
KisImageConfig config; KisImageConfig config;
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
* @param viewConverter the viewconverter for converting between * @param viewConverter the viewconverter for converting between
* window and document coordinates. * window and document coordinates.
*/ */
KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResourceManager *resourceManager, KisView *view, KoShapeBasedDocumentBase *sc); KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResourceManager *resourceManager, KisMainWindow *mainWindow, KisView *view, KoShapeBasedDocumentBase *sc);
~KisCanvas2() override; ~KisCanvas2() override;
......
...@@ -90,8 +90,8 @@ void KisCanvasController::Private::updateDocumentSizeAfterTransform() ...@@ -90,8 +90,8 @@ void KisCanvasController::Private::updateDocumentSizeAfterTransform()
} }
KisCanvasController::KisCanvasController(QPointer<KisView>parent, KActionCollection * actionCollection) KisCanvasController::KisCanvasController(QPointer<KisView>parent, KoCanvasSupervisor *observerProvider, KActionCollection * actionCollection)
: KoCanvasControllerWidget(actionCollection, parent), : KoCanvasControllerWidget(actionCollection, observerProvider, parent),
m_d(new Private(this)) m_d(new Private(this))
{ {
m_d->view = parent; m_d->view = parent;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define KIS_CANVAS_CONTROLLER_H #define KIS_CANVAS_CONTROLLER_H
#include <KoCanvasControllerWidget.h> #include <KoCanvasControllerWidget.h>
#include <libs/flake/KoCanvasSupervisor.h>
#include "kritaui_export.h" #include "kritaui_export.h"
#include "kis_types.h" #include "kis_types.h"
...@@ -32,7 +33,7 @@ class KRITAUI_EXPORT KisCanvasController : public KoCanvasControllerWidget ...@@ -32,7 +33,7 @@ class KRITAUI_EXPORT KisCanvasController : public KoCanvasControllerWidget
Q_OBJECT Q_OBJECT
public: public:
KisCanvasController(QPointer<KisView>parent, KActionCollection * actionCollection); KisCanvasController(QPointer<KisView>parent, KoCanvasSupervisor *observerProvider, KActionCollection * actionCollection);
~KisCanvasController() override; ~KisCanvasController() override;
void setCanvas(KoCanvasBase *canvas) override; void setCanvas(KoCanvasBase *canvas) override;
......
...@@ -38,7 +38,7 @@ void KisActionManagerTest::testUpdateGUI() ...@@ -38,7 +38,7 @@ void KisActionManagerTest::testUpdateGUI()
{ {
KisDocument* doc = createEmptyDocument(); KisDocument* doc = createEmptyDocument();
KisMainWindow* mainWindow = KisPart::instance()->createMainWindow(); KisMainWindow* mainWindow = KisPart::instance()->createMainWindow();
QPointer<KisView> view = new KisView(doc, mainWindow->resourceManager(), mainWindow->actionCollection(), mainWindow); QPointer<KisView> view = new KisView(doc, mainWindow->viewManager(), mainWindow);
KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection()); KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection());
KisPart::instance()->addView(view); KisPart::instance()->addView(view);
mainWindow->showView(view); mainWindow->showView(view);
...@@ -72,7 +72,7 @@ void KisActionManagerTest::testCondition() ...@@ -72,7 +72,7 @@ void KisActionManagerTest::testCondition()
{ {
KisDocument* doc = createEmptyDocument(); KisDocument* doc = createEmptyDocument();
KisMainWindow* mainWindow = KisPart::instance()->createMainWindow(); KisMainWindow* mainWindow = KisPart::instance()->createMainWindow();
QPointer<KisView> view = new KisView(doc, mainWindow->resourceManager(), mainWindow->actionCollection(), mainWindow); QPointer<KisView> view = new KisView(doc, mainWindow->viewManager(), mainWindow);
KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection()); KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection());
KisPart::instance()->addView(view); KisPart::instance()->addView(view);
mainWindow->showView(view); mainWindow->showView(view);
...@@ -116,7 +116,7 @@ void KisActionManagerTest::testTakeAction() ...@@ -116,7 +116,7 @@ void KisActionManagerTest::testTakeAction()
{ {
KisDocument* doc = createEmptyDocument(); KisDocument* doc = createEmptyDocument();
KisMainWindow* mainWindow = KisPart::instance()->createMainWindow(); KisMainWindow* mainWindow = KisPart::instance()->createMainWindow();
QPointer<KisView> view = new KisView(doc, mainWindow->resourceManager(), mainWindow->actionCollection(), mainWindow); QPointer<KisView> view = new KisView(doc, mainWindow->viewManager(), mainWindow);
KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection()); KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection());
KisPart::instance()->addView(view); KisPart::instance()->addView(view);
mainWindow->showView(view); mainWindow->showView(view);
......
...@@ -75,7 +75,7 @@ void KisDerivedResourcesTest::test() ...@@ -75,7 +75,7 @@ void KisDerivedResourcesTest::test()
addResourceTypes(); addResourceTypes();
KisMainWindow* mainWindow = KisPart::instance()->createMainWindow(); KisMainWindow* mainWindow = KisPart::instance()->createMainWindow();
QPointer<KisView> view = new KisView(doc, mainWindow->resourceManager(), mainWindow->actionCollection(), mainWindow); QPointer<KisView> view = new KisView(doc, mainWindow->viewManager(), mainWindow);
KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection()); KisViewManager *viewManager = new KisViewManager(mainWindow, mainWindow->actionCollection());
KoCanvasResourceManager *manager = viewManager->resourceProvider()->resourceManager(); KoCanvasResourceManager *manager = viewManager->resourceProvider()->resourceManager();
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
m_doc->setCurrentImage(m_image); m_doc->setCurrentImage(m_image);
m_mainWindow = KisPart::instance()->createMainWindow(); m_mainWindow = KisPart::instance()->createMainWindow();
m_view = new KisView(m_doc, m_mainWindow->resourceManager(), m_mainWindow->actionCollection(), m_mainWindow); m_view = new KisView(m_doc, m_mainWindow->viewManager(), m_mainWindow);
m_image->refreshGraph(); m_image->refreshGraph();
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
void zoomcontroller_test::testApi() void zoomcontroller_test::testApi()
{ {
KoZoomHandler zoomHandler; KoZoomHandler zoomHandler;
KoZoomController zoomController(new KoCanvasControllerWidget(0), &zoomHandler, new KActionCollection(this), KoZoomAction::AspectMode); KoZoomController zoomController(new KoCanvasControllerWidget(0, 0), &zoomHandler, new KActionCollection(this), KoZoomAction::AspectMode);
Q_UNUSED(zoomController); Q_UNUSED(zoomController);
} }
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
image->initialRefreshGraph(); image->initialRefreshGraph();
mainWindow = new KisMainWindow(); mainWindow = new KisMainWindow();
imageView = new KisView(doc, mainWindow->resourceManager(), mainWindow->actionCollection(), mainWindow); imageView = new KisView(doc, mainWindow->viewManager(), mainWindow);
view = new KisViewManager(mainWindow, mainWindow->actionCollection()); view = new KisViewManager(mainWindow, mainWindow->actionCollection());
KoPattern *newPattern = new KoPattern(fetchDataFileLazy("HR_SketchPaper_01.pat")); KoPattern *newPattern = new KoPattern(fetchDataFileLazy("HR_SketchPaper_01.pat"));
......
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