]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxMRUAction.h
Salome HOME
Bug fix for SSPP10924
[modules/gui.git] / src / Qtx / QtxMRUAction.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxMRUAction.h
20 // Author:    Sergey TELKOV
21
22 #ifndef QTXMRUACTION_H
23 #define QTXMRUACTION_H
24
25 #include "QtxAction.h"
26
27 #include <qmap.h>
28 #include <qstringlist.h>
29
30 class QPopupMenu;
31 class QtxResourceMgr;
32
33 #ifdef WIN32
34 #pragma warning( disable:4251 )
35 #endif
36
37 class QTX_EXPORT QtxMRUAction : public QtxAction
38 {
39   Q_OBJECT
40
41 public:
42   typedef enum { Items, SubMenu }                         PopupMode;
43   typedef enum { MoveFirst, MoveLast, AddFirst, AddLast } InsertMode;
44
45 public:
46   QtxMRUAction( QObject* = 0, const char* = 0 );
47   QtxMRUAction( const QString&, const QString&, QObject*, const char* = 0 );
48   QtxMRUAction( const QString&, const QIconSet&, const QString&, QObject*, const char* = 0 );
49   virtual ~QtxMRUAction();
50
51   int          insertMode() const;
52   void         setInsertMode( const int );
53
54   int          popupMode() const;
55   void         setPopupMode( const int );
56
57   int          count() const;
58   bool         isEmpty() const;
59
60   int          visibleCount() const;
61   void         setVisibleCount( const int );
62
63   void         remove( const int );
64   void         remove( const QString& );
65   void         insert( const QString& );
66
67   QString      item( const int ) const;
68   int          find( const QString& ) const;
69   bool         contains( const QString& ) const;
70
71   virtual bool addTo( QWidget* );
72   virtual bool addTo( QWidget*, const int );
73
74   virtual bool removeFrom( QWidget* );
75
76   virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true );
77   virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const;
78
79 signals:
80   void         activated( QString );
81
82 public slots:
83   virtual void setEnabled( bool );
84
85 private slots:
86   void         onAboutToShow();
87   void         onActivated( int );
88   void         onDestroyed( QObject* );
89
90 private:
91   void         updateState();
92   void         checkPopup( QPopupMenu* );
93   void         updatePopup( QPopupMenu*, const int );
94   bool         removeLinks( QPopupMenu*, const int );
95   bool         insertLinks( QPopupMenu*, const int, const int = -1 );
96
97   int          findId( QPopupMenu*, QPopupMenu* ) const;
98
99 private:
100   typedef struct { int pId, nId; QIntList idList; } Item;
101   typedef QMap<QPopupMenu*, Item>                   ItemsMap;
102   typedef QMap<QPopupMenu*, QPopupMenu*>            MenusMap;
103
104 private:
105   QStringList  myLinks;
106   ItemsMap     myItems;
107   MenusMap     myMenus;
108   int          myVisCount;
109   int          myPopupMode;
110   int          myInsertMode;
111 };
112
113 #endif