Salome HOME
0b845e8327d069c571915f391f01fb40db8ea450
[modules/gui.git] / src / Qtx / QtxMRUAction.h
1 // File:      QtxMRUAction.h
2 // Author:    Sergey TELKOV
3
4 #ifndef QTXMRUACTION_H
5 #define QTXMRUACTION_H
6
7 #include "QtxAction.h"
8
9 #include <qmap.h>
10 #include <qstringlist.h>
11
12 class QPopupMenu;
13 class QtxResourceMgr;
14
15 #ifdef WIN32
16 #pragma warning( disable:4251 )
17 #endif
18
19 class QTX_EXPORT QtxMRUAction : public QtxAction
20 {
21   Q_OBJECT
22
23 public:
24   typedef enum { Items, SubMenu }                         PopupMode;
25   typedef enum { MoveFirst, MoveLast, AddFirst, AddLast } InsertMode;
26
27 public:
28   QtxMRUAction( QObject* = 0, const char* = 0 );
29   QtxMRUAction( const QString&, const QString&, QObject*, const char* = 0 );
30   QtxMRUAction( const QString&, const QIconSet&, const QString&, QObject*, const char* = 0 );
31   virtual ~QtxMRUAction();
32
33   int          insertMode() const;
34   void         setInsertMode( const int );
35
36   int          popupMode() const;
37   void         setPopupMode( const int );
38
39   int          count() const;
40   bool         isEmpty() const;
41
42   int          visibleCount() const;
43   void         setVisibleCount( const int );
44
45   void         remove( const int );
46   void         remove( const QString& );
47   void         insert( const QString& );
48
49   QString      item( const int ) const;
50   int          find( const QString& ) const;
51   bool         contains( const QString& ) const;
52
53   virtual bool addTo( QWidget* );
54   virtual bool addTo( QWidget*, const int );
55
56   virtual bool removeFrom( QWidget* );
57
58   virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true );
59   virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const;
60
61 signals:
62   void         activated( QString );
63
64 public slots:
65   virtual void setEnabled( bool );
66
67 private slots:
68   void         onAboutToShow();
69   void         onActivated( int );
70   void         onDestroyed( QObject* );
71
72 private:
73   void         updateState();
74   void         checkPopup( QPopupMenu* );
75   void         updatePopup( QPopupMenu*, const int );
76   bool         removeLinks( QPopupMenu*, const int );
77   bool         insertLinks( QPopupMenu*, const int, const int = -1 );
78
79   int          findId( QPopupMenu*, QPopupMenu* ) const;
80
81 private:
82   typedef struct { int pId, nId; QIntList idList; } Item;
83   typedef QMap<QPopupMenu*, Item>                   ItemsMap;
84   typedef QMap<QPopupMenu*, QPopupMenu*>            MenusMap;
85
86 private:
87   QStringList  myLinks;
88   ItemsMap     myItems;
89   MenusMap     myMenus;
90   int          myVisCount;
91   int          myPopupMode;
92   int          myInsertMode;
93 };
94
95 #endif