File indexing completed on 2024-05-19 04:07:50
0001 /* 0002 SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PALAPELI_PIECE_P_H 0008 #define PALAPELI_PIECE_P_H 0009 0010 #include <QGraphicsItem> 0011 #include <QObject> 0012 #include <QStyleOptionGraphicsItem> 0013 0014 namespace Palapeli 0015 { 0016 class SelectionAwarePixmapItem : public QObject, public QGraphicsPixmapItem 0017 { 0018 Q_OBJECT 0019 public: 0020 explicit SelectionAwarePixmapItem(const QPixmap& pixmap, QGraphicsItem* parent = nullptr) 0021 : QGraphicsPixmapItem(pixmap, parent) 0022 { 0023 } 0024 0025 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override 0026 { 0027 //suppress the ugly selection outline (we have much nicer selection indications in Palapeli::Piece) 0028 QStyleOptionGraphicsItem opt(*option); 0029 opt.state = opt.state & ~QStyle::State_Selected; 0030 QGraphicsPixmapItem::paint(painter, &opt, widget); 0031 } 0032 Q_SIGNALS: 0033 void selectedChanged(bool selected); 0034 protected: 0035 QVariant itemChange(GraphicsItemChange change, const QVariant& value) override 0036 { 0037 if (change == ItemSelectedChange) 0038 Q_EMIT selectedChanged(value.toBool()); 0039 return QGraphicsPixmapItem::itemChange(change, value); 0040 } 0041 }; 0042 } 0043 0044 #endif // PALAPELI_PIECE_P_H