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

4
#include "view.h"
5 6 7 8 9 10 11 12 13 14 15 16

#include <QDialog>
#include <QRect>

class SplitArea;

struct PixElem
{
	View* view;
	QRect rect;
	QColor color;

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	PixElem() :
		view(NULL),
		color(Qt::gray)
	{}

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

	PixElem(const PixElem& pixElem) :
		view(pixElem.view),
		rect(pixElem.rect),
		color(pixElem.color)
	{}

	bool operator== (const PixElem& other) const
	{
		return view == other.view;
36 37
	}

38 39 40 41 42 43
	PixElem& operator= (const PixElem & other)
	{
		view = other.view;
		rect = other.rect;
		color = other.color;
		return *this;
44 45 46 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 103 104
public:
	enum SelectorDialogType {MOVE,SELECT};

105 106 107 108
	ViewSelector(QWidget* parent = NULL, SelectorDialogType type = MOVE);
	ViewSelector(ViewPixMaps viewPixMap, QWidget* parent = NULL, SelectorDialogType type = MOVE);
	virtual ~ViewSelector()
	{}
109 110

	void setGLVMap(ViewPixMaps viewPixMap);
111
	ViewPixMaps getGLVMap() { return viewPixMap; }
112 113 114

	QPoint getInsertPoint();

115
	void setInsertionName(QString insertionName) { this->insertionName = insertionName; }
116 117 118 119 120 121

	bool keys[3];

protected:
	ViewPixMaps viewPixMap;

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

	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