FreeCAD

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

25

26
#include "PreCompiled.h"
27

28
#ifndef _PreComp_
29
# include <QAction>
30
# include <QMenu>
31
#include <QTextStream>
32
#include <QMessageBox>
33
#endif
34

35
#include <App/DocumentObject.h>
36
#include <Gui/ActionFunction.h>
37
#include <Gui/Control.h>
38
#include <Gui/MainWindow.h>
39
#include <Gui/Selection.h>
40
#include <Gui/ViewProviderDocumentObject.h>
41

42
#include <Mod/TechDraw/App/LineGroup.h>
43

44
#include "PreferencesGui.h"
45
#include "ZVALUE.h"
46
#include "QGIViewBalloon.h"
47
#include "TaskBalloon.h"
48
#include "ViewProviderBalloon.h"
49

50
using namespace TechDrawGui;
51
using namespace TechDraw;
52

53
PROPERTY_SOURCE(TechDrawGui::ViewProviderBalloon, TechDrawGui::ViewProviderDrawingView)
54

55
//**************************************************************************
56
// Construction/Destruction
57

58
ViewProviderBalloon::ViewProviderBalloon()
59
{
60
    sPixmap = "TechDraw_Balloon";
61

62
    static const char *group = "Balloon Format";
63

64
    ADD_PROPERTY_TYPE(Font, (Preferences::labelFont().c_str()), group, App::Prop_None, "The name of the font to use");
65
    ADD_PROPERTY_TYPE(Fontsize, (Preferences::dimFontSizeMM()),
66
                                group, (App::PropertyType)(App::Prop_None), "Balloon text size in units");
67
    double weight = TechDraw::LineGroup::getDefaultWidth("Thin");
68
    ADD_PROPERTY_TYPE(LineWidth, (weight), group, (App::PropertyType)(App::Prop_None), "Leader line width");
69
    ADD_PROPERTY_TYPE(LineVisible, (true), group, (App::PropertyType)(App::Prop_None), "Balloon line visible or hidden");
70
    ADD_PROPERTY_TYPE(Color, (PreferencesGui::dimColor()), group, App::Prop_None, "Color of the balloon");
71

72
    StackOrder.setValue(ZVALUE::DIMENSION);
73
}
74

75
ViewProviderBalloon::~ViewProviderBalloon()
76
{
77
}
78

79
bool ViewProviderBalloon::doubleClicked()
80
{
81
    startDefaultEditMode();
82
    return true;
83
}
84

85
void ViewProviderBalloon::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
86
{
87
    Gui::ActionFunction* func = new Gui::ActionFunction(menu);
88
    QAction* act = menu->addAction(QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue())));
89
    act->setData(QVariant((int)ViewProvider::Default));
90
    func->trigger(act, [this]() {
91
        this->startDefaultEditMode();
92
    });
93

94
    ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
95
}
96

97
bool ViewProviderBalloon::setEdit(int ModNum)
98
{
99
    if (ModNum != ViewProvider::Default ) {
100
        return ViewProviderDrawingView::setEdit(ModNum);
101
    }
102
    if (Gui::Control().activeDialog())  {
103
        return false;
104
    }
105
    // clear the selection (convenience)
106
    Gui::Selection().clearSelection();
107
    auto qgivBalloon(dynamic_cast<QGIViewBalloon*>(getQView()));
108
    if (qgivBalloon) {
109
        Gui::Control().showDialog(new TaskDlgBalloon(qgivBalloon, this));
110
    }
111
    return true;
112
}
113

114
void ViewProviderBalloon::updateData(const App::Property* p)
115
{
116
    //Balloon handles X, Y updates differently that other QGIView
117
    //call QGIViewBalloon::updateView
118
    if (p == &(getViewObject()->X)  ||
119
        p == &(getViewObject()->Y) ){
120
        QGIView* qgiv = getQView();
121
        if (qgiv) {
122
            qgiv->updateView(true);
123
        }
124
    }
125

126
    //Skip QGIView X, Y processing - do not call ViewProviderDrawingView
127
    Gui::ViewProviderDocumentObject::updateData(p);
128
}
129

130
void ViewProviderBalloon::onChanged(const App::Property* p)
131
{
132
    if ((p == &Font)  ||
133
        (p == &Fontsize) ||
134
        (p == &Color) ||
135
        (p == &LineWidth) ||
136
        (p == &LineVisible)) {
137
        QGIView* qgiv = getQView();
138
        if (qgiv) {
139
            qgiv->updateView(true);
140
        }
141
    }
142
    Gui::ViewProviderDocumentObject::onChanged(p);
143
}
144

145
TechDraw::DrawViewBalloon* ViewProviderBalloon::getViewObject() const
146
{
147
    return dynamic_cast<TechDraw::DrawViewBalloon*>(pcObject);
148
}
149

150
void ViewProviderBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
151
// transforms properties that had been changed
152
{
153
    // property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
154
    if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
155
        App::PropertyFloat LineWidthProperty;
156
        // restore the PropertyFloat to be able to set its value
157
        LineWidthProperty.Restore(reader);
158
        LineWidth.setValue(LineWidthProperty.getValue());
159
    }
160
    else {
161
        ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
162
    }
163
}
164

165
bool ViewProviderBalloon::canDelete(App::DocumentObject *obj) const
166
{
167
    // deletions of a balloon object doesn't destroy anything
168
    // thus we can pass this action
169
    Q_UNUSED(obj)
170
    return true;
171
}
172

173
bool ViewProviderBalloon::onDelete(const std::vector<std::string> & parms)
174
{
175
    Q_UNUSED(parms)
176
//    Base::Console().Message("VPB::onDelete() - parms: %d\n", parms.size());
177
    if (Gui::Control().activeDialog())  {
178
        // TODO: make this selective so only a dialog involving this vp's
179
        // feature is blocked.  As is, this will prevent deletion during any
180
        // task dialog.
181
        QString bodyMessage;
182
        QTextStream bodyMessageStream(&bodyMessage);
183
        bodyMessageStream << qApp->translate("TaskBalloon",
184
            "You cannot delete this balloon now because\nthere is an open task dialog.");
185
        QMessageBox::warning(Gui::getMainWindow(),
186
            qApp->translate("TaskBalloon", "Can Not Delete"), bodyMessage,
187
            QMessageBox::Ok);
188
        return false;
189
    }
190
    return true;
191
}
192

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

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

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

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