[Kst] branches/work/kst/portto4/kst/src
Mike Fenton
mike at staikos.net
Wed Jun 18 19:37:05 CEST 2008
SVN commit 821863 by fenton:
Cleanup and enable GradientEditor.
M +30 -5 libkstapp/filltab.cpp
M +3 -0 libkstapp/filltab.h
M +37 -2 libkstapp/filltab.ui
M +4 -8 libkstapp/viewitemdialog.cpp
M +33 -21 widgets/gradienteditor.cpp
M +2 -0 widgets/gradienteditor.h
--- branches/work/kst/portto4/kst/src/libkstapp/filltab.cpp #821862:821863
@@ -11,6 +11,8 @@
#include "filltab.h"
+#include <QDebug>
+
namespace Kst {
FillTab::FillTab(QWidget *parent)
@@ -38,9 +40,10 @@
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()), _gradientEditor, SLOT(resetGradient()));
+ connect(_useGradient, SIGNAL(stateChanged(int)), this, SLOT(updateButtons()));
- //FIXME gradient editor is disabled for now as it is not ready
- _gradientEditor->setEnabled(false);
+ updateButtons();
}
@@ -48,13 +51,25 @@
}
+void FillTab::updateButtons() {
+ _color->setEnabled(!_useGradient->isChecked());
+ _style->setEnabled(!_useGradient->isChecked());
+ _gradientReset->setEnabled(_useGradient->isChecked());
+ _gradientEditor->setEnabled(_useGradient->isChecked());
+}
+
+
QColor FillTab::color() const {
return _color->color();
}
void FillTab::setColor(const QColor &color) {
- _color->setColor(color);
+ if (color.isValid()) {
+ _color->setColor(color);
+ } else {
+ _color->setColor(Qt::white);
+ }
}
@@ -64,17 +79,27 @@
void FillTab::setStyle(Qt::BrushStyle style) {
- _style->setCurrentIndex(_style->findData(QVariant(style)));
+ if (style == Qt::LinearGradientPattern) {
+ _style->setCurrentIndex(Qt::SolidPattern);
+ } else {
+ _style->setCurrentIndex(_style->findData(QVariant(style)));
+ }
}
QGradient FillTab::gradient() const {
- return _gradientEditor->gradient();
+ if (_useGradient->isChecked()) {
+ return _gradientEditor->gradient();
+ } else {
+ return QGradient();
+ }
}
void FillTab::setGradient(const QGradient &gradient) {
+ _useGradient->setChecked(!gradient.stops().empty());
_gradientEditor->setGradient(gradient);
+ updateButtons();
}
}
--- branches/work/kst/portto4/kst/src/libkstapp/filltab.h #821862:821863
@@ -33,6 +33,9 @@
QGradient gradient() const;
void setGradient(const QGradient &gradient);
+
+ public Q_SLOTS:
+ void updateButtons();
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/filltab.ui #821862:821863
@@ -5,10 +5,16 @@
<rect>
<x>0</x>
<y>0</y>
- <width>130</width>
- <height>79</height>
+ <width>459</width>
+ <height>282</height>
</rect>
</property>
+ <property name="minimumSize" >
+ <size>
+ <width>400</width>
+ <height>0</height>
+ </size>
+ </property>
<property name="windowTitle" >
<string>Form</string>
</property>
@@ -35,6 +41,23 @@
<item row="1" column="1" >
<widget class="QComboBox" name="_style" />
</item>
+ <item row="2" column="0" >
+ <widget class="QCheckBox" name="_useGradient" >
+ <property name="text" >
+ <string>Use Linear Gradient</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QPushButton" name="_gradientReset" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>Reset Gradient</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>
@@ -42,6 +65,18 @@
<property name="enabled" >
<bool>false</bool>
</property>
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>400</width>
+ <height>80</height>
+ </size>
+ </property>
</widget>
</item>
</layout>
--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.cpp #821862:821863
@@ -64,12 +64,9 @@
_fillTab->setColor(b.color());
_fillTab->setStyle(b.style());
- //FIXME gradient editor is disabled for now as it is not ready
-#if 0
if (const QGradient *gradient = b.gradient()) {
_fillTab->setGradient(*gradient);
}
-#endif
}
@@ -109,19 +106,18 @@
void ViewItemDialog::fillChanged() {
+ Q_ASSERT(_item);
+
QBrush b = _item->brush();
b.setColor(_fillTab->color());
b.setStyle(_fillTab->style());
- //FIXME gradient editor is disabled for now as it is not ready
-#if 0
QGradient gradient = _fillTab->gradient();
- if (gradient.type() != QGradient::NoGradient)
+ if (gradient.type() != QGradient::NoGradient) {
b = QBrush(gradient);
-#endif
+ }
- Q_ASSERT(_item);
_item->setBrush(b);
}
--- branches/work/kst/portto4/kst/src/widgets/gradienteditor.cpp #821862:821863
@@ -47,10 +47,18 @@
void GradientEditor::setGradient(const QGradient &gradient) {
- _gradient->setStops(gradient.stops());
+ setGradientStops(gradient.stops());
+ update();
}
+void GradientEditor::resetGradient() {
+ QLinearGradient defaultGradient(1,0,0,0);
+ clearGradientStops();
+ update();
+}
+
+
void GradientEditor::mousePressEvent(QMouseEvent *event) {
QWidget::mousePressEvent(event);
@@ -108,33 +116,32 @@
{
Q_UNUSED(event);
- if (!isEnabled()) {
- return;
- }
-
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillRect(rect(), QBrush(gradient()));
- QPoint cursor = QWidget::mapFromGlobal(QCursor::pos());
- if (rect().contains(cursor)) {
- painter.setPen(Qt::black);
- QLine line(QPoint(cursor.x(), rect().y()), QPoint(cursor.x(), rect().bottom()));
- painter.drawLine(line);
- }
+ if (isEnabled()) {
- QList<Stop> stops = _stopHash.values();
- foreach (Stop stop, stops) {
- if (stop.path.contains(cursor)) {
- painter.setPen(Qt::white);
- painter.setBrush(Qt::black);
- painter.drawPath(stop.path);
- } else {
+ QPoint cursor = QWidget::mapFromGlobal(QCursor::pos());
+ if (rect().contains(cursor)) {
painter.setPen(Qt::black);
- painter.setBrush(Qt::white);
- painter.drawPath(stop.path);
+ QLine line(QPoint(cursor.x(), rect().y()), QPoint(cursor.x(), rect().bottom()));
+ painter.drawLine(line);
}
+
+ QList<Stop> stops = _stopHash.values();
+ foreach (Stop stop, stops) {
+ if (stop.path.contains(cursor)) {
+ painter.setPen(Qt::white);
+ painter.setBrush(Qt::black);
+ painter.drawPath(stop.path);
+ } else {
+ painter.setPen(Qt::black);
+ painter.setBrush(Qt::white);
+ painter.drawPath(stop.path);
+ }
+ }
}
}
@@ -190,7 +197,7 @@
_stopHash.clear();
foreach (QGradientStop gradientStop, stops) {
- int position = int(-(gradientStop.first - 1.0 / qreal(rect().width())));
+ int position = int(-((gradientStop.first - 1.0) * qreal(rect().width())));
Stop stop;
stop.pos = position;
stop.color = gradientStop.second;
@@ -199,6 +206,11 @@
}
}
+
+void GradientEditor::clearGradientStops() {
+ _stopHash.clear();
}
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/widgets/gradienteditor.h #821862:821863
@@ -32,6 +32,7 @@
public Q_SLOTS:
void setGradient(const QGradient &gradient);
+ void resetGradient();
Q_SIGNALS:
void changed(const QGradient &gradient);
@@ -48,6 +49,7 @@
QGradientStops gradientStops() const;
void setGradientStops(const QGradientStops &stops);
+ void clearGradientStops();
struct Stop {
int pos;
More information about the Kst
mailing list