Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 419a90fd authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Extend panning range to include any reference images

parent ecfc956d
......@@ -261,6 +261,11 @@ public:
*/
virtual void setScrollBarValue(const QPoint &value) = 0;
/**
* Update the range of scroll bars
*/
virtual void resetScrollBars() = 0;
/**
* Called when the size of your document in view coordinates (pixels) changes, for instance when zooming.
*
......@@ -467,11 +472,11 @@ public:
void panRight() override {}
QPoint scrollBarValue() const override {return QPoint();}
void setScrollBarValue(const QPoint &/*value*/) override {}
void resetScrollBars() override {}
void updateDocumentSize(const QSize &/*sz*/, bool /*recalculateCenter*/) override {}
void setZoomWithWheel(bool /*zoom*/) override {}
void setVastScrolling(qreal /*factor*/) override {}
QPointF currentCursorPosition() const override { return QPointF(); }
};
#endif
......@@ -233,7 +233,7 @@ void KoCanvasControllerWidget::resizeEvent(QResizeEvent *resizeEvent)
// XXX: When resizing, keep the area we're looking at now in the
// center of the resized view.
d->resetScrollBars();
resetScrollBars();
d->setDocumentOffset();
}
......@@ -458,7 +458,7 @@ void KoCanvasControllerWidget::updateDocumentSize(const QSize &sz, bool recalcul
d->ignoreScrollSignals = true;
KoCanvasController::setDocumentSize(sz);
d->viewportWidget->setDocumentSize(sz);
d->resetScrollBars();
resetScrollBars();
// Always emit the new offset.
updateCanvasOffsetX();
......@@ -603,6 +603,16 @@ void KoCanvasControllerWidget::setScrollBarValue(const QPoint &value)
vBar->setValue(value.y());
}
void KoCanvasControllerWidget::resetScrollBars()
{
d->resetScrollBars();
}
qreal KoCanvasControllerWidget::vastScrollingFactor() const
{
return d->vastScrollingFactor;
}
KoCanvasControllerWidget::Private *KoCanvasControllerWidget::priv()
{
return d;
......
......@@ -144,6 +144,8 @@ public:
QPointF currentCursorPosition() const override;
void resetScrollBars() override;
/**
* \internal
*/
......@@ -161,6 +163,8 @@ private Q_SLOTS:
protected:
friend class KisZoomAndPanTest;
qreal vastScrollingFactor() const;
/// reimplemented from QWidget
void paintEvent(QPaintEvent *event) override;
/// reimplemented from QWidget
......
......@@ -1714,6 +1714,10 @@ KisSharedPtr<KisReferenceImagesLayer> KisDocument::referenceImagesLayer() const
void KisDocument::setReferenceImagesLayer(KisSharedPtr<KisReferenceImagesLayer> layer, bool updateImage)
{
if (d->referenceImagesLayer) {
d->referenceImagesLayer->disconnect(this);
}
if (updateImage) {
if (layer) {
d->image->addNode(layer);
......@@ -1723,6 +1727,11 @@ void KisDocument::setReferenceImagesLayer(KisSharedPtr<KisReferenceImagesLayer>
}
d->referenceImagesLayer = layer;
if (d->referenceImagesLayer) {
connect(d->referenceImagesLayer, SIGNAL(sigUpdateCanvas(const QRectF&)),
this, SIGNAL(sigReferenceImagesChanged()));
}
}
void KisDocument::setPreActivatedNode(KisNodeSP activatedNode)
......@@ -1805,3 +1814,14 @@ QColor KisDocument::assistantsGlobalColor()
{
return d->globalAssistantsColor;
}
QRectF KisDocument::documentBounds() const
{
QRectF bounds = d->image->bounds();
if (d->referenceImagesLayer) {
bounds |= d->referenceImagesLayer->boundingImageRect();
}
return bounds;
}
......@@ -445,6 +445,8 @@ Q_SIGNALS:
void sigCompleteBackgroundSaving(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void sigReferenceImagesChanged();
private Q_SLOTS:
void finishExportInBackground();
void slotChildCompletedSavingInBackground(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
......@@ -605,6 +607,11 @@ public:
bool save(bool showWarnings, KisPropertiesConfigurationSP exportConfiguration);
/**
* Return the bounding box of the image and associated elements (e.g. reference images)
*/
QRectF documentBounds() const;
Q_SIGNALS:
void completed();
......
......@@ -251,6 +251,8 @@ void KisCanvas2::setup()
connect(&m_d->regionOfInterestUpdateCompressor, SIGNAL(timeout()), SLOT(slotUpdateRegionOfInterest()));
connect(m_d->view->document(), SIGNAL(sigReferenceImagesChanged()), this, SLOT(slotReferenceImagesChanged()));
initializeFpsDecoration();
}
......@@ -862,6 +864,11 @@ void KisCanvas2::slotUpdateRegionOfInterest()
}
}
void KisCanvas2::slotReferenceImagesChanged()
{
canvasController()->resetScrollBars();
}
void KisCanvas2::setRenderingLimit(const QRect &rc)
{
m_d->renderingLimit = rc;
......
......@@ -296,6 +296,8 @@ private Q_SLOTS:
void slotUpdateRegionOfInterest();
void slotReferenceImagesChanged();
public:
bool isPopupPaletteVisible() const;
......
......@@ -19,6 +19,7 @@
#include "kis_canvas_controller.h"
#include <QMouseEvent>
#include <QScrollBar>
#include <QTabletEvent>
#include <klocalizedstring.h>
......@@ -28,6 +29,7 @@
#include "kis_coordinates_converter.h"
#include "kis_canvas2.h"
#include "opengl/kis_opengl_canvas2.h"
#include "KisDocument.h"
#include "kis_image.h"
#include "KisViewManager.h"
#include "KisView.h"
......@@ -352,3 +354,46 @@ void KisCanvasController::restoreCanvasState(const KisPropertiesConfiguration &c
slotToggleWrapAroundMode(config.getBool("wrapAround", false));
kritaCanvas->setLodAllowedInCanvas(config.getBool("enableInstantPreview", false));
}
void KisCanvasController::resetScrollBars()
{
// The scrollbar value always points at the top-left corner of the
// bit of image we paint.
KisDocument *doc = m_d->view->document();
if (!doc) return;
QRectF documentBounds = doc->documentBounds();
QRectF viewRect = m_d->coordinatesConverter->imageToWidget(documentBounds);
// Cancel out any existing pan
const QRectF imageBounds = m_d->view->image()->bounds();
const QRectF imageBB = m_d->coordinatesConverter->imageToWidget(imageBounds);
QPointF pan = imageBB.topLeft();
viewRect.translate(-pan);
int drawH = viewport()->height();
int drawW = viewport()->width();
qreal horizontalReserve = vastScrollingFactor() * drawW;
qreal verticalReserve = vastScrollingFactor() * drawH;
qreal xMin = viewRect.left() - horizontalReserve;
qreal yMin = viewRect.top() - verticalReserve;
qreal xMax = viewRect.right() - drawW + horizontalReserve;
qreal yMax = viewRect.bottom() - drawH + verticalReserve;
QScrollBar *hScroll = horizontalScrollBar();
QScrollBar *vScroll = verticalScrollBar();
hScroll->setRange(static_cast<int>(xMin), static_cast<int>(xMax));
vScroll->setRange(static_cast<int>(yMin), static_cast<int>(yMax));
int fontHeight = QFontMetrics(font()).height();
vScroll->setPageStep(drawH);
vScroll->setSingleStep(fontHeight);
hScroll->setPageStep(drawW);
hScroll->setSingleStep(fontHeight);
}
......@@ -52,6 +52,8 @@ public:
void saveCanvasState(KisPropertiesConfiguration &config) const;
void restoreCanvasState(const KisPropertiesConfiguration &config);
void resetScrollBars() override;
public Q_SLOTS:
void mirrorCanvas(bool enable);
void rotateCanvas(qreal angle, const QPointF &center);
......
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