summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/kameraklient/cameraiconview.cpp
blob: 795a029bfbd76b625422c92c61efb01a35ad52dd (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
/* ============================================================
 * File  : cameraiconview.cpp
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 * Date  : 2003-01-23
 * Description : 
 * 
 * Copyright 2003 by Renchi Raju <renchi@pooh.tam.uiuc.edu>

 * 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, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * ============================================================ */

// TQt
#include <tqimage.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqrect.h>
#include <tqpalette.h>
#include <tqpoint.h>
#include <tqpopupmenu.h>
#include <tqvaluevector.h>
// KDE
#include <tdelocale.h>
#include <kiconloader.h>
#include <kstandarddirs.h>
#include <ktrader.h>
#include <kservice.h>
// Local
#include "gpfileiteminfo.h"
#include "gpfileiteminfodlg.h"
#include "cameraiconitem.h"
#include "cameraiconview.h"
#include "cameraui.h"

namespace KIPIKameraKlientPlugin
{

const int MAXICONITEMS = 307;
const int THUMBSIZE = 120;

class CameraIconViewPrivate {

public:
    TQPixmap imagePix;
    TQPixmap audioPix;
    TQPixmap videoPix;
    TQPixmap unknownPix;
};

CameraIconView::CameraIconView(TQWidget *parent) : ThumbView(parent) {
    d = new CameraIconViewPrivate;
    setThumbnailSize();
}

CameraIconView::~CameraIconView() {
    delete d;    
}

void CameraIconView::setThumbnailSize() {
    int w = THUMBSIZE;
    int h = THUMBSIZE;
    TQString iconfile = locate("data", "documents");
    TQImage image(iconfile);
    double scale = double(w-10) / double(image.width());
    image = image.smoothScale(w-10, h-10, TQ_ScaleMin);
    TQPixmap pix(w, h);
    pix.fill(colorGroup().base());
    TQPainter p(&pix);
    p.fillRect(0, 0, w, h, TQBrush(colorGroup().base()));
    if(!image.isNull()) {
        p.drawImage((w-image.width())/2, (h-image.height())/2, image);
    }
    p.end();
    d->imagePix = pix;
    createPixmap(d->imagePix, "image", scale);
    d->audioPix = pix;
    createPixmap(d->audioPix, "sound", scale);
    d->videoPix = pix;
    createPixmap(d->videoPix, "video", scale);
    d->unknownPix = pix;
    createPixmap(d->unknownPix, "document", scale);
}

void CameraIconView::createPixmap(TQPixmap& pix, const TQString& icon, double scale) {
    TQString iconfile = locate("data", icon);
    TQImage mimeImg(iconfile);
    mimeImg = mimeImg.smoothScale((int) (mimeImg.width()*scale), (int) (mimeImg.height()*scale), TQ_ScaleMin);
    int w = THUMBSIZE;
    int h = THUMBSIZE;
    TQPainter p(&pix);
    if (!mimeImg.isNull()) {
        p.drawImage((w-mimeImg.width())/2, (h-mimeImg.height())/2, mimeImg);
    }
    p.end();
}

CameraIconItem* CameraIconView::addItem(const GPFileItemInfo* fileInfo) {
    TQPixmap& pix = d->unknownPix;
    if(fileInfo->mime.contains("image")) {
        pix = d->imagePix;
    } else if(fileInfo->mime.contains("audio")) {
        pix = d->audioPix;
    } else if(fileInfo->mime.contains("video")) {
        pix = d->videoPix;
    } else {
        pix = d->unknownPix;
    } 
    CameraIconItem *iconItem = new CameraIconItem(this, fileInfo, pix);
    return iconItem;
}

void CameraIconView::clear() {
    ThumbView::clear();
    emit signalCleared();
}

void CameraIconView::setThumbnail(CameraIconItem* iconItem, const TQImage& thumbnail) {
    if (!iconItem) {
	return;
    }
    iconItem->setPixmap(thumbnail);
}

void CameraIconView::markDownloaded(CameraIconItem* iconItem) {
    if (!iconItem) {
	return;
    }
    GPFileItemInfo *fileInfo = const_cast<GPFileItemInfo*>(iconItem->fileInfo());
    fileInfo->downloaded = 1;
    iconItem->repaint();
}

}  // NameSpace KIPIKameraKlientPlugin

#include "cameraiconview.moc"