camerasDialog.cpp 3.51 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "dialogs/camerasDialog.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
2 3 4

#include "window.h"
#include "camera.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
5

Pierre Kraemer's avatar
Pierre Kraemer committed
6 7 8
#include <QMessageBox>
#include <QMouseEvent>

Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14
namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
15 16 17 18
CamerasDialog::CamerasDialog(Window* window) :
	QDialog(window),
	m_window(window)
{
19 20
	setupUi(this);
	setModal(false);
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26

	connect(addCameraButton, SIGNAL(clicked()), this, SLOT(cb_addCamera()));
	connect(removeCamerasButton, SIGNAL(clicked()), this, SLOT(cb_removeCameras()));

	connect(m_window, SIGNAL(cameraAdded(Camera*)), this, SLOT(cb_addCameraToList(Camera*)));
	connect(m_window, SIGNAL(cameraRemoved(Camera*)), this, SLOT(cb_removeCameraFromList(Camera*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
27 28 29 30 31 32

	connect(cameraList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(cb_itemChanged(QTreeWidgetItem*,int)));

	cameraList->resizeColumnToContents(1);
	cameraList->resizeColumnToContents(2);
	cameraList->resizeColumnToContents(3);
Pierre Kraemer's avatar
Pierre Kraemer committed
33 34 35 36 37
}

CamerasDialog::~CamerasDialog()
{}

Pierre Kraemer's avatar
Pierre Kraemer committed
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79
void CamerasDialog::setCameraType(const QString& name, qglviewer::Camera::Type type)
{
	b_refreshingUI = true;
	QList<QTreeWidgetItem*> items = cameraList->findItems(name, Qt::MatchExactly);
	if(!items.empty())
	{
		if(type == qglviewer::Camera::ORTHOGRAPHIC)
			items[0]->setCheckState(1, Qt::Checked);
		else
			items[0]->setCheckState(1, Qt::Unchecked);
	}
	b_refreshingUI = false;
}

void CamerasDialog::setDrawCamera(const QString& name, bool b)
{
	b_refreshingUI = true;
	QList<QTreeWidgetItem*> items = cameraList->findItems(name, Qt::MatchExactly);
	if(!items.empty())
	{
		if(b)
			items[0]->setCheckState(2, Qt::Checked);
		else
			items[0]->setCheckState(2, Qt::Unchecked);
	}
	b_refreshingUI = false;
}

void CamerasDialog::setDrawCameraPath(const QString& name, bool b)
{
	b_refreshingUI = true;
	QList<QTreeWidgetItem*> items = cameraList->findItems(name, Qt::MatchExactly);
	if(!items.empty())
	{
		if(b)
			items[0]->setCheckState(3, Qt::Checked);
		else
			items[0]->setCheckState(3, Qt::Unchecked);
	}
	b_refreshingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
80 81 82 83 84 85 86
void CamerasDialog::cb_addCamera()
{
	m_window->addCamera();
}

void CamerasDialog::cb_removeCameras()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
87 88
	QList<QTreeWidgetItem*> currentItems = cameraList->selectedItems();
	foreach(QTreeWidgetItem* item, currentItems)
Pierre Kraemer's avatar
Pierre Kraemer committed
89
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
90
		const QString& cname = item->text(0);
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92 93 94 95 96 97 98 99 100
		Camera* c = m_window->getCamera(cname);
		if(!c->isUsed())
			m_window->removeCamera(cname);
		else
			QMessageBox::warning(this, tr("Warning"), "Camera " + cname + " is currently used");
	}
}

void CamerasDialog::cb_addCameraToList(Camera* c)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102 103 104 105 106
	QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(c->getName()));
	item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
	item->setCheckState(1, Qt::Unchecked);
	item->setCheckState(2, Qt::Unchecked);
	item->setCheckState(3, Qt::Unchecked);
	cameraList->addTopLevelItem(item);
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109 110
}

void CamerasDialog::cb_removeCameraFromList(Camera* c)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114 115 116 117 118
	QList<QTreeWidgetItem*> items = cameraList->findItems(c->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];
}

void CamerasDialog::cb_itemChanged(QTreeWidgetItem* item, int column)
{
	if(!b_refreshingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
119
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
120 121
		Camera *c = m_window->getCamera(item->text(0));
		switch(column)
Pierre Kraemer's avatar
Pierre Kraemer committed
122
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
			case 1 :
				if(item->checkState(1) == Qt::Checked)
					c->changeType(qglviewer::Camera::ORTHOGRAPHIC);
				else
					c->changeType(qglviewer::Camera::PERSPECTIVE);
				break;
			case 2 :
				if(item->checkState(2) == Qt::Checked)
					c->setDraw(true);
				else
					c->setDraw(false);
				break;
			case 3 :
				if(item->checkState(3) == Qt::Checked)
					c->setDrawPath(true);
				else
					c->setDrawPath(false);
				break;
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142 143
		}
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
144 145 146 147

} // namespace SCHNApps

} // namespace CGoGN