krita
kis_iconwidget.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
|