From: nds Date: Fri, 21 Sep 2007 12:41:06 +0000 (+0000) Subject: The class creation. X-Git-Tag: TG_Saint_Valentine-Day~52 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1138321f337ccb75d2cf816ea91a85967ff36605;p=modules%2Fgui.git The class creation. --- diff --git a/src/TableViewer/TableViewer.h b/src/TableViewer/TableViewer.h new file mode 100755 index 000000000..62fb94111 --- /dev/null +++ b/src/TableViewer/TableViewer.h @@ -0,0 +1,55 @@ +// 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 +// +#ifndef TABLEVIEWER_H +#define TABLEVIEWER_H + +#if defined TABLEVIEWER_EXPORTS +#if defined WIN32 +#define TABLEVIEWER_EXPORT __declspec( dllexport ) +#else +#define TABLEVIEWER_EXPORT +#endif +#else +#if defined WIN32 +#define TABLEVIEWER_EXPORT __declspec( dllimport ) +#else +#define TABLEVIEWER_EXPORT +#endif +#endif + +#if defined SOLARIS +#define bool int +#define false 0 +#define true 1 +#endif + +#if defined WIN32 +#pragma warning ( disable: 4251 ) +#endif + +#if defined ( _DEBUG ) || defined ( DEBUG ) +#include +#define TABLEVIEWER_VERIFY(x) assert( x ); +#define TABLEVIEWER_ASSERT(x) assert( x ); +#else +#define TABLEVIEWER_VERIFY(x) x +#define TABLEVIEWER_ASSERT(x) +#endif + +#endif diff --git a/src/TableViewer/TableViewer.pro b/src/TableViewer/TableViewer.pro new file mode 100644 index 000000000..461bc659b --- /dev/null +++ b/src/TableViewer/TableViewer.pro @@ -0,0 +1,35 @@ +TEMPLATE = lib + +DESTDIR = ../../$(CONFIG_ID)/lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET + +CASROOT = $$(CASROOT) +CAS_CPPFLAGS = $${CASROOT}/inc +CAS_KERNEL = -L$${CASROOT}/Linux/lib -lTKernel + +INCLUDEPATH = ../../include $${CAS_CPPFLAGS} +LIBS += -L../../$(CONFIG_ID)/lib -lSUIT $${CAS_KERNEL} -lHTMLService + +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += TABLE_VIEWER_EXPORTS OCC_VERSION_MAJOR=6 OCC_VERSION_MINOR=1 OCC_VERSION_MAINTENANCE=1 LIN LINTEL CSFDB No_exception HAVE_CONFIG_H HAVE_LIMITS_H HAVE_WOK_CONFIG_H OCC_CONVERT_SIGNALS + +HEADERS = *.h + +SOURCES = *.cxx + +TRANSLATIONS = resources/TableViewer_images.ts \ + resources/TableViewer_msg_en.ts + +ICONS = resources/*.png + +includes.files = $$HEADERS +includes.path = ../../include + +resources.files = $$ICONS resources/*.qm +resources.path = ../../resources + +INSTALLS += includes resources diff --git a/src/TableViewer/TableViewer_Tool.cxx b/src/TableViewer/TableViewer_Tool.cxx new file mode 100755 index 000000000..b39554d68 --- /dev/null +++ b/src/TableViewer/TableViewer_Tool.cxx @@ -0,0 +1,98 @@ +// 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 +// +// TableViewer_ViewModel.cxx: implementation of the TableViewer_ViewModel class. + +#include "TableViewer_Tool.h" + +#include +#include + +#include +#include + +//================================================================ +// Function : ToExtString +// Purpose : +//================================================================ + +TCollection_ExtendedString TableViewer_Tool::ToExtString( const QString& src ) +{ + if ( src.isEmpty() ) + return TCollection_ExtendedString(); + + Standard_Integer len = src.length(); + Standard_ExtString extStr = new Standard_ExtCharacter [( len + 1 ) * 2]; + memcpy( extStr, src.unicode(), len * 2 ); + extStr[len] = 0; + + TCollection_ExtendedString trg( extStr ); + + delete [] extStr; + + return trg; +} + +//================================================================ +// Function : ToDouble +// Purpose : convert string to double +//================================================================ +double TableViewer_Tool::ToDouble( const QString& txt ) +{ + bool isDone = true; + return TableViewer_Tool::ToDouble( txt, isDone ); +} + +//================================================================ +// Function : ToDouble +// Purpose : convert string to double +//================================================================ +double TableViewer_Tool::ToDouble( const QString& txt, bool& isDone ) +{ + return txt.toDouble( &isDone ); +} + +//================================================================ +// Function : DoubleToQString +// Purpose : convert string to double +//================================================================ +QString TableViewer_Tool::DoubleToQString( const double val, const bool replaceDot ) +{ + QString txt = QString::number( val ); + if ( replaceDot ) + txt.replace( '.', ',' ); + return txt; +} + +//================================================================ +// Function : DoubleToQString +// Purpose : convert Qt color to OpenCascade color +//================================================================ +Quantity_Color TableViewer_Tool::Color( const QColor& c ) +{ + return Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB ); +} + +//================================================================ +// Function : DoubleToQString +// Purpose : convert OpenCascade color to Qt color +//================================================================ +QColor TableViewer_Tool::Color( const Quantity_Color& c ) +{ + return QColor( (int)( 255 * c.Red() ), (int)( 255 * c.Green() ), (int)( 255 * c.Blue() ) ); +} diff --git a/src/TableViewer/TableViewer_Tool.h b/src/TableViewer/TableViewer_Tool.h new file mode 100755 index 000000000..e94dc9dc6 --- /dev/null +++ b/src/TableViewer/TableViewer_Tool.h @@ -0,0 +1,42 @@ +// 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 +// +#if !defined(TABLEVIEWER_TOLL_H) +#define TABLEVIEWER_TOOL_H + +#include "TableViewer.h" + +class TCollection_ExtendedString; +class QString; +class Quantity_Color; +class QColor; + +class TABLEVIEWER_EXPORT TableViewer_Tool +{ +public: + static TCollection_ExtendedString ToExtString( const QString& ); + static double ToDouble( const QString& ); + static double ToDouble( const QString&, bool& ); + static QString DoubleToQString( const double, const bool = false ); + + static Quantity_Color Color( const QColor& ); + static QColor Color( const Quantity_Color& ); +}; + +#endif // !defined(TABLEVIEWER_TOOL_H) + diff --git a/src/TableViewer/TableViewer_ViewManager.cxx b/src/TableViewer/TableViewer_ViewManager.cxx new file mode 100755 index 000000000..14ee13d54 --- /dev/null +++ b/src/TableViewer/TableViewer_ViewManager.cxx @@ -0,0 +1,89 @@ +// 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 +// +#include "TableViewer_ViewManager.h" +#include "TableViewer_ViewModel.h" +#include "TableViewer_ViewWindow.h" + +#include +#include + +/*! + Constructor +*/ +TableViewer_ViewManager::TableViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) +: SUIT_ViewManager( study, desk, new TableViewer_Viewer() ) +{ + setTitle( tr( "TABLE_VIEWER_VIEW_TITLE" ) ); +} + +/*! + Destructor +*/ +TableViewer_ViewManager::~TableViewer_ViewManager() +{ +} + +/*! + \return corresponding viewer +*/ +TableViewer_Viewer* TableViewer_ViewManager::getTableModel() const +{ + return (TableViewer_Viewer*)myViewModel; +} + +/*! + Adds new view + \param theView - view to be added +*/ +/*bool TableViewer_ViewManager::insertView( SUIT_ViewWindow* theView ) +{ + bool res = SUIT_ViewManager::insertView( theView ); + if ( res ) + { + TableViewer_ViewWindow* view = (TableViewer_ViewWindow*)theView; + connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) ); + } + return res; +} +*/ +/*! + Creates new view +*/ +void TableViewer_ViewManager::createView() +{ + createViewWindow(); +} + +/*! + SLOT: called if action "Clone view" is activated, emits signal cloneView() +*/ +/*void TableViewer_ViewManager::onCloneView() +{ + SUIT_ViewWindow* vw = createViewWindow(); + + TableViewer_ViewWindow *newWnd = 0, *clonedWnd = 0; + if( vw && vw->inherits( "TableViewer_ViewWindow" ) ) + newWnd = ( TableViewer_ViewWindow* )vw; + if( sender() && sender()->inherits( "TableViewer_ViewWindow" ) ) + clonedWnd = ( TableViewer_ViewWindow* )sender(); + + if( newWnd && clonedWnd ) + emit cloneView( clonedWnd->getViewFrame(), newWnd->getViewFrame() ); +} +*/ diff --git a/src/TableViewer/TableViewer_ViewManager.h b/src/TableViewer/TableViewer_ViewManager.h new file mode 100755 index 000000000..b80d8381e --- /dev/null +++ b/src/TableViewer/TableViewer_ViewManager.h @@ -0,0 +1,53 @@ +// 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 +// +#ifndef TABLEVIEWER_VIEWMANAGER_H +#define TABLEVIEWER_VIEWMANAGER_H + +#include "TableViewer.h" +#include "SUIT_ViewManager.h" + +class SUIT_Study; +class SUIT_Desktop; +class TableViewer_Viewer; +class TableViewer_ViewFrame; + +class TABLEVIEWER_EXPORT TableViewer_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT + +public: + TableViewer_ViewManager( SUIT_Study*, SUIT_Desktop* ); + ~TableViewer_ViewManager(); + + TableViewer_Viewer* getTableModel() const; + +//protected: +// bool insertView(SUIT_ViewWindow* theView); + +public slots: + void createView(); + +//protected slots: +// void onCloneView(); + +//signals: +// void cloneView( TableViewer_ViewFrame*, TableViewer_ViewFrame* ); +}; + +#endif diff --git a/src/TableViewer/TableViewer_ViewModel.cxx b/src/TableViewer/TableViewer_ViewModel.cxx new file mode 100755 index 000000000..12b7058be --- /dev/null +++ b/src/TableViewer/TableViewer_ViewModel.cxx @@ -0,0 +1,53 @@ +// 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 +// +// TableViewer_ViewModel.cxx: implementation of the TableViewer_ViewModel class. + +#include "TableViewer_ViewModel.h" +#include "TableViewer_ViewWindow.h" +#include "TableViewer_ViewManager.h" + +#include +/*! + Constructor +*/ +TableViewer_Viewer::TableViewer_Viewer() +:SUIT_ViewModel() +{ +} + +/*! + Destructor +*/ +TableViewer_Viewer::~TableViewer_Viewer() +{ +} + +/*! + Create new instance of view window on desktop \a theDesktop. + \retval SUIT_ViewWindow* - created view window pointer. +*/ +SUIT_ViewWindow* TableViewer_Viewer::createView( SUIT_Desktop* theDesktop ) +{ + TableViewer_ViewWindow* vw = new TableViewer_ViewWindow( theDesktop, this ); + QtxTable* tbl = vw->table(); + if ( tbl && getViewManager() ) + tbl->viewport()->installEventFilter( getViewManager() ); + return vw; +} + diff --git a/src/TableViewer/TableViewer_ViewModel.h b/src/TableViewer/TableViewer_ViewModel.h new file mode 100755 index 000000000..cd8f5140b --- /dev/null +++ b/src/TableViewer/TableViewer_ViewModel.h @@ -0,0 +1,44 @@ +// 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 +// +#if !defined(TABLEVIEWER_VIEWMODEL_H) +#define TABLEVIEWER_VIEWMODEL_H + +#include "TableViewer.h" +#include "SUIT_ViewModel.h" + +class SUIT_ViewWindow; +class SUIT_Desktop; +class QString; + +class TABLEVIEWER_EXPORT TableViewer_Viewer: public SUIT_ViewModel +{ + Q_OBJECT + +public: + static QString Type() { return "TableViewer"; } + + TableViewer_Viewer(); + ~TableViewer_Viewer(); + + virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual QString getType() const { return Type(); } +}; + +#endif // !defined(TABLEVIEWER_VIEWMODEL_H) + diff --git a/src/TableViewer/TableViewer_ViewWindow.cxx b/src/TableViewer/TableViewer_ViewWindow.cxx new file mode 100755 index 000000000..fa0a629d0 --- /dev/null +++ b/src/TableViewer/TableViewer_ViewWindow.cxx @@ -0,0 +1,401 @@ +// 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 +// +// TableViewer_ViewModel.cxx: implementation of the TableViewer_ViewModel class. + +#include "TableViewer_ViewWindow.h" +#include "TableViewer_ViewModel.h" +#include "TableViewer_Tool.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +/*! + Constructor +*/ +TableViewer_ViewWindow::TableViewer_ViewWindow( SUIT_Desktop* theDesktop, + TableViewer_Viewer* theModel ) +:SUIT_ViewWindow( theDesktop ) +{ + myModel = theModel; + myTable = new QtxTable( this ); + + //myTable->setReadOnly( true ); + setCentralWidget( myTable ); + + myToolBar = new QtxToolBar( true, tr("LBL_TOOLBAR_LABEL"), this ); + + createActions(); + createToolBar(); + + // fill table + myTable->setColumnCount(3); + myTable->setRowCount(5); + myTable->setCellBackground( 1, 1, Qt::red ); + myTable->setCellForeground( 1, 1, Qt::blue ); + QFont aFont = myTable->font(); + aFont.setBold( true ); + myTable->setCellFont( 1, 1, aFont ); + myTable->setCellFont( 0, 0, aFont ); + + aFont.setUnderline( true ); + myTable->setCellFont( 0, 1, aFont ); + + + myTable->setCellBackground( 2, 2, myTable->cellBackground( 1, 1 ) ); + myTable->setCellForeground( 2, 2, myTable->cellForeground( 1, 1 ) ); + aFont = myTable->cellFont( 1, 1 ); + myTable->setCellFont( 2, 2, aFont ); + myTable->setCellBackground( 0, 1, myTable->cellBackground( 0, 0 ) ); + + myTable->setHeaderData( Qt::Horizontal, 1, "Caption"); + myTable->setHeaderBackground( Qt::Horizontal, 1, Qt::green ); + myTable->setHeaderFont(Qt::Vertical, 2, aFont ); + myTable->setHeaderFont(Qt::Horizontal, 0, aFont ); +} + +/*! + Destructor +*/ +TableViewer_ViewWindow::~TableViewer_ViewWindow() +{ +} + +QtxTable* TableViewer_ViewWindow::table() const +{ + return myTable; +} + +QImage TableViewer_ViewWindow::dumpView() +{ + return QPixmap::grabWindow( table()->winId() ).toImage(); +} + +void TableViewer_ViewWindow::createActions() +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + createAction( DumpId, tr( "MEN_DUMP" ), + resMgr->loadPixmap( "TableViewer", tr( "ICON_DUMP" ) ), + tr( "TIP_DUMP" ), tr( "PRP_DUMP" ) ); + + createAction( CopyId, tr( "MEN_COPY" ), + resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ), + tr( "TIP_COPY" ), tr( "PRP_COPY" ) ); + + createAction( PrintId, tr( "MEN_PRINT" ), + resMgr->loadPixmap( "STD", tr( "ICON_PRINT" ) ), + tr( "TIP_PRINT" ), tr( "PRP_PRINT" ) ); + + createAction( ExportId, tr( "MEN_EXPORT" ), + resMgr->loadPixmap( "TableViewer", tr( "ICON_EXPORT" ) ), + tr( "TIP_EXPORT" ), tr( "PRP_EXPORT" ) ); +} + +int TableViewer_ViewWindow::numRows( const ContentType type ) const +{ + int aRows = 0; + switch ( type ) { + case HorizontalHeader: + aRows = 1; + break; + case Cells: + case VerticalHeader: + aRows = myTable->rowCount(); + break; + default: + break; + } + return aRows; +} + +int TableViewer_ViewWindow::numCols( const ContentType type ) const +{ + int aCols = 0; + switch ( type ) { + case VerticalHeader: + aCols = 1; + break; + case Cells: + case HorizontalHeader: + aCols = myTable->columnCount(); + break; + default: + break; + } + return aCols; +} + +QString TableViewer_ViewWindow::text( const ContentType type, const int row, const int col ) const +{ + QString aTxt = ""; + switch ( type ) { + case VerticalHeader: + aTxt = myTable->headerData( Qt::Vertical, row ).toString(); + break; + case HorizontalHeader: + aTxt = myTable->headerData( Qt::Horizontal, col ).toString(); + break; + case Cells: + if ( myTable->item( row, col ) ) + aTxt = myTable->item( row, col )->text(); + break; + default: + break; + } + return aTxt; +} + +QString TableViewer_ViewWindow::image( const ContentType type, const int row, const int col ) const +{ + return ""; +} + +int TableViewer_ViewWindow::fontFlags( const ContentType type, const int row, const int col ) const +{ + int aFlags = 0; + QFont aFont = myTable->font(); + switch ( type ) { + case VerticalHeader: + aFont = myTable->headerFont( Qt::Horizontal, row ); + break; + case HorizontalHeader: + aFont = myTable->headerFont( Qt::Vertical, col ); + break; + case Cells: + aFont = myTable->cellFont( row, col ); + break; + default: + break; + } + if ( aFont.bold() ) + aFlags |= HTMLService_HTMLText::Bold; + if ( aFont.italic() ) + aFlags |= HTMLService_HTMLText::Bold; + if ( aFont.underline() ) + aFlags |= HTMLService_HTMLText::Underline; + if ( aFont.strikeOut() ) + aFlags |= HTMLService_HTMLText::StrikeOut; + //Subscript + + return aFlags; +} + +QColor TableViewer_ViewWindow::foregroundColor( const ContentType type, const int row, + const int col ) const +{ + QColor aColor; + switch ( type ) { + case VerticalHeader: + case HorizontalHeader: { + bool aHor = type == HorizontalHeader; + aColor = myTable->headerForeground( aHor ? Qt::Horizontal : Qt::Vertical, + aHor ? col : row ); + } + break; + case Cells: + aColor = myTable->cellForeground( row, col ); + break; + default: + break; + } + return aColor; +} + +QColor TableViewer_ViewWindow::backgroundColor( const ContentType type, const int row, + const int col ) const +{ + QColor aColor; + switch ( type ) { + case VerticalHeader: + case HorizontalHeader: { + bool aHor = type == HorizontalHeader; + aColor = myTable->headerForeground( aHor ? Qt::Horizontal : Qt::Vertical, + aHor ? col : row ); + } + break; + case Cells: + aColor = myTable->cellBackground( row, col ); + break; + default: + break; + } + return aColor; +} + +void TableViewer_ViewWindow::createToolBar() +{ + myToolBar->addAction( myActionsMap[DumpId] ); + myToolBar->addAction( myActionsMap[CopyId] ); + myToolBar->addAction( myActionsMap[PrintId] ); + myToolBar->addAction( myActionsMap[ExportId] ); +} + +void TableViewer_ViewWindow::actionActivated( const int id ) +{ + switch ( id ) { + case DumpId: + onDumpView(); + break; + case ExportId: + exportData(); + break; + } +} + +void TableViewer_ViewWindow::registerAction( const int id, QtxAction* a ) +{ + if ( !a ) + return; + + myActionsMap.insert( id, a ); + connect( a, SIGNAL( activated() ), this, SLOT( onActivated() ) ); +} + +QtxAction* TableViewer_ViewWindow::createAction( const int id, const QString& menu, const QPixmap& ico, + const QString& tip, const QString& status, + const int accel, QObject* parent ) +{ + QtxAction* a = new QtxAction( menu, ico, menu, accel, parent ? parent : myDesktop ); + a->setToolTip( tip ); + a->setStatusTip( status ); + registerAction( id, a ); + return a; +} + +void TableViewer_ViewWindow::onActivated() +{ + const QObject* obj = sender(); + const QtxAction* a = ::qobject_cast( obj ); + if ( !a ) + return; + + int id = -1; + for ( ActionsMap::const_iterator it = myActionsMap.begin(); + it != myActionsMap.end() && id == -1; ++it ) { + if ( it.value() == a ) + id = it.key(); + } + + if ( id == -1 ) + return; + + actionActivated( id ); +} + +void TableViewer_ViewWindow::exportData() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + QString fileName = app->getFileName( false, QString::null, tr( "EXPORT_FILTER" ), + tr( "EXPORT_TABLE" ), 0 ); + if ( fileName.isEmpty() ) + return; + + QApplication::setOverrideCursor( Qt::WaitCursor ); + + int rows = numRows( Cells ); + int cols = numCols( Cells ); + int horOffset = numRows( HorizontalHeader ); + int verOffset = numCols( VerticalHeader ); + + Handle(HTMLService_HTMLTable) table = new HTMLService_HTMLTable( rows + horOffset, + cols + verOffset ); + QString title = getViewManager()->getTitle(); + SUIT_ViewWindow* anActiveWnd = getViewManager()->getActiveView(); + if ( anActiveWnd ) + title = anActiveWnd->windowTitle(); + + table->SetTitle( TableViewer_Tool::ToExtString( title ) ); + table->SetWidth( 100, true ); + table->SetBorder( 2 ); + + exportTableData( table, HorizontalHeader, 0, verOffset ); + exportTableData( table, VerticalHeader, horOffset, 0 ); + exportTableData( table, Cells, horOffset, verOffset ); + + Handle(HTMLService_HTMLTableCell) ltCell = table->GetCell( 0, 0 ); + if ( !ltCell.IsNull() ) { + ltCell->SetHeaderCell( true ); + ltCell->SetBackgroundColor( Quantity_NOC_GRAY ); + } + table->GenerateFile( TableViewer_Tool::ToExtString( fileName ), true ); + + QApplication::restoreOverrideCursor(); +} + +void TableViewer_ViewWindow::exportTableData( Handle(HTMLService_HTMLTable)& table, + const ContentType type, + const int rowOffset, const int colOffset ) +{ + if ( table.IsNull() ) + return; + + bool isExpImg = true; + bool dotToComma = false; + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if ( resMgr ) { + isExpImg = resMgr->booleanValue( "TableViewer", "export_table_images", true ); + dotToComma = resMgr->booleanValue( "TableViewer", "replace_dot_by_comma", true ); + } + + for ( int c = 0, nbC = numCols( type ); c < nbC; c++ ) { + for ( int r = 0, nbR = numRows( type ); r < nbR; r++ ) { + Handle(HTMLService_HTMLTableCell) cell = + table->GetCell( r + rowOffset, c + colOffset ); + if ( cell.IsNull() ) + continue; + cell->SetHeaderCell( type != Cells ); + if ( cell->IsHeaderCell() ) + cell->SetBackgroundColor( Quantity_NOC_GRAY ); + if ( isExpImg ) { + QString img = image( type, r, c ); + if ( !img.isEmpty() ) + cell->InsertImage( TableViewer_Tool::ToExtString( img ), 32, 32 ); + } + QString txt = text( type, r, c ); + if ( !txt.isEmpty() ) { + bool aDbl = false; + double aVal = TableViewer_Tool::ToDouble( txt, aDbl ); + if ( aDbl ) + cell->InsertText( TableViewer_Tool::ToExtString( + TableViewer_Tool::DoubleToQString( aVal, dotToComma ) ) ); + else + cell->InsertText( TableViewer_Tool::ToExtString( txt ) ); + } + if ( foregroundColor( type, r, c ).isValid() ) + cell->SetForegroundColor( TableViewer_Tool::Color( foregroundColor( type, r, c ) ) ); + if ( backgroundColor( type, r, c ).isValid() ) + cell->SetBackgroundColor( TableViewer_Tool::Color( backgroundColor( type, r, c ) ) ); + cell->SetFontFlags( fontFlags( type, r, c ) ); + } + } +} diff --git a/src/TableViewer/TableViewer_ViewWindow.h b/src/TableViewer/TableViewer_ViewWindow.h new file mode 100755 index 000000000..9a2f5e1c8 --- /dev/null +++ b/src/TableViewer/TableViewer_ViewWindow.h @@ -0,0 +1,89 @@ +// 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 +// +#if !defined(TABLEVIEWER_VIEWWINDOW_H) +#define TABLEVIEWER_VIEWWINDOW_H + +#include "TableViewer.h" +#include "SUIT_ViewWindow.h" +#include "QtxAction.h" + +#include "HTMLService_HTMLTable.hxx" + +class TableViewer_Viewer; +class SUIT_ViewWindow; +class SUIT_Desktop; +class Handle(HTMLService_HTMLTable); +class QImage; +class QtxTable; +class QToolBar; + +class TABLEVIEWER_EXPORT TableViewer_ViewWindow: public SUIT_ViewWindow +{ + Q_OBJECT + +public: + TableViewer_ViewWindow( SUIT_Desktop* , TableViewer_Viewer* ); + ~TableViewer_ViewWindow(); + + QtxTable* table() const; + QToolBar* getToolBar() { return myToolBar; } + + virtual QImage dumpView(); + +protected: + typedef enum { VerticalHeader, HorizontalHeader, Cells } ContentType; + typedef enum { DumpId, CopyId, PrintId, ExportId, Custom } ActionId; + typedef QMap ActionsMap; + + virtual void createActions(); + virtual void createToolBar(); + virtual void actionActivated( const int ); + virtual void exportTableData( Handle(HTMLService_HTMLTable)&, + const ContentType, const int, const int ); + + void registerAction( const int, QtxAction* ); + QtxAction* createAction( const int, const QString&, const QPixmap&, const QString&, + const QString&, const int = 0, QObject* = 0 ); + + int numRows( const ContentType ) const; + int numCols( const ContentType ) const; + + QString text( const ContentType, const int, const int ) const; + QString image( const ContentType, const int, const int ) const; + int fontFlags( const ContentType, const int, const int ) const; + QColor foregroundColor( const ContentType, const int, const int ) const; + QColor backgroundColor( const ContentType, const int, const int ) const; + +private slots: + void onActivated(); + +private: + void exportData(); + +protected: + TableViewer_Viewer* myModel; + ActionsMap myActionsMap; + +private: + QtxTable* myTable; + QToolBar* myToolBar; +}; + +#endif // !defined(TABLEVIEWER_VIEWWINDOW_H) + diff --git a/src/TableViewer/resources/TableViewer_images.ts b/src/TableViewer/resources/TableViewer_images.ts new file mode 100644 index 000000000..b81cfb8c3 --- /dev/null +++ b/src/TableViewer/resources/TableViewer_images.ts @@ -0,0 +1,24 @@ + + + + TableViewer_ViewManager + + + TABLE_VIEWER_VIEW_TITLE + + + + + TableViewer_ViewWindow + + + ICON_DUMP + table_camera_dump.png + + + + ICON_EXPORT + table_export.png + + + diff --git a/src/TableViewer/resources/TableViewer_msg_en.ts b/src/TableViewer/resources/TableViewer_msg_en.ts new file mode 100644 index 000000000..e61b5e3c0 --- /dev/null +++ b/src/TableViewer/resources/TableViewer_msg_en.ts @@ -0,0 +1,89 @@ + + + + TableViewer_ViewManager + + + TABLE_VIEWER_VIEW_TITLE + TableViewer scene:%M - viewer %V + + + + TableViewer_ViewWindow + + + LBL_TOOLBAR_LABEL + View operations + + + + MEN_DUMP + Dump view... + + + + TIP_DUMP + Dump view + + + + PRP_DUMP + Dump view + + + + MEN_COPY + Copy + + + + TIP_COPY + Copy + + + + PRP_COPY + Copy + + + + MEN_PRINT + Print view + + + + TIP_PRINT + Print view + + + + PRP_PRINT + Print view + + + + MEN_EXPORT + Export to HTML... + + + + TIP_EXPORT + Export as HTML file + + + + PRP_EXPORT + Export to HTML file + + + + EXPORT_FILTER + Hyper text document (*.htm *.html) + + + + EXPORT_TABLE + Export table to file + + + diff --git a/src/TableViewer/resources/table_camera_dump.png b/src/TableViewer/resources/table_camera_dump.png new file mode 100755 index 000000000..b02616f29 Binary files /dev/null and b/src/TableViewer/resources/table_camera_dump.png differ diff --git a/src/TableViewer/resources/table_export.png b/src/TableViewer/resources/table_export.png new file mode 100755 index 000000000..00d739c5a Binary files /dev/null and b/src/TableViewer/resources/table_export.png differ