From f0ac8500b63511a8307f332c4b86670545fc4ca6 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 30 Apr 2011 11:20:53 +0200 Subject: Use BG-Gradient in PictureViewer Use setGradient in PictureViewer again. Modified it to take the colors for the gradient from the top left and bottom right of the QImage. --- pictureviewer.cpp | 8 +++++--- pictureviewer.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pictureviewer.cpp b/pictureviewer.cpp index 33131de..502c544 100644 --- a/pictureviewer.cpp +++ b/pictureviewer.cpp @@ -29,6 +29,7 @@ void PictureViewer::showPic(const QString &path, bool enableDirEntries){ if(!fi.exists() || fi.isDir()){ return; } + QPixmap img(path); if(img.isNull()){ return; @@ -68,6 +69,7 @@ void PictureViewer::showPic(const QString &path, bool enableDirEntries){ resize(img.size() + QSize(20, 20)); setSceneRect(viewport()->rect()); + setGradient(img.toImage()); QGraphicsPixmapItem *item = new QGraphicsPixmapItem(img); mCurrentPic = item; item->setPos(center(img)); @@ -134,9 +136,9 @@ void PictureViewer::wheelEvent(QWheelEvent *event){ } } -void PictureViewer::setGradient(){ - QColor c1(255, 7, 15); - QColor c2(80, 55, 250); +void PictureViewer::setGradient(const QImage &img){ + QColor c1(img.pixel(2, 2)); + QColor c2(img.pixel(img.width() - 2, img.height() - 2)); QLinearGradient g(QPointF(0, 0), sceneRect().bottomRight()); g.setColorAt(0, c1); g.setColorAt(1, c2); diff --git a/pictureviewer.h b/pictureviewer.h index 83c43d3..d4fba4c 100644 --- a/pictureviewer.h +++ b/pictureviewer.h @@ -31,7 +31,7 @@ class PictureViewer : public QGraphicsView { void wheelEvent(QWheelEvent *event); private: - void setGradient(); + void setGradient(const QImage &img); void setDir(const QString &path); bool isPic(const QString &path); QPointF center(const QPixmap &pic); -- cgit v1.2.3-70-g09d2