summaryrefslogtreecommitdiffstats
path: root/pictureviewer2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pictureviewer2.cpp')
-rw-r--r--pictureviewer2.cpp65
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;
+}