//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File : LogWindow.cxx
-// Author : Vadim SANDLER, Open CASCADE S.A. (vadim.sandler@opencascade.com)
-// Module : SALOME
+// File : LogWindow.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
#include "LogWindow.h"
\param parent parent widget
*/
LogWindow::LogWindow( QWidget* parent )
-: QFrame( parent ),
+: QWidget( parent ),
SUIT_PopupClient()
{
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
- QString fntSet = resMgr ? resMgr->stringValue( "Log Window", "font", QString::null ) : QString::null;
+ QString fntSet = resMgr ? resMgr->stringValue( "Log Window", "font", QString() ) : QString();
setFont( SUIT_Tools::stringToFont( fntSet ) );
myView->viewport()->installEventFilter( this );
QVBoxLayout* main = new QVBoxLayout( this );
- main->setMargin( 5 );
+ main->setMargin( 0 );
main->addWidget( myView );
myBannerSize = 0;
contextMenuRequest( (QContextMenuEvent*)e );
return true;
}
- return QFrame::eventFilter( o, e );
+ return QWidget::eventFilter( o, e );
}
/*!
return;
// call application-specific "Save file" dialog box
- QString aName = app->getFileName( false, QString::null, QString( "*.log" ), QString::null, 0 );
+ QString aName = app->getFileName( false, QString(), QString( "*.log" ), QString(), 0 );
if ( aName.isNull() )
return;
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File : LogWindow.h
-// Author : Vadim SANDLER, Open CASCADE S.A. (vadim.sandler@opencascade.com)
-// Module : SALOME
+// File : LogWindow.h
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
#ifndef LOGWINDOW_H
#define LOGWINDOW_H
#include <SUIT_PopupClient.h>
-#include <QFrame>
+#include <QWidget>
#include <QMap>
#include <QStringList>
class QAction;
class QTextEdit;
-class LOGWINDOW_EXPORT LogWindow : public QFrame, public SUIT_PopupClient
+class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient
{
Q_OBJECT
#include <QVBoxLayout>
#include <QAbstractItemModel>
#include <QAbstractItemDelegate>
+#include <QHeaderView>
#include <time.h>
*/
void OB_Browser::adjustWidth()
{
- myView->resizeColumnToContents( 0 );
+ myView->resizeColumnToEncloseContents( 0 );
+}
+
+/*!
+ \brief Adjust first column width to its contents.
+*/
+void OB_Browser::adjustFirstColumnWidth()
+{
+ myView->resizeColumnToEncloseContents( 0 );
+}
+
+/*!
+ \brief Adjust all columns width to its contents except the first column.
+*/
+void OB_Browser::adjustColumnsWidth()
+{
+ for ( int aCol = 1; aCol < myView->header()->count(); aCol++ ) {
+ if ( myView->columnWidth( aCol ) > 0 )
+ myView->resizeColumnToEncloseContents( aCol );
+ }
}
/*!
if ( isSearchToolEnabled() ) {
menu->addSeparator();
- menu->addAction( tr( "MEN_FIND" ), searchTool(), SLOT( find() ) );
+ menu->addAction( tr( "MEN_FIND" ), searchTool(), SLOT( find() ), QKeySequence(Qt::CTRL + Qt::Key_F) );
menu->addSeparator();
}
}
virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true );
void adjustWidth();
+ void adjustFirstColumnWidth();
+ void adjustColumnsWidth();
// san - To be revised or removed
// QTreeView::indexAt() should be used
#include "Plot2d_SetupViewDlg.h"
+#include <SUIT_Session.h>
+#include <SUIT_Application.h>
#include <QtxColorButton.h>
#include <QCheckBox>
myOkBtn->setDefault( TRUE );
myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
myCancelBtn->setAutoDefault( TRUE );
+ myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this );
+ myHelpBtn->setAutoDefault( TRUE );
QHBoxLayout* btnLayout = new QHBoxLayout;
btnLayout->addWidget( myOkBtn );
btnLayout->addStretch();
btnLayout->addWidget( myCancelBtn );
+ btnLayout->addWidget( myHelpBtn );
// layout widgets
topLayout->addWidget( myTitleCheck, 0, 0 );
connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
if ( mySecondAxisY ) {
connect( myTitleY2Check, SIGNAL( clicked() ), this, SLOT( onY2TitleChecked() ) );
{
return myDefCheck->isChecked();
}
+
+/*!
+ Slot, called when user clicks "Help" button
+*/
+void Plot2d_SetupViewDlg::onHelp()
+{
+ SUIT_Application* app = SUIT_Session::session()->activeApplication();
+ if ( app )
+ app->onHelpContextModule( "GUI", "plot2d_viewer_page.html", "settings" );
+}
void onXGridMinorChecked();
void onYGridMinorChecked();
void onY2GridMinorChecked();
+ void onHelp();
private:
QCheckBox* myTitleCheck;
QCheckBox* myDefCheck;
QPushButton* myOkBtn;
QPushButton* myCancelBtn;
+ QPushButton* myHelpBtn;
bool mySecondAxisY;
};
SLOT: called if action "Clone view" is activated, emits signal cloneView()
*/
void Plot2d_ViewManager::onCloneView()
+{
+ if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
+ {
+ Plot2d_ViewWindow* srcWnd = ( Plot2d_ViewWindow* )sender();
+ cloneView( srcWnd );
+ }
+}
+
+/*!
+ \brief Creates clone of source window
+ \param srcWnd source window
+ \return Pointer on the new window
+ \sa onCloneView()
+*/
+Plot2d_ViewWindow* Plot2d_ViewManager::cloneView( Plot2d_ViewWindow* srcWnd )
{
SUIT_ViewWindow* vw = createViewWindow();
- Plot2d_ViewWindow *newWnd = 0, *clonedWnd = 0;
+ Plot2d_ViewWindow* newWnd = 0;
if( vw && vw->inherits( "Plot2d_ViewWindow" ) )
newWnd = ( Plot2d_ViewWindow* )vw;
- if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
- clonedWnd = ( Plot2d_ViewWindow* )sender();
- if( newWnd && clonedWnd )
- emit cloneView( clonedWnd->getViewFrame(), newWnd->getViewFrame() );
+ if( newWnd && srcWnd )
+ emit cloneView( srcWnd->getViewFrame(), newWnd->getViewFrame() );
+
+ return newWnd;
}
/*!
class SUIT_Desktop;
class SUIT_PreferenceMgr;
+class Plot2d_ViewWindow;
class Plot2d_Viewer;
class Plot2d_ViewFrame;
~Plot2d_ViewManager();
Plot2d_Viewer* getPlot2dModel() const;
+ Plot2d_ViewWindow* cloneView( Plot2d_ViewWindow* srcWnd );
static int fillPreferences( SUIT_PreferenceMgr*, const int );
/*!
SLOT: called when action "Clone view" is activated
*/
-void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* )
+void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
{
+ if( !clonedVF || !newVF )
+ return;
+
+ // 1) Copy all properties of view
+
+ newVF->copyPreferences( clonedVF );
+
+ // 2) Display all curves displayed in cloned view
+
+ curveList aCurves;
+ clonedVF->getCurves( aCurves );
+ curveList::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
+
+ for( ; anIt!=aLast; anIt++ )
+ if( clonedVF->isVisible( *anIt ) )
+ newVF->displayCurve( *anIt, false );
+ newVF->Repaint();
+
+ if ( newVF )
+ {
+ // find view window corresponding to the frame
+ QWidget* p = newVF->parentWidget();
+ while( p && !p->inherits( "SUIT_ViewWindow" ) )
+ p = p->parentWidget();
+
+ // emits signal
+ if ( p && p->inherits( "SUIT_ViewWindow" ) )
+ emit viewCloned( (SUIT_ViewWindow*)p );
+ }
}
/*!
void update();
void clearPrs();
void setAutoDel(bool theDel);
+
+signals:
+ void viewCloned( SUIT_ViewWindow* );
protected slots:
- void onChangeBgColor();
- void onDumpView();
- void onShowToolbar();
+ void onChangeBgColor();
+ void onDumpView();
+ void onShowToolbar();
virtual void onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* );
private:
#include <Qtx.h>
#include <QtxAction.h>
#include <QtxMultiAction.h>
+#include <QtxActionToolMgr.h>
#include <QStatusBar>
#include <QLayout>
myViewFrame = new Plot2d_ViewFrame( this, "plotView" );
setCentralWidget( myViewFrame );
- myToolBar = addToolBar( tr("LBL_TOOLBAR_LABEL") );
-
createActions();
createToolBar();
*/
QToolBar* Plot2d_ViewWindow::getToolBar()
{
- return myToolBar;
+ return toolMgr()->toolBar( myToolBar );
}
/*!
*/
void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup )
{
+ QtxActionToolMgr* mgr = toolMgr();
// scaling
QMenu* scalingPopup = thePopup->addMenu( tr( "SCALING_POPUP" ) );
- scalingPopup->addAction( myActionsMap[ PModeXLinearId ] );
- scalingPopup->addAction( myActionsMap[ PModeXLogarithmicId ] );
+ scalingPopup->addAction( mgr->action( PModeXLinearId ) );
+ scalingPopup->addAction( mgr->action( PModeXLogarithmicId ) );
scalingPopup->addSeparator();
- scalingPopup->addAction( myActionsMap[ PModeYLinearId ] );
- scalingPopup->addAction( myActionsMap[ PModeYLogarithmicId ] );
+ scalingPopup->addAction( mgr->action( PModeYLinearId ) );
+ scalingPopup->addAction( mgr->action( PModeYLogarithmicId ) );
// fit data
thePopup->addAction( tr( "TOT_PLOT2D_FITDATA" ), myViewFrame, SLOT( onFitData() ) );
// curve type
QMenu* curTypePopup = thePopup->addMenu( tr( "CURVE_TYPE_POPUP" ) );
- curTypePopup->addAction( myActionsMap[ CurvPointsId ] );
- curTypePopup->addAction( myActionsMap[ CurvLinesId ] );
- curTypePopup->addAction( myActionsMap[ CurvSplinesId ] );
+ curTypePopup->addAction( mgr->action( CurvPointsId ) );
+ curTypePopup->addAction( mgr->action( CurvLinesId ) );
+ curTypePopup->addAction( mgr->action( CurvSplinesId ) );
// legend
- thePopup->addAction( myActionsMap[ LegendId ] );
+ thePopup->addAction( mgr->action( LegendId ) );
// settings
- thePopup->addAction( myActionsMap[ CurvSettingsId ] );
+ thePopup->addAction( mgr->action( CurvSettingsId ) );
}
/*!
*/
void Plot2d_ViewWindow::createActions()
{
- if ( !myActionsMap.isEmpty() )
- return;
-
+ QtxActionToolMgr* mgr = toolMgr();
QtxAction* aAction;
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
0, this);
aAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
- myActionsMap[ DumpId ] = aAction;
+ mgr->registerAction( aAction, DumpId );
// 2. Scaling operations
0, this);
aAction->setStatusTip( tr( "DSC_FITALL" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitAll() ) );
- myActionsMap[ FitAllId ] = aAction;
+ mgr->registerAction( aAction, FitAllId );
// 2.2. Fit Rect
aAction = new QtxAction( tr( "MNU_FITRECT" ),
0, this);
aAction->setStatusTip( tr( "DSC_FITRECT" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitRect() ) );
- myActionsMap[ FitRectId ] = aAction;
+ mgr->registerAction( aAction, FitRectId );
// 2.3. Zoom
aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
0, this);
aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onZoom() ) );
- myActionsMap[ ZoomId ] = aAction;
+ mgr->registerAction( aAction, ZoomId );
// 2.4. Create multi-action for scaling operations
QtxMultiAction* aScaleAction = new QtxMultiAction( this );
- aScaleAction->insertAction( myActionsMap[ FitAllId ] );
- aScaleAction->insertAction( myActionsMap[ FitRectId ] );
- aScaleAction->insertAction( myActionsMap[ ZoomId ] );
- myActionsMap[ ScaleOpId ] = aScaleAction;
+ aScaleAction->insertAction( mgr->action( FitAllId ) );
+ aScaleAction->insertAction( mgr->action( FitRectId ) );
+ aScaleAction->insertAction( mgr->action( ZoomId ) );
+ mgr->registerAction( aScaleAction, ScaleOpId );
// 3. Moving operations
0, this);
aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPanning() ) );
- myActionsMap[ PanId ] = aAction;
+ mgr->registerAction( aAction, PanId );
// 3.2. Global Panning
aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
0, this);
aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onGlobalPanning() ) );
- myActionsMap[ GlobalPanId ] = aAction;
+ mgr->registerAction( aAction, GlobalPanId );
// 3.3. Create multi-action for moving operations
QtxMultiAction* aPanAction = new QtxMultiAction( this );
- aPanAction->insertAction( myActionsMap[ PanId ] );
- aPanAction->insertAction( myActionsMap[ GlobalPanId ] );
- myActionsMap[ MoveOpId ] = aPanAction;
+ aPanAction->insertAction( mgr->action( PanId ) );
+ aPanAction->insertAction( mgr->action( GlobalPanId ) );
+ mgr->registerAction( aPanAction, MoveOpId );
// 4. Curve type operations
0, this );
aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
aAction->setCheckable( true );
- myActionsMap[ CurvPointsId ] = aAction;
+ mgr->registerAction( aAction, CurvPointsId );
// 4.2. Lines
aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_LINES" ),
0, this );
aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_LINES" ) );
aAction->setCheckable( true );
- myActionsMap[ CurvLinesId ] = aAction;
+ mgr->registerAction( aAction, CurvLinesId );
// 4.3. Splines
aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_SPLINES" ),
0, this );
aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
aAction->setCheckable( true );
- myActionsMap[ CurvSplinesId ] = aAction;
+ mgr->registerAction( aAction, CurvSplinesId );
// 4.4. Create action group for curve type operations
QActionGroup* aCurveGroup = new QActionGroup( this );
- aCurveGroup->addAction( myActionsMap[ CurvPointsId ] );
- aCurveGroup->addAction( myActionsMap[ CurvLinesId ] );
- aCurveGroup->addAction( myActionsMap[ CurvSplinesId ] );
+ aCurveGroup->addAction( mgr->action( CurvPointsId ) );
+ aCurveGroup->addAction( mgr->action( CurvLinesId ) );
+ aCurveGroup->addAction( mgr->action( CurvSplinesId ) );
connect( aCurveGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onCurves() ) );
// 5. Horizontal scaling mode operations
aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
aAction->setCheckable( true );
- myActionsMap[ PModeXLinearId ] = aAction;
+ mgr->registerAction( aAction, PModeXLinearId );
// 5.2. Logarithmic
aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" ),
aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
aAction->setCheckable( true );
- myActionsMap[ PModeXLogarithmicId ] = aAction;
+ mgr->registerAction( aAction, PModeXLogarithmicId );
// 5.3. Create action group for horizontal scaling mode operations
QActionGroup* aHorGroup = new QActionGroup( this );
- aHorGroup->addAction( myActionsMap[ PModeXLinearId ] );
- aHorGroup->addAction( myActionsMap[ PModeXLogarithmicId ] );
+ aHorGroup->addAction( mgr->action( PModeXLinearId ) );
+ aHorGroup->addAction( mgr->action( PModeXLogarithmicId ) );
// 6. Vertical scaling mode operations
aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
aAction->setCheckable( true );
- myActionsMap[ PModeYLinearId ] = aAction;
+ mgr->registerAction( aAction, PModeYLinearId );
// 6.2. Logarithmic
aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER" ),
aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
aAction->setCheckable( true );
- myActionsMap[ PModeYLogarithmicId ] = aAction;
+ mgr->registerAction( aAction, PModeYLogarithmicId );
// 6.3. Create action group for vertical scaling mode operations
QActionGroup* aVerGroup = new QActionGroup( this );
- aVerGroup->addAction( myActionsMap[ PModeYLinearId ] );
- aVerGroup->addAction( myActionsMap[ PModeYLogarithmicId ] );
+ aVerGroup->addAction( mgr->action( PModeYLinearId ) );
+ aVerGroup->addAction( mgr->action( PModeYLogarithmicId ) );
// 7. Legend
aAction = new QtxAction( tr( "TOT_PLOT2D_SHOW_LEGEND" ),
aAction->setStatusTip( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onLegend() ) );
aAction->setCheckable( true );
- myActionsMap[ LegendId ] = aAction;
+ mgr->registerAction( aAction, LegendId );
// 8. Settings
aAction = new QtxAction( tr( "TOT_PLOT2D_SETTINGS" ),
0, this );
aAction->setStatusTip( tr( "PRP_PLOT2D_SETTINGS" ) );
connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) );
- myActionsMap[ CurvSettingsId ] = aAction;
+ mgr->registerAction( aAction, CurvSettingsId );
// 9. Clone
aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
0, this);
aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
- myActionsMap[ CloneId ] = aAction;
+ mgr->registerAction( aAction, CloneId );
// 10. Print
aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ),
0, this);
aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) );
connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) );
- myActionsMap[ PrintId ] = aAction;
+ mgr->registerAction( aAction, PrintId );
// Set initial values
onChangeCurveMode();
*/
void Plot2d_ViewWindow::createToolBar()
{
- myToolBar->addAction( myActionsMap[ DumpId ] );
- myToolBar->addAction( myActionsMap[ ScaleOpId ] );
- myToolBar->addAction( myActionsMap[ MoveOpId ] );
- myToolBar->addSeparator();
- myToolBar->addAction( myActionsMap[ CurvPointsId ] );
- myToolBar->addAction( myActionsMap[ CurvLinesId ] );
- myToolBar->addAction( myActionsMap[ CurvSplinesId ] );
- myToolBar->addSeparator();
- myToolBar->addAction( myActionsMap[ PModeXLinearId ] );
- myToolBar->addAction( myActionsMap[ PModeXLogarithmicId ] );
- myToolBar->addSeparator();
- myToolBar->addAction( myActionsMap[ PModeYLinearId ] );
- myToolBar->addAction( myActionsMap[ PModeYLogarithmicId ] );
- myToolBar->addSeparator();
- myToolBar->addAction( myActionsMap[ LegendId ] );
- myToolBar->addAction( myActionsMap[ CurvSettingsId ] );
- myToolBar->addAction( myActionsMap[ CloneId ] );
- myToolBar->addAction( myActionsMap[ PrintId ] );
+ QtxActionToolMgr* mgr = toolMgr();
+ myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) );
+ mgr->append( DumpId, myToolBar );
+ mgr->append( ScaleOpId, myToolBar );
+ mgr->append( MoveOpId, myToolBar );
+ mgr->append( toolMgr()->separator(), myToolBar );
+ mgr->append( CurvPointsId, myToolBar );
+ mgr->append( CurvLinesId, myToolBar );
+ mgr->append( CurvSplinesId, myToolBar );
+ mgr->append( toolMgr()->separator(), myToolBar );
+ mgr->append( PModeXLinearId, myToolBar );
+ mgr->append( PModeXLogarithmicId, myToolBar );
+ mgr->append( toolMgr()->separator(), myToolBar );
+ mgr->append( PModeYLinearId, myToolBar );
+ mgr->append( PModeYLogarithmicId, myToolBar );
+ mgr->append( toolMgr()->separator(), myToolBar );
+ mgr->append( LegendId, myToolBar );
+ mgr->append( CurvSettingsId, myToolBar );
+ mgr->append( CloneId, myToolBar );
+ mgr->append( PrintId, myToolBar );
}
/*!
bool aVerLinear = myViewFrame->isModeVerLinear();
if ( aHorLinear )
- myActionsMap[ PModeXLinearId ]->setChecked( true );
+ toolMgr()->action( PModeXLinearId )->setChecked( true );
else
- myActionsMap[ PModeXLogarithmicId ]->setChecked( true );
+ toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
- myActionsMap[ GlobalPanId ]->setEnabled( aHorLinear && aVerLinear );
+ toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
}
/*!
bool aVerLinear = myViewFrame->isModeVerLinear();
if ( aVerLinear )
- myActionsMap[ PModeYLinearId ]->setChecked( true );
+ toolMgr()->action( PModeYLinearId )->setChecked( true );
else
- myActionsMap[ PModeYLogarithmicId ]->setChecked( true );
+ toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
- myActionsMap[ GlobalPanId ]->setEnabled( aHorLinear && aVerLinear );
+ toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
}
/*!
{
switch ( myViewFrame->getCurveType() ) {
case 0:
- myActionsMap[ CurvPointsId ]->setChecked( true );
+ toolMgr()->action( CurvPointsId )->setChecked( true );
break;
case 1:
- myActionsMap[ CurvLinesId ]->setChecked( true );
+ toolMgr()->action( CurvLinesId )->setChecked( true );
break;
case 2:
- myActionsMap[ CurvSplinesId ]->setChecked( true );
+ toolMgr()->action( CurvSplinesId )->setChecked( true );
break;
default:
break;
*/
void Plot2d_ViewWindow::onChangeLegendMode()
{
- myActionsMap[ LegendId ]->setChecked( myViewFrame->isLegendShow() );
+ toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
}
/*!
*/
void Plot2d_ViewWindow::onViewHorMode()
{
- myViewFrame->setHorScaleMode( myActionsMap[ PModeXLinearId ]->isChecked() ? 0 : 1 );
+ myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
}
/*!
*/
void Plot2d_ViewWindow::onViewVerMode()
{
- myViewFrame->setVerScaleMode( myActionsMap[ PModeYLinearId ]->isChecked() ? 0 : 1 );
+ myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
}
/*!
*/
void Plot2d_ViewWindow::onCurves()
{
- if( myActionsMap[ CurvPointsId ]->isChecked() )
+ if( toolMgr()->action( CurvPointsId )->isChecked() )
myViewFrame->setCurveType( 0 );
- else if ( myActionsMap[ CurvLinesId ]->isChecked() )
+ else if ( toolMgr()->action( CurvLinesId )->isChecked() )
myViewFrame->setCurveType( 1 );
- else if ( myActionsMap[ CurvSplinesId ]->isChecked() )
+ else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
myViewFrame->setCurveType( 2 );
}
\fn void Plot2d_ViewWindow::cloneView();
\brief Emitted when the "Clone View" action is activated.
*/
-
-
{
Q_OBJECT
+public:
+ enum { DumpId,
+ ScaleOpId, FitAllId, FitRectId, ZoomId,
+ MoveOpId, PanId, GlobalPanId,
+ PModeXLinearId, PModeXLogarithmicId,
+ PModeYLinearId, PModeYLogarithmicId,
+ CurvPointsId, CurvLinesId, CurvSplinesId,
+ LegendId,
+ CurvSettingsId,
+ CloneId, PrintId };
+
public:
Plot2d_ViewWindow( SUIT_Desktop*, Plot2d_Viewer* );
virtual ~Plot2d_ViewWindow();
void onViewVerMode();
void onLegend();
void onCurves();
-
+
void onDumpView();
void onPrintView();
-protected:
- enum { DumpId,
- ScaleOpId, FitAllId, FitRectId, ZoomId,
- MoveOpId, PanId, GlobalPanId,
- PModeXLinearId, PModeXLogarithmicId,
- PModeYLinearId, PModeYLogarithmicId,
- CurvPointsId, CurvLinesId, CurvSplinesId,
- LegendId,
- CurvSettingsId,
- CloneId,
- PrintId };
-
- typedef QMap<int, QtxAction*> ActionsMap;
- ActionsMap myActionsMap;
-
protected:
virtual QImage dumpView();
virtual bool dumpViewToFormat( const QImage&,
protected:
Plot2d_Viewer* myModel;
Plot2d_ViewFrame* myViewFrame;
- QToolBar* myToolBar;
- QImage myDumpImage;
+ int myToolBar;
};
#ifdef WIN32
PyConsole_Editor* theListener,
bool sync = false )
: PyInterp_LockRequest( theInterp, theListener, sync ),
- myCommand( theCommand ), myState( PyInterp_Event::OK )
+ myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
{}
protected:
{
int ret = getInterp()->run( myCommand.toLatin1() );
if ( ret < 0 )
- myState = PyInterp_Event::ERROR;
+ myState = PyInterp_Event::ES_ERROR;
else if ( ret > 0 )
- myState = PyInterp_Event::INCOMPLETE;
+ myState = PyInterp_Event::ES_INCOMPLETE;
}
}
addText( pe->text() );
return;
}
- case PyInterp_Event::OK:
- case PyInterp_Event::ERROR:
+ case PyInterp_Event::ES_OK:
+ case PyInterp_Event::ES_ERROR:
{
// clear command buffer
myCommandBuffer.truncate( 0 );
myEventLoop->exit();
break;
}
- case PyInterp_Event::INCOMPLETE:
+ case PyInterp_Event::ES_INCOMPLETE:
{
// extend command buffer (multi-line command)
myCommandBuffer.append( "\n" );
// unset history browsing mode
myCmdInHistory = -1;
- if ( (int)event->type() == (int)PyInterp_Event::OK && myQueue.count() > 0 )
+ if ( (int)event->type() == (int)PyInterp_Event::ES_OK && myQueue.count() > 0 )
{
// process the next sheduled command from the queue (if there is any)
QString nextcmd = myQueue[0];
_tstate = Py_NewInterpreter(); // create an interpreter and save current state
PySys_SetArgv(PyInterp_Interp::_argc,PyInterp_Interp::_argv); // initialize sys.argv
+ if(!builtinmodule) // PAL18041: deepcopy function don't work in Salome
+ {
+ //builtinmodule is static member of PyInterp class
+ //If it is not NULL (initialized to the builtin module of the main interpreter
+ //all the sub interpreters will have the same builtin
+ //_interp is a static member and is the main interpreter
+ //The first time we initialized it to the builtin of main interpreter
+ builtinmodule=PyDict_GetItemString(_interp->modules, "__builtin__");
+ }
+
//If builtinmodule has been initialized all the sub interpreters
// will have the same __builtin__ module
if(builtinmodule){
OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET
INCLUDEPATH += ../../include $$(PYTHONINC)
-unix:LIBS += -L$$(PYTHONLIB) -lpython2.5
-win32:LIBS += -L$$(PYTHONLIB) -lpython25_d
+unix:LIBS += -L$$(PYTHONLIB) -lpython2.5 -L../../$(CONFIG_ID)/lib -lEvent
+win32:LIBS += -L$$(PYTHONLIB) -lpython25_d
win32:LIBS *= -L$(QTLIB)
win32:INCLUDEPATH *= $(QTINC) $(QTINC)\QtCore $(QTINC)\QtGui $(QTINC)\QtXml
#include "PyInterp_Dispatcher.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
#include "PyInterp_Interp.h"
#include "PyInterp_Watcher.h"
+#include <SALOME_Event.h>
#include <QObject>
#include <QCoreApplication>
+class PyInterp_ExecuteEvent: public SALOME_Event
+{
+public:
+ PyInterp_Request* myRequest;
+ PyInterp_ExecuteEvent( PyInterp_Request* r )
+ : myRequest( r ) {}
+ virtual void Execute()
+ {
+ myRequest->execute();
+ }
+};
+
using namespace std;
PyInterp_Dispatcher* PyInterp_Dispatcher::myInstance = 0;
void PyInterp_Request::safeExecute()
{
- execute();
+ ProcessVoidEvent( new PyInterp_ExecuteEvent( this ) );
}
void PyInterp_Request::Destroy( PyInterp_Request* request )
QEvent* PyInterp_Request::createEvent() const
{
- return new PyInterp_Event( PyInterp_Event::NOTIFY, (PyInterp_Request*)this );
+ return new PyInterp_Event( PyInterp_Event::ES_NOTIFY, (PyInterp_Request*)this );
}
void PyInterp_Request::processEvent( QObject* o )
{
if ( getInterp() ){
PyLockWrapper aLock = getInterp()->GetLockWrapper();
- execute();
+ ProcessVoidEvent( new PyInterp_ExecuteEvent( this ) );
}
}
class PyInterp_Interp;
class PyInterp_Watcher;
class PyInterp_Dispatcher;
+class PyInterp_ExecuteEvent;
class PYINTERP_EXPORT PyInterp_Request
{
friend class PyInterp_Dispatcher;
+ friend class PyInterp_ExecuteEvent;
PyInterp_Request();
PyInterp_Request( const PyInterp_Request& );
PyInterp_Event( const PyInterp_Event& );
public:
- enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST };
+ //Execution state
+ enum { ES_NOTIFY = QEvent::User + 5000, ES_OK, ES_ERROR, ES_INCOMPLETE, ES_LAST };
PyInterp_Event( int type, PyInterp_Request* request )
: QEvent( (QEvent::Type)type ), myRequest( request ) {}
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxActionGroup.cxx
+// Author: Sergey TELKOV
+
+#include "QtxActionGroup.h"
+
+#include "QtxComboBox.h"
+
+#include <QMenu>
+#include <QMenuBar>
+#include <QActionGroup>
+
+/*!
+ \class QtxActionGroup
+ \brief The QtxActionGroup class groups actions together.
+
+ QtxActionGroup class operates with a list of actions in the similar way as it does QActionGroup class.
+ But in contrast to the Qt 4's class, QtxActrionGroup behaves rather like it was in Qt series 3x.
+ For example, it automatically shows exclusive combo box widget when action group is added to the toolbar
+ and if \a usesDropDown and \a exclusive flags are both set to \c true.
+
+ The setExclusive() function is used to ensure that only one action is active at any moment:
+ it should be used with actions which have their \a checkable state set to \c true.
+
+ Action group actions appear as individual menu options and toolbar buttons. For exclusive action
+ groups use setUsesDropDown() to display the actions in a subwidget of the toolbar or menu the action group
+ is added on.
+
+ Actions can be added to the action group using add() function. Add the action group to the menu or
+ toolbar in the same way as for single action - using addAction() method of QMenu or QToolbar class.
+*/
+
+/*!
+ \brief Constructor
+
+ The created action group is exclusive by default.
+
+ \param parent owner object
+ \sa setExclusive()
+*/
+QtxActionGroup::QtxActionGroup( QObject* parent )
+: QtxActionSet( parent ),
+ myDropDown( false )
+{
+ setMenu( new QMenu( 0 ) );
+ myActionGroup = new QActionGroup( this );
+
+ connect( myActionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) );
+}
+
+/*!
+ \brief Constructor
+ \param parent owner object
+ \param exclusive if \c true only one action in the group will ever be active
+ \sa setExclusive()
+*/
+QtxActionGroup::QtxActionGroup( QObject* parent, const bool exclusive )
+: QtxActionSet( parent ),
+ myDropDown( false )
+{
+ setMenu( new QMenu( 0 ) );
+ myActionGroup = new QActionGroup( this );
+ myActionGroup->setExclusive( exclusive );
+
+ connect( myActionGroup, SIGNAL( triggered( QAction* ) ), this, SIGNAL( selected( QAction* ) ) );
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxActionGroup::~QtxActionGroup()
+{
+}
+
+/*!
+ \brief Check if the action group is exclusive
+ \return \c true if the action group is exclusive and \c false otherwise
+ \sa setExclusive(), setUsesDropDown()
+*/
+bool QtxActionGroup::isExclusive() const
+{
+ return myActionGroup->isExclusive();
+}
+
+/*!
+ \brief Set/clear the action group exclusiveness
+ \param on if \c true the action group will be exclusive
+ \sa isExclusive(), setUsesDropDown()
+*/
+void QtxActionGroup::setExclusive( const bool on )
+{
+ if ( myActionGroup->isExclusive() == on )
+ return;
+
+ bool e = isEmptyAction();
+
+ myActionGroup->setExclusive( on );
+
+ if ( e != isEmptyAction() )
+ updateType();
+}
+
+/*!
+ \brief Check if action group should appear in a subwidget of parent widget
+
+ Note: for this option to take into effect, the \a exclusive flag should
+ be also set to \c true
+
+ \return \c true if the action group is shown in subwidget
+ \sa setUsesDropDown(), setExclusive()
+*/
+bool QtxActionGroup::usesDropDown() const
+{
+ return myDropDown;
+}
+
+/*!
+ \brief Defines a way how the group's actions should be displayed in parent widget
+ action group is added to - as a group of actions or in a subwidget (e.g. in the
+ combo box).
+ \param on if \c true, action group will be shown in the subwidget
+ \sa usesDropDown(), setExclusive()
+*/
+void QtxActionGroup::setUsesDropDown( const bool on )
+{
+ if ( myDropDown == on )
+ return;
+
+ bool e = isEmptyAction();
+
+ myDropDown = on;
+
+ if ( e != isEmptyAction() )
+ updateType();
+}
+
+/*!
+ \brief Append the specified action into group.
+ \a action action to be added to the action group
+*/
+void QtxActionGroup::add( QAction* a )
+{
+ insertAction( a );
+}
+
+/*!
+ \brief Called when some subwidget item is activated by the user.
+ \param id item identifier
+*/
+void QtxActionGroup::onActivated( int id )
+{
+ const QObject* s = sender();
+
+ QAction* a = action( id );
+ if ( !a )
+ return;
+
+ if ( a->isChecked() )
+ return;
+
+ a->setChecked( true );
+ a->trigger();
+
+ QList<QWidget*> lst = createdWidgets();
+ for ( QList<QWidget*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ QtxComboBox* cb = ::qobject_cast<QtxComboBox*>( *it );
+ if ( cb && cb != s )
+ cb->setCurrentId( id );
+ }
+}
+
+/*!
+ \brief Called when some action owned by this action group is activated by the user
+ \param a action being activated
+*/
+void QtxActionGroup::onTriggered( QAction* a )
+{
+ int id = actionId( a );
+ if ( id != -1 ) {
+ QList<QWidget*> lst = createdWidgets();
+ for ( QList<QWidget*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ QtxComboBox* cb = ::qobject_cast<QtxComboBox*>( *it );
+ if ( cb )
+ cb->setCurrentId( id );
+ }
+ }
+
+ emit selected( a );
+}
+
+/*!
+ \brief Update action group for the specified widget.
+ \param w a widget this action group is added to
+*/
+void QtxActionGroup::updateAction( QWidget* w )
+{
+ if ( !::qobject_cast<QMenu*>( w ) && !::qobject_cast<QMenuBar*>( w ) ) {
+ QtxComboBox* cb = createdWidget( w );
+ if ( !cb )
+ QtxActionSet::updateAction( w );
+ else
+ {
+ updateAction( cb );
+
+ QList<QAction*> lst = actions();
+ for ( QList<QAction*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ w->removeAction( *it );
+ }
+ }
+ else
+ {
+ if ( !usesDropDown() ) {
+ QtxActionSet::updateAction( w );
+ }
+ else {
+ QList<QAction*> lst = actions();
+ for ( QList<QAction*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ w->removeAction( *it );
+ }
+ }
+}
+
+/*!
+ \brief Update action group for the specified combo box.
+ \param cb a combo box this action group is added to
+*/
+void QtxActionGroup::updateAction( QtxComboBox* cb )
+{
+ if ( !cb )
+ return;
+
+ cb->clear();
+ cb->setCleared( false );
+
+ QAction* cur = 0;
+ QList<QAction*> lst = actions();
+ for ( QList<QAction*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ QAction* a = *it;
+ cb->addItem( a->icon(), a->text() );
+ cb->setId( cb->count() - 1, actionId( a ) );
+ if ( a->isChecked() )
+ cur = a;
+ }
+
+ if ( cur )
+ cb->setCurrentId( actionId( cur ) );
+ else
+ cb->setCleared( true );
+}
+
+/*!
+ \brief Create widget representing action group in the widget
+ this action group is added to.
+ \param p widget this action group is being added to
+ \return new widget representing this action group
+*/
+QWidget* QtxActionGroup::createWidget( QWidget* p )
+{
+ if ( ::qobject_cast<QMenu*>( p ) || ::qobject_cast<QMenuBar*>( p ) )
+ return 0;
+
+ QtxComboBox* cb = !isEmptyAction() ? new QtxComboBox( p ) : 0;
+ if ( cb )
+ connect( cb, SIGNAL( activatedId( int ) ), this, SLOT( onActivated( int ) ) );
+ return cb;
+}
+
+/*!
+ \brief Check if the action itself should be invisible
+ (only child action are shown)
+ \return \c true if the action itself should be visible
+*/
+bool QtxActionGroup::isEmptyAction() const
+{
+ return !isExclusive() || !usesDropDown();
+}
+
+/*!
+ \brief Called when action is added to the action group
+ \param a action being added to the action group
+*/
+void QtxActionGroup::actionAdded( QAction* a )
+{
+ myActionGroup->addAction( a );
+ if ( menu() )
+ menu()->addAction( a );
+}
+
+/*!
+ \brief Called when action is removed from the action group
+ \param a action being removed from the action group
+*/
+void QtxActionGroup::actionRemoved( QAction* a )
+{
+ myActionGroup->removeAction( a );
+ if ( menu() )
+ menu()->removeAction( a );
+}
+
+/*!
+ \brief Internal update
+*/
+void QtxActionGroup::updateType()
+{
+ QList<QWidget*> lst = associatedWidgets();
+ for ( QList<QWidget*>::iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ QWidget* w = *it;
+ QList<QAction*> lst = w->actions();
+
+ int i = lst.indexOf( this );
+ w->removeAction( this );
+
+ lst = w->actions();
+ w->insertAction( i < lst.count() ? lst.at( i ) : 0, this );
+ }
+ setVisible( !isEmptyAction() );
+}
+
+/*!
+ \brief Get combo box created by this action group for the specified widget.
+ \param p widget this action group is added to
+ \return combo box if it was created for the specified widget or 0 otherwise
+*/
+QtxComboBox* QtxActionGroup::createdWidget( QWidget* p )
+{
+ QtxComboBox* cb = 0;
+ QList<QWidget*> lst = createdWidgets();
+ for ( QList<QWidget*>::iterator it = lst.begin(); it != lst.end() && !cb; ++it )
+ {
+ if ( (*it)->parent() == p )
+ cb = ::qobject_cast<QtxComboBox*>( *it );
+ }
+ return cb;
+}
+
+/*!
+ \fn void QtxActionGroup::selected( QAction* a );
+ \brief Emitted when some child action is toggled by the user.
+ \param a action being toggled
+*/
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxActionGroup.h
+// Author: Sergey TELKOV
+
+#ifndef QTXACTIONGROUP_H
+#define QTXACTIONGROUP_H
+
+#include "QtxActionSet.h"
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+class QtxComboBox;
+class QActionGroup;
+
+class QTX_EXPORT QtxActionGroup : public QtxActionSet
+{
+ Q_OBJECT
+
+public:
+ QtxActionGroup( QObject* = 0 );
+ QtxActionGroup( QObject*, const bool );
+ virtual ~QtxActionGroup();
+
+ bool isExclusive() const;
+ bool usesDropDown() const;
+
+ void add( QAction* );
+
+public slots:
+ void setExclusive( const bool );
+ void setUsesDropDown( const bool );
+
+signals:
+ void selected( QAction* );
+
+private slots:
+ void onActivated( int );
+ void onTriggered( QAction* );
+
+protected:
+ virtual void updateAction( QWidget* );
+ virtual void updateAction( QtxComboBox* );
+
+ virtual QWidget* createWidget( QWidget* );
+
+ virtual bool isEmptyAction() const;
+ virtual void actionAdded( QAction* );
+ virtual void actionRemoved( QAction* );
+
+private:
+ void updateType();
+ QtxComboBox* createdWidget( QWidget* );
+
+private:
+ bool myDropDown;
+ QActionGroup* myActionGroup;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxMenu.cxx
+// Author: Sergey TELKOV
+//
+
+#include "QtxMenu.h"
+
+#include <QLabel>
+#include <QLayout>
+#include <QPainter>
+#include <QPaintEvent>
+#include <QTextDocument>
+#include <QWidgetAction>
+#include <QLinearGradient>
+#include <QAbstractTextDocumentLayout>
+
+/*!
+ \class QtxMenu::Title
+ \brief Popup menu title item.
+ \internal
+*/
+
+class QtxMenu::Title : public QWidget
+{
+public:
+ Title( QWidget* = 0 );
+ virtual ~Title();
+
+ QIcon icon() const;
+ void setIcon( const QIcon& );
+
+ QString text() const;
+ void setText( const QString& );
+
+ Qt::Alignment alignment() const;
+ void setAlignment( const Qt::Alignment );
+
+ virtual QSize sizeHint() const;
+ virtual QSize minimumSizeHint() const;
+
+protected:
+ virtual void paintEvent( QPaintEvent* );
+
+private:
+ QIcon myIcon;
+ QString myText;
+ Qt::Alignment myAlignment;
+};
+
+/*!
+ \brief Constructor.
+ \param parent parent widget
+ \internal
+*/
+QtxMenu::Title::Title( QWidget* parent )
+: QWidget( parent ),
+ myAlignment( 0 )
+{
+}
+
+/*!
+ \brief Destructor.
+ \internal
+*/
+QtxMenu::Title::~Title()
+{
+}
+
+/*!
+ \brief Get title icon.
+ \return title item icon
+ \internal
+*/
+QIcon QtxMenu::Title::icon() const
+{
+ return myIcon;
+}
+
+/*!
+ \brief Set title icon.
+ \param ico title item icon
+ \internal
+*/
+void QtxMenu::Title::setIcon( const QIcon& ico )
+{
+ myIcon = ico;
+}
+
+/*!
+ \brief Get title menu text.
+ \return menu text for the title item
+ \internal
+*/
+QString QtxMenu::Title::text() const
+{
+ return myText;
+}
+
+/*!
+ \brief Set title menu text.
+ \param txt menu text to be used for the title item
+ \internal
+*/
+void QtxMenu::Title::setText( const QString& txt )
+{
+ myText = txt;
+}
+
+/*!
+ \brief Get title alignment flags.
+ \return title alignment flags
+ \internal
+*/
+Qt::Alignment QtxMenu::Title::alignment() const
+{
+ return myAlignment;
+}
+
+/*!
+ \brief Set title alignment flags.
+ \param a title alignment flags
+ \internal
+*/
+void QtxMenu::Title::setAlignment( const Qt::Alignment a )
+{
+ myAlignment = a;
+}
+
+/*!
+ \brief Get recommended size for the title item widget.
+ \return title item widget size
+ \internal
+*/
+QSize QtxMenu::Title::sizeHint() const
+{
+ int m = 5;
+ QTextDocument doc;
+ doc.setHtml( text() );
+
+ QSize sz = icon().isNull() ? QSize( 0, 0 ) : icon().actualSize( QSize( 16, 16 ) );
+ sz.setWidth( 2 * m + sz.width() + (int)doc.size().width() );
+ sz.setHeight( 2 * m + qMax( sz.height(), (int)doc.size().height() ) );
+ return sz;
+}
+
+/*!
+ \brief Get recommended minimum size for the title item widget.
+ \return title item widget minimum size
+ \internal
+*/
+QSize QtxMenu::Title::minimumSizeHint() const
+{
+ return sizeHint();
+}
+
+/*!
+ \brief Paint the title item widget.
+ \param e paint event (not used)
+ \internal
+*/
+void QtxMenu::Title::paintEvent( QPaintEvent* /*e*/ )
+{
+ int m = 5;
+ QIcon ico = icon();
+ QString txt = text();
+ Qt::Alignment align = alignment();
+
+ QRect base = rect();
+ base.setTop( base.top() + 1 );
+ base.setLeft( base.left() + 1 );
+ base.setRight( base.right() -1 );
+ base.setBottom( base.bottom() - 1 );
+
+ QTextDocument doc;
+ doc.setHtml( txt );
+
+ QSize isz = ico.isNull() ? QSize( 0, 0 ) : ico.actualSize( QSize( 16, 16 ) );
+ QSize sz( (int)doc.size().width(), (int)doc.size().height() );
+
+ QPainter p( this );
+ QAbstractTextDocumentLayout::PaintContext ctx;
+ ctx.palette.setColor( QPalette::Text, palette().color( QPalette::Light ) );
+
+ QLinearGradient linearGrad( base.topLeft(), base.topRight() );
+ linearGrad.setColorAt( 0, palette().color( QPalette::Highlight ) );
+ linearGrad.setColorAt( 1, palette().color( QPalette::Window ) );
+
+ p.fillRect( base, linearGrad );
+
+ QPoint start = base.topLeft() + QPoint( m, m );
+ if ( align & Qt::AlignLeft )
+ start.setX( base.left() + m );
+ else if ( align & Qt::AlignRight )
+ start.setX( base.right() - m - isz.width() - sz.width() );
+ else if ( align & Qt::AlignHCenter )
+ start.setX( base.left() + ( base.width() - isz.width() - sz.width() ) / 2 );
+
+ if ( align & Qt::AlignTop )
+ start.setY( base.top() + m );
+ else if ( align & Qt::AlignBottom )
+ start.setY( base.bottom() - m - qMax( isz.height(), - sz.height() ) );
+ else if ( align & Qt::AlignVCenter )
+ start.setY( base.top() + ( base.height() - qMax( isz.height(), sz.height() ) ) / 2 );
+
+ if ( !ico.isNull() )
+ {
+ ico.paint( &p, QRect( start, isz ) );
+ start.setX( start.x() + isz.width() );
+ }
+
+ p.save();
+ p.translate( start );
+ doc.documentLayout()->draw( &p, ctx );
+ p.restore();
+}
+
+/*!
+ \class QtxMenu
+ \brief The class QtxMenu represents the popup menu with the title.
+
+ The title for the popup menu can be set via setTitleText() method.
+ In addition, title item can contain the icon, which can be set using
+ setTitleIcon() method. Current title text and icon can be retrieved with
+ titleText() and titleIcon() methods.
+
+ The title text alignment flags can be changed using setTitleAlignment()
+ method and retrieved with titleAlignment() method.
+
+ By default, QtxMenu::TitleAuto mode is used. In this mode, the title item
+ is shown only if it is not empty. To show title always (even empty), pass
+ QtxMenu::TitleOn to the setTitleMode() method. To hide the title, use
+ setTitleMode() method with QtxMenu::TitleOff parameter.
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent widget
+*/
+QtxMenu::QtxMenu( QWidget* parent )
+: QMenu( parent ),
+ myMode( TitleAuto )
+{
+ myTitle = new Title( this );
+ myAction = new QWidgetAction( this );
+ myAction->setDefaultWidget( myTitle );
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxMenu::~QtxMenu()
+{
+}
+
+/*!
+ \brief Get title menu text.
+ \return menu text for the title item
+*/
+QString QtxMenu::titleText() const
+{
+ return myTitle->text();
+}
+
+/*!
+ \brief Get title icon.
+ \return title item icon
+*/
+QIcon QtxMenu::titleIcon() const
+{
+ return myTitle->icon();
+}
+
+/*!
+ \brief Get title item display mode.
+ \return popup menu title display mode (QtxMenu::TitleMode)
+*/
+QtxMenu::TitleMode QtxMenu::titleMode() const
+{
+ return myMode;
+}
+
+/*!
+ \brief Get title alignment flags.
+ \return title alignment flags
+*/
+Qt::Alignment QtxMenu::titleAlignment() const
+{
+ return myTitle->alignment();
+}
+
+/*!
+ \brief Set title menu text.
+ \param txt menu text to be used for the title item
+*/
+void QtxMenu::setTitleText( const QString& txt )
+{
+ if ( titleText() == txt )
+ return;
+
+ myTitle->setText( txt );
+
+ updateTitle();
+}
+
+/*!
+ \brief Set title icon.
+ \param ico title item icon
+*/
+void QtxMenu::setTitleIcon( const QIcon& ico )
+{
+ myTitle->setIcon( ico );
+
+ updateTitle();
+}
+
+/*!
+ \brief Set title item display mode.
+ \param m popup menu title display mode (QtxMenu::TitleMode)
+*/
+void QtxMenu::setTitleMode( const QtxMenu::TitleMode m )
+{
+ if ( myMode == m )
+ return;
+
+ myMode = m;
+
+ updateTitle();
+}
+
+/*!
+ \brief Set title alignment flags.
+ \param a title alignment flags
+*/
+void QtxMenu::setTitleAlignment( const Qt::Alignment a )
+{
+ if ( titleAlignment() == a )
+ return;
+
+ myTitle->setAlignment( a );
+
+ updateTitle();
+}
+
+/*!
+ \brief Customize show/hide menu operation.
+ \param on new popup menu visibility state
+*/
+void QtxMenu::setVisible( bool on )
+{
+ if ( on )
+ insertTitle();
+
+ QMenu::setVisible( on );
+
+ if ( !on )
+ removeTitle();
+}
+
+/*!
+ \brief Insert title item to the popup menu.
+*/
+void QtxMenu::insertTitle()
+{
+ if ( titleMode() == TitleOff || ( titleMode() == TitleAuto && titleText().trimmed().isEmpty() ) )
+ return;
+
+ if ( actions().isEmpty() )
+ addAction( myAction );
+ else
+ insertAction( actions().first(), myAction );
+}
+
+/*!
+ \brief Remove title item from the popup menu.
+*/
+void QtxMenu::removeTitle()
+{
+ if ( actions().contains( myAction ) )
+ removeAction( myAction );
+}
+
+/*!
+ \brief Update title item.
+*/
+void QtxMenu::updateTitle()
+{
+ if ( !actions().contains( myAction ) )
+ return;
+
+ removeTitle();
+ insertTitle();
+}
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxMenu.h
+// Author: Sergey TELKOV
+//
+
+#ifndef QTXMENU_H
+#define QTXMENU_H
+
+#include "Qtx.h"
+
+#include <QMenu>
+
+class QWidgetAction;
+
+class QTX_EXPORT QtxMenu : public QMenu
+{
+ Q_OBJECT
+
+ class Title;
+
+public:
+ //! Popup menu title mode
+ typedef enum {
+ TitleAuto, //!< auto mode
+ TitleOn, //!< always on (display title)
+ TitleOff //!< always off (do not display title)
+ } TitleMode;
+
+public:
+ QtxMenu( QWidget* = 0 );
+ virtual ~QtxMenu();
+
+ QIcon titleIcon() const;
+ QString titleText() const;
+
+ TitleMode titleMode() const;
+ Qt::Alignment titleAlignment() const;
+
+ virtual void setTitleIcon( const QIcon& );
+ virtual void setTitleText( const QString& );
+
+ virtual void setTitleMode( const TitleMode );
+ virtual void setTitleAlignment( const Qt::Alignment );
+
+public slots:
+ virtual void setVisible( bool );
+
+private:
+ void updateTitle();
+ void insertTitle();
+ void removeTitle();
+
+private:
+ TitleMode myMode;
+ Title* myTitle;
+ QWidgetAction* myAction;
+};
+
+#endif // QTXMENU_H
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxRubberBand.cxx
+// Author: Alexander A. BORODIN
+//
+
+#include "QtxRubberBand.h"
+
+#include <QBitmap>
+#include <QImage>
+#include <QPaintEvent>
+#include <QPainter>
+#include <QPalette>
+#include <QShowEvent>
+#include <QVectorIterator>
+
+/*!
+ \class QtxAbstractRubberBand
+ \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.
+
+ Currently this class does not support Style functionality in full.
+*/
+
+/*!
+ \brief Constructor
+ \param theParent parent widget
+ */
+
+QtxAbstractRubberBand::QtxAbstractRubberBand( QWidget* theParent)
+ : QWidget( theParent/*,Qt::ToolTip*/ ),
+ myPoints(),
+ myIsClosed( false )
+{
+ setAttribute(Qt::WA_TransparentForMouseEvents);
+#ifndef WIN32
+ setAttribute(Qt::WA_NoSystemBackground);
+#endif //WIN32
+ setAttribute(Qt::WA_WState_ExplicitShowHide);
+ setVisible(false);
+ theParent->installEventFilter(this);
+ setGeometry( QRect(QPoint(0,0), theParent->size() ) );
+}
+
+/*!
+ \brief Destructor
+ */
+QtxAbstractRubberBand::~QtxAbstractRubberBand()
+{
+}
+
+void QtxAbstractRubberBand::clearGeometry()
+{
+ myPoints.clear();
+}
+
+bool QtxAbstractRubberBand::isClosed()
+{
+ return myIsClosed;
+}
+
+void QtxAbstractRubberBand::paintEvent( QPaintEvent* theEvent )
+{
+ if ( !myPoints.empty() )
+ {
+ QPixmap tiledPixmap(16, 16);
+
+ QPainter pixmapPainter(&tiledPixmap);
+ pixmapPainter.setPen(Qt::NoPen);
+ pixmapPainter.setBrush(QBrush( Qt::black, Qt::Dense4Pattern ));
+ pixmapPainter.setBackground(QBrush( Qt::white ));
+ pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
+ pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
+ pixmapPainter.end();
+ // ### workaround for borked XRENDER
+ tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
+
+
+
+ QPainter aPainter( this );
+ aPainter.setRenderHint( QPainter::Antialiasing );
+ QRect r = myPoints.boundingRect();
+ aPainter.setClipRegion( r.normalized().adjusted( -1, -1, 2, 2 ) );
+ aPainter.drawTiledPixmap( 0, 0, width(), height(), tiledPixmap);
+
+ aPainter.end();
+
+ /*
+
+
+
+#ifdef WIN32
+ QPixmap anImage( size() );
+#else
+ QImage anImage( size(), QImage::Format_ARGB32_Premultiplied );
+#endif
+
+ anImage.fill( Qt::transparent );
+ QPainter aImgPainter( &anImage );
+ aImgPainter.setRenderHint( QPainter::Antialiasing );
+ aImgPainter.setCompositionMode(QPainter::CompositionMode_Source);
+
+ QPen aPen( Qt::black );
+ aPen.setWidth( 2 );
+ aImgPainter.setPen( aPen );
+
+ aImgPainter.drawPolyline( myPoints );
+ if ( myIsClosed && myPoints.last() != myPoints.first() )
+ aImgPainter.drawLine( myPoints.last(), myPoints.first() );
+
+ //aImgPainter.setPen(Qt::NoPen);
+ //aImgPainter.setBrush(QBrush( Qt::white, Qt::Dense4Pattern));
+ //aImgPainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
+ //aImgPainter.drawRect(0, 0, width(), height());
+ aImgPainter.end();
+
+ QPainter aPainter( this );
+ aPainter.drawPolyline( myPoints );
+ if ( myIsClosed && myPoints.last() != myPoints.first() )
+ aPainter.drawLine( myPoints.last(), myPoints.first() );
+
+#ifdef WIN32
+ aPainter.drawPixmap( 0, 0, anImage );
+#else
+ aPainter.drawImage( 0, 0, anImage );
+ #endif
+ aPainter.end();*/
+
+ }
+}
+
+void QtxAbstractRubberBand::showEvent( QShowEvent* theEvent )
+{
+ raise();
+ theEvent->ignore();
+}
+
+void QtxAbstractRubberBand::moveEvent( QMoveEvent* )
+{
+}
+
+void QtxAbstractRubberBand::resizeEvent( QResizeEvent* )
+{
+}
+
+bool QtxAbstractRubberBand::eventFilter( QObject* obj, QEvent* e )
+{
+ if ( obj && obj == parent() && e->type() == QEvent::Resize )
+ {
+ QWidget* p = (QWidget*)parent();
+ setGeometry( QRect(QPoint(0,0), p->size() ) );
+ }
+ return QWidget::eventFilter( obj, e );
+}
+
+QRegion createRegion( const QPointF& p1, const QPointF& p2 )
+{
+ if ( p1 == p2 )
+ return QRegion();
+
+ QLineF n = QLineF( p1, p2 ).normalVector();//.unitVector();
+ n.setLength( 1 );
+ n.translate( p1 * -1 );
+ QPointF nPoint = n.p2();
+
+ QPolygonF p;
+ p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint;
+
+ return QRegion( p.toPolygon() );
+}
+
+void QtxAbstractRubberBand::updateMask()
+{
+ QRegion r;
+
+ QVectorIterator<QPoint> it(myPoints);
+ while( it.hasNext() )
+ {
+ QPoint p = it.next();
+ if( !it.hasNext() )
+ break;
+
+ QPoint np = it.peekNext();
+
+ if ( p == np ) continue;
+
+ r += createRegion( p, np );
+ }
+
+ if ( isClosed() )
+ r += createRegion( myPoints.last(), myPoints.first() );
+
+ setMask( r );
+
+}
+
+
+QtxRectRubberBand::QtxRectRubberBand(QWidget* parent)
+ :QtxAbstractRubberBand( parent )
+{
+ myPoints.resize( 4 );
+ myIsClosed = true;
+}
+
+QtxRectRubberBand::~QtxRectRubberBand()
+{
+}
+
+void QtxRectRubberBand::initGeometry( const QRect& theRect )
+{
+ myPoints.clear();
+ myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight() << theRect.bottomLeft();
+ //setMask( QRegion( myPoints ) );
+ updateMask();
+}
+
+void QtxRectRubberBand::setStartPoint( const QPoint& thePoint )
+{
+ myPoints[0] = thePoint;
+ myPoints[1].setY( thePoint.y() );
+ myPoints[3].setX( thePoint.x() );
+ updateMask();
+}
+
+void QtxRectRubberBand::setEndPoint( const QPoint& thePoint)
+{
+ myPoints[2] = thePoint;
+ myPoints[1].setX( thePoint.x() );
+ myPoints[3].setY( thePoint.y() );
+ updateMask();
+}
+
+void QtxRectRubberBand::clearGeometry()
+{
+ QMutableVectorIterator<QPoint> i(myPoints);
+ while (i.hasNext())
+ {
+ i.next();
+ i.setValue( QPoint( -1, -1 ) );
+ }
+}
+
+
+QtxPolyRubberBand::QtxPolyRubberBand(QWidget* parent)
+ :QtxAbstractRubberBand( parent )
+{
+}
+
+QtxPolyRubberBand::~QtxPolyRubberBand()
+{
+}
+
+void QtxPolyRubberBand::initGeometry( const QPolygon& thePoints )
+{
+ myPoints = thePoints;
+ updateMask();
+}
+
+void QtxPolyRubberBand::initGeometry( const QPoint& thePoint )
+{
+ myPoints.clear();
+ myPoints << thePoint;
+ updateMask();
+}
+
+void QtxPolyRubberBand::addNode( const QPoint& thePoint )
+{
+ myPoints << thePoint;
+ updateMask();
+}
+
+void QtxPolyRubberBand::replaceLastNode( const QPoint& thePoint )
+{
+ if ( !myPoints.empty() )
+ {
+ myPoints.pop_back();
+ myPoints << thePoint;
+ updateMask();
+ }
+}
+
+void QtxPolyRubberBand::removeLastNode()
+{
+ if ( !myPoints.empty() )
+ {
+ myPoints.pop_back();
+ updateMask();
+ }
+}
+
+void QtxPolyRubberBand::setClosed( bool theFlag )
+{
+ if (myIsClosed != theFlag )
+ {
+ myIsClosed = theFlag;
+ updateMask();
+ }
+}
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxRubberBand.h
+// Author: Alexander A. BORODIN
+//
+
+#ifndef QTXRUBBERBAND_H
+#define QTXRUBBERBAND_H
+
+#include "Qtx.h"
+
+#include <QWidget>
+
+class QTX_EXPORT QtxAbstractRubberBand: public QWidget
+{
+protected:
+ QtxAbstractRubberBand( QWidget* );
+
+public:
+ virtual ~QtxAbstractRubberBand();
+
+ virtual void clearGeometry();
+
+ bool isClosed();
+
+protected:
+ virtual void paintEvent( QPaintEvent* );
+ virtual void showEvent( QShowEvent* );
+ virtual void moveEvent( QMoveEvent* );
+ virtual void resizeEvent( QResizeEvent* );
+
+ virtual bool eventFilter( QObject*, QEvent* );
+
+ virtual void updateMask();
+
+protected:
+ QPolygon myPoints;
+
+ bool myIsClosed;
+};
+
+class QTX_EXPORT QtxRectRubberBand: public QtxAbstractRubberBand
+{
+public:
+
+ QtxRectRubberBand( QWidget* );
+ virtual ~QtxRectRubberBand();
+
+ void initGeometry( const QRect& );
+ void setStartPoint( const QPoint& );
+ void setEndPoint( const QPoint& );
+
+ virtual void clearGeometry();
+};
+
+class QTX_EXPORT QtxPolyRubberBand: public QtxAbstractRubberBand
+{
+public:
+
+ QtxPolyRubberBand( QWidget* );
+ virtual ~QtxPolyRubberBand();
+
+ void initGeometry( const QPolygon& );
+ void initGeometry( const QPoint& );
+
+ void addNode( const QPoint& );
+ void replaceLastNode( const QPoint& );
+ void removeLastNode();
+
+ void setClosed( bool );
+};
+
+#endif //QTXRUBBERBAND_H
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxTranslator.cxx
+// Author: Alexander SOLOVYOV
+
+#include "QtxTranslator.h"
+
+/*!
+ \class QtxTranslator
+ \brief Extended version of QTranslator
+
+ In addition to the functionality provided by QTranslator class, QtxTranslator
+ allows translating resources defined in the global context (i.e. common resources).
+ The QtxTranslator can be used to workaround QTranslator's limitation which
+ does not allow to process messages with global context.
+
+ For the current moment global context should be specified in translation
+ (*.ts/*.qm) files as "@default" string. For example:
+ \verbatim
+ <!DOCTYPE TS><TS>
+ <context>
+ <name>@default</name>
+ <message>
+ <source>MY_MESSAGE</source>
+ <translation>My translated message</translation>
+ </message>
+ </context>
+ </TS>
+ \endverbatim
+*/
+
+#define GLOBAL_CONTEXT "@default"
+
+/*!
+ \brief Constructor.
+*/
+QtxTranslator::QtxTranslator( QObject* parent )
+: QTranslator( parent )
+{
+}
+
+/*!
+ \brief Destructor.
+*/
+QtxTranslator::~QtxTranslator()
+{
+}
+
+/*!
+ \brief Returns the translation for the key.
+ \param context message context
+ \param sourceText message source name
+ \param comment message comment (optional)
+ \return Translated text if found or \a sourceText otherwise
+*/
+QString QtxTranslator::translate( const char* context, const char* sourceText, const char* comment ) const
+{
+ QString res = QTranslator::translate( context, sourceText, comment );
+ if( res.isNull() )
+ res = QTranslator::translate( GLOBAL_CONTEXT, sourceText, comment );
+ return res;
+}
--- /dev/null
+// 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
+// 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
+// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: QtxTranslator.h
+// Author: Alexander SOLOVYOV
+
+#ifndef QTXTRANSLATOR_H
+#define QTXTRANSLATOR_H
+
+#include <QTranslator>
+
+class QtxTranslator : public QTranslator
+{
+public:
+ QtxTranslator( QObject* parent = 0 );
+ ~QtxTranslator();
+ virtual QString translate( const char*, const char*, const char* = 0 ) const;
+};
+
+#endif