Commit cd95c3c2 authored by Adrian Page's avatar Adrian Page

Add event handling and canvas updates for the OpenGL canvas, making it usable.

svn path=/trunk/koffice/; revision=650603
parent 7e872f8f
......@@ -237,40 +237,30 @@ void KisCanvas2::updateCanvas(const QRectF& rc)
}
}
void KisCanvas2::updateCanvasProjection( const QRect & rc )
{
#ifdef HAVE_OPENGL
if ( m_d->currentCanvasIsOpenGL ) {
Q_ASSERT( !m_d->openGLImageContext.isNull() );
if ( !m_d->openGLImageContext.isNull() ) {
m_d->openGLImageContext->update( rc );
}
}
else {
// Should never have an OpenGL image context and get here as that connects
// to the image directly.
Q_ASSERT( m_d->openGLImageContext.isNull() );
#endif
// XXX: Use the KisQPainterImageContext here
QPainter p( &m_d->canvasCache );
p.setCompositionMode( QPainter::CompositionMode_Source );
p.drawImage( rc.x(), rc.y(),
image()->convertToQImage(rc.x(), rc.y(), rc.width(), rc.height(),
m_d->monitorProfile,
m_d->view->resourceProvider()->HDRExposure() )
, 0, 0, rc.width(), rc.height() );
p.end();
QRect vRect = viewRectFromImagePixels( rc );
if ( !vRect.isEmpty() ) {
m_d->canvasWidget->preScale( vRect );
m_d->canvasWidget->widget()->update( vRect );
}
// XXX: Use the KisQPainterImageContext here
QPainter p( &m_d->canvasCache );
#ifdef HAVE_OPENGL
p.setCompositionMode( QPainter::CompositionMode_Source );
p.drawImage( rc.x(), rc.y(),
image()->convertToQImage(rc.x(), rc.y(), rc.width(), rc.height(),
m_d->monitorProfile,
m_d->view->resourceProvider()->HDRExposure() )
, 0, 0, rc.width(), rc.height() );
p.end();
QRect vRect = viewRectFromImagePixels( rc );
if ( !vRect.isEmpty() ) {
m_d->canvasWidget->preScale( vRect );
m_d->canvasWidget->widget()->update( vRect );
}
#endif
}
......@@ -350,9 +340,14 @@ void KisCanvas2::setImageSize( qint32 w, qint32 h )
void KisCanvas2::connectCurrentImage()
{
#ifdef HAVE_OPENGL
if (!m_d->openGLImageContext.isNull()) {
connect(m_d->openGLImageContext.data(), SIGNAL(sigImageUpdated(QRegion)), SLOT(slotOpenGLImageUpdated(QRegion)));
connect(m_d->openGLImageContext.data(), SIGNAL(sigSizeChanged(qint32, qint32)), SLOT(setImageSize(qint32, qint32)));
if (m_d->openGLImageContext) {
connect(m_d->openGLImageContext, SIGNAL(sigImageUpdated(const QRect &)), SLOT(updateCanvas()));
connect(m_d->openGLImageContext, SIGNAL(sigSizeChanged(qint32, qint32)), SLOT(setImageSize(qint32, qint32)));
} else {
#endif
connect(m_d->view->image(), SIGNAL(sigImageUpdated(const QRect &)), SLOT(updateCanvasProjection(const QRect &)));
connect(m_d->view->image(), SIGNAL(sigSizeChanged(qint32, qint32)), SLOT(setImageSize( qint32, qint32)) );
#ifdef HAVE_OPENGL
}
#endif
}
......@@ -360,10 +355,11 @@ void KisCanvas2::connectCurrentImage()
void KisCanvas2::disconnectCurrentImage()
{
#ifdef HAVE_OPENGL
if (!m_d->openGLImageContext.isNull()) {
if (m_d->openGLImageContext) {
m_d->openGLImageContext->disconnect(this);
}
#endif
m_d->view->image()->disconnect( this );
}
void KisCanvas2::resetCanvas()
......
......@@ -74,6 +74,8 @@ KisOpenGLCanvas2::KisOpenGLCanvas2( KisCanvas2 * canvas, QWidget * parent, KisOp
m_d->toolProxy = KoToolManager::instance()->createToolProxy(m_d->canvas);
m_d->openGLImageContext = context;
m_d->viewConverter = canvas->viewConverter();
setAcceptDrops( true );
setFocusPolicy(Qt::StrongFocus);
if (isSharing()) {
kDebug(41001) << "Created QGLWidget with sharing\n";
......@@ -223,6 +225,56 @@ void KisOpenGLCanvas2::documentOffsetMoved( QPoint pt )
updateGL();
}
void KisOpenGLCanvas2::mouseMoveEvent(QMouseEvent *e) {
m_d->toolProxy->mouseMoveEvent( e, m_d->viewConverter->viewToDocument(e->pos() + m_d->documentOffset ) );
}
void KisOpenGLCanvas2::mousePressEvent(QMouseEvent *e) {
m_d->toolProxy->mousePressEvent( e, m_d->viewConverter->viewToDocument(e->pos() + m_d->documentOffset ) );
}
void KisOpenGLCanvas2::mouseReleaseEvent(QMouseEvent *e) {
m_d->toolProxy->mouseReleaseEvent( e, m_d->viewConverter->viewToDocument(e->pos() + m_d->documentOffset ) );
}
void KisOpenGLCanvas2::mouseDoubleClickEvent(QMouseEvent *e) {
m_d->toolProxy->mouseDoubleClickEvent( e, m_d->viewConverter->viewToDocument(e->pos() + m_d->documentOffset ) );
}
void KisOpenGLCanvas2::keyPressEvent( QKeyEvent *e ) {
m_d->toolProxy->keyPressEvent(e);
}
void KisOpenGLCanvas2::keyReleaseEvent (QKeyEvent *e) {
m_d->toolProxy->keyReleaseEvent(e);
}
void KisOpenGLCanvas2::tabletEvent( QTabletEvent *e )
{
kDebug(41010) << "tablet event: " << e->pressure() << endl;
m_d->toolProxy->tabletEvent( e, m_d->viewConverter->viewToDocument( e->pos() + m_d->documentOffset ) );
}
void KisOpenGLCanvas2::wheelEvent( QWheelEvent *e )
{
m_d->toolProxy->wheelEvent( e, m_d->viewConverter->viewToDocument( e->pos() + m_d->documentOffset ) );
}
bool KisOpenGLCanvas2::event (QEvent *event) {
// we should forward tabs, and let tools decide if they should be used or ignored.
// if the tool ignores it, it will move focus.
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
if(keyEvent->key() == Qt::Key_Backtab)
return true;
if(keyEvent->key() == Qt::Key_Tab && event->type() == QEvent::KeyPress) {
// we loose key-release events, which I think is not an issue.
keyPressEvent(keyEvent);
return true;
}
}
return QWidget::event(event);
}
#include "kis_opengl_canvas2.moc"
#endif // HAVE_OPENGL
......@@ -54,6 +54,38 @@ public:
virtual ~KisOpenGLCanvas2();
public: // QWidget
/// reimplemented method from superclass
void keyPressEvent( QKeyEvent *e );
/// reimplemented method from superclass
void mouseMoveEvent(QMouseEvent *e);
/// reimplemented method from superclass
void mousePressEvent(QMouseEvent *e);
/// reimplemented method from superclass
void mouseReleaseEvent(QMouseEvent *e);
/// reimplemented method from superclass
void mouseDoubleClickEvent(QMouseEvent *e);
/// reimplemented method from superclass
void keyReleaseEvent (QKeyEvent *e);
/// reimplemented method from superclass
//void paintEvent(QPaintEvent * ev);
/// reimplemented method from superclass
void tabletEvent( QTabletEvent *e );
/// reimplemented method from superclass
void wheelEvent( QWheelEvent *e );
/// reimplemented method from superclass
bool event(QEvent *event);
protected:
void initializeGL();
......
......@@ -368,7 +368,7 @@ void KisOpenGLImageContext::setSelectionDisplayEnabled(bool enable)
m_displaySelection = enable;
}
void KisOpenGLImageContext::slotImageUpdated(QRect rc)
void KisOpenGLImageContext::slotImageUpdated(const QRect &rc)
{
QRect r = rc & m_image->bounds();
......
......@@ -99,9 +99,9 @@ signals:
/**
* Emitted whenever an action has caused the image to be recomposited.
*
* @param region The region that has been recomposited.
* @param r The rectangle that has been recomposited.
*/
void sigImageUpdated(QRegion region);
void sigImageUpdated(const QRect &r);
/**
* Emitted whenever the image size changes.
......@@ -124,7 +124,7 @@ protected:
static bool imageCanShareImageContext(KisImageSP image);
protected slots:
void slotImageUpdated(QRect r);
void slotImageUpdated(const QRect &);
void slotImageSizeChanged(qint32 w, qint32 h);
private:
......
......@@ -520,13 +520,6 @@ void KisView2::connectCurrentImage()
connect(img.data(), SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), m_d->layerManager, SLOT(layersUpdated()));
m_d->maskManager->maskUpdated();
{
connect(img.data(), SIGNAL(sigImageUpdated(const QRect &)), m_d->canvas, SLOT(updateCanvasProjection(const QRect &)));
connect(img.data(), SIGNAL(sigSizeChanged(qint32, qint32)), m_d->canvas, SLOT(setImageSize( qint32, qint32)) );
}
}
m_d->canvas->connectCurrentImage();
if( m_d->layerBox )
......@@ -544,7 +537,6 @@ void KisView2::disconnectCurrentImage()
img->disconnect(this);
img->disconnect( m_d->layerManager );
img->disconnect( m_d->canvas );
img->disconnect( m_d->selectionManager );
if( m_d->statusBar )
img->disconnect( m_d->statusBar );
......@@ -554,10 +546,7 @@ void KisView2::disconnectCurrentImage()
if( m_d->birdEyeBox )
m_d->birdEyeBox->setImage(KisImageSP(0));
m_d->canvas->disconnectCurrentImage();
}
}
void KisView2::slotUpdateFullScreen(bool toggle)
......
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