[Kst] branches/work/kst/portto4/kst/src
Mike Fenton
mike at staikos.net
Tue Oct 9 20:56:07 CEST 2007
SVN commit 723465 by fenton:
Implementation of CurveAppearance widget and connecting it to the Curve
and Equation dialogs.
M +15 -1 libkstapp/curvedialog.cpp
M +2 -0 libkstapp/curvedialog.h
M +16 -2 libkstapp/equationdialog.cpp
M +2 -0 libkstapp/equationdialog.h
M +219 -0 widgets/curveappearance.cpp
M +16 -0 widgets/curveappearance.h
M +58 -51 widgets/curveappearance.ui
--- branches/work/kst/portto4/kst/src/libkstapp/curvedialog.cpp #723464:723465
@@ -106,6 +106,11 @@
}
+CurveAppearance* CurveTab::curveAppearanceWidget() {
+ return _curveAppearance;
+}
+
+
CurveDialog::CurveDialog(ObjectPtr dataObject, QWidget *parent)
: DataDialog(dataObject, parent) {
@@ -139,8 +144,17 @@
_curveTab->yError(),
_curveTab->xMinusError(),
_curveTab->yMinusError(),
- QColor(Qt::red));
+ _curveTab->curveAppearanceWidget()->color());
+ curve->setHasPoints(_curveTab->curveAppearanceWidget()->showPoints());
+ curve->setHasLines(_curveTab->curveAppearanceWidget()->showLines());
+ curve->setHasBars(_curveTab->curveAppearanceWidget()->showBars());
+ curve->setLineWidth(_curveTab->curveAppearanceWidget()->lineWidth());
+ curve->setLineStyle(_curveTab->curveAppearanceWidget()->lineStyle());
+ curve->pointType = _curveTab->curveAppearanceWidget()->pointType();
+ curve->setPointDensity(_curveTab->curveAppearanceWidget()->pointDensity());
+ curve->setBarStyle(_curveTab->curveAppearanceWidget()->barStyle());
+
curve->writeLock();
curve->update(0);
curve->unlock();
--- branches/work/kst/portto4/kst/src/libkstapp/curvedialog.h #723464:723465
@@ -47,6 +47,8 @@
VectorPtr yMinusError() const;
void setYMinusError(VectorPtr vector);
+ CurveAppearance* curveAppearanceWidget();
+
private Q_SLOTS:
private:
};
--- branches/work/kst/portto4/kst/src/libkstapp/equationdialog.cpp #723464:723465
@@ -111,6 +111,11 @@
}
+CurveAppearance* EquationTab::curveAppearanceWidget() {
+ return _curveAppearance;
+}
+
+
EquationDialog::EquationDialog(ObjectPtr dataObject, QWidget *parent)
: DataDialog(dataObject, parent) {
@@ -149,14 +154,23 @@
//FIXME assume new plot for now...
//FIXME this should be a command...
//FIXME need some smart placement...
- //FIXME need to hook up appearance and placement...
+ //FIXME need to hook up placement...
CurvePtr curve = new Curve(suggestCurveName(equation->tag(), true),
equation->vX(),
equation->vY(),
0L, 0L, 0L, 0L,
- QColor(Qt::red));
+ _equationTab->curveAppearanceWidget()->color());
+ curve->setHasPoints(_equationTab->curveAppearanceWidget()->showPoints());
+ curve->setHasLines(_equationTab->curveAppearanceWidget()->showLines());
+ curve->setHasBars(_equationTab->curveAppearanceWidget()->showBars());
+ curve->setLineWidth(_equationTab->curveAppearanceWidget()->lineWidth());
+ curve->setLineStyle(_equationTab->curveAppearanceWidget()->lineStyle());
+ curve->pointType = _equationTab->curveAppearanceWidget()->pointType();
+ curve->setPointDensity(_equationTab->curveAppearanceWidget()->pointDensity());
+ curve->setBarStyle(_equationTab->curveAppearanceWidget()->barStyle());
+
curve->writeLock();
curve->update(0);
curve->unlock();
--- branches/work/kst/portto4/kst/src/libkstapp/equationdialog.h #723464:723465
@@ -36,6 +36,8 @@
bool doInterpolation() const;
void setDoInterpolation(bool doInterpolation);
+ CurveAppearance *curveAppearanceWidget();
+
private Q_SLOTS:
private:
void populateFunctionList();
--- branches/work/kst/portto4/kst/src/widgets/curveappearance.cpp #723464:723465
@@ -11,17 +11,236 @@
#include "curveappearance.h"
+#include "curvepointsymbol.h"
+#include "linestyle.h"
+#include <QPainter>
+
namespace Kst {
CurveAppearance::CurveAppearance(QWidget *parent)
: QWidget(parent) {
setupUi(this);
+ drawSampleLine();
+ populatePointSymbolCombo();
+ populateLineStyleCombo();
+
+ connect(_showPoints, SIGNAL(toggled(bool)), this, SLOT(enableSettings()));
+ connect(_showLines, SIGNAL(toggled(bool)), this, SLOT(enableSettings()));
+ connect(_showBars, SIGNAL(toggled(bool)), this, SLOT(enableSettings()));
+
+ connect(_color, SIGNAL(changed(const QColor&)), this, SLOT(populatePointSymbolCombo()));
+ connect(_color, SIGNAL(changed(const QColor&)), this, SLOT(populateLineStyleCombo()));
+
+ connect(_color, SIGNAL(changed(const QColor&)), this, SLOT(drawSampleLine()));
+ connect(_showLines, SIGNAL(clicked()), this, SLOT(drawSampleLine()));
+ connect(_showPoints, SIGNAL(clicked()), this, SLOT(drawSampleLine()));
+ connect(_comboPointSymbol, SIGNAL(activated(int)), this, SLOT(drawSampleLine()));
+ connect(_comboLineStyle, SIGNAL(activated(int)), this, SLOT(drawSampleLine()));
+ connect(_spinBoxLineWidth, SIGNAL(valueChanged(int)), this, SLOT(drawSampleLine()));
+ connect(_barStyle, SIGNAL(activated(int)), this, SLOT(drawSampleLine()));
+ connect(_showBars, SIGNAL(clicked()), this, SLOT(drawSampleLine()));
}
CurveAppearance::~CurveAppearance() {
}
+
+void CurveAppearance::populatePointSymbolCombo() {
+ QStyleOptionComboBox option;
+ option.initFrom(_comboPointSymbol);
+ option.currentIcon = _comboPointSymbol->itemIcon(_comboPointSymbol->currentIndex());
+ option.currentText = _comboPointSymbol->itemText(_comboPointSymbol->currentIndex());
+ option.editable = _comboPointSymbol->isEditable();
+ option.frame = _comboPointSymbol->hasFrame();
+ option.iconSize = _comboPointSymbol->iconSize();
+
+ QRect rect = _comboPointSymbol->style()->subControlRect(
+ QStyle::CC_ComboBox,
+ &option,
+ QStyle::SC_ComboBoxEditField,
+ _comboPointSymbol );
+ rect.setLeft( rect.left() + 2 );
+ rect.setRight( rect.right() - 2 );
+ rect.setTop( rect.top() + 2 );
+ rect.setBottom( rect.bottom() - 2 );
+
+_comboPointSymbol->setIconSize(QSize(rect.height(), rect.width()));
+
+ // fill the point type dialog with point types
+ QPixmap ppix( rect.width(), rect.height() );
+ QPainter pp( &ppix );
+
+ int currentItem = _comboPointSymbol->currentIndex();
+ _comboPointSymbol->clear();
+ pp.setPen(color());
+
+ for (int ptype = 0; ptype < KSTPOINT_MAXTYPE; ptype++) {
+ pp.fillRect(pp.window(), QColor("white"));
+ CurvePointSymbol::draw(ptype, &pp, ppix.width()/2, ppix.height()/2, 0, 600);
+ _comboPointSymbol->addItem(QIcon(ppix), QString::null);
+ }
+
+ if (currentItem > 0) {
+ _comboPointSymbol->setCurrentIndex( currentItem );
+ }
}
+
+void CurveAppearance::enableSettings() {
+ bool enable;
+
+ enable = showLines() || showBars();
+ _comboLineStyle->setEnabled(enable);
+ _textLabelLineStyle->setEnabled(enable);
+
+ enable = enable || showPoints();
+ _textLabelWeight->setEnabled(enable);
+ _spinBoxLineWidth->setEnabled(enable);
+
+ enable = showBars();
+ _textLabelBarStyle->setEnabled(enable);
+ _barStyle->setEnabled(enable);
+
+ enable = showPoints();
+ _textLabelPointStyle->setEnabled(enable);
+ _comboPointSymbol->setEnabled(enable);
+
+ enable = enable && showLines();
+ _textLabelPointDensity->setEnabled(enable);
+ _comboPointDensity->setEnabled(enable);
+}
+
+
+bool CurveAppearance::showLines() {
+ return _showLines->isChecked();
+}
+
+
+bool CurveAppearance::showPoints() {
+ return _showPoints->isChecked();
+}
+
+
+bool CurveAppearance::showBars() {
+ return _showBars->isChecked();
+}
+
+
+QColor CurveAppearance::color() {
+ return _color->color();
+}
+
+
+int CurveAppearance::pointType() {
+ return _comboPointSymbol->currentIndex();
+}
+
+
+int CurveAppearance::lineStyle() {
+ return _comboLineStyle->currentIndex();
+}
+
+
+int CurveAppearance::barStyle() {
+ return _barStyle->currentIndex();
+}
+
+
+int CurveAppearance::pointDensity() {
+ return _comboPointDensity->currentIndex();
+}
+
+
+int CurveAppearance::lineWidth() {
+ if (_spinBoxLineWidth->text() == " ") {
+ return 0;
+ } else {
+ return _spinBoxLineWidth->value();
+ }
+}
+
+
+void CurveAppearance::populateLineStyleCombo() {
+
+ QStyleOptionComboBox option;
+ option.initFrom(_comboLineStyle);
+ option.currentIcon = _comboLineStyle->itemIcon(_comboLineStyle->currentIndex());
+ option.currentText = _comboLineStyle->itemText(_comboLineStyle->currentIndex());
+ option.editable = _comboLineStyle->isEditable();
+ option.frame = _comboLineStyle->hasFrame();
+ option.iconSize = _comboLineStyle->iconSize();
+
+ QRect rect = _comboLineStyle->style()->subControlRect(
+ QStyle::CC_ComboBox,
+ &option,
+ QStyle::SC_ComboBoxEditField,
+ _comboLineStyle );
+ rect.setLeft(rect.left() + 2);
+ rect.setRight(rect.right() - 2);
+ rect.setTop(rect.top() + 2);
+ rect.setBottom(rect.bottom() - 2);
+
+_comboLineStyle->setIconSize(QSize(rect.height(), rect.width()));
+
+ // fill the point type dialog with point types
+ QPixmap ppix(rect.width(), rect.height());
+ QPainter pp(&ppix);
+ QPen pen(color(), 0);
+
+ int currentItem = _comboLineStyle->currentIndex();
+ _comboLineStyle->clear();
+
+ for (int style = 0; style < (int)LINESTYLE_MAXTYPE; style++) {
+ pen.setStyle(LineStyle[style]);
+ pp.setPen(pen);
+ pp.fillRect( pp.window(), QColor("white"));
+ pp.drawLine(1,ppix.height()/2,ppix.width()-1, ppix.height()/2);
+ _comboLineStyle->addItem(QIcon(ppix), QString::null);
+ }
+
+ if (currentItem > 0) {
+ _comboLineStyle->setCurrentIndex( currentItem );
+ }
+}
+
+
+void CurveAppearance::drawSampleLine() {
+ QPixmap pix(_label->contentsRect().height()*7, _label->contentsRect().height());
+ QPainter p(&pix);
+ QPen pen(color(),lineWidth(),LineStyle[lineStyle()]);
+
+ p.fillRect(p.window(), QColor("white"));
+
+ if (showBars()) {
+ QRect rectBar((pix.width()-pix.height())/2,
+ pix.height()/2,
+ pix.height(),
+ (pix.height()/2)+1);
+
+ if (barStyle() == 1) {
+ p.fillRect(rectBar,QBrush(QColor(color())));
+ p.setPen(QPen(QColor("black"),lineWidth(), LineStyle[lineStyle()]));
+ } else {
+ p.setPen(pen);
+ }
+ p.drawRect(rectBar);
+ }
+
+ p.setPen(pen);
+ if (_showLines->isChecked()) {
+ p.drawLine(1, pix.height()/2, pix.width()-1, pix.height()/2);
+ }
+
+ if (_showPoints->isChecked()) {
+ pen.setStyle(Qt::SolidLine);
+ p.setPen(pen);
+ CurvePointSymbol::draw(pointType(), &p, pix.width()/2, pix.height()/2, lineWidth(), 600);
+ }
+
+ _label->setPixmap(pix);
+}
+
+
+}
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/widgets/curveappearance.h #723464:723465
@@ -24,6 +24,22 @@
public:
CurveAppearance(QWidget *parent = 0);
virtual ~CurveAppearance();
+
+ bool showLines();
+ bool showPoints();
+ bool showBars();
+ QColor color();
+ int pointType();
+ int lineStyle();
+ int lineWidth();
+ int barStyle();
+ int pointDensity();
+
+ private slots:
+ void enableSettings();
+ void drawSampleLine();
+ void populatePointSymbolCombo();
+ void populateLineStyleCombo();
};
}
--- branches/work/kst/portto4/kst/src/widgets/curveappearance.ui #723464:723465
@@ -43,54 +43,58 @@
<string>Appearance</string>
</property>
<layout class="QGridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="_label" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Fixed" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="frameShape" >
- <enum>QFrame::NoFrame</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Plain</enum>
- </property>
- <property name="scaledContents" >
- <bool>true</bool>
- </property>
- <property name="wordWrap" >
- <bool>false</bool>
- </property>
- </widget>
+ <item row="0" column="0" colspan="7" >
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="_label" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Preferred" hsizetype="Fixed" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="scaledContents" >
+ <bool>true</bool>
+ </property>
+ <property name="wordWrap" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Kst::ColorButton" name="_color" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>30</width>
+ <height>21</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
</item>
- <item row="0" column="1" >
- <widget class="Kst::ColorButton" name="_color" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item row="0" column="2" colspan="5" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>230</width>
- <height>21</height>
- </size>
- </property>
- </spacer>
- </item>
<item row="1" column="0" colspan="3" >
<widget class="QCheckBox" name="_showPoints" >
<property name="sizePolicy" >
@@ -133,12 +137,12 @@
<bool>false</bool>
</property>
<property name="buddy" >
- <cstring>_combo</cstring>
+ <cstring>_comboPointSymbol</cstring>
</property>
</widget>
</item>
<item row="1" column="4" >
- <widget class="QComboBox" name="_combo" >
+ <widget class="QComboBox" name="_comboPointSymbol" >
<property name="enabled" >
<bool>false</bool>
</property>
@@ -382,7 +386,7 @@
<string>&Bargraph</string>
</property>
<property name="checked" >
- <bool>true</bool>
+ <bool>false</bool>
</property>
</widget>
</item>
@@ -407,6 +411,9 @@
</item>
<item row="3" column="4" colspan="3" >
<widget class="QComboBox" name="_barStyle" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
@@ -459,7 +466,7 @@
<tabstops>
<tabstop>_color</tabstop>
<tabstop>_showPoints</tabstop>
- <tabstop>_combo</tabstop>
+ <tabstop>_comboPointSymbol</tabstop>
<tabstop>_comboPointDensity</tabstop>
<tabstop>_showLines</tabstop>
<tabstop>_comboLineStyle</tabstop>
More information about the Kst
mailing list