From 4de8a959fdb164e4235b6400f54a2f7e46ca9cba Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Mon, 8 Oct 2018 20:53:12 +0200 Subject: [PATCH 01/12] ColorBox replaced by ColorButton. Add alpha channel to all colors. Coordinate changes in color alpha and opacity. --- libscidavis/src/ApplicationWindow.cpp | 4 +- libscidavis/src/AxesDialog.cpp | 13 +-- libscidavis/src/AxesDialog.h | 7 +- libscidavis/src/ColorButton.cpp | 46 +++++++- libscidavis/src/ColorButton.h | 16 +++ libscidavis/src/ConfigDialog.cpp | 7 +- libscidavis/src/ConfigDialog.h | 3 +- libscidavis/src/Convolution.cpp | 4 +- libscidavis/src/Correlation.cpp | 4 +- libscidavis/src/ExpDecayDialog.cpp | 10 +- libscidavis/src/ExpDecayDialog.h | 4 +- libscidavis/src/FFT.cpp | 4 +- libscidavis/src/Filter.cpp | 8 +- libscidavis/src/Filter.h | 4 +- libscidavis/src/FilterDialog.cpp | 12 +- libscidavis/src/FilterDialog.h | 4 +- libscidavis/src/Fit.cpp | 4 +- libscidavis/src/FitDialog.cpp | 11 +- libscidavis/src/FitDialog.h | 4 +- libscidavis/src/Graph.cpp | 26 ++--- libscidavis/src/Grid.cpp | 6 +- libscidavis/src/InterpolationDialog.cpp | 10 +- libscidavis/src/InterpolationDialog.h | 4 +- libscidavis/src/LineDialog.cpp | 11 -- libscidavis/src/LineDialog.h | 1 - libscidavis/src/MultiPeakFit.cpp | 10 +- libscidavis/src/PlotDialog.cpp | 148 +++++++----------------- libscidavis/src/PlotDialog.h | 24 ++-- libscidavis/src/PolynomFitDialog.cpp | 10 +- libscidavis/src/PolynomFitDialog.h | 4 +- libscidavis/src/QwtPieCurve.cpp | 6 +- libscidavis/src/SmoothCurveDialog.cpp | 12 +- libscidavis/src/SmoothCurveDialog.h | 4 +- libscidavis/src/TextDialog.cpp | 39 +++---- libscidavis/src/TextDialog.h | 5 +- libscidavis/src/importOPJ.cpp | 16 +-- 36 files changed, 235 insertions(+), 270 deletions(-) diff --git a/libscidavis/src/ApplicationWindow.cpp b/libscidavis/src/ApplicationWindow.cpp index 9d9dd1e93..12a2d4961 100644 --- a/libscidavis/src/ApplicationWindow.cpp +++ b/libscidavis/src/ApplicationWindow.cpp @@ -95,7 +95,7 @@ #include "Convolution.h" #include "Correlation.h" #include "CurveRangeDialog.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "QwtHistogram.h" #include "OpenProjectDialog.h" #include "IconLoader.h" @@ -9676,7 +9676,7 @@ Graph* ApplicationWindow::openGraph(ApplicationWindow* app, MultiLayer *plot, if (d_file_version <= 77) { int temp_index = convertOldToNewColorIndex(curve[15].toInt()); - ag->updateVectorsLayout(curveID, ColorBox::color(temp_index), curve[16].toInt(), curve[17].toInt(), + ag->updateVectorsLayout(curveID, ColorButton::color(temp_index), curve[16].toInt(), curve[17].toInt(), curve[18].toInt(), curve[19].toInt(), 0, curve[20], curve[21]); } else diff --git a/libscidavis/src/AxesDialog.cpp b/libscidavis/src/AxesDialog.cpp index 21ca66922..991c26aa3 100644 --- a/libscidavis/src/AxesDialog.cpp +++ b/libscidavis/src/AxesDialog.cpp @@ -29,7 +29,6 @@ #include "ApplicationWindow.h" #include "AxesDialog.h" #include "TextDialog.h" -#include "ColorBox.h" #include "Graph.h" #include "Grid.h" #include "Plot.h" @@ -233,10 +232,10 @@ void AxesDialog::initGridPage() rightLayout->addWidget( new QLabel(tr( "Line Color" )), 1, 0 ); - boxColorMajor = new ColorBox(0); + boxColorMajor = new ColorButton(); rightLayout->addWidget( boxColorMajor, 1, 1); - boxColorMinor = new ColorBox(0); + boxColorMinor = new ColorButton(); boxColorMinor->setDisabled(true); rightLayout->addWidget( boxColorMinor, 1, 2); @@ -1050,17 +1049,17 @@ void AxesDialog::updateGrid() grid->enableX(boxMajorGrid->isChecked()); grid->enableXMin(boxMinorGrid->isChecked()); - grid->setMajPenX(QPen(ColorBox::color(boxColorMajor->currentIndex()), boxWidthMajor->value(), + grid->setMajPenX(QPen(boxColorMajor->color(), boxWidthMajor->value(), Graph::getPenStyle(boxTypeMajor->currentIndex()))); - grid->setMinPenX(QPen(ColorBox::color(boxColorMinor->currentIndex()), boxWidthMinor->value(), + grid->setMinPenX(QPen(boxColorMinor->color(), boxWidthMinor->value(), Graph::getPenStyle(boxTypeMinor->currentIndex()))); } else { grid->enableY(boxMajorGrid->isChecked()); grid->enableYMin(boxMinorGrid->isChecked()); - grid->setMajPenY(QPen(ColorBox::color(boxColorMajor->currentIndex()), boxWidthMajor->value(), + grid->setMajPenY(QPen(boxColorMajor->color(), boxWidthMajor->value(), Graph::getPenStyle(boxTypeMajor->currentIndex()))); - grid->setMinPenY(QPen(ColorBox::color(boxColorMinor->currentIndex()), boxWidthMinor->value(), + grid->setMinPenY(QPen(boxColorMinor->color(), boxWidthMinor->value(), Graph::getPenStyle(boxTypeMinor->currentIndex()))); } diff --git a/libscidavis/src/AxesDialog.h b/libscidavis/src/AxesDialog.h index 3886cd096..7926f149d 100644 --- a/libscidavis/src/AxesDialog.h +++ b/libscidavis/src/AxesDialog.h @@ -48,7 +48,6 @@ class QSpinBox; class QTabWidget; class QWidget; class QStringList; -class ColorBox; class ColorButton; class Graph; class TextFormatButtons; @@ -103,9 +102,9 @@ class AxesDialog : public QDialog QCheckBox* boxMajorGrid; QCheckBox* boxMinorGrid; QComboBox* boxTypeMajor; - ColorBox* boxColorMinor; - ColorBox* boxColorMajor; - ColorButton *boxCanvasColor; + ColorButton* boxColorMinor; + ColorButton* boxColorMajor; + ColorButton* boxCanvasColor; QSpinBox* boxWidthMajor; QComboBox* boxTypeMinor; QSpinBox* boxWidthMinor; diff --git a/libscidavis/src/ColorButton.cpp b/libscidavis/src/ColorButton.cpp index e41df3526..32b974a3f 100644 --- a/libscidavis/src/ColorButton.cpp +++ b/libscidavis/src/ColorButton.cpp @@ -28,6 +28,7 @@ ***************************************************************************/ #include "ColorButton.h" +#include #include #include #include @@ -61,7 +62,7 @@ void ColorButton::init() setMaximumWidth(3*btn_size); setMaximumHeight(btn_size); - connect(selectButton, SIGNAL(clicked()), this, SIGNAL(clicked())); + connect(selectButton, SIGNAL(clicked()), this, SLOT(pickColor())); } void ColorButton::setColor(const QColor& c) @@ -69,6 +70,7 @@ void ColorButton::setColor(const QColor& c) QPalette pal; pal.setColor(QPalette::Window, c); display->setPalette(pal); + emit changed(c); } QColor ColorButton::color() const @@ -76,7 +78,49 @@ QColor ColorButton::color() const return display->palette().color(QPalette::Window); } +unsigned int ColorButton::colorIndex(const QColor& c) +{ + const QColor *ite = std::find(std::begin(colors), std::end(colors), c); + if (ite->isValid()) + return (ite - colors); + else + return c.rgba(); +} + +QColor ColorButton::color(unsigned int colorIndex) +{ + if (colorIndex < colors_count) + return colors[colorIndex]; + else + { + QColor qc = QColor::fromRgba(colorIndex); + if (qc.isValid()) + return qc; + else + return QColor(Qt::black); // default color is black. + } +} + +bool ColorButton::isValidColor(const QColor& c) +{ + const QColor *ite = std::find(std::begin(colors), std::end(colors), c); + return (ite->isValid()); +} + +int ColorButton::numPredefinedColors() +{ + return colors_count; +} + QSize ColorButton::sizeHint () const { return QSize(4*btn_size, btn_size); } + +void ColorButton::pickColor() +{ + QColor c = QColorDialog::getColor(color(), this, "Select color", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel); + if ( !c.isValid() || c == color() ) + return; + setColor ( c ) ; +} diff --git a/libscidavis/src/ColorButton.h b/libscidavis/src/ColorButton.h index 0a2c375bd..3a67b7327 100644 --- a/libscidavis/src/ColorButton.h +++ b/libscidavis/src/ColorButton.h @@ -52,6 +52,14 @@ class ColorButton : public QWidget void setColor(const QColor& c); //! Get the color of the display part QColor color() const; + //! Return the index for a given color + static unsigned int colorIndex(const QColor& c); + //! Return the color at index 'colorindex' + static QColor color(unsigned int colorIndex); + //! Returns TRUE if the color is included in the color box, otherwise returns FALSE. + static bool isValidColor(const QColor& color); + //! Returns the number of predefined colors + static int numPredefinedColors(); QSize sizeHint() const; private: @@ -61,10 +69,18 @@ class ColorButton : public QWidget signals: //! Signal clicked: This is emitted when the selection button is clicked void clicked(); + void changed(const QColor &); protected: //! Initialize the widget (called from constructor) void init(); + //! The number of predefined colors + static const int colors_count; + //! Array containing the 24 predefined colors + static const QColor colors[]; + +private slots: + void pickColor(); private: int btn_size; diff --git a/libscidavis/src/ConfigDialog.cpp b/libscidavis/src/ConfigDialog.cpp index ecc928fe0..3cde56dc6 100644 --- a/libscidavis/src/ConfigDialog.cpp +++ b/libscidavis/src/ConfigDialog.cpp @@ -32,7 +32,6 @@ #include "Graph.h" #include "Matrix.h" #include "ColorButton.h" -#include "ColorBox.h" #include #include @@ -697,8 +696,8 @@ void ConfigDialog::initFittingPage() lblPeaksColor = new QLabel(); multiPeakLayout->addWidget(lblPeaksColor); - boxPeaksColor = new ColorBox(0); - boxPeaksColor->setCurrentIndex(app->peakCurvesColor); + boxPeaksColor = new ColorButton(); + boxPeaksColor->setColor(app->peakCurvesColor); multiPeakLayout->addWidget(boxPeaksColor); groupBoxFitParameters = new QGroupBox(); @@ -1184,7 +1183,7 @@ void ConfigDialog::apply() app->fitPoints = generatePointsBox->value(); app->generateUniformFitPoints = generatePointsBtn->isChecked(); app->generatePeakCurves = groupBoxMultiPeak->isChecked(); - app->peakCurvesColor = boxPeaksColor->currentIndex(); + app->peakCurvesColor = boxPeaksColor->colorIndex(boxPeaksColor->color()); app->fit_scale_errors = scaleErrorsBox->isChecked(); app->d_2_linear_fit_points = linearFit2PointsBox->isChecked(); app->saveSettings(); diff --git a/libscidavis/src/ConfigDialog.h b/libscidavis/src/ConfigDialog.h index 24f67b23e..8a3d49469 100644 --- a/libscidavis/src/ConfigDialog.h +++ b/libscidavis/src/ConfigDialog.h @@ -43,7 +43,6 @@ class QLabel; class QRadioButton; class QListWidget; class ColorButton; -class ColorBox; #ifndef TS_PATH #define TS_PATH (qApp->applicationDirPath() + "/translations") @@ -171,7 +170,7 @@ private slots: QGroupBox *groupBoxFittingCurve, *groupBoxFitParameters; QRadioButton *samePointsBtn, *generatePointsBtn; QGroupBox *groupBoxMultiPeak; - ColorBox *boxPeaksColor; + ColorButton *boxPeaksColor; QLabel *lblScriptingLanguage; QComboBox *boxScriptingLanguage; QCheckBox *boxAntialiasing, *boxAutoscale3DPlots, *boxTableComments; diff --git a/libscidavis/src/Convolution.cpp b/libscidavis/src/Convolution.cpp index a1c46a179..fc3f5dca3 100644 --- a/libscidavis/src/Convolution.cpp +++ b/libscidavis/src/Convolution.cpp @@ -30,7 +30,7 @@ #include "MultiLayer.h" #include "Plot.h" #include "PlotCurve.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "core/column/Column.h" #include @@ -162,7 +162,7 @@ void Convolution::addResultCurve() DataCurve *c = new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(x_temp, d_x, d_n); - c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); ml->activeGraph()->insertPlotItem(c, Graph::Line); ml->activeGraph()->updatePlot(); } diff --git a/libscidavis/src/Correlation.cpp b/libscidavis/src/Correlation.cpp index dc024e57f..ea5403670 100644 --- a/libscidavis/src/Correlation.cpp +++ b/libscidavis/src/Correlation.cpp @@ -30,7 +30,7 @@ #include "MultiLayer.h" #include "Plot.h" #include "PlotCurve.h" -#include "ColorBox.h" +#include "ColorButton.h" #include #include #include "core/column/Column.h" @@ -175,7 +175,7 @@ void Correlation::addResultCurve() DataCurve *c = new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(&x_temp[0], &y_temp[0], rows); - c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); ml->activeGraph()->insertPlotItem(c, Graph::Line); ml->activeGraph()->updatePlot(); } diff --git a/libscidavis/src/ExpDecayDialog.cpp b/libscidavis/src/ExpDecayDialog.cpp index 715e33056..230675eb3 100644 --- a/libscidavis/src/ExpDecayDialog.cpp +++ b/libscidavis/src/ExpDecayDialog.cpp @@ -28,7 +28,7 @@ ***************************************************************************/ #include "ExpDecayDialog.h" #include "Graph.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "ApplicationWindow.h" #include "Fit.h" #include "ExponentialFit.h" @@ -111,9 +111,9 @@ gl1->addWidget(boxStart, 5, 1); gl1->addWidget(new QLabel(tr("Color")), 6, 0 ); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); - gl1->addWidget(boxColor, 6, 1); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); + gl1->addWidget(btnColor, 6, 1); gb1->setLayout(gl1); @@ -232,7 +232,7 @@ void ExpDecayDialog::fit() if (fitter->setDataFromCurve(boxName->currentText(), boxStart->text().toDouble(), c->maxXValue())) { - fitter->setColor(boxColor->currentIndex()); + fitter->setColor(ColorButton::colorIndex(btnColor->color())); fitter->scaleErrors(app->fit_scale_errors); fitter->setOutputPrecision(app->fit_output_precision); fitter->generateFunction(app->generateUniformFitPoints, app->fitPoints); diff --git a/libscidavis/src/ExpDecayDialog.h b/libscidavis/src/ExpDecayDialog.h index 7ea199609..326b86a74 100644 --- a/libscidavis/src/ExpDecayDialog.h +++ b/libscidavis/src/ExpDecayDialog.h @@ -36,7 +36,7 @@ class QLineEdit; class QComboBox; class QLabel; class Graph; -class ColorBox; +class ColorButton; class Fit; //! Fit exponential decay dialog @@ -78,7 +78,7 @@ private slots: QLineEdit* boxStart; QLineEdit* boxYOffset; QLabel* thirdLabel, *dampingLabel; - ColorBox* boxColor; + ColorButton* btnColor; }; #endif diff --git a/libscidavis/src/FFT.cpp b/libscidavis/src/FFT.cpp index 743bd516b..7c06b1e17 100644 --- a/libscidavis/src/FFT.cpp +++ b/libscidavis/src/FFT.cpp @@ -29,7 +29,7 @@ #include "FFT.h" #include "MultiLayer.h" #include "Plot.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "core/column/Column.h" #include @@ -175,7 +175,7 @@ void FFT::output(QList columns) Graph* g = ml->activeGraph(); if ( g ) { - g->setCurvePen(0, QPen(ColorBox::color(d_curveColorIndex), 1)); + g->setCurvePen(0, QPen(ColorButton::color(d_curveColorIndex), 1)); Plot* plot = g->plotWidget(); plot->setTitle(QString()); diff --git a/libscidavis/src/Filter.cpp b/libscidavis/src/Filter.cpp index d4bec4dc0..06d02113c 100644 --- a/libscidavis/src/Filter.cpp +++ b/libscidavis/src/Filter.cpp @@ -28,7 +28,7 @@ ***************************************************************************/ #include "Filter.h" #include "Legend.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "Table.h" #include "FunctionCurve.h" #include "PlotCurve.h" @@ -182,7 +182,7 @@ void Filter::setColor(const QString& colorName) c = QColor(Qt::green); else if (colorName == "darkYellow") c = QColor(Qt::darkYellow); - if (!ColorBox::isValidColor(c)) + if (!ColorButton::isValidColor(c)) { QMessageBox::critical((ApplicationWindow *)parent(), tr("Color Name Error"), tr("The color name '%1' is not valid, a default color (red) will be used instead!").arg(colorName)); @@ -190,7 +190,7 @@ void Filter::setColor(const QString& colorName) return; } - d_curveColorIndex = ColorBox::colorIndex(c); + d_curveColorIndex = ColorButton::colorIndex(c); } void Filter::showLegend() @@ -317,7 +317,7 @@ QwtPlotCurve* Filter::addResultCurve(double *x, double *y) DataCurve *c = new DataCurve(t, tableName + "_" + xCol->name(), tableName + "_" + yCol->name()); c->setData(x, y, d_points); - c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); d_graph->insertPlotItem(c, Graph::Line); d_graph->updatePlot(); diff --git a/libscidavis/src/Filter.h b/libscidavis/src/Filter.h index 0ec47e483..6a058d7b2 100644 --- a/libscidavis/src/Filter.h +++ b/libscidavis/src/Filter.h @@ -61,7 +61,7 @@ class Filter : public QObject void setTolerance(double eps){d_tolerance = eps;}; //! Sets the color of the output fit curve. - void setColor(int colorId){d_curveColorIndex = colorId;}; + void setColor(unsigned int colorId){d_curveColorIndex = colorId;}; //! Sets the color of the output fit curve. Provided for convenience. To be used in scripts only! void setColor(const QString& colorName); @@ -139,7 +139,7 @@ class Filter : public QObject int d_points; //! Color index of the result curve - int d_curveColorIndex; + unsigned int d_curveColorIndex; //! Maximum number of iterations per fit int d_max_iterations; diff --git a/libscidavis/src/FilterDialog.cpp b/libscidavis/src/FilterDialog.cpp index 4075e9ee0..445a2f907 100644 --- a/libscidavis/src/FilterDialog.cpp +++ b/libscidavis/src/FilterDialog.cpp @@ -29,7 +29,7 @@ #include "FilterDialog.h" #include "Graph.h" #include "MyParser.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "FFTFilter.h" #include @@ -63,8 +63,8 @@ FilterDialog::FilterDialog(int type, QWidget* parent, Qt::WindowFlags fl ) boxStart->setText(tr("0")); gl1->addWidget(boxStart, 1, 1); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); if (type >= FFTFilter::BandPass) { gl1->addWidget(new QLabel(tr("High Frequency (Hz)")), 2, 0); @@ -82,13 +82,13 @@ FilterDialog::FilterDialog(int type, QWidget* parent, Qt::WindowFlags fl ) gl1->addWidget(boxOffset, 3, 1); gl1->addWidget(new QLabel(tr("Color")), 4, 0); - gl1->addWidget(boxColor, 4, 1); + gl1->addWidget(btnColor, 4, 1); gl1->setRowStretch(5, 1); } else { gl1->addWidget(new QLabel(tr("Color")), 2, 0); - gl1->addWidget(boxColor, 2, 1); + gl1->addWidget(btnColor, 2, 1); gl1->setRowStretch(3, 1); } @@ -179,7 +179,7 @@ else if (filter_type == FFTFilter::BandBlock) else f->setCutoff(from); -f->setColor(boxColor->currentIndex()); +f->setColor(ColorButton::colorIndex(btnColor->color())); f->run(); delete f; } diff --git a/libscidavis/src/FilterDialog.h b/libscidavis/src/FilterDialog.h index e09ce5e53..3285a199b 100644 --- a/libscidavis/src/FilterDialog.h +++ b/libscidavis/src/FilterDialog.h @@ -36,7 +36,7 @@ class QLineEdit; class QComboBox; class QCheckBox; class Graph; -class ColorBox; +class ColorButton; //! Filter options dialog class FilterDialog : public QDialog @@ -53,7 +53,7 @@ class FilterDialog : public QDialog QCheckBox* boxOffset; QLineEdit* boxStart; QLineEdit* boxEnd; - ColorBox* boxColor; + ColorButton* btnColor; public slots: void setGraph(Graph *g); diff --git a/libscidavis/src/Fit.cpp b/libscidavis/src/Fit.cpp index 4edf30959..80605fc5f 100644 --- a/libscidavis/src/Fit.cpp +++ b/libscidavis/src/Fit.cpp @@ -33,7 +33,7 @@ #include "QwtErrorPlotCurve.h" #include "Legend.h" #include "FunctionCurve.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "Script.h" #include "core/column/Column.h" @@ -626,7 +626,7 @@ void Fit::insertFitFunctionCurve(const QString& name, double *x, double *y, int { QString title = d_graph->generateFunctionName(name); FunctionCurve *c = new FunctionCurve((ApplicationWindow *)parent(), FunctionCurve::Normal, title); - c->setPen(QPen(ColorBox::color(d_curveColorIndex), penWidth)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), penWidth)); c->setData(x, y, d_points); c->setRange(d_x[0], d_x[d_n-1]); diff --git a/libscidavis/src/FitDialog.cpp b/libscidavis/src/FitDialog.cpp index afb59fe44..d5d0cad01 100644 --- a/libscidavis/src/FitDialog.cpp +++ b/libscidavis/src/FitDialog.cpp @@ -29,7 +29,7 @@ #include "FitDialog.h" #include "MyParser.h" #include "ApplicationWindow.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "Fit.h" #include "MultiPeakFit.h" #include "ExponentialFit.h" @@ -140,9 +140,9 @@ void FitDialog::initFitPage() gl1->addWidget(boxAlgorithm, 4, 1); gl1->addWidget(new QLabel( tr("Color")), 5, 0); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); - gl1->addWidget(boxColor, 5, 1); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); + gl1->addWidget(btnColor, 5, 1); QGroupBox *gb1 = new QGroupBox(); gb1->setLayout(gl1); @@ -1211,7 +1211,7 @@ void FitDialog::accept() d_fitter->setTolerance (eps); d_fitter->setAlgorithm((Fit::Algorithm)boxAlgorithm->currentIndex()); - d_fitter->setColor(boxColor->currentIndex()); + d_fitter->setColor(ColorButton::colorIndex(btnColor->color())); d_fitter->generateFunction(generatePointsBtn->isChecked(), generatePointsBox->value()); d_fitter->setMaximumIterations(boxPoints->value()); d_fitter->scaleErrors(scaleErrorsBox->isChecked()); @@ -1397,4 +1397,3 @@ void FitDialog::resetFunction() boxParam->clear(); editBox->clear(); } - diff --git a/libscidavis/src/FitDialog.h b/libscidavis/src/FitDialog.h index c1841cbc8..926e99fda 100644 --- a/libscidavis/src/FitDialog.h +++ b/libscidavis/src/FitDialog.h @@ -44,7 +44,7 @@ class QSpinBox; class QLabel; class QRadioButton; class QLineEdit; -class ColorBox; +class ColorButton; class Fit; //! Fit Wizard @@ -179,7 +179,7 @@ private slots: QLabel *lblFunction, *lblPoints, *polynomOrderLabel; QPushButton *btnAddFunc, *btnDelFunc, *btnContinue, *btnApply; QPushButton *buttonEdit, *btnAddTxt, *btnAddName, *btnDeleteFitCurves; - ColorBox* boxColor; + ColorButton* btnColor; QComboBox *boxYErrorSource, *tableNamesBox, *colNamesBox; QRadioButton *generatePointsBtn, *samePointsBtn; QPushButton *btnParamTable, *btnCovMatrix; diff --git a/libscidavis/src/Graph.cpp b/libscidavis/src/Graph.cpp index 37e7aa620..f6c43f1ac 100644 --- a/libscidavis/src/Graph.cpp +++ b/libscidavis/src/Graph.cpp @@ -44,7 +44,7 @@ #include "QwtHistogram.h" #include "VectorCurve.h" #include "ScaleDraw.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "PatternBox.h" #include "SymbolBox.h" #include "FunctionCurve.h" @@ -2339,23 +2339,23 @@ QString Graph::saveCurveLayout(int index) s+="6\t"; else s+=QString::number(c->style())+"\t"; - s+=QString::number(ColorBox::colorIndex(c->pen().color()))+"\t"; + s+=QString::number(ColorButton::colorIndex(c->pen().color()))+"\t"; s+=QString::number(c->pen().style()-1)+"\t"; s+=QString::number(c->pen().width())+"\t"; const QwtSymbol symbol = c->symbol(); s+=QString::number(symbol.size().width())+"\t"; s+=QString::number(SymbolBox::symbolIndex(symbol.style()))+"\t"; - s+=QString::number(ColorBox::colorIndex(symbol.pen().color()))+"\t"; + s+=QString::number(ColorButton::colorIndex(symbol.pen().color()))+"\t"; if (symbol.brush().style() != Qt::NoBrush) - s+=QString::number(ColorBox::colorIndex(symbol.brush().color()))+"\t"; + s+=QString::number(ColorButton::colorIndex(symbol.brush().color()))+"\t"; else s+=QString::number(-1)+"\t"; bool filled = c->brush().style() == Qt::NoBrush ? false : true; s+=QString::number(filled)+"\t"; - s+=QString::number(ColorBox::colorIndex(c->brush().color()))+"\t"; + s+=QString::number(ColorButton::colorIndex(c->brush().color()))+"\t"; s+=QString::number(PatternBox::patternIndex(c->brush().style()))+"\t"; if (style <= LineSymbols || style == Box) s+=QString::number(symbol.pen().width())+"\t"; @@ -2994,13 +2994,13 @@ void Graph::updateCurveLayout(int index, const CurveLayout *cL) if (c_type.isEmpty() || (int)c_type.size() < index) return; - QPen pen = QPen(ColorBox::color(cL->symCol),cL->penWidth, Qt::SolidLine); + QPen pen = QPen(ColorButton::color(cL->symCol),cL->penWidth, Qt::SolidLine); if (cL->symbolFill) - c->setSymbol(QwtSymbol(SymbolBox::style(cL->sType), QBrush(ColorBox::color(cL->fillCol)), pen, QSize(cL->sSize,cL->sSize))); + c->setSymbol(QwtSymbol(SymbolBox::style(cL->sType), QBrush(ColorButton::color(cL->fillCol)), pen, QSize(cL->sSize,cL->sSize))); else c->setSymbol(QwtSymbol(SymbolBox::style(cL->sType), QBrush(), pen, QSize(cL->sSize,cL->sSize))); - c->setPen(QPen(ColorBox::color(cL->lCol), cL->lWidth, getPenStyle(cL->lStyle))); + c->setPen(QPen(ColorButton::color(cL->lCol), cL->lWidth, getPenStyle(cL->lStyle))); int style = c_type[index]; if (style == Scatter) @@ -3018,7 +3018,7 @@ void Graph::updateCurveLayout(int index, const CurveLayout *cL) else c->setStyle((QwtPlotCurve::CurveStyle)cL->connectType); - QBrush brush = QBrush(ColorBox::color(cL->aCol)); + QBrush brush = QBrush(ColorButton::color(cL->aCol)); if (cL->filledArea) brush.setStyle(getBrushStyle(cL->aStyle)); else @@ -4781,8 +4781,8 @@ void Graph::plotBoxDiagram(Table *w, const QStringList& names, int startRow, int c_type.resize(n_curves); c_type[n_curves-1] = Box; - c->setPen(QPen(ColorBox::color(j), 1)); - c->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, QBrush(), QPen(ColorBox::color(j), 1), QSize(7,7))); + c->setPen(QPen(ColorButton::color(j), 1)); + c->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, QBrush(), QPen(ColorButton::color(j), 1), QSize(7,7))); } Legend* mrk=(Legend*) d_plot->marker(legendMarkerID); @@ -4964,7 +4964,7 @@ void Graph::guessUniqueCurveLayout(int& colorIndex, int& symbolIndex) DataCurve *master_curve = er->masterCurve(); if (master_curve) { - colorIndex = ColorBox::colorIndex(master_curve->pen().color()); + colorIndex = ColorButton::colorIndex(master_curve->pen().color()); return; } } @@ -4974,7 +4974,7 @@ void Graph::guessUniqueCurveLayout(int& colorIndex, int& symbolIndex) const QwtPlotCurve *c = curve(i); if (c && c->rtti() == QwtPlotItem::Rtti_PlotCurve) { - int index = ColorBox::colorIndex(c->pen().color()); + int index = ColorButton::colorIndex(c->pen().color()); if (index > colorIndex) colorIndex = index; diff --git a/libscidavis/src/Grid.cpp b/libscidavis/src/Grid.cpp index 1d8197172..b31ac667f 100644 --- a/libscidavis/src/Grid.cpp +++ b/libscidavis/src/Grid.cpp @@ -29,7 +29,7 @@ #include "Plot.h" #include "Graph.h" #include "Grid.h" -#include "ColorBox.h" +#include "ColorButton.h" #include #include @@ -144,8 +144,8 @@ void Grid::load(const QStringList& grid) xAxis = grid[19].toInt(); yAxis = grid[20].toInt(); } else { // older versions of QtiPlot (<= 0.9rc3) - majPenX = QPen(ColorBox::color(grid[5].toInt()), grid[7].toInt(), Graph::getPenStyle(grid[6].toInt())); - minPenX = QPen(ColorBox::color(grid[8].toInt()), grid[10].toInt(), Graph::getPenStyle(grid[9].toInt())); + majPenX = QPen(ColorButton::color(grid[5].toInt()), grid[7].toInt(), Graph::getPenStyle(grid[6].toInt())); + minPenX = QPen(ColorButton::color(grid[8].toInt()), grid[10].toInt(), Graph::getPenStyle(grid[9].toInt())); majPenY = majPenX; minPenY = minPenX; diff --git a/libscidavis/src/InterpolationDialog.cpp b/libscidavis/src/InterpolationDialog.cpp index 06f449479..25e7bd8f2 100644 --- a/libscidavis/src/InterpolationDialog.cpp +++ b/libscidavis/src/InterpolationDialog.cpp @@ -29,7 +29,7 @@ #include "InterpolationDialog.h" #include "Graph.h" #include "MyParser.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "Interpolation.h" #include @@ -78,9 +78,9 @@ InterpolationDialog::InterpolationDialog( QWidget* parent, Qt::WindowFlags fl ) gl1->addWidget(new QLabel(tr("Color")), 5, 0); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); - gl1->addWidget(boxColor, 5, 1); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); + gl1->addWidget(btnColor, 5, 1); gl1->setRowStretch(6, 1); buttonFit = new QPushButton(tr( "&Make" )); @@ -151,7 +151,7 @@ if (from >= to) Interpolation *i = new Interpolation((ApplicationWindow *)this->parent(), graph, curve, from, to, boxMethod->currentIndex()); i->setOutputPoints(boxPoints->value()); -i->setColor(boxColor->currentIndex()); +i->setColor(ColorButton::colorIndex(btnColor->color())); i->run(); delete i; } diff --git a/libscidavis/src/InterpolationDialog.h b/libscidavis/src/InterpolationDialog.h index 378f2b36c..511080eee 100644 --- a/libscidavis/src/InterpolationDialog.h +++ b/libscidavis/src/InterpolationDialog.h @@ -36,7 +36,7 @@ class QLineEdit; class QComboBox; class QSpinBox; class Graph; -class ColorBox; +class ColorButton; //! Interpolation options dialog class InterpolationDialog : public QDialog @@ -54,7 +54,7 @@ class InterpolationDialog : public QDialog QSpinBox* boxPoints; QLineEdit* boxStart; QLineEdit* boxEnd; - ColorBox* boxColor; + ColorButton* btnColor; public slots: void activateCurve(const QString& curveName); diff --git a/libscidavis/src/LineDialog.cpp b/libscidavis/src/LineDialog.cpp index ec4ef3635..992b97c87 100644 --- a/libscidavis/src/LineDialog.cpp +++ b/libscidavis/src/LineDialog.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include LineDialog::LineDialog( ArrowMarker *line, QWidget* parent, Qt::WindowFlags fl ) @@ -155,7 +154,6 @@ LineDialog::LineDialog( ArrowMarker *line, QWidget* parent, Qt::WindowFlags fl ) enableHeadTab(); - connect( colorBox, SIGNAL( clicked() ), this, SLOT(pickColor() ) ); connect( btnOk, SIGNAL( clicked() ), this, SLOT(accept() ) ); connect( btnApply, SIGNAL( clicked() ), this, SLOT(apply() ) ); connect( tw, SIGNAL(currentChanged (int)), this, SLOT(enableButtonDefault(int))); @@ -311,15 +309,6 @@ else tw->setTabEnabled (tw->indexOf(head), false); } -void LineDialog::pickColor() -{ -QColor c = QColorDialog::getColor(colorBox->color(), this); -if ( !c.isValid() || c == colorBox->color() ) - return; - -colorBox->setColor ( c ) ; -} - void LineDialog::setDefaultValues() { ApplicationWindow *app = (ApplicationWindow *)this->parent(); diff --git a/libscidavis/src/LineDialog.h b/libscidavis/src/LineDialog.h index 5c1822052..5f2ab6f68 100644 --- a/libscidavis/src/LineDialog.h +++ b/libscidavis/src/LineDialog.h @@ -60,7 +60,6 @@ public slots: void setDefaultValues(); void displayCoordinates(int unit); void setLineStyle(Qt::PenStyle style); - void pickColor(); void accept(); void apply(); diff --git a/libscidavis/src/MultiPeakFit.cpp b/libscidavis/src/MultiPeakFit.cpp index 42c40237f..64abe3031 100644 --- a/libscidavis/src/MultiPeakFit.cpp +++ b/libscidavis/src/MultiPeakFit.cpp @@ -30,7 +30,7 @@ #include "fit_gsl.h" #include "PlotCurve.h" #include "FunctionCurve.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "core/column/Column.h" #include @@ -213,7 +213,7 @@ void MultiPeakFit::insertPeakFunctionCurve(double *x, double *y, int peak) QString title = tr("Peak") + QString::number(++index); FunctionCurve *c = new FunctionCurve((ApplicationWindow *)parent(), FunctionCurve::Normal, title); - c->setPen(QPen(ColorBox::color(d_peaks_color), 1)); + c->setPen(QPen(ColorButton::color(d_peaks_color), 1)); c->setData(x, y, d_points); c->setRange(d_x[0], d_x[d_n-1]); @@ -334,9 +334,9 @@ void MultiPeakFit::generateFitCurve(const vector& par) label = tableName + "_2"; DataCurve *c = new DataCurve(t, tableName + "_" + columns.at(0)->name(), label); if (d_peaks > 1) - c->setPen(QPen(ColorBox::color(d_curveColorIndex), 2)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), 2)); else - c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); + c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); c->setData(X, Y, d_points); d_graph->insertPlotItem(c, Graph::Line); d_graph->addFitCurve(c); @@ -350,7 +350,7 @@ void MultiPeakFit::generateFitCurve(const vector& par) label = tableName + "_" + tr("peak") + QString::number(i+1); c = new DataCurve(t, tableName + "_" + columns.at(0)->name(), label); - c->setPen(QPen(ColorBox::color(d_peaks_color), 1)); + c->setPen(QPen(ColorButton::color(d_peaks_color), 1)); c->setData(X, Y, d_points); d_graph->insertPlotItem(c, Graph::Line); d_graph->addFitCurve(c); diff --git a/libscidavis/src/PlotDialog.cpp b/libscidavis/src/PlotDialog.cpp index 7cded3fe3..c3f48cd99 100644 --- a/libscidavis/src/PlotDialog.cpp +++ b/libscidavis/src/PlotDialog.cpp @@ -28,7 +28,6 @@ ***************************************************************************/ #include "ApplicationWindow.h" #include "PlotDialog.h" -#include "ColorBox.h" #include "ColorButton.h" #include "PatternBox.h" #include "SymbolBox.h" @@ -59,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -364,9 +362,9 @@ void PlotDialog::initLayerPage() connect(boxCanvasTransparency, SIGNAL(valueChanged(int)), this, SLOT(updateCanvasTransparency(int))); connect(boxAntialiasing, SIGNAL(toggled(bool)), this, SLOT(updateAntialiasing(bool))); connect(boxMargin, SIGNAL(valueChanged (int)), this, SLOT(changeMargin(int))); - connect(boxBorderColor, SIGNAL(clicked()), this, SLOT(pickBorderColor())); - connect(boxBackgroundColor, SIGNAL(clicked()), this, SLOT(pickBackgroundColor())); - connect(boxCanvasColor, SIGNAL(clicked()), this, SLOT(pickCanvasColor())); + connect(boxBorderColor, SIGNAL(changed(const QColor &)), this, SLOT(pickBorderColor(const QColor &))); + connect(boxBackgroundColor, SIGNAL(changed(const QColor &)), this, SLOT(pickBackgroundColor(const QColor &))); + connect(boxCanvasColor, SIGNAL(changed(const QColor &)), this, SLOT(pickCanvasColor(const QColor &))); connect(boxBorderWidth,SIGNAL(valueChanged (int)), this, SLOT(updateBorder(int))); } @@ -377,7 +375,7 @@ void PlotDialog::initPiePage() QGridLayout *gl1 = new QGridLayout(); gl1->addWidget(new QLabel( tr( "Color" )), 0, 0); - boxPieLineColor = new ColorBox(); + boxPieLineColor = new ColorButton(); gl1->addWidget(boxPieLineColor, 0, 1); gl1->addWidget(new QLabel(tr( "Style" )), 1, 0); @@ -400,7 +398,7 @@ void PlotDialog::initPiePage() QGridLayout *gl2 = new QGridLayout(); gl2->addWidget(new QLabel( tr( "First color" )), 0, 0); - boxFirstColor = new ColorBox(); + boxFirstColor = new ColorButton(); gl2->addWidget(boxFirstColor, 0, 1); gl2->addWidget(new QLabel( tr( "Pattern" )), 1, 0); @@ -521,10 +519,8 @@ void PlotDialog::initLinePage() hlayout->addWidget(fillGroupBox); privateTabWidget->addTab( linePage, tr( "Line" ) ); - connect(boxLineColor, SIGNAL(clicked()), this, SLOT(pickBoxLineColor())); connect(boxConnect, SIGNAL(activated(int)), this, SLOT(acceptParams())); connect(boxLineStyle, SIGNAL(activated(int)), this, SLOT(acceptParams())); - connect(boxAreaColor, SIGNAL(clicked()), this, SLOT(pickBoxAreaColor())); connect(boxPattern, SIGNAL(activated(int)), this, SLOT(acceptParams())); connect(fillGroupBox, SIGNAL(toggled(bool)), this, SLOT(showAreaColor(bool))); connect(fillGroupBox, SIGNAL(clicked()), this, SLOT(acceptParams())); @@ -561,9 +557,7 @@ void PlotDialog::initSymbolsPage() privateTabWidget->addTab(symbolPage, tr( "Symbol" )); - connect(boxSymbolColor, SIGNAL(clicked()), this, SLOT(pickBoxSymbolColor())); connect(boxSymbolStyle, SIGNAL(activated(int)), this, SLOT(acceptParams())); - connect(boxFillColor, SIGNAL(clicked()), this, SLOT(pickBoxFillColor())); connect(boxFillSymbol, SIGNAL(clicked()), this, SLOT(fillSymbols())); } @@ -705,11 +699,11 @@ void PlotDialog::initPercentilePage() boxFillSymbols = new QCheckBox(tr( "Fill Color" )); gl2->addWidget(boxFillSymbols, 1, 0); - boxPercFillColor = new ColorBox(); + boxPercFillColor = new ColorButton(); gl2->addWidget(boxPercFillColor, 1, 1); gl2->addWidget(new QLabel(tr( "Edge Color" )), 2, 0); - boxEdgeColor = new ColorBox(); + boxEdgeColor = new ColorButton(); gl2->addWidget(boxEdgeColor, 2, 1); gl2->addWidget(new QLabel(tr( "Edge Width" )), 3, 0); @@ -730,8 +724,6 @@ void PlotDialog::initPercentilePage() connect(box99Style, SIGNAL(activated(int)), this, SLOT(acceptParams())); connect(box1Style, SIGNAL(activated(int)), this, SLOT(acceptParams())); connect(box1Style, SIGNAL(activated(int)), this, SLOT(acceptParams())); - connect(boxEdgeColor, SIGNAL(activated(int)), this, SLOT(acceptParams())); - connect(boxPercFillColor, SIGNAL(activated(int)), this, SLOT(acceptParams())); connect(boxFillSymbols, SIGNAL(clicked()), this, SLOT(fillBoxSymbols())); } @@ -805,8 +797,6 @@ void PlotDialog::initSpectrogramPage() gl1->addWidget(boxContourStyle, 2, 1); hl2->addWidget(defaultPenBox); - connect(levelsColorBox, SIGNAL(clicked()), this, SLOT(pickContourLinesColor())); - axisScaleBox = new QGroupBox(tr( "Color Bar Scale" )); axisScaleBox->setCheckable (true); @@ -897,7 +887,6 @@ void PlotDialog::initErrorsPage() hl->addWidget(gb2); privateTabWidget->addTab( errorsPage, tr( "Error Bars" ) ); - connect(colorBox, SIGNAL(clicked()), this, SLOT(pickErrorBarsColor())); connect(xBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsType())); connect(plusBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsPlus())); connect(minusBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsMinus())); @@ -962,7 +951,7 @@ void PlotDialog::initVectPage() QGroupBox *gb1 = new QGroupBox(); QGridLayout *gl1 = new QGridLayout(gb1); gl1->addWidget(new QLabel(tr( "Color" )), 0, 0); - vectColorBox = new ColorBox(); + vectColorBox = new ColorButton(); gl1->addWidget(vectColorBox, 0, 1); gl1->addWidget(new QLabel(tr( "Line Width" )), 1, 0); vectWidthBox = new QSpinBox(); @@ -1243,50 +1232,8 @@ void PlotDialog::changeErrorBarsType() throughBox->isChecked()); } -void PlotDialog::pickBoxLineColor() -{ - QColor color = QColorDialog::getColor(boxLineColor->color(), this); - if ( !color.isValid() || color == boxLineColor->color() ) - return; - - boxLineColor->setColor(color); -} - -void PlotDialog::pickBoxAreaColor() -{ - QColor color = QColorDialog::getColor(boxAreaColor->color(), this); - if ( !color.isValid() || color == boxAreaColor->color() ) - return; - - boxAreaColor->setColor(color); -} - -void PlotDialog::pickBoxSymbolColor() -{ - QColor color = QColorDialog::getColor(boxSymbolColor->color(), this); - if ( !color.isValid() || color == boxSymbolColor->color() ) - return; - - boxSymbolColor->setColor(color); -} - -void PlotDialog::pickBoxFillColor() +void PlotDialog::pickErrorBarsColor(const QColor& color) { - QColor color = QColorDialog::getColor(boxFillColor->color(), this); - if ( !color.isValid() || color == boxFillColor->color() ) - return; - - boxFillColor->setColor(color); -} - -void PlotDialog::pickErrorBarsColor() -{ - QColor color = QColorDialog::getColor(colorBox->color(), this); - if ( !color.isValid() || color == colorBox->color() ) - return; - - colorBox->setColor (color); - CurveTreeItem *item = (CurveTreeItem *)listBox->currentItem(); if (!item) return; @@ -1559,13 +1506,11 @@ void PlotDialog::setActiveLayer(LayerItem *item) QColor c = p->paletteBackgroundColor(); boxBackgroundTransparency->setValue(c.alpha()); boxBackgroundColor->setEnabled(c.alpha()); - c.setAlpha(255); boxBackgroundColor->setColor(c); c = p->canvasBackground(); boxCanvasTransparency->setValue(c.alpha()); boxCanvasColor->setEnabled(c.alpha()); - c.setAlpha(255); boxCanvasColor->setColor(c); boxAntialiasing->setChecked(g->antialiasing()); @@ -1597,7 +1542,7 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) boxPieLineWidth->setValue(pie->pen().width()); boxPieLineColor->setColor(pie->pen().color()); setPiePenStyle(pie->pen().style()); - boxFirstColor->setCurrentIndex(pie->firstColor()); + boxFirstColor->setColor(pie->firstColor()); return; } @@ -1994,7 +1939,7 @@ bool PlotDialog::acceptParams() Graph::getPenStyle(boxPieLineStyle->currentIndex()))); pie->setRay(boxRadius->value()); pie->setBrushStyle(boxPiePattern->getSelectedPattern()); - pie->setFirstColor(boxFirstColor->currentIndex()); + pie->setFirstColor(boxFirstColor->colorIndex(boxFirstColor->color())); } else if (privateTabWidget->currentWidget() == percentilePage) { @@ -2302,15 +2247,6 @@ void PlotDialog::showDefaultContourLinesBox(bool) defaultPenBox->show(); } -void PlotDialog::pickContourLinesColor() -{ - QColor color = QColorDialog::getColor(levelsColorBox->color(), this); - if ( !color.isValid() || color == levelsColorBox->color() ) - return; - - levelsColorBox->setColor(color); -} - void PlotDialog::updateTreeWidgetItem(QTreeWidgetItem *item) { if (item->type() != QTreeWidgetItem::Type) @@ -2325,6 +2261,12 @@ void PlotDialog::updateTreeWidgetItem(QTreeWidgetItem *item) void PlotDialog::updateBackgroundTransparency(int alpha) { boxBackgroundColor->setEnabled(alpha); + if (alpha != boxBackgroundColor->color().alpha()) + { + QColor c = boxBackgroundColor->color(); + c.setAlpha(alpha); + boxBackgroundColor->setColor(c); + } if (boxAll->isChecked()) { @@ -2358,6 +2300,12 @@ void PlotDialog::updateBackgroundTransparency(int alpha) void PlotDialog::updateCanvasTransparency(int alpha) { boxCanvasColor->setEnabled(alpha); + if (alpha != boxCanvasColor->color().alpha()) + { + QColor c = boxCanvasColor->color(); + c.setAlpha(alpha); + boxCanvasColor->setColor(c); + } if (boxAll->isChecked()) { @@ -2388,14 +2336,13 @@ void PlotDialog::updateCanvasTransparency(int alpha) } } -void PlotDialog::pickCanvasColor() +void PlotDialog::pickCanvasColor(const QColor& c) { - QColor c = QColorDialog::getColor(boxCanvasColor->color(), this); - if ( !c.isValid() || c == boxCanvasColor->color() ) - return; - - boxCanvasColor->setColor ( c ) ; - + QColor color = c; + if (c.alpha() != boxCanvasTransparency->value()) + { + boxCanvasTransparency->setValue(c.alpha()); + } if (boxAll->isChecked()) { QWidgetList allPlots = d_ml->graphPtrs(); @@ -2404,8 +2351,8 @@ void PlotDialog::pickCanvasColor() Graph* g=(Graph*)allPlots.at(i); if (g) { - c.setAlpha(boxCanvasTransparency->value()); - g->setCanvasBackground(c); + color.setAlpha(boxCanvasTransparency->value()); + g->setCanvasBackground(color); g->replot(); } } @@ -2418,21 +2365,20 @@ void PlotDialog::pickCanvasColor() Graph *g = item->graph(); if (g) { - c.setAlpha(boxCanvasTransparency->value()); - g->setCanvasBackground(c); + color.setAlpha(boxCanvasTransparency->value()); + g->setCanvasBackground(color); g->replot(); } } } -void PlotDialog::pickBackgroundColor() +void PlotDialog::pickBackgroundColor(const QColor& c) { - QColor c = QColorDialog::getColor(boxBackgroundColor->color(), this); - if ( !c.isValid() || c == boxBackgroundColor->color() ) - return; - - boxBackgroundColor->setColor ( c ) ; - + QColor color = c; + if (c.alpha() != boxBackgroundTransparency->value()) + { + boxBackgroundTransparency->setValue(c.alpha()); + } if (boxAll->isChecked()) { QWidgetList allPlots = d_ml->graphPtrs(); @@ -2441,8 +2387,8 @@ void PlotDialog::pickBackgroundColor() Graph* g=(Graph*)allPlots.at(i); if (g) { - c.setAlpha(boxBackgroundTransparency->value()); - g->setBackgroundColor(c); + color.setAlpha(boxBackgroundTransparency->value()); + g->setBackgroundColor(color); g->replot(); } } @@ -2455,21 +2401,15 @@ void PlotDialog::pickBackgroundColor() Graph *g = item->graph(); if (g) { - c.setAlpha(boxBackgroundTransparency->value()); - g->setBackgroundColor(c); + color.setAlpha(boxBackgroundTransparency->value()); + g->setBackgroundColor(color); g->replot(); } } } -void PlotDialog::pickBorderColor() +void PlotDialog::pickBorderColor(const QColor& c) { - QColor c = QColorDialog::getColor(boxBorderColor->color(), this); - if ( !c.isValid() || c == boxBorderColor->color() ) - return; - - boxBorderColor->setColor ( c ) ; - if (boxAll->isChecked()) { QWidgetList allPlots = d_ml->graphPtrs(); diff --git a/libscidavis/src/PlotDialog.h b/libscidavis/src/PlotDialog.h index 5045756fb..c5b3aafb7 100644 --- a/libscidavis/src/PlotDialog.h +++ b/libscidavis/src/PlotDialog.h @@ -50,7 +50,6 @@ class QTreeWidget; class LayerItem; class CurveTreeItem; -class ColorBox; class PatternBox; class ColorButton; class MultiLayer; @@ -94,14 +93,8 @@ class PlotDialog : public QDialog void removeSelectedCurve(); - //line plots - void pickBoxLineColor(); - void pickBoxAreaColor(); - void pickBoxSymbolColor(); - void pickBoxFillColor(); - /******* error bars options **************/ - void pickErrorBarsColor(); + void pickErrorBarsColor(const QColor &); void changeErrorBarsType(); void changeErrorBarsPlus(); void changeErrorBarsMinus(); @@ -120,7 +113,6 @@ class PlotDialog : public QDialog void setWhiskersRange(int index); //spectrograms - void pickContourLinesColor(); void showDefaultContourLinesBox(bool show); void showColorMapEditor(bool show); @@ -131,9 +123,9 @@ class PlotDialog : public QDialog void updateCanvasTransparency(int alpha); void updateAntialiasing(bool on); void updateBorder(int width); - void pickBackgroundColor(); - void pickCanvasColor(); - void pickBorderColor(); + void pickBackgroundColor(const QColor &); + void pickCanvasColor(const QColor &); + void pickBorderColor(const QColor &); void changeMargin(int); void setTitlesFont(); void setAxesLabelsFont(); @@ -174,7 +166,7 @@ class PlotDialog : public QDialog ColorButton *boxBorderColor, *boxBackgroundColor, *boxCanvasColor; QSpinBox *boxBackgroundTransparency, *boxCanvasTransparency, *boxBorderWidth, *boxMargin; QSpinBox *boxRadius, *boxPieLineWidth; - ColorBox *boxFirstColor, *boxPieLineColor; + ColorButton *boxFirstColor, *boxPieLineColor; PatternBox *boxPiePattern; QComboBox* boxPieLineStyle; @@ -186,7 +178,7 @@ class PlotDialog : public QDialog QComboBox* boxConnect; QComboBox* boxLineStyle; QSpinBox* boxLineWidth, *boxPenWidth; - ColorButton* boxLineColor, *boxAreaColor; + ColorButton* boxLineColor, *boxAreaColor; QWidget* symbolPage; QSpinBox* boxSymbolSize; ColorButton* boxSymbolColor,*boxFillColor; @@ -199,7 +191,7 @@ class PlotDialog : public QDialog QCheckBox* minusBox; QCheckBox* xBox; ColorButton *colorBox, *levelsColorBox; - ColorBox* vectColorBox; + ColorButton* vectColorBox; QComboBox* widthBox; QComboBox* capBox; QCheckBox* throughBox; @@ -216,7 +208,7 @@ class PlotDialog : public QDialog QCheckBox *filledHeadBox; QSpinBox *boxCoef, *boxWhiskersCoef; QCheckBox *boxFillSymbols, *boxFillSymbol; - ColorBox *boxPercFillColor, *boxEdgeColor; + ColorButton *boxPercFillColor, *boxEdgeColor; QLabel *whiskerCoeffLabel, *whiskerRangeLabel, *boxCoeffLabel; QLabel *boxRangeLabel, *whiskerCntLabel, *boxCntLabel; QGroupBox *GroupBoxVectEnd; diff --git a/libscidavis/src/PolynomFitDialog.cpp b/libscidavis/src/PolynomFitDialog.cpp index 220e660f2..3250d9a33 100644 --- a/libscidavis/src/PolynomFitDialog.cpp +++ b/libscidavis/src/PolynomFitDialog.cpp @@ -28,7 +28,7 @@ ***************************************************************************/ #include "PolynomFitDialog.h" #include "Graph.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "ApplicationWindow.h" #include "PolynomialFit.h" @@ -70,9 +70,9 @@ PolynomFitDialog::PolynomFitDialog( QWidget* parent, Qt::WindowFlags fl ) gl1->addWidget(boxEnd, 3, 1); gl1->addWidget(new QLabel( tr("Color")), 4, 0); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); - gl1->addWidget(boxColor, 4, 1); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); + gl1->addWidget(btnColor, 4, 1); boxShowFormula = new QCheckBox(tr( "Show Formula on Graph?" )); boxShowFormula->setChecked( false ); @@ -115,7 +115,7 @@ void PolynomFitDialog::fit() PolynomialFit *fitter = new PolynomialFit(app, graph, boxOrder->value(), boxShowFormula->isChecked()); if (fitter->setDataFromCurve(curveName, boxStart->text().toDouble(), boxEnd->text().toDouble())) { - fitter->setColor(boxColor->currentIndex()); + fitter->setColor(ColorButton::colorIndex(btnColor->color())); fitter->scaleErrors(app->fit_scale_errors); fitter->setOutputPrecision(app->fit_output_precision); fitter->generateFunction(app->generateUniformFitPoints, app->fitPoints); diff --git a/libscidavis/src/PolynomFitDialog.h b/libscidavis/src/PolynomFitDialog.h index c848b139f..8f233b249 100644 --- a/libscidavis/src/PolynomFitDialog.h +++ b/libscidavis/src/PolynomFitDialog.h @@ -37,7 +37,7 @@ class QPushButton; class QLineEdit; class QComboBox; class Graph; -class ColorBox; +class ColorButton; //! Fit polynomial dialog class PolynomFitDialog : public QDialog @@ -63,7 +63,7 @@ public slots: QSpinBox* boxOrder; QLineEdit* boxStart; QLineEdit* boxEnd; - ColorBox* boxColor; + ColorButton* btnColor; }; #endif diff --git a/libscidavis/src/QwtPieCurve.cpp b/libscidavis/src/QwtPieCurve.cpp index 005b43fc0..1dba14675 100644 --- a/libscidavis/src/QwtPieCurve.cpp +++ b/libscidavis/src/QwtPieCurve.cpp @@ -27,7 +27,7 @@ * * ***************************************************************************/ #include "QwtPieCurve.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "Table.h" #include "core/column/Column.h" @@ -97,8 +97,8 @@ void QwtPieCurve::drawPie(QPainter *painter, QColor QwtPieCurve::color(int i) const { - int index=(d_first_color+i) % ColorBox::numPredefinedColors(); - return ColorBox::color(index); + int index=(d_first_color+i) % ColorButton::numPredefinedColors(); + return ColorButton::color(index); } void QwtPieCurve::setBrushStyle(const Qt::BrushStyle& style) diff --git a/libscidavis/src/SmoothCurveDialog.cpp b/libscidavis/src/SmoothCurveDialog.cpp index eac4c5c63..63a0197c7 100644 --- a/libscidavis/src/SmoothCurveDialog.cpp +++ b/libscidavis/src/SmoothCurveDialog.cpp @@ -29,7 +29,7 @@ #include "SmoothCurveDialog.h" #include "Graph.h" #include "MyParser.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "SmoothFilter.h" #include @@ -55,8 +55,8 @@ SmoothCurveDialog::SmoothCurveDialog(int method, QWidget* parent, Qt::WindowFlag boxName = new QComboBox(); gl1->addWidget(boxName, 0, 1); - boxColor = new ColorBox(); - boxColor->setColor(QColor(Qt::red)); + btnColor = new ColorButton(); + btnColor->setColor(QColor(Qt::red)); if (method == SmoothFilter::SavitzkyGolay) { @@ -79,7 +79,7 @@ SmoothCurveDialog::SmoothCurveDialog(int method, QWidget* parent, Qt::WindowFlag gl1->addWidget(boxPointsRight, 3, 1); gl1->addWidget(new QLabel(tr("Color")), 4, 0); - gl1->addWidget(boxColor, 4, 1); + gl1->addWidget(btnColor, 4, 1); gl1->setRowStretch(5, 1); } else @@ -92,7 +92,7 @@ SmoothCurveDialog::SmoothCurveDialog(int method, QWidget* parent, Qt::WindowFlag gl1->addWidget(boxPointsLeft, 1, 1); gl1->addWidget(new QLabel(tr("Color")), 2, 0); - gl1->addWidget(boxColor, 2, 1); + gl1->addWidget(btnColor, 2, 1); gl1->setRowStretch(3, 1); } gl1->setColumnStretch(2, 1); @@ -127,7 +127,7 @@ void SmoothCurveDialog::smooth() else sf->setSmoothPoints(boxPointsLeft->value()); - sf->setColor(boxColor->currentIndex()); + sf->setColor(ColorButton::colorIndex(btnColor->color())); sf->run(); delete sf; } diff --git a/libscidavis/src/SmoothCurveDialog.h b/libscidavis/src/SmoothCurveDialog.h index 45596b887..386b1b433 100644 --- a/libscidavis/src/SmoothCurveDialog.h +++ b/libscidavis/src/SmoothCurveDialog.h @@ -35,7 +35,7 @@ class QPushButton; class QComboBox; class QSpinBox; class Graph; -class ColorBox; +class ColorButton; //! Smoothing options dialog class SmoothCurveDialog : public QDialog @@ -50,7 +50,7 @@ class SmoothCurveDialog : public QDialog QPushButton* buttonCancel; QComboBox* boxName; QSpinBox *boxPointsLeft, *boxPointsRight, *boxOrder; - ColorBox* boxColor; + ColorButton* btnColor; public slots: void setGraph(Graph *g); diff --git a/libscidavis/src/TextDialog.cpp b/libscidavis/src/TextDialog.cpp index 95123b4ca..cf618abe4 100644 --- a/libscidavis/src/TextDialog.cpp +++ b/libscidavis/src/TextDialog.cpp @@ -129,9 +129,9 @@ TextDialog::TextDialog(TextType type, QWidget* parent, Qt::WindowFlags fl ) // add background button topLayout->addWidget( backgroundBtn, 4, 1 ); - connect(backgroundBtn, SIGNAL(clicked()), this, SLOT(pickBackgroundColor())); connect(boxBackgroundTransparency, SIGNAL(valueChanged(int)), this, SLOT(updateTransparency(int))); + connect(backgroundBtn, SIGNAL(changed(const QColor&)), this, SLOT(pickBackgroundColor(const QColor&))); buttonDefault = new QPushButton( tr( "Set As &Default" ) ); topLayout->addWidget( buttonDefault, 3, 3 ); @@ -178,7 +178,6 @@ TextDialog::TextDialog(TextType type, QWidget* parent, Qt::WindowFlags fl ) setLayout( mainLayout ); // signals and slots connections - connect( colorBtn, SIGNAL( clicked() ), this, SLOT( pickTextColor() ) ); connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); connect( buttonApply, SIGNAL( clicked() ), this, SLOT( apply() ) ); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); @@ -307,33 +306,13 @@ void TextDialog::setTextColor(QColor c) colorBtn->setColor(c); } -void TextDialog::pickTextColor() -{ - QColor c = QColorDialog::getColor( colorBtn->color(), this); - if ( !c.isValid() || c == colorBtn->color() ) - return; - - colorBtn->setColor ( c ) ; -} - void TextDialog::setBackgroundColor(QColor c) { boxBackgroundTransparency->setValue(c.alpha()); backgroundBtn->setEnabled(c.alpha()); - c.setAlpha(255); - backgroundBtn->setColor(c); } -void TextDialog::pickBackgroundColor() -{ - QColor c = QColorDialog::getColor( backgroundBtn->color(), this); - if ( !c.isValid() || c == backgroundBtn->color() ) - return; - - backgroundBtn->setColor ( c ) ; -} - void TextDialog::setFont(const QFont & fnt) { selectedFont = fnt; @@ -341,5 +320,19 @@ void TextDialog::setFont(const QFont & fnt) void TextDialog::updateTransparency(int alpha) { -backgroundBtn->setEnabled(alpha); + if (alpha != backgroundBtn->color().alpha()) + { + QColor c = backgroundBtn->color(); + c.setAlpha(alpha); + backgroundBtn->setColor(c); + } + backgroundBtn->setEnabled(alpha); +} + +void TextDialog::pickBackgroundColor(const QColor& c) +{ + if (c.alpha() != boxBackgroundTransparency->value()) + { + boxBackgroundTransparency->setValue(c.alpha()); + } } diff --git a/libscidavis/src/TextDialog.h b/libscidavis/src/TextDialog.h index 33a8bd6b5..64a2ff7f2 100644 --- a/libscidavis/src/TextDialog.h +++ b/libscidavis/src/TextDialog.h @@ -100,10 +100,6 @@ public slots: private slots: //! Let the user select another font void customFont(); - //! Let the user pick the background color - void pickBackgroundColor(); - //! Let the user pick the text color - void pickTextColor(); //! Accept changes and close dialog void accept(); //! Apply changes @@ -111,6 +107,7 @@ private slots: void setDefaultValues(); void updateTransparency(int alpha); + void pickBackgroundColor(const QColor&); signals: //! Emit all current values diff --git a/libscidavis/src/importOPJ.cpp b/libscidavis/src/importOPJ.cpp index 9226695a1..af0eed416 100644 --- a/libscidavis/src/importOPJ.cpp +++ b/libscidavis/src/importOPJ.cpp @@ -41,7 +41,7 @@ #include #include #include "Matrix.h" -#include "ColorBox.h" +#include "ColorButton.h" #include "MultiLayer.h" #include "Note.h" #include "Folder.h" @@ -820,7 +820,7 @@ bool ImportOPJ::importGraphs(const OriginFile &opj) } cl.lWidth = _curve.lineWidth; - color=_curve.lineColor.regular % ColorBox::numPredefinedColors(); + color=_curve.lineColor.regular % ColorButton::numPredefinedColors(); cl.lCol = (_curve.lineColor.type==Origin::Color::Automatic?0:color); //0xF7 -Automatic color int linestyle=_curve.lineStyle; cl.filledArea=(_curve.fillArea || style==Graph::VerticalBars || style==Graph::HorizontalBars || style==Graph::Histogram || style == Graph::Pie || style == Graph::Box) ? 1 : 0; @@ -956,13 +956,13 @@ bool ImportOPJ::importGraphs(const OriginFile &opj) grid->enableY(!layer.yAxis.majorGrid.hidden); grid->enableYMin(!layer.yAxis.minorGrid.hidden); - grid->setMajPenX(QPen(ColorBox::color(layer.xAxis.majorGrid.color), ceil(layer.xAxis.majorGrid.width), + grid->setMajPenX(QPen(ColorButton::color(layer.xAxis.majorGrid.color), ceil(layer.xAxis.majorGrid.width), Graph::getPenStyle(translateOrigin2ScidavisLineStyle((Origin::GraphCurve::LineStyle)layer.xAxis.majorGrid.style)))); - grid->setMinPenX(QPen(ColorBox::color(layer.xAxis.minorGrid.color), ceil(layer.xAxis.minorGrid.width), + grid->setMinPenX(QPen(ColorButton::color(layer.xAxis.minorGrid.color), ceil(layer.xAxis.minorGrid.width), Graph::getPenStyle(translateOrigin2ScidavisLineStyle((Origin::GraphCurve::LineStyle)layer.xAxis.minorGrid.style)))); - grid->setMajPenY(QPen(ColorBox::color(layer.yAxis.majorGrid.color), ceil(layer.yAxis.majorGrid.width), + grid->setMajPenY(QPen(ColorButton::color(layer.yAxis.majorGrid.color), ceil(layer.yAxis.majorGrid.width), Graph::getPenStyle(translateOrigin2ScidavisLineStyle((Origin::GraphCurve::LineStyle)layer.yAxis.majorGrid.style)))); - grid->setMinPenY(QPen(ColorBox::color(layer.yAxis.minorGrid.color), ceil(layer.yAxis.minorGrid.width), + grid->setMinPenY(QPen(ColorButton::color(layer.yAxis.minorGrid.color), ceil(layer.yAxis.minorGrid.width), Graph::getPenStyle(translateOrigin2ScidavisLineStyle((Origin::GraphCurve::LineStyle)layer.yAxis.minorGrid.style)))); grid->setAxis(2, 0); @@ -1053,8 +1053,8 @@ bool ImportOPJ::importGraphs(const OriginFile &opj) graph->showAxis(i, type, tableName, mw->table(tableName), !(formats[i].hidden), tickTypeMap[formats[i].majorTicksType], tickTypeMap[formats[i].minorTicksType], - !(ticks[i].showMajorLabels), ColorBox::color(formats[i].color), format, prec, - ticks[i].rotation, 0, "", (ticks[i].color==0xF7 ? ColorBox::color(formats[i].color) : ColorBox::color(ticks[i].color))); + !(ticks[i].showMajorLabels), ColorButton::color(formats[i].color), format, prec, + ticks[i].rotation, 0, "", (ticks[i].color==0xF7 ? ColorButton::color(formats[i].color) : ColorButton::color(ticks[i].color))); } From 291e77c0182ee947de02bfc924c8ca64ff2bf17c Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Mon, 8 Oct 2018 23:18:08 +0200 Subject: [PATCH 02/12] Define a macro to save color values including alpha --- libscidavis/src/ColorButton.h | 6 +++++ libscidavis/src/Graph.cpp | 44 ++++++++++++++++----------------- libscidavis/src/Graph3D.cpp | 19 +++++++------- libscidavis/src/Grid.cpp | 8 +++--- libscidavis/src/Spectrogram.cpp | 9 ++++--- 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/libscidavis/src/ColorButton.h b/libscidavis/src/ColorButton.h index 3a67b7327..25c8616b1 100644 --- a/libscidavis/src/ColorButton.h +++ b/libscidavis/src/ColorButton.h @@ -35,6 +35,12 @@ class QPushButton; class QHBoxLayout; class QFrame; +#if QT_VERSION >= 0x050000 +#define COLORNAME( c ) c.name(QColor::HexArgb) +#else +#define COLORNAME( c ) ('#'+QString::number(c.rgba(),16)) +#endif + //! A button used for color selection /** * This button contains two widgets: diff --git a/libscidavis/src/Graph.cpp b/libscidavis/src/Graph.cpp index f6c43f1ac..9b6413ed1 100644 --- a/libscidavis/src/Graph.cpp +++ b/libscidavis/src/Graph.cpp @@ -657,8 +657,8 @@ void Graph::showAxis(int axis, int type, const QString& formatInfo, Table *table if (d_plot->axisEnabled (axis) == axisOn && majTicksTypeList[axis] == majTicksType && minTicksTypeList[axis] == minTicksType && - axesColors()[axis] == c.name() && - axesNumColors()[axis] == labelsColor.name() && + axesColors()[axis] == COLORNAME(c) && + axesNumColors()[axis] == COLORNAME(labelsColor) && prec == d_plot->axisLabelPrecision (axis) && format == d_plot->axisLabelFormat (axis) && labelsRotation(axis) == rotation && @@ -975,8 +975,8 @@ QString Graph::saveAxesColors() int i; for (i=0;i<4;i++) { - colors<palette(); - colors[i]=pal.color(QPalette::Active, QPalette::WindowText).name(); - numColors[i]=pal.color(QPalette::Active, QPalette::Text).name(); + colors[i]=COLORNAME(pal.color(QPalette::Active, QPalette::WindowText)); + numColors[i]=COLORNAME(pal.color(QPalette::Active, QPalette::Text)); } } s+=colors.join ("\t")+"\n"; @@ -1000,7 +1000,7 @@ QStringList Graph::axesColors() QPalette pal; int i; for (i=0;i<4;i++) - colors<palette(); - colors[i]=pal.color(QPalette::Active, QPalette::WindowText).name(); + colors[i]=COLORNAME(pal.color(QPalette::Active, QPalette::WindowText)); } } return colors; @@ -1038,7 +1038,7 @@ QStringList Graph::axesNumColors() QPalette pal; int i; for (i=0;i<4;i++) - colors << QColor(Qt::black).name(); + colors << COLORNAME(QColor(Qt::black)); for (i=0;i<4;i++) { @@ -1046,7 +1046,7 @@ QStringList Graph::axesNumColors() if (scale) { pal=scale->palette(); - colors[i]=pal.color(QPalette::Active, QPalette::Text).name(); + colors[i]=COLORNAME(pal.color(QPalette::Active, QPalette::Text)); } } return colors; @@ -2042,9 +2042,9 @@ QString Graph::saveCanvas() if (w>0) { s += "CanvasFrame\t" + QString::number(w)+"\t"; - s += canvasFrameColor().name()+"\n"; + s += COLORNAME(canvasFrameColor())+"\n"; } - s += "CanvasBackground\t" + d_plot->canvasBackground().name()+"\t"; + s += "CanvasBackground\t" + COLORNAME(d_plot->canvasBackground())+"\t"; s += QString::number(d_plot->canvasBackground().alpha())+"\n"; return s; } @@ -2209,7 +2209,7 @@ QString Graph::saveAxesTitleColors() else c=QColor(Qt::black); - s+=c.name()+"\t"; + s+=COLORNAME(c)+"\t"; } return s+"\n"; } @@ -2218,7 +2218,7 @@ QString Graph::saveTitle() { QString s="PlotTitle\t"; s += d_plot->title().text().replace("\n", "
")+"\t"; - s += d_plot->title().color().name()+"\t"; + s += COLORNAME(d_plot->title().color())+"\t"; s += QString::number(d_plot->title().renderFlags())+"\n"; return s; } @@ -2281,7 +2281,7 @@ QString Graph::savePieCurveLayout() QPen pen=pieCurve->pen(); s+=QString::number(pen.width())+"\t"; - s+=pen.color().name()+"\t"; + s+=COLORNAME(pen.color())+"\t"; s+=penStyleName(pen.style()) + "\t"; Qt::BrushStyle pattern=pieCurve->pattern(); @@ -2379,7 +2379,7 @@ QString Graph::saveCurveLayout(int index) else if(style == VectXYXY || style == VectXYAM) { VectorCurve *v = (VectorCurve*)c; - s+=v->color().name()+"\t"; + s+=COLORNAME(v->color())+"\t"; s+=QString::number(v->width())+"\t"; s+=QString::number(v->headLength())+"\t"; s+=QString::number(v->headAngle())+"\t"; @@ -2465,7 +2465,7 @@ QString Graph::saveCurves() s += er->title().text() + "\t"; s += QString::number(er->width())+"\t"; s += QString::number(er->capLength())+"\t"; - s += er->color().name()+"\t"; + s += COLORNAME(er->color())+"\t"; s += QString::number(er->throughSymbol())+"\t"; s += QString::number(er->plusSide())+"\t"; s += QString::number(er->minusSide())+"\n"; @@ -2716,7 +2716,7 @@ QString Graph::saveMarkers() s+=(QString::number(ep.y(), 'g', 15))+"\t"; s+=QString::number(mrkL->width())+"\t"; - s+=mrkL->color().name()+"\t"; + s+=COLORNAME(mrkL->color())+"\t"; s+=penStyleName(mrkL->style())+"\t"; s+=QString::number(mrkL->hasEndArrow())+"\t"; s+=QString::number(mrkL->hasStartArrow())+"\t"; @@ -2743,10 +2743,10 @@ QString Graph::saveMarkers() s+=QString::number(f.italic())+"\t"; s+=QString::number(f.underline())+"\t"; s+=QString::number(f.strikeOut())+"\t"; - s+=mrk->textColor().name()+"\t"; + s+=COLORNAME(mrk->textColor())+"\t"; s+=QString::number(mrk->frameStyle())+"\t"; s+=QString::number(mrk->angle())+"\t"; - s+=mrk->backgroundColor().name()+"\t"; + s+=COLORNAME(mrk->backgroundColor())+"\t"; s+=QString::number(mrk->backgroundColor().alpha())+"\t"; QStringList textList=mrk->text().split("\n", QString::KeepEmptyParts); @@ -4032,10 +4032,10 @@ QString Graph::saveToString(bool saveAsTemplate) s+=QString::number(this->frameGeometry().height())+"\n"; s+=saveTitle(); s+="" + QString::number(d_antialiasing) + "\n"; - s+="Background\t" + d_plot->paletteBackgroundColor().name() + "\t"; + s+="Background\t" + COLORNAME(d_plot->paletteBackgroundColor()) + "\t"; s+=QString::number(d_plot->paletteBackgroundColor().alpha()) + "\n"; s+="Margin\t"+QString::number(d_plot->margin())+"\n"; - s+="Border\t"+QString::number(d_plot->lineWidth())+"\t"+d_plot->frameColor().name()+"\n"; + s+="Border\t"+QString::number(d_plot->lineWidth())+"\t"+COLORNAME(d_plot->frameColor())+"\n"; s+=grid()->saveToString(); s+=saveEnabledAxes(); s+="AxesTitles\t"+saveScaleTitles(); diff --git a/libscidavis/src/Graph3D.cpp b/libscidavis/src/Graph3D.cpp index effcb7584..fad04446c 100644 --- a/libscidavis/src/Graph3D.cpp +++ b/libscidavis/src/Graph3D.cpp @@ -30,6 +30,7 @@ #include "Bar.h" #include "Cone3D.h" #include "MyParser.h" +#include "ColorButton.h" #include "core/column/Column.h" #include @@ -2531,21 +2532,21 @@ QString Graph3D::saveToString(const QString& geometry) s+="title\t"; s+=title+"\t"; - s+=titleCol.name()+"\t"; + s+=COLORNAME(titleCol)+"\t"; s+=titleFnt.family()+"\t"; s+=QString::number(titleFnt.pointSize())+"\t"; s+=QString::number(titleFnt.weight())+"\t"; s+=QString::number(titleFnt.italic())+"\n"; s+="colors\t"; - s+=meshCol.name()+"\t"; - s+=axesCol.name()+"\t"; - s+=numCol.name()+"\t"; - s+=labelsCol.name()+"\t"; - s+=bgCol.name()+"\t"; - s+=gridCol.name()+"\t"; - s+=fromColor.name()+"\t"; - s+=toColor.name()+"\t"; + s+=COLORNAME(meshCol)+"\t"; + s+=COLORNAME(axesCol)+"\t"; + s+=COLORNAME(numCol)+"\t"; + s+=COLORNAME(labelsCol)+"\t"; + s+=COLORNAME(bgCol)+"\t"; + s+=COLORNAME(gridCol)+"\t"; + s+=COLORNAME(fromColor)+"\t"; + s+=COLORNAME(toColor)+"\t"; s+=QString::number(alpha) + "\t" + color_map + "\n"; s+="axesLabels\t"; diff --git a/libscidavis/src/Grid.cpp b/libscidavis/src/Grid.cpp index b31ac667f..389703954 100644 --- a/libscidavis/src/Grid.cpp +++ b/libscidavis/src/Grid.cpp @@ -257,19 +257,19 @@ QString Grid::saveToString() s += QString::number(yEnabled())+"\t"; s += QString::number(yMinEnabled())+"\t"; - s += majPenX().color().name()+"\t"; + s += COLORNAME(majPenX().color())+"\t"; s += QString::number(majPenX().style() - 1)+"\t"; s += QString::number(majPenX().width())+"\t"; - s += minPenX().color().name()+"\t"; + s += COLORNAME(minPenX().color())+"\t"; s += QString::number(minPenX().style() - 1)+"\t"; s += QString::number(minPenX().width())+"\t"; - s += majPenY().color().name()+"\t"; + s += COLORNAME(majPenY().color())+"\t"; s += QString::number(majPenY().style() - 1)+"\t"; s += QString::number(majPenY().width())+"\t"; - s += minPenY().color().name()+"\t"; + s += COLORNAME(minPenY().color())+"\t"; s += QString::number(minPenY().style() - 1)+"\t"; s += QString::number(minPenY().width())+"\t"; diff --git a/libscidavis/src/Spectrogram.cpp b/libscidavis/src/Spectrogram.cpp index 69ee048ec..a07d8a3fb 100644 --- a/libscidavis/src/Spectrogram.cpp +++ b/libscidavis/src/Spectrogram.cpp @@ -27,6 +27,7 @@ ***************************************************************************/ #include "Spectrogram.h" +#include "ColorButton.h" #include #include #include @@ -256,15 +257,15 @@ else { s += "\t\n"; s += "\t\t" + QString::number(color_map.mode()) + "\n"; - s += "\t\t" + color_map.color1().name() + "\n"; - s += "\t\t" + color_map.color2().name() + "\n"; + s += "\t\t" + COLORNAME(color_map.color1()) + "\n"; + s += "\t\t" + COLORNAME(color_map.color2()) + "\n"; QwtArray colors = color_map.colorStops(); int stops = (int)colors.size(); s += "\t\t" + QString::number(stops - 2) + "\n"; for (int i = 1; i < stops - 1; i++) { s += "\t\t" + QString::number(colors[i]) + "\t"; - s += QColor(color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name(); + s += COLORNAME(QColor(color_map.rgb(QwtDoubleInterval(0,1), colors[i]))); s += "\n"; } s += "\t\n"; @@ -280,7 +281,7 @@ if (contourLines) s += "\t\t"+QString::number(defaultPen)+"\n"; if (defaultPen) { - s += "\t\t\t"+defaultContourPen().color().name()+"\n"; + s += "\t\t\t"+COLORNAME(defaultContourPen().color())+"\n"; s += "\t\t\t"+QString::number(defaultContourPen().width())+"\n"; s += "\t\t\t"+QString::number(defaultContourPen().style() - 1)+"\n"; } From da5e955101632cebc9be65dc9da1d7b4d1fe1cfe Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Mon, 8 Oct 2018 23:21:33 +0200 Subject: [PATCH 03/12] Set basic colors in QColorDialog from internal color list --- libscidavis/src/ColorButton.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libscidavis/src/ColorButton.cpp b/libscidavis/src/ColorButton.cpp index 32b974a3f..25725d38b 100644 --- a/libscidavis/src/ColorButton.cpp +++ b/libscidavis/src/ColorButton.cpp @@ -34,6 +34,35 @@ #include #include +const QColor ColorButton::colors[] = { + QColor(Qt::black), + QColor(Qt::red), + QColor(Qt::green), + QColor(Qt::blue), + QColor(Qt::cyan), + QColor(Qt::magenta), + QColor(Qt::yellow), + QColor(Qt::darkYellow), + QColor(Qt::darkBlue), + QColor(Qt::darkMagenta), + QColor(Qt::darkRed), + QColor(Qt::darkGreen), + QColor(Qt::darkCyan), + QColor("#0000A0"), + QColor("#FF8000"), + QColor("#8000FF"), + QColor("#FF0080"), + QColor(Qt::white), + QColor(Qt::lightGray), + QColor(Qt::gray), + QColor("#FFFF80"), + QColor("#80FFFF"), + QColor("#FF80FF"), + QColor(Qt::darkGray), +}; + +const int ColorButton::colors_count=sizeof(colors)/sizeof(colors[0]); + ColorButton::ColorButton(QWidget *parent) : QWidget(parent) { init(); @@ -41,6 +70,13 @@ ColorButton::ColorButton(QWidget *parent) : QWidget(parent) void ColorButton::init() { + for (int i=0; i<8; i++) + { + for (int j=0; j<3; j++) + { + QColorDialog::setStandardColor(6*i+j, colors[i+8*j].rgb()); + } + } const int btn_size = 28; selectButton = new QPushButton(QPixmap(":/palette.xpm"), QString(), this); selectButton->setMinimumWidth(btn_size); From a3a19f4d3fc5f79d34effd86377862dfe4ed8d51 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Wed, 10 Oct 2018 22:25:30 +0200 Subject: [PATCH 04/12] Remove redundant numPredefinedColors --- libscidavis/src/ColorButton.cpp | 7 +------ libscidavis/src/ColorButton.h | 6 ++---- libscidavis/src/QwtPieCurve.cpp | 2 +- libscidavis/src/importOPJ.cpp | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libscidavis/src/ColorButton.cpp b/libscidavis/src/ColorButton.cpp index 25725d38b..925445982 100644 --- a/libscidavis/src/ColorButton.cpp +++ b/libscidavis/src/ColorButton.cpp @@ -61,7 +61,7 @@ const QColor ColorButton::colors[] = { QColor(Qt::darkGray), }; -const int ColorButton::colors_count=sizeof(colors)/sizeof(colors[0]); +const unsigned int ColorButton::colors_count=sizeof(colors)/sizeof(colors[0]); ColorButton::ColorButton(QWidget *parent) : QWidget(parent) { @@ -143,11 +143,6 @@ bool ColorButton::isValidColor(const QColor& c) return (ite->isValid()); } -int ColorButton::numPredefinedColors() -{ - return colors_count; -} - QSize ColorButton::sizeHint () const { return QSize(4*btn_size, btn_size); diff --git a/libscidavis/src/ColorButton.h b/libscidavis/src/ColorButton.h index 25c8616b1..3c9cc191d 100644 --- a/libscidavis/src/ColorButton.h +++ b/libscidavis/src/ColorButton.h @@ -64,8 +64,8 @@ class ColorButton : public QWidget static QColor color(unsigned int colorIndex); //! Returns TRUE if the color is included in the color box, otherwise returns FALSE. static bool isValidColor(const QColor& color); - //! Returns the number of predefined colors - static int numPredefinedColors(); + //! The number of predefined colors + static const unsigned int colors_count; QSize sizeHint() const; private: @@ -80,8 +80,6 @@ class ColorButton : public QWidget protected: //! Initialize the widget (called from constructor) void init(); - //! The number of predefined colors - static const int colors_count; //! Array containing the 24 predefined colors static const QColor colors[]; diff --git a/libscidavis/src/QwtPieCurve.cpp b/libscidavis/src/QwtPieCurve.cpp index 1dba14675..297d1db4f 100644 --- a/libscidavis/src/QwtPieCurve.cpp +++ b/libscidavis/src/QwtPieCurve.cpp @@ -97,7 +97,7 @@ void QwtPieCurve::drawPie(QPainter *painter, QColor QwtPieCurve::color(int i) const { - int index=(d_first_color+i) % ColorButton::numPredefinedColors(); + int index=(d_first_color+i) % ColorButton::colors_count; return ColorButton::color(index); } diff --git a/libscidavis/src/importOPJ.cpp b/libscidavis/src/importOPJ.cpp index af0eed416..24fafb964 100644 --- a/libscidavis/src/importOPJ.cpp +++ b/libscidavis/src/importOPJ.cpp @@ -820,7 +820,7 @@ bool ImportOPJ::importGraphs(const OriginFile &opj) } cl.lWidth = _curve.lineWidth; - color=_curve.lineColor.regular % ColorButton::numPredefinedColors(); + color=_curve.lineColor.regular % ColorButton::colors_count; cl.lCol = (_curve.lineColor.type==Origin::Color::Automatic?0:color); //0xF7 -Automatic color int linestyle=_curve.lineStyle; cl.filledArea=(_curve.fillArea || style==Graph::VerticalBars || style==Graph::HorizontalBars || style==Graph::Histogram || style == Graph::Pie || style == Graph::Box) ? 1 : 0; From d745453a1eece4a45a21867d5b97e1dc47b43bf9 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Wed, 10 Oct 2018 22:29:26 +0200 Subject: [PATCH 05/12] Avoid defining additional color variables --- libscidavis/src/ColorButton.h | 2 +- libscidavis/src/PlotDialog.cpp | 35 +++++++++++++++++----------------- libscidavis/src/PlotDialog.h | 8 ++++---- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libscidavis/src/ColorButton.h b/libscidavis/src/ColorButton.h index 3c9cc191d..24a072f21 100644 --- a/libscidavis/src/ColorButton.h +++ b/libscidavis/src/ColorButton.h @@ -75,7 +75,7 @@ class ColorButton : public QWidget signals: //! Signal clicked: This is emitted when the selection button is clicked void clicked(); - void changed(const QColor &); + void changed(QColor); protected: //! Initialize the widget (called from constructor) diff --git a/libscidavis/src/PlotDialog.cpp b/libscidavis/src/PlotDialog.cpp index c3f48cd99..60859fb7e 100644 --- a/libscidavis/src/PlotDialog.cpp +++ b/libscidavis/src/PlotDialog.cpp @@ -362,9 +362,9 @@ void PlotDialog::initLayerPage() connect(boxCanvasTransparency, SIGNAL(valueChanged(int)), this, SLOT(updateCanvasTransparency(int))); connect(boxAntialiasing, SIGNAL(toggled(bool)), this, SLOT(updateAntialiasing(bool))); connect(boxMargin, SIGNAL(valueChanged (int)), this, SLOT(changeMargin(int))); - connect(boxBorderColor, SIGNAL(changed(const QColor &)), this, SLOT(pickBorderColor(const QColor &))); - connect(boxBackgroundColor, SIGNAL(changed(const QColor &)), this, SLOT(pickBackgroundColor(const QColor &))); - connect(boxCanvasColor, SIGNAL(changed(const QColor &)), this, SLOT(pickCanvasColor(const QColor &))); + connect(boxBorderColor, SIGNAL(changed(QColor)), this, SLOT(pickBorderColor(QColor))); + connect(boxBackgroundColor, SIGNAL(changed(QColor)), this, SLOT(pickBackgroundColor(QColor))); + connect(boxCanvasColor, SIGNAL(changed(QColor)), this, SLOT(pickCanvasColor(QColor))); connect(boxBorderWidth,SIGNAL(valueChanged (int)), this, SLOT(updateBorder(int))); } @@ -891,6 +891,7 @@ void PlotDialog::initErrorsPage() connect(plusBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsPlus())); connect(minusBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsMinus())); connect(throughBox, SIGNAL(clicked()), this, SLOT(changeErrorBarsThrough())); + connect(colorBox, SIGNAL(changed(QColor)), this, SLOT(pickErrorBarsColor(QColor))); } void PlotDialog::initHistogramPage() @@ -1232,7 +1233,7 @@ void PlotDialog::changeErrorBarsType() throughBox->isChecked()); } -void PlotDialog::pickErrorBarsColor(const QColor& color) +void PlotDialog::pickErrorBarsColor(QColor color) { CurveTreeItem *item = (CurveTreeItem *)listBox->currentItem(); if (!item) @@ -1662,10 +1663,10 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) xBox->setChecked(err->xErrors()); widthBox->setEditText(QString::number(err->width())); capBox->setEditText(QString::number(err->capLength())); - colorBox->setColor(err->color()); throughBox->setChecked(err->throughSymbol()); plusBox->setChecked(err->plusSide()); minusBox->setChecked(err->minusSide()); + colorBox->setColor(err->color()); } } @@ -2336,9 +2337,8 @@ void PlotDialog::updateCanvasTransparency(int alpha) } } -void PlotDialog::pickCanvasColor(const QColor& c) +void PlotDialog::pickCanvasColor(QColor c) { - QColor color = c; if (c.alpha() != boxCanvasTransparency->value()) { boxCanvasTransparency->setValue(c.alpha()); @@ -2351,8 +2351,8 @@ void PlotDialog::pickCanvasColor(const QColor& c) Graph* g=(Graph*)allPlots.at(i); if (g) { - color.setAlpha(boxCanvasTransparency->value()); - g->setCanvasBackground(color); + c.setAlpha(boxCanvasTransparency->value()); + g->setCanvasBackground(c); g->replot(); } } @@ -2365,16 +2365,15 @@ void PlotDialog::pickCanvasColor(const QColor& c) Graph *g = item->graph(); if (g) { - color.setAlpha(boxCanvasTransparency->value()); - g->setCanvasBackground(color); + c.setAlpha(boxCanvasTransparency->value()); + g->setCanvasBackground(c); g->replot(); } } } -void PlotDialog::pickBackgroundColor(const QColor& c) +void PlotDialog::pickBackgroundColor(QColor c) { - QColor color = c; if (c.alpha() != boxBackgroundTransparency->value()) { boxBackgroundTransparency->setValue(c.alpha()); @@ -2387,8 +2386,8 @@ void PlotDialog::pickBackgroundColor(const QColor& c) Graph* g=(Graph*)allPlots.at(i); if (g) { - color.setAlpha(boxBackgroundTransparency->value()); - g->setBackgroundColor(color); + c.setAlpha(boxBackgroundTransparency->value()); + g->setBackgroundColor(c); g->replot(); } } @@ -2401,14 +2400,14 @@ void PlotDialog::pickBackgroundColor(const QColor& c) Graph *g = item->graph(); if (g) { - color.setAlpha(boxBackgroundTransparency->value()); - g->setBackgroundColor(color); + c.setAlpha(boxBackgroundTransparency->value()); + g->setBackgroundColor(c); g->replot(); } } } -void PlotDialog::pickBorderColor(const QColor& c) +void PlotDialog::pickBorderColor(QColor c) { if (boxAll->isChecked()) { diff --git a/libscidavis/src/PlotDialog.h b/libscidavis/src/PlotDialog.h index c5b3aafb7..d504182d1 100644 --- a/libscidavis/src/PlotDialog.h +++ b/libscidavis/src/PlotDialog.h @@ -94,7 +94,7 @@ class PlotDialog : public QDialog void removeSelectedCurve(); /******* error bars options **************/ - void pickErrorBarsColor(const QColor &); + void pickErrorBarsColor(QColor); void changeErrorBarsType(); void changeErrorBarsPlus(); void changeErrorBarsMinus(); @@ -123,9 +123,9 @@ class PlotDialog : public QDialog void updateCanvasTransparency(int alpha); void updateAntialiasing(bool on); void updateBorder(int width); - void pickBackgroundColor(const QColor &); - void pickCanvasColor(const QColor &); - void pickBorderColor(const QColor &); + void pickBackgroundColor(QColor); + void pickCanvasColor(QColor); + void pickBorderColor(QColor); void changeMargin(int); void setTitlesFont(); void setAxesLabelsFont(); From 1cd7434f6721b544a4001999f0f9994ad1284938 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Wed, 10 Oct 2018 22:30:34 +0200 Subject: [PATCH 06/12] Replace macro by inline function --- libscidavis/src/ColorButton.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libscidavis/src/ColorButton.h b/libscidavis/src/ColorButton.h index 24a072f21..abe1cedc7 100644 --- a/libscidavis/src/ColorButton.h +++ b/libscidavis/src/ColorButton.h @@ -36,9 +36,9 @@ class QHBoxLayout; class QFrame; #if QT_VERSION >= 0x050000 -#define COLORNAME( c ) c.name(QColor::HexArgb) +static inline QString COLORNAME( QColor c ) { return c.name(QColor::HexArgb); } #else -#define COLORNAME( c ) ('#'+QString::number(c.rgba(),16)) +static inline QString COLORNAME( QColor c ) { return ('#'+QString::number(c.rgba(),16)); } #endif //! A button used for color selection From ea7252c0b32c5c897e860e65ab1f826ec3b3ba13 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Wed, 10 Oct 2018 23:38:13 +0200 Subject: [PATCH 07/12] Additional basic colors --- libscidavis/src/ColorButton.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/libscidavis/src/ColorButton.cpp b/libscidavis/src/ColorButton.cpp index 925445982..33054b5cc 100644 --- a/libscidavis/src/ColorButton.cpp +++ b/libscidavis/src/ColorButton.cpp @@ -59,6 +59,31 @@ const QColor ColorButton::colors[] = { QColor("#80FFFF"), QColor("#FF80FF"), QColor(Qt::darkGray), + // additional colors from figure 6 in doi:10.1016/j.csda.2008.11.033 + QColor("#023fa5"), + QColor("#4a6fe3"), + QColor("#11c638"), + QColor("#0fcfc0"), + QColor("#8e063b"), + QColor("#d33f6a"), + QColor("#ef9708"), + QColor("#f79cd4"), + QColor("#7d87b9"), + QColor("#8595e1"), + QColor("#8dd593"), + QColor("#9cded6"), + QColor("#bb7784"), + QColor("#e07b91"), + QColor("#f0b98d"), + QColor("#f6c4e1"), + QColor("#bec1d4"), + QColor("#b5bbe3"), + QColor("#c6dec7"), + QColor("#d5eae7"), + QColor("#d6bcc0"), + QColor("#e6afb9"), + QColor("#ead3c6"), + QColor("#f3e1eb"), }; const unsigned int ColorButton::colors_count=sizeof(colors)/sizeof(colors[0]); @@ -70,11 +95,14 @@ ColorButton::ColorButton(QWidget *parent) : QWidget(parent) void ColorButton::init() { + // QColorDialog has 48 basic colors in a 6x8 grid. Using: + // for (int i=0; i < colors_count; i++) {QColorDialog::setStandardColor(i, colors[i].rgb());}; + // arranges the colors in columns of 6. Instead arrange them in rows of 8 colors each. for (int i=0; i<8; i++) { - for (int j=0; j<3; j++) + for (int j=0; j<6; j++) { - QColorDialog::setStandardColor(6*i+j, colors[i+8*j].rgb()); + QColorDialog::setStandardColor(j+6*i, colors[i+8*j].rgb()); } } const int btn_size = 28; From 7a2ea46b2b4bd5b7ab0f68780989035e771c45c3 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Thu, 11 Oct 2018 23:37:53 +0200 Subject: [PATCH 08/12] Avoid possible crash --- libscidavis/src/ColorButton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libscidavis/src/ColorButton.cpp b/libscidavis/src/ColorButton.cpp index 33054b5cc..5738245e9 100644 --- a/libscidavis/src/ColorButton.cpp +++ b/libscidavis/src/ColorButton.cpp @@ -145,7 +145,7 @@ QColor ColorButton::color() const unsigned int ColorButton::colorIndex(const QColor& c) { const QColor *ite = std::find(std::begin(colors), std::end(colors), c); - if (ite->isValid()) + if (ite!=std::end(colors) && ite->isValid()) return (ite - colors); else return c.rgba(); @@ -168,7 +168,7 @@ QColor ColorButton::color(unsigned int colorIndex) bool ColorButton::isValidColor(const QColor& c) { const QColor *ite = std::find(std::begin(colors), std::end(colors), c); - return (ite->isValid()); + return (ite!=std::end(colors) && ite->isValid()); } QSize ColorButton::sizeHint () const From d3bee93ac5803c6e4c1c334a0cababb3389bf024 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Thu, 11 Oct 2018 23:39:32 +0200 Subject: [PATCH 09/12] Remove references to ColorBox --- libscidavis/sourcefiles.pri | 2 -- libscidavis/src/scidavis.sip | 34 +++++++++++++++++----------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libscidavis/sourcefiles.pri b/libscidavis/sourcefiles.pri index dae46b365..7a79811ad 100644 --- a/libscidavis/sourcefiles.pri +++ b/libscidavis/sourcefiles.pri @@ -50,7 +50,6 @@ HEADERS += src/ApplicationWindow.h \ src/Matrix.h \ src/DataSetDialog.h \ src/MyParser.h \ - src/ColorBox.h \ src/SymbolBox.h \ src/PatternBox.h \ src/SymbolDialog.h \ @@ -157,7 +156,6 @@ SOURCES += src/ApplicationWindow.cpp \ src/VectorCurve.cpp \ src/Matrix.cpp \ src/MyParser.cpp\ - src/ColorBox.cpp \ src/SymbolBox.cpp \ src/PatternBox.cpp \ src/SymbolDialog.cpp \ diff --git a/libscidavis/src/scidavis.sip b/libscidavis/src/scidavis.sip index 13b9179e6..10884ddfb 100644 --- a/libscidavis/src/scidavis.sip +++ b/libscidavis/src/scidavis.sip @@ -647,7 +647,7 @@ class QwtSymbol { %TypeHeaderCode #include -#include "ColorBox.h" +#include "ColorButton.h" %End public: enum Style @@ -703,10 +703,10 @@ class QwtSymbol void setColor(int color); %MethodCode QPen pen = sipCpp->pen(); - pen.setColor(ColorBox::color(a0)); + pen.setColor(ColorButton::color(a0)); sipCpp->setPen(pen); QBrush brush = sipCpp->brush(); - brush.setColor(ColorBox::color(a0)); + brush.setColor(ColorButton::color(a0)); sipCpp->setBrush(brush); %End void setOutlineColor(const QColor& color); @@ -718,7 +718,7 @@ class QwtSymbol void setOutlineColor(int color); %MethodCode QPen pen = sipCpp->pen(); - pen.setColor(ColorBox::color(a0)); + pen.setColor(ColorButton::color(a0)); sipCpp->setPen(pen); %End void setFillColor(const QColor& color); @@ -730,7 +730,7 @@ class QwtSymbol void setFillColor(int color); %MethodCode QBrush brush = sipCpp->brush(); - brush.setColor(ColorBox::color(a0)); + brush.setColor(ColorButton::color(a0)); sipCpp->setBrush(brush); %End @@ -782,10 +782,10 @@ class QwtPlotCurve void setColor(int color); %MethodCode QPen pen = sipCpp->pen(); - pen.setColor(ColorBox::color(a0)); + pen.setColor(ColorButton::color(a0)); sipCpp->setPen(pen); QBrush brush = sipCpp->brush(); - brush.setColor(ColorBox::color(a0)); + brush.setColor(ColorButton::color(a0)); sipCpp->setBrush(brush); %End void setOutlineColor(const QColor& color); @@ -797,7 +797,7 @@ class QwtPlotCurve void setOutlineColor(int color); %MethodCode QPen pen = sipCpp->pen(); - pen.setColor(ColorBox::color(a0)); + pen.setColor(ColorButton::color(a0)); sipCpp->setPen(pen); %End void setFillColor(const QColor& color); @@ -809,7 +809,7 @@ class QwtPlotCurve void setFillColor(int color); %MethodCode QBrush brush = sipCpp->brush(); - brush.setColor(ColorBox::color(a0)); + brush.setColor(ColorButton::color(a0)); sipCpp->setBrush(brush); %End void setFillStyle(Qt::BrushStyle style); @@ -908,7 +908,7 @@ class Graph : QWidget /PyName=Layer/ %TypeHeaderCode #include "src/Graph.h" #include "src/Legend.h" -#include "src/ColorBox.h" +#include "src/ColorButton.h" #include "src/FunctionCurve.h" #include "src/DataPointPicker.h" #include @@ -1159,7 +1159,7 @@ class ApplicationWindow: QMainWindow { %TypeHeaderCode #include "src/ApplicationWindow.h" -#include "src/ColorBox.h" +#include "src/ColorButton.h" #include %End %ConvertToSubClassCode @@ -1257,14 +1257,14 @@ public: for (int c =0; c < sipRes->activeGraph()->curves(); c++) { QwtPlotCurve *curve = sipRes->activeGraph()->curve(c); QPen pen = curve->pen(); - pen.setColor(ColorBox::color(a3)); + pen.setColor(ColorButton::color(a3)); curve->setPen(pen); QwtSymbol symbol = curve->symbol(); pen = symbol.pen(); - pen.setColor(ColorBox::color(a3)); + pen.setColor(ColorButton::color(a3)); symbol.setPen(pen); QBrush brush = symbol.brush(); - brush.setColor(ColorBox::color(a3)); + brush.setColor(ColorButton::color(a3)); symbol.setBrush(brush); curve->setSymbol(symbol); } @@ -1283,14 +1283,14 @@ public: if (a3 >= 0) { QwtPlotCurve * c = sipRes->activeGraph()->curve(0); QPen pen = c->pen(); - pen.setColor(ColorBox::color(a3)); + pen.setColor(ColorButton::color(a3)); c->setPen(pen); QwtSymbol symbol = c->symbol(); pen = symbol.pen(); - pen.setColor(ColorBox::color(a3)); + pen.setColor(ColorButton::color(a3)); symbol.setPen(pen); QBrush brush = symbol.brush(); - brush.setColor(ColorBox::color(a3)); + brush.setColor(ColorButton::color(a3)); symbol.setBrush(brush); c->setSymbol(symbol); } From bd0f884d431a0d8a65730d5fc570c94428103acc Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Fri, 12 Oct 2018 09:18:25 +0200 Subject: [PATCH 10/12] Remove use of colorIndex where possible --- libscidavis/src/ApplicationWindow.cpp | 2 +- libscidavis/src/ApplicationWindow.h | 2 +- libscidavis/src/ConfigDialog.cpp | 2 +- libscidavis/src/Convolution.cpp | 2 +- libscidavis/src/Correlation.cpp | 2 +- libscidavis/src/ExpDecayDialog.cpp | 2 +- libscidavis/src/FFT.cpp | 2 +- libscidavis/src/Filter.cpp | 8 ++++---- libscidavis/src/Filter.h | 4 ++-- libscidavis/src/FilterDialog.cpp | 2 +- libscidavis/src/Fit.cpp | 4 ++-- libscidavis/src/FitDialog.cpp | 2 +- libscidavis/src/InterpolationDialog.cpp | 2 +- libscidavis/src/MultiPeakFit.cpp | 8 ++++---- libscidavis/src/MultiPeakFit.h | 5 +++-- libscidavis/src/PolynomFitDialog.cpp | 2 +- libscidavis/src/SmoothCurveDialog.cpp | 2 +- 17 files changed, 27 insertions(+), 26 deletions(-) diff --git a/libscidavis/src/ApplicationWindow.cpp b/libscidavis/src/ApplicationWindow.cpp index 12a2d4961..33a53f709 100644 --- a/libscidavis/src/ApplicationWindow.cpp +++ b/libscidavis/src/ApplicationWindow.cpp @@ -4419,7 +4419,7 @@ void ApplicationWindow::readSettings() generateUniformFitPoints = settings.value("/GenerateFunction", true).toBool(); fitPoints = settings.value("/Points", 100).toInt(); generatePeakCurves = settings.value("/GeneratePeakCurves", true).toBool(); - peakCurvesColor = settings.value("/PeaksColor", 2).toInt();//green color + peakCurvesColor = settings.value("/PeaksColor", "#00ff00").value();//green color fit_scale_errors = settings.value("/ScaleErrors", false).toBool(); d_2_linear_fit_points = settings.value("/TwoPointsLinearFit", true).toBool(); settings.endGroup(); // Fitting diff --git a/libscidavis/src/ApplicationWindow.h b/libscidavis/src/ApplicationWindow.h index 5f75a15a3..036841147 100644 --- a/libscidavis/src/ApplicationWindow.h +++ b/libscidavis/src/ApplicationWindow.h @@ -931,7 +931,7 @@ private slots: bool d_extended_open_dialog; bool generateUniformFitPoints; bool generatePeakCurves; - int peakCurvesColor; + QColor peakCurvesColor; //! User defined size for the Add/Remove curves dialog QSize d_add_curves_dialog_size; diff --git a/libscidavis/src/ConfigDialog.cpp b/libscidavis/src/ConfigDialog.cpp index 3cde56dc6..efbcc6f43 100644 --- a/libscidavis/src/ConfigDialog.cpp +++ b/libscidavis/src/ConfigDialog.cpp @@ -1183,7 +1183,7 @@ void ConfigDialog::apply() app->fitPoints = generatePointsBox->value(); app->generateUniformFitPoints = generatePointsBtn->isChecked(); app->generatePeakCurves = groupBoxMultiPeak->isChecked(); - app->peakCurvesColor = boxPeaksColor->colorIndex(boxPeaksColor->color()); + app->peakCurvesColor = boxPeaksColor->color(); app->fit_scale_errors = scaleErrorsBox->isChecked(); app->d_2_linear_fit_points = linearFit2PointsBox->isChecked(); app->saveSettings(); diff --git a/libscidavis/src/Convolution.cpp b/libscidavis/src/Convolution.cpp index fc3f5dca3..aeaa581e4 100644 --- a/libscidavis/src/Convolution.cpp +++ b/libscidavis/src/Convolution.cpp @@ -162,7 +162,7 @@ void Convolution::addResultCurve() DataCurve *c = new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(x_temp, d_x, d_n); - c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); + c->setPen(QPen(d_curveColor, 1)); ml->activeGraph()->insertPlotItem(c, Graph::Line); ml->activeGraph()->updatePlot(); } diff --git a/libscidavis/src/Correlation.cpp b/libscidavis/src/Correlation.cpp index ea5403670..a342034e5 100644 --- a/libscidavis/src/Correlation.cpp +++ b/libscidavis/src/Correlation.cpp @@ -175,7 +175,7 @@ void Correlation::addResultCurve() DataCurve *c = new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(&x_temp[0], &y_temp[0], rows); - c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); + c->setPen(QPen(d_curveColor, 1)); ml->activeGraph()->insertPlotItem(c, Graph::Line); ml->activeGraph()->updatePlot(); } diff --git a/libscidavis/src/ExpDecayDialog.cpp b/libscidavis/src/ExpDecayDialog.cpp index 230675eb3..213a1b44e 100644 --- a/libscidavis/src/ExpDecayDialog.cpp +++ b/libscidavis/src/ExpDecayDialog.cpp @@ -232,7 +232,7 @@ void ExpDecayDialog::fit() if (fitter->setDataFromCurve(boxName->currentText(), boxStart->text().toDouble(), c->maxXValue())) { - fitter->setColor(ColorButton::colorIndex(btnColor->color())); + fitter->setColor(btnColor->color()); fitter->scaleErrors(app->fit_scale_errors); fitter->setOutputPrecision(app->fit_output_precision); fitter->generateFunction(app->generateUniformFitPoints, app->fitPoints); diff --git a/libscidavis/src/FFT.cpp b/libscidavis/src/FFT.cpp index 7c06b1e17..e109bbb46 100644 --- a/libscidavis/src/FFT.cpp +++ b/libscidavis/src/FFT.cpp @@ -175,7 +175,7 @@ void FFT::output(QList columns) Graph* g = ml->activeGraph(); if ( g ) { - g->setCurvePen(0, QPen(ColorButton::color(d_curveColorIndex), 1)); + g->setCurvePen(0, QPen(d_curveColor, 1)); Plot* plot = g->plotWidget(); plot->setTitle(QString()); diff --git a/libscidavis/src/Filter.cpp b/libscidavis/src/Filter.cpp index 06d02113c..776325164 100644 --- a/libscidavis/src/Filter.cpp +++ b/libscidavis/src/Filter.cpp @@ -62,7 +62,7 @@ Filter::Filter( ApplicationWindow *parent, Table *t, QString name) void Filter::init() { d_n = 0; - d_curveColorIndex = 1; + d_curveColor = ColorButton::color(1); d_tolerance = 1e-4; d_points = 100; d_max_iterations = 1000; @@ -186,11 +186,11 @@ void Filter::setColor(const QString& colorName) { QMessageBox::critical((ApplicationWindow *)parent(), tr("Color Name Error"), tr("The color name '%1' is not valid, a default color (red) will be used instead!").arg(colorName)); - d_curveColorIndex = 1; + d_curveColor = ColorButton::color(1); return; } - d_curveColorIndex = ColorButton::colorIndex(c); + d_curveColor = c; } void Filter::showLegend() @@ -317,7 +317,7 @@ QwtPlotCurve* Filter::addResultCurve(double *x, double *y) DataCurve *c = new DataCurve(t, tableName + "_" + xCol->name(), tableName + "_" + yCol->name()); c->setData(x, y, d_points); - c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); + c->setPen(QPen(d_curveColor, 1)); d_graph->insertPlotItem(c, Graph::Line); d_graph->updatePlot(); diff --git a/libscidavis/src/Filter.h b/libscidavis/src/Filter.h index 6a058d7b2..6e3eede3d 100644 --- a/libscidavis/src/Filter.h +++ b/libscidavis/src/Filter.h @@ -61,7 +61,7 @@ class Filter : public QObject void setTolerance(double eps){d_tolerance = eps;}; //! Sets the color of the output fit curve. - void setColor(unsigned int colorId){d_curveColorIndex = colorId;}; + void setColor(QColor colorId){d_curveColor = colorId;}; //! Sets the color of the output fit curve. Provided for convenience. To be used in scripts only! void setColor(const QString& colorName); @@ -139,7 +139,7 @@ class Filter : public QObject int d_points; //! Color index of the result curve - unsigned int d_curveColorIndex; + QColor d_curveColor; //! Maximum number of iterations per fit int d_max_iterations; diff --git a/libscidavis/src/FilterDialog.cpp b/libscidavis/src/FilterDialog.cpp index 445a2f907..7cfee4c29 100644 --- a/libscidavis/src/FilterDialog.cpp +++ b/libscidavis/src/FilterDialog.cpp @@ -179,7 +179,7 @@ else if (filter_type == FFTFilter::BandBlock) else f->setCutoff(from); -f->setColor(ColorButton::colorIndex(btnColor->color())); +f->setColor(btnColor->color()); f->run(); delete f; } diff --git a/libscidavis/src/Fit.cpp b/libscidavis/src/Fit.cpp index 80605fc5f..51f50747b 100644 --- a/libscidavis/src/Fit.cpp +++ b/libscidavis/src/Fit.cpp @@ -55,7 +55,7 @@ scripted(ScriptingLangManager::newEnv("muParser", parent)) { d_p = 0; d_n = 0; - d_curveColorIndex = 1; + d_curveColor = ColorButton::color(1); d_solver = ScaledLevenbergMarquardt; d_tolerance = 1e-4; d_gen_function = true; @@ -626,7 +626,7 @@ void Fit::insertFitFunctionCurve(const QString& name, double *x, double *y, int { QString title = d_graph->generateFunctionName(name); FunctionCurve *c = new FunctionCurve((ApplicationWindow *)parent(), FunctionCurve::Normal, title); - c->setPen(QPen(ColorButton::color(d_curveColorIndex), penWidth)); + c->setPen(QPen(d_curveColor, penWidth)); c->setData(x, y, d_points); c->setRange(d_x[0], d_x[d_n-1]); diff --git a/libscidavis/src/FitDialog.cpp b/libscidavis/src/FitDialog.cpp index d5d0cad01..80c8a1946 100644 --- a/libscidavis/src/FitDialog.cpp +++ b/libscidavis/src/FitDialog.cpp @@ -1211,7 +1211,7 @@ void FitDialog::accept() d_fitter->setTolerance (eps); d_fitter->setAlgorithm((Fit::Algorithm)boxAlgorithm->currentIndex()); - d_fitter->setColor(ColorButton::colorIndex(btnColor->color())); + d_fitter->setColor(btnColor->color()); d_fitter->generateFunction(generatePointsBtn->isChecked(), generatePointsBox->value()); d_fitter->setMaximumIterations(boxPoints->value()); d_fitter->scaleErrors(scaleErrorsBox->isChecked()); diff --git a/libscidavis/src/InterpolationDialog.cpp b/libscidavis/src/InterpolationDialog.cpp index 25e7bd8f2..de0d1a158 100644 --- a/libscidavis/src/InterpolationDialog.cpp +++ b/libscidavis/src/InterpolationDialog.cpp @@ -151,7 +151,7 @@ if (from >= to) Interpolation *i = new Interpolation((ApplicationWindow *)this->parent(), graph, curve, from, to, boxMethod->currentIndex()); i->setOutputPoints(boxPoints->value()); -i->setColor(ColorButton::colorIndex(btnColor->color())); +i->setColor(btnColor->color()); i->run(); delete i; } diff --git a/libscidavis/src/MultiPeakFit.cpp b/libscidavis/src/MultiPeakFit.cpp index 64abe3031..28dcc1e97 100644 --- a/libscidavis/src/MultiPeakFit.cpp +++ b/libscidavis/src/MultiPeakFit.cpp @@ -213,7 +213,7 @@ void MultiPeakFit::insertPeakFunctionCurve(double *x, double *y, int peak) QString title = tr("Peak") + QString::number(++index); FunctionCurve *c = new FunctionCurve((ApplicationWindow *)parent(), FunctionCurve::Normal, title); - c->setPen(QPen(ColorButton::color(d_peaks_color), 1)); + c->setPen(QPen(d_peaks_color, 1)); c->setData(x, y, d_points); c->setRange(d_x[0], d_x[d_n-1]); @@ -334,9 +334,9 @@ void MultiPeakFit::generateFitCurve(const vector& par) label = tableName + "_2"; DataCurve *c = new DataCurve(t, tableName + "_" + columns.at(0)->name(), label); if (d_peaks > 1) - c->setPen(QPen(ColorButton::color(d_curveColorIndex), 2)); + c->setPen(QPen(d_curveColor, 2)); else - c->setPen(QPen(ColorButton::color(d_curveColorIndex), 1)); + c->setPen(QPen(d_curveColor, 1)); c->setData(X, Y, d_points); d_graph->insertPlotItem(c, Graph::Line); d_graph->addFitCurve(c); @@ -350,7 +350,7 @@ void MultiPeakFit::generateFitCurve(const vector& par) label = tableName + "_" + tr("peak") + QString::number(i+1); c = new DataCurve(t, tableName + "_" + columns.at(0)->name(), label); - c->setPen(QPen(ColorButton::color(d_peaks_color), 1)); + c->setPen(QPen(d_peaks_color, 1)); c->setData(X, Y, d_points); d_graph->insertPlotItem(c, Graph::Line); d_graph->addFitCurve(c); diff --git a/libscidavis/src/MultiPeakFit.h b/libscidavis/src/MultiPeakFit.h index 98b2f1b07..bbb57f86b 100644 --- a/libscidavis/src/MultiPeakFit.h +++ b/libscidavis/src/MultiPeakFit.h @@ -29,6 +29,7 @@ #ifndef MULTIPEAKFIT_H #define MULTIPEAKFIT_H +#include #include "Fit.h" class MultiPeakFit : public Fit @@ -43,7 +44,7 @@ class MultiPeakFit : public Fit void setNumPeaks(int n); void enablePeakCurves(bool on){generate_peak_curves = on;}; - void setPeakCurvesColor(int colorIndex){d_peaks_color = colorIndex;}; + void setPeakCurvesColor(QColor color){d_peaks_color = color;}; static QString generateFormula(int order, PeakProfile profile); static QStringList generateParameterList(int order); @@ -68,7 +69,7 @@ class MultiPeakFit : public Fit bool generate_peak_curves; //! Color index for the peak curves - int d_peaks_color; + QColor d_peaks_color; //! The peak profile PeakProfile d_profile; diff --git a/libscidavis/src/PolynomFitDialog.cpp b/libscidavis/src/PolynomFitDialog.cpp index 3250d9a33..ec9638cba 100644 --- a/libscidavis/src/PolynomFitDialog.cpp +++ b/libscidavis/src/PolynomFitDialog.cpp @@ -115,7 +115,7 @@ void PolynomFitDialog::fit() PolynomialFit *fitter = new PolynomialFit(app, graph, boxOrder->value(), boxShowFormula->isChecked()); if (fitter->setDataFromCurve(curveName, boxStart->text().toDouble(), boxEnd->text().toDouble())) { - fitter->setColor(ColorButton::colorIndex(btnColor->color())); + fitter->setColor(btnColor->color()); fitter->scaleErrors(app->fit_scale_errors); fitter->setOutputPrecision(app->fit_output_precision); fitter->generateFunction(app->generateUniformFitPoints, app->fitPoints); diff --git a/libscidavis/src/SmoothCurveDialog.cpp b/libscidavis/src/SmoothCurveDialog.cpp index 63a0197c7..2617e1181 100644 --- a/libscidavis/src/SmoothCurveDialog.cpp +++ b/libscidavis/src/SmoothCurveDialog.cpp @@ -127,7 +127,7 @@ void SmoothCurveDialog::smooth() else sf->setSmoothPoints(boxPointsLeft->value()); - sf->setColor(ColorButton::colorIndex(btnColor->color())); + sf->setColor(btnColor->color()); sf->run(); delete sf; } From 1363d50d32ccfced06e9fa3fb483dcab359b5aae Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Fri, 12 Oct 2018 09:55:34 +0200 Subject: [PATCH 11/12] Save colors as hex values in .sciproj files --- libscidavis/src/Graph.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libscidavis/src/Graph.cpp b/libscidavis/src/Graph.cpp index 9b6413ed1..51e335f70 100644 --- a/libscidavis/src/Graph.cpp +++ b/libscidavis/src/Graph.cpp @@ -2339,23 +2339,23 @@ QString Graph::saveCurveLayout(int index) s+="6\t"; else s+=QString::number(c->style())+"\t"; - s+=QString::number(ColorButton::colorIndex(c->pen().color()))+"\t"; + s+=COLORNAME(c->pen().color())+"\t"; s+=QString::number(c->pen().style()-1)+"\t"; s+=QString::number(c->pen().width())+"\t"; const QwtSymbol symbol = c->symbol(); s+=QString::number(symbol.size().width())+"\t"; s+=QString::number(SymbolBox::symbolIndex(symbol.style()))+"\t"; - s+=QString::number(ColorButton::colorIndex(symbol.pen().color()))+"\t"; + s+=COLORNAME(symbol.pen().color())+"\t"; if (symbol.brush().style() != Qt::NoBrush) - s+=QString::number(ColorButton::colorIndex(symbol.brush().color()))+"\t"; + s+=COLORNAME(symbol.brush().color())+"\t"; else s+=QString::number(-1)+"\t"; bool filled = c->brush().style() == Qt::NoBrush ? false : true; s+=QString::number(filled)+"\t"; - s+=QString::number(ColorButton::colorIndex(c->brush().color()))+"\t"; + s+=COLORNAME(c->brush().color())+"\t"; s+=QString::number(PatternBox::patternIndex(c->brush().style()))+"\t"; if (style <= LineSymbols || style == Box) s+=QString::number(symbol.pen().width())+"\t"; From 52acd149887d6da2b520763d6e2f83b694396426 Mon Sep 17 00:00:00 2001 From: Miquel Garriga Date: Fri, 12 Oct 2018 11:26:06 +0200 Subject: [PATCH 12/12] Save color settings as hex values --- libscidavis/src/ApplicationWindow.cpp | 56 +++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/libscidavis/src/ApplicationWindow.cpp b/libscidavis/src/ApplicationWindow.cpp index 33a53f709..bda354e01 100644 --- a/libscidavis/src/ApplicationWindow.cpp +++ b/libscidavis/src/ApplicationWindow.cpp @@ -4246,10 +4246,10 @@ void ApplicationWindow::readSettings() settings.endGroup(); // Dialogs settings.beginGroup("/Colors"); - workspaceColor = settings.value("/Workspace","darkGray").value(); + workspaceColor = QColor(settings.value("/Workspace","darkGray").toString()); // see http://doc.trolltech.com/4.2/qvariant.html for instructions on qcolor <-> qvariant conversion - panelsColor = settings.value("/Panels","#ffffff").value(); - panelsTextColor = settings.value("/PanelsText","#000000").value(); + panelsColor = QColor(settings.value("/Panels","#ffffff").toString()); + panelsTextColor = QColor(settings.value("/PanelsText","#000000").toString()); settings.endGroup(); // Colors settings.beginGroup("/Paths"); @@ -4316,9 +4316,9 @@ void ApplicationWindow::readSettings() } settings.beginGroup("/Colors"); - tableBkgdColor = settings.value("/Background","#ffffff").value(); - tableTextColor = settings.value("/Text","#000000").value(); - tableHeaderColor = settings.value("/Header","#000000").value(); + tableBkgdColor = QColor(settings.value("/Background","#ffffff").toString()); + tableTextColor = QColor(settings.value("/Text","#000000").toString()); + tableHeaderColor = QColor(settings.value("/Header","#000000").toString()); settings.endGroup(); // Colors settings.endGroup(); /* --------------- end group Tables ------------------------ */ @@ -4365,14 +4365,14 @@ void ApplicationWindow::readSettings() settings.beginGroup("/Legend"); legendFrameStyle = settings.value("/FrameStyle", Legend::Line).toInt(); - legendTextColor = settings.value("/TextColor", "#000000").value(); //default color Qt::black - legendBackground = settings.value("/BackgroundColor", "#ffffff").value(); //default color Qt::white + legendTextColor = QColor(settings.value("/TextColor", "#000000").toString()); //default color Qt::black + legendBackground = QColor(settings.value("/BackgroundColor", "#ffffff").toString()); //default color Qt::white legendBackground.setAlpha(settings.value("/Transparency", 0).toInt()); // transparent by default; settings.endGroup(); // Legend settings.beginGroup("/Arrows"); defaultArrowLineWidth = settings.value("/Width", 1).toInt(); - defaultArrowColor = settings.value("/Color", "#000000").value();//default color Qt::black + defaultArrowColor = QColor(settings.value("/Color", "#000000").toString());//default color Qt::black defaultArrowHeadLength = settings.value("/HeadLength", 4).toInt(); defaultArrowHeadAngle = settings.value("/HeadAngle", 45).toInt(); defaultArrowHeadFill = settings.value("/HeadFill", true).toBool(); @@ -4399,14 +4399,14 @@ void ApplicationWindow::readSettings() } settings.beginGroup("/Colors"); - plot3DColors << QColor(settings.value("/MaxData", "blue").value()).name(); - plot3DColors << QColor(settings.value("/Labels", "#000000").value()).name(); - plot3DColors << QColor(settings.value("/Mesh", "#000000").value()).name(); - plot3DColors << QColor(settings.value("/Grid", "#000000").value()).name(); - plot3DColors << QColor(settings.value("/MinData", "red").value()).name(); - plot3DColors << QColor(settings.value("/Numbers", "#000000").value()).name(); - plot3DColors << QColor(settings.value("/Axes", "#000000").value()).name(); - plot3DColors << QColor(settings.value("/Background", "#ffffff").value()).name(); + plot3DColors << settings.value("/MaxData", "blue").toString(); + plot3DColors << settings.value("/Labels", "#000000").toString(); + plot3DColors << settings.value("/Mesh", "#000000").toString(); + plot3DColors << settings.value("/Grid", "#000000").toString(); + plot3DColors << settings.value("/MinData", "red").toString(); + plot3DColors << settings.value("/Numbers", "#000000").toString(); + plot3DColors << settings.value("/Axes", "#000000").toString(); + plot3DColors << settings.value("/Background", "#ffffff").toString(); settings.endGroup(); // Colors settings.endGroup(); /* ----------------- end group 3D Plots --------------------------- */ @@ -4419,7 +4419,7 @@ void ApplicationWindow::readSettings() generateUniformFitPoints = settings.value("/GenerateFunction", true).toBool(); fitPoints = settings.value("/Points", 100).toInt(); generatePeakCurves = settings.value("/GeneratePeakCurves", true).toBool(); - peakCurvesColor = settings.value("/PeaksColor", "#00ff00").value();//green color + peakCurvesColor = QColor(settings.value("/PeaksColor", "#00ff00").toString());//green color fit_scale_errors = settings.value("/ScaleErrors", false).toBool(); d_2_linear_fit_points = settings.value("/TwoPointsLinearFit", true).toBool(); settings.endGroup(); // Fitting @@ -4499,9 +4499,9 @@ void ApplicationWindow::saveSettings() settings.endGroup(); // Dialogs settings.beginGroup("/Colors"); - settings.setValue("/Workspace", workspaceColor); - settings.setValue("/Panels", panelsColor); - settings.setValue("/PanelsText", panelsTextColor); + settings.setValue("/Workspace", COLORNAME(workspaceColor)); + settings.setValue("/Panels", COLORNAME(panelsColor)); + settings.setValue("/PanelsText", COLORNAME(panelsTextColor)); settings.endGroup(); // Colors settings.beginGroup("/Paths"); @@ -4551,9 +4551,9 @@ void ApplicationWindow::saveSettings() settings.setValue("/Fonts", tableFonts); settings.beginGroup("/Colors"); - settings.setValue("/Background", tableBkgdColor); - settings.setValue("/Text", tableTextColor); - settings.setValue("/Header", tableHeaderColor); + settings.setValue("/Background", COLORNAME(tableBkgdColor)); + settings.setValue("/Text", COLORNAME(tableTextColor)); + settings.setValue("/Header", COLORNAME(tableHeaderColor)); settings.endGroup(); // Colors settings.endGroup(); /* ----------------- end group Tables ---------- */ @@ -4610,14 +4610,14 @@ void ApplicationWindow::saveSettings() settings.beginGroup("/Legend"); settings.setValue("/FrameStyle", legendFrameStyle); - settings.setValue("/TextColor", legendTextColor); - settings.setValue("/BackgroundColor", legendBackground); + settings.setValue("/TextColor", COLORNAME(legendTextColor)); + settings.setValue("/BackgroundColor", COLORNAME(legendBackground)); settings.setValue("/Transparency", legendBackground.alpha()); settings.endGroup(); // Legend settings.beginGroup("/Arrows"); settings.setValue("/Width", defaultArrowLineWidth); - settings.setValue("/Color", defaultArrowColor.name()); + settings.setValue("/Color", COLORNAME(defaultArrowColor)); settings.setValue("/HeadLength", defaultArrowHeadLength); settings.setValue("/HeadAngle", defaultArrowHeadAngle); settings.setValue("/HeadFill", defaultArrowHeadFill); @@ -4670,7 +4670,7 @@ void ApplicationWindow::saveSettings() settings.setValue("/GenerateFunction", generateUniformFitPoints); settings.setValue("/Points", fitPoints); settings.setValue("/GeneratePeakCurves", generatePeakCurves); - settings.setValue("/PeaksColor", peakCurvesColor); + settings.setValue("/PeaksColor", COLORNAME(peakCurvesColor)); settings.setValue("/ScaleErrors", fit_scale_errors); settings.setValue("/TwoPointsLinearFit", d_2_linear_fit_points); settings.endGroup(); // Fitting