FreeCAD

Форк
0
/
ViewProviderSuppressibleExtension.cpp 
111 строк · 4.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr>               *
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

25
#include <App/Document.h>
26
#include <App/SuppressibleExtension.h>
27

28
#include "ActionFunction.h"
29
#include "Control.h"
30
#include "Document.h"
31

32
#include "Application.h"
33
#include "TreeItemMode.h"
34

35
#include "ViewProviderSuppressibleExtension.h"
36
#include "BitmapFactory.h"
37
#include "ViewProviderDocumentObject.h"
38
#include "qmenu.h"
39

40

41
using namespace Gui;
42

43
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderSuppressibleExtension, Gui::ViewProviderExtension)
44

45
ViewProviderSuppressibleExtension::ViewProviderSuppressibleExtension()
46
{
47
    initExtensionType(ViewProviderSuppressibleExtension::getExtensionClassTypeId());
48
}
49

50
ViewProviderSuppressibleExtension::~ViewProviderSuppressibleExtension() = default;
51

52
void ViewProviderSuppressibleExtension::extensionUpdateData(const App::Property* prop)
53
{
54
    auto vp = getExtendedViewProvider();
55
    auto owner = vp->getObject();
56
    if(!owner || !owner->isValid())
57
        return;
58

59
    auto ext = owner->getExtensionByType<App::SuppressibleExtension>();
60

61
    if (ext && prop == &ext->Suppressed) {
62
        //update the tree item
63
        bool suppressed = ext->Suppressed.getValue();
64
        setSuppressedIcon(suppressed);
65
        getExtendedViewProvider()->signalChangeHighlight(suppressed, Gui::HighlightMode::StrikeOut);
66
    }
67
}
68

69
void ViewProviderSuppressibleExtension::setSuppressedIcon(bool onoff) {
70
    isSetSuppressedIcon = onoff;
71

72
    getExtendedViewProvider()->signalChangeIcon(); // signal icon change
73
}
74

75
QIcon ViewProviderSuppressibleExtension::extensionMergeColorfullOverlayIcons (const QIcon & orig) const
76
{
77
    QIcon mergedicon = orig;
78

79
    if(isSetSuppressedIcon) {
80
        static QPixmap px(Gui::BitmapFactory().pixmapFromSvg("feature_suppressed", QSize(16, 16)));
81

82
        mergedicon = Gui::BitmapFactoryInst::mergePixmap(mergedicon, px, Gui::BitmapFactoryInst::TopLeft);
83
    }
84
    return Gui::ViewProviderExtension::extensionMergeColorfullOverlayIcons(mergedicon);
85
}
86

87

88
void ViewProviderSuppressibleExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*)
89
{
90
    auto vp = getExtendedViewProvider();
91
    auto obj = vp->getObject()->getExtensionByType<App::SuppressibleExtension>();
92
    //Show Suppressed toggle action if the Suppressed property is visible
93
    if (obj && ! obj->Suppressed.testStatus(App::Property::Hidden)) {
94
        Gui::ActionFunction* func = new Gui::ActionFunction(menu);
95
        QAction* act = menu->addAction(QObject::tr("Suppressed"));
96
        act->setCheckable(true);
97
        act->setChecked(obj->Suppressed.getValue());
98
        func->trigger(act, [obj](){
99
            obj->Suppressed.setValue(! obj->Suppressed.getValue());
100
        });
101
    }
102
}
103

104

105
namespace Gui {
106
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderSuppressibleExtensionPython, Gui::ViewProviderSuppressibleExtension)
107

108
// explicit template instantiation
109
template class GuiExport ViewProviderExtensionPythonT<ViewProviderSuppressibleExtension>;
110

111
} //namespace Gui
112

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

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

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

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