Salome HOME
8ad60be5bb1e9b0764f7c8f9b69df617c7859a03
[modules/gui.git] / src / Qtx / QtxListAction.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/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      QtxListAction.hxx
20 // Author:    Sergey TELKOV (Based on code by Eugene AKSENOV)
21
22 #ifndef QTXLISTACTION_H
23 #define QTXLISTACTION_H
24
25 #include "QtxAction.h"
26
27 #include <qmap.h>
28 #include <qframe.h>
29 #include <qstringlist.h>
30
31 class QLabel;
32 class QListBox;
33 class QPopupMenu;
34 class QToolButton;
35 class QToolTipGroup;
36
37 class QtxListFrame;
38
39 #ifdef WIN32
40 #pragma warning( disable:4251 )
41 #endif
42
43 class QTX_EXPORT QtxListAction : public QtxAction
44 {
45     Q_OBJECT
46
47     Q_PROPERTY( QStringList names READ names WRITE addNames )
48
49     class ToolButton;
50
51 public:
52     enum { Item, SubMenu } PopupMode;
53
54 public:
55     QtxListAction( QObject* = 0, const char* = 0, bool = false );
56     QtxListAction( const QString&, const QIconSet&, const QString&, int, QObject*, const char* = 0, bool = false );
57     QtxListAction( const QString&, const QString&, int, QObject*, const char* = 0, bool = false );
58     virtual ~QtxListAction();
59
60 public:
61     virtual bool            addTo( QWidget* );
62     virtual bool            addTo( QWidget*, const int );
63
64     virtual bool            removeFrom( QWidget* );
65     virtual bool            eventFilter( QObject*, QEvent* );
66
67     int                     popupMode() const;
68     void                    setPopupMode( const int );
69
70     QStringList             names() const;
71     void                    addNames( const QStringList&, bool = true );
72     void                    setComment( const QString&, const QString& = QString::null );
73
74     void                    setMaxLines( int );
75     void                    setMaxLineChars( int );
76
77 signals:
78     void                    activated( int );
79
80 public slots:
81     virtual void            setEnabled( bool );
82
83 private slots:
84     void                    onHided();
85     void                    onSingle();
86     void                    onExpand( bool );
87     void                    onMultiple( int );
88     void                    onActivated( int );
89     void                    onDestroyed( QObject* );
90
91 protected:
92     virtual void            addedTo( QWidget*, QWidget* );
93
94 private:
95     void                    initialize();
96     QWidget*                widget( QWidget* ) const;
97     QPopupMenu*             listPopup( QWidget* ) const;
98     QToolButton*            mainButton( QWidget* ) const;
99     QToolButton*            dropButton( QWidget* ) const;
100
101     void                    controlDeleted( QWidget* );
102
103 private:
104     typedef struct { int id; QPopupMenu* popup; } Popups;
105     typedef struct { QToolButton* main; QToolButton* drop; } Buttons;
106     typedef QMap<QWidget*, Popups>  PopupsMap;
107     typedef QMap<QWidget*, Buttons> ButtonsMap;
108     
109 private:
110     int                     myMode;
111     QtxListFrame*           myFrame;
112     bool                    myRaise;
113     PopupsMap               myPopups;
114     ButtonsMap              myButtons;
115     QToolTipGroup*          myTipGroup;
116
117     friend class ToolButton;
118     friend class QtxListFrame;
119 };
120
121 /*!
122   \class QtxListFrame
123 */
124 class QtxListFrame : public QFrame
125 {
126     Q_OBJECT
127
128     class ScrollEvent;
129
130 public:
131     QtxListFrame( QtxListAction*, QWidget* parent, WFlags f = 0 );
132     virtual ~QtxListFrame();
133
134     void                    clear();
135     const QStringList       names() const;
136     void                    addNames( const QStringList& );
137     
138     void                    setSingleComment( const QString& );
139     void                    setMultipleComment( const QString& );
140     
141     int                     selected() const;
142     void                    setSelected( const int );
143     
144     void                    setMaxLines( int );
145     void                    setMaxLineChars( int );
146     
147     virtual bool            event( QEvent* );
148     virtual bool            eventFilter( QObject*, QEvent* );
149
150     void                    setOwner( QWidget* );
151
152     void                    updateComment();
153     
154 signals:
155     void                    hided();
156     void                    selected( int );
157     
158 public slots:
159     virtual void            show();
160     virtual void            hide();
161     
162 private slots:
163     void                    reject();
164     void                    accept();
165     
166     void                    onScroll( int, int );
167     
168 private:
169     void                    setNames( const QStringList& );
170     bool                    handleKeyEvent( QObject*, QKeyEvent* );
171     bool                    handleMouseEvent( QObject*, QMouseEvent* );
172
173     friend class QtxListAction;
174     
175 private:
176     QListBox*               myList;
177     QStringList             myNames;
178     QWidget*                myOwner;
179     QtxListAction*          myAction;
180     QLabel*                 myComment;
181     
182     QString                 mySingleComment;
183     QString                 myMultipleComment;
184     
185     int                     myMaxLines;
186     int                     myMaxLineChars;
187     
188     int                     myScrollVal;
189     bool                    myScrollBlock;
190 };
191
192 #ifdef WIN32
193 #pragma warning( default:4251 )
194 #endif
195
196 #endif