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

Adam Treat treat at kde.org
Mon Jun 18 20:44:14 CEST 2007


SVN commit 677240 by treat:

* Add prelim gradient editor.  All items can
now set a fill gradient for background.  Fix up
colorbutton.  Fix up viewitemdialog.  Other fixes.



 M  +11 -1     libkstapp/viewitemdialog.cpp  
 M  +1 -0      widgets/CMakeLists.txt  
 M  +7 -3      widgets/colorbutton.cpp  
 M  +13 -0     widgets/fillandstroke.cpp  
 M  +3 -0      widgets/fillandstroke.h  
 M  +30 -28    widgets/fillandstroke.ui  
 A             widgets/gradienteditor.cpp   [License: GPL (v2+)]
 A             widgets/gradienteditor.h   [License: GPL (v2+)]
 M  +16 -0     widgets/kstwidgets.h  


--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.cpp #677239:677240
@@ -38,12 +38,15 @@
     : QDialog(parent) {
 
   setModal(false);
+  setWindowTitle(tr("Edit View Item"));
 
   _fillAndStroke = new FillAndStroke(this);
   connect(_fillAndStroke, SIGNAL(fillChanged()), this, SLOT(fillChanged()));
   connect(_fillAndStroke, SIGNAL(strokeChanged()), this, SLOT(strokeChanged()));
 
-  QHBoxLayout *layout = new QHBoxLayout(this);
+  QVBoxLayout *layout = new QVBoxLayout(this);
+  layout->setMargin(0);
+  layout->setSpacing(0);
   layout->addWidget(_fillAndStroke);
   setLayout(layout);
 }
@@ -73,6 +76,9 @@
 
   _fillAndStroke->setFillColor(b.color());
   _fillAndStroke->setFillStyle(b.style());
+  if (const QGradient *gradient = b.gradient()) {
+    _fillAndStroke->setFillGradient(*gradient);
+  }
 }
 
 
@@ -103,6 +109,10 @@
   b.setColor(_fillAndStroke->fillColor());
   b.setStyle(_fillAndStroke->fillStyle());
 
+  QGradient gradient = _fillAndStroke->fillGradient();
+  if (gradient.type() != QGradient::NoGradient)
+    b = QBrush(gradient);
+
   foreach(ViewItem *item, _items) {
     item->setBrush(b);
   }
--- branches/work/kst/portto4/kst/src/widgets/CMakeLists.txt #677239:677240
@@ -8,6 +8,7 @@
    kstwidgets.cpp
    colorbutton.cpp
    fillandstroke.cpp
+   gradienteditor.cpp
    )
 
 kde4_automoc(${kstwidgets_LIB_SRCS})
--- branches/work/kst/portto4/kst/src/widgets/colorbutton.cpp #677239:677240
@@ -48,11 +48,13 @@
 
 void ColorButton::paintEvent(QPaintEvent *event)
 {
-  Q_UNUSED(event);
+  QToolButton::paintEvent(event);
+  if (!isEnabled())
+      return;
 
   QPainter painter(this);
   QBrush brush(_color);
-  qDrawShadePanel(&painter, rect().x(), rect().y(), rect().width(), rect().height(),
+  qDrawShadePanel(&painter, rect().x() + 2, rect().y() + 2, rect().width() - 4, rect().height() - 4,
                   palette(), /*sunken*/ isDown(), /*lineWidth*/ 1, /*fill*/ &brush);
 }
 
@@ -60,8 +62,10 @@
 void ColorButton::chooseColor() {
 
   bool ok;
-  QRgb color = QColorDialog::getRgba(_color.rgba(), &ok, parentWidget());
+  QRgb rgba = QColorDialog::getRgba(_color.rgba(), &ok, parentWidget());
   if (ok) {
+    QColor color;
+    color.setRgba(rgba);
     setColor(color);
   }
 }
--- branches/work/kst/portto4/kst/src/widgets/fillandstroke.cpp #677239:677240
@@ -70,6 +70,7 @@
 
   connect(_color, SIGNAL(changed(const QColor &)), this, SIGNAL(fillChanged()));
   connect(_fillStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(fillChanged()));
+  connect(_gradientEditor, SIGNAL(changed(const QGradient &)), this, SIGNAL(fillChanged()));
 
   connect(_strokeStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(strokeChanged()));
   connect(_width, SIGNAL(valueChanged(double)), this, SIGNAL(strokeChanged()));
@@ -77,6 +78,8 @@
   connect(_brushStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(strokeChanged()));
   connect(_joinStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(strokeChanged()));
   connect(_capStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(strokeChanged()));
+
+  _gradientEditor->setEnabled(true);
 }
 
 
@@ -104,6 +107,16 @@
 }
 
 
+QGradient FillAndStroke::fillGradient() const {
+  return _gradientEditor->gradient();
+}
+
+
+void FillAndStroke::setFillGradient(const QGradient &gradient) {
+  _gradientEditor->setGradient(gradient);
+}
+
+
 Qt::PenStyle FillAndStroke::strokeStyle() const {
   return Qt::PenStyle(_strokeStyle->itemData(_strokeStyle->currentIndex()).toInt());
 }
--- branches/work/kst/portto4/kst/src/widgets/fillandstroke.h #677239:677240
@@ -31,6 +31,9 @@
   Qt::BrushStyle fillStyle() const;
   void setFillStyle(Qt::BrushStyle style);
 
+  QGradient fillGradient() const;
+  void setFillGradient(const QGradient &gradient);
+
   Qt::PenStyle strokeStyle() const;
   void setStrokeStyle(Qt::PenStyle style);
 
--- branches/work/kst/portto4/kst/src/widgets/fillandstroke.ui #677239:677240
@@ -24,38 +24,36 @@
       </attribute>
       <layout class="QGridLayout" >
        <item row="0" column="0" >
-        <widget class="QLabel" name="label" >
-         <property name="text" >
-          <string>Color:</string>
-         </property>
-        </widget>
+        <layout class="QGridLayout" >
+         <item row="0" column="0" >
+          <widget class="QLabel" name="label" >
+           <property name="text" >
+            <string>Color:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1" >
+          <widget class="Kst::ColorButton" name="_color" />
+         </item>
+         <item row="1" column="0" >
+          <widget class="QLabel" name="label_2" >
+           <property name="text" >
+            <string>Style:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1" >
+          <widget class="QComboBox" name="_fillStyle" />
+         </item>
+        </layout>
        </item>
-       <item row="0" column="1" >
-        <widget class="Kst::ColorButton" name="_color" />
-       </item>
        <item row="1" column="0" >
-        <widget class="QLabel" name="label_2" >
-         <property name="text" >
-          <string>Style:</string>
+        <widget class="Kst::GradientEditor" name="_gradientEditor" >
+         <property name="enabled" >
+          <bool>false</bool>
          </property>
         </widget>
        </item>
-       <item row="1" column="1" >
-        <widget class="QComboBox" name="_fillStyle" />
-       </item>
-       <item row="2" column="0" colspan="2" >
-        <spacer>
-         <property name="orientation" >
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" >
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="_stroke" >
@@ -148,8 +146,12 @@
    <extends>QToolButton</extends>
    <header>colorbutton.h</header>
   </customwidget>
+  <customwidget>
+   <class>Kst::GradientEditor</class>
+   <extends>QWidget</extends>
+   <header>gradienteditor.h</header>
+  </customwidget>
  </customwidgets>
- <includes/>
  <resources/>
  <connections/>
 </ui>
--- branches/work/kst/portto4/kst/src/widgets/kstwidgets.h #677239:677240
@@ -100,6 +100,21 @@
 };
 
 
+#include "gradienteditor.h"
+class GradientEditorPlugin : public KstWidgetPlugin {
+  Q_OBJECT
+  Q_INTERFACES(QDesignerCustomWidgetInterface)
+public:
+  GradientEditorPlugin(QObject *parent = 0) : KstWidgetPlugin(parent) {}
+  QString name() const {
+    return QLatin1String("Kst::GradientEditor");
+  } //do not translate
+  QWidget *createWidget(QWidget *parent) {
+    return new Kst::GradientEditor(parent);
+  }
+};
+
+
 class KstWidgets : public QObject, public QDesignerCustomWidgetCollectionInterface {
   Q_OBJECT
   Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
@@ -121,6 +136,7 @@
   (void) new KComponentData("kstwidgets");
   _plugins.append(new ColorButtonPlugin(this));
   _plugins.append(new FillAndStrokePlugin(this));
+  _plugins.append(new GradientEditorPlugin(this));
 }
 
 #endif


More information about the Kst mailing list