~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/whiteboarding/wbwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        setRenderHint(QPainter::Antialiasing);
40
40
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
41
41
 
 
42
    // Make the scroll bars always stay on because otherwise the resize event can cause
 
43
    // an infinite loop as the effective size of the widget changes when scroll bars are
 
44
    // added/removed
 
45
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
 
46
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
 
47
 
42
48
    // create the scene
43
49
        scene_ = new WbScene(session_, this);
44
50
        scene_->setItemIndexMethod(QGraphicsScene::NoIndex);
69
75
    // remove items if corresponding nodes are deleted
70
76
    connect(session_, SIGNAL(nodeToBeRemoved(QDomNode, bool)), SLOT(removeWbItem(QDomNode)));
71
77
    connect(session_, SIGNAL(nodeToBeRemoved(QDomNode, bool)), SLOT(checkForRemovalOfId(QDomNode)));
72
 
    // adjust the viewbox as necessary
 
78
    // adjust the viewBox as necessary
73
79
    connect(session_, SIGNAL(nodeAdded(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode)));
74
80
    connect(session_, SIGNAL(nodeMoved(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode)));
75
81
    connect(session_, SIGNAL(chdataChanged(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode)));
78
84
        setMode(Select);
79
85
 
80
86
    // set the initial size
81
 
    if(session_->document().documentElement().hasAttribute("viewbox"))
82
 
            checkForViewBoxChange(session_->document().documentElement().attributeNode("viewbox"));
 
87
    if(session_->document().documentElement().hasAttribute("viewBox"))
 
88
            checkForViewBoxChange(session_->document().documentElement().attributeNode("viewBox"));
83
89
        else {
84
90
        QSize size;
85
91
        QRectF rect = scene_->sceneRect();
137
143
}
138
144
 
139
145
void WbWidget::setSize(const QSize &size) {
140
 
    session_->setAttribute(session_->document().documentElement(), "viewbox", QString("0 0 %1 %2").arg(size.width()).arg(size.height()));
 
146
    session_->setAttribute(session_->document().documentElement(), "viewBox", QString("0 0 %1 %2").arg(size.width()).arg(size.height()));
141
147
    session_->flush();
142
148
}
143
149
 
144
 
/*! \brief Generates a QRectF based on \a string provided in the SVG viewbox format. */
 
150
/*! \brief Generates a QRectF based on \a string provided in the SVG viewBox format. */
145
151
static QRectF parseSvgViewBox(QString string) {
146
152
    QString strings[4];
147
153
    qreal numbers[4];
159
165
        numbers[i] = strings[i].toDouble();
160
166
    }
161
167
 
162
 
    // qDebug(QString("QRectF(%1 %2 %3 %4)").arg(numbers[0]).arg(numbers[1]).arg(numbers[2]).arg(numbers[3]).toAscii());
 
168
    // qDebug() << QString("QRectF(%1 %2 %3 %4)").arg(numbers[0]).arg(numbers[1]).arg(numbers[2]).arg(numbers[3]).toAscii();
163
169
    return QRect(numbers[0], numbers[1], numbers[2], numbers[3]);
164
170
}
165
171
 
206
212
        QMatrix t;
207
213
        qreal sx = event->size().width() / scene_->sceneRect().width();
208
214
        qreal sy = event->size().height() / scene_->sceneRect().height();
209
 
        // Skip through the boundary region where the scroll bars change to avoid a nasty loop
210
 
        if((sx-sy)/sx < 0.03 && (sy-sx)/sx < 0.03)
211
 
                sx *= 1.05;
 
215
 
212
216
        // Never shrink the view. Only enlarge if necessary.
213
217
        if(sx > 1 || sy > 1) {
214
218
                if(sx > sy)
216
220
                else
217
221
                        t.scale(sy, sy);
218
222
        }
 
223
 
219
224
        setMatrix(t);
220
225
        QGraphicsView::resizeEvent(event);
221
226
}
235
240
        if(mode_ == DrawPath) {
236
241
        // // Create the element with starting position
237
242
        // QPointF sp = mapToScene(mapFromGlobal(event->globalPos()));
238
 
        // qDebug(QString("1: (%1, %2)").arg(sp.x()).arg(sp.y()));
 
243
        // qDebug() << QString("1: (%1, %2)").arg(sp.x()).arg(sp.y());
239
244
        newWbItem_ = new WbNewPath(scene_, startPoint, strokeWidth_, strokeColor_, fillColor_);
240
245
        return;
241
246
        } else if(mode_ == DrawText) {
412
417
    session_->document().save(stream, 1);
413
418
 
414
419
    // qDebug("Document in WbWidget:");
415
 
    // qDebug(xmldump.toAscii());
 
420
    // qDebug() << xmldump.toAscii();
416
421
 
417
422
    renderer_.load(xmldump.toAscii());
418
423
 
421
426
        // resetting elementId is necessary for rendering some updates to the element (e.g. adding child elements to <g/>)
422
427
        wbitem->setElementId(wbitem->id());
423
428
 
424
 
        // qDebug(QString("Rerendering %1").arg((unsigned int) wbitem).toAscii());
 
429
        // qDebug() << QString("Rerendering %1").arg((unsigned int) wbitem).toAscii();
425
430
        wbitem->resetPos();
426
431
    }
427
432
}