1 /***************************************************************************** 2 * LibreMines * 3 * Copyright (C) 2020-2021 Bruno Bollos Correa * 4 * * 5 * This program is free software: you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation, either version 3 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 17 ***************************************************************************** 18 */ 19 20 21 #include "qlabel_adapted.h" 22 #include <QMouseEvent> 23 QLabel_adapted(QWidget * parent)24QLabel_adapted::QLabel_adapted(QWidget *parent): 25 QLabel(parent) 26 { 27 setFocusPolicy(Qt::ClickFocus); 28 } 29 mouseReleaseEvent(QMouseEvent * e)30void QLabel_adapted::mouseReleaseEvent(QMouseEvent *e) 31 { 32 33 #if QT_VERSION > QT_VERSION_CHECK(5, 15, 0) 34 QImage img = pixmap(Qt::ReturnByValue).toImage(); 35 #else 36 QImage img = pixmap()->toImage(); 37 #endif 38 img.invertPixels(); 39 setPixmap(QPixmap::fromImage(img)); 40 41 Q_EMIT SIGNAL_released(e); 42 } 43 mousePressEvent(QMouseEvent * e)44void QLabel_adapted::mousePressEvent(QMouseEvent *e) 45 { 46 #if QT_VERSION > QT_VERSION_CHECK(5, 15, 0) 47 QImage img = pixmap(Qt::ReturnByValue).toImage(); 48 #else 49 QImage img = pixmap()->toImage(); 50 #endif 51 img.invertPixels(); 52 setPixmap(QPixmap::fromImage(img)); 53 54 Q_EMIT SIGNAL_clicked(e); 55 } 56