diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 36c3f2d7ae7..00a39f9fc29 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -157,19 +157,8 @@ MainWindow::MainWindow(QWidget* parent) // setup the sceneview: delegation and columns sizing... sceneView->setItemDelegate(delegate); + resetHeader(); - //sceneView->header()->setStretchLastSection(false); - /* sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); - sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); - sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); - sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); - sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); - sceneView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); - sceneView->resizeColumnToContents(Scene::ColorColumn); - sceneView->resizeColumnToContents(Scene::RenderingModeColumn); - sceneView->resizeColumnToContents(Scene::ABColumn); - sceneView->resizeColumnToContents(Scene::VisibleColumn); -*/ // setup connections connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), this, SLOT(updateInfo())); @@ -1023,6 +1012,7 @@ void MainWindow::open(QString filename) this->addToRecentFiles(fileinfo.absoluteFilePath()); } selectSceneItem(scene->addItem(scene_item)); + sceneView->resizeColumnToContents(Scene::NameColumn); } bool MainWindow::open(QString filename, QString loader_name) { @@ -1180,6 +1170,7 @@ void MainWindow::selectionChanged() this, SLOT(updateInfo())); } viewer->update(); + resetHeader(); } void MainWindow::contextMenuRequested(const QPoint& global_pos) { @@ -1726,11 +1717,13 @@ void MainWindow::restoreCollapseState() QModelIndex modelIndex = scene->index(0,0,scene->invisibleRootItem()->index()); if(modelIndex.isValid()) recurseExpand(modelIndex); + resetHeader(); } void MainWindow::makeNewGroup() { - Scene_group_item * group = new Scene_group_item("New group"); + Scene_group_item * group = new Scene_group_item(); scene->addItem(group); + sceneView->resizeColumnToContents(Scene::NameColumn); } void MainWindow::on_upButton_pressed() @@ -1872,3 +1865,18 @@ void MainWindow::on_actionMaxTextItemsDisplayed_triggered() ui->actionMaxTextItemsDisplayed->setText(QString("Set Maximum Text Items Displayed : %1").arg(text.toInt())); } } + +void MainWindow::resetHeader() +{ + scene->invisibleRootItem()->setColumnCount(5); + sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Interactive); + sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::Fixed); + sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::ResizeToContents); + sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); + sceneView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); + sceneView->header()->resizeSection(Scene::ColorColumn, sceneView->header()->fontMetrics().width(" Color ")); + sceneView->resizeColumnToContents(Scene::RenderingModeColumn); + sceneView->resizeColumnToContents(Scene::NameColumn); + sceneView->header()->resizeSection(Scene::ABColumn, sceneView->header()->fontMetrics().width(QString(" AB "))); + sceneView->header()->resizeSection(Scene::VisibleColumn, sceneView->header()->fontMetrics().width(QString(" View "))); +} diff --git a/Polyhedron/demo/Polyhedron/MainWindow.h b/Polyhedron/demo/Polyhedron/MainWindow.h index 1e7c3bb946d..099c45c2da9 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.h +++ b/Polyhedron/demo/Polyhedron/MainWindow.h @@ -315,6 +315,9 @@ protected Q_SLOTS: void filterOperations(); //!Updates the bounding box and moves the camera to fits the scene. void on_actionRecenterScene_triggered(); + + //!Resizes the header of the scene view + void resetHeader(); protected: QList createSubMenus(QList); /*! For each objects in the sceneView, loads the associated plugins. diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index aa1ce0fce4e..1a12ce75774 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -591,9 +591,7 @@ Scene::data(const QModelIndex &index, int role) const switch(index.column()) { case ColorColumn: - if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) - return m_entries.value(id)->color(); - else if(role == ::Qt::DecorationRole) + if(role == ::Qt::DecorationRole) return m_entries.value(id)->color(); break; case NameColumn: @@ -937,8 +935,8 @@ bool SceneDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, QColor color = QColorDialog::getColor(model->data(index).value(), 0/*, - tr("Select color"), - QColorDialog::ShowAlphaChannel*/); + tr("Select color"), + QColorDialog::ShowAlphaChannel*/); if (color.isValid()) { model->setData(index, color ); }