File indexing completed on 2024-05-12 04:06:23
0001 /* 0002 SPDX-FileCopyrightText: 2009, 2010 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PALAPELI_CONSTRAINTVISUALIZER_H 0008 #define PALAPELI_CONSTRAINTVISUALIZER_H 0009 0010 #include "basics.h" 0011 0012 class QPropertyAnimation; 0013 #include <QList> 0014 0015 namespace Palapeli 0016 { 0017 class Scene; 0018 0019 /* This class creates and manages a draggable frame around a Palapeli 0020 * scene, which is used to expand or contract the scene. The principal 0021 * Palapeli::Scene object is the puzzle table. When a puzzle is loaded, 0022 * the puzzle table and other scenes have their frames (i.e. constraint 0023 * visualizers) automatically set to surround the pieces closely. 0024 * 0025 * A scene can be locked by the user, via Scene::setConstrained(), in 0026 * which case the frame and surrounding areas darken and the frame 0027 * cannot be moved by pushing pieces against it, but the scene size 0028 * can still be changed by dragging the frame with the mouse. 0029 * 0030 * The scene is then said to be "constrained" and its constraint 0031 * visualizer object is "active" (ConstraintVisualizer::m_active true). 0032 */ 0033 class ConstraintVisualizer : public 0034 Palapeli::GraphicsObject<Palapeli::ConstraintVisualizerUserType> 0035 { 0036 Q_OBJECT 0037 public: 0038 explicit ConstraintVisualizer(Palapeli::Scene* scene); 0039 0040 bool isActive() const; 0041 void start (const QRectF& sceneRect, 0042 const int thickness); 0043 void stop(); 0044 public Q_SLOTS: 0045 void setActive(bool active); 0046 void update(const QRectF& sceneRect); 0047 private: 0048 enum Side { LeftSide = 0, RightSide, 0049 TopSide, BottomSide, SideCount }; 0050 enum HandlePosition { LeftHandle = 0, TopLeftHandle, 0051 TopHandle, TopRightHandle, RightHandle, 0052 BottomRightHandle, BottomHandle, 0053 BottomLeftHandle, HandleCount }; 0054 0055 Palapeli::Scene* m_scene; 0056 bool m_active; 0057 0058 QList<QGraphicsRectItem*> m_shadowItems, m_handleItems; 0059 QGraphicsPathItem* m_indicatorItem; 0060 QRectF m_sceneRect; 0061 QPropertyAnimation* m_animator; 0062 bool m_isStopped; 0063 qreal m_thickness; 0064 }; 0065 } 0066 0067 #endif // PALAPELI_CONSTRAINTVISUALIZER_H