Skip to content

Commit

Permalink
Merge pull request #104 from gbm19/colorenhance
Browse files Browse the repository at this point in the history
Color enhance
  • Loading branch information
highperformancecoder authored Oct 20, 2018
2 parents 1555499 + 52acd14 commit c24551e
Show file tree
Hide file tree
Showing 42 changed files with 383 additions and 355 deletions.
2 changes: 0 additions & 2 deletions libscidavis/sourcefiles.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
60 changes: 30 additions & 30 deletions libscidavis/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -4246,10 +4246,10 @@ void ApplicationWindow::readSettings()
settings.endGroup(); // Dialogs

settings.beginGroup("/Colors");
workspaceColor = settings.value("/Workspace","darkGray").value<QColor>();
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<QColor>();
panelsTextColor = settings.value("/PanelsText","#000000").value<QColor>();
panelsColor = QColor(settings.value("/Panels","#ffffff").toString());
panelsTextColor = QColor(settings.value("/PanelsText","#000000").toString());
settings.endGroup(); // Colors

settings.beginGroup("/Paths");
Expand Down Expand Up @@ -4316,9 +4316,9 @@ void ApplicationWindow::readSettings()
}

settings.beginGroup("/Colors");
tableBkgdColor = settings.value("/Background","#ffffff").value<QColor>();
tableTextColor = settings.value("/Text","#000000").value<QColor>();
tableHeaderColor = settings.value("/Header","#000000").value<QColor>();
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 ------------------------ */
Expand Down Expand Up @@ -4365,14 +4365,14 @@ void ApplicationWindow::readSettings()

settings.beginGroup("/Legend");
legendFrameStyle = settings.value("/FrameStyle", Legend::Line).toInt();
legendTextColor = settings.value("/TextColor", "#000000").value<QColor>(); //default color Qt::black
legendBackground = settings.value("/BackgroundColor", "#ffffff").value<QColor>(); //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<QColor>();//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();
Expand All @@ -4399,14 +4399,14 @@ void ApplicationWindow::readSettings()
}

settings.beginGroup("/Colors");
plot3DColors << QColor(settings.value("/MaxData", "blue").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Labels", "#000000").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Mesh", "#000000").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Grid", "#000000").value<QColor>()).name();
plot3DColors << QColor(settings.value("/MinData", "red").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Numbers", "#000000").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Axes", "#000000").value<QColor>()).name();
plot3DColors << QColor(settings.value("/Background", "#ffffff").value<QColor>()).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 --------------------------- */
Expand All @@ -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 = 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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 ---------- */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libscidavis/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 6 additions & 7 deletions libscidavis/src/AxesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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())));
}

Expand Down
7 changes: 3 additions & 4 deletions libscidavis/src/AxesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class QSpinBox;
class QTabWidget;
class QWidget;
class QStringList;
class ColorBox;
class ColorButton;
class Graph;
class TextFormatButtons;
Expand Down Expand Up @@ -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;
Expand Down
105 changes: 104 additions & 1 deletion libscidavis/src/ColorButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,83 @@
***************************************************************************/
#include "ColorButton.h"

#include <QColorDialog>
#include <QPalette>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFrame>

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),
// 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]);

ColorButton::ColorButton(QWidget *parent) : QWidget(parent)
{
init();
}

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<6; j++)
{
QColorDialog::setStandardColor(j+6*i, colors[i+8*j].rgb());
}
}
const int btn_size = 28;
selectButton = new QPushButton(QPixmap(":/palette.xpm"), QString(), this);
selectButton->setMinimumWidth(btn_size);
Expand All @@ -61,22 +126,60 @@ 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)
{
QPalette pal;
pal.setColor(QPalette::Window, c);
display->setPalette(pal);
emit changed(c);
}

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!=std::end(colors) && 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!=std::end(colors) && ite->isValid());
}

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 ) ;
}
Loading

0 comments on commit c24551e

Please sign in to comment.