diff --git a/kspread/kspread_view.cc b/kspread/kspread_view.cc index 3fa48ded15..fef3d1b31a 100644 --- a/kspread/kspread_view.cc +++ b/kspread/kspread_view.cc @@ -1,3896 +1,3903 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include // has to be first #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kspread_map.h" #include "kspread_dlg_scripts.h" #include "kspread_dlg_cons.h" #include "kspread_canvas.h" #include "kspread_tabbar.h" #include "kspread_dlg_formula.h" #include "kspread_dlg_special.h" #include "kspread_dlg_sort.h" #include "kspread_dlg_anchor.h" #include "kspread_dlg_layout.h" #include "kspread_dlg_show.h" #include "kspread_dlg_insert.h" #include "kspread_handler.h" #include "kspread_events.h" #include "kspread_editors.h" #include "kspread_dlg_format.h" // #include "kspread_dlg_oszi.h" #include "kspread_dlg_conditional.h" #include "kspread_dlg_series.h" #include "kspread_dlg_reference.h" #include "kspread_dlg_area.h" #include "kspread_dlg_resize2.h" #include "kspread_dlg_preference.h" #include "kspread_dlg_comment.h" #include "kspread_dlg_angle.h" #include "kspread_dlg_goto.h" #include "kspread_dlg_validity.h" #include "kspread_dlg_pasteinsert.h" #include "kspread_dlg_showColRow.h" #include "kspread_dlg_list.h" #include "kspread_undo.h" #include "handler.h" #include "KSpreadViewIface.h" #include #include #include /***************************************************************************** * * KSpreadView * *****************************************************************************/ KSpreadScripts* KSpreadView::m_pGlobalScriptsDialog = 0L; // non flickering version of KSpell. class KSpreadSpell : public KSpell { public: KSpreadSpell(QWidget *parent, const QString &caption, QObject *receiver, const char *slot, KSpellConfig *kcs=0, bool progressbar = FALSE, bool modal = true ) : KSpell(parent, caption, receiver, slot, kcs, progressbar, modal) { } // override check(...) // mostly copied from kdelibs/kspell/kspell.cpp // the dialog gets created but it gets only shown if something // is misspelled. Otherwise for every cell the dialog would pop up // and disappear bool check( const QString &_buffer, bool _usedialog = true ) { QString qs; usedialog=_usedialog; setUpDialog (); //set the dialog signal handler dialog3slot = SLOT (check3 ()); kdDebug(750) << "KS: check" << endl; origbuffer = _buffer; if ( ( totalpos = origbuffer.length() ) == 0 ) { emit done(origbuffer); return FALSE; } // Torben: I corrected the \n\n problem directly in the // origbuffer since I got errors otherwise if ( origbuffer.right(2) != "\n\n" ) { if (origbuffer.at(origbuffer.length() - 1) != '\n') { origbuffer += '\n'; origbuffer += '\n'; //shouldn't these be removed at some point? } else origbuffer += '\n'; } newbuffer = origbuffer; // KProcIO calls check2 when read from ispell connect(proc, SIGNAL (readReady(KProcIO *)), this, SLOT (check2(KProcIO *))); proc->fputs ("!"); //lastpos is a position in newbuffer (it has offset in it) offset = lastlastline = lastpos = lastline = 0; emitProgress (); // send first buffer line int i = origbuffer.find('\n', 0) + 1; qs = origbuffer.mid (0, i); cleanFputs(qs, FALSE); lastline = i; //the character position, not a line number ksdlg->hide(); return TRUE; } // mostly copied from kdelibs/kspell/kspell.cpp void check2 (KProcIO *) { int e, tempe; QString word; QString line; do { tempe = proc->fgets (line); //get ispell's response if (tempe > 0) { - if ((e = parseOneResponse (line, word, sugg)) == 3 // mistake - || e == 2) // replace + e = parseOneResponse(line, word, sugg); + if ( (e == 3) // mistake + || (e == 2) ) // replace { dlgresult =- 1; // for multibyte encoding posinline needs correction if (ksconfig->encoding() == KS_E_UTF8) { // convert line to UTF-8, cut at pos, convert back to UCS-2 // and get string length posinline = (QString::fromUtf8(origbuffer.mid(lastlastline, lastline - lastlastline).utf8(), posinline)).length(); } lastpos = posinline + lastlastline + offset; //orig is set by parseOneResponse() if (e == 2) // replace { dlgreplacement = word; emit corrected (orig, replacement(), lastpos); offset += replacement().length() - orig.length(); newbuffer.replace (lastpos, orig.length(), word); } else //MISTAKE { cwword = word; if ( usedialog ) { // show the word in the dialog ksdlg->show(); dialog (word, sugg, SLOT (check3())); } else { // No dialog, just emit misspelling and continue emit misspelling (word, sugg, lastpos); dlgresult = KS_IGNORE; check3(); } return; } } } emitProgress (); //maybe } while (tempe > 0); proc->ackRead(); if (tempe == -1) //we were called, but no data seems to be ready... return; //If there is more to check, then send another line to ISpell. if ((unsigned int)lastline < origbuffer.length()) { int i; QString qs; lastpos = (lastlastline = lastline) + offset; //do we really want this? i = origbuffer.find('\n', lastline)+1; qs = origbuffer.mid (lastline, i-lastline); cleanFputs (qs, FALSE); lastline = i; return; } else //This is the end of it all { ksdlg->hide(); newbuffer.truncate (newbuffer.length()-2); emitProgress(); emit done (newbuffer); } } }; KSpreadView::KSpreadView( QWidget *_parent, const char *_name, KSpreadDoc* doc ) : KoView( doc, _parent, _name ) { kdDebug(36001) << "sizeof(KSpreadCell)=" << sizeof(KSpreadCell) <setRange( 0, 4096 ); m_pVertScrollBar->setOrientation( QScrollBar::Vertical ); // Horz. Scroll Bar m_pHorzScrollBar = new QScrollBar( this, "ScrollBar_1" ); m_pHorzScrollBar->setRange( 0, 4096 ); m_pHorzScrollBar->setOrientation( QScrollBar::Horizontal ); // Tab Bar m_pTabBarFirst = newIconButton( "tab_first" ); QObject::connect( m_pTabBarFirst, SIGNAL( clicked() ), SLOT( slotScrollToFirstTable() ) ); m_pTabBarLeft = newIconButton( "tab_left" ); QObject::connect( m_pTabBarLeft, SIGNAL( clicked() ), SLOT( slotScrollToLeftTable() ) ); m_pTabBarRight = newIconButton( "tab_right" ); QObject:: connect( m_pTabBarRight, SIGNAL( clicked() ), SLOT( slotScrollToRightTable() ) ); m_pTabBarLast = newIconButton( "tab_last" ); QObject::connect( m_pTabBarLast, SIGNAL( clicked() ), SLOT( slotScrollToLastTable() ) ); m_pTabBar = new KSpreadTabBar( this ); QObject::connect( m_pTabBar, SIGNAL( tabChanged( const QString& ) ), this, SLOT( changeTable( const QString& ) ) ); // Paper and Border widgets m_pFrame = new QWidget( this ); m_pFrame->raise(); // Edit Bar m_pToolWidget = new QFrame( this ); QHBoxLayout* hbox = new QHBoxLayout( m_pToolWidget ); hbox->addSpacing( 2 ); m_pPosWidget = new KSpreadLocationEditWidget( m_pToolWidget, this ); m_pPosWidget->setMinimumWidth( 100 ); hbox->addWidget( m_pPosWidget ); hbox->addSpacing( 6 ); m_pCancelButton = newIconButton( "abort", TRUE, m_pToolWidget ); hbox->addWidget( m_pCancelButton ); m_pOkButton = newIconButton( "done", TRUE, m_pToolWidget ); hbox->addWidget( m_pOkButton ); hbox->addSpacing( 6 ); // The widget on which we display the table m_pCanvas = new KSpreadCanvas( m_pFrame, this, doc ); // The line-editor that appears above the table and allows to // edit the cells content. It knows about the two buttons. m_pEditWidget = new KSpreadEditWidget( m_pToolWidget, m_pCanvas, m_pCancelButton, m_pOkButton ); m_pEditWidget->setFocusPolicy( QWidget::StrongFocus ); hbox->addWidget( m_pEditWidget, 2 ); hbox->addSpacing( 2 ); m_pCanvas->setEditWidget( m_pEditWidget ); m_pHBorderWidget = new KSpreadHBorder( m_pFrame, m_pCanvas,this ); m_pVBorderWidget = new KSpreadVBorder( m_pFrame, m_pCanvas ,this ); m_pCanvas->setFocusPolicy( QWidget::StrongFocus ); QWidget::setFocusPolicy( QWidget::StrongFocus ); setFocusProxy( m_pCanvas ); connect( this, SIGNAL( invalidated() ), m_pCanvas, SLOT( update() ) ); connect( this, SIGNAL( regionInvalidated( const QRegion&, bool ) ), m_pCanvas, SLOT( repaint( const QRegion&, bool ) ) ); QObject::connect( m_pVertScrollBar, SIGNAL( valueChanged(int) ), m_pCanvas, SLOT( slotScrollVert(int) ) ); QObject::connect( m_pHorzScrollBar, SIGNAL( valueChanged(int) ), m_pCanvas, SLOT( slotScrollHorz(int) ) ); KSpreadTable *tbl; for ( tbl = m_pDoc->map()->firstTable(); tbl != 0L; tbl = m_pDoc->map()->nextTable() ) addTable( tbl ); tbl = m_pDoc->map()->initialActiveTable(); if (tbl) setActiveTable(tbl); else //activate first table which is not hiding setActiveTable(m_pDoc->map()->findTable(m_pTabBar->listshow().first())); QObject::connect( m_pDoc, SIGNAL( sig_addTable( KSpreadTable* ) ), SLOT( slotAddTable( KSpreadTable* ) ) ); QObject::connect( m_pDoc, SIGNAL( sig_refreshView( ) ), this, SLOT( slotRefreshView() ) ); QObject::connect( m_pDoc, SIGNAL( sig_refreshLocale() ), this, SLOT( slotRefreshLocale())); // Handler for moving and resizing embedded parts ContainerHandler* h = new ContainerHandler( this, m_pCanvas ); connect( h, SIGNAL( popupMenu( KoChild*, const QPoint& ) ), this, SLOT( popupChildMenu( KoChild*, const QPoint& ) ) ); m_bold = new KToggleAction( i18n("Bold"), "text_bold", CTRL + Key_B, actionCollection(), "bold"); connect( m_bold, SIGNAL( toggled( bool ) ), this, SLOT( bold( bool ) ) ); m_italic = new KToggleAction( i18n("Italic"), "text_italic", CTRL + Key_I, actionCollection(), "italic"); connect( m_italic, SIGNAL( toggled( bool ) ), this, SLOT( italic( bool ) ) ); m_underline = new KToggleAction( i18n("Underline"), "text_under", CTRL + Key_U, actionCollection(), "underline"); connect( m_underline, SIGNAL( toggled( bool ) ), this, SLOT( underline( bool ) ) ); m_strikeOut = new KToggleAction( i18n("Strike out"), "text_strike", 0, actionCollection(), "strikeout"); connect( m_strikeOut, SIGNAL( toggled( bool ) ), this, SLOT( strikeOut( bool ) ) ); m_percent = new KToggleAction( i18n("Percent format"), "percent", 0, actionCollection(), "percent"); connect( m_percent, SIGNAL( toggled( bool ) ), this, SLOT( percent( bool ) ) ); m_precplus = new KAction( i18n("Increase precision"), "prec_plus", 0, this, SLOT( precisionPlus() ), actionCollection(), "precplus"); m_precminus = new KAction( i18n("Decrease precision"), "prec_minus", 0, this, SLOT( precisionMinus() ), actionCollection(), "precminus"); m_money = new KToggleAction( i18n("Money format"), "money", 0, actionCollection(), "money"); connect( m_money, SIGNAL( toggled( bool ) ), this, SLOT( moneyFormat( bool ) ) ); m_alignLeft = new KToggleAction( i18n("Align left"), "text_left", 0, actionCollection(), "left"); connect( m_alignLeft, SIGNAL( toggled( bool ) ), this, SLOT( alignLeft( bool ) ) ); m_alignLeft->setExclusiveGroup( "Align" ); m_alignCenter = new KToggleAction( i18n("Align center"), "text_center", 0, actionCollection(), "center"); connect( m_alignCenter, SIGNAL( toggled( bool ) ), this, SLOT( alignCenter( bool ) ) ); m_alignCenter->setExclusiveGroup( "Align" ); m_alignRight = new KToggleAction( i18n("Align right"), "text_right", 0, actionCollection(), "right"); connect( m_alignRight, SIGNAL( toggled( bool ) ), this, SLOT( alignRight( bool ) ) ); m_alignRight->setExclusiveGroup( "Align" ); m_alignTop = new KToggleAction( i18n("Align top"), "text_top", 0, actionCollection(), "top"); connect( m_alignTop, SIGNAL( toggled( bool ) ), this, SLOT( alignTop( bool ) ) ); m_alignTop->setExclusiveGroup( "Pos" ); m_alignMiddle = new KToggleAction( i18n("Align middle"), "middle", 0, actionCollection(), "middle"); connect( m_alignMiddle, SIGNAL( toggled( bool ) ), this, SLOT( alignMiddle( bool ) ) ); m_alignMiddle->setExclusiveGroup( "Pos" ); m_alignBottom = new KToggleAction( i18n("Align bottom"), "text_bottom", 0, actionCollection(), "bottom"); connect( m_alignBottom, SIGNAL( toggled( bool ) ), this, SLOT( alignBottom( bool ) ) ); m_alignBottom->setExclusiveGroup( "Pos" ); m_transform = new KAction( i18n("Transform object..."), "rotate", 0, this, SLOT( transformPart() ), actionCollection(), "transform" ); m_transform->setEnabled( FALSE ); // ### This seems to be duplicated .... connect( m_transform, SIGNAL( activated() ), this, SLOT( transformPart() ) ); m_copy = KStdAction::copy( this, SLOT( copySelection() ), actionCollection(), "copy" ); m_copy_as_text=new KAction( i18n("Copy as text"),0, this, SLOT( copyAsText() ), actionCollection(), "copy_as_text" ); m_paste = KStdAction::paste( this, SLOT( paste() ), actionCollection(), "paste" ); m_cut = KStdAction::cut( this, SLOT( cutSelection() ), actionCollection(), "cut" ); m_specialPaste = new KAction( i18n("Special Paste..."), "special_paste",0, this, SLOT( specialPaste() ), actionCollection(), "specialPaste" ); m_editCell = new KAction( i18n("Modify Cell"),"cell_edit", CTRL + Key_M, this, SLOT( editCell() ), actionCollection(), "editCell" ); m_delete = new KAction( i18n("Delete"),"deletecell", 0, this, SLOT( deleteSelection() ), actionCollection(), "delete" ); m_clearText = new KAction( i18n("Text"), 0, this, SLOT( clearTextSelection() ), actionCollection(), "cleartext" ); m_clearComment = new KAction( i18n("Comment"), 0, this, SLOT( clearCommentSelection() ), actionCollection(), "clearcomment" ); m_clearValidity = new KAction( i18n("Validity"), 0, this, SLOT( clearValiditySelection() ), actionCollection(), "clearvalidity" ); m_clearConditional = new KAction( i18n("Conditional cell attributes"), 0, this, SLOT( clearConditionalSelection() ), actionCollection(), "clearconditional" ); // ---------------------------- Bernd ----------------------- //Key_Shift .. m_recalc_workbook = new KAction( i18n("Recalculate Workbook"),Key_F9, this, SLOT( RecalcWorkBook() ), actionCollection(), "RecalcWorkBook" ); m_recalc_worksheet = new KAction( i18n("Recalculate Worksheet"),SHIFT + Key_F9, this, SLOT( RecalcWorkSheet() ), actionCollection(), "RecalcWorkSheet" ); // ---------------------------- Bernd ----------------------- m_adjust = new KAction( i18n("Adjust row and column"), 0, this, SLOT( adjust() ), actionCollection(), "adjust" ); m_default = new KAction( i18n("Default"), 0, this, SLOT( defaultSelection() ), actionCollection(), "default" ); m_areaName = new KAction( i18n("Area name..."), 0, this, SLOT( setAreaName() ), actionCollection(), "areaname" ); m_showArea = new KAction( i18n("Show area..."), 0, this, SLOT( showAreaName() ), actionCollection(), "showArea" ); m_resizeRow = new KAction( i18n("Resize row..."), "resizerow", 0, this, SLOT( resizeRow() ), actionCollection(), "resizeRow" ); m_resizeColumn = new KAction( i18n("Resize column..."), "resizecol", 0, this, SLOT( resizeColumn() ), actionCollection(), "resizeCol" ); m_equalizeRow = new KAction( i18n("Equalize row"), "adjustrow", 0, this, SLOT( equalizeRow() ), actionCollection(), "equalizeRow" ); m_equalizeColumn = new KAction( i18n("Equalize column"), "adjustcol", 0, this, SLOT( equalizeColumn() ), actionCollection(), "equalizeCol" ); m_fontSizeUp = new KAction( i18n("Increase font size"), "fontsizeup", 0, this, SLOT( increaseFontSize() ), actionCollection(), "increaseFontSize" ); m_fontSizeDown = new KAction( i18n("Decrease font size"), "fontsizedown", 0, this, SLOT( decreaseFontSize() ), actionCollection(), "decreaseFontSize" ); m_upper = new KAction( i18n("Upper case"), "upper", 0, this, SLOT( upper() ), actionCollection(), "upper" ); m_lower = new KAction( i18n("Lower case"), "lower", 0, this, SLOT( lower() ), actionCollection(), "lower" ); m_gotoCell = new KAction( i18n("Goto Cell..."),"goto", 0, this, SLOT( gotoCell() ), actionCollection(), "gotoCell" ); m_undo = KStdAction::undo( this, SLOT( undo() ), actionCollection(), "undo" ); m_undo->setEnabled( FALSE ); m_redo = KStdAction::redo( this, SLOT( redo() ), actionCollection(), "redo" ); m_redo->setEnabled( FALSE ); m_paperLayout = new KAction( i18n("Paper Layout..."), 0, this, SLOT( paperLayoutDlg() ), actionCollection(), "paperLayout" ); m_sortList = new KAction( i18n("Sort lists..."), 0, this, SLOT( sortList() ), actionCollection(), "sortlist" ); m_insertTable = new KAction( i18n("Insert Table"),"inserttable", 0, this, SLOT( insertTable() ), actionCollection(), "insertTable" ); m_removeTable = new KAction( i18n("Remove Table"), "delete_table",0,this, SLOT( removeTable() ), actionCollection(), "removeTable" ); m_renameTable=new KAction( i18n("Rename table..."),0,this, SLOT( slotRename() ), actionCollection(), "renameTable" ); m_showTable = new KAction(i18n("Show Table"),0 ,this,SLOT( showTable()), actionCollection(), "showTable" ); m_hideTable = new KAction(i18n("Hide Table"),0 ,this,SLOT( hideTable()), actionCollection(), "hideTable" ); m_preference = new KAction( i18n("Configure KSpread..."),"configure", 0, this, SLOT( preference() ), actionCollection(), "preference" ); m_firstLetterUpper = new KAction( i18n("Convert first letter to upper case"),"first_letter_upper" ,0, this, SLOT( firstLetterUpper() ), actionCollection(), "firstletterupper" ); m_verticalText = new KToggleAction( i18n("Vertical text"),"vertical_text" ,0 ,actionCollection(), "verticaltext" ); connect( m_verticalText, SIGNAL( toggled( bool ) ), this, SLOT( verticalText( bool ) ) ); m_changeAngle = new KAction( i18n("Change Angle..."), 0, this, SLOT( changeAngle() ), actionCollection(), "changeangle" ); m_addModifyComment = new KAction( i18n("&Add/modify comment..."),"comment", 0, this, SLOT( addModifyComment() ), actionCollection(), "addmodifycomment" ); m_removeComment = new KAction( i18n("&Remove comment"),"removecomment", 0, this, SLOT( removeComment() ), actionCollection(), "removecomment" ); m_editGlobalScripts = new KAction( i18n("Edit Global Scripts..."), 0, this, SLOT( editGlobalScripts() ), actionCollection(), "editGlobalScripts" ); m_editLocalScripts = new KAction( i18n("Edit Local Scripts..."), 0, this, SLOT( editLocalScripts() ), actionCollection(), "editLocalScripts" ); m_reloadScripts = new KAction( i18n("Reload Scripts"), 0, this, SLOT( reloadScripts() ), actionCollection(), "reloadScripts" ); m_showPageBorders = new KToggleAction( i18n("Show page borders"), 0, actionCollection(), "showPageBorders"); connect( m_showPageBorders, SIGNAL( toggled( bool ) ), this, SLOT( togglePageBorders( bool ) ) ); KStdAction::find(this, SLOT(find()), actionCollection()); KStdAction::replace(this, SLOT(replace()), actionCollection()); m_conditional = new KAction( i18n("Conditional cell attributes..."), 0, this, SLOT( conditional() ), actionCollection(), "conditional" ); m_validity = new KAction( i18n("Validity..."), 0, this, SLOT( validity() ), actionCollection(), "validity" ); m_sort = new KAction( i18n("Sort..."), 0, this, SLOT( sort() ), actionCollection(), "sort" ); m_consolidate = new KAction( i18n("Consolidate..."), 0, this, SLOT( consolidate() ), actionCollection(), "consolidate" ); m_mergeCell = new KAction( i18n("Merge cells"),"mergecell" ,0, this, SLOT( mergeCell() ), actionCollection(), "mergecell" ); m_dissociateCell = new KAction( i18n("Dissociate cells"),"dissociatecell" ,0, this, SLOT( dissociateCell() ), actionCollection(), "dissociatecell" ); m_increaseIndent = new KAction( i18n("Increase indent"),"format_increaseindent" ,0, this, SLOT( increaseIndent() ), actionCollection(), "increaseindent" ); m_decreaseIndent = new KAction( i18n("Decrease indent"),"format_decreaseindent" ,0, this, SLOT( decreaseIndent() ), actionCollection(),"decreaseindent"); m_multiRow = new KToggleAction( i18n("Multi Row"), "multirow", 0, actionCollection(), "multiRow" ); connect( m_multiRow, SIGNAL( toggled( bool ) ), this, SLOT( multiRow( bool ) ) ); m_selectFont = new KFontAction( i18n("Select Font"), 0, actionCollection(), "selectFont" ); connect( m_selectFont, SIGNAL( activated( const QString& ) ), this, SLOT( fontSelected( const QString& ) ) ); m_selectFontSize = new KFontSizeAction( i18n("Select Font Size"), 0, actionCollection(), "selectFontSize" ); connect( m_selectFontSize, SIGNAL( fontSizeChanged( int ) ), this, SLOT( fontSizeSelected( int ) ) ); m_deleteColumn = new KAction( i18n("Delete Column(s)"), "delete_table_col", 0, this, SLOT( deleteColumn() ), actionCollection(), "deleteColumn" ); m_deleteRow = new KAction( i18n("Delete Row(s)"), "delete_table_row", 0, this, SLOT( deleteRow() ), actionCollection(), "deleteRow" ); m_insertColumn = new KAction( i18n("Insert Column(s)"), "insert_table_col" , 0, this, SLOT( insertColumn() ), actionCollection(), "insertColumn" ); m_insertRow = new KAction( i18n("Insert Row(s)"), "insert_table_row", 0, this, SLOT( insertRow() ), actionCollection(), "insertRow" ); m_hideRow = new KAction( i18n("Hide Row(s)"), "hide_table_row", 0, this, SLOT( hideRow() ), actionCollection(), "hideRow" ); m_showRow = new KAction( i18n("Show Row(s)"), "show_table_row", 0, this, SLOT( showRow() ), actionCollection(), "showRow" ); m_showSelRows = new KAction( i18n("Show Row(s)"), "show_table_row", 0, this, SLOT( showSelRows() ), actionCollection(), "showSelRows" ); m_showSelRows->setEnabled(false); m_hideColumn = new KAction( i18n("Hide Column(s)"), "hide_table_column", 0, this, SLOT( hideColumn() ), actionCollection(), "hideColumn" ); m_showColumn = new KAction( i18n("Show Column(s)"), "show_table_column", 0, this, SLOT( showColumn() ), actionCollection(), "showColumn" ); m_showSelColumns = new KAction( i18n("Show Column(s)"), "show_table_column", 0, this, SLOT( showSelColumns() ), actionCollection(), "showSelColumns" ); m_showSelColumns->setEnabled(false); m_insertCell = new KAction( i18n("Insert Cell(s)..."), "insertcell", 0, this, SLOT( slotInsert() ), actionCollection(), "insertCell" ); m_removeCell = new KAction( i18n("Remove Cell(s)..."), "removecell", 0, this, SLOT( slotRemove() ), actionCollection(), "removeCell" ); m_insertCellCopy = new KAction( i18n("Paste with insertion..."), "insertcellcopy", 0, this, SLOT( slotInsertCellCopy() ), actionCollection(), "insertCellCopy" ); m_cellLayout = new KAction( i18n("Cell Format..."),"cell_layout", CTRL + ALT + Key_F, this, SLOT( layoutDlg() ), actionCollection(), "cellLayout" ); m_formulaSelection = new KSelectAction( i18n("Formula Selection"), 0, actionCollection(), "formulaSelection" ); m_spellChecking = KStdAction::spelling( this, SLOT( extraSpelling() ), actionCollection(), "spelling" ); QStringList lst; lst.append( "sum"); lst.append( "cos"); lst.append( "sqrt"); lst.append( i18n("Others...") ); ((KSelectAction*) m_formulaSelection)->setItems( lst ); m_formulaSelection->setCurrentItem(0); connect( m_formulaSelection, SIGNAL( activated( const QString& ) ), this, SLOT( formulaSelection( const QString& ) ) ); // Insert menu (void) new KAction( i18n("&Math expression..."), "funct", 0, this, SLOT( insertMathExpr() ), actionCollection(), "insertMathExpr" ); (void) new KAction( i18n("&Series..."),"series", 0, this, SLOT( insertSeries() ), actionCollection(), "series" ); (void) new KAction( i18n("&Hyperlink..."), 0, this, SLOT( insertHyperlink() ), actionCollection(), "insertHyperlink" ); m_insertPart=new KoPartSelectAction( i18n("&Object..."), "frame_query", this, SLOT( insertObject() ), actionCollection(), "insertPart"); m_insertChartFrame=new KAction( i18n("&Chart"), "frame_chart", 0, this, SLOT( insertChart() ), actionCollection(), "insertChart" ); m_autoSum = new KAction( i18n("AutoSum"), "black_sum", 0, this, SLOT( autoSum() ), actionCollection(), "autoSum" ); m_sortDec = new KAction( i18n("Sort decreasing"), "sort_decrease", 0, this, SLOT( sortDec() ), actionCollection(), "sortDec" ); m_sortInc = new KAction( i18n("Sort increasing"), "sort_incr", 0, this, SLOT( sortInc() ), actionCollection(), "sortInc" ); m_textColor = new TKSelectColorAction( i18n("Text color"), TKSelectColorAction::TextColor, actionCollection(), "textColor",true ); connect( m_textColor, SIGNAL(activated()), SLOT(changeTextColor()) ); m_textColor->setDefaultColor(QColor()); m_bgColor = new TKSelectColorAction( i18n("Background color"),TKSelectColorAction::FillColor, actionCollection(), "backgroundColor",true ); connect(m_bgColor,SIGNAL(activated()),SLOT(changeBackgroundColor())); m_bgColor->setDefaultColor(QColor()); m_borderLeft = new KAction( i18n("Border left"), "border_left", 0, this, SLOT( borderLeft() ), actionCollection(), "borderLeft" ); m_borderRight = new KAction( i18n("Border Right"), "border_right", 0, this, SLOT( borderRight() ), actionCollection(), "borderRight" ); m_borderTop = new KAction( i18n("Border Top"), "border_top", 0, this, SLOT( borderTop() ), actionCollection(), "borderTop" ); m_borderBottom = new KAction( i18n("Border Bottom"), "border_bottom", 0, this, SLOT( borderBottom() ), actionCollection(), "borderBottom" ); m_borderAll = new KAction( i18n("All borders"), "border_all", 0, this, SLOT( borderAll() ), actionCollection(), "borderAll" ); m_borderRemove = new KAction( i18n("Remove Borders"), "border_remove", 0, this, SLOT( borderRemove() ), actionCollection(), "borderRemove" ); m_borderOutline = new KAction( i18n("Border Outline"), ("border_outline"), 0, this, SLOT( borderOutline() ), actionCollection(), "borderOutline" ); m_borderColor = new TKSelectColorAction( i18n("Border Color"), TKSelectColorAction::LineColor, actionCollection(), "borderColor" ); connect(m_borderColor,SIGNAL(activated()),SLOT(changeBorderColor())); m_tableFormat = new KAction( i18n("Table Style..."), 0, this, SLOT( tableFormat() ), actionCollection(), "tableFormat" ); // m_oszi = new KAction( i18n("Osciloscope..."),"oscilloscope", 0, this, SLOT( oszilloscope() ), actionCollection(), "oszi" ); //menu calc m_menuCalcSum = new KToggleAction( i18n("Sum"), 0, actionCollection(), "menu_sum"); connect( m_menuCalcSum, SIGNAL( toggled( bool ) ), this, SLOT( menuCalc( bool ) ) ); m_menuCalcSum->setExclusiveGroup( "Calc" ); m_menuCalcMin = new KToggleAction( i18n("Min"), 0, actionCollection(), "menu_min"); connect( m_menuCalcMin, SIGNAL( toggled( bool ) ), this, SLOT( menuCalc( bool ) ) ); m_menuCalcMin->setExclusiveGroup( "Calc" ); m_menuCalcMax = new KToggleAction( i18n("Max"), 0, actionCollection(), "menu_max"); connect( m_menuCalcMax, SIGNAL( toggled( bool ) ), this, SLOT( menuCalc( bool ) ) ); m_menuCalcMax->setExclusiveGroup( "Calc" ); m_menuCalcAverage = new KToggleAction( i18n("Average"), 0, actionCollection(), "menu_average"); connect( m_menuCalcAverage, SIGNAL( toggled( bool ) ), this, SLOT( menuCalc( bool ) ) ); m_menuCalcAverage->setExclusiveGroup( "Calc" ); m_menuCalcCount = new KToggleAction( i18n("Count"), 0, actionCollection(), "menu_count"); connect( m_menuCalcCount, SIGNAL( toggled( bool ) ), this, SLOT( menuCalc( bool ) ) ); m_menuCalcCount->setExclusiveGroup( "Calc" ); // connect( this, SIGNAL( childSelected( KoDocumentChild* ) ), this, SLOT( slotChildSelected( KoDocumentChild* ) ) ); connect( this, SIGNAL( childUnselected( KoDocumentChild* ) ), this, SLOT( slotChildUnselected( KoDocumentChild* ) ) ); // If a selected part becomes active this is like it is deselected // just before. connect( this, SIGNAL( childActivated( KoDocumentChild* ) ), this, SLOT( slotChildUnselected( KoDocumentChild* ) ) ); QTimer::singleShot( 0, this, SLOT( initialPosition() ) ); m_findOptions = 0; KStatusBar * sb = statusBar(); Q_ASSERT(sb); m_sbCalcLabel = sb ? new KStatusBarLabel( QString::null, 0, sb ) : 0; addStatusBarItem( m_sbCalcLabel, 0 ); if(m_sbCalcLabel) connect(m_sbCalcLabel ,SIGNAL(itemPressed( int )),this,SLOT(statusBarClicked(int))); } KSpreadView::~KSpreadView() { deleteEditor( true ); if ( !m_transformToolBox.isNull() ) delete (&*m_transformToolBox); /*if(m_sbCalcLabel) { disconnect(m_sbCalcLabel,SIGNAL(pressed( int )),this,SLOT(statusBarClicked(int))); }*/ if(m_spell.kspell) { delete m_spell.kspell; } m_pCanvas->endChoose(); m_pTable = 0; // set the active table to 0L so that when during destruction // of embedded child documents possible repaints in KSpreadTable are not // performed. The repains can happen if you delete an embedded document, // which leads to an regionInvalidated() signal emission in KoView, which calls // repaint, etc.etc. :-) (Simon) delete m_pPopupColumn; delete m_pPopupRow; delete m_pPopupMenu; delete m_popupChild; delete m_popupListChoose; delete m_sbCalcLabel; delete m_dcop; } void KSpreadView::initConfig() { KConfig *config = KSpreadFactory::global()->config(); if( config->hasGroup("Parameters" )) { config->setGroup( "Parameters" ); m_pDoc->setShowHorizontalScrollBar(config->readBoolEntry("Horiz ScrollBar",true)); m_pDoc->setShowVerticalScrollBar(config->readBoolEntry("Vert ScrollBar",true)); m_pDoc->setShowColHeader(config->readBoolEntry("Column Header",true)); m_pDoc->setShowRowHeader(config->readBoolEntry("Row Header",true)); m_pDoc->setCompletionMode((KGlobalSettings::Completion)config->readNumEntry("Completion Mode",(int)(KGlobalSettings::CompletionAuto))); m_pDoc->setMoveToValue((KSpread::MoveTo)config->readNumEntry("Move",(int)(KSpread::Bottom))); m_pDoc->setIndentValue(config->readNumEntry( "Indent",10 ) ); m_pDoc->setTypeOfCalc((MethodOfCalc)config->readNumEntry("Method of Calc",(int)(SumOfNumber))); m_pDoc->setShowTabBar(config->readBoolEntry("Tabbar",true)); m_pDoc->setShowMessageError(config->readBoolEntry( "Msg error" ,false) ); m_pDoc->setShowCommentIndicator(config->readBoolEntry("Comment Indicator",true)); m_pDoc->setShowFormulaBar(config->readBoolEntry("Formula bar",true)); m_pDoc->setShowStatusBar(config->readBoolEntry("Status bar",true)); changeNbOfRecentFiles(config->readNumEntry("NbRecentFile",10)); //autosave value is stored as a minute. //but default value is stored as seconde. m_pDoc->setAutoSave(config->readNumEntry("AutoSave",KoDocument::defaultAutoSave()/60)*60); } if( config->hasGroup("KSpread Color" ) ) { config->setGroup( "KSpread Color" ); QColor _col(Qt::lightGray); _col= config->readColorEntry("GridColor",&_col); m_pDoc->changeDefaultGridPenColor(_col); } if( config->hasGroup("KSpread Page Layout" ) ) { config->setGroup( "KSpread Page Layout" ); if( m_pDoc->isEmpty()) { m_pDoc->setPaperFormat((KoFormat)config->readNumEntry("Default size page",1)); m_pDoc->setPaperOrientation((KoOrientation)config->readNumEntry("Default orientation page",0)); m_pDoc->setPaperUnit((KoUnit::Unit)config->readNumEntry("Default unit page",0)); } } initCalcMenu(); resultOfCalc(); } void KSpreadView::changeNbOfRecentFiles(int _nb) { if(shell()) shell()->setMaxRecentItems( _nb ); } void KSpreadView::initCalcMenu() { switch( doc()->getTypeOfCalc()) { case SumOfNumber: m_menuCalcSum->setChecked(true); break; case Min: m_menuCalcMin->setChecked(true); break; case Max: m_menuCalcMax->setChecked(true); break; case Average: m_menuCalcAverage->setChecked(true); break; case Count: m_menuCalcCount->setChecked(true); break; default : m_menuCalcSum->setChecked(true); break; } } void KSpreadView::RecalcWorkBook(){ KSpreadTable *tbl; for ( tbl = m_pDoc->map()->firstTable(); tbl != 0L; tbl = m_pDoc->map()->nextTable() ){ tbl->recalc(); } // slotUpdateView( activeTable() ); } void KSpreadView::slotRefreshLocale() { kdDebug(36001)<<"KSpreadView::slotRefreshLocale()***************\n"; KSpreadTable *tbl; for ( tbl = m_pDoc->map()->firstTable(); tbl != 0L; tbl = m_pDoc->map()->nextTable() ){ tbl->updateLocale(); } } void KSpreadView::RecalcWorkSheet() { if (m_pTable!= 0) m_pTable->recalc(); //slotUpdateView( activeTable() ); } void KSpreadView::extraSpelling() { if (m_spell.kspell) return; // Already in progress if (m_pTable == 0L) return; // m_spell.macroCmdSpellCheck = 0L; m_spell.firstSpellTable = m_pTable; m_spell.currentSpellTable = m_spell.firstSpellTable; QRect selection = m_pTable->selectionRect(); // if nothing is selected, check every cell if (selection.left() == 0) { m_spell.spellStartCellX = 0; m_spell.spellStartCellY = 0; m_spell.spellEndCellX = 0; m_spell.spellEndCellY = 0; m_spell.spellCheckSelection = false; m_spell.currentCell = m_pTable->firstCell(); } else { m_spell.spellStartCellX = selection.left(); m_spell.spellStartCellY = selection.top(); m_spell.spellEndCellX = selection.right(); m_spell.spellEndCellY = selection.bottom(); m_spell.spellCheckSelection = true; m_spell.currentCell = 0L; // "-1" because X gets increased every time we go into spellCheckReady() m_spell.spellCurrCellX = m_spell.spellStartCellX - 1; m_spell.spellCurrCellY = m_spell.spellStartCellY; } startKSpell(); } void KSpreadView::startKSpell() { m_spell.kspell = new KSpreadSpell( this, i18n( "Spell Checking" ), this, SLOT( spellCheckerReady() ), m_pDoc->getKSpellConfig() ); + m_spell.ignoreWord = m_ignoreWord; + m_spell.kspell->ksConfig().setIgnoreList(m_spell.ignoreWord); + m_spell.kspell->setIgnoreUpperWords(m_pDoc->dontCheckUpperWord()); m_spell.kspell->setIgnoreTitleCase(m_pDoc->dontCheckTitleCase()); QObject::connect( m_spell.kspell, SIGNAL( death() ), this, SLOT( spellCheckerFinished() ) ); QObject::connect( m_spell.kspell, SIGNAL( misspelling( const QString &, const QStringList &, unsigned int) ), this, SLOT( spellCheckerMisspelling( const QString &, const QStringList &, unsigned int) ) ); QObject::connect( m_spell.kspell, SIGNAL( corrected( const QString &, const QString &, unsigned int) ), this, SLOT( spellCheckerCorrected( const QString &, const QString &, unsigned int ) ) ); QObject::connect( m_spell.kspell, SIGNAL( done( const QString & ) ), this, SLOT( spellCheckerDone( const QString & ) ) ); } void KSpreadView::spellCheckerReady() { if (m_pCanvas) m_pCanvas->setCursor( WaitCursor ); // go on to the next cell if (!m_spell.spellCheckSelection) { // if nothing is selected we have to check every cell // we use a different way to make it faster while ( m_spell.currentCell ) { // check text only if ( !m_spell.currentCell->isDefault() && m_spell.currentCell->isString() ) { m_spell.kspell->check( m_spell.currentCell->text(), true ); return; } m_spell.currentCell = m_spell.currentCell->nextCell(); } if (spellSwitchToOtherTable()) spellCheckerReady(); else spellCleanup(); return; } // if something is selected: ++m_spell.spellCurrCellX; if (m_spell.spellCurrCellX > m_spell.spellEndCellX) { m_spell.spellCurrCellX = m_spell.spellStartCellX; ++m_spell.spellCurrCellY; } unsigned int y; unsigned int x; for ( y = m_spell.spellCurrCellY; y <= m_spell.spellEndCellY; ++y ) { for ( x = m_spell.spellCurrCellX; x <= m_spell.spellEndCellX; ++x ) { KSpreadCell * cell = m_spell.currentSpellTable->cellAt(x, y, true); // check text only if (cell->isDefault() || !cell->isString()) continue; m_spell.spellCurrCellX = x; m_spell.spellCurrCellY = y; m_spell.kspell->check( cell->text(), true ); return; } m_spell.spellCurrCellX = m_spell.spellStartCellX; } // if the user selected something to be checked we are done // otherwise ask for checking the next table if any if (m_spell.spellCheckSelection) { // Done spellCleanup(); } else { if (spellSwitchToOtherTable()) spellCheckerReady(); else spellCleanup(); } } void KSpreadView::spellCleanup() { if (m_pCanvas) m_pCanvas->setCursor( ArrowCursor ); m_spell.kspell->cleanUp(); delete m_spell.kspell; m_spell.kspell = 0L; m_spell.firstSpellTable = 0L; m_spell.currentSpellTable = 0L; m_spell.currentCell = 0L; - // not supported yet + KMessageBox::information( this, i18n( "Spell checking is done." ) ); // not supported yet // if(m_spell.macroCmdSpellCheck) // m_pDoc->addCommand(m_spell.macroCmdSpellCheck); } bool KSpreadView::spellSwitchToOtherTable() { // there is no other table if(m_pDoc->map()->count()==1) return false; // for optimization QPtrList tableList = m_pDoc->map()->tableList(); unsigned int curIndex = tableList.findRef(m_spell.currentSpellTable); ++curIndex; // last table? then start at the beginning if ( curIndex >= tableList.count() ) m_spell.currentSpellTable = tableList.first(); else m_spell.currentSpellTable = tableList.at(curIndex); // if the current table is the first one again, we are done. if( m_spell.currentSpellTable == m_spell.firstSpellTable ) { setActiveTable( m_spell.firstSpellTable ); return false; } if (m_spell.spellCheckSelection) { m_spell.spellEndCellX = m_spell.currentSpellTable->maxColumn(); m_spell.spellEndCellY = m_spell.currentSpellTable->maxRow(); m_spell.spellCurrCellX = m_spell.spellStartCellX - 1; m_spell.spellCurrCellY = m_spell.spellStartCellY; } else { m_spell.currentCell = m_spell.currentSpellTable->firstCell(); } if ( KMessageBox::questionYesNo( this, i18n( "Do you want to check the spelling in the next table?") ) != KMessageBox::Yes ) return false; setActiveTable(m_spell.currentSpellTable); return true; } void KSpreadView::spellCheckerMisspelling( const QString &, const QStringList &, unsigned int ) { // scroll to the cell if (!m_spell.spellCheckSelection) { m_spell.spellCurrCellX = m_spell.currentCell->column(); m_spell.spellCurrCellY = m_spell.currentCell->row(); } canvasWidget()->gotoLocation( m_spell.spellCurrCellX, m_spell.spellCurrCellY, activeTable() ); } void KSpreadView::spellCheckerCorrected( const QString & old, const QString & corr, unsigned int pos ) { KSpreadCell * cell; if (m_spell.spellCheckSelection) { cell = m_spell.currentSpellTable->cellAt(m_spell.spellCurrCellX, m_spell.spellCurrCellY, true); } else { cell = m_spell.currentCell; m_spell.spellCurrCellX = cell->column(); m_spell.spellCurrCellY = cell->row(); } Q_ASSERT( cell ); if ( !cell ) return; QString content( cell->text() ); KSpreadUndoSetText* undo = new KSpreadUndoSetText( m_pDoc, m_pTable, content, m_spell.spellCurrCellX, m_spell.spellCurrCellY, cell->formatType()); m_pDoc->undoBuffer()->appendUndo( undo ); content.replace( pos, old.length(), corr ); cell->setCellText( content ); m_pEditWidget->setText( content ); // TODO ?: // if(!m_spell.macroCmdSpellCheck) // m_spell.macroCmdSpellCheck=new KMacroCommand(i18n("Correct misspelled word")); // m_spell.macroCmdSpellCheck->addCommand(textobj->textObject()->replaceSelectionCommand(&cursor, corr, KoTextObject::HighlightSelection, QString::null )); } void KSpreadView::spellCheckerDone( const QString & ) { int result = m_spell.kspell->dlgResult(); // store ignore word - m_spell.ignoreWord = m_spell.kspell->ksConfig().ignoreList(); + m_ignoreWord += m_spell.kspell->ksConfig().ignoreList(); m_spell.kspell->cleanUp(); delete m_spell.kspell; m_spell.kspell = 0L; if ( result != KS_CANCEL && result != KS_STOP ) { if (m_spell.spellCheckSelection) { if ( (m_spell.spellCurrCellY <= m_spell.spellEndCellY) && (m_spell.spellCurrCellX <= m_spell.spellEndCellX) ) { startKSpell(); return; } } else { if ( m_spell.currentCell ) { m_spell.currentCell = m_spell.currentCell->nextCell(); startKSpell(); return; } } } - if (m_pCanvas) - m_pCanvas->setCursor( ArrowCursor ); - // Not implemented yet // if(m_spell.macroCmdSpellCheck) // m_pDoc->addCommand(m_spell.macroCmdSpellCheck); } void KSpreadView::spellCheckerFinished() { if (m_pCanvas) m_pCanvas->setCursor( ArrowCursor ); KSpell::spellStatus status = m_spell.kspell->status(); m_spell.kspell->cleanUp(); delete m_spell.kspell; m_spell.kspell = 0L; bool kspellNotConfigured=false; if (status == KSpell::Error) { KMessageBox::sorry(this, i18n("ISpell could not be started.\n" "Please make sure you have ISpell properly configured and in your PATH.")); kspellNotConfigured=true; } else if (status == KSpell::Crashed) { KMessageBox::sorry(this, i18n("ISpell seems to have crashed.")); } // Not implemented yet // if(m_spell.macroCmdSpellCheck) // m_pDoc->addCommand(m_spell.macroCmdSpellCheck); if(kspellNotConfigured) { KSpreadpreference configDlg( this, 0 ); configDlg.openPage( KSpreadpreference::KS_SPELLING); configDlg.exec(); } } void KSpreadView::initialPosition() { // Set the initial position for the marker as store in the XML file, // (1,1) otherwise int col = m_pDoc->map()->initialMarkerColumn(); if ( col <= 0 ) col = 1; int row = m_pDoc->map()->initialMarkerRow(); if ( row <= 0 ) row = 1; m_pCanvas->gotoLocation( col, row ); //init toggle button updateBorderButton(); m_tableFormat->setEnabled(false); m_mergeCell->setEnabled(false); m_insertChartFrame->setEnabled(false); /*recalc all dependent after loading*/ KSpreadTable *tbl; for ( tbl = m_pDoc->map()->firstTable(); tbl != 0L; tbl = m_pDoc->map()->nextTable() ) { if(tbl->getAutoCalc()) tbl->recalc(); tbl->refreshMergedCell(); } slotUpdateView( activeTable() ); m_bLoading =true; if ( koDocument()->isReadWrite() ) initConfig(); } void KSpreadView::updateEditWidget() { bool active=activeTable()->getShowFormula(); m_alignLeft->setEnabled(!active); m_alignCenter->setEnabled(!active); m_alignRight->setEnabled(!active); m_toolbarLock = TRUE; int column=m_pCanvas->markerColumn(); int row=m_pCanvas->markerRow(); KSpreadCell* cell = m_pTable->cellAt( column,row ); if ( !cell ) { editWidget()->setText( "" ); return; } if ( cell->content() == KSpreadCell::VisualFormula ) editWidget()->setText( "" ); else editWidget()->setText( cell->text() ); QColor color=cell->textColor( column,row); if(!color.isValid()) color=QApplication::palette().active().text(); m_textColor->setCurrentColor( color ); color=cell->bgColor( column,row); if(!color.isValid()) color=QApplication::palette().active().base(); m_bgColor->setCurrentColor( color ); m_selectFontSize->setFontSize( cell->textFontSize( column,row ) ); m_selectFont->setFont( cell->textFontFamily( column,row ) ); m_bold->setChecked( cell->textFontBold( column,row) ); m_italic->setChecked( cell->textFontItalic( column,row) ); m_underline->setChecked( cell->textFontUnderline( column,row ) ); m_strikeOut->setChecked( cell->textFontStrike( column,row ) ); m_alignLeft->setChecked( cell->align( column,row ) == KSpreadLayout::Left ); m_alignRight->setChecked( cell->align( column,row) == KSpreadLayout::Right ); m_alignCenter->setChecked(cell->align( column,row ) == KSpreadLayout::Center ); m_alignTop->setChecked( cell->alignY( column,row ) == KSpreadLayout::Top ); m_alignMiddle->setChecked( cell->alignY( column,row ) == KSpreadLayout::Middle ); m_alignBottom->setChecked( cell->alignY( column,row) == KSpreadLayout::Bottom ); m_verticalText->setChecked( cell->verticalText( column,row ) ); m_multiRow->setChecked( cell->multiRow( column,row ) ); KSpreadCell::FormatType ft = cell->formatType(); m_percent->setChecked( ft == KSpreadCell::Percentage ); m_money->setChecked( ft == KSpreadCell::Money ); m_removeComment->setEnabled( !cell->comment(column,row).isEmpty() ); m_decreaseIndent->setEnabled(cell->getIndent(column,row)>0); m_toolbarLock = FALSE; } void KSpreadView::activateFormulaEditor() { } void KSpreadView::updateReadWrite( bool readwrite ) { #ifdef __GNUC_ #warning TODO #endif // m_pCancelButton->setEnabled( readwrite ); // m_pOkButton->setEnabled( readwrite ); m_pEditWidget->setEnabled( readwrite ); QValueList actions = actionCollection()->actions(); QValueList::ConstIterator aIt = actions.begin(); QValueList::ConstIterator aEnd = actions.end(); for (; aIt != aEnd; ++aIt ) (*aIt)->setEnabled( readwrite ); m_transform->setEnabled( false ); m_redo->setEnabled( false ); m_undo->setEnabled( false ); m_showTable->setEnabled( true ); m_hideTable->setEnabled( true ); m_gotoCell->setEnabled( true ); // m_newView->setEnabled( true ); //m_pDoc->KXMLGUIClient::action( "newView" )->setEnabled( true ); // obsolete (Werner) // m_oszi->setEnabled( true ); } void KSpreadView::tableFormat() { KSpreadFormatDlg dlg( this ); dlg.exec(); } void KSpreadView::autoSum() { // ######## Torben: Make sure that this can not be called // when canvas has a running editor if ( m_pCanvas->editor() ) return; m_pCanvas->createEditor( KSpreadCanvas::CellEditor ); m_pCanvas->editor()->setText( "=sum()" ); m_pCanvas->editor()->setCursorPosition( 5 ); // Try to find numbers above if ( m_pCanvas->markerRow() > 1 ) { KSpreadCell* cell = 0; int r = m_pCanvas->markerRow(); do { cell = activeTable()->cellAt( m_pCanvas->markerColumn(), --r ); } while ( cell && cell->isNumeric() ); if ( r + 1 < m_pCanvas->markerRow() ) { m_pTable->setChooseRect( QRect( m_pCanvas->markerColumn(), r + 1, 1, m_pCanvas->markerRow() - r - 1 ) ); return; } } // Try to find numbers left if ( m_pCanvas->markerColumn() > 1 ) { KSpreadCell* cell = 0; int c = m_pCanvas->markerColumn(); do { cell = activeTable()->cellAt( --c, m_pCanvas->markerRow() ); } while ( cell && cell->isNumeric() ); if ( c + 1 < m_pCanvas->markerColumn() ) { m_pTable->setChooseRect( QRect( c + 1, m_pCanvas->markerRow(), m_pCanvas->markerColumn() - c - 1, 1 ) ); return; } } } /* void KSpreadView::oszilloscope() { QDialog* dlg = new KSpreadOsziDlg( this ); dlg->show(); } */ void KSpreadView::changeTextColor() { if ( m_pTable != 0L ) { m_pTable->setSelectionTextColor( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), m_textColor->color() ); } } void KSpreadView::changeBackgroundColor() { if ( m_pTable != 0L ) { m_pTable->setSelectionbgColor( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), m_bgColor->color() ); } } void KSpreadView::changeBorderColor() { if ( m_pTable != 0L ) { m_pTable->setSelectionBorderColor( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), m_borderColor->color() ); } } void KSpreadView::helpUsing() { kapp->invokeHelp( ); } QButton * KSpreadView::newIconButton( const char *_file, bool _kbutton, QWidget *_parent ) { if ( _parent == 0L ) _parent = this; QButton *pb; if ( !_kbutton ) pb = new QPushButton( _parent ); else pb = new QToolButton( _parent ); pb->setPixmap( QPixmap( KSBarIcon(_file) ) ); return pb; } void KSpreadView::enableUndo( bool _b ) { m_undo->setEnabled( _b ); m_undo->setText(i18n("Undo: %1").arg(m_pDoc->undoBuffer()->getUndoName())); } void KSpreadView::enableRedo( bool _b ) { m_redo->setEnabled( _b ); m_redo->setText(i18n("Redo: %1").arg(m_pDoc->undoBuffer()->getRedoName())); } void KSpreadView::undo() { m_pDoc->undo(); updateEditWidget(); resultOfCalc(); } void KSpreadView::redo() { m_pDoc->redo(); updateEditWidget(); resultOfCalc(); } void KSpreadView::deleteColumn() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isRowSelected() ) m_pTable->removeColumn( m_pCanvas->markerColumn() ); else m_pTable->removeColumn( r.left(),(r.right()-r.left()) ); updateEditWidget(); m_pTable->setSelection(m_pTable->marker()); } void KSpreadView::deleteRow() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isColumnSelected() ) m_pTable->removeRow( m_pCanvas->markerRow() ); else m_pTable->removeRow( r.top(),(r.bottom()-r.top()) ); updateEditWidget(); m_pTable->setSelection(m_pTable->marker()); } void KSpreadView::insertColumn() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isRowSelected() ) m_pTable->insertColumn( m_pCanvas->markerColumn() ); else m_pTable->insertColumn( r.left(),(r.right()-r.left()) ); updateEditWidget(); } void KSpreadView::hideColumn() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isRowSelected() ) m_pTable->hideColumn( m_pCanvas->markerColumn() ); else m_pTable->hideColumn( r.left(),(r.right()-r.left()) ); } void KSpreadView::showColumn() { if ( !m_pTable ) return; KSpreadShowColRow dlg( this,"showCol",KSpreadShowColRow::Column); dlg.exec(); } void KSpreadView::showSelColumns() { if ( !m_pTable ) return; int i; QRect rect = activeTable()->selectionRect(); ColumnLayout * col; QValueListhiddenCols; for ( i = rect.left(); i <= rect.right(); ++i ) { if (i == 2) // "B" { col = activeTable()->columnLayout( 1 ); if ( col->isHide() ) { hiddenCols.append( 1 ); } } col = m_pTable->columnLayout( i ); if ( col->isHide() ) { hiddenCols.append(i); } } if (hiddenCols.count() > 0) m_pTable->showColumn(0, -1, hiddenCols); } void KSpreadView::insertRow() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isColumnSelected() ) m_pTable->insertRow( m_pCanvas->markerRow() ); else m_pTable->insertRow( r.top(),(r.bottom()-r.top()) ); updateEditWidget(); } void KSpreadView::hideRow() { if ( !m_pTable ) return; QRect r( activeTable()-> selectionRect() ); if( r.left()==0 || activeTable()->isColumnSelected() ) m_pTable->hideRow( m_pCanvas->markerRow() ); else m_pTable->hideRow( r.top(),(r.bottom()-r.top()) ); } void KSpreadView::showRow() { if ( !m_pTable ) return; KSpreadShowColRow dlg( this,"showRow",KSpreadShowColRow::Row); dlg.exec(); } void KSpreadView::showSelRows() { if ( !m_pTable ) return; int i; QRect rect = activeTable()->selectionRect(); RowLayout * row; QValueListhiddenRows; for ( i = rect.top(); i <= rect.bottom(); ++i ) { if (i == 2) { row = activeTable()->rowLayout( 1 ); if ( row->isHide() ) { hiddenRows.append(1); } } row = m_pTable->rowLayout( i ); if ( row->isHide() ) { hiddenRows.append(i); } } if (hiddenRows.count() > 0) m_pTable->showRow(0, -1, hiddenRows); } void KSpreadView::fontSelected( const QString &_font ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), _font.latin1() ); // Dont leave the focus in the toolbars combo box ... if ( m_pCanvas->editor() ) m_pCanvas->editor()->setFocus(); else m_pCanvas->setFocus(); } void KSpreadView::decreaseFontSize() { if( !m_pTable ) return; m_pTable->setSelectionSize( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), -1 ); updateEditWidget(); } void KSpreadView::increaseFontSize() { if( !m_pTable ) return; m_pTable->setSelectionSize( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 1 ); updateEditWidget(); } void KSpreadView::lower() { if( !m_pTable ) return; m_pTable->setSelectionUpperLower( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), -1 ); updateEditWidget(); } void KSpreadView::upper() { if( !m_pTable ) return; m_pTable->setSelectionUpperLower( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 1 ); updateEditWidget(); } void KSpreadView::firstLetterUpper() { if( !m_pTable ) return; m_pTable->setSelectionfirstLetterUpper( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::verticalText(bool b) { if( !m_pTable ) return; m_pTable->setSelectionVerticalText( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),b ); if( activeTable()->isRowSelected() == FALSE && activeTable()->isColumnSelected() == FALSE ) m_pCanvas->adjustArea(false); updateEditWidget(); } void KSpreadView::insertMathExpr() { if ( m_pTable == 0L ) return; KSpreadDlgFormula *dlg=new KSpreadDlgFormula( this, "Formula Editor" ); dlg->exec(); // #### Is the dialog deleted when it's closed ? (David) // Torben thinks that not. } void KSpreadView::formulaSelection( const QString &_math ) { if ( m_pTable == 0 ) return; if( _math == i18n("Others...") ) { insertMathExpr(); return; } KSpreadDlgFormula *dlg=new KSpreadDlgFormula( this, "Formula Editor",_math ); dlg->exec(); } void KSpreadView::fontSizeSelected( int _size ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 0L, _size ); // Dont leave the focus in the toolbars combo box ... if ( m_pCanvas->editor() ) m_pCanvas->editor()->setFocus(); else m_pCanvas->setFocus(); } void KSpreadView::bold( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable == 0 ) return; m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 0L, -1, b ); } void KSpreadView::underline( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable == 0 ) return; m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 0L, -1, -1, -1 ,b ); } void KSpreadView::strikeOut( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable == 0 ) return; m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 0L, -1, -1, -1 ,-1,b ); } void KSpreadView::italic( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable == 0 ) return; m_pTable->setSelectionFont( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 0L, -1, -1, b ); } void KSpreadView::sortInc() { QRect r( activeTable()-> selectionRect() ); if ( r.left() == 0 || r.top() == 0 || r.right() == 0 || r.bottom() == 0 ) { KMessageBox::error( this, i18n("You must select multiple cells.") ); return; } // Entire row(s) selected ? Or just one row ? if( activeTable()->isRowSelected() || r.top() == r.bottom() ) activeTable()->sortByRow( r.top() ); else activeTable()->sortByColumn( r.left()); updateEditWidget(); } void KSpreadView::sortDec() { QRect r( activeTable()-> selectionRect() ); if ( r.left() == 0 || r.top() == 0 || r.right() == 0 || r.bottom() == 0 ) { KMessageBox::error( this, i18n("You must select multiple cells.") ); return; } // Entire row(s) selected ? Or just one row ? if( activeTable()->isRowSelected() || r.top() == r.bottom() ) activeTable()->sortByRow( r.top(),KSpreadTable::Decrease); else activeTable()->sortByColumn( r.left(),KSpreadTable::Decrease); updateEditWidget(); } void KSpreadView::reloadScripts() { // TODO } void KSpreadView::runLocalScript() { // TODO } void KSpreadView::editGlobalScripts() { if ( KSpreadView::m_pGlobalScriptsDialog == 0L ) KSpreadView::m_pGlobalScriptsDialog = new KSpreadScripts(); KSpreadView::m_pGlobalScriptsDialog->show(); KSpreadView::m_pGlobalScriptsDialog->raise(); } void KSpreadView::editLocalScripts() { // TODO /* if ( !m_pDoc->editPythonCode() ) { KMessageBox::error( i18n( "Could not start editor" ) ); return; } */ } void KSpreadView::borderBottom() { if ( m_pTable != 0L ) m_pTable->borderBottom( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ,m_borderColor->color()); } void KSpreadView::borderRight() { if ( m_pTable != 0L ) m_pTable->borderRight( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ,m_borderColor->color()); } void KSpreadView::borderLeft() { if ( m_pTable != 0L ) m_pTable->borderLeft( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),m_borderColor->color() ); } void KSpreadView::borderTop() { if ( m_pTable != 0L ) m_pTable->borderTop( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),m_borderColor->color() ); } void KSpreadView::borderOutline() { if ( m_pTable != 0L ) m_pTable->borderOutline( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ,m_borderColor->color()); } void KSpreadView::borderAll() { if ( m_pTable != 0L ) m_pTable->borderAll( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),m_borderColor->color() ); } void KSpreadView::borderRemove() { if ( m_pTable != 0L ) m_pTable->borderRemove( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); } void KSpreadView::addTable( KSpreadTable *_t ) { if( !_t->isHidden() ) { m_pTabBar->addTab( _t->tableName() ); setActiveTable( _t ); } else { m_pTabBar->addHiddenTab(_t->tableName()); } // Connect some signals QObject::connect( _t, SIGNAL( sig_updateView( KSpreadTable* ) ), SLOT( slotUpdateView( KSpreadTable* ) ) ); QObject::connect( _t, SIGNAL( sig_updateView( KSpreadTable *, const QRect& ) ), SLOT( slotUpdateView( KSpreadTable*, const QRect& ) ) ); QObject::connect( _t, SIGNAL( sig_unselect( KSpreadTable *, const QRect& ) ), SLOT( slotUnselect( KSpreadTable *, const QRect& ) ) ); QObject::connect( _t, SIGNAL( sig_updateHBorder( KSpreadTable * ) ), SLOT( slotUpdateHBorder( KSpreadTable * ) ) ); QObject::connect( _t, SIGNAL( sig_updateVBorder( KSpreadTable * ) ), SLOT( slotUpdateVBorder( KSpreadTable * ) ) ); QObject::connect( _t, SIGNAL( sig_changeSelection( KSpreadTable *, const QRect &, const QRect & ) ), SLOT( slotChangeSelection( KSpreadTable *, const QRect &, const QRect & ) ) ); QObject::connect( _t, SIGNAL( sig_changeChooseSelection( KSpreadTable *, const QRect &, const QRect & ) ), SLOT( slotChangeChooseSelection( KSpreadTable *, const QRect &, const QRect & ) ) ); QObject::connect( _t, SIGNAL( sig_nameChanged( KSpreadTable*, const QString& ) ), this, SLOT( slotTableRenamed( KSpreadTable*, const QString& ) ) ); QObject::connect( _t, SIGNAL( sig_TableHidden( KSpreadTable* ) ), this, SLOT( slotTableHidden( KSpreadTable* ) ) ); QObject::connect( _t, SIGNAL( sig_TableShown( KSpreadTable* ) ), this, SLOT( slotTableShown( KSpreadTable* ) ) ); QObject::connect( _t, SIGNAL( sig_TableRemoved( KSpreadTable* ) ), this, SLOT( slotTableRemoved( KSpreadTable* ) ) ); QObject::connect( _t, SIGNAL( sig_TableActivated( KSpreadTable* ) ), this, SLOT( slotTableActivated( KSpreadTable* ) ) ); // ########### Why do these signals not send a pointer to the table? // This will lead to bugs. QObject::connect( _t, SIGNAL( sig_updateChildGeometry( KSpreadChild* ) ), SLOT( slotUpdateChildGeometry( KSpreadChild* ) ) ); QObject::connect( _t, SIGNAL( sig_removeChild( KSpreadChild* ) ), SLOT( slotRemoveChild( KSpreadChild* ) ) ); QObject::connect( _t, SIGNAL( sig_maxColumn( int ) ), m_pCanvas, SLOT( slotMaxColumn( int ) ) ); QObject::connect( _t, SIGNAL( sig_maxRow( int ) ), m_pCanvas, SLOT( slotMaxRow( int ) ) ); QObject::connect( _t, SIGNAL( sig_polygonInvalidated( const QPointArray& ) ), this, SLOT( repaintPolygon( const QPointArray& ) ) ); if(m_bLoading) updateBorderButton(); } void KSpreadView::slotTableRemoved( KSpreadTable *_t ) { QString m_tableName=_t->tableName(); m_pTabBar->removeTab( _t->tableName() ); if(m_pDoc->map()->findTable( m_pTabBar->listshow().first())) setActiveTable( m_pDoc->map()->findTable( m_pTabBar->listshow().first() )); else m_pTable = 0L; QValueList::Iterator it; QValueList area=doc()->listArea(); for ( it = area.begin(); it != area.end(); ++it ) { //remove Area Name when table target is removed if((*it).table_name==m_tableName) { doc()->removeArea((*it).ref_name); //now area name is used in formula //so you must recalc tables when remove areaname KSpreadTable *tbl; for ( tbl = doc()->map()->firstTable(); tbl != 0L; tbl = doc()->map()->nextTable() ) { tbl->refreshRemoveAreaName((*it).ref_name); } } } m_pHorzScrollBar->setValue(activeTable()->getScrollPosX()); m_pVertScrollBar->setValue(activeTable()->getScrollPosY()); } void KSpreadView::removeAllTables() { m_pTabBar->removeAllTabs(); setActiveTable( 0L ); } void KSpreadView::setActiveTable( KSpreadTable *_t,bool updateTable ) { if ( _t == m_pTable ) return; m_pTable = _t; if ( m_pTable == 0L ) return; if(updateTable) { m_pTabBar->setActiveTab( _t->tableName() ); m_pVBorderWidget->repaint(); m_pHBorderWidget->repaint(); m_pCanvas->repaint(); m_pCanvas->slotMaxColumn( m_pTable->maxColumn() ); m_pCanvas->slotMaxRow( m_pTable->maxRow() ); } resultOfCalc(); } void KSpreadView::slotRefreshView( ) { refreshView(); } void KSpreadView::slotTableActivated( KSpreadTable* table ) { m_pTabBar->setActiveTab( table->tableName() ); } void KSpreadView::slotTableRenamed( KSpreadTable* table, const QString& old_name ) { m_pTabBar->renameTab( old_name, table->tableName() ); } void KSpreadView::slotTableHidden( KSpreadTable* table ) { m_pTabBar->hideTable( table->tableName() ); } void KSpreadView::slotTableShown( KSpreadTable* table ) { m_pTabBar->displayTable( table->tableName() ); } void KSpreadView::changeTable( const QString& _name ) { if ( activeTable()->tableName() == _name ) return; KSpreadTable *t = m_pDoc->map()->findTable( _name ); if ( !t ) { kdDebug(36001) << "Unknown table " << _name << endl; return; } m_pCanvas->closeEditor(); activeTable()->setScrollPosX(m_pHorzScrollBar->value()); activeTable()->setScrollPosY(m_pVertScrollBar->value()); setActiveTable( t,false ); t->setActiveTable(); updateEditWidget(); m_pHorzScrollBar->setValue(t->getScrollPosX()); m_pVertScrollBar->setValue(t->getScrollPosY()); //refresh toggle button updateBorderButton(); } void KSpreadView::slotScrollToFirstTable() { m_pTabBar->scrollFirst(); } void KSpreadView::slotScrollToLeftTable() { m_pTabBar->scrollLeft(); } void KSpreadView::slotScrollToRightTable() { m_pTabBar->scrollRight(); } void KSpreadView::slotScrollToLastTable() { m_pTabBar->scrollLast(); } void KSpreadView::insertTable() { m_pCanvas->closeEditor(); activeTable()->setScrollPosX(m_pHorzScrollBar->value()); activeTable()->setScrollPosY(m_pVertScrollBar->value()); KSpreadTable *t = m_pDoc->createTable(); m_pDoc->addTable( t ); m_pHorzScrollBar->setValue(t->getScrollPosX()); m_pVertScrollBar->setValue(t->getScrollPosY()); updateEditWidget(); } void KSpreadView::hideTable() { if ( !m_pTable ) return; m_pTabBar->hideTable(); } void KSpreadView::showTable() { if ( !m_pTable ) return; KSpreadshow dlg( this, "Table show"); dlg.exec(); } void KSpreadView::copySelection() { if ( !m_pTable ) return; if(!m_pCanvas->editor()) { m_pTable->copySelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } else m_pCanvas->editor()->copy(); } void KSpreadView::copyAsText() { if ( !m_pTable ) return; m_pTable->copyAsText( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); } void KSpreadView::cutSelection() { if ( !m_pTable ) return; //don't used this function when we edit a cell. if( !m_pCanvas->editor()) { m_pTable->cutSelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); resultOfCalc(); updateEditWidget(); } else m_pCanvas->editor()->cut(); } void KSpreadView::paste() { if ( !m_pTable ) return; if(!m_pCanvas->editor()) { QRect r( activeTable()-> selectionRect() ); if(r.left()==0 ) r.setCoords(m_pCanvas->markerColumn(), m_pCanvas->markerRow() , m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); m_pTable->paste( QPoint( r.left(),r.top() ) ); if(m_pTable->getAutoCalc()) m_pTable->recalc(); resultOfCalc(); updateEditWidget(); } else m_pCanvas->editor()->paste(); } void KSpreadView::specialPaste() { if ( !m_pTable ) return; KSpreadspecial dlg( this, "Special Paste" ); if( dlg.exec() ) { - if(m_pTable->getAutoCalc()) + if (m_pTable->getAutoCalc()) m_pTable->recalc(); - resultOfCalc(); - updateEditWidget(); + resultOfCalc(); + updateEditWidget(); } } void KSpreadView::removeComment() { if ( !m_pTable ) return; m_pTable->setSelectionRemoveComment( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::changeAngle() { if ( !m_pTable ) return; KSpreadAngle dlg( this, "Angle" ,QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() )); if(dlg.exec()) { if( (activeTable()->isRowSelected() == FALSE) && (activeTable()->isColumnSelected() == FALSE) ) m_pCanvas->adjustArea(false); } } void KSpreadView::mergeCell() { if ( !m_pTable ) return; if((activeTable()->isRowSelected()) ||(activeTable()->isColumnSelected())) { KMessageBox::error( this, i18n("Area too large!")); } else { m_pTable->mergeCell( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); } } void KSpreadView::dissociateCell() { if ( !m_pTable ) return; m_pTable->dissociateCell( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); } void KSpreadView::increaseIndent() { if ( !m_pTable ) return; m_pTable->increaseIndent( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::decreaseIndent() { if ( !m_pTable ) return; int column=m_pCanvas->markerColumn(); int row=m_pCanvas->markerRow(); m_pTable->decreaseIndent( QPoint( column,row ) ); KSpreadCell* cell = m_pTable->cellAt( column,row ); if(cell) m_decreaseIndent->setEnabled(cell->getIndent(column,row)>0); } void KSpreadView::consolidate() { if ( m_pCanvas->editor() ) { m_pCanvas->deleteEditor( true ); // save changes } KSpreadConsolidate *dlg=new KSpreadConsolidate( this, "Consolidate" ); dlg->show(); } void KSpreadView::sortList() { KSpreadList dlg(this,"List selection"); dlg.exec(); } void KSpreadView::gotoCell() { KSpreadGotoDlg dlg( this, "GotoCell" ); dlg.exec(); } void KSpreadView::find() { KoFindDialog dlg( this, "Find", m_findOptions, m_findStrings ); if ( KoFindDialog::Accepted != dlg.exec() ) { return; } m_findOptions = dlg.options(); m_findStrings = dlg.findHistory(); // Do the finding! QPoint m_marker=QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); activeTable()->find( m_marker, dlg.pattern(), dlg.options(), m_pCanvas ); } void KSpreadView::replace() { KoReplaceDialog dlg( this, "Replace", m_findOptions, m_findStrings, m_replaceStrings ); if ( KoReplaceDialog::Accepted != dlg.exec() ) { return; } m_findOptions = dlg.options(); m_findStrings = dlg.findHistory(); m_replaceStrings = dlg.replacementHistory(); // Do the replacement. QPoint m_marker=QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); activeTable()->replace( m_marker, dlg.pattern(), dlg.replacement(), dlg.options(), m_pCanvas ); // Refresh the editWidget KSpreadCell *cell = activeTable()->cellAt( canvasWidget()->markerColumn(), canvasWidget()->markerRow() ); if ( cell->text() != 0L ) editWidget()->setText( cell->text() ); else editWidget()->setText( "" ); } void KSpreadView::conditional() { QRect rect( activeTable()-> selectionRect() ); if( (activeTable()->isRowSelected()) || (activeTable()->isColumnSelected()) ) { KMessageBox::error( this, i18n("Area too large!")); } else { if ( rect.left() == 0 || rect.top() == 0 || rect.right() == 0 || rect.bottom() == 0 ) { rect.setCoords( m_pCanvas->markerColumn(), m_pCanvas->markerRow(),m_pCanvas->markerColumn(), m_pCanvas->markerRow()); } KSpreadconditional dlg(this,"conditional",rect); dlg.exec(); } } void KSpreadView::validity() { QRect rect( activeTable()-> selectionRect() ); if( (activeTable()->isRowSelected()) || (activeTable()->isColumnSelected()) ) { KMessageBox::error( this, i18n("Area too large!")); } else { if ( rect.left() == 0 || rect.top() == 0 || rect.right() == 0 || rect.bottom() == 0 ) { rect.setCoords( m_pCanvas->markerColumn(), m_pCanvas->markerRow(),m_pCanvas->markerColumn(), m_pCanvas->markerRow()); } KSpreadDlgValidity dlg( this,"validity",rect); dlg.exec(); } } void KSpreadView::insertSeries() { KSpreadSeriesDlg dlg( this, "Series", QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); dlg.exec(); } void KSpreadView::sort() { QRect selection( m_pTable->selectionRect() ); if(selection.left()==0) { KMessageBox::error( this, i18n("You must select multiple cells") ); return; } KSpreadSortDlg dlg( this, "Sort" ); dlg.exec(); } void KSpreadView::insertHyperlink() { KSpreadLinkDlg dlg( this, "Create Hyperlink" ); dlg.exec(); } void KSpreadView::setupPrinter( KPrinter &prt ) { //apply page layout parameters KoFormat pageFormat = m_pDoc->paperFormat(); prt.setPageSize( static_cast( KoPageFormat::printerPageSize( pageFormat ) ) ); if ( m_pDoc->orientation() == PG_LANDSCAPE || pageFormat == PG_SCREEN ) prt.setOrientation( KPrinter::Landscape ); else prt.setOrientation( KPrinter::Portrait ); } void KSpreadView::print( KPrinter &prt ) { prt.setFullPage( TRUE ); QPainter painter; painter.begin( &prt ); // Print the table and tell that m_pDoc is NOT embedded. m_pTable->print( painter, &prt ); painter.end(); } void KSpreadView::insertChart( const QRect& _geometry, KoDocumentEntry& _e ) { if ( !m_pTable ) return; // Transform the view coordinates to document coordinates QWMatrix m = matrix().invert(); QPoint tl = m.map( _geometry.topLeft() ); QPoint br = m.map( _geometry.bottomRight() ); if( (activeTable()->isRowSelected()) || (activeTable()->isColumnSelected()) ) { KMessageBox::error( this, i18n("Area too large!")); m_pTable->insertChart( QRect( tl, br ), _e, QRect( m_pCanvas->markerColumn(), m_pCanvas->markerRow(),1,1) ); } else { // Insert the new child in the active table. m_pTable->insertChart( QRect( tl, br ), _e, m_pTable->selectionRect() ); } } void KSpreadView::insertChild( const QRect& _geometry, KoDocumentEntry& _e ) { if ( !m_pTable ) return; // Transform the view coordinates to document coordinates QWMatrix m = matrix().invert(); QPoint tl = m.map( _geometry.topLeft() ); QPoint br = m.map( _geometry.bottomRight() ); // Insert the new child in the active table. m_pTable->insertChild( QRect( tl, br ), _e ); } void KSpreadView::slotRemoveChild( KSpreadChild *_child ) { if ( _child->table() != m_pTable ) return; // Make shure that this child has no active embedded view -> activate ourselfs partManager()->setActivePart( koDocument(), this ); partManager()->setSelectedPart( 0 ); } void KSpreadView::slotUpdateChildGeometry( KSpreadChild */*_child*/ ) { // ############## // TODO /* if ( _child->table() != m_pTable ) return; // Find frame for child KSpreadChildFrame *f = 0L; QPtrListIterator it( m_lstFrames ); for ( ; it.current() && !f; ++it ) if ( it.current()->child() == _child ) f = it.current(); assert( f != 0L ); // Are we already up to date ? if ( _child->geometry() == f->partGeometry() ) return; // TODO zooming f->setPartGeometry( _child->geometry() ); */ } void KSpreadView::togglePageBorders( bool mode ) { if ( !m_pTable ) return; m_pTable->setShowPageBorders( mode ); } void KSpreadView::preference() { if ( !m_pTable ) return; KSpreadpreference dlg( this, "Preference"); if(dlg.exec()) m_pTable->refreshPreference(); } void KSpreadView::addModifyComment() { if ( !m_pTable ) return; KSpreadComment dlg( this, "comment",QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() )); if(dlg.exec()) updateEditWidget(); } void KSpreadView::editCell() { if ( m_pCanvas->editor() ) return; m_pCanvas->createEditor(); } void KSpreadView::nextTable(){ KSpreadTable *t = m_pDoc->map()->nextTable( activeTable() ); if ( !t ) { kdDebug(36001) << "Unknown table " << endl; return; } m_pCanvas->closeEditor(); activeTable()->setScrollPosX(m_pHorzScrollBar->value()); activeTable()->setScrollPosY(m_pVertScrollBar->value()); setActiveTable( t,false ); t->setActiveTable(); } void KSpreadView::previousTable(){ KSpreadTable *t = m_pDoc->map()->previousTable( activeTable() ); if ( !t ) { kdDebug(36001) << "Unknown table " << endl; return; } m_pCanvas->closeEditor(); activeTable()->setScrollPosX(m_pHorzScrollBar->value()); activeTable()->setScrollPosY(m_pVertScrollBar->value()); setActiveTable( t,false ); t->setActiveTable(); } void KSpreadView::keyPressEvent ( QKeyEvent* _ev ) { // Dont eat accelerators if ( _ev->state() & ( Qt::AltButton | Qt::ControlButton ) ){ if ( _ev->state() & ( Qt::ControlButton ) ){ // Universally reserved spreadsheet navigators known to all professional // spreadsheet users around the world -- Bernd switch( _ev->key() ){ case Key_PageDown: nextTable(); return; case Key_PageUp: previousTable(); return; #ifndef NDEBUG case Key_V: // Ctrl+Shift+V to show debug (similar to KWord) if ( _ev->state() & Qt::ShiftButton ) m_pTable->printDebug(); #endif default: QWidget::keyPressEvent( _ev ); return; } } QWidget::keyPressEvent( _ev ); } else QApplication::sendEvent( m_pCanvas, _ev ); } KoDocument* KSpreadView::hitTest( const QPoint &pos ) { // Code copied from KoView::hitTest KoViewChild *viewChild; QWMatrix m = matrix(); m.translate( m_pCanvas->xOffset(), m_pCanvas->yOffset() ); KoDocumentChild *docChild = selectedChild(); if ( docChild ) { if ( ( viewChild = child( docChild->document() ) ) ) { if ( viewChild->frameRegion( m ).contains( pos ) ) return 0; } else if ( docChild->frameRegion( m ).contains( pos ) ) return 0; } docChild = activeChild(); if ( docChild ) { if ( ( viewChild = child( docChild->document() ) ) ) { if ( viewChild->frameRegion( m ).contains( pos ) ) return 0; } else if ( docChild->frameRegion( m ).contains( pos ) ) return 0; } QPoint pos2( int(pos.x() / zoom()), int(pos.y() / zoom()) ); QPtrListIterator it( m_pDoc->children() ); for (; it.current(); ++it ) { // Is the child document on the visible table ? if ( ((KSpreadChild*)it.current())->table() == m_pTable ) { KoDocument *doc = it.current()->hitTest( pos2, m ); if ( doc ) return doc; } } return m_pDoc; } int KSpreadView::leftBorder() const { return YBORDER_WIDTH; } int KSpreadView::rightBorder() const { return m_pVertScrollBar->width(); } int KSpreadView::topBorder() const { return m_pToolWidget->height() + XBORDER_HEIGHT; } int KSpreadView::bottomBorder() const { return m_pHorzScrollBar->height(); } void KSpreadView::refreshView() { bool active=activeTable()->getShowFormula(); m_alignLeft->setEnabled(!active); m_alignCenter->setEnabled(!active); m_alignRight->setEnabled(!active); active=m_pDoc->getShowFormulaBar(); editWidget()->showEditWidget(active); int posFrame=30; if(active) posWidget()->show(); else { posWidget()->hide(); posFrame=0; } m_pToolWidget->show(); // If this value (30) is changed then topBorder() needs to // be changed, too. m_pToolWidget->setGeometry( 0, 0, width(), /*30*/posFrame ); int top = /*30*/posFrame; if(m_pDoc->getShowTabBar()) { m_pTabBarFirst->setGeometry( 0, height() - 16, 16, 16 ); m_pTabBarLeft->setGeometry( 16, height() - 16, 16, 16 ); m_pTabBarRight->setGeometry( 32, height() - 16, 16, 16 ); m_pTabBarLast->setGeometry( 48, height() - 16, 16, 16 ); m_pTabBarFirst->show(); m_pTabBarLeft->show(); m_pTabBarRight->show(); m_pTabBarLast->show(); } else { m_pTabBarFirst->hide(); m_pTabBarLeft->hide(); m_pTabBarRight->hide(); m_pTabBarLast->hide(); } if(!m_pDoc->getShowHorizontalScrollBar()) m_pTabBar->setGeometry( 64, height() - 16, width() -64, 16 ); else m_pTabBar->setGeometry( 64, height() - 16, width() / 2 - 64, 16 ); if(m_pDoc->getShowTabBar()) m_pTabBar->show(); else m_pTabBar->hide(); // David's suggestion: move the scrollbars to KSpreadCanvas, but keep those resize statements int widthScrollbarVertical=16; if(m_pDoc->getShowHorizontalScrollBar()) m_pHorzScrollBar->show(); else m_pHorzScrollBar->hide(); if(!m_pDoc->getShowTabBar() && !m_pDoc->getShowHorizontalScrollBar()) m_pVertScrollBar->setGeometry( width() - 16, top , 16, height() - top ); else m_pVertScrollBar->setGeometry( width() - 16, top , 16, height() - 16 - top ); m_pVertScrollBar->setSteps( 20 /*linestep*/, m_pVertScrollBar->height() /*pagestep*/); if(m_pDoc->getShowVerticalScrollBar()) m_pVertScrollBar->show(); else { widthScrollbarVertical=0; m_pVertScrollBar->hide(); } int widthRowHeader=YBORDER_WIDTH; if(m_pDoc->getShowRowHeader()) m_pVBorderWidget->show(); else { widthRowHeader=0; m_pVBorderWidget->hide(); } int heightColHeader=XBORDER_HEIGHT; if(m_pDoc->getShowColHeader()) m_pHBorderWidget->show(); else { heightColHeader=0; m_pHBorderWidget->hide(); } if(statusBar()) { if(m_pDoc->getShowStatusBar()) statusBar()->show(); else statusBar()->hide(); } m_pHorzScrollBar->setGeometry( width() / 2, height() - 16, width() / 2 - widthScrollbarVertical, 16 ); m_pHorzScrollBar->setSteps( 20 /*linestep*/, m_pHorzScrollBar->width() /*pagestep*/); if(!m_pDoc->getShowTabBar() && !m_pDoc->getShowHorizontalScrollBar()) m_pFrame->setGeometry( 0, top, width()-widthScrollbarVertical, height() - top ); else m_pFrame->setGeometry( 0, top, width()-widthScrollbarVertical, height() -16 - top ); m_pFrame->show(); m_pCanvas->setGeometry( widthRowHeader, heightColHeader, m_pFrame->width() -widthRowHeader, m_pFrame->height() - heightColHeader ); m_pHBorderWidget->setGeometry( widthRowHeader, 0, m_pFrame->width() - widthRowHeader, heightColHeader ); m_pVBorderWidget->setGeometry( 0,heightColHeader, widthRowHeader, m_pFrame->height() - heightColHeader ); } void KSpreadView::resizeEvent( QResizeEvent * ) { refreshView(); } void KSpreadView::popupChildMenu( KoChild* child, const QPoint& global_pos ) { if ( !child ) return; if ( m_popupChild != 0 ) delete m_popupChild; m_popupChildObject = static_cast(child); m_popupChild = new QPopupMenu( this ); m_popupChild->insertItem( i18n("Delete embedded document"), this, SLOT( slotPopupDeleteChild() ) ); m_popupChild->popup( global_pos ); } void KSpreadView::slotPopupDeleteChild() { if ( !m_popupChildObject || !m_popupChildObject->table() ) return; int ret = KMessageBox::warningYesNo(this,i18n("You are going to remove this embedded document.\nDo you want to continue?"),i18n("Delete embedded document")); if ( ret == KMessageBox::Yes ) { m_popupChildObject->table()->deleteChild( m_popupChildObject ); m_popupChildObject = 0; } } void KSpreadView::popupColumnMenu(const QPoint & _point) { assert( m_pTable ); if ( !koDocument()->isReadWrite() ) return; if (m_pPopupColumn != 0L ) delete m_pPopupColumn ; m_pPopupColumn = new QPopupMenu( this ); m_cellLayout->plug( m_pPopupColumn ); m_pPopupColumn->insertSeparator(); m_cut->plug( m_pPopupColumn ); m_copy->plug( m_pPopupColumn ); m_paste->plug( m_pPopupColumn ); m_specialPaste->plug( m_pPopupColumn ); m_insertCellCopy->plug( m_pPopupColumn ); m_pPopupColumn->insertSeparator(); m_default->plug( m_pPopupColumn ); // If there is no selection if((activeTable()->isRowSelected() == FALSE) && (activeTable()->isColumnSelected() == FALSE) ) { m_areaName->plug( m_pPopupColumn ); } m_resizeColumn->plug( m_pPopupColumn ); m_pPopupColumn->insertItem( i18n("Adjust Column"), this, SLOT(slotPopupAdjustColumn() ) ); m_pPopupColumn->insertSeparator(); m_insertColumn->plug( m_pPopupColumn ); m_deleteColumn->plug( m_pPopupColumn ); m_hideColumn->plug( m_pPopupColumn ); m_showSelColumns->setEnabled(false); int i; ColumnLayout * col; QRect rect = activeTable()->selectionRect(); kdDebug(36001) << "Column: L: " << rect.left() << endl; for ( i = rect.left(); i <= rect.right(); ++i ) { if (i == 2) // "B" { col = activeTable()->columnLayout( 1 ); if ( col->isHide() ) { m_showSelColumns->setEnabled(true); m_showSelColumns->plug( m_pPopupColumn ); break; } } col = activeTable()->columnLayout( i ); if ( col->isHide() ) { m_showSelColumns->setEnabled(true); m_showSelColumns->plug( m_pPopupColumn ); break; } } QObject::connect( m_pPopupColumn, SIGNAL(activated( int ) ), this, SLOT(slotActivateTool( int ) ) ); m_pPopupColumn->popup( _point ); } void KSpreadView::slotPopupAdjustColumn() { if ( !m_pTable ) return; canvasWidget()->adjustArea(); } void KSpreadView::popupRowMenu(const QPoint & _point ) { assert( m_pTable ); if ( !koDocument()->isReadWrite() ) return; if (m_pPopupRow != 0L ) delete m_pPopupRow ; m_pPopupRow= new QPopupMenu(); m_cellLayout->plug( m_pPopupRow ); m_pPopupRow->insertSeparator(); m_cut->plug( m_pPopupRow ); m_copy->plug( m_pPopupRow ); m_paste->plug( m_pPopupRow ); m_specialPaste->plug( m_pPopupRow ); m_insertCellCopy->plug( m_pPopupRow ); m_pPopupRow->insertSeparator(); m_default->plug( m_pPopupRow ); // If there is no selection if( (activeTable()->isRowSelected() == FALSE) && (activeTable()->isColumnSelected() == FALSE) ) { m_areaName->plug( m_pPopupRow ); } m_resizeRow->plug( m_pPopupRow ); m_pPopupRow->insertItem( i18n("Adjust Row"), this, SLOT( slotPopupAdjustRow() ) ); m_pPopupRow->insertSeparator(); m_insertRow->plug( m_pPopupRow ); m_deleteRow->plug( m_pPopupRow ); m_hideRow->plug( m_pPopupRow ); m_showSelColumns->setEnabled(false); int i; RowLayout * row; QRect rect = activeTable()->selectionRect(); for ( i = rect.top(); i <= rect.bottom(); ++i ) { kdDebug(36001) << "popupRow: " << rect.top() << endl; if (i == 2) { row = activeTable()->rowLayout( 1 ); if ( row->isHide() ) { m_showSelRows->setEnabled(true); m_showSelRows->plug( m_pPopupRow ); break; } } row = activeTable()->rowLayout( i ); if ( row->isHide() ) { m_showSelRows->setEnabled(true); m_showSelRows->plug( m_pPopupRow ); break; } } QObject::connect( m_pPopupRow, SIGNAL( activated( int ) ), this, SLOT( slotActivateTool( int ) ) ); m_pPopupRow->popup( _point ); } void KSpreadView::slotPopupAdjustRow() { if ( !m_pTable ) return; canvasWidget()->adjustArea(); } void KSpreadView::slotListChoosePopupMenu( ) { assert( m_pTable ); if ( m_popupListChoose != 0L ) delete m_popupListChoose; if(!koDocument()->isReadWrite() ) return; m_popupListChoose = new QPopupMenu(); int id = 0; QRect selection( m_pTable->selectionRect() ); if(selection.left()==0) selection.setCoords(m_pCanvas->markerColumn(),m_pCanvas->markerRow(), m_pCanvas->markerColumn(),m_pCanvas->markerRow()); KSpreadCell *cell = m_pTable->cellAt( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); QString tmp=cell->text(); QStringList itemList; KSpreadCell* c = m_pTable->firstCell(); for( ;c; c = c->nextCell() ) { int col = c->column(); if ( selection.left() <= col && selection.right() >= col &&!c->isObscuringForced()&& !(col==m_pCanvas->markerColumn()&& c->row()==m_pCanvas->markerRow())) { if(c->isString() && c->text()!=tmp && !c->text().isEmpty()) { if(itemList.findIndex(c->text())==-1) itemList.append(c->text()); } } } for ( QStringList::Iterator it = itemList.begin(); it != itemList.end();++it ) m_popupListChoose->insertItem( (*it), id++ ); if(id==0) return; RowLayout *rl = m_pTable->rowLayout( m_pCanvas->markerRow()); int tx = m_pTable->columnPos( m_pCanvas->markerColumn(), m_pCanvas ); int ty = m_pTable->rowPos(m_pCanvas->markerRow(), m_pCanvas ); int h = rl->height( m_pCanvas ); if ( cell->extraYCells()) h = cell->extraHeight(); ty += h; QPoint p( tx, ty ); QPoint p2 = m_pCanvas->mapToGlobal( p ); m_popupListChoose->popup( p2 ); QObject::connect( m_popupListChoose, SIGNAL( activated( int ) ), this, SLOT( slotItemSelected( int ) ) ); } void KSpreadView::slotItemSelected( int id) { QString tmp=m_popupListChoose->text(id); KSpreadCell *cell = m_pTable->nonDefaultCell( m_pCanvas->markerColumn(), m_pCanvas->markerRow(), true ); if(tmp==cell->text()) return; if ( !m_pDoc->undoBuffer()->isLocked() ) { KSpreadUndoSetText* undo = new KSpreadUndoSetText( m_pDoc, m_pTable, cell->text(), m_pCanvas->markerColumn(), m_pCanvas->markerRow(), cell->formatType()); m_pDoc->undoBuffer()->appendUndo( undo ); } cell->setCellText( tmp, true ); editWidget()->setText( tmp ); } void KSpreadView::openPopupMenu( const QPoint & _point ) { assert( m_pTable ); if ( m_pPopupMenu != 0L ) delete m_pPopupMenu; if(!koDocument()->isReadWrite() ) return; m_pPopupMenu = new QPopupMenu(); m_cellLayout->plug( m_pPopupMenu ); m_pPopupMenu->insertSeparator(); m_cut->plug( m_pPopupMenu ); m_copy->plug( m_pPopupMenu ); m_paste->plug( m_pPopupMenu ); m_copy_as_text->plug(m_pPopupMenu ); m_specialPaste->plug( m_pPopupMenu ); m_insertCellCopy->plug( m_pPopupMenu ); m_pPopupMenu->insertSeparator(); m_delete->plug( m_pPopupMenu ); m_adjust->plug( m_pPopupMenu ); m_default->plug( m_pPopupMenu ); // If there is no selection if( (activeTable()->isRowSelected() == FALSE) && (activeTable()->isColumnSelected() == FALSE) ) { m_areaName->plug( m_pPopupMenu ); m_pPopupMenu->insertSeparator(); m_insertCell->plug( m_pPopupMenu ); m_removeCell->plug( m_pPopupMenu ); } KSpreadCell *cell = m_pTable->cellAt( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); m_pPopupMenu->insertSeparator(); m_addModifyComment->plug( m_pPopupMenu ); if( !cell->comment(m_pCanvas->markerColumn(), m_pCanvas->markerRow()).isEmpty() ) { m_removeComment->plug( m_pPopupMenu ); } if(activeTable()->testListChoose(QPoint(m_pCanvas->markerColumn(), m_pCanvas->markerRow()))) { m_pPopupMenu->insertSeparator(); m_pPopupMenu->insertItem( i18n("Selection list..."), this, SLOT( slotListChoosePopupMenu() ) ); } // Remove informations about the last tools we offered m_lstTools.clear(); m_lstTools.setAutoDelete( true ); if(!activeTable()->getWordSpelling( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() )).isEmpty()) { m_popupMenuFirstToolId = 10; int i = 0; QValueList tools = KDataToolInfo::query( "QString", "text/plain", m_pDoc->instance() ); if( tools.count() > 0 ) { m_pPopupMenu->insertSeparator(); QValueList::Iterator entry = tools.begin(); for( ; entry != tools.end(); ++entry ) { QStringList lst = (*entry).userCommands(); QStringList::ConstIterator it = lst.begin(); // ### Torben: Insert pixmaps here, too for (; it != lst.end(); ++it ) m_pPopupMenu->insertItem( *it, m_popupMenuFirstToolId + i++ ); lst = (*entry).commands(); it = lst.begin(); for (; it != lst.end(); ++it ) { ToolEntry *t = new ToolEntry; t->command = *it; t->info = *entry; m_lstTools.append( t ); } } QObject::connect( m_pPopupMenu, SIGNAL( activated( int ) ), this, SLOT( slotActivateTool( int ) ) ); } } m_pPopupMenu->popup( _point ); } void KSpreadView::slotActivateTool( int _id ) { Q_ASSERT( m_pTable ); // Is it the id of a tool in the latest popupmenu ? if( _id < m_popupMenuFirstToolId ) return; ToolEntry* entry = m_lstTools.at( _id - m_popupMenuFirstToolId ); KDataTool* tool = entry->info.createTool(); if ( !tool ) { kdDebug(36001) << "Could not create Tool" << endl; return; } QString text = activeTable()->getWordSpelling( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() )); if ( tool->run( entry->command, &text, "QString", "text/plain") ) { activeTable()->setWordSpelling( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),text); KSpreadCell *cell = m_pTable->cellAt( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); editWidget()->setText( cell->text() ); } } void KSpreadView::deleteSelection() { Q_ASSERT( m_pTable ); m_pTable->deleteSelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); resultOfCalc(); updateEditWidget(); } void KSpreadView::adjust() { if( (activeTable()->isRowSelected()) || (activeTable()->isColumnSelected()) ) { KMessageBox::error( this, i18n("Area too large!")); } else { canvasWidget()->adjustArea(); } } void KSpreadView::clearTextSelection() { Q_ASSERT( m_pTable ); m_pTable->clearTextSelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::clearCommentSelection() { Q_ASSERT( m_pTable ); m_pTable->setSelectionRemoveComment( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::clearValiditySelection() { Q_ASSERT( m_pTable ); m_pTable->clearValiditySelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::clearConditionalSelection() { Q_ASSERT( m_pTable ); m_pTable->clearConditionalSelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::defaultSelection() { Q_ASSERT( m_pTable ); m_pTable->defaultSelection( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ); updateEditWidget(); } void KSpreadView::slotInsert() { QRect r( activeTable()-> selectionRect() ); if(r.left()==0) r.setCoords(m_pCanvas->markerColumn(), m_pCanvas->markerRow() ,m_pCanvas->markerColumn(), m_pCanvas->markerRow()); KSpreadinsert dlg( this, "Insert", r,KSpreadinsert::Insert ); dlg.exec(); } void KSpreadView::slotRemove() { QRect r( activeTable()-> selectionRect() ); if(r.left()==0) r.setCoords(m_pCanvas->markerColumn(), m_pCanvas->markerRow() ,m_pCanvas->markerColumn(), m_pCanvas->markerRow()); KSpreadinsert dlg( this, "Remove", r,KSpreadinsert::Remove ); dlg.exec(); } void KSpreadView::slotInsertCellCopy() { if ( !m_pTable ) return; QRect r( activeTable()->selectionRect() ); if(r.left()==0 ) r.setCoords(m_pCanvas->markerColumn(), m_pCanvas->markerRow() , m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); if( !m_pTable->testAreaPasteInsert()) m_pTable->paste( QPoint( r.left(), r.top() ) ,true, Normal,OverWrite,true); else { QRect r( activeTable()-> selectionRect() ); KSpreadpasteinsert dlg( this, "Remove", r ); dlg.exec(); } if(m_pTable->getAutoCalc()) m_pTable->recalc(); updateEditWidget(); } void KSpreadView::setAreaName() { KSpreadarea dlg( this, "Area Name",QPoint(m_pCanvas->markerColumn(), m_pCanvas->markerRow()) ); dlg.exec(); } void KSpreadView::showAreaName() { KSpreadreference dlg( this, "Show area" ); dlg.exec(); } void KSpreadView::resizeRow() { if( activeTable()->isColumnSelected() ) KMessageBox::error( this, i18n("Area too large!")); else { KSpreadresize2 dlg( this, "Resize row", KSpreadresize2::resize_row ); dlg.exec(); } } void KSpreadView::resizeColumn() { if( activeTable()->isRowSelected() ) KMessageBox::error( this, i18n("Area too large!")); else { KSpreadresize2 dlg( this, "Resize column", KSpreadresize2::resize_column ); dlg.exec(); } } void KSpreadView::equalizeRow() { if( activeTable()->isColumnSelected() ) KMessageBox::error( this, i18n("Area too large!")); else canvasWidget()->equalizeRow(); } void KSpreadView::equalizeColumn() { if( activeTable()->isRowSelected() ) KMessageBox::error( this, i18n("Area too large!")); else canvasWidget()->equalizeColumn(); } void KSpreadView::layoutDlg() { QRect selection( m_pTable->selectionRect() ); if ( selection.contains( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ) ) CellLayoutDlg dlg( this, m_pTable, selection.left(), selection.top(), selection.right(), selection.bottom() ); else CellLayoutDlg dlg( this, m_pTable, m_pCanvas->markerColumn(), m_pCanvas->markerRow(), m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); } void KSpreadView::paperLayoutDlg() { m_pDoc->paperLayoutDlg(); } void KSpreadView::multiRow( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) m_pTable->setSelectionMultiRow( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), b ); } void KSpreadView::alignLeft( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) { if ( !b ) m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Undefined ); else m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Left ); } } void KSpreadView::alignRight( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) { if ( !b ) m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Undefined ); else m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Right ); } } void KSpreadView::alignCenter( bool b ) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) { if ( !b ) m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Undefined ); else m_pTable->setSelectionAlign( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Center ); } } void KSpreadView::alignTop( bool b ) { if ( m_toolbarLock ) return; if ( !b ) return; if ( m_pTable != 0L ) m_pTable->setSelectionAlignY( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Top ); } void KSpreadView::alignBottom( bool b ) { if ( m_toolbarLock ) return; if ( !b ) return; if ( m_pTable != 0L ) m_pTable->setSelectionAlignY( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Bottom ); } void KSpreadView::alignMiddle( bool b ) { if ( m_toolbarLock ) return; if ( !b ) return; if ( m_pTable != 0L ) m_pTable->setSelectionAlignY( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), KSpreadLayout::Middle ); } void KSpreadView::moneyFormat(bool b) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) m_pTable->setSelectionMoneyFormat( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ),b ); updateEditWidget(); } void KSpreadView::precisionPlus() { if ( m_pTable != 0L ) m_pTable->setSelectionPrecision( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), 1 ); } void KSpreadView::precisionMinus() { if ( m_pTable != 0L ) m_pTable->setSelectionPrecision( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ), -1 ); } void KSpreadView::percent( bool b) { if ( m_toolbarLock ) return; if ( m_pTable != 0L ) m_pTable->setSelectionPercent( QPoint( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ) ,b ); updateEditWidget(); } void KSpreadView::insertObject() { KoDocumentEntry e = m_insertPart->documentEntry();//KoPartSelectDia::selectPart( m_pCanvas ); if ( e.isEmpty() ) return; (void)new KSpreadInsertHandler( this, m_pCanvas, e ); } void KSpreadView::insertChart() { if( activeTable()->isColumnSelected() || activeTable()->isRowSelected() ) { KMessageBox::error( this, i18n("Area too large!")); return; } QValueList vec = KoDocumentEntry::query( "'KOfficeChart' in ServiceTypes" ); if ( vec.isEmpty() ) { KMessageBox::error( this, i18n("No charting component registered") ); return; } (void)new KSpreadInsertHandler( this, m_pCanvas, vec[0], TRUE ); } /* // TODO Use KoView setScaling/xScaling/yScaling instead void KSpreadView::zoomMinus() { if ( m_fZoom <= 0.25 ) return; m_fZoom -= 0.25; if ( m_pTable != 0L ) m_pTable->setLayoutDirtyFlag(); m_pCanvas->repaint(); m_pVBorderWidget->repaint(); m_pHBorderWidget->repaint(); } void KSpreadView::zoomPlus() { if ( m_fZoom >= 3 ) return; m_fZoom += 0.25; if ( m_pTable != 0L ) m_pTable->setLayoutDirtyFlag(); m_pCanvas->repaint(); m_pVBorderWidget->repaint(); m_pHBorderWidget->repaint(); } */ void KSpreadView::removeTable() { if ( doc()->map()->count() <= 1||(m_pTabBar->listshow().count()<=1) ) { KNotifyClient::beep(); KMessageBox::sorry( this, i18n("You cannot delete the only table of the map."), i18n("Remove table") ); // FIXME bad english? no english! return; } KNotifyClient::beep(); int ret = KMessageBox::warningYesNo(this,i18n("You are going to remove the active table.\nDo you want to continue?"),i18n("Remove table")); if ( ret == KMessageBox::Yes ) { if ( m_pCanvas->editor() ) { m_pCanvas->deleteEditor( false ); } m_pDoc->setModified( true ); KSpreadTable *tbl = activeTable(); tbl->removeTable(); doc()->map()->removeTable( tbl ); delete tbl; } } void KSpreadView::slotRename() { m_pTabBar->slotRename(); } void KSpreadView::setText( const QString& _text ) { if ( m_pTable == 0L ) return; m_pTable->setText( m_pCanvas->markerRow(), m_pCanvas->markerColumn(), _text ); KSpreadCell* cell = m_pTable->cellAt( m_pCanvas->markerColumn(), m_pCanvas->markerRow() ); if(cell->isString() && !_text.isEmpty() && !_text.at(0).isDigit()) m_pDoc->addStringCompletion(_text); } //------------------------------------------------ // // Document signals // //------------------------------------------------ void KSpreadView::slotAddTable( KSpreadTable *_table ) { addTable( _table ); } void KSpreadView::slotUpdateView( KSpreadTable *_table ) { // kdDebug(36001)<<"void KSpreadView::slotUdateView( KSpreadTable *_table )\n"; // Do we display this table ? if ( _table != m_pTable ) return; m_pCanvas->update(); } void KSpreadView::slotUpdateView( KSpreadTable *_table, const QRect& _rect ) { // qDebug("void KSpreadView::slotUpdateView( KSpreadTable *_table, const QRect& %i %i|%i %i )\n",_rect.left(),_rect.top(),_rect.right(),_rect.bottom()); // Do we display this table ? if ( _table != m_pTable ) return; m_pCanvas->updateCellRect( _rect ); } void KSpreadView::slotUpdateHBorder( KSpreadTable *_table ) { // kdDebug(36001)<<"void KSpreadView::slotUpdateHBorder( KSpreadTable *_table )\n"; // Do we display this table ? if ( _table != m_pTable ) return; m_pHBorderWidget->update(); } void KSpreadView::slotUpdateVBorder( KSpreadTable *_table ) { // kdDebug("void KSpreadView::slotUpdateVBorder( KSpreadTable *_table )\n"; // Do we display this table ? if ( _table != m_pTable ) return; m_pVBorderWidget->update(); } void KSpreadView::slotChangeChooseSelection( KSpreadTable *_table, const QRect &_old, const QRect &_new ) { // Do we display this table ? if ( _table != m_pTable ) return; m_pCanvas->updateChooseMarker( _old, _new ); // Emit a signal for internal use emit sig_chooseSelectionChanged( _table, _new ); } void KSpreadView::slotChangeSelection( KSpreadTable *_table, const QRect &_old, const QRect& _old_marker ) { QRect n = _table->selectionRect(); // QRect m = _table->marker(); // printf ("void KSpreadView::slotChangeSelection( KSpreadTable *_table, const QRect &_old %i %i|%i %i, const QPoint &m %i %i )\n",_old.left(),_old.top(),_old.right(),_old.bottom(),_old_marker.x(),_old_marker.y() ); // printf (" const QRect &_new %i %i|%i %i, const QPoint &m %i %i )\n",n.left(),n.top(),n.right(),n.bottom(),m.x(),m.y() ); // Emit a signal for internal use emit sig_selectionChanged( _table, n ); // Empty selection ? // Activate or deactivate some actions. This code is duplicated // in KSpreadView::slotUnselect if ( ( n.left() == 0 && n.top() == 0 ) || _table->isRowSelected() || _table->isColumnSelected() ) { m_tableFormat->setEnabled( FALSE ); m_mergeCell->setEnabled(false); m_insertChartFrame->setEnabled(false); } else { m_tableFormat->setEnabled( TRUE ); m_mergeCell->setEnabled(true); m_insertChartFrame->setEnabled(true); } if( _table->isColumnSelected() ) { m_resizeRow->setEnabled(false); m_equalizeRow->setEnabled(false); } else { m_resizeRow->setEnabled(true); m_equalizeRow->setEnabled(true); } if( _table->isRowSelected() ) { m_resizeColumn->setEnabled(false); m_equalizeColumn->setEnabled(false); } else { m_resizeColumn->setEnabled(true); m_equalizeColumn->setEnabled(true); } resultOfCalc(); // Send some event around. This is read for example // by the calculator plugin. KSpreadSelectionChanged ev( n, activeTable()->name() ); QApplication::sendEvent( this, &ev ); // Do we display this table ? if ( _table != m_pTable ) return; m_pCanvas->updateSelection( _old, _old_marker ); m_pVBorderWidget->update(); m_pHBorderWidget->update(); } void KSpreadView::resultOfCalc() { double result=0.0; int nbCell=0; QRect n = activeTable()->selectionRect(); QRect tmpRect(n); if(n.left()==0) tmpRect.setCoords( m_pCanvas->markerColumn(), m_pCanvas->markerRow(), m_pCanvas->markerColumn(), m_pCanvas->markerRow()); MethodOfCalc tmpMethod=m_pDoc->getTypeOfCalc() ; if( activeTable()->isColumnSelected() ) { KSpreadCell* c = activeTable()->firstCell(); for( ;c; c = c->nextCell() ) { int col = c->column(); if ( tmpRect.left() <= col && tmpRect.right() >= col &&!c->isObscuringForced()) { if(c->isNumeric()) { double val=c->valueDouble(); switch(tmpMethod) { case SumOfNumber: result+=val; break; case Average: result+=val; break; case Min: if(result!=0) result=QMIN(val,result); else result=val; break; case Max: if(result!=0) result=QMAX(val,result); else result=val; break; case Count: break; default: break; } nbCell++; } } } } else if( activeTable()->isRowSelected() ) { KSpreadCell* c = activeTable()->firstCell(); for( ; c; c = c->nextCell() ) { int row = c->row(); if ( tmpRect.top() <= row && tmpRect.bottom() >= row &&!c->isObscuringForced()) { if(c->isNumeric()) { double val=c->valueDouble(); switch(tmpMethod ) { case SumOfNumber: result+=val; break; case Average: result+=val; break; case Min: if(result!=0) result=QMIN(val,result); else result=val; break; case Max: if(result!=0) result=QMAX(val,result); else result=val; break; case Count: break; default: break; } nbCell++; } } } } else { for (int i=tmpRect.left();i<=tmpRect.right();i++) for(int j=tmpRect.top();j<=tmpRect.bottom();j++) { KSpreadCell *cell = activeTable()->cellAt( i, j ); if(!cell->isDefault() && cell->isNumeric()) { double val= cell->valueDouble(); switch(tmpMethod ) { case SumOfNumber: result+=val; break; case Average: result+=val; break; case Min: if(result!=0) result=QMIN(val,result); else result=val; break; case Max: if(result!=0) result=QMAX(val,result); else result=val; break; case Count: break; default: break; } nbCell++; } } } QString tmp; switch(tmpMethod ) { case SumOfNumber: tmp=i18n(" Sum: %1").arg(result); break; case Average: result=result/nbCell; tmp=i18n("Average: %1").arg(result); break; case Min: tmp=i18n("Min: %1").arg(result); break; case Max: tmp=i18n("Max: %1").arg(result); break; case Count: tmp=i18n("Count: %1").arg(nbCell); break; } if ( m_sbCalcLabel ) m_sbCalcLabel->setText(QString(" ")+tmp+' '); } void KSpreadView::statusBarClicked(int _id) { if(!koDocument()->isReadWrite() ) return; if(_id==0) //menu calc { QPoint mousepos =QCursor::pos(); ((QPopupMenu*)factory()->container("calc_popup",this))->popup(mousepos); } } void KSpreadView::menuCalc(bool) { if( m_menuCalcMin->isChecked()) { doc()->setTypeOfCalc(Min); } else if(m_menuCalcMax->isChecked()) { doc()->setTypeOfCalc(Max); } else if(m_menuCalcCount->isChecked()) { doc()->setTypeOfCalc(Count); } else if(m_menuCalcAverage->isChecked()) { doc()->setTypeOfCalc(Average); } else if(m_menuCalcSum->isChecked()) { doc()->setTypeOfCalc(SumOfNumber); } resultOfCalc(); } void KSpreadView::slotUnselect( KSpreadTable *_table, const QRect& _old ) { // Do we display this table ? if ( _table != m_pTable ) return; // Unselect the action which only works on a selection // with mutiple cells. m_tableFormat->setEnabled( FALSE ); m_mergeCell->setEnabled(false); m_insertChartFrame->setEnabled(false); m_pCanvas->updateSelection( _old, _table->marker() ); m_pVBorderWidget->update(); m_pHBorderWidget->update(); } void KSpreadView::repaintPolygon( const QPointArray& polygon ) { QPointArray arr = polygon; QWMatrix m = matrix()/*.invert()*/; for( int i = 0; i < 4; ++i ) arr.setPoint( i, m.map( arr.point( i ) ) ); emit regionInvalidated( QRegion( arr ), TRUE ); } void KSpreadView::paintContent( QPainter& painter, const QRect& rect, bool transparent ) { m_pDoc->paintContent( painter, rect, transparent, activeTable() ); } QWMatrix KSpreadView::matrix() const { QWMatrix m; m.translate( -m_pCanvas->xOffset(), -m_pCanvas->yOffset() ); m.scale( zoom(), zoom() ); return m; } void KSpreadView::transformPart() { Q_ASSERT( selectedChild() ); if ( m_transformToolBox.isNull() ) { m_transformToolBox = new KoTransformToolBox( selectedChild(), topLevelWidget() ); m_transformToolBox->show(); m_transformToolBox->setDocumentChild( selectedChild() ); } else { m_transformToolBox->show(); m_transformToolBox->raise(); } } void KSpreadView::slotChildSelected( KoDocumentChild* ch ) { m_transform->setEnabled( TRUE ); if ( !m_transformToolBox.isNull() ) { m_transformToolBox->setEnabled( TRUE ); m_transformToolBox->setDocumentChild( ch ); } } void KSpreadView::slotChildUnselected( KoDocumentChild* ) { m_transform->setEnabled( FALSE ); if ( !m_transformToolBox.isNull() ) { m_transformToolBox->setEnabled( FALSE ); } } void KSpreadView::deleteEditor( bool saveChanges ) { m_pCanvas->deleteEditor( saveChanges ); } DCOPObject* KSpreadView::dcopObject() { if ( !m_dcop ) m_dcop = new KSpreadViewIface( this ); return m_dcop; } QWidget *KSpreadView::canvas() { return canvasWidget(); } int KSpreadView::canvasXOffset() const { return canvasWidget()->xOffset(); } int KSpreadView::canvasYOffset() const { return canvasWidget()->yOffset(); } void KSpreadView::guiActivateEvent( KParts::GUIActivateEvent *ev ) { if ( ev->activated() ) { if ( m_sbCalcLabel ) { resultOfCalc(); } } else { /*if(m_sbCalcLabel) { disconnect(m_sbCalcLabel,SIGNAL(pressed( int )),this,SLOT(statusBarClicked(int))); }*/ } KoView::guiActivateEvent( ev ); } void KSpreadView::openPopupMenuMenuPage( const QPoint & _point ) { if(!koDocument()->isReadWrite() ) return; static_cast(factory()->container("menupage_popup",this))->popup(_point); } void KSpreadView::updateBorderButton() { m_showPageBorders->setChecked( m_pTable->isShowPageBorders() ); } #include "kspread_view.moc" diff --git a/kspread/kspread_view.h b/kspread/kspread_view.h index db62d9689e..e8836bf85e 100644 --- a/kspread/kspread_view.h +++ b/kspread/kspread_view.h @@ -1,664 +1,665 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __kspread_gui_h__ #define __kspread_gui_h__ class QFrame; class QScrollBar; class QButton; class KSpreadView; class KSpreadEditWidget; class KSpreadCanvas; class KSpreadHBorder; class KSpreadVBorder; class KSpreadScripts; class KSpreadTable; class KSpreadDoc; class KSpreadPaperLayout; class KSpreadChildPicture; class KSpreadChildFrame; class KSpreadShell; class KSpreadTabBar; class KSpreadEditWidget; class KSpreadCanvas; class KSpreadHBorder; class KSpreadVBorder; class KSpreadChild; class KSpreadCell; class KSpreadLocationEditWidget; class KoDocumentEntry; class KStatusBarLabel; class TKSelectColorAction; class KAction; class KSelectAction; class KFontAction; class KFontSizeAction; class KToggleAction; class KoPartSelectAction; class KSpreadSpell; //class KMacroCommand; class KActionMenu; class DCOPObject; #include #include #include #include #include #include #include #include #include /** */ class KSpreadView : public KoView { friend class KSpreadCanvas; Q_OBJECT public: KSpreadView( QWidget *_parent, const char *_name, KSpreadDoc *_doc ); ~KSpreadView(); KSpreadCanvas* canvasWidget() const { return m_pCanvas; } KSpreadHBorder* hBorderWidget() { return m_pHBorderWidget; } KSpreadVBorder* vBorderWidget() { return m_pVBorderWidget; } QScrollBar* horzScrollBar() { return m_pHorzScrollBar; } QScrollBar* vertScrollBar() { return m_pVertScrollBar; } KSpreadEditWidget* editWidget() { return m_pEditWidget; } //QLabel* posWidget() { return m_pPosWidget; } KSpreadLocationEditWidget* posWidget() { return m_pPosWidget; } KSpreadDoc* doc() { return m_pDoc; } void addTable( KSpreadTable *_t ); //void removeTable( KSpreadTable *_t ); void removeAllTables(); void setActiveTable( KSpreadTable *_t,bool updateTable=true ); const KSpreadTable* activeTable() const { return m_pTable; } KSpreadTable* activeTable() { return m_pTable; } KSpreadTabBar* tabBar() { return m_pTabBar;} void openPopupMenu( const QPoint &_global ); void popupRowMenu(const QPoint & _point ) ; void popupColumnMenu( const QPoint & _point); // void showFormulaToolBar( bool show ); /** * Used by @ref KSpreadEditWidget. Sets the text of the active cell. */ void setText( const QString& _text ); void enableUndo( bool _b ); void enableRedo( bool _b ); /** * Called by @ref KSpreadInsertHandler * * @param _geometry is the zoomed geometry of the new child. */ void insertChart( const QRect& _geometry, KoDocumentEntry& _entry ); /** * Called by @ref KSpreadInsertHandler * * @param _geometry is the geometry of the new child. */ void insertChild( const QRect& _geometry, KoDocumentEntry& _entry ); virtual void print( KPrinter &printer ); virtual void setupPrinter( KPrinter &printer ); void paintContent( QPainter& painter, const QRect& rect, bool transparent ); /** * Fills the @ref KSpreadEditWidget with the current cells * content. This function is usually called after the * cursor moved. */ void updateEditWidget(); /** * Called before saving, to finish the current edition (if any) */ void deleteEditor( bool saveChanges = true ); virtual DCOPObject* dcopObject(); virtual QWidget *canvas(); virtual int canvasXOffset() const; virtual int canvasYOffset() const; /** * @reimp */ KoDocument *hitTest( const QPoint &pos ); void initConfig(); /** * refresh view when you hide/show vertical scrollbar */ void refreshView(); bool isLoading() {return m_bLoading;} /** * write in statusBar result of calc (Min, or Max, average, sum, count) */ void resultOfCalc(); void initCalcMenu(); void changeNbOfRecentFiles(int _nb); void openPopupMenuMenuPage( const QPoint & _point ); void updateBorderButton(); public slots: void initialPosition(); /** * Actions */ void transformPart(); void copySelection(); void cutSelection(); void deleteSelection(); void clearTextSelection(); void clearCommentSelection(); void clearValiditySelection(); void clearConditionalSelection(); void RecalcWorkBook(); void RecalcWorkSheet(); void paste(); void specialPaste(); void editCell(); void setAreaName(); void showAreaName(); void undo(); void redo(); void adjust(); void defaultSelection(); void paperLayoutDlg(); void insertObject(); void editGlobalScripts(); void editLocalScripts(); void reloadScripts(); void runLocalScript(); void togglePageBorders( bool ); void find(); void replace(); void conditional(); void validity(); void insertSeries(); void sort(); void insertHyperlink(); void consolidate(); void insertTable(); void removeTable(); void hideTable(); void showTable(); void helpUsing(); void insertChart(); void moneyFormat(bool b); void alignLeft( bool b ); void alignRight( bool b ); void alignCenter( bool b ); void alignTop( bool b ); void alignMiddle( bool b ); void alignBottom( bool b ); void multiRow( bool b ); void precisionMinus(); void precisionPlus(); void percent(bool b); void fontSelected( const QString &_font ); void fontSizeSelected( int size ); void bold( bool b ); void italic( bool b ); void underline( bool b ); void strikeOut( bool b ); void deleteColumn(); void insertColumn(); void deleteRow(); void insertRow(); void hideRow(); void showRow(); void showSelRows(); void hideColumn(); void showColumn(); void showSelColumns(); void insertMathExpr(); void formulaSelection( const QString &_math ); void changeTextColor(); void changeBackgroundColor(); void sortInc(); void sortDec(); void layoutDlg(); void borderBottom(); void borderRight(); void borderLeft(); void borderTop(); void borderOutline(); void borderAll(); void borderRemove(); void changeBorderColor(); void tableFormat(); // void oszilloscope(); void autoSum(); void resizeRow(); void resizeColumn(); void increaseFontSize(); void decreaseFontSize(); void upper(); void lower(); void equalizeColumn(); void equalizeRow(); void preference(); void firstLetterUpper(); void verticalText(bool ); void addModifyComment(); void removeComment(); void changeAngle(); void mergeCell(); void dissociateCell(); void gotoCell(); void increaseIndent(); void decreaseIndent(); void copyAsText(); /** * @ref #tabBar is connected to this slot. * When the user selects a new table using the @ref #tabBar this slot * is signaled. */ void changeTable( const QString& _name ); void nextTable(); void previousTable(); void sortList(); void statusBarClicked(int _id); void menuCalc(bool); protected slots: /** * Popup menu */ void slotActivateTool( int _id ); void slotInsert(); void slotInsertCellCopy(); void slotRemove(); void slotRename(); /** * Invoked if the popup menu for an embedded document should be opened. */ void popupChildMenu( KoChild*, const QPoint& global_pos ); void slotPopupDeleteChild(); /** * Border popup menu */ void slotPopupAdjustColumn(); void slotPopupAdjustRow(); /** * Scroll @ref #tabBar. */ void slotScrollToFirstTable(); /** * Scroll @ref #tabBar. */ void slotScrollToLeftTable(); /** * Scroll @ref #tabBar. */ void slotScrollToRightTable(); /** * Scroll @ref #tabBar. */ void slotScrollToLastTable(); /** * list from list choose */ void slotItemSelected( int ); void slotListChoosePopupMenu( ); protected slots: void repaintPolygon( const QPointArray& ); void slotChildSelected( KoDocumentChild* ch ); void slotChildUnselected( KoDocumentChild* ); public slots: // Document signals void slotUnselect( KSpreadTable *_table, const QRect& _old ); void slotUpdateView( KSpreadTable *_table ); void slotUpdateView( KSpreadTable *_table, const QRect& ); void slotUpdateHBorder( KSpreadTable *_table ); void slotUpdateVBorder( KSpreadTable *_table ); void slotChangeSelection( KSpreadTable *_table, const QRect &_old, const QRect &_old_marker ); void slotChangeChooseSelection( KSpreadTable *_table, const QRect &_old, const QRect &_new ); void slotAddTable( KSpreadTable *_table ); void slotRemoveChild( KSpreadChild *_child ); void slotUpdateChildGeometry( KSpreadChild *_child ); void slotTableRenamed( KSpreadTable* table, const QString& old_name ); void slotTableHidden( KSpreadTable*_table ); void slotTableShown( KSpreadTable*_table ); void slotTableRemoved( KSpreadTable*_table ); void slotTableActivated( KSpreadTable* table ); void slotRefreshView( ); void slotRefreshLocale(); void extraSpelling(); void spellCheckerReady(); void spellCheckerMisspelling( const QString &, const QStringList &, unsigned int); void spellCheckerCorrected( const QString &, const QString &, unsigned int); void spellCheckerDone( const QString & ); void spellCheckerFinished( ); void startKSpell(); virtual int leftBorder() const; virtual int rightBorder() const; virtual int topBorder() const; virtual int bottomBorder() const; signals: void sig_selectionChanged( KSpreadTable* _table, const QRect& _selection ); void sig_chooseSelectionChanged( KSpreadTable* _table, const QRect& _selection ); protected: // bool eventKeyPressed( QKeyEvent* _event, bool choose ); virtual void keyPressEvent ( QKeyEvent * _ev ); virtual void resizeEvent( QResizeEvent *_ev ); virtual QWMatrix matrix() const; /** * Activates the formula editor for the current cell. * This function is usually called if the user presses * a button in the formula toolbar. */ void activateFormulaEditor(); virtual void updateReadWrite( bool readwrite ); virtual void guiActivateEvent( KParts::GUIActivateEvent *ev ); private: // GUI stuff QButton* newIconButton( const char *_file, bool _kbutton = false, QWidget *_parent = 0L ); QScrollBar *m_pHorzScrollBar; QScrollBar *m_pVertScrollBar; KSpreadCanvas *m_pCanvas; KSpreadVBorder *m_pVBorderWidget; KSpreadHBorder *m_pHBorderWidget; KSpreadEditWidget *m_pEditWidget; QWidget *m_pFrame; QFrame *m_pToolWidget; QButton *m_pTabBarFirst; QButton *m_pTabBarLeft; QButton *m_pTabBarRight; QButton *m_pTabBarLast; QButton *m_pOkButton; QButton *m_pCancelButton; KSpreadTabBar *m_pTabBar; //QLabel *m_pPosWidget; KSpreadLocationEditWidget *m_pPosWidget; KToggleAction* m_bold; KToggleAction* m_italic; KToggleAction* m_underline; KToggleAction* m_strikeOut; KToggleAction* m_percent; KAction* m_precplus; KAction* m_precminus; KToggleAction* m_money; KToggleAction* m_alignLeft; KToggleAction* m_alignCenter; KToggleAction* m_alignRight; KToggleAction* m_alignTop; KToggleAction* m_alignMiddle; KToggleAction* m_alignBottom; KAction* m_transform; KAction* m_copy; KAction* m_copy_as_text; KAction* m_paste; KAction* m_cut; KAction* m_specialPaste; KAction* m_delete; KAction* m_clearText; KAction* m_clearComment; KAction* m_clearValidity; KAction* m_clearConditional; KAction* m_recalc_workbook; KAction* m_recalc_worksheet; KAction* m_adjust; KAction* m_editCell; KAction* m_undo; KAction* m_redo; KAction* m_paperLayout; KAction* m_insertTable; KAction* m_removeTable; KAction* m_renameTable; KAction* m_editGlobalScripts; KAction* m_editLocalScripts; KAction* m_reloadScripts; KAction* m_conditional; KAction* m_validity; KAction* m_sort; KAction* m_consolidate; KAction* m_help; KAction* m_insertCellCopy; KToggleAction* m_multiRow; KFontAction* m_selectFont; KFontSizeAction* m_selectFontSize; KAction* m_deleteColumn; KAction* m_hideColumn; KAction* m_showColumn; KAction* m_showSelColumns; KAction* m_insertColumn; KAction* m_deleteRow; KAction* m_insertRow; KAction* m_hideRow; KAction* m_showRow; KAction* m_showSelRows; KSelectAction* m_formulaSelection; KAction* m_sortDec; KAction* m_sortInc; TKSelectColorAction* m_textColor; TKSelectColorAction* m_bgColor; KAction* m_cellLayout; KAction* m_hideTable; KAction* m_showTable; KAction* m_borderLeft; KAction* m_borderRight; KAction* m_borderTop; KAction* m_borderBottom; KAction* m_borderAll; KAction* m_borderOutline; KAction* m_borderRemove; TKSelectColorAction* m_borderColor; KAction* m_tableFormat; // KAction* m_oszi; KAction* m_autoSum; KToggleAction* m_showPageBorders; KActionMenu* m_scripts; KAction* m_default; KAction* m_areaName; KAction* m_showArea; KAction* m_resizeRow; KAction* m_resizeColumn; KAction* m_fontSizeUp; KAction* m_fontSizeDown; KAction* m_upper; KAction* m_lower; KAction* m_equalizeRow; KAction* m_equalizeColumn; KAction* m_preference; KAction* m_firstLetterUpper; KToggleAction* m_verticalText; KAction* m_addModifyComment; KAction* m_removeComment; KAction* m_insertCell; KAction* m_removeCell; KAction* m_changeAngle; KAction* m_mergeCell; KAction* m_dissociateCell; KAction* m_gotoCell; KAction* m_increaseIndent; KAction* m_decreaseIndent; KAction* m_sortList; KAction* m_spellChecking; KAction* m_insertChartFrame; KToggleAction* m_menuCalcMin; KToggleAction* m_menuCalcMax; KToggleAction* m_menuCalcAverage; KToggleAction* m_menuCalcCount; KToggleAction* m_menuCalcSum; KoPartSelectAction *m_insertPart; // Spell-checking + QStringList m_ignoreWord; struct { KSpreadSpell * kspell; KSpreadTable * firstSpellTable; KSpreadTable * currentSpellTable; KSpreadCell * currentCell; unsigned int spellCurrCellX; unsigned int spellCurrCellY; unsigned int spellStartCellX; unsigned int spellStartCellY; unsigned int spellEndCellX; unsigned int spellEndCellY; bool spellCheckSelection; QStringList ignoreWord; // KMacroCommand * macroCmdSpellCheck; } m_spell; bool spellSwitchToOtherTable(); void spellCleanup(); /** * Pointer to the last popup menu. * Since only one popup menu can be opened at once, its pointer is stored here. * Delete the old one before you store a pointer to anotheron here. * May be 0L. */ QPopupMenu *m_pPopupMenu; int m_popupMenuFirstToolId; QPopupMenu *m_pPopupRow; QPopupMenu *m_pPopupColumn; /** * Used for embedded children. */ QPopupMenu* m_popupChild; /** * used for list of choose */ QPopupMenu* m_popupListChoose; /** * Holds a pointer of the child for which the popup menu has been opened. */ KSpreadChild* m_popupChildObject; /** * This DCOP object represents the view. */ DCOPObject* m_dcop; /** * Tells whether the user modfied the current cell. * Some key events are passed to the @ref EditWindow. When this flag is set and you * want to leave the cell with the marker then you must first save the new text * in the cell before moving the marker. */ bool m_bEditDirtyFlag; /** * The active KSpreadTable. This table has the input focus. It may be 0L, too. */ KSpreadTable* m_pTable; KSpreadDoc *m_pDoc; /** * Flags that indicate whether we should display additional * GUI stuff like rulers and scrollbars. * * @see #showGUI */ bool m_bShowGUI; /** * If @ref #updateEditWidget is called it changes some KToggleActions. * That causes them to emit a signal. If this lock is TRUE, then these * signals are ignored. */ bool m_toolbarLock; struct ToolEntry { QString command; KDataToolInfo info; }; QPtrList m_lstTools; static KSpreadScripts *m_pGlobalScriptsDialog; //used to allow to refresh menubar //otherwise kspread crash when I try to refresh menubar //when I start kspread bool m_bLoading; /** * Holds a guarded pointer to the transformation toolbox. */ QGuardedPtr m_transformToolBox; /** * Find and Replace context. We remember the options and the strings used * previously. */ long m_findOptions; QStringList m_findStrings; QStringList m_replaceStrings; KStatusBarLabel* m_sbCalcLabel; }; #endif