File indexing completed on 2025-01-05 03:58:06
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-06-29 0007 * Description : Pressable Button class using QGraphicsItem 0008 * based on Frederico Duarte implementation. 0009 * 0010 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_FACE_ENGINE_DEMO_BUTTON_H 0017 #define DIGIKAM_FACE_ENGINE_DEMO_BUTTON_H 0018 0019 // Qt includes 0020 0021 #include <QObject> 0022 #include <QPainter> 0023 #include <QGraphicsItem> 0024 #include <QGraphicsSceneMouseEvent> 0025 0026 namespace FaceEngineDemo 0027 { 0028 0029 class Button : public QObject, 0030 public QGraphicsItem 0031 { 0032 Q_OBJECT 0033 Q_INTERFACES(QGraphicsItem) 0034 0035 public: 0036 0037 explicit Button(QGraphicsItem* const parent = nullptr); 0038 explicit Button(const QString& normal, const QString& pressed = QString(), QGraphicsItem* const parent = nullptr); 0039 Button(const QPixmap& normal, const QPixmap& pressed, QGraphicsItem* const parent = nullptr); 0040 ~Button() override; 0041 0042 public: 0043 0044 QRectF boundingRect() const override; 0045 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; 0046 void setPixmap(const QString& normal, const QString& pressed = QString()); 0047 void setPixmap(const QPixmap& normal, const QPixmap& pressed); 0048 0049 Q_SIGNALS: 0050 0051 void clicked(); 0052 0053 protected: 0054 0055 void mousePressEvent(QGraphicsSceneMouseEvent*) override; 0056 void mouseMoveEvent(QGraphicsSceneMouseEvent*) override; 0057 void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override; 0058 0059 private: 0060 0061 // Disable 0062 explicit Button(QObject*); 0063 0064 class Private; 0065 Private* const d; 0066 }; 0067 0068 } // namespace FaceEngineDemo 0069 0070 #endif // DIGIKAM_FACE_ENGINE_DEMO_BUTTON_H