Commit e3ac03b5 authored by David Saxton's avatar David Saxton

Allow changing of plot line style (e.g. solid, dash, dot, etc). "Appearance"

group box needs improving though - atm it is slightly cluttered.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=529047
parent 2b5ae4e6
......@@ -496,8 +496,21 @@ void View::plotfkt(Function *ufkt, QPainter *pDC)
}
bool View::penShouldDraw( double _totalLength, Function * function, Function::PMode pmode )
// does for real numbers what "%" does for integers
double realModulo( double x, double mod )
{
x = qAbs(x);
mod = qAbs(mod);
return x - floor(x/mod)*mod;
}
bool View::penShouldDraw( double length, Function * function, Function::PMode pmode )
{
// Always use a solid line when translating the view
if ( m_zoomMode == Translating )
return true;
Qt::PenStyle style = Qt::SolidLine;
switch ( pmode )
{
......@@ -518,11 +531,11 @@ bool View::penShouldDraw( double _totalLength, Function * function, Function::PM
break;
}
int sep = 7; // separation distance between dots or dashes
int dash = 9; // length of a dash
int dot = 3; // length of a dot
int totalLength = int( qAbs( _totalLength ) );
double sepBig = 8.0; // separation distance between dashes
double sepMid = 7.0; // separation between a dash and a dot
double sepSmall = 6.5; // separation distance between dots
double dash = 9.0; // length of a dash
double dot = 3.5; // length of a dot
switch ( style )
{
......@@ -534,37 +547,37 @@ bool View::penShouldDraw( double _totalLength, Function * function, Function::PM
return true;
case Qt::DashLine:
return (totalLength % (dash + sep)) < dash;
return realModulo( length, dash + sepBig ) < dash;
case Qt::DotLine:
return (totalLength % (dot + sep)) < dot;
return realModulo( length, dot + sepSmall ) < dot;
case Qt::DashDotLine:
{
int at = totalLength % (dash + sep + dot + sep);
double at = realModulo( length, dash + sepMid + dot + sepMid );
if ( at < dash )
return true;
if ( at < (dash + sep) )
if ( at < (dash + sepMid) )
return false;
if ( at < (dash + sep + dot) )
if ( at < (dash + sepMid + dot) )
return true;
return false;
}
case Qt::DashDotDotLine:
{
int at = totalLength % (dash + sep + dot + sep + dot + sep);
double at = realModulo( length, dash + sepMid + dot + sepSmall + dot + sepMid );
if ( at < dash )
return true;
if ( at < (dash + sep) )
if ( at < (dash + sepMid) )
return false;
if ( at < (dash + sep + dot) )
if ( at < (dash + sepMid + dot) )
return true;
if ( at < (dash + sep + dot) )
if ( at < (dash + sepMid + dot + sepSmall) )
return false;
if ( at < (dash + sep + dot + dot) )
if ( at < (dash + sepMid + dot + sepSmall + dot) )
return true;
return false;
}
......@@ -585,8 +598,16 @@ bool View::penShouldDraw( double _totalLength, Function * function, Function::PM
QPen View::penForPlot( Function *ufkt, Function::PMode p_mode, bool antialias ) const
{
QPen pen;
pen.setCapStyle( Qt::RoundCap );
// pen.setStyle( Qt::DashLine );
if ( m_zoomMode == Translating )
{
// plot style is always a solid line when translating the view
pen.setCapStyle( Qt::FlatCap );
}
else
{
pen.setCapStyle( Qt::RoundCap );
// (the style will be set back to FlatCap if the plot style is a solid line)
}
double lineWidth_mm = 0.0;
......
......@@ -24,11 +24,19 @@
#include "function.h"
#include "plotstylewidget.h"
#include <klocale.h>
//BEGIN class PlotStyleWidget
PlotStyleWidget::PlotStyleWidget( QWidget * parent )
: QGroupBox( parent )
{
setupUi(this);
lineStyle->addItem( i18n("Solid"), Qt::SolidLine );
lineStyle->addItem( i18n("Dash"), Qt::DashLine );
lineStyle->addItem( i18n("Dot"), Qt::DotLine );
lineStyle->addItem( i18n("Dash Dot"), Qt::DashDotLine );
lineStyle->addItem( i18n("Dash Dot Dot"), Qt::DashDotDotLine );
}
......@@ -45,8 +53,21 @@ Plot PlotStyleWidget::plot( bool visible )
p.color = color->color();
p.lineWidth = lineWidth->value();
p.visible = visible;
p.style = style();
return p;
}
Qt::PenStyle PlotStyleWidget::style( ) const
{
return (Qt::PenStyle)lineStyle->itemData( lineStyle->currentIndex() ).toInt();
}
void PlotStyleWidget::setStyle( Qt::PenStyle style )
{
lineStyle->setCurrentIndex( lineStyle->findData( style ) );
}
//END class PlotStyleWidget
#include "plotstylewidget.moc"
......@@ -46,6 +46,14 @@ class PlotStyleWidget : public QGroupBox, public Ui_PlotStyleWidet
* control that aspect of a Plot).
*/
Plot plot( bool visible );
/**
* \return the currently selected style.
*/
Qt::PenStyle style() const;
/**
* Sets the currently selected style.
*/
void setStyle( Qt::PenStyle style );
};
#endif
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>327</width>
<height>76</height>
<width>434</width>
<height>201</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -22,20 +22,17 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="KColorButton" name="color" >
<property name="toolTip" >
<string>color of the plot line</string>
</property>
<property name="whatsThis" >
<string>Click this button to choose a color for the plot line.</string>
</property>
<item row="2" column="0" >
<widget class="QLabel" name="textLabel1_3" >
<property name="text" >
<string/>
<string>&amp;Width:</string>
</property>
<property name="buddy" >
<cstring>lineWidth</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="2" column="1" >
<widget class="QDoubleSpinBox" name="lineWidth" >
<property name="alignment" >
<set>Qt::AlignRight</set>
......@@ -54,13 +51,16 @@
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel1_3" >
<property name="text" >
<string>Line &amp;width:</string>
<item row="0" column="1" >
<widget class="KColorButton" name="color" >
<property name="toolTip" >
<string>color of the plot line</string>
</property>
<property name="buddy" >
<cstring>lineWidth</cstring>
<property name="whatsThis" >
<string>Click this button to choose a color for the plot line.</string>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
......@@ -74,6 +74,19 @@
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>&amp;Style:</string>
</property>
<property name="buddy" >
<cstring>lineStyle</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="lineStyle" />
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
......@@ -86,6 +99,11 @@
<pixmap></pixmap>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>color</tabstop>
<tabstop>lineStyle</tabstop>
<tabstop>lineWidth</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment