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