void DimensionManager::show(gig::Region* region) { ignoreColumnClicked = true; this->region = region; refreshManager(); Gtk::Window::show(); deiconify(); ignoreColumnClicked = false; }
void TransferFunctionManager::load(QList<SplineInformation> splineInfo) { m_tfContainer->clearContainer(); for(int i=0; i<splineInfo.count(); i++) m_tfContainer->fromSplineInformation(splineInfo[i]); refreshManager(); }
void DimensionManager::onAllRegionsCheckBoxToggled() { set_title( allRegions() ? _("Dimensions of all Regions") : _("Dimensions of selected Region") ); treeView.set_tooltip_text( allRegions() ? _("Dimensions and numbers in gray indicates a difference among the individual regions.") : _("You are currently only viewing dimensions of the currently selected region.") ); refreshManager(); }
void TransferFunctionManager::append(const char *flnm) { //m_tfContainer->clearContainer(); QDomDocument document; QFile f(flnm); if (f.open(QIODevice::ReadOnly)) { document.setContent(&f); f.close(); } QDomElement main = document.documentElement(); QDomNodeList dlist = main.childNodes(); for(int i=0; i<dlist.count(); i++) { if (dlist.at(i).nodeName() == "transferfunction") m_tfContainer->fromDomElement(dlist.at(i).toElement()); } refreshManager(); }
void DimensionManager::removeDimension() { Glib::RefPtr<Gtk::TreeSelection> sel = treeView.get_selection(); Gtk::TreeModel::iterator it = sel->get_selected(); if (it) { Gtk::TreeModel::Row row = *it; gig::dimension_t type = row[tableModel.m_type]; // assemble the list of regions where the selected dimension shall be // added to std::vector<gig::Region*> vRegions; if (allRegions()) { gig::Instrument* instr = (gig::Instrument*)region->GetParent(); for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) { if (rgn->GetDimensionDefinition(type)) vRegions.push_back(rgn); } } else vRegions.push_back(region); std::set<Glib::ustring> errors; for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) { gig::Region* region = vRegions[iRgn]; gig::dimension_def_t* dim = region->GetDimensionDefinition(type); try { // notify everybody that we're going to update the region region_to_be_changed_signal.emit(region); // remove selected dimension region->DeleteDimension(dim); // let everybody know there was a change region_changed_signal.emit(region); } catch (RIFF::Exception e) { // notify that the changes are over (i.e. to avoid dead locks) region_changed_signal.emit(region); Glib::ustring txt = _("Could not remove dimension: ") + e.Message; if (vRegions.size() == 1) { // show error message directly Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } else { // remember error, they are shown after all regions have been processed errors.insert(txt); } } } // update all GUI elements refreshManager(); if (!errors.empty()) { Glib::ustring txt = _( "The following errors occurred while trying to remove the dimension from all regions:" ); txt += "\n\n"; for (std::set<Glib::ustring>::const_iterator it = errors.begin(); it != errors.end(); ++it) { txt += "-> " + *it + "\n"; } txt += "\n"; txt += _( "You might also want to check the console for further warnings and " "error messages." ); Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } } }
void DimensionManager::addDimension() { Gtk::Dialog dialog(_("New Dimension"), true /*modal*/); // add dimension type combo box to the dialog Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel); for (int i = 0x01; i < 0xff; i++) { Glib::ustring sType = dimTypeAsString(static_cast<gig::dimension_t>(i)); if (sType.find("Unknown") != 0) { Gtk::TreeModel::Row row = *(refComboModel->append()); row[comboModel.m_type_id] = i; row[comboModel.m_type_name] = sType; } } Gtk::Table table(2, 2); Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START); Gtk::ComboBox comboDimType; comboDimType.set_model(refComboModel); comboDimType.pack_start(comboModel.m_type_id); comboDimType.pack_start(comboModel.m_type_name); Gtk::Label labelZones(_("Zones:"), Gtk::ALIGN_START); table.attach(labelDimType, 0, 1, 0, 1); table.attach(comboDimType, 1, 2, 0, 1); table.attach(labelZones, 0, 1, 1, 2); dialog.get_vbox()->pack_start(table); // number of zones: use a combo box with fix values for gig // v2 and a spin button for v3 Gtk::ComboBoxText comboZones; Gtk::SpinButton spinZones; bool version2 = false; if (region) { gig::File* file = (gig::File*)region->GetParent()->GetParent(); version2 = file->pVersion && file->pVersion->major == 2; } if (version2) { for (int i = 1; i <= 5; i++) { char buf[3]; sprintf(buf, "%d", 1 << i); #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2 comboZones.append_text(buf); #else comboZones.append(buf); #endif } table.attach(comboZones, 1, 2, 1, 2); } else { spinZones.set_increments(1, 8); spinZones.set_numeric(true); spinZones.set_range(2, 128); spinZones.set_value(2); table.attach(spinZones, 1, 2, 1, 2); } dialog.add_button(_("_OK"), 0); dialog.add_button(_("_Cancel"), 1); dialog.show_all_children(); if (!dialog.run()) { // OK selected ... Gtk::TreeModel::iterator iterType = comboDimType.get_active(); if (!iterType) return; Gtk::TreeModel::Row rowType = *iterType; if (!rowType) return; int iTypeID = rowType[comboModel.m_type_id]; gig::dimension_t type = static_cast<gig::dimension_t>(iTypeID); gig::dimension_def_t dim; dim.dimension = type; if (version2) { if (comboZones.get_active_row_number() < 0) return; dim.bits = comboZones.get_active_row_number() + 1; dim.zones = 1 << dim.bits; } else { dim.zones = spinZones.get_value_as_int(); dim.bits = zoneCountToBits(dim.zones); } // assemble the list of regions where the selected dimension shall be // added to std::vector<gig::Region*> vRegions; if (allRegions()) { gig::Instrument* instr = (gig::Instrument*)region->GetParent(); for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) { if (!rgn->GetDimensionDefinition(type)) vRegions.push_back(rgn); } } else vRegions.push_back(region); std::set<Glib::ustring> errors; for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) { gig::Region* region = vRegions[iRgn]; try { printf( "Adding dimension (type=0x%x, bits=%d, zones=%d)\n", dim.dimension, dim.bits, dim.zones ); // notify everybody that we're going to update the region region_to_be_changed_signal.emit(region); // add the new dimension to the region // (implicitly creates new dimension regions) region->AddDimension(&dim); // let everybody know there was a change region_changed_signal.emit(region); } catch (RIFF::Exception e) { // notify that the changes are over (i.e. to avoid dead locks) region_changed_signal.emit(region); Glib::ustring txt = _("Could not add dimension: ") + e.Message; if (vRegions.size() == 1) { // show error message directly Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } else { // remember error, they are shown after all regions have been processed errors.insert(txt); } } } // update all GUI elements refreshManager(); if (!errors.empty()) { Glib::ustring txt = _( "The following errors occurred while trying to create the dimension on all regions:" ); txt += "\n\n"; for (std::set<Glib::ustring>::const_iterator it = errors.begin(); it != errors.end(); ++it) { txt += "-> " + *it + "\n"; } txt += "\n"; txt += _( "You might also want to check the console for further warnings and " "error messages." ); Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } } }
void DimensionManager::onColumnClicked() { printf("DimensionManager::onColumnClicked()\n"); //FIXME: BUG: this method is currently very unreliably called, it should actually be called when the user selects another column, it is ATM however also called when the table content changed programmatically causing the dialog below to popup at undesired times ! //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired if (ignoreColumnClicked) { ignoreColumnClicked = false; return; } #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2 // prevents app to crash if this dialog is closed if (!get_visible()) return; #else # warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type ! #endif #if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 3 if (!is_visible()) return; #endif Gtk::TreeModel::Path path; Gtk::TreeViewColumn* focus_column; treeView.get_cursor(path, focus_column); //const int row = path[0]; if (focus_column == treeView.get_column(0)) { Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path); if (!it) return; Gtk::TreeModel::Row row = *it; gig::dimension_t oldType = row[tableModel.m_type]; Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/); int oldTypeIndex = -1; Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel); for (int i = 0x01, count = 0; i < 0xff; i++) { Glib::ustring sType = dimTypeAsString(static_cast<gig::dimension_t>(i)); if (i == oldType) oldTypeIndex = count; if (sType.find("Unknown") != 0) { Gtk::TreeModel::Row row = *(refComboModel->append()); row[comboModel.m_type_id] = i; row[comboModel.m_type_name] = sType; count++; } } Gtk::Table table(1, 2); Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START); Gtk::ComboBox comboDimType; comboDimType.set_model(refComboModel); comboDimType.pack_start(comboModel.m_type_id); comboDimType.pack_start(comboModel.m_type_name); table.attach(labelDimType, 0, 1, 0, 1); table.attach(comboDimType, 1, 2, 0, 1); dialog.get_vbox()->pack_start(table); dialog.add_button(_("_OK"), 0); dialog.add_button(_("_Cancel"), 1); dialog.show_all_children(); comboDimType.set_active(oldTypeIndex); if (!dialog.run()) { // OK selected ... ignoreColumnClicked = true; Gtk::TreeModel::iterator iterType = comboDimType.get_active(); if (!iterType) return; Gtk::TreeModel::Row rowType = *iterType; if (!rowType) return; int iTypeID = rowType[comboModel.m_type_id]; gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID); if (newType == oldType) return; //printf("change 0x%x -> 0x%x\n", oldType, newType); // assemble the list of regions where the selected dimension type // shall be changed std::vector<gig::Region*> vRegions; if (allRegions()) { gig::Instrument* instr = (gig::Instrument*)region->GetParent(); for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) { if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn); } } else vRegions.push_back(region); std::set<Glib::ustring> errors; for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) { gig::Region* region = vRegions[iRgn]; try { // notify everybody that we're going to update the region region_to_be_changed_signal.emit(region); // change the dimension type on that region region->SetDimensionType(oldType, newType); // let everybody know there was a change region_changed_signal.emit(region); } catch (RIFF::Exception e) { // notify that the changes are over (i.e. to avoid dead locks) region_changed_signal.emit(region); Glib::ustring txt = _("Could not alter dimension: ") + e.Message; if (vRegions.size() == 1) { // show error message directly Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } else { // remember error, they are shown after all regions have been processed errors.insert(txt); } } } // update all GUI elements refreshManager(); if (!errors.empty()) { Glib::ustring txt = _( "The following errors occurred while trying to change the dimension type on all regions:" ); txt += "\n\n"; for (std::set<Glib::ustring>::const_iterator it = errors.begin(); it != errors.end(); ++it) { txt += "-> " + *it + "\n"; } txt += "\n"; txt += _( "You might also want to check the console for further warnings and " "error messages." ); Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } } } }
void DimensionManager::set_region(gig::Region* region) { ignoreColumnClicked = true; this->region = region; refreshManager(); ignoreColumnClicked = false; }