Commit 016b07a2 authored by Frédéric Larue's avatar Frédéric Larue

ColorMapSelectionDialog added to GUI_main project.

parent 09e1728d
......@@ -29,6 +29,7 @@ target_link_libraries( ${CURRENT_TARGET}
NodeEditor
UIData
UIParam
Widgets
glew32 opengl32
)
else()
......@@ -40,6 +41,7 @@ target_link_libraries( ${CURRENT_TARGET}
NodeEditor
UIData
UIParam
Widgets
${GLEW_LIBRARIES}
GL
)
......
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#include "ColorMapSelectionDialog.h"
#include "UIMainWindow.h"
ColorMapSelectionDialog::ColorMapSelectionDialog( QWidget *parent, const QString &cmapString )
{
// Create the dialog buttons.
QDialogButtonBox *dlgButtons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
connect( dlgButtons, SIGNAL(accepted()), this, SLOT(accept()) );
connect( dlgButtons, SIGNAL(rejected()), this, SLOT(reject()) );
// If no color map can be found in the application settings, create a default list.
QSettings *settings = UIMainWindow::getUserSettings();
if( !settings->contains("ColorMaps/list") )
{
QStringList colorMapList;
colorMapList << "Error01" << "0: #0000FFFF, 0.333333: 0#FF0000FF, 0.666667: 0#FFFF00FF, 1: 0#00FF00FF";
colorMapList << "Heat01" << "0: #00007FFF, 0.166667: 0#0000FFFF, 0.333333: 0#00FFFFFF, 0.5: 0#00FF00FF, 0.666667: 0#FFFF00FF, 0.833333: 0#FF0000FF, 1: 0#8B0000FF";
colorMapList << "Heat02" << "0: #200000FF, 0.333333: #FF0000FF, 0.666667: #FFFF00FF, 1: #FFFFFFFF";
colorMapList << "Linear01" << "0: #000000FF, 1: 0#FFFFFFFF";
colorMapList << "Linear02" << "0: #00005FFF, 1: 0#FFFFBFFF";
settings->beginGroup( "ColorMaps" );
settings->setValue( "list", colorMapList );
settings->endGroup();
}
// Create a pannel for the edition of a custom colormap.
QGridLayout *l2 = new QGridLayout();
l2->setColumnStretch( 0, 0 );
l2->setColumnStretch( 1, 10 );
l2->setColumnStretch( 2, 0 );
QGroupBox *groupEdit = new QGroupBox( "Selected color map editing" );
groupEdit->setLayout( l2 );
m_CurrentColorMapName = new QLineEdit( "Custom01" );
l2->addWidget( m_CurrentColorMapName, 0, 0 );
m_CurrentColorMap = new GradientWidget();
m_CurrentColorMap->SetValueString( cmapString );
l2->addWidget( m_CurrentColorMap, 0, 1 );
QPushButton *save = new QPushButton("Save");
l2->addWidget( save, 0, 2 );
connect( save, SIGNAL(clicked(bool)), this, SLOT(saveColorMap()) );
// Add an entry in the dialog for each color map found in the application settings.
// One entry consists in the color map name, the associated gradient widget, one button to remove the color map from the list and another to select it.
m_ColorMapListLayout = new QGridLayout();
m_ColorMapListLayout->setColumnStretch( 0, 0 );
m_ColorMapListLayout->setColumnStretch( 1, 10 );
m_ColorMapListLayout->setColumnStretch( 2, 0 );
m_ColorMapListLayout->setColumnStretch( 3, 0 );
QGroupBox *groupList = new QGroupBox( "Available color maps" );
groupList->setLayout( m_ColorMapListLayout );
QStringList colorMapList = settings->value("ColorMaps/list").toStringList();
int i = 0;
for( auto s=colorMapList.begin(); s!=colorMapList.end(); ++s, ++i )
{
QString name = *s;
m_ColorMapListLayout->addWidget( new QLabel(name), i, 0 );
++ s;
GradientWidget *gdt = new GradientWidget();
if( *s == cmapString )
m_CurrentColorMapName->setText( name );
gdt->SetValueString( *s );
gdt->setDisabled( true );
m_ColorMapListLayout->addWidget( gdt, i, 1 );
QPushButton *remove = new QPushButton("X");
remove->setObjectName( QString::number(i) );
m_ColorMapListLayout->addWidget( remove, i, 2 );
QPushButton *select = new QPushButton("Select");
select->setObjectName( QString::number(i) );
m_ColorMapListLayout->addWidget( select , i, 3 );
connect( remove, SIGNAL(clicked(bool)), this, SLOT(removeColorMap()) );
connect( select, SIGNAL(clicked(bool)), this, SLOT(selectColorMap()) );
}
// Set up the global dialog UI.
QVBoxLayout *l = new QVBoxLayout();
l->addWidget( groupList );
l->addWidget( groupEdit );
l->addWidget( dlgButtons );
setLayout( l );
}
void ColorMapSelectionDialog::removeColorMap()
{
int rowId = sender()->objectName().toInt();
// Prompt the user for a removal confirmation.
if( QMessageBox::warning(
this,
"Remove color map",
"Do you really want to remove color map \"" + ((QLabel*) m_ColorMapListLayout->itemAtPosition(rowId,0)->widget())->text() + "\" from the list?",
QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
return;
// Delete all widgets corresponding to the color map to remove.
for( int j=0; j<m_ColorMapListLayout->columnCount(); ++j )
{
QWidget *w = m_ColorMapListLayout->itemAtPosition(rowId,j)->widget();
m_ColorMapListLayout->removeWidget(w);
w->deleteLater();
}
// Repack the remaining widgets in the color map list layout.
for( int i=rowId+1; i<m_ColorMapListLayout->rowCount(); ++i )
{
if( !m_ColorMapListLayout->itemAtPosition(i,0) )
break;
QString objectName = QString::number(i-1);
for( int j=0; j<m_ColorMapListLayout->columnCount(); ++j )
{
QWidget *w = m_ColorMapListLayout->itemAtPosition(i,j)->widget();
m_ColorMapListLayout->removeWidget(w);
m_ColorMapListLayout->addWidget( w, i-1, j );
w->setObjectName( objectName );
}
}
// Save the list to the application settings.
saveToApplicationSettings();
}
void ColorMapSelectionDialog::selectColorMap()
{
int rowId = sender()->objectName().toInt();
QLabel *selectedColorMapName = (QLabel*) m_ColorMapListLayout->itemAtPosition( rowId, 0 )->widget();
GradientWidget *selectedColorMap = (GradientWidget*) m_ColorMapListLayout->itemAtPosition( rowId, 1 )->widget();
m_CurrentColorMapName->setText( selectedColorMapName->text() );
m_CurrentColorMap->SetValueString( selectedColorMap->ValueString() );
}
void ColorMapSelectionDialog::saveColorMap()
{
int foundId = -1, newRowId = 0;
for( int i=0; i<m_ColorMapListLayout->rowCount(); ++i, ++newRowId )
{
if( !m_ColorMapListLayout->itemAtPosition(i,0) )
break;
if( m_CurrentColorMapName->text() == ((QLabel*) m_ColorMapListLayout->itemAtPosition(i,0)->widget())->text() )
{
foundId = i;
break;
}
}
GradientWidget *gdt = NULL;
if( foundId >= 0 )
{
if( QMessageBox::warning(
this,
"Replace color map",
"Color map \"" + m_CurrentColorMapName->text() + "\" already exists.\nDo you want to overwrite it?",
QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
return;
gdt = (GradientWidget*) m_ColorMapListLayout->itemAtPosition(foundId,1)->widget();
}
else
{
m_ColorMapListLayout->addWidget( new QLabel(m_CurrentColorMapName->text()), newRowId, 0 );
gdt = new GradientWidget();
gdt->setDisabled( true );
m_ColorMapListLayout->addWidget( gdt, newRowId, 1 );
QPushButton *remove = new QPushButton("X");
remove->setObjectName( QString::number(newRowId) );
m_ColorMapListLayout->addWidget( remove, newRowId, 2 );
QPushButton *select = new QPushButton("Select");
select->setObjectName( QString::number(newRowId) );
m_ColorMapListLayout->addWidget( select , newRowId, 3 );
connect( remove, SIGNAL(clicked(bool)), this, SLOT(removeColorMap()) );
connect( select, SIGNAL(clicked(bool)), this, SLOT(selectColorMap()) );
}
if( gdt )
gdt->SetValueString( m_CurrentColorMap->ValueString() );
// Save the list to the application settings.
saveToApplicationSettings();
}
void ColorMapSelectionDialog::saveToApplicationSettings()
{
QStringList colorMapList;
for( int i=0; i<m_ColorMapListLayout->rowCount(); ++i )
{
if( !m_ColorMapListLayout->itemAtPosition(i,0) )
break;
colorMapList << ((QLabel*) m_ColorMapListLayout->itemAtPosition(i,0)->widget())->text();
colorMapList << ((GradientWidget*) m_ColorMapListLayout->itemAtPosition(i,1)->widget())->ValueString();
}
QSettings *settings = UIMainWindow::getUserSettings();
settings->beginGroup( "ColorMaps" );
settings->setValue( "list", colorMapList );
settings->endGroup();
}
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifndef __COLORMAPSELECTIONDIALOG_H__
#define __COLORMAPSELECTIONDIALOG_H__
#include <GL/glew.h>
#include <QtWidgets>
#include "GUI_mainDefs.h"
#include "GradientWidget.h"
class GUIMAIN_API ColorMapSelectionDialog : public QDialog
{
Q_OBJECT
QLineEdit *m_CurrentColorMapName;
GradientWidget *m_CurrentColorMap;
QGridLayout *m_ColorMapListLayout;
void saveToApplicationSettings();
public:
ColorMapSelectionDialog( QWidget *parent = NULL, const QString &cmapString = "0: #000000FF, 1: 0#FFFFFFFF" );
inline QString valueString() const { return m_CurrentColorMap->ValueString(); }
private slots:
void removeColorMap();
void selectColorMap();
void saveColorMap();
};
#endif // __COLORMAPSELECTIONDIALOG_H__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment