Commit 7cb584e2 authored by Huon Imberger's avatar Huon Imberger
Browse files

Add "None" option for transparent background in Image view

Summary:
Some users may prefer viewing images with an alpha channel without a
background. Before D11629 this was the behaviour for SVGs, but is now
impossible for both SVGs and raster images. This patch adds this option,
effectively adding functionality for raster images, and getting back the
previous behaviour for SVGs.
We also make {nav None} the default.

For raster images, choosing {nav None} paints the buffer with
`Qt::transparent` where needed.
For SVGs, this option doesn't draw anything, which was the behaviour before
D11629.

Depends on D11629

Example (PNG on left, SVG on right):
{F5764317}

Fullscreen:
{F5766995}

Test Plan:
Test the {nav None} option for both raster images and SVGs.
Ensure other options (checkboard and solid color) are unaffected.

Reviewers: #gwenview, rkflx, ngraham

Reviewed By: #gwenview, rkflx, ngraham

Subscribers: zzag, muhlenpfordt

Tags: #gwenview

Differential Revision: https://phabricator.kde.org/D11630
parent 836ec0e4
......@@ -68,6 +68,7 @@ ConfigDialog::ConfigDialog(QWidget* parent)
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));
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>600</height>
<height>650</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
......@@ -25,6 +25,39 @@
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_0">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="noBackgroundRadioButton">
<property name="text">
<string>None</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_0">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<property name="spacing">
<number>6</number>
......@@ -38,7 +71,7 @@
<string>&amp;Check board</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
......@@ -57,7 +90,7 @@
</item>
</layout>
</item>
<item row="1" column="1">
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>6</number>
......@@ -97,7 +130,7 @@
</item>
</layout>
</item>
<item row="2" column="1">
<item row="3" column="1">
<spacer name="verticalSpacer_1">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -113,7 +146,7 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Mouse wheel behavior:</string>
......@@ -126,7 +159,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="mouseWheelScrollRadioButton">
......@@ -153,7 +186,7 @@
</item>
</layout>
</item>
<item row="4" column="1">
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="mouseWheelBrowseRadioButton">
......@@ -177,7 +210,7 @@
</item>
</layout>
</item>
<item row="5" column="1">
<item row="6" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -193,7 +226,7 @@
</property>
</spacer>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Zoom mode:</string>
......@@ -206,7 +239,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QRadioButton" name="autofitZoomModeRadioButton">
......@@ -233,7 +266,7 @@
</item>
</layout>
</item>
<item row="7" column="1">
<item row="8" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QRadioButton" name="keepSameZoomModeRadioButton">
......@@ -257,7 +290,7 @@
</item>
</layout>
</item>
<item row="8" column="1">
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QRadioButton" name="individualZoomModeRadioButton">
......@@ -281,7 +314,7 @@
</item>
</layout>
</item>
<item row="9" column="1">
<item row="10" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -297,7 +330,7 @@
</property>
</spacer>
</item>
<item row="10" column="1">
<item row="11" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="kcfg_EnlargeSmallerImages">
......@@ -321,7 +354,7 @@
</item>
</layout>
</item>
<item row="11" column="1">
<item row="12" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -337,7 +370,7 @@
</property>
</spacer>
</item>
<item row="12" column="0">
<item row="13" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Animations:</string>
......@@ -350,7 +383,7 @@
</property>
</widget>
</item>
<item row="12" column="1">
<item row="13" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QRadioButton" name="glAnimationRadioButton">
......@@ -377,7 +410,7 @@
</item>
</layout>
</item>
<item row="13" column="1">
<item row="14" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QRadioButton" name="softwareAnimationRadioButton">
......@@ -401,7 +434,7 @@
</item>
</layout>
</item>
<item row="14" column="1">
<item row="15" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QRadioButton" name="noAnimationRadioButton">
......@@ -425,7 +458,7 @@
</item>
</layout>
</item>
<item row="15" column="1">
<item row="16" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -441,14 +474,14 @@
</property>
</spacer>
</item>
<item row="16" column="0">
<item row="17" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;b&gt;Thumbnail Bar&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="17" column="1">
<item row="18" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -464,7 +497,7 @@
</property>
</spacer>
</item>
<item row="18" column="0">
<item row="19" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Orientation:</string>
......@@ -477,7 +510,7 @@
</property>
</widget>
</item>
<item row="18" column="1">
<item row="19" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QRadioButton" name="horizontalRadioButton">
......@@ -501,7 +534,7 @@
</item>
</layout>
</item>
<item row="19" column="1">
<item row="20" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QRadioButton" name="verticalRadioButton">
......@@ -525,7 +558,7 @@
</item>
</layout>
</item>
<item row="20" column="0">
<item row="21" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Row count:</string>
......@@ -538,7 +571,7 @@
</property>
</widget>
</item>
<item row="20" column="1">
<item row="21" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QSpinBox" name="kcfg_ThumbnailBarRowCount">
......@@ -565,7 +598,7 @@
</item>
</layout>
</item>
<item row="21" column="1">
<item row="22" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
......@@ -45,6 +45,7 @@ public:
ForceUpdate
};
enum AlphaBackgroundMode {
AlphaBackgroundNone,
AlphaBackgroundCheckBoard,
AlphaBackgroundSolid
};
......
......@@ -164,17 +164,26 @@ struct RasterImageViewPrivate
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::AlphaBackgroundNone:
painter->fillRect(viewportRect, Qt::transparent);
break;
case AbstractImageView::AlphaBackgroundCheckBoard:
{
const QPoint textureOffset(
zoomedImageTopLeft.x() % texture.width(),
zoomedImageTopLeft.y() % texture.height());
painter->drawTiledPixmap(
viewportRect,
texture,
textureOffset);
break;
}
case AbstractImageView::AlphaBackgroundSolid:
painter->fillRect(viewportRect, mAlphaBackgroundColor);
break;
default:
Q_ASSERT(0);
}
}
};
......@@ -188,7 +197,7 @@ RasterImageView::RasterImageView(QGraphicsItem* parent)
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 +341,15 @@ void RasterImageView::updateFromScaler(int zoomedImageLeft, int zoomedImageTop,
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,6 +389,7 @@ void RasterImageView::onScrollPosChanged(const QPointF& oldPos)
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);
}
......
......@@ -123,6 +123,10 @@ void SvgImageView::drawAlphaBackground(QPainter* painter)
const QRectF imageRect = QRectF(imageOffset(), visibleImageSize());
switch (mAlphaBackgroundMode) {
case AbstractImageView::AlphaBackgroundNone:
// Unlike RasterImageView, SVGs are rendered directly on the image view,
// therefore we can simply not draw a background
break;
case AbstractImageView::AlphaBackgroundCheckBoard:
painter->drawTiledPixmap(imageRect, alphaBackgroundTexture(), scrollPos());
break;
......
......@@ -119,10 +119,11 @@
<group name="ImageView">
<entry name="AlphaBackgroundMode" type="Enum">
<choices name="Gwenview::AbstractImageView::AlphaBackgroundMode">
<choice name="AbstractImageView::AlphaBackgroundNone"/>
<choice name="AbstractImageView::AlphaBackgroundCheckBoard"/>
<choice name="AbstractImageView::AlphaBackgroundSolid"/>
</choices>
<default>AbstractImageView::AlphaBackgroundCheckBoard</default>
<default>AbstractImageView::AlphaBackgroundNone</default>
</entry>
<entry name="AlphaBackgroundColor" type="Color">
<default>#ffffff</default>
......
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