2
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
5
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "myswitcher.h"
23
#include <QPainterPath>
24
#include <QMouseEvent>
27
MySwitcher::MySwitcher(QWidget *parent) :
31
this->setFixedSize(76, 29);
32
m_offImage.load("://res/off.png");
33
m_onImage.load("://res/on.png");
36
bool MySwitcher::isOn() const
41
void MySwitcher::setOnStatus(bool b)
45
emit this->statusChanged(b);
50
void MySwitcher::mousePressEvent(QMouseEvent *event)
52
if (event->button() == Qt::LeftButton) {
53
this->setOnStatus(!m_isOn);
58
void MySwitcher::paintEvent(QPaintEvent *event)
60
QPixmap *m_nowImagePix;
63
m_nowImagePix = &m_onImage;
66
m_nowImagePix = &m_offImage;
69
if(m_nowImagePix->isNull())
72
QPainter painter(this);
73
painter.setRenderHints(QPainter::Antialiasing, true);
76
path.addRoundedRect(rect(), m_nowImagePix->height() / 2.0, m_nowImagePix->height() / 2.0);
79
painter.setClipPath(path);
80
painter.drawPixmap(rect(), *m_nowImagePix);