File indexing completed on 2024-05-12 05:46:33
0001 /* 0002 * Copyright 2009 Matthew Woehlke <mw_triad@users.sourceforge.net> 0003 * 0004 * This program is free software: you can redistribute it and/or modify it 0005 * under the terms of the GNU General Public License as published by the 0006 * Free Software Foundation, either version 2 of the License, or (at your 0007 * option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT 0010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 0012 * more details. 0013 * 0014 * You should have received a copy of the GNU General Public License along with 0015 * this program. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include "kimageframe.h" 0019 #include <QStyle> 0020 #include <QStyleOption> 0021 #include <QPainter> 0022 0023 KImageFrame::KImageFrame(QWidget *parent) : QFrame(parent), _w(0), _h(0) 0024 { 0025 } 0026 0027 void KImageFrame::setImage(const QImage &img) 0028 { 0029 _img = img; 0030 _w = img.width(); 0031 _h = img.height(); 0032 update(); 0033 } 0034 0035 void KImageFrame::paintEvent(QPaintEvent *) 0036 { 0037 QPainter p(this); 0038 QStyleOptionFrame opt; 0039 QRect rf(frameRect()), ri(0, 0, _w, _h); 0040 0041 opt.rect = rf; 0042 opt.state = QStyle::State_Sunken; 0043 0044 style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, this); 0045 0046 ri.moveCenter(rf.center()); 0047 p.drawImage(ri, _img); 0048 0049 p.end(); 0050 } 0051