Commit 10c85cad authored by Mathieu Faverge's avatar Mathieu Faverge

Factorize add_line

parent 96eac179
......@@ -208,39 +208,11 @@ void Settings_window::fill_table(const string &palette_name) {
for(it = colors_settings.begin();
it != colors_settings.end(); ++it)
{
add_state_line(states_table, row, it->first, it->second, p->is_visible( it->first ));
add_table_line(states_table, SLOT(state_color_changed(const QColor &)),
row, it->first, it->second, p->is_visible( it->first ));
}
}
void Settings_window::add_state_line(QTableWidget *table, int &row, string st_name, Color *c, bool checked) {
/* Name */
QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str());
name->setFlags(Qt::ItemIsEnabled);
/* Color */
QtColorPicker *color_widget = new QtColorPicker();
color_widget->setStandardColors();
if(c) {
color_widget->setCurrentColor(QColor(c->get_red()*255, c->get_green()*255, c->get_blue()*255));
}
else { // \todo check the default color value -> put this in Palette as static member
color_widget->setCurrentColor(QColor(0, 244, 222));
}
color_widget->setColorDialogEnabled(true);
connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, SLOT(state_color_changed(const QColor &)));
/* Visible */
QCheckBox *cb = new QCheckBox();
cb->setChecked(checked);
table->insertRow(row);
table->setItem(row, 0, name);
table->setCellWidget(row, 1, color_widget);
table->setCellWidget(row, 2, cb);
row ++;
}
void Settings_window::on_palette_list_currentIndexChanged(const QString & text) {
_changed=true;
fill_table(text.toStdString());
......@@ -350,7 +322,8 @@ void Settings_window::on_reload_states_btn_clicked(){
for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) {
add_state_line(states_table, row, (*it).first.c_str(), (*it).second, true);
add_table_line(states_table, SLOT(state_color_changed(const QColor &)),
row, (*it).first.c_str(), (*it).second, true);
}
}
......@@ -442,6 +415,37 @@ void Settings_window::link_types_color_changed(const QColor &qc) {
color_changed("link_types", link_types_table, qc);
}
void Settings_window::add_table_line(QTableWidget *table,
const char *slot,
int &row, std::string st_name, Color *c, bool checked) {
/* Name */
QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str());
name->setFlags(Qt::ItemIsEnabled);
/* Color */
QtColorPicker *color_widget = new QtColorPicker();
color_widget->setStandardColors();
if(c) {
color_widget->setCurrentColor(QColor(c->get_red()*255, c->get_green()*255, c->get_blue()*255));
}
else { // \todo check the default color value -> put this in Palette as static member
color_widget->setCurrentColor(QColor(255, 255, 255));
}
color_widget->setColorDialogEnabled(false);
connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, slot );
/* Visible */
QCheckBox *cb = new QCheckBox();
cb->setChecked(checked);
table->insertRow(row);
table->setItem(row, 0, name);
table->setCellWidget(row, 1, color_widget);
table->setCellWidget(row, 2, cb);
row ++;
}
/*************************/
/****** Types tab. ******/
/*************************/
......@@ -475,7 +479,8 @@ void Settings_window::fill_event_types_table(const string &palette_name) {
color = (Color *)((*it).second->get_extra_fields()->find(string("Color"))->second);
}
add_event_type_line(event_types_table, row, (*it).first.to_string(), color, true);
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
else { // Look for the state/color pairs in Session.
......@@ -483,43 +488,14 @@ void Settings_window::fill_event_types_table(const string &palette_name) {
for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) {
add_event_type_line(event_types_table, row, (*it).first, (*it).second, p->is_visible((*it).first));
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)),
row, (*it).first, (*it).second, p->is_visible((*it).first));
}
}
}
void Settings_window::add_event_type_line(QTableWidget *table, int &row, std::string st_name, Color *c, bool checked) {
/* Name */
QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str());
name->setFlags(Qt::ItemIsEnabled);
/* Color */
QtColorPicker *color_widget = new QtColorPicker();
color_widget->setStandardColors();
if(c) {
color_widget->setCurrentColor(QColor(c->get_red()*255, c->get_green()*255, c->get_blue()*255));
}
else { // \todo check the default color value -> put this in Palette as static member
color_widget->setCurrentColor(QColor(255, 255, 255));
}
color_widget->setColorDialogEnabled(false);
connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, SLOT( event_types_color_changed(const QColor &)));
/* Visible */
QCheckBox *cb = new QCheckBox();
cb->setChecked(checked);
table->insertRow(row);
table->setItem(row, 0, name);
table->setCellWidget(row, 1, color_widget);
table->setCellWidget(row, 2, cb);
row ++;
}
void Settings_window::fill_link_types_table(const string &palette_name) {
Session &S = Session::getSession();
......@@ -549,7 +525,8 @@ void Settings_window::fill_link_types_table(const string &palette_name) {
}
add_link_type_line(link_types_table, row, (*it).first.to_string(), color, true);
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
......@@ -558,7 +535,8 @@ void Settings_window::fill_link_types_table(const string &palette_name) {
for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) {
add_link_type_line(link_types_table, row, (*it).first, (*it).second, p->is_visible((*it).first));
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)),
row, (*it).first, (*it).second, p->is_visible((*it).first));
}
}
......@@ -566,36 +544,6 @@ void Settings_window::fill_link_types_table(const string &palette_name) {
}
void Settings_window::add_link_type_line(QTableWidget *table, int &row, string st_name, Color *c, bool checked) {
/* Name */
QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str());
name->setFlags(Qt::ItemIsEnabled);
/* Color */
QtColorPicker *color_widget = new QtColorPicker();
color_widget->setStandardColors();
if(c) {
color_widget->setCurrentColor(QColor(c->get_red()*255, c->get_green()*255, c->get_blue()*255));
}
else { // \todo check the default color value -> put this in Palette as static member
color_widget->setCurrentColor(QColor(255, 255, 255));
}
color_widget->setColorDialogEnabled(false);
connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, SLOT( link_types_color_changed(const QColor &)));
/* Visible */
QCheckBox *cb = new QCheckBox();
cb->setChecked(checked);
table->insertRow(row);
table->setItem(row, 0, name);
table->setCellWidget(row, 1, color_widget);
table->setCellWidget(row, 2, cb);
row ++;
}
void Settings_window::on_event_types_palette_list_currentIndexChanged(const QString &text) {
_changed=true;
fill_event_types_table(text.toStdString());
......@@ -631,7 +579,8 @@ void Settings_window::on_reload_link_types_palette_btn_clicked() {
}
add_link_type_line(link_types_table, row, (*it).first.to_string(), color, true);
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
......@@ -661,7 +610,8 @@ void Settings_window::on_reload_event_types_palette_btn_clicked() {
}
add_event_type_line(event_types_table, row, (*it).first.to_string(), color, true);
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
......
......@@ -81,12 +81,6 @@ private:
*/
void fill_table(const std::string &palette_name);
/*!
* \brief Fill a new row to the state table.
* row is incremented at the end of the function.
*/
void add_state_line(QTableWidget *table, int &row, std::string st_name, Color *c, bool checked = true);
/*!
* \brief Reload the general tab.
*/
......@@ -105,18 +99,14 @@ private:
/*!
* \brief add an event type to the table
*/
void add_event_type_line(QTableWidget *table, int&, std::string, Color*, bool);
void add_table_line(QTableWidget *table, const char *slot,
int&, std::string, Color*, bool);
/*!
* \brief Fill the link types table
*/
void fill_link_types_table(const std::string &text);
/*!
* \brief add a link type to the table
*/
void add_link_type_line(QTableWidget *table, int&, std::string, Color*, bool);
/*!
* \brief add a palette to the list, for a given type
*/
......
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