From 81aafd665a74ff4de206667ba495109f34294dd5 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 17 Mar 2012 06:15:56 +0100 Subject: Make background color of PictureViewer2 configurable Add options to ConfigurationDialog to either use a fixed color as background or a gradient picked with random colors picked from the picture. --- pictureviewer2.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'pictureviewer2.cpp') diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index cf24c0a..3234ffc 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "pictureviewer2.h" #include "pictureswidget.h" @@ -42,10 +43,12 @@ PictureViewer2::PictureViewer2(QWidget *parent) : QGraphicsView(parent), mCur(0) setScene(mScene); QDesktopWidget *dw = QApplication::desktop(); QSize screenSize = dw->availableGeometry().size(); + //TODO: configure! mMinimunSize = QSize(screenSize.width() - 100, screenSize.height() - 100); setMinimumSize(mMinimunSize); move(50, 50); setVisible(false); + readSettings(); mScene->setSceneRect(QRectF(0, 0, width() - 10, height() - 10)); showFile(mFiles.at(mCurPos)); } @@ -99,6 +102,13 @@ void PictureViewer2::slide(){ } } +void PictureViewer2::readSettings(){ + QSettings s; + mUseGradient = s.value("ui/pvgradient").toBool(); + QVariant t = s.value("ui/pvbgcolor"); + mBgColor = t.value(); +} + void PictureViewer2::wheelEvent(QWheelEvent *event){ int steps = event->delta() / 8 / 15; if(steps < 0){ @@ -121,7 +131,11 @@ void PictureViewer2::showFile(const PicData &file){ if(pixmap.isNull()){ return; } - setCurPalette(pixmap); + if(mUseGradient){ + setGradient(pixmap); + }else{ + setBackgroundBrush(QBrush(mBgColor)); + } if((pixmap.height() > height()) || (pixmap.width() > width())){ pixmap = pixmap.scaled(QSize(width() - 3, height() - 10), Qt::KeepAspectRatio, Qt::SmoothTransformation); } @@ -136,6 +150,7 @@ void PictureViewer2::showFile(const PicData &file){ mScene->addItem(mCur); mCur->setPos(cX, cY); setWindowTitle(constructWindowTitle()); + //TODO: configure! constructFilenameItem(file, pixmap.size()); } @@ -149,7 +164,7 @@ void PictureViewer2::constructFilenameItem(const PicData &data, QSize picSize){ mScene->addItem(mFnItem); } -void PictureViewer2::setCurPalette(const QPixmap &pic){ +void PictureViewer2::setGradient(const QPixmap &pic){ QPoint val1 = QPoint(qrand() % pic.width(), qrand() % pic.height()); QPoint val2 = QPoint(qrand() % pic.width(), qrand() % pic.height()); QImage img = pic.toImage(); -- cgit v1.2.3-70-g09d2