Commit 0b76582e authored by Fredrik Edemar's avatar Fredrik Edemar

* Use KRadioAction:s + a "no zoom" -item" instead of KToggleAction:s for the zoom menu.

* Don't lose the color settings in the functions if you set a new default color.
* Use the inverted color of the background for the "Fadenkreuz" so you always can see it.
* You can choose if you want to print with transparent background or not.
* Make the file-loading work again for both new and old Kmplot-files.
* When a zoom mode is enabled: use a different mouse cursor.
* Removed some old uncommented code in KPrinterDlg and renamed kcfg_printHeaderTable to printHeaderTable to prevent confusion with KConfig XT.


CCMAIL:kdmoeller@foni.net
CCMAIL:bmlmessmer@web.de

svn path=/trunk/kdeedu/kmplot/; revision=319110
parent c88a4c20
......@@ -13,7 +13,7 @@ TODO
* get slope for a x-point
* Fix the unpolished lines
* #52887, need to calculate with complex numbers.
* Replace KFile with KIO in KmplotIO
* Replace QFile with KIO in KmplotIO
TODO for KDE 3.3
=========================
......@@ -28,6 +28,8 @@ IN PROGRESS
* Configure Dialog for global Settings / save as default Checkboxes (Started)
* A mode for zooming. Ability to disable it with kiosk
* Fix scaling
* Change icon when zooming
* Ability to print background color
DONE
......
......@@ -145,11 +145,14 @@ void MainDlg::setupActions()
( void ) new KAction( i18n( "Edit Plots..." ), "editplots", 0, this, SLOT( slotEditPlots() ), actionCollection(), "editplots" );
//zoom menu
KToggleAction * mnuRectangular = new KToggleAction(i18n("&Zoom rectangular") ,0,view, SLOT( mnuRectangular_clicked() ),actionCollection(),"zoom_rectangular" );
KToggleAction * mnuZoomIn = new KToggleAction(i18n("&Zoom in") ,0,view, SLOT( mnuZoomIn_clicked() ),actionCollection(),"zoom_in" );
KToggleAction * mnuZoomOut = new KToggleAction(i18n("&Zoom out") ,0,view, SLOT( mnuZoomOut_clicked() ),actionCollection(),"zoom_out" );
KToggleAction * mnuZoomCenter = new KToggleAction(i18n("&Center a point") ,0,view, SLOT( mnuCenter_clicked() ),actionCollection(),"zoom_center" );
KRadioAction * mnuNoZoom = new KRadioAction(i18n("&No zoom") ,0,view, SLOT( mnuNoZoom_clicked() ),actionCollection(),"no_zoom" );
KRadioAction * mnuRectangular = new KRadioAction(i18n("&Zoom rectangular") ,0,view, SLOT( mnuRectangular_clicked() ),actionCollection(),"zoom_rectangular" );
KRadioAction * mnuZoomIn = new KRadioAction(i18n("&Zoom in") ,0,view, SLOT( mnuZoomIn_clicked() ),actionCollection(),"zoom_in" );
KRadioAction * mnuZoomOut = new KRadioAction(i18n("&Zoom out") ,0,view, SLOT( mnuZoomOut_clicked() ),actionCollection(),"zoom_out" );
KRadioAction * mnuZoomCenter = new KRadioAction(i18n("&Center a point") ,0,view, SLOT( mnuCenter_clicked() ),actionCollection(),"zoom_center" );
(void ) new KAction(i18n("&Fit widget to trigonometric functions") ,0,view, SLOT( mnuTrig_clicked() ),actionCollection(),"zoom_trig" );
mnuNoZoom->setExclusiveGroup("zoom_modes");
mnuNoZoom->setChecked(true);
mnuRectangular->setExclusiveGroup("zoom_modes");
mnuZoomIn->setExclusiveGroup("zoom_modes");
mnuZoomOut->setExclusiveGroup("zoom_modes");
......@@ -480,6 +483,10 @@ void MainDlg::slotQuickEdit(const QString& tmp_f_str )
view->parser()->delfkt( index );
return;
}
view->parser()->fktext[index].color = view->parser()->fktext[index].color0;
view->parser()->fktext[index].f1_color = view->parser()->fktext[index].color0;
view->parser()->fktext[index].f2_color = view->parser()->fktext[index].color0;
view->parser()->fktext[index].anti_color = view->parser()->fktext[index].color0;
view->parser()->fktext[index].f_mode = 1;
view->parser()->fktext[index].anti_precision=Settings::relativeStepWidth();
view->parser()->fktext[ index ].extstr = f_str;
......@@ -494,7 +501,6 @@ void MainDlg::slotCoord1()
{
Settings::setXRange( 0 );
Settings::setYRange( 0 );
view->getSettings();
m_modified = true;
view->drawPlot();
}
......@@ -503,7 +509,6 @@ void MainDlg::slotCoord2()
{
Settings::setXRange( 2 );
Settings::setYRange( 0 );
view->getSettings();
m_modified = true;
view->drawPlot();
}
......@@ -512,7 +517,6 @@ void MainDlg::slotCoord3()
{
Settings::setXRange( 2 );
Settings::setYRange( 2 );
view->getSettings();
m_modified = true;
view->drawPlot();
}
......
......@@ -32,6 +32,7 @@
// KDE includes
#include <kaction.h>
#include <kapplication.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
......@@ -89,6 +90,7 @@ View::View(KPopupMenu *m, QWidget* parent, const char* name ) : QWidget( parent,
csflg=0;
csmode=-1;
backgroundcolor = Settings::backgroundcolor();
invertColor(backgroundcolor,inverted_backgroundcolor);
setBackgroundColor(backgroundcolor);
setMouseTracking(TRUE);
areaDraw = false;
......@@ -159,6 +161,12 @@ void View::draw(QPaintDevice *dev, int form)
m_printHeaderTable = ( ( KPrinter* ) dev )->option( "app-kmplot-printtable" ) != "-1";
drawHeaderTable( &DC );
dgr.Create( ref, lx, ly, xmin, xmax, ymin, ymax );
if ( ( (KPrinter* )dev )->option( "app-kmplot-printbackground" ) == "-1" )
DC.fillRect( dgr.GetFrame(), backgroundcolor); //draw a colored background
//DC.end();
//((QPixmap *)dev)->fill(QColor("#FF00FF"));
//DC.begin(dev);
}
else if(form==2) // svg
{ ref=QPoint(0, 0);
......@@ -176,7 +184,7 @@ void View::draw(QPaintDevice *dev, int form)
dgr.Create( ref, lx, ly, xmin, xmax, ymin, ymax );
DC.end();
((QPixmap *)dev)->resize((int)(dgr.GetFrame().width()*sf), (int)(dgr.GetFrame().height()*sf));
((QPixmap *)dev)->fill();
((QPixmap *)dev)->fill(backgroundcolor);
DC.begin(dev);
DC.translate(-dgr.GetFrame().left()*sf, -dgr.GetFrame().top()*sf);
DC.scale(sf, sf);
......@@ -200,7 +208,7 @@ void View::draw(QPaintDevice *dev, int form)
area=DC.xForm(PlotArea);
hline.resize(area.width(), 1);
vline.resize(1, area.height());
stepWidth=Settings::relativeStepWidth() * (xmax-xmin) / area.width();
stepWidth=Settings::relativeStepWidth()*(xmax-xmin)/area.width();
isDrawing=true;
stop_calculating = false;
......@@ -578,7 +586,8 @@ void View::mouseMoveEvent(QMouseEvent *e)
return;
}
if ( zoom_mode!=0)
return;
if( m_popupmenushown>0 && !m_popupmenu->isShown() )
{
if ( m_popupmenushown==1)
......@@ -645,7 +654,23 @@ void View::mouseMoveEvent(QMouseEvent *e)
bitBlt(&vline, 0, 0, this, fcx=ptd.x(), area.top(), 1, area.height());
// Fadenkreuz zeichnen
QPen pen((csmode>=0)? m_parser->fktext[csmode].color : 0, 1);
QPen pen;
switch (cstype)
{
case 0:
pen.setColor( m_parser->fktext[csmode].color);
break;
case 1:
pen.setColor( m_parser->fktext[csmode].f1_color);
break;
case 2:
pen.setColor( m_parser->fktext[csmode].f2_color);
break;
default:
pen.setColor(inverted_backgroundcolor);
}
if ( pen.color() == backgroundcolor) // if the "Fadenkreuz" has the same color as the background, the "Fadenkreuz" will have the inverted color of background so you can see it easier
pen.setColor(inverted_backgroundcolor);
DC.begin(this);
DC.setPen(pen);
......@@ -775,7 +800,6 @@ void View::mousePressEvent(QMouseEvent *e)
stop_calculating = true;
return;
}
if(e->button()==RightButton) //clicking with the right mouse button
{
g=tlgy/5.;
......@@ -881,6 +905,7 @@ void View::mousePressEvent(QMouseEvent *e)
m_minmax->selectItem();
stbar->changeItem(m_parser->fktext[ ix ].extstr,4);
mouseMoveEvent(e);
kdDebug() << "Hello" << endl;
return;
}
if(fabs(csypos-m_parser->a1fkt(ix, csxpos))< g && m_parser->fktext[ix].f1_mode)
......@@ -1050,24 +1075,20 @@ void View::getSettings()
{
m_parser->setAngleMode( Settings::anglemode() );
m_parser->dicke0 = Settings::gridLineWidth();
m_parser->fktext[ 0 ].color = Settings::color0().rgb();
m_parser->fktext[ 1 ].color = Settings::color1().rgb();
m_parser->fktext[ 2 ].color = Settings::color2().rgb();
m_parser->fktext[ 3 ].color = Settings::color3().rgb();
m_parser->fktext[ 4 ].color = Settings::color4().rgb();
m_parser->fktext[ 5 ].color = Settings::color5().rgb();
m_parser->fktext[ 6 ].color = Settings::color6().rgb();
m_parser->fktext[ 7 ].color = Settings::color7().rgb();
m_parser->fktext[ 8 ].color = Settings::color8().rgb();
m_parser->fktext[ 9 ].color = Settings::color9().rgb();
m_parser->fktext[ 0 ].color0 = Settings::color0().rgb();
m_parser->fktext[ 1 ].color0 = Settings::color1().rgb();
m_parser->fktext[ 2 ].color0 = Settings::color2().rgb();
m_parser->fktext[ 3 ].color0 = Settings::color3().rgb();
m_parser->fktext[ 4 ].color0 = Settings::color4().rgb();
m_parser->fktext[ 5 ].color0 = Settings::color5().rgb();
m_parser->fktext[ 6 ].color0 = Settings::color6().rgb();
m_parser->fktext[ 7 ].color0 = Settings::color7().rgb();
m_parser->fktext[ 8 ].color0 = Settings::color8().rgb();
m_parser->fktext[ 9 ].color0 = Settings::color9().rgb();
for (int i=0;i<10;i++)
{
m_parser->fktext[i].f1_color = m_parser->fktext[i].color;
m_parser->fktext[i].f2_color = m_parser->fktext[i].color;
m_parser->fktext[i].anti_color = m_parser->fktext[i].color;
}
backgroundcolor = Settings::backgroundcolor();
invertColor(backgroundcolor,inverted_backgroundcolor);
setBackgroundColor(backgroundcolor);
}
void View::init()
......@@ -1699,34 +1720,35 @@ void View::mnuEdit_clicked()
drawPlot();
}
}
void View::mnuNoZoom_clicked()
{
setCursor(Qt::ArrowCursor);
zoom_mode = 0;
}
void View::mnuRectangular_clicked()
{
if ( zoom_mode == 1)
zoom_mode = 0;
else
zoom_mode = 1;
setCursor(Qt::CrossCursor);
zoom_mode = 1;
}
void View::mnuZoomIn_clicked()
{
if ( zoom_mode == 2)
zoom_mode = 0;
else
zoom_mode = 2;
//QCursor custom( KGlobal::iconLoader()->loadIcon("viewmag+",KIcon::MainToolbar),1,1 );
//setCursor(custom);
setCursor(Qt::CrossCursor);
zoom_mode = 2;
}
void View::mnuZoomOut_clicked()
{
if ( zoom_mode == 3)
zoom_mode = 0;
else
zoom_mode = 3;
//QCursor custom( KGlobal::iconLoader()->loadIcon("viewmag+",KIcon::MainToolbar),1,1 );
//setCursor(custom);
setCursor(Qt::CrossCursor);
zoom_mode = 3;
}
void View::mnuCenter_clicked()
{
if ( zoom_mode == 5)
zoom_mode = 0;
else
zoom_mode = 5;
setCursor(Qt::PointingHandCursor);
zoom_mode = 5;
}
void View::mnuTrig_clicked()
{
......@@ -1748,4 +1770,16 @@ void View::mnuTrig_clicked()
Settings::setYRange(4); //custom y-range
drawPlot(); //update all graphs
return;
}
void View::invertColor(QColor &org, QColor &inv)
{
int r = org.red()-255;
if ( r<0) r=r*-1;
int g = org.green()-255;
if ( g<0) g=g*-1;
int b = org.blue()-255;
if ( b<0) b=b*-1;
inv.setRgb(r,g,b);
}
\ No newline at end of file
......@@ -129,6 +129,7 @@ public slots:
void mnuRemove_clicked();
void mnuEdit_clicked();
///Slots for the zoom menu
void mnuNoZoom_clicked();
void mnuRectangular_clicked();
void mnuZoomIn_clicked();
void mnuZoomOut_clicked();
......@@ -145,7 +146,7 @@ protected slots:
void mousePressEvent(QMouseEvent *);
/// when a key is pressed and the graph widget has focus
void keyPressEvent(QKeyEvent * );
/// called when a mouse key is released
void mouseReleaseEvent ( QMouseEvent * e );
private:
......@@ -158,6 +159,8 @@ private:
void setpi(QString *);
/// in trace mode checks, if the function is (near by) zero
bool root(double *);
///return the inverted color
void invertColor(QColor &, QColor &);
/// The central parser instance.
/// @see parser()
......@@ -226,6 +229,8 @@ private:
bool stop_calculating;
/// the background color of the graph
QColor backgroundcolor;
/// the inverted background color used by the "Fadenkreuz"
QColor inverted_backgroundcolor;
/// pointer to KMinMax
KMinMax *m_minmax;
///buffer the current window so all functions don't need to be re-drawed
......
......@@ -91,14 +91,14 @@ void EditFunction::clearWidgets()
editfunctionpage->min->clear();
editfunctionpage->max->clear();
editfunctionpage->lineWidth->setValue( m_parser->dicke0 );
editfunctionpage->color->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color );
editfunctionpage->color->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color0 );
// Clear the Derivatives page
editderivativespage->showDerivative1->setChecked( false );
editderivativespage->lineWidthDerivative1->setValue( 1 );
editderivativespage->lineWidthDerivative1->setValue( editfunctionpage->lineWidth->value() );
editderivativespage->colorDerivative1->setColor( editfunctionpage->color->color() );
editderivativespage->showDerivative2->setChecked( false );
editderivativespage->lineWidthDerivative2->setValue( 1 );
editderivativespage->lineWidthDerivative2->setValue( editfunctionpage->lineWidth->value() );
editderivativespage->colorDerivative2->setColor( editfunctionpage->color->color() );
// Clear the Antiderivative page
......@@ -299,7 +299,10 @@ void EditFunction::accept()
m_parser->fktext[index].anti_linewidth = editantiderivativepage->lineWidthAntiderivative->value();
}
else
{
m_parser->fktext[index].anti_mode = 0;
m_parser->fktext[index].anti_color = m_parser->fktext[index].color0; //default color
}
if( editfunctionpage->hide->isChecked() )
m_parser->fktext[ index ].f_mode = 0;
......@@ -329,7 +332,10 @@ void EditFunction::accept()
m_parser->fktext[ index ].f1_color = editderivativespage->colorDerivative1->color().rgb();
}
else
{
m_parser->fktext[ index ].f1_mode = 0;
m_parser->fktext[index].f1_color = m_parser->fktext[index].color0; //default color
}
if( editderivativespage->showDerivative2->isChecked() )
{
......@@ -338,7 +344,10 @@ void EditFunction::accept()
m_parser->fktext[ index ].f2_color = editderivativespage->colorDerivative2->color().rgb();
}
else
{
m_parser->fktext[index].f1_color = m_parser->fktext[index].color0; //default color
m_parser->fktext[ index ].f2_mode = 0;
}
// call inherited method
KDialogBase::accept();
......
......@@ -64,7 +64,7 @@ void KEditParametric::clearWidgets()
checkBoxRange->setChecked( false );
min->clear();
max->clear();
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color0 );
}
void KEditParametric::setWidgets()
......
......@@ -63,7 +63,7 @@ void KEditPolar::clearWidgets()
min->clear();
max->clear();
kIntNumInputLineWidth->setValue( m_parser->dicke0 );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].color0 );
}
void KEditPolar::setWidgets()
......
......@@ -210,13 +210,4 @@
<whatsthis>The value the zoom in/out-tool should use</whatsthis>
</entry>
</group>
<!--
<group name="KPrinter ">
<entry name="printHeaderTable" type="Bool">
<default>true</default>
<label>print a table with information at the top of the page</label>
</entry>
</group>
-->
</kcfg>
......@@ -95,8 +95,9 @@ void KmPlotIO::save( XParser *parser, const QString filename )
tag = doc.createElement( "scale" );
const char* units[ 8 ] = { "10", "5", "2", "1", "0.5", "pi/2", "pi/3", "pi/4" };
const char* units[ 9 ] = { "10", "5", "2", "1", "0.5", "pi/2", "pi/3", "pi/4","automatic"};
addTag( doc, tag, "tic-x", units[ Settings::xScaling() ] );
kdDebug() << units[ Settings::xScaling() ] << endl;
addTag( doc, tag, "tic-y", units[ Settings::yScaling() ] );
addTag( doc, tag, "print-tic-x", units[ Settings::xPrinting() ] );
addTag( doc, tag, "print-tic-y", units[ Settings::yPrinting() ] );
......@@ -182,7 +183,7 @@ void KmPlotIO::load( XParser *parser, const QString filename )
for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
{
if ( n.nodeName() == "axes" )
parseAxes( n.toElement() );
oldParseAxes( n.toElement() );
if ( n.nodeName() == "grid" )
parseGrid( n.toElement() );
if ( n.nodeName() == "scale" )
......@@ -239,10 +240,10 @@ void KmPlotIO::parseGrid( const QDomElement & n )
int unit2index( const QString unit )
{
const char* units[ 8 ] = { "10", "5", "2", "1", "0.5", "pi/2", "pi/3", "pi/4" };
const char* units[ 9 ] = { "10", "5", "2", "1", "0.5", "pi/2", "pi/3", "pi/4","automatic" };
int index = 0;
while( ( index < 8 ) && ( unit!= units[ index ] ) ) index ++;
if( index == 8 ) index = -1;
while( ( index < 9 ) && ( unit!= units[ index ] ) ) index ++;
if( index == 9 ) index = -1;
return index;
}
......@@ -325,6 +326,9 @@ void KmPlotIO::oldParseFunction( XParser *parser, const QDomElement & n )
parser->fktext[ ix ].f2_mode = n.attribute( "visible-2nd-deriv" ).toInt();
parser->fktext[ ix ].linewidth = n.attribute( "width" ).toInt();
parser->fktext[ ix ].color = QColor( n.attribute( "color" ) ).rgb();
parser->fktext[ ix ].f1_color = parser->fktext[ ix ].color;
parser->fktext[ ix ].f2_color = parser->fktext[ ix ].color;
parser->fktext[ ix ].anti_color = parser->fktext[ ix ].color;
parser->fktext[ ix ].extstr = n.namedItem( "equation" ).toElement().text();
QCString fstr = parser->fktext[ ix ].extstr.utf8();
......@@ -340,3 +344,23 @@ void KmPlotIO::oldParseFunction( XParser *parser, const QDomElement & n )
parser->getext( ix );
}
}
void KmPlotIO::oldParseAxes( const QDomElement &n )
{
Settings::setAxesLineWidth( n.attribute( "width", "1" ).toInt() );
Settings::setAxesColor( QColor( n.attribute( "color", "#000000" ) ) );
Settings::setTicWidth( n.attribute( "tic-width", "3" ).toInt() );
Settings::setTicLength( n.attribute( "tic-length", "10" ).toInt() );
Settings::setShowAxes( true );
Settings::setShowArrows( true );
Settings::setShowLabel( true );
Settings::setShowFrame( true );
Settings::setShowExtraFrame( true );
Settings::setXRange( n.namedItem( "xcoord" ).toElement().text().toInt() );
Settings::setXMin( n.namedItem( "xmin" ).toElement().text() );
Settings::setXMax( n.namedItem( "xmax" ).toElement().text() );
Settings::setYRange( n.namedItem( "ycoord" ).toElement().text().toInt() );
Settings::setYMin( n.namedItem( "ymin" ).toElement().text() );
Settings::setYMax( n.namedItem( "ymax" ).toElement().text() );
}
\ No newline at end of file
......@@ -79,6 +79,8 @@ class KmPlotIO
static void parseFunction( XParser *parser, const QDomElement &n );
/// This is the same as parseFunction but is made for old Kmplot-files
static void oldParseFunction( XParser *parser, const QDomElement &n );
/// This is the same as parseAxes but is made for old Kmplot-files
static void oldParseAxes( const QDomElement &n );
/// Reads parameter values for a function from the node @a n.
/// @param parser points to the parser instance.
/// @param n Node containing the options.
......
......@@ -22,6 +22,7 @@
</Menu>
<Menu name="zoom" noMerge="1"><text>&amp;Zoom</text>
<Action name="no_zoom"/>
<Action name="zoom_rectangular"/>
<Action name="zoom_in"/>
<Action name="zoom_out"/>
......
......@@ -42,22 +42,25 @@ KPrinterDlg::KPrinterDlg( QWidget *parent, const char *name )
layout->setSpacing( KDialog::spacingHint() );
kcfg_printHeaderTable = new QCheckBox( i18n( "Print header table" ), this );
layout->addWidget( kcfg_printHeaderTable );
printHeaderTable = new QCheckBox( i18n( "Print header table" ), this );
transparent_background = new QCheckBox( i18n( "Transparent background" ), this );
layout->addWidget( printHeaderTable );
layout->addWidget( transparent_background );
layout->addStretch( 1 );
}
void KPrinterDlg::getOptions( QMap<QString, QString>& opts, bool include_def )
{
if ( include_def || !kcfg_printHeaderTable->isChecked() )
opts[ "app-kmplot-printtable" ] = ( kcfg_printHeaderTable->isChecked() ? "1" : "-1" );
// Settings::setPrintHeaderTable( kcfg_printHeaderTable->isChecked() );
if ( include_def || !printHeaderTable->isChecked() )
opts[ "app-kmplot-printtable" ] = ( printHeaderTable->isChecked() ? "1" : "-1" );
if ( include_def || !transparent_background->isChecked() )
opts[ "app-kmplot-printbackground" ] = ( transparent_background->isChecked() ? "1" : "-1" );
}
void KPrinterDlg::setOptions( const QMap<QString, QString>& opts )
{
kcfg_printHeaderTable->setChecked( opts[ "app-kmplot-printtable" ] != "-1" );
// kcfg_printHeaderTable->setChecked( Settings::printHeaderTable() );
printHeaderTable->setChecked( opts[ "app-kmplot-printtable" ] != "-1" );
transparent_background->setChecked( opts[ "app-kmplot-printbackground" ] != "-1" );
}
bool KPrinterDlg::isValid( QString& )
......
......@@ -53,7 +53,8 @@ public:
/// Reimplemented.
bool isValid( QString& msg );
/// The check box for the option.
QCheckBox *kcfg_printHeaderTable;
QCheckBox *printHeaderTable;
QCheckBox *transparent_background;
};
#endif //kprinterdlg_included
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