| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2024 Florian Foinant-Willig <[email protected]> * |
| 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 |
|
| 24 |
#include <App/Document.h> |
| 25 |
#include <App/SuppressibleExtension.h> |
| 26 |
|
| 27 |
#include "ActionFunction.h" |
| 28 |
#include "Control.h" |
| 29 |
#include "Document.h" |
| 30 |
|
| 31 |
#include "Application.h" |
| 32 |
#include "TreeItemMode.h" |
| 33 |
|
| 34 |
#include "ViewProviderSuppressibleExtension.h" |
| 35 |
#include "BitmapFactory.h" |
| 36 |
#include "ViewProviderDocumentObject.h" |
| 37 |
#include "qmenu.h" |
| 38 |
|
| 39 |
|
| 40 |
using namespace Gui; |
| 41 |
|
| 42 |
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderSuppressibleExtension, Gui::ViewProviderExtension) |
| 43 |
|
| 44 |
ViewProviderSuppressibleExtension::ViewProviderSuppressibleExtension() |
| 45 |
{ |
| 46 |
initExtensionType(ViewProviderSuppressibleExtension::getExtensionClassTypeId()); |
| 47 |
} |
| 48 |
|
| 49 |
ViewProviderSuppressibleExtension::~ViewProviderSuppressibleExtension() = default; |
| 50 |
|
| 51 |
void ViewProviderSuppressibleExtension::extensionUpdateData(const App::Property* prop) |
| 52 |
{ |
| 53 |
auto vp = getExtendedViewProvider(); |
| 54 |
auto owner = vp->getObject(); |
| 55 |
if (!owner || !owner->isValid()) { |
| 56 |
return; |
| 57 |
} |
| 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 |
{ |
| 71 |
isSetSuppressedIcon = onoff; |
| 72 |
|
| 73 |
getExtendedViewProvider()->signalChangeIcon(); // signal icon change |
| 74 |
} |
| 75 |
|
| 76 |
QIcon ViewProviderSuppressibleExtension::extensionMergeColorfullOverlayIcons(const QIcon& orig) const |
| 77 |
{ |
| 78 |
QIcon mergedicon = orig; |
| 79 |
|
| 80 |
if (isSetSuppressedIcon) { |
| 81 |
static QPixmap px(Gui::BitmapFactory().pixmapFromSvg("feature_suppressed", QSize(16, 16))); |
| 82 |
|
| 83 |
mergedicon |
| 84 |
= Gui::BitmapFactoryInst::mergePixmap(mergedicon, px, Gui::BitmapFactoryInst::TopLeft); |
| 85 |
} |
| 86 |
return Gui::ViewProviderExtension::extensionMergeColorfullOverlayIcons(mergedicon); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
void ViewProviderSuppressibleExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*) |
| 91 |
{ |
| 92 |
auto vp = getExtendedViewProvider(); |
| 93 |
auto obj = vp->getObject()->getExtensionByType<App::SuppressibleExtension>(); |
| 94 |
// Show Suppressed toggle action if the Suppressed property is visible |
| 95 |
if (obj && !obj->Suppressed.testStatus(App::Property::Hidden)) { |
| 96 |
Gui::ActionFunction* func = new Gui::ActionFunction(menu); |
| 97 |
QAction* act = menu->addAction(QObject::tr("Suppressed")); |
| 98 |
act->setCheckable(true); |
| 99 |
act->setChecked(obj->Suppressed.getValue()); |
| 100 |
func->trigger(act, [obj]() { obj->Suppressed.setValue(!obj->Suppressed.getValue()); }); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
namespace Gui |
| 106 |
{ |
| 107 |
EXTENSION_PROPERTY_SOURCE_TEMPLATE( |
| 108 |
Gui::ViewProviderSuppressibleExtensionPython, |
| 109 |
Gui::ViewProviderSuppressibleExtension |
| 110 |
) |
| 111 |
|
| 112 |
// explicit template instantiation |
| 113 |
template class GuiExport ViewProviderExtensionPythonT<ViewProviderSuppressibleExtension>; |
| 114 |
|
| 115 |
} // namespace Gui |