viewSelector.h 2.57 KB
Newer Older
1 2
#ifndef _VIEWSELECTOR_H_
#define _VIEWSELECTOR_H_
3

4
#include "view.h"
5 6 7 8 9 10

#include <QDialog>
#include <QRect>

class SplitArea;

11
class PixElem
12
{
13
public:
14 15 16 17 18 19 20 21 22 23 24 25
	PixElem() :
		view(NULL),
		color(Qt::gray)
	{}

	PixElem(View* view) :
		view(view),
		color(Qt::gray)
	{}

	PixElem(const PixElem& pixElem) :
		view(pixElem.view),
26 27
		color(pixElem.color),
		rect(pixElem.rect)
28 29 30 31 32
	{}

	bool operator== (const PixElem& other) const
	{
		return view == other.view;
33 34
	}

35 36 37 38 39 40
	PixElem& operator= (const PixElem & other)
	{
		view = other.view;
		rect = other.rect;
		color = other.color;
		return *this;
41 42
	}

43 44 45 46
	View* view;
	QColor color;
	QRect rect;
};
47 48 49 50 51 52 53 54

class ViewPixMaps : public QList<QList<PixElem> >
{
public:
	typedef ViewPixMaps::iterator y_iterator;
	typedef QList<PixElem>::iterator x_iterator;

	ViewPixMaps();
55 56
	~ViewPixMaps()
	{}
57 58 59

	void fromSplitArea(SplitArea* splitArea);

60 61 62 63
	int getMaxX() { return maxX; }
	int getMinX() { return minX; }
	int getY() { return Y; }
	int getYMinX() { return YminX; }
64

65
	PixElem& getAt(int x, int y) { return (*this)[y][x]; }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

	y_iterator y_begin(){return this->begin();}
	y_iterator y_end(){return this->end();}
	x_iterator x_begin(y_iterator y_it){return y_it->begin();}
	x_iterator x_end(y_iterator y_it){return y_it->end();}

	void beginMove(int x, int y);
	void moveTmp(int x, int y);
	void confirmMove();
	void cancelMove();

	void insertion(int x, int y);

	bool isModified(){return this->modif;}

private:
	int maxX;
	int minX;
	int Y;
	int YminX;

	int originX, originY;
	PixElem origin;
	int tmpX, tmpY;
	PixElem tmp;

	bool modif;

protected:
	void computeSize();
};

class ViewSelector : public QDialog
{
	Q_OBJECT
101

102
public:
103 104 105 106 107
	enum SelectorDialogType
	{
		MOVE,
		SELECT
	};
108

109 110
	ViewSelector(QWidget* parent = NULL, SelectorDialogType type = MOVE);
	ViewSelector(ViewPixMaps viewPixMap, QWidget* parent = NULL, SelectorDialogType type = MOVE);
111
	~ViewSelector();
112

113
	void setGLVMap(const ViewPixMaps& viewPixMap);
114
	ViewPixMaps getGLVMap() { return viewPixMap; }
115 116 117

	QPoint getInsertPoint();

118
	void setInsertionName(QString insertionName) { this->insertionName = insertionName; }
119 120 121 122 123 124

	bool keys[3];

protected:
	ViewPixMaps viewPixMap;

125 126
	int mouseX;
	int mouseY;
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

	bool pixmapGrabbed;
	QRect grabbed;

	SelectorDialogType type;

	QPoint insertPoint;
	QString insertionName;

protected:
    void paintEvent(QPaintEvent *event);
    void mouseMoveEvent ( QMouseEvent * event );
    void mousePressEvent ( QMouseEvent * event );
    void mouseReleaseEvent( QMouseEvent * event );
    void keyPressEvent( QKeyEvent * event );
    void keyReleaseEvent( QKeyEvent * event );

private:
    QPoint mouseToIndice();
};

#endif