// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
+// License as published by the Free Software Foundation; either
// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#include "SUIT_Desktop.h"
#include "SUIT_ViewModel.h"
+#include <SUIT_ViewWindow.h>
#include "SUIT_Study.h"
-#include <qcursor.h>
-#include <qregexp.h>
-#include <qmessagebox.h>
+#include <QMap>
+#include <QRegExp>
+#include <QIcon>
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
myId = useNewId( getType() );
- connect( theDesktop, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+ connect( theDesktop, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
myStudy = theStudy;
return;
myTitle = theTitle;
- for ( uint i = 0; i < myViews.count(); i++ )
+ for ( int i = 0; i < myViews.count(); i++ )
setViewName( myViews[i] );
}
+void SUIT_ViewManager::setIcon( const QPixmap& theIcon )
+{
+ myIcon = theIcon;
+ for ( int i = 0; i < myViews.count(); i++ )
+ myViews[i]->setWindowIcon( QIcon( myIcon ) );
+}
+
/*!Sets view model \a theViewModel to view manager.*/
-void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel)
+void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel)
{
if (myViewModel && myViewModel != theViewModel) {
myViewModel->setViewManager(0);
/*!Sets view name for view window \a theView.*/
void SUIT_ViewManager::setViewName( SUIT_ViewWindow* theView )
{
- QString title = prepareTitle( getTitle(), myId + 1, myViews.find( theView ) + 1 );
- theView->setCaption( title );
+ QString title = prepareTitle( getTitle(), myId + 1, myViews.indexOf( theView ) + 1 );
+ theView->setWindowTitle( title );
}
QString SUIT_ViewManager::prepareTitle( const QString& title, const int mId, const int vId )
QString res = title;
QRegExp re( "%[%MV]" );
int i = 0;
- while ( ( i = re.search( res, i ) ) != -1 )
+ while ( ( i = re.indexIn( res, i ) ) != -1 )
{
QString rplc;
QString str = res.mid( i, re.matchedLength() );
delete aView;
return 0;
}
-
+
setViewName( aView );
+ aView->setWindowIcon( QIcon( myIcon ) );
+
//myDesktop->addViewWindow( aView );
//it is done automatically during creation of view
- aView->setViewManager(this);
-
- emit viewCreated(aView);
+ aView->setViewManager( this );
+ emit viewCreated( aView );
// Special treatment for the case when <aView> is the first one in this view manager
// -> call onWindowActivated() directly, because somebody may always want
createViewWindow();
}
+QVector<SUIT_ViewWindow*> SUIT_ViewManager::getViews() const
+{
+ QVector<SUIT_ViewWindow*> res;
+ for ( int i = 0; i < myViews.count(); i++ )
+ {
+ if ( myViews[i] )
+ res.append( myViews[i] );
+ }
+
+ return res;
+}
+
/*!Insert view window to view manager.
*\retval false - if something wrong, else true.
*/
bool SUIT_ViewManager::insertView(SUIT_ViewWindow* theView)
{
unsigned int aSize = myViews.size();
- unsigned int aNbItems = myViews.count()+1;
- if (aNbItems > aSize) {
- if (!myViews.resize(aNbItems)) {
- QMessageBox::critical(myDesktop, tr("Critical error"), tr("There is no memory for the new view!!!"));
- return false;
- }
+ unsigned int aNbItems = myViews.count() + 1;
+ if ( aNbItems > aSize )
+ {
+ myViews.resize( aNbItems );
aSize = myViews.size();
}
-
+
connect(theView, SIGNAL(closing(SUIT_ViewWindow*)),
this, SLOT(onClosingView(SUIT_ViewWindow*)));
connect(theView, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
this, SLOT (onContextMenuRequested( QContextMenuEvent * )));
- for (uint i = 0; i < aSize; i++) {
- if (myViews[i]==0) {
- myViews.insert(i, theView);
+ for ( uint i = 0; i < aSize; i++ )
+ {
+ if ( myViews[i] == 0 )
+ {
+ myViews[i] = theView;
return true;
}
}
if ( !theView )
return;
- QGuardedPtr<SUIT_ViewWindow> view( theView );
+ QPointer<SUIT_ViewWindow> view( theView );
view->hide();
- if ( !view->testWFlags( WDestructiveClose ) )
+ if ( !view->testAttribute( Qt::WA_DeleteOnClose ) )
return;
emit deleteView( view );
/*!Remove view window \a theView from view manager.
*And close the last view, if it has \a theView.
*/
-void SUIT_ViewManager::removeView(SUIT_ViewWindow* theView)
+void SUIT_ViewManager::removeView( SUIT_ViewWindow* theView )
{
- theView->disconnect(this);
- myViews.remove(myViews.find(theView));
- if (myActiveView == theView)
+ theView->disconnect( this );
+ myViews.remove( myViews.indexOf( theView ) );
+ if ( myActiveView == theView )
myActiveView = 0;
- int aNumItems = myViews.count();
- if (aNumItems == 0)
- emit lastViewClosed(this);
+ if ( !myViews.count() )
+ emit lastViewClosed( this );
}
/*!
*/
void SUIT_ViewManager::setDestructiveClose( const bool on )
{
- for ( uint i = 0; i < myViews.count(); i++ )
+ for ( int i = 0; i < myViews.count(); i++ )
myViews[i]->setDestructiveClose( on );
}
bool SUIT_ViewManager::isVisible() const
{
bool res = false;
- for ( uint i = 0; i < myViews.count() && !res; i++ )
+ for ( int i = 0; i < myViews.count() && !res; i++ )
res = myViews[i]->isVisibleTo( myViews[i]->parentWidget() );
return res;
}
*/
void SUIT_ViewManager::setShown( const bool on )
{
- for ( uint i = 0; i < myViews.count(); i++ )
+ for ( int i = 0; i < myViews.count(); i++ )
myViews.at( i )->setShown( on );
}
*/
void SUIT_ViewManager::closeAllViews()
{
- for ( uint i = 0; i < myViews.size(); i++ )
+ for ( int i = 0; i < myViews.size(); i++ )
delete myViews[i];
myViews.clear();
}
*\retval QString - type of view model.
*/
QString SUIT_ViewManager::getType() const
-{
- return (!myViewModel)? "": myViewModel->getType();
+{
+ return (!myViewModel)? "": myViewModel->getType();
}
/*!
}
/*!Context menu popup for \a popup.*/
-void SUIT_ViewManager::contextMenuPopup( QPopupMenu* popup )
+void SUIT_ViewManager::contextMenuPopup( QMenu* popup )
{
SUIT_ViewModel* vm = getViewModel();
if ( vm )
// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
+// License as published by the Free Software Foundation; either
// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#define SUIT_VIEWMANAGER_H
#include "SUIT.h"
-#include "SUIT_ViewWindow.h"
+
#include "SUIT_PopupClient.h"
-#include <qobject.h>
-#include <qptrvector.h>
+#include <QObject>
+#include <QPixmap>
+#include <QVector>
+#include <QPointer>
+
+class QMenu;
+class QMouseEvent;
+class QWheelEvent;
+class QKeyEvent;
class SUIT_Study;
class SUIT_Desktop;
class SUIT_ViewModel;
-
-class QPopupMenu;
+class SUIT_ViewWindow;
#ifdef WIN32
#pragma warning( disable:4251 )
virtual ~SUIT_ViewManager();
virtual QString popupClientType() const { return getType(); }
- virtual void contextMenuPopup( QPopupMenu* );
-
+ virtual void contextMenuPopup( QMenu* );
+
void setViewModel(SUIT_ViewModel* theViewModel);
SUIT_ViewModel* getViewModel() { return myViewModel; }
-
+
SUIT_Study* study() const;
- QString getType() const;
+ QString getType() const;
SUIT_ViewWindow* getActiveView() { return myActiveView; }
-
+
int getViewsCount() { return myViews.count(); }
- QPtrVector<SUIT_ViewWindow> getViews() { return myViews; }
+ QVector<SUIT_ViewWindow*> getViews() const;
QString getTitle() const { return myTitle; }
virtual void setTitle( const QString& );
+ QPixmap getIcon() const { return myIcon; }
+ virtual void setIcon( const QPixmap& );
+
SUIT_ViewWindow* createViewWindow();
bool isVisible() const;
public slots:
void createView();
void closeAllViews();
-
+
signals:
void lastViewClosed(SUIT_ViewManager*);
void deleteView(SUIT_ViewWindow*);
void keyPress(SUIT_ViewWindow*, QKeyEvent*);
void keyRelease(SUIT_ViewWindow*, QKeyEvent*);
void activated(SUIT_ViewManager*);
-
+
protected slots:
void onWindowActivated(SUIT_ViewWindow*);
void onClosingView( SUIT_ViewWindow* );
private slots:
void onContextMenuRequested( QContextMenuEvent* e );
-
+
protected:
/*! Inserts the View into internal Views Vector.\n
* Returns true if view has been added successfully
*/
virtual bool insertView(SUIT_ViewWindow* theView);
-
+
/*! Removes the View from internal Views Vector.*/
virtual void removeView(SUIT_ViewWindow* theView);
-
+
/*! Close the specified View.*/
virtual void closeView(SUIT_ViewWindow* theView);
-
+
/*! Used to set unique name for the view.*/
- virtual void setViewName(SUIT_ViewWindow* theView);
+ virtual void setViewName(SUIT_ViewWindow* theView );
QString prepareTitle( const QString&, const int, const int );
static int useNewId( const QString& );
+protected:
+ typedef QPointer<SUIT_ViewWindow> ViewWindow;
+
protected:
SUIT_Desktop* myDesktop;
SUIT_ViewModel* myViewModel;
- QPtrVector<SUIT_ViewWindow> myViews;
+ QVector<ViewWindow> myViews;
SUIT_ViewWindow* myActiveView;
int myId;
+ QPixmap myIcon;
QString myTitle;
SUIT_Study* myStudy;
#include "SUIT_ViewModel.h"
+#include <SUIT_ViewWindow.h>
+
SUIT_ViewModel::StatesMap SUIT_ViewModel::myStateMap;
SUIT_ViewModel::ButtonsMap SUIT_ViewModel::myButtonMap;
/*!Constructor.*/
SUIT_ViewModel::SUIT_ViewModel()
{
- if (!isInitialized) {
+ if ( !isInitialized )
+ {
isInitialized = true;
- SUIT_ViewModel::myStateMap[ZOOM] = Qt::ControlButton;
+ SUIT_ViewModel::myStateMap[ZOOM] = Qt::ControlModifier;
SUIT_ViewModel::myButtonMap[ZOOM] = Qt::LeftButton;
- SUIT_ViewModel::myStateMap[PAN] = Qt::ControlButton;
+ SUIT_ViewModel::myStateMap[PAN] = Qt::ControlModifier;
SUIT_ViewModel::myButtonMap[PAN] = Qt::MidButton;
- SUIT_ViewModel::myStateMap[ROTATE] = Qt::ControlButton;
+ SUIT_ViewModel::myStateMap[ROTATE] = Qt::ControlModifier;
SUIT_ViewModel::myButtonMap[ROTATE] = Qt::RightButton;
- SUIT_ViewModel::myStateMap[FIT_AREA] = Qt::ControlButton;
+ SUIT_ViewModel::myStateMap[FIT_AREA] = Qt::ControlModifier;
SUIT_ViewModel::myButtonMap[FIT_AREA] = Qt::RightButton;
}
myViewManager = 0;
return new SUIT_ViewWindow(theDesktop);
}
+/*!Set view manager.
+ \param theViewManager view manager
+ */
+void SUIT_ViewModel::setViewManager(SUIT_ViewManager* theViewManager)
+{
+ myViewManager = theViewManager;
+}
+
+/*!Get view manager.
+ \return view manager
+ */
+SUIT_ViewManager* SUIT_ViewModel::getViewManager() const
+{
+ return myViewManager;
+}
+
/*! Sets hot button
*\param theOper - hot operation
*\param theState - adding state to state map operations.
*\param theButton - adding state to button map operations.
*/
-void SUIT_ViewModel::setHotButton(HotOperation theOper, Qt::ButtonState theState,
- Qt::ButtonState theButton)
+void SUIT_ViewModel::setHotButton( HotOperation theOper, Qt::KeyboardModifier theState, Qt::MouseButton theButton )
{
myStateMap[theOper] = theState;
myButtonMap[theOper] = theButton;
*\param theState - output state from state map operations.
*\param theButton - output state from button map operations.
*/
-void SUIT_ViewModel::getHotButton(HotOperation theOper, Qt::ButtonState& theState,
- Qt::ButtonState& theButton)
+void SUIT_ViewModel::getHotButton( HotOperation theOper, Qt::KeyboardModifier& theState, Qt::MouseButton& theButton )
{
theState = myStateMap[theOper];
theButton = myButtonMap[theOper];
#define SUIT_VIEWMODEL_H
#include "SUIT.h"
-#include "SUIT_Desktop.h"
-#include "SUIT_ViewWindow.h"
-#include "SUIT_ViewManager.h"
-#include <qobject.h>
-#include <qcursor.h>
+#include <QObject>
+#include <QMap>
+
+class QMenu;
+
+class SUIT_Desktop;
+class SUIT_ViewWindow;
+class SUIT_ViewManager;
#ifdef WIN32
#pragma warning( disable:4251 )
public:
enum HotOperation { PAN, ZOOM, ROTATE, FIT_AREA };
- typedef QMap<HotOperation, Qt::ButtonState> StatesMap;
- typedef QMap<HotOperation, Qt::ButtonState> ButtonsMap;
+ typedef QMap<HotOperation, Qt::KeyboardModifier> StatesMap;
+ typedef QMap<HotOperation, Qt::MouseButton> ButtonsMap;
- SUIT_ViewModel();
- virtual ~SUIT_ViewModel();
+ SUIT_ViewModel();
+ virtual ~SUIT_ViewModel();
- virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
+ virtual SUIT_ViewWindow* createView( SUIT_Desktop* theDesktop );
- virtual void setViewManager(SUIT_ViewManager* theViewManager) { myViewManager = theViewManager; }
- SUIT_ViewManager* getViewManager() const { return myViewManager; }
+ virtual void setViewManager(SUIT_ViewManager* theViewManager);
+ SUIT_ViewManager* getViewManager() const;
virtual QString getType() const { return "SUIT_ViewModel"; }
- virtual void contextMenuPopup(QPopupMenu*) {}
+ virtual void contextMenuPopup( QMenu* ) {}
- static void setHotButton(HotOperation theOper, Qt::ButtonState theState,
- Qt::ButtonState theButton);
- static void getHotButton(HotOperation theOper, Qt::ButtonState& theState,
- Qt::ButtonState& theButton);
+ static void setHotButton( HotOperation theOper, Qt::KeyboardModifier theState,
+ Qt::MouseButton theButton );
+ static void getHotButton( HotOperation theOper, Qt::KeyboardModifier& theState,
+ Qt::MouseButton& theButton );
protected:
- SUIT_ViewManager* myViewManager;
+ SUIT_ViewManager* myViewManager;
public:
static StatesMap myStateMap;
// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
+// License as published by the Free Software Foundation; either
// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SUIT_ViewWindow.h"
+
+#include "SUIT_Tools.h"
+#include "SUIT_Study.h"
#include "SUIT_Desktop.h"
+#include "SUIT_MessageBox.h"
#include "SUIT_Application.h"
-#include "SUIT_Study.h"
#include "SUIT_ViewManager.h"
-#include "SUIT_Tools.h"
-#include "SUIT_MessageBox.h"
-#include <qhbox.h>
-#include <qpopupmenu.h>
-#include <qapplication.h>
-#include <qimage.h>
+
+#include <QEvent>
+#include <QIcon>
+#include <QApplication>
+#include <QContextMenuEvent>
/*!\class SUIT_ViewWindow
* Class provide view window.
const int DUMP_EVENT = QEvent::User + 123;
/*! Constructor.*/
-SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
-: QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
+SUIT_ViewWindow::SUIT_ViewWindow( SUIT_Desktop* theDesktop )
+: QMainWindow( theDesktop )
{
myDesktop = theDesktop;
- if ( myDesktop->icon() )
- setIcon( *myDesktop->icon() );
+ setWindowIcon( myDesktop->windowIcon() );
+
+ setAttribute( Qt::WA_DeleteOnClose );
}
/*! Destructor.*/
bool SUIT_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
{
if( img.isNull() )
- return false;
+ return false;
QString fmt = format;
if( fmt.isEmpty() )
else if( fmt == "JPG" )
fmt = "JPEG";
- QApplication::setOverrideCursor( Qt::waitCursor );
- bool res = img.save( fileName, fmt.latin1() );
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ bool res = img.save( fileName, fmt.toLatin1() );
QApplication::restoreOverrideCursor();
return res;
}
*/
void SUIT_ViewWindow::setDestructiveClose( const bool on )
{
- if ( on )
- setWFlags( WDestructiveClose );
- else
- clearWFlags( WDestructiveClose );
+ setAttribute( Qt::WA_DeleteOnClose, on );
}
/*! Close event \a theEvent.
*/
-void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
+void SUIT_ViewWindow::closeEvent( QCloseEvent* e )
{
-// QMainWindow::closeEvent( theEvent );
+ e->ignore();
emit closing( this );
}
*/
void SUIT_ViewWindow::onDumpView()
{
- qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
- qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
+ QApplication::postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ) ) );
+ QApplication::postEvent( this, new QEvent( (QEvent::Type)DUMP_EVENT ) );
}
/*!
// get file name
SUIT_Application* app = myManager->study()->application();
QString fileName = app->getFileName( false, QString::null, filter(), tr( "TLT_DUMP_VIEW" ), 0 );
- if( !fileName.isEmpty() )
+ if ( !fileName.isEmpty() )
{
- QString fmt = SUIT_Tools::extension( fileName ).upper();
- bOk = dumpViewToFormat( im, fileName, fmt );
+ QString fmt = SUIT_Tools::extension( fileName ).toUpper();
+ bOk = dumpViewToFormat( im, fileName, fmt );
}
else
- {
- bOk = true; // cancelled
- }
+ bOk = true; // cancelled
}
- if ( !bOk ) {
+ if ( !bOk )
SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
- }
- return TRUE;
+
+ return true;
}
return QMainWindow::event( e );
}
/*!
Sets visual parameters of window by its string representation
\param parameters - string with visual parameters
-*/
-void SUIT_ViewWindow::setVisualParameters( const QString& parameters )
+*/
+void SUIT_ViewWindow::setVisualParameters( const QString& /*parameters*/ )
{
}
// SUIT_ViewWindow.h: interface for the SUIT_ViewWindow class.
//
-#if !defined(AFX_SUIT_VIEWWINDOW_H__82C3D51A_6F10_45B0_BCFE_3CB3EF596A4D__INCLUDED_)
-#define AFX_SUIT_VIEWWINDOW_H__82C3D51A_6F10_45B0_BCFE_3CB3EF596A4D__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
+#ifndef SUIT_VIEWWINDOW_H
+#define SUIT_VIEWWINDOW_H
#include "SUIT.h"
-#include <qmainwindow.h>
+#include <QMainWindow>
+#include <QImage>
class SUIT_Desktop;
class SUIT_ViewManager;
-class QImage;
class SUIT_EXPORT SUIT_ViewWindow: public QMainWindow
{