File indexing completed on 2024-12-22 04:10:12

0001 /*
0002  * SPDX-FileCopyrightText: 2009 Matthew Woehlke <mw_triad@users.sourceforge.net>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kimageframe.h"
0008 #include <QStyle>
0009 #include <QStyleOption>
0010 #include <QPainter>
0011 
0012 KImageFrame::KImageFrame(QWidget *parent) : QFrame(parent), _w(0), _h(0)
0013 {
0014 }
0015 
0016 void KImageFrame::setImage(const QImage &image)
0017 {
0018     _image = image;
0019     _w = image.width();
0020     _h = image.height();
0021     update();
0022 }
0023 
0024 void KImageFrame::paintEvent(QPaintEvent*)
0025 {
0026     QPainter p(this);
0027     QStyleOptionFrame opt;
0028     QRect rf(frameRect()), ri(0, 0, _w, _h);
0029 
0030     opt.rect = rf;
0031     opt.state = QStyle::State_Sunken;
0032 
0033     style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, this);
0034 
0035     ri.moveCenter(rf.center());
0036     p.drawImage(ri, _image);
0037 
0038     p.end();
0039 }
0040 
0041 // kate: hl C++; indent-width 4; replace-tabs on;