diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,5 +154,6 @@ add_subdirectory(cursors) add_subdirectory(color-schemes) add_subdirectory(doc) +add_subdirectory(kconf_update) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -114,5 +114,3 @@ DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES slideshow.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/ServiceMenus) -install(FILES gwenview.upd - DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}) diff --git a/app/configdialog.cpp b/app/configdialog.cpp --- a/app/configdialog.cpp +++ b/app/configdialog.cpp @@ -68,8 +68,8 @@ mAlphaBackgroundModeGroup = new InvisibleButtonGroup(widget); mAlphaBackgroundModeGroup->setObjectName(QLatin1String("kcfg_AlphaBackgroundMode")); - mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.checkBoardRadioButton, int(RasterImageView::AlphaBackgroundCheckBoard)); - mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.solidColorRadioButton, int(RasterImageView::AlphaBackgroundSolid)); + mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.checkBoardRadioButton, int(AbstractImageView::AlphaBackgroundCheckBoard)); + mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.solidColorRadioButton, int(AbstractImageView::AlphaBackgroundSolid)); mWheelBehaviorGroup = new InvisibleButtonGroup(widget); mWheelBehaviorGroup->setObjectName(QLatin1String("kcfg_MouseWheelBehavior")); diff --git a/kconf_update/CMakeLists.txt b/kconf_update/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kconf_update/CMakeLists.txt @@ -0,0 +1,4 @@ +install(FILES gwenview.upd + DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}) +install(PROGRAMS gwenview-imageview-alphabackgroundmode-update.pl + DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}) diff --git a/kconf_update/gwenview-imageview-alphabackgroundmode-update.pl b/kconf_update/gwenview-imageview-alphabackgroundmode-update.pl new file mode 100644 --- /dev/null +++ b/kconf_update/gwenview-imageview-alphabackgroundmode-update.pl @@ -0,0 +1,8 @@ +#!/usr/bin/env perl + +use strict; + +while () { + s/RasterImageView::AlphaBackgroundSolid/AbstractImageView::AlphaBackgroundSolid/; + print $_; +} diff --git a/app/gwenview.upd b/kconf_update/gwenview.upd rename from app/gwenview.upd rename to kconf_update/gwenview.upd --- a/app/gwenview.upd +++ b/kconf_update/gwenview.upd @@ -1,4 +1,6 @@ Version=5 + + Id=SideBar_StatusBar_Rename File=gwenviewrc @@ -18,3 +20,10 @@ Key=StatusBarIsVisible,IsVisible BrowseMode Key=StatusBarIsVisible,IsVisible ViewMode RemoveKey=StatusBarIsVisible + + +Id=ImageView_AlphaBackgroundMode_Update +File=gwenviewrc +Options=overwrite +Group=ImageView +Script=gwenview-imageview-alphabackgroundmode-update.pl,perl diff --git a/lib/documentview/abstractimageview.h b/lib/documentview/abstractimageview.h --- a/lib/documentview/abstractimageview.h +++ b/lib/documentview/abstractimageview.h @@ -44,6 +44,11 @@ UpdateIfNecessary, ForceUpdate }; + enum AlphaBackgroundMode { + AlphaBackgroundCheckBoard, + AlphaBackgroundSolid + }; + AbstractImageView(QGraphicsItem* parent); ~AbstractImageView(); @@ -115,6 +120,10 @@ void toggleFullScreenRequested(); protected: + virtual void setAlphaBackgroundMode(AlphaBackgroundMode mode) = 0; + virtual void setAlphaBackgroundColor(const QColor& color) = 0; + const QPixmap& alphaBackgroundTexture() const; + virtual void loadFromDocument() = 0; virtual void onZoomChanged() = 0; /** diff --git a/lib/documentview/abstractimageview.cpp b/lib/documentview/abstractimageview.cpp --- a/lib/documentview/abstractimageview.cpp +++ b/lib/documentview/abstractimageview.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace Gwenview { @@ -56,6 +57,8 @@ QPointF mScrollPos; QPointF mLastDragPos; + const QPixmap mAlphaBackgroundTexture = createAlphaBackgroundTexture(); + void adjustImageOffset(Verbosity verbosity = Notify) { QSizeF zoomedDocSize = q->documentSize() * mZoom; @@ -109,6 +112,17 @@ QPixmap cursorPixmap = QPixmap(path); mZoomCursor = QCursor(cursorPixmap, 11, 11); } + + QPixmap createAlphaBackgroundTexture() + { + QPixmap pix = QPixmap(32, 32); + QPainter painter(&pix); + painter.fillRect(pix.rect(), QColor(128, 128, 128)); + const QColor light = QColor(192, 192, 192); + painter.fillRect(0, 0, 16, 16, light); + painter.fillRect(16, 16, 16, 16, light); + return pix; + } }; AbstractImageView::AbstractImageView(QGraphicsItem* parent) @@ -257,6 +271,11 @@ zoomToFillChanged(d->mZoomToFill); } +const QPixmap& AbstractImageView::alphaBackgroundTexture() const +{ + return d->mAlphaBackgroundTexture; +} + void AbstractImageView::resizeEvent(QGraphicsSceneResizeEvent* event) { QGraphicsWidget::resizeEvent(event); diff --git a/lib/documentview/rasterimageview.h b/lib/documentview/rasterimageview.h --- a/lib/documentview/rasterimageview.h +++ b/lib/documentview/rasterimageview.h @@ -41,21 +41,16 @@ { Q_OBJECT public: - enum AlphaBackgroundMode { - AlphaBackgroundCheckBoard, - AlphaBackgroundSolid - }; - RasterImageView(QGraphicsItem* parent = 0); ~RasterImageView(); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) Q_DECL_OVERRIDE; void setCurrentTool(AbstractRasterImageViewTool* tool); AbstractRasterImageViewTool* currentTool() const; - void setAlphaBackgroundMode(AlphaBackgroundMode mode); - void setAlphaBackgroundColor(const QColor& color); + void setAlphaBackgroundMode(AlphaBackgroundMode mode) override; + void setAlphaBackgroundColor(const QColor& color) override; void setRenderingIntent(const RenderingIntent::Enum& renderingIntent); Q_SIGNALS: diff --git a/lib/documentview/rasterimageview.cpp b/lib/documentview/rasterimageview.cpp --- a/lib/documentview/rasterimageview.cpp +++ b/lib/documentview/rasterimageview.cpp @@ -44,11 +44,10 @@ { RasterImageView* q; ImageScaler* mScaler; - QPixmap mBackgroundTexture; bool mEmittedCompleted; // Config - RasterImageView::AlphaBackgroundMode mAlphaBackgroundMode; + AbstractImageView::AlphaBackgroundMode mAlphaBackgroundMode; QColor mAlphaBackgroundColor; cmsUInt32Number mRenderingIntent; bool mEnlargeSmallerImages; @@ -111,16 +110,6 @@ mApplyDisplayTransform = true; } - void createBackgroundTexture() - { - mBackgroundTexture = QPixmap(32, 32); - QPainter painter(&mBackgroundTexture); - painter.fillRect(mBackgroundTexture.rect(), QColor(128, 128, 128)); - QColor light = QColor(192, 192, 192); - painter.fillRect(0, 0, 16, 16, light); - painter.fillRect(16, 16, 16, 16, light); - } - void setupUpdateTimer() { mUpdateTimer = new QTimer(q); @@ -173,16 +162,16 @@ mAlternateBuffer = QPixmap(); } - void drawAlphaBackground(QPainter* painter, const QRect& viewportRect, const QPoint& zoomedImageTopLeft) + void drawAlphaBackground(QPainter* painter, const QRect& viewportRect, const QPoint& zoomedImageTopLeft, QPixmap texture) { - if (mAlphaBackgroundMode == RasterImageView::AlphaBackgroundCheckBoard) { + if (mAlphaBackgroundMode == AbstractImageView::AlphaBackgroundCheckBoard) { QPoint textureOffset( - zoomedImageTopLeft.x() % mBackgroundTexture.width(), - zoomedImageTopLeft.y() % mBackgroundTexture.height() + zoomedImageTopLeft.x() % texture.width(), + zoomedImageTopLeft.y() % texture.height() ); painter->drawTiledPixmap( viewportRect, - mBackgroundTexture, + texture, textureOffset); } else { painter->fillRect(viewportRect, mAlphaBackgroundColor); @@ -208,7 +197,6 @@ d->mScaler = new ImageScaler(this); connect(d->mScaler, &ImageScaler::scaledRect, this, &RasterImageView::updateFromScaler); - d->createBackgroundTexture(); d->setupUpdateTimer(); } @@ -347,7 +335,8 @@ if (document()->hasAlphaChannel()) { d->drawAlphaBackground( &painter, QRect(viewportLeft, viewportTop, image.width(), image.height()), - QPoint(zoomedImageLeft, zoomedImageTop) + QPoint(zoomedImageLeft, zoomedImageTop), + alphaBackgroundTexture() ); } else { painter.setCompositionMode(QPainter::CompositionMode_Source); diff --git a/lib/documentview/svgviewadapter.h b/lib/documentview/svgviewadapter.h --- a/lib/documentview/svgviewadapter.h +++ b/lib/documentview/svgviewadapter.h @@ -42,6 +42,8 @@ Q_OBJECT public: SvgImageView(QGraphicsItem* parent = 0); + void setAlphaBackgroundMode(AlphaBackgroundMode mode) Q_DECL_OVERRIDE; + void setAlphaBackgroundColor(const QColor& color) Q_DECL_OVERRIDE; protected: void loadFromDocument() Q_DECL_OVERRIDE; @@ -54,7 +56,11 @@ private: QGraphicsSvgItem* mSvgItem; + AbstractImageView::AlphaBackgroundMode mAlphaBackgroundMode; + QColor mAlphaBackgroundColor; void adjustItemPos(); + void drawAlphaBackground(QPainter* painter); + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; }; struct SvgViewAdapterPrivate; diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,11 @@ SvgImageView::SvgImageView(QGraphicsItem* parent) : AbstractImageView(parent) , mSvgItem(new QGraphicsSvgItem(this)) +, mAlphaBackgroundMode(AbstractImageView::AlphaBackgroundCheckBoard) +, mAlphaBackgroundColor(Qt::black) { + // So we aren't unnecessarily drawing the background for every paint() + setCacheMode(QGraphicsItem::DeviceCoordinateCache); } void SvgImageView::loadFromDocument() @@ -96,6 +101,40 @@ void SvgImageView::adjustItemPos() { mSvgItem->setPos(imageOffset() - scrollPos()); + update(); +} + +void SvgImageView::setAlphaBackgroundMode(AbstractImageView::AlphaBackgroundMode mode) +{ + mAlphaBackgroundMode = mode; + update(); +} + +void SvgImageView::setAlphaBackgroundColor(const QColor& color) +{ + mAlphaBackgroundColor = color; + update(); +} + +void SvgImageView::drawAlphaBackground(QPainter* painter) +{ + const QRectF imageRect = QRectF(imageOffset(), visibleImageSize()); + + switch (mAlphaBackgroundMode) { + case AbstractImageView::AlphaBackgroundCheckBoard: + painter->drawTiledPixmap(imageRect, alphaBackgroundTexture(), scrollPos()); + break; + case AbstractImageView::AlphaBackgroundSolid: + painter->fillRect(imageRect, mAlphaBackgroundColor); + break; + default: + Q_ASSERT(0); + } +} + +void SvgImageView::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) +{ + drawAlphaBackground(painter); } //// SvgViewAdapter //// @@ -148,6 +187,8 @@ void SvgViewAdapter::loadConfig() { + d->mView->setAlphaBackgroundMode(GwenviewConfig::alphaBackgroundMode()); + d->mView->setAlphaBackgroundColor(GwenviewConfig::alphaBackgroundColor()); d->mView->setEnlargeSmallerImages(GwenviewConfig::enlargeSmallerImages()); } diff --git a/lib/gwenviewconfig.kcfg b/lib/gwenviewconfig.kcfg --- a/lib/gwenviewconfig.kcfg +++ b/lib/gwenviewconfig.kcfg @@ -118,11 +118,11 @@ - - - + + + - RasterImageView::AlphaBackgroundCheckBoard + AbstractImageView::AlphaBackgroundCheckBoard #ffffff