void ccColorScaleEditorDialog::copyCurrentScale() { if (!m_colorScale) { assert(false); return; } ccColorScale::Shared scale = ccColorScale::Create(m_colorScale->getName()+QString("_copy")); if (!m_colorScale->isRelative()) { double minVal,maxVal; m_colorScale->getAbsoluteBoundaries(minVal,maxVal); scale->setAbsolute(minVal,maxVal); } m_scaleWidget->exportColorScale(scale); assert(m_manager); if (m_manager) m_manager->addScale(scale); updateMainComboBox(); setActiveScale(scale); }
void ccColorScaleEditorDialog::colorScaleChanged(int pos) { QString UUID = rampComboBox->itemData(pos).toString(); ccColorScale::Shared colorScale = ccColorScalesManager::GetUniqueInstance()->getScale(UUID); setActiveScale(colorScale); }
void ccColorScaleEditorDialog::importScale() { //persistent settings QSettings settings; settings.beginGroup(ccPS::LoadFile()); QString currentPath = settings.value(ccPS::CurrentPath(),QApplication::applicationDirPath()).toString(); //ask for a filename QString filename = QFileDialog::getOpenFileName(this,"Select color scale file",currentPath,"*.xml"); if (filename.isEmpty()) { //process cancelled by user return; } //save last loading parameters settings.setValue(ccPS::CurrentPath(),QFileInfo(filename).absolutePath()); settings.endGroup(); //try to load the file ccColorScale::Shared scale = ccColorScale::LoadFromXML(filename); if (scale) { assert(m_manager); if (m_manager) { ccColorScale::Shared otherScale = m_manager->getScale(scale->getUuid()); if (otherScale) { QString message = "A color scale with the same UUID"; if (otherScale->getName() == scale->getName()) message += QString(" and the same name (%1)").arg(scale->getName()); message += " is already in store!"; message += "\n"; message += "Do you want to force the importation of this new scale? (a new UUID will be generated)"; if (QMessageBox::question (this, "UUID conflict", message, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) { ccLog::Warning("[ccColorScaleEditorDialog::importScale] Importation cancelled due to a conflicting UUID (color scale may already be in store)"); return; } //generate a new UUID scale->setUuid(QUuid::createUuid().toString()); } //now we can import the scale m_manager->addScale(scale); ccLog::Print(QString("[ccColorScaleEditorDialog::importScale] Color scale '%1' successfully imported").arg(scale->getName())); } updateMainComboBox(); setActiveScale(scale); } }
void ccColorScaleEditorDialog::createNewScale() { ccColorScale::Shared scale = ccColorScale::Create("New scale"); //add default min and max steps scale->insert(ccColorScaleElement(0.0,Qt::blue),false); scale->insert(ccColorScaleElement(1.0,Qt::red),true); assert(m_manager); if (m_manager) m_manager->addScale(scale); updateMainComboBox(); setActiveScale(scale); }
ccColorScaleEditorDialog::ccColorScaleEditorDialog(ccColorScale::Shared currentScale/*=0*/, QWidget* parent/*=0*/) : QDialog(parent) , Ui::ColorScaleEditorDlg() , m_colorScale(currentScale) , m_scaleWidget(new ccColorScaleEditorWidget(this,Qt::Horizontal)) , m_associatedSF(0) , m_modified(false) , m_minAbsoluteVal(0.0) , m_maxAbsoluteVal(1.0) { setupUi(this); colorScaleEditorFrame->setLayout(new QHBoxLayout()); colorScaleEditorFrame->layout()->setContentsMargins(0,0,0,0); colorScaleEditorFrame->layout()->addWidget(m_scaleWidget); //main combo box connect(rampComboBox, SIGNAL(activated(int)), this, SLOT(colorScaleChanged(int))); //upper buttons connect(renameToolButton, SIGNAL(clicked()), this, SLOT(renameCurrentScale())); connect(saveToolButton, SIGNAL(clicked()), this, SLOT(saveCurrentScale())); connect(deleteToolButton, SIGNAL(clicked()), this, SLOT(deleteCurrentScale())); connect(copyToolButton, SIGNAL(clicked()), this, SLOT(copyCurrentScale())); connect(newToolButton, SIGNAL(clicked()), this, SLOT(createNewScale())); connect(scaleModeComboBox, SIGNAL(activated(int)), this, SLOT(relativeModeChanged(int))); //scale widget connect(m_scaleWidget, SIGNAL(stepSelected(int)), this, SLOT(onStepSelected(int))); connect(m_scaleWidget, SIGNAL(stepModified(int)), this, SLOT(onStepModified(int))); //slider editor connect(deleteSliderToolButton, SIGNAL(clicked()), this, SLOT(deletecSelectedStep())); connect(colorToolButton, SIGNAL(clicked()), this, SLOT(changeSelectedStepColor())); connect(valueDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeSelectedStepValue(double))); //close button connect(closePushButton, SIGNAL(clicked()), this, SLOT(onClose())); //populate main combox box with all known scales updateMainComboBox(); if (!m_colorScale) m_colorScale = ccColorScalesManager::GetDefaultScale(); setActiveScale(m_colorScale); }
void ccColorScaleEditorDialog::deleteCurrentScale() { if (!m_colorScale || m_colorScale->isLocked()) { assert(false); return; } //ask for confirmation if (QMessageBox::warning( this, "Delete scale", "Are you sure?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { return; } //backup current scale ccColorScale::Shared colorScaleToDelete = m_colorScale; setModified(false); //cancel any modification int currentIndex = rampComboBox->currentIndex(); if (currentIndex == 0) currentIndex = 1; else if (currentIndex > 0) --currentIndex; ccColorScalesManager* csManager = ccColorScalesManager::GetUniqueInstance(); assert(csManager); if (csManager) { //activate the neighbor scale in the list ccColorScale::Shared nextScale = csManager->getScale(rampComboBox->itemData(currentIndex).toString()); setActiveScale(nextScale); csManager->removeScale(colorScaleToDelete->getUuid()); } updateMainComboBox(); }
ccColorScaleEditorDialog::ccColorScaleEditorDialog( ccColorScalesManager* manager, ccMainAppInterface* mainApp, ccColorScale::Shared currentScale/*=0*/, QWidget* parent/*=0*/) : QDialog(parent) , Ui::ColorScaleEditorDlg() , m_manager(manager) , m_colorScale(currentScale) , m_scaleWidget(new ccColorScaleEditorWidget(this,Qt::Horizontal)) , m_associatedSF(0) , m_modified(false) , m_minAbsoluteVal(0.0) , m_maxAbsoluteVal(1.0) , m_mainApp(mainApp) { assert(m_manager); setupUi(this); colorScaleEditorFrame->setLayout(new QHBoxLayout()); colorScaleEditorFrame->layout()->setContentsMargins(0,0,0,0); colorScaleEditorFrame->layout()->addWidget(m_scaleWidget); //main combo box connect(rampComboBox, SIGNAL(activated(int)), this, SLOT(colorScaleChanged(int))); //import/export buttons connect(exportToolButton, SIGNAL(clicked()), this, SLOT(exportCurrentScale())); connect(importToolButton, SIGNAL(clicked()), this, SLOT(importScale())); //upper buttons connect(renameToolButton, SIGNAL(clicked()), this, SLOT(renameCurrentScale())); connect(saveToolButton, SIGNAL(clicked()), this, SLOT(saveCurrentScale())); connect(deleteToolButton, SIGNAL(clicked()), this, SLOT(deleteCurrentScale())); connect(copyToolButton, SIGNAL(clicked()), this, SLOT(copyCurrentScale())); connect(newToolButton, SIGNAL(clicked()), this, SLOT(createNewScale())); connect(scaleModeComboBox, SIGNAL(activated(int)), this, SLOT(relativeModeChanged(int))); //scale widget connect(m_scaleWidget, SIGNAL(stepSelected(int)), this, SLOT(onStepSelected(int))); connect(m_scaleWidget, SIGNAL(stepModified(int)), this, SLOT(onStepModified(int))); //slider editor connect(deleteSliderToolButton, SIGNAL(clicked()), this, SLOT(deletecSelectedStep())); connect(colorToolButton, SIGNAL(clicked()), this, SLOT(changeSelectedStepColor())); connect(valueDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeSelectedStepValue(double))); //labels list widget connect(customLabelsGroupBox, SIGNAL(toggled(bool)), this, SLOT(toggleCustomLabelsList(bool))); connect(customLabelsPlainTextEdit, SIGNAL(textChanged()), this, SLOT(onCustomLabelsListChanged())); //apply button connect(applyPushButton, SIGNAL(clicked()), this, SLOT(onApply())); //close button connect(closePushButton, SIGNAL(clicked()), this, SLOT(onClose())); //populate main combox box with all known scales updateMainComboBox(); if (!m_colorScale) m_colorScale = m_manager->getDefaultScale(ccColorScalesManager::BGYR); setActiveScale(m_colorScale); }