From 4b9e5ed96bbd77946f0cb408a114b2432fbdc995 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 17 Jul 2007 12:44:07 +0000 Subject: [PATCH] *** empty log message *** --- src/Qtx/Makefile.am | 6 +- src/Qtx/Qtx.h | 5 + src/Qtx/QtxListView.cxx | 424 ---------------------------------------- src/Qtx/QtxListView.h | 103 ---------- src/Qtx/QtxTreeView.cxx | 135 +++++++++++++ src/Qtx/QtxTreeView.h | 49 +++++ 6 files changed, 192 insertions(+), 530 deletions(-) delete mode 100755 src/Qtx/QtxListView.cxx delete mode 100755 src/Qtx/QtxListView.h create mode 100644 src/Qtx/QtxTreeView.cxx create mode 100644 src/Qtx/QtxTreeView.h diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 4479b8732..03d68f1f8 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -46,6 +46,7 @@ salomeinclude_HEADERS= \ QtxGroupBox.h \ QtxIntSpinBox.h \ QtxListAction.h \ + QtxTreeView.h \ QtxLogoMgr.h \ QtxMainWindow.h \ QtxMap.h \ @@ -71,7 +72,6 @@ salomeinclude_HEADERS= \ #VSR: not yet migrated to Qt4 files # \ QtxListBox.h \ - QtxListView.h \ QtxTable.h # Libraries targets @@ -99,6 +99,7 @@ dist_libqtx_la_SOURCES= \ QtxGroupBox.cxx \ QtxIntSpinBox.cxx \ QtxListAction.cxx \ + QtxTreeView.cxx \ QtxLogoMgr.cxx \ QtxMainWindow.cxx \ QtxMenu.cxx \ @@ -123,7 +124,6 @@ dist_libqtx_la_SOURCES= \ #VSR: not yet migrated to Qt4 files # \ QtxListBox.cxx \ - QtxListView.cxx \ QtxTable.cxx #VSR: already migrated to Qt4 files @@ -145,6 +145,7 @@ MOC_FILES= \ QtxGroupBox_moc.cxx \ QtxIntSpinBox_moc.cxx \ QtxListAction_moc.cxx \ + QtxTreeView_moc.cxx \ QtxLogoMgr_moc.cxx \ QtxMainWindow_moc.cxx \ QtxMenu_moc.cxx \ @@ -167,7 +168,6 @@ MOC_FILES= \ #VSR: not yet migrated to Qt4 files # \ QtxListBox_moc.cxx \ - QtxListView_moc.cxx \ QtxTable_moc.cxx nodist_libqtx_la_SOURCES= $(MOC_FILES) diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index 845e28c13..a96420ce6 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -88,6 +88,11 @@ public: PT_Directory //!< the directory path is required } PathType; + //! Custom data roles + enum { + AppropriateRole = Qt::UserRole + 100 //!< can be used to return \c true if data is appropriate + }; + static QString toQString( const char*, const int = -1 ); static QString toQString( const short*, const int = -1 ); static QString toQString( const unsigned char*, const int = -1 ); diff --git a/src/Qtx/QtxListView.cxx b/src/Qtx/QtxListView.cxx deleted file mode 100755 index 9abe06497..000000000 --- a/src/Qtx/QtxListView.cxx +++ /dev/null @@ -1,424 +0,0 @@ -// 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: QtxListView.cxx -// Author: Sergey TELKOV - -#include "QtxListView.h" - -#include -#include -#include - -static const char* list_xpm[] = { -"16 16 6 1", -". c None", -"a c #E3E9EB", -"b c #798391", -"c c #EBEBEB", -"d c #ABB4BE", -"e c #030E1F", -"................", -"................", -"................", -"...aaaaaaaaaa...", -"..abbbbbbbbbbe..", -"..abecbecbecbe..", -"..abbbbbbbbbbe..", -"..abecbecbecbe..", -"..abecaaaaaaaa..", -"..abeccdbbbbbb..", -"..abecccdbbbbe..", -"..abbbbe.dbbe...", -"...eeeee..de....", -"................", -"................", -"................" }; - -/*! - Constructor -*/ -QtxListView::QtxListView( const int state, QWidget* parent, const char* name, WFlags f ) -: QListView( parent, name, f ), -myButton( 0 ), -myHeaderState( state ) -{ - initialize(); -} - -/*! - Constructor -*/ -QtxListView::QtxListView( QWidget* parent, const char* name, WFlags f ) -: QListView( parent, name, f ), -myButton( 0 ), -myHeaderState( HeaderAuto ) -{ - initialize(); -} - -/*! - Initialization -*/ -void QtxListView::initialize() -{ - if ( myHeaderState == HeaderButton ) - { - QPixmap p( list_xpm ); - - QPushButton* but = new QPushButton( this ); - but->setDefault( false ); - but->setFlat( true ); - but->setIconSet( p ); - but->setBackgroundPixmap( p ); - if ( p.mask() ) - but->setMask( *p.mask() ); - myButton = but; - - connect( myButton, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - } - else - { - header()->installEventFilter( this ); - } - - myPopup = new QPopupMenu( this ); - connect( myPopup, SIGNAL( activated( int ) ), this, SLOT( onShowHide( int ) ) ); - connect( header(), SIGNAL( sizeChange( int, int, int ) ), this, SLOT( onHeaderResized() ) ); -} - -/*! - Destructor -*/ -QtxListView::~QtxListView() -{ -} - -/*! - Add new column - \param label - column title - \param width - column width -*/ -int QtxListView::addColumn( const QString& label, int width ) -{ - int res = QListView::addColumn( label, width ); - for ( int i = myAppropriate.count(); i <= res; i++ ) - myAppropriate.append( 1 ); - onHeaderResized(); - return res; -} - -/*! - Add new column - \param iconset - column icon - \param label - column title - \param width - column width -*/ -int QtxListView::addColumn( const QIconSet& iconset, const QString& label, int width ) -{ - int res = QListView::addColumn( iconset, label, width ); - for ( int i = myAppropriate.count(); i <= res; i++ ) - myAppropriate.append( 1 ); - onHeaderResized(); - return res; -} - -/*! - Removes column - \param index - column index -*/ -void QtxListView::removeColumn( int index ) -{ - QListView::removeColumn( index ); - if ( index >= 0 && index < (int)myAppropriate.count() ) - myAppropriate.remove( myAppropriate.at( index ) ); - onHeaderResized(); -} - -/*! - \return true if column is situated in popup for show/hide columns -*/ -bool QtxListView::appropriate( const int index ) const -{ - return index >= 0 && index < (int)myAppropriate.count() && myAppropriate[index]; -} - -/*! - Sets appropriate state: whether column is situated in popup for show/hide columns - \param index - column index - \param on - new state -*/ -void QtxListView::setAppropriate( const int index, const bool on ) -{ - if ( index < 0 || index >= (int)myAppropriate.count() ) - return; - - myAppropriate[index] = on ? 1 : 0; -} - -/*! - Resizes list view and header -*/ -void QtxListView::resize( int w, int h ) -{ - QListView::resize( w, h ); - onHeaderResized(); -} - -/*! - Shows list view -*/ -void QtxListView::show() -{ - QListView::show(); - onHeaderResized(); -} - -/*! - Update on resize contents -*/ -void QtxListView::resizeContents( int w, int h ) -{ -/* - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - { - if ( header()->orientation() == Qt::Horizontal ) - w += myButton->width(); - else - h += myButton->width(); - } -*/ - QListView::resizeContents( w, h ); - - onHeaderResized(); -} - -/*! - Shows column - \param ind - column index -*/ -void QtxListView::show( int ind ) -{ - setShown( ind, true ); -} - -/*! - Hides column - \param ind - column index -*/ -void QtxListView::hide( int ind ) -{ - setShown( ind, false ); -} - -/*! - \return true if column is shown - \param ind - column index -*/ -bool QtxListView::isShown( int ind ) const -{ - if ( ind>=0 && indcount() ) - return columnWidth( ind ) > 0 || header()->isResizeEnabled( ind ); - else - return false; -} - -/*! - Shows/hides column - \param ind - column index - \param sh - new is shown state -*/ -void QtxListView::setShown( int ind, bool sh ) -{ - if( ind<0 || ind>=header()->count() || isShown( ind )==sh ) - return; - - ColumnData& data = myColumns[ind]; - if ( sh ) - { - int w = data.width; - bool resizeable = data.resizeable; - myColumns.remove( ind ); - - setColumnWidth( ind, w ); - header()->setResizeEnabled( resizeable, ind ); - } - else - { - int w = columnWidth( ind ); - bool r = header()->isResizeEnabled( ind ); - setColumnWidth( ind, 0 ); - header()->setResizeEnabled( false, ind ); - data.width = w; - data.resizeable = r; - } - updateContents(); -} - -/*! - Changes column width - \param c - column index - \param w - new width -*/ -void QtxListView::setColumnWidth( int c, int w ) -{ - if ( myColumns.contains( c ) ) - myColumns[c].width = w; - - QListView::setColumnWidth( c, !myColumns.contains( c ) ? w : 0 ); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxListView::sizeHint() const -{ - QSize sz = QListView::sizeHint(); - - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - sz.setWidth( sz.width() + 2 + myButton->width() ); - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxListView::minimumSizeHint() const -{ - QSize sz = QListView::minimumSizeHint(); - - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - sz.setWidth( sz.width() + 2 + myButton->width() ); - - return sz; -} - -/*! - SLOT: called if header is resized -*/ -void QtxListView::onHeaderResized() -{ - if ( myHeaderState == HeaderAuto ) - { - int c = 0; - for ( int i = 0; i < columns(); i++ ) - { - if ( !header()->label( i ).isEmpty() || - ( header()->iconSet( i ) && !header()->iconSet( i )->isNull() ) ) - c++; - } - - if ( c > 1 ) - header()->show(); - else - header()->hide(); - } - - if ( !myButton || !header()->isVisibleTo( this ) ) - return; - - int lw = lineWidth(); - int h = header()->size().height() - 1; - myButton->setFixedSize( h, h ); - - int x = header()->headerWidth() - header()->offset() + 2; - if ( x < header()->width() - h ) - x = header()->width() - h; - - if ( myHeaderState == HeaderButton ) - { - if ( header()->orientation() == Qt::Horizontal ) - myButton->move( lw+x, lw ); - else - myButton->move( lw, lw+x ); - } -} - -/*! - Shows popup filled with column names to show/hide column - \param x, y - position of popup -*/ -void QtxListView::showPopup( const int x, const int y ) -{ - myPopup->clear(); - for ( int i = 0; i < columns(); i++ ) - { - if ( appropriate( i ) ) - { - int id = myPopup->insertItem( header()->label( i ), i ); - myPopup->setItemChecked( id, isShown( i ) ); - } - } - - if( myPopup->count() ) - myPopup->exec( mapToGlobal( QPoint( x, y ) ) ); -} - -/*! - SLOT: shows popup on button ".." click -*/ -void QtxListView::onButtonClicked() -{ - if ( myHeaderState != HeaderButton ) - return; - - int x = myButton->x(), - y = myButton->y() + myButton->height(); - - showPopup( x, y ); -} - -/*! - SLOT: called on popup action is activated, toggles shown state of column - \param id - column index -*/ -void QtxListView::onShowHide( int id ) -{ - //if ( myHeaderState != HeaderButton ) - // return; - - setShown( id, !isShown( id ) ); -} - -/*! - Receives all resize events sent to the viewport -*/ -void QtxListView::viewportResizeEvent( QResizeEvent* e ) -{ - QListView::viewportResizeEvent( e ); - onHeaderResized(); -} - -/*! - Custom event filter, shows popup on right button click -*/ -bool QtxListView::eventFilter( QObject* o, QEvent* e ) -{ - if( o==header() && e->type()==QEvent::MouseButtonPress ) - { - QMouseEvent* me = ( QMouseEvent* )e; - if( me->button()==Qt::RightButton ) - { - showPopup( me->x()+2, me->y()+2 ); - return true; - } - } - - return QListView::eventFilter( o, e ); -} diff --git a/src/Qtx/QtxListView.h b/src/Qtx/QtxListView.h deleted file mode 100755 index f79411249..000000000 --- a/src/Qtx/QtxListView.h +++ /dev/null @@ -1,103 +0,0 @@ -// 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: QtxListView.h -// Author: Sergey TELKOV - -#ifndef QTXLISTVIEW_H -#define QTXLISTVIEW_H - -#include "Qtx.h" - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -#include -#include - -class QButton; -class QPopupMenu; - -class QTX_EXPORT QtxListView : public QListView -{ - Q_OBJECT - -public: - enum { HeaderAuto, HeaderButton, NoHeaderButton }; - -public: - QtxListView( QWidget* = 0, const char* = 0, WFlags = 0 ); - QtxListView( const int, QWidget* = 0, const char* = 0, WFlags = 0 ); - virtual ~QtxListView(); - - virtual int addColumn( const QString&, int = -1 ); - virtual int addColumn( const QIconSet&, const QString&, int width = -1 ); - - virtual void removeColumn( int ); - - virtual void resize( int, int ); - - void show( int ); - void hide( int ); - - bool isShown( int ) const; - void setShown( int, bool ); - - bool appropriate( const int ) const; - virtual void setAppropriate( const int, const bool ); - - virtual void setColumnWidth( int, int ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - -public slots: - virtual void show(); - virtual void resizeContents( int, int ); - -protected slots: - void onHeaderResized(); - void onButtonClicked(); - void onShowHide( int ); - -protected: - virtual void viewportResizeEvent( QResizeEvent* ); - virtual bool eventFilter( QObject*, QEvent* ); - virtual void showPopup( const int x, const int y ); - -private: - typedef struct { int width; bool resizeable; } ColumnData; - typedef QMap ColumnsMap; - -private: - void initialize(); - -private: - QPopupMenu* myPopup; - QButton* myButton; - ColumnsMap myColumns; - QIntList myAppropriate; - int myHeaderState; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx new file mode 100644 index 000000000..3199ed645 --- /dev/null +++ b/src/Qtx/QtxTreeView.cxx @@ -0,0 +1,135 @@ +// 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: QtxTreeView.cxx +// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "QtxTreeView.h" + +#include +#include +#include + +/*! + \class QtxTreeView::Header + \brief Custom tree view header class. + \internal +*/ + +class QtxTreeView::Header : public QHeaderView +{ +public: + Header( QWidget* parent = 0 ); + ~Header(); + +protected: + void contextMenuEvent( QContextMenuEvent* ); +}; + +/*! + \brief Constructor + \param parent parent widget + \internal +*/ +QtxTreeView::Header::Header( QWidget* parent ) +: QHeaderView( Qt::Horizontal, parent ) +{ +} + +/*! + \brief Destructor + \internal +*/ +QtxTreeView::Header::~Header() +{ +} + +/*! + \brief Customize context menu event. + \internal + + Shows popup menu with the list of the available columns allowing the user to + show/hide the specified column. + + \param e context menu event +*/ +void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) +{ + QMenu menu; + QMap actionMap; + for ( int i = 0; i < count(); i++ ) { + QString lab = model()->headerData( i, orientation(), Qt::DisplayRole ).toString(); + QVariant iconData = model()->headerData( i, orientation(), Qt::DecorationRole ); + QVariant appropriate = model()->headerData( i, orientation(), Qtx::AppropriateRole ); + QIcon icon; + if ( iconData.isValid() ) { + if ( qVariantCanConvert( iconData ) ) + icon = qVariantValue( iconData ); + else if ( qVariantCanConvert( iconData ) ) + icon = qVariantValue( iconData ); + } + if ( ( !lab.isEmpty() || !icon.isNull() ) && + appropriate.isValid() ? appropriate.toBool() : true ) { + QAction* a = menu.addAction( icon, lab ); + a->setCheckable( true ); + a->setChecked( !isSectionHidden( i ) ); + actionMap.insert( a, i ); + } + } + if ( !menu.isEmpty() ) { + QAction* a = menu.exec( e->globalPos() ); + if ( a && actionMap.contains( a ) ) + setSectionHidden( actionMap[ a ], !isSectionHidden( actionMap[ a ] ) ); + } + e->accept(); +} + +/*! + \class QtxTreeView + \brief Tree view class with possibility to display columns popup menu. + + The QtxTreeView class represents a customized tree view class. In addition to the + base functionality inherited from the QTreeView class, clicking at the tree view + header with the right mouse button displays the popup menu allowing the user + to show/hide specified columns. + + By default the popup menu contains items corresponding to all the tree view columns. + In order to disable some columns from being shown in the popup menu one may customize + the data model (see QAbstractItemModel class). The custom model should implement + headerData() method and return \c true for the Qtx::AppropriateRole role for + those columns which should be available in the popup menu and \c false for the columns + which should not be added to it. +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +QtxTreeView::QtxTreeView( QWidget* parent ) +: QTreeView( parent ) +{ + setHeader( new Header() ); +} + +/*! + \brief Destructor. +*/ +QtxTreeView::~QtxTreeView() +{ +} diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h new file mode 100644 index 000000000..6ee7a526a --- /dev/null +++ b/src/Qtx/QtxTreeView.h @@ -0,0 +1,49 @@ +// 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: QtxTreeView.h +// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef QTXTREEVIEW_H +#define QTXTREEVIEW_H + +#include "Qtx.h" + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include + +class QTX_EXPORT QtxTreeView : public QTreeView +{ + Q_OBJECT + + class Header; + +public: + QtxTreeView( QWidget* = 0 ); + virtual ~QtxTreeView(); +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif // QTXTREEVIEW_H -- 2.39.2