From d63c9d696eb6e2539528b99afc21f4086c9defe3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 8b78a8791bc539bcffe7159f9d9714d577cb3d7d) --- kchart/ChangeLog | 182 +- kchart/KChartParamsIface.cc | 464 ----- kchart/KChartParamsIface.cpp | 464 +++++ kchart/KChartViewIface.cc | 100 -- kchart/KChartViewIface.cpp | 100 ++ kchart/Makefile.am | 62 +- kchart/csvimportdialog.cc | 633 ------- kchart/csvimportdialog.cpp | 633 +++++++ kchart/kchartBackgroundPixmapConfigPage.cc | 548 ------ kchart/kchartBackgroundPixmapConfigPage.cpp | 548 ++++++ kchart/kchartColorConfigPage.cc | 220 --- kchart/kchartColorConfigPage.cpp | 220 +++ kchart/kchartComboConfigPage.cc | 137 -- kchart/kchartComboConfigPage.cpp | 137 ++ kchart/kchartConfigDialog.cc | 438 ----- kchart/kchartConfigDialog.cpp | 438 +++++ kchart/kchartDataConfigPage.cc | 149 -- kchart/kchartDataConfigPage.cpp | 149 ++ kchart/kchartDataEditor.cc | 900 ---------- kchart/kchartDataEditor.cpp | 900 ++++++++++ kchart/kchartFontConfigPage.cc | 308 ---- kchart/kchartFontConfigPage.cpp | 308 ++++ kchart/kchartHeaderFooterConfigPage.cc | 182 -- kchart/kchartHeaderFooterConfigPage.cpp | 182 ++ kchart/kchartLegendConfigPage.cc | 385 ----- kchart/kchartLegendConfigPage.cpp | 385 +++++ kchart/kchartLine3dConfigPage.cc | 151 -- kchart/kchartLine3dConfigPage.cpp | 151 ++ kchart/kchartPageLayout.cc | 120 -- kchart/kchartPageLayout.cpp | 120 ++ kchart/kchartParameter3dConfigPage.cc | 126 -- kchart/kchartParameter3dConfigPage.cpp | 126 ++ kchart/kchartParameterConfigPage.cc | 374 ---- kchart/kchartParameterConfigPage.cpp | 374 ++++ kchart/kchartParameterPieConfigPage.cc | 109 -- kchart/kchartParameterPieConfigPage.cpp | 109 ++ kchart/kchartParameterPolarConfigPage.cc | 86 - kchart/kchartParameterPolarConfigPage.cpp | 86 + kchart/kchartPieConfigPage.cc | 196 --- kchart/kchartPieConfigPage.cpp | 196 +++ kchart/kchartPrinterDlg.cc | 85 - kchart/kchartPrinterDlg.cpp | 85 + kchart/kchartSubTypeChartPage.cc | 456 ----- kchart/kchartSubTypeChartPage.cpp | 456 +++++ kchart/kchartWizard.cc | 171 -- kchart/kchartWizard.cpp | 171 ++ kchart/kchartWizardLabelsLegendPage.cc | 340 ---- kchart/kchartWizardLabelsLegendPage.cpp | 340 ++++ kchart/kchartWizardSelectChartSubTypePage.cc | 195 --- kchart/kchartWizardSelectChartSubTypePage.cpp | 195 +++ kchart/kchartWizardSelectChartTypePage.cc | 128 -- kchart/kchartWizardSelectChartTypePage.cpp | 128 ++ kchart/kchartWizardSelectChartTypePage.h | 2 +- kchart/kchartWizardSelectDataFormatPage.cc | 113 -- kchart/kchartWizardSelectDataFormatPage.cpp | 113 ++ kchart/kchartWizardSelectDataPage.cc | 33 - kchart/kchartWizardSelectDataPage.cpp | 33 + kchart/kchartWizardSetupAxesPage.cc | 301 ---- kchart/kchartWizardSetupAxesPage.cpp | 301 ++++ kchart/kchartWizardSetupDataPage.cc | 133 -- kchart/kchartWizardSetupDataPage.cpp | 133 ++ kchart/kchart_factory.cc | 82 - kchart/kchart_factory.cpp | 82 + kchart/kchart_factory_init.cc | 23 - kchart/kchart_factory_init.cpp | 23 + kchart/kchart_params.cc | 1043 ----------- kchart/kchart_params.cpp | 1043 +++++++++++ kchart/kchart_part.cc | 2306 ------------------------- kchart/kchart_part.cpp | 2306 +++++++++++++++++++++++++ kchart/kchart_view.cc | 764 -------- kchart/kchart_view.cpp | 764 ++++++++ kchart/main.cc | 50 - kchart/main.cpp | 50 + 73 files changed, 11972 insertions(+), 11972 deletions(-) delete mode 100644 kchart/KChartParamsIface.cc create mode 100644 kchart/KChartParamsIface.cpp delete mode 100644 kchart/KChartViewIface.cc create mode 100644 kchart/KChartViewIface.cpp delete mode 100644 kchart/csvimportdialog.cc create mode 100644 kchart/csvimportdialog.cpp delete mode 100644 kchart/kchartBackgroundPixmapConfigPage.cc create mode 100644 kchart/kchartBackgroundPixmapConfigPage.cpp delete mode 100644 kchart/kchartColorConfigPage.cc create mode 100644 kchart/kchartColorConfigPage.cpp delete mode 100644 kchart/kchartComboConfigPage.cc create mode 100644 kchart/kchartComboConfigPage.cpp delete mode 100644 kchart/kchartConfigDialog.cc create mode 100644 kchart/kchartConfigDialog.cpp delete mode 100644 kchart/kchartDataConfigPage.cc create mode 100644 kchart/kchartDataConfigPage.cpp delete mode 100644 kchart/kchartDataEditor.cc create mode 100644 kchart/kchartDataEditor.cpp delete mode 100644 kchart/kchartFontConfigPage.cc create mode 100644 kchart/kchartFontConfigPage.cpp delete mode 100644 kchart/kchartHeaderFooterConfigPage.cc create mode 100644 kchart/kchartHeaderFooterConfigPage.cpp delete mode 100644 kchart/kchartLegendConfigPage.cc create mode 100644 kchart/kchartLegendConfigPage.cpp delete mode 100644 kchart/kchartLine3dConfigPage.cc create mode 100644 kchart/kchartLine3dConfigPage.cpp delete mode 100644 kchart/kchartPageLayout.cc create mode 100644 kchart/kchartPageLayout.cpp delete mode 100644 kchart/kchartParameter3dConfigPage.cc create mode 100644 kchart/kchartParameter3dConfigPage.cpp delete mode 100644 kchart/kchartParameterConfigPage.cc create mode 100644 kchart/kchartParameterConfigPage.cpp delete mode 100644 kchart/kchartParameterPieConfigPage.cc create mode 100644 kchart/kchartParameterPieConfigPage.cpp delete mode 100644 kchart/kchartParameterPolarConfigPage.cc create mode 100644 kchart/kchartParameterPolarConfigPage.cpp delete mode 100644 kchart/kchartPieConfigPage.cc create mode 100644 kchart/kchartPieConfigPage.cpp delete mode 100644 kchart/kchartPrinterDlg.cc create mode 100644 kchart/kchartPrinterDlg.cpp delete mode 100644 kchart/kchartSubTypeChartPage.cc create mode 100644 kchart/kchartSubTypeChartPage.cpp delete mode 100644 kchart/kchartWizard.cc create mode 100644 kchart/kchartWizard.cpp delete mode 100644 kchart/kchartWizardLabelsLegendPage.cc create mode 100644 kchart/kchartWizardLabelsLegendPage.cpp delete mode 100644 kchart/kchartWizardSelectChartSubTypePage.cc create mode 100644 kchart/kchartWizardSelectChartSubTypePage.cpp delete mode 100644 kchart/kchartWizardSelectChartTypePage.cc create mode 100644 kchart/kchartWizardSelectChartTypePage.cpp delete mode 100644 kchart/kchartWizardSelectDataFormatPage.cc create mode 100644 kchart/kchartWizardSelectDataFormatPage.cpp delete mode 100644 kchart/kchartWizardSelectDataPage.cc create mode 100644 kchart/kchartWizardSelectDataPage.cpp delete mode 100644 kchart/kchartWizardSetupAxesPage.cc create mode 100644 kchart/kchartWizardSetupAxesPage.cpp delete mode 100644 kchart/kchartWizardSetupDataPage.cc create mode 100644 kchart/kchartWizardSetupDataPage.cpp delete mode 100644 kchart/kchart_factory.cc create mode 100644 kchart/kchart_factory.cpp delete mode 100644 kchart/kchart_factory_init.cc create mode 100644 kchart/kchart_factory_init.cpp delete mode 100644 kchart/kchart_params.cc create mode 100644 kchart/kchart_params.cpp delete mode 100644 kchart/kchart_part.cc create mode 100644 kchart/kchart_part.cpp delete mode 100644 kchart/kchart_view.cc create mode 100644 kchart/kchart_view.cpp delete mode 100644 kchart/main.cc create mode 100644 kchart/main.cpp (limited to 'kchart') diff --git a/kchart/ChangeLog b/kchart/ChangeLog index 5d38df2f..1d9263a9 100644 --- a/kchart/ChangeLog +++ b/kchart/ChangeLog @@ -13,16 +13,16 @@ Start on bug 134194: Impossible to change the data range. Step 1: Actually set and read the data area. * kchart_params.h: store the data area in the params. - * kchartDataConfigPage.cc (init): Set dataArea lineEdit. + * kchartDataConfigPage.cpp (init): Set dataArea lineEdit. (defaults): clear it (apply): set dataArea from the lineEdit - * kchartWizardSelectDataFormatPage.cc (constructor): set dataArea lineEdit + * kchartWizardSelectDataFormatPage.cpp (constructor): set dataArea lineEdit (apply): set dataArea from the lineEdit 2006-11-06 Inge Wallin Fix bug 128758: misinterpretation of the checkbox "first row as label" - * kchart_part.cc (createLabelsAndLegend): Pass parameters as + * kchart_part.cpp (createLabelsAndLegend): Pass parameters as references. 2006-10-29 Inge Wallin @@ -31,38 +31,38 @@ 2006-10-10 Inge Wallin - * kchart_params.cc (saveOasisAxis): Add saving of axis titles. + * kchart_params.cpp (saveOasisAxis): Add saving of axis titles. 2006-10-06 ---- Version 1.6.0 tagged ---- 2006-10-03 Inge Wallin - * kchart_params.cc (loadOasisPlotarea): Fix bug. Pie charts use + * kchart_params.cpp (loadOasisPlotarea): Fix bug. Pie charts use only the y axis, not only the x axis. 2006-09-28 Inge Wallin - * kchart_params.cc (loadOasisPlotarea): Add support for + * kchart_params.cpp (loadOasisPlotarea): Add support for chart:series-source (row or column): 2006-08-11 Inge Wallin Only show checkboxes in config dialog if applicable. * kchart_params.h (KChartParams::part): new method - * kchartDataConfigPage.cc: Only show the checkboxes "First row/col + * kchartDataConfigPage.cpp: Only show the checkboxes "First row/col as headers" if we have external data. 2006-08-06 Inge Wallin Disable "First row/col as label in the data editor. - * kchartDataEditor.cc (kchartDataEditor): Disable checkboxes + * kchartDataEditor.cpp (kchartDataEditor): Disable checkboxes 2006-08-04 Inge Wallin Let the Data Editor use icons for it's buttons. - * kchartDataEditor.cc (kchartDataEditor): Make the insert / delete + * kchartDataEditor.cpp (kchartDataEditor): Make the insert / delete row / col buttons show an icon instead of text. - * kchartDataEditor.cc (addDocs): Add ToolTips to the buttons. + * kchartDataEditor.cpp (addDocs): Add ToolTips to the buttons. 2006-07-18 Inge Wallin @@ -71,7 +71,7 @@ * kchartDataEditor.{h,cc} (currentChanged): New method (m_insertRowButton, m_removeRowButton, m_insertRowButton, m_removeRowButton): New members - * kchartDataEditor.cc (removeCurrentRow, removeCurrentCol): Don't + * kchartDataEditor.cpp (removeCurrentRow, removeCurrentCol): Don't allow to remove a row or column if it's the first column or if there are only 2 of them. @@ -80,9 +80,9 @@ 2006-07-17 Inge Wallin Add "first row/col as legend" checkboxes to data editor. - * kchartDataEditor.cc (kchartDataEditor): Enable existing code - * kchartDataEditor.cc (setData): Enable existing code - * kchartDataEditor.cc (getData): Enable existing code + * kchartDataEditor.cpp (kchartDataEditor): Enable existing code + * kchartDataEditor.cpp (setData): Enable existing code + * kchartDataEditor.cpp (getData): Enable existing code Simplify paintContent(): * kchart_part.{h,cc} (createLabelsAndLegend): New function @@ -99,7 +99,7 @@ Fix bug 108770: [PATCH] kchart should have a format menu * kchart.rc (Format): New menu (KChartTypes toolbar): place to the left - * kchart_view.cc (KChartView::KChartView): change strings for some + * kchart_view.cpp (KChartView::KChartView): change strings for some actions. 2005-08-08 Inge Wallin @@ -110,7 +110,7 @@ 2005-07-28 Inge Wallin Fix bug 108461: Bug in generation of HiLo charts - * kchart_part.cc (paintContent): Add code to handle HiLo chart + * kchart_part.cpp (paintContent): Add code to handle HiLo chart separately. General code cleaning. @@ -153,7 +153,7 @@ * kdchart/KDChartParams.h (lineColor): return _lineColor again. * kdchart/KDChartParams_io.h (saveXML): Only save the line color if it is non-null. - * kchart_part.cc (setAxisDefaults): Always set lineColor to + * kchart_part.cpp (setAxisDefaults): Always set lineColor to null. This compensates for the (now fixed) bug in saving when reading back old charts. @@ -169,7 +169,7 @@ Fix bug 99995: KChart should be able to import CSV data * kchart_part.{h,cc} (doSetData): new method broken out of setData() (setData): Call doSetData - kchart_view.cc (importData): Get data from the dialog and call + kchart_view.cpp (importData): Get data from the dialog and call KChartPart::doSetData() Code cleaning @@ -195,7 +195,7 @@ negative numbers in a 3D bar chart. If all bars are <= 0 the bars with value 0 will still have an arrow. - * kchart_part.cc (KChartPart), kchart_params.cc (KChartParams): + * kchart_part.cpp (KChartPart), kchart_params.cpp (KChartParams): Make sure the excess arrow is solid by calling setDrawSolidExcessArrows(true) after a chart has been loaded or created. @@ -203,7 +203,7 @@ 2005-04-13 Inge Wallin CSV import: Disable irrelevant formats - * csvimportdialog.cc (CSVImportDialog): Disable formats Currency + * csvimportdialog.cpp (CSVImportDialog): Disable formats Currency and Date. Disable "Import Data" if inside KSpread @@ -214,7 +214,7 @@ Get a file name for "Import Data" and actually read data. (No new strings). - * kchart_view.cc (importData): Open a file dialog, and read data. + * kchart_view.cpp (importData): Open a file dialog, and read data. ---------------------------------------------------------------- @@ -224,31 +224,31 @@ * csvimportdialogui.ui: new file * Makefile.am: Add files above * kchart.rc (File menu): Add Action import_data - * kchart_view.cc (import_data): new TDEAction + * kchart_view.cpp (import_data): new TDEAction (importData): new slot 2005-04-10 Inge Wallin Fix the margins on the pie config page. - * kchartParameterPieConfigPage.cc (KChartParameterPieConfigPage): + * kchartParameterPieConfigPage.cpp (KChartParameterPieConfigPage): Added a toplevel layout. 2005-04-07 Fredrik Edemar - * kchart_part.cc (KChartPart): Set modified when the chart type is + * kchart_part.cpp (KChartPart): Set modified when the chart type is changed. 2005-04-07 Inge Wallin - * kchartWizardLabelsLegendPage.cc (KChartWizardLabelsLegendPage): + * kchartWizardLabelsLegendPage.cpp (KChartWizardLabelsLegendPage): Reenable titles for X and Y axis. 2005-04-07 Fredrik Edemar - * kchart_part.cc (KChartPart): The decimal symbol and thousends + * kchart_part.cpp (KChartPart): The decimal symbol and thousends separator is the same as the rest of KDE. - * kchart_params.cc (KChartParams): Revert my last change: use + * kchart_params.cpp (KChartParams): Revert my last change: use KDChart's default precision instead. * KDChart (KDChartAxesPainter.cpp): The axis label: Use at most 6 digits after the decimal point. @@ -258,7 +258,7 @@ Fix bug 103267: Unreasonable precison in axis values * kchartParameterConfigPage.{h,cc} (KChartParameterConfigPage): Add settings for decimal precision for the left axis. - * kchart_params.cc (KChartParams): Set 2 as default decimal + * kchart_params.cpp (KChartParams): Set 2 as default decimal precision. * KDChart: If the totalLen property is >0, the text label should be truncated at the position of totalLen. @@ -268,7 +268,7 @@ 2005-04-06 Inge Wallin Enable axis titles again. - * kchartParameterConfigPage.cc (KChartParameterConfigPage): Don't + * kchartParameterConfigPage.cpp (KChartParameterConfigPage): Don't disable xtitle and ytitle. ---------------------------------------------------------------- @@ -276,15 +276,15 @@ Fix line specific settings * kchartConfigDialog.{h,cc} (linepage3d): resurrected page (all members except - * kchartLine3dConfigPage.cc (lineMarkers): new method + * kchartLine3dConfigPage.cpp (lineMarkers): new method (all 3d stuff): disabled - * kchartParameterConfigPage.cc (lineMarker): moved to the line + * kchartParameterConfigPage.cpp (lineMarker): moved to the line page. ---------------------------------------------------------------- Fix pie specific settings. - * kchartConfigDialog.cc (constructor): Move all type specific + * kchartConfigDialog.cpp (constructor): Move all type specific settings immediately after the subtype page. (constructor): disable the piepage. * kchartParameterPieConfigPage.{h,cc} (explode): new member @@ -292,10 +292,10 @@ * kchartPieConfigPage (explose): Moved to kchartParameterPieConfigPage. Code cleaning - * kchartConfigDialog.cc (constructor): order initializations + * kchartConfigDialog.cpp (constructor): order initializations logically (all): Fix indentation and other smaller stuff. - * kchart_view.cc: Remove reduntant variable actionExtraCreateTemplate. + * kchart_view.cpp: Remove reduntant variable actionExtraCreateTemplate. 2005-04-05 Fredrik Edemar * Use a better layout in KChartParameterPieConfigPage and KChartParameterPolarConfigPage. @@ -328,7 +328,7 @@ Fix bug 102414: KChart shows the startup dialog even when embedded into a spreadsheet. - * kchart_part.cc (constructor): Initialize members but don't call + * kchart_part.cpp (constructor): Initialize members but don't call initDoc(). (initDoc): don't initialize members, and return immediately if called for an embedded chart. @@ -342,14 +342,14 @@ (misc): set m_modified if data changed, including headers. * kchart_part.{h,cc} (slotModified): new slot (setData): connect wizard::finished() with slotModified - * kchart_view.cc (edit, apply, wizard): call setModified() in document + * kchart_view.cpp (edit, apply, wizard): call setModified() in document 2005-03-23 Inge Wallin Implement wish 45358: KChart start up dialog? - * kchart_part.cc (initNullChart): New method + * kchart_part.cpp (initNullChart): New method (initDoc): Call KoTemplateChooseDia(). - * kchart_view.cc (KChartView): Don't initialize the standard chart. + * kchart_view.cpp (KChartView): Don't initialize the standard chart. ---------------------------------------------------------------- @@ -361,7 +361,7 @@ ---------------------------------------------------------------- Bug fix. - * kchartDataEditor.cc (setCols): Set width for all new columns. + * kchartDataEditor.cpp (setCols): Set width for all new columns. (misc): Code cleaning Code cleaning @@ -382,22 +382,22 @@ 2005-03-18 Inge Wallin Improve layout for 3D bar chart parameters. - * kchartParameter3dConfigPage.cc (KChartParameter3dConfigPage): + * kchartParameter3dConfigPage.cpp (KChartParameter3dConfigPage): Improve layout. 2005-03-17 Inge Wallin Remove the 3D Line Parameters page from the config dialog due to general uselessness and uglyness. - * kchartConfigDialog.cc (KChartConfigDialog): Disabled 3D Line + * kchartConfigDialog.cpp (KChartConfigDialog): Disabled 3D Line page. - * kchartLine3dConfigPage.cc (constructor): Changed layout + * kchartLine3dConfigPage.cpp (constructor): Changed layout somewhat, during the experiments. ---------------------------------------------------------------- Fix the uglyness of the font config dialog. - * kchartFontConfigPage.cc (KChartFontConfigPage): Add some stretch + * kchartFontConfigPage.cpp (KChartFontConfigPage): Add some stretch in suitable places. ---------------------------------------------------------------- @@ -432,13 +432,13 @@ ---------------------------------------------------------------- Don't include kchartDataEditor.h where is shouldn't be included. - * kchartBarConfigDialog.cc, kchartColorConfigPage.cc, - kchartDataConfigPage.cc: remove it, and include koChart.h instead + * kchartBarConfigDialog.cpp, kchartColorConfigPage.cpp, + kchartDataConfigPage.cpp: remove it, and include koChart.h instead 2005-03-13 Inge Wallin Make the page layout dialog better looking. - * kchartPageLayout.cc (constructor): Place settings inside a + * kchartPageLayout.cpp (constructor): Place settings inside a button box. ---------------------------------------------------------------- @@ -450,21 +450,21 @@ (getXLabel): removed * kchart_part.h (axisLabelText{short,long}): removed (m_longLabels, m_shortLabels): removed - * kchart_view.cc (edit): remove all stuff within #if 0 - #endif + * kchart_view.cpp (edit): remove all stuff within #if 0 - #endif ---------------------------------------------------------------- Fix problem with mixed plurals/singulars in chart names. - * kchart_view.cc (KChartView): Rename some actions. + * kchart_view.cpp (KChartView): Rename some actions. The default chart is marked as modified even when it's not. - * kchart_part.cc (KChartPart): Remove call to setModified(). + * kchart_part.cpp (KChartPart): Remove call to setModified(). 2005-03-12 Inge Wallin Remove the defaults button from the config dialog. It wasn't working anyway. - * kchartConfigDialog.cc (KChartConfigDialog): Disable the Defaults + * kchartConfigDialog.cpp (KChartConfigDialog): Disable the Defaults button. ---------------------------------------------------------------- @@ -473,7 +473,7 @@ logarithmic axes. * kchartParameterConfigPage.h (KChartParameterConfigPage::lin and log): new members - * kchartParameterConfigPage.cc (KChartParameterConfigPage): Add + * kchartParameterConfigPage.cpp (KChartParameterConfigPage): Add new widgets to the Settings buttonbox (used to be Title) (init): initialize the members from the params. (apply): store the parameters from the values of the widgets @@ -481,13 +481,13 @@ ---------------------------------------------------------------- Fix the bad layout of the title buttonbox. - * kchartParameterConfigPage.cc (KChartParameterConfigPage): Change + * kchartParameterConfigPage.cpp (KChartParameterConfigPage): Change the layout slightly, and add row and col stretch. ---------------------------------------------------------------- Load row and column headers from XML file. - * kchart_part.cc (loadXML): Get the legend and axis label strings + * kchart_part.cpp (loadXML): Get the legend and axis label strings from the KDChart parameters and store in the column and row headers. @@ -497,8 +497,8 @@ Clean up the data editor and remove old cruft. * kchartDataEditor.{h,cc}: Remove all #if 0:ed code. - * Makefile.am (libkchartpart_la_SOURCES): Removed parser.cc, - sheet.cc, sheetdlg.cc, table.cc qttableview.cpp + * Makefile.am (libkchartpart_la_SOURCES): Removed parser.cpp, + sheet.cpp, sheetdlg.cpp, table.cpp qttableview.cpp (noinst_HEADERS): Removed parser.h sheet.h sheetdlg.h table.h qttableview.h Files mentioned above: Removed. @@ -507,20 +507,20 @@ Move Tooltips and Whatsthis help from the old data editor to the new one. - * kchartDataEditor.cc (addDocs): New method + * kchartDataEditor.cpp (addDocs): New method (constructor): Clean up by moving all help generation to addDocs(). ---------------------------------------------------------------- Enable "Finish" button for all pages in the wizard. - * kchartWizard.cc (KChartWizard): Enable Finish button for + * kchartWizard.cpp (KChartWizard): Enable Finish button for "Subtypes" and "Labels & Legend" pages. 2005-03-10 Inge Wallin Make the table in the data editor shrink when number of rows/cols are decreased in the spinboxes. - * kchartDataEditor.cc (askUserForConfirmation): new static + * kchartDataEditor.cpp (askUserForConfirmation): new static function. (setRows, setCols): Handle shrinking @@ -546,25 +546,25 @@ ---------------------------------------------------------------- Cleaning - * kchart_part.cc (paintContent): break out common code out of an + * kchart_part.cpp (paintContent): break out common code out of an if/else construction. ---------------------------------------------------------------- More experiments with visual appearance of the data editor - * kchartDataEditor.cc (setData): Set size of the table widget to + * kchartDataEditor.cpp (setData): Set size of the table widget to (600,300) ---------------------------------------------------------------- Experiment with visual appearance of the new data editor - * kchartDataEditor.cc (setData): Set column widths to 80. + * kchartDataEditor.cpp (setData): Set column widths to 80. ---------------------------------------------------------------- Fix bug introduced by patch to fix bug 14971: Axes label handling in connection with KSpread was broken. - * kchart_part.cc (setData): set m_rowLabels and m_colLabels + * kchart_part.cpp (setData): set m_rowLabels and m_colLabels instead of storing axes labels to the params. 2005-03-08 Inge Wallin @@ -580,13 +580,13 @@ This fixes bug 14971. * kchart_part.h (m_rowLabels, m_colLabels): new members (rowLabelTexts, colLabelTexts): new methods - * kchart_part.cc (paintContent): Paint using the new labels, both + * kchart_part.cpp (paintContent): Paint using the new labels, both for ordinary and transposed tables. * kchartDataEditor.{h,cc} (setRowLabels): new method (getRowLabels): new method (setColLabels): new method (getColLabels): new method - * kchart_view.cc (edit): call new methods above in data editor, + * kchart_view.cpp (edit): call new methods above in data editor, and don't call old methods setLegend, getLegend, setXLabel, etc. 2005-03-07 Inge Wallin @@ -608,18 +608,18 @@ ---------------------------------------------------------------- Cleaning: - * kchart_part.cc (loadOasis): remove parameter names to remove + * kchart_part.cpp (loadOasis): remove parameter names to remove warnings. Reorder chart types to make it more logical order * kchart.rc (Toolbar): Reorder chart types - * kchartWizardSelectChartTypePage.cc (constructor): Reorder chart + * kchartWizardSelectChartTypePage.cpp (constructor): Reorder chart types into same order. 2005-03-06 Inge Wallin Begin to support the Apply button in the data editor. - * kchartDataEditor.cc (kchartDataEditor): connect applyClicked() + * kchartDataEditor.cpp (kchartDataEditor): connect applyClicked() to apply() * kchartDataEditor.{h,cc} (apply): new method. @@ -630,11 +630,11 @@ author. Continue with the new data editor. - * kchartDataEditor.cc (setLegend): Always initialize the row + * kchartDataEditor.cpp (setLegend): Always initialize the row headers, not only the first time. Start fixing default handling in the config dialog. - * kchartConfigDialog.cc (defaults): Call datapage->defaults() + * kchartConfigDialog.cpp (defaults): Call datapage->defaults() instead of init. * kchartDataConfigPage.{h,cc} (defaults): New method. @@ -649,13 +649,13 @@ * kchartDataEditor.{h,cc}: First prototype of a new data editor. Code cleaning. - * kchartFontConfigPage.cc (class KChartFontListBoxItem): Move from + * kchartFontConfigPage.cpp (class KChartFontListBoxItem): Move from kchartDataConfigPage.h. That used to be an error. 2005-02-25 Inge Wallin Fix bug 99998: KChart: 3d Depth parameter has ludicrous max value - * kchartParameter3dConfigPage.cc (KChartParameter3dConfigPage): + * kchartParameter3dConfigPage.cpp (KChartParameter3dConfigPage): Make the depth parameter go from 0 to 2.0 instead of 0 to 40. 2005-02-24 Inge Wallin @@ -689,7 +689,7 @@ Fix bug 99765: "Chart Subtype" config page is missing for Pie, Ring, Box&Whisker chart types. - * kchartConfigDialog.cc (initSubtypePage): Don't create a + * kchartConfigDialog.cpp (initSubtypePage): Don't create a configuration page for subtype if the type doesn't have a subtype. Applicable to Pie, Ring and Box&Whiskers. @@ -698,9 +698,9 @@ Start of a new page in the config dialog for configuring Data. This is not yet finished. * kchartDataConfigPage.h: New file - * kchartDataConfigPage.cc: New file + * kchartDataConfigPage.cpp: New file * kchartConfigDialog.h (KChartConfigDialog::m_datapage): New member - * kchartConfigDialog.cc (KChartConfigDialog): Create the data page + * kchartConfigDialog.cpp (KChartConfigDialog): Create the data page 2005-01-07 Raphael Langerhorst @@ -711,10 +711,10 @@ 2005-01-06 Raphael Langerhorst Improve Data Editor usability: - * sheet.cc: Add tooltips and what's this help. - * sheet.cc: Use a different color for first row and column - * sheetdlg.cc: Add tooltips and what's this help. - * sheetdlg.cc: Change order of widget initialization (better tab order). + * sheet.cpp: Add tooltips and what's this help. + * sheet.cpp: Use a different color for first row and column + * sheetdlg.cpp: Add tooltips and what's this help. + * sheetdlg.cpp: Change order of widget initialization (better tab order). 2004-11-16 Inge Wallin @@ -725,7 +725,7 @@ 2004-11-05 Inge Wallin Fix bug 90895: save config is not needed - * kchart_view.cc (KChartView): Remove actions "loadconfig", + * kchart_view.cpp (KChartView): Remove actions "loadconfig", "saveconfig" and "defaultconfig". * kchart.rc: Remove reference to them in the definition of the Settings menu. @@ -733,26 +733,26 @@ Fix bug 90904: edit/configure is confusingly named * kchart.rc: Add a sub menu for editing only one aspect of the chart. - * kchart_view.cc: Change shortcut for Edit Data - * kchart_view.cc: Change string for Configure Chart + * kchart_view.cpp: Change shortcut for Edit Data + * kchart_view.cpp: Change string for Configure Chart 2004-10-07 Inge Wallin * Cleanup of the following files. Made the code more readable, fixed indentation, added some comments: - sheet.h - - sheet.cc + - sheet.cpp 2004-10-06 Inge Wallin Fix bug 55603: Pressing Enter in Data Editor doesn't update any changes. - * sheetdlg.cc (SheetDlg): Make the OK button the default. + * sheetdlg.cpp (SheetDlg): Make the OK button the default. * Cleanup of the following files. Made the code more readable, fixed indentation, added some comments: - parser.h - - parser.cc + - parser.cpp 2004-10-04 Inge Wallin @@ -760,19 +760,19 @@ readable, fixed indentation, added (a few) comments: (Man, there are a lot of coding styles in there...) - kchart_part.h - - kchart_part.cc + - kchart_part.cpp * Cleaned the following files a little. Made the code more readable, fixed indentation, added (a few) comments: - - kchart.la.cc - - main.cc - - kchart_dummy.cc + - kchart.la.cpp + - main.cpp + - kchart_dummy.cpp - kchart_aboutdata.h - kchart_factory.h - - kchart_factory.cc + - kchart_factory.cpp - kchart_params.h - - kchart_params.cc + - kchart_params.cpp - kchart_view.h - - kchart_view.cc + - kchart_view.cpp diff --git a/kchart/KChartParamsIface.cc b/kchart/KChartParamsIface.cc deleted file mode 100644 index 794c4679..00000000 --- a/kchart/KChartParamsIface.cc +++ /dev/null @@ -1,464 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "KChartParamsIface.h" - -#include "kchart_params.h" - -#include - -namespace KChart -{ - -KChartParamsIface::KChartParamsIface( KChartParams *params_ ) - : DCOPObject() -{ - params = params_; -} - -TQString KChartParamsIface::chartType()const -{ - return params->chartTypeToString(params->chartType()); -} - -void KChartParamsIface::setChartType( const TQString &chart ) -{ - params->setChartType(params->stringToChartType( chart )); -} - -TQString KChartParamsIface::barChartSubType() const -{ - return params->barChartSubTypeToString(params->barChartSubType()); -} - -void KChartParamsIface::setBarChartSubType( const TQString &sub ) -{ - params->setBarChartSubType(params->stringToBarChartSubType( sub )); -} - -bool KChartParamsIface::threeDBars() -{ - return params->threeDBars(); -} - -void KChartParamsIface::setThreeDBars( bool threeDBars ) -{ - params->setThreeDBars(threeDBars); -} - -void KChartParamsIface::setThreeDBarsShadowColors( bool shadow ) -{ - params->setThreeDBarsShadowColors(shadow); -} - -bool KChartParamsIface::threeDBarsShadowColors() const -{ - return params->threeDBarsShadowColors(); -} - -void KChartParamsIface::setThreeDBarAngle( uint angle ) -{ - params->setThreeDBarAngle(angle); -} - -uint KChartParamsIface::threeDBarAngle() const -{ - return params->threeDBarAngle(); -} - -void KChartParamsIface::setThreeDBarDepth( double depth ) -{ - params->setThreeDBarDepth(depth); -} - -double KChartParamsIface::threeDBarDepth() const -{ - return params->threeDBarDepth(); -} - - -bool KChartParamsIface::threeDPies() -{ - return params->threeDPies(); -} - -void KChartParamsIface::setThreeDPieHeight( int pixels ) -{ - params->setThreeDPieHeight(pixels); -} - -int KChartParamsIface::threeDPieHeight() -{ - return params->threeDPieHeight(); -} - -void KChartParamsIface::setPieStart( int degrees ) -{ - params->setPieStart(degrees); -} - -int KChartParamsIface::pieStart() -{ - return params->pieStart(); -} - -void KChartParamsIface::setExplode( bool explode ) -{ - params->setExplode(explode); -} - -bool KChartParamsIface::explode() const -{ - return params->explode(); -} - -void KChartParamsIface::setExplodeFactor( double factor ) -{ - params->setExplodeFactor(factor); -} - -double KChartParamsIface::explodeFactor() const -{ - return params->explodeFactor(); -} - -void KChartParamsIface::setThreeDPies( bool threeDPies ) -{ - params->setThreeDPies(threeDPies); -} - -void KChartParamsIface::hideLegend() -{ - params->setLegendPosition(KDChartParams::NoLegend); -} - -void KChartParamsIface::setLegendPosition(const TQString & pos) -{ - params->setLegendPosition(params->stringToLegendPosition(pos)); -} - -TQString KChartParamsIface::legendPostion() const -{ - return params->legendPositionToString(params->legendPosition()); -} - -void KChartParamsIface::setLegendTitleText( const TQString& text ) -{ - params->setLegendTitleText( text ); -} - -void KChartParamsIface::setLegendSpacing( uint space ) -{ - params->setLegendSpacing(space ); -} - -void KChartParamsIface::setLegendFontRelSize( int legendFontRelSize ) -{ - params->setLegendFontRelSize(legendFontRelSize); -} - -int KChartParamsIface::legendFontRelSize() const -{ - return params->legendFontRelSize(); -} - -void KChartParamsIface::setLegendFontUseRelSize( bool legendFontUseRelSize ) -{ - params->setLegendFontUseRelSize(legendFontUseRelSize); -} - -bool KChartParamsIface::legendFontUseRelSize() const -{ - return params->legendFontUseRelSize(); -} - -void KChartParamsIface::setLegendTitleFontUseRelSize( bool legendTitleFontUseRelSize ) -{ - params->setLegendTitleFontUseRelSize(legendTitleFontUseRelSize); -} - -bool KChartParamsIface::legendTitleFontUseRelSize() const -{ - return params->legendTitleFontUseRelSize(); -} - -void KChartParamsIface::setLegendTitleFontRelSize( int legendTitleFontRelSize ) -{ - params->setLegendTitleFontRelSize(legendTitleFontRelSize); -} - -int KChartParamsIface::legendTitleFontRelSize() const -{ - return params->legendTitleFontRelSize(); -} - -uint KChartParamsIface::legendSpacing() -{ - return params->legendSpacing(); -} - -void KChartParamsIface::setLineChartSubType( const TQString & sub) -{ - params->setLineChartSubType(params->stringToLineChartSubType(sub)); -} - -TQString KChartParamsIface::lineChartSubType() const -{ - return params->lineChartSubTypeToString(params->lineChartSubType()); -} - - -bool KChartParamsIface::lineMarker() const -{ - return params->lineMarker(); -} - -void KChartParamsIface::setLineMarker( bool b) -{ - params->setLineMarker(b); -} - -void KChartParamsIface::setLineWidth( uint width ) -{ - params->setLineWidth( width ); -} - -uint KChartParamsIface::lineWidth() const -{ - return params->lineWidth(); -} - -bool KChartParamsIface::threeDLines() const -{ - return params->threeDLines(); -} - -void KChartParamsIface::setThreeDLines(bool b) -{ - params->setThreeDLines(b); -} - -int KChartParamsIface::threeDLineDepth() const -{ - return params->threeDLineDepth(); -} - -void KChartParamsIface::setThreeDLineDepth( int depth ) -{ - params->setThreeDLineDepth( depth ); -} - -int KChartParamsIface::threeDLineXRotation() const -{ - return params->threeDLineXRotation(); -} - -void KChartParamsIface::setThreeDLineXRotation( int degrees ) -{ - params->setThreeDLineXRotation( degrees ); -} - -void KChartParamsIface::setThreeDLineYRotation( int degrees ) -{ - params->setThreeDLineYRotation(degrees ); -} - -int KChartParamsIface::threeDLineYRotation() const -{ - return params->threeDLineYRotation(); -} - -TQSize KChartParamsIface::lineMarkerSize() const -{ - return params->lineMarkerSize(); -} - -void KChartParamsIface::setLineMarkerSize( TQSize size ) -{ - params->setLineMarkerSize( size ); -} - - -bool KChartParamsIface::showGrid() -{ - return params->showGrid(); -} - -TQString KChartParamsIface::header1Text() const -{ - return params->header1Text(); -} - -void KChartParamsIface::setHeader1Text( const TQString& text ) -{ - params->setHeader1Text(text); -} - -void KChartParamsIface::setHeader2Text( const TQString& text ) -{ - params->setHeader2Text(text); -} - -TQString KChartParamsIface::header2Text() const -{ - return params->header2Text(); -} - - -void KChartParamsIface::setOutlineDataLineWidth( uint width ) -{ - params->setOutlineDataLineWidth( width ); -} - -uint KChartParamsIface::outlineDataLineWidth() const -{ - return params->outlineDataLineWidth(); -} - -void KChartParamsIface::setAreaChartSubType(const TQString &sub) -{ - params->setAreaChartSubType(params->stringToAreaChartSubType(sub)); -} - -TQString KChartParamsIface::areaChartSubType() const -{ - return params->areaChartSubTypeToString(params->areaChartSubType()); -} - -void KChartParamsIface::setAreaLocation(const TQString & loc) -{ - params->setAreaLocation(params->stringToAreaLocation(loc)); -} - -TQString KChartParamsIface::areaLocation() const -{ - return params->areaLocationToString( params->areaLocation()); -} - -void KChartParamsIface::setHiLoChartSubType(const TQString &sub) -{ - params->setHiLoChartSubType(params->stringToHiLoChartSubType(sub)); -} - -TQString KChartParamsIface::hiLoChartSubType() const -{ - return params->hiLoChartSubTypeToString(params->hiLoChartSubType()); -} - -bool KChartParamsIface::hiLoChartPrintHighValues() const -{ - return params->hiLoChartPrintHighValues(); -} - -bool KChartParamsIface::hiLoChartLowValuesUseFontRelSize() const -{ - return params->hiLoChartLowValuesUseFontRelSize(); -} - -int KChartParamsIface::hiLoChartLowValuesFontRelSize() const -{ - return params->hiLoChartLowValuesFontRelSize(); -} - -bool KChartParamsIface::hiLoChartPrintLowValues() const -{ - return params->hiLoChartPrintLowValues(); -} - -int KChartParamsIface::hiLoChartOpenValuesFontRelSize() const -{ - return params->hiLoChartOpenValuesFontRelSize(); -} - -bool KChartParamsIface::hiLoChartPrintCloseValues() const -{ - return params->hiLoChartPrintCloseValues(); -} - -bool KChartParamsIface::hiLoChartCloseValuesUseFontRelSize() const -{ - return params->hiLoChartCloseValuesUseFontRelSize(); -} - -int KChartParamsIface::hiLoChartCloseValuesFontRelSize() const -{ - return params->hiLoChartCloseValuesFontRelSize(); -} - -void KChartParamsIface::setPolarLineWidth( int width ) -{ - params->setPolarLineWidth( width ); -} - -int KChartParamsIface::polarLineWidth() const -{ - return params->polarLineWidth(); -} - -void KChartParamsIface::setPolarZeroDegreePos( int degrees ) -{ - params->setPolarZeroDegreePos( degrees ); -} - -int KChartParamsIface::polarZeroDegreePos() const -{ - return params->polarZeroDegreePos(); -} - -void KChartParamsIface::setPolarRotateCircularLabels( bool rotateCircularLabels ) -{ - params->setPolarRotateCircularLabels( rotateCircularLabels ); -} - -bool KChartParamsIface::polarRotateCircularLabels() const -{ - return params->polarRotateCircularLabels(); -} - -TQSize KChartParamsIface::polarMarkerSize() const -{ - return params->polarMarkerSize(); -} - -void KChartParamsIface::setPolarMarkerSize( TQSize size ) -{ - params->setPolarMarkerSize(size); -} - -int KChartParamsIface::ringStart() const -{ - return params->ringStart(); -} - -void KChartParamsIface::setRingStart( int degrees ) -{ - params->setRingStart( degrees ); -} - - -void KChartParamsIface::setThreeDShadowColors( bool shadow ) -{ - params->setThreeDShadowColors(shadow); -} -bool KChartParamsIface::threeDShadowColors() -{ - return params->threeDShadowColors(); -} - -} //KChart namespace diff --git a/kchart/KChartParamsIface.cpp b/kchart/KChartParamsIface.cpp new file mode 100644 index 00000000..794c4679 --- /dev/null +++ b/kchart/KChartParamsIface.cpp @@ -0,0 +1,464 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "KChartParamsIface.h" + +#include "kchart_params.h" + +#include + +namespace KChart +{ + +KChartParamsIface::KChartParamsIface( KChartParams *params_ ) + : DCOPObject() +{ + params = params_; +} + +TQString KChartParamsIface::chartType()const +{ + return params->chartTypeToString(params->chartType()); +} + +void KChartParamsIface::setChartType( const TQString &chart ) +{ + params->setChartType(params->stringToChartType( chart )); +} + +TQString KChartParamsIface::barChartSubType() const +{ + return params->barChartSubTypeToString(params->barChartSubType()); +} + +void KChartParamsIface::setBarChartSubType( const TQString &sub ) +{ + params->setBarChartSubType(params->stringToBarChartSubType( sub )); +} + +bool KChartParamsIface::threeDBars() +{ + return params->threeDBars(); +} + +void KChartParamsIface::setThreeDBars( bool threeDBars ) +{ + params->setThreeDBars(threeDBars); +} + +void KChartParamsIface::setThreeDBarsShadowColors( bool shadow ) +{ + params->setThreeDBarsShadowColors(shadow); +} + +bool KChartParamsIface::threeDBarsShadowColors() const +{ + return params->threeDBarsShadowColors(); +} + +void KChartParamsIface::setThreeDBarAngle( uint angle ) +{ + params->setThreeDBarAngle(angle); +} + +uint KChartParamsIface::threeDBarAngle() const +{ + return params->threeDBarAngle(); +} + +void KChartParamsIface::setThreeDBarDepth( double depth ) +{ + params->setThreeDBarDepth(depth); +} + +double KChartParamsIface::threeDBarDepth() const +{ + return params->threeDBarDepth(); +} + + +bool KChartParamsIface::threeDPies() +{ + return params->threeDPies(); +} + +void KChartParamsIface::setThreeDPieHeight( int pixels ) +{ + params->setThreeDPieHeight(pixels); +} + +int KChartParamsIface::threeDPieHeight() +{ + return params->threeDPieHeight(); +} + +void KChartParamsIface::setPieStart( int degrees ) +{ + params->setPieStart(degrees); +} + +int KChartParamsIface::pieStart() +{ + return params->pieStart(); +} + +void KChartParamsIface::setExplode( bool explode ) +{ + params->setExplode(explode); +} + +bool KChartParamsIface::explode() const +{ + return params->explode(); +} + +void KChartParamsIface::setExplodeFactor( double factor ) +{ + params->setExplodeFactor(factor); +} + +double KChartParamsIface::explodeFactor() const +{ + return params->explodeFactor(); +} + +void KChartParamsIface::setThreeDPies( bool threeDPies ) +{ + params->setThreeDPies(threeDPies); +} + +void KChartParamsIface::hideLegend() +{ + params->setLegendPosition(KDChartParams::NoLegend); +} + +void KChartParamsIface::setLegendPosition(const TQString & pos) +{ + params->setLegendPosition(params->stringToLegendPosition(pos)); +} + +TQString KChartParamsIface::legendPostion() const +{ + return params->legendPositionToString(params->legendPosition()); +} + +void KChartParamsIface::setLegendTitleText( const TQString& text ) +{ + params->setLegendTitleText( text ); +} + +void KChartParamsIface::setLegendSpacing( uint space ) +{ + params->setLegendSpacing(space ); +} + +void KChartParamsIface::setLegendFontRelSize( int legendFontRelSize ) +{ + params->setLegendFontRelSize(legendFontRelSize); +} + +int KChartParamsIface::legendFontRelSize() const +{ + return params->legendFontRelSize(); +} + +void KChartParamsIface::setLegendFontUseRelSize( bool legendFontUseRelSize ) +{ + params->setLegendFontUseRelSize(legendFontUseRelSize); +} + +bool KChartParamsIface::legendFontUseRelSize() const +{ + return params->legendFontUseRelSize(); +} + +void KChartParamsIface::setLegendTitleFontUseRelSize( bool legendTitleFontUseRelSize ) +{ + params->setLegendTitleFontUseRelSize(legendTitleFontUseRelSize); +} + +bool KChartParamsIface::legendTitleFontUseRelSize() const +{ + return params->legendTitleFontUseRelSize(); +} + +void KChartParamsIface::setLegendTitleFontRelSize( int legendTitleFontRelSize ) +{ + params->setLegendTitleFontRelSize(legendTitleFontRelSize); +} + +int KChartParamsIface::legendTitleFontRelSize() const +{ + return params->legendTitleFontRelSize(); +} + +uint KChartParamsIface::legendSpacing() +{ + return params->legendSpacing(); +} + +void KChartParamsIface::setLineChartSubType( const TQString & sub) +{ + params->setLineChartSubType(params->stringToLineChartSubType(sub)); +} + +TQString KChartParamsIface::lineChartSubType() const +{ + return params->lineChartSubTypeToString(params->lineChartSubType()); +} + + +bool KChartParamsIface::lineMarker() const +{ + return params->lineMarker(); +} + +void KChartParamsIface::setLineMarker( bool b) +{ + params->setLineMarker(b); +} + +void KChartParamsIface::setLineWidth( uint width ) +{ + params->setLineWidth( width ); +} + +uint KChartParamsIface::lineWidth() const +{ + return params->lineWidth(); +} + +bool KChartParamsIface::threeDLines() const +{ + return params->threeDLines(); +} + +void KChartParamsIface::setThreeDLines(bool b) +{ + params->setThreeDLines(b); +} + +int KChartParamsIface::threeDLineDepth() const +{ + return params->threeDLineDepth(); +} + +void KChartParamsIface::setThreeDLineDepth( int depth ) +{ + params->setThreeDLineDepth( depth ); +} + +int KChartParamsIface::threeDLineXRotation() const +{ + return params->threeDLineXRotation(); +} + +void KChartParamsIface::setThreeDLineXRotation( int degrees ) +{ + params->setThreeDLineXRotation( degrees ); +} + +void KChartParamsIface::setThreeDLineYRotation( int degrees ) +{ + params->setThreeDLineYRotation(degrees ); +} + +int KChartParamsIface::threeDLineYRotation() const +{ + return params->threeDLineYRotation(); +} + +TQSize KChartParamsIface::lineMarkerSize() const +{ + return params->lineMarkerSize(); +} + +void KChartParamsIface::setLineMarkerSize( TQSize size ) +{ + params->setLineMarkerSize( size ); +} + + +bool KChartParamsIface::showGrid() +{ + return params->showGrid(); +} + +TQString KChartParamsIface::header1Text() const +{ + return params->header1Text(); +} + +void KChartParamsIface::setHeader1Text( const TQString& text ) +{ + params->setHeader1Text(text); +} + +void KChartParamsIface::setHeader2Text( const TQString& text ) +{ + params->setHeader2Text(text); +} + +TQString KChartParamsIface::header2Text() const +{ + return params->header2Text(); +} + + +void KChartParamsIface::setOutlineDataLineWidth( uint width ) +{ + params->setOutlineDataLineWidth( width ); +} + +uint KChartParamsIface::outlineDataLineWidth() const +{ + return params->outlineDataLineWidth(); +} + +void KChartParamsIface::setAreaChartSubType(const TQString &sub) +{ + params->setAreaChartSubType(params->stringToAreaChartSubType(sub)); +} + +TQString KChartParamsIface::areaChartSubType() const +{ + return params->areaChartSubTypeToString(params->areaChartSubType()); +} + +void KChartParamsIface::setAreaLocation(const TQString & loc) +{ + params->setAreaLocation(params->stringToAreaLocation(loc)); +} + +TQString KChartParamsIface::areaLocation() const +{ + return params->areaLocationToString( params->areaLocation()); +} + +void KChartParamsIface::setHiLoChartSubType(const TQString &sub) +{ + params->setHiLoChartSubType(params->stringToHiLoChartSubType(sub)); +} + +TQString KChartParamsIface::hiLoChartSubType() const +{ + return params->hiLoChartSubTypeToString(params->hiLoChartSubType()); +} + +bool KChartParamsIface::hiLoChartPrintHighValues() const +{ + return params->hiLoChartPrintHighValues(); +} + +bool KChartParamsIface::hiLoChartLowValuesUseFontRelSize() const +{ + return params->hiLoChartLowValuesUseFontRelSize(); +} + +int KChartParamsIface::hiLoChartLowValuesFontRelSize() const +{ + return params->hiLoChartLowValuesFontRelSize(); +} + +bool KChartParamsIface::hiLoChartPrintLowValues() const +{ + return params->hiLoChartPrintLowValues(); +} + +int KChartParamsIface::hiLoChartOpenValuesFontRelSize() const +{ + return params->hiLoChartOpenValuesFontRelSize(); +} + +bool KChartParamsIface::hiLoChartPrintCloseValues() const +{ + return params->hiLoChartPrintCloseValues(); +} + +bool KChartParamsIface::hiLoChartCloseValuesUseFontRelSize() const +{ + return params->hiLoChartCloseValuesUseFontRelSize(); +} + +int KChartParamsIface::hiLoChartCloseValuesFontRelSize() const +{ + return params->hiLoChartCloseValuesFontRelSize(); +} + +void KChartParamsIface::setPolarLineWidth( int width ) +{ + params->setPolarLineWidth( width ); +} + +int KChartParamsIface::polarLineWidth() const +{ + return params->polarLineWidth(); +} + +void KChartParamsIface::setPolarZeroDegreePos( int degrees ) +{ + params->setPolarZeroDegreePos( degrees ); +} + +int KChartParamsIface::polarZeroDegreePos() const +{ + return params->polarZeroDegreePos(); +} + +void KChartParamsIface::setPolarRotateCircularLabels( bool rotateCircularLabels ) +{ + params->setPolarRotateCircularLabels( rotateCircularLabels ); +} + +bool KChartParamsIface::polarRotateCircularLabels() const +{ + return params->polarRotateCircularLabels(); +} + +TQSize KChartParamsIface::polarMarkerSize() const +{ + return params->polarMarkerSize(); +} + +void KChartParamsIface::setPolarMarkerSize( TQSize size ) +{ + params->setPolarMarkerSize(size); +} + +int KChartParamsIface::ringStart() const +{ + return params->ringStart(); +} + +void KChartParamsIface::setRingStart( int degrees ) +{ + params->setRingStart( degrees ); +} + + +void KChartParamsIface::setThreeDShadowColors( bool shadow ) +{ + params->setThreeDShadowColors(shadow); +} +bool KChartParamsIface::threeDShadowColors() +{ + return params->threeDShadowColors(); +} + +} //KChart namespace diff --git a/kchart/KChartViewIface.cc b/kchart/KChartViewIface.cc deleted file mode 100644 index c9c2cbad..00000000 --- a/kchart/KChartViewIface.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "KChartViewIface.h" - -#include "kchart_view.h" - -#include - -namespace KChart -{ - -KChartViewIface::KChartViewIface( KChartView *view_ ) - : KoViewIface( view_ ) -{ - view = view_; -} - -void KChartViewIface::wizard() -{ - view->wizard(); -} - -void KChartViewIface::editData() -{ - view->editData(); -} - -void KChartViewIface::configureChart() -{ - view->slotConfig(); -} - -void KChartViewIface::configureBackground() -{ - view->slotConfigBack(); -} - -void KChartViewIface::configureFont() -{ - view->slotConfigFont(); -} - -void KChartViewIface::configureColor() -{ - view->slotConfigColor(); -} - -void KChartViewIface::configureLegend() -{ - view->slotConfigLegend(); -} - -void KChartViewIface::updateGuiTypeOfChart() -{ - view->updateGuiTypeOfChart(); -} - -void KChartViewIface::saveConfig() -{ - view->saveConfig(); -} - -void KChartViewIface::loadConfig() -{ - view->loadConfig(); -} - -void KChartViewIface::defaultConfig() -{ - view->defaultConfig(); -} - -void KChartViewIface::configSubTypeChart() -{ - view->slotConfigSubTypeChart(); -} - -void KChartViewIface::configHeaderFooter() -{ - view->slotConfigHeaderFooterChart(); -} - -} //KChart namespace diff --git a/kchart/KChartViewIface.cpp b/kchart/KChartViewIface.cpp new file mode 100644 index 00000000..c9c2cbad --- /dev/null +++ b/kchart/KChartViewIface.cpp @@ -0,0 +1,100 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "KChartViewIface.h" + +#include "kchart_view.h" + +#include + +namespace KChart +{ + +KChartViewIface::KChartViewIface( KChartView *view_ ) + : KoViewIface( view_ ) +{ + view = view_; +} + +void KChartViewIface::wizard() +{ + view->wizard(); +} + +void KChartViewIface::editData() +{ + view->editData(); +} + +void KChartViewIface::configureChart() +{ + view->slotConfig(); +} + +void KChartViewIface::configureBackground() +{ + view->slotConfigBack(); +} + +void KChartViewIface::configureFont() +{ + view->slotConfigFont(); +} + +void KChartViewIface::configureColor() +{ + view->slotConfigColor(); +} + +void KChartViewIface::configureLegend() +{ + view->slotConfigLegend(); +} + +void KChartViewIface::updateGuiTypeOfChart() +{ + view->updateGuiTypeOfChart(); +} + +void KChartViewIface::saveConfig() +{ + view->saveConfig(); +} + +void KChartViewIface::loadConfig() +{ + view->loadConfig(); +} + +void KChartViewIface::defaultConfig() +{ + view->defaultConfig(); +} + +void KChartViewIface::configSubTypeChart() +{ + view->slotConfigSubTypeChart(); +} + +void KChartViewIface::configHeaderFooter() +{ + view->slotConfigHeaderFooterChart(); +} + +} //KChart namespace diff --git a/kchart/Makefile.am b/kchart/Makefile.am index fc98f26e..c17ed0c0 100644 --- a/kchart/Makefile.am +++ b/kchart/Makefile.am @@ -3,34 +3,34 @@ INCLUDES = $(KOFFICE_INCLUDES) -I$(srcdir)/kdchart -I$(top_srcdir)/interfaces - ## The lib with most of the code (shared with the kchart filters) lib_LTLIBRARIES = libkchartcommon.la -libkchartcommon_la_SOURCES = kchart_part.cc \ - kchart_view.cc kchart_factory.cc \ - kchartColorConfigPage.cc \ - kchartParameterConfigPage.cc \ - kchartParameter3dConfigPage.cc \ - kchartBackgroundPixmapConfigPage.cc \ - kchartSubTypeChartPage.cc \ - kchartComboConfigPage.cc \ - kchartFontConfigPage.cc \ - kchartDataConfigPage.cc \ - kchartPieConfigPage.cc \ - kchartParameterPieConfigPage.cc \ - kchartConfigDialog.cc \ - kchartWizard.cc \ - kchartWizardLabelsLegendPage.cc \ - kchartWizardSelectChartSubTypePage.cc \ - kchartWizardSelectChartTypePage.cc \ - kchartWizardSelectDataPage.cc \ - kchartWizardSetupAxesPage.cc \ - kchartWizardSetupDataPage.cc \ - kchartWizardSelectDataFormatPage.cc \ - kchartDataEditor.cc \ - KChartViewIface.skel KChartViewIface.cc \ - kchartLegendConfigPage.cc kchart_params.cc KChartParamsIface.skel \ - KChartParamsIface.cc kchartHeaderFooterConfigPage.cc \ - kchartLine3dConfigPage.cc kchartParameterPolarConfigPage.cc kchartPageLayout.cc \ - kchartPrinterDlg.cc \ - csvimportdialog.cc csvimportdialogui.ui +libkchartcommon_la_SOURCES = kchart_part.cpp \ + kchart_view.cpp kchart_factory.cpp \ + kchartColorConfigPage.cpp \ + kchartParameterConfigPage.cpp \ + kchartParameter3dConfigPage.cpp \ + kchartBackgroundPixmapConfigPage.cpp \ + kchartSubTypeChartPage.cpp \ + kchartComboConfigPage.cpp \ + kchartFontConfigPage.cpp \ + kchartDataConfigPage.cpp \ + kchartPieConfigPage.cpp \ + kchartParameterPieConfigPage.cpp \ + kchartConfigDialog.cpp \ + kchartWizard.cpp \ + kchartWizardLabelsLegendPage.cpp \ + kchartWizardSelectChartSubTypePage.cpp \ + kchartWizardSelectChartTypePage.cpp \ + kchartWizardSelectDataPage.cpp \ + kchartWizardSetupAxesPage.cpp \ + kchartWizardSetupDataPage.cpp \ + kchartWizardSelectDataFormatPage.cpp \ + kchartDataEditor.cpp \ + KChartViewIface.skel KChartViewIface.cpp \ + kchartLegendConfigPage.cpp kchart_params.cpp KChartParamsIface.skel \ + KChartParamsIface.cpp kchartHeaderFooterConfigPage.cpp \ + kchartLine3dConfigPage.cpp kchartParameterPolarConfigPage.cpp kchartPageLayout.cpp \ + kchartPrinterDlg.cpp \ + csvimportdialog.cpp csvimportdialogui.ui libkchartcommon_la_LIBADD = $(top_builddir)/interfaces/libkochart.la \ $(LIB_KOFFICEUI) \ @@ -39,14 +39,14 @@ libkchartcommon_la_LDFLAGS = $(KDE_RPATH) -version-info 2:0:0 -no-undefined $(LI ## The part kde_module_LTLIBRARIES = libkchartpart.la -libkchartpart_la_SOURCES = kchart_factory_init.cc +libkchartpart_la_SOURCES = kchart_factory_init.cpp libkchartpart_la_LDFLAGS = $(KDE_PLUGIN) $(LIB_QT) libkchartpart_la_LIBADD = libkchartcommon.la ## The tdeinit loadable module and executable tdeinit_LTLIBRARIES = kchart.la bin_PROGRAMS = -kchart_la_SOURCES = main.cc +kchart_la_SOURCES = main.cpp kchart_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) kchart_la_LIBADD = $(LIB_KOFFICECORE) @@ -91,7 +91,7 @@ xdg_apps_DATA = kchart.desktop SUBDIRS = kdchart . toolbar pics templates messages: rc.cpp - $(XGETTEXT) rc.cpp *.cc kchart_aboutdata.h kdchart/*.cpp -o $(podir)/kchart.pot + $(XGETTEXT) rc.cpp *.cpp kchart_aboutdata.h kdchart/*.cpp -o $(podir)/kchart.pot kde_services_DATA = kchartpart.desktop diff --git a/kchart/csvimportdialog.cc b/kchart/csvimportdialog.cc deleted file mode 100644 index cf13c1b5..00000000 --- a/kchart/csvimportdialog.cc +++ /dev/null @@ -1,633 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999 David Faure - Copyright (C) 2004 Nicolas GOUTTE - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -CSVImportDialog::CSVImportDialog(TQWidget* parent, TQByteArray& fileArray) - : KDialogBase(parent, 0, true, TQString(), Ok|Cancel, No, true), - m_dialog(new DialogUI(this)), - m_adjustRows(false), - m_adjustCols(false), - m_startRow(0), - m_startCol(0), - m_endRow(-1), - m_endCol(-1), - m_textquote('"'), - m_delimiter(","), - m_ignoreDups(false), - m_fileArray(fileArray), - m_codec( TQTextCodec::codecForName( "UTF-8" ) ) -{ - setCaption( i18n( "Import Data" ) ); - kapp->restoreOverrideCursor(); - - TQStringList encodings; - encodings << i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" ); - encodings << i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( TQTextCodec::codecForLocale()->name() ); - encodings += TDEGlobal::charsets()->descriptiveEncodingNames(); - // Add a few non-standard encodings, which might be useful for text files - const TQString description(i18n("Descriptive encoding name","Other ( %1 )")); - encodings << description.arg("Apple Roman"); // Apple - encodings << description.arg("IBM 850") << description.arg("IBM 866"); // MS DOS - encodings << description.arg("CP 1258"); // Windows - m_dialog->comboBoxEncoding->insertStringList(encodings); - - m_formatList << i18n( "Text" ); - m_formatList << i18n( "Number" ); - //m_formatList << i18n( "Currency" ); - //m_formatList << i18n( "Date" ); - m_formatList << i18n( "Decimal Comma Number" ); - m_formatList << i18n( "Decimal Point Number" ); - m_dialog->m_formatComboBox->insertStringList( m_formatList ); - - m_dialog->m_sheet->setReadOnly( true ); - - fillTable(); - - //resize(sizeHint()); - resize( 600, 400 ); // Try to show as much as possible of the table view - setMainWidget(m_dialog); - - m_dialog->m_sheet->setSelectionMode( TQTable::Multi ); - - connect(m_dialog->m_formatComboBox, TQT_SIGNAL(activated( const TQString& )), - this, TQT_SLOT(formatChanged( const TQString& ))); - connect(m_dialog->m_delimiterBox, TQT_SIGNAL(clicked(int)), - this, TQT_SLOT(delimiterClicked(int))); - connect(m_dialog->m_delimiterEdit, TQT_SIGNAL(returnPressed()), - this, TQT_SLOT(returnPressed())); - connect(m_dialog->m_delimiterEdit, TQT_SIGNAL(textChanged ( const TQString & )), - this, TQT_SLOT(formatChanged ( const TQString & ) )); - connect(m_dialog->m_comboQuote, TQT_SIGNAL(activated(const TQString &)), - this, TQT_SLOT(textquoteSelected(const TQString &))); - connect(m_dialog->m_sheet, TQT_SIGNAL(currentChanged(int, int)), - this, TQT_SLOT(currentCellChanged(int, int))); - connect(m_dialog->m_ignoreDuplicates, TQT_SIGNAL(stateChanged(int)), - this, TQT_SLOT(ignoreDuplicatesChanged(int))); - connect(m_dialog->m_updateButton, TQT_SIGNAL(clicked()), - this, TQT_SLOT(updateClicked())); - connect(m_dialog->comboBoxEncoding, TQT_SIGNAL(textChanged ( const TQString & )), - this, TQT_SLOT(encodingChanged ( const TQString & ) )); -} - - -CSVImportDialog::~CSVImportDialog() -{ - kapp->setOverrideCursor(TQt::waitCursor); -} - - -// ---------------------------------------------------------------- -// public methods - - -bool CSVImportDialog::firstRowContainHeaders() -{ - return m_dialog->m_firstRowHeader->isChecked(); -} - - -bool CSVImportDialog::firstColContainHeaders() -{ - return m_dialog->m_firstColHeader->isChecked(); -} - - -int CSVImportDialog::rows() -{ - int rows = m_dialog->m_sheet->numRows(); - - if ( m_endRow >= 0 ) - rows = m_endRow - m_startRow + 1; - - return rows; -} - - -int CSVImportDialog::cols() -{ - int cols = m_dialog->m_sheet->numCols(); - - if ( m_endCol >= 0 ) - cols = m_endCol - m_startCol + 1; - - return cols; -} - - -TQString CSVImportDialog::text(int row, int col) -{ - // Check for overflow. - if ( row >= rows() || col >= cols()) - return TQString(); - - return m_dialog->m_sheet->text( row - m_startRow, col - m_startCol ); -} - - -// ---------------------------------------------------------------- - - -void CSVImportDialog::fillTable( ) -{ - int row, column; - bool lastCharDelimiter = false; - enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, - S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; - - TQChar x; - TQString field; - - kapp->setOverrideCursor(TQt::waitCursor); - - for (row = 0; row < m_dialog->m_sheet->numRows(); ++row) - for (column = 0; column < m_dialog->m_sheet->numCols(); ++column) - m_dialog->m_sheet->clearCell(row, column); - - int maxColumn = 1; - row = column = 1; - TQTextStream inputStream(m_fileArray, IO_ReadOnly); - kdDebug(30501) << "Encoding: " << m_codec->name() << endl; - inputStream.setCodec( m_codec ); - - bool lastCharWasCr = false; // Last character was a Carriage Return - while (!inputStream.atEnd()) - { - inputStream >> x; // read one char - - // ### TODO: we should perhaps skip all other control characters - if ( x == '\r' ) - { - // We have a Carriage Return, assume that its role is the one of a LineFeed - lastCharWasCr = true; - x = '\n'; // Replace by Line Feed - } - else if ( x == '\n' && lastCharWasCr ) - { - // The end of line was already handled by the Carriage Return, so do nothing for this character - lastCharWasCr = false; - continue; - } - else if ( x == TQChar( 0xc ) ) - { - // We have a FormFeed, skip it - lastCharWasCr = false; - continue; - } - else - { - lastCharWasCr = false; - } - - if ( column > maxColumn ) - maxColumn = column; - - switch (state) - { - case S_START : - if (x == m_textquote) - { - state = S_QUOTED_FIELD; - } - else if (x == m_delimiter) - { - if ((m_ignoreDups == false) || (lastCharDelimiter == false)) - ++column; - lastCharDelimiter = true; - } - else if (x == '\n') - { - ++row; - column = 1; - if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) - break; - } - else - { - field += x; - state = S_MAYBE_NORMAL_FIELD; - } - break; - case S_QUOTED_FIELD : - if (x == m_textquote) - { - state = S_MAYBE_END_OF_QUOTED_FIELD; - } - else if (x == '\n') - { - setText(row - m_startRow, column - m_startCol, field); - field = TQString(); - - ++row; - column = 1; - if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) - break; - - state = S_START; - } - else - { - field += x; - } - break; - case S_MAYBE_END_OF_QUOTED_FIELD : - if (x == m_textquote) - { - field += x; - state = S_QUOTED_FIELD; - } - else if (x == m_delimiter || x == '\n') - { - setText(row - m_startRow, column - m_startCol, field); - field = TQString(); - if (x == '\n') - { - ++row; - column = 1; - if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) - break; - } - else - { - if ((m_ignoreDups == false) || (lastCharDelimiter == false)) - ++column; - lastCharDelimiter = true; - } - state = S_START; - } - else - { - state = S_END_OF_QUOTED_FIELD; - } - break; - case S_END_OF_QUOTED_FIELD : - if (x == m_delimiter || x == '\n') - { - setText(row - m_startRow, column - m_startCol, field); - field = TQString(); - if (x == '\n') - { - ++row; - column = 1; - if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) - break; - } - else - { - if ((m_ignoreDups == false) || (lastCharDelimiter == false)) - ++column; - lastCharDelimiter = true; - } - state = S_START; - } - else - { - state = S_END_OF_QUOTED_FIELD; - } - break; - case S_MAYBE_NORMAL_FIELD : - if (x == m_textquote) - { - field = TQString(); - state = S_QUOTED_FIELD; - break; - } - case S_NORMAL_FIELD : - if (x == m_delimiter || x == '\n') - { - setText(row - m_startRow, column - m_startCol, field); - field = TQString(); - if (x == '\n') - { - ++row; - column = 1; - if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) - break; - } - else - { - if ((m_ignoreDups == false) || (lastCharDelimiter == false)) - ++column; - lastCharDelimiter = true; - } - state = S_START; - } - else - { - field += x; - } - } - if (x != m_delimiter) - lastCharDelimiter = false; - } - - if ( !field.isEmpty() ) - { - // the last line of the file had not any line end - setText(row - m_startRow, column - m_startCol, field); - ++row; - field = TQString(); - } - - m_adjustCols = true; - adjustRows( row - m_startRow ); - adjustCols( maxColumn - m_startCol ); - m_dialog->m_colEnd->setMaxValue( maxColumn ); - if ( m_endCol == -1 ) - m_dialog->m_colEnd->setValue( maxColumn ); - - - for (column = 0; column < m_dialog->m_sheet->numCols(); ++column) - { - const TQString header = m_dialog->m_sheet->horizontalHeader()->label(column); - if ( m_formatList.find( header ) == m_formatList.end() ) - m_dialog->m_sheet->horizontalHeader()->setLabel(column, i18n("Text")); - - m_dialog->m_sheet->adjustColumn(column); - } - fillComboBox(); - - kapp->restoreOverrideCursor(); -} - -void CSVImportDialog::fillComboBox() -{ - if ( m_endRow == -1 ) - m_dialog->m_rowEnd->setValue( m_dialog->m_sheet->numRows() ); - else - m_dialog->m_rowEnd->setValue( m_endRow ); - - if ( m_endCol == -1 ) - m_dialog->m_colEnd->setValue( m_dialog->m_sheet->numCols() ); - else - m_dialog->m_colEnd->setValue( m_endCol ); - - m_dialog->m_rowEnd->setMinValue( 1 ); - m_dialog->m_colEnd->setMinValue( 1 ); - m_dialog->m_rowEnd->setMaxValue( m_dialog->m_sheet->numRows() ); - m_dialog->m_colEnd->setMaxValue( m_dialog->m_sheet->numCols() ); - - m_dialog->m_rowStart->setMinValue( 1 ); - m_dialog->m_colStart->setMinValue( 1 ); - m_dialog->m_rowStart->setMaxValue( m_dialog->m_sheet->numRows() ); - m_dialog->m_colStart->setMaxValue( m_dialog->m_sheet->numCols() ); -} - -int CSVImportDialog::headerType(int col) -{ - TQString header = m_dialog->m_sheet->horizontalHeader()->label(col); - - if (header == i18n("Text")) - return TEXT; - else if (header == i18n("Number")) - return NUMBER; - else if (header == i18n("Currency")) - return CURRENCY; - else if ( header == i18n( "Date" ) ) - return DATE; - else if ( header == i18n( "Decimal Comma Number" ) ) - return COMMANUMBER; - else if ( header == i18n( "Decimal Point Number" ) ) - return POINTNUMBER; - else - return TEXT; // Should not happen -} - -void CSVImportDialog::setText(int row, int col, const TQString& text) -{ - if ( row < 1 || col < 1 ) // skipped by the user - return; - - if ( ( row > ( m_endRow - m_startRow ) && m_endRow > 0 ) || ( col > ( m_endCol - m_startCol ) && m_endCol > 0 ) ) - return; - - if ( m_dialog->m_sheet->numRows() < row ) - { - m_dialog->m_sheet->setNumRows( row + 5000 ); /* We add 5000 at a time to limit recalculations */ - m_adjustRows = true; - } - - if ( m_dialog->m_sheet->numCols() < col ) - { - m_dialog->m_sheet->setNumCols( col ); - m_adjustCols = true; - } - - m_dialog->m_sheet->setText( row - 1, col - 1, text ); -} - -/* - * Called after the first fillTable() when number of rows are unknown. - */ -void CSVImportDialog::adjustRows(int iRows) -{ - if (m_adjustRows) - { - m_dialog->m_sheet->setNumRows( iRows ); - m_adjustRows = false; - } -} - -void CSVImportDialog::adjustCols(int iCols) -{ - if (m_adjustCols) - { - m_dialog->m_sheet->setNumCols( iCols ); - m_adjustCols = false; - - if ( m_endCol == -1 ) - { - if ( iCols > ( m_endCol - m_startCol ) ) - iCols = m_endCol - m_startCol; - - m_dialog->m_sheet->setNumCols( iCols ); - } - } -} - -void CSVImportDialog::returnPressed() -{ - if (m_dialog->m_delimiterBox->id(m_dialog->m_delimiterBox->selected()) != 4) - return; - - m_delimiter = m_dialog->m_delimiterEdit->text(); - fillTable(); -} - -void CSVImportDialog::textChanged ( const TQString & ) -{ - m_dialog->m_radioOther->setChecked ( true ); - delimiterClicked(4); // other -} - -void CSVImportDialog::formatChanged( const TQString& newValue ) -{ - //kdDebug(30501) << "CSVImportDialog::formatChanged:" << newValue << endl; - for ( int i = 0; i < m_dialog->m_sheet->numSelections(); ++i ) - { - TQTableSelection select ( m_dialog->m_sheet->selection( i ) ); - for ( int j = select.leftCol(); j <= select.rightCol() ; ++j ) - { - m_dialog->m_sheet->horizontalHeader()->setLabel( j, newValue ); - - } - } -} - -void CSVImportDialog::delimiterClicked(int id) -{ - switch (id) - { - case 0: // comma - m_delimiter = ","; - break; - case 4: // other - m_delimiter = m_dialog->m_delimiterEdit->text(); - break; - case 2: // tab - m_delimiter = "\t"; - break; - case 3: // space - m_delimiter = " "; - break; - case 1: // semicolon - m_delimiter = ";"; - break; - } - - fillTable(); -} - -void CSVImportDialog::textquoteSelected(const TQString& mark) -{ - if (mark == i18n("None")) - m_textquote = 0; - else - m_textquote = mark[0]; - - fillTable(); -} - -void CSVImportDialog::updateClicked() -{ - if ( !checkUpdateRange() ) - return; - - m_startRow = m_dialog->m_rowStart->value() - 1; - m_endRow = m_dialog->m_rowEnd->value(); - - m_startCol = m_dialog->m_colStart->value() - 1; - m_endCol = m_dialog->m_colEnd->value(); - - fillTable(); -} - -bool CSVImportDialog::checkUpdateRange() -{ - if ( ( m_dialog->m_rowStart->value() > m_dialog->m_rowEnd->value() ) - || ( m_dialog->m_colStart->value() > m_dialog->m_colEnd->value() ) ) - { - KMessageBox::error( this, i18n( "Please check the ranges you specified. The start value must be lower than the end value." ) ); - return false; - } - - return true; -} - -void CSVImportDialog::currentCellChanged(int, int col) -{ - const TQString header = m_dialog->m_sheet->horizontalHeader()->label(col); - m_dialog->m_formatComboBox->setCurrentText( header ); -} - -void CSVImportDialog::ignoreDuplicatesChanged(int) -{ - if (m_dialog->m_ignoreDuplicates->isChecked()) - m_ignoreDups = true; - else - m_ignoreDups = false; - fillTable(); -} - -TQTextCodec* CSVImportDialog::getCodec(void) const -{ - const TQString strCodec( TDEGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) ); - kdDebug(30502) << "Encoding: " << strCodec << endl; - - bool ok = false; - TQTextCodec* codec = TQTextCodec::codecForName( strCodec.utf8() ); - - // If TQTextCodec has not found a valid encoding, so try with KCharsets. - if ( codec ) - { - ok = true; - } - else - { - codec = TDEGlobal::charsets()->codecForName( strCodec, ok ); - } - - // Still nothing? - if ( !codec || !ok ) - { - // Default: UTF-8 - kdWarning(30502) << "Cannot find encoding:" << strCodec << endl; - // ### TODO: what parent to use? - KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) ); - return 0; - } - - return codec; -} - -void CSVImportDialog::encodingChanged ( const TQString & ) -{ - TQTextCodec* codec = getCodec(); - - if ( codec ) - { - m_codec = codec; - fillTable(); - } -} - - -#include diff --git a/kchart/csvimportdialog.cpp b/kchart/csvimportdialog.cpp new file mode 100644 index 00000000..cf13c1b5 --- /dev/null +++ b/kchart/csvimportdialog.cpp @@ -0,0 +1,633 @@ +/* This file is part of the KDE project + Copyright (C) 1999 David Faure + Copyright (C) 2004 Nicolas GOUTTE + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +CSVImportDialog::CSVImportDialog(TQWidget* parent, TQByteArray& fileArray) + : KDialogBase(parent, 0, true, TQString(), Ok|Cancel, No, true), + m_dialog(new DialogUI(this)), + m_adjustRows(false), + m_adjustCols(false), + m_startRow(0), + m_startCol(0), + m_endRow(-1), + m_endCol(-1), + m_textquote('"'), + m_delimiter(","), + m_ignoreDups(false), + m_fileArray(fileArray), + m_codec( TQTextCodec::codecForName( "UTF-8" ) ) +{ + setCaption( i18n( "Import Data" ) ); + kapp->restoreOverrideCursor(); + + TQStringList encodings; + encodings << i18n( "Descriptive encoding name", "Recommended ( %1 )" ).arg( "UTF-8" ); + encodings << i18n( "Descriptive encoding name", "Locale ( %1 )" ).arg( TQTextCodec::codecForLocale()->name() ); + encodings += TDEGlobal::charsets()->descriptiveEncodingNames(); + // Add a few non-standard encodings, which might be useful for text files + const TQString description(i18n("Descriptive encoding name","Other ( %1 )")); + encodings << description.arg("Apple Roman"); // Apple + encodings << description.arg("IBM 850") << description.arg("IBM 866"); // MS DOS + encodings << description.arg("CP 1258"); // Windows + m_dialog->comboBoxEncoding->insertStringList(encodings); + + m_formatList << i18n( "Text" ); + m_formatList << i18n( "Number" ); + //m_formatList << i18n( "Currency" ); + //m_formatList << i18n( "Date" ); + m_formatList << i18n( "Decimal Comma Number" ); + m_formatList << i18n( "Decimal Point Number" ); + m_dialog->m_formatComboBox->insertStringList( m_formatList ); + + m_dialog->m_sheet->setReadOnly( true ); + + fillTable(); + + //resize(sizeHint()); + resize( 600, 400 ); // Try to show as much as possible of the table view + setMainWidget(m_dialog); + + m_dialog->m_sheet->setSelectionMode( TQTable::Multi ); + + connect(m_dialog->m_formatComboBox, TQT_SIGNAL(activated( const TQString& )), + this, TQT_SLOT(formatChanged( const TQString& ))); + connect(m_dialog->m_delimiterBox, TQT_SIGNAL(clicked(int)), + this, TQT_SLOT(delimiterClicked(int))); + connect(m_dialog->m_delimiterEdit, TQT_SIGNAL(returnPressed()), + this, TQT_SLOT(returnPressed())); + connect(m_dialog->m_delimiterEdit, TQT_SIGNAL(textChanged ( const TQString & )), + this, TQT_SLOT(formatChanged ( const TQString & ) )); + connect(m_dialog->m_comboQuote, TQT_SIGNAL(activated(const TQString &)), + this, TQT_SLOT(textquoteSelected(const TQString &))); + connect(m_dialog->m_sheet, TQT_SIGNAL(currentChanged(int, int)), + this, TQT_SLOT(currentCellChanged(int, int))); + connect(m_dialog->m_ignoreDuplicates, TQT_SIGNAL(stateChanged(int)), + this, TQT_SLOT(ignoreDuplicatesChanged(int))); + connect(m_dialog->m_updateButton, TQT_SIGNAL(clicked()), + this, TQT_SLOT(updateClicked())); + connect(m_dialog->comboBoxEncoding, TQT_SIGNAL(textChanged ( const TQString & )), + this, TQT_SLOT(encodingChanged ( const TQString & ) )); +} + + +CSVImportDialog::~CSVImportDialog() +{ + kapp->setOverrideCursor(TQt::waitCursor); +} + + +// ---------------------------------------------------------------- +// public methods + + +bool CSVImportDialog::firstRowContainHeaders() +{ + return m_dialog->m_firstRowHeader->isChecked(); +} + + +bool CSVImportDialog::firstColContainHeaders() +{ + return m_dialog->m_firstColHeader->isChecked(); +} + + +int CSVImportDialog::rows() +{ + int rows = m_dialog->m_sheet->numRows(); + + if ( m_endRow >= 0 ) + rows = m_endRow - m_startRow + 1; + + return rows; +} + + +int CSVImportDialog::cols() +{ + int cols = m_dialog->m_sheet->numCols(); + + if ( m_endCol >= 0 ) + cols = m_endCol - m_startCol + 1; + + return cols; +} + + +TQString CSVImportDialog::text(int row, int col) +{ + // Check for overflow. + if ( row >= rows() || col >= cols()) + return TQString(); + + return m_dialog->m_sheet->text( row - m_startRow, col - m_startCol ); +} + + +// ---------------------------------------------------------------- + + +void CSVImportDialog::fillTable( ) +{ + int row, column; + bool lastCharDelimiter = false; + enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, + S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; + + TQChar x; + TQString field; + + kapp->setOverrideCursor(TQt::waitCursor); + + for (row = 0; row < m_dialog->m_sheet->numRows(); ++row) + for (column = 0; column < m_dialog->m_sheet->numCols(); ++column) + m_dialog->m_sheet->clearCell(row, column); + + int maxColumn = 1; + row = column = 1; + TQTextStream inputStream(m_fileArray, IO_ReadOnly); + kdDebug(30501) << "Encoding: " << m_codec->name() << endl; + inputStream.setCodec( m_codec ); + + bool lastCharWasCr = false; // Last character was a Carriage Return + while (!inputStream.atEnd()) + { + inputStream >> x; // read one char + + // ### TODO: we should perhaps skip all other control characters + if ( x == '\r' ) + { + // We have a Carriage Return, assume that its role is the one of a LineFeed + lastCharWasCr = true; + x = '\n'; // Replace by Line Feed + } + else if ( x == '\n' && lastCharWasCr ) + { + // The end of line was already handled by the Carriage Return, so do nothing for this character + lastCharWasCr = false; + continue; + } + else if ( x == TQChar( 0xc ) ) + { + // We have a FormFeed, skip it + lastCharWasCr = false; + continue; + } + else + { + lastCharWasCr = false; + } + + if ( column > maxColumn ) + maxColumn = column; + + switch (state) + { + case S_START : + if (x == m_textquote) + { + state = S_QUOTED_FIELD; + } + else if (x == m_delimiter) + { + if ((m_ignoreDups == false) || (lastCharDelimiter == false)) + ++column; + lastCharDelimiter = true; + } + else if (x == '\n') + { + ++row; + column = 1; + if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) + break; + } + else + { + field += x; + state = S_MAYBE_NORMAL_FIELD; + } + break; + case S_QUOTED_FIELD : + if (x == m_textquote) + { + state = S_MAYBE_END_OF_QUOTED_FIELD; + } + else if (x == '\n') + { + setText(row - m_startRow, column - m_startCol, field); + field = TQString(); + + ++row; + column = 1; + if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) + break; + + state = S_START; + } + else + { + field += x; + } + break; + case S_MAYBE_END_OF_QUOTED_FIELD : + if (x == m_textquote) + { + field += x; + state = S_QUOTED_FIELD; + } + else if (x == m_delimiter || x == '\n') + { + setText(row - m_startRow, column - m_startCol, field); + field = TQString(); + if (x == '\n') + { + ++row; + column = 1; + if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) + break; + } + else + { + if ((m_ignoreDups == false) || (lastCharDelimiter == false)) + ++column; + lastCharDelimiter = true; + } + state = S_START; + } + else + { + state = S_END_OF_QUOTED_FIELD; + } + break; + case S_END_OF_QUOTED_FIELD : + if (x == m_delimiter || x == '\n') + { + setText(row - m_startRow, column - m_startCol, field); + field = TQString(); + if (x == '\n') + { + ++row; + column = 1; + if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) + break; + } + else + { + if ((m_ignoreDups == false) || (lastCharDelimiter == false)) + ++column; + lastCharDelimiter = true; + } + state = S_START; + } + else + { + state = S_END_OF_QUOTED_FIELD; + } + break; + case S_MAYBE_NORMAL_FIELD : + if (x == m_textquote) + { + field = TQString(); + state = S_QUOTED_FIELD; + break; + } + case S_NORMAL_FIELD : + if (x == m_delimiter || x == '\n') + { + setText(row - m_startRow, column - m_startCol, field); + field = TQString(); + if (x == '\n') + { + ++row; + column = 1; + if ( row > ( m_endRow - m_startRow ) && m_endRow >= 0 ) + break; + } + else + { + if ((m_ignoreDups == false) || (lastCharDelimiter == false)) + ++column; + lastCharDelimiter = true; + } + state = S_START; + } + else + { + field += x; + } + } + if (x != m_delimiter) + lastCharDelimiter = false; + } + + if ( !field.isEmpty() ) + { + // the last line of the file had not any line end + setText(row - m_startRow, column - m_startCol, field); + ++row; + field = TQString(); + } + + m_adjustCols = true; + adjustRows( row - m_startRow ); + adjustCols( maxColumn - m_startCol ); + m_dialog->m_colEnd->setMaxValue( maxColumn ); + if ( m_endCol == -1 ) + m_dialog->m_colEnd->setValue( maxColumn ); + + + for (column = 0; column < m_dialog->m_sheet->numCols(); ++column) + { + const TQString header = m_dialog->m_sheet->horizontalHeader()->label(column); + if ( m_formatList.find( header ) == m_formatList.end() ) + m_dialog->m_sheet->horizontalHeader()->setLabel(column, i18n("Text")); + + m_dialog->m_sheet->adjustColumn(column); + } + fillComboBox(); + + kapp->restoreOverrideCursor(); +} + +void CSVImportDialog::fillComboBox() +{ + if ( m_endRow == -1 ) + m_dialog->m_rowEnd->setValue( m_dialog->m_sheet->numRows() ); + else + m_dialog->m_rowEnd->setValue( m_endRow ); + + if ( m_endCol == -1 ) + m_dialog->m_colEnd->setValue( m_dialog->m_sheet->numCols() ); + else + m_dialog->m_colEnd->setValue( m_endCol ); + + m_dialog->m_rowEnd->setMinValue( 1 ); + m_dialog->m_colEnd->setMinValue( 1 ); + m_dialog->m_rowEnd->setMaxValue( m_dialog->m_sheet->numRows() ); + m_dialog->m_colEnd->setMaxValue( m_dialog->m_sheet->numCols() ); + + m_dialog->m_rowStart->setMinValue( 1 ); + m_dialog->m_colStart->setMinValue( 1 ); + m_dialog->m_rowStart->setMaxValue( m_dialog->m_sheet->numRows() ); + m_dialog->m_colStart->setMaxValue( m_dialog->m_sheet->numCols() ); +} + +int CSVImportDialog::headerType(int col) +{ + TQString header = m_dialog->m_sheet->horizontalHeader()->label(col); + + if (header == i18n("Text")) + return TEXT; + else if (header == i18n("Number")) + return NUMBER; + else if (header == i18n("Currency")) + return CURRENCY; + else if ( header == i18n( "Date" ) ) + return DATE; + else if ( header == i18n( "Decimal Comma Number" ) ) + return COMMANUMBER; + else if ( header == i18n( "Decimal Point Number" ) ) + return POINTNUMBER; + else + return TEXT; // Should not happen +} + +void CSVImportDialog::setText(int row, int col, const TQString& text) +{ + if ( row < 1 || col < 1 ) // skipped by the user + return; + + if ( ( row > ( m_endRow - m_startRow ) && m_endRow > 0 ) || ( col > ( m_endCol - m_startCol ) && m_endCol > 0 ) ) + return; + + if ( m_dialog->m_sheet->numRows() < row ) + { + m_dialog->m_sheet->setNumRows( row + 5000 ); /* We add 5000 at a time to limit recalculations */ + m_adjustRows = true; + } + + if ( m_dialog->m_sheet->numCols() < col ) + { + m_dialog->m_sheet->setNumCols( col ); + m_adjustCols = true; + } + + m_dialog->m_sheet->setText( row - 1, col - 1, text ); +} + +/* + * Called after the first fillTable() when number of rows are unknown. + */ +void CSVImportDialog::adjustRows(int iRows) +{ + if (m_adjustRows) + { + m_dialog->m_sheet->setNumRows( iRows ); + m_adjustRows = false; + } +} + +void CSVImportDialog::adjustCols(int iCols) +{ + if (m_adjustCols) + { + m_dialog->m_sheet->setNumCols( iCols ); + m_adjustCols = false; + + if ( m_endCol == -1 ) + { + if ( iCols > ( m_endCol - m_startCol ) ) + iCols = m_endCol - m_startCol; + + m_dialog->m_sheet->setNumCols( iCols ); + } + } +} + +void CSVImportDialog::returnPressed() +{ + if (m_dialog->m_delimiterBox->id(m_dialog->m_delimiterBox->selected()) != 4) + return; + + m_delimiter = m_dialog->m_delimiterEdit->text(); + fillTable(); +} + +void CSVImportDialog::textChanged ( const TQString & ) +{ + m_dialog->m_radioOther->setChecked ( true ); + delimiterClicked(4); // other +} + +void CSVImportDialog::formatChanged( const TQString& newValue ) +{ + //kdDebug(30501) << "CSVImportDialog::formatChanged:" << newValue << endl; + for ( int i = 0; i < m_dialog->m_sheet->numSelections(); ++i ) + { + TQTableSelection select ( m_dialog->m_sheet->selection( i ) ); + for ( int j = select.leftCol(); j <= select.rightCol() ; ++j ) + { + m_dialog->m_sheet->horizontalHeader()->setLabel( j, newValue ); + + } + } +} + +void CSVImportDialog::delimiterClicked(int id) +{ + switch (id) + { + case 0: // comma + m_delimiter = ","; + break; + case 4: // other + m_delimiter = m_dialog->m_delimiterEdit->text(); + break; + case 2: // tab + m_delimiter = "\t"; + break; + case 3: // space + m_delimiter = " "; + break; + case 1: // semicolon + m_delimiter = ";"; + break; + } + + fillTable(); +} + +void CSVImportDialog::textquoteSelected(const TQString& mark) +{ + if (mark == i18n("None")) + m_textquote = 0; + else + m_textquote = mark[0]; + + fillTable(); +} + +void CSVImportDialog::updateClicked() +{ + if ( !checkUpdateRange() ) + return; + + m_startRow = m_dialog->m_rowStart->value() - 1; + m_endRow = m_dialog->m_rowEnd->value(); + + m_startCol = m_dialog->m_colStart->value() - 1; + m_endCol = m_dialog->m_colEnd->value(); + + fillTable(); +} + +bool CSVImportDialog::checkUpdateRange() +{ + if ( ( m_dialog->m_rowStart->value() > m_dialog->m_rowEnd->value() ) + || ( m_dialog->m_colStart->value() > m_dialog->m_colEnd->value() ) ) + { + KMessageBox::error( this, i18n( "Please check the ranges you specified. The start value must be lower than the end value." ) ); + return false; + } + + return true; +} + +void CSVImportDialog::currentCellChanged(int, int col) +{ + const TQString header = m_dialog->m_sheet->horizontalHeader()->label(col); + m_dialog->m_formatComboBox->setCurrentText( header ); +} + +void CSVImportDialog::ignoreDuplicatesChanged(int) +{ + if (m_dialog->m_ignoreDuplicates->isChecked()) + m_ignoreDups = true; + else + m_ignoreDups = false; + fillTable(); +} + +TQTextCodec* CSVImportDialog::getCodec(void) const +{ + const TQString strCodec( TDEGlobal::charsets()->encodingForName( m_dialog->comboBoxEncoding->currentText() ) ); + kdDebug(30502) << "Encoding: " << strCodec << endl; + + bool ok = false; + TQTextCodec* codec = TQTextCodec::codecForName( strCodec.utf8() ); + + // If TQTextCodec has not found a valid encoding, so try with KCharsets. + if ( codec ) + { + ok = true; + } + else + { + codec = TDEGlobal::charsets()->codecForName( strCodec, ok ); + } + + // Still nothing? + if ( !codec || !ok ) + { + // Default: UTF-8 + kdWarning(30502) << "Cannot find encoding:" << strCodec << endl; + // ### TODO: what parent to use? + KMessageBox::error( 0, i18n("Cannot find encoding: %1").arg( strCodec ) ); + return 0; + } + + return codec; +} + +void CSVImportDialog::encodingChanged ( const TQString & ) +{ + TQTextCodec* codec = getCodec(); + + if ( codec ) + { + m_codec = codec; + fillTable(); + } +} + + +#include diff --git a/kchart/kchartBackgroundPixmapConfigPage.cc b/kchart/kchartBackgroundPixmapConfigPage.cc deleted file mode 100644 index d7716d31..00000000 --- a/kchart/kchartBackgroundPixmapConfigPage.cc +++ /dev/null @@ -1,548 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000 Matthias Kalle Dalheimer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartBackgroundPixmapConfigPage.h" -#include "kchartBackgroundPixmapConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartBackgroundPixmapConfigPage::KChartBackgroundPixmapConfigPage( KChartParams* params, TQWidget* parent ) - : TQWidget( parent, "KChartBackgroundPixmapConfigPage" ), - _params( params ) -{ - TQWhatsThis::add( this, - i18n( "On this page, you can select colors or images " - "to be displayed behind the different areas. You " - "can also select whether the images should be " - "stretched or scaled or centered or used as " - "background tiles." ) ); - - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - -#if 0 - TQVBoxLayout* left=new TQVBoxLayout(10); - toplevel->addLayout(left,2); - regionList=new TQListBox(this); - left->addWidget(regionList); -#endif - - TQVBoxLayout* center = new TQVBoxLayout( 10 ); - toplevel->addLayout( center, 2 ); - - - TQLabel* backgroundLA = new TQLabel( i18n( "&Background color:" ), this ); - center->addWidget( backgroundLA ); - _backgroundCB = new KColorButton( this ); - backgroundLA->setBuddy( _backgroundCB ); - center->addWidget( _backgroundCB); - TQString wtstr = i18n( "Here you set the color in which the background " - "of the chart is painted." ); - TQWhatsThis::add( backgroundLA, wtstr ); - TQWhatsThis::add( _backgroundCB, wtstr ); - - - TQLabel* wallpaperLA = new TQLabel( i18n( "Background wallpaper:" ), this ); - center->addWidget( wallpaperLA ); - - wallCB = new TQComboBox( false, this, "wallCombo" ); - wallpaperLA->setBuddy(wallCB); - TQWhatsThis::add( wallCB, i18n( "You can select a background image from " - "this list. Initially, the installed TDE " - "wallpapers will be offered. If you do not " - "find what you are looking for here, you can " - "select any image file by clicking on the " - "Browse button below." ) ); - center->addWidget( wallCB ); - wallCB->insertItem( i18n("None") ); - - loadWallpaperFilesList(); - TQPushButton* browsePB = new TQPushButton( i18n("&Browse..."), this ); - TQWhatsThis::add( browsePB, i18n( "Click this button to select a background " - "image not yet present in the list above. " ) ); - center->addWidget( browsePB ); - connect( browsePB, TQT_SIGNAL( clicked() ), TQT_SLOT( slotBrowse() ) ); - - wallWidget = new TQWidget( this ); - TQWhatsThis::add( wallWidget, i18n( "This area will always display the " - "currently selected background image. " - "Note that the image will be scaled and " - "thus might have a different ratio than " - "it originally had." ) ); - center->addWidget( wallWidget ); - - connect( wallCB, TQT_SIGNAL( activated( int ) ), - this, TQT_SLOT( slotWallPaperChanged( int ) ) ); - - right = new TQVGroupBox( i18n( "Wallpaper Configuration" ), this ); - TQWhatsThis::add( right, i18n( "In this box, you can set various settings " - "that control how the background image is " - "displayed." ) ); - toplevel->addWidget( right ); - - TQHBox* intensityHB = new TQHBox( right ); - intensityHB->setSpacing( 10 ); - TQLabel* intensityLA = new TQLabel( - // xgettext:no-c-format - i18n( "&Intensity in %:" ), intensityHB ); - intensitySB = new TQSpinBox( 1, 100, 1, intensityHB ); - intensityLA->setBuddy( intensitySB ); - // xgettext:no-c-format - TQString ttstr = i18n( "Here you can select how much the image should be " - "brightened up so that it does not disturb the " - "selected area too much.
Different images require " - "different settings, but 25% is a good value to start " - "with." ); - TQWhatsThis::add( intensityLA, ttstr ); - TQWhatsThis::add( intensitySB, ttstr ); - - - stretchedRB = new TQRadioButton( i18n( "Stretched" ), right ); - TQWhatsThis::add( stretchedRB, - i18n( "If you check this box, the selected image will " - "be scaled to fit the total size of the selected " - "area. Image ratio will be adjusted to match " - "the area size and height if necessary." ) ); - stretchedRB->setChecked( true ); - scaledRB = new TQRadioButton( i18n( "Scaled" ), right ); - TQWhatsThis::add( scaledRB, - i18n( "If you check this box, the selected image will " - "be scaled to match the height or width of the " - "selected area - whichever is reached first." ) ); - centeredRB = new TQRadioButton( i18n( "Centered" ), right ); - TQWhatsThis::add( centeredRB, - i18n( "If you check this box, the selected image will " - "be centered over the selected area. If the image " - "is larger then the area, you will only see the " - "middle part of it." ) ); - - tiledRB = new TQRadioButton( i18n( "Tiled" ), right ); - TQWhatsThis::add( tiledRB, - i18n( "If you check this box, the selected image will " - "be used as a background tile. If the image is " - "larger then the selected area, you will only see " - "the upper left part of it." ) ); - TQButtonGroup* alignmentBG; - alignmentBG = new TQButtonGroup( right, "GroupBox_Alignment" ); - alignmentBG->setFrameStyle( TQFrame::NoFrame ); - alignmentBG->insert( stretchedRB ); - alignmentBG->insert( scaledRB ); - alignmentBG->insert( centeredRB ); - alignmentBG->insert( tiledRB ); - - intensitySB->hide(); //the property doesn't work atm -} - -//Code from kcontrol/background/bgdialog.cc -void KChartBackgroundPixmapConfigPage::loadWallpaperFilesList() -{ - // Wallpapers - // the following TQMap is lower cased names mapped to cased names and URLs - // this way we get case insensitive sorting - TQMap > papers; - - //search for .desktop files before searching for images without .desktop files - TQStringList lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*desktop", false, true); - TQStringList files; - for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) - { - KSimpleConfig fileConfig(*it); - fileConfig.setGroup("Wallpaper"); - - TQString imageCaption = fileConfig.readEntry("Name"); - TQString fileName = fileConfig.readEntry("File"); - - if (imageCaption.isEmpty()) - { - imageCaption = fileName; - imageCaption.replace('_', ' '); - imageCaption = KStringHandler::capwords(imageCaption); - } - - // avoid name collisions - TQString rs = imageCaption; - TQString lrs = rs.lower(); - for (int n = 1; papers.find(lrs) != papers.end(); ++n) - { - rs = imageCaption + " (" + TQString::number(n) + ')'; - lrs = rs.lower(); - } - int slash = (*it).findRev('/') + 1; - TQString directory = (*it).left(slash); - bool canLoadScaleable = false; -#ifdef HAVE_LIBART - canLoadScaleable = true; -#endif - if ( fileConfig.readEntry("ImageType") == "pixmap" || canLoadScaleable ) { - papers[lrs] = tqMakePair(rs, directory + fileName); - files.append(directory + fileName); - } - } - - //now find any wallpapers that don't have a .desktop file - lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*", false, true); - for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) - { - if ( !(*it).endsWith(".desktop") && files.grep(*it).empty() ) { - // First try to see if we have a comment describing the image. If we do - // just use the first line of said comment. - KFileMetaInfo metaInfo(*it); - TQString imageCaption; - - if (metaInfo.isValid() && metaInfo.item("Comment").isValid()) - imageCaption = metaInfo.item("Comment").string().section('\n', 0, 0); - - if (imageCaption.isEmpty()) - { - int slash = (*it).findRev('/') + 1; - int endDot = (*it).findRev('.'); - - // strip the extension if it exists - if (endDot != -1 && endDot > slash) - imageCaption = (*it).mid(slash, endDot - slash); - else - imageCaption = (*it).mid(slash); - - imageCaption.replace('_', ' '); - imageCaption = KStringHandler::capwords(imageCaption); - } - - // avoid name collisions - TQString rs = imageCaption; - TQString lrs = rs.lower(); - for (int n = 1; papers.find(lrs) != papers.end(); ++n) - { - rs = imageCaption + " (" + TQString::number(n) + ')'; - lrs = rs.lower(); - } - papers[lrs] = tqMakePair(rs, *it); - } - } - - m_wallpaper.clear(); - //don't start to 0, we have None element - int i = 1; - for (TQMap >::Iterator it = papers.begin(); - it != papers.end(); - ++it) - { - wallCB->insertItem(it.data().first); - m_wallpaper[it.data().second] = i; - i++; - } -} - -void KChartBackgroundPixmapConfigPage::init() -{ -#if 0 - TQStringList lst; - lst.append(i18n( "Outermost Region" )); - lst.append(i18n( "Innermost Region" )); - lst.append(i18n( "Header+Title+Subtitle" )); - lst.append(i18n( "Footers" )); - lst.append(i18n( "Data+Axes+Legend" )); - lst.append(i18n( "Data+Axes" )); - lst.append(i18n( "Data" )); - lst.append(i18n( "Legend" )); - lst.append(i18n( "Left Axis" )); - lst.append(i18n( "Bottom Axis" )); - lst.append(i18n( "Right Axis" )); - lst.append(i18n( "Header A" )); - lst.append(i18n( "Header B" )); - lst.append(i18n( "Header C" )); - lst.append(i18n( "Title A" )); - lst.append(i18n( "Title B" )); - lst.append(i18n( "Title C" )); - lst.append(i18n( "Subtitle A" )); - lst.append(i18n( "Subtitle B" )); - lst.append(i18n( "Subtitle C" )); - lst.append(i18n( "Footer 1 A" )); - lst.append(i18n( "Footer 1 B" )); - lst.append(i18n( "Footer 1 C" )); - lst.append(i18n( "Footer 2 A" )); - lst.append(i18n( "Footer 2 B" )); - lst.append(i18n( "Footer 2 C" )); - lst.append(i18n( "Footer 3 A" )); - lst.append(i18n( "Footer 3 B" )); - lst.append(i18n( "Footer 3 C" )); - regionList->insertStringList(lst); -#endif - // PENDING(kalle) Readapt - // showSettings( _params->backgroundPixmapName ); -// intensitySB->setValue( (int)(_params->backgroundPixmapIntensity * 100.0) ); -// scaledCB->setChecked( _params->backgroundPixmapScaled ); -// centeredCB->setChecked( _params->backgroundPixmapCentered ); - - bool bFound; - const KDChartParams::KDChartFrameSettings * innerFrame = - _params->frameSettings( KDChartEnums::AreaInnermost, bFound ); - if( bFound ) - { - const TQPixmap* backPixmap; - bool isTiledMode = false; - KDFrame::BackPixmapMode backPixmapMode; - const TQBrush& background = innerFrame->frame().background( backPixmap, backPixmapMode ); - const TQColor backColor( background.color() ); - - // Bg color has to be be set in any case, - // even when a (tiled) pixmap is specified: - _backgroundCB->setColor( backColor ); - - - if( !backPixmap || backPixmap->isNull() ) - { - // A pixmap can be in the brush, if used as Tile. - backPixmap = background.pixmap(); - if( backPixmap ) - isTiledMode = true; - } - - if( !backPixmap || backPixmap->isNull() ) //color as background - { - right->setEnabled( false ); - wallCB->setCurrentItem( 0 ); - } - else //pixmap as background - { - _backgroundCB->setEnabled( false ); - wallWidget->setPaletteBackgroundPixmap( *backPixmap ); - wallCB->setCurrentItem( 1 ); - if( isTiledMode ) - { - tiledRB->setChecked( true ); - } - else - { - switch( backPixmapMode ){ - case KDFrame::PixCentered: - centeredRB->setChecked( true ); - break; - case KDFrame::PixScaled: - scaledRB->setChecked( true ); - break; - default: - stretchedRB->setChecked( true ); - } - } - } - } - else - _backgroundCB->setColor(TQColor(230, 222, 222) ); -} - -void KChartBackgroundPixmapConfigPage::apply() -{ - // PENDING(kalle) Readapt - // if( wallCB->currentText() != _params->backgroundPixmapName ) { -// bool load=true; -// if(wallCB->currentText()==i18n("None")) { -// load=false; -// } else { -// _params->backgroundPixmapName = wallCB->currentText(); -// bool load=_params->backgroundPixmap.load( locate( "wallpaper", _params->backgroundPixmapName ) ); -// if(load) -// _params->backgroundPixmapIsDirty = true; -// } - -// if( !load ) { -// _params->backgroundPixmapName = ""; -// _params->backgroundPixmap=TQPixmap(""); -// _params->backgroundPixmapIsDirty = false; -// } -// } -// if( (int)(_params->backgroundPixmapIntensity * 100.0) != -// intensitySB->value() ) { -// _params->backgroundPixmapIntensity = (float)(intensitySB->value()) / 100.0; -// _params->backgroundPixmapIsDirty = true; -// } - -// if( _params->backgroundPixmapScaled != -// scaledCB->isChecked() ) { -// _params->backgroundPixmapScaled = scaledCB->isChecked(); -// _params->backgroundPixmapIsDirty = true; -// } -// if( _params->backgroundPixmapCentered != -// centeredCB->isChecked() ) { -// _params->backgroundPixmapCentered = centeredCB->isChecked(); -// _params->backgroundPixmapIsDirty = true; -// } - - // - // temp. hack: the background is removed if "None" is selected in the combo box - // - // For KOffice 1.5/2.0 this is to be removed by a checkbox. - bool bFound; - const KDChartParams::KDChartFrameSettings * innerFrame = - _params->frameSettings( KDChartEnums::AreaInnermost, bFound ); - if( bFound ) - { - const TQColor backColor( _backgroundCB->color() ); - KDFrame& frame( const_cast(innerFrame->frame()) ); - if ( wallCB->currentItem() == 0 ) - { - frame.setBackPixmap( 0 ); - frame.setBackground( backColor ); - } - else - { - const TQPixmap* pixmap = wallWidget->paletteBackgroundPixmap(); - if ( tiledRB->isChecked() ){ - // We remove the frame's extra pixmap, - frame.setBackPixmap( 0 ); - // because a tiled image is set via a TQBrush. - if( pixmap ) - frame.setBackground( TQBrush( backColor, *pixmap ) ); - else - frame.setBackground( backColor ); - }else{ - KDFrame::BackPixmapMode backPixmapMode; - if ( centeredRB->isChecked() ) - backPixmapMode = KDFrame::PixCentered; - else if ( scaledRB->isChecked() ) - backPixmapMode = KDFrame::PixScaled; - else - backPixmapMode = KDFrame::PixStretched; - // We reset the background color, removing any tiled brush, - frame.setBackground( backColor ); - // because we specify an extra pixmap instead. - frame.setBackPixmap( pixmap, backPixmapMode ); - } - } - } -} - - -void KChartBackgroundPixmapConfigPage::showSettings( const TQString& fileName ) -{ - wallCB->blockSignals(true); - - if (m_wallpaper.find(fileName) == m_wallpaper.end()) - { - int i = wallCB->count(); - TQString imageCaption; - int slash = fileName.findRev('/') + 1; - int endDot = fileName.findRev('.'); - - // strip the extension if it exists - if (endDot != -1 && endDot > slash) - imageCaption = fileName.mid(slash, endDot - slash); - else - imageCaption = fileName.mid(slash); - if (wallCB->text(i-1) == imageCaption) - { - i--; - wallCB->removeItem(i); - } - wallCB->insertItem(imageCaption); - m_wallpaper[fileName] = i; - wallCB->setCurrentItem(i); - } - else - { - wallCB->setCurrentItem(m_wallpaper[fileName]); - } - wallCB->blockSignals(false); - loadWallPaper(); -} - - -void KChartBackgroundPixmapConfigPage::slotBrowse() -{ - //TODO: Support non-local wallpapers - KURL url = KFileDialog::getOpenFileName( 0 ); - if( url.isEmpty() ) - return; - showSettings( url.path() ); -} - -void KChartBackgroundPixmapConfigPage::slotWallPaperChanged( int index ) -{ - if ( index != 0 && loadWallPaper() ) - { - _backgroundCB->setEnabled( false ); - right->setEnabled( true ); - } - else - { - wallWidget->setPaletteBackgroundPixmap( 0 ); - _backgroundCB->setEnabled( true ); - right->setEnabled( false ); - } -} - - -bool KChartBackgroundPixmapConfigPage::loadWallPaper() -{ - int i = wallCB->currentItem(); - if ( i == -1 || i == 0 ) { // 0 is 'None' - wallPixmap.resize(0,0); - wallFile = ""; - } else { - for(TQMap::ConstIterator it = m_wallpaper.begin(); - it != m_wallpaper.end(); - ++it) - { - if (it.data() == i) - { - wallFile = it.key(); - break; - } - } - TQString file = locate("wallpaper", wallFile); - if( file.isEmpty() ) { - kdWarning(35001) << "Couldn't locate wallpaper " << wallFile << endl; - wallPixmap.resize(0,0); - wallFile = ""; - return false; - } else { - wallPixmap.load( file ); - - if( wallPixmap.isNull() ) - return false; -// kdWarning(35001) << "Could not load wallpaper " << file << endl; - } - } - wallWidget->setPaletteBackgroundPixmap( wallPixmap ); - return true; -} - -} //KChart namespace diff --git a/kchart/kchartBackgroundPixmapConfigPage.cpp b/kchart/kchartBackgroundPixmapConfigPage.cpp new file mode 100644 index 00000000..c9213116 --- /dev/null +++ b/kchart/kchartBackgroundPixmapConfigPage.cpp @@ -0,0 +1,548 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Matthias Kalle Dalheimer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartBackgroundPixmapConfigPage.h" +#include "kchartBackgroundPixmapConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartBackgroundPixmapConfigPage::KChartBackgroundPixmapConfigPage( KChartParams* params, TQWidget* parent ) + : TQWidget( parent, "KChartBackgroundPixmapConfigPage" ), + _params( params ) +{ + TQWhatsThis::add( this, + i18n( "On this page, you can select colors or images " + "to be displayed behind the different areas. You " + "can also select whether the images should be " + "stretched or scaled or centered or used as " + "background tiles." ) ); + + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + +#if 0 + TQVBoxLayout* left=new TQVBoxLayout(10); + toplevel->addLayout(left,2); + regionList=new TQListBox(this); + left->addWidget(regionList); +#endif + + TQVBoxLayout* center = new TQVBoxLayout( 10 ); + toplevel->addLayout( center, 2 ); + + + TQLabel* backgroundLA = new TQLabel( i18n( "&Background color:" ), this ); + center->addWidget( backgroundLA ); + _backgroundCB = new KColorButton( this ); + backgroundLA->setBuddy( _backgroundCB ); + center->addWidget( _backgroundCB); + TQString wtstr = i18n( "Here you set the color in which the background " + "of the chart is painted." ); + TQWhatsThis::add( backgroundLA, wtstr ); + TQWhatsThis::add( _backgroundCB, wtstr ); + + + TQLabel* wallpaperLA = new TQLabel( i18n( "Background wallpaper:" ), this ); + center->addWidget( wallpaperLA ); + + wallCB = new TQComboBox( false, this, "wallCombo" ); + wallpaperLA->setBuddy(wallCB); + TQWhatsThis::add( wallCB, i18n( "You can select a background image from " + "this list. Initially, the installed TDE " + "wallpapers will be offered. If you do not " + "find what you are looking for here, you can " + "select any image file by clicking on the " + "Browse button below." ) ); + center->addWidget( wallCB ); + wallCB->insertItem( i18n("None") ); + + loadWallpaperFilesList(); + TQPushButton* browsePB = new TQPushButton( i18n("&Browse..."), this ); + TQWhatsThis::add( browsePB, i18n( "Click this button to select a background " + "image not yet present in the list above. " ) ); + center->addWidget( browsePB ); + connect( browsePB, TQT_SIGNAL( clicked() ), TQT_SLOT( slotBrowse() ) ); + + wallWidget = new TQWidget( this ); + TQWhatsThis::add( wallWidget, i18n( "This area will always display the " + "currently selected background image. " + "Note that the image will be scaled and " + "thus might have a different ratio than " + "it originally had." ) ); + center->addWidget( wallWidget ); + + connect( wallCB, TQT_SIGNAL( activated( int ) ), + this, TQT_SLOT( slotWallPaperChanged( int ) ) ); + + right = new TQVGroupBox( i18n( "Wallpaper Configuration" ), this ); + TQWhatsThis::add( right, i18n( "In this box, you can set various settings " + "that control how the background image is " + "displayed." ) ); + toplevel->addWidget( right ); + + TQHBox* intensityHB = new TQHBox( right ); + intensityHB->setSpacing( 10 ); + TQLabel* intensityLA = new TQLabel( + // xgettext:no-c-format + i18n( "&Intensity in %:" ), intensityHB ); + intensitySB = new TQSpinBox( 1, 100, 1, intensityHB ); + intensityLA->setBuddy( intensitySB ); + // xgettext:no-c-format + TQString ttstr = i18n( "Here you can select how much the image should be " + "brightened up so that it does not disturb the " + "selected area too much.
Different images require " + "different settings, but 25% is a good value to start " + "with." ); + TQWhatsThis::add( intensityLA, ttstr ); + TQWhatsThis::add( intensitySB, ttstr ); + + + stretchedRB = new TQRadioButton( i18n( "Stretched" ), right ); + TQWhatsThis::add( stretchedRB, + i18n( "If you check this box, the selected image will " + "be scaled to fit the total size of the selected " + "area. Image ratio will be adjusted to match " + "the area size and height if necessary." ) ); + stretchedRB->setChecked( true ); + scaledRB = new TQRadioButton( i18n( "Scaled" ), right ); + TQWhatsThis::add( scaledRB, + i18n( "If you check this box, the selected image will " + "be scaled to match the height or width of the " + "selected area - whichever is reached first." ) ); + centeredRB = new TQRadioButton( i18n( "Centered" ), right ); + TQWhatsThis::add( centeredRB, + i18n( "If you check this box, the selected image will " + "be centered over the selected area. If the image " + "is larger then the area, you will only see the " + "middle part of it." ) ); + + tiledRB = new TQRadioButton( i18n( "Tiled" ), right ); + TQWhatsThis::add( tiledRB, + i18n( "If you check this box, the selected image will " + "be used as a background tile. If the image is " + "larger then the selected area, you will only see " + "the upper left part of it." ) ); + TQButtonGroup* alignmentBG; + alignmentBG = new TQButtonGroup( right, "GroupBox_Alignment" ); + alignmentBG->setFrameStyle( TQFrame::NoFrame ); + alignmentBG->insert( stretchedRB ); + alignmentBG->insert( scaledRB ); + alignmentBG->insert( centeredRB ); + alignmentBG->insert( tiledRB ); + + intensitySB->hide(); //the property doesn't work atm +} + +//Code from kcontrol/background/bgdialog.cpp +void KChartBackgroundPixmapConfigPage::loadWallpaperFilesList() +{ + // Wallpapers + // the following TQMap is lower cased names mapped to cased names and URLs + // this way we get case insensitive sorting + TQMap > papers; + + //search for .desktop files before searching for images without .desktop files + TQStringList lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*desktop", false, true); + TQStringList files; + for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) + { + KSimpleConfig fileConfig(*it); + fileConfig.setGroup("Wallpaper"); + + TQString imageCaption = fileConfig.readEntry("Name"); + TQString fileName = fileConfig.readEntry("File"); + + if (imageCaption.isEmpty()) + { + imageCaption = fileName; + imageCaption.replace('_', ' '); + imageCaption = KStringHandler::capwords(imageCaption); + } + + // avoid name collisions + TQString rs = imageCaption; + TQString lrs = rs.lower(); + for (int n = 1; papers.find(lrs) != papers.end(); ++n) + { + rs = imageCaption + " (" + TQString::number(n) + ')'; + lrs = rs.lower(); + } + int slash = (*it).findRev('/') + 1; + TQString directory = (*it).left(slash); + bool canLoadScaleable = false; +#ifdef HAVE_LIBART + canLoadScaleable = true; +#endif + if ( fileConfig.readEntry("ImageType") == "pixmap" || canLoadScaleable ) { + papers[lrs] = tqMakePair(rs, directory + fileName); + files.append(directory + fileName); + } + } + + //now find any wallpapers that don't have a .desktop file + lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*", false, true); + for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) + { + if ( !(*it).endsWith(".desktop") && files.grep(*it).empty() ) { + // First try to see if we have a comment describing the image. If we do + // just use the first line of said comment. + KFileMetaInfo metaInfo(*it); + TQString imageCaption; + + if (metaInfo.isValid() && metaInfo.item("Comment").isValid()) + imageCaption = metaInfo.item("Comment").string().section('\n', 0, 0); + + if (imageCaption.isEmpty()) + { + int slash = (*it).findRev('/') + 1; + int endDot = (*it).findRev('.'); + + // strip the extension if it exists + if (endDot != -1 && endDot > slash) + imageCaption = (*it).mid(slash, endDot - slash); + else + imageCaption = (*it).mid(slash); + + imageCaption.replace('_', ' '); + imageCaption = KStringHandler::capwords(imageCaption); + } + + // avoid name collisions + TQString rs = imageCaption; + TQString lrs = rs.lower(); + for (int n = 1; papers.find(lrs) != papers.end(); ++n) + { + rs = imageCaption + " (" + TQString::number(n) + ')'; + lrs = rs.lower(); + } + papers[lrs] = tqMakePair(rs, *it); + } + } + + m_wallpaper.clear(); + //don't start to 0, we have None element + int i = 1; + for (TQMap >::Iterator it = papers.begin(); + it != papers.end(); + ++it) + { + wallCB->insertItem(it.data().first); + m_wallpaper[it.data().second] = i; + i++; + } +} + +void KChartBackgroundPixmapConfigPage::init() +{ +#if 0 + TQStringList lst; + lst.append(i18n( "Outermost Region" )); + lst.append(i18n( "Innermost Region" )); + lst.append(i18n( "Header+Title+Subtitle" )); + lst.append(i18n( "Footers" )); + lst.append(i18n( "Data+Axes+Legend" )); + lst.append(i18n( "Data+Axes" )); + lst.append(i18n( "Data" )); + lst.append(i18n( "Legend" )); + lst.append(i18n( "Left Axis" )); + lst.append(i18n( "Bottom Axis" )); + lst.append(i18n( "Right Axis" )); + lst.append(i18n( "Header A" )); + lst.append(i18n( "Header B" )); + lst.append(i18n( "Header C" )); + lst.append(i18n( "Title A" )); + lst.append(i18n( "Title B" )); + lst.append(i18n( "Title C" )); + lst.append(i18n( "Subtitle A" )); + lst.append(i18n( "Subtitle B" )); + lst.append(i18n( "Subtitle C" )); + lst.append(i18n( "Footer 1 A" )); + lst.append(i18n( "Footer 1 B" )); + lst.append(i18n( "Footer 1 C" )); + lst.append(i18n( "Footer 2 A" )); + lst.append(i18n( "Footer 2 B" )); + lst.append(i18n( "Footer 2 C" )); + lst.append(i18n( "Footer 3 A" )); + lst.append(i18n( "Footer 3 B" )); + lst.append(i18n( "Footer 3 C" )); + regionList->insertStringList(lst); +#endif + // PENDING(kalle) Readapt + // showSettings( _params->backgroundPixmapName ); +// intensitySB->setValue( (int)(_params->backgroundPixmapIntensity * 100.0) ); +// scaledCB->setChecked( _params->backgroundPixmapScaled ); +// centeredCB->setChecked( _params->backgroundPixmapCentered ); + + bool bFound; + const KDChartParams::KDChartFrameSettings * innerFrame = + _params->frameSettings( KDChartEnums::AreaInnermost, bFound ); + if( bFound ) + { + const TQPixmap* backPixmap; + bool isTiledMode = false; + KDFrame::BackPixmapMode backPixmapMode; + const TQBrush& background = innerFrame->frame().background( backPixmap, backPixmapMode ); + const TQColor backColor( background.color() ); + + // Bg color has to be be set in any case, + // even when a (tiled) pixmap is specified: + _backgroundCB->setColor( backColor ); + + + if( !backPixmap || backPixmap->isNull() ) + { + // A pixmap can be in the brush, if used as Tile. + backPixmap = background.pixmap(); + if( backPixmap ) + isTiledMode = true; + } + + if( !backPixmap || backPixmap->isNull() ) //color as background + { + right->setEnabled( false ); + wallCB->setCurrentItem( 0 ); + } + else //pixmap as background + { + _backgroundCB->setEnabled( false ); + wallWidget->setPaletteBackgroundPixmap( *backPixmap ); + wallCB->setCurrentItem( 1 ); + if( isTiledMode ) + { + tiledRB->setChecked( true ); + } + else + { + switch( backPixmapMode ){ + case KDFrame::PixCentered: + centeredRB->setChecked( true ); + break; + case KDFrame::PixScaled: + scaledRB->setChecked( true ); + break; + default: + stretchedRB->setChecked( true ); + } + } + } + } + else + _backgroundCB->setColor(TQColor(230, 222, 222) ); +} + +void KChartBackgroundPixmapConfigPage::apply() +{ + // PENDING(kalle) Readapt + // if( wallCB->currentText() != _params->backgroundPixmapName ) { +// bool load=true; +// if(wallCB->currentText()==i18n("None")) { +// load=false; +// } else { +// _params->backgroundPixmapName = wallCB->currentText(); +// bool load=_params->backgroundPixmap.load( locate( "wallpaper", _params->backgroundPixmapName ) ); +// if(load) +// _params->backgroundPixmapIsDirty = true; +// } + +// if( !load ) { +// _params->backgroundPixmapName = ""; +// _params->backgroundPixmap=TQPixmap(""); +// _params->backgroundPixmapIsDirty = false; +// } +// } +// if( (int)(_params->backgroundPixmapIntensity * 100.0) != +// intensitySB->value() ) { +// _params->backgroundPixmapIntensity = (float)(intensitySB->value()) / 100.0; +// _params->backgroundPixmapIsDirty = true; +// } + +// if( _params->backgroundPixmapScaled != +// scaledCB->isChecked() ) { +// _params->backgroundPixmapScaled = scaledCB->isChecked(); +// _params->backgroundPixmapIsDirty = true; +// } +// if( _params->backgroundPixmapCentered != +// centeredCB->isChecked() ) { +// _params->backgroundPixmapCentered = centeredCB->isChecked(); +// _params->backgroundPixmapIsDirty = true; +// } + + // + // temp. hack: the background is removed if "None" is selected in the combo box + // + // For KOffice 1.5/2.0 this is to be removed by a checkbox. + bool bFound; + const KDChartParams::KDChartFrameSettings * innerFrame = + _params->frameSettings( KDChartEnums::AreaInnermost, bFound ); + if( bFound ) + { + const TQColor backColor( _backgroundCB->color() ); + KDFrame& frame( const_cast(innerFrame->frame()) ); + if ( wallCB->currentItem() == 0 ) + { + frame.setBackPixmap( 0 ); + frame.setBackground( backColor ); + } + else + { + const TQPixmap* pixmap = wallWidget->paletteBackgroundPixmap(); + if ( tiledRB->isChecked() ){ + // We remove the frame's extra pixmap, + frame.setBackPixmap( 0 ); + // because a tiled image is set via a TQBrush. + if( pixmap ) + frame.setBackground( TQBrush( backColor, *pixmap ) ); + else + frame.setBackground( backColor ); + }else{ + KDFrame::BackPixmapMode backPixmapMode; + if ( centeredRB->isChecked() ) + backPixmapMode = KDFrame::PixCentered; + else if ( scaledRB->isChecked() ) + backPixmapMode = KDFrame::PixScaled; + else + backPixmapMode = KDFrame::PixStretched; + // We reset the background color, removing any tiled brush, + frame.setBackground( backColor ); + // because we specify an extra pixmap instead. + frame.setBackPixmap( pixmap, backPixmapMode ); + } + } + } +} + + +void KChartBackgroundPixmapConfigPage::showSettings( const TQString& fileName ) +{ + wallCB->blockSignals(true); + + if (m_wallpaper.find(fileName) == m_wallpaper.end()) + { + int i = wallCB->count(); + TQString imageCaption; + int slash = fileName.findRev('/') + 1; + int endDot = fileName.findRev('.'); + + // strip the extension if it exists + if (endDot != -1 && endDot > slash) + imageCaption = fileName.mid(slash, endDot - slash); + else + imageCaption = fileName.mid(slash); + if (wallCB->text(i-1) == imageCaption) + { + i--; + wallCB->removeItem(i); + } + wallCB->insertItem(imageCaption); + m_wallpaper[fileName] = i; + wallCB->setCurrentItem(i); + } + else + { + wallCB->setCurrentItem(m_wallpaper[fileName]); + } + wallCB->blockSignals(false); + loadWallPaper(); +} + + +void KChartBackgroundPixmapConfigPage::slotBrowse() +{ + //TODO: Support non-local wallpapers + KURL url = KFileDialog::getOpenFileName( 0 ); + if( url.isEmpty() ) + return; + showSettings( url.path() ); +} + +void KChartBackgroundPixmapConfigPage::slotWallPaperChanged( int index ) +{ + if ( index != 0 && loadWallPaper() ) + { + _backgroundCB->setEnabled( false ); + right->setEnabled( true ); + } + else + { + wallWidget->setPaletteBackgroundPixmap( 0 ); + _backgroundCB->setEnabled( true ); + right->setEnabled( false ); + } +} + + +bool KChartBackgroundPixmapConfigPage::loadWallPaper() +{ + int i = wallCB->currentItem(); + if ( i == -1 || i == 0 ) { // 0 is 'None' + wallPixmap.resize(0,0); + wallFile = ""; + } else { + for(TQMap::ConstIterator it = m_wallpaper.begin(); + it != m_wallpaper.end(); + ++it) + { + if (it.data() == i) + { + wallFile = it.key(); + break; + } + } + TQString file = locate("wallpaper", wallFile); + if( file.isEmpty() ) { + kdWarning(35001) << "Couldn't locate wallpaper " << wallFile << endl; + wallPixmap.resize(0,0); + wallFile = ""; + return false; + } else { + wallPixmap.load( file ); + + if( wallPixmap.isNull() ) + return false; +// kdWarning(35001) << "Could not load wallpaper " << file << endl; + } + } + wallWidget->setPaletteBackgroundPixmap( wallPixmap ); + return true; +} + +} //KChart namespace diff --git a/kchart/kchartColorConfigPage.cc b/kchart/kchartColorConfigPage.cc deleted file mode 100644 index 921b42c4..00000000 --- a/kchart/kchartColorConfigPage.cc +++ /dev/null @@ -1,220 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999 Matthias Kalle Dalheimer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartColorConfigPage.h" -#include "kchartColorConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "kchart_params.h" -#include - -namespace KChart -{ - -KChartColorConfigPage::KChartColorConfigPage( KChartParams* params, - TQWidget* parent, - KDChartTableData *dat ) : - TQWidget( parent ), - m_params( params ), - m_data( dat ), - index( 0 ) -{ - TQWhatsThis::add( this, i18n( "This page lets you configure the colors " - "in which your chart is displayed. Each " - "part of the chart can be assigned a " - "different color." ) ); - - TQVBoxLayout* toplevel = new TQVBoxLayout( this, 14 ); - TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Colors"), this ); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - toplevel->addWidget( gb); - TQString wtstr; - TQGridLayout* grid = new TQGridLayout( gb->layout(), 8, 3 ); - - const int labelAlign = AlignRight | AlignVCenter; - int row = -1; -#define ADD_COLOR_BTN(btn,title,whatsthis) \ -{ \ - ++row; \ - TQLabel* l = new TQLabel( title, gb ); \ - l->setAlignment( labelAlign ); \ - grid->addWidget( l, row, 0 ); \ - btn = new KColorButton( gb ); \ - l->setBuddy( btn ); \ - grid->addWidget( btn, row, 1 ); \ - TQWhatsThis::add( l, whatsthis ); \ - TQWhatsThis::add( btn, whatsthis ); \ -} - ADD_COLOR_BTN(_lineCB, i18n( "&Line color:" ), - i18n( "This is the color that is used for drawing lines like axes." )) - ADD_COLOR_BTN(_gridCB, i18n( "&Grid color:" ), - i18n( "Here you can configure the color that is used for the " - "chart grid. Of course, this setting will only " - "take effect if grid drawing is turned on." )) - ADD_COLOR_BTN(_xtitleCB, i18n( "&X-title color:" ), - i18n( "This color is used for displaying titles for the " - "X (horizontal) axis." )) - ADD_COLOR_BTN(_ytitleCB, i18n( "&Y-title color:" ), - i18n( "This color is used for displaying titles for the " - "Y (vertical) axis." )) -#if 0 - ADD_COLOR_BTN(_ytitle2CB, i18n( "Y-title color (2nd axis):" ), - i18n( "This color is used for displaying titles for the " - "second Y (vertical) axis. It only takes effect if the " - "chart is configured to have a second Y axis." )) -#endif - ADD_COLOR_BTN(_xlabelCB, i18n( "X-label color:" ), - i18n( "Here you can configure the color that is used for " - "labeling the X (horizontal) axis" )) - ADD_COLOR_BTN(_ylabelCB, i18n( "Y-label color:" ), - i18n( "Here you can configure the color that is used for " - "labeling the Y (vertical) axis" )) -#if 0 - ADD_COLOR_BTN(_ylabel2CB, i18n( "Y-label color (2nd axis):" ), - i18n( "Here you can configure the color that is used for " - "labeling the second Y (vertical) axis. Of course, " - "this setting only takes effect if the chart is " - "configured to have two vertical axes." )) -#endif - ADD_COLOR_BTN(_xlineCB, i18n( "X-line color:" ), - i18n( "Here you can configure the line color of the X (horizontal) axis" )) - ADD_COLOR_BTN(_ylineCB, i18n( "Y-line color:" ), - i18n( "Here you can configure the line color of the Y (vertical) axis" )) -#if 0 - ADD_COLOR_BTN(_yline2CB, i18n( "Y-line color (2nd axis):" ), - i18n( "Here you can configure the line color of " - "the second Y (vertical) axis. Of course, " - "this setting only takes effect if the chart is " - "configured to have two vertical axes." )) -#endif - ADD_COLOR_BTN(_xzerolineCB, i18n( "X-Zero-line color:" ), - i18n( "Here you can configure the zero-line's color of the X " - "(horizontal) axis. Of course, this setting only takes " - "effect if the abscissa is displaying a Zero-line." )) - ADD_COLOR_BTN(_yzerolineCB, i18n( "Y-Zero-line color:" ), - i18n( "Here you can configure the zero-line's color of the Y (vertical) axis" )) -#if 0 - ADD_COLOR_BTN(_yzeroline2CB, i18n( "Y-Zero-line color (2nd axis):" ), - i18n( "Here you can configure the color that is used for " - "the Zero-line of the second Y (vertical) axis. Of course, " - "this setting only takes effect if the chart is " - "configured to have two vertical axes." )) -#endif - - TQHBox* dataColorHB = new TQHBox( gb ); - grid->addMultiCellWidget( dataColorHB, 0, row, 2, 2 ); - _dataColorLB = new TDEListBox(dataColorHB); - _dataColorCB = new KColorButton( dataColorHB); - wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button."); - TQWhatsThis::add( _dataColorCB, wtstr ); - initDataColorList(); - connect( _dataColorLB, TQT_SIGNAL(highlighted(int )), this, TQT_SLOT(changeIndex(int))); - connect( _dataColorLB, TQT_SIGNAL(doubleClicked ( TQListBoxItem * )), this, TQT_SLOT(activeColorButton())); - - - - /*TQLabel* edgeLA = new TQLabel( i18n( "Edge color (pies only)" ), this ); - edgeLA->setAlignment( AlignRight | AlignVCenter ); - grid->addWidget( edgeLA, 6, 0 ); - _edgeCB = new KColorButton( this ); - grid->addWidget( _edgeCB, 6, 1 );*/ - -// for( int i = 0; i < NUMDATACOLORS; i++ ) { -// TQString labeltext; -// labeltext.sprintf( i18n( "Data color #%d:"), i ); -// TQLabel* dataLA = new TQLabel( labeltext, this ); -// dataLA->setAlignment(AlignRight | AlignVCenter); -// dataLA->resize( dataLA->sizeHint() ); -// grid->addWidget( dataLA, i, 2 ); -// _dataCB[i] = new KColorButton( this ); -// _dataCB[i]->resize( _dataCB[i]->sizeHint() ); -// grid->addWidget( _dataCB[i], i, 3 ); -// grid->addRowSpacing(i,_textCB->height()); -// grid->setRowStretch(i,0); -// grid->addColSpacing(2,dataLA->width() + 20); -// } -} - - -void KChartColorConfigPage::changeIndex(int newindex) -{ - if(index > m_params->maxDataColor()) - _dataColorLB->setEnabled(false); - else - { - if(!_dataColorCB->isEnabled()) - _dataColorCB->setEnabled(true); - extColor[index] = _dataColorCB->color(); - _dataColorCB->setColor(extColor[newindex]); - index=newindex; - } -} - - -void KChartColorConfigPage::activeColorButton() -{ - _dataColorCB->animateClick(); -} - - -void KChartColorConfigPage::initDataColorList() -{ - TQStringList lst; - for(uint i = 0; i < m_data->rows(); i++) - { - extColor.resize( m_params->maxDataColor() ); - if(imaxDataColor()) - { - _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) ); - extColor[i] =m_params->dataColor(i); - } - } - _dataColorLB->setCurrentItem(0); - - //Fix crash when we didn't create data - if ( m_data->rows() == 0 ) - _dataColorCB->setEnabled(false); - else - _dataColorCB->setColor( extColor[index]); -} - - -void KChartColorConfigPage::apply() -{ - //Nothing to save - if ( m_data->rows() == 0 ) - return; - - extColor[index] = _dataColorCB->color(); - for(uint i =0;irows();i++) - if(imaxDataColor()) - m_params->setDataColor(i,extColor[i]); -} - -} //KChart namespace diff --git a/kchart/kchartColorConfigPage.cpp b/kchart/kchartColorConfigPage.cpp new file mode 100644 index 00000000..921b42c4 --- /dev/null +++ b/kchart/kchartColorConfigPage.cpp @@ -0,0 +1,220 @@ +/* This file is part of the KDE project + Copyright (C) 1999 Matthias Kalle Dalheimer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartColorConfigPage.h" +#include "kchartColorConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kchart_params.h" +#include + +namespace KChart +{ + +KChartColorConfigPage::KChartColorConfigPage( KChartParams* params, + TQWidget* parent, + KDChartTableData *dat ) : + TQWidget( parent ), + m_params( params ), + m_data( dat ), + index( 0 ) +{ + TQWhatsThis::add( this, i18n( "This page lets you configure the colors " + "in which your chart is displayed. Each " + "part of the chart can be assigned a " + "different color." ) ); + + TQVBoxLayout* toplevel = new TQVBoxLayout( this, 14 ); + TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Colors"), this ); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + toplevel->addWidget( gb); + TQString wtstr; + TQGridLayout* grid = new TQGridLayout( gb->layout(), 8, 3 ); + + const int labelAlign = AlignRight | AlignVCenter; + int row = -1; +#define ADD_COLOR_BTN(btn,title,whatsthis) \ +{ \ + ++row; \ + TQLabel* l = new TQLabel( title, gb ); \ + l->setAlignment( labelAlign ); \ + grid->addWidget( l, row, 0 ); \ + btn = new KColorButton( gb ); \ + l->setBuddy( btn ); \ + grid->addWidget( btn, row, 1 ); \ + TQWhatsThis::add( l, whatsthis ); \ + TQWhatsThis::add( btn, whatsthis ); \ +} + ADD_COLOR_BTN(_lineCB, i18n( "&Line color:" ), + i18n( "This is the color that is used for drawing lines like axes." )) + ADD_COLOR_BTN(_gridCB, i18n( "&Grid color:" ), + i18n( "Here you can configure the color that is used for the " + "chart grid. Of course, this setting will only " + "take effect if grid drawing is turned on." )) + ADD_COLOR_BTN(_xtitleCB, i18n( "&X-title color:" ), + i18n( "This color is used for displaying titles for the " + "X (horizontal) axis." )) + ADD_COLOR_BTN(_ytitleCB, i18n( "&Y-title color:" ), + i18n( "This color is used for displaying titles for the " + "Y (vertical) axis." )) +#if 0 + ADD_COLOR_BTN(_ytitle2CB, i18n( "Y-title color (2nd axis):" ), + i18n( "This color is used for displaying titles for the " + "second Y (vertical) axis. It only takes effect if the " + "chart is configured to have a second Y axis." )) +#endif + ADD_COLOR_BTN(_xlabelCB, i18n( "X-label color:" ), + i18n( "Here you can configure the color that is used for " + "labeling the X (horizontal) axis" )) + ADD_COLOR_BTN(_ylabelCB, i18n( "Y-label color:" ), + i18n( "Here you can configure the color that is used for " + "labeling the Y (vertical) axis" )) +#if 0 + ADD_COLOR_BTN(_ylabel2CB, i18n( "Y-label color (2nd axis):" ), + i18n( "Here you can configure the color that is used for " + "labeling the second Y (vertical) axis. Of course, " + "this setting only takes effect if the chart is " + "configured to have two vertical axes." )) +#endif + ADD_COLOR_BTN(_xlineCB, i18n( "X-line color:" ), + i18n( "Here you can configure the line color of the X (horizontal) axis" )) + ADD_COLOR_BTN(_ylineCB, i18n( "Y-line color:" ), + i18n( "Here you can configure the line color of the Y (vertical) axis" )) +#if 0 + ADD_COLOR_BTN(_yline2CB, i18n( "Y-line color (2nd axis):" ), + i18n( "Here you can configure the line color of " + "the second Y (vertical) axis. Of course, " + "this setting only takes effect if the chart is " + "configured to have two vertical axes." )) +#endif + ADD_COLOR_BTN(_xzerolineCB, i18n( "X-Zero-line color:" ), + i18n( "Here you can configure the zero-line's color of the X " + "(horizontal) axis. Of course, this setting only takes " + "effect if the abscissa is displaying a Zero-line." )) + ADD_COLOR_BTN(_yzerolineCB, i18n( "Y-Zero-line color:" ), + i18n( "Here you can configure the zero-line's color of the Y (vertical) axis" )) +#if 0 + ADD_COLOR_BTN(_yzeroline2CB, i18n( "Y-Zero-line color (2nd axis):" ), + i18n( "Here you can configure the color that is used for " + "the Zero-line of the second Y (vertical) axis. Of course, " + "this setting only takes effect if the chart is " + "configured to have two vertical axes." )) +#endif + + TQHBox* dataColorHB = new TQHBox( gb ); + grid->addMultiCellWidget( dataColorHB, 0, row, 2, 2 ); + _dataColorLB = new TDEListBox(dataColorHB); + _dataColorCB = new KColorButton( dataColorHB); + wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button."); + TQWhatsThis::add( _dataColorCB, wtstr ); + initDataColorList(); + connect( _dataColorLB, TQT_SIGNAL(highlighted(int )), this, TQT_SLOT(changeIndex(int))); + connect( _dataColorLB, TQT_SIGNAL(doubleClicked ( TQListBoxItem * )), this, TQT_SLOT(activeColorButton())); + + + + /*TQLabel* edgeLA = new TQLabel( i18n( "Edge color (pies only)" ), this ); + edgeLA->setAlignment( AlignRight | AlignVCenter ); + grid->addWidget( edgeLA, 6, 0 ); + _edgeCB = new KColorButton( this ); + grid->addWidget( _edgeCB, 6, 1 );*/ + +// for( int i = 0; i < NUMDATACOLORS; i++ ) { +// TQString labeltext; +// labeltext.sprintf( i18n( "Data color #%d:"), i ); +// TQLabel* dataLA = new TQLabel( labeltext, this ); +// dataLA->setAlignment(AlignRight | AlignVCenter); +// dataLA->resize( dataLA->sizeHint() ); +// grid->addWidget( dataLA, i, 2 ); +// _dataCB[i] = new KColorButton( this ); +// _dataCB[i]->resize( _dataCB[i]->sizeHint() ); +// grid->addWidget( _dataCB[i], i, 3 ); +// grid->addRowSpacing(i,_textCB->height()); +// grid->setRowStretch(i,0); +// grid->addColSpacing(2,dataLA->width() + 20); +// } +} + + +void KChartColorConfigPage::changeIndex(int newindex) +{ + if(index > m_params->maxDataColor()) + _dataColorLB->setEnabled(false); + else + { + if(!_dataColorCB->isEnabled()) + _dataColorCB->setEnabled(true); + extColor[index] = _dataColorCB->color(); + _dataColorCB->setColor(extColor[newindex]); + index=newindex; + } +} + + +void KChartColorConfigPage::activeColorButton() +{ + _dataColorCB->animateClick(); +} + + +void KChartColorConfigPage::initDataColorList() +{ + TQStringList lst; + for(uint i = 0; i < m_data->rows(); i++) + { + extColor.resize( m_params->maxDataColor() ); + if(imaxDataColor()) + { + _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) ); + extColor[i] =m_params->dataColor(i); + } + } + _dataColorLB->setCurrentItem(0); + + //Fix crash when we didn't create data + if ( m_data->rows() == 0 ) + _dataColorCB->setEnabled(false); + else + _dataColorCB->setColor( extColor[index]); +} + + +void KChartColorConfigPage::apply() +{ + //Nothing to save + if ( m_data->rows() == 0 ) + return; + + extColor[index] = _dataColorCB->color(); + for(uint i =0;irows();i++) + if(imaxDataColor()) + m_params->setDataColor(i,extColor[i]); +} + +} //KChart namespace diff --git a/kchart/kchartComboConfigPage.cc b/kchart/kchartComboConfigPage.cc deleted file mode 100644 index dcf99e4a..00000000 --- a/kchart/kchartComboConfigPage.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartComboConfigPage.h" -#include "kchartComboConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartComboPage::KChartComboPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - //TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 ); - - TQGridLayout* layout = new TQGridLayout(this, 2, 2,KDialog::marginHint(), KDialog::spacingHint() ); - //toplevel->addLayout( layout ); - TQButtonGroup* gb = new TQButtonGroup( i18n("HLC Style"), this ); - TQGridLayout *grid1 = new TQGridLayout(gb,7,1,KDialog::marginHint(), KDialog::spacingHint()); - layout->addWidget(gb,0,0); - - diamond=new TQRadioButton( i18n("Diamond"), gb ); ; - grid1->addWidget(diamond,0,0); - closeconnected=new TQRadioButton( i18n("Close connected"), gb ); - grid1->addWidget(closeconnected,1,0); - connecting=new TQRadioButton( i18n("Connecting"), gb ); - grid1->addWidget(connecting,2,0); - icap=new TQRadioButton( i18n("Icap"), gb ); - grid1->addWidget(icap,3,0); - gb->setAlignment(TQt::AlignLeft); - grid1->addColSpacing(0,diamond->width()); - grid1->addColSpacing(0,closeconnected->width()); - grid1->addColSpacing(0,connecting->width()); - grid1->addColSpacing(0,icap->width()); - grid1->setColStretch(0,1); - grid1->activate(); - //it's not good but I don't know how - //to reduce space - layout->addColSpacing(1,300); -} - -void KChartComboPage::init() -{ - tqDebug( "Sorry, not implemented: KChartComboPage::init()" ); -#ifdef __GNUC__ -#warning Put back in -#endif -#ifdef K - switch((int)_params->hlc_style) - { - case (int)KCHARTHLCSTYLE_DIAMOND: - { - diamond->setChecked(true); - break; - } - case (int)KCHARTHLCSTYLE_CLOSECONNECTED: - { - closeconnected->setChecked(true); - break; - } - case (int)KCHARTHLCSTYLE_CONNECTING: - { - connecting->setChecked(true); - break; - } - case (int)KCHARTHLCSTYLE_ICAP: - { - icap->setChecked(true); - break; - } - default: - { - kdDebug(35001)<<"Error in hlc_style\n"; - break; - } - } -#endif -} - -void KChartComboPage::apply() -{ - tqDebug( "Sorry, not implemented: KChartComboPage::apply()" ); -#ifdef __GNUC__ -#warning Put back in -#endif -#ifdef K - if(diamond->isChecked()) - { - _params->hlc_style = KCHARTHLCSTYLE_DIAMOND; - } - else if(closeconnected->isChecked()) - { - _params->hlc_style = KCHARTHLCSTYLE_CLOSECONNECTED; - } - else if(connecting->isChecked()) - { - _params->hlc_style = KCHARTHLCSTYLE_CONNECTING; - } - else if(icap->isChecked()) - { - _params->hlc_style = KCHARTHLCSTYLE_ICAP; - } - else - { - kdDebug(35001)<<"Error in groupbutton\n"; - } -#endif -} - -} //KChart namespace diff --git a/kchart/kchartComboConfigPage.cpp b/kchart/kchartComboConfigPage.cpp new file mode 100644 index 00000000..dcf99e4a --- /dev/null +++ b/kchart/kchartComboConfigPage.cpp @@ -0,0 +1,137 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartComboConfigPage.h" +#include "kchartComboConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartComboPage::KChartComboPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + //TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 ); + + TQGridLayout* layout = new TQGridLayout(this, 2, 2,KDialog::marginHint(), KDialog::spacingHint() ); + //toplevel->addLayout( layout ); + TQButtonGroup* gb = new TQButtonGroup( i18n("HLC Style"), this ); + TQGridLayout *grid1 = new TQGridLayout(gb,7,1,KDialog::marginHint(), KDialog::spacingHint()); + layout->addWidget(gb,0,0); + + diamond=new TQRadioButton( i18n("Diamond"), gb ); ; + grid1->addWidget(diamond,0,0); + closeconnected=new TQRadioButton( i18n("Close connected"), gb ); + grid1->addWidget(closeconnected,1,0); + connecting=new TQRadioButton( i18n("Connecting"), gb ); + grid1->addWidget(connecting,2,0); + icap=new TQRadioButton( i18n("Icap"), gb ); + grid1->addWidget(icap,3,0); + gb->setAlignment(TQt::AlignLeft); + grid1->addColSpacing(0,diamond->width()); + grid1->addColSpacing(0,closeconnected->width()); + grid1->addColSpacing(0,connecting->width()); + grid1->addColSpacing(0,icap->width()); + grid1->setColStretch(0,1); + grid1->activate(); + //it's not good but I don't know how + //to reduce space + layout->addColSpacing(1,300); +} + +void KChartComboPage::init() +{ + tqDebug( "Sorry, not implemented: KChartComboPage::init()" ); +#ifdef __GNUC__ +#warning Put back in +#endif +#ifdef K + switch((int)_params->hlc_style) + { + case (int)KCHARTHLCSTYLE_DIAMOND: + { + diamond->setChecked(true); + break; + } + case (int)KCHARTHLCSTYLE_CLOSECONNECTED: + { + closeconnected->setChecked(true); + break; + } + case (int)KCHARTHLCSTYLE_CONNECTING: + { + connecting->setChecked(true); + break; + } + case (int)KCHARTHLCSTYLE_ICAP: + { + icap->setChecked(true); + break; + } + default: + { + kdDebug(35001)<<"Error in hlc_style\n"; + break; + } + } +#endif +} + +void KChartComboPage::apply() +{ + tqDebug( "Sorry, not implemented: KChartComboPage::apply()" ); +#ifdef __GNUC__ +#warning Put back in +#endif +#ifdef K + if(diamond->isChecked()) + { + _params->hlc_style = KCHARTHLCSTYLE_DIAMOND; + } + else if(closeconnected->isChecked()) + { + _params->hlc_style = KCHARTHLCSTYLE_CLOSECONNECTED; + } + else if(connecting->isChecked()) + { + _params->hlc_style = KCHARTHLCSTYLE_CONNECTING; + } + else if(icap->isChecked()) + { + _params->hlc_style = KCHARTHLCSTYLE_ICAP; + } + else + { + kdDebug(35001)<<"Error in groupbutton\n"; + } +#endif +} + +} //KChart namespace diff --git a/kchart/kchartConfigDialog.cc b/kchart/kchartConfigDialog.cc deleted file mode 100644 index f0f57d62..00000000 --- a/kchart/kchartConfigDialog.cc +++ /dev/null @@ -1,438 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999,2000 Matthias Kalle Dalheimer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - - -#include "kchartConfigDialog.h" -#include "kchartConfigDialog.moc" - - -#include "kchartBackgroundPixmapConfigPage.h" -#include "kchartSubTypeChartPage.h" -#include "kchartHeaderFooterConfigPage.h" -#include "kchartColorConfigPage.h" -#include "kchartParameterPieConfigPage.h" -#include "kchartFontConfigPage.h" -#include "kchartDataConfigPage.h" -#include "kchartComboConfigPage.h" -#include "kchartParameterConfigPage.h" -#include "kchartPieConfigPage.h" -#include "kchartParameter3dConfigPage.h" -#include "kchartLegendConfigPage.h" -#include "kchartLine3dConfigPage.h" -#include "kchartParameterPolarConfigPage.h" - -#include -#include -#include - -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartConfigDialog::KChartConfigDialog( KChartParams* params, - TQWidget* parent, int flags, - KDChartTableData *dat ) : - TQTabDialog( parent, "Chart config dialog", true ), - m_params( params ), - - m_dataPage(0), - m_subTypePage(0), - - _parameter3dpage(0), - _linepage3d(0), - _parameterpiepage(0), - _polarpage(0), - - m_headerfooterpage(0), - m_legendPage(0), - m_axespage(0), - - _colorpage(0), - _parameterfontpage(0), - _backgroundpixpage(0) - //_piepage(0), -{ - // Geometry page - //_geompage = new KChartGeometryConfigPage( this ); - //addTab( _geompage, i18n( "&Geometry" ) ); - setCaption( i18n( "Chart Setup" ) ); - - if (flags & KC_DATAFORMAT) { - m_dataPage = new KChartDataConfigPage(m_params, this, dat); - addTab( m_dataPage, i18n( "&Data" ) ); - } - else if (flags & KC_SUBTYPE) { - subtypePage(); - } - else if (flags & KC_HEADERFOOTER) { - m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params,this); - addTab( m_headerfooterpage,i18n("Header/Footer")); - } - else if (flags & KC_COLORS ) { - _colorpage = new KChartColorConfigPage( m_params, this, dat ); - addTab( _colorpage, i18n( "&Colors" ) ); - } - else if ( flags & KC_FONT ) { - _parameterfontpage = new KChartFontConfigPage(m_params,this, dat ); - addTab( _parameterfontpage, i18n( "&Font" ) ); - } - else if ( flags & KC_BACK ) { - _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, this ); - addTab( _backgroundpixpage, i18n( "&Background" ) ); - } - else if ( flags & KC_LEGEND ) { - m_legendPage = new KChartLegendConfigPage(m_params,this ); - addTab( m_legendPage,i18n("Legend")); - } - else if ( flags & KC_ALL ) { - // The data page - m_dataPage = new KChartDataConfigPage(m_params, this, dat); - addTab( m_dataPage, i18n( "&Data" ) ); - - // The subtype page - subtypePage(); - - // The subtype configuration page (not for all types). - if ( m_params->chartType() == KChartParams::Bar ) { - _parameter3dpage = new KChartParameter3dConfigPage(m_params,this ); - addTab( _parameter3dpage,i18n("Bar")); - } - else if ( m_params->chartType() == KChartParams::Line) { - _linepage3d= new KChartLine3dConfigPage(m_params,this); - addTab( _linepage3d,i18n("Line")); - } -#if 0 - else if ( m_params->chartType() == KChartParams::BarLines) { - m_barslinesPage = new KChartBarslinesConfigPage(m_params, this); - addTab( _linepage3d,i18n("Line")); - } -#endif - else if ( m_params->chartType() == KChartParams::Pie ) { - - _parameterpiepage = new KChartParameterPieConfigPage(m_params, - this ); - addTab( _parameterpiepage, i18n( "&Pie" ) ); - -#if 0 // Disabled for 1.4. - _piepage = new KChartPieConfigPage(m_params, this, dat ); - addTab( _piepage, i18n( "&Piedata" ) ); -#endif - } - else if ( m_params->chartType() == KChartParams::Polar) { - _polarpage=new KChartParameterPolarConfigPage(m_params,this); - addTab( _polarpage,i18n("&Polar")); - } - - - // The Header/Footer page - m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params, this); - addTab( m_headerfooterpage, i18n("Header/Footer")); - - // The legend page - m_legendPage = new KChartLegendConfigPage(m_params,this ); - addTab( m_legendPage,i18n("Legend")); - - // Add axes page if applicable (all except Pie, Ring). - if ( m_params->chartType() != KChartParams::Pie - && m_params->chartType() != KChartParams::Ring ) { - - m_axespage = new KChartParameterConfigPage(m_params,this ); - addTab( m_axespage, i18n( "&Axes" ) ); - } - - _colorpage = new KChartColorConfigPage( m_params, this, dat ); - addTab( _colorpage, i18n( "&Colors" ) ); - - _parameterfontpage = new KChartFontConfigPage(m_params,this, dat ); - addTab( _parameterfontpage, i18n( "&Font" ) ); - - _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, - this ); - addTab( _backgroundpixpage, i18n( "&Background" ) ); - - if ( m_params->chartType() == KChartParams::HiLo && - ( m_params->hiLoChartSubType() == KChartParams::HiLoClose || - m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) { - // PENDING(kalle) Combo page needs to be redone completely. - // _hlcChart=new KChartComboPage(m_params,this); -// addTab( _hlcChart, i18n( "HLC Chart" ) ); - } - } - - // Get data into the tabs. - init(); - - // Setup main buttons. - setOKButton( i18n( "&OK" ) ); - setApplyButton( i18n( "&Apply" ) ); -#if 0 - setDefaultButton( i18n( "&Defaults" ) ); -#else - setDefaultButton( TQString() ); -#endif - setCancelButton( i18n( "&Cancel" ) ); - - connect( this, TQT_SIGNAL( applyButtonPressed() ), this, TQT_SLOT( apply() ) ); - connect( this, TQT_SIGNAL( defaultButtonPressed() ), this, TQT_SLOT( defaults() ) ); -} - - -void KChartConfigDialog::init() -{ - // Data page - if (m_dataPage) - m_dataPage->init(); - - // Color page - if (_colorpage) { - _colorpage->setLineColor( m_params->outlineDataColor() ); - KDChartAxisParams leftparams; - leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams rightparams; - rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparams; - bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - _colorpage->setGridColor( leftparams.axisGridColor() ); - _colorpage->setXTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosLeft ) ); - _colorpage->setYTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosBottom ) ); -#if 0 - _colorpage->setYTitle2Color( rightparams.axisLineColor() ); -#endif - _colorpage->setXLabelColor( bottomparams.axisLabelsColor() ); - _colorpage->setYLabelColor( leftparams.axisLabelsColor() ); -#if 0 - _colorpage->setYLabel2Color( rightparams.axisLabelsColor() ); -#endif - _colorpage->setXLineColor( bottomparams.axisLineColor() ); - _colorpage->setYLineColor( leftparams.axisLineColor() ); -#if 0 - _colorpage->setYLine2Color( rightparams.axisLineColor() ); -#endif - _colorpage->setXZeroLineColor( bottomparams.axisZeroLineColor() ); - _colorpage->setYZeroLineColor( leftparams.axisZeroLineColor() ); -#if 0 - _colorpage->setYZeroLine2Color( rightparams.axisZeroLineColor() ); -#endif - // PENDING(kalle) Replace with KDChart equivalents - // _colorpage->setBackgroundColor( m_params->BGColor ); - // _colorpage->setPlotColor( m_params->PlotColor ); - // _colorpage->setVolColor( m_params->VolColor ); - //_colorpage->setEdgeColor( m_params->EdgeColor ); - } - - if (m_axespage ) - m_axespage->init(); - -#if 0 - if (_piepage) - _piepage->init(); -#endif - if (_parameterpiepage) - _parameterpiepage->init(); - - if (_parameter3dpage) - _parameter3dpage->init(); - - if ( _linepage3d && m_params->chartType() == KChartParams::Line) - _linepage3d->init(); - - if (_parameterfontpage) - _parameterfontpage->init(); - - if ( m_subTypePage ) - m_subTypePage->init(); - -/* if( _hlcChart) - { - if( m_params->chartType() == KDChartParams::HiLo && - ( m_params->hiLoChartSubType() == KDChartParams::HiLoClose || - m_params->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) ) { - _hlcChart->init(); - } - }*/ - if (_backgroundpixpage) - _backgroundpixpage->init(); - - if (m_legendPage) - m_legendPage->init(); -// for( uint i = 0; i < NUMDATACOLORS; i++ ) -// _colorpage->setDataColor( i, m_params->dataColor( i ) ); - - if (m_headerfooterpage) - m_headerfooterpage->init(); - if (_polarpage) - _polarpage->init(); -} - - -void KChartConfigDialog::apply() -{ - kdDebug(35001) << "***KChartConfig::apply()\n"; - // Copy application data from dialog into parameter structure that is also - // being used by the application. - - // Data page - if (m_dataPage) - m_dataPage->apply(); - - // color page - - // PENDING(kalle) Replace with equivalents - // m_params->BGColor = _colorpage->backgroundColor(); - // m_params->PlotColor = _colorpage->plotColor(); - //m_params->EdgeColor = _colorpage->edgeColor(); - // m_params->VolColor = _colorpage->volColor(); - - if (_colorpage) { - - KDChartAxisParams leftparams; - leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - leftparams.setAxisGridColor( _colorpage->gridColor() ); - m_params->setOutlineDataColor( _colorpage->lineColor() ); - - KDChartAxisParams rightparams; - rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparams; - bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - if( _colorpage->xTitleColor().isValid() ) - m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, _colorpage->xTitleColor() ); - else - m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, TQColor() ); - if( _colorpage->yTitleColor().isValid() ) - m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, _colorpage->yTitleColor() ); - else - m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, TQColor() ); -#if 0 - if( _colorpage->yTitle2Color().isValid() ) - rightparams.setAxisLineColor( _colorpage->yTitle2Color() ); - else - rightparams.setAxisLineColor( TQColor() ); -#endif - - bottomparams.setAxisLabelsColor( _colorpage->xLabelColor() ); - leftparams.setAxisLabelsColor( _colorpage->yLabelColor() ); -#if 0 - rightparams.setAxisLabelsColor( _colorpage->yLabel2Color() ); -#endif - - bottomparams.setAxisLineColor( _colorpage->xLineColor() ); - leftparams.setAxisLineColor( _colorpage->yLineColor() ); -#if 0 - rightparams.setAxisLineColor( _colorpage->yLine2Color() ); -#endif - - bottomparams.setAxisZeroLineColor( _colorpage->xZeroLineColor() ); - leftparams.setAxisZeroLineColor( _colorpage->yZeroLineColor() ); -#if 0 - rightparams.setAxisZeroLineColor( _colorpage->yZeroLine2Color() ); -#endif - m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams ); - m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); -#if 0 - m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparams ); -#endif - } - - if (m_axespage) - m_axespage->apply(); - - if (_parameterpiepage) - _parameterpiepage->apply(); -#if 0 - if (_piepage) - _piepage->apply(); -#endif - if( _parameter3dpage && m_params->chartType() == KChartParams::Bar ) - _parameter3dpage->apply(); - - if( _linepage3d && m_params->chartType() == KChartParams::Line) - _linepage3d->apply(); - - if(_parameterfontpage) - _parameterfontpage->apply(); - - if(_colorpage) - _colorpage->apply(); - - if( m_subTypePage ) - m_subTypePage->apply(); - - if ( m_params->chartType() == KChartParams::HiLo && - ( m_params->hiLoChartSubType() == KChartParams::HiLoClose || - m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) - { - /* if( _hlcChart) - _hlcChart->apply();*/ - } - - if (_backgroundpixpage) - _backgroundpixpage->apply(); - - // for( uint i = 0; i < NUMDATACOLORS; i++ ) - // m_params->_datacolors.setColor( i, _colorpage->dataColor( i ) ); - if (m_legendPage) - m_legendPage->apply(); - - if (m_headerfooterpage) - m_headerfooterpage->apply(); - if (_polarpage) - _polarpage->apply(); - - // Data in the params struct has changed; notify the application. - emit dataChanged(); -} - - -void KChartConfigDialog::subtypePage() -{ - switch( m_params->chartType() ) { - case KDChartParams::Bar: - m_subTypePage = new KChartBarSubTypeChartPage( m_params, this ); - break; - case KDChartParams::Area: - m_subTypePage = new KChartAreaSubTypeChartPage( m_params, this ); - break; - case KDChartParams::Line: - m_subTypePage = new KChartLineSubTypeChartPage( m_params, this ); - break; - case KDChartParams::HiLo: - m_subTypePage = new KChartHiloSubTypeChartPage( m_params, this ); - break; - case KDChartParams::Polar: - m_subTypePage = new KChartPolarSubTypeChartPage( m_params, this ); - break; - default: - // Do nothing. In particular, don't add a page. - return; - ; - } - addTab( m_subTypePage, i18n( "Chart &Sub-type" ) ); -} - - -void KChartConfigDialog::defaults() -{ - //FIXME: NYI -} - - -} //KChart namespace diff --git a/kchart/kchartConfigDialog.cpp b/kchart/kchartConfigDialog.cpp new file mode 100644 index 00000000..f0f57d62 --- /dev/null +++ b/kchart/kchartConfigDialog.cpp @@ -0,0 +1,438 @@ +/* This file is part of the KDE project + Copyright (C) 1999,2000 Matthias Kalle Dalheimer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + + +#include "kchartConfigDialog.h" +#include "kchartConfigDialog.moc" + + +#include "kchartBackgroundPixmapConfigPage.h" +#include "kchartSubTypeChartPage.h" +#include "kchartHeaderFooterConfigPage.h" +#include "kchartColorConfigPage.h" +#include "kchartParameterPieConfigPage.h" +#include "kchartFontConfigPage.h" +#include "kchartDataConfigPage.h" +#include "kchartComboConfigPage.h" +#include "kchartParameterConfigPage.h" +#include "kchartPieConfigPage.h" +#include "kchartParameter3dConfigPage.h" +#include "kchartLegendConfigPage.h" +#include "kchartLine3dConfigPage.h" +#include "kchartParameterPolarConfigPage.h" + +#include +#include +#include + +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartConfigDialog::KChartConfigDialog( KChartParams* params, + TQWidget* parent, int flags, + KDChartTableData *dat ) : + TQTabDialog( parent, "Chart config dialog", true ), + m_params( params ), + + m_dataPage(0), + m_subTypePage(0), + + _parameter3dpage(0), + _linepage3d(0), + _parameterpiepage(0), + _polarpage(0), + + m_headerfooterpage(0), + m_legendPage(0), + m_axespage(0), + + _colorpage(0), + _parameterfontpage(0), + _backgroundpixpage(0) + //_piepage(0), +{ + // Geometry page + //_geompage = new KChartGeometryConfigPage( this ); + //addTab( _geompage, i18n( "&Geometry" ) ); + setCaption( i18n( "Chart Setup" ) ); + + if (flags & KC_DATAFORMAT) { + m_dataPage = new KChartDataConfigPage(m_params, this, dat); + addTab( m_dataPage, i18n( "&Data" ) ); + } + else if (flags & KC_SUBTYPE) { + subtypePage(); + } + else if (flags & KC_HEADERFOOTER) { + m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params,this); + addTab( m_headerfooterpage,i18n("Header/Footer")); + } + else if (flags & KC_COLORS ) { + _colorpage = new KChartColorConfigPage( m_params, this, dat ); + addTab( _colorpage, i18n( "&Colors" ) ); + } + else if ( flags & KC_FONT ) { + _parameterfontpage = new KChartFontConfigPage(m_params,this, dat ); + addTab( _parameterfontpage, i18n( "&Font" ) ); + } + else if ( flags & KC_BACK ) { + _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, this ); + addTab( _backgroundpixpage, i18n( "&Background" ) ); + } + else if ( flags & KC_LEGEND ) { + m_legendPage = new KChartLegendConfigPage(m_params,this ); + addTab( m_legendPage,i18n("Legend")); + } + else if ( flags & KC_ALL ) { + // The data page + m_dataPage = new KChartDataConfigPage(m_params, this, dat); + addTab( m_dataPage, i18n( "&Data" ) ); + + // The subtype page + subtypePage(); + + // The subtype configuration page (not for all types). + if ( m_params->chartType() == KChartParams::Bar ) { + _parameter3dpage = new KChartParameter3dConfigPage(m_params,this ); + addTab( _parameter3dpage,i18n("Bar")); + } + else if ( m_params->chartType() == KChartParams::Line) { + _linepage3d= new KChartLine3dConfigPage(m_params,this); + addTab( _linepage3d,i18n("Line")); + } +#if 0 + else if ( m_params->chartType() == KChartParams::BarLines) { + m_barslinesPage = new KChartBarslinesConfigPage(m_params, this); + addTab( _linepage3d,i18n("Line")); + } +#endif + else if ( m_params->chartType() == KChartParams::Pie ) { + + _parameterpiepage = new KChartParameterPieConfigPage(m_params, + this ); + addTab( _parameterpiepage, i18n( "&Pie" ) ); + +#if 0 // Disabled for 1.4. + _piepage = new KChartPieConfigPage(m_params, this, dat ); + addTab( _piepage, i18n( "&Piedata" ) ); +#endif + } + else if ( m_params->chartType() == KChartParams::Polar) { + _polarpage=new KChartParameterPolarConfigPage(m_params,this); + addTab( _polarpage,i18n("&Polar")); + } + + + // The Header/Footer page + m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params, this); + addTab( m_headerfooterpage, i18n("Header/Footer")); + + // The legend page + m_legendPage = new KChartLegendConfigPage(m_params,this ); + addTab( m_legendPage,i18n("Legend")); + + // Add axes page if applicable (all except Pie, Ring). + if ( m_params->chartType() != KChartParams::Pie + && m_params->chartType() != KChartParams::Ring ) { + + m_axespage = new KChartParameterConfigPage(m_params,this ); + addTab( m_axespage, i18n( "&Axes" ) ); + } + + _colorpage = new KChartColorConfigPage( m_params, this, dat ); + addTab( _colorpage, i18n( "&Colors" ) ); + + _parameterfontpage = new KChartFontConfigPage(m_params,this, dat ); + addTab( _parameterfontpage, i18n( "&Font" ) ); + + _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, + this ); + addTab( _backgroundpixpage, i18n( "&Background" ) ); + + if ( m_params->chartType() == KChartParams::HiLo && + ( m_params->hiLoChartSubType() == KChartParams::HiLoClose || + m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) { + // PENDING(kalle) Combo page needs to be redone completely. + // _hlcChart=new KChartComboPage(m_params,this); +// addTab( _hlcChart, i18n( "HLC Chart" ) ); + } + } + + // Get data into the tabs. + init(); + + // Setup main buttons. + setOKButton( i18n( "&OK" ) ); + setApplyButton( i18n( "&Apply" ) ); +#if 0 + setDefaultButton( i18n( "&Defaults" ) ); +#else + setDefaultButton( TQString() ); +#endif + setCancelButton( i18n( "&Cancel" ) ); + + connect( this, TQT_SIGNAL( applyButtonPressed() ), this, TQT_SLOT( apply() ) ); + connect( this, TQT_SIGNAL( defaultButtonPressed() ), this, TQT_SLOT( defaults() ) ); +} + + +void KChartConfigDialog::init() +{ + // Data page + if (m_dataPage) + m_dataPage->init(); + + // Color page + if (_colorpage) { + _colorpage->setLineColor( m_params->outlineDataColor() ); + KDChartAxisParams leftparams; + leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams rightparams; + rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparams; + bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + _colorpage->setGridColor( leftparams.axisGridColor() ); + _colorpage->setXTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosLeft ) ); + _colorpage->setYTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosBottom ) ); +#if 0 + _colorpage->setYTitle2Color( rightparams.axisLineColor() ); +#endif + _colorpage->setXLabelColor( bottomparams.axisLabelsColor() ); + _colorpage->setYLabelColor( leftparams.axisLabelsColor() ); +#if 0 + _colorpage->setYLabel2Color( rightparams.axisLabelsColor() ); +#endif + _colorpage->setXLineColor( bottomparams.axisLineColor() ); + _colorpage->setYLineColor( leftparams.axisLineColor() ); +#if 0 + _colorpage->setYLine2Color( rightparams.axisLineColor() ); +#endif + _colorpage->setXZeroLineColor( bottomparams.axisZeroLineColor() ); + _colorpage->setYZeroLineColor( leftparams.axisZeroLineColor() ); +#if 0 + _colorpage->setYZeroLine2Color( rightparams.axisZeroLineColor() ); +#endif + // PENDING(kalle) Replace with KDChart equivalents + // _colorpage->setBackgroundColor( m_params->BGColor ); + // _colorpage->setPlotColor( m_params->PlotColor ); + // _colorpage->setVolColor( m_params->VolColor ); + //_colorpage->setEdgeColor( m_params->EdgeColor ); + } + + if (m_axespage ) + m_axespage->init(); + +#if 0 + if (_piepage) + _piepage->init(); +#endif + if (_parameterpiepage) + _parameterpiepage->init(); + + if (_parameter3dpage) + _parameter3dpage->init(); + + if ( _linepage3d && m_params->chartType() == KChartParams::Line) + _linepage3d->init(); + + if (_parameterfontpage) + _parameterfontpage->init(); + + if ( m_subTypePage ) + m_subTypePage->init(); + +/* if( _hlcChart) + { + if( m_params->chartType() == KDChartParams::HiLo && + ( m_params->hiLoChartSubType() == KDChartParams::HiLoClose || + m_params->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) ) { + _hlcChart->init(); + } + }*/ + if (_backgroundpixpage) + _backgroundpixpage->init(); + + if (m_legendPage) + m_legendPage->init(); +// for( uint i = 0; i < NUMDATACOLORS; i++ ) +// _colorpage->setDataColor( i, m_params->dataColor( i ) ); + + if (m_headerfooterpage) + m_headerfooterpage->init(); + if (_polarpage) + _polarpage->init(); +} + + +void KChartConfigDialog::apply() +{ + kdDebug(35001) << "***KChartConfig::apply()\n"; + // Copy application data from dialog into parameter structure that is also + // being used by the application. + + // Data page + if (m_dataPage) + m_dataPage->apply(); + + // color page + + // PENDING(kalle) Replace with equivalents + // m_params->BGColor = _colorpage->backgroundColor(); + // m_params->PlotColor = _colorpage->plotColor(); + //m_params->EdgeColor = _colorpage->edgeColor(); + // m_params->VolColor = _colorpage->volColor(); + + if (_colorpage) { + + KDChartAxisParams leftparams; + leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + leftparams.setAxisGridColor( _colorpage->gridColor() ); + m_params->setOutlineDataColor( _colorpage->lineColor() ); + + KDChartAxisParams rightparams; + rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparams; + bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + if( _colorpage->xTitleColor().isValid() ) + m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, _colorpage->xTitleColor() ); + else + m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, TQColor() ); + if( _colorpage->yTitleColor().isValid() ) + m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, _colorpage->yTitleColor() ); + else + m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, TQColor() ); +#if 0 + if( _colorpage->yTitle2Color().isValid() ) + rightparams.setAxisLineColor( _colorpage->yTitle2Color() ); + else + rightparams.setAxisLineColor( TQColor() ); +#endif + + bottomparams.setAxisLabelsColor( _colorpage->xLabelColor() ); + leftparams.setAxisLabelsColor( _colorpage->yLabelColor() ); +#if 0 + rightparams.setAxisLabelsColor( _colorpage->yLabel2Color() ); +#endif + + bottomparams.setAxisLineColor( _colorpage->xLineColor() ); + leftparams.setAxisLineColor( _colorpage->yLineColor() ); +#if 0 + rightparams.setAxisLineColor( _colorpage->yLine2Color() ); +#endif + + bottomparams.setAxisZeroLineColor( _colorpage->xZeroLineColor() ); + leftparams.setAxisZeroLineColor( _colorpage->yZeroLineColor() ); +#if 0 + rightparams.setAxisZeroLineColor( _colorpage->yZeroLine2Color() ); +#endif + m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams ); + m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); +#if 0 + m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparams ); +#endif + } + + if (m_axespage) + m_axespage->apply(); + + if (_parameterpiepage) + _parameterpiepage->apply(); +#if 0 + if (_piepage) + _piepage->apply(); +#endif + if( _parameter3dpage && m_params->chartType() == KChartParams::Bar ) + _parameter3dpage->apply(); + + if( _linepage3d && m_params->chartType() == KChartParams::Line) + _linepage3d->apply(); + + if(_parameterfontpage) + _parameterfontpage->apply(); + + if(_colorpage) + _colorpage->apply(); + + if( m_subTypePage ) + m_subTypePage->apply(); + + if ( m_params->chartType() == KChartParams::HiLo && + ( m_params->hiLoChartSubType() == KChartParams::HiLoClose || + m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) + { + /* if( _hlcChart) + _hlcChart->apply();*/ + } + + if (_backgroundpixpage) + _backgroundpixpage->apply(); + + // for( uint i = 0; i < NUMDATACOLORS; i++ ) + // m_params->_datacolors.setColor( i, _colorpage->dataColor( i ) ); + if (m_legendPage) + m_legendPage->apply(); + + if (m_headerfooterpage) + m_headerfooterpage->apply(); + if (_polarpage) + _polarpage->apply(); + + // Data in the params struct has changed; notify the application. + emit dataChanged(); +} + + +void KChartConfigDialog::subtypePage() +{ + switch( m_params->chartType() ) { + case KDChartParams::Bar: + m_subTypePage = new KChartBarSubTypeChartPage( m_params, this ); + break; + case KDChartParams::Area: + m_subTypePage = new KChartAreaSubTypeChartPage( m_params, this ); + break; + case KDChartParams::Line: + m_subTypePage = new KChartLineSubTypeChartPage( m_params, this ); + break; + case KDChartParams::HiLo: + m_subTypePage = new KChartHiloSubTypeChartPage( m_params, this ); + break; + case KDChartParams::Polar: + m_subTypePage = new KChartPolarSubTypeChartPage( m_params, this ); + break; + default: + // Do nothing. In particular, don't add a page. + return; + ; + } + addTab( m_subTypePage, i18n( "Chart &Sub-type" ) ); +} + + +void KChartConfigDialog::defaults() +{ + //FIXME: NYI +} + + +} //KChart namespace diff --git a/kchart/kchartDataConfigPage.cc b/kchart/kchartDataConfigPage.cc deleted file mode 100644 index f9cc7e25..00000000 --- a/kchart/kchartDataConfigPage.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartDataConfigPage.h" - -#include "kchartDataConfigPage.moc" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -// For IRIX -namespace std {} - -using namespace std; - -#include "kchart_params.h" -#include "kchart_part.h" - -namespace KChart -{ - -KChartDataConfigPage::KChartDataConfigPage( KChartParams* params, - TQWidget* parent, - KDChartTableData *dat) - : TQWidget( parent ), m_params( params ), data(dat), - m_firstRowAsLabel(0), m_firstColAsLabel(0) -{ - TQGridLayout *grid1 = new TQGridLayout(this, 4, 1, KDialog::marginHint(), - KDialog::spacingHint()); - - // The Data Area - if ( !m_params->part()->canChangeValue() ) { - TQButtonGroup *gb1 = new TQVButtonGroup( i18n( "Data Area" ), this ); - - // ================================================================ - // This code is copied from kchartWizardSelectDataFormatPage.cc - TQHBox *hbox = new TQHBox( gb1 ); - (void) new TQLabel( i18n("Area: "), hbox); - m_dataArea = new TQLineEdit( hbox ); - - // The row/column as label checkboxes. - m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), gb1); - m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), gb1); - - grid1->addWidget(gb1, 0, 0); - } - - // The Data Format button group - TQButtonGroup *gb = new TQVButtonGroup( i18n( "Data Format" ), this ); - - m_rowMajor = new TQRadioButton( i18n( "Data in rows" ), gb ); - m_rowMajor->resize( m_rowMajor->sizeHint() ); - - m_colMajor = new TQRadioButton( i18n( "Data in columns" ), gb ); - m_colMajor->resize( m_colMajor->sizeHint() ); - - grid1->addWidget(gb, 2, 0); - - TQWhatsThis::add(this, i18n("This configuration page can be used to swap the interpretation of rows and columns.")); - TQWhatsThis::add(m_rowMajor, i18n("By default one row is considered to be a data set and each column holds the individual values of the data series. This sets the data in rows on your chart.")); - - TQWhatsThis::add(m_colMajor, i18n("Here you can choose to have each column hold one data set. Note that the values are not really swapped but only their interpretation.")); - m_colMajor->resize( m_colMajor->sizeHint() ); - grid1->addWidget(gb, 1, 0); - grid1->setColStretch(3, 0); - - grid1->activate(); -} - - -void KChartDataConfigPage::init() -{ - if (m_params->dataDirection() == KChartParams::DataRows) - m_rowMajor->setChecked(true); - else - m_colMajor->setChecked(true); - - if ( !m_params->part()->canChangeValue() ) { - m_firstRowAsLabel->setChecked( m_params->firstRowAsLabel() ); - m_firstColAsLabel->setChecked( m_params->firstColAsLabel() ); - - m_dataArea->setText( m_params->dataArea() ); - } -} - - -void KChartDataConfigPage::defaults() -{ - m_colMajor->setChecked( true ); - - if ( !m_params->part()->canChangeValue() ) { - m_firstRowAsLabel->setChecked( false ); - m_firstColAsLabel->setChecked( false ); - - m_dataArea->setText( "" ); - } -} - - -void KChartDataConfigPage::apply() -{ - if (m_rowMajor->isChecked()) - m_params->setDataDirection( KChartParams::DataRows ); - else - m_params->setDataDirection( KChartParams::DataColumns ); - - if ( !m_params->part()->canChangeValue() ) { - m_params->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); - m_params->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); - - m_params->setDataArea( m_dataArea->text() ); - } -} - - -} //KChart namespace diff --git a/kchart/kchartDataConfigPage.cpp b/kchart/kchartDataConfigPage.cpp new file mode 100644 index 00000000..3a3968e4 --- /dev/null +++ b/kchart/kchartDataConfigPage.cpp @@ -0,0 +1,149 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartDataConfigPage.h" + +#include "kchartDataConfigPage.moc" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// For IRIX +namespace std {} + +using namespace std; + +#include "kchart_params.h" +#include "kchart_part.h" + +namespace KChart +{ + +KChartDataConfigPage::KChartDataConfigPage( KChartParams* params, + TQWidget* parent, + KDChartTableData *dat) + : TQWidget( parent ), m_params( params ), data(dat), + m_firstRowAsLabel(0), m_firstColAsLabel(0) +{ + TQGridLayout *grid1 = new TQGridLayout(this, 4, 1, KDialog::marginHint(), + KDialog::spacingHint()); + + // The Data Area + if ( !m_params->part()->canChangeValue() ) { + TQButtonGroup *gb1 = new TQVButtonGroup( i18n( "Data Area" ), this ); + + // ================================================================ + // This code is copied from kchartWizardSelectDataFormatPage.cpp + TQHBox *hbox = new TQHBox( gb1 ); + (void) new TQLabel( i18n("Area: "), hbox); + m_dataArea = new TQLineEdit( hbox ); + + // The row/column as label checkboxes. + m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), gb1); + m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), gb1); + + grid1->addWidget(gb1, 0, 0); + } + + // The Data Format button group + TQButtonGroup *gb = new TQVButtonGroup( i18n( "Data Format" ), this ); + + m_rowMajor = new TQRadioButton( i18n( "Data in rows" ), gb ); + m_rowMajor->resize( m_rowMajor->sizeHint() ); + + m_colMajor = new TQRadioButton( i18n( "Data in columns" ), gb ); + m_colMajor->resize( m_colMajor->sizeHint() ); + + grid1->addWidget(gb, 2, 0); + + TQWhatsThis::add(this, i18n("This configuration page can be used to swap the interpretation of rows and columns.")); + TQWhatsThis::add(m_rowMajor, i18n("By default one row is considered to be a data set and each column holds the individual values of the data series. This sets the data in rows on your chart.")); + + TQWhatsThis::add(m_colMajor, i18n("Here you can choose to have each column hold one data set. Note that the values are not really swapped but only their interpretation.")); + m_colMajor->resize( m_colMajor->sizeHint() ); + grid1->addWidget(gb, 1, 0); + grid1->setColStretch(3, 0); + + grid1->activate(); +} + + +void KChartDataConfigPage::init() +{ + if (m_params->dataDirection() == KChartParams::DataRows) + m_rowMajor->setChecked(true); + else + m_colMajor->setChecked(true); + + if ( !m_params->part()->canChangeValue() ) { + m_firstRowAsLabel->setChecked( m_params->firstRowAsLabel() ); + m_firstColAsLabel->setChecked( m_params->firstColAsLabel() ); + + m_dataArea->setText( m_params->dataArea() ); + } +} + + +void KChartDataConfigPage::defaults() +{ + m_colMajor->setChecked( true ); + + if ( !m_params->part()->canChangeValue() ) { + m_firstRowAsLabel->setChecked( false ); + m_firstColAsLabel->setChecked( false ); + + m_dataArea->setText( "" ); + } +} + + +void KChartDataConfigPage::apply() +{ + if (m_rowMajor->isChecked()) + m_params->setDataDirection( KChartParams::DataRows ); + else + m_params->setDataDirection( KChartParams::DataColumns ); + + if ( !m_params->part()->canChangeValue() ) { + m_params->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); + m_params->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); + + m_params->setDataArea( m_dataArea->text() ); + } +} + + +} //KChart namespace diff --git a/kchart/kchartDataEditor.cc b/kchart/kchartDataEditor.cc deleted file mode 100644 index 8f08dd78..00000000 --- a/kchart/kchartDataEditor.cc +++ /dev/null @@ -1,900 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kdchart/KDChartAxisParams.h" -#include "kchart_params.h" -#include "kchart_factory.h" - -#include "kchartDataEditor.h" -#include "kchartDataEditor.moc" - -namespace KChart -{ - - -// ================================================================ -// Class kchartDataSpinBox - - -// We don't provide very much generality, since this spinbox is used -// here and here only. -// -kchartDataSpinBox::kchartDataSpinBox(TQWidget *parent) - : TQSpinBox(parent) -{ - m_ignore = false; -} - - -kchartDataSpinBox::~kchartDataSpinBox() -{ -} - - -void kchartDataSpinBox::stepUp() -{ - m_ignore = true; - uint const new_value = value() + 1; - - TQSpinBox::stepUp(); - setValue(new_value); - - emit valueChangedSpecial( value() ); - m_ignore = false; -} - - -void kchartDataSpinBox::stepDown() -{ - m_ignore = true; - - uint const new_value = value() - 1; - TQSpinBox::stepDown(); - setValue(new_value); - - emit valueChangedSpecial( value() ); - m_ignore = false; -} - - -bool kchartDataSpinBox::eventFilter( TQObject *obj, TQEvent *ev ) -{ - if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(editor()) ) { - if ( ev->type() == TQEvent::FocusOut ) { - //kdDebug() << "Focus out" << endl; - setValue(editor()->text().toInt()); - - // Don't emit valueChangedSpecial(int) twice when - // stepUp/stepDown has been called - if (!m_ignore) - emit valueChangedSpecial( value() ); - } - } - - // Pass the event on to the parent class. - return TQSpinBox::eventFilter( obj, ev ); -} - - -// ================================================================ -// Class kchartDataTable - - -// Used for the keyboard navigation -// -kchartDataTable::kchartDataTable(TQWidget *parent) - : TQTable(parent) -{ -} - - -kchartDataTable::~kchartDataTable() -{ -} - - -bool kchartDataTable::eventFilter( TQObject *obj, TQEvent *ev ) -{ - if (ev->type() == TQEvent::KeyPress && strcmp(obj->name(), - "qt_tableeditor")==0 ) { - TQKeyEvent *e = (TQKeyEvent *)ev; - - switch ( e->key() ) { - case TQt::Key_Up: - { - if ( currentRow() > 0 ) { - setCurrentCell( currentRow()-1, currentColumn() ); - editCell(currentRow(), currentColumn() ); - return true; - } - break; - } - case TQt::Key_Down: - { - if ( currentRow() < numRows()-1 ) { - setCurrentCell( currentRow()+1, currentColumn() ); - editCell(currentRow(), currentColumn() ); - return true; - } - break; - } - case TQt::Key_Right: - { - if ( currentColumn() < numCols()-1 ) { - setCurrentCell( currentRow(), currentColumn()+1 ); - editCell(currentRow(), currentColumn() ); - return true; - } - break; - } - case TQt::Key_Left: - { - if ( currentColumn() > 0 ) { - setCurrentCell( currentRow(), currentColumn()-1 ); - editCell(currentRow(), currentColumn() ); - return true; - } - break; - } - } - } - - return TQTable::eventFilter( obj, ev ); -} - - -// ================================================================ -// Class kchartDataEditor - - -#define COLUMNWIDTH 80 - -kchartDataEditor::kchartDataEditor(TQWidget* parent) : - KDialogBase(parent, "dataeditor", true, i18n("KChart Data Editor"), - KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply, - KDialogBase::Ok, true) -{ - TQWidget *page = new TQWidget( this ); - setMainWidget(page); - - // Create the main table. - m_table = new kchartDataTable(page); - m_table->setSelectionMode(TQTable::NoSelection); - m_table->setFocus(); - m_table->setRowMovingEnabled(true); - m_table->setColumnMovingEnabled(true); - - connect( m_table, TQT_SIGNAL( currentChanged(int, int) ), - this, TQT_SLOT( currentChanged(int, int) ) ); - - // Create the Rows setting - m_rowsLA = new TQLabel( i18n("# Rows:" ), page ); - m_rowsLA->resize( m_rowsLA->sizeHint() ); - m_rowsSB = new kchartDataSpinBox( page ); - m_rowsSB->resize( m_rowsSB->sizeHint() ); - m_rowsSB->setMinValue(1); - - // Create the columns setting - m_colsLA = new TQLabel( i18n("# Columns:" ), page ); - m_colsLA->resize( m_colsLA->sizeHint() ); - m_colsSB = new kchartDataSpinBox( page ); - m_colsSB->resize( m_colsSB->sizeHint() ); - m_colsSB->setMinValue(1); - -#if 0 - // The row/column as label checkboxes. - m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), page); - m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), page); -#endif - - // Buttons for Inserting / Removing rows & columns - // The icon images are taken from the standard - m_insertRowButton = new TQPushButton( page); - // In 2.0; this is supposed to be just TDEIcon("name").pixmap(32). - m_insertRowButton->setPixmap( BarIcon( TQString("insert_table_row"), - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global() ) ); - //m_insertRowButton = new TQPushButton( i18n("Insert Row") , page); - connect( m_insertRowButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( insertRow() ) ); - - m_removeRowButton = new TQPushButton( page ); - m_removeRowButton->setPixmap( BarIcon( TQString("delete_table_row"), - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global() ) ); - //m_removeRowButton = new TQPushButton( i18n("Remove Row") , page); - connect( m_removeRowButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( removeCurrentRow() ) ); - - m_insertColButton = new TQPushButton( page ); - m_insertColButton->setPixmap( BarIcon( TQString("insert_table_col"), - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global() ) ); - //m_insertColButton = new TQPushButton( i18n("Insert Column") , page); - connect( m_insertColButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( insertColumn() ) ); - - m_removeColButton = new TQPushButton( page ); - m_removeColButton->setPixmap( BarIcon( TQString("delete_table_col"), - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global() ) ); - //m_removeColButton = new TQPushButton( i18n("Remove Column") , page); - connect( m_removeColButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( removeCurrentColumn() ) ); - - // Start the layout. The buttons are at the top. - TQVBoxLayout *topLayout = new TQVBoxLayout( page ); - - TQHBoxLayout* insertRemoveLayout = new TQHBoxLayout( ); - - insertRemoveLayout->setSpacing(5); - insertRemoveLayout->addWidget(m_insertRowButton); - insertRemoveLayout->addWidget(m_removeRowButton); - insertRemoveLayout->addWidget(m_insertColButton); - insertRemoveLayout->addWidget(m_removeColButton); - insertRemoveLayout->addStretch(1); - - topLayout->addLayout(insertRemoveLayout); - topLayout->addSpacing(10); - - // The table is below the buttons. - topLayout->addWidget(m_table); - - // Then, a horizontal layer with the rows and columns settings - TQHBoxLayout *hbl1 = new TQHBoxLayout( ); - hbl1->addWidget(m_rowsLA); - hbl1->addWidget(m_rowsSB); - hbl1->addSpacing(20); - hbl1->addWidget(m_colsLA); - hbl1->addWidget(m_colsSB); - hbl1->addStretch(1); - hbl1->setMargin(10); - topLayout->addLayout(hbl1); - -#if 0 - // Last, the checkboxes with "First row/column as label" - TQHBoxLayout *hbl2 = new TQHBoxLayout( ); - hbl2->addWidget(m_firstRowAsLabel); - hbl2->addWidget(m_firstColAsLabel); - hbl2->addStretch(1); - hbl2->setMargin(10); - topLayout->addLayout(hbl2); -#endif - - topLayout->setStretchFactor(m_table, 1); - topLayout->setStretchFactor(insertRemoveLayout,1); - - // Connect signals from the spin boxes. - connect(m_rowsSB, TQT_SIGNAL(valueChangedSpecial(int)), - this, TQT_SLOT(setRows(int))); - connect(m_colsSB, TQT_SIGNAL(valueChangedSpecial(int)), - this, TQT_SLOT(setCols(int))); - - -#if 0 - // -- Changed data editor to use top row and leftmost column for - // series names and labels so this is no longer necessary. - - connect(m_table->horizontalHeader(), TQT_SIGNAL(clicked(int)), - this, TQT_SLOT(column_clicked(int)) ); - connect(m_table->verticalHeader(), TQT_SIGNAL(clicked(int)), - this, TQT_SLOT(row_clicked(int)) ); -#endif - - connect(m_table, TQT_SIGNAL(valueChanged(int, int)), - this, TQT_SLOT(tableChanged(int, int)) ); - - // At first, assume that any shrinking of the table is a mistake. - // A confirmation dialog will make sure that the user knows what - // (s)he is doing. - m_userWantsToShrink = false; - - // The data is not modified at the start. - m_modified = false; - - // If the cursor starts at cell (0, 0), that is the header row and - // col, and the user isn't allowed to remove those. - m_removeRowButton->setEnabled( false ); - m_removeColButton->setEnabled( false ); - - // Add tooltips and WhatsThis help. - addDocs(); -} - - -// Add Tooltips and WhatsThis help to various parts of the Data Editor. -// -void kchartDataEditor::addDocs() -{ - // The rows settings. - TQString rowwhatsthis = i18n("

Sets the number of rows in the data table." - "

Each row represents one data set.

"); - TQToolTip::add(m_rowsSB, i18n("Number of active data rows")); - TQWhatsThis::add(m_rowsLA, rowwhatsthis); - TQWhatsThis::add(m_rowsSB, rowwhatsthis); - - // The columns settings. - TQString colwhatsthis = i18n("

Sets the number of columns in the data table." - "

The number of columns defines the number of data values in each data set (row).

"); - TQToolTip::add(m_colsSB, i18n("Number of active data columns")); - TQWhatsThis::add(m_colsLA, colwhatsthis); - TQWhatsThis::add(m_colsSB, colwhatsthis); - - // The table. - TQToolTip::add(m_table, i18n("Chart data table.")); - - //GUI - //The TQWhatsThis information below is incorrect since the way that the contents of the table - //are displayed in the chart depends upon the data format selected (which can be - //either "Data in columns" (default) or "Data in rows) - //The names of the data sets / axes labels are no longer set by clicking on the table - //headers - since that was slow to work with and did not allow for keyboard input. - //Instead the names are taken from the topmost row and leftmost column. - // - //eg: Month | Sales - // Jan | 105 - // Feb | 117 - // March | 120 - // - //The captions of the header are automatically set to the names of the cells in the topmost row - //and leftmost column. This means that if you have more data than will fit in the visible area, - //you can still see the column names or row names when the table has been scrolled. - //KSpread could use some functionality like this as well. - - -#if 0 - TQWhatsThis::add(m_table, i18n("

This table contains the data" - " for the chart.

Each row is one data set of values." - " The name of such a data set can be changed in the column header (on the left)" - " of the table. In a line diagram each row is one line. In a ring diagram each row" - " is one slice.

Each column represents one value of each data set." - " Just like rows you can also change the name of each value in the" - " column headers (at the top) of the table. In a bar diagram the number" - " of columns defines the number of value sets. In a ring diagram each" - " column is one ring.

")); -#endif - - TQToolTip::add( m_insertRowButton, i18n("Insert row") ); - TQToolTip::add( m_removeRowButton, i18n("Delete row") ); - TQToolTip::add( m_insertColButton, i18n("Insert column") ); - TQToolTip::add( m_removeColButton, i18n("Delete column") ); -} - - -// Set the data in the data editor. -// -// The data is taken from the KDChart data. This method is never -// called when the chart is a part of a spreadsheet. -// -void kchartDataEditor::setData( KChartParams *params, KDChartTableData *dat ) -{ - unsigned int rowsCount; - unsigned int colsCount; - - // Get the correct number of rows and columns. - if ( dat->usedRows() == 0 && dat->usedCols() == 0) { // Data from KSpread - rowsCount = dat->rows(); - colsCount = dat->cols(); - } - else { - rowsCount = dat->usedRows(); - colsCount = dat->usedCols(); - } - - // Empty table - if ( rowsCount==0 && colsCount==0 ) { - m_table->setNumRows(1); - m_table->setNumCols(1); - resize(600, 300); - return; - } - - rowsCount += headerRows(); - colsCount += headerCols(); - - // Initiate widgets with the correct rows and columns. - m_rowsSB->setValue(rowsCount); - m_colsSB->setValue(colsCount); -#if 0 - m_firstRowAsLabel->setChecked( params->firstRowAsLabel() ); - m_firstColAsLabel->setChecked( params->firstColAsLabel() ); -#endif - - // Fill the data from the chart into the editor. - m_table->setNumRows(rowsCount); - m_table->setNumCols(colsCount); - for (unsigned int row = headerRows(); row < rowsCount; row++) { - for (unsigned int col = headerCols(); col < colsCount; col++) { - TQVariant t = dat->cellVal(row-headerRows(), col-headerCols()); - - // Fill it in from the part. - if (t.isValid()) { - if ( t.type() == TQVariant::Double ) { - m_table->setText(row, col, - TQString("%1").arg(t.toDouble())); - } - else if ( t.type() == TQVariant::String ) - kdDebug(35001) << "I cannot handle strings in the table yet" - << endl; - else { - // nothing on purpose - } - } - } - } - - // Set column widths. The default is a little too wide. - for (unsigned int col = 0; col < colsCount + 1; col++) - m_table->setColumnWidth(col, COLUMNWIDTH); - - // and resize the widget to a good size. - resize(600, 300); -} - - -// Get the data from the data editor and put it back into the chart. -// -void kchartDataEditor::getData( KChartParams *params, KDChartTableData *dat ) -{ - //Number of rows used as headers - int labelRows = headerRows(); - //Number of columns used as headers - int labelCols = headerCols(); - - int numRows = m_table->numRows()-labelRows; - int numCols = m_table->numCols()-labelCols; - - // Make sure that the data table for the chart is not smaller than - // the data in the editor. - if ( static_cast( dat->rows() ) < numRows - || static_cast( dat->cols() ) < numCols ) - dat->expand( numRows, numCols ); - - dat->setUsedRows( numRows ); - dat->setUsedCols( numCols ); - - // Empty table -#if 0 - if ( numRows==1 && numCols==1 && m_table->horizontalHeader()->label(0).isEmpty() - && m_table->verticalHeader()->label(0).isEmpty() - && m_table->text(0, 0).isEmpty() ) { - dat->expand(0,0); - return; - } -#endif - - // Get all the data. - for (int row = labelRows ; row < (numRows+labelRows); row++) { - for (int col = labelCols ; col < (numCols+labelCols); col++) { - - // Get the text and convert to double. - TQString tmp = m_table->text(row, col); - bool bOk; - double val = tmp.toDouble( &bOk ); - if (!bOk) - val = 0.0; - // and do the actual setting. - //t = KoChart::Value( val ); - dat->setCell(row-labelRows,col-labelCols, val); - } - } - -#if 0 - params->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); - params->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); -#endif -} - - -// Set the row labels in the data editor. -// -void kchartDataEditor::setRowLabels(const TQStringList &rowLabels) -{ -#if 0 - TQHeader *rowHeader = m_table->verticalHeader(); - int row; - int numRows = m_rowsSB->value(); - - rowHeader->setLabel(0, ""); - if ( numRows==1 && m_colsSB->value()==1 && m_table->text(0, 0).isEmpty() ) - return; - for (row = 0; row < numRows; row++) { - rowHeader->setLabel(row, rowLabels[row]); - } -#endif - - for (unsigned int i=0; i < rowLabels.count(); i++) { - m_table->setText(i + headerRows(), 0, rowLabels[i]); - } - - updateRowHeaders(); -} - - -int kchartDataEditor::headerRows() -{ - return 1; -} - -int kchartDataEditor::headerCols() -{ - return 1; -} - - -// Get the row labels from the data editor. -// -void kchartDataEditor::getRowLabels(TQStringList &rowLabels) -{ -#if 0 - TQHeader *rowHeader = m_table->verticalHeader(); - int numRows = m_rowsSB->value(); - int row; - - rowLabels.clear(); - for (row = 0; row < numRows; row++) { - rowLabels << rowHeader->label(row); - } -#endif - rowLabels.clear(); - - for (int i=headerRows();i < m_table->numRows();i++) - { - rowLabels << m_table->text(i,0); - } -} - - -// Set the column labels in the data editor. -// -void kchartDataEditor::setColLabels(const TQStringList &colLabels) -{ -#if 0 - TQHeader *colHeader = m_table->horizontalHeader(); - int col; - - int numCols = m_colsSB->value(); - - colHeader->setLabel(0, ""); - if ( m_rowsSB->value()==1 && numCols==1 && m_table->text(0, 0).isEmpty() ) - return; - for (col = 0; col < numCols; col++) { - colHeader->setLabel(col, colLabels[col]); - } -#endif - - for (unsigned int i = 0; i < colLabels.count(); i++) - { - m_table->setText(0,i+headerCols(),colLabels[i]); - } - - updateColHeaders(); -} - - -// Get the column labels from the data editor. -// -void kchartDataEditor::getColLabels(TQStringList &colLabels) -{ -#if 0 - TQHeader *colHeader = m_table->horizontalHeader(); - int numCols = m_colsSB->value(); - int col; - - colLabels.clear(); - for (col = 0; col < numCols; col++) { - colLabels << colHeader->label(col); - } -#endif - - colLabels.clear(); - - for (int i = headerCols(); i < m_table->numCols(); i++) { - colLabels << m_table->text(0, i); - } -} - - -// ================================================================ -// Slots - - -// Slots for the buttons that insert/remove rows/columns. -// - -void kchartDataEditor::removeCurrentRow() -{ - int row = m_table->currentRow(); - - // Can't remove the header row. - if ( row == 0 ) - return; - - // Need at least one data row. - if ( m_table->numRows() == 2 ) - return; - - m_table->removeRow(row); - m_rowsSB->setValue(m_table->numRows()); - - m_modified = true; -} - -void kchartDataEditor::removeCurrentColumn() -{ - int col = m_table->currentColumn(); - - // Can't remove the header column. - if ( col == 0 ) - return; - - // Need at least one data column. - if ( m_table->numCols() == 2 ) - return; - - m_table->removeColumn(col); - m_colsSB->setValue(m_table->numCols()); - - m_modified = true; -} - -void kchartDataEditor::insertColumn() -{ - m_table->insertColumns(m_table->currentColumn() + 1, 1); - m_colsSB->setValue(m_table->numCols()); - updateColHeaders(); - - m_modified = true; -} - -void kchartDataEditor::insertRow() -{ - m_table->insertRows(m_table->currentRow() + 1, 1); - m_rowsSB->setValue(m_table->numRows()); - updateRowHeaders(); - - m_modified = true; -} - - -// Ask user to make sure that (s)he really wants to remove a row or -// column. -// -static int askUserForConfirmation(TQWidget *parent) -{ - return KMessageBox::warningContinueCancel(parent, - i18n("You are about to shrink the data table and remove some values. " - "This will lead to loss of existing data in the table " - "and/or the headers.\n\n" - "This message will not be shown again if you click Continue")); -} - - -// This slot is called when the spinbox for rows is changed. -// -void kchartDataEditor::setRows(int rows) -{ - kdDebug(35001) << "setRows called: rows = " << rows << endl;; - - // Sanity check. This should never happen since the spinbox has a - // minvalue of 1, but just to be sure... - if (rows < 1) { - m_rowsSB->setValue(1); - return; - } - - int old_rows = m_table->numRows(); - if (rows > old_rows) { - m_table->setNumRows(rows); - - // Default value for the new rows: empty string - for (int i = old_rows; i < rows; i++) - m_table->verticalHeader()->setLabel(i, ""); - - m_modified = true; - } - else if (rows < m_table->numRows()) { - bool ask_user = false; - - // Check if the last row is empty. - for (int col=0; colnumCols(); col++) { - if (!m_table->text(rows, col).isEmpty()) { - ask_user = true; - break; - } - } - - // If it is not, ask if the user really wants to shrink the table. - if ( ask_user && !m_userWantsToShrink - && askUserForConfirmation(this) == KMessageBox::Cancel) { - - // The user aborts. Reset the number of rows and return. - m_rowsSB->setValue(m_table->numRows()); - return; - } - - // Record the fact that the user knows what (s)he is doing. - if (ask_user) - m_userWantsToShrink = true; - - // Do the actual shrinking. - m_table->setNumRows(rows); - - m_modified = true; - } -} - - -// This slot is called when the spinbox for columns is changed. -// -void kchartDataEditor::setCols(int cols) -{ - kdDebug(35001) << "setCols called: cols = " << cols << endl;; - - // Sanity check. This should never happen since the spinbox has a - // minvalue of 1, but just to be sure... - if (cols < 1) { - m_colsSB->setValue(1); - return; - } - - int old_cols = m_table->numCols(); - if (cols > old_cols) { - m_table->setNumCols(cols); - - // Default value for the new columns: empty string. - for (int i = old_cols; i < cols; i++) { - m_table->horizontalHeader()->setLabel(i, ""); - m_table->setColumnWidth(i, COLUMNWIDTH); - } - - m_modified = true; - } - else if (cols < m_table->numCols()) { - bool ask_user = false; - - // Check if the last column is empty. - for (int row=0; rownumRows(); row++) { - if (!m_table->text(row, cols).isEmpty()) { - ask_user = true; - break; - } - } - - // If it is not, ask if the user really wants to shrink the table. - if (ask_user && !m_userWantsToShrink - && askUserForConfirmation(this) == KMessageBox::Cancel) { - - // The user aborts. Reset the number of rows and return. - m_colsSB->setValue(m_table->numCols()); - return; - } - - // Record the fact that the user knows what (s)he is doing. - if (ask_user) - m_userWantsToShrink = true; - - // Do the actual shrinking. - m_table->setNumCols(cols); - - m_modified = true; - } -} - - -// Get the new name for a column header. -// -#if 0 // Disabled since the first row / column now contains the labels. -void kchartDataEditor::column_clicked(int column) -{ - bool ok; - TQString name = KInputDialog::getText(i18n("Column Name"), - i18n("Type a new column name:"), - m_table->horizontalHeader()->label(column), - &ok, this, 0, new TQRegExpValidator(TQRegExp(".*"), this) ); - - // Rename the column. - if ( ok ) { - m_table->horizontalHeader()->setLabel(column, name); - m_modified = true; - } -} - - -// Get the new name for a row header. -// -void kchartDataEditor::row_clicked(int row) -{ - bool ok; - TQString name = KInputDialog::getText(i18n("Row Name"), - i18n("Type a new row name:"), - m_table->verticalHeader()->label(row), - &ok, this, 0, new TQRegExpValidator(TQRegExp(".*"), this) ); - - // Rename the row. - if ( ok ) { - m_table->verticalHeader()->setLabel(row, name); - m_modified = true; - } -} -#endif - - -void kchartDataEditor::tableChanged(int row, int col) -{ - if (row <= headerRows()) - updateColHeaders(); - if (col <= headerCols()) - updateRowHeaders(); - - m_modified = true; -} - - -void kchartDataEditor::currentChanged(int row, int col) -{ - m_removeRowButton->setEnabled( row != 0 && m_table->numRows() > 2 ); - m_removeColButton->setEnabled( col != 0 && m_table->numCols() > 2 ); -} - - -void kchartDataEditor::updateRowHeaders() -{ - for (int i=0;inumRows();i++) - { - TQHeader* header=m_table->verticalHeader(); - - TQString tableCellText=m_table->text(i,0); - - if (tableCellText == TQString()) - tableCellText=TQString(""); - - header->setLabel(header->mapToSection(i),tableCellText); - } -} - -void kchartDataEditor::updateColHeaders() -{ - for (int i=0;inumCols();i++) - { - TQHeader* header=m_table->horizontalHeader(); - - TQString tableCellText=m_table->text(0,i); - - if (tableCellText == TQString()) - tableCellText=TQString(""); - - header->setLabel(header->mapToSection(i),tableCellText); - } -} - - -// This is a reimplementation of a slot defined in KDialogBase. The -// reason for the reimplementation is that we need to emit the signal -// with a pointer to this so that we can get the data. -// -void kchartDataEditor::slotApply() -{ - emit applyClicked(this); -} - - -} //KChart namespace diff --git a/kchart/kchartDataEditor.cpp b/kchart/kchartDataEditor.cpp new file mode 100644 index 00000000..8f08dd78 --- /dev/null +++ b/kchart/kchartDataEditor.cpp @@ -0,0 +1,900 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kdchart/KDChartAxisParams.h" +#include "kchart_params.h" +#include "kchart_factory.h" + +#include "kchartDataEditor.h" +#include "kchartDataEditor.moc" + +namespace KChart +{ + + +// ================================================================ +// Class kchartDataSpinBox + + +// We don't provide very much generality, since this spinbox is used +// here and here only. +// +kchartDataSpinBox::kchartDataSpinBox(TQWidget *parent) + : TQSpinBox(parent) +{ + m_ignore = false; +} + + +kchartDataSpinBox::~kchartDataSpinBox() +{ +} + + +void kchartDataSpinBox::stepUp() +{ + m_ignore = true; + uint const new_value = value() + 1; + + TQSpinBox::stepUp(); + setValue(new_value); + + emit valueChangedSpecial( value() ); + m_ignore = false; +} + + +void kchartDataSpinBox::stepDown() +{ + m_ignore = true; + + uint const new_value = value() - 1; + TQSpinBox::stepDown(); + setValue(new_value); + + emit valueChangedSpecial( value() ); + m_ignore = false; +} + + +bool kchartDataSpinBox::eventFilter( TQObject *obj, TQEvent *ev ) +{ + if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(editor()) ) { + if ( ev->type() == TQEvent::FocusOut ) { + //kdDebug() << "Focus out" << endl; + setValue(editor()->text().toInt()); + + // Don't emit valueChangedSpecial(int) twice when + // stepUp/stepDown has been called + if (!m_ignore) + emit valueChangedSpecial( value() ); + } + } + + // Pass the event on to the parent class. + return TQSpinBox::eventFilter( obj, ev ); +} + + +// ================================================================ +// Class kchartDataTable + + +// Used for the keyboard navigation +// +kchartDataTable::kchartDataTable(TQWidget *parent) + : TQTable(parent) +{ +} + + +kchartDataTable::~kchartDataTable() +{ +} + + +bool kchartDataTable::eventFilter( TQObject *obj, TQEvent *ev ) +{ + if (ev->type() == TQEvent::KeyPress && strcmp(obj->name(), + "qt_tableeditor")==0 ) { + TQKeyEvent *e = (TQKeyEvent *)ev; + + switch ( e->key() ) { + case TQt::Key_Up: + { + if ( currentRow() > 0 ) { + setCurrentCell( currentRow()-1, currentColumn() ); + editCell(currentRow(), currentColumn() ); + return true; + } + break; + } + case TQt::Key_Down: + { + if ( currentRow() < numRows()-1 ) { + setCurrentCell( currentRow()+1, currentColumn() ); + editCell(currentRow(), currentColumn() ); + return true; + } + break; + } + case TQt::Key_Right: + { + if ( currentColumn() < numCols()-1 ) { + setCurrentCell( currentRow(), currentColumn()+1 ); + editCell(currentRow(), currentColumn() ); + return true; + } + break; + } + case TQt::Key_Left: + { + if ( currentColumn() > 0 ) { + setCurrentCell( currentRow(), currentColumn()-1 ); + editCell(currentRow(), currentColumn() ); + return true; + } + break; + } + } + } + + return TQTable::eventFilter( obj, ev ); +} + + +// ================================================================ +// Class kchartDataEditor + + +#define COLUMNWIDTH 80 + +kchartDataEditor::kchartDataEditor(TQWidget* parent) : + KDialogBase(parent, "dataeditor", true, i18n("KChart Data Editor"), + KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply, + KDialogBase::Ok, true) +{ + TQWidget *page = new TQWidget( this ); + setMainWidget(page); + + // Create the main table. + m_table = new kchartDataTable(page); + m_table->setSelectionMode(TQTable::NoSelection); + m_table->setFocus(); + m_table->setRowMovingEnabled(true); + m_table->setColumnMovingEnabled(true); + + connect( m_table, TQT_SIGNAL( currentChanged(int, int) ), + this, TQT_SLOT( currentChanged(int, int) ) ); + + // Create the Rows setting + m_rowsLA = new TQLabel( i18n("# Rows:" ), page ); + m_rowsLA->resize( m_rowsLA->sizeHint() ); + m_rowsSB = new kchartDataSpinBox( page ); + m_rowsSB->resize( m_rowsSB->sizeHint() ); + m_rowsSB->setMinValue(1); + + // Create the columns setting + m_colsLA = new TQLabel( i18n("# Columns:" ), page ); + m_colsLA->resize( m_colsLA->sizeHint() ); + m_colsSB = new kchartDataSpinBox( page ); + m_colsSB->resize( m_colsSB->sizeHint() ); + m_colsSB->setMinValue(1); + +#if 0 + // The row/column as label checkboxes. + m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), page); + m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), page); +#endif + + // Buttons for Inserting / Removing rows & columns + // The icon images are taken from the standard + m_insertRowButton = new TQPushButton( page); + // In 2.0; this is supposed to be just TDEIcon("name").pixmap(32). + m_insertRowButton->setPixmap( BarIcon( TQString("insert_table_row"), + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global() ) ); + //m_insertRowButton = new TQPushButton( i18n("Insert Row") , page); + connect( m_insertRowButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( insertRow() ) ); + + m_removeRowButton = new TQPushButton( page ); + m_removeRowButton->setPixmap( BarIcon( TQString("delete_table_row"), + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global() ) ); + //m_removeRowButton = new TQPushButton( i18n("Remove Row") , page); + connect( m_removeRowButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( removeCurrentRow() ) ); + + m_insertColButton = new TQPushButton( page ); + m_insertColButton->setPixmap( BarIcon( TQString("insert_table_col"), + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global() ) ); + //m_insertColButton = new TQPushButton( i18n("Insert Column") , page); + connect( m_insertColButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( insertColumn() ) ); + + m_removeColButton = new TQPushButton( page ); + m_removeColButton->setPixmap( BarIcon( TQString("delete_table_col"), + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global() ) ); + //m_removeColButton = new TQPushButton( i18n("Remove Column") , page); + connect( m_removeColButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( removeCurrentColumn() ) ); + + // Start the layout. The buttons are at the top. + TQVBoxLayout *topLayout = new TQVBoxLayout( page ); + + TQHBoxLayout* insertRemoveLayout = new TQHBoxLayout( ); + + insertRemoveLayout->setSpacing(5); + insertRemoveLayout->addWidget(m_insertRowButton); + insertRemoveLayout->addWidget(m_removeRowButton); + insertRemoveLayout->addWidget(m_insertColButton); + insertRemoveLayout->addWidget(m_removeColButton); + insertRemoveLayout->addStretch(1); + + topLayout->addLayout(insertRemoveLayout); + topLayout->addSpacing(10); + + // The table is below the buttons. + topLayout->addWidget(m_table); + + // Then, a horizontal layer with the rows and columns settings + TQHBoxLayout *hbl1 = new TQHBoxLayout( ); + hbl1->addWidget(m_rowsLA); + hbl1->addWidget(m_rowsSB); + hbl1->addSpacing(20); + hbl1->addWidget(m_colsLA); + hbl1->addWidget(m_colsSB); + hbl1->addStretch(1); + hbl1->setMargin(10); + topLayout->addLayout(hbl1); + +#if 0 + // Last, the checkboxes with "First row/column as label" + TQHBoxLayout *hbl2 = new TQHBoxLayout( ); + hbl2->addWidget(m_firstRowAsLabel); + hbl2->addWidget(m_firstColAsLabel); + hbl2->addStretch(1); + hbl2->setMargin(10); + topLayout->addLayout(hbl2); +#endif + + topLayout->setStretchFactor(m_table, 1); + topLayout->setStretchFactor(insertRemoveLayout,1); + + // Connect signals from the spin boxes. + connect(m_rowsSB, TQT_SIGNAL(valueChangedSpecial(int)), + this, TQT_SLOT(setRows(int))); + connect(m_colsSB, TQT_SIGNAL(valueChangedSpecial(int)), + this, TQT_SLOT(setCols(int))); + + +#if 0 + // -- Changed data editor to use top row and leftmost column for + // series names and labels so this is no longer necessary. + + connect(m_table->horizontalHeader(), TQT_SIGNAL(clicked(int)), + this, TQT_SLOT(column_clicked(int)) ); + connect(m_table->verticalHeader(), TQT_SIGNAL(clicked(int)), + this, TQT_SLOT(row_clicked(int)) ); +#endif + + connect(m_table, TQT_SIGNAL(valueChanged(int, int)), + this, TQT_SLOT(tableChanged(int, int)) ); + + // At first, assume that any shrinking of the table is a mistake. + // A confirmation dialog will make sure that the user knows what + // (s)he is doing. + m_userWantsToShrink = false; + + // The data is not modified at the start. + m_modified = false; + + // If the cursor starts at cell (0, 0), that is the header row and + // col, and the user isn't allowed to remove those. + m_removeRowButton->setEnabled( false ); + m_removeColButton->setEnabled( false ); + + // Add tooltips and WhatsThis help. + addDocs(); +} + + +// Add Tooltips and WhatsThis help to various parts of the Data Editor. +// +void kchartDataEditor::addDocs() +{ + // The rows settings. + TQString rowwhatsthis = i18n("

Sets the number of rows in the data table." + "

Each row represents one data set.

"); + TQToolTip::add(m_rowsSB, i18n("Number of active data rows")); + TQWhatsThis::add(m_rowsLA, rowwhatsthis); + TQWhatsThis::add(m_rowsSB, rowwhatsthis); + + // The columns settings. + TQString colwhatsthis = i18n("

Sets the number of columns in the data table." + "

The number of columns defines the number of data values in each data set (row).

"); + TQToolTip::add(m_colsSB, i18n("Number of active data columns")); + TQWhatsThis::add(m_colsLA, colwhatsthis); + TQWhatsThis::add(m_colsSB, colwhatsthis); + + // The table. + TQToolTip::add(m_table, i18n("Chart data table.")); + + //GUI + //The TQWhatsThis information below is incorrect since the way that the contents of the table + //are displayed in the chart depends upon the data format selected (which can be + //either "Data in columns" (default) or "Data in rows) + //The names of the data sets / axes labels are no longer set by clicking on the table + //headers - since that was slow to work with and did not allow for keyboard input. + //Instead the names are taken from the topmost row and leftmost column. + // + //eg: Month | Sales + // Jan | 105 + // Feb | 117 + // March | 120 + // + //The captions of the header are automatically set to the names of the cells in the topmost row + //and leftmost column. This means that if you have more data than will fit in the visible area, + //you can still see the column names or row names when the table has been scrolled. + //KSpread could use some functionality like this as well. + + +#if 0 + TQWhatsThis::add(m_table, i18n("

This table contains the data" + " for the chart.

Each row is one data set of values." + " The name of such a data set can be changed in the column header (on the left)" + " of the table. In a line diagram each row is one line. In a ring diagram each row" + " is one slice.

Each column represents one value of each data set." + " Just like rows you can also change the name of each value in the" + " column headers (at the top) of the table. In a bar diagram the number" + " of columns defines the number of value sets. In a ring diagram each" + " column is one ring.

")); +#endif + + TQToolTip::add( m_insertRowButton, i18n("Insert row") ); + TQToolTip::add( m_removeRowButton, i18n("Delete row") ); + TQToolTip::add( m_insertColButton, i18n("Insert column") ); + TQToolTip::add( m_removeColButton, i18n("Delete column") ); +} + + +// Set the data in the data editor. +// +// The data is taken from the KDChart data. This method is never +// called when the chart is a part of a spreadsheet. +// +void kchartDataEditor::setData( KChartParams *params, KDChartTableData *dat ) +{ + unsigned int rowsCount; + unsigned int colsCount; + + // Get the correct number of rows and columns. + if ( dat->usedRows() == 0 && dat->usedCols() == 0) { // Data from KSpread + rowsCount = dat->rows(); + colsCount = dat->cols(); + } + else { + rowsCount = dat->usedRows(); + colsCount = dat->usedCols(); + } + + // Empty table + if ( rowsCount==0 && colsCount==0 ) { + m_table->setNumRows(1); + m_table->setNumCols(1); + resize(600, 300); + return; + } + + rowsCount += headerRows(); + colsCount += headerCols(); + + // Initiate widgets with the correct rows and columns. + m_rowsSB->setValue(rowsCount); + m_colsSB->setValue(colsCount); +#if 0 + m_firstRowAsLabel->setChecked( params->firstRowAsLabel() ); + m_firstColAsLabel->setChecked( params->firstColAsLabel() ); +#endif + + // Fill the data from the chart into the editor. + m_table->setNumRows(rowsCount); + m_table->setNumCols(colsCount); + for (unsigned int row = headerRows(); row < rowsCount; row++) { + for (unsigned int col = headerCols(); col < colsCount; col++) { + TQVariant t = dat->cellVal(row-headerRows(), col-headerCols()); + + // Fill it in from the part. + if (t.isValid()) { + if ( t.type() == TQVariant::Double ) { + m_table->setText(row, col, + TQString("%1").arg(t.toDouble())); + } + else if ( t.type() == TQVariant::String ) + kdDebug(35001) << "I cannot handle strings in the table yet" + << endl; + else { + // nothing on purpose + } + } + } + } + + // Set column widths. The default is a little too wide. + for (unsigned int col = 0; col < colsCount + 1; col++) + m_table->setColumnWidth(col, COLUMNWIDTH); + + // and resize the widget to a good size. + resize(600, 300); +} + + +// Get the data from the data editor and put it back into the chart. +// +void kchartDataEditor::getData( KChartParams *params, KDChartTableData *dat ) +{ + //Number of rows used as headers + int labelRows = headerRows(); + //Number of columns used as headers + int labelCols = headerCols(); + + int numRows = m_table->numRows()-labelRows; + int numCols = m_table->numCols()-labelCols; + + // Make sure that the data table for the chart is not smaller than + // the data in the editor. + if ( static_cast( dat->rows() ) < numRows + || static_cast( dat->cols() ) < numCols ) + dat->expand( numRows, numCols ); + + dat->setUsedRows( numRows ); + dat->setUsedCols( numCols ); + + // Empty table +#if 0 + if ( numRows==1 && numCols==1 && m_table->horizontalHeader()->label(0).isEmpty() + && m_table->verticalHeader()->label(0).isEmpty() + && m_table->text(0, 0).isEmpty() ) { + dat->expand(0,0); + return; + } +#endif + + // Get all the data. + for (int row = labelRows ; row < (numRows+labelRows); row++) { + for (int col = labelCols ; col < (numCols+labelCols); col++) { + + // Get the text and convert to double. + TQString tmp = m_table->text(row, col); + bool bOk; + double val = tmp.toDouble( &bOk ); + if (!bOk) + val = 0.0; + // and do the actual setting. + //t = KoChart::Value( val ); + dat->setCell(row-labelRows,col-labelCols, val); + } + } + +#if 0 + params->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); + params->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); +#endif +} + + +// Set the row labels in the data editor. +// +void kchartDataEditor::setRowLabels(const TQStringList &rowLabels) +{ +#if 0 + TQHeader *rowHeader = m_table->verticalHeader(); + int row; + int numRows = m_rowsSB->value(); + + rowHeader->setLabel(0, ""); + if ( numRows==1 && m_colsSB->value()==1 && m_table->text(0, 0).isEmpty() ) + return; + for (row = 0; row < numRows; row++) { + rowHeader->setLabel(row, rowLabels[row]); + } +#endif + + for (unsigned int i=0; i < rowLabels.count(); i++) { + m_table->setText(i + headerRows(), 0, rowLabels[i]); + } + + updateRowHeaders(); +} + + +int kchartDataEditor::headerRows() +{ + return 1; +} + +int kchartDataEditor::headerCols() +{ + return 1; +} + + +// Get the row labels from the data editor. +// +void kchartDataEditor::getRowLabels(TQStringList &rowLabels) +{ +#if 0 + TQHeader *rowHeader = m_table->verticalHeader(); + int numRows = m_rowsSB->value(); + int row; + + rowLabels.clear(); + for (row = 0; row < numRows; row++) { + rowLabels << rowHeader->label(row); + } +#endif + rowLabels.clear(); + + for (int i=headerRows();i < m_table->numRows();i++) + { + rowLabels << m_table->text(i,0); + } +} + + +// Set the column labels in the data editor. +// +void kchartDataEditor::setColLabels(const TQStringList &colLabels) +{ +#if 0 + TQHeader *colHeader = m_table->horizontalHeader(); + int col; + + int numCols = m_colsSB->value(); + + colHeader->setLabel(0, ""); + if ( m_rowsSB->value()==1 && numCols==1 && m_table->text(0, 0).isEmpty() ) + return; + for (col = 0; col < numCols; col++) { + colHeader->setLabel(col, colLabels[col]); + } +#endif + + for (unsigned int i = 0; i < colLabels.count(); i++) + { + m_table->setText(0,i+headerCols(),colLabels[i]); + } + + updateColHeaders(); +} + + +// Get the column labels from the data editor. +// +void kchartDataEditor::getColLabels(TQStringList &colLabels) +{ +#if 0 + TQHeader *colHeader = m_table->horizontalHeader(); + int numCols = m_colsSB->value(); + int col; + + colLabels.clear(); + for (col = 0; col < numCols; col++) { + colLabels << colHeader->label(col); + } +#endif + + colLabels.clear(); + + for (int i = headerCols(); i < m_table->numCols(); i++) { + colLabels << m_table->text(0, i); + } +} + + +// ================================================================ +// Slots + + +// Slots for the buttons that insert/remove rows/columns. +// + +void kchartDataEditor::removeCurrentRow() +{ + int row = m_table->currentRow(); + + // Can't remove the header row. + if ( row == 0 ) + return; + + // Need at least one data row. + if ( m_table->numRows() == 2 ) + return; + + m_table->removeRow(row); + m_rowsSB->setValue(m_table->numRows()); + + m_modified = true; +} + +void kchartDataEditor::removeCurrentColumn() +{ + int col = m_table->currentColumn(); + + // Can't remove the header column. + if ( col == 0 ) + return; + + // Need at least one data column. + if ( m_table->numCols() == 2 ) + return; + + m_table->removeColumn(col); + m_colsSB->setValue(m_table->numCols()); + + m_modified = true; +} + +void kchartDataEditor::insertColumn() +{ + m_table->insertColumns(m_table->currentColumn() + 1, 1); + m_colsSB->setValue(m_table->numCols()); + updateColHeaders(); + + m_modified = true; +} + +void kchartDataEditor::insertRow() +{ + m_table->insertRows(m_table->currentRow() + 1, 1); + m_rowsSB->setValue(m_table->numRows()); + updateRowHeaders(); + + m_modified = true; +} + + +// Ask user to make sure that (s)he really wants to remove a row or +// column. +// +static int askUserForConfirmation(TQWidget *parent) +{ + return KMessageBox::warningContinueCancel(parent, + i18n("You are about to shrink the data table and remove some values. " + "This will lead to loss of existing data in the table " + "and/or the headers.\n\n" + "This message will not be shown again if you click Continue")); +} + + +// This slot is called when the spinbox for rows is changed. +// +void kchartDataEditor::setRows(int rows) +{ + kdDebug(35001) << "setRows called: rows = " << rows << endl;; + + // Sanity check. This should never happen since the spinbox has a + // minvalue of 1, but just to be sure... + if (rows < 1) { + m_rowsSB->setValue(1); + return; + } + + int old_rows = m_table->numRows(); + if (rows > old_rows) { + m_table->setNumRows(rows); + + // Default value for the new rows: empty string + for (int i = old_rows; i < rows; i++) + m_table->verticalHeader()->setLabel(i, ""); + + m_modified = true; + } + else if (rows < m_table->numRows()) { + bool ask_user = false; + + // Check if the last row is empty. + for (int col=0; colnumCols(); col++) { + if (!m_table->text(rows, col).isEmpty()) { + ask_user = true; + break; + } + } + + // If it is not, ask if the user really wants to shrink the table. + if ( ask_user && !m_userWantsToShrink + && askUserForConfirmation(this) == KMessageBox::Cancel) { + + // The user aborts. Reset the number of rows and return. + m_rowsSB->setValue(m_table->numRows()); + return; + } + + // Record the fact that the user knows what (s)he is doing. + if (ask_user) + m_userWantsToShrink = true; + + // Do the actual shrinking. + m_table->setNumRows(rows); + + m_modified = true; + } +} + + +// This slot is called when the spinbox for columns is changed. +// +void kchartDataEditor::setCols(int cols) +{ + kdDebug(35001) << "setCols called: cols = " << cols << endl;; + + // Sanity check. This should never happen since the spinbox has a + // minvalue of 1, but just to be sure... + if (cols < 1) { + m_colsSB->setValue(1); + return; + } + + int old_cols = m_table->numCols(); + if (cols > old_cols) { + m_table->setNumCols(cols); + + // Default value for the new columns: empty string. + for (int i = old_cols; i < cols; i++) { + m_table->horizontalHeader()->setLabel(i, ""); + m_table->setColumnWidth(i, COLUMNWIDTH); + } + + m_modified = true; + } + else if (cols < m_table->numCols()) { + bool ask_user = false; + + // Check if the last column is empty. + for (int row=0; rownumRows(); row++) { + if (!m_table->text(row, cols).isEmpty()) { + ask_user = true; + break; + } + } + + // If it is not, ask if the user really wants to shrink the table. + if (ask_user && !m_userWantsToShrink + && askUserForConfirmation(this) == KMessageBox::Cancel) { + + // The user aborts. Reset the number of rows and return. + m_colsSB->setValue(m_table->numCols()); + return; + } + + // Record the fact that the user knows what (s)he is doing. + if (ask_user) + m_userWantsToShrink = true; + + // Do the actual shrinking. + m_table->setNumCols(cols); + + m_modified = true; + } +} + + +// Get the new name for a column header. +// +#if 0 // Disabled since the first row / column now contains the labels. +void kchartDataEditor::column_clicked(int column) +{ + bool ok; + TQString name = KInputDialog::getText(i18n("Column Name"), + i18n("Type a new column name:"), + m_table->horizontalHeader()->label(column), + &ok, this, 0, new TQRegExpValidator(TQRegExp(".*"), this) ); + + // Rename the column. + if ( ok ) { + m_table->horizontalHeader()->setLabel(column, name); + m_modified = true; + } +} + + +// Get the new name for a row header. +// +void kchartDataEditor::row_clicked(int row) +{ + bool ok; + TQString name = KInputDialog::getText(i18n("Row Name"), + i18n("Type a new row name:"), + m_table->verticalHeader()->label(row), + &ok, this, 0, new TQRegExpValidator(TQRegExp(".*"), this) ); + + // Rename the row. + if ( ok ) { + m_table->verticalHeader()->setLabel(row, name); + m_modified = true; + } +} +#endif + + +void kchartDataEditor::tableChanged(int row, int col) +{ + if (row <= headerRows()) + updateColHeaders(); + if (col <= headerCols()) + updateRowHeaders(); + + m_modified = true; +} + + +void kchartDataEditor::currentChanged(int row, int col) +{ + m_removeRowButton->setEnabled( row != 0 && m_table->numRows() > 2 ); + m_removeColButton->setEnabled( col != 0 && m_table->numCols() > 2 ); +} + + +void kchartDataEditor::updateRowHeaders() +{ + for (int i=0;inumRows();i++) + { + TQHeader* header=m_table->verticalHeader(); + + TQString tableCellText=m_table->text(i,0); + + if (tableCellText == TQString()) + tableCellText=TQString(""); + + header->setLabel(header->mapToSection(i),tableCellText); + } +} + +void kchartDataEditor::updateColHeaders() +{ + for (int i=0;inumCols();i++) + { + TQHeader* header=m_table->horizontalHeader(); + + TQString tableCellText=m_table->text(0,i); + + if (tableCellText == TQString()) + tableCellText=TQString(""); + + header->setLabel(header->mapToSection(i),tableCellText); + } +} + + +// This is a reimplementation of a slot defined in KDialogBase. The +// reason for the reimplementation is that we need to emit the signal +// with a pointer to this so that we can get the data. +// +void kchartDataEditor::slotApply() +{ + emit applyClicked(this); +} + + +} //KChart namespace diff --git a/kchart/kchartFontConfigPage.cc b/kchart/kchartFontConfigPage.cc deleted file mode 100644 index 27f91581..00000000 --- a/kchart/kchartFontConfigPage.cc +++ /dev/null @@ -1,308 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - - -#include "kchartFontConfigPage.h" - -#include "kchartFontConfigPage.moc" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -// For IRIX -namespace std {} - -using namespace std; - -#include "kchart_params.h" - - -class KChartFontListBoxItem : public TQListBoxText -{ -public: - KChartFontListBoxItem( TQListBox* lb, const TQString& text = TQString() ) : - TQListBoxText( lb, text ) {} - KChartFontListBoxItem( const TQString& text = TQString() ) : - TQListBoxText( text ) {} - - void setFont( const TQFont& font ) { - _font = font; - listBox()->repaint(); - } - TQFont font() const { - return _font; - } - -protected: - void paint( TQPainter* painter ) - { - painter->save(); - painter->setFont( _font ); - TQListBoxText::paint( painter ); - painter->restore(); - } - -private: - TQFont _font; -}; - - -// ---------------------------------------------------------------- - - -namespace KChart -{ - -KChartFontConfigPage::KChartFontConfigPage( KChartParams* params, - TQWidget* parent, - KDChartTableData *dat) : - TQWidget( parent ), m_params( params ), data(dat) -{ - TQGridLayout *grid = new TQGridLayout(this,4,3,KDialog::marginHint(), KDialog::spacingHint()); - - // The listbox - m_list = new TQListBox(this); - m_list->resize( m_list->sizeHint() ); - grid->addWidget(m_list, 0, 0); // Row 0-0, col 0-1 - - // The font button. - m_fontButton = new TQPushButton( this); - m_fontButton->setText(i18n("Font...")); - TQWhatsThis::add(m_fontButton, i18n("Select an item in the list above and click on this button to display the TDE font dialog in order to choose a new font for this item.")); - m_fontButton->resize( m_fontButton->sizeHint() ); - grid->addWidget( m_fontButton, 1, 0); - -#if 0 - // FIXME: Integrate the font chooser instead? Well, maybe later. - TDEFontChooser *fontChooser = new TDEFontChooser(this, "fontChooser"); - grid->addMultiCellWidget(fontChooser, 0, 2, 1, 1); -#endif - - grid->setColStretch(2, 1); - grid->setRowStretch(3, 1); - - connect( m_fontButton, TQT_SIGNAL(clicked()), - this, TQT_SLOT(changeLabelFont())); - connect( m_list, TQT_SIGNAL(doubleClicked ( TQListBoxItem * )), - this, TQT_SLOT(changeLabelFont())); - - // Enter the items into the list. - initList(); -} - - -void KChartFontConfigPage::initList() -{ - if ( m_params->chartType() != KChartParams::Pie - && m_params->chartType() != KChartParams::Ring ) { - m_list->insertItem(new KChartFontListBoxItem( i18n("X-Title"))); - m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Title"))); - m_list->insertItem(new KChartFontListBoxItem( i18n("X-Axis"))); - m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Axis"))); - m_list->insertItem(new KChartFontListBoxItem( i18n("All Axes"))); - } - - m_list->insertItem(i18n("Label")); - m_list->setCurrentItem(0); -} - - - -void KChartFontConfigPage::changeLabelFont() -{ - TQFont *font = 0; - TQButton::ToggleState *state = 0; - bool diffAxes = false; - - if (m_list->currentText()==i18n("X-Title")) { - font = &xTitle; - state = &xTitleIsRelative; - } else if(m_list->currentText()==i18n("Y-Title")) { - font = &yTitle; - state = &yTitleIsRelative; - } else if(m_list->currentText()==i18n("X-Axis")) { - font = &xAxis; - state = &xAxisIsRelative; - } else if(m_list->currentText()==i18n("Y-Axis")) { - font = &yAxis; - state = &yAxisIsRelative; - } else if(m_list->currentText()==i18n("All Axes")) { - diffAxes = true; - } else if(m_list->currentText()==i18n("Label")) { - font = &label; - state = &labelIsRelative; - } - else - kdDebug( 35001 ) << "Pb in listBox" << endl; - - if ( diffAxes ) { - TQFont newFont; - int flags = 0; - TQButton::ToggleState newState - = (xAxisIsRelative == yAxisIsRelative) - ? (xAxisIsRelative ? TQButton::On : TQButton::Off) - : TQButton::NoChange; - if (TDEFontDialog::getFontDiff( newFont, - flags, - false, - this, - true, - &newState ) != TQDialog::Rejected) { - if ( TDEFontChooser::FamilyList & flags ) { - xAxis.setFamily( newFont.family() ); - yAxis.setFamily( newFont.family() ); - } - - if ( TDEFontChooser::StyleList & flags ) { - xAxis.setWeight( newFont.weight() ); - xAxis.setItalic( newFont.italic() ); - xAxis.setUnderline( newFont.underline() ); - xAxis.setStrikeOut( newFont.strikeOut() ); - - yAxis.setWeight( newFont.weight() ); - yAxis.setItalic( newFont.italic() ); - yAxis.setUnderline( newFont.underline() ); - yAxis.setStrikeOut( newFont.strikeOut() ); - } - - if ( TDEFontChooser::SizeList & flags ) { - xAxis.setPointSize( newFont.pointSize() ); - yAxis.setPointSize( newFont.pointSize() ); - } - - // CharSet settings are ignored since we are not TQt 2.x compatible - // if( TDEFontChooser::CharsetList & flags ) { - // } - - if ( TQButton::NoChange != newState ) { - xAxisIsRelative = newState; - yAxisIsRelative = newState; - } - } - } - else if ( font && state ) { - TQFont newFont( *font ); - TQButton::ToggleState newState = *state; - if (TDEFontDialog::getFont( newFont, - false, - this, - true, - &newState ) != TQDialog::Rejected) { - *font = newFont; - if ( TQButton::NoChange != newState ) - *state = newState; - } - } -} - - -void KChartFontConfigPage::init() -{ - KDChartAxisParams leftparms; - leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams rightparms; - rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparms; - bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - xAxis = bottomparms.axisLabelsFont(); - xAxisIsRelative = bottomparms.axisLabelsFontUseRelSize() - ? TQButton::On : TQButton::Off; - - if ( TQButton::On == xAxisIsRelative ) - xAxis.setPointSize( bottomparms.axisLabelsFontRelSize() ); - - yAxis = leftparms.axisLabelsFont(); - yAxisIsRelative = leftparms.axisLabelsFontUseRelSize() - ? TQButton::On : TQButton::Off; - - if ( TQButton::On == yAxisIsRelative ) - yAxis.setPointSize( leftparms.axisLabelsFontRelSize() ); - // PENDING(khz) Add support for the other 6 possible axes - - // PENDING(khz) Add support for the other 16 possible hd/ft areas - - - xTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosBottom ); - yTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosLeft ); - xTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosBottom ) ); - yTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosLeft ) ); -// label = _params->labelFont(); - - // PENDING(kalle) Adapt -// for(int i=0;i<12;i++) -// extColor.setColor(i,_params->ExtColor.color(i)); -// index = 0; -// colorButton->setColor(extColor.color(index)); -} - - -void KChartFontConfigPage::apply() -{ - // PENDING(kalle) Adapt - KDChartAxisParams leftparms; - leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams rightparms; - rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparms; - bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - leftparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative ); - if ( TQButton::On == yAxisIsRelative ) - leftparms.setAxisLabelsFontRelSize( yAxis.pointSize() ); - - // PENDING(khz) change right axis handling - // use left axis settings for the right axis as well - // (this must be changed, khz 14.12.2001) - rightparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative ); - if ( TQButton::On == yAxisIsRelative ) - rightparms.setAxisLabelsFontRelSize( yAxis.pointSize() ); - - bottomparms.setAxisLabelsFont( xAxis, TQButton::Off == xAxisIsRelative ); - if ( TQButton::On == xAxisIsRelative ) - bottomparms.setAxisLabelsFontRelSize( xAxis.pointSize() ); - // PENDING(khz) Add support for the other 6 possible axes - - m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparms ); - m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparms ); - m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparms ); - // PENDING(khz) change hd2 and ft handling - // use header settings for header 2 and footer as well - // (this must be changed, khz 14.12.2001) - // PENDING(khz) Add support for the other 16 possible hd/ft areas - - m_params->setAxisTitleFont( KDChartAxisParams::AxisPosLeft, yTitle ); - m_params->setAxisTitleFont( KDChartAxisParams::AxisPosBottom, xTitle ); - m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosLeft, yTitle.pointSize() ); - m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosBottom, xTitle.pointSize() ); -} - -} //KChart namespace diff --git a/kchart/kchartFontConfigPage.cpp b/kchart/kchartFontConfigPage.cpp new file mode 100644 index 00000000..27f91581 --- /dev/null +++ b/kchart/kchartFontConfigPage.cpp @@ -0,0 +1,308 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + + +#include "kchartFontConfigPage.h" + +#include "kchartFontConfigPage.moc" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +// For IRIX +namespace std {} + +using namespace std; + +#include "kchart_params.h" + + +class KChartFontListBoxItem : public TQListBoxText +{ +public: + KChartFontListBoxItem( TQListBox* lb, const TQString& text = TQString() ) : + TQListBoxText( lb, text ) {} + KChartFontListBoxItem( const TQString& text = TQString() ) : + TQListBoxText( text ) {} + + void setFont( const TQFont& font ) { + _font = font; + listBox()->repaint(); + } + TQFont font() const { + return _font; + } + +protected: + void paint( TQPainter* painter ) + { + painter->save(); + painter->setFont( _font ); + TQListBoxText::paint( painter ); + painter->restore(); + } + +private: + TQFont _font; +}; + + +// ---------------------------------------------------------------- + + +namespace KChart +{ + +KChartFontConfigPage::KChartFontConfigPage( KChartParams* params, + TQWidget* parent, + KDChartTableData *dat) : + TQWidget( parent ), m_params( params ), data(dat) +{ + TQGridLayout *grid = new TQGridLayout(this,4,3,KDialog::marginHint(), KDialog::spacingHint()); + + // The listbox + m_list = new TQListBox(this); + m_list->resize( m_list->sizeHint() ); + grid->addWidget(m_list, 0, 0); // Row 0-0, col 0-1 + + // The font button. + m_fontButton = new TQPushButton( this); + m_fontButton->setText(i18n("Font...")); + TQWhatsThis::add(m_fontButton, i18n("Select an item in the list above and click on this button to display the TDE font dialog in order to choose a new font for this item.")); + m_fontButton->resize( m_fontButton->sizeHint() ); + grid->addWidget( m_fontButton, 1, 0); + +#if 0 + // FIXME: Integrate the font chooser instead? Well, maybe later. + TDEFontChooser *fontChooser = new TDEFontChooser(this, "fontChooser"); + grid->addMultiCellWidget(fontChooser, 0, 2, 1, 1); +#endif + + grid->setColStretch(2, 1); + grid->setRowStretch(3, 1); + + connect( m_fontButton, TQT_SIGNAL(clicked()), + this, TQT_SLOT(changeLabelFont())); + connect( m_list, TQT_SIGNAL(doubleClicked ( TQListBoxItem * )), + this, TQT_SLOT(changeLabelFont())); + + // Enter the items into the list. + initList(); +} + + +void KChartFontConfigPage::initList() +{ + if ( m_params->chartType() != KChartParams::Pie + && m_params->chartType() != KChartParams::Ring ) { + m_list->insertItem(new KChartFontListBoxItem( i18n("X-Title"))); + m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Title"))); + m_list->insertItem(new KChartFontListBoxItem( i18n("X-Axis"))); + m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Axis"))); + m_list->insertItem(new KChartFontListBoxItem( i18n("All Axes"))); + } + + m_list->insertItem(i18n("Label")); + m_list->setCurrentItem(0); +} + + + +void KChartFontConfigPage::changeLabelFont() +{ + TQFont *font = 0; + TQButton::ToggleState *state = 0; + bool diffAxes = false; + + if (m_list->currentText()==i18n("X-Title")) { + font = &xTitle; + state = &xTitleIsRelative; + } else if(m_list->currentText()==i18n("Y-Title")) { + font = &yTitle; + state = &yTitleIsRelative; + } else if(m_list->currentText()==i18n("X-Axis")) { + font = &xAxis; + state = &xAxisIsRelative; + } else if(m_list->currentText()==i18n("Y-Axis")) { + font = &yAxis; + state = &yAxisIsRelative; + } else if(m_list->currentText()==i18n("All Axes")) { + diffAxes = true; + } else if(m_list->currentText()==i18n("Label")) { + font = &label; + state = &labelIsRelative; + } + else + kdDebug( 35001 ) << "Pb in listBox" << endl; + + if ( diffAxes ) { + TQFont newFont; + int flags = 0; + TQButton::ToggleState newState + = (xAxisIsRelative == yAxisIsRelative) + ? (xAxisIsRelative ? TQButton::On : TQButton::Off) + : TQButton::NoChange; + if (TDEFontDialog::getFontDiff( newFont, + flags, + false, + this, + true, + &newState ) != TQDialog::Rejected) { + if ( TDEFontChooser::FamilyList & flags ) { + xAxis.setFamily( newFont.family() ); + yAxis.setFamily( newFont.family() ); + } + + if ( TDEFontChooser::StyleList & flags ) { + xAxis.setWeight( newFont.weight() ); + xAxis.setItalic( newFont.italic() ); + xAxis.setUnderline( newFont.underline() ); + xAxis.setStrikeOut( newFont.strikeOut() ); + + yAxis.setWeight( newFont.weight() ); + yAxis.setItalic( newFont.italic() ); + yAxis.setUnderline( newFont.underline() ); + yAxis.setStrikeOut( newFont.strikeOut() ); + } + + if ( TDEFontChooser::SizeList & flags ) { + xAxis.setPointSize( newFont.pointSize() ); + yAxis.setPointSize( newFont.pointSize() ); + } + + // CharSet settings are ignored since we are not TQt 2.x compatible + // if( TDEFontChooser::CharsetList & flags ) { + // } + + if ( TQButton::NoChange != newState ) { + xAxisIsRelative = newState; + yAxisIsRelative = newState; + } + } + } + else if ( font && state ) { + TQFont newFont( *font ); + TQButton::ToggleState newState = *state; + if (TDEFontDialog::getFont( newFont, + false, + this, + true, + &newState ) != TQDialog::Rejected) { + *font = newFont; + if ( TQButton::NoChange != newState ) + *state = newState; + } + } +} + + +void KChartFontConfigPage::init() +{ + KDChartAxisParams leftparms; + leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams rightparms; + rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparms; + bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + xAxis = bottomparms.axisLabelsFont(); + xAxisIsRelative = bottomparms.axisLabelsFontUseRelSize() + ? TQButton::On : TQButton::Off; + + if ( TQButton::On == xAxisIsRelative ) + xAxis.setPointSize( bottomparms.axisLabelsFontRelSize() ); + + yAxis = leftparms.axisLabelsFont(); + yAxisIsRelative = leftparms.axisLabelsFontUseRelSize() + ? TQButton::On : TQButton::Off; + + if ( TQButton::On == yAxisIsRelative ) + yAxis.setPointSize( leftparms.axisLabelsFontRelSize() ); + // PENDING(khz) Add support for the other 6 possible axes + + // PENDING(khz) Add support for the other 16 possible hd/ft areas + + + xTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosBottom ); + yTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosLeft ); + xTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosBottom ) ); + yTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosLeft ) ); +// label = _params->labelFont(); + + // PENDING(kalle) Adapt +// for(int i=0;i<12;i++) +// extColor.setColor(i,_params->ExtColor.color(i)); +// index = 0; +// colorButton->setColor(extColor.color(index)); +} + + +void KChartFontConfigPage::apply() +{ + // PENDING(kalle) Adapt + KDChartAxisParams leftparms; + leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams rightparms; + rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparms; + bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + leftparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative ); + if ( TQButton::On == yAxisIsRelative ) + leftparms.setAxisLabelsFontRelSize( yAxis.pointSize() ); + + // PENDING(khz) change right axis handling + // use left axis settings for the right axis as well + // (this must be changed, khz 14.12.2001) + rightparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative ); + if ( TQButton::On == yAxisIsRelative ) + rightparms.setAxisLabelsFontRelSize( yAxis.pointSize() ); + + bottomparms.setAxisLabelsFont( xAxis, TQButton::Off == xAxisIsRelative ); + if ( TQButton::On == xAxisIsRelative ) + bottomparms.setAxisLabelsFontRelSize( xAxis.pointSize() ); + // PENDING(khz) Add support for the other 6 possible axes + + m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparms ); + m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparms ); + m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparms ); + // PENDING(khz) change hd2 and ft handling + // use header settings for header 2 and footer as well + // (this must be changed, khz 14.12.2001) + // PENDING(khz) Add support for the other 16 possible hd/ft areas + + m_params->setAxisTitleFont( KDChartAxisParams::AxisPosLeft, yTitle ); + m_params->setAxisTitleFont( KDChartAxisParams::AxisPosBottom, xTitle ); + m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosLeft, yTitle.pointSize() ); + m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosBottom, xTitle.pointSize() ); +} + +} //KChart namespace diff --git a/kchart/kchartHeaderFooterConfigPage.cc b/kchart/kchartHeaderFooterConfigPage.cc deleted file mode 100644 index 8e11184e..00000000 --- a/kchart/kchartHeaderFooterConfigPage.cc +++ /dev/null @@ -1,182 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartHeaderFooterConfigPage.h" -#include "kchartHeaderFooterConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartHeaderFooterConfigPage::KChartHeaderFooterConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - TQGridLayout* layout = new TQGridLayout( this, 4, 3 ); - layout->setSpacing( KDialog::spacingHint() ); - layout->setMargin( KDialog::marginHint() ); - - TQLabel *lab=new TQLabel(i18n("Title:"), this); - TQWhatsThis::add(lab, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart.")); - layout->addWidget(lab,0,0); - - titleEdit=new TQLineEdit(this); - TQWhatsThis::add(titleEdit, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart.")); - layout->addWidget(titleEdit,0,1); - - titleColorButton=new KColorButton(this); - TQWhatsThis::add(titleColorButton, i18n("Click on this button to choose the color for the title font.")); - layout->addWidget(titleColorButton,0,2); - - titleFontButton=new TQPushButton(i18n("Font..."),this); - TQWhatsThis::add(titleFontButton, i18n("Click on this button to choose the font family, style and size for the title.")); - layout->addWidget(titleFontButton,0,3); - connect( titleFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeTitleFont())); - - lab=new TQLabel(i18n("Subtitle:"),this); - TQWhatsThis::add(lab, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); - layout->addWidget(lab,1,0); - - subtitleEdit=new TQLineEdit(this); - TQWhatsThis::add(subtitleEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); - layout->addWidget(subtitleEdit,1,1); - - subtitleColorButton=new KColorButton(this); - TQWhatsThis::add(subtitleColorButton, i18n("Click on this button to choose the color for the subtitle font.")); - layout->addWidget(subtitleColorButton,1,2); - - subtitleFontButton=new TQPushButton(i18n("Font..."),this); - TQWhatsThis::add(subtitleFontButton, i18n("Click on this button to choose the font family, style and size for the subtitle.")); - layout->addWidget(subtitleFontButton,1,3); - connect( subtitleFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeSubtitleFont())); - - lab=new TQLabel(i18n("Footer:"),this); - TQWhatsThis::add(lab, i18n("Write here the footer of your chart if you want one. The footer will be centered at the bottom just below your chart.")); - layout->addWidget(lab,2,0); - - footerEdit=new TQLineEdit(this); - TQWhatsThis::add(footerEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); - layout->addWidget(footerEdit,2,1); - - footerColorButton=new KColorButton(this); - TQWhatsThis::add(footerColorButton, i18n("Click on this button to choose the color for the footer font.")); - layout->addWidget(footerColorButton,2,2); - - footerFontButton=new TQPushButton(i18n("Font..."),this); - TQWhatsThis::add(footerFontButton, i18n("Click on this button to choose the font family, style and size for the footer.")); - connect( footerFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeFooterFont())); - layout->addWidget(footerFontButton,2,3); - - layout->addItem( new TQSpacerItem( 5, 5, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 3, 0 ); - - layout->activate(); -} - -void KChartHeaderFooterConfigPage::init() -{ - titleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader ) ); - subtitleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader2 )); - footerColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosFooter ) ); - titleEdit->setText(_params->header1Text()); - subtitleEdit->setText(_params->header2Text()); - footerEdit->setText(_params->footerText()); - - - titleFont = _params->header1Font(); - titleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader) - ? TQButton::On - : TQButton::Off; - if( TQButton::On == titleFontIsRelative ) - titleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader) ); - - subtitleFont = _params->header2Font(); - subtitleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader2) - ? TQButton::On - : TQButton::Off; - if( TQButton::On == subtitleFontIsRelative ) - subtitleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader2) ); - - footerFont = _params->footerFont(); - footerFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosFooter) - ? TQButton::On - : TQButton::Off; - if( TQButton::On == footerFontIsRelative ) - footerFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosFooter) ); -} - - -void KChartHeaderFooterConfigPage::apply() -{ - _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader,titleColorButton->color() ); - _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader2,subtitleColorButton->color() ); - _params->setHeaderFooterColor( KDChartParams::HdFtPosFooter, footerColorButton->color() ); - - - _params->setHeader1Text(titleEdit->text()); - _params->setHeader2Text(subtitleEdit->text()); - _params->setFooterText(footerEdit->text()); - - - _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader, titleFont, - titleFontIsRelative, - titleFont.pointSize() ); - _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader2, subtitleFont, - subtitleFontIsRelative, - subtitleFont.pointSize() ); - _params->setHeaderFooterFont( KDChartParams::HdFtPosFooter, footerFont, - footerFontIsRelative, - footerFont.pointSize() ); -} - -void KChartHeaderFooterConfigPage::changeTitleFont() -{ - TQButton::ToggleState state = titleFontIsRelative; - if ( TDEFontDialog::getFont( titleFont,false,this, true,&state ) != TQDialog::Rejected - && TQButton::NoChange != state ) - titleFontIsRelative = state; -} - -void KChartHeaderFooterConfigPage::changeSubtitleFont() -{ - TQButton::ToggleState state = subtitleFontIsRelative; - if ( TDEFontDialog::getFont( subtitleFont,false,this, true,&state ) != TQDialog::Rejected - && TQButton::NoChange != state ) - subtitleFontIsRelative = state; -} - -void KChartHeaderFooterConfigPage::changeFooterFont() -{ - TQButton::ToggleState state = footerFontIsRelative; - if ( TDEFontDialog::getFont( footerFont,false,this, true,&state ) != TQDialog::Rejected - && TQButton::NoChange != state ) - footerFontIsRelative = state; -} - -} //KChart namespace diff --git a/kchart/kchartHeaderFooterConfigPage.cpp b/kchart/kchartHeaderFooterConfigPage.cpp new file mode 100644 index 00000000..8e11184e --- /dev/null +++ b/kchart/kchartHeaderFooterConfigPage.cpp @@ -0,0 +1,182 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartHeaderFooterConfigPage.h" +#include "kchartHeaderFooterConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartHeaderFooterConfigPage::KChartHeaderFooterConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + TQGridLayout* layout = new TQGridLayout( this, 4, 3 ); + layout->setSpacing( KDialog::spacingHint() ); + layout->setMargin( KDialog::marginHint() ); + + TQLabel *lab=new TQLabel(i18n("Title:"), this); + TQWhatsThis::add(lab, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart.")); + layout->addWidget(lab,0,0); + + titleEdit=new TQLineEdit(this); + TQWhatsThis::add(titleEdit, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart.")); + layout->addWidget(titleEdit,0,1); + + titleColorButton=new KColorButton(this); + TQWhatsThis::add(titleColorButton, i18n("Click on this button to choose the color for the title font.")); + layout->addWidget(titleColorButton,0,2); + + titleFontButton=new TQPushButton(i18n("Font..."),this); + TQWhatsThis::add(titleFontButton, i18n("Click on this button to choose the font family, style and size for the title.")); + layout->addWidget(titleFontButton,0,3); + connect( titleFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeTitleFont())); + + lab=new TQLabel(i18n("Subtitle:"),this); + TQWhatsThis::add(lab, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); + layout->addWidget(lab,1,0); + + subtitleEdit=new TQLineEdit(this); + TQWhatsThis::add(subtitleEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); + layout->addWidget(subtitleEdit,1,1); + + subtitleColorButton=new KColorButton(this); + TQWhatsThis::add(subtitleColorButton, i18n("Click on this button to choose the color for the subtitle font.")); + layout->addWidget(subtitleColorButton,1,2); + + subtitleFontButton=new TQPushButton(i18n("Font..."),this); + TQWhatsThis::add(subtitleFontButton, i18n("Click on this button to choose the font family, style and size for the subtitle.")); + layout->addWidget(subtitleFontButton,1,3); + connect( subtitleFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeSubtitleFont())); + + lab=new TQLabel(i18n("Footer:"),this); + TQWhatsThis::add(lab, i18n("Write here the footer of your chart if you want one. The footer will be centered at the bottom just below your chart.")); + layout->addWidget(lab,2,0); + + footerEdit=new TQLineEdit(this); + TQWhatsThis::add(footerEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title.")); + layout->addWidget(footerEdit,2,1); + + footerColorButton=new KColorButton(this); + TQWhatsThis::add(footerColorButton, i18n("Click on this button to choose the color for the footer font.")); + layout->addWidget(footerColorButton,2,2); + + footerFontButton=new TQPushButton(i18n("Font..."),this); + TQWhatsThis::add(footerFontButton, i18n("Click on this button to choose the font family, style and size for the footer.")); + connect( footerFontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeFooterFont())); + layout->addWidget(footerFontButton,2,3); + + layout->addItem( new TQSpacerItem( 5, 5, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 3, 0 ); + + layout->activate(); +} + +void KChartHeaderFooterConfigPage::init() +{ + titleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader ) ); + subtitleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader2 )); + footerColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosFooter ) ); + titleEdit->setText(_params->header1Text()); + subtitleEdit->setText(_params->header2Text()); + footerEdit->setText(_params->footerText()); + + + titleFont = _params->header1Font(); + titleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader) + ? TQButton::On + : TQButton::Off; + if( TQButton::On == titleFontIsRelative ) + titleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader) ); + + subtitleFont = _params->header2Font(); + subtitleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader2) + ? TQButton::On + : TQButton::Off; + if( TQButton::On == subtitleFontIsRelative ) + subtitleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader2) ); + + footerFont = _params->footerFont(); + footerFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosFooter) + ? TQButton::On + : TQButton::Off; + if( TQButton::On == footerFontIsRelative ) + footerFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosFooter) ); +} + + +void KChartHeaderFooterConfigPage::apply() +{ + _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader,titleColorButton->color() ); + _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader2,subtitleColorButton->color() ); + _params->setHeaderFooterColor( KDChartParams::HdFtPosFooter, footerColorButton->color() ); + + + _params->setHeader1Text(titleEdit->text()); + _params->setHeader2Text(subtitleEdit->text()); + _params->setFooterText(footerEdit->text()); + + + _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader, titleFont, + titleFontIsRelative, + titleFont.pointSize() ); + _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader2, subtitleFont, + subtitleFontIsRelative, + subtitleFont.pointSize() ); + _params->setHeaderFooterFont( KDChartParams::HdFtPosFooter, footerFont, + footerFontIsRelative, + footerFont.pointSize() ); +} + +void KChartHeaderFooterConfigPage::changeTitleFont() +{ + TQButton::ToggleState state = titleFontIsRelative; + if ( TDEFontDialog::getFont( titleFont,false,this, true,&state ) != TQDialog::Rejected + && TQButton::NoChange != state ) + titleFontIsRelative = state; +} + +void KChartHeaderFooterConfigPage::changeSubtitleFont() +{ + TQButton::ToggleState state = subtitleFontIsRelative; + if ( TDEFontDialog::getFont( subtitleFont,false,this, true,&state ) != TQDialog::Rejected + && TQButton::NoChange != state ) + subtitleFontIsRelative = state; +} + +void KChartHeaderFooterConfigPage::changeFooterFont() +{ + TQButton::ToggleState state = footerFontIsRelative; + if ( TDEFontDialog::getFont( footerFont,false,this, true,&state ) != TQDialog::Rejected + && TQButton::NoChange != state ) + footerFontIsRelative = state; +} + +} //KChart namespace diff --git a/kchart/kchartLegendConfigPage.cc b/kchart/kchartLegendConfigPage.cc deleted file mode 100644 index dc18d717..00000000 --- a/kchart/kchartLegendConfigPage.cc +++ /dev/null @@ -1,385 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartLegendConfigPage.h" -#include "kchartLegendConfigPage.moc" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" -#include "kchart_factory.h" - -#include "KDFrameProfileSection.h" - - -namespace KChart -{ - - -KChartLegendConfigPage::KChartLegendConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - //Layout for 4 blocks - TQGridLayout* layout = new TQGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() ); - - //1. Block: General settings - TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, i18n("General"), this ); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - layout->addWidget( gb, 0, 0 ); - - TQGridLayout *grid2 = new TQGridLayout( gb->layout(), 4, 2 ); - - TQLabel* lab = new TQLabel( i18n("Title:"), gb ); - TQWhatsThis::add(lab, i18n("Write here the title of the legend, which is displayed at the top of the legend box.")); - grid2->addWidget( lab, 0, 0 ); - - title = new TQLineEdit( gb ); - grid2->addWidget( title, 0, 1 ); - - // 2. Block: Legend position - gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Legend Position"), this ); - TQWhatsThis::add(gb, i18n("Choose the location of the legend on the chart by " - "clicking a location button.\nUse the central button to hide the legend.")); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - gb->setExclusive( true ); - - TQGridLayout *grid1 = new TQGridLayout( gb->layout(), 5, 5 ); - - lTopLeft = addButton( grid1, gb, i18n("Top-Left"), "chart_legend_topleft", 0, 0 ); - lTopLeftTop = addButton( grid1, gb, i18n("Top-Left-Top"), "chart_legend_toplefttop", 0, 1 ); - lTop = addButton( grid1, gb, i18n("Top"), "chart_legend_top", 0, 2 ); - lTopRightTop = addButton( grid1, gb, i18n("Top-Right-Top"), "chart_legend_toprighttop", 0, 3 ); - lTopRight = addButton( grid1, gb, i18n("Top-Right"), "chart_legend_topright", 0, 4 ); - - lTopLeftLeft = addButton( grid1, gb, i18n("Top-Left-Left"), "chart_legend_topleftleft", 1, 0 ); - lTopRightRight = addButton( grid1, gb, i18n("Top-Right-Right"), "chart_legend_toprightright", 1, 4 ); - - lLeft = addButton( grid1, gb, i18n("Left"), "chart_legend_left", 2, 0 ); - noLegend = addButton( grid1, gb, i18n("No Legend"), "chart_legend_nolegend", 2, 2 ); - lRight = addButton( grid1, gb, i18n("Right"), "chart_legend_right", 2, 4 ); - - lBottomLeftLeft = addButton( grid1, gb, i18n("Bottom-Left-Left"), "chart_legend_bottomleftleft", 3, 0 ); - lBottomRightRight = addButton( grid1, gb, i18n("Bottom-Right-Right"), "chart_legend_bottomrightright", 3, 4 ); - - lBottomLeft = addButton( grid1, gb, i18n("Bottom-Left"), "chart_legend_bottomleft", 4, 0 ); - lBottomLeftBottom = addButton( grid1, gb, i18n("Bottom-Left-Bottom"), "chart_legend_bottomleftbottom", 4, 1 ); - lBottom = addButton( grid1, gb, i18n("Bottom"), "chart_legend_bottom", 4, 2 ); - lBottomRightBottom= addButton( grid1, gb, i18n("Bottom-Right-Bottom"), "chart_legend_bottomrightbottom",4, 3 ); - lBottomRight = addButton( grid1, gb, i18n("Bottom-Right"), "chart_legend_bottomright", 4, 4 ); - - gb->setAlignment( TQt::AlignLeft ); - layout->addMultiCellWidget( gb, 1,2, 0,0 ); - - // 3. Block: Font - gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Font"), this ); - TQWhatsThis::add(gb, i18n("This Font box can be used to set different fonts for the legend title and the individual entries.")); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - layout->addWidget( gb, 0, 1 ); - - TQGridLayout *grid4 = new TQGridLayout( gb->layout(), 4, 2 ); - titleLegendFontButton = new TQPushButton( gb ); - - lab = new TQLabel( i18n("Legend title font:"), gb ); - grid4->addWidget( lab, 0 ,0 ); - - titleLegendFontButton->setText( i18n("Select Font...") ); - TQWhatsThis::add(titleLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend title.")); - grid4->addWidget( titleLegendFontButton, 1, 0 ); - - lab = new TQLabel( i18n("Legend text font:"), gb ); - grid4->addWidget( lab, 2, 0 ); - textLegendFontButton = new TQPushButton( gb ); - textLegendFontButton->setText( i18n("Select Font...") ); - TQWhatsThis::add(textLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend text.")); - grid4->addWidget( textLegendFontButton, 3, 0 ); - - connect( titleLegendFontButton, TQT_SIGNAL(clicked()), - this, TQT_SLOT(changeTitleLegendFont())); - connect( textLegendFontButton, TQT_SIGNAL(clicked()), - this, TQT_SLOT(changeTextLegendFont())); - - // 4. Block: Qt::Orientation - orientationGroup = new TQVButtonGroup( i18n("Orientation"), this ); - TQWhatsThis::add(orientationGroup, i18n("Select, if the legend's items should be drawn next to each other, or below each other.")); - orientationGroup->setRadioButtonExclusive(true); - orientationGroup->layout()->setSpacing(KDialog::spacingHint()); - orientationGroup->layout()->setMargin(KDialog::marginHint()); - layout->addWidget( orientationGroup, 1, 1 ); - - TQRadioButton* orientation = new TQRadioButton( i18n("Vertically"), orientationGroup ); - orientation = new TQRadioButton( i18n("Horizontally"), orientationGroup ); - Q_UNUSED(orientation); - - // 5. Block: Text Colors - gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Color"), this ); - TQWhatsThis::add(gb, i18n("This Color box can be used to set different colors for the legend title and text.")); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - layout->addWidget( gb, 2, 1 ); - - TQGridLayout *grid3 = new TQGridLayout( gb->layout(), 6, 2 ); - - lab = new TQLabel( i18n("Legend title color:"), gb ); - grid3->addWidget( lab, 0, 0 ); - - legendTitleColor = new KColorButton( gb ); - TQWhatsThis::add(legendTitleColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend title.")); - grid3->addWidget( legendTitleColor, 1, 0 ); - - - lab = new TQLabel( i18n("Legend text color:"), gb ); - grid3->addWidget( lab, 2, 0 ); - - legendTextColor = new KColorButton( gb ); - TQWhatsThis::add(legendTextColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend text.")); - grid3->addWidget( legendTextColor, 3, 0 ); - - - lab = new TQLabel( i18n("Legend frame color:"), gb ); - grid3->addWidget( lab, 4, 0 ); - - legendFrameColor = new KColorButton( gb ); - TQWhatsThis::add(legendFrameColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend frame.")); - - grid3->addWidget( legendFrameColor, 5, 0 ); - - //it's not good but I don't know how - //to reduce space - layout->addColSpacing( 1, 300 ); -} - -void KChartLegendConfigPage::init() -{ - switch( _params->legendPosition()) - { - case KDChartParams::NoLegend: - noLegend->setOn( true ); - break; - case KDChartParams::LegendTop: - lTop->setOn( true ); - break; - case KDChartParams::LegendBottom: - lBottom->setOn( true ); - break; - case KDChartParams::LegendLeft: - lLeft->setOn( true ); - break; - case KDChartParams::LegendRight: - lRight->setOn( true ); - break; - case KDChartParams::LegendTopLeft: - lTopLeft->setOn( true ); - break; - case KDChartParams::LegendTopLeftTop: - lTopLeftTop->setOn( true ); - break; - case KDChartParams::LegendTopLeftLeft: - lTopLeftLeft->setOn( true ); - break; - case KDChartParams::LegendTopRight: - lTopRight->setOn( true ); - break; - case KDChartParams::LegendTopRightTop: - lTopRightTop->setOn( true ); - break; - case KDChartParams::LegendTopRightRight: - lTopRightRight->setOn( true ); - break; - case KDChartParams::LegendBottomRight: - lBottomRight->setOn( true ); - break; - case KDChartParams::LegendBottomRightBottom: - lBottomRightBottom->setOn( true ); - break; - case KDChartParams::LegendBottomRightRight: - lBottomRightRight->setOn( true ); - break; - case KDChartParams::LegendBottomLeft: - lBottomLeft->setOn( true ); - break; - case KDChartParams::LegendBottomLeftBottom: - lBottomLeftBottom->setOn( true ); - break; - case KDChartParams::LegendBottomLeftLeft: - lBottomLeftLeft->setOn( true ); - break; - default: - lRight->setOn( true ); - break; - } - - title->setText(_params->legendTitleText()); - - legendTitleColor->setColor(_params->legendTitleTextColor()); - - legendTextColor->setColor(_params->legendTextColor()); - - TQColor frameColor(TQt::black); - bool bFound; - const KDChartParams::KDChartFrameSettings * legendFrame = - _params->frameSettings( KDChartEnums::AreaLegend, bFound ); - if( bFound ) - { - const KDFrameProfileSection * top = - const_cast(legendFrame->frame().profile( KDFrame::ProfileTop )).first(); - if( top ) - frameColor = top->pen().color(); - } - legendFrameColor->setColor(frameColor); - - if( _params->legendOrientation() == Qt::Vertical ) - orientationGroup->setButton(0); - else - orientationGroup->setButton(1); - - titleLegend = _params->legendTitleFont(); - titleLegendIsRelative = _params->legendTitleFontUseRelSize() - ? TQButton::On - : TQButton::Off; - if( TQButton::On == titleLegendIsRelative ) - titleLegend.setPointSize( _params->legendTitleFontRelSize() ); - - textLegend=_params->legendFont(); - textLegendIsRelative = _params->legendFontUseRelSize() - ? TQButton::On - : TQButton::Off; - if( TQButton::On == textLegendIsRelative ) - textLegend.setPointSize(_params->legendFontRelSize()); -} - -void KChartLegendConfigPage::changeTitleLegendFont() -{ - TQButton::ToggleState state = titleLegendIsRelative; - if ( TDEFontDialog::getFont( titleLegend,false,this, true,&state ) != TQDialog::Rejected - && TQButton::NoChange != state ) - titleLegendIsRelative = state; -} - -void KChartLegendConfigPage::changeTextLegendFont() -{ - TQButton::ToggleState state = textLegendIsRelative; - if ( TDEFontDialog::getFont( textLegend,false,this, true,&state ) != TQDialog::Rejected - && TQButton::NoChange != state ) - textLegendIsRelative = state; -} - -void KChartLegendConfigPage::apply() -{ - if( noLegend->isOn() ) - _params->setLegendPosition( KDChartParams::NoLegend ); - else if( lTop->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTop ); - else if( lBottom->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottom ); - else if( lLeft->isOn() ) - _params->setLegendPosition( KDChartParams::LegendLeft ); - else if( lRight->isOn() ) - _params->setLegendPosition( KDChartParams::LegendRight ); - else if( lTopLeft->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopLeft ); - else if( lTopLeftTop->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopLeftTop ); - else if( lTopLeftLeft->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopLeftLeft ); - else if( lTopRight->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopRight ); - else if( lTopRightTop->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopRightTop ); - else if( lTopRightRight->isOn() ) - _params->setLegendPosition( KDChartParams::LegendTopRightRight ); - else if( lBottomRight->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomRight ); - else if( lBottomRightBottom->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomRightBottom ); - else if( lBottomRightRight->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomRightRight ); - else if( lBottomLeft->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomLeft ); - else if( lBottomLeftBottom->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomLeftBottom ); - else if( lBottomLeftLeft->isOn() ) - _params->setLegendPosition( KDChartParams::LegendBottomLeftLeft ); - else - _params->setLegendPosition( KDChartParams::LegendRight ); - - if( orientationGroup->selectedId() == 0 ) - _params->setLegendOrientation( Qt::Vertical ); - else - _params->setLegendOrientation( Qt::Horizontal ); - - _params->setLegendTitleText(title->text()); - _params->setLegendTitleTextColor(legendTitleColor->color()); - _params->setLegendTextColor(legendTextColor->color()); - - const TQColor frameColor(legendFrameColor->color()); - if( frameColor == TQt::black ) - _params->removeFrame( KDChartEnums::AreaLegend ); - else - _params->setSimpleFrame( KDChartEnums::AreaLegend, - 0,0, 0,0, - true, - true, - KDFrame::FrameFlat, - 1, - 0, - frameColor ); - - _params->setLegendTitleFont(titleLegend, TQButton::Off == titleLegendIsRelative); - if( TQButton::On == titleLegendIsRelative ) - _params->setLegendTitleFontRelSize(titleLegend.pointSize()); - _params->setLegendFont(textLegend, TQButton::Off == textLegendIsRelative); - if( TQButton::On == textLegendIsRelative ) - _params->setLegendFontRelSize(textLegend.pointSize()); -} - -TQPushButton* KChartLegendConfigPage::addButton( TQGridLayout* layout, - TQButtonGroup* gb, - const TQString &toolTipText, - const TQString &icon, - int posY, - int posX ) -{ - TQPushButton* button = new TQPushButton( gb ); - button->setToggleButton( true ); - button->setPixmap( BarIcon( icon, - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global() ) ); - TQToolTip::add( button, toolTipText ); - layout->addWidget( button, posY, posX ); - return button; -} - -} //KChart namespace diff --git a/kchart/kchartLegendConfigPage.cpp b/kchart/kchartLegendConfigPage.cpp new file mode 100644 index 00000000..dc18d717 --- /dev/null +++ b/kchart/kchartLegendConfigPage.cpp @@ -0,0 +1,385 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartLegendConfigPage.h" +#include "kchartLegendConfigPage.moc" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" +#include "kchart_factory.h" + +#include "KDFrameProfileSection.h" + + +namespace KChart +{ + + +KChartLegendConfigPage::KChartLegendConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + //Layout for 4 blocks + TQGridLayout* layout = new TQGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() ); + + //1. Block: General settings + TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, i18n("General"), this ); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + layout->addWidget( gb, 0, 0 ); + + TQGridLayout *grid2 = new TQGridLayout( gb->layout(), 4, 2 ); + + TQLabel* lab = new TQLabel( i18n("Title:"), gb ); + TQWhatsThis::add(lab, i18n("Write here the title of the legend, which is displayed at the top of the legend box.")); + grid2->addWidget( lab, 0, 0 ); + + title = new TQLineEdit( gb ); + grid2->addWidget( title, 0, 1 ); + + // 2. Block: Legend position + gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Legend Position"), this ); + TQWhatsThis::add(gb, i18n("Choose the location of the legend on the chart by " + "clicking a location button.\nUse the central button to hide the legend.")); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + gb->setExclusive( true ); + + TQGridLayout *grid1 = new TQGridLayout( gb->layout(), 5, 5 ); + + lTopLeft = addButton( grid1, gb, i18n("Top-Left"), "chart_legend_topleft", 0, 0 ); + lTopLeftTop = addButton( grid1, gb, i18n("Top-Left-Top"), "chart_legend_toplefttop", 0, 1 ); + lTop = addButton( grid1, gb, i18n("Top"), "chart_legend_top", 0, 2 ); + lTopRightTop = addButton( grid1, gb, i18n("Top-Right-Top"), "chart_legend_toprighttop", 0, 3 ); + lTopRight = addButton( grid1, gb, i18n("Top-Right"), "chart_legend_topright", 0, 4 ); + + lTopLeftLeft = addButton( grid1, gb, i18n("Top-Left-Left"), "chart_legend_topleftleft", 1, 0 ); + lTopRightRight = addButton( grid1, gb, i18n("Top-Right-Right"), "chart_legend_toprightright", 1, 4 ); + + lLeft = addButton( grid1, gb, i18n("Left"), "chart_legend_left", 2, 0 ); + noLegend = addButton( grid1, gb, i18n("No Legend"), "chart_legend_nolegend", 2, 2 ); + lRight = addButton( grid1, gb, i18n("Right"), "chart_legend_right", 2, 4 ); + + lBottomLeftLeft = addButton( grid1, gb, i18n("Bottom-Left-Left"), "chart_legend_bottomleftleft", 3, 0 ); + lBottomRightRight = addButton( grid1, gb, i18n("Bottom-Right-Right"), "chart_legend_bottomrightright", 3, 4 ); + + lBottomLeft = addButton( grid1, gb, i18n("Bottom-Left"), "chart_legend_bottomleft", 4, 0 ); + lBottomLeftBottom = addButton( grid1, gb, i18n("Bottom-Left-Bottom"), "chart_legend_bottomleftbottom", 4, 1 ); + lBottom = addButton( grid1, gb, i18n("Bottom"), "chart_legend_bottom", 4, 2 ); + lBottomRightBottom= addButton( grid1, gb, i18n("Bottom-Right-Bottom"), "chart_legend_bottomrightbottom",4, 3 ); + lBottomRight = addButton( grid1, gb, i18n("Bottom-Right"), "chart_legend_bottomright", 4, 4 ); + + gb->setAlignment( TQt::AlignLeft ); + layout->addMultiCellWidget( gb, 1,2, 0,0 ); + + // 3. Block: Font + gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Font"), this ); + TQWhatsThis::add(gb, i18n("This Font box can be used to set different fonts for the legend title and the individual entries.")); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + layout->addWidget( gb, 0, 1 ); + + TQGridLayout *grid4 = new TQGridLayout( gb->layout(), 4, 2 ); + titleLegendFontButton = new TQPushButton( gb ); + + lab = new TQLabel( i18n("Legend title font:"), gb ); + grid4->addWidget( lab, 0 ,0 ); + + titleLegendFontButton->setText( i18n("Select Font...") ); + TQWhatsThis::add(titleLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend title.")); + grid4->addWidget( titleLegendFontButton, 1, 0 ); + + lab = new TQLabel( i18n("Legend text font:"), gb ); + grid4->addWidget( lab, 2, 0 ); + textLegendFontButton = new TQPushButton( gb ); + textLegendFontButton->setText( i18n("Select Font...") ); + TQWhatsThis::add(textLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend text.")); + grid4->addWidget( textLegendFontButton, 3, 0 ); + + connect( titleLegendFontButton, TQT_SIGNAL(clicked()), + this, TQT_SLOT(changeTitleLegendFont())); + connect( textLegendFontButton, TQT_SIGNAL(clicked()), + this, TQT_SLOT(changeTextLegendFont())); + + // 4. Block: Qt::Orientation + orientationGroup = new TQVButtonGroup( i18n("Orientation"), this ); + TQWhatsThis::add(orientationGroup, i18n("Select, if the legend's items should be drawn next to each other, or below each other.")); + orientationGroup->setRadioButtonExclusive(true); + orientationGroup->layout()->setSpacing(KDialog::spacingHint()); + orientationGroup->layout()->setMargin(KDialog::marginHint()); + layout->addWidget( orientationGroup, 1, 1 ); + + TQRadioButton* orientation = new TQRadioButton( i18n("Vertically"), orientationGroup ); + orientation = new TQRadioButton( i18n("Horizontally"), orientationGroup ); + Q_UNUSED(orientation); + + // 5. Block: Text Colors + gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Color"), this ); + TQWhatsThis::add(gb, i18n("This Color box can be used to set different colors for the legend title and text.")); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + layout->addWidget( gb, 2, 1 ); + + TQGridLayout *grid3 = new TQGridLayout( gb->layout(), 6, 2 ); + + lab = new TQLabel( i18n("Legend title color:"), gb ); + grid3->addWidget( lab, 0, 0 ); + + legendTitleColor = new KColorButton( gb ); + TQWhatsThis::add(legendTitleColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend title.")); + grid3->addWidget( legendTitleColor, 1, 0 ); + + + lab = new TQLabel( i18n("Legend text color:"), gb ); + grid3->addWidget( lab, 2, 0 ); + + legendTextColor = new KColorButton( gb ); + TQWhatsThis::add(legendTextColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend text.")); + grid3->addWidget( legendTextColor, 3, 0 ); + + + lab = new TQLabel( i18n("Legend frame color:"), gb ); + grid3->addWidget( lab, 4, 0 ); + + legendFrameColor = new KColorButton( gb ); + TQWhatsThis::add(legendFrameColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend frame.")); + + grid3->addWidget( legendFrameColor, 5, 0 ); + + //it's not good but I don't know how + //to reduce space + layout->addColSpacing( 1, 300 ); +} + +void KChartLegendConfigPage::init() +{ + switch( _params->legendPosition()) + { + case KDChartParams::NoLegend: + noLegend->setOn( true ); + break; + case KDChartParams::LegendTop: + lTop->setOn( true ); + break; + case KDChartParams::LegendBottom: + lBottom->setOn( true ); + break; + case KDChartParams::LegendLeft: + lLeft->setOn( true ); + break; + case KDChartParams::LegendRight: + lRight->setOn( true ); + break; + case KDChartParams::LegendTopLeft: + lTopLeft->setOn( true ); + break; + case KDChartParams::LegendTopLeftTop: + lTopLeftTop->setOn( true ); + break; + case KDChartParams::LegendTopLeftLeft: + lTopLeftLeft->setOn( true ); + break; + case KDChartParams::LegendTopRight: + lTopRight->setOn( true ); + break; + case KDChartParams::LegendTopRightTop: + lTopRightTop->setOn( true ); + break; + case KDChartParams::LegendTopRightRight: + lTopRightRight->setOn( true ); + break; + case KDChartParams::LegendBottomRight: + lBottomRight->setOn( true ); + break; + case KDChartParams::LegendBottomRightBottom: + lBottomRightBottom->setOn( true ); + break; + case KDChartParams::LegendBottomRightRight: + lBottomRightRight->setOn( true ); + break; + case KDChartParams::LegendBottomLeft: + lBottomLeft->setOn( true ); + break; + case KDChartParams::LegendBottomLeftBottom: + lBottomLeftBottom->setOn( true ); + break; + case KDChartParams::LegendBottomLeftLeft: + lBottomLeftLeft->setOn( true ); + break; + default: + lRight->setOn( true ); + break; + } + + title->setText(_params->legendTitleText()); + + legendTitleColor->setColor(_params->legendTitleTextColor()); + + legendTextColor->setColor(_params->legendTextColor()); + + TQColor frameColor(TQt::black); + bool bFound; + const KDChartParams::KDChartFrameSettings * legendFrame = + _params->frameSettings( KDChartEnums::AreaLegend, bFound ); + if( bFound ) + { + const KDFrameProfileSection * top = + const_cast(legendFrame->frame().profile( KDFrame::ProfileTop )).first(); + if( top ) + frameColor = top->pen().color(); + } + legendFrameColor->setColor(frameColor); + + if( _params->legendOrientation() == Qt::Vertical ) + orientationGroup->setButton(0); + else + orientationGroup->setButton(1); + + titleLegend = _params->legendTitleFont(); + titleLegendIsRelative = _params->legendTitleFontUseRelSize() + ? TQButton::On + : TQButton::Off; + if( TQButton::On == titleLegendIsRelative ) + titleLegend.setPointSize( _params->legendTitleFontRelSize() ); + + textLegend=_params->legendFont(); + textLegendIsRelative = _params->legendFontUseRelSize() + ? TQButton::On + : TQButton::Off; + if( TQButton::On == textLegendIsRelative ) + textLegend.setPointSize(_params->legendFontRelSize()); +} + +void KChartLegendConfigPage::changeTitleLegendFont() +{ + TQButton::ToggleState state = titleLegendIsRelative; + if ( TDEFontDialog::getFont( titleLegend,false,this, true,&state ) != TQDialog::Rejected + && TQButton::NoChange != state ) + titleLegendIsRelative = state; +} + +void KChartLegendConfigPage::changeTextLegendFont() +{ + TQButton::ToggleState state = textLegendIsRelative; + if ( TDEFontDialog::getFont( textLegend,false,this, true,&state ) != TQDialog::Rejected + && TQButton::NoChange != state ) + textLegendIsRelative = state; +} + +void KChartLegendConfigPage::apply() +{ + if( noLegend->isOn() ) + _params->setLegendPosition( KDChartParams::NoLegend ); + else if( lTop->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTop ); + else if( lBottom->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottom ); + else if( lLeft->isOn() ) + _params->setLegendPosition( KDChartParams::LegendLeft ); + else if( lRight->isOn() ) + _params->setLegendPosition( KDChartParams::LegendRight ); + else if( lTopLeft->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopLeft ); + else if( lTopLeftTop->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopLeftTop ); + else if( lTopLeftLeft->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopLeftLeft ); + else if( lTopRight->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopRight ); + else if( lTopRightTop->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopRightTop ); + else if( lTopRightRight->isOn() ) + _params->setLegendPosition( KDChartParams::LegendTopRightRight ); + else if( lBottomRight->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomRight ); + else if( lBottomRightBottom->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomRightBottom ); + else if( lBottomRightRight->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomRightRight ); + else if( lBottomLeft->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomLeft ); + else if( lBottomLeftBottom->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomLeftBottom ); + else if( lBottomLeftLeft->isOn() ) + _params->setLegendPosition( KDChartParams::LegendBottomLeftLeft ); + else + _params->setLegendPosition( KDChartParams::LegendRight ); + + if( orientationGroup->selectedId() == 0 ) + _params->setLegendOrientation( Qt::Vertical ); + else + _params->setLegendOrientation( Qt::Horizontal ); + + _params->setLegendTitleText(title->text()); + _params->setLegendTitleTextColor(legendTitleColor->color()); + _params->setLegendTextColor(legendTextColor->color()); + + const TQColor frameColor(legendFrameColor->color()); + if( frameColor == TQt::black ) + _params->removeFrame( KDChartEnums::AreaLegend ); + else + _params->setSimpleFrame( KDChartEnums::AreaLegend, + 0,0, 0,0, + true, + true, + KDFrame::FrameFlat, + 1, + 0, + frameColor ); + + _params->setLegendTitleFont(titleLegend, TQButton::Off == titleLegendIsRelative); + if( TQButton::On == titleLegendIsRelative ) + _params->setLegendTitleFontRelSize(titleLegend.pointSize()); + _params->setLegendFont(textLegend, TQButton::Off == textLegendIsRelative); + if( TQButton::On == textLegendIsRelative ) + _params->setLegendFontRelSize(textLegend.pointSize()); +} + +TQPushButton* KChartLegendConfigPage::addButton( TQGridLayout* layout, + TQButtonGroup* gb, + const TQString &toolTipText, + const TQString &icon, + int posY, + int posX ) +{ + TQPushButton* button = new TQPushButton( gb ); + button->setToggleButton( true ); + button->setPixmap( BarIcon( icon, + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global() ) ); + TQToolTip::add( button, toolTipText ); + layout->addWidget( button, posY, posX ); + return button; +} + +} //KChart namespace diff --git a/kchart/kchartLine3dConfigPage.cc b/kchart/kchartLine3dConfigPage.cc deleted file mode 100644 index f3750f73..00000000 --- a/kchart/kchartLine3dConfigPage.cc +++ /dev/null @@ -1,151 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000,2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartLine3dConfigPage.h" -#include "kchartLine3dConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartLine3dConfigPage::KChartLine3dConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - TQGridLayout *grid1 = new TQGridLayout(this,8,3,KDialog::marginHint(), KDialog::spacingHint()); - -#if 0 - // The 3D line on/off button. - line3d=new TQCheckBox(i18n("3D lines"),this); - grid1->addWidget(line3d,1,0); - - connect(line3d, TQT_SIGNAL(toggled ( bool )), - this, TQT_SLOT(slotChange3DParameter(bool))); -#endif - - // The line width label and input. - TQLabel *tmpLabel = new TQLabel( i18n( "Line width:" ), this ); - grid1->addWidget(tmpLabel,2,0); - lineWidth=new KIntNumInput(0, this, 10); - TQWhatsThis::add(lineWidth, i18n("You can set here the line width for your chart. Default is 1.")); - grid1->addWidget(lineWidth,2,1); - - lineMarkers = new TQCheckBox( i18n( "Line markers" ), this ); - TQWhatsThis::add(lineMarkers, i18n("Check this option if you want to add dots on your chart as markers.")); - grid1->addWidget(lineMarkers, 3, 0); - -#if 0 - // The "Draw shadow color" checkbox - drawShadowColor=new TQCheckBox(i18n("Draw shadow color"),this); - grid1->addWidget(drawShadowColor,3,0); - - tmpLabel = new TQLabel( i18n( "Rotation around the X-axis in degrees:" ), - this ); - tmpLabel->resize( tmpLabel->sizeHint() ); - grid1->addWidget(tmpLabel,4,0); - - angle3dX=new KIntNumInput(0, this, 10); - grid1->addWidget(angle3dX,4,1); - angle3dX->setRange(0, 90, 1); - - tmpLabel = new TQLabel( i18n( "Rotation around the Y-axis in degrees:" ), this ); - tmpLabel->resize( tmpLabel->sizeHint() ); - grid1->addWidget(tmpLabel,5,0); - - angle3dY=new KIntNumInput(0, this, 10); - grid1->addWidget(angle3dY,5,1); - angle3dY->setRange(0, 90, 1); - - - tmpLabel = new TQLabel( i18n( "Depth:" ), this ); - tmpLabel->resize( tmpLabel->sizeHint() ); - grid1->addWidget(tmpLabel,6,0); - - depth=new KDoubleNumInput(0, this); - depth->resize(100,depth->sizeHint().height()); - grid1->addWidget(depth,6,1); - depth->setRange(0,40, 0.1); -#endif -#if 0 - grid1->addColSpacing(0,depth->width()); - grid1->addColSpacing(0,angle3dX->width()); -#endif - grid1->setColStretch(2,1); - grid1->setRowStretch(7,1); - grid1->activate(); - //it's not good but I don't know how - //to reduce space - //layout->addColSpacing(1,300); -} - -void KChartLine3dConfigPage::slotChange3DParameter(bool b) -{ -#if 0 - angle3dX->setEnabled(b); - angle3dY->setEnabled(b); - depth->setEnabled(b); - drawShadowColor->setEnabled(b); -#endif - lineWidth->setEnabled(!b); -} - - -void KChartLine3dConfigPage::init() -{ -#if 0 - bool state=_params->threeDLines(); - line3d->setChecked(state); - - angle3dX->setValue( _params->threeDLineXRotation() ); - angle3dY->setValue( _params->threeDLineYRotation() ); - depth->setValue( _params->threeDLineDepth() ); - drawShadowColor->setChecked(_params->threeDShadowColors()); -#endif - lineWidth->setValue(_params->lineWidth()); - lineMarkers->setChecked(_params->lineMarker()); -#if 0 - slotChange3DParameter(state); -#endif -} - -void KChartLine3dConfigPage::apply() -{ -#if 0 - _params->setThreeDLines(line3d->isChecked()); - _params->setThreeDLineXRotation( angle3dX->value() ); - _params->setThreeDLineYRotation( angle3dY->value() ); - _params->setThreeDLineDepth( static_cast( depth->value() ) ); - _params->setThreeDShadowColors( drawShadowColor->isChecked()); -#endif - _params->setLineWidth( lineWidth->value() ); - _params->setLineMarker(lineMarkers->isChecked()); -} - - -} //KChart namespace diff --git a/kchart/kchartLine3dConfigPage.cpp b/kchart/kchartLine3dConfigPage.cpp new file mode 100644 index 00000000..f3750f73 --- /dev/null +++ b/kchart/kchartLine3dConfigPage.cpp @@ -0,0 +1,151 @@ +/* This file is part of the KDE project + Copyright (C) 2000,2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartLine3dConfigPage.h" +#include "kchartLine3dConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartLine3dConfigPage::KChartLine3dConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + TQGridLayout *grid1 = new TQGridLayout(this,8,3,KDialog::marginHint(), KDialog::spacingHint()); + +#if 0 + // The 3D line on/off button. + line3d=new TQCheckBox(i18n("3D lines"),this); + grid1->addWidget(line3d,1,0); + + connect(line3d, TQT_SIGNAL(toggled ( bool )), + this, TQT_SLOT(slotChange3DParameter(bool))); +#endif + + // The line width label and input. + TQLabel *tmpLabel = new TQLabel( i18n( "Line width:" ), this ); + grid1->addWidget(tmpLabel,2,0); + lineWidth=new KIntNumInput(0, this, 10); + TQWhatsThis::add(lineWidth, i18n("You can set here the line width for your chart. Default is 1.")); + grid1->addWidget(lineWidth,2,1); + + lineMarkers = new TQCheckBox( i18n( "Line markers" ), this ); + TQWhatsThis::add(lineMarkers, i18n("Check this option if you want to add dots on your chart as markers.")); + grid1->addWidget(lineMarkers, 3, 0); + +#if 0 + // The "Draw shadow color" checkbox + drawShadowColor=new TQCheckBox(i18n("Draw shadow color"),this); + grid1->addWidget(drawShadowColor,3,0); + + tmpLabel = new TQLabel( i18n( "Rotation around the X-axis in degrees:" ), + this ); + tmpLabel->resize( tmpLabel->sizeHint() ); + grid1->addWidget(tmpLabel,4,0); + + angle3dX=new KIntNumInput(0, this, 10); + grid1->addWidget(angle3dX,4,1); + angle3dX->setRange(0, 90, 1); + + tmpLabel = new TQLabel( i18n( "Rotation around the Y-axis in degrees:" ), this ); + tmpLabel->resize( tmpLabel->sizeHint() ); + grid1->addWidget(tmpLabel,5,0); + + angle3dY=new KIntNumInput(0, this, 10); + grid1->addWidget(angle3dY,5,1); + angle3dY->setRange(0, 90, 1); + + + tmpLabel = new TQLabel( i18n( "Depth:" ), this ); + tmpLabel->resize( tmpLabel->sizeHint() ); + grid1->addWidget(tmpLabel,6,0); + + depth=new KDoubleNumInput(0, this); + depth->resize(100,depth->sizeHint().height()); + grid1->addWidget(depth,6,1); + depth->setRange(0,40, 0.1); +#endif +#if 0 + grid1->addColSpacing(0,depth->width()); + grid1->addColSpacing(0,angle3dX->width()); +#endif + grid1->setColStretch(2,1); + grid1->setRowStretch(7,1); + grid1->activate(); + //it's not good but I don't know how + //to reduce space + //layout->addColSpacing(1,300); +} + +void KChartLine3dConfigPage::slotChange3DParameter(bool b) +{ +#if 0 + angle3dX->setEnabled(b); + angle3dY->setEnabled(b); + depth->setEnabled(b); + drawShadowColor->setEnabled(b); +#endif + lineWidth->setEnabled(!b); +} + + +void KChartLine3dConfigPage::init() +{ +#if 0 + bool state=_params->threeDLines(); + line3d->setChecked(state); + + angle3dX->setValue( _params->threeDLineXRotation() ); + angle3dY->setValue( _params->threeDLineYRotation() ); + depth->setValue( _params->threeDLineDepth() ); + drawShadowColor->setChecked(_params->threeDShadowColors()); +#endif + lineWidth->setValue(_params->lineWidth()); + lineMarkers->setChecked(_params->lineMarker()); +#if 0 + slotChange3DParameter(state); +#endif +} + +void KChartLine3dConfigPage::apply() +{ +#if 0 + _params->setThreeDLines(line3d->isChecked()); + _params->setThreeDLineXRotation( angle3dX->value() ); + _params->setThreeDLineYRotation( angle3dY->value() ); + _params->setThreeDLineDepth( static_cast( depth->value() ) ); + _params->setThreeDShadowColors( drawShadowColor->isChecked()); +#endif + _params->setLineWidth( lineWidth->value() ); + _params->setLineMarker(lineMarkers->isChecked()); +} + + +} //KChart namespace diff --git a/kchart/kchartPageLayout.cc b/kchart/kchartPageLayout.cc deleted file mode 100644 index e2587b9f..00000000 --- a/kchart/kchartPageLayout.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Montel Laurent - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - - -#include "kchartPageLayout.h" -#include "kchartPageLayout.moc" -#include "kchart_params.h" -#include -#include -#include -#include -#include -#include - -namespace KChart -{ - -KChartPageLayout::KChartPageLayout( KChartParams* _params, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, TRUE,i18n("Page Layout"),KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::User1 | KDialogBase::Apply , KDialogBase::Ok,true ) -{ - params=_params; -#if 0 - TQWidget *page = new TQWidget( this ); -#else - TQGroupBox* page = new TQGroupBox( 2, Qt::Horizontal, i18n("Margins"), - this ); -#endif - setMainWidget(page); - - // FIXME: The following code is strange, since it is written to - // use a grid layout with a standard TQWidget. However, with the - // TQGroupBox, it looks better, and since it actually works, there - // is no immediate need for rewriting. In the sake of clarity, it - // should be done though, and we should use the layout - // capabilities of the groupbox instead.. - - setButtonText( KDialogBase::User1, i18n("&Reset") ); - - TQGridLayout *grid = new TQGridLayout(page, 4, 2, KDialog::marginHint(), KDialog::spacingHint()); - - TQLabel *lab=new TQLabel(i18n("Left:"),page); - grid->addWidget(lab,0,0); - - leftBorder=new TQLineEdit(page); - leftBorder->setValidator( new KIntValidator( 0,9999,leftBorder ) ); - grid->addWidget(leftBorder,1,0); - - lab=new TQLabel(i18n("Right:"),page); - grid->addWidget(lab,0,1); - - rightBorder=new TQLineEdit(page); - rightBorder->setValidator( new KIntValidator( 0,9999,rightBorder ) ); - grid->addWidget(rightBorder,1,1); - - lab=new TQLabel(i18n("Top:"),page); - grid->addWidget(lab,2,0); - - topBorder=new TQLineEdit(page); - topBorder->setValidator( new KIntValidator( 0,9999,topBorder ) ); - grid->addWidget(topBorder,3,0); - - lab=new TQLabel(i18n("Bottom:"),page); - grid->addWidget(lab,2,1); - - bottomBorder=new TQLineEdit(page); - bottomBorder->setValidator( new KIntValidator( 0,9999,bottomBorder ) ); - grid->addWidget(bottomBorder,3,1); - - init(); - connect( this, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( slotOk() ) ); - connect( this, TQT_SIGNAL( applyClicked() ), this, TQT_SLOT( slotApply() ) ); - connect( this, TQT_SIGNAL( user1Clicked() ), this ,TQT_SLOT( slotReset() )); - -} - -void KChartPageLayout::init() -{ - oldGlobalLeadingRight = params->globalLeadingRight(); - oldGlobalLeadingLeft = params->globalLeadingLeft(); - oldGlobalLeadingTop = params->globalLeadingTop(); - oldGlobalLeadingBottom = params->globalLeadingBottom(); - slotReset(); -} - -void KChartPageLayout::slotOk() -{ - slotApply(); - accept(); -} - -void KChartPageLayout::slotApply() -{ - params->setGlobalLeading( leftBorder->text().toInt(),topBorder->text().toInt() , rightBorder->text().toInt(), bottomBorder->text().toInt() ); - emit dataChanged(); -} - -void KChartPageLayout::slotReset() -{ - rightBorder->setText(TQString::number(oldGlobalLeadingRight)); - leftBorder->setText(TQString::number(oldGlobalLeadingLeft)); - topBorder->setText(TQString::number(oldGlobalLeadingTop)); - bottomBorder->setText(TQString::number(oldGlobalLeadingBottom)); -} - -} //KChart namespace diff --git a/kchart/kchartPageLayout.cpp b/kchart/kchartPageLayout.cpp new file mode 100644 index 00000000..e2587b9f --- /dev/null +++ b/kchart/kchartPageLayout.cpp @@ -0,0 +1,120 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Montel Laurent + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + + +#include "kchartPageLayout.h" +#include "kchartPageLayout.moc" +#include "kchart_params.h" +#include +#include +#include +#include +#include +#include + +namespace KChart +{ + +KChartPageLayout::KChartPageLayout( KChartParams* _params, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, TRUE,i18n("Page Layout"),KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::User1 | KDialogBase::Apply , KDialogBase::Ok,true ) +{ + params=_params; +#if 0 + TQWidget *page = new TQWidget( this ); +#else + TQGroupBox* page = new TQGroupBox( 2, Qt::Horizontal, i18n("Margins"), + this ); +#endif + setMainWidget(page); + + // FIXME: The following code is strange, since it is written to + // use a grid layout with a standard TQWidget. However, with the + // TQGroupBox, it looks better, and since it actually works, there + // is no immediate need for rewriting. In the sake of clarity, it + // should be done though, and we should use the layout + // capabilities of the groupbox instead.. + + setButtonText( KDialogBase::User1, i18n("&Reset") ); + + TQGridLayout *grid = new TQGridLayout(page, 4, 2, KDialog::marginHint(), KDialog::spacingHint()); + + TQLabel *lab=new TQLabel(i18n("Left:"),page); + grid->addWidget(lab,0,0); + + leftBorder=new TQLineEdit(page); + leftBorder->setValidator( new KIntValidator( 0,9999,leftBorder ) ); + grid->addWidget(leftBorder,1,0); + + lab=new TQLabel(i18n("Right:"),page); + grid->addWidget(lab,0,1); + + rightBorder=new TQLineEdit(page); + rightBorder->setValidator( new KIntValidator( 0,9999,rightBorder ) ); + grid->addWidget(rightBorder,1,1); + + lab=new TQLabel(i18n("Top:"),page); + grid->addWidget(lab,2,0); + + topBorder=new TQLineEdit(page); + topBorder->setValidator( new KIntValidator( 0,9999,topBorder ) ); + grid->addWidget(topBorder,3,0); + + lab=new TQLabel(i18n("Bottom:"),page); + grid->addWidget(lab,2,1); + + bottomBorder=new TQLineEdit(page); + bottomBorder->setValidator( new KIntValidator( 0,9999,bottomBorder ) ); + grid->addWidget(bottomBorder,3,1); + + init(); + connect( this, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( slotOk() ) ); + connect( this, TQT_SIGNAL( applyClicked() ), this, TQT_SLOT( slotApply() ) ); + connect( this, TQT_SIGNAL( user1Clicked() ), this ,TQT_SLOT( slotReset() )); + +} + +void KChartPageLayout::init() +{ + oldGlobalLeadingRight = params->globalLeadingRight(); + oldGlobalLeadingLeft = params->globalLeadingLeft(); + oldGlobalLeadingTop = params->globalLeadingTop(); + oldGlobalLeadingBottom = params->globalLeadingBottom(); + slotReset(); +} + +void KChartPageLayout::slotOk() +{ + slotApply(); + accept(); +} + +void KChartPageLayout::slotApply() +{ + params->setGlobalLeading( leftBorder->text().toInt(),topBorder->text().toInt() , rightBorder->text().toInt(), bottomBorder->text().toInt() ); + emit dataChanged(); +} + +void KChartPageLayout::slotReset() +{ + rightBorder->setText(TQString::number(oldGlobalLeadingRight)); + leftBorder->setText(TQString::number(oldGlobalLeadingLeft)); + topBorder->setText(TQString::number(oldGlobalLeadingTop)); + bottomBorder->setText(TQString::number(oldGlobalLeadingBottom)); +} + +} //KChart namespace diff --git a/kchart/kchartParameter3dConfigPage.cc b/kchart/kchartParameter3dConfigPage.cc deleted file mode 100644 index 1b37b8cc..00000000 --- a/kchart/kchartParameter3dConfigPage.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartParameter3dConfigPage.h" -#include "kchartParameter3dConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartParameter3dConfigPage::KChartParameter3dConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),m_params( params ) -{ - TQGridLayout* layout = new TQGridLayout(this, 2, 2,KDialog::marginHint(),KDialog::spacingHint()); - - - TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, - i18n("3D Parameters"), this ); - gb->layout()->setSpacing(KDialog::spacingHint()); - gb->layout()->setMargin(KDialog::marginHint()); - - // The grid layout inside the buttongroup. - TQGridLayout *grid1 = new TQGridLayout(gb->layout(), 5, 3); - layout->addWidget(gb,0,0); - - // The main on/off checkbox. - bar3d=new TQCheckBox(i18n("3D bar"),gb); - TQWhatsThis::add(bar3d, i18n("If checked, this will enable 3D mode for viewing the bars. You can then add a shadow and set the angle and depth for 3D.")); - grid1->addWidget(bar3d,0,0); - - connect(bar3d, TQT_SIGNAL(toggled ( bool )), - this, TQT_SLOT(slotChange3DParameter(bool))); - - // Checkbox for shadows - drawShadowColor=new TQCheckBox(i18n("Draw dark shadow"),gb); - TQWhatsThis::add(drawShadowColor, i18n("If checked, this will add a dark shadow on the 3D bars.")); - grid1->addWidget(drawShadowColor,1,0); - - TQLabel *tmpLabel = new TQLabel( i18n( "Angle:" ), gb ); - tmpLabel->resize( tmpLabel->sizeHint() ); - grid1->addWidget(tmpLabel,2,0); - - angle3d=new KIntNumInput(0, gb, 10); - TQWhatsThis::add(angle3d, i18n("You can set here the angle for the 3D effect from 0 to 90. 90 will give you flat bars without any 3D effect.\nDefault is 45.")); - grid1->addWidget(angle3d,2,1); - angle3d->setRange(0, 90, 1); - - tmpLabel = new TQLabel( i18n( "Depth:" ), gb ); - tmpLabel->resize( tmpLabel->sizeHint() ); - grid1->addWidget(tmpLabel,3,0); - - depth=new KDoubleNumInput(0, gb); - TQWhatsThis::add(depth, i18n("You can set here the depth of the 3D effect from 0 to 2. 0 will give you no depth at all.\nDefault is 1.")); - depth->resize(100,depth->sizeHint().height()); - grid1->addWidget(depth,3,1); - depth->setRange(0, 2.0, 0.1); - - gb->setAlignment(TQt::AlignLeft); - grid1->addColSpacing(0,depth->width()); - grid1->addColSpacing(0,angle3d->width()); - grid1->setColStretch(2,1); - grid1->setRowStretch(4,1); - - //it's not good but I don't know how - //to reduce space - //layout->addColSpacing(1,300); -} - - -void KChartParameter3dConfigPage::slotChange3DParameter(bool b) -{ - angle3d->setEnabled(b); - depth->setEnabled(b); - drawShadowColor->setEnabled(b); -} - - -void KChartParameter3dConfigPage::init() -{ - bool state=m_params->threeDBars(); - bar3d->setChecked(state); - - drawShadowColor->setChecked(m_params->threeDShadowColors()); - angle3d->setValue( m_params->threeDBarAngle() ); - depth->setValue( m_params->threeDBarDepth() ); - slotChange3DParameter(state); -} - - -void KChartParameter3dConfigPage::apply() -{ - m_params->setThreeDBars(bar3d->isChecked()); - m_params->setThreeDBarAngle( angle3d->value() ); - m_params->setThreeDBarDepth( depth->value() ); - m_params->setThreeDShadowColors( drawShadowColor->isChecked()); -} - - -} //KChart namespace diff --git a/kchart/kchartParameter3dConfigPage.cpp b/kchart/kchartParameter3dConfigPage.cpp new file mode 100644 index 00000000..1b37b8cc --- /dev/null +++ b/kchart/kchartParameter3dConfigPage.cpp @@ -0,0 +1,126 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartParameter3dConfigPage.h" +#include "kchartParameter3dConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartParameter3dConfigPage::KChartParameter3dConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),m_params( params ) +{ + TQGridLayout* layout = new TQGridLayout(this, 2, 2,KDialog::marginHint(),KDialog::spacingHint()); + + + TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, + i18n("3D Parameters"), this ); + gb->layout()->setSpacing(KDialog::spacingHint()); + gb->layout()->setMargin(KDialog::marginHint()); + + // The grid layout inside the buttongroup. + TQGridLayout *grid1 = new TQGridLayout(gb->layout(), 5, 3); + layout->addWidget(gb,0,0); + + // The main on/off checkbox. + bar3d=new TQCheckBox(i18n("3D bar"),gb); + TQWhatsThis::add(bar3d, i18n("If checked, this will enable 3D mode for viewing the bars. You can then add a shadow and set the angle and depth for 3D.")); + grid1->addWidget(bar3d,0,0); + + connect(bar3d, TQT_SIGNAL(toggled ( bool )), + this, TQT_SLOT(slotChange3DParameter(bool))); + + // Checkbox for shadows + drawShadowColor=new TQCheckBox(i18n("Draw dark shadow"),gb); + TQWhatsThis::add(drawShadowColor, i18n("If checked, this will add a dark shadow on the 3D bars.")); + grid1->addWidget(drawShadowColor,1,0); + + TQLabel *tmpLabel = new TQLabel( i18n( "Angle:" ), gb ); + tmpLabel->resize( tmpLabel->sizeHint() ); + grid1->addWidget(tmpLabel,2,0); + + angle3d=new KIntNumInput(0, gb, 10); + TQWhatsThis::add(angle3d, i18n("You can set here the angle for the 3D effect from 0 to 90. 90 will give you flat bars without any 3D effect.\nDefault is 45.")); + grid1->addWidget(angle3d,2,1); + angle3d->setRange(0, 90, 1); + + tmpLabel = new TQLabel( i18n( "Depth:" ), gb ); + tmpLabel->resize( tmpLabel->sizeHint() ); + grid1->addWidget(tmpLabel,3,0); + + depth=new KDoubleNumInput(0, gb); + TQWhatsThis::add(depth, i18n("You can set here the depth of the 3D effect from 0 to 2. 0 will give you no depth at all.\nDefault is 1.")); + depth->resize(100,depth->sizeHint().height()); + grid1->addWidget(depth,3,1); + depth->setRange(0, 2.0, 0.1); + + gb->setAlignment(TQt::AlignLeft); + grid1->addColSpacing(0,depth->width()); + grid1->addColSpacing(0,angle3d->width()); + grid1->setColStretch(2,1); + grid1->setRowStretch(4,1); + + //it's not good but I don't know how + //to reduce space + //layout->addColSpacing(1,300); +} + + +void KChartParameter3dConfigPage::slotChange3DParameter(bool b) +{ + angle3d->setEnabled(b); + depth->setEnabled(b); + drawShadowColor->setEnabled(b); +} + + +void KChartParameter3dConfigPage::init() +{ + bool state=m_params->threeDBars(); + bar3d->setChecked(state); + + drawShadowColor->setChecked(m_params->threeDShadowColors()); + angle3d->setValue( m_params->threeDBarAngle() ); + depth->setValue( m_params->threeDBarDepth() ); + slotChange3DParameter(state); +} + + +void KChartParameter3dConfigPage::apply() +{ + m_params->setThreeDBars(bar3d->isChecked()); + m_params->setThreeDBarAngle( angle3d->value() ); + m_params->setThreeDBarDepth( depth->value() ); + m_params->setThreeDShadowColors( drawShadowColor->isChecked()); +} + + +} //KChart namespace diff --git a/kchart/kchartParameterConfigPage.cc b/kchart/kchartParameterConfigPage.cc deleted file mode 100644 index da6c8017..00000000 --- a/kchart/kchartParameterConfigPage.cc +++ /dev/null @@ -1,374 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - - -#include "kchartParameterConfigPage.h" -#include "kchartParameterConfigPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kdchart/KDChartAxisParams.h" -#include "kchart_params.h" - -namespace KChart -{ - -KChartParameterConfigPage::KChartParameterConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - // toplevel layout - TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 ); - - TQGridLayout* layout = new TQGridLayout( 1, 3 ); - toplevel->addLayout( layout ); - - // The "Parameters" button group - TQButtonGroup* gb1 = new TQButtonGroup( 0, Qt::Vertical, i18n("Parameters"), this ); - gb1->layout()->setSpacing(KDialog::spacingHint()); - gb1->layout()->setMargin(KDialog::marginHint()); - TQGridLayout *grid1 = new TQGridLayout(gb1->layout(),9,1); - - grid = new TQCheckBox( i18n( "Grid" ), gb1 ); - TQWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore.")); - grid1->addWidget(grid, 0, 0); - //gb1->insert(grid); - - yaxis = new TQCheckBox( i18n( "Y-axis" ), gb1); - TQWhatsThis::add(yaxis, i18n("If this is checked, the Y-axis is shown. If you uncheck this option, the Y-axis and the Y grid lines will not be displayed anymore.")); - connect( yaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) ); - grid1->addWidget(yaxis, 1, 0); - //gb1->insert(yaxis); - - xaxis = new TQCheckBox( i18n( "X-axis" ), gb1 ); - TQWhatsThis::add(xaxis, i18n("If this is checked, the X-axis is shown. If you uncheck this option, the X-axis and the X grid lines will not be displayed anymore.")); - connect( xaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) ); - grid1->addWidget(xaxis, 2, 0); - //gb1->insert(xaxis); - -#if 0 - xlabel = new TQCheckBox( i18n( "Has X-label" ), gb1 ); - grid1->addWidget(xlabel,3,0); - - yaxis2 = new TQCheckBox( i18n( "Y-axis 2" ), gb1 ); - grid1->addWidget(yaxis2,4,0); -#endif - -#if 0 // Moved to the Line page - lineMarker = new TQCheckBox( i18n( "Line marker" ), gb1 ); - grid1->addWidget(lineMarker, 4, 0); -#endif -#if 0 - llabel = new TQCheckBox( i18n( "Legend" ), gb1 ); - grid1->addWidget(llabel,6,0); -#endif - - // The "Settings" button group - TQButtonGroup* gb2 = new TQButtonGroup( 0, Qt::Vertical, - i18n("Settings"), this ); - gb2->layout()->setSpacing(KDialog::spacingHint()); - gb2->layout()->setMargin(KDialog::marginHint()); - TQGridLayout *grid2 = new TQGridLayout(gb2->layout(),8,1); - - TQBoxLayout * l = new TQVBoxLayout( grid2 ); - - TQHBoxLayout * top = new TQHBoxLayout( l ); - // The X axis title - TQLabel *tmpLabel = new TQLabel( i18n( "X-title:" ), gb2 ); - top->addWidget(tmpLabel); - // The Y axis title - tmpLabel = new TQLabel( i18n( "Y-title:" ), gb2 ); - top->addWidget(tmpLabel); - - TQHBoxLayout * bottom = new TQHBoxLayout( l ); - xtitle= new TQLineEdit( gb2 ); - TQWhatsThis::add(xtitle, i18n("Write the title for the X-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab.")); - bottom->addWidget(xtitle); - ytitle= new TQLineEdit( gb2 ); - TQWhatsThis::add(ytitle, i18n("Write the title for the Y-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab.")); - bottom->addWidget(ytitle); - - // Linear or logarithmic scale - TQVButtonGroup *scaletype = new TQVButtonGroup(i18n("Scale Types"), gb2); - lin = new TQRadioButton( i18n("Linear scale"), scaletype); - TQWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default.")); - log = new TQRadioButton( i18n("Logarithmic scale"), scaletype); - TQWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic.")); - grid2->addWidget(scaletype, 1, 0); - - // Decimal precision - TQVButtonGroup *precision = new TQVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2); - grid2->addWidget(precision, 2, 0); - TQRadioButton * automatic_precision = new TQRadioButton( i18n("Automatic precision"), precision); - TQWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply.")); - automatic_precision->setChecked(true); - max = new TQRadioButton( i18n("Decimal precision:"), precision); - TQWhatsThis::add(max, i18n("This sets the Y-axis precision. For example, if you choose a precision of 2, the value 5 will be displayed as 5.00 alongside the Y-axis.")); - connect(automatic_precision, TQT_SIGNAL(toggled(bool)), this, - TQT_SLOT(automatic_precision_toggled(bool)) ); - maximum_length = new TQSpinBox(0, 15, 1, precision ); - TQWhatsThis::add(maximum_length, i18n("Set the precision you want to display for the Y-axis, if you choose Decimal precision. The range is 0 to 15; 2 being the default.")); - maximum_length->setValue(2); - -#if 0 - tmpLabel = new TQLabel( i18n( "Y-label format:" ), gb2 ); - grid2->addWidget(tmpLabel,0,1); - - ylabel_fmt= new TQLineEdit( gb2 ); - ylabel_fmt->setMaximumWidth(130); - grid2->addWidget(ylabel_fmt,1,1); - ylabel_fmt->setEnabled(false); - - tmpLabel = new TQLabel( i18n( "Y-title 2:" ), gb2 ); - grid2->addWidget(tmpLabel,2,1); - - ytitle2= new TQLineEdit( gb2 ); - ytitle2->setMaximumWidth(130); - grid2->addWidget(ytitle2,3,1); - - tmpLabel = new TQLabel( i18n( "Y-label format 2:" ), gb2 ); - grid2->addWidget(tmpLabel,4,1); - - ylabel2_fmt= new TQLineEdit( gb2 ); - ylabel2_fmt->setMaximumWidth(130); - grid2->addWidget(ylabel2_fmt,5,1); -#endif - layout->addWidget(gb1,0,0); - layout->addWidget(gb2,0,1); - -#if 0 - grid1->activate(); - grid2->activate(); -#endif - /*connect( grid, TQT_SIGNAL( toggled( bool ) ), - this, TQT_SLOT( changeState( bool ) ) );*/ - /*connect( xaxis, TQT_SIGNAL( toggled( bool ) ), - this, TQT_SLOT( changeXaxisState( bool ) ) );*/ -} - - - void KChartParameterConfigPage::changeXaxisState(bool /*state*/) -{ -#if 0 - if(state) - xlabel->setEnabled(true); - else - xlabel->setEnabled(false); -#endif -} - -void KChartParameterConfigPage::init() -{ - // PENDING(kalle) adapt these to KDChart - // grid->setChecked(_params->grid); - // xlabel->setChecked(_params->hasxlabel); - - grid->setChecked(_params->showGrid()); - - xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom)); - yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft)); - -#if 0 - llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend); -#endif - -#if 0 - if ( _params->chartType() == KDChartParams::Line ) { - lineMarker->setEnabled(true); - lineMarker->setChecked(_params->lineMarker()); - } - else { - lineMarker->setEnabled(false); - lineMarker->setChecked(false); - } -#endif - - // PENDING(kalle) Adapt this - // if(_params->has_yaxis2()) - // { - // yaxis2->setChecked(_params->yaxis2); - // int len=_params->ylabel2_fmt.length(); - // ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3)); - - // ytitle2->setText(_params->ytitle2); - // } - // else -#if 0 - { - yaxis2->setEnabled(false); - ylabel2_fmt->setEnabled(false); - ytitle2->setEnabled(false); - } - - // PENDING(kalle) Adapt this - // xtitle->setText(_params->xtitle); - // ytitle->setText(_params->ytitle); - // int len=_params->ylabel_fmt.length(); - // ylabel_fmt->setText(_params->ylabel_fmt.right(len-3)); - - // if(_params->xaxis) - // xlabel->setEnabled(true); - // else - xlabel->setEnabled(false); -#endif - - xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) ); - ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) ); - axisChanged(); - - // Linear / logarithmic Y axis - if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() == - KDChartAxisParams::AxisCalcLinear ) - lin->setChecked(true); - else - log->setChecked(true); - - if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() == - KDCHART_AXIS_LABELS_AUTO_DIGITS ) - maximum_length->setEnabled(false); - else - { - max->setChecked(true); - maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ); - } -} - - -void KChartParameterConfigPage::apply() -{ -#if 0 - _params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend); -#endif - - _params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked()); - _params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked()); - - _params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft, - grid->isChecked() ); - _params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom, - grid->isChecked() ); - - _params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() ); - _params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() ); - -// PENDING(kalle) Adapt this - // _params->border=border->isChecked(); - // _params->llabel=llabel->isChecked(); - // if(xaxis->isChecked()) - // _params->hasxlabel=xlabel->isChecked(); - // if(_params->has_yaxis2()) - // { - // _params->yaxis2=yaxis2->isChecked(); - // if(!ylabel2_fmt->text().isEmpty()) - // _params->ylabel2_fmt="%g "+ylabel2_fmt->text(); - // _params->ytitle2=ytitle2->text(); - // } - - - // PENDING(kalle) Adapt this - // if(grid->isChecked()) - // _params->shelf=shelf->isChecked(); - // _params->xtitle=xtitle->text(); - // _params->ytitle=ytitle->text(); - // if(!ylabel_fmt->text().isEmpty()) - // _params->ylabel_fmt="%g "+ylabel_fmt->text(); - - // PENDING(kalle) Adapt this - // if(annotation->text().isEmpty()) { - // if(_params->annotation) { - // delete _params->annotation; - // _params->annotation=0; - // } - // } - // else - // { - // if(!_params->annotation) - // _params->annotation=new KChartAnnotationType; - // _params->annotation->note=annotation->text(); - // _params->annotation->color=color->color(); - // _params->annotation->point=element->value()-1; - // _params->setAnnotationFont( annotationFont ); - // } - -#if 0 - if( _params->chartType() == KDChartParams::Line ) - _params->setLineMarker(lineMarker->isChecked()); -#endif - - // Set the scale for the Y axis (linear / logarithmic) - { - KDChartAxisParams params; - params = _params->axisParams( KDChartAxisParams::AxisPosLeft ); - - if (lin->isChecked()) - params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear); - else - { - if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic) - { - // Since in this version of kdChart logarithmic scales only work for Line charts, - // lets switch now - _params->setChartType( KChartParams::Line ); - } - params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); - } - - if ( maximum_length->isEnabled() ) - params.setAxisDigitsBehindComma( maximum_length->value() ); - else - params.setAxisDigitsBehindComma( KDCHART_AXIS_LABELS_AUTO_DIGITS ); - - _params->setAxisParams( KDChartAxisParams::AxisPosLeft, params ); - } -} - -void KChartParameterConfigPage::automatic_precision_toggled(bool toggled) -{ - if (toggled) - maximum_length->setEnabled(false); - else - maximum_length->setEnabled(true); -} - -void KChartParameterConfigPage::axisChanged() -{ - if ( !xaxis->isChecked() || !yaxis->isChecked() ) - { - xtitle->setEnabled( false ); - ytitle->setEnabled( false ); - } - else - { - xtitle->setEnabled( true ); - ytitle->setEnabled( true ); - } -} - -} //KChart namespace diff --git a/kchart/kchartParameterConfigPage.cpp b/kchart/kchartParameterConfigPage.cpp new file mode 100644 index 00000000..da6c8017 --- /dev/null +++ b/kchart/kchartParameterConfigPage.cpp @@ -0,0 +1,374 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + + +#include "kchartParameterConfigPage.h" +#include "kchartParameterConfigPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kdchart/KDChartAxisParams.h" +#include "kchart_params.h" + +namespace KChart +{ + +KChartParameterConfigPage::KChartParameterConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + // toplevel layout + TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 ); + + TQGridLayout* layout = new TQGridLayout( 1, 3 ); + toplevel->addLayout( layout ); + + // The "Parameters" button group + TQButtonGroup* gb1 = new TQButtonGroup( 0, Qt::Vertical, i18n("Parameters"), this ); + gb1->layout()->setSpacing(KDialog::spacingHint()); + gb1->layout()->setMargin(KDialog::marginHint()); + TQGridLayout *grid1 = new TQGridLayout(gb1->layout(),9,1); + + grid = new TQCheckBox( i18n( "Grid" ), gb1 ); + TQWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore.")); + grid1->addWidget(grid, 0, 0); + //gb1->insert(grid); + + yaxis = new TQCheckBox( i18n( "Y-axis" ), gb1); + TQWhatsThis::add(yaxis, i18n("If this is checked, the Y-axis is shown. If you uncheck this option, the Y-axis and the Y grid lines will not be displayed anymore.")); + connect( yaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) ); + grid1->addWidget(yaxis, 1, 0); + //gb1->insert(yaxis); + + xaxis = new TQCheckBox( i18n( "X-axis" ), gb1 ); + TQWhatsThis::add(xaxis, i18n("If this is checked, the X-axis is shown. If you uncheck this option, the X-axis and the X grid lines will not be displayed anymore.")); + connect( xaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) ); + grid1->addWidget(xaxis, 2, 0); + //gb1->insert(xaxis); + +#if 0 + xlabel = new TQCheckBox( i18n( "Has X-label" ), gb1 ); + grid1->addWidget(xlabel,3,0); + + yaxis2 = new TQCheckBox( i18n( "Y-axis 2" ), gb1 ); + grid1->addWidget(yaxis2,4,0); +#endif + +#if 0 // Moved to the Line page + lineMarker = new TQCheckBox( i18n( "Line marker" ), gb1 ); + grid1->addWidget(lineMarker, 4, 0); +#endif +#if 0 + llabel = new TQCheckBox( i18n( "Legend" ), gb1 ); + grid1->addWidget(llabel,6,0); +#endif + + // The "Settings" button group + TQButtonGroup* gb2 = new TQButtonGroup( 0, Qt::Vertical, + i18n("Settings"), this ); + gb2->layout()->setSpacing(KDialog::spacingHint()); + gb2->layout()->setMargin(KDialog::marginHint()); + TQGridLayout *grid2 = new TQGridLayout(gb2->layout(),8,1); + + TQBoxLayout * l = new TQVBoxLayout( grid2 ); + + TQHBoxLayout * top = new TQHBoxLayout( l ); + // The X axis title + TQLabel *tmpLabel = new TQLabel( i18n( "X-title:" ), gb2 ); + top->addWidget(tmpLabel); + // The Y axis title + tmpLabel = new TQLabel( i18n( "Y-title:" ), gb2 ); + top->addWidget(tmpLabel); + + TQHBoxLayout * bottom = new TQHBoxLayout( l ); + xtitle= new TQLineEdit( gb2 ); + TQWhatsThis::add(xtitle, i18n("Write the title for the X-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab.")); + bottom->addWidget(xtitle); + ytitle= new TQLineEdit( gb2 ); + TQWhatsThis::add(ytitle, i18n("Write the title for the Y-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab.")); + bottom->addWidget(ytitle); + + // Linear or logarithmic scale + TQVButtonGroup *scaletype = new TQVButtonGroup(i18n("Scale Types"), gb2); + lin = new TQRadioButton( i18n("Linear scale"), scaletype); + TQWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default.")); + log = new TQRadioButton( i18n("Logarithmic scale"), scaletype); + TQWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic.")); + grid2->addWidget(scaletype, 1, 0); + + // Decimal precision + TQVButtonGroup *precision = new TQVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2); + grid2->addWidget(precision, 2, 0); + TQRadioButton * automatic_precision = new TQRadioButton( i18n("Automatic precision"), precision); + TQWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply.")); + automatic_precision->setChecked(true); + max = new TQRadioButton( i18n("Decimal precision:"), precision); + TQWhatsThis::add(max, i18n("This sets the Y-axis precision. For example, if you choose a precision of 2, the value 5 will be displayed as 5.00 alongside the Y-axis.")); + connect(automatic_precision, TQT_SIGNAL(toggled(bool)), this, + TQT_SLOT(automatic_precision_toggled(bool)) ); + maximum_length = new TQSpinBox(0, 15, 1, precision ); + TQWhatsThis::add(maximum_length, i18n("Set the precision you want to display for the Y-axis, if you choose Decimal precision. The range is 0 to 15; 2 being the default.")); + maximum_length->setValue(2); + +#if 0 + tmpLabel = new TQLabel( i18n( "Y-label format:" ), gb2 ); + grid2->addWidget(tmpLabel,0,1); + + ylabel_fmt= new TQLineEdit( gb2 ); + ylabel_fmt->setMaximumWidth(130); + grid2->addWidget(ylabel_fmt,1,1); + ylabel_fmt->setEnabled(false); + + tmpLabel = new TQLabel( i18n( "Y-title 2:" ), gb2 ); + grid2->addWidget(tmpLabel,2,1); + + ytitle2= new TQLineEdit( gb2 ); + ytitle2->setMaximumWidth(130); + grid2->addWidget(ytitle2,3,1); + + tmpLabel = new TQLabel( i18n( "Y-label format 2:" ), gb2 ); + grid2->addWidget(tmpLabel,4,1); + + ylabel2_fmt= new TQLineEdit( gb2 ); + ylabel2_fmt->setMaximumWidth(130); + grid2->addWidget(ylabel2_fmt,5,1); +#endif + layout->addWidget(gb1,0,0); + layout->addWidget(gb2,0,1); + +#if 0 + grid1->activate(); + grid2->activate(); +#endif + /*connect( grid, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( changeState( bool ) ) );*/ + /*connect( xaxis, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( changeXaxisState( bool ) ) );*/ +} + + + void KChartParameterConfigPage::changeXaxisState(bool /*state*/) +{ +#if 0 + if(state) + xlabel->setEnabled(true); + else + xlabel->setEnabled(false); +#endif +} + +void KChartParameterConfigPage::init() +{ + // PENDING(kalle) adapt these to KDChart + // grid->setChecked(_params->grid); + // xlabel->setChecked(_params->hasxlabel); + + grid->setChecked(_params->showGrid()); + + xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom)); + yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft)); + +#if 0 + llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend); +#endif + +#if 0 + if ( _params->chartType() == KDChartParams::Line ) { + lineMarker->setEnabled(true); + lineMarker->setChecked(_params->lineMarker()); + } + else { + lineMarker->setEnabled(false); + lineMarker->setChecked(false); + } +#endif + + // PENDING(kalle) Adapt this + // if(_params->has_yaxis2()) + // { + // yaxis2->setChecked(_params->yaxis2); + // int len=_params->ylabel2_fmt.length(); + // ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3)); + + // ytitle2->setText(_params->ytitle2); + // } + // else +#if 0 + { + yaxis2->setEnabled(false); + ylabel2_fmt->setEnabled(false); + ytitle2->setEnabled(false); + } + + // PENDING(kalle) Adapt this + // xtitle->setText(_params->xtitle); + // ytitle->setText(_params->ytitle); + // int len=_params->ylabel_fmt.length(); + // ylabel_fmt->setText(_params->ylabel_fmt.right(len-3)); + + // if(_params->xaxis) + // xlabel->setEnabled(true); + // else + xlabel->setEnabled(false); +#endif + + xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) ); + ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) ); + axisChanged(); + + // Linear / logarithmic Y axis + if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() == + KDChartAxisParams::AxisCalcLinear ) + lin->setChecked(true); + else + log->setChecked(true); + + if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() == + KDCHART_AXIS_LABELS_AUTO_DIGITS ) + maximum_length->setEnabled(false); + else + { + max->setChecked(true); + maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ); + } +} + + +void KChartParameterConfigPage::apply() +{ +#if 0 + _params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend); +#endif + + _params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked()); + _params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked()); + + _params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft, + grid->isChecked() ); + _params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom, + grid->isChecked() ); + + _params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() ); + _params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() ); + +// PENDING(kalle) Adapt this + // _params->border=border->isChecked(); + // _params->llabel=llabel->isChecked(); + // if(xaxis->isChecked()) + // _params->hasxlabel=xlabel->isChecked(); + // if(_params->has_yaxis2()) + // { + // _params->yaxis2=yaxis2->isChecked(); + // if(!ylabel2_fmt->text().isEmpty()) + // _params->ylabel2_fmt="%g "+ylabel2_fmt->text(); + // _params->ytitle2=ytitle2->text(); + // } + + + // PENDING(kalle) Adapt this + // if(grid->isChecked()) + // _params->shelf=shelf->isChecked(); + // _params->xtitle=xtitle->text(); + // _params->ytitle=ytitle->text(); + // if(!ylabel_fmt->text().isEmpty()) + // _params->ylabel_fmt="%g "+ylabel_fmt->text(); + + // PENDING(kalle) Adapt this + // if(annotation->text().isEmpty()) { + // if(_params->annotation) { + // delete _params->annotation; + // _params->annotation=0; + // } + // } + // else + // { + // if(!_params->annotation) + // _params->annotation=new KChartAnnotationType; + // _params->annotation->note=annotation->text(); + // _params->annotation->color=color->color(); + // _params->annotation->point=element->value()-1; + // _params->setAnnotationFont( annotationFont ); + // } + +#if 0 + if( _params->chartType() == KDChartParams::Line ) + _params->setLineMarker(lineMarker->isChecked()); +#endif + + // Set the scale for the Y axis (linear / logarithmic) + { + KDChartAxisParams params; + params = _params->axisParams( KDChartAxisParams::AxisPosLeft ); + + if (lin->isChecked()) + params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear); + else + { + if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic) + { + // Since in this version of kdChart logarithmic scales only work for Line charts, + // lets switch now + _params->setChartType( KChartParams::Line ); + } + params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); + } + + if ( maximum_length->isEnabled() ) + params.setAxisDigitsBehindComma( maximum_length->value() ); + else + params.setAxisDigitsBehindComma( KDCHART_AXIS_LABELS_AUTO_DIGITS ); + + _params->setAxisParams( KDChartAxisParams::AxisPosLeft, params ); + } +} + +void KChartParameterConfigPage::automatic_precision_toggled(bool toggled) +{ + if (toggled) + maximum_length->setEnabled(false); + else + maximum_length->setEnabled(true); +} + +void KChartParameterConfigPage::axisChanged() +{ + if ( !xaxis->isChecked() || !yaxis->isChecked() ) + { + xtitle->setEnabled( false ); + ytitle->setEnabled( false ); + } + else + { + xtitle->setEnabled( true ); + ytitle->setEnabled( true ); + } +} + +} //KChart namespace diff --git a/kchart/kchartParameterPieConfigPage.cc b/kchart/kchartParameterPieConfigPage.cc deleted file mode 100644 index d640333e..00000000 --- a/kchart/kchartParameterPieConfigPage.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartParameterPieConfigPage.h" - -#include "kchartParameterPieConfigPage.moc" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartParameterPieConfigPage::KChartParameterPieConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - TQVBoxLayout *toplevel = new TQVBoxLayout( this, 10 ); - TQVBoxLayout *grid1 = new TQVBoxLayout(this); - toplevel->addLayout( grid1 ); - - TQVButtonGroup* gb = new TQVButtonGroup( i18n( "Parameter" ), this ); - grid1->addWidget(gb); - - pie3d = new TQCheckBox(i18n("Pie 3D"), gb); - TQWhatsThis::add(pie3d, i18n("Uncheck this option if you do not want a 3D effect for your pie.")); - drawShadowColor=new TQCheckBox(i18n("Draw shadow color"), gb); - TQWhatsThis::add(drawShadowColor, i18n("Uncheck this option if you do not want a shadow color on a 3D pie.")); - - TQLabel *label = new TQLabel( i18n( "Explode factor (%):" ), gb ); - explode = new TQSpinBox(0, 100, 1, gb); - TQWhatsThis::add(explode, i18n("This will place gaps between the segments of your pie. Default is 0 which means the pie is a whole.")); - - label = new TQLabel( i18n( "Start angle:" ), gb ); - angle = new TQSpinBox(0, 90, 1, gb); - TQWhatsThis::add(angle, i18n("This will set the orientation of your pie. Default is 0.")); - - label = new TQLabel( i18n( "3D-depth:" ), gb ); - depth = new TQSpinBox(0, 40, 1, gb); - TQWhatsThis::add(depth, i18n("Set the depth from 0 to 40 of the 3D effect, if you have checked Pie 3D. Default is 20.")); - - grid1->activate(); - - connect(pie3d,TQT_SIGNAL(toggled ( bool )),this, TQT_SLOT(active3DPie(bool))); -} - -void KChartParameterPieConfigPage::active3DPie(bool b) -{ - drawShadowColor->setEnabled(b); - depth->setEnabled(b); -} - -void KChartParameterPieConfigPage::init() -{ - bool state=_params->threeDPies(); - pie3d->setChecked(state); - depth->setEnabled(state); - active3DPie(state); - - explode->setValue((int)(_params->explodeFactor() * 100)); - depth->setValue( _params->threeDPieHeight() ); - drawShadowColor->setChecked(_params->threeDShadowColors()); - angle->setValue( _params->pieStart() ); - -} - - -void KChartParameterPieConfigPage::apply() -{ - _params->setThreeDPies( pie3d->isChecked() ); - if( _params->threeDPies() ) { - _params->setThreeDPieHeight( depth->value() ); - } - _params->setThreeDShadowColors( drawShadowColor->isChecked()); - _params->setExplodeFactor(((double)(explode->value()))/100.0); - _params->setPieStart( angle->value() ); -} - -} //KChart namespace diff --git a/kchart/kchartParameterPieConfigPage.cpp b/kchart/kchartParameterPieConfigPage.cpp new file mode 100644 index 00000000..d640333e --- /dev/null +++ b/kchart/kchartParameterPieConfigPage.cpp @@ -0,0 +1,109 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartParameterPieConfigPage.h" + +#include "kchartParameterPieConfigPage.moc" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartParameterPieConfigPage::KChartParameterPieConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + TQVBoxLayout *toplevel = new TQVBoxLayout( this, 10 ); + TQVBoxLayout *grid1 = new TQVBoxLayout(this); + toplevel->addLayout( grid1 ); + + TQVButtonGroup* gb = new TQVButtonGroup( i18n( "Parameter" ), this ); + grid1->addWidget(gb); + + pie3d = new TQCheckBox(i18n("Pie 3D"), gb); + TQWhatsThis::add(pie3d, i18n("Uncheck this option if you do not want a 3D effect for your pie.")); + drawShadowColor=new TQCheckBox(i18n("Draw shadow color"), gb); + TQWhatsThis::add(drawShadowColor, i18n("Uncheck this option if you do not want a shadow color on a 3D pie.")); + + TQLabel *label = new TQLabel( i18n( "Explode factor (%):" ), gb ); + explode = new TQSpinBox(0, 100, 1, gb); + TQWhatsThis::add(explode, i18n("This will place gaps between the segments of your pie. Default is 0 which means the pie is a whole.")); + + label = new TQLabel( i18n( "Start angle:" ), gb ); + angle = new TQSpinBox(0, 90, 1, gb); + TQWhatsThis::add(angle, i18n("This will set the orientation of your pie. Default is 0.")); + + label = new TQLabel( i18n( "3D-depth:" ), gb ); + depth = new TQSpinBox(0, 40, 1, gb); + TQWhatsThis::add(depth, i18n("Set the depth from 0 to 40 of the 3D effect, if you have checked Pie 3D. Default is 20.")); + + grid1->activate(); + + connect(pie3d,TQT_SIGNAL(toggled ( bool )),this, TQT_SLOT(active3DPie(bool))); +} + +void KChartParameterPieConfigPage::active3DPie(bool b) +{ + drawShadowColor->setEnabled(b); + depth->setEnabled(b); +} + +void KChartParameterPieConfigPage::init() +{ + bool state=_params->threeDPies(); + pie3d->setChecked(state); + depth->setEnabled(state); + active3DPie(state); + + explode->setValue((int)(_params->explodeFactor() * 100)); + depth->setValue( _params->threeDPieHeight() ); + drawShadowColor->setChecked(_params->threeDShadowColors()); + angle->setValue( _params->pieStart() ); + +} + + +void KChartParameterPieConfigPage::apply() +{ + _params->setThreeDPies( pie3d->isChecked() ); + if( _params->threeDPies() ) { + _params->setThreeDPieHeight( depth->value() ); + } + _params->setThreeDShadowColors( drawShadowColor->isChecked()); + _params->setExplodeFactor(((double)(explode->value()))/100.0); + _params->setPieStart( angle->value() ); +} + +} //KChart namespace diff --git a/kchart/kchartParameterPolarConfigPage.cc b/kchart/kchartParameterPolarConfigPage.cc deleted file mode 100644 index b6e1fe59..00000000 --- a/kchart/kchartParameterPolarConfigPage.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartParameterPolarConfigPage.h" - -#include "kchartParameterPolarConfigPage.moc" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartParameterPolarConfigPage::KChartParameterPolarConfigPage( KChartParams* params, - TQWidget* parent ) : - TQWidget( parent ),_params( params ) -{ - TQVBoxLayout *grid1 = new TQVBoxLayout(this); - TQVButtonGroup* gb = new TQVButtonGroup( i18n( "Parameter" ), this ); - grid1->addWidget(gb); - - polarMarker=new TQCheckBox(i18n("Polar marker"), gb); - TQWhatsThis::add(polarMarker, i18n("If this is checked, the polar markers are shown; otherwise they are not.")); - showCircularLabel = new TQCheckBox(i18n("Show circular label"), gb); - TQWhatsThis::add(showCircularLabel, i18n("Toggle the circular label display.")); - - TQLabel *label = new TQLabel( i18n( "Zero degree position:" ), gb ); - angle = new TQSpinBox(-359, 359, 1, gb); - TQWhatsThis::add(angle, i18n("Set the position for the X axis (horizontal) from -359 to 359. Default is 0.")); - - label=new TQLabel(i18n("Line width:"), gb); - lineWidth=new TQSpinBox(gb); - TQWhatsThis::add(lineWidth, i18n("Set the width for the chart lines. 0 is default and is the thinnest.")); - - grid1->activate(); -} - - -void KChartParameterPolarConfigPage::init() -{ - polarMarker->setChecked(_params->polarMarker()); - angle->setValue( _params->polarZeroDegreePos() ); - showCircularLabel->setChecked(_params->polarRotateCircularLabels()); - lineWidth->setValue(_params->polarLineWidth()); -} - - -void KChartParameterPolarConfigPage::apply() -{ - _params->setPolarZeroDegreePos(angle->value()); - _params->setPolarMarker(polarMarker->isChecked()); - _params->setPolarRotateCircularLabels(showCircularLabel->isChecked()); - _params->setPolarLineWidth(lineWidth->value()); -} - -} //KChart namespace diff --git a/kchart/kchartParameterPolarConfigPage.cpp b/kchart/kchartParameterPolarConfigPage.cpp new file mode 100644 index 00000000..b6e1fe59 --- /dev/null +++ b/kchart/kchartParameterPolarConfigPage.cpp @@ -0,0 +1,86 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartParameterPolarConfigPage.h" + +#include "kchartParameterPolarConfigPage.moc" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartParameterPolarConfigPage::KChartParameterPolarConfigPage( KChartParams* params, + TQWidget* parent ) : + TQWidget( parent ),_params( params ) +{ + TQVBoxLayout *grid1 = new TQVBoxLayout(this); + TQVButtonGroup* gb = new TQVButtonGroup( i18n( "Parameter" ), this ); + grid1->addWidget(gb); + + polarMarker=new TQCheckBox(i18n("Polar marker"), gb); + TQWhatsThis::add(polarMarker, i18n("If this is checked, the polar markers are shown; otherwise they are not.")); + showCircularLabel = new TQCheckBox(i18n("Show circular label"), gb); + TQWhatsThis::add(showCircularLabel, i18n("Toggle the circular label display.")); + + TQLabel *label = new TQLabel( i18n( "Zero degree position:" ), gb ); + angle = new TQSpinBox(-359, 359, 1, gb); + TQWhatsThis::add(angle, i18n("Set the position for the X axis (horizontal) from -359 to 359. Default is 0.")); + + label=new TQLabel(i18n("Line width:"), gb); + lineWidth=new TQSpinBox(gb); + TQWhatsThis::add(lineWidth, i18n("Set the width for the chart lines. 0 is default and is the thinnest.")); + + grid1->activate(); +} + + +void KChartParameterPolarConfigPage::init() +{ + polarMarker->setChecked(_params->polarMarker()); + angle->setValue( _params->polarZeroDegreePos() ); + showCircularLabel->setChecked(_params->polarRotateCircularLabels()); + lineWidth->setValue(_params->polarLineWidth()); +} + + +void KChartParameterPolarConfigPage::apply() +{ + _params->setPolarZeroDegreePos(angle->value()); + _params->setPolarMarker(polarMarker->isChecked()); + _params->setPolarRotateCircularLabels(showCircularLabel->isChecked()); + _params->setPolarLineWidth(lineWidth->value()); +} + +} //KChart namespace diff --git a/kchart/kchartPieConfigPage.cc b/kchart/kchartPieConfigPage.cc deleted file mode 100644 index 31ec42a6..00000000 --- a/kchart/kchartPieConfigPage.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000,2001,2002,2003,2004 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "kchartPieConfigPage.h" -#include "kchartPieConfigPage.moc" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - - -namespace KChart -{ - -KChartPieConfigPage::KChartPieConfigPage( KChartParams* params, - TQWidget* parent, - KDChartTableData* data) : - TQWidget( parent ),_params( params ) -{ - // col=_params->colPie; - pos=-1; - TQGridLayout *grid = new TQGridLayout(this,10,4,KDialog::marginHint(), - KDialog::spacingHint()); - // The listview - list = new TQListView( this ); - list->resize( list->sizeHint() ); - grid->addMultiCellWidget(list,0,9,0,0); - list->addColumn( i18n("Hide Piece") ); - list->setRootIsDecorated( TRUE ); - - TQLabel* label = new TQLabel( i18n( "Column active:" ), this ); - label->resize( label->sizeHint() ); - grid->addWidget( label,0,1); - - column = new TQSpinBox(1, data->cols(), 1, this); - column->resize(100, column->sizeHint().height() ); - grid->addWidget( column,1,1); - - column->setValue(col+1); - - label = new TQLabel( i18n( "Move piece to:" ), this ); - label->resize( label->sizeHint() ); - grid->addWidget( label,2,1); - - dist = new TQSpinBox(0, 400, 1, this); - dist->resize(100, dist->sizeHint().height() ); - grid->addWidget( dist,3,1); - - label = new TQLabel( i18n( "Explode factor (%):" ), this ); - label->resize( label->sizeHint() ); - grid->addWidget( label,4,1); - - explose = new TQSpinBox(0, 100, 1, this); - explose->resize(100, explose->sizeHint().height() ); - grid->addWidget( explose,5,1); - - grid->addColSpacing(0,list->width()); - grid->addColSpacing(2,list->width()); - grid->addColSpacing(3,list->width()); - - - initList(); - dist->setEnabled(false); - - connect(column,TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(changeValue(int))); - - connect( list, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( slotselected(TQListViewItem *) ) ); -} - - -void KChartPieConfigPage::initList() -{ - //int index; - // PENDING(kalle) Put back in - // for( TQStringList::Iterator it = _params->legend.begin(); it != _params->legend.end(); ++it ) { -// (void)new TQCheckListItem( list, (*it),TQCheckListItem::CheckBox ) ; - -// } - TQListViewItemIterator it( list ); - //Select or not CheckBox - // PENDING(kalle) Put back in - // for( ; it.current(); ++it ) { -// index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); -// ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; -// } -// value.duplicate(_params->explode); -} - - -void KChartPieConfigPage::slotselected(TQListViewItem */*it*/) -{ - //column : 0 - //cout <<"Select :"<<(it)->text(0).ascii()<legend.findIndex((it)->text(0)); - if(pos==-1) - dist->setEnabled(true); - else - value[pos]=dist->value(); - - // PENDING(kalle) Put back in - // pos=_params->legend.count()*col+index; - dist->setValue(value[pos]); -} - - -void KChartPieConfigPage::changeValue(int val) -{ - col=val-1; - TQListViewItemIterator it( list ); - //Select or not CheckBox - ; - //int index=0; - for( ; it.current(); ++it ) { - // PENDING(kalle) Put back in - // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); -// ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; - } - - if(pos!=-1) { - value[pos]=dist->value(); - // PENDING(kalle) Put back in - // pos=_params->legend.count()*col+index; - dist->setValue(value[pos]); - } -} - - -void KChartPieConfigPage::init() -{ - TQListViewItemIterator it( list ); - //Select or not CheckBox - - //int index = 0; - for( ; it.current(); ++it ) { - // PENDING(kalle) Put back in - // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); - // ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; - } - - // PENDING(kalle) Put back in -// value.duplicate(_params->explode); -// if(pos!=-1) { -// pos=_params->legend.count()*col; -// dist->setValue( value[pos]); -// } - explose->setValue((int)(_params->explodeFactor()*100)); -} - - -void KChartPieConfigPage::apply() -{ - TQListViewItemIterator it( list ); - //Select or not CheckBox - //int index = 0; - for( ; it.current(); ++it ) { - // PENDING(kalle) Put back in - // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); -// _params->missing[_params->legend.count()*col+index]=((TQCheckListItem*)it.current())->isOn() ; - } - // _params->colPie=col; - - // PENDING(kalle) Put back in - // value[pos]=dist->value(); -// _params->explode.duplicate(value); - _params->setExplodeFactor(((double)(explose->value()))/100); -} - -} //KChart namespace diff --git a/kchart/kchartPieConfigPage.cpp b/kchart/kchartPieConfigPage.cpp new file mode 100644 index 00000000..31ec42a6 --- /dev/null +++ b/kchart/kchartPieConfigPage.cpp @@ -0,0 +1,196 @@ +/* This file is part of the KDE project + Copyright (C) 2000,2001,2002,2003,2004 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kchartPieConfigPage.h" +#include "kchartPieConfigPage.moc" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + + +namespace KChart +{ + +KChartPieConfigPage::KChartPieConfigPage( KChartParams* params, + TQWidget* parent, + KDChartTableData* data) : + TQWidget( parent ),_params( params ) +{ + // col=_params->colPie; + pos=-1; + TQGridLayout *grid = new TQGridLayout(this,10,4,KDialog::marginHint(), + KDialog::spacingHint()); + // The listview + list = new TQListView( this ); + list->resize( list->sizeHint() ); + grid->addMultiCellWidget(list,0,9,0,0); + list->addColumn( i18n("Hide Piece") ); + list->setRootIsDecorated( TRUE ); + + TQLabel* label = new TQLabel( i18n( "Column active:" ), this ); + label->resize( label->sizeHint() ); + grid->addWidget( label,0,1); + + column = new TQSpinBox(1, data->cols(), 1, this); + column->resize(100, column->sizeHint().height() ); + grid->addWidget( column,1,1); + + column->setValue(col+1); + + label = new TQLabel( i18n( "Move piece to:" ), this ); + label->resize( label->sizeHint() ); + grid->addWidget( label,2,1); + + dist = new TQSpinBox(0, 400, 1, this); + dist->resize(100, dist->sizeHint().height() ); + grid->addWidget( dist,3,1); + + label = new TQLabel( i18n( "Explode factor (%):" ), this ); + label->resize( label->sizeHint() ); + grid->addWidget( label,4,1); + + explose = new TQSpinBox(0, 100, 1, this); + explose->resize(100, explose->sizeHint().height() ); + grid->addWidget( explose,5,1); + + grid->addColSpacing(0,list->width()); + grid->addColSpacing(2,list->width()); + grid->addColSpacing(3,list->width()); + + + initList(); + dist->setEnabled(false); + + connect(column,TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(changeValue(int))); + + connect( list, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( slotselected(TQListViewItem *) ) ); +} + + +void KChartPieConfigPage::initList() +{ + //int index; + // PENDING(kalle) Put back in + // for( TQStringList::Iterator it = _params->legend.begin(); it != _params->legend.end(); ++it ) { +// (void)new TQCheckListItem( list, (*it),TQCheckListItem::CheckBox ) ; + +// } + TQListViewItemIterator it( list ); + //Select or not CheckBox + // PENDING(kalle) Put back in + // for( ; it.current(); ++it ) { +// index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); +// ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; +// } +// value.duplicate(_params->explode); +} + + +void KChartPieConfigPage::slotselected(TQListViewItem */*it*/) +{ + //column : 0 + //cout <<"Select :"<<(it)->text(0).ascii()<legend.findIndex((it)->text(0)); + if(pos==-1) + dist->setEnabled(true); + else + value[pos]=dist->value(); + + // PENDING(kalle) Put back in + // pos=_params->legend.count()*col+index; + dist->setValue(value[pos]); +} + + +void KChartPieConfigPage::changeValue(int val) +{ + col=val-1; + TQListViewItemIterator it( list ); + //Select or not CheckBox + ; + //int index=0; + for( ; it.current(); ++it ) { + // PENDING(kalle) Put back in + // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); +// ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; + } + + if(pos!=-1) { + value[pos]=dist->value(); + // PENDING(kalle) Put back in + // pos=_params->legend.count()*col+index; + dist->setValue(value[pos]); + } +} + + +void KChartPieConfigPage::init() +{ + TQListViewItemIterator it( list ); + //Select or not CheckBox + + //int index = 0; + for( ; it.current(); ++it ) { + // PENDING(kalle) Put back in + // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); + // ((TQCheckListItem*)it.current())->setOn(_params->missing[_params->legend.count()*col+index]) ; + } + + // PENDING(kalle) Put back in +// value.duplicate(_params->explode); +// if(pos!=-1) { +// pos=_params->legend.count()*col; +// dist->setValue( value[pos]); +// } + explose->setValue((int)(_params->explodeFactor()*100)); +} + + +void KChartPieConfigPage::apply() +{ + TQListViewItemIterator it( list ); + //Select or not CheckBox + //int index = 0; + for( ; it.current(); ++it ) { + // PENDING(kalle) Put back in + // index = _params->legend.findIndex(((TQCheckListItem*)it.current())->text()); +// _params->missing[_params->legend.count()*col+index]=((TQCheckListItem*)it.current())->isOn() ; + } + // _params->colPie=col; + + // PENDING(kalle) Put back in + // value[pos]=dist->value(); +// _params->explode.duplicate(value); + _params->setExplodeFactor(((double)(explose->value()))/100); +} + +} //KChart namespace diff --git a/kchart/kchartPrinterDlg.cc b/kchart/kchartPrinterDlg.cc deleted file mode 100644 index a02592de..00000000 --- a/kchart/kchartPrinterDlg.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* -* -* Copyright (C) 2005 Fredrik Edemar -* f_edemar@linux.se -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -* -*/ - -// TQt includes -#include - -// KDE includes -#include -#include -#include - -// local includes -#include "kchartPrinterDlg.h" -namespace KChart -{ - - KChartPrinterDlg::KChartPrinterDlg( TQWidget *parent, const char *name ) - : KPrintDialogPage( parent, name ) -{ - setTitle( i18n( "KChart Options" ) ); - TQVBoxLayout *layout = new TQVBoxLayout( this ); - layout->setMargin( KDialog::marginHint() ); - layout->setSpacing( KDialog::spacingHint() ); - txtSizex = new KIntNumInput(this ); - txtSizex->setSuffix("%"); - txtSizex->setMinValue(1); - txtSizex->setMaxValue(100); - txtSizex->setValue(100); - txtSizey = new KIntNumInput(this ); - txtSizey->setSuffix("%"); - txtSizey->setMinValue(1); - txtSizey->setMaxValue(100); - txtSizey->setValue(100); - - layout->addWidget( new TQLabel(i18n("Print Size"), this) ); - layout->addWidget( new TQLabel(i18n("Width: "), this) ); - layout->addWidget( txtSizex ); - layout->addWidget( new TQLabel(i18n("Height: "), this) ); - layout->addWidget( txtSizey ); - layout->addStretch( 1 ); -} - -void KChartPrinterDlg::getOptions( TQMap& opts, bool ) -{ - opts["kde-kchart-printsizex"] = TQString::number(txtSizex->value()); - opts["kde-kchart-printsizey"] = TQString::number(txtSizey->value()); -} - -void KChartPrinterDlg::setOptions( const TQMap& opts ) -{ - if ( opts["kde-kchart-printsizex"].isEmpty() ) - txtSizex->setValue(100); - else - txtSizex->setValue((opts["kde-kchart-printsizex"]).toInt()); - if ( opts["kde-kchart-printsizey"].isEmpty() ) - txtSizey->setValue(100); - else - txtSizey->setValue((opts["kde-kchart-printsizey"]).toInt()); -} - -bool KChartPrinterDlg::isValid( const TQString& ) -{ - return true; -} -} //namespace KChart -#include "kchartPrinterDlg.moc" diff --git a/kchart/kchartPrinterDlg.cpp b/kchart/kchartPrinterDlg.cpp new file mode 100644 index 00000000..a02592de --- /dev/null +++ b/kchart/kchartPrinterDlg.cpp @@ -0,0 +1,85 @@ +/* +* +* Copyright (C) 2005 Fredrik Edemar +* f_edemar@linux.se +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +* +*/ + +// TQt includes +#include + +// KDE includes +#include +#include +#include + +// local includes +#include "kchartPrinterDlg.h" +namespace KChart +{ + + KChartPrinterDlg::KChartPrinterDlg( TQWidget *parent, const char *name ) + : KPrintDialogPage( parent, name ) +{ + setTitle( i18n( "KChart Options" ) ); + TQVBoxLayout *layout = new TQVBoxLayout( this ); + layout->setMargin( KDialog::marginHint() ); + layout->setSpacing( KDialog::spacingHint() ); + txtSizex = new KIntNumInput(this ); + txtSizex->setSuffix("%"); + txtSizex->setMinValue(1); + txtSizex->setMaxValue(100); + txtSizex->setValue(100); + txtSizey = new KIntNumInput(this ); + txtSizey->setSuffix("%"); + txtSizey->setMinValue(1); + txtSizey->setMaxValue(100); + txtSizey->setValue(100); + + layout->addWidget( new TQLabel(i18n("Print Size"), this) ); + layout->addWidget( new TQLabel(i18n("Width: "), this) ); + layout->addWidget( txtSizex ); + layout->addWidget( new TQLabel(i18n("Height: "), this) ); + layout->addWidget( txtSizey ); + layout->addStretch( 1 ); +} + +void KChartPrinterDlg::getOptions( TQMap& opts, bool ) +{ + opts["kde-kchart-printsizex"] = TQString::number(txtSizex->value()); + opts["kde-kchart-printsizey"] = TQString::number(txtSizey->value()); +} + +void KChartPrinterDlg::setOptions( const TQMap& opts ) +{ + if ( opts["kde-kchart-printsizex"].isEmpty() ) + txtSizex->setValue(100); + else + txtSizex->setValue((opts["kde-kchart-printsizex"]).toInt()); + if ( opts["kde-kchart-printsizey"].isEmpty() ) + txtSizey->setValue(100); + else + txtSizey->setValue((opts["kde-kchart-printsizey"]).toInt()); +} + +bool KChartPrinterDlg::isValid( const TQString& ) +{ + return true; +} +} //namespace KChart +#include "kchartPrinterDlg.moc" diff --git a/kchart/kchartSubTypeChartPage.cc b/kchart/kchartSubTypeChartPage.cc deleted file mode 100644 index 9ccad59e..00000000 --- a/kchart/kchartSubTypeChartPage.cc +++ /dev/null @@ -1,456 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999,2000 Matthias Kalle Dalheimer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include - -#include "kchartSubTypeChartPage.h" -#include "kchartSubTypeChartPage.moc" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -#include "kchart_factory.h" - -namespace KChart -{ - -KChartHiloSubTypeChartPage::KChartHiloSubTypeChartPage( KChartParams* params, - TQWidget* parent ) : - KChartSubTypeChartPage( params, parent ) -{ - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); - TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); - toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); - normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); - subtypeBG->insert( normal, KDChartParams::AreaNormal ); - stacked = new TQRadioButton(i18n("HiLoClose"), subtypeBG ); - subtypeBG->insert( stacked, KDChartParams::AreaStacked ); - percent = new TQRadioButton( i18n("HiLoOpenClose"), subtypeBG ); - subtypeBG->insert( percent, KDChartParams::AreaPercent ); - subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); - connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( slotChangeSubType( int ) ) ); - - TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); - TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); - toplevel->addWidget( exampleGB, 2 ); - exampleLA = new TQLabel( exampleGB ); - exampleLA->setAlignment( AlignCenter | AlignVCenter ); - // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. -} - -void KChartHiloSubTypeChartPage::init() -{ - switch( m_params->hiLoChartSubType() ) { - case KDChartParams::HiLoNormal: - normal->setChecked( true ); - break; - case KDChartParams::HiLoClose: - stacked->setChecked( true ); - break; - case KDChartParams::HiLoOpenClose: - percent->setChecked( true ); - break; - default: - { - kdDebug( 35001 ) << "Error in stack_type" << endl; - abort(); - break; - } - } - - slotChangeSubType( m_params->hiLoChartSubType() ); -} - -void KChartHiloSubTypeChartPage::slotChangeSubType( int type ) -{ - switch( type ) { - case KDChartParams::HiLoNormal: - exampleLA->setPixmap( UserIcon( "chart_hilo_normal", KChartFactory::global() ) ); - break; - case KDChartParams::HiLoClose: - exampleLA->setPixmap( UserIcon( "chart_hilo_close", KChartFactory::global() ) ); - break; - case KDChartParams::HiLoOpenClose: - exampleLA->setPixmap( UserIcon( "chart_hilo_openclose", KChartFactory::global() ) ); - break; - }; -} - - - -void KChartHiloSubTypeChartPage::apply() -{ - if( normal->isChecked() ) - m_params->setHiLoChartSubType( KDChartParams::HiLoNormal ); - else if( stacked->isChecked() ) - m_params->setHiLoChartSubType( KDChartParams::HiLoClose ); - else if( percent->isChecked() ) - m_params->setHiLoChartSubType( KDChartParams::HiLoOpenClose ); - else { - kdDebug( 35001 ) << "Error in groupbutton" << endl; - } -} - -KChartAreaSubTypeChartPage::KChartAreaSubTypeChartPage( KChartParams* params, - TQWidget* parent ) : - KChartSubTypeChartPage( params, parent ) -{ - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); - TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); - toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); - normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); - subtypeBG->insert( normal, KDChartParams::AreaNormal ); - stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); - subtypeBG->insert( stacked, KDChartParams::AreaStacked ); - percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); - subtypeBG->insert( percent, KDChartParams::AreaPercent ); - subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); - connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( slotChangeSubType( int ) ) ); - - TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); - TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); - toplevel->addWidget( exampleGB, 2 ); - exampleLA = new TQLabel( exampleGB ); - exampleLA->setAlignment( AlignCenter | AlignVCenter ); - // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. -} - - -void KChartAreaSubTypeChartPage::init() -{ - switch( m_params->areaChartSubType() ) { - case KDChartParams::AreaNormal: - normal->setChecked( true ); - break; - case KDChartParams::AreaStacked: - stacked->setChecked( true ); - break; - case KDChartParams::AreaPercent: - percent->setChecked( true ); - break; - default: - { - kdDebug( 35001 ) << "Error in stack_type" << endl; - abort(); - break; - } - } - - slotChangeSubType( m_params->areaChartSubType() ); -} - -void KChartAreaSubTypeChartPage::slotChangeSubType( int type ) -{ - switch( type ) { - case KDChartParams::AreaNormal: - exampleLA->setPixmap( UserIcon( "chart_area_normal", KChartFactory::global() ) ); - break; - case KDChartParams::AreaStacked: - exampleLA->setPixmap( UserIcon( "chart_area_stacked", KChartFactory::global() ) ); - break; - case KDChartParams::AreaPercent: - exampleLA->setPixmap( UserIcon( "chart_area_percent", KChartFactory::global() ) ); - break; - }; -} - - - -void KChartAreaSubTypeChartPage::apply() -{ - if( normal->isChecked() ) - m_params->setAreaChartSubType( KDChartParams::AreaNormal ); - else if( stacked->isChecked() ) - m_params->setAreaChartSubType( KDChartParams::AreaStacked ); - else if( percent->isChecked() ) - m_params->setAreaChartSubType( KDChartParams::AreaPercent ); - else { - kdDebug( 35001 ) << "Error in groupbutton" << endl; - } -} - -KChartBarSubTypeChartPage::KChartBarSubTypeChartPage( KChartParams* params, - TQWidget* parent ) : - KChartSubTypeChartPage( params, parent ) -{ - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - TQVBox *left = new TQVBox( this ); - TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), left ); - TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); - //toplevel->addWidget( subtypeBG, AlignCenter ); - toplevel->addWidget( left, AlignCenter ); - - normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); - subtypeBG->insert( normal, KDChartParams::BarNormal ); - stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); - subtypeBG->insert( stacked, KDChartParams::BarStacked ); - percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); - subtypeBG->insert( percent, KDChartParams::BarPercent ); - - subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); - connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( slotChangeSubType( int ) ) ); - - //TQHBox *hbox = new TQHBox( this ); - new TQLabel( i18n( "Number of lines: "), left ); - m_numLines = new TQSpinBox( left ); - // FIXME: Use a grid layout instead - new TQLabel( "", left); - left->setStretchFactor( left, 1 ); - - TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); - TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); - toplevel->addWidget( exampleGB, 2 ); - exampleLA = new TQLabel( exampleGB ); - exampleLA->setAlignment( AlignCenter | AlignVCenter ); -} - -void KChartBarSubTypeChartPage::init() -{ - // SUM is for areas only and therefore not configurable here. - switch( m_params->barChartSubType() ) { - case KDChartParams::BarNormal: - normal->setChecked( true ); - break; - case KDChartParams::BarStacked: - stacked->setChecked( true ); - break; - case KDChartParams::BarPercent: - percent->setChecked( true ); - break; - default: - { - kdDebug( 35001 ) << "Error in stack_type" << endl; - break; - } - } - - m_numLines->setValue( m_params->barNumLines() ); - - slotChangeSubType( m_params->barChartSubType() ); -} - - -void KChartBarSubTypeChartPage::slotChangeSubType( int type ) -{ - switch( type ) { - case KDChartParams::BarStacked: - exampleLA->setPixmap( UserIcon( "chart_bar_layer", KChartFactory::global() ) ); - break; - case KDChartParams::BarNormal: - exampleLA->setPixmap( UserIcon( "chart_bar_beside", KChartFactory::global() ) ); - break; - case KDChartParams::BarPercent: - exampleLA->setPixmap( UserIcon( "chart_bar_percent", KChartFactory::global() ) ); - break; - }; -} - - -void KChartBarSubTypeChartPage::apply() -{ - if( normal->isChecked() ) { - m_params->setBarChartSubType( KDChartParams::BarNormal ); - } else if( stacked->isChecked() ) { - m_params->setBarChartSubType( KDChartParams::BarStacked ); - } else if( percent->isChecked() ) { - m_params->setBarChartSubType( KDChartParams::BarPercent ); - } else { - kdDebug( 35001 ) << "Error in groupbutton" << endl; - } - - // FIXME: Error controls. - m_params->setBarNumLines( m_numLines->value() ); -} - -KChartLineSubTypeChartPage::KChartLineSubTypeChartPage( KChartParams* params, - TQWidget* parent ) : - KChartSubTypeChartPage( params, parent ) -{ - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); - TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); - toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); - normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); - subtypeBG->insert( normal, KDChartParams::AreaNormal ); - stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); - subtypeBG->insert( stacked, KDChartParams::AreaStacked ); - percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); - subtypeBG->insert( percent, KDChartParams::AreaPercent ); - subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); - connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( slotChangeSubType( int ) ) ); - - TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); - TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); - toplevel->addWidget( exampleGB, 2 ); - exampleLA = new TQLabel( exampleGB ); - exampleLA->setAlignment( AlignCenter | AlignVCenter ); - // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. -} - -void KChartLineSubTypeChartPage::init() -{ - switch( m_params->lineChartSubType() ) { - case KDChartParams::LineNormal: - normal->setChecked( true ); - break; - case KDChartParams::LineStacked: - stacked->setChecked( true ); - break; - case KDChartParams::LinePercent: - percent->setChecked( true ); - break; - default: - { - kdDebug( 35001 ) << "Error in stack_type" << endl; - abort(); - break; - } - } - - slotChangeSubType( m_params->lineChartSubType() ); -} - -void KChartLineSubTypeChartPage::slotChangeSubType( int type ) -{ - switch( type ) { - case KDChartParams::AreaNormal: - exampleLA->setPixmap( UserIcon( "chart_line_normal", KChartFactory::global() ) ); - break; - case KDChartParams::AreaStacked: - exampleLA->setPixmap( UserIcon( "chart_line_stacked", KChartFactory::global() ) ); - break; - case KDChartParams::AreaPercent: - exampleLA->setPixmap( UserIcon( "chart_line_percent", KChartFactory::global() ) ); - break; - }; -} - - - -void KChartLineSubTypeChartPage::apply() -{ - if( normal->isChecked() ) - m_params->setLineChartSubType( KDChartParams::LineNormal ); - else if( stacked->isChecked() ) - m_params->setLineChartSubType( KDChartParams::LineStacked ); - else if( percent->isChecked() ) - m_params->setLineChartSubType( KDChartParams::LinePercent ); - else { - kdDebug( 35001 ) << "Error in groupbutton" << endl; - } -} - -KChartPolarSubTypeChartPage::KChartPolarSubTypeChartPage( KChartParams* params, - TQWidget* parent ) : - KChartSubTypeChartPage( params, parent ) -{ - TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); - TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); - TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); - toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); - normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); - subtypeBG->insert( normal, KDChartParams::AreaNormal ); - stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); - subtypeBG->insert( stacked, KDChartParams::AreaStacked ); - percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); - subtypeBG->insert( percent, KDChartParams::AreaPercent ); - subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); - connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( slotChangeSubType( int ) ) ); - - TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); - TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); - toplevel->addWidget( exampleGB, 2 ); - exampleLA = new TQLabel( exampleGB ); - exampleLA->setAlignment( AlignCenter | AlignVCenter ); - // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. -} - -void KChartPolarSubTypeChartPage::init() -{ - switch( m_params->polarChartSubType() ) { - case KDChartParams::PolarNormal: - normal->setChecked( true ); - break; - case KDChartParams::PolarStacked: - stacked->setChecked( true ); - break; - case KDChartParams::PolarPercent: - percent->setChecked( true ); - break; - default: - { - kdDebug( 35001 ) << "Error in stack_type" << endl; - abort(); - break; - } - } - - slotChangeSubType( m_params->lineChartSubType() ); -} - -void KChartPolarSubTypeChartPage::slotChangeSubType( int type ) -{ - switch( type ) { - case KDChartParams::PolarNormal: - exampleLA->setPixmap( UserIcon( "chart_polar_normal", KChartFactory::global() ) ); - break; - case KDChartParams::PolarStacked: - exampleLA->setPixmap( UserIcon( "chart_polar_stacked", KChartFactory::global() ) ); - break; - case KDChartParams::PolarPercent: - exampleLA->setPixmap( UserIcon( "chart_polar_percent", KChartFactory::global() ) ); - break; - }; -} - - - -void KChartPolarSubTypeChartPage::apply() -{ - if( normal->isChecked() ) - m_params->setPolarChartSubType( KDChartParams::PolarNormal ); - else if( stacked->isChecked() ) - m_params->setPolarChartSubType( KDChartParams::PolarStacked ); - else if( percent->isChecked() ) - m_params->setPolarChartSubType( KDChartParams::PolarPercent ); - else { - kdDebug( 35001 ) << "Error in groupbutton" << endl; - } -} - -} //KChart namespace diff --git a/kchart/kchartSubTypeChartPage.cpp b/kchart/kchartSubTypeChartPage.cpp new file mode 100644 index 00000000..9ccad59e --- /dev/null +++ b/kchart/kchartSubTypeChartPage.cpp @@ -0,0 +1,456 @@ +/* This file is part of the KDE project + Copyright (C) 1999,2000 Matthias Kalle Dalheimer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include + +#include "kchartSubTypeChartPage.h" +#include "kchartSubTypeChartPage.moc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +#include "kchart_factory.h" + +namespace KChart +{ + +KChartHiloSubTypeChartPage::KChartHiloSubTypeChartPage( KChartParams* params, + TQWidget* parent ) : + KChartSubTypeChartPage( params, parent ) +{ + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); + TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); + toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); + normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); + subtypeBG->insert( normal, KDChartParams::AreaNormal ); + stacked = new TQRadioButton(i18n("HiLoClose"), subtypeBG ); + subtypeBG->insert( stacked, KDChartParams::AreaStacked ); + percent = new TQRadioButton( i18n("HiLoOpenClose"), subtypeBG ); + subtypeBG->insert( percent, KDChartParams::AreaPercent ); + subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); + connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( slotChangeSubType( int ) ) ); + + TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); + TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); + toplevel->addWidget( exampleGB, 2 ); + exampleLA = new TQLabel( exampleGB ); + exampleLA->setAlignment( AlignCenter | AlignVCenter ); + // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. +} + +void KChartHiloSubTypeChartPage::init() +{ + switch( m_params->hiLoChartSubType() ) { + case KDChartParams::HiLoNormal: + normal->setChecked( true ); + break; + case KDChartParams::HiLoClose: + stacked->setChecked( true ); + break; + case KDChartParams::HiLoOpenClose: + percent->setChecked( true ); + break; + default: + { + kdDebug( 35001 ) << "Error in stack_type" << endl; + abort(); + break; + } + } + + slotChangeSubType( m_params->hiLoChartSubType() ); +} + +void KChartHiloSubTypeChartPage::slotChangeSubType( int type ) +{ + switch( type ) { + case KDChartParams::HiLoNormal: + exampleLA->setPixmap( UserIcon( "chart_hilo_normal", KChartFactory::global() ) ); + break; + case KDChartParams::HiLoClose: + exampleLA->setPixmap( UserIcon( "chart_hilo_close", KChartFactory::global() ) ); + break; + case KDChartParams::HiLoOpenClose: + exampleLA->setPixmap( UserIcon( "chart_hilo_openclose", KChartFactory::global() ) ); + break; + }; +} + + + +void KChartHiloSubTypeChartPage::apply() +{ + if( normal->isChecked() ) + m_params->setHiLoChartSubType( KDChartParams::HiLoNormal ); + else if( stacked->isChecked() ) + m_params->setHiLoChartSubType( KDChartParams::HiLoClose ); + else if( percent->isChecked() ) + m_params->setHiLoChartSubType( KDChartParams::HiLoOpenClose ); + else { + kdDebug( 35001 ) << "Error in groupbutton" << endl; + } +} + +KChartAreaSubTypeChartPage::KChartAreaSubTypeChartPage( KChartParams* params, + TQWidget* parent ) : + KChartSubTypeChartPage( params, parent ) +{ + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); + TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); + toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); + normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); + subtypeBG->insert( normal, KDChartParams::AreaNormal ); + stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); + subtypeBG->insert( stacked, KDChartParams::AreaStacked ); + percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); + subtypeBG->insert( percent, KDChartParams::AreaPercent ); + subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); + connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( slotChangeSubType( int ) ) ); + + TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); + TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); + toplevel->addWidget( exampleGB, 2 ); + exampleLA = new TQLabel( exampleGB ); + exampleLA->setAlignment( AlignCenter | AlignVCenter ); + // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. +} + + +void KChartAreaSubTypeChartPage::init() +{ + switch( m_params->areaChartSubType() ) { + case KDChartParams::AreaNormal: + normal->setChecked( true ); + break; + case KDChartParams::AreaStacked: + stacked->setChecked( true ); + break; + case KDChartParams::AreaPercent: + percent->setChecked( true ); + break; + default: + { + kdDebug( 35001 ) << "Error in stack_type" << endl; + abort(); + break; + } + } + + slotChangeSubType( m_params->areaChartSubType() ); +} + +void KChartAreaSubTypeChartPage::slotChangeSubType( int type ) +{ + switch( type ) { + case KDChartParams::AreaNormal: + exampleLA->setPixmap( UserIcon( "chart_area_normal", KChartFactory::global() ) ); + break; + case KDChartParams::AreaStacked: + exampleLA->setPixmap( UserIcon( "chart_area_stacked", KChartFactory::global() ) ); + break; + case KDChartParams::AreaPercent: + exampleLA->setPixmap( UserIcon( "chart_area_percent", KChartFactory::global() ) ); + break; + }; +} + + + +void KChartAreaSubTypeChartPage::apply() +{ + if( normal->isChecked() ) + m_params->setAreaChartSubType( KDChartParams::AreaNormal ); + else if( stacked->isChecked() ) + m_params->setAreaChartSubType( KDChartParams::AreaStacked ); + else if( percent->isChecked() ) + m_params->setAreaChartSubType( KDChartParams::AreaPercent ); + else { + kdDebug( 35001 ) << "Error in groupbutton" << endl; + } +} + +KChartBarSubTypeChartPage::KChartBarSubTypeChartPage( KChartParams* params, + TQWidget* parent ) : + KChartSubTypeChartPage( params, parent ) +{ + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + TQVBox *left = new TQVBox( this ); + TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), left ); + TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); + //toplevel->addWidget( subtypeBG, AlignCenter ); + toplevel->addWidget( left, AlignCenter ); + + normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); + subtypeBG->insert( normal, KDChartParams::BarNormal ); + stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); + subtypeBG->insert( stacked, KDChartParams::BarStacked ); + percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); + subtypeBG->insert( percent, KDChartParams::BarPercent ); + + subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); + connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( slotChangeSubType( int ) ) ); + + //TQHBox *hbox = new TQHBox( this ); + new TQLabel( i18n( "Number of lines: "), left ); + m_numLines = new TQSpinBox( left ); + // FIXME: Use a grid layout instead + new TQLabel( "", left); + left->setStretchFactor( left, 1 ); + + TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); + TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); + toplevel->addWidget( exampleGB, 2 ); + exampleLA = new TQLabel( exampleGB ); + exampleLA->setAlignment( AlignCenter | AlignVCenter ); +} + +void KChartBarSubTypeChartPage::init() +{ + // SUM is for areas only and therefore not configurable here. + switch( m_params->barChartSubType() ) { + case KDChartParams::BarNormal: + normal->setChecked( true ); + break; + case KDChartParams::BarStacked: + stacked->setChecked( true ); + break; + case KDChartParams::BarPercent: + percent->setChecked( true ); + break; + default: + { + kdDebug( 35001 ) << "Error in stack_type" << endl; + break; + } + } + + m_numLines->setValue( m_params->barNumLines() ); + + slotChangeSubType( m_params->barChartSubType() ); +} + + +void KChartBarSubTypeChartPage::slotChangeSubType( int type ) +{ + switch( type ) { + case KDChartParams::BarStacked: + exampleLA->setPixmap( UserIcon( "chart_bar_layer", KChartFactory::global() ) ); + break; + case KDChartParams::BarNormal: + exampleLA->setPixmap( UserIcon( "chart_bar_beside", KChartFactory::global() ) ); + break; + case KDChartParams::BarPercent: + exampleLA->setPixmap( UserIcon( "chart_bar_percent", KChartFactory::global() ) ); + break; + }; +} + + +void KChartBarSubTypeChartPage::apply() +{ + if( normal->isChecked() ) { + m_params->setBarChartSubType( KDChartParams::BarNormal ); + } else if( stacked->isChecked() ) { + m_params->setBarChartSubType( KDChartParams::BarStacked ); + } else if( percent->isChecked() ) { + m_params->setBarChartSubType( KDChartParams::BarPercent ); + } else { + kdDebug( 35001 ) << "Error in groupbutton" << endl; + } + + // FIXME: Error controls. + m_params->setBarNumLines( m_numLines->value() ); +} + +KChartLineSubTypeChartPage::KChartLineSubTypeChartPage( KChartParams* params, + TQWidget* parent ) : + KChartSubTypeChartPage( params, parent ) +{ + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); + TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); + toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); + normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); + subtypeBG->insert( normal, KDChartParams::AreaNormal ); + stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); + subtypeBG->insert( stacked, KDChartParams::AreaStacked ); + percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); + subtypeBG->insert( percent, KDChartParams::AreaPercent ); + subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); + connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( slotChangeSubType( int ) ) ); + + TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); + TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); + toplevel->addWidget( exampleGB, 2 ); + exampleLA = new TQLabel( exampleGB ); + exampleLA->setAlignment( AlignCenter | AlignVCenter ); + // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. +} + +void KChartLineSubTypeChartPage::init() +{ + switch( m_params->lineChartSubType() ) { + case KDChartParams::LineNormal: + normal->setChecked( true ); + break; + case KDChartParams::LineStacked: + stacked->setChecked( true ); + break; + case KDChartParams::LinePercent: + percent->setChecked( true ); + break; + default: + { + kdDebug( 35001 ) << "Error in stack_type" << endl; + abort(); + break; + } + } + + slotChangeSubType( m_params->lineChartSubType() ); +} + +void KChartLineSubTypeChartPage::slotChangeSubType( int type ) +{ + switch( type ) { + case KDChartParams::AreaNormal: + exampleLA->setPixmap( UserIcon( "chart_line_normal", KChartFactory::global() ) ); + break; + case KDChartParams::AreaStacked: + exampleLA->setPixmap( UserIcon( "chart_line_stacked", KChartFactory::global() ) ); + break; + case KDChartParams::AreaPercent: + exampleLA->setPixmap( UserIcon( "chart_line_percent", KChartFactory::global() ) ); + break; + }; +} + + + +void KChartLineSubTypeChartPage::apply() +{ + if( normal->isChecked() ) + m_params->setLineChartSubType( KDChartParams::LineNormal ); + else if( stacked->isChecked() ) + m_params->setLineChartSubType( KDChartParams::LineStacked ); + else if( percent->isChecked() ) + m_params->setLineChartSubType( KDChartParams::LinePercent ); + else { + kdDebug( 35001 ) << "Error in groupbutton" << endl; + } +} + +KChartPolarSubTypeChartPage::KChartPolarSubTypeChartPage( KChartParams* params, + TQWidget* parent ) : + KChartSubTypeChartPage( params, parent ) +{ + TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 ); + TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this ); + TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown.")); + toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter ); + normal = new TQRadioButton( i18n( "Normal" ), subtypeBG ); + subtypeBG->insert( normal, KDChartParams::AreaNormal ); + stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG ); + subtypeBG->insert( stacked, KDChartParams::AreaStacked ); + percent = new TQRadioButton( i18n( "Percent" ), subtypeBG ); + subtypeBG->insert( percent, KDChartParams::AreaPercent ); + subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() ); + connect( subtypeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( slotChangeSubType( int ) ) ); + + TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this ); + TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose.")); + toplevel->addWidget( exampleGB, 2 ); + exampleLA = new TQLabel( exampleGB ); + exampleLA->setAlignment( AlignCenter | AlignVCenter ); + // PENDING(kalle) Make image scale with available space once TQt 2.2 is out. +} + +void KChartPolarSubTypeChartPage::init() +{ + switch( m_params->polarChartSubType() ) { + case KDChartParams::PolarNormal: + normal->setChecked( true ); + break; + case KDChartParams::PolarStacked: + stacked->setChecked( true ); + break; + case KDChartParams::PolarPercent: + percent->setChecked( true ); + break; + default: + { + kdDebug( 35001 ) << "Error in stack_type" << endl; + abort(); + break; + } + } + + slotChangeSubType( m_params->lineChartSubType() ); +} + +void KChartPolarSubTypeChartPage::slotChangeSubType( int type ) +{ + switch( type ) { + case KDChartParams::PolarNormal: + exampleLA->setPixmap( UserIcon( "chart_polar_normal", KChartFactory::global() ) ); + break; + case KDChartParams::PolarStacked: + exampleLA->setPixmap( UserIcon( "chart_polar_stacked", KChartFactory::global() ) ); + break; + case KDChartParams::PolarPercent: + exampleLA->setPixmap( UserIcon( "chart_polar_percent", KChartFactory::global() ) ); + break; + }; +} + + + +void KChartPolarSubTypeChartPage::apply() +{ + if( normal->isChecked() ) + m_params->setPolarChartSubType( KDChartParams::PolarNormal ); + else if( stacked->isChecked() ) + m_params->setPolarChartSubType( KDChartParams::PolarStacked ); + else if( percent->isChecked() ) + m_params->setPolarChartSubType( KDChartParams::PolarPercent ); + else { + kdDebug( 35001 ) << "Error in groupbutton" << endl; + } +} + +} //KChart namespace diff --git a/kchart/kchartWizard.cc b/kchart/kchartWizard.cc deleted file mode 100644 index 01e5bf45..00000000 --- a/kchart/kchartWizard.cc +++ /dev/null @@ -1,171 +0,0 @@ - -#include "kchartWizard.h" -#include "kchartWizardSelectDataPage.h" -#include "kchartWizardSelectChartTypePage.h" -#include "kchartWizardSelectChartSubTypePage.h" -#include "kchartWizardSetupDataPage.h" -#include "kchartWizardLabelsLegendPage.h" -#include "kchartWizardSetupAxesPage.h" -#include "kchartWizardSelectDataFormatPage.h" - -#include -#include -#include - -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartWizard::KChartWizard ( KChartPart* _chart, TQWidget *parent, const char* name, - bool modal, WFlags f ) : - KWizard( parent, name, modal, f ), - m_chart( _chart ) -{ - // First page: select the data range - m_dataFormatPage = new KChartWizardSelectDataFormatPage(this, m_chart); - addPage( m_dataFormatPage, i18n("Data")); - setFinishEnabled(m_dataFormatPage, true); - setHelpEnabled(m_dataFormatPage, false); - - // Second page: select the major chart type - m_chartTypePage = new KChartWizardSelectChartTypePage( this, m_chart ); - addPage( m_chartTypePage, i18n( "Select Chart Type" ) ); - //finishButton()->setEnabled( TRUE ); - setFinishEnabled(m_chartTypePage, true); - setHelpEnabled(m_chartTypePage, false); - - // Third page: select the minor chart type - m_chartSubtypePage = new KChartWizardSelectChartSubTypePage( this, m_chart ); - addPage( m_chartSubtypePage, i18n( "Select Chart Sub-type" ) ); - setFinishEnabled(m_chartSubtypePage, true); - setHelpEnabled(m_chartSubtypePage, false); - - // Fourth page: labels/legends setup - m_labelsLegendPage = new KChartWizardLabelsLegendPage( this, m_chart ); - addPage( m_labelsLegendPage, i18n( "Labels & Legend" ) ); - setFinishEnabled(m_labelsLegendPage, true); - setHelpEnabled(m_labelsLegendPage, false); - - // Fifth page: axes setup - m_axespage = new KChartWizardSetupAxesPage( this, m_chart ); - addPage( m_axespage, i18n( "Setup Axes" ) ); - setFinishEnabled(m_axespage, true); - setNextEnabled(m_axespage, false); - setHelpEnabled(m_axespage, false); - - // connect( this, TQT_SIGNAL( finished() ), _selectdatapage, TQT_SLOT( apply() ) ); - connect(this, TQT_SIGNAL(finished()), m_dataFormatPage, TQT_SLOT(apply())); - connect(this, TQT_SIGNAL(finished()), m_chartTypePage, TQT_SLOT(apply())); - connect(this ,TQT_SIGNAL(finished()), m_chartSubtypePage, TQT_SLOT(apply())); - connect(this, TQT_SIGNAL(finished()), m_labelsLegendPage, TQT_SLOT(apply())); - connect(this, TQT_SIGNAL(finished()), m_axespage, TQT_SLOT(apply())); - - connect( m_chartTypePage, TQT_SIGNAL( chartChange( int ) ), - this, TQT_SLOT( subType( int ) ) ); - adjustSize(); - - subType( m_chart->params()->chartType() ); - kdDebug(35001) << "kchartwizard created" << endl; -} - - -KChartWizard::~KChartWizard() -{ - // delete _selectdatapage; - delete m_chartTypePage; - delete m_chartSubtypePage; - //delete _setupdatapage; - delete m_labelsLegendPage; - delete m_axespage; - delete m_dataFormatPage; -} - -void KChartWizard::subType(int _type) -{ - KChartParams::ChartType type = (KChartParams::ChartType) _type; - if (type == KChartParams::Bar || - type == KChartParams::Line || - type == KChartParams::Area || - type == KChartParams::HiLo || - type == KChartParams::Polar) { - m_chartSubtypePage->chartSubType = true; - } else { - m_chartSubtypePage->chartSubType = false; - } - m_chartSubtypePage->changeSubTypeName( type ); - if( ( type == KChartParams::Bar && m_chart->params()->threeDBars() ) - || ( type == KChartParams::Pie && m_chart->params()->threeDPies() ) ) { - m_axespage->chart3d = true; - } else { - m_axespage->chart3d = false; - } - -#if 0 // No second Y axis so far /ingwa - if ( m_chart->params()->axisVisible( KDChartAxisParams::AxisPosRight ) ) { - m_labelsLegendPage->ytitle2 = true; - } else { - m_labelsLegendPage->ytitle2 = false; - } -#endif -} - - -bool KChartWizard::appropriate( TQWidget * w ) const -{ - // Show the sub-type page only if has anything to show - if ( w == m_chartSubtypePage ) - return m_chartSubtypePage->chartSubType; - else - return true; -} - - -void KChartWizard::next() -{ - // Some sort of a hack. We want the chart-subtype-page to get - // dynamically built when it's going to be shown - //if ( currentPage() == _charttypePage ) - //_chartSubtypePage->createChildren(); - - TQWizard::next(); -} - -void KChartWizard::accept() -{ - emit finished(); - TQWizard::accept(); -} - -void KChartWizard::reject() -{ - emit cancelled(); - TQWizard::reject(); -} - -void KChartWizard::setDataArea( const TQString &dataArea ) -{ - m_dataFormatPage->setDataArea( dataArea ); -} - - -TQString KChartWizard::dataArea() const -{ - return m_dataFormatPage->dataArea(); -} - - -void KChartWizard::emitNeedNewData( const char* area, int rowcol, - bool firstRowIsLegend, - bool firstColIsLabel ) -{ - emit needNewData( area, rowcol, firstRowIsLegend, firstColIsLabel ); -} - -} //KChart namespace - -#include "kchartWizard.moc" diff --git a/kchart/kchartWizard.cpp b/kchart/kchartWizard.cpp new file mode 100644 index 00000000..01e5bf45 --- /dev/null +++ b/kchart/kchartWizard.cpp @@ -0,0 +1,171 @@ + +#include "kchartWizard.h" +#include "kchartWizardSelectDataPage.h" +#include "kchartWizardSelectChartTypePage.h" +#include "kchartWizardSelectChartSubTypePage.h" +#include "kchartWizardSetupDataPage.h" +#include "kchartWizardLabelsLegendPage.h" +#include "kchartWizardSetupAxesPage.h" +#include "kchartWizardSelectDataFormatPage.h" + +#include +#include +#include + +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartWizard::KChartWizard ( KChartPart* _chart, TQWidget *parent, const char* name, + bool modal, WFlags f ) : + KWizard( parent, name, modal, f ), + m_chart( _chart ) +{ + // First page: select the data range + m_dataFormatPage = new KChartWizardSelectDataFormatPage(this, m_chart); + addPage( m_dataFormatPage, i18n("Data")); + setFinishEnabled(m_dataFormatPage, true); + setHelpEnabled(m_dataFormatPage, false); + + // Second page: select the major chart type + m_chartTypePage = new KChartWizardSelectChartTypePage( this, m_chart ); + addPage( m_chartTypePage, i18n( "Select Chart Type" ) ); + //finishButton()->setEnabled( TRUE ); + setFinishEnabled(m_chartTypePage, true); + setHelpEnabled(m_chartTypePage, false); + + // Third page: select the minor chart type + m_chartSubtypePage = new KChartWizardSelectChartSubTypePage( this, m_chart ); + addPage( m_chartSubtypePage, i18n( "Select Chart Sub-type" ) ); + setFinishEnabled(m_chartSubtypePage, true); + setHelpEnabled(m_chartSubtypePage, false); + + // Fourth page: labels/legends setup + m_labelsLegendPage = new KChartWizardLabelsLegendPage( this, m_chart ); + addPage( m_labelsLegendPage, i18n( "Labels & Legend" ) ); + setFinishEnabled(m_labelsLegendPage, true); + setHelpEnabled(m_labelsLegendPage, false); + + // Fifth page: axes setup + m_axespage = new KChartWizardSetupAxesPage( this, m_chart ); + addPage( m_axespage, i18n( "Setup Axes" ) ); + setFinishEnabled(m_axespage, true); + setNextEnabled(m_axespage, false); + setHelpEnabled(m_axespage, false); + + // connect( this, TQT_SIGNAL( finished() ), _selectdatapage, TQT_SLOT( apply() ) ); + connect(this, TQT_SIGNAL(finished()), m_dataFormatPage, TQT_SLOT(apply())); + connect(this, TQT_SIGNAL(finished()), m_chartTypePage, TQT_SLOT(apply())); + connect(this ,TQT_SIGNAL(finished()), m_chartSubtypePage, TQT_SLOT(apply())); + connect(this, TQT_SIGNAL(finished()), m_labelsLegendPage, TQT_SLOT(apply())); + connect(this, TQT_SIGNAL(finished()), m_axespage, TQT_SLOT(apply())); + + connect( m_chartTypePage, TQT_SIGNAL( chartChange( int ) ), + this, TQT_SLOT( subType( int ) ) ); + adjustSize(); + + subType( m_chart->params()->chartType() ); + kdDebug(35001) << "kchartwizard created" << endl; +} + + +KChartWizard::~KChartWizard() +{ + // delete _selectdatapage; + delete m_chartTypePage; + delete m_chartSubtypePage; + //delete _setupdatapage; + delete m_labelsLegendPage; + delete m_axespage; + delete m_dataFormatPage; +} + +void KChartWizard::subType(int _type) +{ + KChartParams::ChartType type = (KChartParams::ChartType) _type; + if (type == KChartParams::Bar || + type == KChartParams::Line || + type == KChartParams::Area || + type == KChartParams::HiLo || + type == KChartParams::Polar) { + m_chartSubtypePage->chartSubType = true; + } else { + m_chartSubtypePage->chartSubType = false; + } + m_chartSubtypePage->changeSubTypeName( type ); + if( ( type == KChartParams::Bar && m_chart->params()->threeDBars() ) + || ( type == KChartParams::Pie && m_chart->params()->threeDPies() ) ) { + m_axespage->chart3d = true; + } else { + m_axespage->chart3d = false; + } + +#if 0 // No second Y axis so far /ingwa + if ( m_chart->params()->axisVisible( KDChartAxisParams::AxisPosRight ) ) { + m_labelsLegendPage->ytitle2 = true; + } else { + m_labelsLegendPage->ytitle2 = false; + } +#endif +} + + +bool KChartWizard::appropriate( TQWidget * w ) const +{ + // Show the sub-type page only if has anything to show + if ( w == m_chartSubtypePage ) + return m_chartSubtypePage->chartSubType; + else + return true; +} + + +void KChartWizard::next() +{ + // Some sort of a hack. We want the chart-subtype-page to get + // dynamically built when it's going to be shown + //if ( currentPage() == _charttypePage ) + //_chartSubtypePage->createChildren(); + + TQWizard::next(); +} + +void KChartWizard::accept() +{ + emit finished(); + TQWizard::accept(); +} + +void KChartWizard::reject() +{ + emit cancelled(); + TQWizard::reject(); +} + +void KChartWizard::setDataArea( const TQString &dataArea ) +{ + m_dataFormatPage->setDataArea( dataArea ); +} + + +TQString KChartWizard::dataArea() const +{ + return m_dataFormatPage->dataArea(); +} + + +void KChartWizard::emitNeedNewData( const char* area, int rowcol, + bool firstRowIsLegend, + bool firstColIsLabel ) +{ + emit needNewData( area, rowcol, firstRowIsLegend, firstColIsLabel ); +} + +} //KChart namespace + +#include "kchartWizard.moc" diff --git a/kchart/kchartWizardLabelsLegendPage.cc b/kchart/kchartWizardLabelsLegendPage.cc deleted file mode 100644 index 3899a276..00000000 --- a/kchart/kchartWizardLabelsLegendPage.cc +++ /dev/null @@ -1,340 +0,0 @@ -#include "kchartWizardLabelsLegendPage.h" -#include "kchart_view.h" -#include "kchart_part.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartWizardLabelsLegendPage::KChartWizardLabelsLegendPage( TQWidget* parent, KChartPart* chart ) : - TQWidget( parent ), - _chart( chart ) -{ -#if 0 - ytitle2=true; -#endif - - KDChartAxisParams leftparams; - leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams bottomparams; - bottomparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosBottom ); - x_color=bottomparams.axisLineColor(); - y_color=leftparams.axisLineColor(); - xlabel=bottomparams.axisLabelsFont(); - ylabel=leftparams.axisLabelsFont(); - - TQGridLayout *grid1 = new TQGridLayout(this,2,2,KDialog::marginHint(), KDialog::spacingHint()); - - TQGroupBox* tmpTQGroupBox; - tmpTQGroupBox = new TQGroupBox( this, "GroupBox_1" ); - tmpTQGroupBox->setFrameStyle( 49 ); - - TQGridLayout *grid2 = new TQGridLayout(tmpTQGroupBox,4,4,KDialog::marginHint(), KDialog::spacingHint()); - - TQLabel* titleLA = new TQLabel( i18n( "Title:" ),tmpTQGroupBox ); - grid2->addWidget(titleLA,0,0); - - _titleED = new TQLineEdit( tmpTQGroupBox ); - grid2->addWidget(_titleED,0,1); - _titleED->setText( _chart->params()->header1Text() ); - - titlefont = new TQPushButton( tmpTQGroupBox ); - grid2->addWidget(titlefont,0,2); - titlefont->setText(i18n("Font...")); - - titlecolor=new KColorButton(tmpTQGroupBox); - grid2->addWidget(titlecolor,0,3); - title_color=_chart->params()->headerFooterColor( KDChartParams::HdFtPosHeader ); - titlecolor->setColor( title_color ); - - - TQLabel* xlabelLA = new TQLabel( i18n( "X-title:" ), tmpTQGroupBox ); - //xlabelLA->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(xlabelLA,1,0); - - _xlabelED = new TQLineEdit( tmpTQGroupBox ); - //_xlabelED->setEnabled(false); //Not supported by kdChart yet - _xlabelED->setText(_chart->params()->axisTitle( KDChartAxisParams::AxisPosBottom)); - grid2->addWidget(_xlabelED,1,1); - - xtitlefont = new TQPushButton( tmpTQGroupBox ); - xtitlefont->setText(i18n("Font...")); - //xtitlefont->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(xtitlefont,1,2); - - xtitlecolor=new KColorButton(tmpTQGroupBox); - // PENDING(kalle) Put back in - // x_color=_chart->params()->XTitleColor; - xtitlecolor->setColor( x_color ); - //xtitlecolor->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(xtitlecolor,1,3); - - - TQLabel* ylabelLA = new TQLabel( i18n( "Y-title:" ), tmpTQGroupBox ); - //ylabelLA->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(ylabelLA,2,0); - - _ylabelED = new TQLineEdit( tmpTQGroupBox ); - //_ylabelED->setEnabled(false); //Not supported by kdChart yet - _ylabelED->setText(_chart->params()->axisTitle( KDChartAxisParams::AxisPosLeft)); - grid2->addWidget(_ylabelED,2,1); - - - ytitlefont = new TQPushButton( tmpTQGroupBox); - ytitlefont->setText(i18n("Font...")); - //ytitlefont->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(ytitlefont,2,2); - - ytitlecolor=new KColorButton(tmpTQGroupBox); - //ytitlecolor->setEnabled(false); //Not supported by kdChart yet - // PENDING(kalle) Put back in - // y_color=_chart->params()->YTitleColor; - ytitlecolor->setColor( y_color ); - grid2->addWidget(ytitlecolor,2,3); - -#if 0 - //ytitle2 doesn't work - TQLabel* ylabelLA2 = new TQLabel( i18n( "Y-title 2:" ), tmpTQGroupBox ); - ylabelLA2->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(ylabelLA2,3,0); - - _ylabel2ED = new TQLineEdit( tmpTQGroupBox ); - _ylabel2ED->setEnabled(false); //Not supported by kdChart yet - // PENDING(kalle) Put back in - // _ylabel2ED->setText(_chart->params()->ytitle2); - grid2->addWidget(_ylabel2ED,3,1); - - ytitle2font = new TQPushButton( tmpTQGroupBox); - ytitle2font->setText(i18n("Font...")); - ytitle2font->setEnabled(false); //Not supported by kdChart yet - grid2->addWidget(ytitle2font,3,2); - - ytitle2color=new KColorButton(tmpTQGroupBox); - ytitle2color->setEnabled(false); //Not supported by kdChart yet - // PENDING(kalle) Put back in - // y_color2=_chart->params()->YTitle2Color; - ytitle2color->setColor( y_color2 ); - grid2->addWidget(ytitle2color,3,3); -#endif - - // PENDING(kalle) Put back in - // xlabel=_chart->params()->xTitleFont(); - // ylabel=_chart->params()->yTitleFont(); - - - TQLabel* lab = new TQLabel( i18n( "Legend title:" ), tmpTQGroupBox ); - grid2->addWidget(lab,3,0); - - _legendTitleText = new TQLineEdit( tmpTQGroupBox ); - grid2->addWidget(_legendTitleText,3,1); - _legendTitleText->setText( _chart->params()->legendTitleText() ); - - - legendTitleFont = new TQPushButton( tmpTQGroupBox ); - legendTitleFont->setText(i18n("Font...")); - _legendTitleFont=_chart->params()->legendTitleFont(); - grid2->addWidget(legendTitleFont,3,2); - - legendTitleColor=new KColorButton(tmpTQGroupBox); - _legendTitleColor=_chart->params()->legendTitleTextColor(); - legendTitleColor->setColor( _legendTitleColor ); - grid2->addWidget(legendTitleColor,3,3); - - - lab = new TQLabel( i18n( "Legend text:" ), tmpTQGroupBox ); - grid2->addWidget(lab,4,0); - - legendTextFont = new TQPushButton( tmpTQGroupBox ); - _legendTextFont=_chart->params()->legendFont(); - legendTextFont->setText(i18n("Font...")); - grid2->addWidget(legendTextFont,4,2); - - legendTextColor=new KColorButton(tmpTQGroupBox); - _legendTextColor=_chart->params()->legendTextColor(); - legendTextColor->setColor( _legendTextColor ); - grid2->addWidget(legendTextColor,4,3); - - title=_chart->params()->header1Font(); - grid1->addWidget(tmpTQGroupBox,0,0); - - connect(xtitlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeXLabelFont())); - connect(ytitlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeYLabelFont())); -#if 0 - connect(ytitle2font,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeY2LabelFont())); -#endif - connect(titlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeTitleFont())); - connect(legendTitleFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLegendTitleFont())); - - connect(legendTextFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLegendTextFont())); - - connect(xtitlecolor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeXLabelColor(const TQColor &))); - connect(ytitlecolor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeYLabelColor(const TQColor &))); - connect(titlecolor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeTitleColor(const TQColor &))); -#if 0 - connect(ytitle2color,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeYTitle2Color(const TQColor &))); -#endif - connect(legendTitleColor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeLegendTitleColor(const TQColor &))); - - connect(legendTextColor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeLegendTextColor(const TQColor &))); - -} - - -KChartWizardLabelsLegendPage::~KChartWizardLabelsLegendPage() -{ - // _chart->removeAutoUpdate( preview ); -} - -void KChartWizardLabelsLegendPage::changeLegendTextFont() -{ - if (TDEFontDialog::getFont( _legendTextFont,false,this ) == TQDialog::Rejected ) - return; -} - -void KChartWizardLabelsLegendPage::changeLegendTitleFont() -{ - if (TDEFontDialog::getFont( _legendTitleFont,false,this ) == TQDialog::Rejected ) - return; -} - -void KChartWizardLabelsLegendPage::changeXLabelFont() -{ - if (TDEFontDialog::getFont( xlabel,false,this ) == TQDialog::Rejected ) - return; -} - -void KChartWizardLabelsLegendPage::changeYLabelFont() -{ - if (TDEFontDialog::getFont( ylabel ,false,this ) == TQDialog::Rejected ) - return; -} - -#if 0 -void KChartWizardLabelsLegendPage::changeY2LabelFont() -{ - if (TDEFontDialog::getFont( ylabel2, false, this ) == TQDialog::Rejected ) - return; -} -#endif - -void KChartWizardLabelsLegendPage::changeTitleFont() -{ - if (TDEFontDialog::getFont( title ,false,this ) == TQDialog::Rejected ) - return; - -} - -void KChartWizardLabelsLegendPage::changeLegendTextColor(const TQColor &_color) -{ - _legendTextColor=_color; -} - -void KChartWizardLabelsLegendPage::changeXLabelColor(const TQColor &_color) -{ - x_color=_color; -} - -void KChartWizardLabelsLegendPage::changeYLabelColor(const TQColor &_color) -{ - y_color=_color; -} - -void KChartWizardLabelsLegendPage::changeTitleColor(const TQColor &_color) -{ - title_color=_color; -} - -#if 0 -void KChartWizardLabelsLegendPage::changeYTitle2Color(const TQColor &_color) -{ - y_color2=_color; -} -#endif - -void KChartWizardLabelsLegendPage::changeLegendTitleColor(const TQColor &_color) -{ - _legendTitleColor=_color; -} - -void KChartWizardLabelsLegendPage::paintEvent( TQPaintEvent * ) -{ -#if 0 - if( ytitle2 ) { - _ylabel2ED->setEnabled(true); - ytitle2color->setEnabled(true); - } - else { - _ylabel2ED->setEnabled(false); - ytitle2color->setEnabled(false); - } -#endif -} - -void KChartWizardLabelsLegendPage::apply( ) -{ - _chart->params()->setHeader1Text( _titleED->text() ); - - // PENDING(kalle) Put back in - // _chart->params()->setXTitleFont(xlabel); - // _chart->params()->setYTitleFont(ylabel); - // _chart->params()->xtitle= _xlabelED->text(); - // _chart->params()->ytitle= _ylabelED->text(); - // _chart->params()->XTitleColor=x_color; - // _chart->params()->YTitleColor=y_color; - // _chart->params()->YTitle2Color=y_color2; - // _chart->params()->ytitle2=_ylabel2ED->text(); - - _chart->params()->setHeaderFooterColor( KDChartParams::HdFtPosHeader, title_color ); - _chart->params()->setHeaderFooterFont( KDChartParams::HdFtPosHeader, title, true, title.pointSize()*4 ); - _chart->params()->setAxisTitle( KDChartAxisParams::AxisPosBottom, _xlabelED->text() ); - _chart->params()->setAxisTitle( KDChartAxisParams::AxisPosLeft, _ylabelED->text() ); - - _chart->params()->setLegendTitleText(_legendTitleText->text()); - _chart->params()->setLegendTitleTextColor(_legendTitleColor); - _chart->params()->setLegendTitleFont( _legendTitleFont,false); - _chart->params()->setLegendTitleFontRelSize( _legendTitleFont.pointSize()*4 ); - _chart->params()->setLegendTextColor(_legendTextColor); - _chart->params()->setLegendFont( _legendTextFont,false); - _chart->params()->setLegendFontRelSize( _legendTextFont.pointSize()*4 ); - - KDChartAxisParams leftparams; - leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams bottomparams; - bottomparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosBottom ); - if( x_color.isValid() ) - bottomparams.setAxisLineColor( x_color ); - if( y_color.isValid() ) - leftparams.setAxisLineColor( y_color ); - if(bottomparams.axisLabelsFont()!=xlabel){ - bottomparams.setAxisLabelsFont( xlabel,false ); - bottomparams.setAxisLabelsFontRelSize( xlabel.pointSize()*4 ); - } - if(leftparams.axisLabelsFont()!=ylabel){ - leftparams.setAxisLabelsFont( ylabel,false ); - leftparams.setAxisLabelsFontRelSize( ylabel.pointSize()*4 ); - } - - _chart->params()->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams ); - _chart->params()->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); -} - -} //KChart namespace - -#include "kchartWizardLabelsLegendPage.moc" diff --git a/kchart/kchartWizardLabelsLegendPage.cpp b/kchart/kchartWizardLabelsLegendPage.cpp new file mode 100644 index 00000000..3899a276 --- /dev/null +++ b/kchart/kchartWizardLabelsLegendPage.cpp @@ -0,0 +1,340 @@ +#include "kchartWizardLabelsLegendPage.h" +#include "kchart_view.h" +#include "kchart_part.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartWizardLabelsLegendPage::KChartWizardLabelsLegendPage( TQWidget* parent, KChartPart* chart ) : + TQWidget( parent ), + _chart( chart ) +{ +#if 0 + ytitle2=true; +#endif + + KDChartAxisParams leftparams; + leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams bottomparams; + bottomparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosBottom ); + x_color=bottomparams.axisLineColor(); + y_color=leftparams.axisLineColor(); + xlabel=bottomparams.axisLabelsFont(); + ylabel=leftparams.axisLabelsFont(); + + TQGridLayout *grid1 = new TQGridLayout(this,2,2,KDialog::marginHint(), KDialog::spacingHint()); + + TQGroupBox* tmpTQGroupBox; + tmpTQGroupBox = new TQGroupBox( this, "GroupBox_1" ); + tmpTQGroupBox->setFrameStyle( 49 ); + + TQGridLayout *grid2 = new TQGridLayout(tmpTQGroupBox,4,4,KDialog::marginHint(), KDialog::spacingHint()); + + TQLabel* titleLA = new TQLabel( i18n( "Title:" ),tmpTQGroupBox ); + grid2->addWidget(titleLA,0,0); + + _titleED = new TQLineEdit( tmpTQGroupBox ); + grid2->addWidget(_titleED,0,1); + _titleED->setText( _chart->params()->header1Text() ); + + titlefont = new TQPushButton( tmpTQGroupBox ); + grid2->addWidget(titlefont,0,2); + titlefont->setText(i18n("Font...")); + + titlecolor=new KColorButton(tmpTQGroupBox); + grid2->addWidget(titlecolor,0,3); + title_color=_chart->params()->headerFooterColor( KDChartParams::HdFtPosHeader ); + titlecolor->setColor( title_color ); + + + TQLabel* xlabelLA = new TQLabel( i18n( "X-title:" ), tmpTQGroupBox ); + //xlabelLA->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(xlabelLA,1,0); + + _xlabelED = new TQLineEdit( tmpTQGroupBox ); + //_xlabelED->setEnabled(false); //Not supported by kdChart yet + _xlabelED->setText(_chart->params()->axisTitle( KDChartAxisParams::AxisPosBottom)); + grid2->addWidget(_xlabelED,1,1); + + xtitlefont = new TQPushButton( tmpTQGroupBox ); + xtitlefont->setText(i18n("Font...")); + //xtitlefont->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(xtitlefont,1,2); + + xtitlecolor=new KColorButton(tmpTQGroupBox); + // PENDING(kalle) Put back in + // x_color=_chart->params()->XTitleColor; + xtitlecolor->setColor( x_color ); + //xtitlecolor->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(xtitlecolor,1,3); + + + TQLabel* ylabelLA = new TQLabel( i18n( "Y-title:" ), tmpTQGroupBox ); + //ylabelLA->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(ylabelLA,2,0); + + _ylabelED = new TQLineEdit( tmpTQGroupBox ); + //_ylabelED->setEnabled(false); //Not supported by kdChart yet + _ylabelED->setText(_chart->params()->axisTitle( KDChartAxisParams::AxisPosLeft)); + grid2->addWidget(_ylabelED,2,1); + + + ytitlefont = new TQPushButton( tmpTQGroupBox); + ytitlefont->setText(i18n("Font...")); + //ytitlefont->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(ytitlefont,2,2); + + ytitlecolor=new KColorButton(tmpTQGroupBox); + //ytitlecolor->setEnabled(false); //Not supported by kdChart yet + // PENDING(kalle) Put back in + // y_color=_chart->params()->YTitleColor; + ytitlecolor->setColor( y_color ); + grid2->addWidget(ytitlecolor,2,3); + +#if 0 + //ytitle2 doesn't work + TQLabel* ylabelLA2 = new TQLabel( i18n( "Y-title 2:" ), tmpTQGroupBox ); + ylabelLA2->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(ylabelLA2,3,0); + + _ylabel2ED = new TQLineEdit( tmpTQGroupBox ); + _ylabel2ED->setEnabled(false); //Not supported by kdChart yet + // PENDING(kalle) Put back in + // _ylabel2ED->setText(_chart->params()->ytitle2); + grid2->addWidget(_ylabel2ED,3,1); + + ytitle2font = new TQPushButton( tmpTQGroupBox); + ytitle2font->setText(i18n("Font...")); + ytitle2font->setEnabled(false); //Not supported by kdChart yet + grid2->addWidget(ytitle2font,3,2); + + ytitle2color=new KColorButton(tmpTQGroupBox); + ytitle2color->setEnabled(false); //Not supported by kdChart yet + // PENDING(kalle) Put back in + // y_color2=_chart->params()->YTitle2Color; + ytitle2color->setColor( y_color2 ); + grid2->addWidget(ytitle2color,3,3); +#endif + + // PENDING(kalle) Put back in + // xlabel=_chart->params()->xTitleFont(); + // ylabel=_chart->params()->yTitleFont(); + + + TQLabel* lab = new TQLabel( i18n( "Legend title:" ), tmpTQGroupBox ); + grid2->addWidget(lab,3,0); + + _legendTitleText = new TQLineEdit( tmpTQGroupBox ); + grid2->addWidget(_legendTitleText,3,1); + _legendTitleText->setText( _chart->params()->legendTitleText() ); + + + legendTitleFont = new TQPushButton( tmpTQGroupBox ); + legendTitleFont->setText(i18n("Font...")); + _legendTitleFont=_chart->params()->legendTitleFont(); + grid2->addWidget(legendTitleFont,3,2); + + legendTitleColor=new KColorButton(tmpTQGroupBox); + _legendTitleColor=_chart->params()->legendTitleTextColor(); + legendTitleColor->setColor( _legendTitleColor ); + grid2->addWidget(legendTitleColor,3,3); + + + lab = new TQLabel( i18n( "Legend text:" ), tmpTQGroupBox ); + grid2->addWidget(lab,4,0); + + legendTextFont = new TQPushButton( tmpTQGroupBox ); + _legendTextFont=_chart->params()->legendFont(); + legendTextFont->setText(i18n("Font...")); + grid2->addWidget(legendTextFont,4,2); + + legendTextColor=new KColorButton(tmpTQGroupBox); + _legendTextColor=_chart->params()->legendTextColor(); + legendTextColor->setColor( _legendTextColor ); + grid2->addWidget(legendTextColor,4,3); + + title=_chart->params()->header1Font(); + grid1->addWidget(tmpTQGroupBox,0,0); + + connect(xtitlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeXLabelFont())); + connect(ytitlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeYLabelFont())); +#if 0 + connect(ytitle2font,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeY2LabelFont())); +#endif + connect(titlefont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeTitleFont())); + connect(legendTitleFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLegendTitleFont())); + + connect(legendTextFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLegendTextFont())); + + connect(xtitlecolor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeXLabelColor(const TQColor &))); + connect(ytitlecolor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeYLabelColor(const TQColor &))); + connect(titlecolor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeTitleColor(const TQColor &))); +#if 0 + connect(ytitle2color,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeYTitle2Color(const TQColor &))); +#endif + connect(legendTitleColor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeLegendTitleColor(const TQColor &))); + + connect(legendTextColor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeLegendTextColor(const TQColor &))); + +} + + +KChartWizardLabelsLegendPage::~KChartWizardLabelsLegendPage() +{ + // _chart->removeAutoUpdate( preview ); +} + +void KChartWizardLabelsLegendPage::changeLegendTextFont() +{ + if (TDEFontDialog::getFont( _legendTextFont,false,this ) == TQDialog::Rejected ) + return; +} + +void KChartWizardLabelsLegendPage::changeLegendTitleFont() +{ + if (TDEFontDialog::getFont( _legendTitleFont,false,this ) == TQDialog::Rejected ) + return; +} + +void KChartWizardLabelsLegendPage::changeXLabelFont() +{ + if (TDEFontDialog::getFont( xlabel,false,this ) == TQDialog::Rejected ) + return; +} + +void KChartWizardLabelsLegendPage::changeYLabelFont() +{ + if (TDEFontDialog::getFont( ylabel ,false,this ) == TQDialog::Rejected ) + return; +} + +#if 0 +void KChartWizardLabelsLegendPage::changeY2LabelFont() +{ + if (TDEFontDialog::getFont( ylabel2, false, this ) == TQDialog::Rejected ) + return; +} +#endif + +void KChartWizardLabelsLegendPage::changeTitleFont() +{ + if (TDEFontDialog::getFont( title ,false,this ) == TQDialog::Rejected ) + return; + +} + +void KChartWizardLabelsLegendPage::changeLegendTextColor(const TQColor &_color) +{ + _legendTextColor=_color; +} + +void KChartWizardLabelsLegendPage::changeXLabelColor(const TQColor &_color) +{ + x_color=_color; +} + +void KChartWizardLabelsLegendPage::changeYLabelColor(const TQColor &_color) +{ + y_color=_color; +} + +void KChartWizardLabelsLegendPage::changeTitleColor(const TQColor &_color) +{ + title_color=_color; +} + +#if 0 +void KChartWizardLabelsLegendPage::changeYTitle2Color(const TQColor &_color) +{ + y_color2=_color; +} +#endif + +void KChartWizardLabelsLegendPage::changeLegendTitleColor(const TQColor &_color) +{ + _legendTitleColor=_color; +} + +void KChartWizardLabelsLegendPage::paintEvent( TQPaintEvent * ) +{ +#if 0 + if( ytitle2 ) { + _ylabel2ED->setEnabled(true); + ytitle2color->setEnabled(true); + } + else { + _ylabel2ED->setEnabled(false); + ytitle2color->setEnabled(false); + } +#endif +} + +void KChartWizardLabelsLegendPage::apply( ) +{ + _chart->params()->setHeader1Text( _titleED->text() ); + + // PENDING(kalle) Put back in + // _chart->params()->setXTitleFont(xlabel); + // _chart->params()->setYTitleFont(ylabel); + // _chart->params()->xtitle= _xlabelED->text(); + // _chart->params()->ytitle= _ylabelED->text(); + // _chart->params()->XTitleColor=x_color; + // _chart->params()->YTitleColor=y_color; + // _chart->params()->YTitle2Color=y_color2; + // _chart->params()->ytitle2=_ylabel2ED->text(); + + _chart->params()->setHeaderFooterColor( KDChartParams::HdFtPosHeader, title_color ); + _chart->params()->setHeaderFooterFont( KDChartParams::HdFtPosHeader, title, true, title.pointSize()*4 ); + _chart->params()->setAxisTitle( KDChartAxisParams::AxisPosBottom, _xlabelED->text() ); + _chart->params()->setAxisTitle( KDChartAxisParams::AxisPosLeft, _ylabelED->text() ); + + _chart->params()->setLegendTitleText(_legendTitleText->text()); + _chart->params()->setLegendTitleTextColor(_legendTitleColor); + _chart->params()->setLegendTitleFont( _legendTitleFont,false); + _chart->params()->setLegendTitleFontRelSize( _legendTitleFont.pointSize()*4 ); + _chart->params()->setLegendTextColor(_legendTextColor); + _chart->params()->setLegendFont( _legendTextFont,false); + _chart->params()->setLegendFontRelSize( _legendTextFont.pointSize()*4 ); + + KDChartAxisParams leftparams; + leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams bottomparams; + bottomparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosBottom ); + if( x_color.isValid() ) + bottomparams.setAxisLineColor( x_color ); + if( y_color.isValid() ) + leftparams.setAxisLineColor( y_color ); + if(bottomparams.axisLabelsFont()!=xlabel){ + bottomparams.setAxisLabelsFont( xlabel,false ); + bottomparams.setAxisLabelsFontRelSize( xlabel.pointSize()*4 ); + } + if(leftparams.axisLabelsFont()!=ylabel){ + leftparams.setAxisLabelsFont( ylabel,false ); + leftparams.setAxisLabelsFontRelSize( ylabel.pointSize()*4 ); + } + + _chart->params()->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams ); + _chart->params()->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); +} + +} //KChart namespace + +#include "kchartWizardLabelsLegendPage.moc" diff --git a/kchart/kchartWizardSelectChartSubTypePage.cc b/kchart/kchartWizardSelectChartSubTypePage.cc deleted file mode 100644 index 2c86549a..00000000 --- a/kchart/kchartWizardSelectChartSubTypePage.cc +++ /dev/null @@ -1,195 +0,0 @@ - -#include "kchartWizardSelectChartSubTypePage.h" -#include "kchart_view.h" -#include "kchart_part.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kchart_params.h" - - -namespace KChart -{ - -KChartWizardSelectChartSubTypePage::KChartWizardSelectChartSubTypePage( TQWidget* parent, - KChartPart* chart ) : - TQWidget( parent ), - m_chart( chart ) -{ - // FIXME: Use KChartPart::chartType() instead, when implemented. - m_charttype = (KChartParams::ChartType) m_chart->params()->chartType(); - chartSubType = true; - - TQGridLayout *grid1 = new TQGridLayout(this, 3, 2, KDialog::marginHint(), - KDialog::spacingHint()); - - TQVBoxLayout *lay1 = new TQVBoxLayout( ); - lay1->setMargin( KDialog::marginHint() ); - lay1->setSpacing( KDialog::spacingHint() ); - - TQButtonGroup *grp = new TQButtonGroup( 1, Qt::Horizontal, - i18n( "Chart Sub Type" ), this ); - grp->setRadioButtonExclusive( true ); - grp->layout(); - lay1->addWidget(grp); - m_normal = new TQRadioButton( i18n( "Normal" ), grp ); - m_stacked = new TQRadioButton( i18n( "Stacked" ), grp ); - m_percent = new TQRadioButton( i18n( "Percent" ), grp ); - - TQHBox *hbox = new TQHBox( this ); - /*TQLabel *lbl =*/ new TQLabel( i18n( "Number of lines: "), hbox ); - m_numLines = new TQSpinBox( hbox ); - - if( ( m_chart->chartType() == KChartParams::Bar && - m_chart->params()->barChartSubType() == KDChartParams::BarNormal ) - || ( m_chart->chartType() == KChartParams::Line && - m_chart->params()->lineChartSubType() == KDChartParams::LineNormal ) - || ( m_chart->chartType() == KChartParams::Polar && - m_chart->params()->polarChartSubType() == KDChartParams::PolarNormal ) - || ( m_chart->chartType() == KChartParams::Area && - m_chart->params()->areaChartSubType() == KDChartParams::AreaNormal ) ) - m_normal->setChecked( true ); - else if( ( m_chart->params()->chartType() == KChartParams::Bar && - m_chart->params()->barChartSubType() == KDChartParams::BarStacked ) || - ( m_chart->params()->chartType() == KChartParams::Line && - m_chart->params()->lineChartSubType() == KDChartParams::LineStacked ) || - ( m_chart->params()->chartType() == KChartParams::Polar && - m_chart->params()->polarChartSubType() == KDChartParams::PolarStacked ) || - ( m_chart->params()->chartType() == KChartParams::Area && - m_chart->params()->areaChartSubType() == KDChartParams::AreaStacked ) ) - m_stacked->setChecked( true ); - else if( ( m_chart->params()->chartType() == KChartParams::Bar && - m_chart->params()->barChartSubType() == KDChartParams::BarPercent ) || - ( m_chart->params()->chartType() == KChartParams::Line && - m_chart->params()->lineChartSubType() == KDChartParams::LinePercent ) || - ( m_chart->params()->chartType() == KChartParams::Polar && - m_chart->params()->polarChartSubType() == KDChartParams::PolarPercent ) || - ( m_chart->params()->chartType() == KChartParams::Area && - m_chart->params()->areaChartSubType() == KDChartParams::AreaPercent ) ) - m_percent->setChecked( true ); - else { - kdDebug(35001)<<"Error in chart_type\n"; - } - - m_numLines->setValue( m_chart->params()->barNumLines() ); - - if( m_chart->params()->chartType() == KChartParams::HiLo) - { - if( m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoNormal) - m_normal->setChecked( true ); - else if(m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoClose) - m_stacked->setChecked(true); - else if(m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoOpenClose) - m_percent->setChecked(true); - } - - changeSubTypeName( m_chart->chartType()); - if(!chartSubType) - grp->setEnabled(false); - - grid1->addWidget(grp, 0, 0); - grid1->addWidget(hbox, 1, 0); -} - - - -void KChartWizardSelectChartSubTypePage::apply() -{ - if (chartSubType) { - if( m_normal->isChecked() ) - switch( m_chart->params()->chartType() ) { - case KChartParams::Bar: - m_chart->params()->setBarChartSubType( KDChartParams::BarNormal ); - // FIXME: Error controls. - m_chart->params()->setBarNumLines( m_numLines->value() ); - break; - case KChartParams::Line: - m_chart->params()->setLineChartSubType( KDChartParams::LineNormal ); - break; - case KChartParams::Area: - m_chart->params()->setAreaChartSubType( KDChartParams::AreaNormal ); - break; - case KChartParams::HiLo: - m_chart->params()->setHiLoChartSubType(KDChartParams::HiLoNormal); - break; - case KChartParams::Polar: - m_chart->params()->setPolarChartSubType( KDChartParams::PolarNormal ); - default: - kdDebug( 35001 ) << "Error in group button\n"; - } - else if ( m_stacked->isChecked() ) - switch( m_chart->params()->chartType() ) { - case KChartParams::Bar: - m_chart->params()->setBarChartSubType( KDChartParams::BarStacked ); - break; - case KChartParams::Line: - m_chart->params()->setLineChartSubType( KDChartParams::LineStacked ); - break; - case KChartParams::Area: - m_chart->params()->setAreaChartSubType( KDChartParams::AreaStacked ); - break; - case KChartParams::HiLo: - m_chart->params()->setHiLoChartSubType( KDChartParams::HiLoClose); - break; - case KChartParams::Polar: - m_chart->params()->setPolarChartSubType( KDChartParams::PolarStacked ); - break; - default: - kdDebug( 35001 ) << "Error in group button\n"; - } - else if( m_percent->isChecked() ) - switch( m_chart->params()->chartType() ) { - case KChartParams::Bar: - m_chart->params()->setBarChartSubType( KDChartParams::BarPercent ); - break; - case KChartParams::Line: - m_chart->params()->setLineChartSubType( KDChartParams::LinePercent ); - break; - case KChartParams::Area: - m_chart->params()->setAreaChartSubType( KDChartParams::AreaPercent ); - break; - case KChartParams::HiLo: - m_chart->params()->setHiLoChartSubType( KDChartParams::HiLoOpenClose); - break; - case KChartParams::Polar: - m_chart->params()->setPolarChartSubType( KDChartParams::PolarPercent ); - break; - default: - kdDebug( 35001 ) << "Error in group button\n"; - } - else - kdDebug(35001)<<"Error in groupbutton\n"; - } -} - -void KChartWizardSelectChartSubTypePage::changeSubTypeName( KChartParams::ChartType _type) -{ - if (_type==KChartParams::HiLo) - { - m_stacked->setText( i18n("HiLoClose") ); - m_percent->setText( i18n("HiLoOpenClose") ); - } - else - { - m_stacked->setText( i18n( "Stacked" ) ); - m_percent->setText( i18n( "Percent" ) ); - } -} - -} //KChart namespace - -#include "kchartWizardSelectChartSubTypePage.moc" diff --git a/kchart/kchartWizardSelectChartSubTypePage.cpp b/kchart/kchartWizardSelectChartSubTypePage.cpp new file mode 100644 index 00000000..2c86549a --- /dev/null +++ b/kchart/kchartWizardSelectChartSubTypePage.cpp @@ -0,0 +1,195 @@ + +#include "kchartWizardSelectChartSubTypePage.h" +#include "kchart_view.h" +#include "kchart_part.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kchart_params.h" + + +namespace KChart +{ + +KChartWizardSelectChartSubTypePage::KChartWizardSelectChartSubTypePage( TQWidget* parent, + KChartPart* chart ) : + TQWidget( parent ), + m_chart( chart ) +{ + // FIXME: Use KChartPart::chartType() instead, when implemented. + m_charttype = (KChartParams::ChartType) m_chart->params()->chartType(); + chartSubType = true; + + TQGridLayout *grid1 = new TQGridLayout(this, 3, 2, KDialog::marginHint(), + KDialog::spacingHint()); + + TQVBoxLayout *lay1 = new TQVBoxLayout( ); + lay1->setMargin( KDialog::marginHint() ); + lay1->setSpacing( KDialog::spacingHint() ); + + TQButtonGroup *grp = new TQButtonGroup( 1, Qt::Horizontal, + i18n( "Chart Sub Type" ), this ); + grp->setRadioButtonExclusive( true ); + grp->layout(); + lay1->addWidget(grp); + m_normal = new TQRadioButton( i18n( "Normal" ), grp ); + m_stacked = new TQRadioButton( i18n( "Stacked" ), grp ); + m_percent = new TQRadioButton( i18n( "Percent" ), grp ); + + TQHBox *hbox = new TQHBox( this ); + /*TQLabel *lbl =*/ new TQLabel( i18n( "Number of lines: "), hbox ); + m_numLines = new TQSpinBox( hbox ); + + if( ( m_chart->chartType() == KChartParams::Bar && + m_chart->params()->barChartSubType() == KDChartParams::BarNormal ) + || ( m_chart->chartType() == KChartParams::Line && + m_chart->params()->lineChartSubType() == KDChartParams::LineNormal ) + || ( m_chart->chartType() == KChartParams::Polar && + m_chart->params()->polarChartSubType() == KDChartParams::PolarNormal ) + || ( m_chart->chartType() == KChartParams::Area && + m_chart->params()->areaChartSubType() == KDChartParams::AreaNormal ) ) + m_normal->setChecked( true ); + else if( ( m_chart->params()->chartType() == KChartParams::Bar && + m_chart->params()->barChartSubType() == KDChartParams::BarStacked ) || + ( m_chart->params()->chartType() == KChartParams::Line && + m_chart->params()->lineChartSubType() == KDChartParams::LineStacked ) || + ( m_chart->params()->chartType() == KChartParams::Polar && + m_chart->params()->polarChartSubType() == KDChartParams::PolarStacked ) || + ( m_chart->params()->chartType() == KChartParams::Area && + m_chart->params()->areaChartSubType() == KDChartParams::AreaStacked ) ) + m_stacked->setChecked( true ); + else if( ( m_chart->params()->chartType() == KChartParams::Bar && + m_chart->params()->barChartSubType() == KDChartParams::BarPercent ) || + ( m_chart->params()->chartType() == KChartParams::Line && + m_chart->params()->lineChartSubType() == KDChartParams::LinePercent ) || + ( m_chart->params()->chartType() == KChartParams::Polar && + m_chart->params()->polarChartSubType() == KDChartParams::PolarPercent ) || + ( m_chart->params()->chartType() == KChartParams::Area && + m_chart->params()->areaChartSubType() == KDChartParams::AreaPercent ) ) + m_percent->setChecked( true ); + else { + kdDebug(35001)<<"Error in chart_type\n"; + } + + m_numLines->setValue( m_chart->params()->barNumLines() ); + + if( m_chart->params()->chartType() == KChartParams::HiLo) + { + if( m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoNormal) + m_normal->setChecked( true ); + else if(m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoClose) + m_stacked->setChecked(true); + else if(m_chart->params()->hiLoChartSubType()==KDChartParams::HiLoOpenClose) + m_percent->setChecked(true); + } + + changeSubTypeName( m_chart->chartType()); + if(!chartSubType) + grp->setEnabled(false); + + grid1->addWidget(grp, 0, 0); + grid1->addWidget(hbox, 1, 0); +} + + + +void KChartWizardSelectChartSubTypePage::apply() +{ + if (chartSubType) { + if( m_normal->isChecked() ) + switch( m_chart->params()->chartType() ) { + case KChartParams::Bar: + m_chart->params()->setBarChartSubType( KDChartParams::BarNormal ); + // FIXME: Error controls. + m_chart->params()->setBarNumLines( m_numLines->value() ); + break; + case KChartParams::Line: + m_chart->params()->setLineChartSubType( KDChartParams::LineNormal ); + break; + case KChartParams::Area: + m_chart->params()->setAreaChartSubType( KDChartParams::AreaNormal ); + break; + case KChartParams::HiLo: + m_chart->params()->setHiLoChartSubType(KDChartParams::HiLoNormal); + break; + case KChartParams::Polar: + m_chart->params()->setPolarChartSubType( KDChartParams::PolarNormal ); + default: + kdDebug( 35001 ) << "Error in group button\n"; + } + else if ( m_stacked->isChecked() ) + switch( m_chart->params()->chartType() ) { + case KChartParams::Bar: + m_chart->params()->setBarChartSubType( KDChartParams::BarStacked ); + break; + case KChartParams::Line: + m_chart->params()->setLineChartSubType( KDChartParams::LineStacked ); + break; + case KChartParams::Area: + m_chart->params()->setAreaChartSubType( KDChartParams::AreaStacked ); + break; + case KChartParams::HiLo: + m_chart->params()->setHiLoChartSubType( KDChartParams::HiLoClose); + break; + case KChartParams::Polar: + m_chart->params()->setPolarChartSubType( KDChartParams::PolarStacked ); + break; + default: + kdDebug( 35001 ) << "Error in group button\n"; + } + else if( m_percent->isChecked() ) + switch( m_chart->params()->chartType() ) { + case KChartParams::Bar: + m_chart->params()->setBarChartSubType( KDChartParams::BarPercent ); + break; + case KChartParams::Line: + m_chart->params()->setLineChartSubType( KDChartParams::LinePercent ); + break; + case KChartParams::Area: + m_chart->params()->setAreaChartSubType( KDChartParams::AreaPercent ); + break; + case KChartParams::HiLo: + m_chart->params()->setHiLoChartSubType( KDChartParams::HiLoOpenClose); + break; + case KChartParams::Polar: + m_chart->params()->setPolarChartSubType( KDChartParams::PolarPercent ); + break; + default: + kdDebug( 35001 ) << "Error in group button\n"; + } + else + kdDebug(35001)<<"Error in groupbutton\n"; + } +} + +void KChartWizardSelectChartSubTypePage::changeSubTypeName( KChartParams::ChartType _type) +{ + if (_type==KChartParams::HiLo) + { + m_stacked->setText( i18n("HiLoClose") ); + m_percent->setText( i18n("HiLoOpenClose") ); + } + else + { + m_stacked->setText( i18n( "Stacked" ) ); + m_percent->setText( i18n( "Percent" ) ); + } +} + +} //KChart namespace + +#include "kchartWizardSelectChartSubTypePage.moc" diff --git a/kchart/kchartWizardSelectChartTypePage.cc b/kchart/kchartWizardSelectChartTypePage.cc deleted file mode 100644 index 8ea02100..00000000 --- a/kchart/kchartWizardSelectChartTypePage.cc +++ /dev/null @@ -1,128 +0,0 @@ - -#include "kchartWizardSelectChartTypePage.h" -#include "kchart_params.h" -#include "kchart_view.h" -#include "kchart_factory.h" -#include "kchart_part.h" - -#include -#include -#include -#include - -#include -#include -#include - -namespace KChart -{ - - -KChartButton::KChartButton(TQWidget *parent, const TQString & _text, const TQPixmap &_pixmap) - : TQVBox(parent) -{ - // The button - m_button = new TQPushButton(this); - m_button->setPixmap(_pixmap); - m_button->setToggleButton( true ); - - // The text - TQLabel *label = new TQLabel(_text, this); - label->setSizePolicy(TQSizePolicy::Fixed,TQSizePolicy::Fixed); - setSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed); -} - -KChartButton::~KChartButton() -{ -} - - -// ================================================================ - - -KChartWizardSelectChartTypePage::KChartWizardSelectChartTypePage( TQWidget* parent, - KChartPart* chart ) - : TQWidget( parent ), - m_chart( chart ) -{ - m_typeBG = new TQButtonGroup( this ); - m_typeBG->setExclusive( true ); - m_typeBG->hide(); - // m_typeBG->resize - - m_colPos=0; - m_rowPos=0; - m_layout = new TQGridLayout(this, 3, 4, 5); - m_layout->setRowStretch(0, 0); - m_layout->setRowStretch(1, 0); - m_layout->setRowStretch(2, 0); - - addButton( i18n( "Bar" ), "chart_bar", KChartParams::Bar ); - addButton( i18n( "Lines" ), "chart_line", KChartParams::Line ); - addButton( i18n( "Area" ), "chart_area", KChartParams::Area ); -#if 0 - addButton( i18n( "Bars & Lines" ), "chart_barlines", KChartParams::BarLines ); -#endif - - addButton( i18n("Hi-Lo-Close"), "chart_hilo", KChartParams::HiLo ); - addButton( i18n("Box & Whisker "), "chart_boxwhisker", KChartParams::BoxWhisker ); - incPos(); - incPos(); - - addButton( i18n( "Pie" ), "chart_pie", KChartParams::Pie ); - addButton( i18n( "Ring" ), "chart_ring", KChartParams::Ring ); - addButton( i18n( "Polar" ), "chart_polar", KChartParams::Polar); - - TQPushButton *current = ((TQPushButton*)m_typeBG->find( m_chart->params()->chartType() )); - if (current != NULL) { - current->setOn( true ); - } - - m_type = m_chart->params()->chartType(); - connect( m_typeBG, TQT_SIGNAL( clicked( int ) ), - this, TQT_SLOT( chartTypeSelected( int ) ) ); - - //// parent->resize( 425, 256 ); - // parent->resize(xstep*5+50, ystep*4 + 100); -} - - -void KChartWizardSelectChartTypePage::addButton(const TQString &name, - const TQString &icon_name, - int type) -{ - KChartButton *button = new KChartButton( this, name, - BarIcon( icon_name, - TDEIcon::SizeMedium, - TDEIcon::DefaultState, - KChartFactory::global()) ); - m_layout->addWidget(button, m_rowPos, m_colPos); - m_typeBG->insert( button->button(), type ); - - incPos(); -} - -void KChartWizardSelectChartTypePage::incPos() -{ - if (m_colPos == 3) { - m_colPos=0; - m_rowPos++; //place the next button in the second row - } - else - m_colPos++; -} - -void KChartWizardSelectChartTypePage::chartTypeSelected( int type ) -{ - m_type = (KChartParams::ChartType) type; - emit chartChange(type); -} - -void KChartWizardSelectChartTypePage::apply() -{ - m_chart->params()->setChartType( m_type ); -} - -} //namespace KChart - -#include "kchartWizardSelectChartTypePage.moc" diff --git a/kchart/kchartWizardSelectChartTypePage.cpp b/kchart/kchartWizardSelectChartTypePage.cpp new file mode 100644 index 00000000..8ea02100 --- /dev/null +++ b/kchart/kchartWizardSelectChartTypePage.cpp @@ -0,0 +1,128 @@ + +#include "kchartWizardSelectChartTypePage.h" +#include "kchart_params.h" +#include "kchart_view.h" +#include "kchart_factory.h" +#include "kchart_part.h" + +#include +#include +#include +#include + +#include +#include +#include + +namespace KChart +{ + + +KChartButton::KChartButton(TQWidget *parent, const TQString & _text, const TQPixmap &_pixmap) + : TQVBox(parent) +{ + // The button + m_button = new TQPushButton(this); + m_button->setPixmap(_pixmap); + m_button->setToggleButton( true ); + + // The text + TQLabel *label = new TQLabel(_text, this); + label->setSizePolicy(TQSizePolicy::Fixed,TQSizePolicy::Fixed); + setSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed); +} + +KChartButton::~KChartButton() +{ +} + + +// ================================================================ + + +KChartWizardSelectChartTypePage::KChartWizardSelectChartTypePage( TQWidget* parent, + KChartPart* chart ) + : TQWidget( parent ), + m_chart( chart ) +{ + m_typeBG = new TQButtonGroup( this ); + m_typeBG->setExclusive( true ); + m_typeBG->hide(); + // m_typeBG->resize + + m_colPos=0; + m_rowPos=0; + m_layout = new TQGridLayout(this, 3, 4, 5); + m_layout->setRowStretch(0, 0); + m_layout->setRowStretch(1, 0); + m_layout->setRowStretch(2, 0); + + addButton( i18n( "Bar" ), "chart_bar", KChartParams::Bar ); + addButton( i18n( "Lines" ), "chart_line", KChartParams::Line ); + addButton( i18n( "Area" ), "chart_area", KChartParams::Area ); +#if 0 + addButton( i18n( "Bars & Lines" ), "chart_barlines", KChartParams::BarLines ); +#endif + + addButton( i18n("Hi-Lo-Close"), "chart_hilo", KChartParams::HiLo ); + addButton( i18n("Box & Whisker "), "chart_boxwhisker", KChartParams::BoxWhisker ); + incPos(); + incPos(); + + addButton( i18n( "Pie" ), "chart_pie", KChartParams::Pie ); + addButton( i18n( "Ring" ), "chart_ring", KChartParams::Ring ); + addButton( i18n( "Polar" ), "chart_polar", KChartParams::Polar); + + TQPushButton *current = ((TQPushButton*)m_typeBG->find( m_chart->params()->chartType() )); + if (current != NULL) { + current->setOn( true ); + } + + m_type = m_chart->params()->chartType(); + connect( m_typeBG, TQT_SIGNAL( clicked( int ) ), + this, TQT_SLOT( chartTypeSelected( int ) ) ); + + //// parent->resize( 425, 256 ); + // parent->resize(xstep*5+50, ystep*4 + 100); +} + + +void KChartWizardSelectChartTypePage::addButton(const TQString &name, + const TQString &icon_name, + int type) +{ + KChartButton *button = new KChartButton( this, name, + BarIcon( icon_name, + TDEIcon::SizeMedium, + TDEIcon::DefaultState, + KChartFactory::global()) ); + m_layout->addWidget(button, m_rowPos, m_colPos); + m_typeBG->insert( button->button(), type ); + + incPos(); +} + +void KChartWizardSelectChartTypePage::incPos() +{ + if (m_colPos == 3) { + m_colPos=0; + m_rowPos++; //place the next button in the second row + } + else + m_colPos++; +} + +void KChartWizardSelectChartTypePage::chartTypeSelected( int type ) +{ + m_type = (KChartParams::ChartType) type; + emit chartChange(type); +} + +void KChartWizardSelectChartTypePage::apply() +{ + m_chart->params()->setChartType( m_type ); +} + +} //namespace KChart + +#include "kchartWizardSelectChartTypePage.moc" diff --git a/kchart/kchartWizardSelectChartTypePage.h b/kchart/kchartWizardSelectChartTypePage.h index 16c28944..91b62da3 100644 --- a/kchart/kchartWizardSelectChartTypePage.h +++ b/kchart/kchartWizardSelectChartTypePage.h @@ -18,7 +18,7 @@ class KChartPart; // Contains a button with a text label below it // -// FIXME: Move to kchartWizardSelectChartTypePage.cc +// FIXME: Move to kchartWizardSelectChartTypePage.cpp class KChartButton : public TQVBox { Q_OBJECT diff --git a/kchart/kchartWizardSelectDataFormatPage.cc b/kchart/kchartWizardSelectDataFormatPage.cc deleted file mode 100644 index d40e95fe..00000000 --- a/kchart/kchartWizardSelectDataFormatPage.cc +++ /dev/null @@ -1,113 +0,0 @@ - -#include "kchartWizardSelectDataFormatPage.h" -#include "kchart_view.h" -#include "kchart_part.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartWizardSelectDataFormatPage::KChartWizardSelectDataFormatPage( TQWidget* parent, - KChartPart* chart ) : - TQWidget( parent ), - m_chart( chart ) -{ - TQGridLayout *grid1 = new TQGridLayout(this, 6, 1, KDialog::marginHint(), - KDialog::spacingHint()); - - // The Data Area - TQButtonGroup *gb1 = new TQVButtonGroup( i18n( "Data Area" ), this ); - - TQHBox *hbox = new TQHBox( gb1 ); - (void) new TQLabel( i18n("Area: "), hbox); - m_dataArea = new TQLineEdit( hbox ); - grid1->addWidget(gb1, 0, 0); - - // The row/column as label checkboxes. - m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), gb1); - m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), gb1); - - // The Data Format button group - TQButtonGroup *gb = new TQVButtonGroup( i18n( "Data Format" ), this ); - - m_rowMajor = new TQRadioButton( i18n( "Data in rows" ), gb ); - m_rowMajor->resize( m_rowMajor->sizeHint() ); - - m_colMajor = new TQRadioButton( i18n( "Data in columns" ), gb ); - m_colMajor->resize( m_colMajor->sizeHint() ); - - grid1->addWidget(gb, 3, 0); - - TQLabel *lbl = new TQLabel( i18n( - "\n" - "If the selected data area does not match the data you want,\n" - "select the data now.\n" - "\n" - "Include cells that you want to use as row and column labels,\n" - "if you want them in the chart.\n" - ), this); - grid1->addWidget(lbl, 4, 0); - - grid1->setColStretch(5, 0); - - grid1->activate(); - - // Enter the data into the widgets. - if ( m_chart->params()->dataDirection() == KChartParams::DataColumns) - m_colMajor->setChecked(true); - else - m_rowMajor->setChecked(true); - - m_dataArea->setText( m_chart->params()->dataArea() ); -} - - -TQString KChartWizardSelectDataFormatPage::dataArea() const -{ - return m_dataArea->text(); -} - -void KChartWizardSelectDataFormatPage::setDataArea( const TQString &area ) -{ - m_dataArea->setText( area ); -} - - -void KChartWizardSelectDataFormatPage::apply() -{ - if (m_rowMajor->isChecked()) - m_chart->params()->setDataDirection( KChartParams::DataRows ); - else - m_chart->params()->setDataDirection( KChartParams::DataColumns ); - - m_chart->params()->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); - m_chart->params()->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); - - m_chart->params()->setDataArea( m_dataArea->text() ); - // FIXME: Actually take use the new data area. -} - - -} //KChart namespace - -#include "kchartWizardSelectDataFormatPage.moc" diff --git a/kchart/kchartWizardSelectDataFormatPage.cpp b/kchart/kchartWizardSelectDataFormatPage.cpp new file mode 100644 index 00000000..d40e95fe --- /dev/null +++ b/kchart/kchartWizardSelectDataFormatPage.cpp @@ -0,0 +1,113 @@ + +#include "kchartWizardSelectDataFormatPage.h" +#include "kchart_view.h" +#include "kchart_part.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartWizardSelectDataFormatPage::KChartWizardSelectDataFormatPage( TQWidget* parent, + KChartPart* chart ) : + TQWidget( parent ), + m_chart( chart ) +{ + TQGridLayout *grid1 = new TQGridLayout(this, 6, 1, KDialog::marginHint(), + KDialog::spacingHint()); + + // The Data Area + TQButtonGroup *gb1 = new TQVButtonGroup( i18n( "Data Area" ), this ); + + TQHBox *hbox = new TQHBox( gb1 ); + (void) new TQLabel( i18n("Area: "), hbox); + m_dataArea = new TQLineEdit( hbox ); + grid1->addWidget(gb1, 0, 0); + + // The row/column as label checkboxes. + m_firstRowAsLabel = new TQCheckBox( i18n( "First row as label" ), gb1); + m_firstColAsLabel = new TQCheckBox( i18n( "First column as label" ), gb1); + + // The Data Format button group + TQButtonGroup *gb = new TQVButtonGroup( i18n( "Data Format" ), this ); + + m_rowMajor = new TQRadioButton( i18n( "Data in rows" ), gb ); + m_rowMajor->resize( m_rowMajor->sizeHint() ); + + m_colMajor = new TQRadioButton( i18n( "Data in columns" ), gb ); + m_colMajor->resize( m_colMajor->sizeHint() ); + + grid1->addWidget(gb, 3, 0); + + TQLabel *lbl = new TQLabel( i18n( + "\n" + "If the selected data area does not match the data you want,\n" + "select the data now.\n" + "\n" + "Include cells that you want to use as row and column labels,\n" + "if you want them in the chart.\n" + ), this); + grid1->addWidget(lbl, 4, 0); + + grid1->setColStretch(5, 0); + + grid1->activate(); + + // Enter the data into the widgets. + if ( m_chart->params()->dataDirection() == KChartParams::DataColumns) + m_colMajor->setChecked(true); + else + m_rowMajor->setChecked(true); + + m_dataArea->setText( m_chart->params()->dataArea() ); +} + + +TQString KChartWizardSelectDataFormatPage::dataArea() const +{ + return m_dataArea->text(); +} + +void KChartWizardSelectDataFormatPage::setDataArea( const TQString &area ) +{ + m_dataArea->setText( area ); +} + + +void KChartWizardSelectDataFormatPage::apply() +{ + if (m_rowMajor->isChecked()) + m_chart->params()->setDataDirection( KChartParams::DataRows ); + else + m_chart->params()->setDataDirection( KChartParams::DataColumns ); + + m_chart->params()->setFirstRowAsLabel( m_firstRowAsLabel->isChecked() ); + m_chart->params()->setFirstColAsLabel( m_firstColAsLabel->isChecked() ); + + m_chart->params()->setDataArea( m_dataArea->text() ); + // FIXME: Actually take use the new data area. +} + + +} //KChart namespace + +#include "kchartWizardSelectDataFormatPage.moc" diff --git a/kchart/kchartWizardSelectDataPage.cc b/kchart/kchartWizardSelectDataPage.cc deleted file mode 100644 index 40dafc12..00000000 --- a/kchart/kchartWizardSelectDataPage.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* $Id$ */ - -#include "kchartWizardSelectDataPage.h" - -#include -#include -#include - -namespace KChart -{ - -KChartWizardSelectDataPage::KChartWizardSelectDataPage( TQWidget* parent ) : - TQWidget( parent ) -{ - rangeED = new TQLineEdit( this, "LineEdit_1" ); - rangeED->setGeometry( 10, 90, 380, 30 ); - rangeED->setText( "" ); - - TQLabel* tmpTQLabel; - tmpTQLabel = new TQLabel( this, "Label_1" ); - tmpTQLabel->setGeometry( 10, 30, 360, 20 ); - tmpTQLabel->setText( "If the selected cells dont match your table," ); - - tmpTQLabel = new TQLabel( this, "Label_2" ); - tmpTQLabel->setGeometry( 10, 50, 360, 20 ); - tmpTQLabel->setText( "you must select another rectangular area here." ); - - kdDebug(35001) << "send needNewData() signal here and update area field in KChartWizard" << endl; - - setMinimumSize( 600, 300 ); -} - -} //namespace KChart diff --git a/kchart/kchartWizardSelectDataPage.cpp b/kchart/kchartWizardSelectDataPage.cpp new file mode 100644 index 00000000..40dafc12 --- /dev/null +++ b/kchart/kchartWizardSelectDataPage.cpp @@ -0,0 +1,33 @@ +/* $Id$ */ + +#include "kchartWizardSelectDataPage.h" + +#include +#include +#include + +namespace KChart +{ + +KChartWizardSelectDataPage::KChartWizardSelectDataPage( TQWidget* parent ) : + TQWidget( parent ) +{ + rangeED = new TQLineEdit( this, "LineEdit_1" ); + rangeED->setGeometry( 10, 90, 380, 30 ); + rangeED->setText( "" ); + + TQLabel* tmpTQLabel; + tmpTQLabel = new TQLabel( this, "Label_1" ); + tmpTQLabel->setGeometry( 10, 30, 360, 20 ); + tmpTQLabel->setText( "If the selected cells dont match your table," ); + + tmpTQLabel = new TQLabel( this, "Label_2" ); + tmpTQLabel->setGeometry( 10, 50, 360, 20 ); + tmpTQLabel->setText( "you must select another rectangular area here." ); + + kdDebug(35001) << "send needNewData() signal here and update area field in KChartWizard" << endl; + + setMinimumSize( 600, 300 ); +} + +} //namespace KChart diff --git a/kchart/kchartWizardSetupAxesPage.cc b/kchart/kchartWizardSetupAxesPage.cc deleted file mode 100644 index 5514e82b..00000000 --- a/kchart/kchartWizardSetupAxesPage.cc +++ /dev/null @@ -1,301 +0,0 @@ -#include "kchartWizardSetupAxesPage.h" -#include "kchart_view.h" -#include "kchart_part.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include - -#include "kchart_params.h" - -namespace KChart -{ - -KChartWizardSetupAxesPage::KChartWizardSetupAxesPage( TQWidget* parent, - KChartPart* chart ) : - TQWidget( parent ), - _chart( chart ) -{ - chart3d=true; - - TQGridLayout *grid1 = new TQGridLayout(this,2,2,KDialog::marginHint(), KDialog::spacingHint()); - - TQGroupBox* tmpTQGroupBox; - tmpTQGroupBox = new TQGroupBox( this, "GroupBox_1" ); - tmpTQGroupBox->setFrameStyle( 49 ); - - TQGridLayout *grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); - - - //grid = new TQCheckBox( i18n( "Has grid:" ), tmpTQGroupBox ); - new TQLabel( i18n( "Grid Lines" ), tmpTQGroupBox ); - gridX = new TQCheckBox( i18n( "X axis:" ), tmpTQGroupBox ); - gridY = new TQCheckBox( i18n( "Y axis:" ), tmpTQGroupBox ); - - gridX->setChecked(_chart->params()->showGrid()); - gridY->setChecked(_chart->params()->showGrid()); - grid2->addWidget(gridX, 0, 0); - grid2->addWidget(gridY, 1, 0); - - gridColor=new KColorButton(tmpTQGroupBox); - // PENDING(kalle) Put back in - // colorGrid=_chart->params()->GridColor; - gridColor->setColor( colorGrid ); - grid2->addWidget(gridColor, 0, 1); - - border = new TQCheckBox( i18n( "Border:" ), tmpTQGroupBox ); - // PENDING(kalle) Put back in - // border->setChecked( _chart->params()->border ); - grid2->addWidget(border, 2, 0); - border->setEnabled(false); - - borderColor=new KColorButton(tmpTQGroupBox); - // PENDING(kalle) Put back in - // colorBorder=_chart->params()->LineColor; - borderColor->setColor( colorBorder ); - grid2->addWidget(borderColor,2,1); - borderColor->setEnabled(false); - - grid1->addWidget(tmpTQGroupBox,0,0); - - - tmpTQGroupBox = new TQGroupBox( this, "GroupBox_2" ); - tmpTQGroupBox->setFrameStyle( 49 ); - - grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); - - TQLabel *tmpLabel; - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Angle 3D:")); - grid2->addWidget(tmpLabel,0,0); - angle = new TQSpinBox(1, 90, 1,tmpTQGroupBox ); - angle->setValue( _chart->params()->threeDBarAngle() ); - grid2->addWidget(angle,0,1); - - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Depth 3D:")); - grid2->addWidget(tmpLabel,1,0); - depth = new TQSpinBox(1, 40, 1, tmpTQGroupBox); - depth->setValue( static_cast( _chart->params()->threeDBarDepth() ) ); - grid2->addWidget(depth,1,1); - - // Bar width is computed automatically in KDChart (and can be - // changed via gaps) - // tmpLabel=new TQLabel(tmpTQGroupBox); -// tmpLabel->setText(i18n("Bar width:")); -// grid2->addWidget(tmpLabel,2,0); -// barWidth = new TQSpinBox(1, 200, 1, tmpTQGroupBox); -// barWidth->setValue(_chart->params()->bar_width); -// grid2->addWidget(barWidth,2,1); - - grid1->addWidget(tmpTQGroupBox,0,1); - - tmpTQGroupBox = new TQGroupBox( this, "GroupBox_3" ); - tmpTQGroupBox->setFrameStyle( 49 ); - - grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); - - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Y interval:")); - grid2->addWidget(tmpLabel,0,0); - - TQString tmp; - y_interval=new TQLineEdit(tmpTQGroupBox); - y_interval->setValidator(new KFloatValidator( y_interval)); - grid2->addWidget(y_interval,0,1); - // PENDING(kalle) Put back in - // if( _chart->params()->requested_yinterval != -DBL_MAX) -// y_interval->setText( tmp.setNum(_chart->params()->requested_yinterval)); - - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Y min:")); - grid2->addWidget(tmpLabel,1,0); - y_min=new TQLineEdit(tmpTQGroupBox); - y_min->setValidator(new KFloatValidator( y_min)); - grid2->addWidget(y_min,1,1); - // PENDING(kalle) Put back in - // if( _chart->params()->requested_ymin != DBL_MAX) -// y_min->setText( tmp.setNum(_chart->params()->requested_ymin)); - - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Y max:")); - grid2->addWidget(tmpLabel,2,0); - y_max=new TQLineEdit(tmpTQGroupBox); - y_max->setValidator(new KFloatValidator( y_max)); - grid2->addWidget(y_max,2,1); - // PENDING(kalle) Put back in - // if( _chart->params()->requested_ymax != -DBL_MAX) -// y_max->setText( tmp.setNum(_chart->params()->requested_ymax)); - - grid1->addWidget(tmpTQGroupBox,1,0); - tmpTQGroupBox->setEnabled(false); - - tmpTQGroupBox = new TQGroupBox( this, "GroupBox_3" ); - tmpTQGroupBox->setFrameStyle( 49 ); - - grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); - - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Y-label format:")); - grid2->addWidget(tmpLabel,0,0); - ylabel_fmt=new TQLineEdit(tmpTQGroupBox); - grid2->addWidget(ylabel_fmt,0,1); - - // PENDING(kalle) Put back in - // if( !_chart->params()->ylabel_fmt.isEmpty()) { -// int len=_chart->params()->ylabel_fmt.length(); -// ylabel_fmt->setText(_chart->params()->ylabel_fmt.right(len-3)); -// } - ylabelFont = new TQPushButton( tmpTQGroupBox); - grid2->addWidget(ylabelFont,1,0); - ylabelFont->setText(i18n("Font...")); - // PENDING(kalle) Put back in - // ylabel=_chart->params()->yAxisFont(); - - ylabelColor=new KColorButton(tmpTQGroupBox); - grid2->addWidget(ylabelColor,1,1); - // PENDING(kalle) Put back in - // ycolor=_chart->params()->YLabelColor; - ylabelColor->setColor( ycolor ); - -#if 0 - tmpLabel=new TQLabel(tmpTQGroupBox); - tmpLabel->setText(i18n("Y-label 2 format:")); - grid2->addWidget(tmpLabel,2,0); - - ylabel2_fmt=new TQLineEdit(tmpTQGroupBox); - grid2->addWidget(ylabel2_fmt,2,1); - // PENDING(kalle) Put back in - // if( !_chart->params()->ylabel2_fmt.isEmpty()) { -// int len=_chart->params()->ylabel2_fmt.length(); -// ylabel2_fmt->setText(_chart->params()->ylabel2_fmt.right(len-3)); -// } -#endif - tmpTQGroupBox->setEnabled(false); - grid1->addWidget(tmpTQGroupBox,1,1); - - - - connect(ylabelFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLabelFont())); - - - connect(ylabelColor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeLabelColor(const TQColor &))); - connect(borderColor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeBorderColor(const TQColor &))); - connect(gridColor,TQT_SIGNAL(changed( const TQColor & )), - this,TQT_SLOT(changeGridColor(const TQColor &))); -} - - -KChartWizardSetupAxesPage::~KChartWizardSetupAxesPage() -{ - // _chart->removeAutoUpdate( preview ); -} - -void KChartWizardSetupAxesPage::changeLabelColor(const TQColor &_color) -{ - ycolor=_color; -} - -void KChartWizardSetupAxesPage::changeBorderColor(const TQColor &_color) -{ - colorBorder=_color; -} - -void KChartWizardSetupAxesPage::changeGridColor(const TQColor &_color) -{ - colorGrid=_color; -} - -void KChartWizardSetupAxesPage::changeLabelFont() -{ - if( TDEFontDialog::getFont( ylabel,false,this ) == TQDialog::Rejected ) - return; -} - -void KChartWizardSetupAxesPage::paintEvent( TQPaintEvent *) -{ - if(chart3d) { - angle->setEnabled(true); - depth->setEnabled(true); - //barWidth->setEnabled(true); - } else { - angle->setEnabled(false); - depth->setEnabled(false); - //barWidth->setEnabled(false); - } -} - -void KChartWizardSetupAxesPage::apply() -{ - _chart->params()->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,gridY->isChecked() ); - _chart->params()->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,gridX->isChecked() ); - - KDChartAxisParams leftparams; - leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); -/* if( !y_max->text().isEmpty()) - { - leftparams.setAxisAreaMode(KDChartAxisParams::AxisAreaModeMinMaxSize); - leftparams.setAxisAreaMax(y_max->text().toDouble()); - } - else - leftparams.setAxisAreaMode(KDChartAxisParams::AxisAreaModeAutoSize);*/ - //leftparams.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); - _chart->params()->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); - // PENDING(kalle) Put back in - // _chart->params()->grid =grid->isChecked() ; -// if( !y_interval->text().isEmpty()) -// _chart->params()->requested_yinterval=y_interval->text().toDouble(); -// else -// _chart->params()->requested_yinterval=0; -// if( !y_max->text().isEmpty()) -// _chart->params()->requested_ymax=y_max->text().toDouble(); -// else -// _chart->params()->requested_ymax=0; -// if( !y_min->text().isEmpty()) -// _chart->params()->requested_ymin=y_min->text().toDouble(); -// else -// _chart->params()->requested_ymin=0; - - // PENDING(kalle) Put back in -// _chart->params()->border =border->isChecked() ; - - _chart->params()->setThreeDBarAngle( angle->value() ); - // PENDING(kalle) Put back in - // if(! ylabel_fmt->text().isEmpty()) { -// TQString tmp="%g "+ylabel_fmt->text(); -// _chart->params()->ylabel_fmt=tmp; -// } else { -// _chart->params()->ylabel_fmt=""; -// } -// _chart->params()->setYAxisFont(ylabel); -// _chart->params()->YLabelColor=ycolor; -// _chart->params()->GridColor=colorGrid; -// _chart->params()->LineColor=colorBorder; - _chart->params()->setThreeDBarDepth( depth->value() ); - // PENDING(kalle) Put back in - // if(! ylabel2_fmt->text().isEmpty()) { -// TQString tmp="%g "+ylabel2_fmt->text(); -// _chart->params()->ylabel2_fmt=tmp; -// } else { -// _chart->params()->ylabel2_fmt=""; -// } -} - -} //namespace KChart - -#include "kchartWizardSetupAxesPage.moc" diff --git a/kchart/kchartWizardSetupAxesPage.cpp b/kchart/kchartWizardSetupAxesPage.cpp new file mode 100644 index 00000000..5514e82b --- /dev/null +++ b/kchart/kchartWizardSetupAxesPage.cpp @@ -0,0 +1,301 @@ +#include "kchartWizardSetupAxesPage.h" +#include "kchart_view.h" +#include "kchart_part.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include + +#include "kchart_params.h" + +namespace KChart +{ + +KChartWizardSetupAxesPage::KChartWizardSetupAxesPage( TQWidget* parent, + KChartPart* chart ) : + TQWidget( parent ), + _chart( chart ) +{ + chart3d=true; + + TQGridLayout *grid1 = new TQGridLayout(this,2,2,KDialog::marginHint(), KDialog::spacingHint()); + + TQGroupBox* tmpTQGroupBox; + tmpTQGroupBox = new TQGroupBox( this, "GroupBox_1" ); + tmpTQGroupBox->setFrameStyle( 49 ); + + TQGridLayout *grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); + + + //grid = new TQCheckBox( i18n( "Has grid:" ), tmpTQGroupBox ); + new TQLabel( i18n( "Grid Lines" ), tmpTQGroupBox ); + gridX = new TQCheckBox( i18n( "X axis:" ), tmpTQGroupBox ); + gridY = new TQCheckBox( i18n( "Y axis:" ), tmpTQGroupBox ); + + gridX->setChecked(_chart->params()->showGrid()); + gridY->setChecked(_chart->params()->showGrid()); + grid2->addWidget(gridX, 0, 0); + grid2->addWidget(gridY, 1, 0); + + gridColor=new KColorButton(tmpTQGroupBox); + // PENDING(kalle) Put back in + // colorGrid=_chart->params()->GridColor; + gridColor->setColor( colorGrid ); + grid2->addWidget(gridColor, 0, 1); + + border = new TQCheckBox( i18n( "Border:" ), tmpTQGroupBox ); + // PENDING(kalle) Put back in + // border->setChecked( _chart->params()->border ); + grid2->addWidget(border, 2, 0); + border->setEnabled(false); + + borderColor=new KColorButton(tmpTQGroupBox); + // PENDING(kalle) Put back in + // colorBorder=_chart->params()->LineColor; + borderColor->setColor( colorBorder ); + grid2->addWidget(borderColor,2,1); + borderColor->setEnabled(false); + + grid1->addWidget(tmpTQGroupBox,0,0); + + + tmpTQGroupBox = new TQGroupBox( this, "GroupBox_2" ); + tmpTQGroupBox->setFrameStyle( 49 ); + + grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); + + TQLabel *tmpLabel; + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Angle 3D:")); + grid2->addWidget(tmpLabel,0,0); + angle = new TQSpinBox(1, 90, 1,tmpTQGroupBox ); + angle->setValue( _chart->params()->threeDBarAngle() ); + grid2->addWidget(angle,0,1); + + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Depth 3D:")); + grid2->addWidget(tmpLabel,1,0); + depth = new TQSpinBox(1, 40, 1, tmpTQGroupBox); + depth->setValue( static_cast( _chart->params()->threeDBarDepth() ) ); + grid2->addWidget(depth,1,1); + + // Bar width is computed automatically in KDChart (and can be + // changed via gaps) + // tmpLabel=new TQLabel(tmpTQGroupBox); +// tmpLabel->setText(i18n("Bar width:")); +// grid2->addWidget(tmpLabel,2,0); +// barWidth = new TQSpinBox(1, 200, 1, tmpTQGroupBox); +// barWidth->setValue(_chart->params()->bar_width); +// grid2->addWidget(barWidth,2,1); + + grid1->addWidget(tmpTQGroupBox,0,1); + + tmpTQGroupBox = new TQGroupBox( this, "GroupBox_3" ); + tmpTQGroupBox->setFrameStyle( 49 ); + + grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); + + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Y interval:")); + grid2->addWidget(tmpLabel,0,0); + + TQString tmp; + y_interval=new TQLineEdit(tmpTQGroupBox); + y_interval->setValidator(new KFloatValidator( y_interval)); + grid2->addWidget(y_interval,0,1); + // PENDING(kalle) Put back in + // if( _chart->params()->requested_yinterval != -DBL_MAX) +// y_interval->setText( tmp.setNum(_chart->params()->requested_yinterval)); + + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Y min:")); + grid2->addWidget(tmpLabel,1,0); + y_min=new TQLineEdit(tmpTQGroupBox); + y_min->setValidator(new KFloatValidator( y_min)); + grid2->addWidget(y_min,1,1); + // PENDING(kalle) Put back in + // if( _chart->params()->requested_ymin != DBL_MAX) +// y_min->setText( tmp.setNum(_chart->params()->requested_ymin)); + + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Y max:")); + grid2->addWidget(tmpLabel,2,0); + y_max=new TQLineEdit(tmpTQGroupBox); + y_max->setValidator(new KFloatValidator( y_max)); + grid2->addWidget(y_max,2,1); + // PENDING(kalle) Put back in + // if( _chart->params()->requested_ymax != -DBL_MAX) +// y_max->setText( tmp.setNum(_chart->params()->requested_ymax)); + + grid1->addWidget(tmpTQGroupBox,1,0); + tmpTQGroupBox->setEnabled(false); + + tmpTQGroupBox = new TQGroupBox( this, "GroupBox_3" ); + tmpTQGroupBox->setFrameStyle( 49 ); + + grid2 = new TQGridLayout(tmpTQGroupBox,3,2,KDialog::marginHint(), KDialog::spacingHint()); + + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Y-label format:")); + grid2->addWidget(tmpLabel,0,0); + ylabel_fmt=new TQLineEdit(tmpTQGroupBox); + grid2->addWidget(ylabel_fmt,0,1); + + // PENDING(kalle) Put back in + // if( !_chart->params()->ylabel_fmt.isEmpty()) { +// int len=_chart->params()->ylabel_fmt.length(); +// ylabel_fmt->setText(_chart->params()->ylabel_fmt.right(len-3)); +// } + ylabelFont = new TQPushButton( tmpTQGroupBox); + grid2->addWidget(ylabelFont,1,0); + ylabelFont->setText(i18n("Font...")); + // PENDING(kalle) Put back in + // ylabel=_chart->params()->yAxisFont(); + + ylabelColor=new KColorButton(tmpTQGroupBox); + grid2->addWidget(ylabelColor,1,1); + // PENDING(kalle) Put back in + // ycolor=_chart->params()->YLabelColor; + ylabelColor->setColor( ycolor ); + +#if 0 + tmpLabel=new TQLabel(tmpTQGroupBox); + tmpLabel->setText(i18n("Y-label 2 format:")); + grid2->addWidget(tmpLabel,2,0); + + ylabel2_fmt=new TQLineEdit(tmpTQGroupBox); + grid2->addWidget(ylabel2_fmt,2,1); + // PENDING(kalle) Put back in + // if( !_chart->params()->ylabel2_fmt.isEmpty()) { +// int len=_chart->params()->ylabel2_fmt.length(); +// ylabel2_fmt->setText(_chart->params()->ylabel2_fmt.right(len-3)); +// } +#endif + tmpTQGroupBox->setEnabled(false); + grid1->addWidget(tmpTQGroupBox,1,1); + + + + connect(ylabelFont,TQT_SIGNAL(clicked()),this,TQT_SLOT(changeLabelFont())); + + + connect(ylabelColor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeLabelColor(const TQColor &))); + connect(borderColor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeBorderColor(const TQColor &))); + connect(gridColor,TQT_SIGNAL(changed( const TQColor & )), + this,TQT_SLOT(changeGridColor(const TQColor &))); +} + + +KChartWizardSetupAxesPage::~KChartWizardSetupAxesPage() +{ + // _chart->removeAutoUpdate( preview ); +} + +void KChartWizardSetupAxesPage::changeLabelColor(const TQColor &_color) +{ + ycolor=_color; +} + +void KChartWizardSetupAxesPage::changeBorderColor(const TQColor &_color) +{ + colorBorder=_color; +} + +void KChartWizardSetupAxesPage::changeGridColor(const TQColor &_color) +{ + colorGrid=_color; +} + +void KChartWizardSetupAxesPage::changeLabelFont() +{ + if( TDEFontDialog::getFont( ylabel,false,this ) == TQDialog::Rejected ) + return; +} + +void KChartWizardSetupAxesPage::paintEvent( TQPaintEvent *) +{ + if(chart3d) { + angle->setEnabled(true); + depth->setEnabled(true); + //barWidth->setEnabled(true); + } else { + angle->setEnabled(false); + depth->setEnabled(false); + //barWidth->setEnabled(false); + } +} + +void KChartWizardSetupAxesPage::apply() +{ + _chart->params()->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,gridY->isChecked() ); + _chart->params()->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,gridX->isChecked() ); + + KDChartAxisParams leftparams; + leftparams = _chart->params()->axisParams( KDChartAxisParams::AxisPosLeft ); +/* if( !y_max->text().isEmpty()) + { + leftparams.setAxisAreaMode(KDChartAxisParams::AxisAreaModeMinMaxSize); + leftparams.setAxisAreaMax(y_max->text().toDouble()); + } + else + leftparams.setAxisAreaMode(KDChartAxisParams::AxisAreaModeAutoSize);*/ + //leftparams.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); + _chart->params()->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams ); + // PENDING(kalle) Put back in + // _chart->params()->grid =grid->isChecked() ; +// if( !y_interval->text().isEmpty()) +// _chart->params()->requested_yinterval=y_interval->text().toDouble(); +// else +// _chart->params()->requested_yinterval=0; +// if( !y_max->text().isEmpty()) +// _chart->params()->requested_ymax=y_max->text().toDouble(); +// else +// _chart->params()->requested_ymax=0; +// if( !y_min->text().isEmpty()) +// _chart->params()->requested_ymin=y_min->text().toDouble(); +// else +// _chart->params()->requested_ymin=0; + + // PENDING(kalle) Put back in +// _chart->params()->border =border->isChecked() ; + + _chart->params()->setThreeDBarAngle( angle->value() ); + // PENDING(kalle) Put back in + // if(! ylabel_fmt->text().isEmpty()) { +// TQString tmp="%g "+ylabel_fmt->text(); +// _chart->params()->ylabel_fmt=tmp; +// } else { +// _chart->params()->ylabel_fmt=""; +// } +// _chart->params()->setYAxisFont(ylabel); +// _chart->params()->YLabelColor=ycolor; +// _chart->params()->GridColor=colorGrid; +// _chart->params()->LineColor=colorBorder; + _chart->params()->setThreeDBarDepth( depth->value() ); + // PENDING(kalle) Put back in + // if(! ylabel2_fmt->text().isEmpty()) { +// TQString tmp="%g "+ylabel2_fmt->text(); +// _chart->params()->ylabel2_fmt=tmp; +// } else { +// _chart->params()->ylabel2_fmt=""; +// } +} + +} //namespace KChart + +#include "kchartWizardSetupAxesPage.moc" diff --git a/kchart/kchartWizardSetupDataPage.cc b/kchart/kchartWizardSetupDataPage.cc deleted file mode 100644 index 1d057d4c..00000000 --- a/kchart/kchartWizardSetupDataPage.cc +++ /dev/null @@ -1,133 +0,0 @@ -/* $Id$ */ - -#include "kchartWizardSetupDataPage.h" -#include "kchart_view.h" -#include "kchartWizard.h" - -#include -#include -#include -#include - -namespace KChart -{ - -KChartWizardSetupDataPage::KChartWizardSetupDataPage( TQWidget* parent, - KChartPart* chart) : - TQWidget( parent ), - _chart( chart ), - _parent( (KChartWizard*)parent ) -{ - TQButtonGroup* tmpTQGroupBox; - tmpTQGroupBox = new TQButtonGroup( this, "GroupBox_1" ); - tmpTQGroupBox->setGeometry( 260, 10, 130, 80 ); - tmpTQGroupBox->setFrameStyle( 49 ); - tmpTQGroupBox->setAlignment( 1 ); - - datarow = new TQRadioButton( this, "RadioButton_1" ); - datarow->setGeometry( 270, 40, 100, 20 ); - datarow->setText( i18n("Rows") ); - connect( datarow, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( dataInRowsClicked() ) ); - tmpTQGroupBox->insert( datarow ); - - datacol = new TQRadioButton( this, "RadioButton_2" ); - datacol->setGeometry( 270, 60, 100, 20 ); - datacol->setText( i18n("Columns") ); - datacol->setChecked( true ); - connect( datarow, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( dataInColsClicked() ) ); - tmpTQGroupBox->insert( datacol ); - - TQLabel* tmpTQLabel; - tmpTQLabel = new TQLabel( this, "Label_3" ); - tmpTQLabel->setGeometry( 270, 20, 100, 20 ); - tmpTQLabel->setText( i18n("Data is in:") ); - - TQButtonGroup* descrBG = new TQButtonGroup( this ); - descrBG->hide(); - coldescript = new TQCheckBox( this, "CheckBox_3" ); - coldescript->setGeometry( 260, 110, 20, 30 ); - coldescript->setChecked( true ); - connect( coldescript, TQT_SIGNAL( toggled( bool ) ), - this, TQT_SLOT( firstColumnIsDescriptionToggled( bool ) ) ); - coldescript->setText( "" ); - descrBG->insert( coldescript ); - - tmpTQLabel = new TQLabel( this, "Label_4" ); - tmpTQLabel->setGeometry( 280, 110, 100, 30 ); - tmpTQLabel->setText( i18n("Use first row as description") ); - tmpTQLabel->setAlignment( 1313 ); - - rowdescript = new TQCheckBox( this, "CheckBox_4" ); - rowdescript->setGeometry( 260, 150, 20, 30 ); - connect( rowdescript, TQT_SIGNAL( toggled( bool ) ), - this, TQT_SLOT( firstRowIsDescriptionToggled( bool ) ) ); - rowdescript->setText( "" ); - descrBG->insert( rowdescript ); - - tmpTQLabel = new TQLabel( this, "Label_5" ); - tmpTQLabel->setGeometry( 280, 150, 100, 30 ); - tmpTQLabel->setText( i18n("Use first column as description") ); - tmpTQLabel->setAlignment( 1313 ); - - TQFrame* tmpTQFrame; - tmpTQFrame = new TQFrame( this, "Frame_1" ); - tmpTQFrame->setGeometry( 10, 10, 240, 220 ); - tmpTQFrame->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); - tmpTQFrame->setLineWidth( 2 ); - - /* - preview = new kchartWidget( _chart, tmpTQFrame ); - preview->show(); - _chart->addAutoUpdate( preview ); - preview->resize( tmpTQFrame->contentsRect().width(), - tmpTQFrame->contentsRect().height() ); - */ - //parent->resize( 400, 350 ); -} - - -KChartWizardSetupDataPage::~KChartWizardSetupDataPage() -{ - /* - _chart->removeAutoUpdate( preview ); - */ -} - - -void KChartWizardSetupDataPage::dataInRowsClicked() -{ - _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), KChartWizard::Row, - coldescript->isChecked(), - rowdescript->isChecked() ); -} - -void KChartWizardSetupDataPage::dataInColsClicked() -{ - _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), KChartWizard::Col, - coldescript->isChecked(), - rowdescript->isChecked() ); -} - -void KChartWizardSetupDataPage::firstColumnIsDescriptionToggled( bool ) -{ - _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), - ( datarow->isChecked() ? KChartWizard::Row : - KChartWizard::Col ), - coldescript->isChecked(), - rowdescript->isChecked() ); -} - -void KChartWizardSetupDataPage::firstRowIsDescriptionToggled( bool ) -{ - _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), - ( datarow->isChecked() ? KChartWizard::Row - : KChartWizard::Col ), - coldescript->isChecked(), - rowdescript->isChecked() ); -} - -} //namespace KChart - -#include "kchartWizardSetupDataPage.moc" diff --git a/kchart/kchartWizardSetupDataPage.cpp b/kchart/kchartWizardSetupDataPage.cpp new file mode 100644 index 00000000..1d057d4c --- /dev/null +++ b/kchart/kchartWizardSetupDataPage.cpp @@ -0,0 +1,133 @@ +/* $Id$ */ + +#include "kchartWizardSetupDataPage.h" +#include "kchart_view.h" +#include "kchartWizard.h" + +#include +#include +#include +#include + +namespace KChart +{ + +KChartWizardSetupDataPage::KChartWizardSetupDataPage( TQWidget* parent, + KChartPart* chart) : + TQWidget( parent ), + _chart( chart ), + _parent( (KChartWizard*)parent ) +{ + TQButtonGroup* tmpTQGroupBox; + tmpTQGroupBox = new TQButtonGroup( this, "GroupBox_1" ); + tmpTQGroupBox->setGeometry( 260, 10, 130, 80 ); + tmpTQGroupBox->setFrameStyle( 49 ); + tmpTQGroupBox->setAlignment( 1 ); + + datarow = new TQRadioButton( this, "RadioButton_1" ); + datarow->setGeometry( 270, 40, 100, 20 ); + datarow->setText( i18n("Rows") ); + connect( datarow, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( dataInRowsClicked() ) ); + tmpTQGroupBox->insert( datarow ); + + datacol = new TQRadioButton( this, "RadioButton_2" ); + datacol->setGeometry( 270, 60, 100, 20 ); + datacol->setText( i18n("Columns") ); + datacol->setChecked( true ); + connect( datarow, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( dataInColsClicked() ) ); + tmpTQGroupBox->insert( datacol ); + + TQLabel* tmpTQLabel; + tmpTQLabel = new TQLabel( this, "Label_3" ); + tmpTQLabel->setGeometry( 270, 20, 100, 20 ); + tmpTQLabel->setText( i18n("Data is in:") ); + + TQButtonGroup* descrBG = new TQButtonGroup( this ); + descrBG->hide(); + coldescript = new TQCheckBox( this, "CheckBox_3" ); + coldescript->setGeometry( 260, 110, 20, 30 ); + coldescript->setChecked( true ); + connect( coldescript, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( firstColumnIsDescriptionToggled( bool ) ) ); + coldescript->setText( "" ); + descrBG->insert( coldescript ); + + tmpTQLabel = new TQLabel( this, "Label_4" ); + tmpTQLabel->setGeometry( 280, 110, 100, 30 ); + tmpTQLabel->setText( i18n("Use first row as description") ); + tmpTQLabel->setAlignment( 1313 ); + + rowdescript = new TQCheckBox( this, "CheckBox_4" ); + rowdescript->setGeometry( 260, 150, 20, 30 ); + connect( rowdescript, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( firstRowIsDescriptionToggled( bool ) ) ); + rowdescript->setText( "" ); + descrBG->insert( rowdescript ); + + tmpTQLabel = new TQLabel( this, "Label_5" ); + tmpTQLabel->setGeometry( 280, 150, 100, 30 ); + tmpTQLabel->setText( i18n("Use first column as description") ); + tmpTQLabel->setAlignment( 1313 ); + + TQFrame* tmpTQFrame; + tmpTQFrame = new TQFrame( this, "Frame_1" ); + tmpTQFrame->setGeometry( 10, 10, 240, 220 ); + tmpTQFrame->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + tmpTQFrame->setLineWidth( 2 ); + + /* + preview = new kchartWidget( _chart, tmpTQFrame ); + preview->show(); + _chart->addAutoUpdate( preview ); + preview->resize( tmpTQFrame->contentsRect().width(), + tmpTQFrame->contentsRect().height() ); + */ + //parent->resize( 400, 350 ); +} + + +KChartWizardSetupDataPage::~KChartWizardSetupDataPage() +{ + /* + _chart->removeAutoUpdate( preview ); + */ +} + + +void KChartWizardSetupDataPage::dataInRowsClicked() +{ + _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), KChartWizard::Row, + coldescript->isChecked(), + rowdescript->isChecked() ); +} + +void KChartWizardSetupDataPage::dataInColsClicked() +{ + _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), KChartWizard::Col, + coldescript->isChecked(), + rowdescript->isChecked() ); +} + +void KChartWizardSetupDataPage::firstColumnIsDescriptionToggled( bool ) +{ + _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), + ( datarow->isChecked() ? KChartWizard::Row : + KChartWizard::Col ), + coldescript->isChecked(), + rowdescript->isChecked() ); +} + +void KChartWizardSetupDataPage::firstRowIsDescriptionToggled( bool ) +{ + _parent->emitNeedNewData( (const char*)_parent->dataArea().local8Bit(), + ( datarow->isChecked() ? KChartWizard::Row + : KChartWizard::Col ), + coldescript->isChecked(), + rowdescript->isChecked() ); +} + +} //namespace KChart + +#include "kchartWizardSetupDataPage.moc" diff --git a/kchart/kchart_factory.cc b/kchart/kchart_factory.cc deleted file mode 100644 index 05362738..00000000 --- a/kchart/kchart_factory.cc +++ /dev/null @@ -1,82 +0,0 @@ -/** - * $Id: kchart_factory.cc 483001 2005-11-24 18:27:18Z dfaure $ - * - * Kalle Dalheimer - */ - - -#include "kchart_factory.h" -#include "kchart_aboutdata.h" -#include "kchart_part.h" -#include -#include -#include -#include -#include - -namespace KChart -{ - -TDEInstance *KChartFactory::s_global = 0; -TDEAboutData *KChartFactory::s_aboutData = 0; - - -KChartFactory::KChartFactory( TQObject* parent, const char* name ) - : KoFactory( parent, name ) -{ - global(); -} - - -KChartFactory::~KChartFactory() -{ - delete s_aboutData; - s_aboutData = 0; - delete s_global; - s_global = 0; -} - - -KParts::Part* KChartFactory::createPartObject( TQWidget *parentWidget, - const char *widgetName, - TQObject* parent, - const char* name, - const char *classname, - const TQStringList & ) -{ - bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 ); - - KChartPart *part = new KChartPart( parentWidget, widgetName, parent, name, - !bWantKoDocument ); - - if ( !bWantKoDocument ) - part->setReadWrite( false ); - - return part; -} - - -TDEAboutData* KChartFactory::aboutData() -{ - if( !s_aboutData ) - s_aboutData = newKChartAboutData(); - return s_aboutData; -} - - -TDEInstance* KChartFactory::global() -{ - if ( !s_global ) - { - s_global = new TDEInstance(aboutData()); - s_global->dirs()->addResourceType( "kchart_template", - TDEStandardDirs::kde_default("data") + "kchart/templates/"); - // Tell the iconloader about share/apps/koffice/icons - s_global->iconLoader()->addAppDir("koffice"); - } - return s_global; -} - -} //namespace KChart - -#include diff --git a/kchart/kchart_factory.cpp b/kchart/kchart_factory.cpp new file mode 100644 index 00000000..ff00f205 --- /dev/null +++ b/kchart/kchart_factory.cpp @@ -0,0 +1,82 @@ +/** + * $Id: kchart_factory.cpp 483001 2005-11-24 18:27:18Z dfaure $ + * + * Kalle Dalheimer + */ + + +#include "kchart_factory.h" +#include "kchart_aboutdata.h" +#include "kchart_part.h" +#include +#include +#include +#include +#include + +namespace KChart +{ + +TDEInstance *KChartFactory::s_global = 0; +TDEAboutData *KChartFactory::s_aboutData = 0; + + +KChartFactory::KChartFactory( TQObject* parent, const char* name ) + : KoFactory( parent, name ) +{ + global(); +} + + +KChartFactory::~KChartFactory() +{ + delete s_aboutData; + s_aboutData = 0; + delete s_global; + s_global = 0; +} + + +KParts::Part* KChartFactory::createPartObject( TQWidget *parentWidget, + const char *widgetName, + TQObject* parent, + const char* name, + const char *classname, + const TQStringList & ) +{ + bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 ); + + KChartPart *part = new KChartPart( parentWidget, widgetName, parent, name, + !bWantKoDocument ); + + if ( !bWantKoDocument ) + part->setReadWrite( false ); + + return part; +} + + +TDEAboutData* KChartFactory::aboutData() +{ + if( !s_aboutData ) + s_aboutData = newKChartAboutData(); + return s_aboutData; +} + + +TDEInstance* KChartFactory::global() +{ + if ( !s_global ) + { + s_global = new TDEInstance(aboutData()); + s_global->dirs()->addResourceType( "kchart_template", + TDEStandardDirs::kde_default("data") + "kchart/templates/"); + // Tell the iconloader about share/apps/koffice/icons + s_global->iconLoader()->addAppDir("koffice"); + } + return s_global; +} + +} //namespace KChart + +#include diff --git a/kchart/kchart_factory_init.cc b/kchart/kchart_factory_init.cc deleted file mode 100644 index 42b2b2ca..00000000 --- a/kchart/kchart_factory_init.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kchart_factory.h" - -K_EXPORT_COMPONENT_FACTORY( libkchartpart, KChart::KChartFactory ) - diff --git a/kchart/kchart_factory_init.cpp b/kchart/kchart_factory_init.cpp new file mode 100644 index 00000000..42b2b2ca --- /dev/null +++ b/kchart/kchart_factory_init.cpp @@ -0,0 +1,23 @@ +/* This file is part of the KDE project + Copyright (C) 2005 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kchart_factory.h" + +K_EXPORT_COMPONENT_FACTORY( libkchartpart, KChart::KChartFactory ) + diff --git a/kchart/kchart_params.cc b/kchart/kchart_params.cc deleted file mode 100644 index 2cd8da51..00000000 --- a/kchart/kchart_params.cc +++ /dev/null @@ -1,1043 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001,2002,2003,2004 Laurent Montel - Copyright (C) 2006 Thorsten Zachmann - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - - -//#include -#include -using std::cout; -using std::cerr; - - -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include "kdchart/KDChartParams.h" -#include "kdchart/KDChartAxisParams.h" - -#include "kchart_params.h" -#include "kchart_part.h" -#include "KChartParamsIface.h" - - -namespace KChart -{ - - -KChartParams::KChartParams( KChartPart *_part ) - : KDChartParams(), - m_part( _part ) -{ - // Default values for subtypes. - m_firstRowAsLabel = false; - m_firstColAsLabel = false; - - // Default values for OpenDocument extensions. - m_barNumLines = 0; - - m_dcop = 0; - //dcopObject(); // build it -} - - -KChartParams::~KChartParams() -{ - delete m_dcop; -} - - -// ---------------------------------------------------------------- - - -TQString KChartParams::chartTypeToString( ChartType _type) const -{ -#if 0 - if (_type == BarLines ) - return "BarLines"; - else -#endif - return KDChartParams::chartTypeToString( (KDChartParams::ChartType) _type ); -} - - -KChartParams::ChartType -KChartParams::stringToChartType( const TQString& _string ) -{ -#if 0 - if ( _string == "BarLines" ) - return BarLines; - else -#endif - return (ChartType) KDChartParams::stringToChartType( _string ); -} - - -void KChartParams::setFirstRowAsLabel( bool _val ) -{ - m_firstRowAsLabel = _val; - - // The rest of this method is only applicable if the data is from - // an external source, e.g. from kspread. - if ( m_part->canChangeValue() ) - return; - - m_part->doSetData( *m_part->data(), - m_firstRowAsLabel, m_firstColAsLabel ); -} - -void KChartParams::setFirstColAsLabel( bool _val ) -{ - m_firstColAsLabel = _val; - - // The rest of this method is only applicable if the data is from - // an external source, e.g. kspread. - if ( m_part->canChangeValue() ) - return; - - m_part->doSetData( *m_part->data(), - m_firstRowAsLabel, m_firstColAsLabel ); -} - - -DCOPObject* KChartParams::dcopObject() -{ - if ( !m_dcop ) - m_dcop = new KChartParamsIface( this ); - return m_dcop; -} - - -// ================================================================ -// Loading and Saving - - - -static const struct { - const char *oasisClass; - KChartParams::ChartType chartType; -} oasisChartTypes[] = { - { "chart:bar", KChartParams::Bar }, - { "chart:line", KChartParams::Line }, - { "chart:area", KChartParams::Area }, - { "chart:circle", KChartParams::Pie }, - //{ "chart:xxx", KChartParams::HiLo }, - //{ "chart:stock", KChartParams::??? }, - //{ "chart:add-in", KChartParams::??? }, - //{ "chart:scatter",KChartParams::??? }, - { "chart:ring", KChartParams::Ring }, - { "chart:radar", KChartParams::Polar } - //{ "chart:xxx", KChartParams::BoxWhisker }, - - //{ "chart:xxx", KChartParams::BarLines }, - // FIXME: More? -}; - - -static const unsigned int numOasisChartTypes - = sizeof oasisChartTypes / sizeof *oasisChartTypes; - - -#if 0 // Example code!! - KoOasisLoadingContext loadingContext( this, oasisStyles, store ); - KoStyleStack &styleStack = loadingContext.styleStack(); - - styleStack.save(); - styleStack.setTypeProperties( "graphic" ); // load graphic-properties - loadingContext.fillStyleStack( chartElem, KoXmlNS::chart, "style-name" ); - - const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, "fill-color" ); - kDebug() << "fillColor=" << fillColor << endl; - - styleStack.restore(); -#endif - - -// Load the data from an OpenDocument chart:chart element. - -void KChartParams::loadOasisFont( KoOasisLoadingContext& context, TQFont& font, TQColor& color ) -{ - KoStyleStack& styleStack = context.styleStack(); - styleStack.setTypeProperties( "text" ); // load all style attributes from "style:text-properties" - - if ( styleStack.hasAttributeNS( KoXmlNS::fo, "color" ) ) { // 3.10.3 - color.setNamedColor( styleStack.attributeNS( KoXmlNS::fo, "color" ) ); // #rrggbb format - } - if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-family" ) // 3.10.9 - || styleStack.hasAttributeNS( KoXmlNS::style, "font-name" ) ) { // 3.10.8 - // Hmm, the remove "'" could break it's in the middle of the fontname... - TQString fontName = styleStack.attributeNS( KoXmlNS::fo, "font-family" ).remove( "'" ); - if ( fontName.isEmpty() ) { - // ##### TODO. This is wrong. style:font-name refers to a font-decl entry. - // We have to look it up there, and retrieve _all_ font attributes from it, not just the name. - fontName = styleStack.attributeNS( KoXmlNS::style, "font-name" ).remove( "'" ); - } - // 'Thorndale' is not known outside OpenOffice so we substitute it - // with 'Times New Roman' that looks nearly the same. - if ( fontName == "Thorndale" ) - fontName = "Times New Roman"; - - fontName.remove( TQRegExp( "\\sCE$" ) ); // Arial CE -> Arial - font.setFamily( fontName ); - } - if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-size" ) ) { // 3.10.14 - double pointSize = styleStack.fontSize(); - font.setPointSizeFloat( pointSize ); - kdDebug(35001) << "font size: " << pointSize << endl; - } - if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-weight" ) ) { // 3.10.24 - TQString fontWeight = styleStack.attributeNS( KoXmlNS::fo, "font-weight" ); - int boldness; - if ( fontWeight == "normal" ) - boldness = 50; - else if ( fontWeight == "bold" ) - boldness = 75; - else - // XSL/CSS has 100,200,300...900. Not the same scale as TQt! - // See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight - boldness = fontWeight.toInt() / 10; - font.setWeight( boldness ); - } - if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-style" ) ) { // 3.10.19 - if ( styleStack.attributeNS( KoXmlNS::fo, "font-style" ) == "italic" || - styleStack.attributeNS( KoXmlNS::fo, "font-style" ) == "oblique" ) { // no difference in kotext - font.setItalic( true ); - } - } -} - -bool KChartParams::loadOasis( const TQDomElement &chartElem, - KoOasisLoadingContext &loadingContext, - TQString &errorMessage, - KoStore */*store*/ ) -{ - const TQString chartClass = chartElem.attributeNS( KoXmlNS::chart, - "class", TQString() ); - bool knownType = false; - - // Find out what KChart charttype the OASIS charttype corresponds to. - for ( unsigned int i = 0 ; i < numOasisChartTypes ; ++i ) { - if ( chartClass == oasisChartTypes[i].oasisClass ) { - kdDebug(35001) << "found chart of type " << chartClass << endl; - //cerr << "found chart of type " << chartClass.latin1() << "\n"; - - setChartType( oasisChartTypes[i].chartType ); - knownType = true; - break; - } - } - - // If we can't find out what charttype it is, we might as well end here. - if ( !knownType ) { - errorMessage = i18n( "Unknown chart type %1" ).arg( chartClass ); - kdDebug(35001) << errorMessage << endl; - return false; - } - - // Title TODO (more details, e.g. font, placement etc) - TQDomElement titleElem = KoDom::namedItemNS( chartElem, - KoXmlNS::chart, "title" ); - if ( !titleElem.isNull() ) { - loadingContext.styleStack().save(); - loadingContext.fillStyleStack( titleElem, KoXmlNS::chart, "style-name", "chart" ); - TQFont font; - TQColor color; - loadOasisFont( loadingContext, font, color ); - setHeaderFooterFont( KDChartParams::HdFtPosHeader, font, true, font.pointSize()*4 ); - setHeaderFooterColor( KDChartParams::HdFtPosHeader, color ); - loadingContext.styleStack().restore(); - - TQDomElement pElem = KoDom::namedItemNS( titleElem, - KoXmlNS::text, "p" ); - setHeader1Text( pElem.text() ); - } - - // Subtitle TODO (more details) - TQDomElement subtitleElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, - "subtitle" ); - if ( !subtitleElem.isNull() ) { - loadingContext.styleStack().save(); - loadingContext.fillStyleStack( subtitleElem, KoXmlNS::chart, "style-name", "chart" ); - TQFont font; - TQColor color; - loadOasisFont( loadingContext, font, color ); - setHeaderFooterFont( KDChartParams::HdFtPosHeader2, font, true, font.pointSize()*4 ); - setHeaderFooterColor( KDChartParams::HdFtPosHeader2, color ); - loadingContext.styleStack().restore(); - - TQDomElement pElem = KoDom::namedItemNS( subtitleElem, - KoXmlNS::text, "p" ); - setHeader2Text( pElem.text() ); - } - - // Footer TODO (more details) - TQDomElement footerElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, - "footer" ); - if ( !footerElem.isNull() ) { - loadingContext.styleStack().save(); - loadingContext.fillStyleStack( footerElem, KoXmlNS::chart, "style-name", "chart" ); - TQFont font; - TQColor color; - loadOasisFont( loadingContext, font, color ); - setHeaderFooterFont( KDChartParams::HdFtPosFooter, font, true, font.pointSize()*4 ); - setHeaderFooterColor( KDChartParams::HdFtPosFooter, color ); - loadingContext.styleStack().restore(); - - TQDomElement pElem = KoDom::namedItemNS( footerElem, - KoXmlNS::text, "p" ); - setFooterText( pElem.text() ); - } - - // TODO: Get legend settings - TQDomElement legendElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, - "legend" ); - if ( !legendElem.isNull() ) - { - loadingContext.styleStack().save(); - loadingContext.fillStyleStack( legendElem, KoXmlNS::chart, "style-name", "chart" ); - TQFont font; - TQColor color; - loadOasisFont( loadingContext, font, color ); - //tz I didn't find that Oasis support seperate font/colors for the title and the rest of the legent - setLegendFont( font, false ); - setLegendFontRelSize( font.pointSize()*4 ); - setLegendTitleFont( font, false); - setLegendTitleFontRelSize( font.pointSize()*4 ); - setLegendTextColor( color ); - setLegendTitleTextColor( color ); - loadingContext.styleStack().restore(); - TQString lp; - if ( legendElem.hasAttributeNS( KoXmlNS::chart, "legend-position" ) ) - { - lp = legendElem.attributeNS( KoXmlNS::chart, "legend-position", TQString() ); - } - TQString lalign; - if ( legendElem.hasAttributeNS( KoXmlNS::chart, "legend-align" ) ) - { - lalign = legendElem.attributeNS( KoXmlNS::chart, "legend-align", TQString() ); - } - - LegendPosition lpos = NoLegend; - int align = 1; - if ( lalign == "start" ) - { - align = 0; - } - else if ( lalign == "end" ) - { - align = 2; - } - - if ( lp == "start" ) - { - lpos = LegendLeft; - if ( align == 0 ) - lpos = LegendTopLeftLeft; - else if ( align == 2 ) - lpos = LegendBottomLeftLeft; - } - else if ( lp == "end" ) - { - lpos = LegendRight; - if ( align == 0 ) - lpos = LegendTopRightRight; - else if ( align == 2 ) - lpos = LegendBottomRightRight; - } - else if ( lp == "top" ) - { - lpos = LegendTop; - if ( align == 0 ) - lpos = LegendTopLeftTop; - else if ( align == 2 ) - lpos = LegendTopRightTop; - } - else if ( lp == "bottom" ) - { - lpos = LegendBottom; - if ( align == 0 ) - lpos = LegendBottomLeftBottom; - else if ( align == 2 ) - lpos = LegendBottomRightBottom; - } - else if ( lp == "top-start" ) - { - lpos = LegendTopLeft; - } - else if ( lp == "bottom-start" ) - { - lpos = LegendBottomLeft; - } - else if ( lp == "top-end" ) - { - lpos = LegendTopRight; - } - else if ( lp == "bottom-end" ) - { - lpos = LegendBottomRight; - } - - setLegendPosition( lpos ); - //bodyWriter->addAttribute( "koffice:title", legendTitleText() ); - if ( legendElem.hasAttributeNS( KoXmlNS::koffice, "title" ) ) - { - setLegendTitleText( legendElem.attributeNS( KoXmlNS::koffice, "title", TQString() ) ); - } - } - else - { - setLegendPosition( NoLegend ); - } - - // Get the plot-area. This is where the action is. - TQDomElement plotareaElem = KoDom::namedItemNS( chartElem, - KoXmlNS::chart, "plot-area" ); - if ( !plotareaElem.isNull() ) { - return loadOasisPlotarea( plotareaElem, loadingContext, errorMessage ); - } - - return false; -} - - -bool KChartParams::loadOasisPlotarea( const TQDomElement &plotareaElem, - KoOasisLoadingContext &loadingContext, - TQString &errorMessage ) -{ - TQString tmp; - - //cerr << ">>> ==========================================================\n"; - - // FIXME: attribute table:cell-range-address - the cells in a spreadsheet - - // Get whether there is a label on the first row or column of the data. - // This info is in the attribute chart:data-source-has-labels. - // - // NOTE: Only used in spreadsheets. - tmp = plotareaElem.attributeNS( KoXmlNS::chart, - "data-source-has-labels", TQString() ); - m_firstRowAsLabel = false; - m_firstColAsLabel = false; - if ( tmp == "none" || tmp == "" ) - ; // NOTHING - else if ( tmp == "row" ) - m_firstRowAsLabel = true; - else if ( tmp == "column" ) - m_firstColAsLabel = true; - else if ( tmp == "both" ) { - m_firstRowAsLabel = true; - m_firstColAsLabel = true; - } - else { - errorMessage = "Unknown value for chart:data-source-has-labels:" - + tmp; - return false; - } - - // ---------------------------------------------------------------- - // Now get the style and use it to get the contents. - // This is hidden in the attribute chart:style-name. - KoStyleStack &styleStack = loadingContext.styleStack(); - - - tmp = plotareaElem.attributeNS( KoXmlNS::chart, "style-name", - TQString() ); - //kdDebug(35001) << "Style name for the plot area: " << tmp << endl; - styleStack.save(); - styleStack.setTypeProperties( "chart" ); // load chart properties - loadingContext.fillStyleStack( plotareaElem, KoXmlNS::chart, "style-name", "chart" ); - - if ( styleStack.attributeNS( KoXmlNS::chart, "three-dimensional" ) == "true" ) { - setThreeDBars( true ); - setThreeDLines( true ); - setThreeDPies( true ); - } - else { - setThreeDBars( false ); - setThreeDLines( false ); - setThreeDPies( false ); - } - - switch ( m_chartType ) { - case NoType: - break; - - case Bar: - // Find out subtype - tmp = styleStack.attributeNS( KoXmlNS::chart, "vertical" ); - // FIXME:Qt::Vertical is ignored. At least store it so we can - // save it again even if we don't support it. - - //kdDebug(35001) << " ======> Qt::Vertical: " << tmp << " <======" << endl; - // Set the bar chart subtype. - if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) - setBarChartSubType( BarStacked ); - else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) - setBarChartSubType( BarPercent ); - else - setBarChartSubType( BarNormal ); - - break; - - // chart:vertical - true if vertical bars (only bar charts) - // chart:stacked - true for stacked bars - // chart:percentage - true for percentage (mut. excl with stacked) - // chart:connect-bars - true if lines to connect bars should be drawn - // only used for stacked and percentage bars. - // FIXME: Support lines on bar charts. - // chart:lines-used - 0-n, number of lines on a bar chart. (def: 0) - - case Line: - // Set the line chart subtype. - if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) - setLineChartSubType( LineStacked ); - else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) - setLineChartSubType( LinePercent ); - else - setLineChartSubType( LineNormal ); - - break; - - // FIXME: Why is this even there? Seems like an unnecessary attr. - // chart:lines - true for line charts, false otherwise - - // chart:stacked - true for stacked bars - // chart:percentage - true for percentage (mut. excl with stacked) - - // chart:symbol-type - used with line charts, should be "automatic" - - case Area: - // Set the area chart subtype. - if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) - setAreaChartSubType( AreaStacked ); - else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) - setAreaChartSubType( AreaPercent ); - else - setAreaChartSubType( AreaNormal ); - - break; - - // chart:stacked - true for stacked bars - // chart:percentage - true for percentage (mut. excl with stacked) - - case Pie: - break; - - case HiLo: - break; - - case Ring: - break; - - case Polar: - break; - - case BoxWhisker: - break; - } - // TODO: - // And get the info from the style. Here is the contents: - - - // TODO: These items are currently not used. They should be at least - // be stored so that we can save them again. - // chart:interpolation - "cubic-spline" if using cubic splines - // chart:splines - - // chart:spline-order - "2" for cubic splines - // chart:spline-resolution - how smooth (default: 20) - - // -- Used when chart:class == "stock: - // chart:stock-updown-bars - boolean - // chart:stock-with-volume - boolean - // chart:japanese-candle-sticks - boolean - - // chart:series-source - "rows" or "columns" - // "columns" is the default - if ( styleStack.attributeNS( KoXmlNS::chart, "series-source" ) == "rows" ) { - setDataDirection( DataRows ); - } - - // chart:data-label-number - "value" / "percentage" / "none" (def: none) - - // chart:data-label-text - true if data hapoints have text labels - // chart:data-label-symbol - true if data hapoints have legend symbol - // (default: false for both) - - styleStack.restore(); - - // ---------------------------------------------------------------- - // In the plot-area element there are two chart:axis elements - - TQDomElement xAxisElem; - TQDomElement yAxisElem; - - TQDomElement axisElem; - forEachElement( axisElem, plotareaElem ) { - - // If this element is not an axis, then continue - if ( axisElem.tagName() != "axis" ) - continue; - - tmp = axisElem.attributeNS( KoXmlNS::chart, "name", - TQString()); - //kdDebug(35001) << "Got axis " << tmp << endl; - //cerr << "Got axis " << tmp.latin1() << "\n"; - if ( tmp == "primary-x" ) - xAxisElem = axisElem; - else if ( tmp == "primary-y" ) - yAxisElem = axisElem; - else - // Only supports two axes so far. - continue; - } - - // Load the axes. Pie charts use only the y axis. - if ( m_chartType != Pie - && !loadOasisAxis( xAxisElem, loadingContext, errorMessage, - KDChartAxisParams::AxisPosBottom) ) - return false; - if ( !loadOasisAxis( yAxisElem, loadingContext, errorMessage, - KDChartAxisParams::AxisPosLeft) ) - return false; - - // Attributes for the axes: - // chart:name - either "primary-x" or "primary-y" - -#if 0 - const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, - "fill-color" ); - kdDebug() << "fillColor=" << fillColor << endl; -#endif - - //cerr << "<<< ==========================================================\n"; - - return true; -} - - -bool KChartParams::loadOasisAxis( const TQDomElement &axisElem, - KoOasisLoadingContext &loadingContext, - TQString &errorMessage, - KDChartAxisParams::AxisPos axisPos ) -{ - Q_UNUSED( errorMessage ); - - TQString tmp; - TQDomElement tmpElem; - KoStyleStack &styleStack = loadingContext.styleStack(); - - // Get the axis to manipulate. - // TODO - - // Get the axis title (== axis label) if any. - TQDomElement titleElem = KoDom::namedItemNS( axisElem, - KoXmlNS::chart, "title" ); - if ( !titleElem.isNull() ) { - tmpElem = KoDom::namedItemNS( titleElem, KoXmlNS::text, "p" ); - setAxisTitle( axisPos, tmpElem.text() ); - } - - - - //cerr << ">>> ----------------------------------------------------------\n"; - //cerr << "Loading axis " << axisElem.attributeNS( KoXmlNS::chart, "name", - // TQString()).latin1() - // << "\n"; - - tmp = axisElem.attributeNS( KoXmlNS::chart, "style-name", TQString() ); - //kdDebug(35001) << "Style name for the axis: " << tmp << endl; - //cerr << "Style name for the axis: " << tmp.latin1() << "\n"; - styleStack.save(); - styleStack.setTypeProperties( "chart" ); // load chart properties - loadingContext.fillStyleStack( axisElem, KoXmlNS::chart, "style-name", "chart" ); - - // chart:class - "category" / "value" / "domain" (domain for scatter) - // child: chart:categories - - // child: chart:title - Name of title if any. - // child: chart:grid - // attr: chart:class - "major" / "minor" - - // chart:style-name - Associated style with the following info: - // -------------------------------- - // chart:display-label - true if an axis label should be shown. - - // chart:tick-marks-major-inner - true if display tickmarks at major - // chart:tick-marks-major-outer or minor intervals outside / inside - // chart:tick-minor-major-inner the chart area. - // chart:tick-minor-major-outer - - // chart:logarithmic - true if logarithmic scale - - // text:line-break - true if categories can be broken - - // chart:text-overlap - true if labels can overlap - - // chart:label-arrangement - "side-by-side" / "stagger-even" / - // "stagger-odd" (def: side-by-side) - - // chart:visible - true if labels + ticks should be shown. - - // children: - // chart: - // chart: - // chart: - // chart: - // chart: - styleStack.restore(); - - //cerr << "<<< ----------------------------------------------------------\n"; - return true; -} - - -// ---------------------------------------------------------------- - - -void KChartParams::saveOasis( KoXmlWriter* bodyWriter, KoGenStyles& mainStyles ) const -{ - bool knownType = false; - for ( unsigned int i = 0 ; i < numOasisChartTypes ; ++i ) { - if ( m_chartType == oasisChartTypes[i].chartType ) { - bodyWriter->addAttribute( "chart:class", oasisChartTypes[i].oasisClass ); - knownType = true; - break; - } - } - - if ( !knownType ) { - kdError(32001) << "Unknown chart type in KChartParams::saveOasis, extend oasisChartTypes!" << endl; - } - - bodyWriter->startElement( "chart:title" ); - TQRect rect( headerFooterRect( KDChartParams::HdFtPosHeader ) ); - bodyWriter->addAttributePt( "svg:x", rect.x() ); - bodyWriter->addAttributePt( "svg:y", rect.y() ); - bodyWriter->addAttribute( "chart:style-name", saveOasisFont( mainStyles, header1Font(), headerFooterColor( KDChartParams::HdFtPosHeader ) ) ); - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( header1Text() ); - bodyWriter->endElement(); // text:p - bodyWriter->endElement(); // chart:title - - TQString subTitle( header2Text() ); - if ( !subTitle.isEmpty() ) { - - kdDebug(32001) << "header rect: " << headerFooterRect( KDChartParams::HdFtPosHeader2 ) << endl; - TQRect rect( headerFooterRect( KDChartParams::HdFtPosHeader2 ) ); - bodyWriter->startElement( "chart:subtitle" ); - bodyWriter->addAttributePt( "svg:x", rect.x() ); - bodyWriter->addAttributePt( "svg:y", rect.y() ); - bodyWriter->addAttribute( "chart:style-name", - saveOasisFont( mainStyles, - header2Font(), - headerFooterColor( KDChartParams::HdFtPosHeader2 ) ) ); - - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( subTitle ); - bodyWriter->endElement(); // text:p - bodyWriter->endElement(); // chart:subtitle - } - - - TQString footer( footerText() ); - if ( !footer.isEmpty() ) { - TQRect rect( headerFooterRect( KDChartParams::HdFtPosFooter ) ); - bodyWriter->startElement( "chart:footer" ); - bodyWriter->addAttributePt( "svg:x", rect.x() ); - bodyWriter->addAttributePt( "svg:y", rect.y() ); - bodyWriter->addAttribute( "chart:style-name", - saveOasisFont( mainStyles, - footerFont(), - headerFooterColor( KDChartParams::HdFtPosFooter ) ) ); - - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( footer ); - bodyWriter->endElement(); // text:p - bodyWriter->endElement(); // chart:footer - } - - // TODO legend - LegendPosition lpos = legendPosition(); - if ( lpos != NoLegend ) { - bodyWriter->startElement( "chart:legend" ); - TQString lp; - TQString lalign; - switch ( lpos ) { - case LegendTop: - lp = "top"; - lalign = "center"; - break; - case LegendBottom: - lp = "bottom"; - lalign = "center"; - break; - case LegendLeft: - lp = "start"; - lalign = "center"; - break; - case LegendRight: - lp = "end"; - lalign = "center"; - break; - case LegendTopLeft: - lp = "top-start"; - break; - case LegendTopLeftTop: - lp = "top"; - lalign = "start"; - break; - case LegendTopLeftLeft: - lp = "start"; - lalign = "start"; - break; - case LegendTopRight: - lp = "top-end"; - break; - case LegendTopRightTop: - lp = "top"; - lalign = "end"; - break; - case LegendTopRightRight: - lp = "end"; - lalign = "start"; - break; - case LegendBottomLeft: - lp = "bottom-start"; - break; - case LegendBottomLeftBottom: - lp = "bottom"; - lalign = "start"; - break; - case LegendBottomLeftLeft: - lp = "start"; - lalign = "end"; - break; - case LegendBottomRight: - lp = "bottom-end"; - break; - case LegendBottomRightBottom: - lp = "bottom"; - lalign = "end"; - break; - case LegendBottomRightRight: - lp = "end"; - lalign = "end"; - break; - default: - lp = "end"; - lalign = "center"; - break; - } - - bodyWriter->addAttribute( "chart:legend-position", lp ); - bodyWriter->addAttribute( "chart:legend-align", lalign ); - bodyWriter->addAttribute( "chart:style-name", - saveOasisFont( mainStyles, - legendFont(), - legendTextColor() ) ); - bodyWriter->addAttribute( "koffice:title", legendTitleText() ); - bodyWriter->endElement(); // chart:legend - } - - bodyWriter->startElement( "chart:plot-area" ); - saveOasisPlotArea( bodyWriter, mainStyles ); - bodyWriter->endElement(); - - // TODO... -} - - -void KChartParams::saveOasisPlotArea( KoXmlWriter* bodyWriter, KoGenStyles& mainStyles ) const -{ - TQString dataSourceHasLabels; - if ( m_firstRowAsLabel ) - if ( m_firstColAsLabel ) - dataSourceHasLabels = "both"; - else - dataSourceHasLabels = "row"; - else - if ( m_firstColAsLabel ) - dataSourceHasLabels = "column"; - else - dataSourceHasLabels = "none"; - bodyWriter->addAttribute( "chart:data-source-has-labels", dataSourceHasLabels ); - - // Prepare the style for the plot area - KoGenStyle plotAreaStyle( KoGenStyle::STYLE_AUTO, "chart" ); - - switch ( m_chartType ) { - case NoType: - break; - - case Bar: - switch( barChartSubType() ) { - case BarStacked: - plotAreaStyle.addProperty( "chart:stacked", "true" ); - break; - case BarPercent: - plotAreaStyle.addProperty( "chart:percentage", "true" ); - break; - case BarNormal: - break; - case BarMultiRows: - break; - } - plotAreaStyle.addProperty( "chart:vertical", "false" ); // #### always? - plotAreaStyle.addProperty( "chart:lines-used", 0 ); // FIXME: for now - - if ( threeDBars() ) - plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); - - case Line: - switch( lineChartSubType() ) { - case LineStacked: - plotAreaStyle.addProperty( "chart:stacked", "true" ); - break; - case LinePercent: - plotAreaStyle.addProperty( "chart:percentage", "true" ); - break; - case LineNormal: - break; - } - plotAreaStyle.addProperty( "chart:symbol-type", "automatic" ); - - if ( threeDLines() ) - plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); - - break; - - case Area: - switch( areaChartSubType() ) { - case AreaStacked: - plotAreaStyle.addProperty( "chart:stacked", "true" ); - break; - case AreaPercent: - plotAreaStyle.addProperty( "chart:percentage", "true" ); - break; - case AreaNormal: - break; - } - //plotAreaStyle.addProperty( "chart:lines-used", 0 ); // #### for now - - // TODO - very similar - - case Pie: - if ( threeDPies() ) - plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); - - break; - - case HiLo: - break; - - case Ring: - break; - - case Polar: - break; - - case BoxWhisker: - break; - } - - // chart:series-source - plotAreaStyle.addProperty( "chart:series-source", - ( dataDirection() == DataRows ) ? "rows" : "columns" ); - - // Register the style, and get back its auto-generated name - const TQString styleName = mainStyles.lookup( plotAreaStyle, "ch" ); - - bodyWriter->addAttribute( "chart:style-name", styleName ); - - saveOasisAxis( bodyWriter, mainStyles, KDChartAxisParams::AxisPosBottom, "x" ); - saveOasisAxis( bodyWriter, mainStyles, KDChartAxisParams::AxisPosLeft, "y" ); - - // TODO chart:series - // TODO chart:wall - // TODO chart:floor -} - - -void KChartParams::saveOasisAxis( KoXmlWriter* bodyWriter, - KoGenStyles& mainStyles, - KDChartAxisParams::AxisPos axisPos, - const char* axisName ) const -{ - bodyWriter->startElement( "chart:axis" ); - - bodyWriter->addAttribute( "chart:dimension", axisName ); - bodyWriter->addAttribute( "chart:name", TQCString( "primary-" ) + axisName ); - - KoGenStyle axisStyle( KoGenStyle::STYLE_AUTO, "chart" ); - - // TODO: Save axis style properties, like - axisStyle.addProperty( "chart:display-label", "true" ); // ### - - - const TQString styleName = mainStyles.lookup( axisStyle, "ch" ); - bodyWriter->addAttribute( "chart:style-name", styleName ); - - // Write axis titles if any. - TQString tmpStr = axisTitle( axisPos ); - if ( tmpStr != "" ) { - bodyWriter->startElement( "chart:title" ); - // TODO: Save style, svg:x, svg:y - - // Write the text in the axis title. - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( tmpStr - .remove( TQRegExp( "^
" ) ) - .remove( TQRegExp( "
$" ) ) ); - bodyWriter->endElement(); // text:p - - bodyWriter->endElement(); // chart:title - } - - // TODO x axis has chart:categories, y axis has chart:grid ? - // Maybe that part should be done by the caller of saveOasisAxis then - // including the opening/closing of the chart:axis element... - - bodyWriter->endElement(); // chart:axis -} - - -TQString KChartParams::saveOasisFont( KoGenStyles& mainStyles, const TQFont& font, const TQColor& color ) const -{ - KoGenStyle::PropertyType tt = KoGenStyle::TextType; - KoGenStyle autoStyle( KoGenStyle::STYLE_AUTO, "chart", 0 ); - autoStyle.addProperty( "fo:font-family", font.family(), tt ); - autoStyle.addPropertyPt( "fo:font-size", font.pointSize(), tt ); - autoStyle.addProperty( "fo:color", color.isValid() ? color.name() : "#000000", tt ); - int w = font.weight(); - autoStyle.addProperty( "fo:font-weight", w == 50 ? "normal" : w == 75 ? "bold" : TQString::number( tqRound( w / 10 ) * 100 ), tt ); - autoStyle.addProperty( "fo:font-style", font.italic() ? "italic" : "normal", tt ); - - return mainStyles.lookup( autoStyle, "ch", KoGenStyles::ForceNumbering ); -} - - -} //KChart namespace - diff --git a/kchart/kchart_params.cpp b/kchart/kchart_params.cpp new file mode 100644 index 00000000..2cd8da51 --- /dev/null +++ b/kchart/kchart_params.cpp @@ -0,0 +1,1043 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002,2003,2004 Laurent Montel + Copyright (C) 2006 Thorsten Zachmann + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +//#include +#include +using std::cout; +using std::cerr; + + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "kdchart/KDChartParams.h" +#include "kdchart/KDChartAxisParams.h" + +#include "kchart_params.h" +#include "kchart_part.h" +#include "KChartParamsIface.h" + + +namespace KChart +{ + + +KChartParams::KChartParams( KChartPart *_part ) + : KDChartParams(), + m_part( _part ) +{ + // Default values for subtypes. + m_firstRowAsLabel = false; + m_firstColAsLabel = false; + + // Default values for OpenDocument extensions. + m_barNumLines = 0; + + m_dcop = 0; + //dcopObject(); // build it +} + + +KChartParams::~KChartParams() +{ + delete m_dcop; +} + + +// ---------------------------------------------------------------- + + +TQString KChartParams::chartTypeToString( ChartType _type) const +{ +#if 0 + if (_type == BarLines ) + return "BarLines"; + else +#endif + return KDChartParams::chartTypeToString( (KDChartParams::ChartType) _type ); +} + + +KChartParams::ChartType +KChartParams::stringToChartType( const TQString& _string ) +{ +#if 0 + if ( _string == "BarLines" ) + return BarLines; + else +#endif + return (ChartType) KDChartParams::stringToChartType( _string ); +} + + +void KChartParams::setFirstRowAsLabel( bool _val ) +{ + m_firstRowAsLabel = _val; + + // The rest of this method is only applicable if the data is from + // an external source, e.g. from kspread. + if ( m_part->canChangeValue() ) + return; + + m_part->doSetData( *m_part->data(), + m_firstRowAsLabel, m_firstColAsLabel ); +} + +void KChartParams::setFirstColAsLabel( bool _val ) +{ + m_firstColAsLabel = _val; + + // The rest of this method is only applicable if the data is from + // an external source, e.g. kspread. + if ( m_part->canChangeValue() ) + return; + + m_part->doSetData( *m_part->data(), + m_firstRowAsLabel, m_firstColAsLabel ); +} + + +DCOPObject* KChartParams::dcopObject() +{ + if ( !m_dcop ) + m_dcop = new KChartParamsIface( this ); + return m_dcop; +} + + +// ================================================================ +// Loading and Saving + + + +static const struct { + const char *oasisClass; + KChartParams::ChartType chartType; +} oasisChartTypes[] = { + { "chart:bar", KChartParams::Bar }, + { "chart:line", KChartParams::Line }, + { "chart:area", KChartParams::Area }, + { "chart:circle", KChartParams::Pie }, + //{ "chart:xxx", KChartParams::HiLo }, + //{ "chart:stock", KChartParams::??? }, + //{ "chart:add-in", KChartParams::??? }, + //{ "chart:scatter",KChartParams::??? }, + { "chart:ring", KChartParams::Ring }, + { "chart:radar", KChartParams::Polar } + //{ "chart:xxx", KChartParams::BoxWhisker }, + + //{ "chart:xxx", KChartParams::BarLines }, + // FIXME: More? +}; + + +static const unsigned int numOasisChartTypes + = sizeof oasisChartTypes / sizeof *oasisChartTypes; + + +#if 0 // Example code!! + KoOasisLoadingContext loadingContext( this, oasisStyles, store ); + KoStyleStack &styleStack = loadingContext.styleStack(); + + styleStack.save(); + styleStack.setTypeProperties( "graphic" ); // load graphic-properties + loadingContext.fillStyleStack( chartElem, KoXmlNS::chart, "style-name" ); + + const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, "fill-color" ); + kDebug() << "fillColor=" << fillColor << endl; + + styleStack.restore(); +#endif + + +// Load the data from an OpenDocument chart:chart element. + +void KChartParams::loadOasisFont( KoOasisLoadingContext& context, TQFont& font, TQColor& color ) +{ + KoStyleStack& styleStack = context.styleStack(); + styleStack.setTypeProperties( "text" ); // load all style attributes from "style:text-properties" + + if ( styleStack.hasAttributeNS( KoXmlNS::fo, "color" ) ) { // 3.10.3 + color.setNamedColor( styleStack.attributeNS( KoXmlNS::fo, "color" ) ); // #rrggbb format + } + if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-family" ) // 3.10.9 + || styleStack.hasAttributeNS( KoXmlNS::style, "font-name" ) ) { // 3.10.8 + // Hmm, the remove "'" could break it's in the middle of the fontname... + TQString fontName = styleStack.attributeNS( KoXmlNS::fo, "font-family" ).remove( "'" ); + if ( fontName.isEmpty() ) { + // ##### TODO. This is wrong. style:font-name refers to a font-decl entry. + // We have to look it up there, and retrieve _all_ font attributes from it, not just the name. + fontName = styleStack.attributeNS( KoXmlNS::style, "font-name" ).remove( "'" ); + } + // 'Thorndale' is not known outside OpenOffice so we substitute it + // with 'Times New Roman' that looks nearly the same. + if ( fontName == "Thorndale" ) + fontName = "Times New Roman"; + + fontName.remove( TQRegExp( "\\sCE$" ) ); // Arial CE -> Arial + font.setFamily( fontName ); + } + if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-size" ) ) { // 3.10.14 + double pointSize = styleStack.fontSize(); + font.setPointSizeFloat( pointSize ); + kdDebug(35001) << "font size: " << pointSize << endl; + } + if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-weight" ) ) { // 3.10.24 + TQString fontWeight = styleStack.attributeNS( KoXmlNS::fo, "font-weight" ); + int boldness; + if ( fontWeight == "normal" ) + boldness = 50; + else if ( fontWeight == "bold" ) + boldness = 75; + else + // XSL/CSS has 100,200,300...900. Not the same scale as TQt! + // See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight + boldness = fontWeight.toInt() / 10; + font.setWeight( boldness ); + } + if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-style" ) ) { // 3.10.19 + if ( styleStack.attributeNS( KoXmlNS::fo, "font-style" ) == "italic" || + styleStack.attributeNS( KoXmlNS::fo, "font-style" ) == "oblique" ) { // no difference in kotext + font.setItalic( true ); + } + } +} + +bool KChartParams::loadOasis( const TQDomElement &chartElem, + KoOasisLoadingContext &loadingContext, + TQString &errorMessage, + KoStore */*store*/ ) +{ + const TQString chartClass = chartElem.attributeNS( KoXmlNS::chart, + "class", TQString() ); + bool knownType = false; + + // Find out what KChart charttype the OASIS charttype corresponds to. + for ( unsigned int i = 0 ; i < numOasisChartTypes ; ++i ) { + if ( chartClass == oasisChartTypes[i].oasisClass ) { + kdDebug(35001) << "found chart of type " << chartClass << endl; + //cerr << "found chart of type " << chartClass.latin1() << "\n"; + + setChartType( oasisChartTypes[i].chartType ); + knownType = true; + break; + } + } + + // If we can't find out what charttype it is, we might as well end here. + if ( !knownType ) { + errorMessage = i18n( "Unknown chart type %1" ).arg( chartClass ); + kdDebug(35001) << errorMessage << endl; + return false; + } + + // Title TODO (more details, e.g. font, placement etc) + TQDomElement titleElem = KoDom::namedItemNS( chartElem, + KoXmlNS::chart, "title" ); + if ( !titleElem.isNull() ) { + loadingContext.styleStack().save(); + loadingContext.fillStyleStack( titleElem, KoXmlNS::chart, "style-name", "chart" ); + TQFont font; + TQColor color; + loadOasisFont( loadingContext, font, color ); + setHeaderFooterFont( KDChartParams::HdFtPosHeader, font, true, font.pointSize()*4 ); + setHeaderFooterColor( KDChartParams::HdFtPosHeader, color ); + loadingContext.styleStack().restore(); + + TQDomElement pElem = KoDom::namedItemNS( titleElem, + KoXmlNS::text, "p" ); + setHeader1Text( pElem.text() ); + } + + // Subtitle TODO (more details) + TQDomElement subtitleElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, + "subtitle" ); + if ( !subtitleElem.isNull() ) { + loadingContext.styleStack().save(); + loadingContext.fillStyleStack( subtitleElem, KoXmlNS::chart, "style-name", "chart" ); + TQFont font; + TQColor color; + loadOasisFont( loadingContext, font, color ); + setHeaderFooterFont( KDChartParams::HdFtPosHeader2, font, true, font.pointSize()*4 ); + setHeaderFooterColor( KDChartParams::HdFtPosHeader2, color ); + loadingContext.styleStack().restore(); + + TQDomElement pElem = KoDom::namedItemNS( subtitleElem, + KoXmlNS::text, "p" ); + setHeader2Text( pElem.text() ); + } + + // Footer TODO (more details) + TQDomElement footerElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, + "footer" ); + if ( !footerElem.isNull() ) { + loadingContext.styleStack().save(); + loadingContext.fillStyleStack( footerElem, KoXmlNS::chart, "style-name", "chart" ); + TQFont font; + TQColor color; + loadOasisFont( loadingContext, font, color ); + setHeaderFooterFont( KDChartParams::HdFtPosFooter, font, true, font.pointSize()*4 ); + setHeaderFooterColor( KDChartParams::HdFtPosFooter, color ); + loadingContext.styleStack().restore(); + + TQDomElement pElem = KoDom::namedItemNS( footerElem, + KoXmlNS::text, "p" ); + setFooterText( pElem.text() ); + } + + // TODO: Get legend settings + TQDomElement legendElem = KoDom::namedItemNS( chartElem, KoXmlNS::chart, + "legend" ); + if ( !legendElem.isNull() ) + { + loadingContext.styleStack().save(); + loadingContext.fillStyleStack( legendElem, KoXmlNS::chart, "style-name", "chart" ); + TQFont font; + TQColor color; + loadOasisFont( loadingContext, font, color ); + //tz I didn't find that Oasis support seperate font/colors for the title and the rest of the legent + setLegendFont( font, false ); + setLegendFontRelSize( font.pointSize()*4 ); + setLegendTitleFont( font, false); + setLegendTitleFontRelSize( font.pointSize()*4 ); + setLegendTextColor( color ); + setLegendTitleTextColor( color ); + loadingContext.styleStack().restore(); + TQString lp; + if ( legendElem.hasAttributeNS( KoXmlNS::chart, "legend-position" ) ) + { + lp = legendElem.attributeNS( KoXmlNS::chart, "legend-position", TQString() ); + } + TQString lalign; + if ( legendElem.hasAttributeNS( KoXmlNS::chart, "legend-align" ) ) + { + lalign = legendElem.attributeNS( KoXmlNS::chart, "legend-align", TQString() ); + } + + LegendPosition lpos = NoLegend; + int align = 1; + if ( lalign == "start" ) + { + align = 0; + } + else if ( lalign == "end" ) + { + align = 2; + } + + if ( lp == "start" ) + { + lpos = LegendLeft; + if ( align == 0 ) + lpos = LegendTopLeftLeft; + else if ( align == 2 ) + lpos = LegendBottomLeftLeft; + } + else if ( lp == "end" ) + { + lpos = LegendRight; + if ( align == 0 ) + lpos = LegendTopRightRight; + else if ( align == 2 ) + lpos = LegendBottomRightRight; + } + else if ( lp == "top" ) + { + lpos = LegendTop; + if ( align == 0 ) + lpos = LegendTopLeftTop; + else if ( align == 2 ) + lpos = LegendTopRightTop; + } + else if ( lp == "bottom" ) + { + lpos = LegendBottom; + if ( align == 0 ) + lpos = LegendBottomLeftBottom; + else if ( align == 2 ) + lpos = LegendBottomRightBottom; + } + else if ( lp == "top-start" ) + { + lpos = LegendTopLeft; + } + else if ( lp == "bottom-start" ) + { + lpos = LegendBottomLeft; + } + else if ( lp == "top-end" ) + { + lpos = LegendTopRight; + } + else if ( lp == "bottom-end" ) + { + lpos = LegendBottomRight; + } + + setLegendPosition( lpos ); + //bodyWriter->addAttribute( "koffice:title", legendTitleText() ); + if ( legendElem.hasAttributeNS( KoXmlNS::koffice, "title" ) ) + { + setLegendTitleText( legendElem.attributeNS( KoXmlNS::koffice, "title", TQString() ) ); + } + } + else + { + setLegendPosition( NoLegend ); + } + + // Get the plot-area. This is where the action is. + TQDomElement plotareaElem = KoDom::namedItemNS( chartElem, + KoXmlNS::chart, "plot-area" ); + if ( !plotareaElem.isNull() ) { + return loadOasisPlotarea( plotareaElem, loadingContext, errorMessage ); + } + + return false; +} + + +bool KChartParams::loadOasisPlotarea( const TQDomElement &plotareaElem, + KoOasisLoadingContext &loadingContext, + TQString &errorMessage ) +{ + TQString tmp; + + //cerr << ">>> ==========================================================\n"; + + // FIXME: attribute table:cell-range-address - the cells in a spreadsheet + + // Get whether there is a label on the first row or column of the data. + // This info is in the attribute chart:data-source-has-labels. + // + // NOTE: Only used in spreadsheets. + tmp = plotareaElem.attributeNS( KoXmlNS::chart, + "data-source-has-labels", TQString() ); + m_firstRowAsLabel = false; + m_firstColAsLabel = false; + if ( tmp == "none" || tmp == "" ) + ; // NOTHING + else if ( tmp == "row" ) + m_firstRowAsLabel = true; + else if ( tmp == "column" ) + m_firstColAsLabel = true; + else if ( tmp == "both" ) { + m_firstRowAsLabel = true; + m_firstColAsLabel = true; + } + else { + errorMessage = "Unknown value for chart:data-source-has-labels:" + + tmp; + return false; + } + + // ---------------------------------------------------------------- + // Now get the style and use it to get the contents. + // This is hidden in the attribute chart:style-name. + KoStyleStack &styleStack = loadingContext.styleStack(); + + + tmp = plotareaElem.attributeNS( KoXmlNS::chart, "style-name", + TQString() ); + //kdDebug(35001) << "Style name for the plot area: " << tmp << endl; + styleStack.save(); + styleStack.setTypeProperties( "chart" ); // load chart properties + loadingContext.fillStyleStack( plotareaElem, KoXmlNS::chart, "style-name", "chart" ); + + if ( styleStack.attributeNS( KoXmlNS::chart, "three-dimensional" ) == "true" ) { + setThreeDBars( true ); + setThreeDLines( true ); + setThreeDPies( true ); + } + else { + setThreeDBars( false ); + setThreeDLines( false ); + setThreeDPies( false ); + } + + switch ( m_chartType ) { + case NoType: + break; + + case Bar: + // Find out subtype + tmp = styleStack.attributeNS( KoXmlNS::chart, "vertical" ); + // FIXME:Qt::Vertical is ignored. At least store it so we can + // save it again even if we don't support it. + + //kdDebug(35001) << " ======> Qt::Vertical: " << tmp << " <======" << endl; + // Set the bar chart subtype. + if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) + setBarChartSubType( BarStacked ); + else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) + setBarChartSubType( BarPercent ); + else + setBarChartSubType( BarNormal ); + + break; + + // chart:vertical - true if vertical bars (only bar charts) + // chart:stacked - true for stacked bars + // chart:percentage - true for percentage (mut. excl with stacked) + // chart:connect-bars - true if lines to connect bars should be drawn + // only used for stacked and percentage bars. + // FIXME: Support lines on bar charts. + // chart:lines-used - 0-n, number of lines on a bar chart. (def: 0) + + case Line: + // Set the line chart subtype. + if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) + setLineChartSubType( LineStacked ); + else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) + setLineChartSubType( LinePercent ); + else + setLineChartSubType( LineNormal ); + + break; + + // FIXME: Why is this even there? Seems like an unnecessary attr. + // chart:lines - true for line charts, false otherwise + + // chart:stacked - true for stacked bars + // chart:percentage - true for percentage (mut. excl with stacked) + + // chart:symbol-type - used with line charts, should be "automatic" + + case Area: + // Set the area chart subtype. + if ( styleStack.attributeNS( KoXmlNS::chart, "stacked" ) == "true" ) + setAreaChartSubType( AreaStacked ); + else if ( styleStack.attributeNS( KoXmlNS::chart, "percentage" ) == "true" ) + setAreaChartSubType( AreaPercent ); + else + setAreaChartSubType( AreaNormal ); + + break; + + // chart:stacked - true for stacked bars + // chart:percentage - true for percentage (mut. excl with stacked) + + case Pie: + break; + + case HiLo: + break; + + case Ring: + break; + + case Polar: + break; + + case BoxWhisker: + break; + } + // TODO: + // And get the info from the style. Here is the contents: + + + // TODO: These items are currently not used. They should be at least + // be stored so that we can save them again. + // chart:interpolation - "cubic-spline" if using cubic splines + // chart:splines - + // chart:spline-order - "2" for cubic splines + // chart:spline-resolution - how smooth (default: 20) + + // -- Used when chart:class == "stock: + // chart:stock-updown-bars - boolean + // chart:stock-with-volume - boolean + // chart:japanese-candle-sticks - boolean + + // chart:series-source - "rows" or "columns" + // "columns" is the default + if ( styleStack.attributeNS( KoXmlNS::chart, "series-source" ) == "rows" ) { + setDataDirection( DataRows ); + } + + // chart:data-label-number - "value" / "percentage" / "none" (def: none) + + // chart:data-label-text - true if data hapoints have text labels + // chart:data-label-symbol - true if data hapoints have legend symbol + // (default: false for both) + + styleStack.restore(); + + // ---------------------------------------------------------------- + // In the plot-area element there are two chart:axis elements + + TQDomElement xAxisElem; + TQDomElement yAxisElem; + + TQDomElement axisElem; + forEachElement( axisElem, plotareaElem ) { + + // If this element is not an axis, then continue + if ( axisElem.tagName() != "axis" ) + continue; + + tmp = axisElem.attributeNS( KoXmlNS::chart, "name", + TQString()); + //kdDebug(35001) << "Got axis " << tmp << endl; + //cerr << "Got axis " << tmp.latin1() << "\n"; + if ( tmp == "primary-x" ) + xAxisElem = axisElem; + else if ( tmp == "primary-y" ) + yAxisElem = axisElem; + else + // Only supports two axes so far. + continue; + } + + // Load the axes. Pie charts use only the y axis. + if ( m_chartType != Pie + && !loadOasisAxis( xAxisElem, loadingContext, errorMessage, + KDChartAxisParams::AxisPosBottom) ) + return false; + if ( !loadOasisAxis( yAxisElem, loadingContext, errorMessage, + KDChartAxisParams::AxisPosLeft) ) + return false; + + // Attributes for the axes: + // chart:name - either "primary-x" or "primary-y" + +#if 0 + const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, + "fill-color" ); + kdDebug() << "fillColor=" << fillColor << endl; +#endif + + //cerr << "<<< ==========================================================\n"; + + return true; +} + + +bool KChartParams::loadOasisAxis( const TQDomElement &axisElem, + KoOasisLoadingContext &loadingContext, + TQString &errorMessage, + KDChartAxisParams::AxisPos axisPos ) +{ + Q_UNUSED( errorMessage ); + + TQString tmp; + TQDomElement tmpElem; + KoStyleStack &styleStack = loadingContext.styleStack(); + + // Get the axis to manipulate. + // TODO + + // Get the axis title (== axis label) if any. + TQDomElement titleElem = KoDom::namedItemNS( axisElem, + KoXmlNS::chart, "title" ); + if ( !titleElem.isNull() ) { + tmpElem = KoDom::namedItemNS( titleElem, KoXmlNS::text, "p" ); + setAxisTitle( axisPos, tmpElem.text() ); + } + + + + //cerr << ">>> ----------------------------------------------------------\n"; + //cerr << "Loading axis " << axisElem.attributeNS( KoXmlNS::chart, "name", + // TQString()).latin1() + // << "\n"; + + tmp = axisElem.attributeNS( KoXmlNS::chart, "style-name", TQString() ); + //kdDebug(35001) << "Style name for the axis: " << tmp << endl; + //cerr << "Style name for the axis: " << tmp.latin1() << "\n"; + styleStack.save(); + styleStack.setTypeProperties( "chart" ); // load chart properties + loadingContext.fillStyleStack( axisElem, KoXmlNS::chart, "style-name", "chart" ); + + // chart:class - "category" / "value" / "domain" (domain for scatter) + // child: chart:categories + + // child: chart:title - Name of title if any. + // child: chart:grid + // attr: chart:class - "major" / "minor" + + // chart:style-name - Associated style with the following info: + // -------------------------------- + // chart:display-label - true if an axis label should be shown. + + // chart:tick-marks-major-inner - true if display tickmarks at major + // chart:tick-marks-major-outer or minor intervals outside / inside + // chart:tick-minor-major-inner the chart area. + // chart:tick-minor-major-outer + + // chart:logarithmic - true if logarithmic scale + + // text:line-break - true if categories can be broken + + // chart:text-overlap - true if labels can overlap + + // chart:label-arrangement - "side-by-side" / "stagger-even" / + // "stagger-odd" (def: side-by-side) + + // chart:visible - true if labels + ticks should be shown. + + // children: + // chart: + // chart: + // chart: + // chart: + // chart: + styleStack.restore(); + + //cerr << "<<< ----------------------------------------------------------\n"; + return true; +} + + +// ---------------------------------------------------------------- + + +void KChartParams::saveOasis( KoXmlWriter* bodyWriter, KoGenStyles& mainStyles ) const +{ + bool knownType = false; + for ( unsigned int i = 0 ; i < numOasisChartTypes ; ++i ) { + if ( m_chartType == oasisChartTypes[i].chartType ) { + bodyWriter->addAttribute( "chart:class", oasisChartTypes[i].oasisClass ); + knownType = true; + break; + } + } + + if ( !knownType ) { + kdError(32001) << "Unknown chart type in KChartParams::saveOasis, extend oasisChartTypes!" << endl; + } + + bodyWriter->startElement( "chart:title" ); + TQRect rect( headerFooterRect( KDChartParams::HdFtPosHeader ) ); + bodyWriter->addAttributePt( "svg:x", rect.x() ); + bodyWriter->addAttributePt( "svg:y", rect.y() ); + bodyWriter->addAttribute( "chart:style-name", saveOasisFont( mainStyles, header1Font(), headerFooterColor( KDChartParams::HdFtPosHeader ) ) ); + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( header1Text() ); + bodyWriter->endElement(); // text:p + bodyWriter->endElement(); // chart:title + + TQString subTitle( header2Text() ); + if ( !subTitle.isEmpty() ) { + + kdDebug(32001) << "header rect: " << headerFooterRect( KDChartParams::HdFtPosHeader2 ) << endl; + TQRect rect( headerFooterRect( KDChartParams::HdFtPosHeader2 ) ); + bodyWriter->startElement( "chart:subtitle" ); + bodyWriter->addAttributePt( "svg:x", rect.x() ); + bodyWriter->addAttributePt( "svg:y", rect.y() ); + bodyWriter->addAttribute( "chart:style-name", + saveOasisFont( mainStyles, + header2Font(), + headerFooterColor( KDChartParams::HdFtPosHeader2 ) ) ); + + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( subTitle ); + bodyWriter->endElement(); // text:p + bodyWriter->endElement(); // chart:subtitle + } + + + TQString footer( footerText() ); + if ( !footer.isEmpty() ) { + TQRect rect( headerFooterRect( KDChartParams::HdFtPosFooter ) ); + bodyWriter->startElement( "chart:footer" ); + bodyWriter->addAttributePt( "svg:x", rect.x() ); + bodyWriter->addAttributePt( "svg:y", rect.y() ); + bodyWriter->addAttribute( "chart:style-name", + saveOasisFont( mainStyles, + footerFont(), + headerFooterColor( KDChartParams::HdFtPosFooter ) ) ); + + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( footer ); + bodyWriter->endElement(); // text:p + bodyWriter->endElement(); // chart:footer + } + + // TODO legend + LegendPosition lpos = legendPosition(); + if ( lpos != NoLegend ) { + bodyWriter->startElement( "chart:legend" ); + TQString lp; + TQString lalign; + switch ( lpos ) { + case LegendTop: + lp = "top"; + lalign = "center"; + break; + case LegendBottom: + lp = "bottom"; + lalign = "center"; + break; + case LegendLeft: + lp = "start"; + lalign = "center"; + break; + case LegendRight: + lp = "end"; + lalign = "center"; + break; + case LegendTopLeft: + lp = "top-start"; + break; + case LegendTopLeftTop: + lp = "top"; + lalign = "start"; + break; + case LegendTopLeftLeft: + lp = "start"; + lalign = "start"; + break; + case LegendTopRight: + lp = "top-end"; + break; + case LegendTopRightTop: + lp = "top"; + lalign = "end"; + break; + case LegendTopRightRight: + lp = "end"; + lalign = "start"; + break; + case LegendBottomLeft: + lp = "bottom-start"; + break; + case LegendBottomLeftBottom: + lp = "bottom"; + lalign = "start"; + break; + case LegendBottomLeftLeft: + lp = "start"; + lalign = "end"; + break; + case LegendBottomRight: + lp = "bottom-end"; + break; + case LegendBottomRightBottom: + lp = "bottom"; + lalign = "end"; + break; + case LegendBottomRightRight: + lp = "end"; + lalign = "end"; + break; + default: + lp = "end"; + lalign = "center"; + break; + } + + bodyWriter->addAttribute( "chart:legend-position", lp ); + bodyWriter->addAttribute( "chart:legend-align", lalign ); + bodyWriter->addAttribute( "chart:style-name", + saveOasisFont( mainStyles, + legendFont(), + legendTextColor() ) ); + bodyWriter->addAttribute( "koffice:title", legendTitleText() ); + bodyWriter->endElement(); // chart:legend + } + + bodyWriter->startElement( "chart:plot-area" ); + saveOasisPlotArea( bodyWriter, mainStyles ); + bodyWriter->endElement(); + + // TODO... +} + + +void KChartParams::saveOasisPlotArea( KoXmlWriter* bodyWriter, KoGenStyles& mainStyles ) const +{ + TQString dataSourceHasLabels; + if ( m_firstRowAsLabel ) + if ( m_firstColAsLabel ) + dataSourceHasLabels = "both"; + else + dataSourceHasLabels = "row"; + else + if ( m_firstColAsLabel ) + dataSourceHasLabels = "column"; + else + dataSourceHasLabels = "none"; + bodyWriter->addAttribute( "chart:data-source-has-labels", dataSourceHasLabels ); + + // Prepare the style for the plot area + KoGenStyle plotAreaStyle( KoGenStyle::STYLE_AUTO, "chart" ); + + switch ( m_chartType ) { + case NoType: + break; + + case Bar: + switch( barChartSubType() ) { + case BarStacked: + plotAreaStyle.addProperty( "chart:stacked", "true" ); + break; + case BarPercent: + plotAreaStyle.addProperty( "chart:percentage", "true" ); + break; + case BarNormal: + break; + case BarMultiRows: + break; + } + plotAreaStyle.addProperty( "chart:vertical", "false" ); // #### always? + plotAreaStyle.addProperty( "chart:lines-used", 0 ); // FIXME: for now + + if ( threeDBars() ) + plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); + + case Line: + switch( lineChartSubType() ) { + case LineStacked: + plotAreaStyle.addProperty( "chart:stacked", "true" ); + break; + case LinePercent: + plotAreaStyle.addProperty( "chart:percentage", "true" ); + break; + case LineNormal: + break; + } + plotAreaStyle.addProperty( "chart:symbol-type", "automatic" ); + + if ( threeDLines() ) + plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); + + break; + + case Area: + switch( areaChartSubType() ) { + case AreaStacked: + plotAreaStyle.addProperty( "chart:stacked", "true" ); + break; + case AreaPercent: + plotAreaStyle.addProperty( "chart:percentage", "true" ); + break; + case AreaNormal: + break; + } + //plotAreaStyle.addProperty( "chart:lines-used", 0 ); // #### for now + + // TODO - very similar + + case Pie: + if ( threeDPies() ) + plotAreaStyle.addProperty( "chart:three-dimensional", "true" ); + + break; + + case HiLo: + break; + + case Ring: + break; + + case Polar: + break; + + case BoxWhisker: + break; + } + + // chart:series-source + plotAreaStyle.addProperty( "chart:series-source", + ( dataDirection() == DataRows ) ? "rows" : "columns" ); + + // Register the style, and get back its auto-generated name + const TQString styleName = mainStyles.lookup( plotAreaStyle, "ch" ); + + bodyWriter->addAttribute( "chart:style-name", styleName ); + + saveOasisAxis( bodyWriter, mainStyles, KDChartAxisParams::AxisPosBottom, "x" ); + saveOasisAxis( bodyWriter, mainStyles, KDChartAxisParams::AxisPosLeft, "y" ); + + // TODO chart:series + // TODO chart:wall + // TODO chart:floor +} + + +void KChartParams::saveOasisAxis( KoXmlWriter* bodyWriter, + KoGenStyles& mainStyles, + KDChartAxisParams::AxisPos axisPos, + const char* axisName ) const +{ + bodyWriter->startElement( "chart:axis" ); + + bodyWriter->addAttribute( "chart:dimension", axisName ); + bodyWriter->addAttribute( "chart:name", TQCString( "primary-" ) + axisName ); + + KoGenStyle axisStyle( KoGenStyle::STYLE_AUTO, "chart" ); + + // TODO: Save axis style properties, like + axisStyle.addProperty( "chart:display-label", "true" ); // ### + + + const TQString styleName = mainStyles.lookup( axisStyle, "ch" ); + bodyWriter->addAttribute( "chart:style-name", styleName ); + + // Write axis titles if any. + TQString tmpStr = axisTitle( axisPos ); + if ( tmpStr != "" ) { + bodyWriter->startElement( "chart:title" ); + // TODO: Save style, svg:x, svg:y + + // Write the text in the axis title. + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( tmpStr + .remove( TQRegExp( "^
" ) ) + .remove( TQRegExp( "
$" ) ) ); + bodyWriter->endElement(); // text:p + + bodyWriter->endElement(); // chart:title + } + + // TODO x axis has chart:categories, y axis has chart:grid ? + // Maybe that part should be done by the caller of saveOasisAxis then + // including the opening/closing of the chart:axis element... + + bodyWriter->endElement(); // chart:axis +} + + +TQString KChartParams::saveOasisFont( KoGenStyles& mainStyles, const TQFont& font, const TQColor& color ) const +{ + KoGenStyle::PropertyType tt = KoGenStyle::TextType; + KoGenStyle autoStyle( KoGenStyle::STYLE_AUTO, "chart", 0 ); + autoStyle.addProperty( "fo:font-family", font.family(), tt ); + autoStyle.addPropertyPt( "fo:font-size", font.pointSize(), tt ); + autoStyle.addProperty( "fo:color", color.isValid() ? color.name() : "#000000", tt ); + int w = font.weight(); + autoStyle.addProperty( "fo:font-weight", w == 50 ? "normal" : w == 75 ? "bold" : TQString::number( tqRound( w / 10 ) * 100 ), tt ); + autoStyle.addProperty( "fo:font-style", font.italic() ? "italic" : "normal", tt ); + + return mainStyles.lookup( autoStyle, "ch", KoGenStyles::ForceNumbering ); +} + + +} //KChart namespace + diff --git a/kchart/kchart_part.cc b/kchart/kchart_part.cc deleted file mode 100644 index fb6a6414..00000000 --- a/kchart/kchart_part.cc +++ /dev/null @@ -1,2306 +0,0 @@ -/** - * - * Kalle Dalheimer - */ - -#include // For basic data types characteristics. - -// For debugging -#include -using std::cout; -using std::cerr; - -#include "kchart_part.h" -#include "kchart_view.h" -#include "kchart_factory.h" -#include "kchartWizard.h" -#include "kchart_params.h" -#include "kdchart/KDChart.h" -#include "kdchart/KDChartTable.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -using namespace std; - -// Some hardcoded data for a chart - -/* ----- set some data ----- */ -// float a[6] = { 0.5, 0.09, 0.6, 0.85, 0.0, 0.90 }, -// b[6] = { 1.9, 1.3, 0.6, 0.75, 0.1, -2.0 }; -/* ----- X labels ----- */ -// char *t[6] = { "Chicago", "New York", "L.A.", "Atlanta", "Paris, MD\n(USA) ", "London" }; -/* ----- data set colors (RGB) ----- */ -// TQColor sc[2] = { TQColor( 255, 128, 128 ), TQColor( 128, 128, 255 ) }; - - -namespace KChart -{ - -KChartPart::KChartPart( TQWidget *parentWidget, const char *widgetName, - TQObject* parent, const char* name, - bool singleViewMode ) - : KoChart::Part( parentWidget, widgetName, parent, name, singleViewMode ), - m_params( 0 ), - m_parentWidget( parentWidget ), - m_rowLabels(), m_colLabels() -{ - kdDebug(35001) << "Constructor started!" << endl; - - setInstance( KChartFactory::global(), false ); - setTemplateType( "kchart_template" ); - - // Init some members that need it. - { - // Create the chart parameters and let the default be a bar chart - // with 3D looks. - m_params = new KChartParams( this ); - m_params->setChartType( KChartParams::Bar ); - m_params->setBarChartSubType( KChartParams::BarNormal ); - m_params->setThreeDBars( true ); - - //Changed this to use columns rather than rows by default - //because I believe that this is the more common format for - //entering data (you can see this looking at the fact that - //most spreadsheet packages allow far more rows than columns) - //-- Robert Knight - - // Handle data in columns by default - m_params->setDataDirection( KChartParams::DataColumns ); - } - - (void)new WizardExt( this ); - m_bCanChangeValue = true; - - // Display parameters - m_displayData = m_currentData; - - // Set the size to minimal. - initEmpty(); -} - - -KChartPart::~KChartPart() -{ - //kdDebug(35001) << "Part is going to be destroyed now!!!" << endl; - delete m_params; -} - - -// Reimplement KoDocument::initDoc() - -bool KChartPart::initDoc(InitDocFlags flags, TQWidget* parentWidget) -{ - // Initialize the parameter set for this chart document -#if 0 - kdDebug(35001) << "================================================================" << endl; - kdDebug(35001) << "InitDOC: flags = " << flags << endl; - kdDebug(35001) << "================================================================" << endl; -#endif - - TQString f; - - // Embedded documents are initially created like a normal empty - // document. If this is in KSpread or another program where the - // data is external then the document will be updated later on in - // the creation process anyway. - if (flags == KoDocument::InitDocEmbedded) { - initEmpty(); - return true; - } - - // If we are supposed to create a new, empty document, then do so. - if (flags == KoDocument::InitDocEmpty) { - initEmpty(); - return true; - } - - KoTemplateChooseDia::ReturnType ret; - KoTemplateChooseDia::DialogType dlgtype; - - // If we must create a new document, then only present templates - // to the user, otherwise also present existing documents and - // recent documents. - if (flags == KoDocument::InitDocFileNew ) - dlgtype = KoTemplateChooseDia::OnlyTemplates; - else - dlgtype = KoTemplateChooseDia::Everything; - ret = KoTemplateChooseDia::choose( KChartFactory::global(), f, - dlgtype, "kchart_template", - parentWidget ); - - if ( ret == KoTemplateChooseDia::File ) { - KURL url( f ); - return openURL( url ); - } - else if ( ret == KoTemplateChooseDia::Empty ) { - initEmpty(); - return true; - } - else if ( ret == KoTemplateChooseDia::Template ) { - //TODO: Activate this for KOffice 1.5/2.0 -// if ( f.endsWith("/templates/chart/.source/BarChart.chrt") ) { -// generateBarChartTemplate(); -// return true; -// } - TQFileInfo fileInfo( f ); - TQString fileName( fileInfo.dirPath( true ) + "/" + - fileInfo.baseName() + ".chrt" ); - - resetURL(); - bool ok = loadNativeFormat( fileName ); - if ( !ok ) - showLoadingErrorDialog(); - setEmpty(); - //initConfig(); - return ok; - } - - return false; -} - -void KChartPart::initEmpty() -{ - initNullChart(); - - resetURL(); - setEmpty(); -} - - -// This method creates the simplest chart imaginable: -// Data size 1x1, empty, no headers -// -void KChartPart::initNullChart() -{ - // Fill cells with data if there is none. - //kdDebug(35001) << "Initialize null chart." << endl; - - // Empty data. Note, we don't use (0,0) or (1,1) for the size - // here, because otherwise KDChart won't draw anything - m_currentData.expand(2, 2); - m_params->setFirstRowAsLabel(false); - m_params->setFirstColAsLabel(false); - - // Fill column and row labels. - m_colLabels << TQString(""); - m_rowLabels << TQString(""); - - setChartDefaults(); - - m_params->setDrawSolidExcessArrows(true); -} - - -void KChartPart::generateBarChartTemplate() -{ - int col; - int row; - - kdDebug()<<"KChartPart::initTestChart()\n"; - - // Fill cells with data if there is none. - if (m_currentData.rows() == 0) { - //kdDebug(35001) << "Initialize with some data!!!" << endl; - m_currentData.expand( 4, 4 ); - m_currentData.setUsedRows( 4 ); - m_currentData.setUsedCols( 4 ); - for (row = 0; row < 4; row++) { - for (col = 0; col < 4; col++) { - m_currentData.setCell(row, col, - static_cast (row + col)); - - // Fill column label, but only on the first iteration. - if (row == 0) { - m_colLabels << i18n("Column %1").arg(col + 1); - } - } - - // Fill row label. - m_rowLabels << i18n("Row %1").arg(row + 1); - } - } - - setChartDefaults(); - // FIXME: Should this go into setChartDefaults()? - m_params->setDrawSolidExcessArrows(true); -} - - -KoView* KChartPart::createViewInstance( TQWidget* parent, const char* name ) -{ - return new KChartView( this, parent, name ); -} - - -// ================================================================ -// Painting - - -void KChartPart::paintContent( TQPainter& painter, const TQRect& rect, - bool /*transparent*/, - double /*zoomX*/, double /*zoomY*/ ) -{ - int numDatasets; - - // If params is 0, initDoc() has not been called. - Q_ASSERT( m_params != 0 ); - - KDChartAxisParams xAxisParms; - xAxisParms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - // Handle data in rows or columns. - // - // This means getting row or column headers from the document and - // set them as X axis labels or legend according to the current - // setting. Also, transpose the data if it should be displayed in - // columns instead of in rows. - - - // Create the displayData table. - numDatasets = createDisplayData(); - - // Create and set the axis labels and legend. - TQStringList longLabels; - TQStringList shortLabels; - createLabelsAndLegend(longLabels, shortLabels); - - // Set the x axis labels. - xAxisParms.setAxisLabelStringLists( &longLabels, &shortLabels ); - m_params->setAxisParams(KDChartAxisParams::AxisPosBottom, xAxisParms); - - - // Handle some types or subtypes of charts specially, notably: - // - Bar charts with lines in them - - if ( m_params->chartType() == KChartParams::Bar) { - if ( m_params->barNumLines() > 0 ) { - - // If this is a bar chart and the user wants a few lines in - // it, we need to create an additional chart in the same - // drawing area. - - // Specify that we want to have an additional chart. - m_params->setAdditionalChartType( KDChartParams::Line ); - - const int numBarDatasets = numDatasets - m_params->barNumLines(); - - // Assign the datasets to the charts: DataEntry, from, to, chart# - m_params->setChartSourceMode( KDChartParams::DataEntry, - 0, numBarDatasets - 1, - 0 ); // The bar chart - m_params->setChartSourceMode( KDChartParams::DataEntry, - numBarDatasets, numDatasets - 1, - 1 ); // The line chart - } - else { - // Otherwise we don't want any extra chart. - m_params->setAdditionalChartType( KDChartParams::NoType ); - } - } - - // Ok, we have now created a data set for display, and params with - // suitable legends and axis labels. Now start the real painting. - - // Handle transparency. - // Wrong: this flickers; better do this as part of the double-buffering. - //if ( !transparent ) - // painter.eraseRect( rect ); - - // ## TODO: support zooming - - // Double-buffering - if ( m_bufferPixmap.width() < rect.width() - || m_bufferPixmap.height() < rect.height() ) - { - m_bufferPixmap.resize( rect.size() ); - } - - TQPainter bufferPainter( &m_bufferPixmap ); - - // We only need to draw the document rectangle "rect". - KDChart::paint( &bufferPainter, m_params, &m_displayData, 0, &rect ); - - // This is always the empty rect... - // Shouldn't creating a TQPainter in a paintEvent set up clipping automatically? - // I thought it did (DF) - //const TQRect clipRect = painter.clipRegion().boundingRect(); - //painter.drawPixmap( clipRect.topLeft(), m_bufferPixmap, clipRect ); - - painter.drawPixmap( 0, 0, m_bufferPixmap ); -} - - -// Create the data table m_displayData from m_currentData, taking into -// account if the first row or line contains headers. The chart type -// HiLo demands special handling. -// -// Return number of datasets. -// -// Note: While the current KD Chart 1.1.3 version is still expecting data -// to be in rows, the upcoming KD Chart 2.0 release will be using -// data in columns instead, to it will be matching KSpread's way. -// -khz, 2005-11-15 -// -// FIXME: Rewrite so that we only copy data when necessary. -// On the other hand, the next version of KDChart is able to -// get data directly without storing it into a KDChartData -// class first, so we might never need to. -// -int KChartPart::createDisplayData() -{ - int rowOffset = 0; - int colOffset = 0; - int numDatasets = 0; - - if ( !canChangeValue() ) { - if ( m_params->firstRowAsLabel() ) - rowOffset++; - if ( m_params->firstColAsLabel() ) - colOffset++; - } - - // After this sequence, m_DisplayData contains the data in the - // correct transposition, and the X axis and the legend contain - // the correct labels. - TQVariant value1; - TQVariant value2; - int prop; - if (m_params->dataDirection() == KChartParams::DataRows) { - // Data is handled in rows. This is the way KDChart works also. - - numDatasets = m_currentData.usedRows() - rowOffset; - m_displayData.expand( numDatasets, - m_currentData.usedCols() - colOffset ); - - // Remove the first row and/or col if they are used for headers. - for (uint row = rowOffset; row < m_currentData.usedRows(); row++) { - for (uint col = colOffset; col < m_currentData.usedCols(); col++) { - if ( m_currentData.cellContent( row, col, - value1, value2, prop ) ) { - m_displayData.setCell(row - rowOffset, col - colOffset, - value1, value2); - m_displayData.setProp(row - rowOffset, col - colOffset, - prop); - } - } - } - } - else { - // Data is handled in columns. We will have to transpose - // everything since KDChart wants its data in rows. - - // Resize displayData so that the transposed data has room. - numDatasets = m_currentData.usedCols() - colOffset; - m_displayData.expand( numDatasets, - m_currentData.usedRows() - rowOffset ); - - // Copy data and transpose it. - for (uint row = colOffset; row < m_currentData.usedCols(); row++) { - for (uint col = rowOffset; col < m_currentData.usedRows(); col++) { - if ( m_currentData.cellContent( col, row, - value1, value2, prop ) ) { - m_displayData.setCell(row - colOffset, col - rowOffset, - value1, value2); - m_displayData.setProp(row - colOffset, col - rowOffset, - prop); - } - } - } - } - - // If this is a HiLo chart, we need to manually create the correct - // values. This is not done by KDChart. - // - // Here we don't need to transpose, since we can start from the - // newly generated displayData. - if (m_params->chartType() == KChartParams::HiLo) { - KDChartTableData tmpData = m_displayData; - - // Calculate the min, max, open and close values for each row. - m_displayData.expand(tmpData.usedRows(), 4); - for (uint row = 0; row < tmpData.usedRows(); row++) { - double minVal = DBL_MAX; - double maxVal = -DBL_MAX; - - // Calculate min and max for this row. - // - // Note that we have already taken care of different data - // directions above. - for (uint col = 0; col < tmpData.usedCols(); col++) { - double data = tmpData.cellVal(row, col).toDouble(); - - if (data < minVal) - minVal = data; - if (data > maxVal) - maxVal = data; - } - m_displayData.setCell(row, 0, minVal); // min - m_displayData.setCell(row, 1, maxVal); // max - m_displayData.setCell(row, 2, tmpData.cellVal(row, 0).toDouble()); // open - m_displayData.setCell(row, 3, // close - tmpData.cellVal(row, tmpData.usedCols() - 1).toDouble()); - } - } - - return numDatasets; -} - - -void KChartPart::createLabelsAndLegend( TQStringList &longLabels, - TQStringList &shortLabels ) -{ - longLabels.clear(); - shortLabels.clear(); - - const uint dataColumnCount = m_currentData.cols(); - const uint dataRowCount = m_currentData.rows(); - const uint columnLabelCount = m_colLabels.count(); - const uint rowLabelCount = m_rowLabels.count(); - - // Handle HiLo charts separately. - if (m_params->chartType() == KChartParams::HiLo) { - - // FIXME: In a HiLo chart, the Legend should be the same as the - // labels on the X Axis. Should we disable one of them? - - // Set the correct X axis labels and legend. - longLabels.clear(); - shortLabels.clear(); - if (m_params->dataDirection() == KChartParams::DataRows) { - - // If data are in rows, then the X axis labels should be - // taken from the row headers. - for ( uint row = 0; row < dataRowCount ; row++ ) { - - TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); - - longLabels << label; - shortLabels << label.left( 3 ); - } - } - else { - // If data are in columns, then the X axis labels should - // be taken from the column headers. - for ( uint col = 0; col < dataColumnCount; col++ ) { - - TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); - - longLabels << m_colLabels[col]; - shortLabels << m_colLabels[col].left( 3 ); - } - } - } - else if (m_params->dataDirection() == KChartParams::DataRows) { - // Data is handled in rows. This is the way KDChart works also. - - // Set X axis labels from column headers. - for ( uint col = 0; col < dataColumnCount; col++ ) { - - TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); - - longLabels << label; - shortLabels << label.left( 3 ); - } - - // Set legend from row headers. - for ( uint row = 0; row < dataRowCount; row++ ) { - TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); - - m_params->setLegendText( row, label ); - } - } - else { - // Data is handled in columns. - - // Set X axis labels from row headers. - for ( uint row = 0; row < dataRowCount; row++ ) { - - TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); - - longLabels << label; - shortLabels << label.left( 3 ); - } - - // Set legend from column headers. - for ( uint col = 0; col < dataColumnCount ; col++ ) { - TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); - - m_params->setLegendText( col, label ); - } - } -} - - - -// ================================================================ - - -void KChartPart::analyzeHeaders() -{ -#if 0 - analyzeHeaders( m_currentData ); -#else - doSetData( m_currentData, - m_params->firstRowAsLabel(), m_params->firstColAsLabel()); -#endif -} - - -// This function sets the data from an external source. It is called, -// for instance, when the chart is initialized from a spreadsheet in -// KSpread. -// -void KChartPart::analyzeHeaders( const KDChartTableData& data ) -{ - // FIXME(khz): replace this when automatic string detection works in KDChart - // Does the top/left cell contain a string? - bool isStringTopLeft = (data.cellVal( 0, 0 ).type() == TQVariant::String); - - // Does the first row (without first cell) contain only strings? - bool isStringFirstRow = true; - for ( uint col = 1; isStringFirstRow && col < data.cols(); col++ ) { - isStringFirstRow = (data.cellVal( 0, col ).type() == TQVariant::String); - } - - // Just in case, we only have 1 row, we never use it for label text. - // This prevents a crash. - // - // FIXME: Wonder if this is still true for KDChart 1.1.3 / iw - // Disabling... -#if 1 - if ( data.rows() == 1 ) - isStringFirstRow = false; -#endif - - // Does the first column (without first cell) contain only strings? - bool isStringFirstCol = true; - for ( uint row = 1; isStringFirstCol && row < data.rows(); row++ ) { - isStringFirstCol = (data.cellVal( row, 0 ).type() == TQVariant::String); - } - - // Just in case, we only have 1 column, we never use it for axis - // label text => prevents crash. -#if 1 - if ( data.cols() == 1 ) - isStringFirstRow = FALSE; -#endif - - bool hasColHeader = false; - bool hasRowHeader = false; - - // Let's check if we have a full axis label text column - if ( isStringFirstCol && isStringTopLeft - || isStringFirstCol && isStringFirstRow ) - hasColHeader = true; - - // Let's check if we have a full label text row. - if ( isStringFirstRow && isStringTopLeft - || isStringFirstCol && isStringFirstRow ) - hasRowHeader = true; - - m_params->setFirstRowAsLabel( hasRowHeader ); - m_params->setFirstColAsLabel( hasColHeader ); - - doSetData(data, hasRowHeader, hasColHeader); -} - - - -void KChartPart::doSetData( const KDChartTableData& data, - bool firstRowHeader, - bool firstColHeader ) -{ - uint rowStart = 0; - uint colStart = 0; - uint col; - uint row; - - // From this point, we know that the labels and legend are going - // to be taken from the data if firstRowHeader or firstColheader - // is true. - - if (firstRowHeader) - rowStart = 1; - if (firstColHeader) - colStart = 1; - - // Generate m_rowlabels from the column headers if applicable. - m_rowLabels.clear(); - if ( firstColHeader ) { - for( row = rowStart; row < data.rows(); row++ ) { - m_rowLabels << data.cellVal( row, 0 ).toString(); - } - } - else { - for( row = rowStart; row < data.rows(); row++ ) - m_rowLabels << ""; - - // FIXME: Check what this does, and if we don't have to check - // the data order (rows / cols). - m_params->setLegendSource( KDChartParams::LegendAutomatic ); - } - - // Generate X labels from the row headers if applicable - m_colLabels.clear(); - if ( firstRowHeader ) { - for( col = colStart; col < data.cols(); col++ ) { - m_colLabels << data.cellVal( 0, col ).toString(); - } - } - else { - for( col = colStart; col < data.cols(); col++ ) - m_colLabels << ""; - } - - // Doesn't hurt if data == m_currentData, but necessary if not. - m_currentData = data; - - //setChartDefaults(); - - emit docChanged(); -} - - -void KChartPart::resizeData( int rows, int cols ) -{ - m_currentData.expand( rows, cols ); - m_currentData.setUsedRows( rows ); - m_currentData.setUsedCols( cols ); -} - - -void KChartPart::setCellData( int row, int column, const TQVariant &val) -{ - m_currentData.setCell( row, column, val ); -} - - -bool KChartPart::showWizard( TQString &dataArea ) -{ - KChartWizard *wizard = new KChartWizard( this, m_parentWidget, "wizard" ); - - connect( wizard, TQT_SIGNAL(finished()), this, TQT_SLOT(slotModified()) ); - - wizard->setDataArea( dataArea ); - - bool ret = wizard->exec(); - - delete wizard; - return ret; -} - - -void KChartPart::initLabelAndLegend() -{ - // Labels and legends are automatically initialized to reasonable - // default values in KDChart -} - - -// Set up some values for the chart Axis, that are not well chosen by -// default by KDChart. -// - -void KChartPart::setChartDefaults() -{ - // - // Settings for the Y axis. - // - KDChartAxisParams yAxis; - yAxis = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - - // decimal symbol and thousands separator - yAxis.setAxisLabelsRadix( TDEGlobal::locale()->decimalSymbol(), - TDEGlobal::locale()->thousandsSeparator() ); - - m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, yAxis ); - - // - // Settings for the X axis. - // - KDChartAxisParams xAxis; - xAxis = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - // These two shouldn't be necessary to set. - xAxis.setAxisFirstLabelText(); - xAxis.setAxisLastLabelText(); - - m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, xAxis ); - - // Other parameters for various things. - m_params->setLineColor(); - - // Setting the background layer. - KDFrame frame; - frame.setBackground( TQBrush( TQColor( 230, 222, 222 ) ) ); - m_params->setFrame( KDChartEnums::AreaInnermost, frame, 0, 0, 0, 0 ); -} - - -// ================================================================ -// Loading and Storing - - -// ---------------------------------------------------------------- -// Save and Load program configuration - - - -void KChartPart::loadConfig( TDEConfig *conf ) -{ - conf->setGroup("ChartParameters"); - - // TODO: the fonts - // PENDING(kalle) Put the applicable ones of these back in - // TQFont tempfont; - // tempfont = conf->readFontEntry("titlefont", &titlefont); - // setTitleFont(tempfont); - // tempfont = conf->readFontEntry("ytitlefont", &ytitlefont); - // setYTitleFont(tempfont); - // tempfont = conf->readFontEntry("xtitlefont", &xtitlefont); - // setXTitleFont(tempfont); - // tempfont = conf->readFontEntry("yaxisfont", &yaxisfont); - // setYAxisFont(tempfont); - // tempfont = conf->readFontEntry("xaxisfont", &xaxisfont); - // setXAxisFont(tempfont); - // tempfont = conf->readFontEntry("labelfont", &labelfont); - // setLabelFont(tempfont); - // tempfont = conf->readFontEntry("annotationfont", &annotationfont); - // setAnnotationFont(tempfont); - - // ylabel_fmt = conf->readEntry("ylabel_fmt", ylabel_fmt ); - // ylabel2_fmt = conf->readEntry("ylabel2_fmt", ylabel2_fmt); - // xlabel_spacing = conf->readNumEntry("xlabel_spacing"); - // ylabel_density = conf->readNumEntry("ylabel_density", ylabel_density); - // requested_ymin = conf->readDoubleNumEntry("requested_ymin", requested_ymin); - // requested_ymax = conf->readDoubleNumEntry("requested_ymax", requested_ymax ); - // requested_yinterval = conf->readDoubleNumEntry("requested_yinterval", - // requested_yinterval); - // shelf = conf->readBoolEntry("shelf", shelf); - // grid = conf->readBoolEntry("grid", grid); - // xaxis = conf->readBoolEntry("xaxis", xaxis); - // yaxis = conf->readBoolEntry("yaxis", yaxis); - // yaxis2 = conf->readBoolEntry("yaxis2", yaxis); - // llabel = conf->readBoolEntry("llabel", llabel); - // yval_style = conf->readNumEntry("yval_style", yval_style); - // stack_type = (KChartStackType)conf->readNumEntry("stack_type", stack_type); - m_params->setLineMarker(conf->readBoolEntry("lineMarker", - m_params->lineMarker())); - m_params->setThreeDBarDepth( conf->readDoubleNumEntry("_3d_depth", - m_params->threeDBarDepth() ) ); - m_params->setThreeDBarAngle( conf->readNumEntry( "_3d_angle", - m_params->threeDBarAngle() ) ); - - KDChartAxisParams leftparams; - leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams rightparams; - rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparams; - bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - bottomparams.setAxisLineColor( conf->readColorEntry( "XTitleColor", 0 ) ); - leftparams.setAxisLineColor( conf->readColorEntry( "YTitleColor", 0 ) ); - rightparams.setAxisLineColor( conf->readColorEntry( "YTitle2Color", 0 ) ); - bottomparams.setAxisLabelsColor( conf->readColorEntry( "XLabelColor", 0 ) ); - leftparams.setAxisLabelsColor( conf->readColorEntry( "YLabelColor", 0 ) ); - rightparams.setAxisLabelsColor( conf->readColorEntry( "YLabel2Color", 0 ) ); - leftparams.setAxisGridColor( conf->readColorEntry( "GridColor", 0 ) ); - m_params->setOutlineDataColor( conf->readColorEntry( "LineColor", 0 ) ); - m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, - leftparams ); - m_params->setAxisParams( KDChartAxisParams::AxisPosRight, - rightparams ); - m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, - bottomparams ); - - // hlc_style = (KChartHLCStyle)conf->readNumEntry("hlc_style", hlc_style); - // hlc_cap_width = conf->readNumEntry("hlc_cap_width", hlc_cap_width); - // // TODO: Annotation font - // num_scatter_pts = conf->readNumEntry("num_scatter_pts", num_scatter_pts); - // // TODO: Scatter type - // thumbnail = conf->readBoolEntry("thumbnail", thumbnail); - // thumblabel = conf->readEntry("thumblabel", thumblabel); - // border = conf->readBoolEntry("border", border); - // BGColor = conf->readColorEntry("BGColor", &BGColor); - // PlotColor = conf->readColorEntry("PlotColor", &PlotColor); - // VolColor = conf->readColorEntry("VolColor", &VolColor); - // EdgeColor = conf->readColorEntry("EdgeColor", &EdgeColor); - // loadColorArray(conf, &SetColor, "SetColor"); - // loadColorArray(conf, &ExtColor, "ExtColor"); - // loadColorArray(conf, &ExtVolColor, "ExtVolColor"); - // transparent_bg = conf->readBoolEntry("transparent_bg", transparent_bg); - // // TODO: explode, missing - // percent_labels = (KChartPercentType)conf->readNumEntry("percent_labels", - // percent_labels); - // label_dist = conf->readNumEntry("label_dist", label_dist); - // label_line = conf->readBoolEntry("label_line", label_line); - m_params->setChartType( (KChartParams::ChartType)conf->readNumEntry( "type", m_params->chartType() ) ); - // other_threshold = conf->readNumEntry("other_threshold", other_threshold); - - // backgroundPixmapName = conf->readPathEntry( "backgroundPixmapName" ); - // if( !backgroundPixmapName.isNull() ) { - // backgroundPixmap.load( locate( "wallpaper", backgroundPixmapName )); - // backgroundPixmapIsDirty = true; - // } else - // backgroundPixmapIsDirty = false; - // backgroundPixmapScaled = conf->readBoolEntry( "backgroundPixmapScaled", true ); - // backgroundPixmapCentered = conf->readBoolEntry( "backgroundPixmapCentered", true ); - // backgroundPixmapIntensity = conf->readDoubleNumEntry( "backgroundPixmapIntensity", 0.25 ); -} - - -void KChartPart::defaultConfig( ) -{ - delete m_params; - m_params = new KChartParams( this ); - setChartDefaults(); -} - - -void KChartPart::saveConfig( TDEConfig *conf ) -{ - conf->setGroup("ChartParameters"); - - // PENDING(kalle) Put some of these back in - // the fonts - // conf->writeEntry("titlefont", titlefont); - // conf->writeEntry("ytitlefont", ytitlefont); - // conf->writeEntry("xtitlefont", xtitlefont); - // conf->writeEntry("yaxisfont", yaxisfont); - // conf->writeEntry("xaxisfont", xaxisfont); - // conf->writeEntry("labelfont", labelfont); - - // conf->writeEntry("ylabel_fmt", ylabel_fmt); - // conf->writeEntry("ylabel2_fmt", ylabel2_fmt); - // conf->writeEntry("xlabel_spacing", xlabel_spacing); - // conf->writeEntry("ylabel_density", ylabel_density); - // conf->writeEntry("requested_ymin", requested_ymin); - // conf->writeEntry("requested_ymax", requested_ymax); - // conf->writeEntry("requested_yinterval", requested_yinterval); - - // conf->writeEntry("shelf", shelf); - // conf->writeEntry("grid", grid ); - // conf->writeEntry("xaxis", xaxis); - // conf->writeEntry("yaxis", yaxis); - // conf->writeEntry("yaxis2", yaxis2); - // conf->writeEntry("llabel", llabel); - // conf->writeEntry("yval_style", yval_style ); - // conf->writeEntry("stack_type", (int)stack_type); - - conf->writeEntry( "_3d_depth", m_params->threeDBarDepth() ); - conf->writeEntry( "_3d_angle", m_params->threeDBarAngle() ); - - KDChartAxisParams leftparams; - leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); - KDChartAxisParams rightparams; - rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); - KDChartAxisParams bottomparams; - bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - conf->writeEntry( "LineColor", m_params->outlineDataColor() ); - conf->writeEntry( "XTitleColor", bottomparams.axisLineColor() ); - conf->writeEntry( "YTitleColor", leftparams.axisLineColor() ); - conf->writeEntry( "YTitle2Color", rightparams.axisLineColor() ); - conf->writeEntry( "XLabelColor", bottomparams.axisLabelsColor() ); - conf->writeEntry( "YLabelColor", leftparams.axisLabelsColor() ); - conf->writeEntry( "YLabel2Color", rightparams.axisLabelsColor() ); - conf->writeEntry( "GridColor", leftparams.axisGridColor() ); - - // conf->writeEntry("hlc_style", (int)hlc_style); - // conf->writeEntry("hlc_cap_width", hlc_cap_width ); - // // TODO: Annotation type!!! - // conf->writeEntry("annotationfont", annotationfont); - // conf->writeEntry("num_scatter_pts", num_scatter_pts); - // // TODO: Scatter type!!! - // conf->writeEntry("thumbnail", thumbnail); - // conf->writeEntry("thumblabel", thumblabel); - // conf->writeEntry("thumbval", thumbval); - // conf->writeEntry("border", border); - // conf->writeEntry("BGColor", BGColor); - // conf->writeEntry("PlotColor", PlotColor); - // conf->writeEntry("VolColor", VolColor); - // conf->writeEntry("EdgeColor", EdgeColor); - // saveColorArray(conf, &SetColor, "SetColor"); - // saveColorArray(conf, &ExtColor, "ExtColor"); - // saveColorArray(conf, &ExtVolColor, "ExtVolColor"); - - - // conf->writeEntry("transparent_bg", transparent_bg); - // // TODO: explode, missing - // conf->writeEntry("percent_labels",(int) percent_labels ); - // conf->writeEntry("label_dist", label_dist); - // conf->writeEntry("label_line", label_line); - conf->writeEntry( "type", (int) m_params->chartType() ); - // conf->writeEntry("other_threshold", other_threshold); - - // background pixmap stuff - // if( !backgroundPixmapName.isNull() ) - // conf->writePathEntry( "backgroundPixmapName", backgroundPixmapName ); - // conf->writeEntry( "backgroundPixmapIsDirty", backgroundPixmapIsDirty ); - // conf->writeEntry( "backgroundPixmapScaled", backgroundPixmapScaled ); - // conf->writeEntry( "backgroundPixmapCentered", backgroundPixmapCentered ); - // conf->writeEntry( "backgroundPixmapIntensity", backgroundPixmapIntensity ); - conf->writeEntry( "lineMarker", (int) m_params->lineMarker()); -} - - -// ---------------------------------------------------------------- -// Save and Load OpenDocument file format - - -bool KChartPart::loadOasis( const TQDomDocument& doc, - KoOasisStyles& oasisStyles, - const TQDomDocument& /*settings*/, - KoStore *store ) -{ - kdDebug(35001) << "kchart loadOasis called" << endl; - - // Set some sensible defaults. - setChartDefaults(); - - TQDomElement content = doc.documentElement(); - TQDomElement bodyElem ( KoDom::namedItemNS( content, - KoXmlNS::office, "body" ) ); - if ( bodyElem.isNull() ) { - kdError(32001) << "No office:body found!" << endl; - setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) ); - return false; - } - - // Get the office:chart element. - TQDomElement officeChartElem = KoDom::namedItemNS( bodyElem, - KoXmlNS::office, "chart" ); - if ( officeChartElem.isNull() ) { - kdError(32001) << "No office:chart found!" << endl; - TQDomElement childElem; - TQString localName; - forEachElement( childElem, bodyElem ) { - localName = childElem.localName(); - } - - if ( localName.isEmpty() ) - setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No tag found inside office:body." ) ); - else - setErrorMessage( i18n( "This document is not a chart, but %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) ); - - return false; - } - - TQDomElement chartElem = KoDom::namedItemNS( officeChartElem, - KoXmlNS::chart, "chart" ); - if ( chartElem.isNull() ) { - setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No chart:chart tag found." ) ); - return false; - } - - // Get the loading context and stylestack from the styles. - KoOasisLoadingContext loadingContext( this, oasisStyles, store ); - //KoStyleStack &styleStack = loadingContext.styleStack(); - -#if 0 // Example code!! - // load chart properties into the stylestack. - styleStack.save(); - styleStack.setTypeProperties( "chart" ); // load chart properties - loadingContext.fillStyleStack( chartElem, KoXmlNS::chart, "style-name" ); - - const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, "fill-color" ); - kdDebug() << "fillColor=" << fillColor << endl; - - styleStack.restore(); -#endif - - // Load chart parameters, most of these are stored in the - // chart:plot-area element within chart:chart. - TQString errorMessage; - bool ok = m_params->loadOasis( chartElem, loadingContext, errorMessage, - store); - if ( !ok ) { - setErrorMessage( errorMessage ); - return false; - } - - // TODO Load data direction (see loadAuxiliary) - - // Load the data table. - TQDomElement tableElem = KoDom::namedItemNS( chartElem, - KoXmlNS::table, "table" ); - if ( !tableElem.isNull() ) { - ok = loadOasisData( tableElem ); - if ( !ok ) - return false; // TODO setErrorMessage - } - - return true; -} - - -bool KChartPart::loadOasisData( const TQDomElement& tableElem ) -{ - int numberHeaderColumns = 0; - TQDomElement tableHeaderColumns = KoDom::namedItemNS( tableElem, - KoXmlNS::table, - "table-header-columns" ); - - TQDomElement elem; - forEachElement( elem, tableHeaderColumns ) { - if ( elem.localName() == "table-column" ) { - int repeated = elem.attributeNS( KoXmlNS::table, "number-columns-repeated", TQString() ).toInt(); - numberHeaderColumns += TQMAX( 1, repeated ); - } - } - - // With 0 you get no titles, and with more than 1 we ignore the others. - Q_ASSERT( numberHeaderColumns == 1 ); - - int numberDataColumns = 0; - TQDomElement tableColumns = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-columns" ); - forEachElement( elem, tableColumns ) { - if ( elem.localName() == "table-column" ) { - int repeated = elem.attributeNS( KoXmlNS::table, "number-columns-repeated", TQString() ).toInt(); - numberDataColumns += TQMAX( 1, repeated ); - } - } - - // Parse table-header-rows for the column names. - m_colLabels.clear(); - TQDomElement tableHeaderRows = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-header-rows" ); - if ( tableHeaderRows.isNull() ) - kdWarning(35001) << "No table-header-rows element found!" << endl; - TQDomElement tableHeaderRow = KoDom::namedItemNS( tableHeaderRows, KoXmlNS::table, "table-row" ); - if ( tableHeaderRow.isNull() ) - kdWarning(35001) << "No table-row inside table-header-rows!" << endl; - - int cellNum = 0; - forEachElement( elem, tableHeaderRow ) { - if ( elem.localName() == "table-cell" ) { - ++cellNum; - if ( cellNum > numberHeaderColumns ) { - TQDomElement pElem = KoDom::namedItemNS( elem, KoXmlNS::text, "p" ); - m_colLabels.append( pElem.text() ); - } - } - } - numberDataColumns = TQMAX( numberDataColumns, cellNum - numberHeaderColumns ); - if ( (int)m_colLabels.count() != numberDataColumns ) - kdWarning(35001) << "Got " << m_colLabels.count() - << " column titles, expected " << numberDataColumns - << endl; - - // Get the number of rows, and read row labels - int numberDataRows = 0; - TQDomElement tableRows = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-rows" ); - - m_rowLabels.clear(); - forEachElement( elem, tableRows ) { - if ( elem.localName() == "table-row" ) { - int repeated = elem.attributeNS( KoXmlNS::table, "number-rows-repeated", TQString() ).toInt(); - Q_ASSERT( repeated <= 1 ); // we don't handle yet the case where data rows are repeated (can this really happen?) - numberDataRows += TQMAX( 1, repeated ); - if ( numberHeaderColumns > 0 ) { - TQDomElement firstCell = KoDom::namedItemNS( elem, KoXmlNS::table, "table-cell" ); - TQDomElement pElem = KoDom::namedItemNS( firstCell, KoXmlNS::text, "p" ); - m_rowLabels.append( pElem.text() ); - } - } - } - - kdDebug(35001) << "numberHeaderColumns=" << numberHeaderColumns - << " numberDataColumns=" << numberDataColumns - << " numberDataRows=" << numberDataRows << endl; - - if ( (int)m_rowLabels.count() != numberDataRows) - kdWarning(35001) << "Got " << m_rowLabels.count() - << " row labels, expected " << numberDataRows << endl; - - m_currentData.expand( numberDataRows, numberDataColumns ); - m_currentData.setUsedCols( numberDataColumns ); - m_currentData.setUsedRows( numberDataRows ); - - // Now really load the cells. - int row = 0; - TQDomElement rowElem; - forEachElement( rowElem, tableRows ) { - if ( rowElem.localName() == "table-row" ) { - int col = 0; - int cellNum = 0; - TQDomElement cellElem; - forEachElement( cellElem, rowElem ) { - if ( cellElem.localName() == "table-cell" ) { - ++cellNum; - if ( cellNum > numberHeaderColumns ) { - TQString valueType = cellElem.attributeNS( KoXmlNS::office, "value-type", TQString() ); - if ( valueType != "float" ) - kdWarning(35001) << "Don't know how to handle value-type " << valueType << endl; - else { - TQString value = cellElem.attributeNS( KoXmlNS::office, "value", TQString() ); - double val = value.toDouble(); - - m_currentData.setCell( row, col, val ); - } - ++col; - } - } - } - ++row; - } - } - - return true; -} - - -bool KChartPart::saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) -{ - manifestWriter->addManifestEntry( "content.xml", "text/xml" ); - KoOasisStore oasisStore( store ); - - KoXmlWriter* contentWriter = oasisStore.contentWriter(); - if ( !contentWriter ) - return false; - - KoGenStyles mainStyles; - - KoXmlWriter* bodyWriter = oasisStore.bodyWriter(); - bodyWriter->startElement( "office:body" ); - bodyWriter->startElement( "office:chart" ); - bodyWriter->startElement( "chart:chart" ); - - // Indent to indicate that this is inside some tags. - { - // Saves chart class, title, legend, plot-area - m_params->saveOasis( bodyWriter, mainStyles ); - - // Save the data table. - saveOasisData( bodyWriter, mainStyles ); - } - - bodyWriter->endElement(); // chart:chart - bodyWriter->endElement(); // office:chart - bodyWriter->endElement(); // office:body - - contentWriter->startElement( "office:automatic-styles" ); - writeAutomaticStyles( *contentWriter, mainStyles ); - contentWriter->endElement(); // office:automatic-styles - - oasisStore.closeContentWriter(); - - // Done with content.xml - -#if 0 - if ( !store->open( "styles.xml" ) ) - return false; - manifestWriter->addManifestEntry( "styles.xml", "text/xml" ); - saveOasisDocumentStyles( store, mainStyles, savingContext, saveFlag, - headerFooterContent ); - if ( !store->close() ) // done with styles.xml - return false; -#endif - - return true; -} - - -void KChartPart::saveOasisData( KoXmlWriter* bodyWriter, - KoGenStyles& mainStyles ) const -{ - Q_UNUSED( mainStyles ); - - const int cols = m_currentData.usedCols() - ? TQMIN(m_currentData.usedCols(), m_currentData.cols()) - : m_currentData.cols(); - const int rows = m_currentData.usedRows() - ? TQMIN(m_currentData.usedRows(), m_currentData.rows()) - : m_currentData.rows(); - - bodyWriter->startElement( "table:table" ); - bodyWriter->addAttribute( "table:name", "local-table" ); - - // Exactly one header column, always. - bodyWriter->startElement( "table:table-header-columns" ); - bodyWriter->startElement( "table:table-column" ); - bodyWriter->endElement(); // table:table-column - bodyWriter->endElement(); // table:table-header-columns - - // Then "cols" columns - bodyWriter->startElement( "table:table-columns" ); - bodyWriter->startElement( "table:table-column" ); - bodyWriter->addAttribute( "table:number-columns-repeated", cols ); - bodyWriter->endElement(); // table:table-column - bodyWriter->endElement(); // table:table-columns - - // Exactly one header row, always. - bodyWriter->startElement( "table:table-header-rows" ); - bodyWriter->startElement( "table:table-row" ); - - // The first column in header row is just the header column - no title needed - bodyWriter->startElement( "table:table-cell" ); - bodyWriter->addAttribute( "office:value-type", "string" ); - bodyWriter->startElement( "text:p" ); - bodyWriter->endElement(); // text:p - bodyWriter->endElement(); // table:table-cell - - // Save column labels in the first header row, for instance: - // - // Column 1 - // - TQStringList::const_iterator colLabelIt = m_colLabels.begin(); - for ( int col = 0; col < cols ; ++col ) { - if ( colLabelIt != m_colLabels.end() ) { - bodyWriter->startElement( "table:table-cell" ); - bodyWriter->addAttribute( "office:value-type", "string" ); - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( *colLabelIt ); - bodyWriter->endElement(); // text:p - bodyWriter->endElement(); // table:table-cell - ++colLabelIt; - } - } - - bodyWriter->endElement(); // table:table-row - bodyWriter->endElement(); // table:table-header-rows - bodyWriter->startElement( "table:table-rows" ); - - TQStringList::const_iterator rowLabelIt = m_rowLabels.begin(); - for ( int row = 0; row < rows ; ++row ) { - bodyWriter->startElement( "table:table-row" ); - - if ( rowLabelIt != m_rowLabels.end() ) { - // Save row labels, similar to column labels - bodyWriter->startElement( "table:table-cell" ); - bodyWriter->addAttribute( "office:value-type", "string" ); - - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( *rowLabelIt ); - bodyWriter->endElement(); // text:p - - bodyWriter->endElement(); // table:table-cell - ++rowLabelIt; - } - - for ( int col = 0; col < cols; ++col ) { - TQVariant value( m_currentData.cellVal( row, col ) ); - TQString valType; - TQString valStr; - - switch ( value.type() ) { - case TQVariant::Invalid: - break; - case TQVariant::String: - valType = "string"; - valStr = value.toString(); - break; - case TQVariant::Double: - valType = "float"; - valStr = TQString::number( value.toDouble(), 'g', DBL_DIG ); - break; - case TQVariant::DateTime: - valType = "date"; - valStr = ""; /* like in saveXML, but why? */ - break; - default: { - kdDebug(35001) << "ERROR: cell " << row << "," << col - << " has unknown type." << endl; - } - } - - // Add the value type and the string to the XML tree. - bodyWriter->startElement( "table:table-cell" ); - if ( !valType.isEmpty() ) { - bodyWriter->addAttribute( "office:value-type", valType ); - if ( value.type() == TQVariant::Double ) - bodyWriter->addAttribute( "office:value", valStr ); - - bodyWriter->startElement( "text:p" ); - bodyWriter->addTextNode( valStr ); - bodyWriter->endElement(); // text:p - } - bodyWriter->endElement(); // table:table-cell - } - bodyWriter->endElement(); // table:table-row - } - - bodyWriter->endElement(); // table:table-rows - bodyWriter->endElement(); // table:table -} - -void KChartPart::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles ) const -{ - TQValueList styles = mainStyles.styles( KoGenStyle::STYLE_AUTO ); - TQValueList::const_iterator it = styles.begin(); - for ( ; it != styles.end() ; ++it ) { - (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:chart-properties" ); - } - -} - -// ---------------------------------------------------------------- -// Save and Load old KChart file format - - -TQDomDocument KChartPart::saveXML() -{ - TQDomElement tmpElem; - - //kdDebug(35001) << "kchart saveXML called" << endl; - - // The biggest part of the saving is done by KDChart itself, so we - // don't have to do it. - TQDomDocument doc = m_params->saveXML( false ); - - // ---------------------------------------------------------------- - // The rest of the saving has to be done by us. - - TQDomElement docRoot = doc.documentElement(); - - // Save auxiliary data. - TQDomElement aux = doc.createElement( "KChartAuxiliary" ); - docRoot.appendChild( aux ); - - // The data direction (rows/columns). - tmpElem = doc.createElement( "direction" ); - tmpElem.setAttribute( "value", (int) m_params->dataDirection() ); - aux.appendChild( tmpElem ); - - tmpElem = doc.createElement( "dataaslabel" ); - tmpElem.setAttribute( "firstrow", - m_params->firstRowAsLabel() ? "true" : "false" ); - tmpElem.setAttribute( "firstcol", - m_params->firstColAsLabel() ? "true" : "false" ); - aux.appendChild( tmpElem ); - - tmpElem = doc.createElement( "barnumlines" ); - tmpElem.setAttribute( "value", (int) m_params->barNumLines() ); - aux.appendChild( tmpElem ); - - // Save the data values. - TQDomElement data = doc.createElement( "data" ); - docRoot.appendChild( data ); - - int cols = m_currentData.usedCols() - ? TQMIN(m_currentData.usedCols(), m_currentData.cols()) - : m_currentData.cols(); - int rows = m_currentData.usedRows() - ? TQMIN(m_currentData.usedRows(), m_currentData.rows()) - : m_currentData.rows(); - data.setAttribute( "cols", cols ); - data.setAttribute( "rows", rows ); - kdDebug(35001) << " writing " << cols << "," << rows << " (cols,rows)." << endl; - - for (int i=0; i!=rows; ++i) { - for (int j=0; j!=cols; ++j) { - TQDomElement e = doc.createElement( "cell" ); - data.appendChild( e ); - TQString valType; - TQVariant value( m_currentData.cellVal( i,j ) ); - switch ( value.type() ) { - case TQVariant::Invalid: valType = "NoValue"; break; - case TQVariant::String: valType = "String"; break; - case TQVariant::Double: valType = "Double"; break; - case TQVariant::DateTime: valType = "DateTime"; break; - default: { - valType = "(unknown)"; - kdDebug(35001) << "ERROR: cell " << i << "," << j - << " has unknown type." << endl; - } - } - - e.setAttribute( "valType", valType ); - //kdDebug(35001) << " cell " << i << "," << j - // << " saved with type '" << valType << "'." << endl; - switch ( value.type() ) { - case TQVariant::String: e.setAttribute( "value", value.toString() ); - break; - case TQVariant::Double: e.setAttribute( "value", TQString::number( value.toDouble() ) ); - break; - case TQVariant::DateTime:e.setAttribute( "value", "" ); - break; - default: { - e.setAttribute( "value", "" ); - if( TQVariant::Invalid != value.type() ) - kdDebug(35001) << "ERROR: cell " << i << "," << j - << " has unknown type." << endl; - } - } - } - } - - return doc; -} - - -bool KChartPart::loadXML( TQIODevice*, const TQDomDocument& doc ) -{ - kdDebug(35001) << "kchart loadXML called" << endl; - - // Set some sensible defaults. - setChartDefaults(); - - // First try to load the KDChart parameters. - bool result = m_params->loadXML( doc ); - - // If went well, try to load the auxiliary data and the data... - if (result) { - result = loadAuxiliary(doc) && loadData( doc, m_currentData ); - } - else { - // ...but if it did, try to load the old XML format. - result = loadOldXML( doc ); - } - - // If everything is OK, then get the headers from the KDChart parameters. - if (result) { - TQStringList legendLabels; - KDChartAxisParams params; - params = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); - - // Get the legend. - TQString str; - uint index = 0; - while ((str = m_params->legendText(index++)) != TQString()) - legendLabels << str; - - if (m_params->dataDirection() == KChartParams::DataRows) { - m_colLabels = params.axisLabelStringList(); - m_rowLabels = legendLabels; - } - else { - m_colLabels = legendLabels; - m_rowLabels = params.axisLabelStringList(); - } - - } - - m_params->setDrawSolidExcessArrows(true); - - return result; -} - - -// Load the auxiliary data. -// -// Currently, that means the data direction. -// -bool KChartPart::loadAuxiliary( const TQDomDocument& doc ) -{ - TQDomElement chart = doc.documentElement(); - TQDomElement aux = chart.namedItem("KChartAuxiliary").toElement(); - - // Older XML files might be missing this section. That is OK; the - // defaults will be used. - if (aux.isNull()) - return true; - - TQDomNode node = aux.firstChild(); - - // If the aux section exists, it should contain data. - while (!node.isNull()) { - - TQDomElement e = node.toElement(); - if (e.isNull()) { - // FIXME: Should this be regarded as an error? - node = node.nextSibling(); - continue; - } - - // Check for direction - if ( e.tagName() == "direction" ) { - if ( e.hasAttribute("value") ) { - bool ok; - - // Read the direction. On failure, use the default. - int dir = e.attribute("value").toInt(&ok); - if ( !ok ) - dir = (int) KChartParams::DataColumns; - - //kdDebug(35001) << "Got aux value \"direction\": " << dir << endl; - m_params->setDataDirection( (KChartParams::DataDirection) dir ); - } - else { - kdDebug(35001) << "Error in direction tag." << endl; - } - } - - // Check for first row / col as label - else if ( e.tagName() == "dataaslabel" ) { - TQString val; - - if ( e.hasAttribute("firstrow") ) { - // Read the direction. On failure, use the default. - val = e.attribute("firstrow"); - if ( val == "true" ) - m_params->setFirstRowAsLabel( true ); - else - m_params->setFirstRowAsLabel( false ); - } - else { - kdDebug(35001) << "Error in barnumlines tag." << endl; - m_params->setFirstRowAsLabel( false ); - } - - if ( e.hasAttribute("firstcol") ) { - // Read the direction. On failure, use the default. - val = e.attribute("firstcol"); - if ( val == "true" ) - m_params->setFirstColAsLabel( true ); - else - m_params->setFirstColAsLabel( false ); - } - else { - kdDebug(35001) << "Error in barnumlines tag." << endl; - m_params->setFirstColAsLabel( false ); - } - } - - // Check for number of lines in a bar chart. - else if ( e.tagName() == "barnumlines" ) { - if ( e.hasAttribute("value") ) { - bool ok; - - // Read the number of lines. On failure, use the default. - int barNumLines = e.attribute("value").toInt(&ok); - if ( !ok ) - barNumLines = 0; - - //kdDebug(35001) << "Got aux value \"barnumlines\": " - // << barNumLines << endl; - m_params->setBarNumLines( barNumLines ); - } - else { - kdDebug(35001) << "Error in barnumlines tag." << endl; - } - } -#if 0 - // Expand with more auxiliary types when needed. - else if ( e.tagName() == "..." ) { - } - and so on... -#endif - - node = node.nextSibling(); - } - - return true; -} - - -bool KChartPart::loadData( const TQDomDocument& doc, - KDChartTableData& m_currentData ) -{ - kdDebug(35001) << "kchart loadData called" << endl; - - TQDomElement chart = doc.documentElement(); - TQDomElement data = chart.namedItem("data").toElement(); - bool ok; - int cols = data.attribute("cols").toInt(&ok); - kdDebug(35001) << "cols readed as:" << cols << endl; - if ( !ok ){ - return false; - } - - int rows = data.attribute("rows").toInt(&ok); - if ( !ok ){ - return false; - } - - kdDebug(35001) << rows << " x " << cols << endl; - m_currentData.expand(rows, cols); - m_currentData.setUsedCols( cols ); - m_currentData.setUsedRows( rows ); - kdDebug(35001) << "Expanded!" << endl; - TQDomNode n = data.firstChild(); - //TQArray tmpExp(rows*cols); - //TQArray tmpMissing(rows*cols); - for (int i=0; i!=rows; i++) { - for (int j=0; j!=cols; j++) { - if (n.isNull()) { - kdDebug(35001) << "Some problems, there is less data than it should be!" << endl; - break; - } - TQDomElement e = n.toElement(); - if ( !e.isNull() && e.tagName() == "cell" ) { - // add the cell to the corresponding place... - TQVariant t; - if ( e.hasAttribute("value") && e.hasAttribute("valType") ) { - TQString valueType = e.attribute("valType").lower(); - if ( "string" == valueType ) { - t = e.attribute("value"); - } - else if ( "double" == valueType ) { - bool bOk; - double val = e.attribute("value").toDouble(&bOk); - if ( !bOk ) - val = 0.0; - t = val; - /* - } else if ( "datetime" == valueType ) { - t = . . . - */ - } else { - t.clear(); - if ( "novalue" != valueType ) - kdDebug(35001) << "ERROR: cell " << i << "," << j << " has unknown type '" << valueType << "'." << endl; - } - } else - t.clear(); - - m_currentData.setCell(i,j, t ); - - /* - if ( e.hasAttribute( "hide" ) ) { - tmpMissing[cols*j+i] = (bool)e.attribute("hide").toInt( &ok ); - if ( !ok ) - return false; - } else { - tmpMissing[cols*j+i] = false; - } - if ( e.hasAttribute( "dist" ) ) { - tmpExp[cols*j+i] = e.attribute("dist").toInt( &ok ); - if ( !ok ) - return false; - } else { - tmpExp[cols*j+i] = 0; - } - */ - - n = n.nextSibling(); - } - } - } - /* - m_params->missing=tmpMissing; - m_params->explode=tmpExp; - */ - return true; -} - - -// ---------------------------------------------------------------- -// Save and Load real old KChart file format - - -bool KChartPart::loadOldXML( const TQDomDocument& doc ) -{ - kdDebug(35001) << "kchart loadOldXML called" << endl; - if ( doc.doctype().name() != "chart" ) - return false; - - kdDebug(35001) << "Ok, it is a chart" << endl; - - TQDomElement chart = doc.documentElement(); - if ( chart.attribute( "mime" ) != "application/x-kchart" && chart.attribute( "mime" ) != "application/vnd.kde.kchart" ) - return false; - - kdDebug(35001) << "Mimetype ok" << endl; - -#if 0 - TQDomElement data = chart.namedItem("data").toElement(); - bool ok; - int cols = data.attribute("cols").toInt(&ok); - kdDebug(35001) << "cols readed as:" << cols << endl; - if (!ok) { return false; } - int rows = data.attribute("rows").toInt(&ok); - if (!ok) { return false; } - kdDebug(35001) << rows << " x " << cols << endl; - m_currentData.expand(rows, cols); - kdDebug(35001) << "Expanded!" << endl; - TQDomNode n = data.firstChild(); - TQArray tmpExp(rows*cols); - TQArray tmpMissing(rows*cols); - - for (int i=0; i!=rows; i++) { - for (int j=0; j!=cols; j++) { - if (n.isNull()) { - kdDebug(35001) << "Some problems, there is less data than it should be!" << endl; - break; - } - - TQDomElement e = n.toElement(); - if ( !e.isNull() && e.tagName() == "cell" ) { - // add the cell to the corresponding place... - double val = e.attribute("value").toDouble(&ok); - if (!ok) { return false; } - kdDebug(35001) << i << " " << j << "=" << val << endl; - KoChart::Value t( val ); - // kdDebug(35001) << "Set cell for " << row << "," << col << endl; - m_currentData.setCell(i,j,t); - if ( e.hasAttribute( "hide" ) ) { - tmpMissing[cols*j+i] = (bool)e.attribute("hide").toInt( &ok ); - if ( !ok ) - return false; - } else { - tmpMissing[cols*j+i] = false; - } - if ( e.hasAttribute( "dist" ) ) { - tmpExp[cols*j+i] = e.attribute("dist").toInt( &ok ); - if ( !ok ) - return false; - } else { - tmpExp[cols*j+i] = 0; - } - - n = n.nextSibling(); - } - } - } - m_params->missing=tmpMissing; - m_params->explode=tmpExp; -#endif - - -/* - enum KChartType { - KCHARTTYPE_LINE, - KCHARTTYPE_AREA, - KCHARTTYPE_BAR, - KCHARTTYPE_HILOCLOSE, - KCHARTTYPE_COMBO_LINE_BAR, aka, VOL[ume] - KCHARTTYPE_COMBO_HLC_BAR, - KCHARTTYPE_COMBO_LINE_AREA, - KCHARTTYPE_COMBO_HLC_AREA, - KCHARTTYPE_3DHILOCLOSE, - KCHARTTYPE_3DCOMBO_LINE_BAR, - KCHARTTYPE_3DCOMBO_LINE_AREA, - KCHARTTYPE_3DCOMBO_HLC_BAR, - KCHARTTYPE_3DCOMBO_HLC_AREA, - KCHARTTYPE_3DBAR, - KCHARTTYPE_3DAREA, - KCHARTTYPE_3DLINE, - KCHARTTYPE_3DPIE, - KCHARTTYPE_2DPIE - }; -*/ - bool ok; - TQDomElement params = chart.namedItem( "params" ).toElement(); - if ( params.hasAttribute( "type" ) ) { - int type=params.attribute("type").toInt( &ok ); - if ( !ok ) - return false; - switch(type) - { - case 1: - m_params->setChartType(KChartParams::Line); - break; - case 2: - m_params->setChartType(KChartParams::Area); - break; - case 3: - m_params->setChartType(KChartParams::Bar); - break; - case 4: - m_params->setChartType(KChartParams::HiLo); - break; - case 5: - case 6: - case 7: - case 8: - /* KCHARTTYPE_COMBO_LINE_BAR, aka, VOL[ume] - KCHARTTYPE_COMBO_HLC_BAR, - KCHARTTYPE_COMBO_LINE_AREA, - KCHARTTYPE_COMBO_HLC_AREA, - */ - /* line by default*/ - m_params->setChartType(KChartParams::Line); - break; - case 9: - m_params->setChartType(KChartParams::HiLo); - break; - case 10: - m_params->setChartType(KChartParams::Bar); - break; - case 11: - m_params->setChartType(KChartParams::Area); - break; - case 12: - m_params->setChartType(KChartParams::Bar); - break; - case 13: - m_params->setChartType(KChartParams::Area); - break; - case 14: - m_params->setChartType(KChartParams::Bar); - break; - case 15: - m_params->setChartType(KChartParams::Area); - break; - case 16: - m_params->setChartType(KChartParams::Line); - break; - case 17: - case 18: - m_params->setChartType(KChartParams::Pie); - break; - - } - if ( !ok ) - return false; - } -#if 0 - if ( params.hasAttribute( "subtype" ) ) { - m_params->stack_type = (KChartStackType)params.attribute("subtype").toInt( &ok ); - if ( !ok ) - return false; - } - if ( params.hasAttribute( "hlc_style" ) ) { - m_params->hlc_style = (KChartHLCStyle)params.attribute("hlc_style").toInt( &ok ); - if ( !ok ) - return false; - } - if ( params.hasAttribute( "hlc_cap_width" ) ) { - m_params->hlc_cap_width = (short)params.attribute( "hlc_cap_width" ).toShort( &ok ); - if ( !ok ) - return false; - } - - TQDomElement title = params.namedItem( "title" ).toElement(); - if ( !title.isNull()) { - TQString t = title.text(); - m_params->title=t; - } - TQDomElement titlefont = params.namedItem( "titlefont" ).toElement(); - if ( !titlefont.isNull()) { - TQDomElement font = titlefont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setTitleFont(toFont(font)); - } - TQDomElement xtitle = params.namedItem( "xtitle" ).toElement(); - if ( !xtitle.isNull()) { - TQString t = xtitle.text(); - m_params->xtitle=t; - } - TQDomElement xtitlefont = params.namedItem( "xtitlefont" ).toElement(); - if ( !xtitlefont.isNull()) { - TQDomElement font = xtitlefont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setXTitleFont(toFont(font)); - } - TQDomElement ytitle = params.namedItem( "ytitle" ).toElement(); - if ( !ytitle.isNull()) { - TQString t = ytitle.text(); - m_params->ytitle=t; - } - TQDomElement ytitle2 = params.namedItem( "ytitle2" ).toElement(); - if ( !ytitle2.isNull()) { - TQString t = ytitle2.text(); - m_params->ytitle2=t; - } - TQDomElement ytitlefont = params.namedItem( "ytitlefont" ).toElement(); - if ( !ytitlefont.isNull()) { - TQDomElement font = ytitlefont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setYTitleFont(toFont(font)); - } - TQDomElement ylabelfmt = params.namedItem( "ylabelfmt" ).toElement(); - if ( !ylabelfmt.isNull()) { - TQString t = ylabelfmt.text(); - m_params->ylabel_fmt=t; - } - TQDomElement ylabel2fmt = params.namedItem( "ylabel2fmt" ).toElement(); - if ( !ylabel2fmt.isNull()) { - TQString t = ylabel2fmt.text(); - m_params->ylabel2_fmt=t; - } - TQDomElement labelfont = params.namedItem( "labelfont" ).toElement(); - if ( !labelfont.isNull()) { - TQDomElement font = labelfont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setLabelFont(toFont(font)); - } - - TQDomElement yaxisfont = params.namedItem( "yaxisfont" ).toElement(); - if ( !yaxisfont.isNull()) { - TQDomElement font = yaxisfont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setYAxisFont(toFont(font)); - } - - TQDomElement xaxisfont = params.namedItem( "xaxisfont" ).toElement(); - if ( !xaxisfont.isNull()) { - TQDomElement font = xaxisfont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setXAxisFont(toFont(font)); - } - TQDomElement annotationFont = params.namedItem("annotationfont").toElement(); - if ( !annotationFont.isNull()) { - TQDomElement font = annotationFont.namedItem( "font" ).toElement(); - if ( !font.isNull() ) - m_params->setAnnotationFont(toFont(font)); - } - - TQDomElement yaxis = params.namedItem( "yaxis" ).toElement(); - if ( !yaxis.isNull()) { - if (yaxis.hasAttribute( "yinterval" )) { - m_params->requested_yinterval= yaxis.attribute("yinterval").toDouble( &ok ); - if ( !ok ) return false; - } - if (yaxis.hasAttribute( "ymin" )) { - m_params->requested_ymin= yaxis.attribute("ymin").toDouble( &ok ); - if ( !ok ) return false; - } - if (yaxis.hasAttribute( "ymax" ) ) { - m_params->requested_ymax= yaxis.attribute("ymax").toDouble( &ok ); - if ( !ok ) return false; - } - } -#endif - - TQDomElement graph = params.namedItem( "graph" ).toElement(); - if (!graph.isNull()) { - if (graph.hasAttribute( "grid" )) { - bool b=(bool) graph.attribute("grid").toInt( &ok ); - m_params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,b ); - m_params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,b ); - if (!ok) return false; - } - if (graph.hasAttribute( "xaxis" )) { - bool b=(bool) graph.attribute("xaxis").toInt( &ok ); - if (!ok) return false; - m_params->setAxisVisible(KDChartAxisParams::AxisPosBottom,b); - } - if (graph.hasAttribute( "yaxis" )) { - bool b=(bool) graph.attribute("yaxis").toInt( &ok ); - if (!ok) return false; - m_params->setAxisVisible(KDChartAxisParams::AxisPosLeft,b); - } -#if 0 - //no implemented - if (graph.hasAttribute( "shelf" )) { - m_params->shelf=(bool) graph.attribute("shelf").toInt( &ok ); - if (!ok) return false; - } -#endif - if (graph.hasAttribute( "yaxis2" )) { - bool b=(bool) graph.attribute("yaxis2").toInt( &ok ); - if (!ok) return false; - m_params->setAxisVisible(KDChartAxisParams::AxisPosRight,b); - } - -#if 0 - //no implemented - if (graph.hasAttribute( "ystyle" )) { - m_params->yval_style=(bool) graph.attribute("ystyle").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute( "border" )) { - m_params->border=(bool) graph.attribute("border").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute( "transbg" )) { - m_params->transparent_bg=(bool) graph.attribute("transbg").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute( "xlabel" )) { - m_params->hasxlabel=(bool) graph.attribute("xlabel").toInt( &ok ); - if (!ok) return false; - } - if ( graph.hasAttribute( "xlabel_spacing" ) ) { - m_params->xlabel_spacing = (short)graph.attribute( "xlabel_spacing" ).toShort( &ok ); - if ( !ok ) - return false; - } - if ( graph.hasAttribute( "ylabel_density" ) ) { - m_params->ylabel_density = (short)graph.attribute( "ylabel_density" ).toShort( &ok ); - if ( !ok ) - return false; - } - if (graph.hasAttribute( "line")) { - m_params->label_line=(bool) graph.attribute("line").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute( "percent")) { - m_params->percent_labels=(KChartPercentType) graph.attribute("percent").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute("cross")) { - m_params->cross=(bool) graph.attribute("cross").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute("thumbnail")) { - m_params->thumbnail=(bool) graph.attribute("thumbnail").toInt( &ok ); - if (!ok) return false; - } - if (graph.hasAttribute("thumblabel")) { - m_params->thumblabel= graph.attribute("thumblabel"); - } - if (graph.hasAttribute("thumbval")) { - m_params->thumbval=(bool) graph.attribute("thumbval").toDouble( &ok ); - if (!ok) - return false; - } -#endif - } - -#if 0 - TQDomElement graphparams = params.namedItem( "graphparams" ).toElement(); - if (!graphparams.isNull()) { - if (graphparams.hasAttribute( "dept3d" )) { - m_params->_3d_depth=graphparams.attribute("dept3d").toDouble( &ok ); - if (!ok) return false; - } - if (graphparams.hasAttribute( "angle3d" )) { - m_params->_3d_angle=graphparams.attribute("angle3d").toShort( &ok ); - if (!ok) return false; - } - if (graphparams.hasAttribute( "barwidth" )) { - m_params->bar_width=graphparams.attribute("barwidth").toShort( &ok ); - if (!ok) return false; - } - if (graphparams.hasAttribute( "colpie" )) { - m_params->colPie=graphparams.attribute("colpie").toInt( &ok ); - if (!ok) return false; - } - if (graphparams.hasAttribute( "other_threshold" )) { - m_params->other_threshold=graphparams.attribute("other_threshold").toShort( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "offsetCol" )) { - m_params->offsetCol = graphparams.attribute("offsetCol").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "hard_size" )) { - m_params->hard_size = (bool)graphparams.attribute("hard_size").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "hard_graphheight" )) { - m_params->hard_graphheight = graphparams.attribute("hard_graphheight").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "hard_graphwidth" )) { - m_params->hard_graphwidth = graphparams.attribute("hard_graphwidth").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "hard_xorig" )) { - m_params->hard_xorig = graphparams.attribute("hard_xorig").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "hard_yorig" )) { - m_params->hard_yorig = graphparams.attribute("hard_yorig").toInt( &ok ); - if (!ok) - return false; - } - if (graphparams.hasAttribute( "labeldist" )) { - m_params->label_dist=graphparams.attribute("labeldist").toInt( &ok ); - if (!ok) return false; - } - } - - TQDomElement graphcolor = params.namedItem( "graphcolor" ).toElement(); - if (!graphcolor.isNull()) { - if (graphcolor.hasAttribute( "bgcolor" )) { - m_params->BGColor= TQColor( graphcolor.attribute( "bgcolor" ) ); - } - if (graphcolor.hasAttribute( "gridcolor" )) { - m_params->GridColor= TQColor( graphcolor.attribute( "gridcolor" ) ); - } - if (graphcolor.hasAttribute( "linecolor" )) { - m_params->LineColor= TQColor( graphcolor.attribute( "linecolor" ) ); - } - if (graphcolor.hasAttribute( "plotcolor" )) { - m_params->PlotColor= TQColor( graphcolor.attribute( "plotcolor" ) ); - } - if (graphcolor.hasAttribute( "volcolor" )) { - m_params->VolColor= TQColor( graphcolor.attribute( "volcolor" ) ); - } - if (graphcolor.hasAttribute( "titlecolor" )) { - m_params->TitleColor= TQColor( graphcolor.attribute( "titlecolor" ) ); - } - if (graphcolor.hasAttribute( "xtitlecolor" )) { - m_params->XTitleColor= TQColor( graphcolor.attribute( "xtitlecolor" ) ); - } - if (graphcolor.hasAttribute( "ytitlecolor" )) { - m_params->YTitleColor= TQColor( graphcolor.attribute( "ytitlecolor" ) ); - } - if (graphcolor.hasAttribute( "ytitle2color" )) { - m_params->YTitle2Color= TQColor( graphcolor.attribute( "ytitle2color" ) ); - } - if (graphcolor.hasAttribute( "xlabelcolor" )) { - m_params->XLabelColor= TQColor( graphcolor.attribute( "xlabelcolor" ) ); - } - if (graphcolor.hasAttribute( "ylabelcolor" )) { - m_params->YLabelColor= TQColor( graphcolor.attribute( "ylabelcolor" ) ); - } - if (graphcolor.hasAttribute( "ylabel2color" )) { - m_params->YLabel2Color= TQColor( graphcolor.attribute( "ylabel2color" ) ); - } - } - - TQDomElement annotation = params.namedItem( "annotation" ).toElement(); - if (!annotation.isNull()) { - m_params->annotation=new KChartAnnotationType; - if (annotation.hasAttribute( "color" )) { - m_params->annotation->color= TQColor( annotation.attribute( "color" ) ); - } - if (annotation.hasAttribute( "point" )) { - m_params->annotation->point=annotation.attribute("point").toDouble( &ok ); - if (!ok) return false; - } - } - - TQDomElement note = params.namedItem( "note" ).toElement(); - if ( !note.isNull()) { - TQString t = note.text(); - m_params->annotation->note=t; - } - - TQDomElement scatter = params.namedItem( "scatter" ).toElement(); - if ( !scatter.isNull() ) { - m_params->scatter = new KChartScatterType; - if ( scatter.hasAttribute( "point" ) ) { - m_params->scatter->point = scatter.attribute( "point" ).toDouble( &ok ); - if ( !ok ) - return false; - } - if ( scatter.hasAttribute( "val" ) ) { - m_params->scatter->val = scatter.attribute( "val" ).toDouble( &ok ); - if ( !ok ) - return false; - } - if ( scatter.hasAttribute( "width" ) ) { - m_params->scatter->width = scatter.attribute( "val" ).toUShort( &ok ); - if ( !ok ) - return false; - } - if ( scatter.hasAttribute( "color" )) { - m_params->scatter->color= TQColor( scatter.attribute( "color" ) ); - } - if ( scatter.hasAttribute( "ind" ) ) { - m_params->scatter->ind = (KChartScatterIndType)scatter.attribute( "ind" ).toInt( &ok ); - if ( !ok ) - return false; - } - } - - TQDomElement legend = chart.namedItem("legend").toElement(); - if (!legend.isNull()) { - int number = legend.attribute("number").toInt(&ok); - if (!ok) { return false; } - TQDomNode name = legend.firstChild(); - m_params->legend.clear(); - for(int i=0; ilegend+=t; - name = name.nextSibling(); - } - } - } - - TQDomElement xlbl = chart.namedItem("xlbl").toElement(); - if (!xlbl.isNull()) { - int number = xlbl.attribute("number").toInt(&ok); - if (!ok) { return false; } - TQDomNode label = xlbl.firstChild(); - m_params->xlbl.clear(); - for (int i=0; ixlbl+=t; - label = label.nextSibling(); - } - } - } - - TQDomElement backgroundPixmap = chart.namedItem( "backgroundPixmap" ).toElement(); - if ( !backgroundPixmap.isNull() ) { - if ( backgroundPixmap.hasAttribute( "name" ) ) - m_params->backgroundPixmapName = backgroundPixmap.attribute( "name" ); - if ( backgroundPixmap.hasAttribute( "isDirty" ) ) { - m_params->backgroundPixmapIsDirty = (bool)backgroundPixmap.attribute( "isDirty" ).toInt( &ok ); - if ( !ok ) - return false; - } - if ( backgroundPixmap.hasAttribute( "scaled" ) ) { - m_params->backgroundPixmapScaled = (bool)backgroundPixmap.attribute( "scaled" ).toInt( &ok ); - if ( !ok ) - return false; - } - if ( backgroundPixmap.hasAttribute( "centered" ) ) { - m_params->backgroundPixmapCentered = (bool)backgroundPixmap.attribute( "centered" ).toInt( &ok ); - if ( !ok ) - return false; - } - if ( backgroundPixmap.hasAttribute( "intensity" ) ) { - m_params->backgroundPixmapIntensity = backgroundPixmap.attribute( "intensity" ).toFloat( &ok ); - if ( !ok ) - return false; - } - } - - TQDomElement extcolor = chart.namedItem("extcolor").toElement(); - if (!extcolor.isNull()) { - unsigned int number = extcolor.attribute("number").toInt(&ok); - if (!ok) { return false; } - TQDomNode color = extcolor.firstChild(); - - for (unsigned int i=0; iExtColor.setColor(i,TQColor( element.attribute( "name" ) )); - } - color = color.nextSibling(); - } - } - } - - if ( !m_params->backgroundPixmapName.isNull() ) { - m_params->backgroundPixmap.load( locate( "wallpaper", - m_params->backgroundPixmapName )); - m_params->backgroundPixmapIsDirty = true; - } -#endif - return true; -} - - - -void KChartPart::slotModified() -{ - kdDebug(35001) << "slotModified called!" << endl; - - setModified(true); -} - - -bool KChartPart::showEmbedInitDialog(TQWidget* /*parent*/) -{ - // Don't show an embed dialog - return true; -} - - -} //KChart namespace - -#include "kchart_part.moc" diff --git a/kchart/kchart_part.cpp b/kchart/kchart_part.cpp new file mode 100644 index 00000000..fb6a6414 --- /dev/null +++ b/kchart/kchart_part.cpp @@ -0,0 +1,2306 @@ +/** + * + * Kalle Dalheimer + */ + +#include // For basic data types characteristics. + +// For debugging +#include +using std::cout; +using std::cerr; + +#include "kchart_part.h" +#include "kchart_view.h" +#include "kchart_factory.h" +#include "kchartWizard.h" +#include "kchart_params.h" +#include "kdchart/KDChart.h" +#include "kdchart/KDChartTable.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +// Some hardcoded data for a chart + +/* ----- set some data ----- */ +// float a[6] = { 0.5, 0.09, 0.6, 0.85, 0.0, 0.90 }, +// b[6] = { 1.9, 1.3, 0.6, 0.75, 0.1, -2.0 }; +/* ----- X labels ----- */ +// char *t[6] = { "Chicago", "New York", "L.A.", "Atlanta", "Paris, MD\n(USA) ", "London" }; +/* ----- data set colors (RGB) ----- */ +// TQColor sc[2] = { TQColor( 255, 128, 128 ), TQColor( 128, 128, 255 ) }; + + +namespace KChart +{ + +KChartPart::KChartPart( TQWidget *parentWidget, const char *widgetName, + TQObject* parent, const char* name, + bool singleViewMode ) + : KoChart::Part( parentWidget, widgetName, parent, name, singleViewMode ), + m_params( 0 ), + m_parentWidget( parentWidget ), + m_rowLabels(), m_colLabels() +{ + kdDebug(35001) << "Constructor started!" << endl; + + setInstance( KChartFactory::global(), false ); + setTemplateType( "kchart_template" ); + + // Init some members that need it. + { + // Create the chart parameters and let the default be a bar chart + // with 3D looks. + m_params = new KChartParams( this ); + m_params->setChartType( KChartParams::Bar ); + m_params->setBarChartSubType( KChartParams::BarNormal ); + m_params->setThreeDBars( true ); + + //Changed this to use columns rather than rows by default + //because I believe that this is the more common format for + //entering data (you can see this looking at the fact that + //most spreadsheet packages allow far more rows than columns) + //-- Robert Knight + + // Handle data in columns by default + m_params->setDataDirection( KChartParams::DataColumns ); + } + + (void)new WizardExt( this ); + m_bCanChangeValue = true; + + // Display parameters + m_displayData = m_currentData; + + // Set the size to minimal. + initEmpty(); +} + + +KChartPart::~KChartPart() +{ + //kdDebug(35001) << "Part is going to be destroyed now!!!" << endl; + delete m_params; +} + + +// Reimplement KoDocument::initDoc() + +bool KChartPart::initDoc(InitDocFlags flags, TQWidget* parentWidget) +{ + // Initialize the parameter set for this chart document +#if 0 + kdDebug(35001) << "================================================================" << endl; + kdDebug(35001) << "InitDOC: flags = " << flags << endl; + kdDebug(35001) << "================================================================" << endl; +#endif + + TQString f; + + // Embedded documents are initially created like a normal empty + // document. If this is in KSpread or another program where the + // data is external then the document will be updated later on in + // the creation process anyway. + if (flags == KoDocument::InitDocEmbedded) { + initEmpty(); + return true; + } + + // If we are supposed to create a new, empty document, then do so. + if (flags == KoDocument::InitDocEmpty) { + initEmpty(); + return true; + } + + KoTemplateChooseDia::ReturnType ret; + KoTemplateChooseDia::DialogType dlgtype; + + // If we must create a new document, then only present templates + // to the user, otherwise also present existing documents and + // recent documents. + if (flags == KoDocument::InitDocFileNew ) + dlgtype = KoTemplateChooseDia::OnlyTemplates; + else + dlgtype = KoTemplateChooseDia::Everything; + ret = KoTemplateChooseDia::choose( KChartFactory::global(), f, + dlgtype, "kchart_template", + parentWidget ); + + if ( ret == KoTemplateChooseDia::File ) { + KURL url( f ); + return openURL( url ); + } + else if ( ret == KoTemplateChooseDia::Empty ) { + initEmpty(); + return true; + } + else if ( ret == KoTemplateChooseDia::Template ) { + //TODO: Activate this for KOffice 1.5/2.0 +// if ( f.endsWith("/templates/chart/.source/BarChart.chrt") ) { +// generateBarChartTemplate(); +// return true; +// } + TQFileInfo fileInfo( f ); + TQString fileName( fileInfo.dirPath( true ) + "/" + + fileInfo.baseName() + ".chrt" ); + + resetURL(); + bool ok = loadNativeFormat( fileName ); + if ( !ok ) + showLoadingErrorDialog(); + setEmpty(); + //initConfig(); + return ok; + } + + return false; +} + +void KChartPart::initEmpty() +{ + initNullChart(); + + resetURL(); + setEmpty(); +} + + +// This method creates the simplest chart imaginable: +// Data size 1x1, empty, no headers +// +void KChartPart::initNullChart() +{ + // Fill cells with data if there is none. + //kdDebug(35001) << "Initialize null chart." << endl; + + // Empty data. Note, we don't use (0,0) or (1,1) for the size + // here, because otherwise KDChart won't draw anything + m_currentData.expand(2, 2); + m_params->setFirstRowAsLabel(false); + m_params->setFirstColAsLabel(false); + + // Fill column and row labels. + m_colLabels << TQString(""); + m_rowLabels << TQString(""); + + setChartDefaults(); + + m_params->setDrawSolidExcessArrows(true); +} + + +void KChartPart::generateBarChartTemplate() +{ + int col; + int row; + + kdDebug()<<"KChartPart::initTestChart()\n"; + + // Fill cells with data if there is none. + if (m_currentData.rows() == 0) { + //kdDebug(35001) << "Initialize with some data!!!" << endl; + m_currentData.expand( 4, 4 ); + m_currentData.setUsedRows( 4 ); + m_currentData.setUsedCols( 4 ); + for (row = 0; row < 4; row++) { + for (col = 0; col < 4; col++) { + m_currentData.setCell(row, col, + static_cast (row + col)); + + // Fill column label, but only on the first iteration. + if (row == 0) { + m_colLabels << i18n("Column %1").arg(col + 1); + } + } + + // Fill row label. + m_rowLabels << i18n("Row %1").arg(row + 1); + } + } + + setChartDefaults(); + // FIXME: Should this go into setChartDefaults()? + m_params->setDrawSolidExcessArrows(true); +} + + +KoView* KChartPart::createViewInstance( TQWidget* parent, const char* name ) +{ + return new KChartView( this, parent, name ); +} + + +// ================================================================ +// Painting + + +void KChartPart::paintContent( TQPainter& painter, const TQRect& rect, + bool /*transparent*/, + double /*zoomX*/, double /*zoomY*/ ) +{ + int numDatasets; + + // If params is 0, initDoc() has not been called. + Q_ASSERT( m_params != 0 ); + + KDChartAxisParams xAxisParms; + xAxisParms = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + // Handle data in rows or columns. + // + // This means getting row or column headers from the document and + // set them as X axis labels or legend according to the current + // setting. Also, transpose the data if it should be displayed in + // columns instead of in rows. + + + // Create the displayData table. + numDatasets = createDisplayData(); + + // Create and set the axis labels and legend. + TQStringList longLabels; + TQStringList shortLabels; + createLabelsAndLegend(longLabels, shortLabels); + + // Set the x axis labels. + xAxisParms.setAxisLabelStringLists( &longLabels, &shortLabels ); + m_params->setAxisParams(KDChartAxisParams::AxisPosBottom, xAxisParms); + + + // Handle some types or subtypes of charts specially, notably: + // - Bar charts with lines in them + + if ( m_params->chartType() == KChartParams::Bar) { + if ( m_params->barNumLines() > 0 ) { + + // If this is a bar chart and the user wants a few lines in + // it, we need to create an additional chart in the same + // drawing area. + + // Specify that we want to have an additional chart. + m_params->setAdditionalChartType( KDChartParams::Line ); + + const int numBarDatasets = numDatasets - m_params->barNumLines(); + + // Assign the datasets to the charts: DataEntry, from, to, chart# + m_params->setChartSourceMode( KDChartParams::DataEntry, + 0, numBarDatasets - 1, + 0 ); // The bar chart + m_params->setChartSourceMode( KDChartParams::DataEntry, + numBarDatasets, numDatasets - 1, + 1 ); // The line chart + } + else { + // Otherwise we don't want any extra chart. + m_params->setAdditionalChartType( KDChartParams::NoType ); + } + } + + // Ok, we have now created a data set for display, and params with + // suitable legends and axis labels. Now start the real painting. + + // Handle transparency. + // Wrong: this flickers; better do this as part of the double-buffering. + //if ( !transparent ) + // painter.eraseRect( rect ); + + // ## TODO: support zooming + + // Double-buffering + if ( m_bufferPixmap.width() < rect.width() + || m_bufferPixmap.height() < rect.height() ) + { + m_bufferPixmap.resize( rect.size() ); + } + + TQPainter bufferPainter( &m_bufferPixmap ); + + // We only need to draw the document rectangle "rect". + KDChart::paint( &bufferPainter, m_params, &m_displayData, 0, &rect ); + + // This is always the empty rect... + // Shouldn't creating a TQPainter in a paintEvent set up clipping automatically? + // I thought it did (DF) + //const TQRect clipRect = painter.clipRegion().boundingRect(); + //painter.drawPixmap( clipRect.topLeft(), m_bufferPixmap, clipRect ); + + painter.drawPixmap( 0, 0, m_bufferPixmap ); +} + + +// Create the data table m_displayData from m_currentData, taking into +// account if the first row or line contains headers. The chart type +// HiLo demands special handling. +// +// Return number of datasets. +// +// Note: While the current KD Chart 1.1.3 version is still expecting data +// to be in rows, the upcoming KD Chart 2.0 release will be using +// data in columns instead, to it will be matching KSpread's way. +// -khz, 2005-11-15 +// +// FIXME: Rewrite so that we only copy data when necessary. +// On the other hand, the next version of KDChart is able to +// get data directly without storing it into a KDChartData +// class first, so we might never need to. +// +int KChartPart::createDisplayData() +{ + int rowOffset = 0; + int colOffset = 0; + int numDatasets = 0; + + if ( !canChangeValue() ) { + if ( m_params->firstRowAsLabel() ) + rowOffset++; + if ( m_params->firstColAsLabel() ) + colOffset++; + } + + // After this sequence, m_DisplayData contains the data in the + // correct transposition, and the X axis and the legend contain + // the correct labels. + TQVariant value1; + TQVariant value2; + int prop; + if (m_params->dataDirection() == KChartParams::DataRows) { + // Data is handled in rows. This is the way KDChart works also. + + numDatasets = m_currentData.usedRows() - rowOffset; + m_displayData.expand( numDatasets, + m_currentData.usedCols() - colOffset ); + + // Remove the first row and/or col if they are used for headers. + for (uint row = rowOffset; row < m_currentData.usedRows(); row++) { + for (uint col = colOffset; col < m_currentData.usedCols(); col++) { + if ( m_currentData.cellContent( row, col, + value1, value2, prop ) ) { + m_displayData.setCell(row - rowOffset, col - colOffset, + value1, value2); + m_displayData.setProp(row - rowOffset, col - colOffset, + prop); + } + } + } + } + else { + // Data is handled in columns. We will have to transpose + // everything since KDChart wants its data in rows. + + // Resize displayData so that the transposed data has room. + numDatasets = m_currentData.usedCols() - colOffset; + m_displayData.expand( numDatasets, + m_currentData.usedRows() - rowOffset ); + + // Copy data and transpose it. + for (uint row = colOffset; row < m_currentData.usedCols(); row++) { + for (uint col = rowOffset; col < m_currentData.usedRows(); col++) { + if ( m_currentData.cellContent( col, row, + value1, value2, prop ) ) { + m_displayData.setCell(row - colOffset, col - rowOffset, + value1, value2); + m_displayData.setProp(row - colOffset, col - rowOffset, + prop); + } + } + } + } + + // If this is a HiLo chart, we need to manually create the correct + // values. This is not done by KDChart. + // + // Here we don't need to transpose, since we can start from the + // newly generated displayData. + if (m_params->chartType() == KChartParams::HiLo) { + KDChartTableData tmpData = m_displayData; + + // Calculate the min, max, open and close values for each row. + m_displayData.expand(tmpData.usedRows(), 4); + for (uint row = 0; row < tmpData.usedRows(); row++) { + double minVal = DBL_MAX; + double maxVal = -DBL_MAX; + + // Calculate min and max for this row. + // + // Note that we have already taken care of different data + // directions above. + for (uint col = 0; col < tmpData.usedCols(); col++) { + double data = tmpData.cellVal(row, col).toDouble(); + + if (data < minVal) + minVal = data; + if (data > maxVal) + maxVal = data; + } + m_displayData.setCell(row, 0, minVal); // min + m_displayData.setCell(row, 1, maxVal); // max + m_displayData.setCell(row, 2, tmpData.cellVal(row, 0).toDouble()); // open + m_displayData.setCell(row, 3, // close + tmpData.cellVal(row, tmpData.usedCols() - 1).toDouble()); + } + } + + return numDatasets; +} + + +void KChartPart::createLabelsAndLegend( TQStringList &longLabels, + TQStringList &shortLabels ) +{ + longLabels.clear(); + shortLabels.clear(); + + const uint dataColumnCount = m_currentData.cols(); + const uint dataRowCount = m_currentData.rows(); + const uint columnLabelCount = m_colLabels.count(); + const uint rowLabelCount = m_rowLabels.count(); + + // Handle HiLo charts separately. + if (m_params->chartType() == KChartParams::HiLo) { + + // FIXME: In a HiLo chart, the Legend should be the same as the + // labels on the X Axis. Should we disable one of them? + + // Set the correct X axis labels and legend. + longLabels.clear(); + shortLabels.clear(); + if (m_params->dataDirection() == KChartParams::DataRows) { + + // If data are in rows, then the X axis labels should be + // taken from the row headers. + for ( uint row = 0; row < dataRowCount ; row++ ) { + + TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); + + longLabels << label; + shortLabels << label.left( 3 ); + } + } + else { + // If data are in columns, then the X axis labels should + // be taken from the column headers. + for ( uint col = 0; col < dataColumnCount; col++ ) { + + TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); + + longLabels << m_colLabels[col]; + shortLabels << m_colLabels[col].left( 3 ); + } + } + } + else if (m_params->dataDirection() == KChartParams::DataRows) { + // Data is handled in rows. This is the way KDChart works also. + + // Set X axis labels from column headers. + for ( uint col = 0; col < dataColumnCount; col++ ) { + + TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); + + longLabels << label; + shortLabels << label.left( 3 ); + } + + // Set legend from row headers. + for ( uint row = 0; row < dataRowCount; row++ ) { + TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); + + m_params->setLegendText( row, label ); + } + } + else { + // Data is handled in columns. + + // Set X axis labels from row headers. + for ( uint row = 0; row < dataRowCount; row++ ) { + + TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString(); + + longLabels << label; + shortLabels << label.left( 3 ); + } + + // Set legend from column headers. + for ( uint col = 0; col < dataColumnCount ; col++ ) { + TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString(); + + m_params->setLegendText( col, label ); + } + } +} + + + +// ================================================================ + + +void KChartPart::analyzeHeaders() +{ +#if 0 + analyzeHeaders( m_currentData ); +#else + doSetData( m_currentData, + m_params->firstRowAsLabel(), m_params->firstColAsLabel()); +#endif +} + + +// This function sets the data from an external source. It is called, +// for instance, when the chart is initialized from a spreadsheet in +// KSpread. +// +void KChartPart::analyzeHeaders( const KDChartTableData& data ) +{ + // FIXME(khz): replace this when automatic string detection works in KDChart + // Does the top/left cell contain a string? + bool isStringTopLeft = (data.cellVal( 0, 0 ).type() == TQVariant::String); + + // Does the first row (without first cell) contain only strings? + bool isStringFirstRow = true; + for ( uint col = 1; isStringFirstRow && col < data.cols(); col++ ) { + isStringFirstRow = (data.cellVal( 0, col ).type() == TQVariant::String); + } + + // Just in case, we only have 1 row, we never use it for label text. + // This prevents a crash. + // + // FIXME: Wonder if this is still true for KDChart 1.1.3 / iw + // Disabling... +#if 1 + if ( data.rows() == 1 ) + isStringFirstRow = false; +#endif + + // Does the first column (without first cell) contain only strings? + bool isStringFirstCol = true; + for ( uint row = 1; isStringFirstCol && row < data.rows(); row++ ) { + isStringFirstCol = (data.cellVal( row, 0 ).type() == TQVariant::String); + } + + // Just in case, we only have 1 column, we never use it for axis + // label text => prevents crash. +#if 1 + if ( data.cols() == 1 ) + isStringFirstRow = FALSE; +#endif + + bool hasColHeader = false; + bool hasRowHeader = false; + + // Let's check if we have a full axis label text column + if ( isStringFirstCol && isStringTopLeft + || isStringFirstCol && isStringFirstRow ) + hasColHeader = true; + + // Let's check if we have a full label text row. + if ( isStringFirstRow && isStringTopLeft + || isStringFirstCol && isStringFirstRow ) + hasRowHeader = true; + + m_params->setFirstRowAsLabel( hasRowHeader ); + m_params->setFirstColAsLabel( hasColHeader ); + + doSetData(data, hasRowHeader, hasColHeader); +} + + + +void KChartPart::doSetData( const KDChartTableData& data, + bool firstRowHeader, + bool firstColHeader ) +{ + uint rowStart = 0; + uint colStart = 0; + uint col; + uint row; + + // From this point, we know that the labels and legend are going + // to be taken from the data if firstRowHeader or firstColheader + // is true. + + if (firstRowHeader) + rowStart = 1; + if (firstColHeader) + colStart = 1; + + // Generate m_rowlabels from the column headers if applicable. + m_rowLabels.clear(); + if ( firstColHeader ) { + for( row = rowStart; row < data.rows(); row++ ) { + m_rowLabels << data.cellVal( row, 0 ).toString(); + } + } + else { + for( row = rowStart; row < data.rows(); row++ ) + m_rowLabels << ""; + + // FIXME: Check what this does, and if we don't have to check + // the data order (rows / cols). + m_params->setLegendSource( KDChartParams::LegendAutomatic ); + } + + // Generate X labels from the row headers if applicable + m_colLabels.clear(); + if ( firstRowHeader ) { + for( col = colStart; col < data.cols(); col++ ) { + m_colLabels << data.cellVal( 0, col ).toString(); + } + } + else { + for( col = colStart; col < data.cols(); col++ ) + m_colLabels << ""; + } + + // Doesn't hurt if data == m_currentData, but necessary if not. + m_currentData = data; + + //setChartDefaults(); + + emit docChanged(); +} + + +void KChartPart::resizeData( int rows, int cols ) +{ + m_currentData.expand( rows, cols ); + m_currentData.setUsedRows( rows ); + m_currentData.setUsedCols( cols ); +} + + +void KChartPart::setCellData( int row, int column, const TQVariant &val) +{ + m_currentData.setCell( row, column, val ); +} + + +bool KChartPart::showWizard( TQString &dataArea ) +{ + KChartWizard *wizard = new KChartWizard( this, m_parentWidget, "wizard" ); + + connect( wizard, TQT_SIGNAL(finished()), this, TQT_SLOT(slotModified()) ); + + wizard->setDataArea( dataArea ); + + bool ret = wizard->exec(); + + delete wizard; + return ret; +} + + +void KChartPart::initLabelAndLegend() +{ + // Labels and legends are automatically initialized to reasonable + // default values in KDChart +} + + +// Set up some values for the chart Axis, that are not well chosen by +// default by KDChart. +// + +void KChartPart::setChartDefaults() +{ + // + // Settings for the Y axis. + // + KDChartAxisParams yAxis; + yAxis = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + + // decimal symbol and thousands separator + yAxis.setAxisLabelsRadix( TDEGlobal::locale()->decimalSymbol(), + TDEGlobal::locale()->thousandsSeparator() ); + + m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, yAxis ); + + // + // Settings for the X axis. + // + KDChartAxisParams xAxis; + xAxis = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + // These two shouldn't be necessary to set. + xAxis.setAxisFirstLabelText(); + xAxis.setAxisLastLabelText(); + + m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, xAxis ); + + // Other parameters for various things. + m_params->setLineColor(); + + // Setting the background layer. + KDFrame frame; + frame.setBackground( TQBrush( TQColor( 230, 222, 222 ) ) ); + m_params->setFrame( KDChartEnums::AreaInnermost, frame, 0, 0, 0, 0 ); +} + + +// ================================================================ +// Loading and Storing + + +// ---------------------------------------------------------------- +// Save and Load program configuration + + + +void KChartPart::loadConfig( TDEConfig *conf ) +{ + conf->setGroup("ChartParameters"); + + // TODO: the fonts + // PENDING(kalle) Put the applicable ones of these back in + // TQFont tempfont; + // tempfont = conf->readFontEntry("titlefont", &titlefont); + // setTitleFont(tempfont); + // tempfont = conf->readFontEntry("ytitlefont", &ytitlefont); + // setYTitleFont(tempfont); + // tempfont = conf->readFontEntry("xtitlefont", &xtitlefont); + // setXTitleFont(tempfont); + // tempfont = conf->readFontEntry("yaxisfont", &yaxisfont); + // setYAxisFont(tempfont); + // tempfont = conf->readFontEntry("xaxisfont", &xaxisfont); + // setXAxisFont(tempfont); + // tempfont = conf->readFontEntry("labelfont", &labelfont); + // setLabelFont(tempfont); + // tempfont = conf->readFontEntry("annotationfont", &annotationfont); + // setAnnotationFont(tempfont); + + // ylabel_fmt = conf->readEntry("ylabel_fmt", ylabel_fmt ); + // ylabel2_fmt = conf->readEntry("ylabel2_fmt", ylabel2_fmt); + // xlabel_spacing = conf->readNumEntry("xlabel_spacing"); + // ylabel_density = conf->readNumEntry("ylabel_density", ylabel_density); + // requested_ymin = conf->readDoubleNumEntry("requested_ymin", requested_ymin); + // requested_ymax = conf->readDoubleNumEntry("requested_ymax", requested_ymax ); + // requested_yinterval = conf->readDoubleNumEntry("requested_yinterval", + // requested_yinterval); + // shelf = conf->readBoolEntry("shelf", shelf); + // grid = conf->readBoolEntry("grid", grid); + // xaxis = conf->readBoolEntry("xaxis", xaxis); + // yaxis = conf->readBoolEntry("yaxis", yaxis); + // yaxis2 = conf->readBoolEntry("yaxis2", yaxis); + // llabel = conf->readBoolEntry("llabel", llabel); + // yval_style = conf->readNumEntry("yval_style", yval_style); + // stack_type = (KChartStackType)conf->readNumEntry("stack_type", stack_type); + m_params->setLineMarker(conf->readBoolEntry("lineMarker", + m_params->lineMarker())); + m_params->setThreeDBarDepth( conf->readDoubleNumEntry("_3d_depth", + m_params->threeDBarDepth() ) ); + m_params->setThreeDBarAngle( conf->readNumEntry( "_3d_angle", + m_params->threeDBarAngle() ) ); + + KDChartAxisParams leftparams; + leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams rightparams; + rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparams; + bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + bottomparams.setAxisLineColor( conf->readColorEntry( "XTitleColor", 0 ) ); + leftparams.setAxisLineColor( conf->readColorEntry( "YTitleColor", 0 ) ); + rightparams.setAxisLineColor( conf->readColorEntry( "YTitle2Color", 0 ) ); + bottomparams.setAxisLabelsColor( conf->readColorEntry( "XLabelColor", 0 ) ); + leftparams.setAxisLabelsColor( conf->readColorEntry( "YLabelColor", 0 ) ); + rightparams.setAxisLabelsColor( conf->readColorEntry( "YLabel2Color", 0 ) ); + leftparams.setAxisGridColor( conf->readColorEntry( "GridColor", 0 ) ); + m_params->setOutlineDataColor( conf->readColorEntry( "LineColor", 0 ) ); + m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, + leftparams ); + m_params->setAxisParams( KDChartAxisParams::AxisPosRight, + rightparams ); + m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, + bottomparams ); + + // hlc_style = (KChartHLCStyle)conf->readNumEntry("hlc_style", hlc_style); + // hlc_cap_width = conf->readNumEntry("hlc_cap_width", hlc_cap_width); + // // TODO: Annotation font + // num_scatter_pts = conf->readNumEntry("num_scatter_pts", num_scatter_pts); + // // TODO: Scatter type + // thumbnail = conf->readBoolEntry("thumbnail", thumbnail); + // thumblabel = conf->readEntry("thumblabel", thumblabel); + // border = conf->readBoolEntry("border", border); + // BGColor = conf->readColorEntry("BGColor", &BGColor); + // PlotColor = conf->readColorEntry("PlotColor", &PlotColor); + // VolColor = conf->readColorEntry("VolColor", &VolColor); + // EdgeColor = conf->readColorEntry("EdgeColor", &EdgeColor); + // loadColorArray(conf, &SetColor, "SetColor"); + // loadColorArray(conf, &ExtColor, "ExtColor"); + // loadColorArray(conf, &ExtVolColor, "ExtVolColor"); + // transparent_bg = conf->readBoolEntry("transparent_bg", transparent_bg); + // // TODO: explode, missing + // percent_labels = (KChartPercentType)conf->readNumEntry("percent_labels", + // percent_labels); + // label_dist = conf->readNumEntry("label_dist", label_dist); + // label_line = conf->readBoolEntry("label_line", label_line); + m_params->setChartType( (KChartParams::ChartType)conf->readNumEntry( "type", m_params->chartType() ) ); + // other_threshold = conf->readNumEntry("other_threshold", other_threshold); + + // backgroundPixmapName = conf->readPathEntry( "backgroundPixmapName" ); + // if( !backgroundPixmapName.isNull() ) { + // backgroundPixmap.load( locate( "wallpaper", backgroundPixmapName )); + // backgroundPixmapIsDirty = true; + // } else + // backgroundPixmapIsDirty = false; + // backgroundPixmapScaled = conf->readBoolEntry( "backgroundPixmapScaled", true ); + // backgroundPixmapCentered = conf->readBoolEntry( "backgroundPixmapCentered", true ); + // backgroundPixmapIntensity = conf->readDoubleNumEntry( "backgroundPixmapIntensity", 0.25 ); +} + + +void KChartPart::defaultConfig( ) +{ + delete m_params; + m_params = new KChartParams( this ); + setChartDefaults(); +} + + +void KChartPart::saveConfig( TDEConfig *conf ) +{ + conf->setGroup("ChartParameters"); + + // PENDING(kalle) Put some of these back in + // the fonts + // conf->writeEntry("titlefont", titlefont); + // conf->writeEntry("ytitlefont", ytitlefont); + // conf->writeEntry("xtitlefont", xtitlefont); + // conf->writeEntry("yaxisfont", yaxisfont); + // conf->writeEntry("xaxisfont", xaxisfont); + // conf->writeEntry("labelfont", labelfont); + + // conf->writeEntry("ylabel_fmt", ylabel_fmt); + // conf->writeEntry("ylabel2_fmt", ylabel2_fmt); + // conf->writeEntry("xlabel_spacing", xlabel_spacing); + // conf->writeEntry("ylabel_density", ylabel_density); + // conf->writeEntry("requested_ymin", requested_ymin); + // conf->writeEntry("requested_ymax", requested_ymax); + // conf->writeEntry("requested_yinterval", requested_yinterval); + + // conf->writeEntry("shelf", shelf); + // conf->writeEntry("grid", grid ); + // conf->writeEntry("xaxis", xaxis); + // conf->writeEntry("yaxis", yaxis); + // conf->writeEntry("yaxis2", yaxis2); + // conf->writeEntry("llabel", llabel); + // conf->writeEntry("yval_style", yval_style ); + // conf->writeEntry("stack_type", (int)stack_type); + + conf->writeEntry( "_3d_depth", m_params->threeDBarDepth() ); + conf->writeEntry( "_3d_angle", m_params->threeDBarAngle() ); + + KDChartAxisParams leftparams; + leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft ); + KDChartAxisParams rightparams; + rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight ); + KDChartAxisParams bottomparams; + bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + conf->writeEntry( "LineColor", m_params->outlineDataColor() ); + conf->writeEntry( "XTitleColor", bottomparams.axisLineColor() ); + conf->writeEntry( "YTitleColor", leftparams.axisLineColor() ); + conf->writeEntry( "YTitle2Color", rightparams.axisLineColor() ); + conf->writeEntry( "XLabelColor", bottomparams.axisLabelsColor() ); + conf->writeEntry( "YLabelColor", leftparams.axisLabelsColor() ); + conf->writeEntry( "YLabel2Color", rightparams.axisLabelsColor() ); + conf->writeEntry( "GridColor", leftparams.axisGridColor() ); + + // conf->writeEntry("hlc_style", (int)hlc_style); + // conf->writeEntry("hlc_cap_width", hlc_cap_width ); + // // TODO: Annotation type!!! + // conf->writeEntry("annotationfont", annotationfont); + // conf->writeEntry("num_scatter_pts", num_scatter_pts); + // // TODO: Scatter type!!! + // conf->writeEntry("thumbnail", thumbnail); + // conf->writeEntry("thumblabel", thumblabel); + // conf->writeEntry("thumbval", thumbval); + // conf->writeEntry("border", border); + // conf->writeEntry("BGColor", BGColor); + // conf->writeEntry("PlotColor", PlotColor); + // conf->writeEntry("VolColor", VolColor); + // conf->writeEntry("EdgeColor", EdgeColor); + // saveColorArray(conf, &SetColor, "SetColor"); + // saveColorArray(conf, &ExtColor, "ExtColor"); + // saveColorArray(conf, &ExtVolColor, "ExtVolColor"); + + + // conf->writeEntry("transparent_bg", transparent_bg); + // // TODO: explode, missing + // conf->writeEntry("percent_labels",(int) percent_labels ); + // conf->writeEntry("label_dist", label_dist); + // conf->writeEntry("label_line", label_line); + conf->writeEntry( "type", (int) m_params->chartType() ); + // conf->writeEntry("other_threshold", other_threshold); + + // background pixmap stuff + // if( !backgroundPixmapName.isNull() ) + // conf->writePathEntry( "backgroundPixmapName", backgroundPixmapName ); + // conf->writeEntry( "backgroundPixmapIsDirty", backgroundPixmapIsDirty ); + // conf->writeEntry( "backgroundPixmapScaled", backgroundPixmapScaled ); + // conf->writeEntry( "backgroundPixmapCentered", backgroundPixmapCentered ); + // conf->writeEntry( "backgroundPixmapIntensity", backgroundPixmapIntensity ); + conf->writeEntry( "lineMarker", (int) m_params->lineMarker()); +} + + +// ---------------------------------------------------------------- +// Save and Load OpenDocument file format + + +bool KChartPart::loadOasis( const TQDomDocument& doc, + KoOasisStyles& oasisStyles, + const TQDomDocument& /*settings*/, + KoStore *store ) +{ + kdDebug(35001) << "kchart loadOasis called" << endl; + + // Set some sensible defaults. + setChartDefaults(); + + TQDomElement content = doc.documentElement(); + TQDomElement bodyElem ( KoDom::namedItemNS( content, + KoXmlNS::office, "body" ) ); + if ( bodyElem.isNull() ) { + kdError(32001) << "No office:body found!" << endl; + setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) ); + return false; + } + + // Get the office:chart element. + TQDomElement officeChartElem = KoDom::namedItemNS( bodyElem, + KoXmlNS::office, "chart" ); + if ( officeChartElem.isNull() ) { + kdError(32001) << "No office:chart found!" << endl; + TQDomElement childElem; + TQString localName; + forEachElement( childElem, bodyElem ) { + localName = childElem.localName(); + } + + if ( localName.isEmpty() ) + setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No tag found inside office:body." ) ); + else + setErrorMessage( i18n( "This document is not a chart, but %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) ); + + return false; + } + + TQDomElement chartElem = KoDom::namedItemNS( officeChartElem, + KoXmlNS::chart, "chart" ); + if ( chartElem.isNull() ) { + setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No chart:chart tag found." ) ); + return false; + } + + // Get the loading context and stylestack from the styles. + KoOasisLoadingContext loadingContext( this, oasisStyles, store ); + //KoStyleStack &styleStack = loadingContext.styleStack(); + +#if 0 // Example code!! + // load chart properties into the stylestack. + styleStack.save(); + styleStack.setTypeProperties( "chart" ); // load chart properties + loadingContext.fillStyleStack( chartElem, KoXmlNS::chart, "style-name" ); + + const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw, "fill-color" ); + kdDebug() << "fillColor=" << fillColor << endl; + + styleStack.restore(); +#endif + + // Load chart parameters, most of these are stored in the + // chart:plot-area element within chart:chart. + TQString errorMessage; + bool ok = m_params->loadOasis( chartElem, loadingContext, errorMessage, + store); + if ( !ok ) { + setErrorMessage( errorMessage ); + return false; + } + + // TODO Load data direction (see loadAuxiliary) + + // Load the data table. + TQDomElement tableElem = KoDom::namedItemNS( chartElem, + KoXmlNS::table, "table" ); + if ( !tableElem.isNull() ) { + ok = loadOasisData( tableElem ); + if ( !ok ) + return false; // TODO setErrorMessage + } + + return true; +} + + +bool KChartPart::loadOasisData( const TQDomElement& tableElem ) +{ + int numberHeaderColumns = 0; + TQDomElement tableHeaderColumns = KoDom::namedItemNS( tableElem, + KoXmlNS::table, + "table-header-columns" ); + + TQDomElement elem; + forEachElement( elem, tableHeaderColumns ) { + if ( elem.localName() == "table-column" ) { + int repeated = elem.attributeNS( KoXmlNS::table, "number-columns-repeated", TQString() ).toInt(); + numberHeaderColumns += TQMAX( 1, repeated ); + } + } + + // With 0 you get no titles, and with more than 1 we ignore the others. + Q_ASSERT( numberHeaderColumns == 1 ); + + int numberDataColumns = 0; + TQDomElement tableColumns = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-columns" ); + forEachElement( elem, tableColumns ) { + if ( elem.localName() == "table-column" ) { + int repeated = elem.attributeNS( KoXmlNS::table, "number-columns-repeated", TQString() ).toInt(); + numberDataColumns += TQMAX( 1, repeated ); + } + } + + // Parse table-header-rows for the column names. + m_colLabels.clear(); + TQDomElement tableHeaderRows = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-header-rows" ); + if ( tableHeaderRows.isNull() ) + kdWarning(35001) << "No table-header-rows element found!" << endl; + TQDomElement tableHeaderRow = KoDom::namedItemNS( tableHeaderRows, KoXmlNS::table, "table-row" ); + if ( tableHeaderRow.isNull() ) + kdWarning(35001) << "No table-row inside table-header-rows!" << endl; + + int cellNum = 0; + forEachElement( elem, tableHeaderRow ) { + if ( elem.localName() == "table-cell" ) { + ++cellNum; + if ( cellNum > numberHeaderColumns ) { + TQDomElement pElem = KoDom::namedItemNS( elem, KoXmlNS::text, "p" ); + m_colLabels.append( pElem.text() ); + } + } + } + numberDataColumns = TQMAX( numberDataColumns, cellNum - numberHeaderColumns ); + if ( (int)m_colLabels.count() != numberDataColumns ) + kdWarning(35001) << "Got " << m_colLabels.count() + << " column titles, expected " << numberDataColumns + << endl; + + // Get the number of rows, and read row labels + int numberDataRows = 0; + TQDomElement tableRows = KoDom::namedItemNS( tableElem, KoXmlNS::table, "table-rows" ); + + m_rowLabels.clear(); + forEachElement( elem, tableRows ) { + if ( elem.localName() == "table-row" ) { + int repeated = elem.attributeNS( KoXmlNS::table, "number-rows-repeated", TQString() ).toInt(); + Q_ASSERT( repeated <= 1 ); // we don't handle yet the case where data rows are repeated (can this really happen?) + numberDataRows += TQMAX( 1, repeated ); + if ( numberHeaderColumns > 0 ) { + TQDomElement firstCell = KoDom::namedItemNS( elem, KoXmlNS::table, "table-cell" ); + TQDomElement pElem = KoDom::namedItemNS( firstCell, KoXmlNS::text, "p" ); + m_rowLabels.append( pElem.text() ); + } + } + } + + kdDebug(35001) << "numberHeaderColumns=" << numberHeaderColumns + << " numberDataColumns=" << numberDataColumns + << " numberDataRows=" << numberDataRows << endl; + + if ( (int)m_rowLabels.count() != numberDataRows) + kdWarning(35001) << "Got " << m_rowLabels.count() + << " row labels, expected " << numberDataRows << endl; + + m_currentData.expand( numberDataRows, numberDataColumns ); + m_currentData.setUsedCols( numberDataColumns ); + m_currentData.setUsedRows( numberDataRows ); + + // Now really load the cells. + int row = 0; + TQDomElement rowElem; + forEachElement( rowElem, tableRows ) { + if ( rowElem.localName() == "table-row" ) { + int col = 0; + int cellNum = 0; + TQDomElement cellElem; + forEachElement( cellElem, rowElem ) { + if ( cellElem.localName() == "table-cell" ) { + ++cellNum; + if ( cellNum > numberHeaderColumns ) { + TQString valueType = cellElem.attributeNS( KoXmlNS::office, "value-type", TQString() ); + if ( valueType != "float" ) + kdWarning(35001) << "Don't know how to handle value-type " << valueType << endl; + else { + TQString value = cellElem.attributeNS( KoXmlNS::office, "value", TQString() ); + double val = value.toDouble(); + + m_currentData.setCell( row, col, val ); + } + ++col; + } + } + } + ++row; + } + } + + return true; +} + + +bool KChartPart::saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) +{ + manifestWriter->addManifestEntry( "content.xml", "text/xml" ); + KoOasisStore oasisStore( store ); + + KoXmlWriter* contentWriter = oasisStore.contentWriter(); + if ( !contentWriter ) + return false; + + KoGenStyles mainStyles; + + KoXmlWriter* bodyWriter = oasisStore.bodyWriter(); + bodyWriter->startElement( "office:body" ); + bodyWriter->startElement( "office:chart" ); + bodyWriter->startElement( "chart:chart" ); + + // Indent to indicate that this is inside some tags. + { + // Saves chart class, title, legend, plot-area + m_params->saveOasis( bodyWriter, mainStyles ); + + // Save the data table. + saveOasisData( bodyWriter, mainStyles ); + } + + bodyWriter->endElement(); // chart:chart + bodyWriter->endElement(); // office:chart + bodyWriter->endElement(); // office:body + + contentWriter->startElement( "office:automatic-styles" ); + writeAutomaticStyles( *contentWriter, mainStyles ); + contentWriter->endElement(); // office:automatic-styles + + oasisStore.closeContentWriter(); + + // Done with content.xml + +#if 0 + if ( !store->open( "styles.xml" ) ) + return false; + manifestWriter->addManifestEntry( "styles.xml", "text/xml" ); + saveOasisDocumentStyles( store, mainStyles, savingContext, saveFlag, + headerFooterContent ); + if ( !store->close() ) // done with styles.xml + return false; +#endif + + return true; +} + + +void KChartPart::saveOasisData( KoXmlWriter* bodyWriter, + KoGenStyles& mainStyles ) const +{ + Q_UNUSED( mainStyles ); + + const int cols = m_currentData.usedCols() + ? TQMIN(m_currentData.usedCols(), m_currentData.cols()) + : m_currentData.cols(); + const int rows = m_currentData.usedRows() + ? TQMIN(m_currentData.usedRows(), m_currentData.rows()) + : m_currentData.rows(); + + bodyWriter->startElement( "table:table" ); + bodyWriter->addAttribute( "table:name", "local-table" ); + + // Exactly one header column, always. + bodyWriter->startElement( "table:table-header-columns" ); + bodyWriter->startElement( "table:table-column" ); + bodyWriter->endElement(); // table:table-column + bodyWriter->endElement(); // table:table-header-columns + + // Then "cols" columns + bodyWriter->startElement( "table:table-columns" ); + bodyWriter->startElement( "table:table-column" ); + bodyWriter->addAttribute( "table:number-columns-repeated", cols ); + bodyWriter->endElement(); // table:table-column + bodyWriter->endElement(); // table:table-columns + + // Exactly one header row, always. + bodyWriter->startElement( "table:table-header-rows" ); + bodyWriter->startElement( "table:table-row" ); + + // The first column in header row is just the header column - no title needed + bodyWriter->startElement( "table:table-cell" ); + bodyWriter->addAttribute( "office:value-type", "string" ); + bodyWriter->startElement( "text:p" ); + bodyWriter->endElement(); // text:p + bodyWriter->endElement(); // table:table-cell + + // Save column labels in the first header row, for instance: + // + // Column 1 + // + TQStringList::const_iterator colLabelIt = m_colLabels.begin(); + for ( int col = 0; col < cols ; ++col ) { + if ( colLabelIt != m_colLabels.end() ) { + bodyWriter->startElement( "table:table-cell" ); + bodyWriter->addAttribute( "office:value-type", "string" ); + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( *colLabelIt ); + bodyWriter->endElement(); // text:p + bodyWriter->endElement(); // table:table-cell + ++colLabelIt; + } + } + + bodyWriter->endElement(); // table:table-row + bodyWriter->endElement(); // table:table-header-rows + bodyWriter->startElement( "table:table-rows" ); + + TQStringList::const_iterator rowLabelIt = m_rowLabels.begin(); + for ( int row = 0; row < rows ; ++row ) { + bodyWriter->startElement( "table:table-row" ); + + if ( rowLabelIt != m_rowLabels.end() ) { + // Save row labels, similar to column labels + bodyWriter->startElement( "table:table-cell" ); + bodyWriter->addAttribute( "office:value-type", "string" ); + + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( *rowLabelIt ); + bodyWriter->endElement(); // text:p + + bodyWriter->endElement(); // table:table-cell + ++rowLabelIt; + } + + for ( int col = 0; col < cols; ++col ) { + TQVariant value( m_currentData.cellVal( row, col ) ); + TQString valType; + TQString valStr; + + switch ( value.type() ) { + case TQVariant::Invalid: + break; + case TQVariant::String: + valType = "string"; + valStr = value.toString(); + break; + case TQVariant::Double: + valType = "float"; + valStr = TQString::number( value.toDouble(), 'g', DBL_DIG ); + break; + case TQVariant::DateTime: + valType = "date"; + valStr = ""; /* like in saveXML, but why? */ + break; + default: { + kdDebug(35001) << "ERROR: cell " << row << "," << col + << " has unknown type." << endl; + } + } + + // Add the value type and the string to the XML tree. + bodyWriter->startElement( "table:table-cell" ); + if ( !valType.isEmpty() ) { + bodyWriter->addAttribute( "office:value-type", valType ); + if ( value.type() == TQVariant::Double ) + bodyWriter->addAttribute( "office:value", valStr ); + + bodyWriter->startElement( "text:p" ); + bodyWriter->addTextNode( valStr ); + bodyWriter->endElement(); // text:p + } + bodyWriter->endElement(); // table:table-cell + } + bodyWriter->endElement(); // table:table-row + } + + bodyWriter->endElement(); // table:table-rows + bodyWriter->endElement(); // table:table +} + +void KChartPart::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles ) const +{ + TQValueList styles = mainStyles.styles( KoGenStyle::STYLE_AUTO ); + TQValueList::const_iterator it = styles.begin(); + for ( ; it != styles.end() ; ++it ) { + (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:chart-properties" ); + } + +} + +// ---------------------------------------------------------------- +// Save and Load old KChart file format + + +TQDomDocument KChartPart::saveXML() +{ + TQDomElement tmpElem; + + //kdDebug(35001) << "kchart saveXML called" << endl; + + // The biggest part of the saving is done by KDChart itself, so we + // don't have to do it. + TQDomDocument doc = m_params->saveXML( false ); + + // ---------------------------------------------------------------- + // The rest of the saving has to be done by us. + + TQDomElement docRoot = doc.documentElement(); + + // Save auxiliary data. + TQDomElement aux = doc.createElement( "KChartAuxiliary" ); + docRoot.appendChild( aux ); + + // The data direction (rows/columns). + tmpElem = doc.createElement( "direction" ); + tmpElem.setAttribute( "value", (int) m_params->dataDirection() ); + aux.appendChild( tmpElem ); + + tmpElem = doc.createElement( "dataaslabel" ); + tmpElem.setAttribute( "firstrow", + m_params->firstRowAsLabel() ? "true" : "false" ); + tmpElem.setAttribute( "firstcol", + m_params->firstColAsLabel() ? "true" : "false" ); + aux.appendChild( tmpElem ); + + tmpElem = doc.createElement( "barnumlines" ); + tmpElem.setAttribute( "value", (int) m_params->barNumLines() ); + aux.appendChild( tmpElem ); + + // Save the data values. + TQDomElement data = doc.createElement( "data" ); + docRoot.appendChild( data ); + + int cols = m_currentData.usedCols() + ? TQMIN(m_currentData.usedCols(), m_currentData.cols()) + : m_currentData.cols(); + int rows = m_currentData.usedRows() + ? TQMIN(m_currentData.usedRows(), m_currentData.rows()) + : m_currentData.rows(); + data.setAttribute( "cols", cols ); + data.setAttribute( "rows", rows ); + kdDebug(35001) << " writing " << cols << "," << rows << " (cols,rows)." << endl; + + for (int i=0; i!=rows; ++i) { + for (int j=0; j!=cols; ++j) { + TQDomElement e = doc.createElement( "cell" ); + data.appendChild( e ); + TQString valType; + TQVariant value( m_currentData.cellVal( i,j ) ); + switch ( value.type() ) { + case TQVariant::Invalid: valType = "NoValue"; break; + case TQVariant::String: valType = "String"; break; + case TQVariant::Double: valType = "Double"; break; + case TQVariant::DateTime: valType = "DateTime"; break; + default: { + valType = "(unknown)"; + kdDebug(35001) << "ERROR: cell " << i << "," << j + << " has unknown type." << endl; + } + } + + e.setAttribute( "valType", valType ); + //kdDebug(35001) << " cell " << i << "," << j + // << " saved with type '" << valType << "'." << endl; + switch ( value.type() ) { + case TQVariant::String: e.setAttribute( "value", value.toString() ); + break; + case TQVariant::Double: e.setAttribute( "value", TQString::number( value.toDouble() ) ); + break; + case TQVariant::DateTime:e.setAttribute( "value", "" ); + break; + default: { + e.setAttribute( "value", "" ); + if( TQVariant::Invalid != value.type() ) + kdDebug(35001) << "ERROR: cell " << i << "," << j + << " has unknown type." << endl; + } + } + } + } + + return doc; +} + + +bool KChartPart::loadXML( TQIODevice*, const TQDomDocument& doc ) +{ + kdDebug(35001) << "kchart loadXML called" << endl; + + // Set some sensible defaults. + setChartDefaults(); + + // First try to load the KDChart parameters. + bool result = m_params->loadXML( doc ); + + // If went well, try to load the auxiliary data and the data... + if (result) { + result = loadAuxiliary(doc) && loadData( doc, m_currentData ); + } + else { + // ...but if it did, try to load the old XML format. + result = loadOldXML( doc ); + } + + // If everything is OK, then get the headers from the KDChart parameters. + if (result) { + TQStringList legendLabels; + KDChartAxisParams params; + params = m_params->axisParams( KDChartAxisParams::AxisPosBottom ); + + // Get the legend. + TQString str; + uint index = 0; + while ((str = m_params->legendText(index++)) != TQString()) + legendLabels << str; + + if (m_params->dataDirection() == KChartParams::DataRows) { + m_colLabels = params.axisLabelStringList(); + m_rowLabels = legendLabels; + } + else { + m_colLabels = legendLabels; + m_rowLabels = params.axisLabelStringList(); + } + + } + + m_params->setDrawSolidExcessArrows(true); + + return result; +} + + +// Load the auxiliary data. +// +// Currently, that means the data direction. +// +bool KChartPart::loadAuxiliary( const TQDomDocument& doc ) +{ + TQDomElement chart = doc.documentElement(); + TQDomElement aux = chart.namedItem("KChartAuxiliary").toElement(); + + // Older XML files might be missing this section. That is OK; the + // defaults will be used. + if (aux.isNull()) + return true; + + TQDomNode node = aux.firstChild(); + + // If the aux section exists, it should contain data. + while (!node.isNull()) { + + TQDomElement e = node.toElement(); + if (e.isNull()) { + // FIXME: Should this be regarded as an error? + node = node.nextSibling(); + continue; + } + + // Check for direction + if ( e.tagName() == "direction" ) { + if ( e.hasAttribute("value") ) { + bool ok; + + // Read the direction. On failure, use the default. + int dir = e.attribute("value").toInt(&ok); + if ( !ok ) + dir = (int) KChartParams::DataColumns; + + //kdDebug(35001) << "Got aux value \"direction\": " << dir << endl; + m_params->setDataDirection( (KChartParams::DataDirection) dir ); + } + else { + kdDebug(35001) << "Error in direction tag." << endl; + } + } + + // Check for first row / col as label + else if ( e.tagName() == "dataaslabel" ) { + TQString val; + + if ( e.hasAttribute("firstrow") ) { + // Read the direction. On failure, use the default. + val = e.attribute("firstrow"); + if ( val == "true" ) + m_params->setFirstRowAsLabel( true ); + else + m_params->setFirstRowAsLabel( false ); + } + else { + kdDebug(35001) << "Error in barnumlines tag." << endl; + m_params->setFirstRowAsLabel( false ); + } + + if ( e.hasAttribute("firstcol") ) { + // Read the direction. On failure, use the default. + val = e.attribute("firstcol"); + if ( val == "true" ) + m_params->setFirstColAsLabel( true ); + else + m_params->setFirstColAsLabel( false ); + } + else { + kdDebug(35001) << "Error in barnumlines tag." << endl; + m_params->setFirstColAsLabel( false ); + } + } + + // Check for number of lines in a bar chart. + else if ( e.tagName() == "barnumlines" ) { + if ( e.hasAttribute("value") ) { + bool ok; + + // Read the number of lines. On failure, use the default. + int barNumLines = e.attribute("value").toInt(&ok); + if ( !ok ) + barNumLines = 0; + + //kdDebug(35001) << "Got aux value \"barnumlines\": " + // << barNumLines << endl; + m_params->setBarNumLines( barNumLines ); + } + else { + kdDebug(35001) << "Error in barnumlines tag." << endl; + } + } +#if 0 + // Expand with more auxiliary types when needed. + else if ( e.tagName() == "..." ) { + } + and so on... +#endif + + node = node.nextSibling(); + } + + return true; +} + + +bool KChartPart::loadData( const TQDomDocument& doc, + KDChartTableData& m_currentData ) +{ + kdDebug(35001) << "kchart loadData called" << endl; + + TQDomElement chart = doc.documentElement(); + TQDomElement data = chart.namedItem("data").toElement(); + bool ok; + int cols = data.attribute("cols").toInt(&ok); + kdDebug(35001) << "cols readed as:" << cols << endl; + if ( !ok ){ + return false; + } + + int rows = data.attribute("rows").toInt(&ok); + if ( !ok ){ + return false; + } + + kdDebug(35001) << rows << " x " << cols << endl; + m_currentData.expand(rows, cols); + m_currentData.setUsedCols( cols ); + m_currentData.setUsedRows( rows ); + kdDebug(35001) << "Expanded!" << endl; + TQDomNode n = data.firstChild(); + //TQArray tmpExp(rows*cols); + //TQArray tmpMissing(rows*cols); + for (int i=0; i!=rows; i++) { + for (int j=0; j!=cols; j++) { + if (n.isNull()) { + kdDebug(35001) << "Some problems, there is less data than it should be!" << endl; + break; + } + TQDomElement e = n.toElement(); + if ( !e.isNull() && e.tagName() == "cell" ) { + // add the cell to the corresponding place... + TQVariant t; + if ( e.hasAttribute("value") && e.hasAttribute("valType") ) { + TQString valueType = e.attribute("valType").lower(); + if ( "string" == valueType ) { + t = e.attribute("value"); + } + else if ( "double" == valueType ) { + bool bOk; + double val = e.attribute("value").toDouble(&bOk); + if ( !bOk ) + val = 0.0; + t = val; + /* + } else if ( "datetime" == valueType ) { + t = . . . + */ + } else { + t.clear(); + if ( "novalue" != valueType ) + kdDebug(35001) << "ERROR: cell " << i << "," << j << " has unknown type '" << valueType << "'." << endl; + } + } else + t.clear(); + + m_currentData.setCell(i,j, t ); + + /* + if ( e.hasAttribute( "hide" ) ) { + tmpMissing[cols*j+i] = (bool)e.attribute("hide").toInt( &ok ); + if ( !ok ) + return false; + } else { + tmpMissing[cols*j+i] = false; + } + if ( e.hasAttribute( "dist" ) ) { + tmpExp[cols*j+i] = e.attribute("dist").toInt( &ok ); + if ( !ok ) + return false; + } else { + tmpExp[cols*j+i] = 0; + } + */ + + n = n.nextSibling(); + } + } + } + /* + m_params->missing=tmpMissing; + m_params->explode=tmpExp; + */ + return true; +} + + +// ---------------------------------------------------------------- +// Save and Load real old KChart file format + + +bool KChartPart::loadOldXML( const TQDomDocument& doc ) +{ + kdDebug(35001) << "kchart loadOldXML called" << endl; + if ( doc.doctype().name() != "chart" ) + return false; + + kdDebug(35001) << "Ok, it is a chart" << endl; + + TQDomElement chart = doc.documentElement(); + if ( chart.attribute( "mime" ) != "application/x-kchart" && chart.attribute( "mime" ) != "application/vnd.kde.kchart" ) + return false; + + kdDebug(35001) << "Mimetype ok" << endl; + +#if 0 + TQDomElement data = chart.namedItem("data").toElement(); + bool ok; + int cols = data.attribute("cols").toInt(&ok); + kdDebug(35001) << "cols readed as:" << cols << endl; + if (!ok) { return false; } + int rows = data.attribute("rows").toInt(&ok); + if (!ok) { return false; } + kdDebug(35001) << rows << " x " << cols << endl; + m_currentData.expand(rows, cols); + kdDebug(35001) << "Expanded!" << endl; + TQDomNode n = data.firstChild(); + TQArray tmpExp(rows*cols); + TQArray tmpMissing(rows*cols); + + for (int i=0; i!=rows; i++) { + for (int j=0; j!=cols; j++) { + if (n.isNull()) { + kdDebug(35001) << "Some problems, there is less data than it should be!" << endl; + break; + } + + TQDomElement e = n.toElement(); + if ( !e.isNull() && e.tagName() == "cell" ) { + // add the cell to the corresponding place... + double val = e.attribute("value").toDouble(&ok); + if (!ok) { return false; } + kdDebug(35001) << i << " " << j << "=" << val << endl; + KoChart::Value t( val ); + // kdDebug(35001) << "Set cell for " << row << "," << col << endl; + m_currentData.setCell(i,j,t); + if ( e.hasAttribute( "hide" ) ) { + tmpMissing[cols*j+i] = (bool)e.attribute("hide").toInt( &ok ); + if ( !ok ) + return false; + } else { + tmpMissing[cols*j+i] = false; + } + if ( e.hasAttribute( "dist" ) ) { + tmpExp[cols*j+i] = e.attribute("dist").toInt( &ok ); + if ( !ok ) + return false; + } else { + tmpExp[cols*j+i] = 0; + } + + n = n.nextSibling(); + } + } + } + m_params->missing=tmpMissing; + m_params->explode=tmpExp; +#endif + + +/* + enum KChartType { + KCHARTTYPE_LINE, + KCHARTTYPE_AREA, + KCHARTTYPE_BAR, + KCHARTTYPE_HILOCLOSE, + KCHARTTYPE_COMBO_LINE_BAR, aka, VOL[ume] + KCHARTTYPE_COMBO_HLC_BAR, + KCHARTTYPE_COMBO_LINE_AREA, + KCHARTTYPE_COMBO_HLC_AREA, + KCHARTTYPE_3DHILOCLOSE, + KCHARTTYPE_3DCOMBO_LINE_BAR, + KCHARTTYPE_3DCOMBO_LINE_AREA, + KCHARTTYPE_3DCOMBO_HLC_BAR, + KCHARTTYPE_3DCOMBO_HLC_AREA, + KCHARTTYPE_3DBAR, + KCHARTTYPE_3DAREA, + KCHARTTYPE_3DLINE, + KCHARTTYPE_3DPIE, + KCHARTTYPE_2DPIE + }; +*/ + bool ok; + TQDomElement params = chart.namedItem( "params" ).toElement(); + if ( params.hasAttribute( "type" ) ) { + int type=params.attribute("type").toInt( &ok ); + if ( !ok ) + return false; + switch(type) + { + case 1: + m_params->setChartType(KChartParams::Line); + break; + case 2: + m_params->setChartType(KChartParams::Area); + break; + case 3: + m_params->setChartType(KChartParams::Bar); + break; + case 4: + m_params->setChartType(KChartParams::HiLo); + break; + case 5: + case 6: + case 7: + case 8: + /* KCHARTTYPE_COMBO_LINE_BAR, aka, VOL[ume] + KCHARTTYPE_COMBO_HLC_BAR, + KCHARTTYPE_COMBO_LINE_AREA, + KCHARTTYPE_COMBO_HLC_AREA, + */ + /* line by default*/ + m_params->setChartType(KChartParams::Line); + break; + case 9: + m_params->setChartType(KChartParams::HiLo); + break; + case 10: + m_params->setChartType(KChartParams::Bar); + break; + case 11: + m_params->setChartType(KChartParams::Area); + break; + case 12: + m_params->setChartType(KChartParams::Bar); + break; + case 13: + m_params->setChartType(KChartParams::Area); + break; + case 14: + m_params->setChartType(KChartParams::Bar); + break; + case 15: + m_params->setChartType(KChartParams::Area); + break; + case 16: + m_params->setChartType(KChartParams::Line); + break; + case 17: + case 18: + m_params->setChartType(KChartParams::Pie); + break; + + } + if ( !ok ) + return false; + } +#if 0 + if ( params.hasAttribute( "subtype" ) ) { + m_params->stack_type = (KChartStackType)params.attribute("subtype").toInt( &ok ); + if ( !ok ) + return false; + } + if ( params.hasAttribute( "hlc_style" ) ) { + m_params->hlc_style = (KChartHLCStyle)params.attribute("hlc_style").toInt( &ok ); + if ( !ok ) + return false; + } + if ( params.hasAttribute( "hlc_cap_width" ) ) { + m_params->hlc_cap_width = (short)params.attribute( "hlc_cap_width" ).toShort( &ok ); + if ( !ok ) + return false; + } + + TQDomElement title = params.namedItem( "title" ).toElement(); + if ( !title.isNull()) { + TQString t = title.text(); + m_params->title=t; + } + TQDomElement titlefont = params.namedItem( "titlefont" ).toElement(); + if ( !titlefont.isNull()) { + TQDomElement font = titlefont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setTitleFont(toFont(font)); + } + TQDomElement xtitle = params.namedItem( "xtitle" ).toElement(); + if ( !xtitle.isNull()) { + TQString t = xtitle.text(); + m_params->xtitle=t; + } + TQDomElement xtitlefont = params.namedItem( "xtitlefont" ).toElement(); + if ( !xtitlefont.isNull()) { + TQDomElement font = xtitlefont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setXTitleFont(toFont(font)); + } + TQDomElement ytitle = params.namedItem( "ytitle" ).toElement(); + if ( !ytitle.isNull()) { + TQString t = ytitle.text(); + m_params->ytitle=t; + } + TQDomElement ytitle2 = params.namedItem( "ytitle2" ).toElement(); + if ( !ytitle2.isNull()) { + TQString t = ytitle2.text(); + m_params->ytitle2=t; + } + TQDomElement ytitlefont = params.namedItem( "ytitlefont" ).toElement(); + if ( !ytitlefont.isNull()) { + TQDomElement font = ytitlefont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setYTitleFont(toFont(font)); + } + TQDomElement ylabelfmt = params.namedItem( "ylabelfmt" ).toElement(); + if ( !ylabelfmt.isNull()) { + TQString t = ylabelfmt.text(); + m_params->ylabel_fmt=t; + } + TQDomElement ylabel2fmt = params.namedItem( "ylabel2fmt" ).toElement(); + if ( !ylabel2fmt.isNull()) { + TQString t = ylabel2fmt.text(); + m_params->ylabel2_fmt=t; + } + TQDomElement labelfont = params.namedItem( "labelfont" ).toElement(); + if ( !labelfont.isNull()) { + TQDomElement font = labelfont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setLabelFont(toFont(font)); + } + + TQDomElement yaxisfont = params.namedItem( "yaxisfont" ).toElement(); + if ( !yaxisfont.isNull()) { + TQDomElement font = yaxisfont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setYAxisFont(toFont(font)); + } + + TQDomElement xaxisfont = params.namedItem( "xaxisfont" ).toElement(); + if ( !xaxisfont.isNull()) { + TQDomElement font = xaxisfont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setXAxisFont(toFont(font)); + } + TQDomElement annotationFont = params.namedItem("annotationfont").toElement(); + if ( !annotationFont.isNull()) { + TQDomElement font = annotationFont.namedItem( "font" ).toElement(); + if ( !font.isNull() ) + m_params->setAnnotationFont(toFont(font)); + } + + TQDomElement yaxis = params.namedItem( "yaxis" ).toElement(); + if ( !yaxis.isNull()) { + if (yaxis.hasAttribute( "yinterval" )) { + m_params->requested_yinterval= yaxis.attribute("yinterval").toDouble( &ok ); + if ( !ok ) return false; + } + if (yaxis.hasAttribute( "ymin" )) { + m_params->requested_ymin= yaxis.attribute("ymin").toDouble( &ok ); + if ( !ok ) return false; + } + if (yaxis.hasAttribute( "ymax" ) ) { + m_params->requested_ymax= yaxis.attribute("ymax").toDouble( &ok ); + if ( !ok ) return false; + } + } +#endif + + TQDomElement graph = params.namedItem( "graph" ).toElement(); + if (!graph.isNull()) { + if (graph.hasAttribute( "grid" )) { + bool b=(bool) graph.attribute("grid").toInt( &ok ); + m_params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,b ); + m_params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,b ); + if (!ok) return false; + } + if (graph.hasAttribute( "xaxis" )) { + bool b=(bool) graph.attribute("xaxis").toInt( &ok ); + if (!ok) return false; + m_params->setAxisVisible(KDChartAxisParams::AxisPosBottom,b); + } + if (graph.hasAttribute( "yaxis" )) { + bool b=(bool) graph.attribute("yaxis").toInt( &ok ); + if (!ok) return false; + m_params->setAxisVisible(KDChartAxisParams::AxisPosLeft,b); + } +#if 0 + //no implemented + if (graph.hasAttribute( "shelf" )) { + m_params->shelf=(bool) graph.attribute("shelf").toInt( &ok ); + if (!ok) return false; + } +#endif + if (graph.hasAttribute( "yaxis2" )) { + bool b=(bool) graph.attribute("yaxis2").toInt( &ok ); + if (!ok) return false; + m_params->setAxisVisible(KDChartAxisParams::AxisPosRight,b); + } + +#if 0 + //no implemented + if (graph.hasAttribute( "ystyle" )) { + m_params->yval_style=(bool) graph.attribute("ystyle").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute( "border" )) { + m_params->border=(bool) graph.attribute("border").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute( "transbg" )) { + m_params->transparent_bg=(bool) graph.attribute("transbg").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute( "xlabel" )) { + m_params->hasxlabel=(bool) graph.attribute("xlabel").toInt( &ok ); + if (!ok) return false; + } + if ( graph.hasAttribute( "xlabel_spacing" ) ) { + m_params->xlabel_spacing = (short)graph.attribute( "xlabel_spacing" ).toShort( &ok ); + if ( !ok ) + return false; + } + if ( graph.hasAttribute( "ylabel_density" ) ) { + m_params->ylabel_density = (short)graph.attribute( "ylabel_density" ).toShort( &ok ); + if ( !ok ) + return false; + } + if (graph.hasAttribute( "line")) { + m_params->label_line=(bool) graph.attribute("line").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute( "percent")) { + m_params->percent_labels=(KChartPercentType) graph.attribute("percent").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute("cross")) { + m_params->cross=(bool) graph.attribute("cross").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute("thumbnail")) { + m_params->thumbnail=(bool) graph.attribute("thumbnail").toInt( &ok ); + if (!ok) return false; + } + if (graph.hasAttribute("thumblabel")) { + m_params->thumblabel= graph.attribute("thumblabel"); + } + if (graph.hasAttribute("thumbval")) { + m_params->thumbval=(bool) graph.attribute("thumbval").toDouble( &ok ); + if (!ok) + return false; + } +#endif + } + +#if 0 + TQDomElement graphparams = params.namedItem( "graphparams" ).toElement(); + if (!graphparams.isNull()) { + if (graphparams.hasAttribute( "dept3d" )) { + m_params->_3d_depth=graphparams.attribute("dept3d").toDouble( &ok ); + if (!ok) return false; + } + if (graphparams.hasAttribute( "angle3d" )) { + m_params->_3d_angle=graphparams.attribute("angle3d").toShort( &ok ); + if (!ok) return false; + } + if (graphparams.hasAttribute( "barwidth" )) { + m_params->bar_width=graphparams.attribute("barwidth").toShort( &ok ); + if (!ok) return false; + } + if (graphparams.hasAttribute( "colpie" )) { + m_params->colPie=graphparams.attribute("colpie").toInt( &ok ); + if (!ok) return false; + } + if (graphparams.hasAttribute( "other_threshold" )) { + m_params->other_threshold=graphparams.attribute("other_threshold").toShort( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "offsetCol" )) { + m_params->offsetCol = graphparams.attribute("offsetCol").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "hard_size" )) { + m_params->hard_size = (bool)graphparams.attribute("hard_size").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "hard_graphheight" )) { + m_params->hard_graphheight = graphparams.attribute("hard_graphheight").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "hard_graphwidth" )) { + m_params->hard_graphwidth = graphparams.attribute("hard_graphwidth").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "hard_xorig" )) { + m_params->hard_xorig = graphparams.attribute("hard_xorig").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "hard_yorig" )) { + m_params->hard_yorig = graphparams.attribute("hard_yorig").toInt( &ok ); + if (!ok) + return false; + } + if (graphparams.hasAttribute( "labeldist" )) { + m_params->label_dist=graphparams.attribute("labeldist").toInt( &ok ); + if (!ok) return false; + } + } + + TQDomElement graphcolor = params.namedItem( "graphcolor" ).toElement(); + if (!graphcolor.isNull()) { + if (graphcolor.hasAttribute( "bgcolor" )) { + m_params->BGColor= TQColor( graphcolor.attribute( "bgcolor" ) ); + } + if (graphcolor.hasAttribute( "gridcolor" )) { + m_params->GridColor= TQColor( graphcolor.attribute( "gridcolor" ) ); + } + if (graphcolor.hasAttribute( "linecolor" )) { + m_params->LineColor= TQColor( graphcolor.attribute( "linecolor" ) ); + } + if (graphcolor.hasAttribute( "plotcolor" )) { + m_params->PlotColor= TQColor( graphcolor.attribute( "plotcolor" ) ); + } + if (graphcolor.hasAttribute( "volcolor" )) { + m_params->VolColor= TQColor( graphcolor.attribute( "volcolor" ) ); + } + if (graphcolor.hasAttribute( "titlecolor" )) { + m_params->TitleColor= TQColor( graphcolor.attribute( "titlecolor" ) ); + } + if (graphcolor.hasAttribute( "xtitlecolor" )) { + m_params->XTitleColor= TQColor( graphcolor.attribute( "xtitlecolor" ) ); + } + if (graphcolor.hasAttribute( "ytitlecolor" )) { + m_params->YTitleColor= TQColor( graphcolor.attribute( "ytitlecolor" ) ); + } + if (graphcolor.hasAttribute( "ytitle2color" )) { + m_params->YTitle2Color= TQColor( graphcolor.attribute( "ytitle2color" ) ); + } + if (graphcolor.hasAttribute( "xlabelcolor" )) { + m_params->XLabelColor= TQColor( graphcolor.attribute( "xlabelcolor" ) ); + } + if (graphcolor.hasAttribute( "ylabelcolor" )) { + m_params->YLabelColor= TQColor( graphcolor.attribute( "ylabelcolor" ) ); + } + if (graphcolor.hasAttribute( "ylabel2color" )) { + m_params->YLabel2Color= TQColor( graphcolor.attribute( "ylabel2color" ) ); + } + } + + TQDomElement annotation = params.namedItem( "annotation" ).toElement(); + if (!annotation.isNull()) { + m_params->annotation=new KChartAnnotationType; + if (annotation.hasAttribute( "color" )) { + m_params->annotation->color= TQColor( annotation.attribute( "color" ) ); + } + if (annotation.hasAttribute( "point" )) { + m_params->annotation->point=annotation.attribute("point").toDouble( &ok ); + if (!ok) return false; + } + } + + TQDomElement note = params.namedItem( "note" ).toElement(); + if ( !note.isNull()) { + TQString t = note.text(); + m_params->annotation->note=t; + } + + TQDomElement scatter = params.namedItem( "scatter" ).toElement(); + if ( !scatter.isNull() ) { + m_params->scatter = new KChartScatterType; + if ( scatter.hasAttribute( "point" ) ) { + m_params->scatter->point = scatter.attribute( "point" ).toDouble( &ok ); + if ( !ok ) + return false; + } + if ( scatter.hasAttribute( "val" ) ) { + m_params->scatter->val = scatter.attribute( "val" ).toDouble( &ok ); + if ( !ok ) + return false; + } + if ( scatter.hasAttribute( "width" ) ) { + m_params->scatter->width = scatter.attribute( "val" ).toUShort( &ok ); + if ( !ok ) + return false; + } + if ( scatter.hasAttribute( "color" )) { + m_params->scatter->color= TQColor( scatter.attribute( "color" ) ); + } + if ( scatter.hasAttribute( "ind" ) ) { + m_params->scatter->ind = (KChartScatterIndType)scatter.attribute( "ind" ).toInt( &ok ); + if ( !ok ) + return false; + } + } + + TQDomElement legend = chart.namedItem("legend").toElement(); + if (!legend.isNull()) { + int number = legend.attribute("number").toInt(&ok); + if (!ok) { return false; } + TQDomNode name = legend.firstChild(); + m_params->legend.clear(); + for(int i=0; ilegend+=t; + name = name.nextSibling(); + } + } + } + + TQDomElement xlbl = chart.namedItem("xlbl").toElement(); + if (!xlbl.isNull()) { + int number = xlbl.attribute("number").toInt(&ok); + if (!ok) { return false; } + TQDomNode label = xlbl.firstChild(); + m_params->xlbl.clear(); + for (int i=0; ixlbl+=t; + label = label.nextSibling(); + } + } + } + + TQDomElement backgroundPixmap = chart.namedItem( "backgroundPixmap" ).toElement(); + if ( !backgroundPixmap.isNull() ) { + if ( backgroundPixmap.hasAttribute( "name" ) ) + m_params->backgroundPixmapName = backgroundPixmap.attribute( "name" ); + if ( backgroundPixmap.hasAttribute( "isDirty" ) ) { + m_params->backgroundPixmapIsDirty = (bool)backgroundPixmap.attribute( "isDirty" ).toInt( &ok ); + if ( !ok ) + return false; + } + if ( backgroundPixmap.hasAttribute( "scaled" ) ) { + m_params->backgroundPixmapScaled = (bool)backgroundPixmap.attribute( "scaled" ).toInt( &ok ); + if ( !ok ) + return false; + } + if ( backgroundPixmap.hasAttribute( "centered" ) ) { + m_params->backgroundPixmapCentered = (bool)backgroundPixmap.attribute( "centered" ).toInt( &ok ); + if ( !ok ) + return false; + } + if ( backgroundPixmap.hasAttribute( "intensity" ) ) { + m_params->backgroundPixmapIntensity = backgroundPixmap.attribute( "intensity" ).toFloat( &ok ); + if ( !ok ) + return false; + } + } + + TQDomElement extcolor = chart.namedItem("extcolor").toElement(); + if (!extcolor.isNull()) { + unsigned int number = extcolor.attribute("number").toInt(&ok); + if (!ok) { return false; } + TQDomNode color = extcolor.firstChild(); + + for (unsigned int i=0; iExtColor.setColor(i,TQColor( element.attribute( "name" ) )); + } + color = color.nextSibling(); + } + } + } + + if ( !m_params->backgroundPixmapName.isNull() ) { + m_params->backgroundPixmap.load( locate( "wallpaper", + m_params->backgroundPixmapName )); + m_params->backgroundPixmapIsDirty = true; + } +#endif + return true; +} + + + +void KChartPart::slotModified() +{ + kdDebug(35001) << "slotModified called!" << endl; + + setModified(true); +} + + +bool KChartPart::showEmbedInitDialog(TQWidget* /*parent*/) +{ + // Don't show an embed dialog + return true; +} + + +} //KChart namespace + +#include "kchart_part.moc" diff --git a/kchart/kchart_view.cc b/kchart/kchart_view.cc deleted file mode 100644 index ba2d1321..00000000 --- a/kchart/kchart_view.cc +++ /dev/null @@ -1,764 +0,0 @@ -/** - * - * Kalle Dalheimer - */ - - -#include -#include -#include -#include -#include -#include // For TQByteArray - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "kdchart/KDChart.h" -#include "kchart_view.h" -#include "kchart_factory.h" -#include "kchart_part.h" -#include "kchart_params.h" -#include "kchartWizard.h" -#include "kchartDataEditor.h" -#include "kchartConfigDialog.h" -#include "KChartViewIface.h" -#include "kchartPageLayout.h" -#include "kchartPrinterDlg.h" -#include "csvimportdialog.h" - - -using namespace std; - - -//#include "sheetdlg.h" - -namespace KChart -{ - - -KChartView::KChartView( KChartPart* part, TQWidget* parent, const char* name ) - : KoView( part, parent, name ) -{ - - // No flicker - setBackgroundMode( TQt::NoBackground ); - - setInstance( KChartFactory::global() ); - if ( koDocument()->isReadWrite() ) - setXMLFile( "kchart.rc" ); - else - setXMLFile( "kchart_readonly.rc" ); - m_dcop = 0; - dcopObject(); // build it - - m_importData = new TDEAction( i18n( "Import Data..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( importData() ), - actionCollection(), "import_data" ); -#if 0 - TDEAction * actionExtraCreateTemplate = -#endif - new TDEAction( i18n( "&Create Template From Document..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( extraCreateTemplate() ), - actionCollection(), "extra_template" ); - - m_wizard = new TDEAction( i18n("Customize with &Wizard..."), - "wizard", 0, - TQT_TQOBJECT(this), TQT_SLOT( wizard() ), - actionCollection(), "wizard"); - m_edit = new TDEAction( i18n("Edit &Data..."), "edit", 0, - TQT_TQOBJECT(this), TQT_SLOT( editData() ), - actionCollection(), "editdata"); - m_config = new TDEAction( i18n( "&Chart..." ), "configure", 0, - - TQT_TQOBJECT(this), TQT_SLOT( slotConfig() ), - actionCollection(), "config" ); - - // One TDEToggleAction per chart type - m_chartbars = new TDEToggleAction( i18n("&Bar"), "chart_bar_3d", 0, TQT_TQOBJECT(this), - TQT_SLOT( barsChart() ), actionCollection(), - "barschart"); - m_chartbars->setExclusiveGroup( "charttypes" ); - m_chartbars->setChecked( true ); - - m_chartline = new TDEToggleAction( i18n("&Line"), "chart_line", 0, TQT_TQOBJECT(this), - TQT_SLOT( lineChart() ), actionCollection(), - "linechart"); - m_chartline->setExclusiveGroup( "charttypes" ); - - m_chartareas = new TDEToggleAction( i18n("&Area"), "chart_area", 0, TQT_TQOBJECT(this), - TQT_SLOT( areasChart() ), actionCollection(), - "areaschart"); - m_chartareas->setExclusiveGroup( "charttypes" ); - - m_charthilo = new TDEToggleAction( i18n("&HiLo"), "chart_hilo", 0, TQT_TQOBJECT(this), - TQT_SLOT( hiLoChart() ), actionCollection(), - "hilochart"); - m_charthilo->setExclusiveGroup( "charttypes" ); - - m_chartbw = new TDEToggleAction( i18n("Bo&x && Whiskers"), "chart_boxwhisker", 0, TQT_TQOBJECT(this), - TQT_SLOT( bwChart() ), actionCollection(), - "bwchart"); - m_chartbw->setExclusiveGroup( "charttypes" ); - - m_chartpie = new TDEToggleAction( i18n("&Pie"), "chart_pie", 0, TQT_TQOBJECT(this), - TQT_SLOT( pieChart() ), actionCollection(), - "piechart"); - m_chartpie->setExclusiveGroup( "charttypes" ); - - m_chartring = new TDEToggleAction( i18n("&Ring"), "chart_ring", 0, TQT_TQOBJECT(this), - TQT_SLOT( ringChart() ), actionCollection(), - "ringchart"); - m_chartring->setExclusiveGroup( "charttypes" ); - - m_chartpolar = new TDEToggleAction( i18n("&Polar"), "chart_polar", 0, TQT_TQOBJECT(this), - TQT_SLOT( polarChart() ), actionCollection(), - "polarchart"); - m_chartpolar->setExclusiveGroup( "charttypes" ); - - // Configuration TDEActions - m_colorConfig = new TDEAction( i18n( "&Colors..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigColor() ), - actionCollection(), "color_config" ); - - m_fontConfig = new TDEAction( i18n( "&Font..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigFont() ), - actionCollection(), "font_config" ); - - m_backConfig = new TDEAction( i18n( "&Background..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigBack() ), - actionCollection(), "back_config" ); - - m_legendConfig = new TDEAction( i18n( "&Legend..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigLegend() ), - actionCollection(), "legend_config" ); - - m_subTypeChartConfig = new TDEAction( i18n( "Chart &Sub-type..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigSubTypeChart() ), - actionCollection(), "legend_subtype" ); - - m_dataFormatConfig = new TDEAction( i18n( "&Data Format..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigDataFormat() ), - actionCollection(), "data_format" ); - - m_headerFooterConfig = new TDEAction( i18n( "&Header && Footer..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigHeaderFooterChart() ), - actionCollection(), "headerfooter_subtype" ); - - m_pageLayoutConfig = new TDEAction( i18n( "Page Layout..." ), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotConfigPageLayout() ), - actionCollection(), "page_layout" ); - - // initialize the configuration - // loadConfig(); - - // Disable some things if we can't change the data, e.g. because - // we are inside another application that provides the data for us. - if (!((KChartPart*)koDocument())->canChangeValue()) { - m_edit->setEnabled(false); - m_importData->setEnabled(false); - } - - updateGuiTypeOfChart(); -} - - -KChartView::~KChartView() -{ - delete m_dcop; -} - - -DCOPObject* KChartView::dcopObject() -{ - if ( !m_dcop ) - m_dcop = new KChartViewIface( this ); - - return m_dcop; -} - - -void KChartView::paintEvent( TQPaintEvent* /*ev*/ ) -{ - TQPainter painter( this ); - - // ### TODO: Scaling - - // Let the document do the drawing - // This calls KChartPart::paintContent, basically. - koDocument()->paintEverything( painter, rect(), false, this ); -} - - -void KChartView::updateReadWrite( bool /*readwrite*/ ) -{ -#ifdef __GNUC__ -#warning TODO -#endif -} - - -// Edit the data to the chart. -// This opens a spreadsheet like editor with the data in it. -// - -void KChartView::editData() -{ - kchartDataEditor ed(this); - KChartParams *params = ((KChartPart*)koDocument())->params(); - KDChartTableData *dat = ((KChartPart*)koDocument())->data(); - - kdDebug(35001) << "***Before calling editor: cols =" << dat->cols() - << " , rows = " << dat->rows() - << " , usedCols = " << dat->usedCols() - << " usedRows = " << dat->usedRows() << endl; - - ed.setData( params, dat ); - ed.setRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); - ed.setColLabels(((KChartPart*)koDocument())->colLabelTexts()); - - // Activate the Apply button in the editor. - connect(&ed, TQT_SIGNAL(applyClicked(kchartDataEditor *)), - TQT_TQOBJECT(this), TQT_SLOT(applyEdit(kchartDataEditor *))); - - // Execute the data editor. - if ( ed.exec() != TQDialog::Accepted ) { - return; - } - if (!ed.modified()) - return; - - // Get the data and legend back. - ed.getData(params, dat); - ed.getRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); - ed.getColLabels(((KChartPart*)koDocument())->colLabelTexts()); - ((KChartPart*)koDocument())->setModified(true); - - kdDebug(35001) << "***After calling editor: cols =" << dat->cols() - << " , rows = " << dat->rows() - << " , usedCols = " << dat->usedCols() - << " usedRows = " << dat->usedRows() << endl; - update(); -} - - -void KChartView::applyEdit(kchartDataEditor *ed) -{ - if (!ed->modified()) - return; - - ed->getData( ((KChartPart*)koDocument())->params(), - ((KChartPart*)koDocument())->data() ); - ed->getRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); - ed->getColLabels(((KChartPart*)koDocument())->colLabelTexts()); - - ((KChartPart*)koDocument())->setModified(true); - - update(); -} - - -void KChartView::wizard() -{ - kdDebug(35001) << "Wizard called" << endl; - KChartWizard *wiz = new KChartWizard((KChartPart*)koDocument(), this, - "KChart Wizard", true); - kdDebug(35001) << "Executed. Now, display it" << endl; - if (wiz->exec()) { - ((KChartPart*)koDocument())->setModified(true); - update(); - updateGuiTypeOfChart(); - kdDebug(35001) << "Ok, executed..." << endl; - } -} - - -void KChartView::updateGuiTypeOfChart() -{ - KDChartParams* params = ((KChartPart*)koDocument())->params(); - - switch(params->chartType()) { - case KDChartParams::Bar: - m_chartbars->setChecked(true); - break; - case KDChartParams::Line: - m_chartline->setChecked(true); - break; - case KDChartParams::Area: - m_chartareas->setChecked(true); - break; - case KDChartParams::Pie: - m_chartpie->setChecked(true); - break; - case KDChartParams::HiLo: - m_charthilo->setChecked(true); - break; - case KDChartParams::Ring: - m_chartring->setChecked(true); - break; - case KDChartParams::Polar: - m_chartpolar->setChecked(true); - break; - case KDChartParams::BoxWhisker: - m_chartbw->setChecked( true ); - break; - default: - //todo - break; - } - - // Disable subtype configuration button if appropriate. - updateButton(); -} - - -void KChartView::slotConfig() -{ - config(KChartConfigDialog::KC_ALL); -} - - -void KChartView::config(int flags) -{ - // open a config dialog depending on the chart type - KChartParams *params = ((KChartPart*)koDocument())->params(); - KDChartTableData *dat = ((KChartPart*)koDocument())->data(); - - KChartConfigDialog *d = new KChartConfigDialog( params, this, flags, - dat ); - - connect( d, TQT_SIGNAL( dataChanged() ), - TQT_TQOBJECT(this), TQT_SLOT( slotRepaint() ) ); - d->exec(); - delete d; -} - - -void KChartView::slotRepaint() -{ - ((KChartPart*)koDocument())->setModified(true); - update(); -} - - -void KChartView::saveConfig() -{ - kdDebug(35001) << "Save config..." << endl; - ((KChartPart*)koDocument())->saveConfig( TDEGlobal::config() ); -} - - -void KChartView::loadConfig() -{ - kdDebug(35001) << "Load config..." << endl; - - TDEGlobal::config()->reparseConfiguration(); - ((KChartPart*)koDocument())->loadConfig( TDEGlobal::config() ); - - updateGuiTypeOfChart(); - //refresh chart when you load config - update(); -} - - -void KChartView::defaultConfig() -{ - ((KChartPart*)koDocument())->defaultConfig( ); - updateGuiTypeOfChart(); - update(); -} - - -void KChartView::pieChart() -{ - if ( m_chartpie->isChecked() ) { - forceAxisParams(false); - KChartParams *params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::Pie ); - params->setThreeDPies(params->threeDBars()); - params->setExplodeFactor( 0 ); - params->setExplode( true ); - - updateButton(); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartpie->setChecked( true ); // always one has to be checked ! -} - -void KChartView::forceAxisParams(bool lineMode) { - KChartParams *params = ((KChartPart*)koDocument())->params(); - KDChartAxisParams axisParams; - axisParams = params->axisParams( KDChartAxisParams::AxisPosLeft ); - if(params->chartType() == KChartParams::Line) - m_logarithmicScale = axisParams.axisCalcMode(); - if(lineMode) { - if(m_logarithmicScale) - axisParams.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); - } else - axisParams.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear); - params->setAxisParams( KDChartAxisParams::AxisPosLeft, axisParams ); -} - -void KChartView::lineChart() -{ - if ( m_chartline->isChecked() ) { - forceAxisParams(true); - KChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::Line ); - params->setLineChartSubType( KDChartParams::LineNormal ); - - updateButton(); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartline->setChecked( true ); // always one has to be checked ! - -} - - -void KChartView::barsChart() -{ - if ( m_chartbars->isChecked() ) { - forceAxisParams(false); - KChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::Bar ); - params->setBarChartSubType( KDChartParams::BarNormal ); - - updateButton(); - params->setThreeDBars( params->threeDPies() ); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartbars->setChecked( true ); // always one has to be checked ! -} - - -void KChartView::areasChart() -{ - if ( m_chartareas->isChecked() ) { - forceAxisParams(false); - KChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::Area ); - params->setAreaChartSubType( KDChartParams::AreaNormal ); - - updateButton(); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartareas->setChecked( true ); // always one has to be checked ! - -} - - -void KChartView::hiLoChart() -{ - if ( m_charthilo->isChecked() ) { - forceAxisParams(false); - KChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::HiLo ); - params->setHiLoChartSubType( KDChartParams::HiLoNormal ); - - updateButton(); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_charthilo->setChecked( true ); // always one has to be checked ! -} - - -void KChartView::ringChart() -{ - if ( m_chartring->isChecked() ) { - forceAxisParams(false); - KChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KChartParams::Ring ); - - updateButton(); - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartring->setChecked( true ); // always one has to be checked ! - -} - - -void KChartView::polarChart() -{ - if ( m_chartpolar->isChecked() ) { - forceAxisParams(false); - KDChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KDChartParams::Polar ); - params->setPolarChartSubType( KDChartParams::PolarNormal ); - - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartpolar->setChecked( true ); // always one has to be checked ! -} - - -void KChartView::bwChart() -{ - if ( m_chartbw->isChecked() ) { - forceAxisParams(false); - KDChartParams* params = ((KChartPart*)koDocument())->params(); - - params->setChartType( KDChartParams::BoxWhisker ); - params->setBWChartSubType( KDChartParams::BWNormal ); - - update(); - ((KChartPart*)koDocument())->setModified(true); - } - else - m_chartbw->setChecked( true ); // always one has to be checked ! -} - - -void KChartView::mousePressEvent ( TQMouseEvent *e ) -{ - if (!koDocument()->isReadWrite() || !factory()) - return; - if ( e->button() == Qt::RightButton ) - ((TQPopupMenu*)factory()->container("action_popup",this))->popup(TQCursor::pos()); -} - - -void KChartView::slotConfigColor() -{ - config(KChartConfigDialog::KC_COLORS); -} - - -void KChartView::slotConfigFont() -{ - config(KChartConfigDialog::KC_FONT); -} - - -void KChartView::slotConfigBack() -{ - config(KChartConfigDialog::KC_BACK); -} - - -void KChartView::slotConfigLegend() -{ - config(KChartConfigDialog::KC_LEGEND); -} - -void KChartView::slotConfigDataFormat() -{ - config(KChartConfigDialog::KC_DATAFORMAT); -} - -void KChartView::slotConfigSubTypeChart() -{ - config(KChartConfigDialog::KC_SUBTYPE); -} - - -void KChartView::slotConfigHeaderFooterChart() -{ - config(KChartConfigDialog::KC_HEADERFOOTER); -} - - -// FIXME: Rename into something suitable. -void KChartView::updateButton() -{ - // Disable sub chart config item. - KChartParams* params = ((KChartPart*)koDocument())->params(); - - bool state=(params->chartType()==KChartParams::Bar || - params->chartType()==KChartParams::Area || - params->chartType()==KChartParams::Line || - params->chartType()==KChartParams::HiLo || - params->chartType()==KChartParams::Polar); - m_subTypeChartConfig->setEnabled(state); -} - - -void KChartView::slotConfigPageLayout() -{ - KChartParams *params = ((KChartPart*)koDocument())->params(); - KChartPageLayout *dialog = new KChartPageLayout(params, this, - "Page Layout"); - - connect( dialog, TQT_SIGNAL( dataChanged() ), - this, TQT_SLOT( slotRepaint() ) ); - - dialog->exec(); - delete dialog; -} - - -void KChartView::setupPrinter( KPrinter &printer ) -{ - if ( !printer.previewOnly() ) - printer.addDialogPage( new KChartPrinterDlg( 0, "KChart page" ) ); -} - - -void KChartView::print(KPrinter &printer) -{ - printer.setFullPage( false ); - - TQPainter painter; - painter.begin(&printer); - TQPaintDeviceMetrics pdm( &printer ); - - int height; - int width; - if ( !printer.previewOnly() ) { - int const scalex = printer.option("kde-kchart-printsizex").toInt(); - int const scaley = printer.option("kde-kchart-printsizey").toInt(); - - width = pdm.width() * scalex / 100; - height = pdm.height() * scaley / 100; - } - else { - // Fill the whole page. - width = pdm.width(); - height = pdm.height(); - } - - TQRect rect(0, 0, width, height); - KDChart::print(&painter, - ((KChartPart*)koDocument())->params(), - ((KChartPart*)koDocument())->data(), - 0, // regions - &rect); - - painter.end(); -} - - -// Import data from a Comma Separated Values file. -// - -void KChartView::importData() -{ - // Get the name of the file to open. - TQString filename = KFileDialog::getOpenFileName(TQString(),// startDir - TQString(),// filter - 0, - i18n("Import Data")); - kdDebug(35001) << "Filename = <" << filename << ">" << endl; - if (filename.isEmpty()) - return; - - // Check to see if we can read the file. - TQFile inFile(filename); - if (!inFile.open(IO_ReadOnly)) { - KMessageBox::sorry( 0, i18n("The file %1 could not be read.") - .arg(filename) ); - inFile.close(); - return; - } - - // Let the CSV dialog structure the data in the file. - TQByteArray inData( inFile.readAll() ); - inFile.close(); - CSVImportDialog *dialog = new CSVImportDialog(0L, inData); - - if ( !dialog->exec() ) { - kdDebug(35001) << "Cancel was pressed" << endl; - return; - } - - kdDebug(35001) << "OK was pressed" << endl; - - uint rows = dialog->rows(); - uint cols = dialog->cols(); - - kdDebug(35001) << "Rows: " << rows << " Cols: " << cols << endl; - - bool hasRowHeaders = ( rows > 1 && dialog->firstRowContainHeaders() ); - bool hasColHeaders = ( cols > 1 && dialog->firstColContainHeaders() ); - - KDChartTableData data( rows, cols ); - data.setUsedRows( rows ); - data.setUsedCols( cols ); - for (uint row = 0; row < rows; row++) { - for (uint col = 0; col < cols; col++) { - bool ok; - TQString tmp; - double val; - - // Get the text and convert to double unless in the headers. - tmp = dialog->text( row, col ); - if ( ( row == 0 && hasRowHeaders ) - || ( col == 0 && hasColHeaders ) ) { - kdDebug(35001) << "Setting header (" << row << "," << col - << ") to value " << tmp << endl; - data.setCell( row, col, tmp ); - } - else { - val = tmp.toDouble(&ok); - if (!ok) - val = 0.0; - - kdDebug(35001) << "Setting (" << row << "," << col - << ") to value " << val << endl; - - // and do the actual setting. - data.setCell( row, col, val ); - } - } - } - - ((KChartPart*)koDocument())->doSetData( data, - hasRowHeaders, hasColHeaders ); -} - - -void KChartView::extraCreateTemplate() -{ - int width = 60; - int height = 60; - TQPixmap pix = koDocument()->generatePreview(TQSize(width, height)); - - KTempFile tempFile( TQString(), ".chrt" ); - tempFile.setAutoDelete(true); - - koDocument()->saveNativeFormat( tempFile.name() ); - - KoTemplateCreateDia::createTemplate( "kchart_template", KChartFactory::global(), - tempFile.name(), pix, this ); - - KChartFactory::global()->dirs()->addResourceType("kchart_template", - TDEStandardDirs::kde_default( "data" ) + - "kchart/templates/"); -} - - -} //KChart namespace - -#include "kchart_view.moc" diff --git a/kchart/kchart_view.cpp b/kchart/kchart_view.cpp new file mode 100644 index 00000000..ba2d1321 --- /dev/null +++ b/kchart/kchart_view.cpp @@ -0,0 +1,764 @@ +/** + * + * Kalle Dalheimer + */ + + +#include +#include +#include +#include +#include +#include // For TQByteArray + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kdchart/KDChart.h" +#include "kchart_view.h" +#include "kchart_factory.h" +#include "kchart_part.h" +#include "kchart_params.h" +#include "kchartWizard.h" +#include "kchartDataEditor.h" +#include "kchartConfigDialog.h" +#include "KChartViewIface.h" +#include "kchartPageLayout.h" +#include "kchartPrinterDlg.h" +#include "csvimportdialog.h" + + +using namespace std; + + +//#include "sheetdlg.h" + +namespace KChart +{ + + +KChartView::KChartView( KChartPart* part, TQWidget* parent, const char* name ) + : KoView( part, parent, name ) +{ + + // No flicker + setBackgroundMode( TQt::NoBackground ); + + setInstance( KChartFactory::global() ); + if ( koDocument()->isReadWrite() ) + setXMLFile( "kchart.rc" ); + else + setXMLFile( "kchart_readonly.rc" ); + m_dcop = 0; + dcopObject(); // build it + + m_importData = new TDEAction( i18n( "Import Data..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( importData() ), + actionCollection(), "import_data" ); +#if 0 + TDEAction * actionExtraCreateTemplate = +#endif + new TDEAction( i18n( "&Create Template From Document..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( extraCreateTemplate() ), + actionCollection(), "extra_template" ); + + m_wizard = new TDEAction( i18n("Customize with &Wizard..."), + "wizard", 0, + TQT_TQOBJECT(this), TQT_SLOT( wizard() ), + actionCollection(), "wizard"); + m_edit = new TDEAction( i18n("Edit &Data..."), "edit", 0, + TQT_TQOBJECT(this), TQT_SLOT( editData() ), + actionCollection(), "editdata"); + m_config = new TDEAction( i18n( "&Chart..." ), "configure", 0, + + TQT_TQOBJECT(this), TQT_SLOT( slotConfig() ), + actionCollection(), "config" ); + + // One TDEToggleAction per chart type + m_chartbars = new TDEToggleAction( i18n("&Bar"), "chart_bar_3d", 0, TQT_TQOBJECT(this), + TQT_SLOT( barsChart() ), actionCollection(), + "barschart"); + m_chartbars->setExclusiveGroup( "charttypes" ); + m_chartbars->setChecked( true ); + + m_chartline = new TDEToggleAction( i18n("&Line"), "chart_line", 0, TQT_TQOBJECT(this), + TQT_SLOT( lineChart() ), actionCollection(), + "linechart"); + m_chartline->setExclusiveGroup( "charttypes" ); + + m_chartareas = new TDEToggleAction( i18n("&Area"), "chart_area", 0, TQT_TQOBJECT(this), + TQT_SLOT( areasChart() ), actionCollection(), + "areaschart"); + m_chartareas->setExclusiveGroup( "charttypes" ); + + m_charthilo = new TDEToggleAction( i18n("&HiLo"), "chart_hilo", 0, TQT_TQOBJECT(this), + TQT_SLOT( hiLoChart() ), actionCollection(), + "hilochart"); + m_charthilo->setExclusiveGroup( "charttypes" ); + + m_chartbw = new TDEToggleAction( i18n("Bo&x && Whiskers"), "chart_boxwhisker", 0, TQT_TQOBJECT(this), + TQT_SLOT( bwChart() ), actionCollection(), + "bwchart"); + m_chartbw->setExclusiveGroup( "charttypes" ); + + m_chartpie = new TDEToggleAction( i18n("&Pie"), "chart_pie", 0, TQT_TQOBJECT(this), + TQT_SLOT( pieChart() ), actionCollection(), + "piechart"); + m_chartpie->setExclusiveGroup( "charttypes" ); + + m_chartring = new TDEToggleAction( i18n("&Ring"), "chart_ring", 0, TQT_TQOBJECT(this), + TQT_SLOT( ringChart() ), actionCollection(), + "ringchart"); + m_chartring->setExclusiveGroup( "charttypes" ); + + m_chartpolar = new TDEToggleAction( i18n("&Polar"), "chart_polar", 0, TQT_TQOBJECT(this), + TQT_SLOT( polarChart() ), actionCollection(), + "polarchart"); + m_chartpolar->setExclusiveGroup( "charttypes" ); + + // Configuration TDEActions + m_colorConfig = new TDEAction( i18n( "&Colors..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigColor() ), + actionCollection(), "color_config" ); + + m_fontConfig = new TDEAction( i18n( "&Font..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigFont() ), + actionCollection(), "font_config" ); + + m_backConfig = new TDEAction( i18n( "&Background..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigBack() ), + actionCollection(), "back_config" ); + + m_legendConfig = new TDEAction( i18n( "&Legend..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigLegend() ), + actionCollection(), "legend_config" ); + + m_subTypeChartConfig = new TDEAction( i18n( "Chart &Sub-type..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigSubTypeChart() ), + actionCollection(), "legend_subtype" ); + + m_dataFormatConfig = new TDEAction( i18n( "&Data Format..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigDataFormat() ), + actionCollection(), "data_format" ); + + m_headerFooterConfig = new TDEAction( i18n( "&Header && Footer..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigHeaderFooterChart() ), + actionCollection(), "headerfooter_subtype" ); + + m_pageLayoutConfig = new TDEAction( i18n( "Page Layout..." ), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotConfigPageLayout() ), + actionCollection(), "page_layout" ); + + // initialize the configuration + // loadConfig(); + + // Disable some things if we can't change the data, e.g. because + // we are inside another application that provides the data for us. + if (!((KChartPart*)koDocument())->canChangeValue()) { + m_edit->setEnabled(false); + m_importData->setEnabled(false); + } + + updateGuiTypeOfChart(); +} + + +KChartView::~KChartView() +{ + delete m_dcop; +} + + +DCOPObject* KChartView::dcopObject() +{ + if ( !m_dcop ) + m_dcop = new KChartViewIface( this ); + + return m_dcop; +} + + +void KChartView::paintEvent( TQPaintEvent* /*ev*/ ) +{ + TQPainter painter( this ); + + // ### TODO: Scaling + + // Let the document do the drawing + // This calls KChartPart::paintContent, basically. + koDocument()->paintEverything( painter, rect(), false, this ); +} + + +void KChartView::updateReadWrite( bool /*readwrite*/ ) +{ +#ifdef __GNUC__ +#warning TODO +#endif +} + + +// Edit the data to the chart. +// This opens a spreadsheet like editor with the data in it. +// + +void KChartView::editData() +{ + kchartDataEditor ed(this); + KChartParams *params = ((KChartPart*)koDocument())->params(); + KDChartTableData *dat = ((KChartPart*)koDocument())->data(); + + kdDebug(35001) << "***Before calling editor: cols =" << dat->cols() + << " , rows = " << dat->rows() + << " , usedCols = " << dat->usedCols() + << " usedRows = " << dat->usedRows() << endl; + + ed.setData( params, dat ); + ed.setRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); + ed.setColLabels(((KChartPart*)koDocument())->colLabelTexts()); + + // Activate the Apply button in the editor. + connect(&ed, TQT_SIGNAL(applyClicked(kchartDataEditor *)), + TQT_TQOBJECT(this), TQT_SLOT(applyEdit(kchartDataEditor *))); + + // Execute the data editor. + if ( ed.exec() != TQDialog::Accepted ) { + return; + } + if (!ed.modified()) + return; + + // Get the data and legend back. + ed.getData(params, dat); + ed.getRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); + ed.getColLabels(((KChartPart*)koDocument())->colLabelTexts()); + ((KChartPart*)koDocument())->setModified(true); + + kdDebug(35001) << "***After calling editor: cols =" << dat->cols() + << " , rows = " << dat->rows() + << " , usedCols = " << dat->usedCols() + << " usedRows = " << dat->usedRows() << endl; + update(); +} + + +void KChartView::applyEdit(kchartDataEditor *ed) +{ + if (!ed->modified()) + return; + + ed->getData( ((KChartPart*)koDocument())->params(), + ((KChartPart*)koDocument())->data() ); + ed->getRowLabels(((KChartPart*)koDocument())->rowLabelTexts()); + ed->getColLabels(((KChartPart*)koDocument())->colLabelTexts()); + + ((KChartPart*)koDocument())->setModified(true); + + update(); +} + + +void KChartView::wizard() +{ + kdDebug(35001) << "Wizard called" << endl; + KChartWizard *wiz = new KChartWizard((KChartPart*)koDocument(), this, + "KChart Wizard", true); + kdDebug(35001) << "Executed. Now, display it" << endl; + if (wiz->exec()) { + ((KChartPart*)koDocument())->setModified(true); + update(); + updateGuiTypeOfChart(); + kdDebug(35001) << "Ok, executed..." << endl; + } +} + + +void KChartView::updateGuiTypeOfChart() +{ + KDChartParams* params = ((KChartPart*)koDocument())->params(); + + switch(params->chartType()) { + case KDChartParams::Bar: + m_chartbars->setChecked(true); + break; + case KDChartParams::Line: + m_chartline->setChecked(true); + break; + case KDChartParams::Area: + m_chartareas->setChecked(true); + break; + case KDChartParams::Pie: + m_chartpie->setChecked(true); + break; + case KDChartParams::HiLo: + m_charthilo->setChecked(true); + break; + case KDChartParams::Ring: + m_chartring->setChecked(true); + break; + case KDChartParams::Polar: + m_chartpolar->setChecked(true); + break; + case KDChartParams::BoxWhisker: + m_chartbw->setChecked( true ); + break; + default: + //todo + break; + } + + // Disable subtype configuration button if appropriate. + updateButton(); +} + + +void KChartView::slotConfig() +{ + config(KChartConfigDialog::KC_ALL); +} + + +void KChartView::config(int flags) +{ + // open a config dialog depending on the chart type + KChartParams *params = ((KChartPart*)koDocument())->params(); + KDChartTableData *dat = ((KChartPart*)koDocument())->data(); + + KChartConfigDialog *d = new KChartConfigDialog( params, this, flags, + dat ); + + connect( d, TQT_SIGNAL( dataChanged() ), + TQT_TQOBJECT(this), TQT_SLOT( slotRepaint() ) ); + d->exec(); + delete d; +} + + +void KChartView::slotRepaint() +{ + ((KChartPart*)koDocument())->setModified(true); + update(); +} + + +void KChartView::saveConfig() +{ + kdDebug(35001) << "Save config..." << endl; + ((KChartPart*)koDocument())->saveConfig( TDEGlobal::config() ); +} + + +void KChartView::loadConfig() +{ + kdDebug(35001) << "Load config..." << endl; + + TDEGlobal::config()->reparseConfiguration(); + ((KChartPart*)koDocument())->loadConfig( TDEGlobal::config() ); + + updateGuiTypeOfChart(); + //refresh chart when you load config + update(); +} + + +void KChartView::defaultConfig() +{ + ((KChartPart*)koDocument())->defaultConfig( ); + updateGuiTypeOfChart(); + update(); +} + + +void KChartView::pieChart() +{ + if ( m_chartpie->isChecked() ) { + forceAxisParams(false); + KChartParams *params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::Pie ); + params->setThreeDPies(params->threeDBars()); + params->setExplodeFactor( 0 ); + params->setExplode( true ); + + updateButton(); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartpie->setChecked( true ); // always one has to be checked ! +} + +void KChartView::forceAxisParams(bool lineMode) { + KChartParams *params = ((KChartPart*)koDocument())->params(); + KDChartAxisParams axisParams; + axisParams = params->axisParams( KDChartAxisParams::AxisPosLeft ); + if(params->chartType() == KChartParams::Line) + m_logarithmicScale = axisParams.axisCalcMode(); + if(lineMode) { + if(m_logarithmicScale) + axisParams.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic); + } else + axisParams.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear); + params->setAxisParams( KDChartAxisParams::AxisPosLeft, axisParams ); +} + +void KChartView::lineChart() +{ + if ( m_chartline->isChecked() ) { + forceAxisParams(true); + KChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::Line ); + params->setLineChartSubType( KDChartParams::LineNormal ); + + updateButton(); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartline->setChecked( true ); // always one has to be checked ! + +} + + +void KChartView::barsChart() +{ + if ( m_chartbars->isChecked() ) { + forceAxisParams(false); + KChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::Bar ); + params->setBarChartSubType( KDChartParams::BarNormal ); + + updateButton(); + params->setThreeDBars( params->threeDPies() ); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartbars->setChecked( true ); // always one has to be checked ! +} + + +void KChartView::areasChart() +{ + if ( m_chartareas->isChecked() ) { + forceAxisParams(false); + KChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::Area ); + params->setAreaChartSubType( KDChartParams::AreaNormal ); + + updateButton(); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartareas->setChecked( true ); // always one has to be checked ! + +} + + +void KChartView::hiLoChart() +{ + if ( m_charthilo->isChecked() ) { + forceAxisParams(false); + KChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::HiLo ); + params->setHiLoChartSubType( KDChartParams::HiLoNormal ); + + updateButton(); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_charthilo->setChecked( true ); // always one has to be checked ! +} + + +void KChartView::ringChart() +{ + if ( m_chartring->isChecked() ) { + forceAxisParams(false); + KChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KChartParams::Ring ); + + updateButton(); + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartring->setChecked( true ); // always one has to be checked ! + +} + + +void KChartView::polarChart() +{ + if ( m_chartpolar->isChecked() ) { + forceAxisParams(false); + KDChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KDChartParams::Polar ); + params->setPolarChartSubType( KDChartParams::PolarNormal ); + + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartpolar->setChecked( true ); // always one has to be checked ! +} + + +void KChartView::bwChart() +{ + if ( m_chartbw->isChecked() ) { + forceAxisParams(false); + KDChartParams* params = ((KChartPart*)koDocument())->params(); + + params->setChartType( KDChartParams::BoxWhisker ); + params->setBWChartSubType( KDChartParams::BWNormal ); + + update(); + ((KChartPart*)koDocument())->setModified(true); + } + else + m_chartbw->setChecked( true ); // always one has to be checked ! +} + + +void KChartView::mousePressEvent ( TQMouseEvent *e ) +{ + if (!koDocument()->isReadWrite() || !factory()) + return; + if ( e->button() == Qt::RightButton ) + ((TQPopupMenu*)factory()->container("action_popup",this))->popup(TQCursor::pos()); +} + + +void KChartView::slotConfigColor() +{ + config(KChartConfigDialog::KC_COLORS); +} + + +void KChartView::slotConfigFont() +{ + config(KChartConfigDialog::KC_FONT); +} + + +void KChartView::slotConfigBack() +{ + config(KChartConfigDialog::KC_BACK); +} + + +void KChartView::slotConfigLegend() +{ + config(KChartConfigDialog::KC_LEGEND); +} + +void KChartView::slotConfigDataFormat() +{ + config(KChartConfigDialog::KC_DATAFORMAT); +} + +void KChartView::slotConfigSubTypeChart() +{ + config(KChartConfigDialog::KC_SUBTYPE); +} + + +void KChartView::slotConfigHeaderFooterChart() +{ + config(KChartConfigDialog::KC_HEADERFOOTER); +} + + +// FIXME: Rename into something suitable. +void KChartView::updateButton() +{ + // Disable sub chart config item. + KChartParams* params = ((KChartPart*)koDocument())->params(); + + bool state=(params->chartType()==KChartParams::Bar || + params->chartType()==KChartParams::Area || + params->chartType()==KChartParams::Line || + params->chartType()==KChartParams::HiLo || + params->chartType()==KChartParams::Polar); + m_subTypeChartConfig->setEnabled(state); +} + + +void KChartView::slotConfigPageLayout() +{ + KChartParams *params = ((KChartPart*)koDocument())->params(); + KChartPageLayout *dialog = new KChartPageLayout(params, this, + "Page Layout"); + + connect( dialog, TQT_SIGNAL( dataChanged() ), + this, TQT_SLOT( slotRepaint() ) ); + + dialog->exec(); + delete dialog; +} + + +void KChartView::setupPrinter( KPrinter &printer ) +{ + if ( !printer.previewOnly() ) + printer.addDialogPage( new KChartPrinterDlg( 0, "KChart page" ) ); +} + + +void KChartView::print(KPrinter &printer) +{ + printer.setFullPage( false ); + + TQPainter painter; + painter.begin(&printer); + TQPaintDeviceMetrics pdm( &printer ); + + int height; + int width; + if ( !printer.previewOnly() ) { + int const scalex = printer.option("kde-kchart-printsizex").toInt(); + int const scaley = printer.option("kde-kchart-printsizey").toInt(); + + width = pdm.width() * scalex / 100; + height = pdm.height() * scaley / 100; + } + else { + // Fill the whole page. + width = pdm.width(); + height = pdm.height(); + } + + TQRect rect(0, 0, width, height); + KDChart::print(&painter, + ((KChartPart*)koDocument())->params(), + ((KChartPart*)koDocument())->data(), + 0, // regions + &rect); + + painter.end(); +} + + +// Import data from a Comma Separated Values file. +// + +void KChartView::importData() +{ + // Get the name of the file to open. + TQString filename = KFileDialog::getOpenFileName(TQString(),// startDir + TQString(),// filter + 0, + i18n("Import Data")); + kdDebug(35001) << "Filename = <" << filename << ">" << endl; + if (filename.isEmpty()) + return; + + // Check to see if we can read the file. + TQFile inFile(filename); + if (!inFile.open(IO_ReadOnly)) { + KMessageBox::sorry( 0, i18n("The file %1 could not be read.") + .arg(filename) ); + inFile.close(); + return; + } + + // Let the CSV dialog structure the data in the file. + TQByteArray inData( inFile.readAll() ); + inFile.close(); + CSVImportDialog *dialog = new CSVImportDialog(0L, inData); + + if ( !dialog->exec() ) { + kdDebug(35001) << "Cancel was pressed" << endl; + return; + } + + kdDebug(35001) << "OK was pressed" << endl; + + uint rows = dialog->rows(); + uint cols = dialog->cols(); + + kdDebug(35001) << "Rows: " << rows << " Cols: " << cols << endl; + + bool hasRowHeaders = ( rows > 1 && dialog->firstRowContainHeaders() ); + bool hasColHeaders = ( cols > 1 && dialog->firstColContainHeaders() ); + + KDChartTableData data( rows, cols ); + data.setUsedRows( rows ); + data.setUsedCols( cols ); + for (uint row = 0; row < rows; row++) { + for (uint col = 0; col < cols; col++) { + bool ok; + TQString tmp; + double val; + + // Get the text and convert to double unless in the headers. + tmp = dialog->text( row, col ); + if ( ( row == 0 && hasRowHeaders ) + || ( col == 0 && hasColHeaders ) ) { + kdDebug(35001) << "Setting header (" << row << "," << col + << ") to value " << tmp << endl; + data.setCell( row, col, tmp ); + } + else { + val = tmp.toDouble(&ok); + if (!ok) + val = 0.0; + + kdDebug(35001) << "Setting (" << row << "," << col + << ") to value " << val << endl; + + // and do the actual setting. + data.setCell( row, col, val ); + } + } + } + + ((KChartPart*)koDocument())->doSetData( data, + hasRowHeaders, hasColHeaders ); +} + + +void KChartView::extraCreateTemplate() +{ + int width = 60; + int height = 60; + TQPixmap pix = koDocument()->generatePreview(TQSize(width, height)); + + KTempFile tempFile( TQString(), ".chrt" ); + tempFile.setAutoDelete(true); + + koDocument()->saveNativeFormat( tempFile.name() ); + + KoTemplateCreateDia::createTemplate( "kchart_template", KChartFactory::global(), + tempFile.name(), pix, this ); + + KChartFactory::global()->dirs()->addResourceType("kchart_template", + TDEStandardDirs::kde_default( "data" ) + + "kchart/templates/"); +} + + +} //KChart namespace + +#include "kchart_view.moc" diff --git a/kchart/main.cc b/kchart/main.cc deleted file mode 100644 index 97d046d1..00000000 --- a/kchart/main.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999 Kalle Dalheimer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include "kchart_aboutdata.h" - -using namespace KChart; - -namespace KChart -{ - -static const TDECmdLineOptions options[]= -{ - {"+[file]", I18N_NOOP("File to open"),0}, - TDECmdLineLastOption -}; - -} //namespace KChart - - -extern "C" KCHART_EXPORT int kdemain( int argc, char **argv ) -{ - TDECmdLineArgs::init( argc, argv, newKChartAboutData()); - TDECmdLineArgs::addCmdLineOptions( options ); - - KoApplication app; - if (!app.start()) - return 1; - app.exec(); - - return 0; -} diff --git a/kchart/main.cpp b/kchart/main.cpp new file mode 100644 index 00000000..97d046d1 --- /dev/null +++ b/kchart/main.cpp @@ -0,0 +1,50 @@ +/* This file is part of the KDE project + Copyright (C) 1999 Kalle Dalheimer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include "kchart_aboutdata.h" + +using namespace KChart; + +namespace KChart +{ + +static const TDECmdLineOptions options[]= +{ + {"+[file]", I18N_NOOP("File to open"),0}, + TDECmdLineLastOption +}; + +} //namespace KChart + + +extern "C" KCHART_EXPORT int kdemain( int argc, char **argv ) +{ + TDECmdLineArgs::init( argc, argv, newKChartAboutData()); + TDECmdLineArgs::addCmdLineOptions( options ); + + KoApplication app; + if (!app.start()) + return 1; + app.exec(); + + return 0; +} -- cgit v1.2.1