[Kst] branches/work/kst/portto4/kst/src

Mike Fenton mike at staikos.net
Thu Aug 7 20:45:39 CEST 2008


SVN commit 843749 by fenton:

Add configurable background for views.
Add special reset mode for gradient editor.
Save background as application setting.


 M  +54 -0     libkstapp/applicationsettings.cpp  
 M  +8 -0      libkstapp/applicationsettings.h  
 M  +41 -0     libkstapp/applicationsettingsdialog.cpp  
 M  +4 -0      libkstapp/applicationsettingsdialog.h  
 M  +5 -1      libkstapp/filltab.cpp  
 M  +1 -1      libkstapp/filltab.h  
 M  +14 -5     libkstapp/view.cpp  
 M  +1 -0      libkstapp/view.h  
 M  +12 -1     widgets/gradienteditor.cpp  
 M  +3 -0      widgets/gradienteditor.h  


--- branches/work/kst/portto4/kst/src/libkstapp/applicationsettings.cpp #843748:843749
@@ -22,6 +22,7 @@
 #include <QX11Info>
 #endif
 
+
 namespace Kst {
 
 static ApplicationSettings *_self = 0;
@@ -60,6 +61,23 @@
   _snapToGrid = _settings->value("grid/snaptogrid", QVariant(false)).toBool();
   _gridHorSpacing = _settings->value("grid/horizontalspacing", 20.0).toDouble();
   _gridVerSpacing = _settings->value("grid/verticalspacing", 20.0).toDouble();
+
+  Qt::BrushStyle style = (Qt::BrushStyle)_settings->value("fill/style", "0").toInt();
+  if (style < Qt::LinearGradientPattern) {
+    _backgroundBrush.setColor(QColor(_settings->value("fill/color", "white").toString()));
+    _backgroundBrush.setStyle(style);
+  }
+
+  QString stopList = _settings->value("fill/gradient", "0,#cccccc,1,#ffffff").toString();
+  if (!stopList.isEmpty()) {
+    QStringList stopInfo = stopList.split(',', QString::SkipEmptyParts);
+    QLinearGradient gradient(0.0, 0.0, 0.0, 1.0);
+    for (int i = 0; i < stopInfo.size(); i+=2) {
+      gradient.setColorAt(stopInfo.at(i).toDouble(), QColor(stopInfo.at(i+1)));
+    }
+   _gradientStops = gradient.stops();
+    _backgroundBrush = QBrush(gradient);
+  }
 }
 
 
@@ -218,7 +236,43 @@
   emit modified();
 }
 
+QBrush ApplicationSettings::backgroundBrush() const {
+  return _backgroundBrush;
 }
 
 
+void ApplicationSettings::setBackgroundBrush(const QBrush brush) {
+  _backgroundBrush = brush;
+  _gradientStops.clear();
+  _settings->setValue("fill/color", brush.color().name());
+  _settings->setValue("fill/style", QVariant(brush.style()).toString());
+
+  QString stopList;
+  if (brush.gradient()) {
+    foreach(QGradientStop stop, brush.gradient()->stops()) {
+      qreal point = (qreal)stop.first;
+      QColor color = (QColor)stop.second;
+
+      _gradientStops.append(qMakePair(point, color));
+
+      stopList += QString::number(point);
+      stopList += ",";
+      stopList += color.name();
+      stopList += ",";
+    }
+  }
+  _settings->setValue("fill/gradient", stopList);
+
+  emit modified();
+}
+
+
+QGradientStops ApplicationSettings::gradientStops() const {
+  return _gradientStops;
+}
+
+
+}
+
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/applicationsettings.h #843748:843749
@@ -13,6 +13,7 @@
 #define APPLICATIONSETTINGS_H
 
 #include <QObject>
+#include <QBrush>
 
 class QSettings;
 
@@ -62,6 +63,11 @@
     qreal gridVerticalSpacing() const;
     void setGridVerticalSpacing(qreal spacing);
 
+    QBrush backgroundBrush() const;
+    void setBackgroundBrush(const QBrush brush);
+
+    QGradientStops gradientStops() const;
+
   Q_SIGNALS:
     void modified();
 
@@ -83,6 +89,8 @@
     bool _snapToGrid;
     qreal _gridHorSpacing;
     qreal _gridVerSpacing;
+    QBrush _backgroundBrush;
+    QGradientStops _gradientStops;
 
     friend class ApplicationSettingsDialog;
 };
--- branches/work/kst/portto4/kst/src/libkstapp/applicationsettingsdialog.cpp #843748:843749
@@ -14,6 +14,7 @@
 #include "applicationsettings.h"
 #include "gridtab.h"
 #include "generaltab.h"
+#include "filltab.h"
 #include "dialogpage.h"
 
 #include <QDebug>
@@ -27,8 +28,11 @@
 
   _generalTab = new GeneralTab(this);
   _gridTab = new GridTab(this);
+  _fillTab = new FillTab(false, this);
+
   connect(_generalTab, SIGNAL(apply()), this, SLOT(generalChanged()));
   connect(_gridTab, SIGNAL(apply()), this, SLOT(gridChanged()));
+  connect(_fillTab, SIGNAL(apply()), this, SLOT(fillChanged()));
 
   DialogPage *general = new DialogPage(this);
   general->setPageTitle(tr("General"));
@@ -40,8 +44,14 @@
   grid->addDialogTab(_gridTab);
   addDialogPage(grid);
 
+  DialogPage *fill = new DialogPage(this);
+  fill->setPageTitle(tr("Fill"));
+  fill->addDialogTab(_fillTab);
+  addDialogPage(fill);
+
   setupGeneral();
   setupGrid();
+  setupFill();
 }
 
 
@@ -68,6 +78,18 @@
 }
 
 
+void ApplicationSettingsDialog::setupFill() {
+  QBrush b = ApplicationSettings::self()->backgroundBrush();
+
+  _fillTab->setColor(b.color());
+  _fillTab->setStyle(b.style());
+
+  if (const QGradient *gradient = b.gradient()) {
+    _fillTab->setGradient(*gradient);
+  }
+}
+
+
 void ApplicationSettingsDialog::generalChanged() {
   //Need to block the signals so that the modified signal only goes out once...
   ApplicationSettings::self()->blockSignals(true);
@@ -96,6 +118,25 @@
   emit ApplicationSettings::self()->modified();
 }
 
+
+void ApplicationSettingsDialog::fillChanged() {
+  QBrush b = ApplicationSettings::self()->backgroundBrush();
+
+  b.setColor(_fillTab->color());
+  b.setStyle(_fillTab->style());
+
+  QGradient gradient = _fillTab->gradient();
+  if (gradient.type() != QGradient::NoGradient) {
+    QLinearGradient linearGradient;
+    linearGradient.setStops(gradient.stops());
+    b = QBrush(linearGradient);
+  }
+
+  ApplicationSettings::self()->setBackgroundBrush(b);
+
+  emit ApplicationSettings::self()->modified();
 }
 
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/applicationsettingsdialog.h #843748:843749
@@ -22,6 +22,7 @@
 
 class GeneralTab;
 class GridTab;
+class FillTab;
 
 class KST_EXPORT ApplicationSettingsDialog : public Dialog
 {
@@ -33,14 +34,17 @@
   private Q_SLOTS:
     void generalChanged();
     void gridChanged();
+    void fillChanged();
 
   private:
     void setupGeneral();
     void setupGrid();
+    void setupFill();
 
   private:
     GeneralTab *_generalTab;
     GridTab *_gridTab;
+    FillTab *_fillTab;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/filltab.cpp #843748:843749
@@ -15,7 +15,7 @@
 
 namespace Kst {
 
-FillTab::FillTab(QWidget *parent)
+FillTab::FillTab(bool resetFullMono, QWidget *parent)
   : DialogTab(parent) {
 
   setupUi(this);
@@ -37,9 +37,13 @@
   _style->addItem("FDiagPattern", Qt::FDiagPattern);
   _style->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
 
+  _gradientEditor->setResetMode(resetFullMono);
+
   connect(_color, SIGNAL(changed(const QColor &)), this, SIGNAL(modified()));
   connect(_style, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
   connect(_gradientEditor, SIGNAL(changed(const QGradient &)), this, SIGNAL(modified()));
+  connect(_gradientReset, SIGNAL(pressed()), this, SIGNAL(modified()));
+  connect(_useGradient, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
   connect(_gradientReset, SIGNAL(pressed()), _gradientEditor, SLOT(resetGradient()));
   connect(_useGradient, SIGNAL(stateChanged(int)), this, SLOT(updateButtons()));
 
--- branches/work/kst/portto4/kst/src/libkstapp/filltab.h #843748:843749
@@ -22,7 +22,7 @@
 class KST_EXPORT FillTab : public DialogTab, Ui::FillTab {
   Q_OBJECT
   public:
-    FillTab(QWidget *parent = 0);
+    FillTab(bool resetFullMono = true, QWidget *parent = 0);
     virtual ~FillTab();
 
     QColor color() const;
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #843748:843749
@@ -286,10 +286,8 @@
 
     setSceneRect(QRectF(0.0, 0.0, width() - 4.0, height() - 4.0));
 
-    QLinearGradient l(0.0, 0.0, 0.0, height() - 4.0);
-    l.setColorAt(0.0, Qt::white);
-    l.setColorAt(1.0, Qt::lightGray);
-    setBackgroundBrush(l);
+    updateBrush();
+
     setCacheMode(QGraphicsView::CacheBackground);
 
     foreach (QGraphicsItem *item, items()) {
@@ -306,8 +304,18 @@
 }
 
 
+void View::updateBrush() {
+  if (!ApplicationSettings::self()->gradientStops().empty()) {
+    QLinearGradient l(0.0, height() - 4.0, 0.0, 0.0);
+    l.setStops(ApplicationSettings::self()->gradientStops());
+    setBackgroundBrush(l);
+  } else {
+    setBackgroundBrush(ApplicationSettings::self()->backgroundBrush());
+  }
+}
+
+
 void View::drawBackground(QPainter *painter, const QRectF &rect) {
-
   QGraphicsView::drawBackground(painter, rect);
 
   if (!showGrid())
@@ -355,6 +363,7 @@
                         ApplicationSettings::self()->gridVerticalSpacing()));
 
   updateFont();
+  updateBrush();
 
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #843748:843749
@@ -104,6 +104,7 @@
 
   private Q_SLOTS:
     void updateSettings();
+    void updateBrush();
     void updateFont();
 
   private:
--- branches/work/kst/portto4/kst/src/widgets/gradienteditor.cpp #843748:843749
@@ -21,7 +21,7 @@
 namespace Kst {
 
 GradientEditor::GradientEditor(QWidget *parent)
-  : QWidget(parent), _gradient(0), _movingStop(-1) {
+  : QWidget(parent), _gradient(0), _movingStop(-1), _fullResetMode(true) {
   setMouseTracking(true);
   setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
 
@@ -52,9 +52,20 @@
 }
 
 
+void GradientEditor::setResetMode(bool full) {
+  _fullResetMode = full;
+}
+
+
 void GradientEditor::resetGradient() {
   QLinearGradient defaultGradient(1,0,0,0);
   clearGradientStops();
+  if (!_fullResetMode) {
+    QGradientStops stops;
+    stops.append(qMakePair(1.0, QColor(Qt::white)));
+    stops.append(qMakePair(0.0, QColor(Qt::lightGray)));
+    setGradientStops(stops);
+  }
   update();
 }
 
--- branches/work/kst/portto4/kst/src/widgets/gradienteditor.h #843748:843749
@@ -30,6 +30,8 @@
 
   QGradient gradient() const;
 
+  void setResetMode(bool full);
+
 public Q_SLOTS:
   void setGradient(const QGradient &gradient);
   void resetGradient();
@@ -61,6 +63,7 @@
   QGradient *_gradient;
   QHash<int, Stop> _stopHash;
   int _movingStop;
+  bool _fullResetMode;
 };
 
 }


More information about the Kst mailing list