1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_Popup.cxx
31 #include "QAD_Popup.h"
32 #include "utilities.h"
34 /*****************************************************************************
35 ** Class QAD_PopupClientServer
36 *****************************************************************************/
41 QAD_PopupServer::QAD_PopupServer() :
48 Enables/disables creation of popup.
49 Useful when user doesn't want to create popup
50 provided by server by default and does not
51 want to inherit from the server
53 void QAD_PopupServer::enablePopup( bool enable )
55 myEnablePopup = enable;
59 Called by popup client when it wants
62 QPopupMenu* QAD_PopupServer::createPopup()
68 myPopup = new QPopupMenu;
69 onCreatePopup(); /* add specific menu items */
74 Called by popup client when popup
77 void QAD_PopupServer::destroyPopup()
79 if ( myPopup ) myPopup->clear();
85 QAD_PopupServer::~QAD_PopupServer()
87 delete (QPopupMenu*) myPopup;
90 /*****************************************************************************
91 ** Class QAD_PopupClient
92 *****************************************************************************/
97 QAD_PopupClient::QAD_PopupClient() :
105 QAD_PopupClient::~QAD_PopupClient()
110 Sets a popup server for this client
112 void QAD_PopupClient::setPopupServer ( QAD_PopupServer* server)
114 myPopupServer = server;
118 Returns the popup server for this client
120 QAD_PopupServer* QAD_PopupClient::getPopupServer () const
122 return myPopupServer;
125 /*****************************************************************************
126 ** Class QAD_PopupClientServer
127 *****************************************************************************/
132 QAD_PopupClientServer::QAD_PopupClientServer( bool separateItems, bool smartSeparator ) :
133 myOnlyServer( false ),
134 mySeparateItems( separateItems ),
135 mySmartSeparator( smartSeparator )
142 QAD_PopupClientServer::~QAD_PopupClientServer()
147 Called by popup client when it wants
148 to activate popup. The result is the
149 popup returned by this object's server
150 ( client role ) + the appended popup
151 provided by itself ( server role ).
153 QPopupMenu* QAD_PopupClientServer::createPopup()
155 if ( !myEnablePopup )
158 QPopupMenu* popupMenu = 0;
160 { /* get the popup provided by my server */
161 popupMenu = myPopupServer->createPopup();
165 { /* there is no popup from my server */
166 if ( !myPopup ) myPopup = new QPopupMenu;
172 if ( myPopup ) myPopup->clear();
174 myOnlyServer = false;
177 /* Attach my popup to the popup of my server */
178 if ( popupMenu->count() && mySeparateItems )
180 /* Separate my items only if I will really
183 int sepId, numBefore, numAfter;
184 sepId = mySmartSeparator ? popupMenu->insertSeparator(0) : popupMenu->insertSeparator();
185 numBefore = popupMenu->count();
186 int sepPosBefore = mySmartSeparator ? 0 : numBefore - 1;
191 numAfter = popupMenu->count();
192 int sepPosAfter = popupMenu->indexOf(sepId);
193 if ( numAfter > numBefore || ( sepPosAfter != -1 && sepPosAfter && sepPosAfter != numAfter - 1 ) ) {
194 myIDs.append( sepId );
196 else if ( sepPosAfter != -1 )
197 popupMenu->removeItem( sepId );
200 onCreatePopup(); /* add items */
206 Deactivates the popup
208 void QAD_PopupClientServer::destroyPopup()
212 /* remove all my items */
213 QValueList<int>::ConstIterator it;
214 for( it = myIDs.begin(); it != myIDs.end(); ++it )
215 myPopup->removeItem ( *it );
217 /* clear list of IDs */
221 { /* popup must be empty now */
222 QAD_ASSERT_DEBUG_ONLY ( !myPopup->count() );
228 /* dispatch to my server */
230 myPopupServer->destroyPopup();