diff options
author | Arno <am@disconnect.de> | 2012-03-08 06:05:11 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-03-08 06:05:11 +0100 |
commit | 57f69839e3bab9ab73f15811374099576216282b (patch) | |
tree | 667efb0992ec4f72f4dc44a868fa568c750177d1 /pictureviewer2.cpp | |
parent | e3fe65d3e8ca88dbd76d9c026cf9f8690a972902 (diff) | |
download | SheMov-57f69839e3bab9ab73f15811374099576216282b.tar.gz SheMov-57f69839e3bab9ab73f15811374099576216282b.tar.bz2 SheMov-57f69839e3bab9ab73f15811374099576216282b.zip |
First draft of PictureViewer2
Doesn't do much other than showing a default picture, but it behaves
like a QDialog and positions itself correctly. It's quite a pain in the
ass with a tiling window manager...
Diffstat (limited to 'pictureviewer2.cpp')
-rw-r--r-- | pictureviewer2.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp new file mode 100644 index 0000000..0c2530e --- /dev/null +++ b/pictureviewer2.cpp @@ -0,0 +1,65 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QDesktopWidget> +#include <QApplication> +#include <QGraphicsScene> +#include <QGraphicsPixmapItem> +#include <QImage> + +#include "pictureviewer2.h" + +const QString PictureViewer2::mDefaultFile(":/picgone.png"); + +PictureViewer2::PictureViewer2(QWidget *parent) : QGraphicsView(parent), mCur(0) { + //behave like QDialog, but don't be one... + setWindowFlags(QFlags<Qt::WindowType>(0x1|0x2|0x1000|0x2000|0x10000|0x8000000)); + + //setup gui + mScene = new QGraphicsScene(this); + setScene(mScene); + QDesktopWidget *dw = QApplication::desktop(); + QSize screenSize = dw->availableGeometry().size(); + mMinimunSize = QSize(screenSize.width() - 100, screenSize.height() - 100); + setMinimumSize(mMinimunSize); + move(50, 50); + setVisible(false); + setFile(); +} + +void PictureViewer2::setFile(const QString file){ + QPixmap pixmap(file); + if(pixmap.isNull()){ + return; + } + setCurPalette(pixmap); + if((pixmap.height() > height()) || (pixmap.width() > width())){ + pixmap = pixmap.scaled(QSize(width() - 3, height() - 10), Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + if(mCur){ + mScene->removeItem(mCur); + mCur = 0; + } + mCur = new QGraphicsPixmapItem(pixmap); + mScene->addItem(mCur); +} + +void PictureViewer2::setCurPalette(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(); + QColor c1(img.pixel(val1)); + QColor c2(img.pixel(val2)); + QLinearGradient g(QPoint(0,0), QPoint(rect().bottomRight())); + g.setColorAt(0, c1); + g.setColorAt(1, c2); + setBackgroundBrush(QBrush(g)); +} + +QSize PictureViewer2::sizeHint() const{ + return mMinimunSize; +} |