-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonwidgetmediator.h
65 lines (57 loc) · 1.72 KB
/
buttonwidgetmediator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef BUTTONWIDGETMEDIATOR_H
#define BUTTONWIDGETMEDIATOR_H
#include <QMap>
#include <QString>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include "qgraphicsitemfactory.h"
#include "qgraphicsitemcomposite.h"
#include "graphicsscene.h"
#include "commands.h"
class Mediator : public QWidget
{
Q_OBJECT
signals:
void clicked(const QString& uid);
void mousepressed();
void mousereleased();
void mousemove(const QPointF & pos);
public:
Mediator(QWidget* parent = 0);
virtual ~Mediator(){}
virtual void registerCommand(const QString& uid, Command* command) = 0;
virtual void registerScene(GraphicsScene* scene) = 0;
virtual GraphicsScene* getScene() const = 0;
virtual QList<QGraphicsItem*> getSelection() const = 0;
virtual void toggleSelection(QGraphicsItem* item) = 0;
virtual void clearSelection() = 0;
};
class ButtonWidgetMediator : public Mediator
{
Q_OBJECT
public:
explicit ButtonWidgetMediator(QWidget *parent = 0);
virtual ~ButtonWidgetMediator();
virtual void registerCommand(const QString& uid, Command* command) final;
virtual void registerScene(GraphicsScene* scene) final;
virtual GraphicsScene *getScene() const final;
virtual QList<QGraphicsItem*> getSelection() const final;
virtual void toggleSelection(QGraphicsItem *item) final;
virtual void clearSelection() final;
private slots:
void sceneClicked();
void buttonClicked();
protected:
void handleItem(QGraphicsItem* item);
QGraphicsItem *getParent(QGraphicsItem *item);
void registerButton(const QString& uid);
private:
QMap<QString, QPushButton*> registry;
QMap<QString, Command*> commands;
QList<QGraphicsItem*> selected;
GraphicsScene* scene = nullptr;
QVBoxLayout *layout = nullptr;
QString uid;
};
#endif // BUTTONWIDETMEDIATOR_H