2 changes: 1 addition & 1 deletion src/libkst/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ DataSource::DataSource(ObjectStore *store, QSettings *cfg, const QString& filena
interf_vector(new NotSupportedImp<DataVector>),
interf_matrix(new NotSupportedImp<DataMatrix>),
_watcher(0),
_color(NextColor::self().next())
_color(NextColor::self().current())
{
Q_UNUSED(type)
Q_UNUSED(store)
Expand Down
6 changes: 5 additions & 1 deletion src/libkst/nextcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ QColor NextColor::next() {
return QColor();
}

NextColor& NextColor::self() {
QColor NextColor::current() {
return QColor();
}

NextColor& NextColor::self() {
Q_ASSERT(NextColor::_instance);
return *NextColor::_instance;
}
Expand Down
1 change: 1 addition & 0 deletions src/libkst/nextcolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class KSTCORE_EXPORT NextColor
public:
virtual ~NextColor();
virtual QColor next() = 0;
virtual QColor current() = 0;
static NextColor& self();

protected:
Expand Down
17 changes: 14 additions & 3 deletions src/libkstapp/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,17 @@ void CommandLineParser::createCurveInPlot(VectorPtr xv, VectorPtr yv, VectorPtr
curve->setYVector(yv);
curve->setXError(0);
curve->setXMinusError(0);
curve->setColor(ColorSequence::self().next());
if (_doConsecutivePlots) {
ColorSequence::self().setIndex(0);
}
curve->setColor(ColorSequence::self().current());
if (!_doConsecutivePlots) {
ColorSequence::self().incIndex();
}
curve->setHasPoints(_usePoints);
curve->setHasLines(_useLines);
curve->setHasBars(_useBargraph);
curve->setLineWidth(dialogDefaults().value("curves/lineWidth",0).toInt());
//curve->setPointType(ptype++ % KSTPOINT_MAXTYPE);

if (ev) {
curve->setYError(ev);
Expand Down Expand Up @@ -938,7 +943,13 @@ Kst::ObjectList<Kst::Object> CommandLineParser::autoCurves(DataSourcePtr ds)
curve->setXError(0);
curve->setXMinusError(0);
curve->setYMinusError(0);
curve->setColor(Kst::ColorSequence::self().next());
if (_doConsecutivePlots) {
ColorSequence::self().setIndex(0);
}
curve->setColor(Kst::ColorSequence::self().current());
if (!_doConsecutivePlots) {
ColorSequence::self().incIndex();
}
curve->setLineWidth(1);

curve->writeLock();
Expand Down
4 changes: 2 additions & 2 deletions src/libkstapp/curvedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ ObjectPtr CurveDialog::createNewDataObject() {
curve->registerChange();
curve->unlock();

_curveTab->curveAppearance()->setWidgetDefaults();
_curveTab->curveAppearance()->setWidgetDefaults(true);

if(editMode()==New) {
PlotItem *plotItem = 0;
Expand Down Expand Up @@ -633,7 +633,7 @@ ObjectPtr CurveDialog::editExistingDataObject() const {
curve->registerChange();
curve->unlock();

_curveTab->curveAppearance()->setWidgetDefaults(false);
_curveTab->curveAppearance()->setWidgetDefaults();
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/libkstapp/datawizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,9 +1163,13 @@ void DataWizard::finished() {
QColor color;
int ptype = 0;
int i_plot = 0;

for (DataVectorList::Iterator it = vectors.begin(); it != vectors.end(); ++it) {
if (_pageDataPresentation->plotData()) {
color = ColorSequence::self().next();
Q_ASSERT(plotList[i_plot]);

color = plotList[i_plot]->nextColor();

colors.append(color);

DataVectorPtr vector = kst_cast<DataVector>(*it);
Expand All @@ -1191,7 +1195,6 @@ void DataWizard::finished() {
curve->registerChange();
curve->unlock();

Q_ASSERT(plotList[i_plot]);

PlotRenderItem *renderItem = plotList[i_plot]->renderItem(PlotRenderItem::Cartesian);
renderItem->addRelation(kst_cast<Relation>(curve));
Expand Down Expand Up @@ -1263,8 +1266,10 @@ void DataWizard::finished() {
curve->setPointSize(dialogDefaults().value("curves/pointSize",CURVE_DEFAULT_POINT_SIZE).toDouble());
curve->setPointType(ptype++ % KSTPOINT_MAXTYPE);

Q_ASSERT(plotList[i_plot]);

if (!_pageDataPresentation->plotDataPSD() || colors.count() <= indexColor) {
color = ColorSequence::self().next();
color = plotList[i_plot]->nextColor();
} else {
color = colors[indexColor];
indexColor++;
Expand All @@ -1275,8 +1280,6 @@ void DataWizard::finished() {
curve->registerChange();
curve->unlock();

Q_ASSERT(plotList[i_plot]);

PlotRenderItem *renderItem = plotList[i_plot]->renderItem(PlotRenderItem::Cartesian);
plotList[i_plot]->xAxis()->setAxisLog(_pagePlot->PSDLogX());
plotList[i_plot]->yAxis()->setAxisLog(_pagePlot->PSDLogY());
Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/equationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ ObjectPtr EquationDialog::createNewDataObject() {
curve->registerChange();
curve->unlock();

_equationTab->curveAppearance()->setWidgetDefaults();
_equationTab->curveAppearance()->setWidgetDefaults(true);
_lastXVectorName = equation->vXIn()->Name();

if(editMode()==New) {
Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/filterfitdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ ObjectPtr FilterFitDialog::createNewDataObject() {
curve->registerChange();
curve->unlock();

_filterFitTab->curveAppearance()->setWidgetDefaults();
_filterFitTab->curveAppearance()->setWidgetDefaults(true);

PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
renderItem->addRelation(kst_cast<Relation>(curve));
Expand Down
4 changes: 4 additions & 0 deletions src/libkstapp/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "datavector.h"
#include "commandlineparser.h"
#include "dialogdefaults.h"
#include "colorsequence.h"
#include "settings.h"

#include "dialoglauncher.h"
Expand Down Expand Up @@ -2646,6 +2647,9 @@ void MainWindow::readSettings() {
restoreState(_settings.value("toolbarState").toByteArray());
_tabTiedAct->setChecked(_settings.value("tieTabs").toBool());

// read default curve color and set the color sequence.
int color_offset = dialogDefaults().value("curves/default_color", 0).toInt();
ColorSequence::self().setOffset(color_offset);
}


Expand Down
7 changes: 7 additions & 0 deletions src/libkstapp/plotitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
***************************************************************************/

#include "plotitem.h"
#include "colorsequence.h"

#include "plotitemmanager.h"
#include "plotrenderitem.h"
Expand Down Expand Up @@ -160,6 +161,12 @@ ScriptInterface* PlotItem::createScriptInterface() {
}


QColor PlotItem::nextColor() {
ColorSequence::self().setIndex(curveList().count());
return ColorSequence::self().current();
}


void PlotItem::applyDefaults() {
QFont font;

Expand Down
2 changes: 2 additions & 0 deletions src/libkstapp/plotitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ class PlotItem : public ViewItem, public PlotItemInterface

virtual ScriptInterface *createScriptInterface();

QColor nextColor();

protected:
virtual QString _automaticDescriptiveName() const;
virtual void _initializeShortName();
Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/powerspectrumdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ ObjectPtr PowerSpectrumDialog::createNewDataObject() {
curve->registerChange();
curve->unlock();

_powerSpectrumTab->curveAppearance()->setWidgetDefaults();
_powerSpectrumTab->curveAppearance()->setWidgetDefaults(true);

if(editMode()==New) {
PlotItem *plotItem = 0;
Expand Down
83 changes: 62 additions & 21 deletions src/libkstapp/themedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "stroketab.h"
#include "labelpropertiestab.h"
#include "dialogdefaults.h"
#include "colorsequence.h"

#include "plotitem.h"
#include "boxitem.h"
Expand Down Expand Up @@ -64,6 +65,18 @@ ThemeDialog::ThemeDialog(QWidget *parent) : QDialog(parent) {
_labelColor->setFixedWidth(h);
_labelColor->setFixedHeight(h);

// fill color combobox
int color_offset = ColorSequence::self().offset();
ColorSequence::self().setOffset(0);

for (int i_color = 0; i_color < ColorSequence::self().count(); i_color++) {
QPixmap pm = QPixmap(32,32);
pm.fill(ColorSequence::self().entry(i_color));
QIcon icon = QIcon(pm);
_curveColor->addItem(icon, "");
}
ColorSequence::self().setOffset(color_offset);

_applyToExisting->setChecked(true);
_saveAsDefault->setChecked(true);
}
Expand All @@ -76,6 +89,12 @@ void ThemeDialog::reset() {
setFillTab();
setStrokeTab();
setFontTab();

// reset the curve color combobox
int i_color = dialogDefaults().value("curves/default_color", 0).toInt();
if (i_color > _curveColor->count()) i_color = 0;
_curveColor->setCurrentIndex(i_color);

}

void ThemeDialog::apply() {
Expand Down Expand Up @@ -105,40 +124,62 @@ void ThemeDialog::apply() {

typesWithFill.append(View::staticDefaultsGroupName());

if (_curveBox->isChecked()) {
ColorSequence::self().setOffset(_curveColor->currentIndex());
}

if (_saveAsDefault->isChecked()) {
foreach(const QString &type, typesWithFill) {
saveDialogDefaultsBrush(type,b);
if (_fillBox->isChecked()) {
foreach(const QString &type, typesWithFill) {
saveDialogDefaultsBrush(type,b);
}
}
if (_strokeBox->isChecked()) {
foreach(const QString &type, typesWithStroke) {
saveDialogDefaultsPen(type,p);
}
}
foreach(const QString &type, typesWithStroke) {
saveDialogDefaultsPen(type,p);

if (_fontBox->isChecked()) {
QFont F = font();
QColor C = _labelColor->color();
PlotItem::saveDialogDefaultsFont(F, C);
LabelItem::saveDialogDefaultsFont(F, C);
LegendItem::saveDialogDefaultsFont(F, C);
}

if (_curveBox->isChecked()) {
dialogDefaults().setValue("curves/default_color", _curveColor->currentIndex());
}
// FIXME: save font defaults
QFont F = font();
QColor C = _labelColor->color();
PlotItem::saveDialogDefaultsFont(F, C);
LabelItem::saveDialogDefaultsFont(F, C);
LegendItem::saveDialogDefaultsFont(F, C);
}

if (_applyToExisting->isChecked()) {
QList<ViewItem *> view_items = ViewItem::getItems<ViewItem>();

foreach (ViewItem *item, view_items) {
if (item->hasStroke()) {
item->storePen(p); // fixme: plots don't get repainted
if (_strokeBox->isChecked()) {
if (item->hasStroke()) {
item->storePen(p); // fixme: plots don't get repainted
}
}
if (item->hasBrush()) {
item->setBrush(b);
if (_fillBox->isChecked()) {
if (item->hasBrush()) {
item->setBrush(b);
}
}
QFont F = font();
QColor C = _labelColor->color();
if (item->hasFont()) {
item->setFont(F,C);
if (_fontBox->isChecked()) {
QFont F = font();
QColor C = _labelColor->color();
if (item->hasFont()) {
item->setFont(F,C);
}
}
}
QList<View*> views = kstApp->mainWindow()->tabWidget()->views();
foreach (View *view, views) {
view->setBackgroundBrush(b);
if (_fillBox->isChecked()) {
QList<View*> views = kstApp->mainWindow()->tabWidget()->views();
foreach (View *view, views) {
view->setBackgroundBrush(b);
}
}
}
}
Expand Down
Loading