cameraViewDialog.cpp 2.61 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "dialogs/cameraViewDialog.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
2 3 4 5 6 7 8 9

#include "window.h"
#include "view.h"
#include "camera.h"

#include <QMessageBox>
#include <QMouseEvent>

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

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
16
CameraViewDialog::CameraViewDialog(Window* window, View* view) :
17
	QDialog(view),
Pierre Kraemer's avatar
Pierre Kraemer committed
18
	m_window(window),
19 20
	m_view(view),
	b_refreshingUI(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
21
{
22 23
	setupUi(this);
	setWindowTitle(m_view->getName() + QString(" : camera"));
24

25
	connect(cameraList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedCameraChanged()));
26

27 28
	connect(m_window, SIGNAL(cameraAdded(Camera*)), this, SLOT(addCameraToList(Camera*)));
	connect(m_window, SIGNAL(cameraRemoved(Camera*)), this, SLOT(removeCameraFromList(Camera*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
29

30 31 32
	connect(m_window, SIGNAL(viewAndCameraLinked(View*, Camera*)), this, SLOT(selectCamera(View*, Camera*)));
	connect(m_window, SIGNAL(viewAndCameraUnlinked(View*, Camera*)), this, SLOT(deselectCamera(View*, Camera*)));

Pierre Kraemer's avatar
Pierre Kraemer committed
33 34 35
	QList<Camera*> cameras = m_window->getCamerasList();
	foreach(Camera* c, cameras)
		cameraList->addItem(c->getName());
36 37

	selectCurrentCamera();
Pierre Kraemer's avatar
Pierre Kraemer committed
38 39 40 41 42
}

CameraViewDialog::~CameraViewDialog()
{}

43 44
void CameraViewDialog::selectCurrentCamera()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
45
	Camera* current = m_view->getCurrentCamera();
46 47 48 49 50 51 52 53 54
	for(int i = 0; i < cameraList->count(); ++i)
	{
		if(cameraList->item(i)->text() == current->getName())
			cameraList->item(i)->setSelected(true);
		else
			cameraList->item(i)->setSelected(false);
	}
}

55
void CameraViewDialog::selectedCameraChanged()
56
{
57
	if(!b_refreshingUI)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	{
		QList<QListWidgetItem*> currentItems = cameraList->selectedItems();
		if(currentItems.empty())
			selectCurrentCamera();
		else
		{
			const QString& cname = currentItems[0]->text();
			Camera* c = m_window->getCamera(cname);
			m_window->linkViewAndCamera(m_view, c);
		}
	}
}

void CameraViewDialog::selectCamera(View* view, Camera* camera)
{
	if(view == m_view)
74
	{
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
		QList<QListWidgetItem*> items = cameraList->findItems(camera->getName(), Qt::MatchExactly);
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(true);
			b_refreshingUI = false;
		}
	}
}

void CameraViewDialog::deselectCamera(View* view, Camera* camera)
{
	if(view == m_view)
	{
		QList<QListWidgetItem*> items = cameraList->findItems(camera->getName(), Qt::MatchExactly);
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(false);
			b_refreshingUI = false;
		}
96 97 98
	}
}

99
void CameraViewDialog::addCameraToList(Camera* c)
100 101 102 103
{
	cameraList->addItem(c->getName());
}

104
void CameraViewDialog::removeCameraFromList(Camera* c)
Pierre Kraemer's avatar
Pierre Kraemer committed
105
{
106 107 108
	QList<QListWidgetItem*> items = cameraList->findItems(c->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];
Pierre Kraemer's avatar
Pierre Kraemer committed
109
}
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113

} // namespace SCHNApps

} // namespace CGoGN