Salome HOME
debd6bdfb490676c24a5ddb84343b83b5b511b3c
[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   Q_PROPERTY( int visibleCount READ visibleCount WRITE setVisibleCount )
42
43 public:
44   enum { Items, SubMenu };
45   enum { MoveFirst, MoveLast, AddFirst, AddLast };
46
47 public:
48   QtxMRUAction( QObject* = 0, const char* = 0 );
49   QtxMRUAction( const QString&, const QString&, QObject*, const char* = 0 );
50   QtxMRUAction( const QString&, const QIconSet&, const QString&, QObject*, const char* = 0 );
51   virtual ~QtxMRUAction();
52
53   int          insertMode() const;
54   void         setInsertMode( const int );
55
56   int          popupMode() const;
57   void         setPopupMode( const int );
58
59   int          count() const;
60   bool         isEmpty() const;
61
62   int          visibleCount() const;
63   void         setVisibleCount( const int );
64
65   void         remove( const int );
66   void         remove( const QString& );
67   void         insert( const QString& );
68
69   QString      item( const int ) const;
70   int          find( const QString& ) const;
71   bool         contains( const QString& ) const;
72
73   virtual bool addTo( QWidget* );
74   virtual bool addTo( QWidget*, const int );
75
76   virtual bool removeFrom( QWidget* );
77
78   virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true );
79   virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const;
80
81 signals:
82   void         activated( QString );
83
84 public slots:
85   virtual void setEnabled( bool );
86
87 private slots:
88   void         onAboutToShow();
89   void         onActivated( int );
90   void         onDestroyed( QObject* );
91
92 private:
93   void         updateState();
94   void         checkPopup( QPopupMenu* );
95   void         updatePopup( QPopupMenu*, const int );
96   bool         removeLinks( QPopupMenu*, const int );
97   bool         insertLinks( QPopupMenu*, const int, const int = -1 );
98
99   int          findId( QPopupMenu*, QPopupMenu* ) const;
100
101 private:
102   typedef struct { int pId, nId; QIntList idList; } Item;
103   typedef QMap<QPopupMenu*, Item>                   ItemsMap;
104   typedef QMap<QPopupMenu*, QPopupMenu*>            MenusMap;
105
106 private:
107   QStringList  myLinks;
108   ItemsMap     myItems;
109   MenusMap     myMenus;
110   int          myVisCount;
111   int          myPopupMode;
112   int          myInsertMode;
113 };
114
115 #endif