File: kimageframe.cpp

package info (click to toggle)
kf6-kconfigwidgets 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,020 kB
  • sloc: cpp: 6,309; sh: 18; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
    SPDX-FileCopyrightText: 2009 Matthew Woehlke <mw_triad@users.sourceforge.net>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "kimageframe.h"
#include <QPainter>
#include <QStyle>
#include <QStyleOption>

KImageFrame::KImageFrame(QWidget *parent)
    : QFrame(parent)
    , _w(0)
    , _h(0)
{
}

void KImageFrame::setImage(const QImage &img)
{
    _img = img;
    _w = img.width();
    _h = img.height();
    update();
}

void KImageFrame::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    QStyleOptionFrame opt;
    QRect rf(frameRect());
    QRect ri(0, 0, _w, _h);

    opt.rect = rf;
    opt.state = QStyle::State_Sunken;

    style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, this);

    ri.moveCenter(rf.center());
    p.drawImage(ri, _img);

    p.end();
}

#include "moc_kimageframe.cpp"