summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/printwizard/tphoto.cpp
blob: 451e124e067e1be1c4f6b49658b815decd6710e9 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
                          tphoto.cpp  -  description
                             -------------------
    begin                : Thu Sep 12 2002
    copyright            : (C) 2002 by Todd Shoemaker
                         : (C) 2007 Angelo Naselli
    email                : jtshoe11@yahoo.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

// TQt includes.
 
#include <tqpainter.h>
#include <tqdir.h>
#include <tqmessagebox.h>
#include <tqdragobject.h>
#include <tqstringlist.h>
#include <tqurl.h>
#include <tqstrlist.h>

// KDE includes.

#include <kprinter.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <kdebug.h>

// Local includes.

#include "tphoto.h"
#include "utils.h"

// LibKDcraw includes.

#include <libkdcraw/version.h>
#include <libkdcraw/kdcraw.h>

#if KDCRAW_VERSION < 0x000106
#include <libkdcraw/dcrawbinary.h>
#endif

#define IMAGE_FILE_MASK "*"
//"*.jpg;*.jpeg;*.JPG;*.JPEG;*.png;*.PNG"

namespace KIPIPrintWizardPlugin
{

TPhoto::TPhoto(int thumbnailSize)
{
  m_size = 0;
  cropRegion = TQRect(-1, -1, -1, -1);
  rotation = 0;
  copies = 1;

  filename = "";
  m_exiv2Iface = NULL;

  m_thumbnail = NULL;

  this->m_thumbnailSize = thumbnailSize;
}

TPhoto::~TPhoto()
{
  if (m_thumbnail)
    delete m_thumbnail;
  if (m_size)
    delete m_size;
  if (m_exiv2Iface)
    delete m_exiv2Iface;
}

void TPhoto::loadCache()
{
  // load the thumbnail and size only once.
  if (m_thumbnail)
    delete m_thumbnail;


  TQImage photo = loadPhoto();

  m_thumbnail = new TQPixmap(TQImage( photo.scale(m_thumbnailSize, m_thumbnailSize, TQ_ScaleMin) ));

  if (m_size)
    delete m_size;
  m_size = new TQSize(photo.width(), photo.height());
}

TQPixmap & TPhoto::thumbnail()
{
  if (!m_thumbnail)
    loadCache();
  return *m_thumbnail;
}

TQImage  TPhoto::loadPhoto()
{
  TQImage photo;

  // Check if RAW file.
#if KDCRAW_VERSION < 0x000106
  TQString rawFilesExt(KDcrawIface::DcrawBinary::instance()->rawFiles());
#else
  TQString rawFilesExt(KDcrawIface::KDcraw::rawFiles());
#endif
  TQFileInfo fileInfo(filename.path());
  if (rawFilesExt.upper().contains( fileInfo.extension(false).upper() ))
    KDcrawIface::KDcraw::loadDcrawPreview(photo, filename.path());
  else
    photo.load(filename.path()); // PENDING(blackie) handle URL

  return photo;
}

TQSize & TPhoto::size()  // private
{
  if (m_size == 0)
    loadCache();
  return *m_size;
}

KExiv2Iface::KExiv2 *TPhoto::exiv2Iface()
{
  if (!m_exiv2Iface && !filename.url().isEmpty())
  {
    m_exiv2Iface = new KExiv2Iface::KExiv2(filename.path());
  }

  return m_exiv2Iface;
}

int TPhoto::width()
{
  return size().width();
}

int TPhoto::height()
{
  return size().height();
}

}  // NameSpace KIPIPrintWizardPlugin