krita

kis_iconwidget.cc

00001 /*
00002  *  Copyright (c) 2000 Matthias Elter  <elter@kde.org>
00003  *  Copyright (c) 2003 Patrick Julien  <freak@codepimps.org>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.g
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include <qpainter.h>
00021 #include <koIconChooser.h>
00022 #include "kis_iconwidget.h"
00023 
00024 KisIconWidget::KisIconWidget(QWidget *parent, const char *name) : super(parent, name)
00025 {
00026     m_item = 0;
00027 }
00028 
00029 void KisIconWidget::slotSetItem(KoIconItem& item)
00030 {
00031     m_item = &item;
00032     update();
00033 }
00034 
00035 void KisIconWidget::drawButtonLabel(QPainter *p)
00036 {
00037     if (m_item) {
00038         const QPixmap& pix = m_item->pixmap();
00039         Q_INT32 x = 2;
00040         Q_INT32 y = 2;
00041         Q_INT32 pw = pix.width();
00042         Q_INT32 ph = pix.height();
00043         Q_INT32 cw = width();
00044         Q_INT32 ch = height();
00045         Q_INT32 itemWidth = 24;
00046         Q_INT32 itemHeight = 24;
00047 
00048         if (pw < itemWidth)
00049             x = (cw - pw) / 2;
00050         if (ph < itemHeight)
00051             y = (cw - ph) / 2;
00052 
00053         if (!m_item->hasValidThumb() || (pw <= itemWidth && ph <= itemHeight)) {
00054             p->drawPixmap(x, y, pix, 0, 0, itemWidth, itemHeight);
00055         } else {
00056             const QPixmap& thumbpix = m_item->thumbPixmap();
00057 
00058             x = 2;
00059             y = 2;
00060             pw = thumbpix.width();
00061             ph = thumbpix.height();
00062             cw = width();
00063             ch = height();
00064 
00065             if (pw < itemWidth)
00066                 x = (cw - pw) / 2;
00067 
00068             if (ph < itemHeight)
00069                 y = (cw - ph) / 2;
00070 
00071             p->drawPixmap(x, y, thumbpix, 0, 0, itemWidth, itemHeight);
00072         }
00073 
00074         p->setPen(gray);
00075         p->drawRect(0, 0, cw + 1, ch + 1);
00076     }
00077 }
00078 
00079 #include "kis_iconwidget.moc"
00080 
KDE Home | KDE Accessibility Home | Description of Access Keys