~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kword/deldia.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
 
20
20
#include "kwdoc.h"
21
 
#include "kwframe.h"
22
21
#include "kwtableframeset.h"
23
 
#include "kwcanvas.h"
24
22
#include "deldia.h"
25
23
#include "deldia.moc"
26
24
#include "kwcommand.h"
 
25
#include "kwview.h"
 
26
#include "kwcanvas.h"
27
27
 
28
28
#include <klocale.h>
29
29
 
30
 
#include <qwidget.h>
31
 
#include <qlayout.h>
32
30
#include <qlabel.h>
33
 
#include <qstring.h>
34
 
#include <qevent.h>
35
31
#include <qspinbox.h>
36
 
#include <qradiobutton.h>
37
 
#include <qbuttongroup.h>
38
 
#include <qpainter.h>
39
32
 
40
33
#include <stdlib.h>
41
34
 
50
43
    table = _table;
51
44
    doc = _doc;
52
45
    canvas = _canvas;
 
46
    m_toRemove.clear();
53
47
 
54
48
    setupTab1();
55
49
    setButtonOKText(i18n("&Delete"), type == ROW ?
63
57
{
64
58
    tab1 = plainPage();
65
59
    grid1 = new QGridLayout( tab1, 4, 1, 0, spacingHint() );
66
 
 
67
 
    rc = new QLabel( type == ROW ? i18n( "Delete Row:" ) : i18n( "Delete Column:" ), tab1 );
 
60
    QString message =type == ROW ? i18n( "Delete rows:" ) : i18n( "Delete columns:" );
 
61
    bool firstSelectedCell = true; // used to know whether to add a ", " to the message string.
 
62
 
 
63
    uint max = (type == ROW) ? table->getRows() : table->getCols(); // max row/col to loop up to
 
64
    for (uint i=0;i<max; i++)
 
65
    {
 
66
        if ( ( (type == ROW) && table->isRowSelected(i)) ||
 
67
                ( (type == COL) && table->isColSelected(i) ) )
 
68
        {
 
69
            if (!firstSelectedCell)
 
70
                message += ", "; // i18n??
 
71
            message += QString::number(i +1);
 
72
            m_toRemove.push_back(i);
 
73
            firstSelectedCell = false;
 
74
       }
 
75
    }
 
76
    if ( m_toRemove.isEmpty() ) // Nothing selected, so we want to remove the row/col where the cursor is
 
77
    {
 
78
        int val = type == ROW ? canvas->currentTableRow() : canvas->currentTableCol();
 
79
        Q_ASSERT( val != -1 );
 
80
        message += QString::number(val+1);
 
81
        m_toRemove.push_back(val);
 
82
    }
 
83
    Q_ASSERT(m_toRemove.count() > 0);
 
84
 
 
85
    if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() ) )
 
86
        // all the columns are selected and the user asked to remove columns or the same with rows
 
87
        // => we want to delete the whole table
 
88
        message = i18n("Delete the whole table");
 
89
 
 
90
    // do not display hugely long dialogs if many rows/cells are selected
 
91
    if (m_toRemove.count() > 10)
 
92
        message = ROW ? i18n("Delete all selected rows") : i18n("Delete all selected cells");
 
93
 
 
94
    rc = new QLabel( message , tab1 );
68
95
    rc->resize( rc->sizeHint() );
69
96
    rc->setAlignment( AlignLeft | AlignBottom );
70
97
    grid1->addWidget( rc, 1, 0 );
71
 
 
72
 
    value = new QSpinBox( 1, type == ROW ? table->getRows() : table->getCols(), 1, tab1 );
73
 
    value->resize( value->sizeHint() );
74
 
    value->setValue( type == ROW ? table->getRows() : table->getCols() );
75
 
    grid1->addWidget( value, 2, 0 );
76
 
 
77
 
    grid1->addRowSpacing( 1, rc->height() );
78
 
    grid1->addRowSpacing( 2, value->height() );
79
 
    grid1->setRowStretch( 0, 1 );
80
 
    grid1->setRowStretch( 1, 0 );
81
 
    grid1->setRowStretch( 2, 0 );
82
 
    grid1->setRowStretch( 3, 1 );
83
 
 
84
 
    grid1->addColSpacing( 0, rc->width() );
85
 
    grid1->addColSpacing( 0, value->width() );
86
 
    grid1->setColStretch( 0, 1 );
87
98
}
88
99
 
89
100
bool KWDeleteDia::doDelete()
90
101
{
91
 
    unsigned int remove= value->value() - 1;
92
 
    if ( type == ROW )
93
 
    {
94
 
        KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove row"), table, remove);
95
 
         cmd->execute();
96
 
         doc->addCommand(cmd);
97
 
        //table->deleteRow( value->value() - 1 );
98
 
    }
99
 
    else
100
 
    {
101
 
         KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove column"), table, remove);
102
 
        cmd->execute();
103
 
        doc->addCommand(cmd);
104
 
        //table->deleteCol( value->value() - 1 );
105
 
    }
106
 
 
107
 
 
108
 
 
109
 
#if 0
110
 
    QPainter p;
111
 
    p.begin( canvas );
112
 
 
113
 
    if ( type == ROW )
114
 
        table->deleteRow( value->value() - 1 );
115
 
    else
116
 
        table->deleteCol( value->value() - 1 );
117
 
 
118
 
    canvas->getCursor()->setFrameSet( doc->getFrameSetNum( table->getFrameSet( 0, 0 ) ) + 1 );
119
 
    doc->drawMarker( *canvas->getCursor(), &p, canvas->contentsX(), canvas->contentsY() );
120
 
    canvas->getCursor()->init( dynamic_cast<KWTextFrameSet*>( doc->getFrameSet( canvas->getCursor()->getFrameSet() - 1 ) )->getFirstParag(), true );
121
 
    canvas->getCursor()->gotoStartOfParag();
122
 
    canvas->getCursor()->cursorGotoLineStart();
123
 
    p.end();
124
 
 
125
 
    canvas->recalcCursor();
126
 
#endif
 
102
    KWView *view = canvas->gui()->getView();
 
103
    if(!view) return false; // can't happen
 
104
 
 
105
    if(type == ROW)
 
106
        view->tableDeleteRow(m_toRemove);
 
107
    else
 
108
        view->tableDeleteCol(m_toRemove);
 
109
 
127
110
    return true;
128
111
}
129
112