diff --git a/app/viewmainpage.cpp b/app/viewmainpage.cpp --- a/app/viewmainpage.cpp +++ b/app/viewmainpage.cpp @@ -374,7 +374,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) @@ -322,8 +323,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()), @@ -349,10 +350,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); @@ -630,16 +637,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)); @@ -805,11 +809,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