chalk

kis_iconwidget.cpp
1/*
2 * Copyright (c) 2000 Matthias Elter <elter@kde.org>
3 * Copyright (c) 2003 Patrick Julien <freak@codepimps.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.g
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include <tqpainter.h>
21#include <koIconChooser.h>
22#include "kis_iconwidget.h"
23
24KisIconWidget::KisIconWidget(TQWidget *parent, const char *name) : super(parent, name)
25{
26 m_item = 0;
27}
28
29void KisIconWidget::slotSetItem(KoIconItem& item)
30{
31 m_item = &item;
32 update();
33}
34
35void KisIconWidget::drawButtonLabel(TQPainter *p)
36{
37 if (m_item) {
38 const TQPixmap& pix = m_item->pixmap();
39 TQ_INT32 x = 2;
40 TQ_INT32 y = 2;
41 TQ_INT32 pw = pix.width();
42 TQ_INT32 ph = pix.height();
43 TQ_INT32 cw = width();
44 TQ_INT32 ch = height();
45 TQ_INT32 itemWidth = 24;
46 TQ_INT32 itemHeight = 24;
47
48 if (pw < itemWidth)
49 x = (cw - pw) / 2;
50 if (ph < itemHeight)
51 y = (cw - ph) / 2;
52
53 if (!m_item->hasValidThumb() || (pw <= itemWidth && ph <= itemHeight)) {
54 p->drawPixmap(x, y, pix, 0, 0, itemWidth, itemHeight);
55 } else {
56 const TQPixmap& thumbpix = m_item->thumbPixmap();
57
58 x = 2;
59 y = 2;
60 pw = thumbpix.width();
61 ph = thumbpix.height();
62 cw = width();
63 ch = height();
64
65 if (pw < itemWidth)
66 x = (cw - pw) / 2;
67
68 if (ph < itemHeight)
69 y = (cw - ph) / 2;
70
71 p->drawPixmap(x, y, thumbpix, 0, 0, itemWidth, itemHeight);
72 }
73
74 p->setPen(gray);
75 p->drawRect(0, 0, cw + 1, ch + 1);
76 }
77}
78
79#include "kis_iconwidget.moc"
80