diff --git a/app/configdialog.cpp b/app/configdialog.cpp --- a/app/configdialog.cpp +++ b/app/configdialog.cpp @@ -68,6 +68,7 @@ mAlphaBackgroundModeGroup = new InvisibleButtonGroup(widget); mAlphaBackgroundModeGroup->setObjectName(QLatin1String("kcfg_AlphaBackgroundMode")); + mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.noBackgroundRadioButton, int(AbstractImageView::AlphaBackgroundNone)); mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.checkBoardRadioButton, int(AbstractImageView::AlphaBackgroundCheckBoard)); mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.solidColorRadioButton, int(AbstractImageView::AlphaBackgroundSolid)); diff --git a/app/imageviewconfigpage.ui b/app/imageviewconfigpage.ui --- a/app/imageviewconfigpage.ui +++ b/app/imageviewconfigpage.ui @@ -7,7 +7,7 @@ 0 0 500 - 600 + 641 @@ -25,25 +25,53 @@ - - - 6 + + + + + None + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Mouse wheel behavior: - - 0 + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + mouseWheelScrollRadioButton + + + + - + - &Check board - - - true + Browse - + Qt::Horizontal @@ -57,12 +85,21 @@ - + 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -97,7 +134,7 @@ - + Qt::Vertical @@ -113,33 +150,20 @@ - - - - Mouse wheel behavior: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - mouseWheelScrollRadioButton - - - - - + + - + - Scroll + Autofit each image true - + Qt::Horizontal @@ -153,17 +177,20 @@ - - + + - + - Browse + Scroll + + + true - + Qt::Horizontal @@ -177,7 +204,7 @@ - + Qt::Vertical @@ -193,7 +220,7 @@ - + Zoom mode: @@ -206,34 +233,7 @@ - - - - - - Autofit each image - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - + @@ -257,7 +257,7 @@ - + @@ -281,7 +281,7 @@ - + Qt::Vertical @@ -297,7 +297,7 @@ - + @@ -321,7 +321,7 @@ - + Qt::Vertical @@ -337,7 +337,7 @@ - + Animations: @@ -350,7 +350,7 @@ - + @@ -377,7 +377,7 @@ - + @@ -401,7 +401,7 @@ - + @@ -425,7 +425,7 @@ - + Qt::Vertical @@ -441,14 +441,14 @@ - + <b>Thumbnail Bar</b> - + Qt::Vertical @@ -464,7 +464,7 @@ - + Orientation: @@ -477,7 +477,7 @@ - + @@ -501,7 +501,7 @@ - + @@ -525,7 +525,7 @@ - + Row count: @@ -538,7 +538,7 @@ - + @@ -565,7 +565,7 @@ - + Qt::Vertical @@ -578,19 +578,56 @@ + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + &Check board + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + KColorButton QPushButton
kcolorbutton.h
- - QSpinBox - QSpinBox -
knuminput.h
-
checkBoardRadioButton diff --git a/lib/documentview/abstractimageview.h b/lib/documentview/abstractimageview.h --- a/lib/documentview/abstractimageview.h +++ b/lib/documentview/abstractimageview.h @@ -45,6 +45,7 @@ ForceUpdate }; enum AlphaBackgroundMode { + AlphaBackgroundNone, AlphaBackgroundCheckBoard, AlphaBackgroundSolid }; diff --git a/lib/documentview/documentview.h b/lib/documentview/documentview.h --- a/lib/documentview/documentview.h +++ b/lib/documentview/documentview.h @@ -126,7 +126,7 @@ void moveTo(const QRect&); void moveToAnimated(const QRect&); QPropertyAnimation* fadeIn(); - void fadeOut(); + QPropertyAnimation* fadeOut(); void fakeFadeOut(); void setGeometry(const QRectF& rect) Q_DECL_OVERRIDE; diff --git a/lib/documentview/documentview.cpp b/lib/documentview/documentview.cpp --- a/lib/documentview/documentview.cpp +++ b/lib/documentview/documentview.cpp @@ -759,9 +759,10 @@ return d->mFadeAnimation.data(); } -void DocumentView::fadeOut() +QPropertyAnimation* DocumentView::fadeOut() { d->fadeTo(0); + return d->mFadeAnimation.data(); } void DocumentView::slotFadeInFinished() diff --git a/lib/documentview/documentviewcontainer.cpp b/lib/documentview/documentviewcontainer.cpp --- a/lib/documentview/documentviewcontainer.cpp +++ b/lib/documentview/documentviewcontainer.cpp @@ -183,13 +183,17 @@ if (animated && crossFade) { DocumentView* oldView = *d->mRemovedViews.begin(); DocumentView* newView = *d->mAddedViews.begin(); + newView->setZValue(oldView->zValue() - 1); newView->setGeometry(rect()); newView->setEraseBorders(true); - QPropertyAnimation* anim = newView->fadeIn(); - oldView->setZValue(-1); - connect(anim, &QPropertyAnimation::finished, oldView, &DocumentView::hideAndDeleteLater); + // We animate both views so there are no artifacts when switching between images with/without transparency + QPropertyAnimation* newViewAnim = newView->fadeIn(); + QPropertyAnimation* oldViewAnim = oldView->fadeOut(); + + connect(newViewAnim, &QPropertyAnimation::finished, oldView, &DocumentView::hideAndDeleteLater); + connect(oldViewAnim, &QPropertyAnimation::finished, oldView, &DocumentView::hideAndDeleteLater); d->mRemovedViews.clear(); return; diff --git a/lib/documentview/rasterimageview.cpp b/lib/documentview/rasterimageview.cpp --- a/lib/documentview/rasterimageview.cpp +++ b/lib/documentview/rasterimageview.cpp @@ -164,17 +164,29 @@ void drawAlphaBackground(QPainter* painter, const QRect& viewportRect, const QPoint& zoomedImageTopLeft, QPixmap texture) { - if (mAlphaBackgroundMode == AbstractImageView::AlphaBackgroundCheckBoard) { - QPoint textureOffset( - zoomedImageTopLeft.x() % texture.width(), - zoomedImageTopLeft.y() % texture.height() - ); - painter->drawTiledPixmap( - viewportRect, - texture, - textureOffset); - } else { - painter->fillRect(viewportRect, mAlphaBackgroundColor); + switch (mAlphaBackgroundMode) { + case (AbstractImageView::AlphaBackgroundCheckBoard): { + QPoint textureOffset( + zoomedImageTopLeft.x() % texture.width(), + zoomedImageTopLeft.y() % texture.height() + ); + painter->drawTiledPixmap( + viewportRect, + texture, + textureOffset); + break; + } + case (AbstractImageView::AlphaBackgroundSolid): { + painter->fillRect(viewportRect, mAlphaBackgroundColor); + break; + } + case (AbstractImageView::AlphaBackgroundNone): { + painter->fillRect(viewportRect, Qt::transparent); + break; + } + default: { + Q_ASSERT(0); + } } } }; @@ -188,7 +200,7 @@ d->mApplyDisplayTransform = true; d->mDisplayTransform = 0; - d->mAlphaBackgroundMode = AlphaBackgroundCheckBoard; + d->mAlphaBackgroundMode = AlphaBackgroundNone; d->mAlphaBackgroundColor = Qt::black; d->mRenderingIntent = INTENT_PERCEPTUAL; d->mEnlargeSmallerImages = false; @@ -332,14 +344,15 @@ d->mBufferIsEmpty = false; { QPainter painter(&d->mCurrentBuffer); + painter.setCompositionMode(QPainter::CompositionMode_Source); if (document()->hasAlphaChannel()) { d->drawAlphaBackground( &painter, QRect(viewportLeft, viewportTop, image.width(), image.height()), QPoint(zoomedImageLeft, zoomedImageTop), alphaBackgroundTexture() ); - } else { - painter.setCompositionMode(QPainter::CompositionMode_Source); + // This is required so transparent pixels don't replace our background + painter.setCompositionMode(QPainter::CompositionMode_SourceOver); } painter.drawImage(viewportLeft, viewportTop, image); } @@ -379,11 +392,11 @@ if (d->mAlternateBuffer.size() != d->mCurrentBuffer.size()) { d->mAlternateBuffer = QPixmap(d->mCurrentBuffer.size()); } + d->mAlternateBuffer.fill(Qt::transparent); QPainter painter(&d->mAlternateBuffer); painter.drawPixmap(-delta, d->mCurrentBuffer); } qSwap(d->mCurrentBuffer, d->mAlternateBuffer); - // Scale missing parts QRegion bufferRegion = QRegion(d->mCurrentBuffer.rect().translated(scrollPos().toPoint())); QRegion updateRegion = bufferRegion - bufferRegion.translated(-delta.toPoint()); diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -130,6 +130,11 @@ painter->fillRect(imageRect, mAlphaBackgroundColor); break; } + case AbstractImageView::AlphaBackgroundNone: { + // Unlike RasterImageView, SVGs are rendered directly on the image view, + // therefore we can simply not draw a background + break; + } default: { Q_ASSERT(0); } diff --git a/lib/gwenviewconfig.kcfg b/lib/gwenviewconfig.kcfg --- a/lib/gwenviewconfig.kcfg +++ b/lib/gwenviewconfig.kcfg @@ -119,10 +119,11 @@ + - AbstractImageView::AlphaBackgroundCheckBoard + AbstractImageView::AlphaBackgroundNone #ffffff