]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
SalomePyQt: allow inserting custom widget as a Preferences item V8_3_asterstudy_v0.8.1
authorvsr <vsr@opencascade.com>
Mon, 22 May 2017 05:59:44 +0000 (08:59 +0300)
committervsr <vsr@opencascade.com>
Wed, 31 May 2017 09:44:45 +0000 (12:44 +0300)
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip

index 4748bde6982715b6c778880625545e9b1a41ccf9..699ce585fe5122057558b27bed50a58d235c49e7 100644 (file)
 #include <QApplication>
 #include <QPaintEvent>
 #include <QCoreApplication>
 #include <QApplication>
 #include <QPaintEvent>
 #include <QCoreApplication>
+#include <QVBoxLayout>
 
 #include <utilities.h>
 
 #include <utilities.h>
+
 namespace
 {
   /*!
 namespace
 {
   /*!
@@ -329,6 +331,90 @@ void SALOME_Selection::ClearFilters()
   ProcessVoidEvent( new TEvent( mySelMgr ) );
 }
 
   ProcessVoidEvent( new TEvent( mySelMgr ) );
 }
 
+/*!
+  \class UserDefinedContent
+  \brief The class represents base class for user defined widget that
+  can be inserted to the Preferences dialog.
+*/
+
+/*!
+  \brief Constructor
+*/
+UserDefinedContent::UserDefinedContent()
+  : QWidget()
+{
+}
+
+/*!
+  \brief Called from Preferences dialog to store settings to the resource file.
+*/
+void UserDefinedContent::store()
+{
+}
+
+/*!
+  \brief Called from Preferences dialog to restore settings from the resource file.
+*/
+void UserDefinedContent::retrieve()
+{
+}
+
+/*!
+  \class SgPyQtUserDefinedContent
+  \brief A Wrapper for UserDefinedContent class.
+  \internal
+*/
+class SgPyQtUserDefinedContent: public QtxUserDefinedContent
+{
+public:
+  SgPyQtUserDefinedContent(UserDefinedContent*);
+  virtual ~SgPyQtUserDefinedContent();
+
+  void store( QtxResourceMgr*, QtxPreferenceMgr* );
+  void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
+
+private:
+  UserDefinedContent* myContent;
+};
+
+/*!
+  \brief Create custom item for Preferences dialog wrapping widget passed from Python.
+  \internal
+*/
+SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
+  : QtxUserDefinedContent( 0 ), myContent( content )
+{
+  QVBoxLayout* l = new QVBoxLayout( this );
+  l->setContentsMargins( 0, 0, 0, 0 );
+  l->addWidget( myContent );
+}
+
+/*!
+  \brief Destructor.
+  \internal
+*/
+SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
+{
+}
+
+/*!
+  \brief Called from Preferences dialog to store settings to the resource file.
+  \internal
+*/
+void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
+{
+  myContent->store();
+}
+
+/*!
+  \brief Called from Preferences dialog to restore settings from the resource file.
+  \internal
+*/
+void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
+{
+  myContent->retrieve();
+}
+
 /*!
   \class SalomePyQt
   \brief The class provides utility functions which can be used in the Python
 /*!
   \class SalomePyQt
   \brief The class provides utility functions which can be used in the Python
@@ -2440,7 +2526,39 @@ void SalomePyQt::setPreferenceProperty( const int id,
       }
     }
   };
       }
     }
   };
-  ProcessVoidEvent( new TEvent( id, prop, var) );
+  ProcessVoidEvent( new TEvent( id, prop, var ) );
+}
+
+/*!
+  \brief Set specific widget as a custom preferences item.
+  \param id preferences identifier
+  \param prop preferences property name
+  \param widget custom widget
+*/
+void SalomePyQt::setPreferencePropertyWg( const int id, 
+                                          const QString& prop,
+                                          UserDefinedContent* widget )
+{
+  class TEvent: public SALOME_Event
+  {
+    int      myId;
+    QString  myProp;
+    UserDefinedContent* myWidget;
+  public:
+    TEvent( const int id, const QString& prop, UserDefinedContent* widget ) 
+      : myId( id ), myProp( prop ), myWidget( widget ) {}
+    virtual void Execute() 
+    {
+      LightApp_Module* module = getActiveModule();
+      if ( module ) {
+       LightApp_Preferences* pref = module->getApp()->preferences();
+       if ( pref ) {
+         pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( id, prop, widget ) );
 }
 
 /*!
 }
 
 /*!
index d31a8600fcee4365ef0f0ff845b9534a6afbb556..a64b01e897527e70aaa2049c7c76440ec33fad1a 100644 (file)
@@ -114,6 +114,23 @@ enum {
   PT_Font     = LightApp_Preferences::Font, 
   PT_DirList  = LightApp_Preferences::DirList, 
   PT_File     = LightApp_Preferences::File, 
   PT_Font     = LightApp_Preferences::Font, 
   PT_DirList  = LightApp_Preferences::DirList, 
   PT_File     = LightApp_Preferences::File, 
+  PT_Slider       = LightApp_Preferences::Slider, 
+  PT_Shortcut     = LightApp_Preferences::Shortcut, 
+  PT_ShortcutTree = LightApp_Preferences::ShortcutTree, 
+  PT_BiColor      = LightApp_Preferences::BiColor, 
+  PT_Background   = LightApp_Preferences::Background, 
+  PT_UserDefined  = LightApp_Preferences::UserDefined, 
+};
+
+class UserDefinedContent: public QWidget
+{
+  Q_OBJECT
+
+public:
+  explicit UserDefinedContent();
+
+  virtual void store();
+  virtual void retrieve();
 };
 
 //! Orientation
 };
 
 //! Orientation
@@ -277,6 +294,7 @@ public:
                                           const QString& = QString() );
   static QVariant          preferenceProperty( const int, const QString& );
   static void              setPreferenceProperty( const int, const QString&, const QVariant& );
                                           const QString& = QString() );
   static QVariant          preferenceProperty( const int, const QString& );
   static void              setPreferenceProperty( const int, const QString&, const QVariant& );
+  static void              setPreferencePropertyWg( const int, const QString&, UserDefinedContent* );
   static void              addPreferenceProperty( const int, const QString&, const int, const QVariant& );
 
   static void              message( const QString&, bool = true );
   static void              addPreferenceProperty( const int, const QString&, const int, const QVariant& );
 
   static void              message( const QString&, bool = true );
index 59309bcfdb0481a4edcd55f08717c6f53a83b678..ca70e94c574d53085f758500c7bd885902332afd 100644 (file)
@@ -102,6 +102,12 @@ enum PrefType {
   PT_Font, 
   PT_DirList, 
   PT_File, 
   PT_Font, 
   PT_DirList, 
   PT_File, 
+  PT_Slider,
+  PT_Shortcut,
+  PT_ShortcutTree,
+  PT_BiColor,
+  PT_Background,
+  PT_UserDefined
 };
 
 enum Orientation {
 };
 
 enum Orientation {
@@ -237,6 +243,26 @@ private:
   QtxTreeView( const QtxTreeView& );
 };
 
   QtxTreeView( const QtxTreeView& );
 };
 
+class UserDefinedContent : public QWidget
+{
+%TypeHeaderCode
+#include <SalomePyQt.h>
+%End
+
+%ConvertToSubClassCode
+    if ( qobject_cast<UserDefinedContent*>( sipCpp ) )
+      sipClass = sipClass_UserDefinedContent;
+    else
+      sipClass = NULL;
+%End
+
+public:
+  explicit UserDefinedContent();
+
+  virtual void store();
+  virtual void retrieve();
+};
+
 enum VisibilityState 
 {
   ShownState,
 enum VisibilityState 
 {
   ShownState,
@@ -391,6 +417,9 @@ public:
   static void              setPreferenceProperty( const int, 
                                                   const QString&,
                                                   const QVariant& ) /ReleaseGIL/ ;
   static void              setPreferenceProperty( const int, 
                                                   const QString&,
                                                   const QVariant& ) /ReleaseGIL/ ;
+  static void              setPreferencePropertyWg( const int, 
+                                                    const QString&,    
+                                                    UserDefinedContent* ) /ReleaseGIL/ ;
   static void              addPreferenceProperty( const int, 
                                                   const QString&, 
                                                  const int, 
   static void              addPreferenceProperty( const int, 
                                                   const QString&, 
                                                  const int,