From 230c5a198cba9feaa51541d12795cfa9d2efc092 Mon Sep 17 00:00:00 2001 From: Barth Netterfield Date: Wed, 24 Nov 2021 22:00:35 -0500 Subject: [PATCH] Some work with the theme dialog Some bug fixes. Also, set the default curve color. --- src/libkstapp/mainwindow.cpp | 4 + src/libkstapp/themedialog.cpp | 83 ++++++++--- src/libkstapp/themedialog.ui | 240 ++++++++++++++++++++----------- src/libkstmath/colorsequence.cpp | 16 +-- src/libkstmath/colorsequence.h | 6 +- 5 files changed, 228 insertions(+), 121 deletions(-) diff --git a/src/libkstapp/mainwindow.cpp b/src/libkstapp/mainwindow.cpp index 966b7c14e..65e4eecc5 100644 --- a/src/libkstapp/mainwindow.cpp +++ b/src/libkstapp/mainwindow.cpp @@ -58,6 +58,7 @@ #include "datavector.h" #include "commandlineparser.h" #include "dialogdefaults.h" +#include "colorsequence.h" #include "settings.h" #include "dialoglauncher.h" @@ -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); } diff --git a/src/libkstapp/themedialog.cpp b/src/libkstapp/themedialog.cpp index 1fe242dd9..d0295856b 100644 --- a/src/libkstapp/themedialog.cpp +++ b/src/libkstapp/themedialog.cpp @@ -24,6 +24,7 @@ #include "stroketab.h" #include "labelpropertiestab.h" #include "dialogdefaults.h" +#include "colorsequence.h" #include "plotitem.h" #include "boxitem.h" @@ -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); } @@ -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() { @@ -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 view_items = ViewItem::getItems(); 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 views = kstApp->mainWindow()->tabWidget()->views(); - foreach (View *view, views) { - view->setBackgroundBrush(b); + if (_fillBox->isChecked()) { + QList views = kstApp->mainWindow()->tabWidget()->views(); + foreach (View *view, views) { + view->setBackgroundBrush(b); + } } } } diff --git a/src/libkstapp/themedialog.ui b/src/libkstapp/themedialog.ui index 480523994..b74719ec1 100644 --- a/src/libkstapp/themedialog.ui +++ b/src/libkstapp/themedialog.ui @@ -6,11 +6,11 @@ 0 0 - 575 - 336 + 879 + 268 - + @@ -36,104 +36,174 @@ - - - - 0 - 0 - - - - Fonts - - - true - - - - - - + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Curve + + + true + + + + - Fo&nt size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - _labelFontScale + Default Color: - - - - 1 - - - -25.000000000000000 + + + + + 0 + 0 + - - 1.000000000000000 - - - - - - - Font fa&mily: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - _family - - - - - - - - - Italic + Default Curve Color - - + + Qt::LeftToRight - - true + + 13 - - - - - - - Bold - - - + + + + Qt::Vertical - - true + + + 20 + 9 + - + - - - - points - - + + + + + + + + 0 + 0 + + + + Fonts + + + true + + + + + + + + Fo&nt size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + _labelFontScale + + + + + + + 1 + + + -25.000000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + Font fa&mily: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + _family + + + + + + + + + + Italic + + + + + + true + + + + + + + + + + Bold + + + + + + true + + + + + + + points + + + + - - - + + + diff --git a/src/libkstmath/colorsequence.cpp b/src/libkstmath/colorsequence.cpp index 11178b135..196e6a6b1 100644 --- a/src/libkstmath/colorsequence.cpp +++ b/src/libkstmath/colorsequence.cpp @@ -13,15 +13,6 @@ // delivers new colors... // -// Inrement Index: IncIndex() -// Set index: SetIndex(i) -// Index: Index() -// Current primary Color: Current(Background) -// Current Bar color: CurrentBar(Background) -// Current Head Color: CurrentHead(Background) - -// Only increment if there are multiple curves in a plot. - // application specific includes #include "colorsequence.h" #include @@ -68,6 +59,7 @@ ColorSequence::ColorSequence() { _count = _colors.size(); _ptr = 0; + _offset = 0; } @@ -77,7 +69,7 @@ ColorSequence::~ColorSequence() { QColor ColorSequence::next() { incIndex(); - return entry(_ptr); + return entry(_ptr); } @@ -85,11 +77,9 @@ QColor ColorSequence::current() { return entry(_ptr); } - - QColor ColorSequence::entry(int i) { // makes sure 0<=i