dialogList.cpp 2.72 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9 10
#include "dialogList.h"
#include "Utils/cgognStream.h"


namespace CGoGN
{

namespace SCHNApps
{

Sylvain Thery's avatar
Sylvain Thery committed
11
ListPopUp::ListPopUp(const QString& name, QWidget* parent) :
Sylvain Thery's avatar
Sylvain Thery committed
12 13 14
	QDialog(parent)
{
	setWindowTitle(name);
Sylvain Thery's avatar
Sylvain Thery committed
15
	setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
Sylvain Thery's avatar
Sylvain Thery committed
16 17
	m_layout = new QVBoxLayout(this);
	setLayout(m_layout);
Sylvain Thery's avatar
Sylvain Thery committed
18
	m_layout->setContentsMargins(1, 1, 1, 1);
Sylvain Thery's avatar
Sylvain Thery committed
19 20 21 22 23 24 25 26 27
	m_list_items = new QListWidget();
	m_list_items->setSelectionMode(QAbstractItemView::NoSelection);
	m_layout->addWidget(m_list_items);
}

ListPopUp::~ListPopUp()
{
}

Sylvain Thery's avatar
Sylvain Thery committed
28 29
QSize ListPopUp::sizeHint() const
{
Sylvain Thery's avatar
Sylvain Thery committed
30
	return QSize(170,100);
Sylvain Thery's avatar
Sylvain Thery committed
31 32
}

Sylvain Thery's avatar
Sylvain Thery committed
33 34 35 36 37
QListWidget* ListPopUp::list()
{
	return m_list_items;
}

Sylvain Thery's avatar
Sylvain Thery committed
38 39 40 41 42 43 44 45 46 47
void ListPopUp::show()
{
	int rows = m_list_items->model()->rowCount();
	int rowSize = m_list_items->sizeHintForRow(0);
	int height = rows * rowSize + 6;
	if (height < 96)
		height = 96;
	m_list_items->setFixedHeight(height);
	QDialog::show();
}
Sylvain Thery's avatar
Sylvain Thery committed
48 49 50 51 52

QListWidgetItem* ListPopUp::addItem(const QString& str, Qt::CheckState checked)
{
	QListWidgetItem* item = new QListWidgetItem(str, m_list_items);
	item->setCheckState(checked);
Sylvain Thery's avatar
Sylvain Thery committed
53 54 55 56 57 58 59 60 61 62 63 64
	int rows = m_list_items->model()->rowCount();
	int rowSize = m_list_items->sizeHintForRow(0);
	int height = rows * rowSize;
	if (height >= m_list_items->size().height())
		m_list_items->setFixedHeight(height + 6);
		
	//QFontMetrics fm(m_list_items->font());
	//int maxTextWidth = fm.width(item->text());
	//if (maxTextWidth < 140)
	//	maxTextWidth = 140;
	//m_list_items->setFixedWidth(maxTextWidth + 40);
	
Sylvain Thery's avatar
Sylvain Thery committed
65 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
	return item;
}

QListWidgetItem* ListPopUp::getItem(unsigned int row)
{
	return m_list_items->item(row);
}

unsigned int ListPopUp::nbItems()
{
	return m_list_items->count();
}

QListWidgetItem* ListPopUp::findItem(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		return items[0];
	return NULL;
}

bool ListPopUp::removeItem(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(items.empty())
		return false;
	m_list_items->takeItem(m_list_items->row(items[0]));
Sylvain Thery's avatar
Sylvain Thery committed
92

Sylvain Thery's avatar
Sylvain Thery committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	return true;
}

void ListPopUp::check(const QString& str, Qt::CheckState ck)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		items[0]->setCheckState(ck);
	else
		CGoGNerr<< "ListPopUp::check()"<< str.toStdString()<< " not in list"<< CGoGNendl;
}

 bool ListPopUp::isChecked(const QString& str)
{
	QList<QListWidgetItem*> items = m_list_items->findItems(str, Qt::MatchExactly);
	if(!items.empty())
		return (items[0]->checkState() == Qt::Checked);
	CGoGNerr<< "ListPopUp::isChecked()"<< str.toStdString()<< " not in list"<< CGoGNendl;
	return false;
}


} // namespace SCHNApps

} // namespace CGoGN