summaryrefslogtreecommitdiffstats
path: root/libk9copy/k9drawimage.cpp
blob: 25593c5e3aaf46be16003242c2512bd3005ea75d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// C++ Implementation: k9drawimage
//
// Description: 
//
//
// Author: Jean-Michel PETIT <[email protected]>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9drawimage.h"
#include <tqpainter.h>

k9DrawImage::k9DrawImage(TQWidget *parent, const char *name)
 : TQWidget(parent, name)
{
}


k9DrawImage::~k9DrawImage()
{
}

void k9DrawImage::setImage(const TQImage &_image){
    m_pixmap =_image;
    tqrepaint();
}

void k9DrawImage::setImage(TQString _fileName) {
        m_pixmap.load(_fileName);
        tqrepaint();
}

void k9DrawImage::paintEvent ( TQPaintEvent * ) {
        int top,left;
        TQPainter p(this);
        
        double wratio=(double)width()/(double)m_pixmap.width();
        double hratio=(double)height()/(double)m_pixmap.height();
        double ratio= wratio < hratio ? wratio:hratio;

        top =(int) (height() -m_pixmap.height()*ratio)/2+1;
        left =(int) (width() -m_pixmap.width()*ratio)/2 ;

        p.scale(ratio,ratio);
        p.drawPixmap((int)(left/ratio),(int)(top/ratio),m_pixmap);
    }
#include "k9drawimage.moc"