FreeCAD

Форк
0
/
QGIView.cpp 
774 строки · 24.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk>            *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QGraphicsSceneHoverEvent>
26
# include <QGraphicsSceneMouseEvent>
27
# include <QPainter>
28
# include <QStyleOptionGraphicsItem>
29
# include <QTransform>
30
#endif
31

32
#include <App/Application.h>
33
#include <App/DocumentObject.h>
34
#include <Base/Console.h>
35
#include <Gui/Application.h>
36
#include <Gui/Document.h>
37
#include <Gui/Selection.h>
38
#include <Gui/Tools.h>
39
#include <Gui/ViewProvider.h>
40
#include <Mod/TechDraw/App/DrawPage.h>
41
#include <Mod/TechDraw/App/DrawProjGroup.h>
42
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
43
#include <Mod/TechDraw/App/DrawUtil.h>
44
#include <Mod/TechDraw/App/DrawView.h>
45

46
#include "QGIView.h"
47
#include "MDIViewPage.h"
48
#include "PreferencesGui.h"
49
#include "QGCustomBorder.h"
50
#include "QGCustomClip.h"
51
#include "QGCustomImage.h"
52
#include "QGCustomLabel.h"
53
#include "QGICaption.h"
54
#include "QGIVertex.h"
55
#include "QGIViewClip.h"
56
#include "QGSPage.h"
57
#include "QGVPage.h"
58
#include "Rez.h"
59
#include "ViewProviderDrawingView.h"
60
#include "ViewProviderPage.h"
61
#include "ZVALUE.h"
62

63

64
using namespace TechDrawGui;
65
using namespace TechDraw;
66

67
const float labelCaptionFudge = 0.2f;   // temp fiddle for devel
68

69
QGIView::QGIView()
70
    :QGraphicsItemGroup(),
71
     viewObj(nullptr),
72
     m_innerView(false),
73
     m_multiselectActivated(false)
74
{
75
    setCacheMode(QGraphicsItem::NoCache);
76
    setHandlesChildEvents(false);
77
    setAcceptHoverEvents(true);
78
    setFlag(QGraphicsItem::ItemIsSelectable, true);
79
    setFlag(QGraphicsItem::ItemIsMovable, true);
80
    setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
81
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
82

83
    m_colNormal = prefNormalColor();
84
    m_colCurrent = m_colNormal;
85
    m_pen.setColor(m_colCurrent);
86

87
    m_decorPen.setStyle(Qt::DashLine);
88
    m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
89

90
    m_label = new QGCustomLabel();
91
    addToGroup(m_label);
92
    m_border = new QGCustomBorder();
93
    addToGroup(m_border);
94
    m_caption = new QGICaption();
95
    addToGroup(m_caption);
96
    m_lock = new QGCustomImage();
97
    m_lock->setParentItem(m_border);
98
    m_lock->load(QString::fromUtf8(":/icons/TechDraw_Lock.svg"));
99
    QSize sizeLock = m_lock->imageSize();
100
    m_lockWidth = (double) sizeLock.width();
101
    m_lockHeight = (double) sizeLock.height();
102
    m_lock->hide();
103
}
104

105
void QGIView::isVisible(bool state)
106
{
107
    auto feat = getViewObject();
108
    if (!feat) return;
109
    auto vp = QGIView::getViewProvider(feat);
110
    if (!vp) return;
111
    Gui::ViewProviderDocumentObject* vpdo = dynamic_cast<Gui::ViewProviderDocumentObject*>(vp);
112
    if (!vpdo) return;
113
    vpdo->Visibility.setValue(state);
114
}
115

116
bool QGIView::isVisible()
117
{
118
    auto feat = getViewObject();
119
    if (!feat) return false;
120
    auto vp = QGIView::getViewProvider(feat);
121
    if (!vp) return false;
122
    Gui::ViewProviderDocumentObject* vpdo = dynamic_cast<Gui::ViewProviderDocumentObject*>(vp);
123
    if (!vpdo) return false;
124
    return vpdo->Visibility.getValue();
125
}
126

127
//Gets selection state for this view and/or eventually its children
128
bool QGIView::getGroupSelection()
129
{
130
    return isSelected();
131
}
132

133
//Set selection state for this and its children
134
//required for items like dimensions & balloons
135
void QGIView::setGroupSelection(bool isSelected)
136
{
137
    setSelected(isSelected);
138
}
139

140
// Set selection state of the feature (empty subName) or its sub items
141
void QGIView::setGroupSelection(bool isSelected, const std::vector<std::string> &subNames)
142
{
143
    Q_UNUSED(subNames);
144
    setGroupSelection(isSelected);
145
}
146

147
void QGIView::alignTo(QGraphicsItem*item, const QString &alignment)
148
{
149
    alignHash.clear();
150
    alignHash.insert(alignment, item);
151
}
152

153
QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
154
{
155
    QPointF newPos(0.0, 0.0);
156
//    Base::Console().Message("QGIV::itemChange(%d)\n", change);
157
    if(change == ItemPositionChange && scene()) {
158
        newPos = value.toPointF();            //position within parent!
159

160
        TechDraw::DrawView *viewObj = getViewObject();
161
        if (viewObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
162
            // restrict movements of secondary views.
163
            TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(viewObj);
164
            TechDraw::DrawProjGroup* dpg = dpgi->getPGroup();
165
            if (dpg) {
166
                if(alignHash.size() == 1) {   //if aligned.
167
                    QGraphicsItem* item = alignHash.begin().value();
168
                    QString alignMode   = alignHash.begin().key();
169
                    if(alignMode == QString::fromLatin1("Vertical")) {
170
                        newPos.setX(item->pos().x());
171
                    } else if(alignMode == QString::fromLatin1("Horizontal")) {
172
                        newPos.setY(item->pos().y());
173
                    }
174
                }
175
            }
176
        }
177
        // tell the feature that we have moved
178
        Gui::ViewProvider *vp = getViewProvider(viewObj);
179
        if (vp && !vp->isRestoring()) {
180
            viewObj->setPosition(Rez::appX(newPos.x()), Rez::appX(-newPos.y()));
181
        }
182

183
        return newPos;
184
    }
185

186
    if (change == ItemSelectedHasChanged && scene()) {
187
        if(isSelected()) {
188
            m_colCurrent = getSelectColor();
189
//            m_selectState = 2;
190
        } else {
191
            m_colCurrent = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
192
//            m_selectState = 0;
193
        }
194
        drawBorder();
195
    }
196

197
    return QGraphicsItemGroup::itemChange(change, value);
198
}
199

200
void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event)
201
{
202
//    Base::Console().Message("QGIV::mousePressEvent() - %s\n", getViewName());
203
    Qt::KeyboardModifiers originalModifiers = event->modifiers();
204
    if (event->button()&Qt::LeftButton) {
205
        m_multiselectActivated = false;
206
    }
207

208
    if (event->button() == Qt::LeftButton && PreferencesGui::multiSelection()) {
209
        std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx();
210
        if (selection.size() == 1
211
            && selection.front().getObject() == getViewObject()
212
            && selection.front().hasSubNames()) {
213

214
            m_multiselectActivated = true;
215
            event->setModifiers(originalModifiers | Qt::ControlModifier);
216
        }
217
    }
218

219
    QGraphicsItemGroup::mousePressEvent(event);
220

221
    event->setModifiers(originalModifiers);
222
}
223

224
void QGIView::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
225
{
226
    QGraphicsItemGroup::mouseMoveEvent(event);
227
}
228

229
void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
230
{
231
//    Base::Console().Message("QGIV::mouseReleaseEvent() - %s\n", getViewName());
232
    Qt::KeyboardModifiers originalModifiers = event->modifiers();
233
    if ((event->button()&Qt::LeftButton) && m_multiselectActivated) {
234
        if (PreferencesGui::multiSelection()) {
235
            event->setModifiers(originalModifiers | Qt::ControlModifier);
236
        }
237

238
        m_multiselectActivated = false;
239
    }
240

241
    QGraphicsItemGroup::mouseReleaseEvent(event);
242

243
    event->setModifiers(originalModifiers);
244
}
245

246
void QGIView::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
247
{
248
//    Base::Console().Message("QGIV::hoverEnterEvent()\n");
249
    Q_UNUSED(event);
250
    // TODO don't like this but only solution at the minute (MLP)
251
    if (isSelected()) {
252
        m_colCurrent = getSelectColor();
253
        setFocus();
254
    } else {
255
        m_colCurrent = getPreColor();
256
    }
257
    drawBorder();
258
}
259

260
void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
261
{
262
    Q_UNUSED(event);
263
    if(isSelected()) {
264
        m_colCurrent = getSelectColor();
265
    } else {
266
        m_colCurrent = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
267
    }
268
    drawBorder();
269
}
270

271
//sets position in /Gui(graphics), not /App
272
void QGIView::setPosition(qreal xPos, qreal yPos)
273
{
274
//    Base::Console().Message("QGIV::setPosition(%.3f, %.3f) (gui)\n", x, y);
275
    double newX = xPos;
276
    double newY = -yPos;
277
    double oldX = pos().x();
278
    double oldY = pos().y();
279

280
    if (TechDraw::DrawUtil::fpCompare(newX, oldX) &&
281
        TechDraw::DrawUtil::fpCompare(newY, oldY)) {
282
        return;
283
    } else {
284
        setPos(newX, newY);
285
    }
286
}
287

288
QGIViewClip* QGIView::getClipGroup()
289
{
290
    if (!getViewObject()->isInClip()) {
291
        return nullptr;
292
    }
293

294
    auto parentClip( dynamic_cast<QGCustomClip*>( parentItem() ) );
295
    if (!parentClip) return nullptr;
296

297
    auto parentView( dynamic_cast<QGIViewClip*>( parentClip->parentItem() ) );
298
    return parentView;
299
}
300

301
void QGIView::updateView(bool forceUpdate)
302
{
303
//    Base::Console().Message("QGIV::updateView() - %s\n", getViewObject()->getNameInDocument());
304

305
    //allow/prevent dragging
306
    if (getViewObject()->isLocked()) {
307
        setFlag(QGraphicsItem::ItemIsMovable, false);
308
    } else {
309
        setFlag(QGraphicsItem::ItemIsMovable, true);
310
    }
311

312
    if (getViewObject() && forceUpdate) {
313
        setPosition(Rez::guiX(getViewObject()->X.getValue()),
314
                    Rez::guiX(getViewObject()->Y.getValue()));
315
    }
316

317
    double appRotation = getViewObject()->Rotation.getValue();
318
    double guiRotation = rotation();
319
    if (!TechDraw::DrawUtil::fpCompare(appRotation, guiRotation)) {
320
        rotateView();
321
    }
322

323
    QGIView::draw();
324
}
325

326
//QGIVP derived classes do not need a rotate view method as rotation is handled on App side.
327
void QGIView::rotateView()
328
{
329
//NOTE: QPainterPaths have to be rotated individually. This transform handles Rotation for everything else.
330
//Scale is handled in GeometryObject for DVP & descendents
331
//Objects not descended from DVP must setScale for themselves
332
//note that setTransform(, ,rotation, ,) is not the same as setRotation!!!
333
    double rot = getViewObject()->Rotation.getValue();
334
    QPointF centre = boundingRect().center();
335
    setTransform(QTransform().translate(centre.x(), centre.y()).rotate(-rot).translate(-centre.x(), -centre.y()));
336
}
337

338
double QGIView::getScale()
339
{
340
    TechDraw::DrawView* feat = getViewObject();
341
    if (!feat) {
342
        return 1.0;
343
    }
344
    return feat->getScale();
345
}
346
const char * QGIView::getViewName() const
347
{
348
    return viewName.c_str();
349
}
350
const std::string QGIView::getViewNameAsString() const
351
{
352
    return viewName;
353
}
354

355

356
TechDraw::DrawView * QGIView::getViewObject() const
357
{
358
    return viewObj;
359
}
360

361
void QGIView::setViewFeature(TechDraw::DrawView *obj)
362
{
363
    if (!obj)
364
        return;
365

366
    viewObj = obj;
367
    viewName = obj->getNameInDocument();
368

369
    //mark the actual QGraphicsItem so we can check what's in the scene later
370
    setData(0, QString::fromUtf8("QGIV"));
371
    setData(1, QString::fromUtf8(obj->getNameInDocument()));
372
}
373

374
void QGIView::toggleCache(bool state)
375
{
376
    // temp for devl. chaching was hiding problems WF
377
    //setCacheMode((state)? NoCache : NoCache);
378
    Q_UNUSED(state);
379
    setCacheMode(NoCache);
380
}
381

382
void QGIView::draw()
383
{
384
//    Base::Console().Message("QGIV::draw()\n");
385
    double xFeat, yFeat;
386
    if (getViewObject()) {
387
        xFeat = Rez::guiX(getViewObject()->X.getValue());
388
        yFeat = Rez::guiX(getViewObject()->Y.getValue());
389
        if (!getViewObject()->LockPosition.getValue()) {
390
            setPosition(xFeat, yFeat);
391
        }
392
    }
393
    if (isVisible()) {
394
        drawBorder();
395
        show();
396
    } else {
397
        hide();
398
    }
399
}
400

401
void QGIView::drawCaption()
402
{
403
//    Base::Console().Message("QGIV::drawCaption()\n");
404
    prepareGeometryChange();
405
    QRectF displayArea = customChildrenBoundingRect();
406
    m_caption->setDefaultTextColor(m_colCurrent);
407
    m_font.setFamily(Preferences::labelFontQString());
408
    int fontSize = exactFontSize(Preferences::labelFont(),
409
                                 Preferences::labelFontSizeMM());
410
    m_font.setPixelSize(fontSize);
411
    m_caption->setFont(m_font);
412
    QString captionStr = QString::fromUtf8(getViewObject()->Caption.getValue());
413
    m_caption->setPlainText(captionStr);
414
    QRectF captionArea = m_caption->boundingRect();
415
    QPointF displayCenter = displayArea.center();
416
    m_caption->setX(displayCenter.x() - captionArea.width()/2.);
417
    double labelHeight = (1 - labelCaptionFudge) * m_label->boundingRect().height();
418
    auto vp = static_cast<ViewProviderDrawingView*>(getViewProvider(getViewObject()));
419
    if (getFrameState() || vp->KeepLabel.getValue()) {            //place below label if label visible
420
        m_caption->setY(displayArea.bottom() + labelHeight);
421
    } else {
422
        m_caption->setY(displayArea.bottom() + labelCaptionFudge * Preferences::labelFontSizeMM());
423
    }
424
    m_caption->show();
425
}
426

427
void QGIView::drawBorder()
428
{
429
//    Base::Console().Message("QGIV::drawBorder() - %s\n", getViewName());
430
    auto feat = getViewObject();
431
    if (!feat)
432
        return;
433

434
    drawCaption();   //always draw caption
435

436
    auto vp = static_cast<ViewProviderDrawingView*>(getViewProvider(getViewObject()));
437
    if (!getFrameState() && !vp->KeepLabel.getValue()) {
438
         m_label->hide();
439
         m_border->hide();
440
         m_lock->hide();
441
        return;
442
    }
443

444
    m_label->hide();
445
    m_border->hide();
446
    m_lock->hide();
447

448
    m_label->setDefaultTextColor(m_colCurrent);
449
    m_font.setFamily(Preferences::labelFontQString());
450
    int fontSize = exactFontSize(Preferences::labelFont(),
451
                                 Preferences::labelFontSizeMM());
452
    m_font.setPixelSize(fontSize);
453
    m_label->setFont(m_font);
454

455
    QString labelStr = QString::fromStdString( getViewObject()->Label.getValue() );
456
    m_label->setPlainText(labelStr);
457
    QRectF labelArea = m_label->boundingRect();                //m_label coords
458
    double labelWidth = m_label->boundingRect().width();
459
    double labelHeight = (1 - labelCaptionFudge) * m_label->boundingRect().height();
460

461
    QBrush b(Qt::NoBrush);
462
    m_border->setBrush(b);
463
    m_decorPen.setColor(m_colCurrent);
464
    m_border->setPen(m_decorPen);
465

466
    QRectF displayArea = customChildrenBoundingRect();
467
    double displayWidth = displayArea.width();
468
    double displayHeight = displayArea.height();
469
    QPointF displayCenter = displayArea.center();
470
    m_label->setX(displayCenter.x() - labelArea.width()/2.);
471
    m_label->setY(displayArea.bottom());
472

473
    double frameWidth = displayWidth;
474
    if (labelWidth > displayWidth) {
475
        frameWidth = labelWidth;
476
    }
477
    double frameHeight = labelHeight + displayHeight;
478

479
    QRectF frameArea = QRectF(displayCenter.x() - frameWidth/2.,
480
                              displayArea.top(),
481
                              frameWidth,
482
                              frameHeight);
483

484
    double lockX = frameArea.left();
485
    double lockY = frameArea.bottom() - m_lockHeight;
486
    if (feat->isLocked() &&
487
        feat->showLock()) {
488
        m_lock->setZValue(ZVALUE::LOCK);
489
        m_lock->setPos(lockX, lockY);
490
        m_lock->show();
491
    } else {
492
        m_lock->hide();
493
    }
494

495
    prepareGeometryChange();
496
    m_border->setRect(frameArea.adjusted(-2, -2, 2,2));
497
    m_border->setPos(0., 0.);
498

499
    m_label->show();
500
    if (getFrameState()) {
501
        m_border->show();
502
    }
503
}
504

505
void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
506
{
507
    QStyleOptionGraphicsItem myOption(*option);
508
    myOption.state &= ~QStyle::State_Selected;
509

510
//    painter->setPen(Qt::red);
511
//    painter->drawRect(boundingRect());          //good for debugging
512

513
    QGraphicsItemGroup::paint(painter, &myOption, widget);
514
}
515

516
QRectF QGIView::customChildrenBoundingRect() const
517
{
518
    QList<QGraphicsItem*> children = childItems();
519
    // exceptions not to be included in determining the frame rectangle
520
    int dimItemType = QGraphicsItem::UserType + 106;  // TODO: Get magic number from include by name
521
    int borderItemType = QGraphicsItem::UserType + 136;  // TODO: Magic number warning
522
    int labelItemType = QGraphicsItem::UserType + 135;  // TODO: Magic number warning
523
    int captionItemType = QGraphicsItem::UserType + 180;  // TODO: Magic number warning
524
    int leaderItemType = QGraphicsItem::UserType + 232;  // TODO: Magic number warning
525
    int textLeaderItemType = QGraphicsItem::UserType + 233;  // TODO: Magic number warning
526
    int editablePathItemType = QGraphicsItem::UserType + 301;  // TODO: Magic number warning
527
    int movableTextItemType = QGraphicsItem::UserType + 300;
528
    int weldingSymbolItemType = QGraphicsItem::UserType + 340;
529
    int centerMarkItemType = QGraphicsItem::UserType + 171;
530
    QRectF result;
531
    for (auto& child : children) {
532
        if (!child->isVisible()) {
533
            continue;
534
        }
535
        if ( (child->type() != dimItemType) &&
536
             (child->type() != leaderItemType) &&
537
             (child->type() != textLeaderItemType) &&
538
             (child->type() != editablePathItemType) &&
539
             (child->type() != movableTextItemType) &&
540
             (child->type() != borderItemType) &&
541
             (child->type() != labelItemType)  &&
542
             (child->type() != weldingSymbolItemType)  &&
543
             (child->type() != captionItemType)  &&
544
             (child->type() != centerMarkItemType)) {
545
            QRectF childRect = mapFromItem(child, child->boundingRect()).boundingRect();
546
            result = result.united(childRect);
547
        }
548
    }
549
    return result;
550
}
551

552
QRectF QGIView::boundingRect() const
553
{
554
    return m_border->rect().adjusted(-2., -2., 2., 2.);     //allow for border line width  //TODO: fiddle brect if border off?
555
}
556

557
QGIView* QGIView::getQGIVByName(std::string name)
558
{
559
    QList<QGraphicsItem*> qgItems = scene()->items();
560
    QList<QGraphicsItem*>::iterator it = qgItems.begin();
561
    for (; it != qgItems.end(); it++) {
562
        QGIView* qv = dynamic_cast<QGIView*>((*it));
563
        if (qv) {
564
            std::string qvName = qv->getViewNameAsString();
565
            if (name == qvName) {
566
                return (qv);
567
            }
568
        }
569
    }
570
    return nullptr;
571
}
572

573
/* static */
574
Gui::ViewProvider* QGIView::getViewProvider(App::DocumentObject* obj)
575
{
576
    if (obj) {
577
        Gui::Document* guiDoc = Gui::Application::Instance->getDocument(obj->getDocument());
578
        return guiDoc->getViewProvider(obj);
579
    }
580
    return nullptr;
581
}
582

583
MDIViewPage* QGIView::getMDIViewPage() const
584
{
585
    if (!getViewObject()) {
586
        return nullptr;
587
    }
588
    ViewProviderPage* vpp = getViewProviderPage(getViewObject());
589
    if (vpp) {
590
        return vpp->getMDIViewPage();
591
    }
592
    return nullptr;
593
}
594

595
ViewProviderPage* QGIView::getViewProviderPage(TechDraw::DrawView* dView)
596
{
597
    if (!dView)  {
598
        return nullptr;
599
    }
600
    TechDraw::DrawPage* page = dView->findParentPage();
601
    if (!page) {
602
        return nullptr;
603
    }
604

605
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
606
    if (!activeGui) {
607
        return nullptr;
608
    }
609

610
    return dynamic_cast<ViewProviderPage*>(activeGui->getViewProvider(page));
611
}
612

613
//remove a child of this from scene while keeping scene indexes valid
614
void QGIView::removeChild(QGIView* child)
615
{
616
    if (child && (child->parentItem() == this) ) {
617
        prepareGeometryChange();
618
        scene()->removeItem(child);
619
    }
620
}
621

622
bool QGIView::getFrameState()
623
{
624
//    Base::Console().Message("QGIV::getFrameState() - %s\n", getViewName());
625
    TechDraw::DrawView* dv = getViewObject();
626
    if (!dv) return true;
627

628
    TechDraw::DrawPage* page = dv->findParentPage();
629
    if (!page) return true;
630

631
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
632
    Gui::ViewProvider* vp = activeGui->getViewProvider(page);
633
    ViewProviderPage* vpp = dynamic_cast<ViewProviderPage*>(vp);
634
    if (!vpp) return true;
635

636
    return vpp->getFrameState();
637
}
638

639
void QGIView::hideFrame()
640
{
641
    m_border->hide();
642
    m_label->hide();
643
}
644

645
void QGIView::addArbitraryItem(QGraphicsItem* qgi)
646
{
647
    if (qgi) {
648
//        m_randomItems.push_back(qgi);
649
        addToGroup(qgi);
650
        qgi->show();
651
    }
652
}
653

654
void QGIView::switchParentItem(QGIView *targetParent)
655
{
656
    auto currentParent = dynamic_cast<QGIView *>(this->parentItem());
657
    if (currentParent != targetParent) {
658
        if (targetParent) {
659
            targetParent->addToGroup(this);
660
            targetParent->updateView();
661
            if (currentParent) {
662
                currentParent->updateView();
663
            }
664
        }
665
        else {
666
            while (currentParent) {
667
                currentParent->removeFromGroup(this);
668
                currentParent->updateView();
669
                currentParent = dynamic_cast<QGIView *>(this->parentItem());
670
            }
671
        }
672
    }
673
}
674

675
void QGIView::setStack(int z)
676
{
677
    m_zOrder = z;
678
    setZValue(z);
679
    draw();
680
}
681

682
void QGIView::setStackFromVP()
683
{
684
    TechDraw::DrawView* feature = getViewObject();
685
    ViewProviderDrawingView* vpdv = static_cast<ViewProviderDrawingView*>
686
                                    (getViewProvider(feature));
687
    int z = vpdv->getZ();
688
    setStack(z);
689
}
690

691
QColor QGIView::prefNormalColor()
692
{
693
    return PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
694
}
695

696
QColor QGIView::getPreColor()
697
{
698
    return PreferencesGui::getAccessibleQColor(PreferencesGui::preselectQColor());
699
}
700

701
QColor QGIView::getSelectColor()
702
{
703
    return PreferencesGui::getAccessibleQColor(PreferencesGui::selectQColor());
704
}
705

706
Base::Reference<ParameterGrp> QGIView::getParmGroupCol()
707
{
708
    return App::GetApplication().GetUserParameter()
709
           .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
710
}
711

712
//convert input font size in mm to scene units
713
//note that when used to set font size this will result in
714
//text that is smaller than sizeInMillimetres.  If exactly
715
//correct sized text is required, use exactFontSize.
716
int QGIView::calculateFontPixelSize(double sizeInMillimetres)
717
{
718
    // Calculate font size in pixels by using resolution conversion
719
    // and round to nearest integer
720
    return (int) (Rez::guiX(sizeInMillimetres) + 0.5);
721
}
722

723
int QGIView::calculateFontPixelWidth(const QFont &font)
724
{
725
    // Return the width of digit 0, most likely the most wide digit
726
    return Gui::QtTools::horizontalAdvance(QFontMetrics(font), QChar::fromLatin1('0'));
727
}
728

729
const double QGIView::DefaultFontSizeInMM = 5.0;
730

731
void QGIView::dumpRect(const char* text, QRectF rect) {
732
    Base::Console().Message("DUMP - %s - rect: (%.3f, %.3f) x (%.3f, %.3f)\n", text,
733
                            rect.left(), rect.top(), rect.right(), rect.bottom());
734
}
735

736
//determine the required font size to generate text with upper case
737
//letter height = nominalSize
738
int QGIView::exactFontSize(std::string fontFamily, double nominalSize)
739
{
740
    double sceneSize = Rez::guiX(nominalSize);      //desired height in scene units
741
    QFont font;
742
    font.setFamily(QString::fromUtf8(fontFamily.c_str()));
743
    font.setPixelSize(sceneSize);
744

745
    QFontMetricsF fm(font);
746
    double capHeight = fm.capHeight();
747
    double ratio = sceneSize / capHeight;
748
    return (int) sceneSize * ratio;
749
}
750

751
void QGIView::makeMark(double xPos, double yPos, QColor color)
752
{
753
    QGIVertex* vItem = new QGIVertex(-1);
754
    vItem->setParentItem(this);
755
    vItem->setPos(xPos, yPos);
756
    vItem->setWidth(2.0);
757
    vItem->setRadius(20.0);
758
    vItem->setNormalColor(color);
759
    vItem->setFillColor(color);
760
    vItem->setPrettyNormal();
761
    vItem->setZValue(ZVALUE::VERTEX);
762
}
763

764
void QGIView::makeMark(Base::Vector3d pos, QColor color)
765
{
766
    makeMark(pos.x, pos.y, color);
767
}
768

769
void QGIView::makeMark(QPointF pos, QColor color)
770
{
771
    makeMark(pos.x(), pos.y(), color);
772
}
773

774
#include <Mod/TechDraw/Gui/moc_QGIView.cpp>
775

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.