Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    const int n = 3;

    QTableWidget *mainTable = new QTableWidget(n,n);
    QTableWidgetItem *widgetItem = 0;
    QStringList nameItems;

      nameItems << "First" << "Second" << "Third";
      mainTable->setHorizontalHeaderLabels(nameItems); //set headers on Horizontal
      mainTable->setVerticalHeaderLabels(nameItems);   //set headers on Vertical

      for(int i = 0;  i < n; ++i)
        {
          for(int j = 0; j < n; ++j)
            {
              widgetItem = new QTableWidgetItem(QString("%1,%2").arg(i).arg(j));
              mainTable->setItem(i,j,widgetItem);
            }
        }
    mainTable->setGeometry(430,340,400,180);
    mainTable->setWindowTitle("Main table");
    mainTable->show();

    return a.exec();
}
Ejemplo n.º 2
0
void model_import_dlg::create_mesh_tab(QTabWidget * parent, size_t index, render::lod lod)
{
	QWidget * tab = new QWidget(parent);
	tab->setObjectName("meshTab");

	auto & geometry = conv.get(index).geometry.at(lod);
	auto & material = conv.get(index).materials.at(lod);

	QGroupBox * geometry_box = new QGroupBox(tab);
	geometry_box->setGeometry(10, 10, 561, 115);
	geometry_box->setTitle("Geometry");

	QLabel * vertices = new QLabel(geometry_box);
	vertices->setGeometry(20, 20, 200, 20);
	vertices->setText("Vertices: " + QString::number(geometry.vertex_count));

	QLabel * faces = new QLabel(geometry_box);
	faces->setGeometry(20, 40, 200, 20);
	faces->setText("Faces: " + QString::number(geometry.index_count / 3));

	QLabel * indices = new QLabel(geometry_box);
	indices->setGeometry(20, 60, 200, 20);
	indices->setText("Indices: " + QString::number(geometry.index_count));

	QLabel * layout = new QLabel(geometry_box);
	layout->setGeometry(20, 80, 200, 20);
	layout->setText("Layout: " + QString::fromStdString(render::vertex::str(geometry.vertex_type)));

	QGroupBox * material_box = new QGroupBox(tab);
	material_box->setGeometry(10, 130, 561, 400);
	material_box->setTitle("Material");

	QGroupBox * colors_box = new QGroupBox(material_box);
	colors_box->setGeometry(15, 20, 455, 134);
	colors_box->setTitle("Colors");

	QTableWidget * colorsTable = new QTableWidget(colors_box);
	colorsTable->setGeometry(15, 25, 237, 92);
	colorsTable->setObjectName("colorsTable");
	colorsTable->setRowCount(3);
	colorsTable->setColumnCount(3);
	colorsTable->setFrameShape(QFrame::NoFrame);
	colorsTable->setShowGrid(false);
	colorsTable->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
	colorsTable->setEditTriggers(QAbstractItemView::DoubleClicked);
	colorsTable->horizontalHeader()->setDefaultSectionSize(60);
	colorsTable->verticalHeader()->setDefaultSectionSize(23);
	colorsTable->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);

	QStringList color_types;
	color_types.append("Ambient");
	color_types.append("Diffuse");
	color_types.append("Specular");

	QStringList color_channels;
	color_channels.append("R");
	color_channels.append("G");
	color_channels.append("B");

	colorsTable->setVerticalHeaderLabels(color_types);
	colorsTable->setHorizontalHeaderLabels(color_channels);

	colorsTable->setItem(0, 0, new QTableWidgetItem(QString::number(rgb_to_byte(material.ambient.x))));
	colorsTable->setItem(0, 1, new QTableWidgetItem(QString::number(rgb_to_byte(material.ambient.y))));
	colorsTable->setItem(0, 2, new QTableWidgetItem(QString::number(rgb_to_byte(material.ambient.z))));
	colorsTable->setItem(1, 0, new QTableWidgetItem(QString::number(rgb_to_byte(material.diffuse.x))));
	colorsTable->setItem(1, 1, new QTableWidgetItem(QString::number(rgb_to_byte(material.diffuse.y))));
	colorsTable->setItem(1, 2, new QTableWidgetItem(QString::number(rgb_to_byte(material.diffuse.z))));
	colorsTable->setItem(2, 0, new QTableWidgetItem(QString::number(rgb_to_byte(material.specular.x))));
	colorsTable->setItem(2, 1, new QTableWidgetItem(QString::number(rgb_to_byte(material.specular.y))));
	colorsTable->setItem(2, 2, new QTableWidgetItem(QString::number(rgb_to_byte(material.specular.z))));

	QPushButton * colorPick = new QPushButton(colors_box);
	colorPick->setGeometry(290, 24, 75, 23);
	colorPick->setObjectName("colorPick");
	colorPick->setText("Pick");

	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			colorsTable->item(i, j)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

	QObject::connect(colorsTable, SIGNAL(itemSelectionChanged()), this, SLOT(on_color_table_changed()));
	QObject::connect(colorPick, SIGNAL(pressed()), this, SLOT(on_color_pick()));

	QLabel * spec_power = new QLabel(colors_box);
	spec_power->setGeometry(290, 89, 80, 23);
	spec_power->setText("Specular power: ");

	QDoubleSpinBox * spec_power_box = new QDoubleSpinBox(colors_box);
	spec_power_box->setObjectName("specularSpinBox");
	spec_power_box->setDecimals(2);
	spec_power_box->setSingleStep(0.05);
	spec_power_box->setFrame(false);
	spec_power_box->setGeometry(390, 89, 50, 23);
	spec_power_box->setValue(material.specular_power);

	QGroupBox * textures_box = new QGroupBox(material_box);
	textures_box->setGeometry(15, 159, 531, 225);
	textures_box->setTitle("Textures");

	QTableWidget * texturesTable = new QTableWidget(textures_box);
	texturesTable->setObjectName("texturesTable");
	texturesTable->setGeometry(15, 25, 500, 150);
	texturesTable->setRowCount(material.textures.size());
	texturesTable->setColumnCount(2);
	texturesTable->setFrameShape(QFrame::NoFrame);
	texturesTable->setShowGrid(false);
	texturesTable->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
	texturesTable->setEditTriggers(QAbstractItemView::DoubleClicked);
	texturesTable->horizontalHeader()->setDefaultSectionSize(60);
	texturesTable->verticalHeader()->setDefaultSectionSize(23);
	texturesTable->verticalHeader()->setVisible(false);

	QStringList texture_headers;
	texture_headers.append("File");
	texture_headers.append("Type");
	texturesTable->setHorizontalHeaderLabels(texture_headers);

	int i = 0;
	assimp::texture_type_map texture_map;

	for (auto texture : material.textures)
	{
		texturesTable->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(texture.second.texture_path.generic_string())));
		texturesTable->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(texture_map.get(texture.first))));
		texturesTable->setColumnWidth(0, 350);
		texturesTable->setColumnWidth(1, 150);

		i++;
	}

	for (i = 0; i < texturesTable->rowCount(); i++)
	for (int j = 0; j < texturesTable->columnCount(); j++)
		texturesTable->item(i, j)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

	QPushButton * add_texture = new QPushButton(textures_box);
	add_texture->setGeometry(15, 185, 75, 23);
	add_texture->setText("Add");

	QPushButton * edit_texture = new QPushButton(textures_box);
	edit_texture->setGeometry(100, 185, 75, 23);
	edit_texture->setObjectName("textureEditButton");
	edit_texture->setText("Edit");
	edit_texture->setEnabled(false);

	QPushButton * delete_texture = new QPushButton(textures_box);
	delete_texture->setGeometry(185, 185, 75, 23);
	delete_texture->setObjectName("textureDeleteButton");
	delete_texture->setText("Delete");
	delete_texture->setEnabled(false);

	QObject::connect(texturesTable, SIGNAL(itemSelectionChanged()), this, SLOT(on_texture_table_changed()));
	QObject::connect(add_texture, SIGNAL(pressed()), this, SLOT(on_texture_add()));
	QObject::connect(edit_texture, SIGNAL(pressed()), this, SLOT(on_texture_edit()));
	QObject::connect(delete_texture, SIGNAL(pressed()), this, SLOT(on_texture_delete()));

	QString title = "Mesh " + QString::number(index);
	parent->addTab(tab, title);
}