From e9ae80694875f869892f13f4fcaf1170a00dea41 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- quanta/dialogs/tagdialogs/pictureview.cpp | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 quanta/dialogs/tagdialogs/pictureview.cpp (limited to 'quanta/dialogs/tagdialogs/pictureview.cpp') diff --git a/quanta/dialogs/tagdialogs/pictureview.cpp b/quanta/dialogs/tagdialogs/pictureview.cpp new file mode 100644 index 00000000..0082d379 --- /dev/null +++ b/quanta/dialogs/tagdialogs/pictureview.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + pictureview.cpp - description + ------------------- + begin : Mon Nov 29 1999 + copyright : (C) 1999 by Dmitry Poplavsky & Yacovlev Alexander + email : pdima@mail.univ.kiev.ua + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "pictureview.h" +#include "pictureview.moc" +#include "qpainter.h" +#include + +PictureView::PictureView(QWidget *parent, char *file, const char *name ) : QFrame(parent,name) +{ + if ( file ) { + pix = new QImage(file); + picwidth = pix->width(); + picheight = pix->height(); + x_of = 0; + y_of = 0; + scale(); + } else { + pix = new QImage(); + picwidth = 0; + picheight = 0; + x_of = 0; + y_of = 0; + } + + + setFrameStyle ( Box|Sunken ); +} + +PictureView::~PictureView() +{ +} + +void PictureView::paintEvent( QPaintEvent * e ) +{ + QPainter p; + p.begin( this ); + p.drawImage( x_of, y_of, *pix ); + p.end(); + + QFrame::paintEvent(e); + +} + +void PictureView::resizeEvent ( QResizeEvent * e){ + scale(); + QFrame::resizeEvent(e); +} + +/** set image */ +void PictureView::slotSetImage(const QString& file) +{ + pix->load( file ); + picwidth = pix->width(); + picheight = pix->height(); + + scale(); + repaint(); +} + +/** try scale image */ +void PictureView::scale(){ + float width_ot,height_ot; + + width_ot = 1; + height_ot = 1; + x_of = y_of = 0; + + if ( picwidth > size().width() ) width_ot = (float)size().width()/(float)picwidth; + else x_of = (size().width()-picwidth)/2; + if ( picheight > size().height() ) height_ot = (float)size().height()/(float)picheight; + else y_of = (size().height()-picheight)/2; + + if ( width_ot < 1 || height_ot < 1) { + if ( width_ot < height_ot) { + *pix = pix->smoothScale( (int)(width_ot*picwidth), (int)(width_ot*picheight)); + y_of = ( size().height()-(int)(width_ot*picheight) )/2; + } + else { + *pix = pix->smoothScale( (int)(height_ot*picwidth), (int)(height_ot*picheight)); + x_of = ( size().width()-(int)(height_ot*picwidth) )/2; + } + + picwidth = size().width(); + picheight = size().height(); + } + + +} -- cgit v1.2.3