/* 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 #include #include #include #include #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(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; }