1 | /*************************************************************************** |
---|---|
2 | * Copyright (C) 1999-2006 by Éric Bischoff <ebischoff@nerim.net> * |
3 | * Copyright (C) 2007 by Albert Astals Cid <aacid@kde.org> * |
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 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | ***************************************************************************/ |
10 | |
11 | /* Play ground widget */ |
12 | |
13 | #ifndef _PLAYGROUND_H_ |
14 | #define _PLAYGROUND_H_ |
15 | |
16 | #include <QGraphicsView> |
17 | #include <QMap> |
18 | |
19 | #include <QSvgRenderer> |
20 | #include <QUndoGroup> |
21 | |
22 | class KActionCollection; |
23 | |
24 | class Action; |
25 | class ToDraw; |
26 | class TopLevel; |
27 | |
28 | class QGraphicsSvgItem; |
29 | |
30 | class PlayGround : public QGraphicsView |
31 | { |
32 | Q_OBJECT |
33 | |
34 | public: |
35 | PlayGround(TopLevel *parent); |
36 | ~PlayGround(); |
37 | |
38 | enum LoadError { NoError, OldFileVersionError, OtherError }; |
39 | |
40 | void reset(); |
41 | LoadError loadFrom(const QString &name); |
42 | bool saveAs(const QString &name); |
43 | bool printPicture(QPrinter &printer); |
44 | QPixmap getPicture(); |
45 | |
46 | void connectRedoAction(QAction *action); |
47 | void connectUndoAction(QAction *action); |
48 | |
49 | void registerPlayGrounds(); |
50 | bool loadPlayGround(const QString &gameboardFile); |
51 | |
52 | QString currentGameboard() const; |
53 | |
54 | bool isAspectRatioLocked() const; |
55 | |
56 | public Q_SLOTS: |
57 | void lockAspectRatio(bool lock); |
58 | |
59 | protected: |
60 | |
61 | void mousePressEvent(QMouseEvent *event); |
62 | void resizeEvent(QResizeEvent *event); |
63 | |
64 | private: |
65 | QRectF backgroundRect() const; |
66 | bool insideBackground(const QSizeF &size, const QPointF &pos) const; |
67 | void placeDraggedItem(const QPoint &pos); |
68 | void placeNewItem(const QPoint &pos); |
69 | void playGroundPixmap(const QString &playgroundName, QPixmap &pixmap); |
70 | |
71 | void recenterView(); |
72 | |
73 | QGraphicsScene *scene() const; |
74 | QUndoStack *undoStack() const; |
75 | |
76 | QString m_gameboardFile; // the file the board |
77 | QMap<QString, QString> m_objectsNameSound; // map between element name and sound |
78 | QMap<QString, double> m_objectsNameRatio; // map between element name and scaling ratio |
79 | |
80 | TopLevel *m_topLevel; // Top-level window |
81 | |
82 | QString m_pickedElement; // the SVG element the cursor is |
83 | ToDraw *m_dragItem; // the item we are dragging |
84 | QSvgRenderer m_SvgRenderer; // the SVG renderer |
85 | int m_nextZValue; // the next Z value to use |
86 | |
87 | bool m_lockAspect; // whether we are locking aspect ratio |
88 | QUndoGroup m_undoGroup; |
89 | |
90 | class SceneData |
91 | { |
92 | public: |
93 | QGraphicsScene *scene; |
94 | QUndoStack *undoStack; |
95 | }; |
96 | QMap <QString, SceneData> m_scenes; // caches the items of each playground |
97 | }; |
98 | |
99 | #endif |
100 | |
101 | /* kate: replace-tabs on; indent-width 2; */ |
102 |