Salome HOME
998f6eb172cb7f54deabaa931ccd3007e19ef16f
[modules/gui.git] / src / Qtx / QtxMRUAction.h
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      QtxMRUAction.h
24 // Author:    Sergey TELKOV
25 //
26 #ifndef QTXMRUACTION_H
27 #define QTXMRUACTION_H
28
29 #include "QtxAction.h"
30
31 #include <QStringList>
32
33 class QtxResourceMgr;
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 class QTX_EXPORT QtxMRUAction : public QtxAction
40 {
41   Q_OBJECT
42
43 public:
44   //! Items insertion policy
45   typedef enum { MoveFirst,   //!< put the specified item to the beginning
46                  MoveLast,    //!< put the specified item to the end
47                  AddFirst,    //!< if specified item doesn't exist, add it to the beginning
48                  AddLast      //!< if specified item doesn't exist, add it to the end
49   } InsertionMode;
50
51   typedef enum { LinkAuto,    //!< put the full path of link into the menu if link file names of severals link are same
52                  LinkShort,   //!< put the only file name of link into the menu
53                  LinkFull     //!< put the full path of link into the menu
54   } LinkType;
55
56 public:
57   QtxMRUAction( QObject* = 0 );
58   QtxMRUAction( const QString&, const QString&, QObject* = 0 );
59   QtxMRUAction( const QString&, const QIcon&, const QString&, QObject* = 0 );
60   virtual ~QtxMRUAction();
61
62   int          insertMode() const;
63   void         setInsertMode( const int );
64
65   int          linkType() const;
66   void         setLinkType( const int );
67
68   int          count() const;
69   bool         isEmpty() const;
70
71   int          visibleCount() const;
72   void         setVisibleCount( const int );
73
74   bool         isClearPossible() const;
75   void         setClearPossible( const bool );
76
77   int          historyCount() const;
78   void         setHistoryCount( const int );
79
80   void         remove( const int );
81   void         remove( const QString& );
82   void         insert( const QString& );
83
84   QString      item( const int ) const;
85   int          find( const QString& ) const;
86   bool         contains( const QString& ) const;
87
88   virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true );
89   virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const;
90
91 public slots:
92   void         clear();
93
94 signals:
95   void         activated( const QString& );
96
97 private slots:
98   void         onActivated();
99   void         onAboutToShow();
100   void         onCleared( bool );
101
102 private:
103   void         updateMenu();
104
105 private:
106   QStringList  myLinks;        //!< most recent used items
107   QAction*     myClear;        //!< clear item
108   int          myVisCount;     //!< number of visible MRU items
109   int          myHistoryCount; //!< number of stored MRU items
110   int          myLinkType;     //!< type of link names in menu
111   int          myInsertMode;   //!< items insertion policy
112 };
113
114 #endif