ViewProviderPage.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # ifdef FC_OS_WIN32
00028 # include <windows.h>
00029 # endif
00030 # include <QAction>
00031 # include <QMenu>
00032 # include <QTimer>
00033 #endif
00034
00036 #include <Base/Console.h>
00037 #include <Base/Parameter.h>
00038 #include <Base/Exception.h>
00039 #include <Base/Sequencer.h>
00040 #include <App/Application.h>
00041 #include <App/Document.h>
00042 #include <App/DocumentObject.h>
00043 #include <Gui/SoFCSelection.h>
00044 #include <Gui/Selection.h>
00045 #include <Gui/MainWindow.h>
00046 #include <Gui/BitmapFactory.h>
00047 #include <Gui/ViewProviderDocumentObjectGroup.h>
00048
00049
00050 #include "ViewProviderPage.h"
00051 #include <Mod/Drawing/App/FeaturePage.h>
00052
00053 using namespace DrawingGui;
00054
00055 PROPERTY_SOURCE(DrawingGui::ViewProviderDrawingPage, Gui::ViewProviderDocumentObjectGroup)
00056
00057
00058
00059
00060
00061 ViewProviderDrawingPage::ViewProviderDrawingPage()
00062 : view(0)
00063 {
00064 sPixmap = "Page";
00065 ADD_PROPERTY(HintScale,(10.0));
00066 ADD_PROPERTY(HintOffsetX,(10.0));
00067 ADD_PROPERTY(HintOffsetY,(10.0));
00068 }
00069
00070 ViewProviderDrawingPage::~ViewProviderDrawingPage()
00071 {
00072 }
00073
00074 void ViewProviderDrawingPage::attach(App::DocumentObject *pcFeat)
00075 {
00076
00077 ViewProviderDocumentObject::attach(pcFeat);
00078 }
00079
00080 void ViewProviderDrawingPage::setDisplayMode(const char* ModeName)
00081 {
00082 ViewProviderDocumentObject::setDisplayMode(ModeName);
00083 }
00084
00085 std::vector<std::string> ViewProviderDrawingPage::getDisplayModes(void) const
00086 {
00087
00088 std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
00089 StrList.push_back("Drawing");
00090 return StrList;
00091 }
00092
00093 void ViewProviderDrawingPage::updateData(const App::Property* prop)
00094 {
00095 Gui::ViewProviderDocumentObjectGroup::updateData(prop);
00096 if (prop->getTypeId() == App::PropertyFileIncluded::getClassTypeId()) {
00097 if (std::string(getPageObject()->PageResult.getValue()) != "") {
00098 DrawingView* view = showDrawingView();
00099 view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
00100 if (view->isHidden())
00101 QTimer::singleShot(300, view, SLOT(viewAll()));
00102 else
00103 view->viewAll();
00104 }
00105 }
00106 }
00107
00108 void ViewProviderDrawingPage::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
00109 {
00110 QAction* act;
00111 act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
00112 }
00113
00114 bool ViewProviderDrawingPage::setEdit(int ModNum)
00115 {
00116 doubleClicked();
00117 return false;
00118 }
00119
00120 bool ViewProviderDrawingPage::doubleClicked(void)
00121 {
00122 if (!this->view) {
00123 showDrawingView();
00124 this->view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
00125 view->viewAll();
00126 }
00127 Gui::getMainWindow()->setActiveWindow(this->view);
00128 return true;
00129 }
00130
00131 DrawingView* ViewProviderDrawingPage::showDrawingView()
00132 {
00133 if (!view){
00134 view = new DrawingView(Gui::getMainWindow());
00135 view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape"));
00136 view->setWindowTitle(QObject::tr("Drawing viewer"));
00137 Gui::getMainWindow()->addWindow(view);
00138 }
00139
00140 return view;
00141 }
00142
00143 Drawing::FeaturePage* ViewProviderDrawingPage::getPageObject() const
00144 {
00145 return dynamic_cast<Drawing::FeaturePage*>(pcObject);
00146 }