diff --git a/app/viewmainpage.cpp b/app/viewmainpage.cpp --- a/app/viewmainpage.cpp +++ b/app/viewmainpage.cpp @@ -371,7 +371,7 @@ void applyPalette(bool fullScreenMode) { - mDocumentViewContainer->setPalette(mGvCore->palette(fullScreenMode ? GvCore::FullScreenViewPalette : GvCore::NormalViewPalette)); + mDocumentViewContainer->applyPalette(mGvCore->palette(fullScreenMode ? GvCore::FullScreenViewPalette : GvCore::NormalViewPalette)); setupThumbnailBarStyleSheet(); } }; diff --git a/lib/documentview/documentview.h b/lib/documentview/documentview.h --- a/lib/documentview/documentview.h +++ b/lib/documentview/documentview.h @@ -134,12 +134,6 @@ int sortKey() const; void setSortKey(int sortKey); - /** - * If true, areas around the document will be painted with the default brush. - * If false they will be kept transparent. - */ - void setEraseBorders(bool); - bool isAnimated() const; public Q_SLOTS: diff --git a/lib/documentview/documentview.cpp b/lib/documentview/documentview.cpp --- a/lib/documentview/documentview.cpp +++ b/lib/documentview/documentview.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,7 @@ BirdEyeView* mBirdEyeView; QPointer mMoveAnimation; QPointer mFadeAnimation; + QGraphicsOpacityEffect* mOpacityEffect; LoadingIndicator* mLoadingIndicator; @@ -99,7 +101,6 @@ DocumentView::Setup mSetup; bool mCurrent; bool mCompareMode; - bool mEraseBorders; int controlWheelAccumulatedDelta; void setCurrentAdapter(AbstractDocumentViewAdapter* adapter) @@ -319,8 +320,8 @@ } } // Create a new fade animation - QPropertyAnimation* anim = new QPropertyAnimation(q, "opacity"); - anim->setStartValue(q->opacity()); + QPropertyAnimation* anim = new QPropertyAnimation(mOpacityEffect, "opacity"); + anim->setStartValue(mOpacityEffect->opacity()); anim->setEndValue(value); if (qFuzzyCompare(value, 1)) { QObject::connect(anim, SIGNAL(finished()), @@ -346,10 +347,16 @@ d->mBirdEyeView = 0; d->mCurrent = false; d->mCompareMode = false; - d->mEraseBorders = false; d->controlWheelAccumulatedDelta = 0; - setOpacity(0); + // We use an opacity effect instead of using the opacity property directly, because the latter operates at + // the painter level, which means if you draw multiple layers in paint(), all layers get the specified + // opacity, resulting in all layers being visible when 0 < opacity < 1. + // QGraphicsEffects on the other hand, operate after all painting is done, therefore 'flattening' all layers. + // This is important for fade effects, where we don't want any background layers visible during the fade. + d->mOpacityEffect = new QGraphicsOpacityEffect(this); + d->mOpacityEffect->setOpacity(0); + setGraphicsEffect(d->mOpacityEffect); scene->addItem(this); @@ -627,16 +634,13 @@ void DocumentView::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { - QRectF visibleRect = mapRectFromItem(d->mAdapter->widget(), d->mAdapter->visibleDocumentRect()); - if (d->mEraseBorders) { - QRegion borders = QRegion(boundingRect().toRect()) - - QRegion(visibleRect.toRect()); - Q_FOREACH(const QRect& rect, borders.rects()) { - painter->eraseRect(rect); - } - } + // Fill background manually, because setAutoFillBackground(true) fill with QPalette::Window, + // but our palettes use QPalette::Base for the background color/texture + painter->fillRect(rect(), palette().base()); + // Selection indicator/highlight if (d->mCompareMode && d->mCurrent) { + QRectF visibleRect = mapRectFromItem(d->mAdapter->widget(), d->mAdapter->visibleDocumentRect()); painter->save(); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(palette().highlight().color(), 2)); @@ -801,11 +805,6 @@ d->mSortKey = sortKey; } -void DocumentView::setEraseBorders(bool value) -{ - d->mEraseBorders = value; -} - void DocumentView::hideAndDeleteLater() { hide(); diff --git a/lib/documentview/documentviewcontainer.h b/lib/documentview/documentviewcontainer.h --- a/lib/documentview/documentviewcontainer.h +++ b/lib/documentview/documentviewcontainer.h @@ -77,6 +77,11 @@ void showMessageWidget(QGraphicsWidget*, Qt::Alignment); + /** + * Set palette on this and all document views + */ + void applyPalette(const QPalette& palette); + public Q_SLOTS: void updateLayout(); diff --git a/lib/documentview/documentviewcontainer.cpp b/lib/documentview/documentviewcontainer.cpp --- a/lib/documentview/documentviewcontainer.cpp +++ b/lib/documentview/documentviewcontainer.cpp @@ -119,6 +119,7 @@ DocumentView* DocumentViewContainer::createView() { DocumentView* view = new DocumentView(d->mScene); + view->setPalette(palette()); d->mAddedViews << view; view->show(); connect(view, &DocumentView::fadeInFinished, this, &DocumentViewContainer::slotFadeInFinished); @@ -185,7 +186,6 @@ DocumentView* newView = *d->mAddedViews.begin(); newView->setGeometry(rect()); - newView->setEraseBorders(true); QPropertyAnimation* anim = newView->fadeIn(); oldView->setZValue(-1); @@ -256,7 +256,8 @@ } else { // Not animated, set final geometry and opacity now view->setGeometry(rect); - view->setOpacity(1); + // Assumes opacity set using QGraphicsOpacityEffect, and not the opacity() property + view->setGraphicsEffect(0); } ++col; @@ -300,7 +301,6 @@ } d->mAddedViews.remove(view); d->mViews.insert(view); - view->setEraseBorders(false); } void DocumentViewContainer::slotConfigChanged() @@ -331,4 +331,12 @@ widget->setZValue(1); } +void DocumentViewContainer::applyPalette(const QPalette& palette) +{ + setPalette(palette); + for (DocumentView* view : (d->mViews | d->mAddedViews)) { + view->setPalette(palette); + } +} + } // namespace diff --git a/lib/documentview/svgviewadapter.h b/lib/documentview/svgviewadapter.h --- a/lib/documentview/svgviewadapter.h +++ b/lib/documentview/svgviewadapter.h @@ -58,6 +58,8 @@ QGraphicsSvgItem* mSvgItem; AbstractImageView::AlphaBackgroundMode mAlphaBackgroundMode; QColor mAlphaBackgroundColor; + bool mDocumentFullyLoaded; + void adjustItemPos(); void drawAlphaBackground(QPainter* painter); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -47,6 +47,7 @@ , mSvgItem(new QGraphicsSvgItem(this)) , mAlphaBackgroundMode(AbstractImageView::AlphaBackgroundCheckBoard) , mAlphaBackgroundColor(Qt::black) +, mDocumentFullyLoaded(false) { // So we aren't unnecessarily drawing the background for every paint() setCacheMode(QGraphicsItem::DeviceCoordinateCache); @@ -79,6 +80,7 @@ } applyPendingScrollPos(); completed(); + mDocumentFullyLoaded = true; } void SvgImageView::onZoomChanged() @@ -138,7 +140,9 @@ void SvgImageView::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { - drawAlphaBackground(painter); + if (mDocumentFullyLoaded) { + drawAlphaBackground(painter); + } } //// SvgViewAdapter ////