summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/tagdialogs/pictureview.cpp
blob: 65102ba80dad34c5b526e2267e1cf5ed9c0cb9ea (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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 "tqpainter.h"
#include <tqimage.h>

PictureView::PictureView(TQWidget *parent, char *file, const char *name ) : TQFrame(parent,name)
{
    if ( file ) {
      pix = new TQImage(file);
      picwidth  = pix->width();
      picheight = pix->height();
      x_of = 0;
      y_of = 0;
      scale();
    } else {
      pix = new TQImage();
      picwidth  = 0;
      picheight = 0;
      x_of = 0;
      y_of = 0;
    }


    setFrameStyle ( Box|Sunken );
}

PictureView::~PictureView()
{
}

void PictureView::paintEvent( TQPaintEvent * e )
{
    TQPainter p;
    p.begin( this );
    p.drawImage( x_of, y_of, *pix );
    p.end();

    TQFrame::paintEvent(e);

}

void PictureView::resizeEvent ( TQResizeEvent *  e){
  scale();
  TQFrame::resizeEvent(e);
}

/** set image */
void PictureView::slotSetImage(const TQString& 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();
  }


}