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
void KoCanvasControllerWidget::Private::activate()
{
QWidget *parent = q;
while (parent->parentWidget()) {
parent = parent->parentWidget();
}
KoCanvasSupervisor *observerProvider = dynamic_cast<KoCanvasSupervisor*>(parent);
if (!observerProvider) {
return;
}
KoCanvasBase *canvas = q->canvas();
Q_FOREACH (KoCanvasObserverBase *docker, observerProvider->canvasObservers()) {
KoCanvasObserverBase *observer = dynamic_cast<KoCanvasObserverBase*>(docker);
......@@ -157,11 +151,6 @@ void KoCanvasControllerWidget::Private::activate()
void KoCanvasControllerWidget::Private::unsetCanvas()
{
QWidget *parent = q;
while (parent->parentWidget()) {
parent = parent->parentWidget();
}
KoCanvasSupervisor *observerProvider = dynamic_cast<KoCanvasSupervisor*>(parent);
if (!observerProvider) {
return;
}
......@@ -176,10 +165,10 @@ void KoCanvasControllerWidget::Private::unsetCanvas()
}
////////////
KoCanvasControllerWidget::KoCanvasControllerWidget(KActionCollection * actionCollection, QWidget *parent)
KoCanvasControllerWidget::KoCanvasControllerWidget(KActionCollection * actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent)
: QAbstractScrollArea(parent)
, 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
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......
......@@ -32,7 +32,7 @@
class KoShape;
class KoCanvasBase;
class KoCanvasSupervisor;
/**
* KoCanvasController implementation for QWidget based canvases
*/
......@@ -45,7 +45,7 @@ public:
* Constructor.
* @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;
/**
......
......@@ -28,6 +28,7 @@
#include <FlakeDebug.h>
#include <KoConfig.h>
#include "KoCanvasSupervisor.h"
class KoCanvasControllerWidget;
class Viewport;
......@@ -37,8 +38,9 @@ class Q_DECL_HIDDEN KoCanvasControllerWidget::Private
{
public:
Private(KoCanvasControllerWidget *qq)
Private(KoCanvasControllerWidget *qq, KoCanvasSupervisor *observerProvider)
: q(qq)
, observerProvider(observerProvider)
, canvas(0)
, ignoreScrollSignals(false)
, zoomWithWheel(false)
......@@ -58,6 +60,7 @@ public:
void unsetCanvas();
KoCanvasControllerWidget *q;
KoCanvasSupervisor *observerProvider;
QPointer<KoCanvasBase> canvas;
Viewport *viewportWidget;
bool ignoreScrollSignals;
......
......@@ -303,10 +303,7 @@ void KisSketchView::documentChanged()
connect(d->doc, SIGNAL(modified(bool)), SIGNAL(modifiedChanged()));
QPointer<KisView> view = qobject_cast<KisView*>(KisPart::instance()->createView(d->doc,
d->viewManager->resourceProvider()->resourceManager(),
d->viewManager->actionCollection(),
QApplication::activeWindow()));
QPointer<KisView> view = KisPart::instance()->createView(d->doc, d->viewManager, QApplication::activeWindow());
view->setViewManager(d->viewManager);
view->canvasBase()->setFavoriteResourceManager(d->viewManager->paintOpBox()->favoriteResourcesManager());
view->slotLoadingFinished();
......
......@@ -879,7 +879,7 @@ void KisMainWindow::showDocument(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);
emit guiLoadingFinished();
......
......@@ -228,10 +228,7 @@ KisMainWindow *KisPart::createMainWindow(QUuid id)
return mw;
}
KisView *KisPart::createView(KisDocument *document,
KoCanvasResourceManager *resourceManager,
KActionCollection *actionCollection,
QWidget *parent)
KisView *KisPart::createView(KisDocument *document, KisViewManager *viewManager, QWidget *parent)
{
// If creating the canvas fails, record this and disable OpenGL next time
KisConfig cfg;
......@@ -246,7 +243,7 @@ KisView *KisPart::createView(KisDocument *document,
grp.sync();
QApplication::setOverrideCursor(Qt::WaitCursor);
KisView *view = new KisView(document, resourceManager, actionCollection, parent);
KisView *view = new KisView(document, viewManager, parent);
QApplication::restoreOverrideCursor();
// Record successful canvas creation
......
......@@ -206,10 +206,7 @@ public:
* 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.
*/
KisView *createView(KisDocument *document,
KoCanvasResourceManager *resourceManager,
KActionCollection *actionCollection,
QWidget *parent);
KisView *createView(KisDocument *document, KisViewManager *viewManager, QWidget *parent);
/**
* Adds a view to the document. If the part doesn't know yet about
......
......@@ -108,12 +108,12 @@ class Q_DECL_HIDDEN KisView::Private
public:
Private(KisView *_q,
KisDocument *document,
KoCanvasResourceManager *resourceManager,
KActionCollection *actionCollection)
: actionCollection(actionCollection)
KisViewManager *viewManager)
: actionCollection(viewManager->actionCollection())
, viewManager(viewManager)
, viewConverter()
, canvasController(_q, actionCollection)
, canvas(&viewConverter, resourceManager, _q, document->shapeController())
, canvasController(_q, viewManager->mainWindow(), viewManager->actionCollection())
, canvas(&viewConverter, viewManager->resourceProvider()->resourceManager(), viewManager->mainWindow(), _q, document->shapeController())
, zoomManager(_q, &this->viewConverter, &this->canvasController)
, paintingAssistantsDecoration(new KisPaintingAssistantsDecoration(_q))
, referenceImagesDecoration(new KisReferenceImagesDecoration(_q))
......@@ -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)
, d(new Private(this, document, resourceManager, actionCollection))
, d(new Private(this, document, viewManager))
{
Q_ASSERT(document);
connect(document, SIGNAL(titleModified(QString,bool)), this, SIGNAL(titleModified(QString,bool)));
......@@ -653,7 +653,7 @@ QPrintDialog *KisView::createPrintDialog(KisPrintJob *printJob, QWidget *parent)
KisMainWindow * KisView::mainWindow() const
{
return dynamic_cast<KisMainWindow *>(window());
return d->viewManager->mainWindow();
}
void KisView::setSubWindow(QMdiSubWindow *subWindow)
......
......@@ -74,7 +74,7 @@ public:
/**
* 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;
QAction *undoAction() const;
......
......@@ -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)
, m_d(new KisCanvas2Private(this, coordConverter, view, resourceManager))
{
......@@ -179,7 +179,7 @@ KisCanvas2::KisCanvas2(KisCoordinatesConverter *coordConverter, KoCanvasResource
* light.
*/
m_d->bootstrapLodBlocked = true;
connect(view->mainWindow(), SIGNAL(guiLoadingFinished()), SLOT(bootstrapFinished()));
connect(mainWindow, SIGNAL(guiLoadingFinished()), SLOT(bootstrapFinished()));
KisImageConfig config;
......
......@@ -76,7 +76,7 @@ public:
* @param viewConverter the viewconverter for converting between
* 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;
......
......@@ -90,8 +90,8 @@ void KisCanvasController::Private::updateDocumentSizeAfterTransform()
}
KisCanvasController::KisCanvasController(QPointer<KisView>parent, KActionCollection * actionCollection)
: KoCanvasControllerWidget(actionCollection, parent),
KisCanvasController::KisCanvasController(QPointer<KisView>parent, KoCanvasSupervisor *observerProvider, KActionCollection * actionCollection)
: KoCanvasControllerWidget(actionCollection, observerProvider, parent),
m_d(new Private(this))
{
m_d->view = parent;
......
......@@ -20,6 +20,7 @@
#define KIS_CANVAS_CONTROLLER_H
#include <KoCanvasControllerWidget.h>
#include <libs/flake/KoCanvasSupervisor.h>
#include "kritaui_export.h"
#include "kis_types.h"
......@@ -32,7 +33,7 @@ class KRITAUI_EXPORT KisCanvasController : public KoCanvasControllerWidget
Q_OBJECT
public:
KisCanvasController(QPointer<KisView>parent, KActionCollection * actionCollection);
KisCanvasController(QPointer<KisView>parent, KoCanvasSupervisor *observerProvider, KActionCollection * actionCollection);
~KisCanvasController() override;
void setCanvas(KoCanvasBase *canvas) override;
......
......@@ -38,7 +38,7 @@ void KisActionManagerTest::testUpdateGUI()
{
KisDocument* doc = createEmptyDocument();
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());
KisPart::instance()->addView(view);
mainWindow->showView(view);
......@@ -72,7 +72,7 @@ void KisActionManagerTest::testCondition()
{
KisDocument* doc = createEmptyDocument();
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());
KisPart::instance()->addView(view);
mainWindow->showView(view);
......@@ -116,7 +116,7 @@ void KisActionManagerTest::testTakeAction()
{
KisDocument* doc = createEmptyDocument();
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());
KisPart::instance()->addView(view);
mainWindow->showView(view);
......
......@@ -75,7 +75,7 @@ void KisDerivedResourcesTest::test()
addResourceTypes();
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());
KoCanvasResourceManager *manager = viewManager->resourceProvider()->resourceManager();
......
......@@ -59,7 +59,7 @@ public:
m_doc->setCurrentImage(m_image);
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();
......
......@@ -31,7 +31,7 @@
void zoomcontroller_test::testApi()
{
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);
}
......
......@@ -59,7 +59,7 @@ public:
image->initialRefreshGraph();
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());
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