00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <kprinter.h>
00030
00031
00032 #include <assert.h>
00033 #include <stdlib.h>
00034 #include <time.h>
00035
00036
00037 #include <qbuffer.h>
00038 #include <qclipboard.h>
00039 #include <qcursor.h>
00040 #include <qlayout.h>
00041 #include <qpaintdevicemetrics.h>
00042 #include <qregexp.h>
00043 #include <qtimer.h>
00044 #include <qtoolbutton.h>
00045 #include <qsqldatabase.h>
00046 #include <qlistview.h>
00047 #include <qsizepolicy.h>
00048
00049
00050 #include <dcopclient.h>
00051 #include <dcopref.h>
00052 #include <kapplication.h>
00053 #include <kconfig.h>
00054 #include <kdebug.h>
00055 #include <kfind.h>
00056 #include <kfinddialog.h>
00057 #include <kfontdialog.h>
00058 #include <kinputdialog.h>
00059 #include <kmessagebox.h>
00060 #include <knotifyclient.h>
00061 #include <kpassdlg.h>
00062 #include <kprocio.h>
00063 #include <kreplace.h>
00064 #include <kreplacedialog.h>
00065 #include <kspell.h>
00066 #include <kspelldlg.h>
00067 #include <kstatusbar.h>
00068 #include <kstdaction.h>
00069 #include <kstandarddirs.h>
00070 #include <ktempfile.h>
00071 #include <kparts/partmanager.h>
00072 #include <klistview.h>
00073 #include <kpushbutton.h>
00074
00075
00076 #include <tkcoloractions.h>
00077 #include <kdatatool.h>
00078 #include <KoCharSelectDia.h>
00079 #include <KoCommandHistory.h>
00080 #include <KoMainWindow.h>
00081 #include <KoOasisLoadingContext.h>
00082 #include <KoOasisStore.h>
00083 #include <KoOasisStyles.h>
00084 #include <KoPartSelectAction.h>
00085 #include <KoStoreDrag.h>
00086 #include <KoTabBar.h>
00087 #include <kspread_toolbox.h>
00088 #include <KoTemplateCreateDia.h>
00089 #include <KoZoomAction.h>
00090
00091
00092 #include "commands.h"
00093 #include "damages.h"
00094 #include "digest.h"
00095 #include "inspector.h"
00096 #include "ksploadinginfo.h"
00097 #include "kspread_canvas.h"
00098 #include "kspread_editors.h"
00099 #include "kspread_events.h"
00100 #include "kspread_global.h"
00101 #include "kspread_handler.h"
00102 #include "kspread_locale.h"
00103 #include "kspread_map.h"
00104 #include "selection.h"
00105 #include "kspread_sheetprint.h"
00106 #include "kspread_style.h"
00107 #include "kspread_style_manager.h"
00108 #include "kspread_undo.h"
00109 #include "testrunner.h"
00110 #include "valuecalc.h"
00111 #include "valueconverter.h"
00112
00113
00114 #include "dialogs/kspread_dlg_angle.h"
00115 #include "dialogs/kspread_dlg_area.h"
00116 #include "dialogs/kspread_dlg_comment.h"
00117 #include "dialogs/kspread_dlg_conditional.h"
00118 #include "dialogs/kspread_dlg_cons.h"
00119 #include "dialogs/kspread_dlg_csv.h"
00120 #include "dialogs/kspread_dlg_database.h"
00121 #include "dialogs/kspread_dlg_format.h"
00122 #include "dialogs/kspread_dlg_formula.h"
00123 #include "dialogs/kspread_dlg_goalseek.h"
00124 #include "dialogs/kspread_dlg_goto.h"
00125 #include "dialogs/kspread_dlg_insert.h"
00126 #include "dialogs/kspread_dlg_layout.h"
00127 #include "dialogs/kspread_dlg_list.h"
00128
00129 #include "dialogs/kspread_dlg_paperlayout.h"
00130 #include "dialogs/kspread_dlg_pasteinsert.h"
00131 #include "dialogs/kspread_dlg_preference.h"
00132 #include "dialogs/kspread_dlg_reference.h"
00133 #include "dialogs/kspread_dlg_resize2.h"
00134 #include "dialogs/kspread_dlg_series.h"
00135 #include "dialogs/kspread_dlg_show.h"
00136 #include "dialogs/kspread_dlg_showColRow.h"
00137 #include "dialogs/kspread_dlg_sort.h"
00138 #include "dialogs/kspread_dlg_special.h"
00139 #include "dialogs/kspread_dlg_styles.h"
00140 #include "dialogs/kspread_dlg_subtotal.h"
00141 #include "dialogs/kspread_dlg_validity.h"
00142 #include "dialogs/link.h"
00143 #include "dialogs/sheet_properties.h"
00144 #include "dialogs/kspread_dlg_find.h"
00145 #include "dialogs/SheetSelectWidget.h"
00146 #include "kspread_propertyEditor.h"
00147 #include "kspread_generalProperty.h"
00148
00149
00150 #include "KSpreadViewIface.h"
00151
00152 #include "kspread_view.h"
00153
00154 namespace KSpread
00155 {
00156 class ViewActions;
00157
00158 class View::Private
00159 {
00160 public:
00161 View* view;
00162 Doc* doc;
00163 DCOPObject* dcop;
00164
00165
00166
00167 Sheet* activeSheet;
00168
00169
00170 QWidget *frame;
00171 QFrame *toolWidget;
00172 Canvas *canvas;
00173 VBorder *vBorderWidget;
00174 HBorder *hBorderWidget;
00175 QScrollBar *horzScrollBar;
00176 QScrollBar *vertScrollBar;
00177 KoTabBar *tabBar;
00178 KStatusBarLabel* calcLabel;
00179
00180
00181 QHBoxLayout* formulaBarLayout;
00182 ComboboxLocationEditWidget *posWidget;
00183 QButton* formulaButton;
00184 QButton *okButton;
00185 QButton *cancelButton;
00186 KSpread::EditWidget *editWidget;
00187 QGridLayout* viewLayout;
00188 QHBoxLayout* tabScrollBarLayout;
00189
00190
00191 ViewActions* actions;
00192
00193
00194
00195
00196 bool toolbarLock;
00197
00198
00199
00200 bool loading;
00201
00202
00203 Selection* selection;
00204 Selection* choice;
00205 QMap<Sheet*, QPoint> savedAnchors;
00206 QMap<Sheet*, QPoint> savedMarkers;
00207 QMap<Sheet*, KoPoint> savedOffsets;
00208
00209
00210
00211 long findOptions;
00212 QStringList findStrings;
00213 QStringList replaceStrings;
00214 FindOption::searchTypeValue typeValue;
00215 FindOption::searchDirectionValue directionValue;
00216
00217 KFind* find;
00218 KReplace* replace;
00219 int findLeftColumn;
00220 int findRightColumn;
00221 QPoint findPos;
00222 QPoint findEnd;
00223
00224 InsertHandler* insertHandler;
00225
00226
00227 KoCharSelectDia* specialCharDlg;
00228
00229
00230 QGuardedPtr<KoTransformToolBox> transformToolBox;
00231
00232
00233
00234
00235 QPopupMenu *popupMenu;
00236 int popupMenuFirstToolId;
00237
00238 QPopupMenu *popupRow;
00239 QPopupMenu *popupColumn;
00240 QPopupMenu* popupChild;
00241 QPopupMenu* popupListChoose;
00242
00243
00244 Child* popupChildObject;
00245
00246
00247 struct
00248 {
00249 KSpell * kspell;
00250 Sheet * firstSpellSheet;
00251 Sheet * currentSpellSheet;
00252 Cell * currentCell;
00253 MacroUndoAction *macroCmdSpellCheck;
00254 unsigned int spellCurrCellX;
00255 unsigned int spellCurrCellY;
00256 unsigned int spellStartCellX;
00257 unsigned int spellStartCellY;
00258 unsigned int spellEndCellX;
00259 unsigned int spellEndCellY;
00260 bool spellCheckSelection;
00261 QStringList replaceAll;
00262 } spell;
00263
00264 struct
00265 {
00266 Sheet * currentSheet;
00267 Sheet * firstSheet;
00268 } searchInSheets;
00269
00270
00271 struct ToolEntry
00272 {
00273 QString command;
00274 KDataToolInfo info;
00275 };
00276 QPtrList<ToolEntry> toolList;
00277
00278 void initActions();
00279 void adjustActions( bool mode );
00280 void adjustActions( Sheet* sheet, Cell* cell );
00281 void adjustWorkbookActions( bool mode );
00282 void updateButton( Cell *cell, int column, int row);
00283 QButton* newIconButton( const char *_file, bool _kbutton = false, QWidget *_parent = 0L );
00284
00285 PropertyEditor *m_propertyEditor;
00286
00287
00288
00289 QTimer statusBarOpTimer;
00290 };
00291
00292 class ViewActions
00293 {
00294 public:
00295
00296
00297 KAction* cellLayout;
00298 KAction *actionExtraProperties;
00299 KAction* defaultFormat;
00300 KToggleAction* bold;
00301 KToggleAction* italic;
00302 KToggleAction* underline;
00303 KToggleAction* strikeOut;
00304 KFontAction* selectFont;
00305 KFontSizeAction* selectFontSize;
00306 KAction* fontSizeUp;
00307 KAction* fontSizeDown;
00308 TKSelectColorAction* textColor;
00309 KToggleAction* alignLeft;
00310 KToggleAction* alignCenter;
00311 KToggleAction* alignRight;
00312 KToggleAction* alignTop;
00313 KToggleAction* alignMiddle;
00314 KToggleAction* alignBottom;
00315 KToggleAction* wrapText;
00316 KToggleAction* verticalText;
00317 KAction* increaseIndent;
00318 KAction* decreaseIndent;
00319 KAction* changeAngle;
00320 KToggleAction* percent;
00321 KAction* precplus;
00322 KAction* precminus;
00323 KToggleAction* money;
00324 KAction* upper;
00325 KAction* lower;
00326 KAction* firstLetterUpper;
00327 TKSelectColorAction* bgColor;
00328 KAction* borderLeft;
00329 KAction* borderRight;
00330 KAction* borderTop;
00331 KAction* borderBottom;
00332 KAction* borderAll;
00333 KAction* borderOutline;
00334 KAction* borderRemove;
00335 TKSelectColorAction* borderColor;
00336 KSelectAction* selectStyle;
00337 KAction* createStyle;
00338
00339
00340 KAction* editCell;
00341 KAction* insertCell;
00342 KAction* removeCell;
00343 KAction* deleteCell;
00344 KToolBarPopupAction* mergeCell;
00345 KAction* mergeCellHorizontal;
00346 KAction* mergeCellVertical;
00347 KAction* dissociateCell;
00348 KAction* clearText;
00349 KAction* conditional;
00350 KAction* clearConditional;
00351 KAction* validity;
00352 KAction* clearValidity;
00353 KAction* addModifyComment;
00354 KAction* removeComment;
00355 KAction* clearComment;
00356
00357
00358 KAction* resizeColumn;
00359 KAction* insertColumn;
00360 KAction* deleteColumn;
00361 KAction* hideColumn;
00362 KAction* showColumn;
00363 KAction* equalizeColumn;
00364 KAction* showSelColumns;
00365 KAction* resizeRow;
00366 KAction* insertRow;
00367 KAction* deleteRow;
00368 KAction* hideRow;
00369 KAction* showRow;
00370 KAction* equalizeRow;
00371 KAction* showSelRows;
00372 KAction* adjust;
00373
00374
00375 KAction* sheetProperties;
00376 KAction* insertSheet;
00377 KAction* menuInsertSheet;
00378 KAction* removeSheet;
00379 KAction* renameSheet;
00380 KAction* hideSheet;
00381 KAction* showSheet;
00382 KAction* autoFormat;
00383 KAction* areaName;
00384 KAction* showArea;
00385 KAction* insertSeries;
00386 KAction* insertFunction;
00387 KAction* insertSpecialChar;
00388 KAction* insertFromDatabase;
00389 KAction* insertFromTextfile;
00390 KAction* insertFromClipboard;
00391 KAction* transform;
00392 KAction* sort;
00393 KAction* sortDec;
00394 KAction* sortInc;
00395 KAction* fillRight;
00396 KAction* fillLeft;
00397 KAction* fillUp;
00398 KAction* fillDown;
00399 KAction* paperLayout;
00400 KAction* definePrintRange;
00401 KAction* resetPrintRange;
00402 KToggleAction* showPageBorders;
00403 KAction* recalcWorksheet;
00404 KAction* recalcWorkbook;
00405 KToggleAction* protectSheet;
00406 KToggleAction* protectDoc;
00407
00408
00409 KAction* cut;
00410 KAction* copy;
00411 KAction* paste;
00412 KAction* specialPaste;
00413 KAction* insertCellCopy;
00414 KAction* find;
00415 KAction* replace;
00416
00417
00418 KAction* gotoCell;
00419 KAction* nextSheet;
00420 KAction* prevSheet;
00421 KAction* firstSheet;
00422 KAction* lastSheet;
00423
00424
00425 KAction* styleDialog;
00426 KAction* autoSum;
00427 KSelectAction* formulaSelection;
00428 KAction* insertLink;
00429 KAction* removeLink;
00430 KAction* consolidate;
00431 KAction* goalSeek;
00432 KAction* subTotals;
00433 KAction* textToColumns;
00434 KAction* multipleOperations;
00435 KAction* createTemplate;
00436 KoPartSelectAction *insertPart;
00437 KToggleAction* insertChartFrame;
00438 KAction* insertPicture;
00439 KAction* customList;
00440 KAction* spellChecking;
00441 KAction* internalTests;
00442 KAction* inspector;
00443
00444
00445 KoZoomAction* viewZoom;
00446 KToggleAction* showStatusBar;
00447 KToggleAction* showTabBar;
00448 KToggleAction* showFormulaBar;
00449 KAction* preference;
00450
00451
00452 KToggleAction* calcNone;
00453 KToggleAction* calcMin;
00454 KToggleAction* calcMax;
00455 KToggleAction* calcAverage;
00456 KToggleAction* calcCount;
00457 KToggleAction* calcSum;
00458 KToggleAction* calcCountA;
00459 };
00460
00461
00462 void View::Private::initActions()
00463 {
00464 actions = new ViewActions;
00465
00466 KActionCollection* ac = view->actionCollection();
00467
00468
00469
00470 actions->cellLayout = new KAction( i18n("Cell Format..."), "cell_layout",
00471 Qt::CTRL+ Qt::ALT+ Qt::Key_F, view, SLOT( layoutDlg() ), ac, "cellLayout" );
00472 actions->cellLayout->setToolTip( i18n("Set the cell formatting.") );
00473
00474 actions->actionExtraProperties = new KAction( i18n( "&Properties" ), "penbrush", 0,
00475 view, SLOT( extraProperties() ), ac, "extra_properties" );
00476
00477 actions->defaultFormat = new KAction( i18n("Default"),
00478 0, view, SLOT( defaultSelection() ), ac, "default" );
00479 actions->defaultFormat->setToolTip( i18n("Resets to the default format.") );
00480
00481 actions->bold = new KToggleAction( i18n("Bold"), "text_bold",
00482 Qt::CTRL+Qt::Key_B, ac, "bold");
00483 QObject::connect( actions->bold, SIGNAL( toggled( bool) ),
00484 view, SLOT( bold( bool ) ) );
00485
00486 actions->italic = new KToggleAction( i18n("Italic"), "text_italic",
00487 Qt::CTRL+Qt::Key_I, ac, "italic");
00488 QObject::connect( actions->italic, SIGNAL( toggled( bool) ),
00489 view, SLOT( italic( bool ) ) );
00490
00491 actions->underline = new KToggleAction( i18n("Underline"), "text_under",
00492 Qt::CTRL+Qt::Key_U, ac, "underline");
00493 QObject::connect( actions->underline, SIGNAL( toggled( bool) ),
00494 view, SLOT( underline( bool ) ) );
00495
00496 actions->strikeOut = new KToggleAction( i18n("Strike Out"), "text_strike",
00497 0, ac, "strikeout");
00498 QObject::connect( actions->strikeOut, SIGNAL( toggled( bool) ),
00499 view, SLOT( strikeOut( bool ) ) );
00500
00501 actions->selectFont = new KFontAction( i18n("Select Font..."),
00502 0, ac, "selectFont" );
00503 QObject::connect( actions->selectFont, SIGNAL( activated( const QString& ) ),
00504 view, SLOT( fontSelected( const QString& ) ) );
00505
00506 actions->selectFontSize = new KFontSizeAction( i18n("Select Font Size"),
00507 0, ac, "selectFontSize" );
00508 QObject::connect( actions->selectFontSize, SIGNAL( fontSizeChanged( int ) ),
00509 view, SLOT( fontSizeSelected( int ) ) );
00510
00511 actions->fontSizeUp = new KAction( i18n("Increase Font Size"), "fontsizeup",
00512 0, view, SLOT( increaseFontSize() ), ac, "increaseFontSize" );
00513
00514 actions->fontSizeDown = new KAction( i18n("Decrease Font Size"), "fontsizedown",
00515 0, view, SLOT( decreaseFontSize() ), ac, "decreaseFontSize" );
00516
00517 actions->textColor = new TKSelectColorAction( i18n("Text Color"),
00518 TKSelectColorAction::TextColor, view, SLOT( changeTextColor() ),
00519 ac, "textColor",true );
00520 actions->textColor->setDefaultColor(QColor());
00521
00522 actions->alignLeft = new KToggleAction( i18n("Align Left"), "text_left",
00523 0, ac, "left");
00524 QObject::connect( actions->alignLeft, SIGNAL( toggled( bool ) ),
00525 view, SLOT( alignLeft( bool ) ) );
00526 actions->alignLeft->setExclusiveGroup( "Align" );
00527 actions->alignLeft->setToolTip(i18n("Left justify the cell contents."));
00528
00529 actions->alignCenter = new KToggleAction( i18n("Align Center"), "text_center",
00530 0, ac, "center");
00531 QObject::connect( actions->alignCenter, SIGNAL( toggled( bool ) ),
00532 view, SLOT( alignCenter( bool ) ) );
00533 actions->alignCenter->setExclusiveGroup( "Align" );
00534 actions->alignCenter->setToolTip(i18n("Center the cell contents."));
00535
00536 actions->alignRight = new KToggleAction( i18n("Align Right"), "text_right",
00537 0, ac, "right");
00538 QObject::connect( actions->alignRight, SIGNAL( toggled( bool ) ),
00539 view, SLOT( alignRight( bool ) ) );
00540 actions->alignRight->setExclusiveGroup( "Align" );
00541 actions->alignRight->setToolTip(i18n("Right justify the cell contents."));
00542
00543 actions->alignTop = new KToggleAction( i18n("Align Top"), "text_top",
00544 0, ac, "top");
00545 QObject::connect( actions->alignTop, SIGNAL( toggled( bool ) ),
00546 view, SLOT( alignTop( bool ) ) );
00547 actions->alignTop->setExclusiveGroup( "Pos" );
00548 actions->alignTop->setToolTip(i18n("Align cell contents along the top of the cell."));
00549
00550 actions->alignMiddle = new KToggleAction( i18n("Align Middle"), "middle",
00551 0, ac, "middle");
00552 QObject::connect( actions->alignMiddle, SIGNAL( toggled( bool ) ),
00553 view, SLOT( alignMiddle( bool ) ) );
00554 actions->alignMiddle->setExclusiveGroup( "Pos" );
00555 actions->alignMiddle->setToolTip(i18n("Align cell contents centered in the cell."));
00556
00557 actions->alignBottom = new KToggleAction( i18n("Align Bottom"), "text_bottom",
00558 0, ac, "bottom");
00559 QObject::connect( actions->alignBottom, SIGNAL( toggled( bool ) ),
00560 view, SLOT( alignBottom( bool ) ) );
00561 actions->alignBottom->setExclusiveGroup( "Pos" );
00562 actions->alignBottom->setToolTip(i18n("Align cell contents along the bottom of the cell."));
00563
00564 actions->wrapText = new KToggleAction( i18n("Wrap Text"), "multirow",
00565 0, ac, "multiRow" );
00566 QObject::connect( actions->wrapText, SIGNAL( toggled( bool ) ),
00567 view, SLOT( wrapText( bool ) ) );
00568 actions->wrapText->setToolTip(i18n("Make the cell text wrap onto multiple lines."));
00569
00570 actions->verticalText = new KToggleAction( i18n("Vertical Text"),"vertical_text" ,
00571 0 ,ac, "verticaltext" );
00572 QObject::connect( actions->verticalText, SIGNAL( toggled( bool ) ),
00573 view, SLOT( verticalText( bool ) ) );
00574 actions->verticalText->setToolTip(i18n("Print cell contents vertically."));
00575
00576 actions->increaseIndent = new KAction( i18n("Increase Indent"),
00577 QApplication::reverseLayout() ? "format_decreaseindent":"format_increaseindent",
00578 0, view, SLOT( increaseIndent() ), ac, "increaseindent" );
00579 actions->increaseIndent->setToolTip(i18n("Increase the indentation."));
00580
00581 actions->decreaseIndent = new KAction( i18n("Decrease Indent"),
00582 QApplication::reverseLayout() ? "format_increaseindent" : "format_decreaseindent",
00583 0, view, SLOT( decreaseIndent() ), ac, "decreaseindent");
00584 actions->decreaseIndent->setToolTip(i18n("Decrease the indentation."));
00585
00586 actions->changeAngle = new KAction( i18n("Change Angle..."),
00587 0, view, SLOT( changeAngle() ), ac, "changeangle" );
00588 actions->changeAngle->setToolTip(i18n("Change the angle that cell contents are printed."));
00589
00590 actions->percent = new KToggleAction( i18n("Percent Format"), "percent",
00591 0, ac, "percent");
00592 QObject::connect( actions->percent, SIGNAL( toggled( bool ) ),
00593 view, SLOT( percent( bool ) ) );
00594 actions->percent->setToolTip(i18n("Set the cell formatting to look like a percentage."));
00595
00596 actions->precplus = new KAction( i18n("Increase Precision"), "prec_plus",
00597 0, view, SLOT( precisionPlus() ), ac, "precplus");
00598 actions->precplus->setToolTip(i18n("Increase the decimal precision shown onscreen."));
00599
00600 actions->precminus = new KAction( i18n("Decrease Precision"), "prec_minus",
00601 0, view, SLOT( precisionMinus() ), ac, "precminus");
00602 actions->precminus->setToolTip(i18n("Decrease the decimal precision shown onscreen."));
00603
00604 actions->money = new KToggleAction( i18n("Money Format"), "money",
00605 0, ac, "money");
00606 QObject::connect( actions->money, SIGNAL( toggled( bool ) ),
00607 view, SLOT( moneyFormat( bool ) ) );
00608 actions->money->setToolTip(i18n("Set the cell formatting to look like your local currency."));
00609
00610 actions->upper = new KAction( i18n("Upper Case"), "fontsizeup",
00611 0, view, SLOT( upper() ), ac, "upper" );
00612 actions->upper->setToolTip(i18n("Convert all letters to upper case."));
00613
00614 actions->lower = new KAction( i18n("Lower Case"), "fontsizedown",
00615 0, view, SLOT( lower() ), ac, "lower" );
00616 actions->lower->setToolTip(i18n("Convert all letters to lower case."));
00617
00618 actions->firstLetterUpper = new KAction( i18n("Convert First Letter to Upper Case"), "first_letter_upper",
00619 0, view, SLOT( firstLetterUpper() ),ac, "firstletterupper" );
00620 actions->firstLetterUpper->setToolTip(i18n("Capitalize the first letter."));
00621
00622 actions->bgColor = new TKSelectColorAction( i18n("Background Color"),
00623 TKSelectColorAction::FillColor, ac, "backgroundColor", true );
00624 QObject::connect(actions->bgColor, SIGNAL( activated() ),
00625 view, SLOT( changeBackgroundColor() ) );
00626 actions->bgColor->setDefaultColor(QColor());
00627 actions->bgColor->setToolTip(i18n("Set the background color."));
00628
00629 actions->borderLeft = new KAction( i18n("Border Left"), "border_left",
00630 0, view, SLOT( borderLeft() ), ac, "borderLeft" );
00631 actions->borderLeft->setToolTip(i18n("Set a left border to the selected area."));
00632
00633 actions->borderRight = new KAction( i18n("Border Right"), "border_right",
00634 0, view, SLOT( borderRight() ), ac, "borderRight" );
00635 actions->borderRight->setToolTip(i18n("Set a right border to the selected area."));
00636
00637 actions->borderTop = new KAction( i18n("Border Top"), "border_top",
00638 0, view, SLOT( borderTop() ), ac, "borderTop" );
00639 actions->borderTop->setToolTip(i18n("Set a top border to the selected area."));
00640
00641 actions->borderBottom = new KAction( i18n("Border Bottom"), "border_bottom",
00642 0, view, SLOT( borderBottom() ), ac, "borderBottom" );
00643 actions->borderBottom->setToolTip(i18n("Set a bottom border to the selected area."));
00644
00645 actions->borderAll = new KAction( i18n("All Borders"), "border_all",
00646 0, view, SLOT( borderAll() ), ac, "borderAll" );
00647 actions->borderAll->setToolTip(i18n("Set a border around all cells in the selected area."));
00648
00649 actions->borderRemove = new KAction( i18n("Remove Borders"), "border_remove",
00650 0, view, SLOT( borderRemove() ), ac, "borderRemove" );
00651 actions->borderRemove->setToolTip(i18n("Remove all borders in the selected area."));
00652
00653 actions->borderOutline = new KAction( i18n("Border Outline"), ("border_outline"),
00654 0, view, SLOT( borderOutline() ), ac, "borderOutline" );
00655 actions->borderOutline->setToolTip(i18n("Set a border to the outline of the selected area."));
00656
00657 actions->borderColor = new TKSelectColorAction( i18n("Border Color"),
00658 TKSelectColorAction::LineColor, ac, "borderColor" );
00659 QObject::connect( actions->borderColor, SIGNAL( activated() ),
00660 view, SLOT( changeBorderColor() ) );
00661 actions->borderColor->setToolTip( i18n( "Select a new border color." ) );
00662
00663 actions->selectStyle = new KSelectAction( i18n( "St&yle" ),
00664 0, ac, "stylemenu" );
00665 actions->selectStyle->setToolTip( i18n( "Apply a predefined style to the selected cells." ) );
00666 QObject::connect( actions->selectStyle, SIGNAL( activated( const QString & ) ),
00667 view, SLOT( styleSelected( const QString & ) ) );
00668
00669 actions->createStyle = new KAction( i18n( "Create Style From Cell..." ),
00670 0, view, SLOT( createStyleFromCell()), ac, "createStyle" );
00671 actions->createStyle->setToolTip( i18n( "Create a new style based on the currently selected cell." ) );
00672
00673
00674
00675 actions->editCell = new KAction( i18n("Modify Cell"),"cell_edit",
00676 Qt::CTRL+Qt::Key_M, view, SLOT( editCell() ), ac, "editCell" );
00677 actions->editCell->setToolTip(i18n("Edit the highlighted cell."));
00678
00679 actions->insertCell = new KAction( i18n("Insert Cells..."), "insertcell",
00680 0, view, SLOT( slotInsert() ), ac, "insertCell" );
00681 actions->insertCell->setToolTip(i18n("Insert a blank cell into the spreadsheet."));
00682
00683 actions->removeCell = new KAction( i18n("Remove Cells..."), "removecell",
00684 0, view, SLOT( slotRemove() ), ac, "removeCell" );
00685 actions->removeCell->setToolTip(i18n("Removes the current cell from the spreadsheet."));
00686
00687 actions->deleteCell = new KAction( i18n("Delete"), "deletecell",
00688 0, view, SLOT( deleteSelection() ), ac, "delete" );
00689 actions->deleteCell->setToolTip(i18n("Delete all contents and formatting of the current cell."));
00690
00691 actions->mergeCell = new KToolBarPopupAction( i18n("Merge Cells"),"mergecell",
00692 0, view, SLOT( mergeCell() ), ac, "mergecell" );
00693 actions->mergeCell->setToolTip(i18n("Merge the selected region."));
00694 actions->mergeCell->plug( actions->mergeCell->popupMenu() );
00695
00696 actions->mergeCellHorizontal = new KAction( i18n("Merge Cells Horizontally"),"mergecell-horizontal",
00697 0, view, SLOT( mergeCellHorizontal() ), ac, "mergecellHorizontal" );
00698 actions->mergeCellHorizontal->setToolTip(i18n("Merge the selected region horizontally."));
00699 actions->mergeCellHorizontal->plug( actions->mergeCell->popupMenu() );
00700
00701 actions->mergeCellVertical = new KAction( i18n("Merge Cells Vertically"),"mergecell-vertical",
00702 0, view, SLOT( mergeCellVertical() ), ac, "mergecellVertical" );
00703 actions->mergeCellVertical->setToolTip(i18n("Merge the selected region vertically."));
00704 actions->mergeCellVertical->plug( actions->mergeCell->popupMenu() );
00705
00706 actions->dissociateCell = new KAction( i18n("Dissociate Cells"),"dissociatecell",
00707 0, view, SLOT( dissociateCell() ), ac, "dissociatecell" );
00708 actions->dissociateCell->setToolTip(i18n("Unmerge the selected region."));
00709
00710 actions->clearText = new KAction( i18n("Text"),
00711 0, view, SLOT( clearTextSelection() ), ac, "cleartext" );
00712 actions->clearText->setToolTip(i18n("Remove the contents of the current cell."));
00713
00714 actions->conditional = new KAction( i18n("Conditional Cell Attributes..."),
00715 0, view, SLOT( conditional() ), ac, "conditional" );
00716 actions->conditional->setToolTip(i18n("Set cell format based on certain conditions."));
00717
00718
00719 actions->clearConditional = new KAction( i18n("Conditional Cell Attributes"),
00720 0, view, SLOT( clearConditionalSelection() ), ac, "clearconditional" );
00721 actions->clearConditional->setToolTip(i18n("Remove the conditional cell formatting."));
00722
00723 actions->validity = new KAction( i18n("Validity..."),
00724 0, view, SLOT( validity() ), ac, "validity" );
00725 actions->validity->setToolTip(i18n("Set tests to confirm cell data is valid."));
00726
00727 actions->clearValidity = new KAction( i18n("Validity"),
00728 0, view, SLOT( clearValiditySelection() ), ac, "clearvalidity" );
00729 actions->clearValidity->setToolTip(i18n("Remove the validity tests on this cell."));
00730
00731 actions->addModifyComment = new KAction( i18n("&Add/Modify Comment..."),"comment",
00732 0, view, SLOT( addModifyComment() ), ac, "addmodifycomment" );
00733 actions->addModifyComment->setToolTip(i18n("Edit a comment for this cell."));
00734
00735 actions->removeComment = new KAction( i18n("&Remove Comment"),"removecomment",
00736 0, view, SLOT( removeComment() ), ac, "removecomment" );
00737 actions->removeComment->setToolTip(i18n("Remove this cell's comment."));
00738
00739 actions->clearComment = new KAction( i18n("Comment"),
00740 0, view, SLOT( clearCommentSelection() ), ac, "clearcomment" );
00741 actions->clearComment->setToolTip(i18n("Remove this cell's comment."));
00742
00743
00744
00745 actions->resizeColumn = new KAction( i18n("Resize Column..."), "resizecol",
00746 0, view, SLOT( resizeColumn() ), ac, "resizeCol" );
00747 actions->resizeColumn->setToolTip(i18n("Change the width of a column."));
00748
00749 actions->insertColumn = new KAction( i18n("Insert Columns"), "insert_table_col",
00750 0, view, SLOT( insertColumn() ), ac, "insertColumn" );
00751 actions->insertColumn->setToolTip(i18n("Inserts a new column into the spreadsheet."));
00752
00753 actions->deleteColumn = new KAction( i18n("Delete Columns"), "delete_table_col",
00754 0, view, SLOT( deleteColumn() ), ac, "deleteColumn" );
00755 actions->deleteColumn->setToolTip(i18n("Removes a column from the spreadsheet."));
00756
00757 actions->hideColumn = new KAction( i18n("Hide Columns"), "hide_table_column",
00758 0, view, SLOT( hideColumn() ), ac, "hideColumn" );
00759 actions->hideColumn->setToolTip(i18n("Hide the column from view."));
00760
00761 actions->showColumn = new KAction( i18n("Show Columns..."), "show_table_column",
00762 0, view, SLOT( showColumn() ), ac, "showColumn" );
00763 actions->showColumn->setToolTip(i18n("Show hidden columns."));
00764
00765 actions->equalizeColumn = new KAction( i18n("Equalize Column"), "adjustcol",
00766 0, view, SLOT( equalizeColumn() ), ac, "equalizeCol" );
00767 actions->equalizeColumn->setToolTip(i18n("Resizes selected columns to be the same size."));
00768
00769 actions->showSelColumns = new KAction( i18n("Show Columns"), "show_sheet_column",
00770 0, view, SLOT( showSelColumns() ), ac, "showSelColumns" );
00771 actions->showSelColumns->setToolTip(i18n("Show hidden columns in the selection."));
00772 actions->showSelColumns->setEnabled(false);
00773
00774 actions->resizeRow = new KAction( i18n("Resize Row..."), "resizerow",
00775 0, view, SLOT( resizeRow() ), ac, "resizeRow" );
00776 actions->resizeRow->setToolTip(i18n("Change the height of a row."));
00777
00778 actions->insertRow = new KAction( i18n("Insert Rows"), "insert_table_row",
00779 0, view, SLOT( insertRow() ), ac, "insertRow" );
00780 actions->insertRow->setToolTip(i18n("Inserts a new row into the spreadsheet."));
00781
00782 actions->deleteRow = new KAction( i18n("Delete Rows"), "delete_table_row",
00783 0, view, SLOT( deleteRow() ), ac, "deleteRow" );
00784 actions->deleteRow->setToolTip(i18n("Removes a row from the spreadsheet."));
00785
00786 actions->hideRow = new KAction( i18n("Hide Rows"), "hide_table_row",
00787 0, view, SLOT( hideRow() ), ac, "hideRow" );
00788 actions->hideRow->setToolTip(i18n("Hide a row from view."));
00789
00790 actions->showRow = new KAction( i18n("Show Rows..."), "show_table_row",
00791 0, view, SLOT( showRow() ), ac, "showRow" );
00792 actions->showRow->setToolTip(i18n("Show hidden rows."));
00793
00794 actions->equalizeRow = new KAction( i18n("Equalize Row"), "adjustrow",
00795 0, view, SLOT( equalizeRow() ), ac, "equalizeRow" );
00796 actions->equalizeRow->setToolTip(i18n("Resizes selected rows to be the same size."));
00797
00798 actions->showSelRows = new KAction( i18n("Show Rows"), "show_table_row",
00799 0, view, SLOT( showSelRows() ), ac, "showSelRows" );
00800 actions->showSelRows->setEnabled(false);
00801 actions->showSelRows->setToolTip(i18n("Show hidden rows in the selection."));
00802
00803 actions->adjust = new KAction( i18n("Adjust Row && Column"),
00804 0, view, SLOT( adjust() ), ac, "adjust" );
00805 actions->adjust->setToolTip(i18n("Adjusts row/column size so that the contents will fit."));
00806
00807
00808 actions->sheetProperties = new KAction( i18n("Sheet Properties"),
00809 0, view, SLOT( sheetProperties() ), ac, "sheetProperties" );
00810 actions->sheetProperties->setToolTip(i18n("Modify current sheet's properties."));
00811
00812 actions->insertSheet = new KAction( i18n("Insert Sheet"),"inserttable",
00813 0, view, SLOT( insertSheet() ), ac, "insertSheet" );
00814 actions->insertSheet->setToolTip(i18n("Insert a new sheet."));
00815
00816
00817 actions->menuInsertSheet = new KAction( i18n("&Sheet"),"inserttable",
00818 0, view, SLOT( insertSheet() ), ac, "menuInsertSheet" );
00819 actions->menuInsertSheet->setToolTip(i18n("Insert a new sheet."));
00820
00821 actions->removeSheet = new KAction( i18n("Remove Sheet"), "delete_table",
00822 0, view, SLOT( removeSheet() ), ac, "removeSheet" );
00823 actions->removeSheet->setToolTip(i18n("Remove the active sheet."));
00824
00825 actions->renameSheet=new KAction( i18n("Rename Sheet..."),
00826 0, view, SLOT( slotRename() ), ac, "renameSheet" );
00827 actions->renameSheet->setToolTip(i18n("Rename the active sheet."));
00828
00829 actions->showSheet = new KAction(i18n("Show Sheet..."),
00830 0, view, SLOT( showSheet()), ac, "showSheet" );
00831 actions->showSheet->setToolTip(i18n("Show a hidden sheet."));
00832
00833 actions->hideSheet = new KAction(i18n("Hide Sheet"),
00834 0, view, SLOT( hideSheet() ), ac, "hideSheet" );
00835 actions->hideSheet->setToolTip(i18n("Hide the active sheet."));
00836
00837 actions->autoFormat = new KAction( i18n("AutoFormat..."),
00838 0, view, SLOT( sheetFormat() ), ac, "sheetFormat" );
00839 actions->autoFormat->setToolTip(i18n("Set the worksheet formatting."));
00840
00841 actions->areaName = new KAction( i18n("Area Name..."),
00842 0, view, SLOT( setAreaName() ), ac, "areaname" );
00843 actions->areaName->setToolTip(i18n("Set a name for a region of the spreadsheet."));
00844
00845 actions->showArea = new KAction( i18n("Show Area..."),
00846 0, view, SLOT( showAreaName() ), ac, "showArea" );
00847 actions->showArea->setToolTip(i18n("Display a named area."));
00848
00849 actions->insertFunction = new KAction( i18n("&Function..."), "funct",
00850 0, view, SLOT( insertMathExpr() ), ac, "insertMathExpr" );
00851 actions->insertFunction->setToolTip(i18n("Insert math expression."));
00852
00853 actions->insertSeries = new KAction( i18n("&Series..."),"series",
00854 0, view, SLOT( insertSeries() ), ac, "series");
00855 actions->insertSeries ->setToolTip(i18n("Insert a series."));
00856
00857 actions->insertLink = new KAction( i18n("&Link..."), "insert_link",
00858 0, view, SLOT( insertHyperlink() ), ac, "insertHyperlink" );
00859 actions->insertLink->setToolTip(i18n("Insert an Internet hyperlink."));
00860
00861 actions->removeLink = new KAction( i18n("&Remove Link"),
00862 0, view, SLOT( removeHyperlink() ), ac, "removeHyperlink" );
00863 actions->removeLink->setToolTip(i18n("Remove a link."));
00864
00865 actions->insertSpecialChar = new KAction( i18n( "S&pecial Character..." ), "char",
00866 view, SLOT( insertSpecialChar() ), ac, "insertSpecialChar" );
00867 actions->insertSpecialChar->setToolTip( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
00868
00869 actions->insertPart = new KoPartSelectAction( i18n("&Object"), "frame_query",
00870 view, SLOT( insertObject() ), ac, "insertPart");
00871 actions->insertPart->setToolTip(i18n("Insert an object from another program."));
00872
00873 actions->insertChartFrame = new KToggleAction( i18n("&Chart"), "insert_chart",
00874 0, view, SLOT( insertChart() ), ac, "insertChart" );
00875 actions->insertChartFrame->setToolTip(i18n("Insert a chart."));
00876
00877 actions->insertPicture = new KAction( i18n("&Picture"),
00878 0, view, SLOT( insertPicture() ), ac, "insertPicture" );
00879 actions->insertPicture->setToolTip(i18n("Insert a picture."));
00880
00881 #ifndef QT_NO_SQL
00882 actions->insertFromDatabase = new KAction( i18n("From &Database..."),
00883 0, view, SLOT( insertFromDatabase() ), ac, "insertFromDatabase");
00884 actions->insertFromDatabase->setToolTip(i18n("Insert data from a SQL database."));
00885 #endif
00886
00887 actions->insertFromTextfile = new KAction( i18n("From &Text File..."),
00888 0, view, SLOT( insertFromTextfile() ), ac, "insertFromTextfile");
00889 actions->insertFromTextfile->setToolTip(i18n("Insert data from a text file to the current cursor position/selection."));
00890
00891 actions->insertFromClipboard = new KAction( i18n("From &Clipboard..."),
00892 0, view, SLOT( insertFromClipboard() ), ac, "insertFromClipboard");
00893 actions->insertFromClipboard->setToolTip(i18n("Insert CSV data from the clipboard to the current cursor position/selection."));
00894
00895
00896
00897
00898
00899
00900 actions->sort = new KAction( i18n("&Sort..."),
00901 0, view, SLOT( sort() ), ac, "sort" );
00902 actions->sort->setToolTip(i18n("Sort a group of cells."));
00903
00904 actions->sortDec = new KAction( i18n("Sort &Decreasing"), "sort_decrease",
00905 0, view, SLOT( sortDec() ), ac, "sortDec" );
00906 actions->sortDec->setToolTip(i18n("Sort a group of cells in decreasing (last to first) order."));
00907
00908 actions->sortInc = new KAction( i18n("Sort &Increasing"), "sort_incr",
00909 0, view, SLOT( sortInc() ), ac, "sortInc" );
00910 actions->sortInc->setToolTip(i18n("Sort a group of cells in ascending (first to last) order."));
00911
00912 actions->paperLayout = new KAction( i18n("Page Layout..."),
00913 0, view, SLOT( paperLayoutDlg() ), ac, "paperLayout" );
00914 actions->paperLayout->setToolTip(i18n("Specify the layout of the spreadsheet for a printout."));
00915
00916 actions->definePrintRange = new KAction( i18n("Define Print Range"),
00917 0, view, SLOT( definePrintRange() ), ac, "definePrintRange" );
00918 actions->definePrintRange->setToolTip(i18n("Define the print range in the current sheet."));
00919
00920 actions->resetPrintRange = new KAction( i18n("Reset Print Range"),
00921 0, view, SLOT( resetPrintRange() ), ac, "resetPrintRange" );
00922 actions->definePrintRange->setToolTip(i18n("Define the print range in the current sheet."));
00923
00924 actions->showPageBorders = new KToggleAction( i18n("Show Page Borders"),
00925 0, ac, "showPageBorders");
00926 actions->showPageBorders->setCheckedState(i18n("Hide Page Borders"));
00927 QObject::connect( actions->showPageBorders, SIGNAL( toggled( bool ) ),
00928 view, SLOT( togglePageBorders( bool ) ) );
00929 actions->showPageBorders->setToolTip( i18n( "Show on the spreadsheet where the page borders will be." ) );
00930
00931 actions->recalcWorksheet = new KAction( i18n("Recalculate Sheet"),
00932 Qt::SHIFT + Qt::Key_F9, view, SLOT( recalcWorkSheet() ), ac, "RecalcWorkSheet" );
00933 actions->recalcWorksheet->setToolTip(i18n("Recalculate the value of every cell in the current worksheet."));
00934
00935 actions->recalcWorkbook = new KAction( i18n("Recalculate Document"),
00936 Qt::Key_F9, view, SLOT( recalcWorkBook() ), ac, "RecalcWorkBook" );
00937 actions->recalcWorkbook->setToolTip(i18n("Recalculate the value of every cell in all worksheets."));
00938
00939 actions->protectSheet = new KToggleAction( i18n( "Protect &Sheet..." ),
00940 0, ac, "protectSheet" );
00941 actions->protectSheet->setToolTip( i18n( "Protect the sheet from being modified." ) );
00942 QObject::connect( actions->protectSheet, SIGNAL( toggled( bool ) ),
00943 view, SLOT( toggleProtectSheet( bool ) ) );
00944
00945 actions->protectDoc = new KToggleAction( i18n( "Protect &Document..." ),
00946 0, ac, "protectDoc" );
00947 actions->protectDoc->setToolTip( i18n( "Protect the document from being modified." ) );
00948 QObject::connect( actions->protectDoc, SIGNAL( toggled( bool ) ),
00949 view, SLOT( toggleProtectDoc( bool ) ) );
00950
00951
00952
00953 actions->copy = KStdAction::copy( view, SLOT( copySelection() ), ac, "copy" );
00954 actions->copy->setToolTip(i18n("Copy the cell object to the clipboard."));
00955
00956 actions->paste = KStdAction::paste( view, SLOT( paste() ), ac, "paste" );
00957 actions->paste->setToolTip(i18n("Paste the contents of the clipboard at the cursor."));
00958
00959 actions->cut = KStdAction::cut( view, SLOT( cutSelection() ), ac, "cut" );
00960 actions->cut->setToolTip(i18n("Move the cell object to the clipboard."));
00961
00962 actions->specialPaste = new KAction( i18n("Special Paste..."), "special_paste",
00963 0, view, SLOT( specialPaste() ), ac, "specialPaste" );
00964 actions->specialPaste->setToolTip(i18n("Paste the contents of the clipboard with special options."));
00965
00966 actions->insertCellCopy = new KAction( i18n("Paste with Insertion"), "insertcellcopy",
00967 0, view, SLOT( slotInsertCellCopy() ), ac, "insertCellCopy" );
00968 actions->insertCellCopy->setToolTip(i18n("Inserts a cell from the clipboard into the spreadsheet."));
00969
00970 actions->find = KStdAction::find( view, SLOT(find()), ac );
00971 KStdAction::findNext( view, SLOT( findNext() ), ac );
00972 KStdAction::findPrev( view, SLOT( findPrevious() ), ac );
00973
00974 actions->replace = KStdAction::replace( view, SLOT(replace()), ac );
00975
00976 actions->fillRight = new KAction( i18n( "&Right" ), 0,
00977 0, view, SLOT( fillRight() ), ac, "fillRight" );
00978
00979 actions->fillLeft = new KAction( i18n( "&Left" ), 0,
00980 0, view, SLOT( fillLeft() ), ac, "fillLeft" );
00981
00982 actions->fillDown = new KAction( i18n( "&Down" ), 0,
00983 0, view, SLOT( fillDown() ), ac, "fillDown" );
00984
00985 actions->fillUp = new KAction( i18n( "&Up" ), 0,
00986 0, view, SLOT( fillUp() ), ac, "fillUp" );
00987
00988
00989
00990 actions->styleDialog = new KAction( i18n( "Style Manager" ),
00991 0, view, SLOT( styleDialog() ), ac, "styles" );
00992 actions->styleDialog->setToolTip( i18n( "Edit and organize cell styles." ) );
00993
00994 actions->autoSum = new KAction( i18n("Autosum"), "black_sum",
00995 0, view, SLOT( autoSum() ), ac, "autoSum" );
00996 actions->autoSum->setToolTip(i18n("Insert the 'sum' function"));
00997
00998 actions->spellChecking = KStdAction::spelling( view, SLOT( extraSpelling() ),
00999 ac, "spelling" );
01000 actions->spellChecking->setToolTip(i18n("Check the spelling."));
01001
01002 actions->formulaSelection = new KSelectAction(i18n("Formula Selection"),
01003 0, ac, "formulaSelection");
01004 actions->formulaSelection->setToolTip(i18n("Insert a function."));
01005 QStringList lst;
01006 lst.append( "SUM");
01007 lst.append( "AVERAGE");
01008 lst.append( "IF");
01009 lst.append( "COUNT");
01010 lst.append( "MIN");
01011 lst.append( "MAX");
01012 lst.append( i18n("Others...") );
01013 ((KSelectAction*) actions->formulaSelection)->setItems( lst );
01014 actions->formulaSelection->setComboWidth( 80 );
01015 actions->formulaSelection->setCurrentItem(0);
01016 QObject::connect( actions->formulaSelection, SIGNAL( activated( const QString& ) ),
01017 view, SLOT( formulaSelection( const QString& ) ) );
01018
01019 actions->viewZoom = new KoZoomAction( i18n( "Zoom" ), "viewmag", 0, ac, "view_zoom" );
01020 QObject::connect( actions->viewZoom, SIGNAL( zoomChanged( const QString & ) ),
01021 view, SLOT( viewZoom( const QString & ) ) );
01022
01023 actions->consolidate = new KAction( i18n("&Consolidate..."),
01024 0, view, SLOT( consolidate() ), ac, "consolidate" );
01025 actions->consolidate->setToolTip(i18n("Create a region of summary data from a group of similar regions."));
01026
01027 actions->goalSeek = new KAction( i18n("&Goal Seek..."),
01028 0, view, SLOT( goalSeek() ), ac, "goalSeek" );
01029 actions->goalSeek->setToolTip( i18n("Repeating calculation to find a specific value.") );
01030
01031 actions->subTotals = new KAction( i18n("&Subtotals..."),
01032 0, view, SLOT( subtotals() ), ac, "subtotals" );
01033 actions->subTotals->setToolTip( i18n("Create different kind of subtotals to a list or database.") );
01034
01035 actions->textToColumns = new KAction( i18n("&Text to Columns..."),
01036 0, view, SLOT( textToColumns() ), ac, "textToColumns" );
01037 actions->textToColumns->setToolTip( i18n("Expand the content of cells to multiple columns.") );
01038
01039 actions->multipleOperations = new KAction( i18n("&Multiple Operations..."),
01040 0, view, SLOT( multipleOperations() ), ac, "multipleOperations" );
01041 actions->multipleOperations->setToolTip( i18n("Apply the same formula to various cells using different values for the parameter.") );
01042
01043 actions->createTemplate = new KAction( i18n( "&Create Template From Document..." ),
01044 0, view, SLOT( createTemplate() ), ac, "createTemplate" );
01045
01046 actions->customList = new KAction( i18n("Custom Lists..."),
01047 0, view, SLOT( sortList() ), ac, "sortlist" );
01048 actions->customList->setToolTip(i18n("Create custom lists for sorting or autofill."));
01049
01050
01051
01052 actions->gotoCell = new KAction( i18n("Goto Cell..."),"goto",
01053 0, view, SLOT( gotoCell() ), ac, "gotoCell" );
01054 actions->gotoCell->setToolTip(i18n("Move to a particular cell."));
01055
01056 actions->nextSheet = new KAction( i18n("Next Sheet"), "forward",
01057 Qt::CTRL+Qt::Key_PageDown, view, SLOT( nextSheet() ), ac, "nextSheet");
01058 actions->nextSheet->setToolTip(i18n("Move to the next sheet."));
01059
01060 actions->prevSheet = new KAction( i18n("Previous Sheet"), "back",
01061 Qt::CTRL+Qt::Key_PageUp, view, SLOT( previousSheet() ), ac, "previousSheet");
01062 actions->prevSheet->setToolTip(i18n("Move to the previous sheet."));
01063
01064 actions->firstSheet = new KAction( i18n("First Sheet"), "start",
01065 0, view, SLOT( firstSheet() ), ac, "firstSheet");
01066 actions->firstSheet->setToolTip(i18n("Move to the first sheet."));
01067
01068 actions->lastSheet = new KAction( i18n("Last Sheet"), "finish",
01069 0, view, SLOT( lastSheet() ), ac, "lastSheet");
01070 actions->lastSheet->setToolTip(i18n("Move to the last sheet."));
01071
01072
01073
01074 actions->showStatusBar = new KToggleAction( i18n("Show Status Bar"),
01075 0, ac, "showStatusBar" );
01076 actions->showStatusBar->setCheckedState(i18n("Hide Status Bar"));
01077 QObject::connect( actions->showStatusBar, SIGNAL( toggled( bool ) ),
01078 view, SLOT( showStatusBar( bool ) ) );
01079 actions->showStatusBar->setToolTip(i18n("Show the status bar."));
01080
01081 actions->showTabBar = new KToggleAction( i18n("Show Tab Bar"),
01082 0, ac, "showTabBar" );
01083 actions->showTabBar->setCheckedState(i18n("Hide Tab Bar"));
01084 QObject::connect( actions->showTabBar, SIGNAL( toggled( bool ) ),
01085 view, SLOT( showTabBar( bool ) ) );
01086 actions->showTabBar->setToolTip(i18n("Show the tab bar."));
01087
01088 actions->showFormulaBar = new KToggleAction( i18n("Show Formula Bar"),
01089 0, ac, "showFormulaBar" );
01090 actions->showFormulaBar->setCheckedState(i18n("Hide Formula Bar"));
01091 QObject::connect( actions->showFormulaBar, SIGNAL( toggled( bool ) ),
01092 view, SLOT( showFormulaBar( bool ) ) );
01093 actions->showFormulaBar->setToolTip(i18n("Show the formula bar."));
01094
01095 actions->preference = new KAction( i18n("Configure KSpread..."),"configure",
01096 0, view, SLOT( preference() ), ac, "preference" );
01097 actions->preference->setToolTip(i18n("Set various KSpread options."));
01098
01099
01100
01101 actions->calcNone = new KToggleAction( i18n("None"), 0, ac, "menu_none");
01102 QObject::connect( actions->calcNone, SIGNAL( toggled( bool ) ),
01103 view, SLOT( menuCalc( bool ) ) );
01104 actions->calcNone->setExclusiveGroup( "Calc" );
01105 actions->calcNone->setToolTip(i18n("No calculation"));
01106
01107 actions->calcSum = new KToggleAction( i18n("Sum"), 0, ac, "menu_sum");
01108 QObject::connect( actions->calcSum, SIGNAL( toggled( bool ) ),
01109 view, SLOT( menuCalc( bool ) ) );
01110 actions->calcSum->setExclusiveGroup( "Calc" );
01111 actions->calcSum->setToolTip(i18n("Calculate using sum."));
01112
01113 actions->calcMin = new KToggleAction( i18n("Min"), 0, ac, "menu_min");
01114 QObject::connect( actions->calcMin, SIGNAL( toggled( bool ) ),
01115 view, SLOT( menuCalc( bool ) ) );
01116 actions->calcMin->setExclusiveGroup( "Calc" );
01117 actions->calcMin->setToolTip(i18n("Calculate using minimum."));
01118
01119 actions->calcMax = new KToggleAction( i18n("Max"), 0, ac, "menu_max");
01120 QObject::connect( actions->calcMax, SIGNAL( toggled( bool ) ),
01121 view, SLOT( menuCalc( bool ) ) );
01122 actions->calcMax->setExclusiveGroup( "Calc" );
01123 actions->calcMax->setToolTip(i18n("Calculate using maximum."));
01124
01125 actions->calcAverage = new KToggleAction( i18n("Average"), 0, ac, "menu_average");
01126 QObject::connect( actions->calcAverage, SIGNAL( toggled( bool ) ),
01127 view, SLOT( menuCalc( bool ) ) );
01128 actions->calcAverage->setExclusiveGroup( "Calc" );
01129 actions->calcAverage->setToolTip(i18n("Calculate using average."));
01130
01131 actions->calcCount = new KToggleAction( i18n("Count"), 0, ac, "menu_count");
01132 QObject::connect( actions->calcCount, SIGNAL( toggled( bool ) ),
01133 view, SLOT( menuCalc( bool ) ) );
01134 actions->calcCount->setExclusiveGroup( "Calc" );
01135 actions->calcCount->setToolTip(i18n("Calculate using the count."));
01136
01137 actions->calcCountA = new KToggleAction( i18n("CountA"), 0, ac, "menu_counta");
01138 QObject::connect( actions->calcCountA, SIGNAL( toggled( bool ) ),
01139 view, SLOT( menuCalc( bool ) ) );
01140 actions->calcCountA->setExclusiveGroup( "Calc" );
01141 actions->calcCountA->setToolTip(i18n("Calculate using the countA."));
01142
01143
01144
01145 actions->internalTests = new KAction( i18n("Run Internal Tests..."), "internalTests",
01146 Qt::CTRL+ Qt::SHIFT + Qt::Key_T, view, SLOT( runInternalTests() ), ac, "internalTests" );
01147 actions->inspector = new KAction( i18n("Run Inspector..."), "inspector",
01148 Qt::CTRL+ Qt::SHIFT + Qt::Key_I, view, SLOT( runInspector() ), ac, "inspector" );
01149
01150 m_propertyEditor = 0;
01151 }
01152
01153 void View::Private::adjustActions( bool mode )
01154 {
01155 actions->replace->setEnabled( mode );
01156 actions->insertSeries->setEnabled( mode );
01157 actions->insertLink->setEnabled( mode );
01158 actions->insertSpecialChar->setEnabled( mode );
01159 actions->insertFunction->setEnabled( mode );
01160 actions->removeComment->setEnabled( mode );
01161 actions->decreaseIndent->setEnabled( mode );
01162 actions->bold->setEnabled( mode );
01163 actions->italic->setEnabled( mode );
01164 actions->underline->setEnabled( mode );
01165 actions->strikeOut->setEnabled( mode );
01166 actions->percent->setEnabled( mode );
01167 actions->precplus->setEnabled( mode );
01168 actions->precminus->setEnabled( mode );
01169 actions->money->setEnabled( mode );
01170 actions->alignLeft->setEnabled( mode );
01171 actions->alignCenter->setEnabled( mode );
01172 actions->alignRight->setEnabled( mode );
01173 actions->alignTop->setEnabled( mode );
01174 actions->alignMiddle->setEnabled( mode );
01175 actions->alignBottom->setEnabled( mode );
01176 actions->paste->setEnabled( mode );
01177 actions->cut->setEnabled( mode );
01178 actions->specialPaste->setEnabled( mode );
01179 actions->deleteCell->setEnabled( mode );
01180 actions->clearText->setEnabled( mode );
01181 actions->clearComment->setEnabled( mode );
01182 actions->clearValidity->setEnabled( mode );
01183 actions->clearConditional->setEnabled( mode );
01184 actions->recalcWorkbook->setEnabled( mode );
01185 actions->recalcWorksheet->setEnabled( mode );
01186 actions->adjust->setEnabled( mode );
01187 actions->editCell->setEnabled( mode );
01188 actions->paperLayout->setEnabled( mode );
01189 actions->styleDialog->setEnabled( mode );
01190 actions->definePrintRange->setEnabled( mode );
01191 actions->resetPrintRange->setEnabled( mode );
01192 actions->insertFromDatabase->setEnabled( mode );
01193 actions->insertFromTextfile->setEnabled( mode );
01194 actions->insertFromClipboard->setEnabled( mode );
01195 actions->conditional->setEnabled( mode );
01196 actions->validity->setEnabled( mode );
01197 actions->goalSeek->setEnabled( mode );
01198 actions->subTotals->setEnabled( mode );
01199 actions->multipleOperations->setEnabled( mode );
01200 actions->textToColumns->setEnabled( mode );
01201 actions->consolidate->setEnabled( mode );
01202 actions->insertCellCopy->setEnabled( mode );
01203 actions->wrapText->setEnabled( mode );
01204 actions->selectFont->setEnabled( mode );
01205 actions->selectFontSize->setEnabled( mode );
01206 actions->deleteColumn->setEnabled( mode );
01207 actions->hideColumn->setEnabled( mode );
01208 actions->showColumn->setEnabled( mode );
01209 actions->showSelColumns->setEnabled( mode );
01210 actions->insertColumn->setEnabled( mode );
01211 actions->deleteRow->setEnabled( mode );
01212 actions->insertRow->setEnabled( mode );
01213 actions->hideRow->setEnabled( mode );
01214 actions->showRow->setEnabled( mode );
01215 actions->showSelRows->setEnabled( mode );
01216 actions->formulaSelection->setEnabled( mode );
01217 actions->textColor->setEnabled( mode );
01218 actions->bgColor->setEnabled( mode );
01219 actions->cellLayout->setEnabled( mode );
01220 actions->borderLeft->setEnabled( mode );
01221 actions->borderRight->setEnabled( mode );
01222 actions->borderTop->setEnabled( mode );
01223 actions->borderBottom->setEnabled( mode );
01224 actions->borderAll->setEnabled( mode );
01225 actions->borderOutline->setEnabled( mode );
01226 actions->borderRemove->setEnabled( mode );
01227 actions->borderColor->setEnabled( mode );
01228 actions->removeSheet->setEnabled( mode );
01229 actions->autoSum->setEnabled( mode );
01230 actions->defaultFormat->setEnabled( mode );
01231 actions->areaName->setEnabled( mode );
01232 actions->resizeRow->setEnabled( mode );
01233 actions->resizeColumn->setEnabled( mode );
01234 actions->fontSizeUp->setEnabled( mode );
01235 actions->fontSizeDown->setEnabled( mode );
01236 actions->upper->setEnabled( mode );
01237 actions->lower->setEnabled( mode );
01238 actions->equalizeRow->setEnabled( mode );
01239 actions->equalizeColumn->setEnabled( mode );
01240 actions->verticalText->setEnabled( mode );
01241 actions->addModifyComment->setEnabled( mode );
01242 actions->removeComment->setEnabled( mode );
01243 actions->insertCell->setEnabled( mode );
01244 actions->removeCell->setEnabled( mode );
01245 actions->changeAngle->setEnabled( mode );
01246 actions->dissociateCell->setEnabled( mode );
01247 actions->increaseIndent->setEnabled( mode );
01248 actions->decreaseIndent->setEnabled( mode );
01249 actions->spellChecking->setEnabled( mode );
01250 actions->calcMin->setEnabled( mode );
01251 actions->calcMax->setEnabled( mode );
01252 actions->calcAverage->setEnabled( mode );
01253 actions->calcCount->setEnabled( mode );
01254 actions->calcCountA->setEnabled( mode );
01255 actions->calcSum->setEnabled( mode );
01256 actions->calcNone->setEnabled( mode );
01257 actions->insertPart->setEnabled( mode );
01258 actions->createStyle->setEnabled( mode );
01259 actions->selectStyle->setEnabled( mode );
01260 actions->insertChartFrame->setEnabled( mode );
01261
01262 actions->autoFormat->setEnabled( false );
01263 actions->sort->setEnabled( false );
01264 actions->mergeCell->setEnabled( false );
01265 actions->mergeCellHorizontal->setEnabled( false );
01266 actions->mergeCellVertical->setEnabled( false );
01267 actions->sortDec->setEnabled( false );
01268 actions->sortInc->setEnabled( false );
01269
01270
01271 actions->fillRight->setEnabled( false );
01272 actions->fillLeft->setEnabled( false );
01273 actions->fillUp->setEnabled( false );
01274 actions->fillDown->setEnabled( false );
01275
01276 if ( mode && !view->doc()->map()->isProtected() )
01277 actions->renameSheet->setEnabled( true );
01278 else
01279 actions->renameSheet->setEnabled( false );
01280
01281 actions->showStatusBar->setChecked( view->doc()->showStatusBar() );
01282 actions->showTabBar->setChecked( view->doc()->showTabBar() );
01283 actions->showFormulaBar->setChecked( view->doc()->showFormulaBar() );
01284
01285 formulaButton->setEnabled( mode );
01286
01287 if ( activeSheet )
01288 {
01289 selection->update();
01290 view->objectSelectedChanged();
01291 }
01292 }
01293
01294 void View::Private::adjustActions( Sheet* sheet, Cell* cell )
01295 {
01296 if ( sheet->isProtected() && !cell->isDefault() && cell->format()->notProtected( cell->column(), cell->row() ) )
01297 {
01298 if ( selection->isSingular() )
01299 {
01300 if ( !actions->bold->isEnabled() )
01301 adjustActions( true );
01302 }
01303 else
01304 {
01305 if ( actions->bold->isEnabled() )
01306 adjustActions( false );
01307 }
01308 }
01309 else if ( sheet->isProtected() )
01310 {
01311 if ( actions->bold->isEnabled() )
01312 adjustActions( false );
01313 }
01314 }
01315
01316 void View::Private::adjustWorkbookActions( bool mode )
01317 {
01318 tabBar->setReadOnly( !view->doc()->isReadWrite() || view->doc()->map()->isProtected() );
01319
01320 actions->hideSheet->setEnabled( mode );
01321 actions->showSheet->setEnabled( mode );
01322 actions->insertSheet->setEnabled( mode );
01323 actions->menuInsertSheet->setEnabled( mode );
01324 actions->removeSheet->setEnabled( mode );
01325
01326 if ( mode )
01327 {
01328 if ( activeSheet && !activeSheet->isProtected() )
01329 {
01330 bool state = ( view->doc()->map()->visibleSheets().count() > 1 );
01331 actions->removeSheet->setEnabled( state );
01332 actions->hideSheet->setEnabled( state );
01333 }
01334 actions->showSheet->setEnabled( view->doc()->map()->hiddenSheets().count() > 0 );
01335 actions->renameSheet->setEnabled( activeSheet && !activeSheet->isProtected() );
01336 }
01337 }
01338
01339
01340 void View::Private::updateButton( Cell *cell, int column, int row)
01341 {
01342 toolbarLock = true;
01343
01344
01345
01346
01347 QStringList fontList;
01348 KFontChooser::getFontList( fontList, 0 );
01349 QString fontFamily = cell->format()->textFontFamily( column,row );
01350 for ( QStringList::Iterator it = fontList.begin(); it != fontList.end(); ++it )
01351 if ((*it).lower() == fontFamily.lower())
01352 {
01353 actions->selectFont->setFont( fontFamily );
01354 break;
01355 }
01356
01357 actions->selectFontSize->setFontSize( cell->format()->textFontSize( column, row ) );
01358 actions->bold->setChecked( cell->format()->textFontBold( column, row ) );
01359 actions->italic->setChecked( cell->format()->textFontItalic( column, row) );
01360 actions->underline->setChecked( cell->format()->textFontUnderline( column, row ) );
01361 actions->strikeOut->setChecked( cell->format()->textFontStrike( column, row ) );
01362
01363 actions->alignLeft->setChecked( cell->format()->align( column, row ) == Format::Left );
01364 actions->alignCenter->setChecked( cell->format()->align( column, row ) == Format::Center );
01365 actions->alignRight->setChecked( cell->format()->align( column, row ) == Format::Right );
01366
01367 actions->alignTop->setChecked( cell->format()->alignY( column, row ) == Format::Top );
01368 actions->alignMiddle->setChecked( cell->format()->alignY( column, row ) == Format::Middle );
01369 actions->alignBottom->setChecked( cell->format()->alignY( column, row ) == Format::Bottom );
01370
01371 actions->verticalText->setChecked( cell->format()->verticalText( column,row ) );
01372
01373 actions->wrapText->setChecked( cell->format()->multiRow( column,row ) );
01374
01375 FormatType ft = cell->formatType();
01376 actions->percent->setChecked( ft == Percentage_format );
01377 actions->money->setChecked( ft == Money_format );
01378
01379 if ( activeSheet && !activeSheet->isProtected() )
01380 actions->removeComment->setEnabled( !cell->format()->comment(column,row).isEmpty() );
01381
01382 if ( activeSheet && !activeSheet->isProtected() )
01383 actions->decreaseIndent->setEnabled( cell->format()->getIndent( column, row ) > 0.0 );
01384
01385 toolbarLock = false;
01386 if ( activeSheet )
01387 adjustActions( activeSheet, cell );
01388 }
01389
01390 QButton* View::Private::newIconButton( const char *_file, bool _kbutton, QWidget *_parent )
01391 {
01392 if ( _parent == 0L )
01393 _parent = view;
01394
01395 if ( !_kbutton ) {
01396 QPushButton* pb = new QPushButton( _parent );
01397 pb->setIconSet( SmallIconSet(_file) );
01398 return pb;
01399 } else {
01400 QToolButton* pb = new QToolButton( _parent );
01401 pb->setIconSet( SmallIconSet(_file) );
01402 return pb;
01403 }
01404 }
01405
01406 KPSheetSelectPage::KPSheetSelectPage( QWidget *parent )
01407 : KPrintDialogPage(parent),
01408 gui(new SheetSelectWidget(this))
01409 {
01410 setTitle(gui->caption());
01411
01412
01413 gui->ListViewAvailable->setSorting(-1);
01414 gui->ListViewSelected->setSorting(-1);
01415
01416
01417 connect(gui->ButtonSelectAll,SIGNAL(clicked()),this,SLOT(selectAll()));
01418 connect(gui->ButtonSelect,SIGNAL(clicked()),this,SLOT(select()));
01419 connect(gui->ButtonRemove,SIGNAL(clicked()),this,SLOT(remove()));
01420 connect(gui->ButtonRemoveAll,SIGNAL(clicked()),this,SLOT(removeAll()));
01421
01422 connect(gui->ButtonMoveTop,SIGNAL(clicked()),this,SLOT(moveTop()));
01423 connect(gui->ButtonMoveUp,SIGNAL(clicked()),this,SLOT(moveUp()));
01424 connect(gui->ButtonMoveDown,SIGNAL(clicked()),this,SLOT(moveDown()));
01425 connect(gui->ButtonMoveBottom,SIGNAL(clicked()),this,SLOT(moveBottom()));
01426 }
01427
01428
01429
01430
01431
01432 void KPSheetSelectPage::getOptions( QMap<QString,QString>& opts, bool )
01433 {
01434 QStringList sheetlist = this->selectedSheets();
01435 QStringList::iterator it;
01436 unsigned int i = 0;
01437 for (it = sheetlist.begin(); it != sheetlist.end(); ++it, i++)
01438 {
01439 opts.insert(printOptionForIndex(i),*it);
01440 }
01441 }
01442
01443 void KPSheetSelectPage::setOptions( const QMap<QString,QString>& opts )
01444 {
01445 unsigned int i = 0;
01446 QStringList sheetlist;
01447 while (opts.contains(printOptionForIndex(i)))
01448 {
01449 sheetlist.prepend(opts[printOptionForIndex(i++)]);
01450 }
01451
01452 QStringList::iterator it;
01453 for (it = sheetlist.begin(); it != sheetlist.end(); ++it)
01454 {
01455 kdDebug() << " adding sheet to list of printed sheets: " << *it << endl;
01456 this->prependSelectedSheet(*it);
01457 }
01458 }
01459
01460 bool KPSheetSelectPage::isValid(QString& )
01461 {
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471 return true;
01472 }
01473
01474 QString KPSheetSelectPage::printOptionForIndex(unsigned int index)
01475 {
01476 return QString("sheetprintorder%1").arg(index);
01477 }
01478
01479 void KPSheetSelectPage::prependAvailableSheet(const QString& sheetname)
01480 {
01481 Q_ASSERT(gui);
01482 new QListViewItem(gui->ListViewAvailable,sheetname);
01483 }
01484
01485 void KPSheetSelectPage::prependSelectedSheet(const QString& sheetname)
01486 {
01487 Q_ASSERT(gui);
01488 new QListViewItem(gui->ListViewSelected,sheetname);
01489 }
01490
01491 QStringList KPSheetSelectPage::selectedSheets()
01492 {
01493 Q_ASSERT(gui);
01494 QStringList list;
01495 QListViewItem* item = gui->ListViewSelected->firstChild();
01496 while (item)
01497 {
01498 list.append(item->text(0));
01499 item = item->nextSibling();
01500 }
01501 return list;
01502 }
01503
01504 QStringList KPSheetSelectPage::selectedSheets(KPrinter &prt)
01505 {
01506 QStringList list;
01507 unsigned int index;
01508 const QMap<QString,QString>& options = prt.options();
01509 for (index = 0; options.contains(KPSheetSelectPage::printOptionForIndex(index)); index++)
01510 {
01511 list.append(options[KPSheetSelectPage::printOptionForIndex(index)]);
01512 }
01513 return list;
01514 }
01515
01516 void KPSheetSelectPage::clearSelection()
01517 {
01518 gui->ListViewSelected->clear();
01519 }
01520
01521 void KPSheetSelectPage::selectAll()
01522 {
01523
01524
01525 QStringList list;
01526 QListViewItem* item = gui->ListViewAvailable->firstChild();
01527 while (item)
01528 {
01529 list.prepend(item->text(0));
01530 item = item->nextSibling();
01531 }
01532 QStringList::iterator it;
01533 for (it = list.begin(); it != list.end(); ++it)
01534 {
01535 this->prependSelectedSheet(*it);
01536 }
01537 }
01538
01539 void KPSheetSelectPage::select()
01540 {
01541
01542
01543 QStringList list;
01544 QListViewItem* item = gui->ListViewAvailable->firstChild();
01545 while (item)
01546 {
01547 if (item->isSelected())
01548 list.prepend(item->text(0));
01549 item = item->nextSibling();
01550 }
01551 QStringList::iterator it;
01552 for (it = list.begin(); it != list.end(); ++it)
01553 {
01554 this->prependSelectedSheet(*it);
01555 }
01556 }
01557
01558 void KPSheetSelectPage::remove()
01559 {
01560 QListViewItem* item = gui->ListViewSelected->firstChild();
01561 QListViewItem* nextitem = NULL;
01562 while (item)
01563 {
01564 nextitem = item->nextSibling();
01565 if (item->isSelected())
01566 delete item;
01567 item = nextitem;
01568 }
01569 }
01570
01571 void KPSheetSelectPage::removeAll()
01572 {
01573 gui->ListViewSelected->clear();
01574 }
01575
01576
01577 void KPSheetSelectPage::moveTop()
01578 {
01579
01580
01581
01582 QValueList<QListViewItem*> newlist;
01583 QListViewItem* item = gui->ListViewSelected->firstChild();
01584 QListViewItem* nextitem = NULL;
01585
01586 while (item)
01587 {
01588 nextitem = item->nextSibling();
01589 if (item->isSelected())
01590 {
01591 newlist.prepend(item);
01592 gui->ListViewSelected->takeItem(item);
01593 }
01594 item = nextitem;
01595 }
01596
01597 item = gui->ListViewSelected->firstChild();
01598 while (item)
01599 {
01600
01601 nextitem = item->nextSibling();
01602 if (!item->isSelected())
01603 {
01604 newlist.prepend(item);
01605 gui->ListViewSelected->takeItem(item);
01606 }
01607 item = nextitem;
01608 }
01609
01610
01611
01612 QValueList<QListViewItem*>::iterator it;
01613 for (it = newlist.begin(); it != newlist.end(); ++it)
01614 {
01615
01616 gui->ListViewSelected->insertItem(*it);
01617 }
01618 }
01619
01620 void KPSheetSelectPage::moveUp()
01621 {
01622
01623
01624
01625 QValueList<QListViewItem*> newlist;
01626 QListViewItem* item = gui->ListViewSelected->firstChild();
01627 QListViewItem* nextitem = NULL;
01628 while (item)
01629 {
01630 nextitem = item->nextSibling();
01631 if (!item->isSelected())
01632 {
01633 while (nextitem && nextitem->isSelected())
01634 {
01635 QListViewItem* nextnextitem = nextitem->nextSibling();
01636 newlist.prepend(nextitem);
01637 gui->ListViewSelected->takeItem(nextitem);
01638 nextitem = nextnextitem;
01639 }
01640 }
01641
01642 newlist.prepend(item);
01643 gui->ListViewSelected->takeItem(item);
01644 item = nextitem;
01645 }
01646
01647
01648
01649 QValueList<QListViewItem*>::iterator it;
01650 for (it = newlist.begin(); it != newlist.end(); ++it)
01651 {
01652
01653 gui->ListViewSelected->insertItem(*it);
01654 }
01655 }
01656
01657 void KPSheetSelectPage::moveDown()
01658 {
01659 QListViewItem* item = gui->ListViewSelected->lastItem();
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670 while (item)
01671 {
01672 while (item && !item->isSelected() && item->itemAbove() && item->itemAbove()->isSelected())
01673 {
01674 QListViewItem* tempitem = item->itemAbove();
01675 tempitem->moveItem(item);
01676 }
01677 if (item)
01678 item = item->itemAbove();
01679 }
01680 }
01681
01682 void KPSheetSelectPage::moveBottom()
01683 {
01684
01685
01686
01687 QValueList<QListViewItem*> newlist;
01688 QListViewItem* item = gui->ListViewSelected->firstChild();
01689 QListViewItem* nextitem = NULL;
01690
01691 while (item)
01692 {
01693
01694 nextitem = item->nextSibling();
01695 if (!item->isSelected())
01696 {
01697 newlist.prepend(item);
01698 gui->ListViewSelected->takeItem(item);
01699 }
01700 item = nextitem;
01701 }
01702
01703 item = gui->ListViewSelected->firstChild();
01704 while (item)
01705 {
01706 nextitem = item->nextSibling();
01707 if (item->isSelected())
01708 {
01709 newlist.prepend(item);
01710 gui->ListViewSelected->takeItem(item);
01711 }
01712 item = nextitem;
01713 }
01714
01715
01716
01717 QValueList<QListViewItem*>::iterator it;
01718 for (it = newlist.begin(); it != newlist.end(); ++it)
01719 {
01720
01721 gui->ListViewSelected->insertItem(*it);
01722 }
01723 }
01724
01725
01726
01727
01728
01729
01730
01731
01732 View::View( QWidget *_parent, const char *_name,
01733 Doc *_doc )
01734 : KoView( _doc, _parent, _name )
01735 {
01736 ElapsedTime et( "View constructor" );
01737 kdDebug(36001) << "sizeof(Cell)=" << sizeof(Cell) <<endl;
01738
01739 d = new Private;
01740 d->view = this;
01741 d->doc = _doc;
01742
01743 d->dcop = 0;
01744
01745 d->activeSheet = 0;
01746
01747 d->toolbarLock = false;
01748 d->loading = true;
01749
01750 d->selection = new Selection( this );
01751 d->choice = new Selection( this );
01752 d->choice->setMultipleSelection(true);
01753 connect(d->selection, SIGNAL(changed(const Region&)), this, SLOT(slotChangeSelection(const Region&)));
01754 connect(d->choice, SIGNAL(changed(const Region&)), this, SLOT(slotChangeChoice(const Region&)));
01755
01756 d->findOptions = 0;
01757 d->findLeftColumn = 0;
01758 d->findRightColumn = 0;
01759 d->typeValue = FindOption::Value;
01760 d->directionValue = FindOption::Row;
01761 d->find = 0;
01762 d->replace = 0;
01763
01764 d->popupMenuFirstToolId = 0;
01765 d->popupMenu = 0;
01766 d->popupColumn = 0;
01767 d->popupRow = 0;
01768 d->popupChild = 0;
01769 d->popupListChoose = 0;
01770 d->popupChildObject = 0;
01771
01772 d->searchInSheets.currentSheet = 0;
01773 d->searchInSheets.firstSheet = 0;
01774
01775
01776 d->spell.kspell = 0;
01777 d->spell.macroCmdSpellCheck = 0;
01778 d->spell.firstSpellSheet = 0;
01779 d->spell.currentSpellSheet = 0;
01780 d->spell.currentCell = 0;
01781 d->spell.spellStartCellX = 0;
01782 d->spell.spellStartCellY = 0;
01783 d->spell.spellEndCellX = 0;
01784 d->spell.spellEndCellY = 0;
01785 d->spell.spellCheckSelection = false;
01786
01787 d->insertHandler = 0L;
01788 d->specialCharDlg = 0;
01789
01790 setInstance( Factory::global() );
01791 if ( doc()->isReadWrite() )
01792 setXMLFile( "kspread.rc" );
01793 else
01794 setXMLFile( "kspread_readonly.rc" );
01795
01796
01797 dcopObject();
01798
01799 connect( doc()->commandHistory(), SIGNAL( commandExecuted() ),
01800 this, SLOT( commandExecuted() ) );
01801
01802
01803 initView();
01804
01805 d->initActions();
01806
01807
01808
01809 KoContainerHandler* h = new KoContainerHandler( this, d->canvas );
01810 connect( h, SIGNAL( popupMenu( KoChild*, const QPoint& ) ), this, SLOT( popupChildMenu( KoChild*, const QPoint& ) ) );
01811
01812
01813 connect( this, SIGNAL( childSelected( KoDocumentChild* ) ),
01814 this, SLOT( slotChildSelected( KoDocumentChild* ) ) );
01815 connect( this, SIGNAL( childUnselected( KoDocumentChild* ) ),
01816 this, SLOT( slotChildUnselected( KoDocumentChild* ) ) );
01817
01818
01819 connect( this, SIGNAL( childActivated( KoDocumentChild* ) ),
01820 this, SLOT( slotChildUnselected( KoDocumentChild* ) ) );
01821
01822 connect( d->canvas, SIGNAL( objectSelectedChanged() ),
01823 this, SLOT( objectSelectedChanged() ) );
01824
01825 QObject::connect( doc()->map(), SIGNAL( sig_addSheet( Sheet* ) ), SLOT( slotAddSheet( Sheet* ) ) );
01826
01827 QObject::connect( doc(), SIGNAL( sig_refreshView( ) ), this, SLOT( slotRefreshView() ) );
01828
01829 QObject::connect( doc(), SIGNAL( sig_refreshLocale() ), this, SLOT( refreshLocale()));
01830
01831 QObject::connect( doc(), SIGNAL( sig_addAreaName( const QString & ) ), d->posWidget, SLOT( slotAddAreaName( const QString & ) ) );
01832
01833 QObject::connect( doc(), SIGNAL( sig_removeAreaName( const QString & ) ), d->posWidget, SLOT( slotRemoveAreaName( const QString & ) ) );
01834
01835 QObject::connect( doc(), SIGNAL( damagesFlushed( const QValueList<Damage*>& ) ),
01836 this, SLOT( handleDamages( const QValueList<Damage*>& ) ) );
01837
01838
01839
01840
01841 if (!doc()->isReadWrite())
01842 {
01843 setZoom( 100, true );
01844 }
01845
01846 viewZoom( QString::number( doc()->zoom() ) );
01847
01848
01849 d->actions->selectStyle->setItems( d->doc->styleManager()->styleNames() );
01850
01851
01852
01853
01854
01855
01856 if ( !doc()->map()->sheetList().isEmpty() )
01857 QTimer::singleShot(50, this, SLOT(initialPosition()));
01858
01859 connect (&d->statusBarOpTimer, SIGNAL(timeout()), this, SLOT(calcStatusBarOp()));
01860 }
01861
01862 View::~View()
01863 {
01864
01865 if ( doc()->isReadWrite() )
01866 deleteEditor( true );
01867 if ( !d->transformToolBox.isNull() )
01868 delete (&*d->transformToolBox);
01869
01870
01871
01872
01873
01874
01875 delete d->spell.kspell;
01876
01877 d->canvas->endChoose();
01878 d->activeSheet = 0;
01879
01880
01881
01882
01883
01884 delete d->selection;
01885 delete d->choice;
01886
01887 delete d->popupColumn;
01888 delete d->popupRow;
01889 delete d->popupMenu;
01890 delete d->popupChild;
01891 delete d->popupListChoose;
01892 delete d->calcLabel;
01893 delete d->dcop;
01894
01895 delete d->insertHandler;
01896 d->insertHandler = 0L;
01897
01898 delete d->actions;
01899
01900
01901
01902 delete d->canvas;
01903 delete d;
01904 }
01905
01906 Doc* View::doc() const
01907 {
01908 return d->doc;
01909 }
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921 void View::initView()
01922 {
01923 d->viewLayout = new QGridLayout( this, 3, 4 );
01924
01925
01926 d->calcLabel = 0;
01927 d->vertScrollBar = new QScrollBar( this, "ScrollBar_2" );
01928 d->vertScrollBar->setRange( 0, 4096 );
01929 d->vertScrollBar->setOrientation( QScrollBar::Vertical );
01930 d->vertScrollBar->setLineStep(60);
01931 d->vertScrollBar->setPageStep(60);
01932
01933
01934 d->toolWidget = new QFrame( this );
01935
01936 d->formulaBarLayout = new QHBoxLayout( d->toolWidget );
01937 d->formulaBarLayout->setMargin( 4 );
01938 d->formulaBarLayout->addSpacing( 2 );
01939
01940 d->posWidget = new ComboboxLocationEditWidget( d->toolWidget, this );
01941 d->posWidget->setMinimumWidth( 100 );
01942 d->formulaBarLayout->addWidget( d->posWidget );
01943 d->formulaBarLayout->addSpacing( 6 );
01944
01945 d->formulaButton = d->newIconButton( "funct", true, d->toolWidget );
01946 d->formulaBarLayout->addWidget( d->formulaButton );
01947 d->formulaBarLayout->addSpacing( 2 );
01948 connect( d->formulaButton, SIGNAL( clicked() ), SLOT( insertMathExpr() ) );
01949
01950 d->cancelButton = d->newIconButton( "cancel", true, d->toolWidget );
01951 d->formulaBarLayout->addWidget( d->cancelButton );
01952 d->okButton = d->newIconButton( "ok", true, d->toolWidget );
01953 d->formulaBarLayout->addWidget( d->okButton );
01954 d->formulaBarLayout->addSpacing( 6 );
01955
01956
01957 d->canvas = new Canvas( this );
01958
01959
01960
01961 d->editWidget = new EditWidget( d->toolWidget, d->canvas, d->cancelButton, d->okButton );
01962 d->editWidget->setFocusPolicy( QWidget::StrongFocus );
01963 d->formulaBarLayout->addWidget( d->editWidget, 2 );
01964 d->formulaBarLayout->addSpacing( 2 );
01965
01966 d->canvas->setEditWidget( d->editWidget );
01967
01968 d->hBorderWidget = new HBorder( this, d->canvas,this );
01969 d->vBorderWidget = new VBorder( this, d->canvas ,this );
01970
01971 d->canvas->setFocusPolicy( QWidget::StrongFocus );
01972 QWidget::setFocusPolicy( QWidget::StrongFocus );
01973 setFocusProxy( d->canvas );
01974
01975 connect( this, SIGNAL( invalidated() ), d->canvas, SLOT( update() ) );
01976
01977 QWidget* bottomPart = new QWidget( this );
01978 d->tabScrollBarLayout = new QHBoxLayout( bottomPart );
01979 d->tabScrollBarLayout->setAutoAdd( true );
01980 d->tabBar = new KoTabBar( bottomPart );
01981 d->horzScrollBar = new QScrollBar( bottomPart, "ScrollBar_1" );
01982
01983 d->horzScrollBar->setRange( 0, 4096 );
01984 d->horzScrollBar->setOrientation( QScrollBar::Horizontal );
01985
01986 d->horzScrollBar->setLineStep(60);
01987 d->horzScrollBar->setPageStep(60);
01988
01989 QObject::connect( d->tabBar, SIGNAL( tabChanged( const QString& ) ), this, SLOT( changeSheet( const QString& ) ) );
01990 QObject::connect( d->tabBar, SIGNAL( tabMoved( unsigned, unsigned ) ),
01991 this, SLOT( moveSheet( unsigned, unsigned ) ) );
01992 QObject::connect( d->tabBar, SIGNAL( contextMenu( const QPoint& ) ),
01993 this, SLOT( popupTabBarMenu( const QPoint& ) ) );
01994 QObject::connect( d->tabBar, SIGNAL( doubleClicked() ),
01995 this, SLOT( slotRename() ) );
01996
01997 d->viewLayout->setColStretch( 1, 10 );
01998 d->viewLayout->setRowStretch( 2, 10 );
01999 d->viewLayout->addMultiCellWidget( d->toolWidget, 0, 0, 0, 2 );
02000 d->viewLayout->addMultiCellWidget( d->hBorderWidget, 1, 1, 1, 2 );
02001 d->viewLayout->addWidget( d->vBorderWidget, 2, 0 );
02002 d->viewLayout->addWidget( d->canvas, 2, 1 );
02003 d->viewLayout->addWidget( d->vertScrollBar, 2, 2 );
02004 d->viewLayout->addMultiCellWidget( bottomPart, 3, 3, 0, 2 );
02005
02006 KStatusBar * sb = statusBar();
02007 Q_ASSERT(sb);
02008 d->calcLabel = sb ? new KStatusBarLabel( QString::null, 0, sb ) : 0;
02009 addStatusBarItem( d->calcLabel, 0 );
02010 if (d->calcLabel)
02011 connect(d->calcLabel ,SIGNAL(itemPressed( int )),this,SLOT(statusBarClicked(int)));
02012
02013
02014 QObject::connect( d->vertScrollBar, SIGNAL( valueChanged(int) ), d->canvas, SLOT( slotScrollVert(int) ) );
02015 QObject::connect( d->horzScrollBar, SIGNAL( valueChanged(int) ), d->canvas, SLOT( slotScrollHorz(int) ) );
02016
02017 }
02018
02019 Canvas* View::canvasWidget() const
02020 {
02021 return d->canvas;
02022 }
02023
02024 HBorder* View::hBorderWidget()const
02025 {
02026 return d->hBorderWidget;
02027 }
02028
02029 VBorder* View::vBorderWidget()const
02030 {
02031 return d->vBorderWidget;
02032 }
02033
02034 QScrollBar* View::horzScrollBar()const
02035 {
02036 return d->horzScrollBar;
02037 }
02038
02039 QScrollBar* View::vertScrollBar()const
02040 {
02041 return d->vertScrollBar;
02042 }
02043
02044 EditWidget* View::editWidget()const
02045 {
02046 return d->editWidget;
02047 }
02048
02049 ComboboxLocationEditWidget* View::posWidget()const
02050 {
02051 return d->posWidget;
02052 }
02053
02054 KoTabBar* View::tabBar() const
02055 {
02056 return d->tabBar;
02057 }
02058
02059 bool View::isLoading() const
02060 {
02061 return d->loading;
02062 }
02063
02064 Selection* View::selectionInfo() const
02065 {
02066 return d->selection;
02067 }
02068
02069 Selection* View::choice() const
02070 {
02071 return d->choice;
02072 }
02073
02074 void View::resetInsertHandle()
02075 {
02076 d->actions->insertChartFrame->setChecked( false );
02077
02078
02079 d->insertHandler = 0;
02080 }
02081
02082 bool View::isInsertingObject()
02083 {
02084 return d->insertHandler;
02085 }
02086
02087 const Sheet* View::activeSheet() const
02088 {
02089 return d->activeSheet;
02090 }
02091
02092 Sheet* View::activeSheet()
02093 {
02094 return d->activeSheet;
02095 }
02096
02097 void View::initConfig()
02098 {
02099 KConfig *config = Factory::global()->config();
02100 if ( config->hasGroup("Parameters" ))
02101 {
02102 config->setGroup( "Parameters" );
02103 if ( !doc()->configLoadFromFile() )
02104 doc()->setShowHorizontalScrollBar(config->readBoolEntry("Horiz ScrollBar",true));
02105 if ( !doc()->configLoadFromFile() )
02106 doc()->setShowVerticalScrollBar(config->readBoolEntry("Vert ScrollBar",true));
02107 doc()->setShowColHeader(config->readBoolEntry("Column Header",true));
02108 doc()->setShowRowHeader(config->readBoolEntry("Row Header",true));
02109 if ( !doc()->configLoadFromFile() )
02110 doc()->setCompletionMode((KGlobalSettings::Completion)config->readNumEntry("Completion Mode",(int)(KGlobalSettings::CompletionAuto)));
02111 doc()->setMoveToValue((KSpread::MoveTo)config->readNumEntry("Move",(int)(Bottom)));
02112 doc()->setIndentValue( config->readDoubleNumEntry( "Indent", 10.0 ) );
02113 doc()->setTypeOfCalc((MethodOfCalc)config->readNumEntry("Method of Calc",(int)(SumOfNumber)));
02114 if ( !doc()->configLoadFromFile() )
02115 doc()->setShowTabBar(config->readBoolEntry("Tabbar",true));
02116
02117 doc()->setShowMessageError(config->readBoolEntry( "Msg error" ,false) );
02118
02119 doc()->setShowFormulaBar(config->readBoolEntry("Formula bar",true));
02120 doc()->setShowStatusBar(config->readBoolEntry("Status bar",true));
02121
02122 changeNbOfRecentFiles(config->readNumEntry("NbRecentFile",10));
02123
02124
02125 doc()->setAutoSave(config->readNumEntry("AutoSave",KoDocument::defaultAutoSave()/60)*60);
02126 doc()->setBackupFile( config->readBoolEntry("BackupFile",true));
02127 }
02128
02129 if ( config->hasGroup("KSpread Color" ) )
02130 {
02131 config->setGroup( "KSpread Color" );
02132 QColor _col(Qt::lightGray);
02133 _col = config->readColorEntry("GridColor", &_col);
02134 doc()->setGridColor(_col);
02135
02136 QColor _pbCol(Qt::red);
02137 _pbCol = config->readColorEntry("PageBorderColor", &_pbCol);
02138 doc()->changePageBorderColor(_pbCol);
02139 }
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156 initCalcMenu();
02157 calcStatusBarOp();
02158 }
02159
02160 void View::changeNbOfRecentFiles(int _nb)
02161 {
02162 if (shell())
02163 shell()->setMaxRecentItems( _nb );
02164 }
02165
02166 void View::initCalcMenu()
02167 {
02168 switch( doc()->getTypeOfCalc())
02169 {
02170 case SumOfNumber:
02171 d->actions->calcSum->setChecked(true);
02172 break;
02173 case Min:
02174 d->actions->calcMin->setChecked(true);
02175 break;
02176 case Max:
02177 d->actions->calcMax->setChecked(true);
02178 break;
02179 case Average:
02180 d->actions->calcAverage->setChecked(true);
02181 break;
02182 case Count:
02183 d->actions->calcCount->setChecked(true);
02184 break;
02185 case CountA:
02186 d->actions->calcCountA->setChecked(true);
02187 break;
02188 case NoneCalc:
02189 d->actions->calcNone->setChecked(true);
02190 break;
02191 default :
02192 d->actions->calcSum->setChecked(true);
02193 break;
02194 }
02195
02196 }
02197
02198
02199 void View::recalcWorkBook()
02200 {
02201 if (!activeSheet())
02202 return;
02203
02204 Sheet * tbl;
02205 doc()->emitBeginOperation( true );
02206 for ( tbl = doc()->map()->firstSheet();
02207 tbl != 0L;
02208 tbl = doc()->map()->nextSheet() )
02209 {
02210
02211
02212 tbl->recalc( true);
02213
02214 }
02215
02216 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
02217 }
02218
02219 void View::refreshLocale()
02220 {
02221 doc()->emitBeginOperation(true);
02222 Sheet *tbl;
02223 for ( tbl = doc()->map()->firstSheet();
02224 tbl != 0L;
02225 tbl = doc()->map()->nextSheet() )
02226 {
02227 tbl->updateLocale();
02228 }
02229 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
02230 }
02231
02232 void View::recalcWorkSheet()
02233 {
02234 if ( d->activeSheet != 0 )
02235 {
02236 doc()->emitBeginOperation( true );
02237
02238
02239 d->activeSheet->recalc( true);
02240
02241 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
02242 }
02243 }
02244
02245
02246 void View::extraSpelling()
02247 {
02248 if ( d->spell.kspell )
02249 return;
02250
02251 if (d->activeSheet == 0L)
02252 return;
02253
02254 d->spell.macroCmdSpellCheck = 0L;
02255 d->spell.firstSpellSheet = d->activeSheet;
02256 d->spell.currentSpellSheet = d->spell.firstSpellSheet;
02257
02258 QRect selection = d->selection->selection();
02259
02260
02261 if (d->selection->isSingular())
02262 {
02263 d->spell.spellStartCellX = 0;
02264 d->spell.spellStartCellY = 0;
02265 d->spell.spellEndCellX = 0;
02266 d->spell.spellEndCellY = 0;
02267 d->spell.spellCheckSelection = false;
02268 d->spell.currentCell = d->activeSheet->firstCell();
02269 }
02270 else
02271 {
02272 d->spell.spellStartCellX = selection.left();
02273 d->spell.spellStartCellY = selection.top();
02274 d->spell.spellEndCellX = selection.right();
02275 d->spell.spellEndCellY = selection.bottom();
02276 d->spell.spellCheckSelection = true;
02277 d->spell.currentCell = 0L;
02278
02279
02280 d->spell.spellCurrCellX = d->spell.spellStartCellX - 1;
02281 d->spell.spellCurrCellY = d->spell.spellStartCellY;
02282 }
02283
02284 startKSpell();
02285 }
02286
02287
02288 void View::startKSpell()
02289 {
02290 if ( doc()->getKSpellConfig() )
02291 {
02292 doc()->getKSpellConfig()->setIgnoreList( doc()->spellListIgnoreAll() );
02293 doc()->getKSpellConfig()->setReplaceAllList( d->spell.replaceAll );
02294
02295 }
02296 d->spell.kspell = new KSpell( this, i18n( "Spell Checking" ), this,
02297 SLOT( spellCheckerReady() ),
02298 doc()->getKSpellConfig() );
02299
02300 d->spell.kspell->setIgnoreUpperWords( doc()->dontCheckUpperWord() );
02301 d->spell.kspell->setIgnoreTitleCase( doc()->dontCheckTitleCase() );
02302
02303 QObject::connect( d->spell.kspell, SIGNAL( death() ),
02304 this, SLOT( spellCheckerFinished() ) );
02305 QObject::connect( d->spell.kspell, SIGNAL( misspelling( const QString &,
02306 const QStringList &,
02307 unsigned int) ),
02308 this, SLOT( spellCheckerMisspelling( const QString &,
02309 const QStringList &,
02310 unsigned int) ) );
02311 QObject::connect( d->spell.kspell, SIGNAL( corrected( const QString &,
02312 const QString &,
02313 unsigned int) ),
02314 this, SLOT( spellCheckerCorrected( const QString &,
02315 const QString &,
02316 unsigned int ) ) );
02317 QObject::connect( d->spell.kspell, SIGNAL( done( const QString & ) ),
02318 this, SLOT( spellCheckerDone( const QString & ) ) );
02319 QObject::connect( d->spell.kspell, SIGNAL( ignoreall (const QString & ) ),
02320 this, SLOT( spellCheckerIgnoreAll( const QString & ) ) );
02321
02322 QObject::connect( d->spell.kspell, SIGNAL( replaceall( const QString & , const QString & )), this, SLOT( spellCheckerReplaceAll( const QString & , const QString & )));
02323
02324 }
02325
02326 void View::spellCheckerReplaceAll( const QString &orig, const QString & replacement)
02327 {
02328 d->spell.replaceAll.append( orig);
02329 d->spell.replaceAll.append( replacement);
02330 }
02331
02332
02333 void View::spellCheckerIgnoreAll( const QString & word)
02334 {
02335 doc()->addIgnoreWordAll( word );
02336 }
02337
02338
02339 void View::spellCheckerReady()
02340 {
02341 if (d->canvas)
02342 d->canvas->setCursor( WaitCursor );
02343
02344
02345 if (!d->spell.spellCheckSelection)
02346 {
02347
02348
02349 while ( d->spell.currentCell )
02350 {
02351
02352 if ( d->spell.currentCell->value().isString() )
02353 {
02354 d->spell.kspell->check( d->spell.currentCell->text(), true );
02355
02356 return;
02357 }
02358
02359 d->spell.currentCell = d->spell.currentCell->nextCell();
02360 if ( d->spell.currentCell && d->spell.currentCell->isDefault() )
02361 kdDebug() << "checking default cell!!" << endl << endl;
02362 }
02363
02364 if (spellSwitchToOtherSheet())
02365 spellCheckerReady();
02366 else
02367 spellCleanup();
02368
02369 return;
02370 }
02371
02372
02373
02374 ++d->spell.spellCurrCellX;
02375 if (d->spell.spellCurrCellX > d->spell.spellEndCellX)
02376 {
02377 d->spell.spellCurrCellX = d->spell.spellStartCellX;
02378 ++d->spell.spellCurrCellY;
02379 }
02380
02381 unsigned int y;
02382 unsigned int x;
02383
02384 for ( y = d->spell.spellCurrCellY; y <= d->spell.spellEndCellY; ++y )
02385 {
02386 for ( x = d->spell.spellCurrCellX; x <= d->spell.spellEndCellX; ++x )
02387 {
02388 Cell * cell = d->spell.currentSpellSheet->cellAt( x, y );
02389
02390
02391 if (cell->isDefault() || !cell->value().isString())
02392 continue;
02393
02394 d->spell.spellCurrCellX = x;
02395 d->spell.spellCurrCellY = y;
02396
02397 d->spell.kspell->check( cell->text(), true );
02398
02399 return;
02400 }
02401 d->spell.spellCurrCellX = d->spell.spellStartCellX;
02402 }
02403
02404
02405
02406 if (d->spell.spellCheckSelection)
02407 {
02408
02409 spellCleanup();
02410 }
02411 else
02412 {
02413 if (spellSwitchToOtherSheet())
02414 spellCheckerReady();
02415 else
02416 spellCleanup();
02417 }
02418 }
02419
02420
02421 void View::spellCleanup()
02422 {
02423 if ( d->canvas )
02424 d->canvas->setCursor( ArrowCursor );
02425
02426 d->spell.kspell->cleanUp();
02427 delete d->spell.kspell;
02428 d->spell.kspell = 0L;
02429 d->spell.firstSpellSheet = 0L;
02430 d->spell.currentSpellSheet = 0L;
02431 d->spell.currentCell = 0L;
02432 d->spell.replaceAll.clear();
02433
02434
02435 KMessageBox::information( this, i18n( "Spell checking is complete." ) );
02436
02437 if ( d->spell.macroCmdSpellCheck )
02438 doc()->addCommand( d->spell.macroCmdSpellCheck );
02439 d->spell.macroCmdSpellCheck=0L;
02440 }
02441
02442
02443 bool View::spellSwitchToOtherSheet()
02444 {
02445
02446 if ( doc()->map()->count() == 1 )
02447 return false;
02448
02449
02450 QPtrList<Sheet> sheetList = doc()->map()->sheetList();
02451
02452 unsigned int curIndex = sheetList.findRef(d->spell.currentSpellSheet);
02453 ++curIndex;
02454
02455
02456 if ( curIndex >= sheetList.count() )
02457 d->spell.currentSpellSheet = sheetList.first();
02458 else
02459 d->spell.currentSpellSheet = sheetList.at(curIndex);
02460
02461
02462 if ( d->spell.currentSpellSheet == d->spell.firstSpellSheet )
02463 {
02464 setActiveSheet( d->spell.firstSpellSheet );
02465 return false;
02466 }
02467
02468 if (d->spell.spellCheckSelection)
02469 {
02470 d->spell.spellEndCellX = d->spell.currentSpellSheet->maxColumn();
02471 d->spell.spellEndCellY = d->spell.currentSpellSheet->maxRow();
02472
02473 d->spell.spellCurrCellX = d->spell.spellStartCellX - 1;
02474 d->spell.spellCurrCellY = d->spell.spellStartCellY;
02475 }
02476 else
02477 {
02478 d->spell.currentCell = d->spell.currentSpellSheet->firstCell();
02479 }
02480
02481 if ( KMessageBox::questionYesNo( this,
02482 i18n( "Do you want to check the spelling in the next sheet?") )
02483 != KMessageBox::Yes )
02484 return false;
02485
02486 setActiveSheet( d->spell.currentSpellSheet );
02487
02488 return true;
02489 }
02490
02491
02492 void View::spellCheckerMisspelling( const QString &,
02493 const QStringList &,
02494 unsigned int )
02495 {
02496
02497 if ( !d->spell.spellCheckSelection )
02498 {
02499 d->spell.spellCurrCellX = d->spell.currentCell->column();
02500 d->spell.spellCurrCellY = d->spell.currentCell->row();
02501 }
02502
02503 d->selection->initialize(QPoint(d->spell.spellCurrCellX, d->spell.spellCurrCellY));
02504 }
02505
02506
02507 void View::spellCheckerCorrected( const QString & old, const QString & corr,
02508 unsigned int pos )
02509 {
02510 Cell * cell;
02511
02512 if (d->spell.spellCheckSelection)
02513 {
02514 cell = d->spell.currentSpellSheet->cellAt( d->spell.spellCurrCellX,
02515 d->spell.spellCurrCellY );
02516 }
02517 else
02518 {
02519 cell = d->spell.currentCell;
02520 d->spell.spellCurrCellX = cell->column();
02521 d->spell.spellCurrCellY = cell->row();
02522 }
02523
02524 Q_ASSERT( cell );
02525 if ( !cell )
02526 return;
02527
02528 doc()->emitBeginOperation(false);
02529 QString content( cell->text() );
02530
02531 UndoSetText* undo = new UndoSetText( doc(), d->activeSheet,
02532 content,
02533 d->spell.spellCurrCellX,
02534 d->spell.spellCurrCellY,
02535 cell->formatType());
02536 content.replace( pos, old.length(), corr );
02537 cell->setCellText( content );
02538 d->editWidget->setText( content );
02539
02540 if ( !d->spell.macroCmdSpellCheck )
02541 d->spell.macroCmdSpellCheck = new MacroUndoAction( doc(), i18n("Correct Misspelled Word") );
02542 d->spell.macroCmdSpellCheck->addCommand( undo );
02543 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
02544 }
02545
02546 void View::spellCheckerDone( const QString & )
02547 {
02548 int result = d->spell.kspell->dlgResult();
02549
02550 d->spell.kspell->cleanUp();
02551 delete d->spell.kspell;
02552 d->spell.kspell = 0L;
02553
02554 if ( result != KS_CANCEL && result != KS_STOP )
02555 {
02556 if (d->spell.spellCheckSelection)
02557 {
02558 if ( (d->spell.spellCurrCellY <= d->spell.spellEndCellY)
02559 && (d->spell.spellCurrCellX <= d->spell.spellEndCellX) )
02560 {
02561 startKSpell();
02562 return;
02563 }
02564 }
02565 else
02566 {
02567 if ( d->spell.currentCell )
02568 {
02569 d->spell.currentCell = d->spell.currentCell->nextCell();
02570
02571 startKSpell();
02572
02573 return;
02574 }
02575 }
02576 }
02577 d->spell.replaceAll.clear();
02578
02579 if ( d->spell.macroCmdSpellCheck )
02580 {
02581 doc()->addCommand( d->spell.macroCmdSpellCheck );
02582 }
02583 d->spell.macroCmdSpellCheck=0L;
02584 }
02585
02586 void View::spellCheckerFinished()
02587 {
02588 if (d->canvas)
02589 d->canvas->setCursor( ArrowCursor );
02590
02591 KSpell::spellStatus status = d->spell.kspell->status();
02592 d->spell.kspell->cleanUp();
02593 delete d->spell.kspell;
02594 d->spell.kspell = 0L;
02595 d->spell.replaceAll.clear();
02596
02597 bool kspellNotConfigured=false;
02598
02599 if (status == KSpell::Error)
02600 {
02601 KMessageBox::sorry(this, i18n("ISpell could not be started.\n"
02602 "Please make sure you have ISpell properly configured and in your PATH."));
02603 kspellNotConfigured=true;
02604 }
02605 else if (status == KSpell::Crashed)
02606 {
02607 KMessageBox::sorry(this, i18n("ISpell seems to have crashed."));
02608 }
02609
02610 if (d->spell.macroCmdSpellCheck)
02611 {
02612 doc()->addCommand( d->spell.macroCmdSpellCheck );
02613 }
02614 d->spell.macroCmdSpellCheck=0L;
02615
02616
02617 if (kspellNotConfigured)
02618 {
02619 PreferenceDialog configDlg( this, 0 );
02620 configDlg.openPage( PreferenceDialog::KS_SPELLING);
02621 configDlg.exec();
02622 }
02623 }
02624
02625 void View::initialPosition()
02626 {
02627
02628 QPtrListIterator<Sheet> it( doc()->map()->sheetList() );
02629 for( ; it.current(); ++it )
02630 addSheet( it.current() );
02631
02632 Sheet * tbl = 0L;
02633 if ( doc()->isEmbedded() )
02634 {
02635 tbl = doc()->displaySheet();
02636 }
02637
02638 if ( !tbl )
02639 tbl = doc()->map()->initialActiveSheet();
02640 if ( tbl )
02641 setActiveSheet( tbl );
02642 else
02643 {
02644
02645 tbl = doc()->map()->findSheet( doc()->map()->visibleSheets().first());
02646 if ( !tbl )
02647 {
02648 tbl = doc()->map()->firstSheet();
02649 if ( tbl )
02650 {
02651 tbl->setHidden( false );
02652 QString tabName = tbl->sheetName();
02653 d->tabBar->addTab( tabName );
02654 }
02655 }
02656 setActiveSheet( tbl );
02657 }
02658
02659 refreshView();
02660
02661 int col = 1;
02662 int row = 1;
02663 double offsetX = 0;
02664 double offsetY = 0;
02665
02666 if (KSPLoadingInfo* loadingInfo = doc()->loadingInfo())
02667 {
02668 kdDebug() << "View::initialPosition(): setting initial position" << endl;
02669 d->savedAnchors = loadingInfo->cursorPositions();
02670 d->savedMarkers = loadingInfo->cursorPositions();
02671 d->savedOffsets = loadingInfo->scrollingOffsets();
02672
02673 QMapIterator<Sheet*, QPoint> it = d->savedMarkers.find(d->activeSheet);
02674 QPoint cursor = (it == d->savedMarkers.end()) ? QPoint(1,1) : *it;
02675 col = cursor.x();
02676 row = cursor.y();
02677
02678 QMapIterator<Sheet*, KoPoint> it2 = d->savedOffsets.find(d->activeSheet);
02679 KoPoint offset = (it2 == d->savedOffsets.end()) ? KoPoint() : *it2;
02680 offsetX = offset.x();
02681 offsetY = offset.y();
02682 }
02683 else
02684 {
02685 offsetX = doc()->map()->initialXOffset();
02686 offsetY = doc()->map()->initialYOffset();
02687
02688
02689 col = doc()->map()->initialMarkerColumn();
02690 if ( col <= 0 )
02691 col = 1;
02692 row = doc()->map()->initialMarkerRow();
02693 if ( row <= 0 )
02694 row = 1;
02695 }
02696 d->canvas->setXOffset( offsetX );
02697 d->canvas->setYOffset( offsetY );
02698 d->selection->initialize( QPoint(col, row) );
02699
02700 updateBorderButton();
02701 updateShowSheetMenu();
02702
02703 d->actions->autoFormat->setEnabled(false);
02704 d->actions->sort->setEnabled(false);
02705 d->actions->mergeCell->setEnabled(false);
02706 d->actions->mergeCellHorizontal->setEnabled(false);
02707 d->actions->mergeCellVertical->setEnabled(false);
02708 d->actions->createStyle->setEnabled(false);
02709
02710 d->actions->fillUp->setEnabled( false );
02711 d->actions->fillRight->setEnabled( false );
02712 d->actions->fillDown->setEnabled( false );
02713 d->actions->fillLeft->setEnabled( false );
02714
02715
02716 doc()->decreaseNumOperation();
02717
02718 QRect vr( activeSheet()->visibleRect( d->canvas ) );
02719
02720 doc()->emitBeginOperation( false );
02721 activeSheet()->setRegionPaintDirty( vr );
02722 doc()->emitEndOperation( vr );
02723
02724 if ( koDocument()->isReadWrite() )
02725 initConfig();
02726
02727 d->adjustActions( !d->activeSheet->isProtected() );
02728 d->adjustWorkbookActions( !doc()->map()->isProtected() );
02729
02730
02731 d->loading = false;
02732 doc()->deleteLoadingInfo();
02733 }
02734
02735
02736 void View::updateEditWidgetOnPress()
02737 {
02738 if (!d->activeSheet)
02739 return;
02740
02741 int column = d->canvas->markerColumn();
02742 int row = d->canvas->markerRow();
02743
02744 Cell* cell = d->activeSheet->cellAt( column, row );
02745 if ( !cell )
02746 {
02747 d->editWidget->setText( "" );
02748 return;
02749 }
02750 if ( d->activeSheet->isProtected() && cell->format()->isHideFormula( column, row ) )
02751 d->editWidget->setText( cell->strOutText() );
02752 else if ( d->activeSheet->isProtected() && cell->format()->isHideAll( column, row ) )
02753 d->editWidget->setText( "" );
02754 else
02755 d->editWidget->setText( cell->text() );
02756
02757 d->updateButton(cell, column, row);
02758 d->adjustActions( d->activeSheet, cell );
02759 }
02760
02761 void View::updateEditWidget()
02762 {
02763 if (!d->activeSheet)
02764 return;
02765
02766 int column = d->canvas->markerColumn();
02767 int row = d->canvas->markerRow();
02768
02769 Cell * cell = d->activeSheet->cellAt( column, row );
02770 bool active = activeSheet()->getShowFormula()
02771 && !( d->activeSheet->isProtected() && cell && cell->format()->isHideFormula( column, row ) );
02772
02773 if ( d->activeSheet && !d->activeSheet->isProtected() )
02774 {
02775 d->actions->alignLeft->setEnabled(!active);
02776 d->actions->alignCenter->setEnabled(!active);
02777 d->actions->alignRight->setEnabled(!active);
02778 }
02779
02780 if ( !cell )
02781 {
02782 d->editWidget->setText( "" );
02783 if ( d->activeSheet->isProtected() )
02784 d->editWidget->setEnabled( false );
02785 else
02786 d->editWidget->setEnabled( true );
02787 return;
02788 }
02789
02790 if ( d->activeSheet->isProtected() && cell->format()->isHideFormula( column, row ) )
02791 d->editWidget->setText( cell->strOutText() );
02792 else if ( d->activeSheet->isProtected() && cell->format()->isHideAll( column, row ) )
02793 d->editWidget->setText( "" );
02794 else
02795 d->editWidget->setText( cell->text() );
02796
02797 if ( d->activeSheet->isProtected() && !cell->format()->notProtected( column, row ) )
02798 d->editWidget->setEnabled( false );
02799 else
02800 d->editWidget->setEnabled( true );
02801
02802 if ( d->canvas->editor() )
02803 {
02804 d->canvas->editor()->setEditorFont(cell->format()->textFont(column, row), true);
02805 d->canvas->editor()->setFocus();
02806 }
02807 d->updateButton(cell, column, row);
02808 d->adjustActions( d->activeSheet, cell );
02809 }
02810
02811 void View::activateFormulaEditor()
02812 {
02813 }
02814
02815 void View::objectSelectedChanged()
02816 {
02817 if ( d->canvas->isObjectSelected() )
02818 d->actions->actionExtraProperties->setEnabled( true );
02819 else
02820 d->actions->actionExtraProperties->setEnabled( false );
02821 }
02822
02823 void View::updateReadWrite( bool readwrite )
02824 {
02825
02826
02827 d->editWidget->setEnabled( readwrite );
02828
02829 QValueList<KAction*> actions = actionCollection()->actions();
02830 QValueList<KAction*>::ConstIterator aIt = actions.begin();
02831 QValueList<KAction*>::ConstIterator aEnd = actions.end();
02832 for (; aIt != aEnd; ++aIt )
02833 (*aIt)->setEnabled( readwrite );
02834
02835
02836 if ( !doc() || !doc()->map() || doc()->map()->isProtected() )
02837 {
02838 d->actions->showSheet->setEnabled( false );
02839 d->actions->hideSheet->setEnabled( false );
02840 }
02841 else
02842 {
02843 d->actions->showSheet->setEnabled( true );
02844 d->actions->hideSheet->setEnabled( true );
02845 }
02846 d->actions->gotoCell->setEnabled( true );
02847 d->actions->viewZoom->setEnabled( true );
02848 d->actions->showPageBorders->setEnabled( true );
02849 d->actions->find->setEnabled( true);
02850 d->actions->replace->setEnabled( readwrite );
02851 if ( !doc()->isReadWrite())
02852 d->actions->copy->setEnabled( true );
02853
02854
02855 }
02856
02857 void View::createTemplate()
02858 {
02859 int width = 60;
02860 int height = 60;
02861 QPixmap pix = doc()->generatePreview(QSize(width, height));
02862
02863 KTempFile tempFile( QString::null, ".kst" );
02864
02865 if (tempFile.status() != 0)
02866 {
02867 qWarning("Creation of temprary file to store template failed.");
02868 return;
02869 }
02870
02871 tempFile.setAutoDelete(true);
02872
02873 doc()->saveNativeFormat( tempFile.name() );
02874
02875 KoTemplateCreateDia::createTemplate( "kspread_template", Factory::global(),
02876 tempFile.name(), pix, this );
02877
02878 Factory::global()->dirs()->addResourceType("kspread_template",
02879 KStandardDirs::kde_default( "data" ) +
02880 "kspread/templates/");
02881 }
02882
02883 void View::sheetFormat()
02884 {
02885 FormatDialog dlg( this );
02886 dlg.exec();
02887 }
02888
02889 void View::autoSum()
02890 {
02891 if (!activeSheet())
02892 return;
02893
02894
02895
02896 if ( d->canvas->editor() )
02897 return;
02898
02899
02900
02901
02902 Range rg;
02903
02904 QRect sel = d->selection->selection(false);
02905
02906 if (sel.height() > 1)
02907 {
02908 if (d->selection->marker().y()==sel.top())
02909 sel.setTop(sel.top()+1);
02910 if (d->selection->marker().y()==sel.bottom())
02911 sel.setBottom(sel.bottom()-1);
02912 }
02913 else
02914 {
02915 if (sel.width() > 1)
02916 {
02917 if (d->selection->marker().x()==sel.left())
02918 sel.setLeft(sel.left()+1);
02919
02920 if (d->selection->marker().x()==sel.right())
02921 sel.setRight(sel.right()-1);
02922 }
02923 else
02924 {
02925 sel=QRect();
02926
02927
02928
02929
02930 int start = -1, end = -1;
02931
02932 if ( (d->selection->marker().y() > 1) && activeSheet()->cellAt(d->selection->marker().x(), d->selection->marker().y()-1)->value().isNumber() )
02933 {
02934
02935 start = end = d->selection->marker().y()-1;
02936 for (start--; (start > 0) && activeSheet()->cellAt(d->selection->marker().x(), start)->value().isNumber(); start--) ;
02937
02938 Point startPoint, endPoint;
02939 startPoint.setRow(start+1);
02940 startPoint.setColumn(d->selection->marker().x());
02941 endPoint.setRow(end);
02942 endPoint.setColumn(d->selection->marker().x());
02943
02944 QString str = Range(startPoint, endPoint).toString();
02945
02946 d->canvas->createEditor( Canvas::CellEditor , true , true );
02947 d->canvas->editor()->setText("=SUM(" + str + ")");
02948 d->canvas->editor()->setCursorPosition(5 + str.length());
02949 return;
02950 }
02951 else if ( (d->selection->marker().x() > 1) && activeSheet()->cellAt(d->selection->marker().x()-1, d->selection->marker().y())->value().isNumber() )
02952 {
02953
02954 start = end = d->selection->marker().x()-1;
02955 for (start--; (start > 0) && activeSheet()->cellAt(start, d->selection->marker().y())->value().isNumber(); start--) ;
02956
02957 Point startPoint, endPoint;
02958 startPoint.setColumn(start+1);
02959 startPoint.setRow(d->selection->marker().y());
02960 endPoint.setColumn(end);
02961 endPoint.setRow(d->selection->marker().y());
02962
02963 QString str = Range(startPoint, endPoint).toString();
02964
02965 d->canvas->createEditor( Canvas::CellEditor , true , true );
02966 d->canvas->editor()->setText("=SUM(" + str + ")");
02967 d->canvas->editor()->setCursorPosition(5 + str.length());
02968 return;
02969 }
02970 }
02971 }
02972
02973 if ( (sel.width() > 1) && (sel.height() > 1) )
02974 sel=QRect();
02975
02976 rg.setRange(sel);
02977
02978 d->canvas->createEditor( Canvas::CellEditor , true , true );
02979
02980
02981 if ( (rg.range().isValid() ) && (!rg.range().isEmpty()) )
02982 {
02983 d->canvas->editor()->setText( "=SUM("+rg.toString()+")" );
02984 d->canvas->deleteEditor(true);
02985 }
02986 else
02987 {
02988 d->canvas->startChoose();
02989 d->canvas->editor()->setText( "=SUM()" );
02990 d->canvas->editor()->setCursorPosition( 5 );
02991 }
02992 }
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002 void View::changeTextColor()
03003 {
03004 if ( d->activeSheet != 0L )
03005 {
03006 doc()->emitBeginOperation(false);
03007 d->activeSheet->setSelectionTextColor( selectionInfo(), d->actions->textColor->color() );
03008 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03009 }
03010 }
03011
03012 void View::setSelectionTextColor(const QColor &txtColor)
03013 {
03014 if (d->activeSheet != 0L)
03015 {
03016 doc()->emitBeginOperation(false);
03017 d->activeSheet->setSelectionTextColor( selectionInfo(), txtColor );
03018
03019 markSelectionAsDirty();
03020 doc()->emitEndOperation();
03021 }
03022 }
03023
03024 void View::changeBackgroundColor()
03025 {
03026 if ( d->activeSheet != 0L )
03027 {
03028 doc()->emitBeginOperation(false);
03029 d->activeSheet->setSelectionbgColor( selectionInfo(), d->actions->bgColor->color() );
03030 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03031 }
03032 }
03033
03034 void View::setSelectionBackgroundColor(const QColor &bgColor)
03035 {
03036 if (d->activeSheet != 0L)
03037 {
03038 doc()->emitBeginOperation(false);
03039 d->activeSheet->setSelectionbgColor( selectionInfo(), bgColor );
03040 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03041 }
03042 }
03043
03044 void View::changeBorderColor()
03045 {
03046 if ( d->activeSheet != 0L )
03047 {
03048 doc()->emitBeginOperation(false);
03049 d->activeSheet->setSelectionBorderColor( selectionInfo(), d->actions->borderColor->color() );
03050 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03051 }
03052 }
03053
03054 void View::setSelectionBorderColor(const QColor &bdColor)
03055 {
03056 if (d->activeSheet != 0L)
03057 {
03058 doc()->emitBeginOperation(false);
03059 d->activeSheet->setSelectionBorderColor( selectionInfo(), bdColor );
03060 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03061 }
03062 }
03063
03064 void View::helpUsing()
03065 {
03066 kapp->invokeHelp( );
03067 }
03068
03069 void View::enableUndo( bool _b )
03070 {
03071 KAction* action = actionCollection()->action( "office_undo" );
03072 if( action ) action->setEnabled( _b );
03073 }
03074
03075 void View::enableRedo( bool _b )
03076 {
03077 KAction* action = actionCollection()->action( "office_redo" );
03078 if( action ) action->setEnabled( _b );
03079 }
03080
03081 void View::enableInsertColumn( bool _b )
03082 {
03083 if ( d->activeSheet && !d->activeSheet->isProtected() )
03084 d->actions->insertColumn->setEnabled( _b );
03085 }
03086
03087 void View::enableInsertRow( bool _b )
03088 {
03089 if ( d->activeSheet && !d->activeSheet->isProtected() )
03090 d->actions->insertRow->setEnabled( _b );
03091 }
03092
03093 void View::deleteColumn()
03094 {
03095 if ( !d->activeSheet )
03096 return;
03097
03098 doc()->emitBeginOperation( false );
03099
03100 QRect r( d->selection->selection() );
03101
03102 d->activeSheet->removeColumn( r.left(), ( r.right()-r.left() ) );
03103
03104 updateEditWidget();
03105
03106 d->selection->update();
03107
03108 QRect vr( d->activeSheet->visibleRect( d->canvas ) );
03109 vr.setLeft( r.left() );
03110
03111 doc()->emitEndOperation( vr );
03112 }
03113
03114 void View::deleteRow()
03115 {
03116 if ( !d->activeSheet )
03117 return;
03118
03119 doc()->emitBeginOperation( false );
03120 QRect r( d->selection->selection() );
03121 d->activeSheet->removeRow( r.top(),(r.bottom()-r.top()) );
03122
03123 updateEditWidget();
03124
03125 d->selection->update();
03126
03127 QRect vr( d->activeSheet->visibleRect( d->canvas ) );
03128 vr.setTop( r.top() );
03129
03130 doc()->emitEndOperation( vr );
03131 }
03132
03133 void View::insertColumn()
03134 {
03135 if ( !d->activeSheet )
03136 return;
03137
03138 doc()->emitBeginOperation( false );
03139 QRect r( d->selection->selection() );
03140 d->activeSheet->insertColumn( r.left(), ( r.right()-r.left() ) );
03141
03142 updateEditWidget();
03143
03144 QRect vr( d->activeSheet->visibleRect( d->canvas ) );
03145 vr.setLeft( r.left() - 1 );
03146
03147 doc()->emitEndOperation( vr );
03148 }
03149
03150 void View::hideColumn()
03151 {
03152 if ( !d->activeSheet )
03153 return;
03154
03155 if ( d->selection->isRowSelected() )
03156 {
03157 KMessageBox::error( this, i18n( "Area is too large." ) );
03158 return;
03159 }
03160
03161 d->activeSheet->hideColumn(*selectionInfo());
03162 }
03163
03164 void View::showColumn()
03165 {
03166 if ( !d->activeSheet )
03167 return;
03168
03169 ShowColRow dlg( this, "showCol", ShowColRow::Column );
03170 dlg.exec();
03171 }
03172
03173 void View::showSelColumns()
03174 {
03175 if ( !d->activeSheet )
03176 return;
03177
03178 d->activeSheet->showColumn(*selectionInfo());
03179 }
03180
03181 void View::insertRow()
03182 {
03183 if ( !d->activeSheet )
03184 return;
03185 doc()->emitBeginOperation( false );
03186 QRect r( d->selection->selection() );
03187 d->activeSheet->insertRow( r.top(), ( r.bottom() - r.top() ) );
03188
03189 updateEditWidget();
03190 QRect vr( d->activeSheet->visibleRect( d->canvas ) );
03191 vr.setTop( r.top() - 1 );
03192
03193 doc()->emitEndOperation( vr );
03194 }
03195
03196 void View::hideRow()
03197 {
03198 if ( !d->activeSheet )
03199 return;
03200
03201 if ( d->selection->isColumnSelected() )
03202 {
03203 KMessageBox::error( this, i18n( "Area is too large." ) );
03204 return;
03205 }
03206
03207 d->activeSheet->hideRow(*selectionInfo());
03208 }
03209
03210 void View::showRow()
03211 {
03212 if ( !d->activeSheet )
03213 return;
03214
03215 ShowColRow dlg( this, "showRow", ShowColRow::Row );
03216 dlg.exec();
03217 }
03218
03219 void View::showSelRows()
03220 {
03221 if ( !d->activeSheet )
03222 return;
03223
03224 d->activeSheet->showRow(*selectionInfo());
03225 }
03226
03227 void View::fontSelected( const QString & _font )
03228 {
03229 if ( d->toolbarLock )
03230 return;
03231
03232 doc()->emitBeginOperation(false);
03233 if ( d->activeSheet != 0L )
03234 d->activeSheet->setSelectionFont( d->selection, _font.latin1() );
03235
03236
03237 if ( d->canvas->editor() )
03238 {
03239 Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
03240 d->canvas->editor()->setEditorFont( cell->format()->textFont( cell->column(), cell->row() ), true );
03241 d->canvas->editor()->setFocus();
03242 }
03243 else
03244 d->canvas->setFocus();
03245
03246 markSelectionAsDirty();
03247 doc()->emitEndOperation();
03248 }
03249
03250 void View::decreaseFontSize()
03251 {
03252 setSelectionFontSize( -1 );
03253 }
03254
03255 void View::increaseFontSize()
03256 {
03257 setSelectionFontSize( 1 );
03258 }
03259
03260 void View::setSelectionFontSize( int size )
03261 {
03262 if ( d->activeSheet != NULL )
03263 {
03264 d->activeSheet->setSelectionSize( selectionInfo(), size );
03265 }
03266 }
03267
03268 void View::lower()
03269 {
03270 if ( !d->activeSheet )
03271 return;
03272
03273 doc()->emitBeginOperation( false );
03274
03275 d->activeSheet->setSelectionUpperLower( selectionInfo(), -1 );
03276 updateEditWidget();
03277
03278 markSelectionAsDirty();
03279 doc()->emitEndOperation();
03280 }
03281
03282 void View::upper()
03283 {
03284 if ( !d->activeSheet )
03285 return;
03286
03287 doc()->emitBeginOperation( false );
03288
03289 d->activeSheet->setSelectionUpperLower( selectionInfo(), 1 );
03290 updateEditWidget();
03291
03292 markSelectionAsDirty();
03293 doc()->emitEndOperation();
03294 }
03295
03296 void View::firstLetterUpper()
03297 {
03298 if ( !d->activeSheet )
03299 return;
03300 doc()->emitBeginOperation( false );
03301 d->activeSheet->setSelectionfirstLetterUpper( selectionInfo() );
03302 updateEditWidget();
03303
03304 markSelectionAsDirty();
03305 doc()->emitEndOperation();
03306 }
03307
03308 void View::verticalText(bool b)
03309 {
03310 if ( !d->activeSheet )
03311 return;
03312
03313 doc()->emitBeginOperation( false );
03314 d->activeSheet->setSelectionVerticalText( selectionInfo(), b );
03315 d->activeSheet->adjustArea(*selectionInfo());
03316 updateEditWidget();
03317
03318 markSelectionAsDirty();
03319 doc()->emitEndOperation();
03320 }
03321
03322 void View::insertSpecialChar()
03323 {
03324 QString f( d->actions->selectFont->font() );
03325 QChar c = ' ';
03326
03327 if ( d->specialCharDlg == 0 )
03328 {
03329 d->specialCharDlg = new KoCharSelectDia( this, "insert special char", f, c, false );
03330 connect( d->specialCharDlg, SIGNAL( insertChar( QChar, const QString & ) ),
03331 this, SLOT( slotSpecialChar( QChar, const QString & ) ) );
03332 connect( d->specialCharDlg, SIGNAL( finished() ),
03333 this, SLOT( slotSpecialCharDlgClosed() ) );
03334 }
03335 d->specialCharDlg->show();
03336 }
03337
03338 void View::slotSpecialCharDlgClosed()
03339 {
03340 if ( d->specialCharDlg )
03341 {
03342 disconnect( d->specialCharDlg, SIGNAL(insertChar(QChar,const QString &)),
03343 this, SLOT(slotSpecialChar(QChar,const QString &)));
03344 disconnect( d->specialCharDlg, SIGNAL( finished() ),
03345 this, SLOT( slotSpecialCharDlgClosed() ) );
03346 d->specialCharDlg->deleteLater();
03347 d->specialCharDlg = 0L;
03348 }
03349 }
03350
03351 void View::slotSpecialChar( QChar c, const QString & _font )
03352 {
03353 if ( d->activeSheet )
03354 {
03355 QPoint marker( d->selection->marker() );
03356 Cell * cell = d->activeSheet->nonDefaultCell( marker );
03357 if ( cell->format()->textFont( marker.x(), marker.y() ).family() != _font )
03358 {
03359 cell->format()->setTextFontFamily( _font );
03360 }
03361 EditWidget * edit = d->editWidget;
03362 QKeyEvent ev( QEvent::KeyPress, 0, 0, 0, QString( c ) );
03363 QApplication::sendEvent( edit, &ev );
03364 }
03365 }
03366
03367 void View::insertMathExpr()
03368 {
03369 if ( d->activeSheet == 0L )
03370 return;
03371
03372 FormulaDialog * dlg = new FormulaDialog( this, "Function" );
03373 dlg->show();
03374
03375
03376
03377
03378 }
03379
03380 void View::formulaSelection( const QString &_math )
03381 {
03382 if ( d->activeSheet == 0 )
03383 return;
03384
03385 if ( _math == i18n("Others...") )
03386 {
03387 insertMathExpr();
03388 return;
03389 }
03390
03391 FormulaDialog *dlg = new FormulaDialog( this, "Formula Editor", _math );
03392 dlg->exec();
03393 }
03394
03395 void View::fontSizeSelected( int _size )
03396 {
03397 if ( d->toolbarLock )
03398 return;
03399
03400 doc()->emitBeginOperation( false );
03401
03402 if ( d->activeSheet != 0L )
03403 d->activeSheet->setSelectionFont( selectionInfo(), 0L, _size );
03404
03405
03406 if ( d->canvas->editor() )
03407 {
03408 Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
03409 d->canvas->editor()->setEditorFont( cell->format()->textFont( d->canvas->markerColumn(),
03410 d->canvas->markerRow() ), true );
03411 d->canvas->editor()->setFocus();
03412 }
03413 else
03414 d->canvas->setFocus();
03415
03416 markSelectionAsDirty();
03417 doc()->emitEndOperation();
03418 }
03419
03420 void View::bold( bool b )
03421 {
03422 if ( d->toolbarLock )
03423 return;
03424 if ( d->activeSheet == 0 )
03425 return;
03426
03427 doc()->emitBeginOperation( false );
03428
03429 int col = d->canvas->markerColumn();
03430 int row = d->canvas->markerRow();
03431 d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, b );
03432
03433 if ( d->canvas->editor() )
03434 {
03435 Cell * cell = d->activeSheet->cellAt( col, row );
03436 d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
03437 }
03438
03439 markSelectionAsDirty();
03440 doc()->emitEndOperation();
03441 }
03442
03443 void View::underline( bool b )
03444 {
03445 if ( d->toolbarLock )
03446 return;
03447 if ( d->activeSheet == 0 )
03448 return;
03449
03450 doc()->emitBeginOperation( false );
03451
03452 int col = d->canvas->markerColumn();
03453 int row = d->canvas->markerRow();
03454
03455 d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, -1 ,b );
03456 if ( d->canvas->editor() )
03457 {
03458 Cell * cell = d->activeSheet->cellAt( col, row );
03459 d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
03460 }
03461
03462 markSelectionAsDirty();
03463 doc()->emitEndOperation();
03464 }
03465
03466 void View::strikeOut( bool b )
03467 {
03468 if ( d->toolbarLock )
03469 return;
03470 if ( d->activeSheet == 0 )
03471 return;
03472
03473 doc()->emitBeginOperation( false );
03474
03475 int col = d->canvas->markerColumn();
03476 int row = d->canvas->markerRow();
03477
03478 d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, -1 ,-1, b );
03479 if ( d->canvas->editor() )
03480 {
03481 Cell * cell = d->activeSheet->cellAt( col, row );
03482 d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
03483 }
03484
03485 markSelectionAsDirty();
03486 doc()->emitEndOperation();
03487 }
03488
03489
03490 void View::italic( bool b )
03491 {
03492 if ( d->toolbarLock )
03493 return;
03494 if ( d->activeSheet == 0 )
03495 return;
03496
03497 doc()->emitBeginOperation( false );
03498
03499 int col = d->canvas->markerColumn();
03500 int row = d->canvas->markerRow();
03501
03502 d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, b );
03503 if ( d->canvas->editor() )
03504 {
03505 Cell * cell = d->activeSheet->cellAt( col, row );
03506 d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
03507 }
03508
03509 markSelectionAsDirty();
03510 doc()->emitEndOperation();
03511 }
03512
03513 void View::sortInc()
03514 {
03515 if (!activeSheet())
03516 return;
03517
03518 QRect range = d->selection->selection();
03519 if ( d->selection->isSingular() )
03520 {
03521 KMessageBox::error( this, i18n( "You must select multiple cells." ) );
03522 return;
03523 }
03524
03525 doc()->emitBeginOperation( false );
03526
03527
03528 if ( d->selection->isRowSelected() || range.top() == range.bottom() )
03529 activeSheet()->sortByRow( range, range.top(), Sheet::Increase );
03530 else
03531 activeSheet()->sortByColumn( range, range.left(), Sheet::Increase );
03532 updateEditWidget();
03533
03534 markSelectionAsDirty();
03535 doc()->emitEndOperation();
03536 }
03537
03538 void View::sortDec()
03539 {
03540 QRect range = d->selection->selection();
03541 if ( d->selection->isSingular() )
03542 {
03543 KMessageBox::error( this, i18n( "You must select multiple cells." ) );
03544 return;
03545 }
03546
03547 doc()->emitBeginOperation( false );
03548
03549
03550 if ( d->selection->isRowSelected() || range.top() == range.bottom() )
03551 activeSheet()->sortByRow( range, range.top(), Sheet::Decrease );
03552 else
03553 activeSheet()->sortByColumn( range, range.left(), Sheet::Decrease );
03554 updateEditWidget();
03555
03556 markSelectionAsDirty();
03557 doc()->emitEndOperation();
03558 }
03559
03560
03561 void View::borderBottom()
03562 {
03563 if ( d->activeSheet != 0L )
03564 {
03565 doc()->emitBeginOperation( false );
03566
03567 d->activeSheet->borderBottom( d->selection, d->actions->borderColor->color() );
03568
03569 markSelectionAsDirty();
03570 doc()->emitEndOperation();
03571 }
03572 }
03573
03574 void View::setSelectionBottomBorderColor( const QColor & color )
03575 {
03576 if ( d->activeSheet != 0L )
03577 {
03578 doc()->emitBeginOperation( false );
03579 d->activeSheet->borderBottom( selectionInfo(), color );
03580
03581 markSelectionAsDirty();
03582 doc()->emitEndOperation();
03583 }
03584 }
03585
03586 void View::borderRight()
03587 {
03588 if ( d->activeSheet != 0L )
03589 {
03590 doc()->emitBeginOperation( false );
03591 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
03592 d->activeSheet->borderLeft( d->selection, d->actions->borderColor->color() );
03593 else
03594 d->activeSheet->borderRight( d->selection, d->actions->borderColor->color() );
03595
03596 markSelectionAsDirty();
03597 doc()->emitEndOperation();
03598 }
03599 }
03600
03601 void View::setSelectionRightBorderColor( const QColor & color )
03602 {
03603 if ( d->activeSheet != 0L )
03604 {
03605 doc()->emitBeginOperation( false );
03606 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
03607 d->activeSheet->borderLeft( selectionInfo(), color );
03608 else
03609 d->activeSheet->borderRight( selectionInfo(), color );
03610
03611 markSelectionAsDirty();
03612 doc()->emitEndOperation();
03613 }
03614 }
03615
03616 void View::borderLeft()
03617 {
03618 if ( d->activeSheet != 0L )
03619 {
03620 doc()->emitBeginOperation( false );
03621 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
03622 d->activeSheet->borderRight( d->selection, d->actions->borderColor->color() );
03623 else
03624 d->activeSheet->borderLeft( d->selection, d->actions->borderColor->color() );
03625
03626 markSelectionAsDirty();
03627 doc()->emitEndOperation();
03628 }
03629 }
03630
03631 void View::setSelectionLeftBorderColor( const QColor & color )
03632 {
03633 if ( d->activeSheet != 0L )
03634 {
03635 doc()->emitBeginOperation( false );
03636 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
03637 d->activeSheet->borderRight( selectionInfo(), color );
03638 else
03639 d->activeSheet->borderLeft( selectionInfo(), color );
03640
03641 markSelectionAsDirty();
03642 doc()->emitEndOperation();
03643 }
03644 }
03645
03646 void View::borderTop()
03647 {
03648 if ( d->activeSheet != 0L )
03649 {
03650 doc()->emitBeginOperation( false );
03651 d->activeSheet->borderTop( d->selection, d->actions->borderColor->color() );
03652
03653 markSelectionAsDirty();
03654 doc()->emitEndOperation();
03655 }
03656 }
03657
03658 void View::setSelectionTopBorderColor( const QColor & color )
03659 {
03660 if ( d->activeSheet != 0L )
03661 {
03662 doc()->emitBeginOperation( false );
03663 d->activeSheet->borderTop( selectionInfo(), color );
03664
03665 markSelectionAsDirty();
03666 doc()->emitEndOperation();
03667 }
03668 }
03669
03670 void View::borderOutline()
03671 {
03672 if ( d->activeSheet != 0L )
03673 {
03674 doc()->emitBeginOperation( false );
03675 d->activeSheet->borderOutline( d->selection, d->actions->borderColor->color() );
03676
03677 markSelectionAsDirty();
03678 doc()->emitEndOperation();
03679 }
03680 }
03681
03682 void View::setSelectionOutlineBorderColor( const QColor & color )
03683 {
03684 if ( d->activeSheet != 0L )
03685 {
03686 doc()->emitBeginOperation( false );
03687 d->activeSheet->borderOutline( selectionInfo(), color );
03688
03689 markSelectionAsDirty();
03690 doc()->emitEndOperation();
03691 }
03692 }
03693
03694 void View::borderAll()
03695 {
03696 if ( d->activeSheet != 0L )
03697 {
03698 doc()->emitBeginOperation( false );
03699 d->activeSheet->borderAll( d->selection, d->actions->borderColor->color() );
03700
03701 markSelectionAsDirty();
03702 doc()->emitEndOperation();
03703 }
03704 }
03705
03706 void View::setSelectionAllBorderColor( const QColor & color )
03707 {
03708 if ( d->activeSheet != 0L )
03709 {
03710 doc()->emitBeginOperation( false );
03711 d->activeSheet->borderAll( selectionInfo(), color );
03712
03713 markSelectionAsDirty();
03714 doc()->emitEndOperation();
03715 }
03716 }
03717
03718 void View::borderRemove()
03719 {
03720 if ( d->activeSheet != 0L )
03721 {
03722 doc()->emitBeginOperation(false);
03723 d->activeSheet->borderRemove( d->selection );
03724
03725 markSelectionAsDirty();
03726 doc()->emitEndOperation();
03727 }
03728 }
03729
03730 void View::addSheet( Sheet * _t )
03731 {
03732 doc()->emitBeginOperation( false );
03733
03734 insertSheet( _t );
03735
03736
03737 QObject::connect( _t, SIGNAL( sig_refreshView() ), SLOT( slotRefreshView() ) );
03738 QObject::connect( _t, SIGNAL( sig_updateView( Sheet* ) ), SLOT( slotUpdateView( Sheet* ) ) );
03739 QObject::connect( _t->print(), SIGNAL( sig_updateView( Sheet* ) ), SLOT( slotUpdateView( Sheet* ) ) );
03740 QObject::connect( _t, SIGNAL( sig_updateView( Sheet *, const Region& ) ),
03741 SLOT( slotUpdateView( Sheet*, const Region& ) ) );
03742 QObject::connect( _t, SIGNAL( sig_updateView( EmbeddedObject* )), SLOT( slotUpdateView( EmbeddedObject* ) ) );
03743
03744 QObject::connect( _t, SIGNAL( sig_updateHBorder( Sheet * ) ),
03745 SLOT( slotUpdateHBorder( Sheet * ) ) );
03746 QObject::connect( _t, SIGNAL( sig_updateVBorder( Sheet * ) ),
03747 SLOT( slotUpdateVBorder( Sheet * ) ) );
03748 QObject::connect( _t, SIGNAL( sig_nameChanged( Sheet*, const QString& ) ),
03749 this, SLOT( slotSheetRenamed( Sheet*, const QString& ) ) );
03750 QObject::connect( _t, SIGNAL( sig_SheetHidden( Sheet* ) ),
03751 this, SLOT( slotSheetHidden( Sheet* ) ) );
03752 QObject::connect( _t, SIGNAL( sig_SheetShown( Sheet* ) ),
03753 this, SLOT( slotSheetShown( Sheet* ) ) );
03754 QObject::connect( _t, SIGNAL( sig_SheetRemoved( Sheet* ) ),
03755 this, SLOT( slotSheetRemoved( Sheet* ) ) );
03756
03757
03758 QObject::connect( _t, SIGNAL( sig_updateChildGeometry( EmbeddedKOfficeObject* ) ),
03759 SLOT( slotUpdateChildGeometry( EmbeddedKOfficeObject* ) ) );
03760 QObject::connect( _t, SIGNAL( sig_maxColumn( int ) ), d->canvas, SLOT( slotMaxColumn( int ) ) );
03761 QObject::connect( _t, SIGNAL( sig_maxRow( int ) ), d->canvas, SLOT( slotMaxRow( int ) ) );
03762
03763 if ( !d->loading )
03764 updateBorderButton();
03765
03766 if ( !d->activeSheet )
03767 {
03768 doc()->emitEndOperation();
03769 return;
03770 }
03771 doc()->emitEndOperation( *selectionInfo() );
03772 }
03773
03774 void View::slotSheetRemoved( Sheet *_t )
03775 {
03776 doc()->emitBeginOperation( false );
03777
03778 QString m_sheetName=_t->sheetName();
03779 d->tabBar->removeTab( _t->sheetName() );
03780 if (doc()->map()->findSheet( doc()->map()->visibleSheets().first()))
03781 setActiveSheet( doc()->map()->findSheet( doc()->map()->visibleSheets().first() ));
03782 else
03783 d->activeSheet = 0L;
03784
03785 QValueList<Reference>::Iterator it;
03786 QValueList<Reference> area=doc()->listArea();
03787 for ( it = area.begin(); it != area.end(); ++it )
03788 {
03789
03790 if ( (*it).sheet_name == m_sheetName )
03791 {
03792 doc()->removeArea( (*it).ref_name );
03793
03794
03795 Sheet * tbl;
03796
03797 for ( tbl = doc()->map()->firstSheet(); tbl != 0L; tbl = doc()->map()->nextSheet() )
03798 {
03799 tbl->refreshRemoveAreaName((*it).ref_name);
03800 }
03801 }
03802 }
03803
03804 doc()->emitEndOperation( *selectionInfo() );
03805 }
03806
03807 void View::removeAllSheets()
03808 {
03809 doc()->emitBeginOperation(false);
03810 d->tabBar->clear();
03811
03812 setActiveSheet( 0L );
03813
03814 doc()->emitEndOperation();
03815 }
03816
03817 void View::setActiveSheet( Sheet * _t, bool updateSheet )
03818 {
03819 if ( _t == d->activeSheet )
03820 return;
03821
03822 doc()->emitBeginOperation(false);
03823
03824 saveCurrentSheetSelection();
03825
03826 Sheet * oldSheet = d->activeSheet;
03827
03828 d->activeSheet = _t;
03829
03830 if ( d->activeSheet == 0L )
03831 {
03832 doc()->emitEndOperation();
03833 return;
03834 }
03835
03836 if ( oldSheet && oldSheet->layoutDirection()==Sheet::RightToLeft != d->activeSheet->layoutDirection()==Sheet::RightToLeft )
03837 refreshView();
03838
03839 doc()->setDisplaySheet( d->activeSheet );
03840 if ( updateSheet )
03841 {
03842 d->tabBar->setActiveTab( _t->sheetName() );
03843 d->vBorderWidget->repaint();
03844 d->hBorderWidget->repaint();
03845 d->activeSheet->setRegionPaintDirty(QRect(QPoint(0,0), QPoint(KS_colMax, KS_rowMax)));
03846 d->canvas->slotMaxColumn( d->activeSheet->maxColumn() );
03847 d->canvas->slotMaxRow( d->activeSheet->maxRow() );
03848 }
03849
03850 d->actions->showPageBorders->setChecked( d->activeSheet->isShowPageBorders() );
03851 d->actions->protectSheet->setChecked( d->activeSheet->isProtected() );
03852 d->actions->protectDoc->setChecked( doc()->map()->isProtected() );
03853 d->adjustActions( !d->activeSheet->isProtected() );
03854 d->adjustWorkbookActions( !doc()->map()->isProtected() );
03855
03856
03857 QMapIterator<Sheet*, QPoint> it = d->savedAnchors.find(d->activeSheet);
03858 QMapIterator<Sheet*, QPoint> it2 = d->savedMarkers.find(d->activeSheet);
03859 QMapIterator<Sheet*, KoPoint> it3 = d->savedOffsets.find(d->activeSheet);
03860
03861
03862 QPoint newAnchor = (it == d->savedAnchors.end()) ? QPoint(1,1) : *it;
03863 QPoint newMarker = (it2 == d->savedMarkers.end()) ? QPoint(1,1) : *it2;
03864
03865 d->selection->clear();
03866 d->selection->setSheet( d->activeSheet );
03867 d->selection->initialize(QRect(newMarker, newAnchor));
03868
03869 d->canvas->scrollToCell(newMarker);
03870 if (it3 != d->savedOffsets.end())
03871 {
03872 d->canvas->setXOffset((*it3).x());
03873 d->canvas->setYOffset((*it3).y());
03874 d->horzScrollBar->setValue((*it3).x());
03875 d->vertScrollBar->setValue((*it3).y());
03876 }
03877 calcStatusBarOp();
03878
03879 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03880 }
03881
03882 void View::slotSheetRenamed( Sheet* sheet, const QString& old_name )
03883 {
03884 doc()->emitBeginOperation( false );
03885 d->tabBar->renameTab( old_name, sheet->sheetName() );
03886 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03887 }
03888
03889 void View::slotSheetHidden( Sheet* )
03890 {
03891 doc()->emitBeginOperation(false);
03892 updateShowSheetMenu();
03893 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03894 }
03895
03896 void View::slotSheetShown( Sheet* )
03897 {
03898 doc()->emitBeginOperation(false);
03899 d->tabBar->setTabs( doc()->map()->visibleSheets() );
03900 updateShowSheetMenu();
03901 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
03902 }
03903
03904 void View::changeSheet( const QString& _name )
03905 {
03906 if ( activeSheet()->sheetName() == _name )
03907 return;
03908
03909 Sheet *t = doc()->map()->findSheet( _name );
03910 if ( !t )
03911 {
03912 kdDebug(36001) << "Unknown sheet " << _name << endl;
03913 return;
03914 }
03915 doc()->emitBeginOperation(false);
03916 d->canvas->closeEditor();
03917 setActiveSheet( t, false );
03918
03919 d->canvas->updateEditor();
03920 updateEditWidget();
03921
03922 updateBorderButton();
03923
03924
03925 d->vBorderWidget->repaint();
03926 d->hBorderWidget->repaint();
03927 d->canvas->slotMaxColumn( d->activeSheet->maxColumn() );
03928 d->canvas->slotMaxRow( d->activeSheet->maxRow() );
03929 t->setRegionPaintDirty( t->visibleRect( d->canvas ) );
03930 doc()->emitEndOperation();
03931 }
03932
03933 void View::moveSheet( unsigned sheet, unsigned target )
03934 {
03935 if( doc()->map()->isProtected() ) return;
03936
03937 QStringList vs = doc()->map()->visibleSheets();
03938
03939 if( target >= vs.count() )
03940 doc()->map()->moveSheet( vs[ sheet ], vs[ vs.count()-1 ], false );
03941 else
03942 doc()->map()->moveSheet( vs[ sheet ], vs[ target ], true );
03943
03944 d->tabBar->moveTab( sheet, target );
03945 }
03946
03947 void View::sheetProperties()
03948 {
03949
03950 if( doc()->map()->isProtected() ) return;
03951 if( d->activeSheet->isProtected() ) return;
03952
03953 bool directionChanged = false;
03954
03955 SheetPropertiesDialog* dlg = new SheetPropertiesDialog( this );
03956 dlg->setLayoutDirection( d->activeSheet->layoutDirection() );
03957 dlg->setAutoCalc( d->activeSheet->getAutoCalc() );
03958 dlg->setShowGrid( d->activeSheet->getShowGrid() );
03959 dlg->setShowPageBorders( d->activeSheet->isShowPageBorders() );
03960 dlg->setShowFormula( d->activeSheet->getShowFormula() );
03961 dlg->setHideZero( d->activeSheet->getHideZero() );
03962 dlg->setShowFormulaIndicator( d->activeSheet->getShowFormulaIndicator() );
03963 dlg->setShowCommentIndicator( d->activeSheet->getShowCommentIndicator() );
03964 dlg->setColumnAsNumber( d->activeSheet->getShowColumnNumber() );
03965 dlg->setLcMode( d->activeSheet->getLcMode() );
03966 dlg->setCapitalizeFirstLetter( d->activeSheet->getFirstLetterUpper() );
03967
03968 if( dlg->exec() )
03969 {
03970 SheetPropertiesCommand* command = new SheetPropertiesCommand( doc(), d->activeSheet );
03971
03972 if ( d->activeSheet->layoutDirection() != dlg->layoutDirection() )
03973 directionChanged = true;
03974
03975 command->setLayoutDirection( dlg->layoutDirection() );
03976 command->setAutoCalc( dlg->autoCalc() );
03977 command->setShowGrid( dlg->showGrid() );
03978 command->setShowPageBorders( dlg->showPageBorders() );
03979 command->setShowFormula( dlg->showFormula() );
03980 command->setHideZero( dlg->hideZero() );
03981 command->setShowFormulaIndicator( dlg->showFormulaIndicator() );
03982 command->setShowCommentIndicator( dlg->showCommentIndicator() );
03983 command->setColumnAsNumber( dlg->columnAsNumber() );
03984 command->setLcMode( dlg->lcMode() );
03985 command->setCapitalizeFirstLetter( dlg->capitalizeFirstLetter() );
03986 doc()->addCommand( command );
03987 command->execute();
03988 }
03989
03990 delete dlg;
03991
03992 if ( directionChanged )
03993 {
03994
03995 d->horzScrollBar->setValue( d->horzScrollBar->maxValue() -
03996 d->horzScrollBar->value() );
03997 d->hBorderWidget->update();
03998 }
03999 }
04000
04001 void View::insertSheet()
04002 {
04003 if ( doc()->map()->isProtected() )
04004 {
04005 KMessageBox::error( 0, i18n ( "You cannot change a protected sheet." ) );
04006 return;
04007 }
04008
04009 doc()->emitBeginOperation( false );
04010 d->canvas->closeEditor();
04011 Sheet * t = doc()->map()->createSheet();
04012 KCommand* command = new AddSheetCommand( t );
04013 doc()->addCommand( command );
04014 updateEditWidget();
04015 setActiveSheet( t );
04016
04017 if ( doc()->map()->visibleSheets().count() > 1 )
04018 {
04019 d->actions->removeSheet->setEnabled( true );
04020 d->actions->hideSheet->setEnabled( true );
04021 }
04022
04023 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
04024 }
04025
04026 void View::hideSheet()
04027 {
04028 if ( !d->activeSheet )
04029 return;
04030
04031 if ( doc()->map()->visibleSheets().count() == 1)
04032 {
04033 KMessageBox::error( this, i18n("You cannot hide the last visible sheet.") );
04034 return;
04035 }
04036
04037 QStringList vs = doc()->map()->visibleSheets();
04038 int i = vs.findIndex( d->activeSheet->tableName() ) - 1;
04039 if( i < 0 ) i = 1;
04040 QString sn = vs[i];
04041
04042 doc()->emitBeginOperation(false);
04043
04044 KCommand* command = new HideSheetCommand( activeSheet() );
04045 doc()->addCommand( command );
04046 command->execute();
04047
04048 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
04049
04050 d->tabBar->removeTab( d->activeSheet->sheetName() );
04051 d->tabBar->setActiveTab( sn );
04052 }
04053
04054 void View::showSheet()
04055 {
04056 if ( !d->activeSheet )
04057 return;
04058
04059 ShowDialog dlg( this, "Sheet show");
04060 dlg.exec();
04061 }
04062
04063 void View::copySelection()
04064 {
04065 if ( !d->activeSheet )
04066 return;
04067
04068 if ( canvasWidget()->isObjectSelected() )
04069 {
04070 canvasWidget()->copyOasisObjects();
04071 return;
04072 }
04073 if ( !d->canvas->editor() )
04074 {
04075 d->activeSheet->copySelection( selectionInfo() );
04076
04077 updateEditWidget();
04078 }
04079 else
04080 d->canvas->editor()->copy();
04081 }
04082
04083 void View::copyAsText()
04084 {
04085 if ( !d->activeSheet )
04086 return;
04087 d->activeSheet->copyAsText( selectionInfo() );
04088 }
04089
04090
04091 void View::cutSelection()
04092 {
04093 if ( !d->activeSheet )
04094 return;
04095
04096 doc()->emitBeginOperation(false);
04097
04098 if ( canvasWidget()->isObjectSelected() )
04099 {
04100 canvasWidget()->copyOasisObjects();
04101 markSelectionAsDirty();
04102 doc()->emitEndOperation();
04103
04104 KMacroCommand * macroCommand = 0L;
04105 QPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
04106 for ( ; it.current() ; ++it )
04107 {
04108 if ( it.current()->sheet() == canvasWidget()->activeSheet() && it.current()->isSelected() )
04109 {
04110 if( !macroCommand )
04111 macroCommand = new KMacroCommand( i18n( "Cut Objects" ) );
04112 RemoveObjectCommand *cmd = new RemoveObjectCommand( it.current(), true );
04113 macroCommand->addCommand( cmd );
04114 }
04115 }
04116 if ( macroCommand )
04117 {
04118 doc()->addCommand( macroCommand );
04119 canvasWidget()->setMouseSelectedObject( false );
04120 macroCommand->execute();
04121 }
04122
04123 return;
04124 }
04125 if ( !d->canvas->editor())
04126 {
04127 d->activeSheet->cutSelection( selectionInfo() );
04128 calcStatusBarOp();
04129 updateEditWidget();
04130 }
04131 else
04132 d->canvas->editor()->cut();
04133
04134 markSelectionAsDirty();
04135 doc()->emitEndOperation();
04136 }
04137
04138 void View::paste()
04139 {
04140 if ( !d->activeSheet )
04141 return;
04142
04143 if (!koDocument()->isReadWrite())
04144 return;
04145
04146 QMimeSource *data = QApplication::clipboard()->data( QClipboard::Clipboard );
04147 for ( int i=0; data->format(i) != 0; i++ )
04148 kdDebug() << "format:" << data->format(i) << endl;
04149
04150 if ( data->provides( KoStoreDrag::mimeType("application/vnd.oasis.opendocument.spreadsheet" ) ))
04151 {
04152 canvasWidget()->deselectAllObjects();
04153 QCString returnedTypeMime = "application/vnd.oasis.opendocument.spreadsheet";
04154 const QByteArray arr = data->encodedData( returnedTypeMime );
04155 if( arr.isEmpty() )
04156 return;
04157 QBuffer buffer( arr );
04158 KoStore * store = KoStore::createStore( &buffer, KoStore::Read );
04159
04160 KoOasisStore oasisStore( store );
04161 QDomDocument doc;
04162 QString errorMessage;
04163 bool ok = oasisStore.loadAndParse( "content.xml", doc, errorMessage );
04164 if ( !ok ) {
04165 kdError(32001) << "Error parsing content.xml: " << errorMessage << endl;
04166 return;
04167 }
04168
04169 KoOasisStyles oasisStyles;
04170 QDomDocument stylesDoc;
04171 (void)oasisStore.loadAndParse( "styles.xml", stylesDoc, errorMessage );
04172
04173 oasisStyles.createStyleMap( stylesDoc, true );
04174
04175 oasisStyles.createStyleMap( doc, false );
04176
04177
04178 QDomElement content = doc.documentElement();
04179 QDomElement realBody ( KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
04180 if ( realBody.isNull() )
04181 {
04182 kdDebug() << "Invalid OASIS OpenDocument file. No office:body tag found." << endl;
04183 return;
04184 }
04185 QDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "spreadsheet" );
04186
04187 if ( body.isNull() )
04188 {
04189 kdError(32001) << "No office:spreadsheet found!" << endl;
04190 QDomElement childElem;
04191 QString localName;
04192 forEachElement( childElem, realBody ) {
04193 localName = childElem.localName();
04194 }
04195 return;
04196 }
04197
04198 KoOasisLoadingContext context( d->doc, oasisStyles, store );
04199 Q_ASSERT( !oasisStyles.officeStyle().isNull() );
04200
04201
04202 d->doc->styleManager()->loadOasisStyleTemplate( oasisStyles );
04203
04204
04205 d->doc->loadOasisAreaName( body );
04206 d->doc->loadOasisCellValidation( body );
04207
04208
04209 QDictIterator<QDomElement> it( oasisStyles.styles("table-cell") );
04210 QDict<Style> styleElements;
04211 for (;it.current();++it)
04212 {
04213 if ( it.current()->hasAttributeNS( KoXmlNS::style , "name" ) )
04214 {
04215 QString name = it.current()->attributeNS( KoXmlNS::style , "name" , QString::null );
04216 styleElements.insert( name , new Style());
04217 styleElements[name]->loadOasisStyle( oasisStyles , *(it.current()) );
04218 }
04219 }
04220
04221
04222 bool result = d->doc->map()->loadOasis( body, context, styleElements );
04223
04224
04225 QDictIterator<Style> styleIter( styleElements );
04226 for (;styleIter.current();++styleIter)
04227 if (styleIter.current()->release())
04228 delete styleIter.current();
04229
04230 if (!result)
04231 return;
04232
04233 }
04234 else
04235 {
04236
04237 QPixmap clipboardPixmap = QApplication::clipboard()->pixmap( QClipboard::Clipboard );
04238 if (!clipboardPixmap.isNull())
04239 {
04240 d->activeSheet->insertPicture( markerDocumentPosition() , clipboardPixmap );
04241 }
04242 }
04243
04244 doc()->emitBeginOperation( false );
04245 if ( !d->canvas->editor() )
04246 {
04247
04248 d->activeSheet->paste( d->selection->lastRange(), true,
04249 Paste::Normal, Paste::OverWrite,
04250 false, 0, true );
04251 calcStatusBarOp();
04252 updateEditWidget();
04253 }
04254 else
04255 {
04256 d->canvas->editor()->paste();
04257 }
04258 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
04259 }
04260
04261 void View::specialPaste()
04262 {
04263 if ( !d->activeSheet )
04264 return;
04265
04266 SpecialDialog dlg( this, "Special Paste" );
04267 if ( dlg.exec() )
04268 {
04269 if ( d->activeSheet->getAutoCalc() )
04270 {
04271 doc()->emitBeginOperation( false );
04272 d->activeSheet->recalc();
04273 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
04274 }
04275 calcStatusBarOp();
04276 updateEditWidget();
04277 }
04278 }
04279
04280 void View::removeComment()
04281 {
04282 if ( !d->activeSheet )
04283 return;
04284
04285 doc()->emitBeginOperation(false);
04286 d->activeSheet->setSelectionRemoveComment( selectionInfo() );
04287 updateEditWidget();
04288
04289 markSelectionAsDirty();
04290 doc()->emitEndOperation();
04291 }
04292
04293
04294 void View::changeAngle()
04295 {
04296 if ( !d->activeSheet )
04297 return;
04298
04299 AngleDialog dlg( this, "Angle" ,
04300 QPoint( d->canvas->markerColumn(), d->canvas->markerRow() ));
04301 if ( dlg.exec() )
04302 {
04303
04304 d->activeSheet->adjustArea(*selectionInfo());
04305 }
04306 }
04307
04308 void View::setSelectionAngle( int angle )
04309 {
04310 doc()->emitBeginOperation( false );
04311
04312 if ( d->activeSheet != NULL )
04313 {
04314 d->activeSheet->setSelectionAngle( selectionInfo(), angle );
04315 d->activeSheet->adjustArea(*selectionInfo());
04316 }
04317
04318 markSelectionAsDirty();
04319 doc()->emitEndOperation();
04320 }
04321
04322 void View::mergeCell()
04323 {
04324
04325 if( !d->activeSheet )
04326 return;
04327 d->activeSheet->mergeCells(*selectionInfo());
04328 }
04329
04330 void View::mergeCellHorizontal()
04331 {
04332
04333 if( !d->activeSheet )
04334 return;
04335 d->activeSheet->mergeCells(*selectionInfo(), true);
04336 }
04337
04338 void View::mergeCellVertical()
04339 {
04340
04341 if( !d->activeSheet )
04342 return;
04343 d->activeSheet->mergeCells(*selectionInfo(), false, true);
04344 }
04345
04346 void View::dissociateCell()
04347 {
04348
04349 if( !d->activeSheet )
04350 return;
04351 d->activeSheet->dissociateCells(*selectionInfo());
04352 }
04353
04354
04355 void View::increaseIndent()
04356 {
04357 if ( !d->activeSheet )
04358 return;
04359
04360 doc()->emitBeginOperation( false );
04361 d->activeSheet->increaseIndent( d->selection );
04362 updateEditWidget();
04363
04364 markSelectionAsDirty();
04365 doc()->emitEndOperation();
04366 }
04367
04368 void View::decreaseIndent()
04369 {
04370 if ( !d->activeSheet )
04371 return;
04372
04373 doc()->emitBeginOperation( false );
04374 int column = d->canvas->markerColumn();
04375 int row = d->canvas->markerRow();
04376
04377 d->activeSheet->decreaseIndent( d->selection );
04378 Cell * cell = d->activeSheet->cellAt( column, row );
04379 if ( cell )
04380 if ( !d->activeSheet->isProtected() )
04381 d->actions->decreaseIndent->setEnabled( cell->format()->getIndent( column, row ) > 0.0 );
04382
04383 markSelectionAsDirty();
04384 doc()->emitEndOperation();
04385 }
04386
04387 void View::goalSeek()
04388 {
04389 if ( d->canvas->editor() )
04390 {
04391 d->canvas->deleteEditor( true );
04392 }
04393
04394 GoalSeekDialog * dlg
04395 = new GoalSeekDialog( this, QPoint( d->canvas->markerColumn(),
04396 d->canvas->markerRow() ),
04397 "GoalSeekDialog" );
04398 dlg->show();
04399
04400 }
04401
04402 void View::subtotals()
04403 {
04404 if (!activeSheet())
04405 return;
04406
04407 QRect selection( d->selection->selection() );
04408 if ( ( selection.width() < 2 ) || ( selection.height() < 2 ) )
04409 {
04410 KMessageBox::error( this, i18n("You must select multiple cells.") );
04411 return;
04412 }
04413
04414 SubtotalDialog dlg(this, selection, "SubtotalDialog" );
04415 if ( dlg.exec() )
04416 {
04417 doc()->emitBeginOperation( false );
04418
04419 d->selection->initialize( QRect(dlg.selection().topLeft(), dlg.selection().bottomRight()));
04420 doc()->emitEndOperation( selection );
04421 }
04422 }
04423
04424 void View::multipleOperations()
04425 {
04426 if ( d->canvas->editor() )
04427 {
04428 d->canvas->deleteEditor( true );
04429 }
04430
04431
04432 }
04433
04434 void View::textToColumns()
04435 {
04436 if (!activeSheet())
04437 return;
04438
04439 d->canvas->closeEditor();
04440
04441 QRect area=d->selection->selection();
04442
04443
04444 area.setRight(area.left());
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454 CSVDialog dialog( this, "CSVDialog", area, CSVDialog::Column );
04455 if( !dialog.cancelled() )
04456 dialog.exec();
04457 }
04458
04459 void View::consolidate()
04460 {
04461 d->canvas->closeEditor();
04462 ConsolidateDialog * dlg = new ConsolidateDialog( this, "ConsolidateDialog" );
04463 dlg->show();
04464
04465 }
04466
04467 void View::sortList()
04468 {
04469 if (!activeSheet()) return;
04470
04471 ListDialog dlg( this, "List selection" );
04472 dlg.exec();
04473 }
04474
04475 void View::gotoCell()
04476 {
04477 if (!activeSheet()) return;
04478
04479 GotoDialog dlg( this, "GotoCell" );
04480 dlg.exec();
04481 }
04482
04483 void View::find()
04484 {
04485 if (!activeSheet()) return;
04486
04487 FindDlg dlg( this, "Find", d->findOptions, d->findStrings );
04488 dlg.setHasSelection( !d->selection->isSingular() );
04489 dlg.setHasCursor( true );
04490 if ( KFindDialog::Accepted != dlg.exec() )
04491 return;
04492
04493
04494 d->findOptions = dlg.options();
04495 d->findStrings = dlg.findHistory();
04496 d->typeValue = dlg.searchType();
04497 d->directionValue = dlg.searchDirection();
04498
04499
04500 delete d->find;
04501 delete d->replace;
04502 d->find = new KFind( dlg.pattern(), dlg.options(), this );
04503 d->replace = 0L;
04504
04505 d->searchInSheets.currentSheet = activeSheet();
04506 d->searchInSheets.firstSheet = d->searchInSheets.currentSheet;
04507
04508 initFindReplace();
04509 findNext();
04510 }
04511
04512
04513
04514 void View::initFindReplace()
04515 {
04516 KFind* findObj = d->find ? d->find : d->replace;
04517 Q_ASSERT( findObj );
04518 connect(findObj, SIGNAL( highlight( const QString &, int, int ) ),
04519 this, SLOT( slotHighlight( const QString &, int, int ) ) );
04520 connect(findObj, SIGNAL( findNext() ),
04521 this, SLOT( findNext() ) );
04522
04523 bool bck = d->findOptions & KFindDialog::FindBackwards;
04524 Sheet* currentSheet = d->searchInSheets.currentSheet;
04525
04526 QRect region = ( d->findOptions & KFindDialog::SelectedText )
04527 ? d->selection->selection()
04528 : QRect( 1, 1, currentSheet->maxColumn(), currentSheet->maxRow() );
04529
04530 int colStart = !bck ? region.left() : region.right();
04531 int colEnd = !bck ? region.right() : region.left();
04532 int rowStart = !bck ? region.top() :region.bottom();
04533 int rowEnd = !bck ? region.bottom() : region.top();
04534 if ( d->findOptions & KFindDialog::FromCursor ) {
04535 QPoint marker( d->selection->marker() );
04536 colStart = marker.x();
04537 rowStart = marker.y();
04538 }
04539 d->findLeftColumn = region.left();
04540 d->findRightColumn = region.right();
04541 d->findPos = QPoint( colStart, rowStart );
04542 d->findEnd = QPoint( colEnd, rowEnd );
04543
04544
04545 }
04546
04547 void View::findNext()
04548 {
04549 KFind* findObj = d->find ? d->find : d->replace;
04550 if ( !findObj ) {
04551 find();
04552 return;
04553 }
04554 KFind::Result res = KFind::NoMatch;
04555 Cell* cell = findNextCell();
04556 bool forw = ! ( d->findOptions & KFindDialog::FindBackwards );
04557 while ( res == KFind::NoMatch && cell )
04558 {
04559 if ( findObj->needData() )
04560 {
04561 if ( d->typeValue == FindOption::Note )
04562 findObj->setData( cell->format()->comment( cell->column(), cell->row() ) );
04563 else
04564 findObj->setData( cell->text() );
04565 d->findPos = QPoint( cell->column(), cell->row() );
04566
04567 }
04568
04569
04570 if ( d->find )
04571 res = d->find->find();
04572 else
04573 res = d->replace->replace();
04574
04575 if ( res == KFind::NoMatch ) {
04576
04577 if ( d->directionValue == FindOption::Row )
04578 {
04579 if ( forw )
04580 ++d->findPos.rx();
04581 else
04582 --d->findPos.rx();
04583 }
04584 else
04585 {
04586 if ( forw )
04587 ++d->findPos.ry();
04588 else
04589 --d->findPos.ry();
04590 }
04591 cell = findNextCell();
04592 }
04593 }
04594
04595 if ( res == KFind::NoMatch )
04596 {
04597
04598
04599 if ( findObj->shouldRestart() ) {
04600 d->findOptions &= ~KFindDialog::FromCursor;
04601 findObj->resetCounts();
04602 findNext();
04603 }
04604 else {
04605 if ( d->find )
04606 d->find->closeFindNextDialog();
04607 else
04608 d->replace->closeReplaceNextDialog();
04609 }
04610 }
04611 }
04612
04613 Cell* View::nextFindValidCell( int col, int row )
04614 {
04615 Cell *cell = d->searchInSheets.currentSheet->cellAt( col, row );
04616 if ( cell->isDefault() || cell->isObscured() || cell->isFormula() )
04617 cell = 0L;
04618 if ( d->typeValue == FindOption::Note && cell && cell->format()->comment(col, row).isEmpty())
04619 cell = 0L;
04620 return cell;
04621 }
04622
04623 Cell* View::findNextCell()
04624 {
04625
04626
04627
04628 Sheet* sheet = d->searchInSheets.currentSheet;
04629 Cell* cell = 0L;
04630 bool forw = ! ( d->findOptions & KFindDialog::FindBackwards );
04631 int col = d->findPos.x();
04632 int row = d->findPos.y();
04633 int maxRow = sheet->maxRow();
04634
04635
04636 if ( d->directionValue == FindOption::Row )
04637 {
04638 while ( !cell && row != d->findEnd.y() && (forw ? row < maxRow : row >= 0) )
04639 {
04640 while ( !cell && (forw ? col <= d->findRightColumn : col >= d->findLeftColumn) )
04641 {
04642 cell = nextFindValidCell( col, row );
04643 if ( forw ) ++col;
04644 else --col;
04645 }
04646 if ( cell )
04647 break;
04648
04649 if ( forw ) {
04650 col = d->findLeftColumn;
04651 ++row;
04652 } else {
04653 col = d->findRightColumn;
04654 --row;
04655 }
04656
04657 }
04658 }
04659 else
04660 {
04661 while ( !cell && (forw ? col <= d->findRightColumn : col >= d->findLeftColumn) )
04662 {
04663 while ( !cell && row != d->findEnd.y() && (forw ? row < maxRow : row >= 0) )
04664 {
04665 cell = nextFindValidCell( col, row );
04666 if ( forw ) ++row;
04667 else --row;
04668 }
04669 if ( cell )
04670 break;
04671
04672 if ( forw ) {
04673 row = 0;
04674 ++col;
04675 } else {
04676 col = maxRow;
04677 --col;
04678 }
04679
04680 }
04681 }
04682
04683
04684
04685
04686 return cell;
04687 }
04688
04689 void View::findPrevious()
04690 {
04691 KFind* findObj = d->find ? d->find : d->replace;
04692 if ( !findObj ) {
04693 find();
04694 return;
04695 }
04696
04697 int opt = d->findOptions;
04698 bool forw = ! ( opt & KFindDialog::FindBackwards );
04699 if ( forw )
04700 d->findOptions = ( opt | KFindDialog::FindBackwards );
04701 else
04702 d->findOptions = ( opt & ~KFindDialog::FindBackwards );
04703
04704 findNext();
04705
04706 d->findOptions = opt;
04707 }
04708
04709 void View::replace()
04710 {
04711 if (!d->activeSheet)
04712 return;
04713
04714 SearchDlg dlg( this, "Replace", d->findOptions, d->findStrings, d->replaceStrings );
04715 dlg.setHasSelection( !d->selection->isSingular() );
04716 dlg.setHasCursor( true );
04717 if ( KReplaceDialog::Accepted != dlg.exec() )
04718 return;
04719
04720 d->findOptions = dlg.options();
04721 d->findStrings = dlg.findHistory();
04722 d->replaceStrings = dlg.replacementHistory();
04723 d->typeValue = dlg.searchType();
04724
04725 delete d->find;
04726 delete d->replace;
04727 d->find = 0L;
04728
04729
04730
04731
04732 if (dlg.pattern() == "^" && dlg.replacement().isEmpty())
04733 return;
04734 d->replace = new KReplace( dlg.pattern(), dlg.replacement(), dlg.options() );
04735
04736 d->searchInSheets.currentSheet = activeSheet();
04737 d->searchInSheets.firstSheet = d->searchInSheets.currentSheet;
04738 initFindReplace();
04739 connect( d->replace, SIGNAL( replace( const QString &, int, int, int ) ),
04740 this, SLOT( slotReplace( const QString &, int, int, int ) ) );
04741
04742 if ( !doc()->undoLocked() )
04743 {
04744 QRect region( d->findPos, d->findEnd );
04745
04746 UndoChangeAreaTextCell *undo = new UndoChangeAreaTextCell( doc(), d->searchInSheets.currentSheet, region );
04747 doc()->addCommand( undo );
04748 }
04749
04750 findNext();
04751
04752 #if 0
04753
04754
04755 Cell *cell = activeSheet()->cellAt( canvasWidget()->markerColumn(),
04756 canvasWidget()->markerRow() );
04757 if ( cell->text() != 0L )
04758 d->editWidget->setText( cell->text() );
04759 else
04760 d->editWidget->setText( "" );
04761 #endif
04762 }
04763
04764 void View::slotHighlight( const QString &, int , int )
04765 {
04766 d->selection->initialize( d->findPos );
04767 KDialogBase *baseDialog=0L;
04768 if ( d->find )
04769 baseDialog = d->find->findNextDialog();
04770 else
04771 baseDialog = d->replace->replaceNextDialog();
04772 kdDebug()<<" baseDialog :"<<baseDialog<<endl;
04773 QRect globalRect( d->findPos, d->findEnd );
04774 globalRect.moveTopLeft( canvasWidget()->mapToGlobal( globalRect.topLeft() ) );
04775 KDialog::avoidArea( baseDialog, QRect( d->findPos, d->findEnd ));
04776 }
04777
04778 void View::slotReplace( const QString &newText, int, int, int )
04779 {
04780
04781 Cell *cell = d->searchInSheets.currentSheet->cellAt( d->findPos );
04782
04783
04784 cell->setDisplayDirtyFlag();
04785 if ( d->typeValue == FindOption::Value )
04786 cell->setCellText( newText );
04787 else if ( d->typeValue == FindOption::Note )
04788 cell->format()->setComment( newText );
04789 cell->clearDisplayDirtyFlag();
04790 }
04791
04792 void View::conditional()
04793 {
04794 QRect rect( d->selection->selection() );
04795
04796 if ( util_isRowOrColumnSelected(rect))
04797 {
04798 KMessageBox::error( this, i18n("Area is too large.") );
04799 }
04800 else
04801 {
04802 ConditionalDialog dlg( this, "ConditionalDialog", rect);
04803 dlg.exec();
04804 }
04805 }
04806
04807 void View::validity()
04808 {
04809 QRect rect( d->selection->selection() );
04810
04811 if (d->selection->isColumnOrRowSelected())
04812 {
04813 KMessageBox::error( this, i18n("Area is too large."));
04814 }
04815 else
04816 {
04817 DlgValidity dlg( this,"validity",rect);
04818 dlg.exec();
04819 }
04820 }
04821
04822
04823 void View::insertSeries()
04824 {
04825 d->canvas->closeEditor();
04826 SeriesDlg dlg( this, "Series", QPoint( d->canvas->markerColumn(), d->canvas->markerRow() ) );
04827 dlg.exec();
04828 }
04829
04830 void View::sort()
04831 {
04832 if ( d->selection->isSingular() )
04833 {
04834 KMessageBox::error( this, i18n("You must select multiple cells.") );
04835 return;
04836 }
04837
04838 SortDialog dlg( this, "Sort" );
04839 dlg.exec();
04840 }
04841
04842 void View::removeHyperlink()
04843 {
04844 QPoint marker( d->selection->marker() );
04845 Cell * cell = d->activeSheet->cellAt( marker );
04846 if( !cell ) return;
04847 if( cell->link().isEmpty() ) return;
04848
04849 LinkCommand* command = new LinkCommand( cell, QString::null, QString::null );
04850 doc()->addCommand( command );
04851 command->execute();
04852
04853 canvasWidget()->setFocus();
04854 d->editWidget->setText( cell->text() );
04855 }
04856
04857 void View::insertHyperlink()
04858 {
04859 if (!activeSheet())
04860 return;
04861
04862 d->canvas->closeEditor();
04863
04864 QPoint marker( d->selection->marker() );
04865 Cell* cell = d->activeSheet->cellAt( marker );
04866
04867 LinkDialog* dlg = new LinkDialog( this );
04868 dlg->setCaption( i18n( "Insert Link" ) );
04869 if( cell )
04870 {
04871 dlg->setText( cell->text() );
04872 if( !cell->link().isEmpty() )
04873 {
04874 dlg->setCaption( i18n( "Edit Link" ) );
04875 dlg->setLink( cell->link() );
04876 }
04877 }
04878
04879 if( dlg->exec() == KDialog::Accepted )
04880 {
04881 cell = d->activeSheet->nonDefaultCell( marker );
04882
04883 LinkCommand* command = new LinkCommand( cell, dlg->text(), dlg->link() );
04884 doc()->addCommand( command );
04885 command->execute();
04886
04887
04888 canvasWidget()->setFocus();
04889 d->editWidget->setText( cell->text() );
04890 }
04891 delete dlg;
04892 }
04893
04894 void View::insertFromDatabase()
04895 {
04896 #ifndef QT_NO_SQL
04897 d->canvas->closeEditor();
04898
04899 QRect rect = d->selection->selection();
04900
04901 QStringList str = QSqlDatabase::drivers();
04902 if ( str.isEmpty() )
04903 {
04904 KMessageBox::error( this, i18n("No database drivers available. To use this feature you need "
04905 "to install the necessary Qt 3 database drivers.") );
04906
04907 return;
04908 }
04909
04910 doc()->doNotPaint( true );
04911 DatabaseDialog dlg(this, rect, "DatabaseDialog");
04912 dlg.exec();
04913 doc()->doNotPaint( false );
04914 #endif
04915 }
04916
04917 void View::insertFromTextfile()
04918 {
04919 d->canvas->closeEditor();
04920
04921 doc()->doNotPaint( true );
04922 CSVDialog dialog( this, "CSVDialog", d->selection->selection(), CSVDialog::File );
04923 if( !dialog.cancelled() )
04924 dialog.exec();
04925 doc()->doNotPaint( false );
04926 }
04927
04928 void View::insertFromClipboard()
04929 {
04930 d->canvas->closeEditor();
04931 doc()->doNotPaint( true );
04932 CSVDialog dialog( this, "CSVDialog", d->selection->selection(), CSVDialog::Clipboard );
04933 if( !dialog.cancelled() )
04934 dialog.exec();
04935 doc()->doNotPaint( false );
04936 }
04937
04938 void View::setupPrinter( KPrinter &prt )
04939 {
04940 if (!activeSheet())
04941 return;
04942
04943 SheetPrint* print = d->activeSheet->print();
04944
04945
04946 KoFormat pageFormat = print->paperFormat();
04947
04948 prt.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pageFormat ) ) );
04949
04950 if ( print->orientation() == PG_LANDSCAPE || pageFormat == PG_SCREEN )
04951 prt.setOrientation( KPrinter::Landscape );
04952 else
04953 prt.setOrientation( KPrinter::Portrait );
04954
04955 prt.setFullPage( true );
04956
04957
04958
04959 KPSheetSelectPage* sheetpage = new KPSheetSelectPage();
04960 prt.addDialogPage(sheetpage);
04961
04962
04963 QPtrList<Sheet> sheetlist = doc()->map()->sheetList();
04964 Sheet* sheet = sheetlist.last();
04965 while ( sheet )
04966 {
04967 kdDebug() << "Adding " << sheet->sheetName() << endl;
04968 sheetpage->prependAvailableSheet(sheet->sheetName());
04969 sheet = sheetlist.prev();
04970 }
04971 }
04972
04973 void View::print( KPrinter &prt )
04974 {
04975 if (!activeSheet())
04976 return;
04977
04978
04979 Sheet* selectedsheet = this->activeSheet();
04980
04981
04982 QStringList sheetlist = KPSheetSelectPage::selectedSheets(prt);
04983
04984 if (sheetlist.empty())
04985 {
04986 kdDebug() << "No sheet for printing selected, printing active sheet" << endl;
04987 sheetlist.append(d->activeSheet->sheetName());
04988 }
04989
04990 QPainter painter;
04991 painter.begin( &prt );
04992
04993 bool firstpage = true;
04994
04995 QStringList::iterator sheetlistiterator;
04996 for (sheetlistiterator = sheetlist.begin(); sheetlistiterator != sheetlist.end(); ++sheetlistiterator)
04997 {
04998 kdDebug() << " printing sheet " << *sheetlistiterator << endl;
04999 Sheet* sheet = doc()->map()->findSheet(*sheetlistiterator);
05000 if (sheet == NULL)
05001 {
05002 kdWarning() << i18n("Sheet %1 could not be found for printing").arg(*sheetlistiterator) << endl;
05003 continue;
05004 }
05005
05006 setActiveSheet(sheet,FALSE);
05007
05008 SheetPrint* print = d->activeSheet->print();
05009
05010 if (firstpage)
05011 firstpage=false;
05012 else
05013 {
05014 kdDebug() << " inserting new page" << endl;
05015 prt.newPage();
05016 }
05017
05018 if ( d->canvas->editor() )
05019 {
05020 d->canvas->deleteEditor( true );
05021 }
05022
05023 int oldZoom = doc()->zoom();
05024
05025
05026
05027
05028
05029
05030 QPaintDeviceMetrics metrics( &prt );
05031
05032 int dpiX = metrics.logicalDpiX();
05033 int dpiY = metrics.logicalDpiY();
05034
05035 doc()->setZoomAndResolution( int( print->zoom() * 100 ), dpiX, dpiY );
05036
05037
05038 KoOrientation _orient = print->orientation();
05039
05040
05041 if ( prt.orientation() == KPrinter::Landscape )
05042 {
05043 print->setPaperOrientation( PG_LANDSCAPE );
05044 }
05045 else
05046 {
05047 print->setPaperOrientation( PG_PORTRAIT );
05048 }
05049
05050 bool result = print->print( painter, &prt );
05051
05052
05053 print->setPaperOrientation( _orient );
05054
05055 doc()->setZoomAndResolution( oldZoom, KoGlobal::dpiX(), KoGlobal::dpiY() );
05056 doc()->newZoomAndResolution( true, false );
05057
05058
05059 doc()->emitBeginOperation( false );
05060 setZoom( oldZoom, false );
05061 doc()->emitEndOperation();
05062
05063
05064 if( !result )
05065 {
05066 if( !prt.previewOnly() )
05067 {
05068 KMessageBox::information( 0,
05069 i18n("Nothing to print for sheet %1.").arg(
05070 d->activeSheet->sheetName()) );
05071
05072
05073
05074 }
05075 }
05076 }
05077
05078 painter.end();
05079 this->setActiveSheet(selectedsheet);
05080 }
05081
05082 void View::insertChart( const QRect& _geometry, KoDocumentEntry& _e )
05083 {
05084 if ( !d->activeSheet )
05085 return;
05086
05087
05088 KoRect unzoomedRect = doc()->unzoomRect( _geometry );
05089 unzoomedRect.moveBy( d->canvas->xOffset(), d->canvas->yOffset() );
05090
05091 InsertObjectCommand *cmd = 0;
05092 if ( d->selection->isColumnOrRowSelected() )
05093 {
05094 KMessageBox::error( this, i18n("Area is too large."));
05095 return;
05096 }
05097 else
05098 cmd = new InsertObjectCommand( unzoomedRect, _e, d->selection->selection(), d->canvas );
05099
05100 doc()->addCommand( cmd );
05101 cmd->execute();
05102 }
05103
05104 void View::insertChild( const QRect& _geometry, KoDocumentEntry& _e )
05105 {
05106 if ( !d->activeSheet )
05107 return;
05108
05109
05110 KoRect unzoomedRect = doc()->unzoomRect( _geometry );
05111 unzoomedRect.moveBy( d->canvas->xOffset(), d->canvas->yOffset() );
05112
05113 InsertObjectCommand *cmd = new InsertObjectCommand( unzoomedRect, _e, d->canvas );
05114 doc()->addCommand( cmd );
05115 cmd->execute();
05116 }
05117
05118 KoPoint View::markerDocumentPosition()
05119 {
05120 QPoint marker=selectionInfo()->marker();
05121
05122 return KoPoint( d->activeSheet->dblColumnPos(marker.x()),
05123 d->activeSheet->dblRowPos(marker.y()) );
05124 }
05125
05126 void View::insertPicture()
05127 {
05128
05129
05130
05131
05132
05133
05134
05135 KURL file = KFileDialog::getImageOpenURL( QString::null, d->canvas );
05136
05137 if (file.isEmpty())
05138 return;
05139
05140 if ( !d->activeSheet )
05141 return;
05142
05143 InsertObjectCommand *cmd = new InsertObjectCommand( KoRect(markerDocumentPosition(),KoSize(0,0)) , file, d->canvas );
05144 doc()->addCommand( cmd );
05145 cmd->execute();
05146 }
05147
05148 void View::slotUpdateChildGeometry( EmbeddedKOfficeObject * )
05149 {
05150
05151
05152
05153
05154
05155
05156
05157
05158
05159
05160
05161
05162
05163
05164
05165
05166
05167
05168
05169
05170
05171
05172 }
05173
05174 void View::toggleProtectDoc( bool mode )
05175 {
05176 if ( !doc() || !doc()->map() )
05177 return;
05178
05179 QCString passwd;
05180 if ( mode )
05181 {
05182 int result = KPasswordDialog::getNewPassword( passwd, i18n( "Protect Document" ) );
05183 if ( result != KPasswordDialog::Accepted )
05184 {
05185 d->actions->protectDoc->setChecked( false );
05186 return;
05187 }
05188
05189 QCString hash( "" );
05190 QString password( passwd );
05191 if ( password.length() > 0 )
05192 SHA1::getHash( password, hash );
05193 doc()->map()->setProtected( hash );
05194 }
05195 else
05196 {
05197 int result = KPasswordDialog::getPassword( passwd, i18n( "Unprotect Document" ) );
05198 if ( result != KPasswordDialog::Accepted )
05199 {
05200 d->actions->protectDoc->setChecked( true );
05201 return;
05202 }
05203
05204 QCString hash( "" );
05205 QString password( passwd );
05206 if ( password.length() > 0 )
05207 SHA1::getHash( password, hash );
05208 if ( !doc()->map()->checkPassword( hash ) )
05209 {
05210 KMessageBox::error( 0, i18n( "Password is incorrect." ) );
05211 d->actions->protectDoc->setChecked( true );
05212 return;
05213 }
05214
05215 doc()->map()->setProtected( QCString() );
05216 }
05217
05218 doc()->setModified( true );
05219 d->adjustWorkbookActions( !mode );
05220 }
05221
05222 void View::toggleProtectSheet( bool mode )
05223 {
05224 if ( !d->activeSheet )
05225 return;
05226
05227 QCString passwd;
05228 if ( mode )
05229 {
05230 int result = KPasswordDialog::getNewPassword( passwd, i18n( "Protect Sheet" ) );
05231 if ( result != KPasswordDialog::Accepted )
05232 {
05233 d->actions->protectSheet->setChecked( false );
05234 return;
05235 }
05236
05237 QCString hash( "" );
05238 QString password( passwd );
05239 if ( password.length() > 0 )
05240 SHA1::getHash( password, hash );
05241
05242 d->activeSheet->setProtected( hash );
05243 }
05244 else
05245 {
05246 int result = KPasswordDialog::getPassword( passwd, i18n( "Unprotect Sheet" ) );
05247 if ( result != KPasswordDialog::Accepted )
05248 {
05249 d->actions->protectSheet->setChecked( true );
05250 return;
05251 }
05252
05253 QCString hash( "" );
05254 QString password( passwd );
05255 if ( password.length() > 0 )
05256 SHA1::getHash( password, hash );
05257
05258 if ( !d->activeSheet->checkPassword( hash ) )
05259 {
05260 KMessageBox::error( 0, i18n( "Password is incorrect." ) );
05261 d->actions->protectSheet->setChecked( true );
05262 return;
05263 }
05264
05265 d->activeSheet->setProtected( QCString() );
05266 }
05267 doc()->setModified( true );
05268 d->adjustActions( !mode );
05269 doc()->emitBeginOperation();
05270
05271 refreshView();
05272 updateEditWidget();
05273 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
05274 }
05275
05276 void View::togglePageBorders( bool mode )
05277 {
05278 if ( !d->activeSheet )
05279 return;
05280
05281 doc()->emitBeginOperation( false );
05282 d->activeSheet->setShowPageBorders( mode );
05283 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
05284 }
05285
05286 void View::viewZoom( const QString & s )
05287 {
05288
05289 int oldZoom = doc()->zoom();
05290
05291 bool ok = false;
05292 QRegExp regexp("(\\d+)");
05293 regexp.search(s);
05294 int newZoom=regexp.cap(1).toInt(&ok);
05295 if ( !ok || newZoom < 10 )
05296 newZoom = oldZoom;
05297 if ( newZoom != oldZoom )
05298 {
05299 d->actions->viewZoom->setZoom( newZoom );
05300
05301 doc()->emitBeginOperation( false );
05302
05303 d->canvas->closeEditor();
05304 setZoom( newZoom, true );
05305
05306 if (activeSheet())
05307 {
05308 QRect r( d->activeSheet->visibleRect( d->canvas ) );
05309 r.setWidth( r.width() + 2 );
05310 doc()->emitEndOperation( r );
05311 }
05312 }
05313 }
05314
05315 void View::setZoom( int zoom, bool )
05316 {
05317 kdDebug() << "---------SetZoom: " << zoom << endl;
05318
05319
05320 doc()->emitBeginOperation( false );
05321
05322 doc()->setZoomAndResolution( zoom, KoGlobal::dpiX(), KoGlobal::dpiY());
05323
05324
05325 Q_ASSERT(d->activeSheet);
05326
05327 if (d->activeSheet)
05328 d->activeSheet->setRegionPaintDirty(QRect(QPoint(0,0), QPoint(KS_colMax, KS_rowMax)));
05329
05330 doc()->refreshInterface();
05331 doc()->emitEndOperation();
05332 }
05333
05334 void View::showStatusBar( bool b )
05335 {
05336 doc()->setShowStatusBar( b );
05337 refreshView();
05338 }
05339
05340 void View::showTabBar( bool b )
05341 {
05342 doc()->setShowTabBar( b );
05343 refreshView();
05344 }
05345
05346 void View::showFormulaBar( bool b )
05347 {
05348 doc()->setShowFormulaBar( b );
05349 refreshView();
05350 }
05351
05352 void View::preference()
05353 {
05354 if ( !d->activeSheet )
05355 return;
05356
05357 PreferenceDialog dlg( this, "Preference" );
05358 if ( dlg.exec() )
05359 {
05360 doc()->emitBeginOperation( false );
05361 d->activeSheet->refreshPreference();
05362 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
05363 }
05364 }
05365
05366 void View::addModifyComment()
05367 {
05368 if ( !d->activeSheet )
05369 return;
05370
05371 CommentDialog dlg( this, "comment",
05372 QPoint( d->canvas->markerColumn(),
05373 d->canvas->markerRow() ) );
05374 if ( dlg.exec() )
05375 updateEditWidget();
05376 }
05377
05378 void View::setSelectionComment( QString comment )
05379 {
05380 if ( d->activeSheet != NULL )
05381 {
05382 doc()->emitBeginOperation( false );
05383
05384 d->activeSheet->setSelectionComment( selectionInfo(), comment.stripWhiteSpace() );
05385 updateEditWidget();
05386
05387 markSelectionAsDirty();
05388 doc()->emitEndOperation();
05389 }
05390 }
05391
05392 void View::editCell()
05393 {
05394 if ( d->canvas->editor() )
05395 return;
05396
05397 d->canvas->createEditor(true);
05398 }
05399
05400 bool View::showSheet(const QString& sheetName) {
05401 Sheet *t=doc()->map()->findSheet(sheetName);
05402 if ( !t )
05403 {
05404 kdDebug(36001) << "Unknown sheet " <<sheetName<< endl;
05405 return false;
05406 }
05407 d->canvas->closeEditor();
05408 setActiveSheet( t );
05409
05410 return true;
05411 }
05412
05413 void View::nextSheet()
05414 {
05415 Sheet * t = doc()->map()->nextSheet( activeSheet() );
05416 if ( !t )
05417 {
05418 kdDebug(36001) << "Unknown sheet " << endl;
05419 return;
05420 }
05421 d->canvas->closeEditor();
05422 setActiveSheet( t );
05423 d->tabBar->setActiveTab( t->sheetName() );
05424 d->tabBar->ensureVisible( t->sheetName() );
05425 }
05426
05427 void View::previousSheet()
05428 {
05429 Sheet * t = doc()->map()->previousSheet( activeSheet() );
05430 if ( !t )
05431 {
05432 kdDebug(36001) << "Unknown sheet " << endl;
05433 return;
05434 }
05435 d->canvas->closeEditor();
05436 setActiveSheet( t );
05437 d->tabBar->setActiveTab( t->sheetName() );
05438 d->tabBar->ensureVisible( t->sheetName() );
05439 }
05440
05441 void View::firstSheet()
05442 {
05443 Sheet *t = doc()->map()->firstSheet();
05444 if ( !t )
05445 {
05446 kdDebug(36001) << "Unknown sheet " << endl;
05447 return;
05448 }
05449 d->canvas->closeEditor();
05450 setActiveSheet( t );
05451 d->tabBar->setActiveTab( t->sheetName() );
05452 d->tabBar->ensureVisible( t->sheetName() );
05453 }
05454
05455 void View::lastSheet()
05456 {
05457 Sheet *t = doc()->map()->lastSheet( );
05458 if ( !t )
05459 {
05460 kdDebug(36001) << "Unknown sheet " << endl;
05461 return;
05462 }
05463 d->canvas->closeEditor();
05464 setActiveSheet( t );
05465 d->tabBar->setActiveTab( t->sheetName() );
05466 d->tabBar->ensureVisible( t->sheetName() );
05467 }
05468
05469 void View::keyPressEvent ( QKeyEvent* _ev )
05470 {
05471
05472 if ( _ev->state() & ( Qt::AltButton | Qt::ControlButton ) )
05473 {
05474 if ( _ev->state() & ( Qt::ControlButton ) )
05475 {
05476 switch( _ev->key() )
05477 {
05478 #ifndef NDEBUG
05479 case Qt::Key_V:
05480 if ( _ev->state() & Qt::ShiftButton )
05481 d->activeSheet->printDebug();
05482 #endif
05483 default:
05484 QWidget::keyPressEvent( _ev );
05485 return;
05486 }
05487 }
05488 QWidget::keyPressEvent( _ev );
05489 }
05490 else
05491 QApplication::sendEvent( d->canvas, _ev );
05492 }
05493
05494 KoDocument * View::hitTest( const QPoint& )
05495 {
05496
05497
05498
05499
05500
05501
05502
05503
05504
05505
05506
05507
05508
05509
05510
05511
05512
05513
05514
05515
05516
05517
05518
05519
05520
05521
05522
05523
05524
05525
05526
05527
05528
05529
05530
05531
05532
05533
05534
05535
05536
05537
05538
05539
05540
05541 return doc();
05542 }
05543
05544 int View::leftBorder() const
05545 {
05546 return int( d->canvas->doc()->zoomItX( YBORDER_WIDTH ) );
05547 }
05548
05549 int View::rightBorder() const
05550 {
05551 return d->vertScrollBar->width();
05552 }
05553
05554 int View::topBorder() const
05555 {
05556 return d->toolWidget->height() + int( d->canvas->doc()->zoomItX( Format::globalRowHeight() + 2 ) );
05557 }
05558
05559 int View::bottomBorder() const
05560 {
05561 return d->horzScrollBar->height();
05562 }
05563
05564 void View::refreshView()
05565 {
05566 kdDebug() << "refreshing view" << endl;
05567
05568 Sheet * sheet = activeSheet();
05569 if ( !sheet )
05570 return;
05571
05572 d->adjustActions( !sheet->isProtected() );
05573 d->actions->viewZoom->setZoom( doc()->zoom() );
05574
05575 bool active = sheet->getShowFormula();
05576 if ( sheet && !sheet->isProtected() )
05577 {
05578 d->actions->alignLeft->setEnabled( !active );
05579 d->actions->alignCenter->setEnabled( !active );
05580 d->actions->alignRight->setEnabled( !active );
05581 }
05582
05583 d->tabBar->setReadOnly( !doc()->isReadWrite() || doc()->map()->isProtected() );
05584
05585 d->toolWidget->setShown( doc()->showFormulaBar() );
05586 d->editWidget->showEditWidget( doc()->showFormulaBar() );
05587 d->hBorderWidget->setShown( doc()->showColumnHeader() );
05588 d->vBorderWidget->setShown( doc()->showRowHeader() );
05589 d->vertScrollBar->setShown( doc()->showVerticalScrollBar() );
05590 d->horzScrollBar->setShown( doc()->showHorizontalScrollBar() );
05591 d->tabBar->setShown( doc()->showTabBar() );
05592 if ( statusBar() ) statusBar()->setShown( doc()->showStatusBar() );
05593
05594 d->canvas->updatePosWidget();
05595
05596 d->hBorderWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
05597 d->hBorderWidget->setMinimumHeight( doc()->zoomItY( Format::globalRowHeight() + 2 ) );
05598 d->vBorderWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding );
05599 d->vBorderWidget->setMinimumWidth( doc()->zoomItX( YBORDER_WIDTH ) );
05600
05601 Sheet::LayoutDirection sheetDir = sheet->layoutDirection();
05602 bool interfaceIsRTL = QApplication::reverseLayout();
05603
05604 kdDebug()<<" sheetDir == Sheet::LeftToRight :"<<( sheetDir == Sheet::LeftToRight )<<endl;
05605 if ((sheetDir == Sheet::LeftToRight && !interfaceIsRTL) ||
05606 (sheetDir == Sheet::RightToLeft && interfaceIsRTL))
05607 {
05608 d->formulaBarLayout->setDirection( QBoxLayout::LeftToRight );
05609 d->viewLayout->setOrigin( QGridLayout::TopLeft );
05610 d->tabScrollBarLayout->setDirection( QBoxLayout::LeftToRight );
05611 d->tabBar->setReverseLayout( interfaceIsRTL );
05612 }
05613 else
05614 {
05615 d->formulaBarLayout->setDirection( QBoxLayout::RightToLeft );
05616 d->viewLayout->setOrigin( QGridLayout::TopRight );
05617 d->tabScrollBarLayout->setDirection( QBoxLayout::RightToLeft );
05618 d->tabBar->setReverseLayout( !interfaceIsRTL );
05619 }
05620 }
05621
05622 void View::resizeEvent( QResizeEvent * )
05623 {
05624 }
05625
05626 void View::popupChildMenu( KoChild* child, const QPoint& )
05627 {
05628 if ( !child )
05629 return;
05630
05631 delete d->popupChild;
05632
05633
05634
05635
05636
05637
05638
05639
05640
05641 }
05642
05643 void View::slotPopupDeleteChild()
05644 {
05645
05646
05647
05648
05649
05650
05651
05652
05653
05654
05655
05656
05657
05658
05659
05660
05661 }
05662
05663 void View::popupColumnMenu( const QPoint & _point )
05664 {
05665 assert( d->activeSheet );
05666
05667 if ( !koDocument()->isReadWrite() )
05668 return;
05669
05670 delete d->popupColumn ;
05671
05672 d->popupColumn = new QPopupMenu( this );
05673
05674 bool isProtected = d->activeSheet->isProtected();
05675
05676 if ( !isProtected )
05677 {
05678 d->actions->cellLayout->plug( d->popupColumn );
05679 d->popupColumn->insertSeparator();
05680 d->actions->cut->plug( d->popupColumn );
05681 }
05682 d->actions->copy->plug( d->popupColumn );
05683 if ( !isProtected )
05684 {
05685 d->actions->paste->plug( d->popupColumn );
05686 d->actions->specialPaste->plug( d->popupColumn );
05687 d->actions->insertCellCopy->plug( d->popupColumn );
05688 d->popupColumn->insertSeparator();
05689 d->actions->defaultFormat->plug( d->popupColumn );
05690
05691 if (!d->selection->isColumnOrRowSelected())
05692 {
05693 d->actions->areaName->plug( d->popupColumn );
05694 }
05695
05696 d->actions->resizeColumn->plug( d->popupColumn );
05697 d->popupColumn->insertItem( i18n("Adjust Column"), this, SLOT(slotPopupAdjustColumn() ) );
05698 d->popupColumn->insertSeparator();
05699 d->actions->insertColumn->plug( d->popupColumn );
05700 d->actions->deleteColumn->plug( d->popupColumn );
05701 d->actions->hideColumn->plug( d->popupColumn );
05702
05703 d->actions->showSelColumns->setEnabled(false);
05704
05705 ColumnFormat* format;
05706
05707 Region::ConstIterator endOfList = d->selection->constEnd();
05708 for (Region::ConstIterator it = d->selection->constBegin(); it != endOfList; ++it)
05709 {
05710 QRect range = (*it)->rect().normalize();
05711 int col;
05712 for (col = range.left(); col < range.right(); ++col)
05713 {
05714 format = activeSheet()->columnFormat(col);
05715
05716 if ( format->isHide() )
05717 {
05718 d->actions->showSelColumns->setEnabled( true );
05719 d->actions->showSelColumns->plug( d->popupColumn );
05720 break;
05721 }
05722 }
05723 if (range.left() > 1 && col == range.right())
05724 {
05725 bool allHidden = true;
05726 for (col = 1; col < range.left(); ++col)
05727 {
05728 format = activeSheet()->columnFormat(col);
05729
05730 allHidden &= format->isHide();
05731 }
05732 if (allHidden)
05733 {
05734 d->actions->showSelColumns->setEnabled( true );
05735 d->actions->showSelColumns->plug( d->popupColumn );
05736 break;
05737 }
05738 }
05739 else
05740 {
05741 break;
05742 }
05743 }
05744 }
05745
05746 QObject::connect( d->popupColumn, SIGNAL(activated( int ) ), this, SLOT( slotActivateTool( int ) ) );
05747
05748 d->popupColumn->popup( _point );
05749 }
05750
05751 void View::slotPopupAdjustColumn()
05752 {
05753 if ( !d->activeSheet )
05754 return;
05755
05756 d->activeSheet->adjustColumn(*selectionInfo());
05757 }
05758
05759 void View::popupRowMenu( const QPoint & _point )
05760 {
05761 assert( d->activeSheet );
05762
05763 if ( !koDocument()->isReadWrite() )
05764 return;
05765
05766 delete d->popupRow ;
05767
05768 d->popupRow= new QPopupMenu();
05769
05770 bool isProtected = d->activeSheet->isProtected();
05771
05772 if ( !isProtected )
05773 {
05774 d->actions->cellLayout->plug( d->popupRow );
05775 d->popupRow->insertSeparator();
05776 d->actions->cut->plug( d->popupRow );
05777 }
05778 d->actions->copy->plug( d->popupRow );
05779 if ( !isProtected )
05780 {
05781 d->actions->paste->plug( d->popupRow );
05782 d->actions->specialPaste->plug( d->popupRow );
05783 d->actions->insertCellCopy->plug( d->popupRow );
05784 d->popupRow->insertSeparator();
05785 d->actions->defaultFormat->plug( d->popupRow );
05786
05787 if (!d->selection->isColumnOrRowSelected())
05788 {
05789 d->actions->areaName->plug(d->popupRow);
05790 }
05791
05792 d->actions->resizeRow->plug( d->popupRow );
05793 d->popupRow->insertItem( i18n("Adjust Row"), this, SLOT( slotPopupAdjustRow() ) );
05794 d->popupRow->insertSeparator();
05795 d->actions->insertRow->plug( d->popupRow );
05796 d->actions->deleteRow->plug( d->popupRow );
05797 d->actions->hideRow->plug( d->popupRow );
05798
05799 d->actions->showSelColumns->setEnabled(false);
05800
05801 RowFormat* format;
05802 Region::ConstIterator endOfList = d->selection->constEnd();
05803 for (Region::ConstIterator it = d->selection->constBegin(); it != endOfList; ++it)
05804 {
05805 QRect range = (*it)->rect().normalize();
05806 int row;
05807 for (row = range.top(); row < range.bottom(); ++row)
05808 {
05809 format = activeSheet()->rowFormat(row);
05810
05811 if ( format->isHide() )
05812 {
05813 d->actions->showSelRows->setEnabled( true );
05814 d->actions->showSelRows->plug( d->popupRow );
05815 break;
05816 }
05817 }
05818 if (range.top() > 1 && row == range.bottom())
05819 {
05820 bool allHidden = true;
05821 for (row = 1; row < range.top(); ++row)
05822 {
05823 format = activeSheet()->rowFormat(row);
05824
05825 allHidden &= format->isHide();
05826 }
05827 if (allHidden)
05828 {
05829 d->actions->showSelRows->setEnabled( true );
05830 d->actions->showSelRows->plug( d->popupRow );
05831 break;
05832 }
05833 }
05834 else
05835 {
05836 break;
05837 }
05838 }
05839 }
05840
05841 QObject::connect( d->popupRow, SIGNAL( activated( int ) ), this, SLOT( slotActivateTool( int ) ) );
05842 d->popupRow->popup( _point );
05843 }
05844
05845 void View::slotPopupAdjustRow()
05846 {
05847 if ( !d->activeSheet )
05848 return;
05849
05850 d->activeSheet->adjustRow(*selectionInfo());
05851 }
05852
05853
05854 void View::slotListChoosePopupMenu( )
05855 {
05856 if ( !koDocument()->isReadWrite() )
05857 return;
05858
05859 assert( d->activeSheet );
05860 delete d->popupListChoose;
05861
05862 d->popupListChoose = new QPopupMenu();
05863 int id = 0;
05864 QRect selection( d->selection->selection() );
05865 Cell * cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
05866 QString tmp = cell->text();
05867 QStringList itemList;
05868
05869 for ( int col = selection.left(); col <= selection.right(); ++col )
05870 {
05871 Cell * c = d->activeSheet->getFirstCellColumn( col );
05872 while ( c )
05873 {
05874 if ( !c->isPartOfMerged()
05875 && !( col == d->canvas->markerColumn()
05876 && c->row() == d->canvas->markerRow()) )
05877 {
05878 if ( c->value().isString() && c->text() != tmp && !c->text().isEmpty() )
05879 {
05880 if ( itemList.findIndex( c->text() ) == -1 )
05881 itemList.append(c->text());
05882 }
05883 }
05884
05885 c = d->activeSheet->getNextCellDown( col, c->row() );
05886 }
05887 }
05888
05889
05890
05891
05892
05893
05894
05895
05896
05897
05898
05899
05900
05901
05902
05903
05904
05905
05906 for ( QStringList::Iterator it = itemList.begin(); it != itemList.end();++it )
05907 d->popupListChoose->insertItem( (*it), id++ );
05908
05909 if ( id == 0 )
05910 return;
05911 RowFormat * rl = d->activeSheet->rowFormat( d->canvas->markerRow());
05912 double tx = d->activeSheet->dblColumnPos( d->canvas->markerColumn(), d->canvas );
05913 double ty = d->activeSheet->dblRowPos(d->canvas->markerRow(), d->canvas );
05914 double h = rl->dblHeight( d->canvas );
05915 if ( cell->extraYCells() )
05916 h = cell->extraHeight();
05917 ty += h;
05918
05919 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
05920 {
05921 tx = canvasWidget()->width() - tx;
05922 }
05923
05924 QPoint p( (int)tx, (int)ty );
05925 QPoint p2 = d->canvas->mapToGlobal( p );
05926
05927 if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
05928 {
05929 p2.setX( p2.x() - d->popupListChoose->sizeHint().width() + 1 );
05930 }
05931
05932 d->popupListChoose->popup( p2 );
05933 QObject::connect( d->popupListChoose, SIGNAL( activated( int ) ),
05934 this, SLOT( slotItemSelected( int ) ) );
05935 }
05936
05937
05938 void View::slotItemSelected( int id )
05939 {
05940 QString tmp = d->popupListChoose->text( id );
05941 int x = d->canvas->markerColumn();
05942 int y = d->canvas->markerRow();
05943 Cell * cell = d->activeSheet->nonDefaultCell( x, y );
05944
05945 if ( tmp == cell->text() )
05946 return;
05947
05948 doc()->emitBeginOperation( false );
05949
05950 if ( !doc()->undoLocked() )
05951 {
05952 UndoSetText* undo = new UndoSetText( doc(), d->activeSheet, cell->text(),
05953 x, y, cell->formatType() );
05954 doc()->addCommand( undo );
05955 }
05956
05957 cell->setCellText( tmp );
05958 d->editWidget->setText( tmp );
05959
05960 doc()->emitEndOperation( QRect( x, y, 1, 1 ) );
05961 }
05962
05963 void View::openPopupMenu( const QPoint & _point )
05964 {
05965 assert( d->activeSheet );
05966 delete d->popupMenu;
05967
05968 if ( !koDocument()->isReadWrite() )
05969 return;
05970
05971 d->popupMenu = new QPopupMenu();
05972
05973 EmbeddedObject *obj;
05974 if ( d->canvas->isObjectSelected() && ( obj = d->canvas->getObject( d->canvas->mapFromGlobal( _point ), d->activeSheet ) ) && obj->isSelected() )
05975 {
05976 d->actions->deleteCell->plug( d->popupMenu );
05977 d->popupMenu->insertSeparator();
05978 d->actions->cut->plug( d->popupMenu );
05979 d->actions->copy->plug( d->popupMenu );
05980 d->actions->paste->plug( d->popupMenu );
05981 d->popupMenu->popup( _point );
05982 d->popupMenu->insertSeparator();
05983 d->actions->actionExtraProperties->plug( d->popupMenu );
05984 return;
05985 }
05986
05987 Cell * cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
05988
05989 bool isProtected = d->activeSheet->isProtected();
05990 if ( !cell->isDefault() && cell->format()->notProtected( d->canvas->markerColumn(), d->canvas->markerRow() )
05991 && d->selection->isSingular() )
05992 isProtected = false;
05993
05994 if ( !isProtected )
05995 {
05996 d->actions->cellLayout->plug( d->popupMenu );
05997 d->popupMenu->insertSeparator();
05998 d->actions->cut->plug( d->popupMenu );
05999 }
06000 d->actions->copy->plug( d->popupMenu );
06001 if ( !isProtected )
06002 d->actions->paste->plug( d->popupMenu );
06003
06004 if ( !isProtected )
06005 {
06006 d->actions->specialPaste->plug( d->popupMenu );
06007 d->actions->insertCellCopy->plug( d->popupMenu );
06008 d->popupMenu->insertSeparator();
06009 d->actions->deleteCell->plug( d->popupMenu );
06010 d->actions->adjust->plug( d->popupMenu );
06011 d->actions->defaultFormat->plug( d->popupMenu );
06012
06013
06014 if (!d->selection->isColumnOrRowSelected())
06015 {
06016 d->actions->areaName->plug( d->popupMenu );
06017 d->popupMenu->insertSeparator();
06018 d->actions->insertCell->plug( d->popupMenu );
06019 d->actions->removeCell->plug( d->popupMenu );
06020 }
06021
06022 d->popupMenu->insertSeparator();
06023 d->actions->addModifyComment->plug( d->popupMenu );
06024 if ( !cell->format()->comment(d->canvas->markerColumn(), d->canvas->markerRow()).isEmpty() )
06025 {
06026 d->actions->removeComment->plug( d->popupMenu );
06027 }
06028
06029 if (activeSheet()->testListChoose(selectionInfo()))
06030 {
06031 d->popupMenu->insertSeparator();
06032 d->popupMenu->insertItem( i18n("Selection List..."), this, SLOT( slotListChoosePopupMenu() ) );
06033 }
06034 }
06035
06036
06037 d->toolList.clear();
06038 d->toolList.setAutoDelete( true );
06039
06040 if ( !isProtected && !activeSheet()->getWordSpelling( selectionInfo() ).isEmpty() )
06041 {
06042 d->popupMenuFirstToolId = 10;
06043 int i = 0;
06044 QValueList<KDataToolInfo> tools = KDataToolInfo::query( "QString", "text/plain", doc()->instance() );
06045 if ( tools.count() > 0 )
06046 {
06047 d->popupMenu->insertSeparator();
06048 QValueList<KDataToolInfo>::Iterator entry = tools.begin();
06049 for( ; entry != tools.end(); ++entry )
06050 {
06051 QStringList lst = (*entry).userCommands();
06052 QStringList::ConstIterator it = lst.begin();
06053
06054
06055 for (; it != lst.end(); ++it )
06056 d->popupMenu->insertItem( *it, d->popupMenuFirstToolId + i++ );
06057
06058 lst = (*entry).commands();
06059 it = lst.begin();
06060 for (; it != lst.end(); ++it )
06061 {
06062 Private::ToolEntry *t = new Private::ToolEntry;
06063 t->command = *it;
06064 t->info = *entry;
06065 d->toolList.append( t );
06066 }
06067 }
06068
06069 QObject::connect( d->popupMenu, SIGNAL( activated( int ) ), this, SLOT( slotActivateTool( int ) ) );
06070 }
06071 }
06072
06073 d->popupMenu->popup( _point );
06074 }
06075
06076 void View::slotActivateTool( int _id )
06077 {
06078 if (!activeSheet()) return;
06079
06080
06081 if ( _id < d->popupMenuFirstToolId )
06082 return;
06083
06084 Private::ToolEntry* entry = d->toolList.at( _id - d->popupMenuFirstToolId );
06085
06086 KDataTool* tool = entry->info.createTool();
06087 if ( !tool )
06088 {
06089 kdDebug(36001) << "Could not create Tool" << endl;
06090 return;
06091 }
06092
06093 QString text = activeSheet()->getWordSpelling( selectionInfo() );
06094
06095 if ( tool->run( entry->command, &text, "QString", "text/plain") )
06096 {
06097 doc()->emitBeginOperation(false);
06098
06099 activeSheet()->setWordSpelling( selectionInfo(), text);
06100
06101 Cell *cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
06102 d->editWidget->setText( cell->text() );
06103
06104 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06105 }
06106 }
06107
06108 void View::deleteSelection()
06109 {
06110 if (!activeSheet()) return;
06111
06112 if ( canvasWidget()->isObjectSelected() )
06113 {
06114 deleteSelectedObjects();
06115 return;
06116 }
06117
06118 doc()->emitBeginOperation( false );
06119 d->activeSheet->deleteSelection( selectionInfo() );
06120 calcStatusBarOp();
06121 updateEditWidget();
06122
06123 markSelectionAsDirty();
06124 doc()->emitEndOperation();
06125 }
06126
06127 void View::deleteSelectedObjects()
06128 {
06129 KMacroCommand * macroCommand = 0L;
06130 QPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
06131 for ( ; it.current() ; ++it )
06132 {
06133 if ( it.current()->sheet() == canvasWidget()->activeSheet() && it.current()->isSelected() )
06134 {
06135
06136 if( !macroCommand )
06137 macroCommand = new KMacroCommand( i18n( "Remove Object" ) );
06138 RemoveObjectCommand *cmd = new RemoveObjectCommand( it.current() );
06139 macroCommand->addCommand( cmd );
06140 }
06141 }
06142 if ( macroCommand )
06143 {
06144 doc()->addCommand( macroCommand );
06145 canvasWidget()->setMouseSelectedObject( false );
06146 macroCommand->execute();
06147 }
06148 }
06149
06150 void View::adjust()
06151 {
06152 if ( !d->activeSheet )
06153 return;
06154
06155 d->activeSheet->adjustArea(*selectionInfo());
06156 }
06157
06158 void View::clearTextSelection()
06159 {
06160 if (!activeSheet())
06161 return;
06162
06163 doc()->emitBeginOperation( false );
06164 d->activeSheet->clearTextSelection( selectionInfo() );
06165
06166 updateEditWidget();
06167
06168 markSelectionAsDirty();
06169 doc()->emitEndOperation();
06170 }
06171
06172 void View::clearCommentSelection()
06173 {
06174 if (!activeSheet())
06175 return;
06176
06177 doc()->emitBeginOperation( false );
06178 d->activeSheet->setSelectionRemoveComment( selectionInfo() );
06179
06180 updateEditWidget();
06181
06182 markSelectionAsDirty();
06183 doc()->emitEndOperation();
06184 }
06185
06186 void View::clearValiditySelection()
06187 {
06188 if (!activeSheet())
06189 return;
06190
06191 doc()->emitBeginOperation( false );
06192 d->activeSheet->clearValiditySelection( selectionInfo() );
06193
06194 updateEditWidget();
06195
06196 markSelectionAsDirty();
06197 doc()->emitEndOperation();
06198 }
06199
06200 void View::clearConditionalSelection()
06201 {
06202 if (!activeSheet())
06203 return;
06204
06205 doc()->emitBeginOperation( false );
06206 d->activeSheet->clearConditionalSelection( selectionInfo() );
06207
06208 updateEditWidget();
06209
06210 markSelectionAsDirty();
06211 doc()->emitEndOperation();
06212 }
06213
06214 void View::fillRight()
06215 {
06216 if (!activeSheet())
06217 return;
06218
06219 doc()->emitBeginOperation( false );
06220 d->activeSheet->fillSelection( selectionInfo(), Sheet::Right );
06221
06222 markSelectionAsDirty();
06223 doc()->emitEndOperation();
06224 }
06225
06226 void View::fillLeft()
06227 {
06228 if (!activeSheet())
06229 return;
06230
06231 doc()->emitBeginOperation( false );
06232 d->activeSheet->fillSelection( selectionInfo(), Sheet::Left );
06233
06234 markSelectionAsDirty();
06235 doc()->emitEndOperation();
06236 }
06237
06238 void View::fillUp()
06239 {
06240 if (!activeSheet())
06241 return;
06242
06243 doc()->emitBeginOperation( false );
06244 d->activeSheet->fillSelection( selectionInfo(), Sheet::Up );
06245
06246 markSelectionAsDirty();
06247 doc()->emitEndOperation();
06248 }
06249
06250 void View::fillDown()
06251 {
06252 if (!activeSheet())
06253 return;
06254
06255 doc()->emitBeginOperation( false );
06256 d->activeSheet->fillSelection( selectionInfo(), Sheet::Down );
06257
06258 markSelectionAsDirty();
06259 doc()->emitEndOperation();
06260 }
06261
06262 void View::defaultSelection()
06263 {
06264 if (!activeSheet())
06265 return;
06266
06267 doc()->emitBeginOperation( false );
06268 d->activeSheet->defaultSelection( selectionInfo() );
06269
06270 updateEditWidget();
06271
06272 markSelectionAsDirty();
06273 doc()->emitEndOperation();
06274 }
06275
06276 void View::slotInsert()
06277 {
06278 QRect r( d->selection->selection() );
06279 InsertDialog dlg( this, "InsertDialog", r, InsertDialog::Insert );
06280 dlg.exec();
06281 }
06282
06283 void View::slotRemove()
06284 {
06285 QRect r( d->selection->selection() );
06286 InsertDialog dlg( this, "Remove", r, InsertDialog::Remove );
06287 dlg.exec();
06288 }
06289
06290 void View::slotInsertCellCopy()
06291 {
06292 if ( !d->activeSheet )
06293 return;
06294
06295 if ( !d->activeSheet->testAreaPasteInsert() )
06296 {
06297 doc()->emitBeginOperation( false );
06298 d->activeSheet->paste( d->selection->lastRange(), true,
06299 Paste::Normal, Paste::OverWrite, true );
06300 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06301 }
06302 else
06303 {
06304 PasteInsertDialog dlg( this, "Remove", d->selection->selection() );
06305 dlg.exec();
06306 }
06307
06308 if ( d->activeSheet->getAutoCalc() )
06309 {
06310 doc()->emitBeginOperation( false );
06311 d->activeSheet->recalc();
06312 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06313 }
06314 updateEditWidget();
06315 }
06316
06317 void View::setAreaName()
06318 {
06319 AreaDialog dlg( this, "Area Name",QPoint(d->canvas->markerColumn(), d->canvas->markerRow()) );
06320 dlg.exec();
06321 }
06322
06323 void View::showAreaName()
06324 {
06325 reference dlg( this, "Show Area" );
06326 dlg.exec();
06327 }
06328
06329 void View::resizeRow()
06330 {
06331 if (!activeSheet()) return;
06332
06333 if ( d->selection->isColumnSelected() )
06334 KMessageBox::error( this, i18n("Area is too large."));
06335 else
06336 {
06337 ResizeRow dlg( this );
06338 dlg.exec();
06339 }
06340 }
06341
06342 void View::resizeColumn()
06343 {
06344 if (!activeSheet()) return;
06345
06346
06347 if ( d->selection->isRowSelected() )
06348 KMessageBox::error( this, i18n( "Area is too large." ) );
06349 else
06350 {
06351 ResizeColumn dlg( this );
06352 dlg.exec();
06353 }
06354 }
06355
06356 void View::equalizeRow()
06357 {
06358 if (!activeSheet()) return;
06359
06360 if ( d->selection->isColumnSelected() )
06361 KMessageBox::error( this, i18n( "Area is too large." ) );
06362 else
06363 {
06364 doc()->emitBeginOperation( false );
06365 canvasWidget()->equalizeRow();
06366 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06367 }
06368 }
06369
06370 void View::equalizeColumn()
06371 {
06372 if (!activeSheet())
06373 return;
06374
06375 if ( d->selection->isRowSelected() )
06376 KMessageBox::error( this, i18n( "Area is too large." ) );
06377 else
06378 {
06379 doc()->emitBeginOperation( false );
06380 canvasWidget()->equalizeColumn();
06381 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06382 }
06383 }
06384
06385
06386 void View::layoutDlg()
06387 {
06388 if (!activeSheet())
06389 return;
06390
06391 CellFormatDialog dlg( this, d->activeSheet );
06392 }
06393
06394 void View::extraProperties()
06395 {
06396 if (!activeSheet())
06397 return;
06398
06399
06400 d->m_propertyEditor = new PropertyEditor( this, "KPrPropertyEditor", d->activeSheet, doc() );
06401 d->m_propertyEditor->setCaption( i18n( "Properties" ) );
06402
06403 connect( d->m_propertyEditor, SIGNAL( propertiesOk() ), this, SLOT( propertiesOk() ) );
06404 d->m_propertyEditor->exec();
06405 disconnect( d->m_propertyEditor, SIGNAL( propertiesOk() ), this, SLOT( propertiesOk() ) );
06406
06407 delete d->m_propertyEditor;
06408 d->m_propertyEditor = 0;
06409 }
06410
06411 void View::propertiesOk()
06412 {
06413 KCommand *cmd = d->m_propertyEditor->getCommand();
06414
06415 if ( cmd )
06416 {
06417 cmd->execute();
06418 doc()->addCommand( cmd );
06419 }
06420 }
06421
06422 void View::styleDialog()
06423 {
06424 StyleDlg dlg( this, doc()->styleManager() );
06425 dlg.exec();
06426
06427 d->actions->selectStyle->setItems( doc()->styleManager()->styleNames() );
06428 if ( d->activeSheet )
06429 {
06430 d->activeSheet->setLayoutDirtyFlag();
06431 d->activeSheet->setRegionPaintDirty( d->activeSheet->visibleRect( d->canvas ) );
06432 }
06433 if ( d->canvas )
06434 d->canvas->repaint();
06435 }
06436
06437 void View::paperLayoutDlg()
06438 {
06439 if ( d->canvas->editor() )
06440 {
06441 d->canvas->deleteEditor( true );
06442 }
06443 SheetPrint* print = d->activeSheet->print();
06444
06445 KoPageLayout pl;
06446 pl.format = print->paperFormat();
06447 pl.orientation = print->orientation();
06448
06449 pl.ptWidth = MM_TO_POINT( print->paperWidth() );
06450 pl.ptHeight = MM_TO_POINT( print->paperHeight() );
06451 pl.ptLeft = MM_TO_POINT( print->leftBorder() );
06452 pl.ptRight = MM_TO_POINT( print->rightBorder() );
06453 pl.ptTop = MM_TO_POINT( print->topBorder() );
06454 pl.ptBottom = MM_TO_POINT( print->bottomBorder() );
06455
06456 KoHeadFoot hf;
06457 hf.headLeft = print->localizeHeadFootLine( print->headLeft() );
06458 hf.headRight = print->localizeHeadFootLine( print->headRight() );
06459 hf.headMid = print->localizeHeadFootLine( print->headMid() );
06460 hf.footLeft = print->localizeHeadFootLine( print->footLeft() );
06461 hf.footRight = print->localizeHeadFootLine( print->footRight() );
06462 hf.footMid = print->localizeHeadFootLine( print->footMid() );
06463
06464 KoUnit::Unit unit = doc()->unit();
06465
06466 PaperLayout * dlg
06467 = new PaperLayout( this, "PageLayout", pl, hf,
06468 FORMAT_AND_BORDERS | HEADER_AND_FOOTER,
06469 unit, d->activeSheet, this );
06470 dlg->show();
06471
06472 }
06473
06474 void View::definePrintRange()
06475 {
06476 d->activeSheet->print()->definePrintRange( selectionInfo() );
06477 }
06478
06479 void View::resetPrintRange()
06480 {
06481 d->activeSheet->print()->resetPrintRange();
06482 }
06483
06484 void View::wrapText( bool b )
06485 {
06486 if ( d->toolbarLock )
06487 return;
06488
06489 if ( d->activeSheet != 0L )
06490 {
06491 doc()->emitBeginOperation( false );
06492 d->activeSheet->setSelectionMultiRow( selectionInfo(), b );
06493 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06494 }
06495 }
06496
06497 void View::alignLeft( bool b )
06498 {
06499 if ( d->toolbarLock )
06500 return;
06501
06502 if ( d->activeSheet != 0L )
06503 {
06504 doc()->emitBeginOperation( false );
06505 if ( !b )
06506 d->activeSheet->setSelectionAlign( selectionInfo(),
06507 Format::Undefined );
06508 else
06509 d->activeSheet->setSelectionAlign( selectionInfo(),
06510 Format::Left );
06511
06512 markSelectionAsDirty();
06513 doc()->emitEndOperation();
06514 }
06515 }
06516
06517 void View::alignRight( bool b )
06518 {
06519 if ( d->toolbarLock )
06520 return;
06521
06522 if ( d->activeSheet != 0L )
06523 {
06524 doc()->emitBeginOperation( false );
06525 if ( !b )
06526 d->activeSheet->setSelectionAlign( selectionInfo(), Format::Undefined );
06527 else
06528 d->activeSheet->setSelectionAlign( selectionInfo(), Format::Right );
06529
06530 markSelectionAsDirty();
06531 doc()->emitEndOperation();
06532 }
06533 }
06534
06535 void View::alignCenter( bool b )
06536 {
06537 if ( d->toolbarLock )
06538 return;
06539
06540 if ( d->activeSheet != 0L )
06541 {
06542 doc()->emitBeginOperation( false );
06543 if ( !b )
06544 d->activeSheet->setSelectionAlign( selectionInfo(), Format::Undefined );
06545 else
06546 d->activeSheet->setSelectionAlign( selectionInfo(), Format::Center );
06547
06548 markSelectionAsDirty();
06549 doc()->emitEndOperation();
06550 }
06551 }
06552
06553 void View::alignTop( bool b )
06554 {
06555 if ( d->toolbarLock )
06556 return;
06557
06558 if ( d->activeSheet != 0L )
06559 {
06560 doc()->emitBeginOperation( false );
06561 if ( !b )
06562 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
06563 else
06564 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Top );
06565
06566 markSelectionAsDirty();
06567 doc()->emitEndOperation();
06568 }
06569 }
06570
06571 void View::alignBottom( bool b )
06572 {
06573 if ( d->toolbarLock )
06574 return;
06575
06576 if ( d->activeSheet != 0L )
06577 {
06578 doc()->emitBeginOperation( false );
06579 if ( !b )
06580 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
06581 else
06582 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Bottom );
06583
06584 markSelectionAsDirty();
06585 doc()->emitEndOperation();
06586 }
06587 }
06588
06589 void View::alignMiddle( bool b )
06590 {
06591 if ( d->toolbarLock )
06592 return;
06593
06594 if ( d->activeSheet != 0L )
06595 {
06596 doc()->emitBeginOperation( false );
06597 if ( !b )
06598 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
06599 else
06600 d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Middle );
06601
06602 markSelectionAsDirty();
06603 doc()->emitEndOperation();
06604 }
06605 }
06606
06607 void View::moneyFormat(bool b)
06608 {
06609 if ( d->toolbarLock )
06610 return;
06611
06612 doc()->emitBeginOperation( false );
06613 if ( d->activeSheet != 0L )
06614 d->activeSheet->setSelectionMoneyFormat( selectionInfo(), b );
06615 updateEditWidget();
06616
06617 markSelectionAsDirty();
06618 doc()->emitEndOperation();
06619 }
06620
06621 void View::createStyleFromCell()
06622 {
06623 if ( !d->activeSheet )
06624 return;
06625
06626 QPoint p( d->selection->selection().topLeft() );
06627 Cell * cell = d->activeSheet->nonDefaultCell( p.x(), p.y() );
06628
06629 bool ok = false;
06630 QString styleName( "" );
06631
06632 while( true )
06633 {
06634 styleName = KInputDialog::getText( i18n( "Create Style From Cell" ),
06635 i18n( "Enter name:" ), styleName, &ok, this );
06636
06637 if ( !ok )
06638 return;
06639
06640 styleName = styleName.stripWhiteSpace();
06641
06642 if ( styleName.length() < 1 )
06643 {
06644 KNotifyClient::beep();
06645 KMessageBox::sorry( this, i18n( "The style name cannot be empty." ) );
06646 continue;
06647 }
06648
06649 if ( doc()->styleManager()->style( styleName ) != 0 )
06650 {
06651 KNotifyClient::beep();
06652 KMessageBox::sorry( this, i18n( "A style with this name already exists." ) );
06653 continue;
06654 }
06655 break;
06656 }
06657
06658 CustomStyle * style = new CustomStyle( cell->format()->style(), styleName );
06659
06660 doc()->styleManager()->m_styles[ styleName ] = style;
06661 cell->format()->setStyle( style );
06662 QStringList lst( d->actions->selectStyle->items() );
06663 lst.push_back( styleName );
06664 d->actions->selectStyle->setItems( lst );
06665 }
06666
06667 void View::styleSelected( const QString & style )
06668 {
06669 if (d->activeSheet )
06670 {
06671 Style * s = doc()->styleManager()->style( style );
06672
06673 if ( s )
06674 {
06675 doc()->emitBeginOperation(false);
06676 d->activeSheet->setSelectionStyle( selectionInfo(), s );
06677
06678 markSelectionAsDirty();
06679 doc()->emitEndOperation();
06680 }
06681 }
06682 }
06683
06684 void View::precisionPlus()
06685 {
06686 setSelectionPrecision( 1 );
06687 }
06688
06689 void View::precisionMinus()
06690 {
06691 setSelectionPrecision( -1 );
06692 }
06693
06694 void View::setSelectionPrecision( int delta )
06695 {
06696 if ( d->activeSheet != NULL )
06697 {
06698 doc()->emitBeginOperation( false );
06699 d->activeSheet->setSelectionPrecision( selectionInfo(), delta );
06700
06701 markSelectionAsDirty();
06702 doc()->emitEndOperation();
06703 }
06704 }
06705
06706 void View::percent( bool b )
06707 {
06708 if ( d->toolbarLock )
06709 return;
06710
06711 doc()->emitBeginOperation( false );
06712 if ( d->activeSheet != 0L )
06713 d->activeSheet->setSelectionPercent( selectionInfo() ,b );
06714 updateEditWidget();
06715
06716 markSelectionAsDirty();
06717 doc()->emitEndOperation();
06718 }
06719
06720
06721 void View::insertObject()
06722 {
06723 if (!activeSheet())
06724 return;
06725
06726 doc()->emitBeginOperation( false );
06727 KoDocumentEntry e = d->actions->insertPart->documentEntry();
06728 if ( e.isEmpty() )
06729 {
06730 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06731 return;
06732 }
06733
06734
06735 delete d->insertHandler;
06736
06737 d->insertHandler = new InsertPartHandler( this, d->canvas, e );
06738 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06739 }
06740
06741 void View::insertChart()
06742 {
06743 if (!activeSheet())
06744 return;
06745
06746 if ( d->selection->isColumnOrRowSelected() )
06747 {
06748 KMessageBox::error( this, i18n("Area too large."));
06749 return;
06750 }
06751 QValueList<KoDocumentEntry> vec = KoDocumentEntry::query( true, "'KOfficeChart' in ServiceTypes" );
06752 if ( vec.isEmpty() )
06753 {
06754 KMessageBox::error( this, i18n("No charting component registered.") );
06755 return;
06756 }
06757
06758
06759 delete d->insertHandler;
06760
06761 doc()->emitBeginOperation( false );
06762
06763 d->insertHandler = new InsertChartHandler( this, d->canvas, vec[0] );
06764 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06765 }
06766
06767
06768
06769
06770
06771
06772
06773
06774
06775
06776
06777
06778
06779
06780
06781
06782
06783
06784
06785
06786
06787
06788
06789
06790
06791
06792
06793
06794
06795
06796
06797
06798
06799
06800
06801
06802 void View::removeSheet()
06803 {
06804 if ( doc()->map()->count() <= 1 || ( doc()->map()->visibleSheets().count() <= 1 ) )
06805 {
06806 KNotifyClient::beep();
06807 KMessageBox::sorry( this, i18n("You cannot delete the only sheet."), i18n("Remove Sheet") );
06808 return;
06809 }
06810 KNotifyClient::beep();
06811 int ret = KMessageBox::warningContinueCancel( this, i18n( "You are about to remove the active sheet.\nDo you want to continue?" ),
06812 i18n( "Remove Sheet" ),KGuiItem(i18n("&Delete"),"editdelete") );
06813
06814 if ( ret == KMessageBox::Continue )
06815 {
06816 doc()->emitBeginOperation( false );
06817 if ( d->canvas->editor() )
06818 {
06819 d->canvas->deleteEditor( false );
06820 }
06821 doc()->setModified( true );
06822 Sheet * tbl = activeSheet();
06823 KCommand* command = new RemoveSheetCommand( tbl );
06824 doc()->addCommand( command );
06825 command->execute();
06826
06827
06828 #if 0
06829 UndoRemoveSheet * undo = new UndoRemoveSheet( doc(), tbl );
06830 doc()->addCommand( undo );
06831 tbl->doc()->map()->takeSheet( tbl );
06832 doc()->takeSheet( tbl );
06833 #endif
06834 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06835 }
06836 }
06837
06838
06839 void View::slotRename()
06840 {
06841
06842 Sheet * sheet = activeSheet();
06843
06844 if( sheet->isProtected() )
06845 {
06846 KMessageBox::error( 0, i18n ( "You cannot change a protected sheet." ) );
06847 return;
06848 }
06849
06850 bool ok;
06851 QString activeName = sheet->sheetName();
06852 QString newName = KInputDialog::getText( i18n("Rename Sheet"),i18n("Enter name:"), activeName, &ok, this );
06853
06854 if( !ok ) return;
06855
06856 while (!util_validateSheetName(newName))
06857 {
06858 KNotifyClient::beep();
06859 KMessageBox::information( this, i18n("Sheet name contains illegal characters. Only numbers and letters are allowed."),
06860 i18n("Change Sheet Name") );
06861
06862 newName = newName.simplifyWhiteSpace();
06863 int n = newName.find('-');
06864 if ( n > -1 ) newName[n] = '_';
06865 n = newName.find('!');
06866 if ( n > -1 ) newName[n] = '_';
06867 n = newName.find('$');
06868 if ( n > -1 ) newName[n] = '_';
06869
06870 newName = KInputDialog::getText( i18n("Rename Sheet"),i18n("Enter name:"), newName, &ok, this );
06871
06872 if ( !ok ) return;
06873 }
06874
06875 if ( (newName.stripWhiteSpace()).isEmpty() )
06876 {
06877 KNotifyClient::beep();
06878 KMessageBox::information( this, i18n("Sheet name cannot be empty."), i18n("Change Sheet Name") );
06879
06880 slotRename();
06881 }
06882 else if ( newName != activeName )
06883 {
06884
06885 if ( doc()->map()->findSheet( newName ) )
06886 {
06887 KNotifyClient::beep();
06888 KMessageBox::information( this, i18n("This name is already used."), i18n("Change Sheet Name") );
06889
06890 slotRename();
06891 return;
06892 }
06893
06894 KCommand* command = new RenameSheetCommand( sheet, newName );
06895 doc()->addCommand( command );
06896 command->execute();
06897
06898
06899
06900 doc()->emitBeginOperation(false);
06901 updateEditWidget();
06902 doc()->setModified( true );
06903 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06904 }
06905 }
06906
06907 void View::setText (const QString & _text, bool array)
06908 {
06909 if ( d->activeSheet == 0L )
06910 return;
06911
06912 if (array) {
06913
06914 d->activeSheet->setArrayFormula (d->selection, _text);
06915 }
06916 else
06917 {
06918
06919 int x = d->canvas->markerColumn();
06920 int y = d->canvas->markerRow();
06921
06922 d->activeSheet->setText( y, x, _text );
06923
06924 Cell * cell = d->activeSheet->cellAt( x, y );
06925 if ( cell->value().isString() && !_text.isEmpty() && !_text.at(0).isDigit() && !cell->isFormula() )
06926 doc()->addStringCompletion( _text );
06927 }
06928 }
06929
06930
06931
06932
06933
06934
06935
06936 void View::slotAddSheet( Sheet *_sheet )
06937 {
06938 addSheet( _sheet );
06939 }
06940
06941 void View::slotRefreshView()
06942 {
06943 refreshView();
06944 d->canvas->repaint();
06945 d->vBorderWidget->repaint();
06946 d->hBorderWidget->repaint();
06947 }
06948
06949 void View::slotUpdateView( Sheet *_sheet )
06950 {
06951
06952 if ( ( !activeSheet() ) || ( _sheet != d->activeSheet ) )
06953 return;
06954
06955 d->activeSheet->setRegionPaintDirty( d->activeSheet->visibleRect( d->canvas ) );
06956 doc()->emitEndOperation();
06957 }
06958
06959 void View::slotUpdateView( Sheet * _sheet, const Region& region )
06960 {
06961
06962
06963
06964 if ( _sheet != d->activeSheet )
06965 return;
06966
06967
06968 d->activeSheet->setRegionPaintDirty( region );
06969 doc()->emitEndOperation( region );
06970 }
06971
06972 void View::slotUpdateView( EmbeddedObject *obj )
06973 {
06974 d->canvas->repaintObject( obj );
06975 }
06976
06977 void View::slotUpdateHBorder( Sheet * _sheet )
06978 {
06979
06980
06981
06982 if ( _sheet != d->activeSheet )
06983 return;
06984
06985 doc()->emitBeginOperation(false);
06986 d->hBorderWidget->update();
06987 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
06988 }
06989
06990 void View::slotUpdateVBorder( Sheet *_sheet )
06991 {
06992
06993
06994
06995 if ( _sheet != d->activeSheet )
06996 return;
06997
06998 doc()->emitBeginOperation( false );
06999 d->vBorderWidget->update();
07000 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
07001 }
07002
07003 void View::slotChangeSelection(const KSpread::Region& changedRegion)
07004 {
07005
07006
07007 if (!changedRegion.isValid())
07008 {
07009 return;
07010 }
07011
07012 doc()->emitBeginOperation( false );
07013
07014 bool colSelected = d->selection->isColumnSelected();
07015 bool rowSelected = d->selection->isRowSelected();
07016 if (d->activeSheet && !d->activeSheet->isProtected())
07017 {
07018
07019 d->actions->resizeRow->setEnabled( !colSelected );
07020 d->actions->equalizeRow->setEnabled( !colSelected );
07021 d->actions->hideRow->setEnabled( !colSelected );
07022 d->actions->validity->setEnabled( !colSelected && !rowSelected);
07023 d->actions->conditional->setEnabled( !colSelected && !rowSelected);
07024 d->actions->resizeColumn->setEnabled( !rowSelected );
07025 d->actions->equalizeColumn->setEnabled( !rowSelected );
07026 d->actions->hideColumn->setEnabled( !rowSelected );
07027 d->actions->textToColumns->setEnabled( !rowSelected );
07028
07029 bool simpleSelection = d->selection->isSingular() || colSelected || rowSelected;
07030 d->actions->autoFormat->setEnabled( !simpleSelection );
07031 d->actions->sort->setEnabled( !simpleSelection );
07032 d->actions->mergeCell->setEnabled( !simpleSelection );
07033 d->actions->mergeCellHorizontal->setEnabled( !simpleSelection );
07034 d->actions->mergeCellVertical->setEnabled( !simpleSelection );
07035 d->actions->fillRight->setEnabled( !simpleSelection );
07036 d->actions->fillUp->setEnabled( !simpleSelection );
07037 d->actions->fillDown->setEnabled( !simpleSelection );
07038 d->actions->fillLeft->setEnabled( !simpleSelection );
07039 d->actions->sortDec->setEnabled( !simpleSelection );
07040 d->actions->sortInc->setEnabled( !simpleSelection);
07041 d->actions->createStyle->setEnabled( simpleSelection );
07042
07043 bool contiguousSelection = d->selection->isContiguous();
07044 d->actions->subTotals->setEnabled(contiguousSelection);
07045 }
07046 d->actions->selectStyle->setCurrentItem( -1 );
07047
07048 d->statusBarOpTimer.start(250, true);
07049
07050
07051
07052
07053
07054 d->canvas->setSelectionChangePaintDirty( d->activeSheet, changedRegion );
07055 d->vBorderWidget->update();
07056 d->hBorderWidget->update();
07057
07058 if (colSelected || rowSelected)
07059 {
07060 doc()->emitEndOperation();
07061 return;
07062 }
07063
07064 d->canvas->validateSelection();
07065
07066
07067
07068
07069
07070 if (!activeChild())
07071 d->canvas->scrollToCell(selectionInfo()->marker());
07072
07073
07074
07075 if ( !d->canvas->editor() && !d->canvas->chooseMode() )
07076 {
07077 updateEditWidgetOnPress();
07078 }
07079 d->canvas->updatePosWidget();
07080
07081 doc()->emitEndOperation();
07082 }
07083
07084 void View::slotChangeChoice(const KSpread::Region& changedRegion)
07085 {
07086 if (!changedRegion.isValid())
07087 {
07088 return;
07089 }
07090 doc()->emitBeginOperation( false );
07091 d->canvas->updateEditor();
07092 d->canvas->setSelectionChangePaintDirty( d->activeSheet, changedRegion );
07093 d->canvas->scrollToCell(choice()->marker());
07094 doc()->emitEndOperation( *choice() );
07095 kdDebug() << "Choice: " << *choice() << endl;
07096 }
07097
07098 void View::calcStatusBarOp()
07099 {
07100 Sheet * sheet = activeSheet();
07101 ValueCalc* calc = d->doc->calc();
07102 Value val;
07103 QRect tmpRect(d->selection->selection());
07104 MethodOfCalc tmpMethod = doc()->getTypeOfCalc();
07105 if ( tmpMethod != NoneCalc )
07106 {
07107
07108 Value range = sheet->valueRange (tmpRect.left(), tmpRect.top(),
07109 tmpRect.right(), tmpRect.bottom());
07110 switch (tmpMethod)
07111 {
07112 case SumOfNumber:
07113 val = calc->sum (range);
07114 break;
07115 case Average:
07116 val = calc->avg (range);
07117 break;
07118 case Min:
07119 val = calc->min (range);
07120 break;
07121 case Max:
07122 val = calc->max (range);
07123 break;
07124 case CountA:
07125 val = Value (calc->count (range));
07126 break;
07127 case Count:
07128 val = Value (calc->count (range, false));
07129 case NoneCalc:
07130 break;
07131 default:
07132 break;
07133 }
07134
07135 }
07136
07137 QString res = d->doc->converter()->asString (val).asString ();
07138 QString tmp;
07139 switch(tmpMethod )
07140 {
07141 case SumOfNumber:
07142 tmp = i18n("Sum: ") + res;
07143 break;
07144 case Average:
07145 tmp = i18n("Average: ") + res;
07146 break;
07147 case Min:
07148 tmp = i18n("Min: ") + res;
07149 break;
07150 case Max:
07151 tmp = i18n("Max: ") + res;
07152 break;
07153 case Count:
07154 tmp = i18n("Count: ") + res;
07155 break;
07156 case CountA:
07157 tmp = i18n("CountA: ") + res;
07158 break;
07159 case NoneCalc:
07160 tmp = "";
07161 break;
07162 }
07163
07164
07165 if ( d->calcLabel )
07166 d->calcLabel->setText(QString(" ") + tmp + ' ');
07167
07168 }
07169
07170 void View::statusBarClicked(int _id)
07171 {
07172 if ( !koDocument()->isReadWrite() || !factory() )
07173 return;
07174 if ( _id == 0 )
07175 {
07176 QPoint mousepos = QCursor::pos();
07177 ((QPopupMenu*)factory()->container( "calc_popup" , this ) )->popup( mousepos );
07178 }
07179 }
07180
07181 void View::menuCalc( bool )
07182 {
07183 doc()->emitBeginOperation(false);
07184 if ( d->actions->calcMin->isChecked() )
07185 {
07186 doc()->setTypeOfCalc( Min );
07187 }
07188 else if ( d->actions->calcMax->isChecked() )
07189 {
07190 doc()->setTypeOfCalc( Max );
07191 }
07192 else if ( d->actions->calcCount->isChecked() )
07193 {
07194 doc()->setTypeOfCalc( Count );
07195 }
07196 else if ( d->actions->calcAverage->isChecked() )
07197 {
07198 doc()->setTypeOfCalc( Average );
07199 }
07200 else if ( d->actions->calcSum->isChecked() )
07201 {
07202 doc()->setTypeOfCalc( SumOfNumber );
07203 }
07204 else if ( d->actions->calcCountA->isChecked() )
07205 {
07206 doc()->setTypeOfCalc( CountA );
07207 }
07208 else if ( d->actions->calcNone->isChecked() )
07209 doc()->setTypeOfCalc( NoneCalc );
07210
07211 calcStatusBarOp();
07212
07213 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
07214 }
07215
07216
07217 QWMatrix View::matrix() const
07218 {
07219 QWMatrix m;
07220 m.scale( d->doc->zoomedResolutionX(),
07221 d->doc->zoomedResolutionY() );
07222 m.translate( - d->canvas->xOffset(), - d->canvas->yOffset() );
07223 return m;
07224 }
07225
07226 void View::transformPart()
07227 {
07228 Q_ASSERT( selectedChild() );
07229
07230 if ( d->transformToolBox.isNull() )
07231 {
07232 d->transformToolBox = new KoTransformToolBox( selectedChild(), topLevelWidget() );
07233 d->transformToolBox->show();
07234
07235 d->transformToolBox->setDocumentChild( selectedChild() );
07236 }
07237 else
07238 {
07239 d->transformToolBox->show();
07240 d->transformToolBox->raise();
07241 }
07242 }
07243
07244 void View::slotChildSelected( KoDocumentChild* )
07245 {
07246
07247
07248
07249
07250
07251
07252
07253
07254
07255
07256
07257
07258 doc()->emitBeginOperation( false );
07259 d->activeSheet->setRegionPaintDirty(QRect(QPoint(0,0), QPoint(KS_colMax, KS_rowMax)));
07260
07261 doc()->emitEndOperation();
07262 paintUpdates();
07263 }
07264
07265 void View::slotChildUnselected( KoDocumentChild* )
07266 {
07267
07268
07269
07270
07271
07272
07273
07274
07275
07276
07277
07278
07279 doc()->emitBeginOperation( false );
07280 d->activeSheet->setRegionPaintDirty(QRect(QPoint(0,0), QPoint(KS_colMax, KS_rowMax)));
07281 doc()->emitEndOperation();
07282 paintUpdates();
07283 }
07284
07285
07286 void View::deleteEditor( bool saveChanges )
07287 {
07288 doc()->emitBeginOperation( false );
07289 d->canvas->deleteEditor( saveChanges );
07290
07291 markSelectionAsDirty();
07292 doc()->emitEndOperation();
07293 }
07294
07295 DCOPObject * View::dcopObject()
07296 {
07297 if ( !d->dcop )
07298 d->dcop = new ViewIface( this );
07299
07300 return d->dcop;
07301 }
07302
07303 QWidget * View::canvas() const
07304 {
07305 return canvasWidget();
07306 }
07307
07308 int View::canvasXOffset() const
07309 {
07310 if (!d->activeSheet)
07311 return 0;
07312
07313 double zoomedResX = d->activeSheet->doc()->zoomedResolutionX();
07314 return int( canvasWidget()->xOffset() * zoomedResX );
07315 }
07316
07317 int View::canvasYOffset() const
07318 {
07319 if (!d->activeSheet)
07320 return 0;
07321
07322 double zoomedResY = d->activeSheet->doc()->zoomedResolutionY();
07323 return int( canvasWidget()->yOffset() * zoomedResY );
07324 }
07325
07326
07327 void View::guiActivateEvent( KParts::GUIActivateEvent *ev )
07328 {
07329 if ( d->activeSheet )
07330 {
07331 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
07332
07333 if ( ev->activated() )
07334 {
07335 if ( d->calcLabel )
07336 calcStatusBarOp();
07337 }
07338 else
07339 {
07340
07341
07342
07343
07344 }
07345 }
07346
07347 KoView::guiActivateEvent( ev );
07348 }
07349
07350 void View::popupTabBarMenu( const QPoint & _point )
07351 {
07352 if ( !koDocument()->isReadWrite() || !factory() )
07353 return;
07354 if ( d->tabBar )
07355 {
07356 bool state = ( doc()->map()->visibleSheets().count() > 1 );
07357 if ( d->activeSheet && d->activeSheet->isProtected() )
07358 {
07359 d->actions->removeSheet->setEnabled( false );
07360 d->actions->hideSheet->setEnabled( false );
07361 d->actions->showSheet->setEnabled( false );
07362 }
07363 else
07364 {
07365 d->actions->removeSheet->setEnabled( state);
07366 d->actions->hideSheet->setEnabled( state );
07367 d->actions->showSheet->setEnabled( doc()->map()->hiddenSheets().count()>0 );
07368 }
07369 if ( !doc() || !doc()->map() || doc()->map()->isProtected() )
07370 {
07371 d->actions->insertSheet->setEnabled( false );
07372 d->actions->renameSheet->setEnabled( false );
07373 d->actions->showSheet->setEnabled( false );
07374 d->actions->hideSheet->setEnabled( false );
07375 d->actions->removeSheet->setEnabled( false );
07376 }
07377 static_cast<QPopupMenu*>(factory()->container("menupage_popup",this))->popup(_point);
07378 }
07379 }
07380
07381 void View::updateBorderButton()
07382 {
07383
07384 if ( d->activeSheet )
07385 d->actions->showPageBorders->setChecked( d->activeSheet->isShowPageBorders() );
07386
07387 }
07388
07389 void View::removeSheet( Sheet *_t )
07390 {
07391 doc()->emitBeginOperation(false);
07392 QString m_tablName=_t->sheetName();
07393 d->tabBar->removeTab( m_tablName );
07394 setActiveSheet( doc()->map()->findSheet( doc()->map()->visibleSheets().first() ));
07395
07396 bool state = doc()->map()->visibleSheets().count() > 1;
07397 d->actions->removeSheet->setEnabled( state );
07398 d->actions->hideSheet->setEnabled( state );
07399 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
07400 }
07401
07402 void View::insertSheet( Sheet* sheet )
07403 {
07404 doc()->emitBeginOperation( false );
07405 QString tabName = sheet->sheetName();
07406 if ( !sheet->isHidden() )
07407 {
07408 d->tabBar->addTab( tabName );
07409 }
07410
07411 bool state = ( doc()->map()->visibleSheets().count() > 1 );
07412 d->actions->removeSheet->setEnabled( state );
07413 d->actions->hideSheet->setEnabled( state );
07414 doc()->emitEndOperation( sheet->visibleRect( d->canvas ) );
07415 }
07416
07417 QColor View::borderColor() const
07418 {
07419 return d->actions->borderColor->color();
07420 }
07421
07422 void View::updateShowSheetMenu()
07423 {
07424 doc()->emitBeginOperation( false );
07425 if ( d->activeSheet->isProtected() )
07426 d->actions->showSheet->setEnabled( false );
07427 else
07428 d->actions->showSheet->setEnabled( doc()->map()->hiddenSheets().count() > 0 );
07429 doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
07430 }
07431
07432 void View::closeEditor()
07433 {
07434 if ( d->activeSheet ) {
07435 doc()->emitBeginOperation( false );
07436 d->canvas->closeEditor();
07437
07438 markSelectionAsDirty();
07439 doc()->emitEndOperation();
07440 }
07441 }
07442
07443 void View::markSelectionAsDirty()
07444 {
07445 if (!d->activeSheet)
07446 return;
07447
07448 d->activeSheet->setRegionPaintDirty( *selectionInfo() );
07449 }
07450
07451 void View::paintUpdates()
07452 {
07453
07454
07455
07456 d->canvas->paintUpdates();
07457 }
07458
07459 void View::commandExecuted()
07460 {
07461 updateEditWidget();
07462 calcStatusBarOp();
07463 }
07464
07465 void View::initialiseMarkerFromSheet( Sheet *_sheet, const QPoint &point )
07466 {
07467 d->savedMarkers.replace( _sheet, point);
07468 }
07469
07470 QPoint View::markerFromSheet( Sheet* sheet ) const
07471 {
07472 QMapIterator<Sheet*, QPoint> it = d->savedMarkers.find(sheet);
07473 QPoint newMarker = (it == d->savedMarkers.end()) ? QPoint(1,1) : *it;
07474 return newMarker;
07475 }
07476
07477 KoPoint View::offsetFromSheet( Sheet* sheet ) const
07478 {
07479 QMapIterator<Sheet*, KoPoint> it = d->savedOffsets.find(sheet);
07480 KoPoint offset = (it == d->savedOffsets.end()) ? KoPoint() : *it;
07481 return offset;
07482 }
07483
07484 void View::saveCurrentSheetSelection()
07485 {
07486
07487 if (d->activeSheet != NULL)
07488 {
07489 d->savedAnchors.replace(d->activeSheet, d->selection->anchor());
07490 kdDebug() << " Current scrollbar vert value: " << d->canvas->vertScrollBar()->value() << endl;
07491 kdDebug() << "Saving marker pos: " << d->selection->marker() << endl;
07492 d->savedMarkers.replace(d->activeSheet, d->selection->marker());
07493 d->savedOffsets.replace(d->activeSheet, KoPoint(d->canvas->xOffset(),
07494 d->canvas->yOffset()));
07495 }
07496 }
07497
07498 void View::handleDamages( const QValueList<Damage*>& damages )
07499 {
07500 QValueList<Damage*>::ConstIterator it;
07501 for( it = damages.begin(); it != damages.end(); ++it )
07502 {
07503 Damage* damage = *it;
07504 if( !damage ) continue;
07505
07506 if( damage->type() == Damage::Cell )
07507 {
07508 CellDamage* cd = static_cast<CellDamage*>( damage );
07509 Cell* damagedCell = cd->cell();
07510 Sheet* damagedSheet = damagedCell->sheet();
07511 QRect drect( damagedCell->column(), damagedCell->row(), 1, 1 );
07512 damagedSheet->setRegionPaintDirty( drect );
07513 paintUpdates();
07514 }
07515
07516 if( damage->type() == Damage::Sheet )
07517 {
07518 SheetDamage* sd = static_cast<SheetDamage*>( damage );
07519 Sheet* damagedSheet = sd->sheet();
07520
07521 if( sd->action() == SheetDamage::PropertiesChanged )
07522 {
07523 CellBinding * b = 0;
07524 for ( b = damagedSheet->firstCellBinding(); b != 0;
07525 b = damagedSheet->nextCellBinding() )
07526 b->cellChanged( 0 );
07527
07528 d->activeSheet->setRegionPaintDirty( QRect(QPoint(0,0),
07529 QPoint(KS_colMax, KS_rowMax)));
07530
07531 paintUpdates();
07532 refreshView();
07533 }
07534
07535 }
07536
07537 }
07538 }
07539
07540 void View::runInternalTests()
07541 {
07542
07543 KSpread::TestRunner* runner = new KSpread::TestRunner();
07544 runner->exec();
07545 delete runner;
07546 }
07547
07548 void View::runInspector()
07549 {
07550
07551 if(!d->activeSheet) return;
07552 Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
07553 KSpread::Inspector* ins = new KSpread::Inspector( cell );
07554 ins->exec();
07555 delete ins;
07556 }
07557
07558 QColor View::highlightColor()
07559 {
07560 return QApplication::palette().active().highlight().light( 175 );
07561 }
07562
07563 }
07564
07565 #include "kspread_view.moc"