File indexing completed on 2024-04-14 04:02:00

0001 /*
0002     SPDX-FileCopyrightText: 2006 Matthew Williams <matt@milliams.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GAMEBOARDVIEW_H
0008 #define GAMEBOARDVIEW_H
0009 
0010 #include <QGraphicsView>
0011 
0012 #include "gameboardscene.h"
0013 
0014 /**
0015  * @short Actual game board widget
0016  *
0017  * A simple subclass of QGraphicsView simply to be able to resize the board according to user preferences.
0018  *
0019  * @author Matt Williams <matt@milliams.com>
0020  */
0021 
0022 class GameBoardView : public QGraphicsView
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     /**
0028      * Constructor
0029      *
0030      * @param parent the parent of the widget
0031      */
0032     explicit GameBoardView(QWidget *parent = nullptr);
0033     /**
0034      * Asks the scene through ( qobject_cast<GameBoardScene*>(scene()) ) for the smallest size it should be
0035      */
0036     QSize minimumSizeHint() const override
0037     {
0038         if (scene() == nullptr) {
0039           return {};
0040         } else {
0041             return qobject_cast<GameBoardScene *>(scene())->minimumSizeHint();
0042         }
0043     }
0044 public Q_SLOTS:
0045     ///Automatically resizes the board according to the users preferences. Deprecated for a bit
0046     void setBoardSize();
0047 protected:
0048     ///Overloaded to resize board.
0049     void resizeEvent(QResizeEvent *event) override
0050     {
0051         if (scene() != nullptr) {
0052             fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
0053         } QGraphicsView::resizeEvent(event);
0054     }
0055 };
0056 
0057 #endif // GAMEBOARDVIEW_H