~ubuntu-branches/ubuntu/warty/koffice/warty

« back to all changes in this revision

Viewing changes to kugar/kudesigner_lib/cv.cpp

  • 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:
 
1
/***************************************************************************
 
2
                          cv.cpp  -  description
 
3
                             -------------------
 
4
    begin                : 07.06.2002
 
5
    copyright            : (C) 2002 by Alexander Dymo
 
6
    email                : cloudtemple@mksat.net
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU Library General Public License as       *
 
13
 *   published by the Free Software Foundation; either version 2 of the    *
 
14
 *   License, or (at your option) any later version.                       *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
#include <algorithm>
 
18
#include "cv.h"
 
19
#include <qwmatrix.h>
 
20
#include <qevent.h>
 
21
#include <qpoint.h>
 
22
#include <qcanvas.h>
 
23
#include <qaction.h>
 
24
#include <qcursor.h>
 
25
#include <qpainter.h>
 
26
#include <qbitmap.h>
 
27
#include <qimage.h>
 
28
 
 
29
#include <qprinter.h>
 
30
#ifndef PURE_QT
 
31
#include <kdebug.h>
 
32
#endif
 
33
 
 
34
#include "mycanvas.h"
 
35
#include "canvbox.h"
 
36
#include "canvdefs.h"
 
37
#include "creportitem.h"
 
38
#include "clabel.h"
 
39
#include "cfield.h"
 
40
#include "cspecialfield.h"
 
41
#include "ccalcfield.h"
 
42
#include "cline.h"
 
43
#include "canvkutemplate.h"
 
44
#include "canvdetailbase.h"
 
45
#include "canvband.h"
 
46
#include "property.h"
 
47
#include "plugin.h"
 
48
//#include "kudesigner_view.h"
 
49
#include "kudesigner_command.h"
 
50
 
 
51
 
 
52
void SelectionRect::draw(QPainter & painter)
 
53
{
 
54
//    painter.setPen(Qt::NoPen);
 
55
 
 
56
/*  QPrinter pr;
 
57
  if ( pr.setup() ) {
 
58
    QPainter p(&pr);
 
59
    canvas()->drawArea( canvas()->rect(), &p );
 
60
  } */
 
61
 
 
62
/*    qDebug("creating pixmap");
 
63
    QPixmap mp(rect().size());
 
64
    qDebug("creating painter");
 
65
    QPainter p(&mp);
 
66
    qDebug("filling pixmap");
 
67
    canvas()->drawArea(canvas()->rect(), &p);
 
68
    qDebug("converting to image");
 
69
    QImage im = mp.convertToImage();
 
70
    if (!im.isNull())
 
71
    {
 
72
        qDebug("do dither");
 
73
        mp.convertFromImage(im,  Qt::OrderedAlphaDither);
 
74
 
 
75
        qDebug("creating brush");
 
76
        QBrush br(KGlobalSettings::highlightColor(),Qt::CustomPattern);
 
77
        br.setPixmap(mp);
 
78
        painter.setBrush(br);
 
79
    }
 
80
    qDebug("drawing");*/
 
81
//    painter.drawRect(rect());
 
82
    QPen pen(QColor(0,0,0), 0, Qt::DotLine);
 
83
    painter.setPen(pen);
 
84
    painter.setBrush(QBrush(NoBrush));
 
85
    painter.drawRect(rect());
 
86
//  QCanvasRectangle::draw(painter);
 
87
}
 
88
 
 
89
 
 
90
 
 
91
ReportCanvas::ReportCanvas(QCanvas * canvas, QWidget * parent, const char * name, WFlags f):
 
92
    QCanvasView(canvas, parent, name, f),m_plugin(0)/*,m_view(parent)*/
 
93
{
 
94
    m_canvas=(MyCanvas*)canvas;
 
95
    itemToInsert = 0;
 
96
    moving = 0;
 
97
    resizing = 0;
 
98
    selectionStarted = 0;
 
99
    request = RequestNone;
 
100
    selectionRect = new SelectionRect(0, 0, 0, 0, canvas);
 
101
 
 
102
    connect(m_canvas, SIGNAL(itemSelected()), this, SLOT(selectItem()));
 
103
}
 
104
 
 
105
void ReportCanvas::setPlugin(KuDesignerPlugin *plugin)
 
106
{
 
107
        m_plugin=plugin;
 
108
}
 
109
 
 
110
void ReportCanvas::deleteItem(QCanvasItemList &l)
 
111
{
 
112
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
113
    {
 
114
        m_canvas->unselectItem((CanvasBox*)*it);
 
115
        if ( ((MyCanvas*)(canvas()))->templ->removeReportItem(*it) )
 
116
            break;
 
117
    }
 
118
}
 
119
 
 
120
void ReportCanvas::editItem(QCanvasItemList &/* l */)
 
121
{
 
122
    //display editor for report items or sections
 
123
/*  for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
124
    {
 
125
        if ((*it)->rtti() >= 1800) //for my own report items
 
126
        {
 
127
            CanvasBox *l = (CanvasBox*)(*it);
 
128
            dlgItemOptions *dlgOpts = new dlgItemOptions(&(l->props), this);
 
129
            dlgOpts->exec();
 
130
            delete dlgOpts;
 
131
            if ((*it)->rtti() == KuDesignerRttiKugarTemplate)
 
132
                ((CanvasKugarTemplate*)(*it))->updatePaperProps();
 
133
            (*it)->hide();
 
134
            (*it)->show();
 
135
            if ((*it)->rtti() < 2000)
 
136
                ((MyCanvas *)(canvas()))->templ->arrangeSections();
 
137
            canvas()->update();
 
138
            emit modificationPerformed();
 
139
            break;
 
140
        }
 
141
    }*/
 
142
}
 
143
 
 
144
void ReportCanvas::selectItemFromList(QCanvasItemList &l)
 
145
{
 
146
    //display editor for report items or sections
 
147
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
148
    {
 
149
        if ((*it)->rtti() >= 1800 ) //include bands and the template itself
 
150
        {
 
151
            CanvasBox *b = (CanvasBox*)(*it);
 
152
            if (!m_canvas->selected.containsRef(b))
 
153
            {
 
154
                m_canvas->unselectAll();
 
155
                m_canvas->selectItem(b, false);
 
156
                canvas()->update();
 
157
//                qWarning("selected item set");
 
158
//                selected->drawHolders();
 
159
                return;
 
160
            }
 
161
            if (m_canvas->selected.containsRef(b))
 
162
            {
 
163
                if (m_canvas->selected.count() > 1)
 
164
                {
 
165
                    m_canvas->unselectAll();
 
166
                    m_canvas->selectItem(b, false);
 
167
                    canvas()->update();
 
168
                }
 
169
                return;
 
170
            }
 
171
        }
 
172
    }
 
173
    m_canvas->unselectAll();
 
174
//    qWarning("unselect");
 
175
}
 
176
 
 
177
 
 
178
void ReportCanvas::placeItem(QCanvasItemList &l, QMouseEvent *e)
 
179
{
 
180
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
181
    {
 
182
        if ( ((*it)->rtti() > 1800) && (((*it)->rtti() < 2000)) )
 
183
        {
 
184
            int band = (*it)->rtti();
 
185
            int bandLevel = -1;
 
186
            if ( (band == KuDesignerRttiDetailHeader) ||
 
187
                 (band == KuDesignerRttiDetail ) ||
 
188
                 (band == KuDesignerRttiDetailFooter) )
 
189
                 bandLevel = ((CanvasDetailBase *)(*it))->level();
 
190
            emit itemPlaced(e->x(), e->y(), band, bandLevel);
 
191
 
 
192
//            emit modificationPerformed();
 
193
        }
 
194
    }
 
195
    itemToInsert = 0;
 
196
    emit selectedActionProcessed();
 
197
}
 
198
 
 
199
 
 
200
bool ReportCanvas::startResizing(QMouseEvent * /*e*/, QPoint &p)
 
201
{
 
202
    if (m_canvas->selected.count()==0) return false;
 
203
    for (CanvasBox *cbx=m_canvas->selected.first();
 
204
        cbx;cbx=m_canvas->selected.next())
 
205
    {
 
206
        resizing_type=cbx->isInHolder(p);
 
207
        if (resizing_type)
 
208
        {
 
209
            m_canvas->selectItem(cbx,false);
 
210
            //kdDebug()<<"A Widget should be resized"<<endl;
 
211
                    moving = 0;
 
212
                    resizing = cbx;
 
213
            moving_start = p;
 
214
            moving_offsetX=0;
 
215
            moving_offsetY=0;
 
216
 
 
217
            if (cbx->rtti()>2001)
 
218
            {
 
219
                            CanvasReportItem *item = (CanvasReportItem *)(cbx);
 
220
                resizing_constraint.setX((int)item->section()->x());
 
221
                resizing_constraint.setY((int)item->section()->y());
 
222
                resizing_constraint.setWidth(item->section()->width());
 
223
                resizing_constraint.setHeight(
 
224
                    item->section()->height());
 
225
                if (cbx->rtti()!=KuDesignerRttiCanvasLine)
 
226
                {
 
227
                    resizing_minSize.setWidth(10);
 
228
                    resizing_minSize.setHeight(10);
 
229
                }
 
230
                else
 
231
                {
 
232
                    resizing_minSize.setWidth(0);
 
233
                    resizing_minSize.setHeight(0);
 
234
                }
 
235
            }
 
236
            else
 
237
                if (cbx->rtti()>=KuDesignerRttiReportHeader)
 
238
                {
 
239
                    resizing_constraint=QRect(0,0,1000,1000);
 
240
                    resizing_minSize.setWidth(0);
 
241
                    resizing_minSize.setHeight(
 
242
                        ((CanvasBand*)cbx)->minHeight());
 
243
                }
 
244
                else
 
245
                {
 
246
                    resizing_constraint=QRect(0,0,1000,1000);
 
247
                    resizing_minSize.setWidth(0);
 
248
                    resizing_minSize.setHeight(10);
 
249
                }
 
250
                    return true;
 
251
        }
 
252
    }
 
253
    return false;
 
254
}
 
255
 
 
256
void ReportCanvas::startMoveOrResizeOrSelectItem(QCanvasItemList &l,
 
257
    QMouseEvent * /*e*/, QPoint &p)
 
258
{
 
259
    //allow user to move any item except for page rectangle
 
260
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
261
    {
 
262
        CanvasBox *cb=(CanvasBox*)(*it);
 
263
        if (cb->rtti() >= 1700) //> 2001)
 
264
        {
 
265
            moving_start = p;
 
266
            moving_offsetX=0;
 
267
            moving_offsetY=0;
 
268
            resizing_type=cb->isInHolder(p);
 
269
            if ((*it)->rtti() >2001)
 
270
            {
 
271
                        CanvasReportItem *item = (CanvasReportItem *)(*it);
 
272
                        moving = item;
 
273
                        resizing = 0;
 
274
                        return;
 
275
            }
 
276
        }
 
277
    }
 
278
    moving = 0;
 
279
    resizing = 0;
 
280
    selectionStarted = 1;
 
281
    selectionRect->setX(p.x());
 
282
    selectionRect->setY(p.y());
 
283
    selectionRect->setZ(50);
 
284
    selectionRect->show();
 
285
}
 
286
 
 
287
void ReportCanvas::contentsMousePressEvent(QMouseEvent* e)
 
288
{
 
289
    QPoint p = inverseWorldMatrix().QWMatrix::map(e->pos());
 
290
    QCanvasItemList l=canvas()->collisions(p);
 
291
 
 
292
    //if there is a request for properties or for delete operation
 
293
    //perform that and do not take care about mouse buttons
 
294
 
 
295
//    qWarning("mouse press");
 
296
 
 
297
    switch (request)
 
298
    {
 
299
        case RequestProps:
 
300
            clearRequest();
 
301
            editItem(l);
 
302
            return;
 
303
        case RequestDelete:
 
304
            deleteItem(l);
 
305
            clearRequest();
 
306
            return;
 
307
        case RequestNone:
 
308
            break;
 
309
    }
 
310
 
 
311
    moving = 0;
 
312
    resizing = 0;
 
313
    selectionStarted = 0;
 
314
 
 
315
 
 
316
 
 
317
/*    CanvasBox *b;
 
318
    qWarning("Selected items:");
 
319
    for (b = selected.first(); b; b = selected.next())
 
320
        qWarning("%s", b->props["Text"].first.latin1());
 
321
 
 
322
  */
 
323
    switch (e->button())
 
324
    {
 
325
        case LeftButton:
 
326
            if (itemToInsert)
 
327
            {
 
328
//                qWarning("placing item");
 
329
                m_canvas->unselectAll();
 
330
                placeItem(l, e);
 
331
            }
 
332
            else
 
333
            {
 
334
//                qWarning("starting move or resize");
 
335
                if (!startResizing(e,p))
 
336
                {
 
337
                        selectItemFromList(l);
 
338
                        startMoveOrResizeOrSelectItem(l, e, p);
 
339
                }
 
340
            }
 
341
            break;
 
342
        default:
 
343
            break;
 
344
    }
 
345
}
 
346
 
 
347
void ReportCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
 
348
{
 
349
    selectionRect->setSize(0, 0);
 
350
    selectionRect->setX(0);
 
351
    selectionRect->setY(0);
 
352
    selectionRect->hide();
 
353
 
 
354
    QPoint p = inverseWorldMatrix().QWMatrix::map(e->pos());
 
355
    QCanvasItemList l=canvas()->collisions(p);
 
356
 
 
357
    switch (e->button())
 
358
    {
 
359
        case LeftButton:
 
360
            if (selectionStarted)
 
361
                finishSelection();
 
362
            break;
 
363
/*        case MidButton:
 
364
            deleteItem(l);
 
365
            break;
 
366
        case RightButton:
 
367
            editItem(l);
 
368
            break;*/
 
369
        default:
 
370
            break;
 
371
    }
 
372
}
 
373
 
 
374
 
 
375
void ReportCanvas::fixMinValues(double &pos,double minv,double &offset)
 
376
{
 
377
        if (pos<minv)
 
378
        {
 
379
                offset=offset+pos-minv;
 
380
                pos=minv;
 
381
        }
 
382
        else
 
383
        {
 
384
                if (offset<0)
 
385
                {
 
386
                        offset=offset+pos-minv;
 
387
                        if (offset<0)
 
388
                                pos=minv;
 
389
                        else
 
390
                        {
 
391
                                pos=offset+minv;
 
392
                                offset=0;
 
393
                        }
 
394
                }
 
395
        }
 
396
}
 
397
 
 
398
void ReportCanvas::fixMaxValues(double &pos,double size,double maxv,double &offset)
 
399
{
 
400
        double tmpMax=pos+size;
 
401
        if (tmpMax>maxv)
 
402
        {
 
403
                offset=offset+tmpMax-maxv;
 
404
                pos=maxv-size;
 
405
        }
 
406
        else
 
407
        {
 
408
                if (offset>0)
 
409
                {
 
410
                        offset=offset+tmpMax-maxv;
 
411
                        if (offset>0)
 
412
                                pos=maxv-size;
 
413
                        else
 
414
                        {
 
415
                                pos=offset+maxv-size;
 
416
                                offset=0;
 
417
                        }
 
418
                }
 
419
        }
 
420
}
 
421
 
 
422
void ReportCanvas::contentsMouseMoveEvent(QMouseEvent* e)
 
423
{
 
424
    QPoint p = inverseWorldMatrix().map(e->pos());
 
425
 
 
426
/*    QCanvasItemList l=canvas()->collisions(p);
 
427
  setCursor(QCursor(Qt::ArrowCursor));
 
428
    unsetCursor();
 
429
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
430
    {
 
431
        if ((*it)->rtti() > 2000)
 
432
        {
 
433
            CanvasReportItem *item = (CanvasReportItem*)(*it);
 
434
            if (item->bottomRightResizableRect().contains(e->pos()))
 
435
                setCursor(QCursor(Qt::SizeFDiagCursor));
 
436
        }
 
437
    }*/
 
438
 
 
439
    if ( moving )
 
440
    {
 
441
        double newXPos=moving->x()+p.x()-moving_start.x();
 
442
        double newYPos=moving->y()+p.y()-moving_start.y();
 
443
        fixMinValues(newYPos,moving->parentSection->y(),moving_offsetY);
 
444
        fixMinValues(newXPos,moving->parentSection->x(),moving_offsetX);
 
445
        fixMaxValues(newYPos,moving->height(),moving->parentSection->y()+moving->parentSection->height(),moving_offsetY);
 
446
        fixMaxValues(newXPos,moving->width(),moving->parentSection->x()+moving->parentSection->width(),moving_offsetX);
 
447
 
 
448
        moving->move(newXPos,newYPos);
 
449
/*      attempt to prevent item collisions
 
450
        QCanvasItemList l=canvas()->collisions(moving->rect());
 
451
        if (l.count() > 2)
 
452
        {
 
453
            moving->moveBy(-(p.x() - moving_start.x()),
 
454
                           -(p.y() - moving_start.y()));
 
455
            canvas()->update();
 
456
            return;
 
457
        }*/
 
458
        moving_start = p;
 
459
        moving->updateGeomProps();
 
460
        canvas()->update();
 
461
        emit modificationPerformed();
 
462
    }
 
463
    if (resizing)
 
464
    {
 
465
        QCanvasRectangle *r = (QCanvasRectangle *)resizing;
 
466
        double newXPos=r->x();
 
467
        double newYPos=r->y();
 
468
        double h=r->height();
 
469
        double w=r->width();
 
470
//      kdDebug()<<"resizing"<<endl;
 
471
 
 
472
//vertical resizing
 
473
        if (resizing_type & CanvasBox::ResizeBottom)
 
474
        {
 
475
//              kdDebug()<<"Resize bottom"<<endl;
 
476
                h = h + p.y() - moving_start.y();
 
477
                fixMaxValues(h,r->y(),resizing_constraint.bottom(),moving_offsetY);
 
478
                if(resizing->rtti() != KuDesignerRttiCanvasLine)
 
479
                        fixMinValues(h,resizing_minSize.height(),moving_offsetY);
 
480
        }
 
481
        else
 
482
                if (resizing_type & CanvasBox::ResizeTop)
 
483
                {
 
484
//                      kdDebug()<<"Resize top"<<endl;
 
485
                        newYPos=r->y()+p.y()-moving_start.y();
 
486
                        fixMinValues(newYPos,resizing_constraint.top(),moving_offsetY);
 
487
                        if(resizing->rtti() != KuDesignerRttiCanvasLine)
 
488
                                fixMaxValues(newYPos, resizing_minSize.height(),r->y()+r->height(),moving_offsetY);
 
489
                        h=h+(r->y()-newYPos);
 
490
                }
 
491
 
 
492
 
 
493
//horizontal resizing
 
494
        if (resizing_type & CanvasBox::ResizeRight)
 
495
        {
 
496
//              kdDebug()<<"Resize right"<<endl;
 
497
                w = w + p.x() - moving_start.x();
 
498
                fixMaxValues(w,r->x(),resizing_constraint.right(),moving_offsetX);
 
499
                if(resizing->rtti() != KuDesignerRttiCanvasLine)
 
500
                        fixMinValues(w,resizing_minSize.width(),moving_offsetX);
 
501
 
 
502
        }
 
503
        else
 
504
                if (resizing_type & CanvasBox::ResizeLeft)
 
505
                {
 
506
//                      kdDebug()<<"Resize left"<<endl;
 
507
                        newXPos=r->x()+p.x()-moving_start.x();
 
508
                        fixMinValues(newXPos,resizing_constraint.left(),moving_offsetX);
 
509
                        if(resizing->rtti() != KuDesignerRttiCanvasLine)
 
510
                                fixMaxValues(newXPos, resizing_minSize.width(),r->x()+r->width(),moving_offsetX);
 
511
                        w=w+(r->x()-newXPos);
 
512
                }
 
513
 
 
514
        r->move(newXPos,newYPos);
 
515
        r->setSize((int)w, (int)h);
 
516
        moving_start = p;
 
517
        resizing->updateGeomProps();
 
518
        canvas()->update();
 
519
        emit modificationPerformed();
 
520
    }
 
521
    if (selectionStarted)
 
522
    {
 
523
/*        qDebug("x_start = %d, y_start = %d, x_end = %d, y_end = %d", moving_start.x(),
 
524
            moving_start.y(), e->pos().x(), e->pos().y());*/
 
525
        selectionRect->setSize((int) (e->pos().x() - selectionRect->x()),
 
526
            (int) (e->pos().y() - selectionRect->y() ));
 
527
        m_canvas->unselectAll();
 
528
        QCanvasItemList l = canvas()->collisions(selectionRect->rect());
 
529
        for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
530
        {
 
531
            QRect r;
 
532
            int left = selectionRect->rect().left();
 
533
            int right = selectionRect->rect().right();
 
534
            int top = selectionRect->rect().top();
 
535
            int bottom = selectionRect->rect().bottom();
 
536
            r.setLeft(left<right ? left : right);
 
537
            r.setRight(left<right ? right : left);
 
538
            r.setTop(top<bottom ? top : bottom);
 
539
            r.setBottom(top<bottom ? bottom : top);
 
540
 
 
541
            if ( ((*it)->rtti() > 2001) &&
 
542
                (r.contains(((CanvasBox*)(*it))->rect())) )
 
543
            {
 
544
                m_canvas->selectItem((CanvasBox*)(*it));
 
545
                canvas()->update();
 
546
            }
 
547
        }
 
548
 
 
549
 
 
550
/*        selectionRect->setSize(e->pos().x() - selectionRect->x(),
 
551
            e->pos().y() - selectionRect->y());
 
552
        unselectAll();
 
553
        QCanvasItemList l = canvas()->collisions(selectionRect->rect());
 
554
        for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
 
555
        {
 
556
            if ( ((*it)->rtti() > 2001) &&
 
557
                (selectionRect->rect().contains(((CanvasBox*)(*it))->rect())) )
 
558
            {
 
559
                selectItem((CanvasBox*)(*it));
 
560
                canvas()->update();
 
561
            }
 
562
        }*/
 
563
    }
 
564
}
 
565
 
 
566
 
 
567
void ReportCanvas::contentsMouseDoubleClickEvent( QMouseEvent *e )
 
568
{
 
569
    CanvasReportItem *item = 0L;
 
570
    if ( e->button() == Qt::LeftButton && m_canvas->selected.count() == 1 )
 
571
        item = dynamic_cast<CanvasReportItem *>( m_canvas->selected.first() );
 
572
    if ( item )
 
573
    {
 
574
        item->fastProperty();
 
575
        item->hide();
 
576
        item->show();
 
577
    }
 
578
}
 
579
 
 
580
void ReportCanvas::setRequest(RequestType r)
 
581
{
 
582
    switch (r)
 
583
    {
 
584
        case RequestProps:
 
585
            QApplication::restoreOverrideCursor();
 
586
            QApplication::setOverrideCursor(Qt::PointingHandCursor);
 
587
            break;
 
588
        case RequestDelete:
 
589
            QApplication::restoreOverrideCursor();
 
590
            QApplication::setOverrideCursor(Qt::ForbiddenCursor);
 
591
            break;
 
592
        case RequestNone:
 
593
            QApplication::restoreOverrideCursor();
 
594
            break;
 
595
    }
 
596
    request = r;
 
597
}
 
598
 
 
599
void ReportCanvas::clearRequest()
 
600
{
 
601
    QApplication::restoreOverrideCursor();
 
602
    request = RequestNone;
 
603
    emit selectedEditActionProcessed();
 
604
}
 
605
 
 
606
bool ReportCanvas::requested()
 
607
{
 
608
    if (request == RequestNone)
 
609
        return false;
 
610
    else
 
611
        return true;
 
612
}
 
613
 
 
614
void ReportCanvas::updateProperty(QString name, QString value)
 
615
{
 
616
    CanvasBox *b;
 
617
    for (b = m_canvas->selected.first(); b; b = m_canvas->selected.next())
 
618
    {
 
619
        b->props[name]->setValue(value);
 
620
        b->hide();
 
621
        b->show();
 
622
        if ((b->rtti()>=1800) && (b->rtti()<2000))
 
623
           ((MyCanvas*)(canvas()))->templ->arrangeSections();
 
624
    }
 
625
}
 
626
 
 
627
 
 
628
void ReportCanvas::finishSelection()
 
629
{
 
630
    selectionStarted = false;
 
631
 
 
632
    if (!m_canvas->selected.isEmpty())
 
633
        if (m_canvas->selected.count() > 1)
 
634
        {
 
635
            // handling multiple selection
 
636
            std::map<QString, PropPtr > curr = m_canvas->selected.first()->props;
 
637
 
 
638
            CanvasBox *b = m_canvas->selected.first();
 
639
            b = m_canvas->selected.next();
 
640
            while (b)
 
641
            {
 
642
                std::map<QString, PropPtr > selProps;
 
643
                std::insert_iterator< std::map<QString, PropPtr > > it(selProps, selProps.begin());
 
644
                std::set_intersection(curr.begin(), curr.end(), b->props.begin(), b->props.end(), it);
 
645
 
 
646
                curr = selProps;
 
647
 
 
648
/*                qWarning("Multiple selection property list:");
 
649
                for (std::map<QString, PropPtr>::const_iterator i = curr->begin(); i != curr->end(); ++i )
 
650
                {
 
651
                    qWarning("   %s = %s", i->first.latin1(), i->second->value().latin1());
 
652
                }*/
 
653
 
 
654
                b = m_canvas->selected.next();
 
655
            }
 
656
 
 
657
/*            qWarning("Multiple selection property list:");
 
658
            for (std::map<QString, PropPtr>::const_iterator i = curr->begin(); i != curr->end(); ++i )
 
659
            {
 
660
                qWarning("   %s = %s", i->first.latin1(), i->second->value().latin1());
 
661
            }*/
 
662
 
 
663
            std::map<QString, PropPtr > *x = new std::map<QString, PropPtr >(curr);
 
664
            emit selectionMade(x,0);
 
665
        }
 
666
        else
 
667
            emit selectionMade(&(m_canvas->selected.first()->props),
 
668
                m_canvas->selected.first());
 
669
 
 
670
/*  CanvasBox *b;
 
671
    for (b = selected.first(); b; b = selected.next())
 
672
    {
 
673
        qWarning("item with rtti = %d is selected", b->rtti());
 
674
    }*/
 
675
 
 
676
}
 
677
 
 
678
void ReportCanvas::contentsDragMoveEvent ( QDragMoveEvent * event) {
 
679
//perhaps this could be optimized a littlebit
 
680
        if (!m_plugin) return;
 
681
        QCanvasItemList l=canvas()->collisions(event->pos());
 
682
//      kdDebug()<<l.count()<<endl;
 
683
        if (l.count()<2)
 
684
        {
 
685
                event->ignore();
 
686
                return;
 
687
        }
 
688
        CanvasBox *b=(CanvasBox*) (*(l.begin()));
 
689
        if (m_plugin->dragMove(event,b))
 
690
                event->accept();
 
691
        else
 
692
                event->ignore();
 
693
}
 
694
 
 
695
void ReportCanvas::contentsDragEnterEvent ( QDragEnterEvent * /*event*/) {
 
696
//      event->accept();
 
697
}
 
698
 
 
699
 
 
700
 
 
701
void ReportCanvas::keyPressEvent( QKeyEvent *e )
 
702
{
 
703
   qDebug("keyPress (selection : %d)", m_canvas->selected.count());
 
704
 
 
705
    if ( m_canvas->selected.count() == 1 ) {
 
706
        CanvasReportItem *item = static_cast<CanvasReportItem *>( m_canvas->selected.first() );
 
707
 
 
708
        switch ( e->key() ) {
 
709
            case Qt::Key_Delete:
 
710
                qDebug("Deleting selection");
 
711
/*                unselectItem(item);
 
712
                ( (MyCanvas*) canvas() )->templ->removeReportItem( item );
 
713
                clearRequest();*/
 
714
//                deleteSelected();
 
715
                //FIXME: this disregards undo/redo
 
716
                if (((MyCanvas*)canvas())->selected.count() > 0)
 
717
                {
 
718
                    DeleteReportItemsCommand *cmd = new DeleteReportItemsCommand(((MyCanvas*)canvas()), ((MyCanvas*)canvas())->selected);
 
719
                    cmd->execute();
 
720
                    delete cmd;
 
721
                }
 
722
                return;
 
723
 
 
724
            /* Adjust height with - and +  */
 
725
            case Qt::Key_Minus:
 
726
            case Qt::Key_Plus:
 
727
                {
 
728
                    int size = item->props["FontSize"]->value().toInt();
 
729
 
 
730
                    if ( e->key() == Qt::Key_Minus )
 
731
                        size--;
 
732
                    else
 
733
                        size++;
 
734
 
 
735
                    if ( size < 5 )
 
736
                        size = 5;
 
737
 
 
738
                    if ( size > 50 )
 
739
                        size = 50;
 
740
 
 
741
                    updateProperty( "FontSize", QString::number( size ) );
 
742
                    return;
 
743
                }
 
744
 
 
745
            default:
 
746
                e->ignore();
 
747
        }
 
748
 
 
749
    }
 
750
}
 
751
 
 
752
void ReportCanvas::selectItem( )
 
753
{
 
754
    if (!selectionStarted)
 
755
        finishSelection();
 
756
}
 
757
 
 
758
/*void ReportCanvas::deleteSelected( )
 
759
{
 
760
    CanvasBox *b;
 
761
 
 
762
    QPtrList<CanvasBox> list = m_canvas->selected;
 
763
    unselectAll();
 
764
 
 
765
    for (b = list.first(); b; b = list.next())
 
766
    {
 
767
        ( (MyCanvas*) canvas() )->templ->removeReportItem( b );
 
768
    }
 
769
}
 
770
*/
 
771
#ifndef PURE_QT
 
772
#include "cv.moc"
 
773
#endif
 
774