From: nds Date: Fri, 21 Sep 2007 12:48:08 +0000 (+0000) Subject: Porting on Qt4. X-Git-Tag: TG_Saint_Valentine-Day~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f7501b79fdabec51171bb4f83355c3c9b0c1e5fa;p=modules%2Fgui.git Porting on Qt4. --- diff --git a/src/Plot2d/Plot2d.pro b/src/Plot2d/Plot2d.pro new file mode 100644 index 000000000..12abe7b16 --- /dev/null +++ b/src/Plot2d/Plot2d.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib + +DESTDIR = ../../$(CONFIG_ID)/lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET + +PYTHONVER=2.4 +PYTHONHOME=$$(PYTHONHOME) +PYTHONINC=$${PYTHONHOME}/include/python$${PYTHONVER} + +QWTHOME=$$(QWTHOME) +QWTINC=$${QWTHOME}/include +QWTLIB=$${QWTHOME}/lib + +INCLUDEPATH += ../../include $${QWTINC} $${PYTHONINC} +INCLUDEPATH += ../Qtx ../SUIT +unix:LIBS += -L$${QWTLIB} -lqwt +win32:LIBS += /LIBPATH:$$(QWTLIB) +LIBS += -L../../$(CONFIG_ID)/lib -lQtx -lSUIT + +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += PLOT2D_EXPORTS + +HEADERS = *.h + +SOURCES = *.cxx + +TRANSLATIONS = resources/Plot2d_msg_en.ts \ + resources/Plot2d_images.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/Qtx/QtxActionSet.cxx b/src/Qtx/QtxActionSet.cxx index b25caad93..da8d7630d 100644 --- a/src/Qtx/QtxActionSet.cxx +++ b/src/Qtx/QtxActionSet.cxx @@ -21,6 +21,8 @@ #include "QtxActionSet.h" +#include + /*! \class QtxActionSet \brief An action class which is represented in the menu bar (or toolbar) as @@ -45,8 +47,6 @@ QtxActionSet::QtxActionSet( QObject* parent ) connect( this, SIGNAL( changed() ), this, SLOT( onChanged() ) ); setVisible( false ); - - update(); } /*! @@ -103,7 +103,7 @@ void QtxActionSet::insertActions( const QList& lst, const int index ) connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onActionTriggered( bool ) ) ); } - update(); + updateAction(); } /*! @@ -130,7 +130,9 @@ int QtxActionSet::insertAction( QAction* a, const int id, const int index ) connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onActionTriggered( bool ) ) ); - update(); + actionAdded( a ); + + updateAction(); return ident; } @@ -179,6 +181,7 @@ void QtxActionSet::removeAction( QAction* a ) return; mySet.removeAll( a ); + actionRemoved( a ); delete a; } @@ -204,7 +207,7 @@ void QtxActionSet::clear() qDeleteAll( mySet ); mySet.clear(); - update(); + updateAction(); } /*! @@ -214,6 +217,10 @@ void QtxActionSet::clear() */ void QtxActionSet::onChanged() { + QList lst = createdWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + (*it)->setEnabled( isEnabled() ); + if ( !isVisible() || !isEmptyAction() ) return; @@ -247,7 +254,7 @@ void QtxActionSet::addedTo( QWidget* w ) { QtxAction::addedTo( w ); - update( w ); + updateAction( w ); } /*! @@ -258,7 +265,7 @@ void QtxActionSet::removedFrom( QWidget* w ) { QtxAction::removedFrom( w ); - update( w ); + updateAction( w ); } /*! @@ -303,6 +310,20 @@ void QtxActionSet::setActionId( QAction* a, const int id ) a->setData( id ); } +/*! + \brief Notify that action was added +*/ +void QtxActionSet::actionAdded( QAction* ) +{ +} + +/*! + \brief Notify that action was removed +*/ +void QtxActionSet::actionRemoved( QAction* ) +{ +} + /*! \brief Getneration unique action identifier \return generation action ID @@ -323,18 +344,18 @@ int QtxActionSet::generateId() const /*! \brief Update action set. */ -void QtxActionSet::update() +void QtxActionSet::updateAction() { QList lst = associatedWidgets(); for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) - update( *it ); + updateAction( *it ); } /*! \brief Update action set for the specified widget. \param w a widget this action is added to */ -void QtxActionSet::update( QWidget* w ) +void QtxActionSet::updateAction( QWidget* w ) { if ( !w ) return; @@ -342,16 +363,29 @@ void QtxActionSet::update( QWidget* w ) for ( ActionList::iterator it = mySet.begin(); it != mySet.end(); ++it ) w->removeAction( *it ); - if ( !associatedWidgets().contains( w ) ) - return; - + QAction* first = 0; for ( int i = 0; i < mySet.count(); i++ ) { QAction* a = mySet.at( i ); + if ( !first ) + first = a; w->insertAction( this, a ); } + if ( first ) + { + QApplication::instance()->removeEventFilter( this ); + + w->insertAction( first, this ); + + QApplication::instance()->installEventFilter( this ); + } } +/*! + \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 QtxActionSet::isEmptyAction() const { return true; diff --git a/src/Qtx/QtxActionSet.h b/src/Qtx/QtxActionSet.h index 4de899787..652ae6c15 100644 --- a/src/Qtx/QtxActionSet.h +++ b/src/Qtx/QtxActionSet.h @@ -64,19 +64,23 @@ protected: virtual void addedTo( QWidget* ); virtual void removedFrom( QWidget* ); + virtual void actionAdded( QAction* ); + virtual void actionRemoved( QAction* ); + QAction* action( int ) const; int actionId( QAction* ) const; void setActionId( QAction*, const int ); virtual bool isEmptyAction() const; + virtual void updateAction(); + virtual void updateAction( QWidget* ); + private: - void update(); - void update( QWidget* ); int generateId() const; private: - typedef QList ActionList; + typedef QList ActionList; private: ActionList mySet; //!< actions list diff --git a/src/Qtx/QtxMultiAction.cxx b/src/Qtx/QtxMultiAction.cxx new file mode 100644 index 000000000..37b8f440a --- /dev/null +++ b/src/Qtx/QtxMultiAction.cxx @@ -0,0 +1,390 @@ +// 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: QtxMultiAction.cxx +// Author: Sergey TELKOV +// + +#include "QtxMultiAction.h" + +#include +#include +#include +#include +#include +#include +#include + +/*! + \class QtxMultiAction::Filter + \brief Waches for the buttons in the popup menu + to update the tool buttons state. + \internal +*/ + +class QtxMultiAction::Filter : public QObject +{ +public: + //! \brief Constructor + Filter( QObject* parent ) : QObject( parent ) {} + //! \brief Destructor + ~Filter() {} + //! \brief Process events from the child tool buttons + bool eventFilter( QObject* o, QEvent* e ) + { + if ( e->type() == QEvent::Leave ) { + QToolButton* tb = qobject_cast( o ); + if ( tb ) + tb->setDown( false ); + } + return QObject::eventFilter( o, e ); + } +}; + +/*! + \class QtxMultiAction::Button + \brief Custom button to be used in the toolbar. + \internal +*/ + +class QtxMultiAction::Button : public QToolButton +{ +public: + //! \brief Constructor + Button( QWidget* parent = 0 ) : QToolButton( parent ) {} + //! \brief Destructor + ~Button() {}; + +protected: + //! \brief Paint the button + virtual void paintEvent( QPaintEvent* e ) + { + QToolButton::paintEvent( e ); + + int s = 10; + int m = -2; + int w = width(); + int h = height(); + + QStyleOptionButton opt; + opt.initFrom( this ); + QRect rect = opt.rect; + int x = rect.x(), y = rect.y(); + if ( isDown() ) + opt.rect = QRect( x + w - s - m, y + h - s - m, s, s ); + else + opt.rect = QRect( x + w - s - m - 1, y + h - s - m - 1, s, s ); + + QPainter p( this ); + style()->drawPrimitive( QStyle::PE_IndicatorSpinDown, &opt, &p ); + } +}; + +/*! + \class QtxMultiAction + \brief The class QtxMultiAction implements modifiable action. + + The QtxMultiAction class provides a possibility to assign a set of actions + (insertAction() function). The action can be used in the toolbar (and even + in the menu) to show drop-down menu with the list of the assigned actions. + + Initially the first action from the list becomes current and it is activated + when the tool button is clicked by the user. If user presses and holds the mouse + button at the tool button, it shows the popup menu with all the assigned actions. + When the user selects any action from the popup menu, it becames current. +*/ + +/*! + \brief Constructor. + \param parent parent object +*/ +QtxMultiAction::QtxMultiAction( QObject* parent ) +: QtxActionSet( parent ), + myCurrent( 0 ) +{ + setVisible( true ); + setMenu( new QMenu( 0 ) ); + + connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) ); +} + +/*! + \brief Constructor. + \param txt action menu text + \param parent parent object +*/ +QtxMultiAction::QtxMultiAction( const QString& txt, QObject* parent ) +: QtxActionSet( parent ), + myCurrent( 0 ) +{ + setText( txt ); + setVisible( true ); + setMenu( new QMenu( 0 ) ); + + connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) ); +} + +/*! + \brief Constructor. + \param ico action menu icon + \param txt action menu text + \param parent parent object +*/ +QtxMultiAction::QtxMultiAction( const QIcon& ico, const QString& txt, QObject* parent ) +: QtxActionSet( parent ), + myCurrent( 0 ) +{ + setIcon( ico ); + setText( txt ); + setVisible( true ); + setMenu( new QMenu( 0 ) ); + + connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) ); +} + +/*! + \brief Destructor +*/ +QtxMultiAction::~QtxMultiAction() +{ +} + +/*! + \brief Set current action. + \param a action to be set current +*/ +void QtxMultiAction::setActiveAction( QAction* a ) +{ + if ( a && actions().contains( a ) && a != myCurrent && a->isEnabled() ) { + myCurrent = a; + updateAction(); + } +} + +/*! + \brief Get current action. + \return current action (0 if there is no active action) +*/ +QAction* QtxMultiAction::activeAction() const +{ + return myCurrent; +} + +/*! + \brief Called when the user activates the current action + (for example by clicking the tool button). + \param on (not used) +*/ +void QtxMultiAction::onClicked( bool /*on*/ ) +{ + if ( myCurrent ) + myCurrent->activate( QAction::Trigger ); +} + +/*! + \brief Called when user activates any action from the + dropdown menu. + \param a action being activated +*/ +void QtxMultiAction::onTriggered( QAction* a ) +{ + if ( !a ) + return; + + QList lst = createdWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + { + QToolButton* tb = ::qobject_cast( *it ); + if ( tb && tb->menu() ) + tb->menu()->hide(); + } + + if ( myCurrent != a ) + { + myCurrent = a; + updateAction(); + } +} + +/*! + \brief Update action. +*/ +void QtxMultiAction::updateAction() +{ + QtxActionSet::updateAction(); + + QList lst = createdWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + updateButton( ::qobject_cast( *it ) ); +} + +/*! + \brief Update child (popup menu) action. + \param w widget menu widget +*/ +void QtxMultiAction::updateAction( QWidget* w ) +{ + if ( !w ) + return; + + if ( w->inherits( "QMenu" ) ) + { + QtxActionSet::updateAction( menu() ); + + QApplication::instance()->removeEventFilter( this ); + + menu()->removeAction( this ); + + QApplication::instance()->installEventFilter( this ); + } +} + +/*! + \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 QtxMultiAction::isEmptyAction() const +{ + return false; +} + +/*! + \brief Create widget to be displayed in the toolbar. + \param parent parent widget (should be toolbar) + \return toolbar button +*/ +QWidget* QtxMultiAction::createWidget( QWidget* parent ) +{ + QToolBar* tb = ::qobject_cast( parent ); + if ( !tb ) + return 0; + + QToolButton* w = new Button( tb ); + w->setMenu( new QMenu( w ) ); + w->setFocusPolicy( Qt::NoFocus ); + w->setIconSize( tb->iconSize() ); + w->setToolButtonStyle( tb->toolButtonStyle() ); + + connect( w, SIGNAL( clicked( bool ) ), this, SLOT( onClicked( bool ) ) ); + connect( tb, SIGNAL( iconSizeChanged( const QSize& ) ), w, SLOT( setIconSize( QSize ) ) ); + connect( tb, SIGNAL( toolButtonStyleChanged( Qt::ToolButtonStyle ) ), + w, SLOT( setToolButtonStyle( Qt::ToolButtonStyle ) ) ); + + updateButton( w ); + return w; +} + +/*! + \brief Called when the child action is added to this action. + \param a child action being added +*/ +void QtxMultiAction::actionAdded( QAction* a ) +{ + connect( a, SIGNAL( changed() ), this, SLOT( onActionChanged() ) ); + onActionChanged(); +} + +/*! + \brief Called when the child action is removed from this action. + \param a child action being removed +*/ +void QtxMultiAction::actionRemoved( QAction* a ) +{ + disconnect( a, SIGNAL( changed() ), this, SLOT( onActionChanged() ) ); + + if ( myCurrent != a ) + return; + + myCurrent = 0; + + onActionChanged(); + + updateAction(); +} + +/*! + \brief Update toolbar button. + \param btn toolbar button +*/ +void QtxMultiAction::updateButton( QToolButton* btn ) +{ + if ( !btn ) + return; + + btn->setIcon( myCurrent ? myCurrent->icon() : QIcon() ); + btn->setText( myCurrent ? myCurrent->text() : QString() ); + btn->setToolTip( myCurrent ? myCurrent->toolTip() : QString() ); + btn->setStatusTip( myCurrent ? myCurrent->statusTip() : QString() ); + + QMenu* pm = btn->menu(); + if ( !pm ) + return; + + pm->clear(); + for ( int i = 0; pm->layout() && i < pm->layout()->count(); i++ ) + delete pm->layout()->widget(); + + delete pm->layout(); + + QVBoxLayout* vbox = new QVBoxLayout( pm ); + vbox->setMargin( 1 ); + vbox->setSpacing( 0 ); + Filter* filter = new Filter( vbox ); + QList actList = actions(); + for ( QList::iterator itr = actList.begin(); itr != actList.end(); ++itr ) + { + QToolButton* b = new QToolButton( pm ); + b->setDefaultAction( *itr ); + b->setToolTip( (*itr)->toolTip() ); + b->setAutoRaise( true ); + b->setIconSize( btn->iconSize() ); + b->setToolButtonStyle( btn->toolButtonStyle() ); + b->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + b->installEventFilter( filter ); + vbox->addWidget( b ); + } +} + +/*! + \brief Called when any child action is enabled/disabled. + + If the current action is disabled, the multi-action switches + to first found enabled. If all child actions are disabled, the + action itself is also disabled. +*/ +void QtxMultiAction::onActionChanged() +{ + if ( myCurrent && myCurrent->isEnabled() ) + return; + + QList alist = actions(); + QAction* a = 0; + for ( QList::ConstIterator it = alist.begin(); it != alist.end() && !a; ++it ) { + if ( (*it)->isEnabled() ) + a = *it; + } + + if ( a ) + myCurrent = a; + else + myCurrent = alist.isEmpty() ? 0 : alist.first(); + + setEnabled( myCurrent && myCurrent->isEnabled() ); + updateAction(); +} diff --git a/src/Qtx/QtxMultiAction.h b/src/Qtx/QtxMultiAction.h new file mode 100644 index 000000000..07bb3e062 --- /dev/null +++ b/src/Qtx/QtxMultiAction.h @@ -0,0 +1,68 @@ +// 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: QtxMultiAction.h +// Author: Sergey TELKOV +// + +#ifndef QTXMULTIACTION_H +#define QTXMULTIACTION_H + +#include "QtxActionSet.h" + +class QToolButton; + +class QTX_EXPORT QtxMultiAction : public QtxActionSet +{ + Q_OBJECT + + class Button; + class Filter; + +public: + QtxMultiAction( QObject* parent = 0 ); + QtxMultiAction( const QString&, QObject* parent = 0 ); + QtxMultiAction( const QIcon&, const QString&, QObject* parent = 0 ); + virtual ~QtxMultiAction(); + + void setActiveAction( QAction* ); + QAction* activeAction() const; + +private slots: + void onClicked( bool ); + void onTriggered( QAction* ); + void onActionChanged(); + +protected: + virtual bool isEmptyAction() const; + virtual QWidget* createWidget( QWidget* ); + + virtual void updateAction(); + virtual void updateAction( QWidget* ); + + virtual void actionAdded( QAction* ); + virtual void actionRemoved( QAction* ); + +private: + void updateButton( QToolButton* ); + +private: + QAction* myCurrent; +}; + +#endif // QTXMULTIACTION_H diff --git a/src/Qtx/QtxTable.cxx b/src/Qtx/QtxTable.cxx new file mode 100644 index 000000000..01fec0d9b --- /dev/null +++ b/src/Qtx/QtxTable.cxx @@ -0,0 +1,1871 @@ +// 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: QtxTable.cxx +// Author: Sergey TELKOV + +#include "QtxTable.h" + +#ifndef QT_NO_TABLE + +//#include "QtxStyleWrap.h" + +#include +#include +#include +#include +//#include +#include +//#include +#include +#include +#include +#include +//#include + +/*! + Class QtxTable::Header + Internal header for QtxTable +*/ + +/*class QtxTable::Header : public QHeaderView +{ +public: + Header( int, QtxTable*, const char* = 0 ); + virtual ~Header(); + + QtxTable* table() const; + + void clear(); + + QColor foregroundColor( const int ) const; + QColor backgroundColor( const int ) const; + void setForegroundColor( const int, const QColor& ); + void setBackgroundColor( const int, const QColor& ); + + void removeSection( const int ); + virtual void setLabel( int, const QString&, int = -1 ); + + QRect indexRect( const int, int* = 0 ); + void swapSections( const int, const int ); + int spanedSection( const int index ); + + virtual QSize sizeHint() const; + +protected: + virtual void mouseMoveEvent( QMouseEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + virtual void mouseReleaseEvent( QMouseEvent* ); + virtual void paintSection( QPainter*, int, const QRect& ); + virtual void paintEvent( QPaintEvent * ); + +private: + typedef QMap ColorMap; + +private: + QHeaderView* mainHeader() const; + bool filterEvent( QMouseEvent* ); + + QPoint sectionCenter( const int, const QPoint& = QPoint() ) const; + +private: + QtxTable* myTable; + ColorMap myFgColor; + ColorMap myBgColor; + int myPressed; + int mySection; + friend class QtxTable::StyleItem; +}; + +QtxTable::Header::Header( int n, QtxTable* table, const char* name ) +: QHeaderView( n, table, name ), +myTable( table ), +myPressed( -1 ), +mySection( -1 ) +{ + setWFlags( WRepaintNoErase ); +} + +QtxTable::Header::~Header() +{ +} + +QtxTable* QtxTable::Header::table() const +{ + return myTable; +} + +void QtxTable::Header::clear() +{ + for ( int i = 0; i < (int)count(); i++ ) + setLabel( i, orientation() == Qt::Horizontal ? QString( "" ) : QString::null ); + myFgColor.clear(); + myBgColor.clear(); +} + +QSize QtxTable::Header::sizeHint() const +{ + QSize sz = QHeaderView::sizeHint(); + + int size = orientation() == Qt::Horizontal ? sz.height() : sz.width(); + + for ( int i = 0; i < (int)count(); i++ ) + { + QString lab = label( mapToSection( i ) ); + if ( !QStyleSheet::mightBeRichText( lab ) ) + continue; + + int s = 0; + QIconSet* icon = iconSet( mapToSection( i ) ); + if ( icon ) + { + QPixmap pixmap = icon->pixmap( QIconSet::Small, QIconSet::Normal ); + s = orientation() == Qt::Horizontal ? pixmap.height() : pixmap.width(); + } + + QStyleSheet sheet; + QStyleSheetItem* item = sheet.item( "p" ); + if ( item ) + { + item->setMargin( QStyleSheetItem::MarginAll, 0 ); + item->setWhiteSpaceMode( QStyleSheetItem::WhiteSpaceNoWrap ); + } + + QSimpleRichText rt( QString( "

%1

" ).arg( lab ), font(), QString::null, &sheet ); + if ( orientation() == Qt::Horizontal ) + rt.setWidth( sectionSize( mapToSection( i ) ) ); + s += orientation() == Qt::Horizontal ? rt.height() : rt.width(); + + size = QMAX( size, s ); + } + + if ( orientation() == Qt::Horizontal ) + sz.setHeight( size ); + else + sz.setWidth( size ); + + return sz; +} + +void QtxTable::Header::removeSection( const int section ) +{ + int old = count(); + + removeLabel( section ); + + if ( old == count() ) + return; + + ColorMap newFMap, newBMap; + for ( ColorMap::ConstIterator fIt = myFgColor.begin(); fIt != myFgColor.end(); ++fIt ) + { + if ( fIt.key() == section ) + continue; + newFMap.insert( fIt.key() < section ? fIt.key() : fIt.key() - 1, fIt.data() ); + } + myFgColor = newFMap; + + for ( ColorMap::ConstIterator bIt = myBgColor.begin(); bIt != myBgColor.end(); ++bIt ) + { + if ( bIt.key() == section ) + continue; + newBMap.insert( bIt.key() < section ? bIt.key() : bIt.key() - 1, bIt.data() ); + } + myBgColor = newBMap; +} + +void QtxTable::Header::setLabel( int section, const QString& s, int size ) +{ + QHeaderView::setLabel( section, s, size ); + if ( table() && isUpdatesEnabled() ) + table()->updateHeaderGeometries( orientation() ); +} + +QColor QtxTable::Header::foregroundColor( const int section ) const +{ + return myFgColor.contains( section ) ? myFgColor[section] : QColor(); +} + +QColor QtxTable::Header::backgroundColor( const int section ) const +{ + return myBgColor.contains( section ) ? myBgColor[section] : QColor(); +} + +void QtxTable::Header::setForegroundColor( const int section, const QColor& c ) +{ + if ( foregroundColor( section ) == c ) + return; + + myFgColor.insert( section, c ); + if ( isUpdatesEnabled() ) + repaint( indexRect( mapToIndex( section ) ) ); +} + +void QtxTable::Header::setBackgroundColor( const int section, const QColor& c ) +{ + if ( backgroundColor( section ) == c ) + return; + + myBgColor.insert( section, c ); + if ( isUpdatesEnabled() ) + repaint( indexRect( mapToIndex( section ) ) ); +} + +void QtxTable::Header::swapSections( const int oldIdx, const int newIdx ) +{ + QIconSet oldIconSet, newIconSet; + if ( iconSet( oldIdx ) ) + oldIconSet = *iconSet( oldIdx ); + if ( iconSet( newIdx ) ) + newIconSet = *iconSet( newIdx ); + QString oldLabel = label( oldIdx ); + QString newLabel = label( newIdx ); + QHeaderView::setLabel( oldIdx, newIconSet, newLabel ); + QHeaderView::setLabel( newIdx, oldIconSet, oldLabel ); + + QColor oldFg = foregroundColor( oldIdx ); + QColor newFg = foregroundColor( newIdx ); + setForegroundColor( oldIdx, newFg ); + setForegroundColor( newIdx, oldFg ); + + QColor oldBg = backgroundColor( oldIdx ); + QColor newBg = backgroundColor( newIdx ); + setBackgroundColor( oldIdx, newBg ); + setBackgroundColor( newIdx, oldBg ); +} + +void QtxTable::Header::mouseMoveEvent( QMouseEvent* e ) +{ + if ( e->button() == NoButton && filterEvent( e ) ) + return; + + QHeaderView::mouseMoveEvent( e ); + if ( mainHeader() ) + QApplication::sendEvent( mainHeader(), e ); +} + +void QtxTable::Header::mousePressEvent( QMouseEvent* e ) +{ + if ( filterEvent( e ) ) + return; + + int index = mapToIndex( sectionAt( ( orientation() == Horizontal ? e->pos().x() : e->pos().y() ) + offset() ) ); + SpanRange range = findSpanRange( index ); + + bool shift = e->state() & ShiftButton; + if ( mainHeader() ) + QApplication::sendEvent( mainHeader(), e ); + + for ( int i = range.second; i >= range.first && !shift; i-- ) + { + QPoint pos = sectionCenter( i, e->pos() ); + QMouseEvent me( e->type(), pos, e->button(), e->state() | ControlButton ); + if ( i == range.first ) + QHeaderView::mousePressEvent( &me ); + if ( mainHeader() ) + QApplication::sendEvent( mainHeader(), &me ); + } + + if ( !shift ) + { + QMouseEvent me( e->type(), sectionCenter( index, e->pos() ), e->button(), e->state() | ControlButton ); + if ( mainHeader() ) + QApplication::sendEvent( mainHeader(), &me ); + } + + myPressed = range.first; + repaint( indexRect( range.first ) ); +} + +void QtxTable::Header::mouseReleaseEvent( QMouseEvent* e ) +{ + QHeaderView::mouseReleaseEvent( e ); + if ( mainHeader() ) + QApplication::sendEvent( mainHeader(), e ); + + repaint( indexRect( myPressed ) ); + myPressed = -1; +} + +void QtxTable::Header::paintSection( QPainter* p, int index, const QRect& fr ) +{ + int idx = index; + QRect r = fr; + if ( index < count() ) + r = indexRect( index, &idx ); + + // Currently painted section number. This number will be used in the drawing style. + // Because QHeaderView::paintSection() implementation doesn't send section id through style options :( + mySection = mapToSection( index ); + + QHeaderView::paintSection( p, idx, r ); + + mySection = -1; +} + +void QtxTable::Header::paintEvent( QPaintEvent *pe ) +{ + QRect r = rect(); + QPixmap pix( r.width(), r.height() ); + QPainter::redirect( this, &pix ); + QHeaderView::paintEvent( pe ); + QPainter::redirect( this, 0 ); + QPainter painter( this ); + painter.drawPixmap( r, pix ); + //QHeaderView::paintEvent( pe ); +} + +bool QtxTable::Header::filterEvent( QMouseEvent* e ) +{ + int c = orientation() == Qt::Horizontal ? e->pos().x() : e->pos().y(); + c += offset(); +/* + if ( reverse() ) + c = d->lastPos - c; +*+/ + int section = sectionAt( c ); + if ( section < 0 ) + return false; + + int handleIdx = -1; + int margin = style().pixelMetric( QStyle::PM_HeaderGripMargin ); + int index = mapToIndex( section ); + + QRect r = sectionRect( section ); + int size = sectionSize( section ); + int pos = ( orientation() == Qt::Horizontal ? r.x() : r.y() ) + offset(); + if ( c < pos + margin ) + handleIdx = index - 1; + else if ( c > pos + size - margin ) + handleIdx = index; + + if ( handleIdx == -1 ) + return false; + + return findSpanRange( handleIdx ).second != handleIdx; +} + +QPoint QtxTable::Header::sectionCenter( const int index, const QPoint& p ) const +{ + QPoint pos = p; + if ( orientation() == Qt::Horizontal ) + pos.setX( sectionPos( mapToSection( index ) ) + sectionSize( mapToSection( index ) ) / 2 - offset() ); + else + pos.setY( sectionPos( mapToSection( index ) ) + sectionSize( mapToSection( index ) ) / 2 - offset() ); + + if ( p.isNull() ) + { + if ( orientation() == Qt::Horizontal ) + pos.setY( height() / 2 ); + else + pos.setX( width() / 2 ); + } + return pos; +} + +QtxTable::Header::SpanRange QtxTable::Header::findSpanRange( const int index ) +{ + SpanRange res( index, index ); + if ( mySpanRanges.isEmpty() ) + { + // no span sections and no first simple sections stored in map + // so we have to fill it. + for ( int i = 0; i < (int)count(); i++ ) + { + int sp = horizontalSpan( mapToSection( i ) ); + sp = QMAX( sp, 1 ); + SpanRange range( i, QMIN( i + sp - 1, count() - 1 ) ); + if ( range.first == range.second && !mySpanRanges.isEmpty() ) + continue; // do not store simple section without span (store only first) + mySpanRanges.insert( i, range ); + for ( int j = i + 1; j < i + sp; j++ ) + mySpanRanges.insert( j, range ); + i += sp - 1; + } + } + + if ( mySpanRanges.contains( index ) ) + res = mySpanRanges[ index ]; + + + /* try to optimise by checking range during step from one to next + SpanRangeList ranges; + spanRanges( ranges ); + + for ( SpanRangeList::const_iterator it = ranges.begin(); it != ranges.end() && res.first < 0; ++it ) + { + if ( (*it).first <= index && index <= (*it).second ) + res = *it; + } + *+/ + for ( int i = 0; i < (int)count() && res.first < 0; i++ ) + { + int sp = horizontalSpan( mapToSection( i ) ); + sp = QMAX( sp, 1 ); + SpanRange range( i, QMIN( i + sp - 1, count() - 1 ) ); + if ( range.first <= index && index <= range.second ) + res = range; + i += sp - 1; + } + return res; +} + +QRect QtxTable::Header::indexRect( const int index, int* start ) +{ + SpanRange range = findSpanRange( index ); + + if ( start ) + *start = range.first; + + QRect r; + for ( int i = range.first; i <= range.second; i++ ) + r = r.unite( sRect( i ) ); + return r; +} + +int QtxTable::Header::spanedSection( const int index ) +{ + SpanRange range = findSpanRange( index ); + return range.first; +} + +QHeaderView* QtxTable::Header::mainHeader() const +{ + if ( !table() ) + return 0; + + return orientation() == Qt::Horizontal ? table()->horizontalHeader() : + table()->verticalHeader(); +} +*/ +/*! + Class QtxTable::StyleItem +*/ +/* +class QtxTable::StyleItem : public QtxStyleWrapItem +{ +public: + StyleItem( QtxStyleWrap* ); + ~StyleItem(); + virtual bool drawControl( QStyle::ControlElement, QPainter*, const QWidget*, const QRect&, + const QColorGroup&, QStyle::SFlags, const QStyleOption& ) const; + virtual bool drawPrimitive( QStyle::PrimitiveElement, QPainter*, const QRect&, + const QColorGroup&, QStyle::SFlags, const QStyleOption& ) const; +}; + +QtxTable::StyleItem::StyleItem( QtxStyleWrap* wrap ) +: QtxStyleWrapItem( wrap ) +{ +} + +QtxTable::StyleItem::~StyleItem() +{ +} + +bool QtxTable::StyleItem::drawControl( QStyle::ControlElement element, QPainter* p, const QWidget* widget, + const QRect& r, const QColorGroup& cg, QStyle::SFlags flags, + const QStyleOption& opt ) const +{ + if ( element != QStyle::CE_HeaderLabel ) + return false; + + const QHeaderView* header = (const QHeaderView*)widget; + int section = opt.headerSection(); + + QColor fc; + QTableWidget* table = ::qobject_cast( header->parent() ); + if ( table && table->verticalHeader() != header && table->horizontalHeader() != header ) + fc = ((Header*)header)->foregroundColor( section ); + + QColorGroup grp( cg ); + if ( fc.isValid() ) + grp.setColor( QColorGroup::ButtonText, fc ); + grp.setColor( QColorGroup::Text, grp.buttonText() ); + + QString lab = header->label( section ); + if ( !QStyleSheet::mightBeRichText( lab ) ) + { + if ( style() ) + style()->drawControl( element, p, widget, r, grp, flags, opt ); + } + else + { + QRect rect = r; + QIconSet* icon = header->iconSet( section ); + if ( icon ) + { + QPixmap pixmap = icon->pixmap( QIconSet::Small, flags & QStyle::Style_Enabled ? QIconSet::Normal : + QIconSet::Disabled ); + int pixw = pixmap.width(); + int pixh = pixmap.height(); + + QRect pixRect = rect; + pixRect.setY( rect.center().y() - (pixh - 1) / 2 ); + if ( style() ) + style()->drawItem( p, pixRect, AlignVCenter, cg, flags & QStyle::Style_Enabled, &pixmap, QString::null ); + rect.setLeft( rect.left() + pixw + 2 ); + } + + QStyleSheet sheet; + QStyleSheetItem* i = sheet.item( "p" ); + if ( i ) + { + i->setMargin( QStyleSheetItem::MarginAll, 0 ); + i->setWhiteSpaceMode( QStyleSheetItem::WhiteSpaceNoWrap ); + } + + QSimpleRichText rt( QString( "

%1

" ).arg( lab ), header->font(), QString::null, &sheet ); + rt.setWidth( rect.width() ); + rt.draw( p, rect.x(), rect.y() + ( rect.height() - rt.height() ) / 2, rect, grp ); + } + + return true; +} + +bool QtxTable::StyleItem::drawPrimitive( QStyle::PrimitiveElement pe, QPainter* p, const QRect& r, + const QColorGroup& cg, QStyle::SFlags flags, const QStyleOption& opt ) const +{ + if ( pe != QStyle::PE_HeaderSection ) + return false; + + if ( opt.isDefault() ) + return false; + + QHeaderView* hdr = ::qobject_cast( opt.widget() ); + if ( !hdr ) + return false; + + QTableWidget* table = ::qobject_cast( hdr->parent() ); + if ( table && ( table->verticalHeader() == hdr || table->horizontalHeader() == hdr ) ) + return false; + + Header* h = (Header*)hdr; + int section = h->mySection; + + if ( section < 0 ) + return false; + + QColorGroup grp( cg ); + QColor c = h->backgroundColor( section ); + if ( c.isValid() ) + { + grp.setColor( QColorGroup::Button, c ); + grp.setColor( QColorGroup::Light, c ); + } + if ( style() ) + style()->drawPrimitive( pe, p, r, grp, flags, opt ); + + return true; +} +*/ +/*! + Class QtxTable +*/ + +/*! + Constructor +*/ +QtxTable::QtxTable( QWidget* parent, const char* name ) + : QTableWidget( parent )//, + //myStyleWrapper( 0 ), + //myHeaderEditor( 0 ), + //myEditedHeader( 0 ), + //myEditedSection( -1 ), + //mySelectAll( 0 ) +{ + setObjectName( name ); + + /*myVerHeaders.setAutoDelete( true ); + myHorHeaders.setAutoDelete( true ); + + verticalHeader()->setStyle( styleWrapper() ); + horizontalHeader()->setStyle( styleWrapper() ); + + connect( verticalHeader(), SIGNAL( sizeChange( int, int, int ) ), + this, SLOT( onHeaderSizeChange( int, int, int ) ) ); + connect( horizontalHeader(), SIGNAL( sizeChange( int, int, int ) ), + this, SLOT( onHeaderSizeChange( int, int, int ) ) ); + connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + connect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + + updateHeaders( Qt::Horizontal ); + updateHeaders( Qt::Vertical ); + */ +} + +/*! + Constructor +*/ +QtxTable::QtxTable( int numRows, int numCols, QWidget* parent, const char* name ) +: QTableWidget( numRows, numCols, parent )//, + //myStyleWrapper( 0 ), + //myHeaderEditor( 0 ), + //myEditedHeader( 0 ), + //myEditedSection( -1 ), + //mySelectAll( 0 ) +{ + setObjectName( name ); + /* + myVerHeaders.setAutoDelete( true ); + myHorHeaders.setAutoDelete( true ); + + verticalHeader()->setStyle( styleWrapper() ); + horizontalHeader()->setStyle( styleWrapper() ); + + connect( verticalHeader(), SIGNAL( sizeChange( int, int, int ) ), + this, SLOT( onHeaderSizeChange( int, int, int ) ) ); + connect( horizontalHeader(), SIGNAL( sizeChange( int, int, int ) ), + this, SLOT( onHeaderSizeChange( int, int, int ) ) ); + connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + connect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + */ +} + +/*! + Destructor +*/ +QtxTable::~QtxTable() +{ + //delete myStyleWrapper; +} + +bool QtxTable::isSelectAllEnabled() const +{ + return true;//mySelectAll; +} + +void QtxTable::setSelectAllEnabled( const bool on ) +{ + /* if ( isSelectAllEnabled() == on ) + return; + + if ( on ) + connect( mySelectAll = new QToolButton( this ), SIGNAL( clicked() ), this, SLOT( selectAll() ) ); + else + { + delete mySelectAll; + mySelectAll = 0; + } + updateSelectAllButton(); + */ +} + +/*! + Select the all cells of the table. +*/ +void QtxTable::selectAll() +{ + /* + if ( selectionMode() != Multi && selectionMode() != MultiRow ) + return; + + selectCells( 0, 0, numRows() - 1, numCols() - 1 ); + */ +} + +/*! + Reimplemented for 'SelectAll' button geometry updating. +*/ +void QtxTable::setTopMargin( int m ) +{ + //QTableWidget::setTopMargin( m ); + //updateSelectAllButton(); +} + +/*! + Reimplemented for 'SelectAll' button geometry updating. +*/ +void QtxTable::setLeftMargin( int m ) +{ + //QTableWidget::setLeftMargin( m ); + //updateSelectAllButton(); +} + +/*! + Reimplemented for 'SelectAll' button updating. +*/ +void QtxTable::setSelectionMode( SelectionMode mode ) +{ + QTableWidget::setSelectionMode( mode ); + //updateSelectAllButton(); +} + +/*! + \return true if header is editable + \param o - header orientation +*/ +bool QtxTable::headerEditable( Qt::Orientation o, const int idx ) const +{ + //QHeaderView* hdr = idx < 0 ? header( o ) : header( o, idx ); + return true;//myHeaderEditable.contains( hdr ) ? myHeaderEditable[hdr] : false; +} + +/*! + Changes editable state of header + \param o - header orientation + \param on - new state +*/ +void QtxTable::setHeaderEditable( Qt::Orientation o, const bool on, const int idx ) +{ + /*if ( headerEditable( o, idx ) == on ) + return; + + QHeaderView* hdr = idx < 0 ? header( o ) : header( o, idx ); + myHeaderEditable.insert( hdr, on ); + + if ( !on && myEditedHeader == hdr ) + endHeaderEdit( false ); + + if ( on ) + hdr->installEventFilter( this ); + else + hdr->removeEventFilter( this ); + */ +} + +void QtxTable::setHeadersEditable( Qt::Orientation o, bool on ) +{ + /* setHeaderEditable( o, on ); + for ( int i = 0; i < numHeaders( o ); i++ ) + setHeaderEditable( o, on, i ); + */ +} + +/*! + Starts edition of header + \param o - header orientation + \param sec - column/row +*/ +bool QtxTable::editHeader( Qt::Orientation o, const int sec ) +{ + return true;//beginHeaderEdit( o, sec ); +} + +/*! + Finishes edition of header + \param accept - whether new value must be accepted +*/ +void QtxTable::endEditHeader( const bool accept ) +{ + //endHeaderEdit( accept ); +} + +/*! + Custom event filter + Starts edition of header by double click + Finishes edition by escape/return/enter pressing +*/ +bool QtxTable::eventFilter( QObject* o, QEvent* e ) +{ + /*if ( e->type() == QEvent::MouseButtonDblClick ) + { + QMouseEvent* me = (QMouseEvent*)e; + QHeaderView* hdr = ::qobject_cast( o ); + if ( hdr ) + return beginHeaderEdit( hdr, me->pos() ); + } + + if ( o == myHeaderEditor && e->type() == QEvent::KeyPress && isHeaderEditing() ) + { + QKeyEvent* ke = (QKeyEvent*)e; + if ( ke->key() == Key_Escape ) + { + endHeaderEdit( false ); + return true; + } + + if ( ke->state() == NoButton && ( ke->key() == Key_Return || ke->key() == Key_Enter ) ) + { + endHeaderEdit( true ); + return true; + } + + return false; + } + + if ( o == myHeaderEditor && e->type() == QEvent::FocusOut && + ((QFocusEvent*)e)->reason() != QFocusEvent::Popup ) + { + endHeaderEdit(); + return true; + } + + if ( e->type() == QEvent::Wheel && isHeaderEditing() ) + return true; + */ + return QTableWidget::eventFilter( o, e ); +} + +void QtxTable::adjustRow( int row ) +{ + //QTableWidget::adjustRow( row ); + + /*int size = 0; + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + QHeaderView* hdr = myVerHeaders.at( i ); + QString txt = hdr->label( row ); + int h = hdr->iconSet( row ) ? hdr->iconSet( row )->pixmap().height() : 0; + if ( !QStyleSheet::mightBeRichText( txt ) ) + h = QMAX( h, hdr->fontMetrics().height() ); + else + { + QStyleSheet sheet; + QStyleSheetItem* item = sheet.item( "p" ); + if ( item ) + item->setMargin( QStyleSheetItem::MarginAll, 0 ); + + QSimpleRichText rt( txt, hdr->font(), QString::null, &sheet ); + rt.setWidth( hdr->width() ); + h = QMAX( h, rt.height() ); + } + size = QMAX( size, h ); + } + + size = QMAX( size, rowHeight( row ) ); + setRowHeight( row, size ); + */ +} + +void QtxTable::adjustColumn( int col ) +{ + //QTableWidget::adjustColumn( col ); + /* + int size = 0; + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + Header* hdr = (Header*)myHorHeaders.at( i ); + QString txt = hdr->label( col ); + int w = hdr->iconSet( col ) ? + hdr->iconSet( col )->pixmap( QIconSet::Automatic, QIconSet::Normal ).width() + 5 : 0; + int txtW = 0; + if ( !QStyleSheet::mightBeRichText( txt ) ) + txtW += hdr->fontMetrics().width( txt ); + else + { + QStyleSheet sheet; + QStyleSheetItem* item = sheet.item( "p" ); + if ( item ) + { + item->setMargin( QStyleSheetItem::MarginAll, 0 ); + item->setWhiteSpaceMode( QStyleSheetItem::WhiteSpaceNoWrap ); + } + + QSimpleRichText rt( QString( "

%1

" ).arg( txt ), hdr->font(), QString::null, &sheet ); + txtW += rt.width(); + } + + if ( hdr->horizontalSpan( col ) > 1 ) + txtW = txtW / hdr->horizontalSpan( col ); + + w = w + txtW + 10; + + size = QMAX( size, w ); + } + + for ( int i = 0; i < numRows(); i++ ) + { + QFont fnt = cellFont( i, col ); + int sz = QFontMetrics( fnt ).width( text( i, col ) ) + 10; + size = QMAX( size, sz ); + } + + size = QMAX( size, columnWidth( col ) ); + setColumnWidth( col, size ); + */ +} + +void QtxTable::rowHeightChanged( int row ) +{ + //QTableWidget::rowHeightChanged( row ); + /* + int h = rowHeight( row ); + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + QHeaderView* hdr = myVerHeaders.at( i ); + hdr->resizeSection( row, h ); + } + */ +} + +void QtxTable::columnWidthChanged( int col ) +{ + //QTableWidget::columnWidthChanged( col ); + /* + int w = columnWidth( col ); + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + QHeaderView* hdr = myHorHeaders.at( i ); + hdr->resizeSection( col, w ); + } + */ +} + +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::setNumRows( int rows ) +{ + endHeaderEdit(); + int old = numRows(); + + QTableWidget::setNumRows( rows ); + + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + Header* hdr = (Header*)myVerHeaders.at( i ); + for ( int d = hdr->count() - 1; d >= (int)numRows(); d-- ) + hdr->removeSection( d ); + for ( int c = hdr->count(); c < (int)numRows(); c++ ) + hdr->addLabel( QString::null ); + } +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::setNumCols( int cols ) +{ + + endHeaderEdit(); + int old = numCols(); + + QTableWidget::setNumCols( cols ); + + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + Header* hdr = (Header*)myHorHeaders.at( i ); + for ( int d = hdr->count() - 1; d >= (int)numCols(); d-- ) + hdr->removeSection( d ); + for ( int c = hdr->count(); c < (int)numCols(); c++ ) + hdr->addLabel( QString::null ); + } +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::insertRows( int row, int count ) +{ + endHeaderEdit(); + + QTableWidget::insertRows( row, count ); + + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + Header* hdr = (Header*)myVerHeaders.at( i ); + for ( int j = numRows() - count - 1; j >= row; --j ) + hdr->swapSections( j, j + count ); + } +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::insertColumns( int col, int count ) +{ + /* + endHeaderEdit(); + + QTableWidget::insertColumns( col, count ); + + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + Header* hdr = (Header*)myHorHeaders.at( i ); + for ( int j = numCols() - count - 1; j >= col; --j ) + hdr->swapSections( j, j + count ); + } +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::removeRow( int row ) +{ + endHeaderEdit(); + + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + Header* hdr = (Header*)myVerHeaders.at( i ); + hdr->removeSection( row ); + } + + QTableWidget::removeRow( row ); +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::removeRows( const QVector& rows ) +{ + endHeaderEdit(); + + int decr = 0; + QMap indexes; + for ( int r = 0; r < numRows(); r++ ) + { + if ( rows.contains( r ) ) + decr++; + else + indexes.insert( r, r - decr ); + } + + for ( uint i = 0; i < myVerHeaders.count(); i++ ) + { + Header* hdr = (Header*)myVerHeaders.at( i ); + for ( int d = rows.count() - 1; d >= 0; d-- ) + hdr->removeSection( rows[d] ); + } + QTableWidget::removeRows( rows ); +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::removeColumn( int col ) +{ + endHeaderEdit(); + + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + Header* hdr = (Header*)myHorHeaders.at( i ); + hdr->removeSection( col ); + } + QTableWidget::removeColumn( col ); +} +*/ +/*! + Reimplemented for internal reasons. + Firstly end the edition of header. +*/ +/*void QtxTable::removeColumns( const QVector& cols ) +{ + endHeaderEdit(); + + int decr = 0; + QMap indexes; + for ( int c = 0; c < numCols(); c++ ) + { + if ( cols.contains( c ) ) + decr++; + else + indexes.insert( c, c - decr ); + } + + for ( uint i = 0; i < myHorHeaders.count(); i++ ) + { + Header* hdr = (Header*)myHorHeaders.at( i ); + for ( int d = cols.count() - 1; d >= 0; d-- ) + hdr->removeSection( cols[d] ); + } + QTableWidget::removeColumns( cols ); +} +*/ +void QtxTable::setUpdatesEnabled( bool enable ) +{ + /* + QTableWidget::setUpdatesEnabled( enable ); + + if ( enable ) + { + updateHeaderGeometries( Qt::Horizontal ); + updateHeaderGeometries( Qt::Vertical ); + } + */ +} + +QHeaderView* QtxTable::header( const Qt::Orientation o, const int idx ) const +{ + /* + HeaderVector* vec = headerVector( o ); + + if ( idx < 0 || idx >= (int)vec->count() ) + return 0; + + return vec->at( idx ); + */ + return 0; +} + +int QtxTable::numHeaders( const Qt::Orientation o ) const +{ + return 0;//headerVector( o )->count(); +} + +void QtxTable::setNumHeaders( const Qt::Orientation o, const int n ) +{ + /* + headerVector( o )->resize( QMAX( n, 0 ) ); + + updateHeaders( o ); + updateHeaderSizes( o ); + updateHeaderSpace( o ); + + updateGeometries(); + */ +} + +QVariant QtxTable::headerData( const Qt::Orientation o, const int section, const int role ) const +{ + QVariant res; + if ( model() ) + res = model()->headerData( section, o, role ); + return res; +} + +QFont QtxTable::headerFont( const Qt::Orientation o, const int section ) const +{ + QFont res = o == Qt::Horizontal ? horizontalHeader()->font() : + verticalHeader()->font(); + QVariant aVar = headerData( o, section, Qt::FontRole ); + if ( aVar.isValid() && aVar.canConvert( QVariant::Font ) ) + res = aVar.value(); + return res; +} + +QColor QtxTable::headerForeground( const Qt::Orientation o, const int section ) const +{ + QColor res; + QVariant aVar = headerData( o, section, Qt::ForegroundRole ); + if ( aVar.isValid() && aVar.canConvert( QVariant::Color ) ) + res = aVar.value(); + return res; +} + +QColor QtxTable::headerBackground( const Qt::Orientation o, const int section ) const +{ + QColor res; + QVariant aVar = headerData( o, section, Qt::BackgroundRole ); + if ( aVar.isValid() && aVar.canConvert( QVariant::Color ) ) + res = aVar.value(); + return res; +} + +QIcon QtxTable::headerIcon( const Qt::Orientation o, const int section ) const +{ + QIcon res; + QVariant aVar = headerData( o, section, Qt::DecorationRole ); + if ( aVar.isValid() && aVar.canConvert( QVariant::Icon ) ) + res = aVar.value(); + return res; +} + +void QtxTable::setHeaderData( const Qt::Orientation o, const int section, const QVariant& var, + const int role ) +{ + QTableWidgetItem* anItem = 0; + if ( o == Qt::Horizontal ) + anItem = horizontalHeaderItem( section ); + else + anItem = verticalHeaderItem( section ); + if ( !anItem ) { + anItem = new QTableWidgetItem(); + if ( o == Qt::Horizontal ) + setHorizontalHeaderItem( section, anItem ); + else + setVerticalHeaderItem( section, anItem ); + } + + if ( model() ) + model()->setHeaderData( section, o, var, role ); +} + +void QtxTable::setHeaderFont( const Qt::Orientation o, const int section, const QFont& font ) +{ + setHeaderData( o, section, QVariant( font ), Qt::FontRole ); +} + +void QtxTable::setHeaderForeground( const Qt::Orientation o, const int section, const QColor& c ) +{ + setHeaderData( o, section, QVariant( c ), Qt::ForegroundRole ); +} + +void QtxTable::setHeaderBackground( const Qt::Orientation o, const int section, const QColor& c ) +{ + setHeaderData( o, section, QVariant( c ), Qt::BackgroundRole ); +} + +void QtxTable::setHeaderIcon( const Qt::Orientation o, const int section, const QIcon& icon ) +{ + setHeaderData( o, section, QVariant( icon ), Qt::DecorationRole ); +} + +QVariant QtxTable::cellData( const int row, const int col ) const +{ + QVariant res; + QTableWidgetItem* anItem = item( row, col ); + if ( anItem ) + res = anItem->data( Qt::DisplayRole ); + + return res; +} + +QFont QtxTable::cellFont( const int row, const int col ) const +{ + QFont res = font(); + QTableWidgetItem* anItem = item( row, col ); + if ( anItem ) + res = anItem->font(); + + return res; +} + +QColor QtxTable::cellForeground( const int row, const int col ) const +{ + QColor res; + QTableWidgetItem* anItem = item( row, col ); + if ( anItem && anItem->foreground().style() != Qt::NoBrush ) + res = anItem->foreground().color(); + return res; +} + +QColor QtxTable::cellBackground( const int row, const int col ) const +{ + QColor res; + QTableWidgetItem* anItem = item( row, col ); + if ( anItem && anItem->background().style() != Qt::NoBrush ) + res = anItem->background().color(); + return res; +} + +QIcon QtxTable::cellIcon( const int row, const int col ) const +{ + QIcon res; + QTableWidgetItem* anItem = item( row, col ); + if ( anItem ) + res = anItem->icon(); + + return res; +} + +void QtxTable::setCellFont( const int row, const int col, const QFont& f ) +{ + QTableWidgetItem* anItem = getItem( row, col ); + if ( anItem ) + anItem->setFont( f ); +} + +void QtxTable::setCellForeground( const int row, const int col, const QColor& c ) +{ + if ( !c.isValid() ) + return; + + QTableWidgetItem* anItem = getItem( row, col ); + if ( anItem ) + anItem->setForeground( c ); +} + +void QtxTable::setCellBackground( const int row, const int col, const QColor& c ) +{ + if ( !c.isValid() ) + return; + + QTableWidgetItem* anItem = getItem( row, col ); + if ( anItem ) + anItem->setBackground( c ); +} + +/*void QtxTable::paintCell( QPainter* p, int row, int col, const QRect& cr, + bool selected, const QColorGroup& cg ) +{ + QColor fg = cellForeground( row, col ); + QColor bg = cellBackground( row, col ); + + QColorGroup cGroup = cg; + if ( fg.isValid() ) + cGroup.setColor( QColorGroup::Text, fg ); + if ( bg.isValid() ) + cGroup.setColor( QColorGroup::Base, bg ); + + p->save(); + p->setFont( cellFont( row, col ) ); + + QTableWidget::paintCell( p, row, col, cr, selected, cGroup ); + + p->restore(); +} +*/ + +void QtxTable::clear( const bool withHeaders ) +{ + if ( withHeaders ) + clear(); + else + clearContents(); + + /* + if ( !withHeaders ) + return; + + QHeaderView* hh = horizontalHeader(); + for ( int hi = 0; hi < hh->count(); hi++ ) + hh->setLabel( hi, QString( "" ) ); + QHeaderView* vh = verticalHeader(); + for ( int vi = 0; vi < vh->count(); vi++ ) + vh->setLabel( vi, QString( "" ) ); + + for ( int h = 0; h < (int)myHorHeaders.size(); h++ ) + ((Header*)myHorHeaders.at( h ))->clear(); + for ( int v = 0; v < (int)myVerHeaders.size(); v++ ) + ((Header*)myVerHeaders.at( v ))->clear(); + */ +} + +/*! + SLOT: called on scroll +*/ +void QtxTable::onScrollBarMoved( int ) +{ + //updateHeaderEditor(); +} + +/*! + SLOT: called on header size changing +*/ +void QtxTable::onHeaderSizeChange( int section, int oldSize, int newSize ) +{ + /* + const QHeaderView* header = ::qobject_cast( sender() ); + if ( !header ) + return; + + HeaderVector* vec = headerVector( header->orientation() ); + for ( int i = 0; i < (int)vec->size(); i++ ) + { + QHeaderView* hdr = vec->at( i ); + hdr->resizeSection( section, newSize ); + } + + if ( header == myEditedHeader ) + updateHeaderEditor(); + */ +} + +/*! + Custom hide event handler +*/ +void QtxTable::hideEvent( QHideEvent* e ) +{ + //endHeaderEdit(); + + QTableWidget::hideEvent( e ); +} + +/*! + Custom resize event handler +*/ +void QtxTable::resizeEvent( QResizeEvent* e ) +{ + QTableWidget::resizeEvent( e ); + + //updateHeaderEditor(); + + //updateGeometries(); +} + +/*! + Return item from cell + \param row - table row + \param col - table column + \param created - if item not exit and create=true, it will be created +*/ +QTableWidgetItem* QtxTable::getItem( const int row, const int col, const bool created ) +{ + QTableWidgetItem* anItem = item( row, col ); + if ( !anItem && created && row < rowCount() && col < columnCount() ) { + anItem = new QTableWidgetItem(); + setItem( row, col, anItem ); + } + return anItem; +} + + +/*! + Starts edition of header + \param o - header orientation + \param sec - column/row +*/ +bool QtxTable::beginHeaderEdit( Qt::Orientation o, const int section, const int idx ) +{ + /* + QHeaderView* hdr = 0; + if ( idx < 0 ) + hdr = header( o ); + if ( !hdr->isVisibleTo( this ) ) + hdr = header( o, idx ); + + return beginHeaderEdit( hdr, section ); + */ + return true; +} + +bool QtxTable::beginHeaderEdit( QHeaderView* hdr, const int s ) +{ + /* + if ( !hdr || !myHeaderEditable.contains( hdr ) || !myHeaderEditable[hdr] || !hdr->isVisibleTo( this ) ) + return false; + + endHeaderEdit(); + + int section = s; + QRect r = headerSectionRect( hdr, s, §ion ); + if ( !r.isValid() ) + return false; + + if ( hdr->orientation() == Qt::Horizontal ) + r.setLeft( QMAX( r.left(), leftMargin() ) ); + else + r.setTop( QMAX( r.top(), topMargin() ) ); + + myHeaderEditor = createHeaderEditor( hdr, section ); + if ( !myHeaderEditor ) + return false; + + myEditedHeader = hdr; + myEditedSection = section; + + myHeaderEditor->reparent( this, QPoint( 0, 0 ), false ); + + updateHeaderEditor(); + + myHeaderEditor->show(); + + myHeaderEditor->setActiveWindow(); + myHeaderEditor->setFocus(); + + myHeaderEditor->installEventFilter( this ); + */ + return true; +} + +/*! + Finishes edition of header + \param accept - whether new value must be accepted +*/ +void QtxTable::endHeaderEdit( const bool accept ) +{ + /* + if ( !isHeaderEditing() ) + return; + + QString oldTxt = myEditedHeader ? myEditedHeader->label( myEditedSection ) : QString::null; + + if ( accept && myEditedHeader ) + setHeaderContentFromEditor( myEditedHeader, myEditedSection, myHeaderEditor ); + + QString newTxt = myEditedHeader ? myEditedHeader->label( myEditedSection ) : QString::null; + + int sec = myEditedSection; + QHeaderView* hdr = myEditedHeader; + + myEditedHeader = 0; + myEditedSection = -1; + + myHeaderEditor->hide(); + myHeaderEditor->deleteLater(); + myHeaderEditor->removeEventFilter( this ); + myHeaderEditor = 0; + + if ( oldTxt != newTxt ) + { + emit headerEdited( hdr, sec ); + emit headerEdited( hdr == horizontalHeader() ? Qt::Horizontal : Qt::Vertical, sec ); + } + */ +} + +/*! + \return true if header is being edited +*/ +bool QtxTable::isHeaderEditing() const +{ + return true;//myHeaderEditor && myEditedHeader && myEditedSection != -1; +} + +/*! + Creates and \return header editor + \param hdr - header + \param sec - column/row + \param init - init editor with value +*/ +QWidget* QtxTable::createHeaderEditor( QHeaderView* hdr, const int sec, const bool init ) +{ + + //QString lab = hdr ? hdr->label( sec ) : QString::null; + + QWidget* wid = 0; + /* + if ( !QStyleSheet::mightBeRichText( lab ) && !lab.contains( "\n" ) ) + { + QLineEdit* le = new QLineEdit( 0 ); + if ( init ) + le->setText( lab ); + wid = le; + } + else + { + QTextEdit* te = new QTextEdit( 0 ); + te->setVScrollBarMode( QTextEdit::AlwaysOff ); + te->setHScrollBarMode( QTextEdit::AlwaysOff ); + QStyleSheet* sheet = new QStyleSheet( te ); + QStyleSheetItem* i = sheet->item( "p" ); + if ( i ) + i->setMargin( QStyleSheetItem::MarginAll, 0 ); + te->setStyleSheet( sheet ); + + if ( init ) + te->setText( lab ); + wid = te; + } + */ + return wid; +} + +/*! + Initialize editor with value + \param hdr - header + \param sec - column/row + \param editor - editor +*/ +void QtxTable::setHeaderContentFromEditor( QHeaderView* hdr, const int sec, QWidget* editor ) +{ + /* + if ( !hdr || !editor ) + return; + + QLineEdit* le = ::qobject_cast( editor ); + if ( le ) + hdr->setLabel( sec, le->text() ); + else + { + QTextEdit* te = ::qobject_cast( editor ); + if ( te ) + hdr->setLabel( sec, te->text().remove( "\n" ) ); + } + */ +} + +/*! + \return header + \param o - orientation +*/ +QHeaderView* QtxTable::header( Qt::Orientation o ) const +{ + return o == Qt::Horizontal ? horizontalHeader() : verticalHeader(); +} + +/*! + Starts edition of header + \param o - header orientation + \param p - point +*/ +bool QtxTable::beginHeaderEdit( QHeaderView* hdr, const QPoint& p ) +{ + /* + if ( !hdr ) + return false; + + int pos = hdr->orientation() == Qt::Horizontal ? p.x() : p.y(); + int sec = hdr->sectionAt( hdr->offset() + pos ); + if ( sec < 0 ) + return false; + + bool ok = false; + QPoint pnt = mapFromGlobal( hdr->mapToGlobal( p ) ); + int cur = hdr->orientation() == Qt::Horizontal ? pnt.x() : pnt.y(); + + int bid = 0; + QRect sRect = headerSectionRect( hdr, sec, &bid ); + if ( sRect.isValid() ) + { + int m = 4; + int from = hdr->orientation() == Qt::Horizontal ? sRect.left() : sRect.top(); + int to = hdr->orientation() == Qt::Horizontal ? sRect.right() - m : sRect.bottom() - m; + if ( sec > 0 ) + from += m; + + ok = from <= cur && cur <= to; + } + + if ( ok ) + beginHeaderEdit( hdr, sec ); + + return ok; + */ + return true; +} + +/*! + \return rectangle of header section + \param hdr - header + \param sec - column/row +*/ +QRect QtxTable::headerSectionRect( QHeaderView* hdr, const int sec, int* main ) const +{ + QRect r( -1, -1, -1, -1 ); + + /*if ( !hdr ) + return r; + + r = hdr->sectionRect( sec ); + if ( hdr != verticalHeader() && hdr != horizontalHeader() ) + r = ((Header*)hdr)->indexRect( hdr->mapToIndex( sec ), main ); + + if ( r.isValid() ) + r = QRect( mapFromGlobal( hdr->mapToGlobal( r.topLeft() ) ), r.size() ); + */ + + return r; +} + +/*! + Updates header editor +*/ +void QtxTable::updateHeaderEditor() +{ + /* + if ( !myHeaderEditor || !myEditedHeader || myEditedSection < 0 ) + return; + + QRect r = headerSectionRect( myEditedHeader, myEditedSection ); + if ( !r.isValid() ) + return; + + if ( myEditedHeader->orientation() == Qt::Horizontal ) + { + r.setLeft( QMAX( r.left(), leftMargin() ) ); + r.setRight( QMIN( r.right(), width() - rightMargin() - 2 ) ); + } + else + { + r.setTop( QMAX( r.top(), topMargin() ) ); + r.setBottom( QMIN( r.bottom(), height() - bottomMargin() - 2 ) ); + } + + myHeaderEditor->resize( r.size() ); + myHeaderEditor->move( r.topLeft() ); + */ +} + +/*! + Remove selected rows or columns if any of cell selected in it +*/ +void QtxTable::removeSelected( const bool row ) +{ + /* + QValueList idsList; + QMap idMap; + int i = 0; + for ( int nb = numSelections(); i < nb; i++ ) + { + QTableSelection sel = selection( i ); + int minId = row ? sel.topRow() : sel.leftCol(); + int maxId = row ? sel.bottomRow() : sel.rightCol(); + for ( ; minId <= maxId; minId++ ) + if ( !idMap.contains( minId ) ) + { + idMap[ minId ] = 1; + idsList.append( minId ); + } + } + if ( idMap.isEmpty() ) + return; + + qHeapSort( idsList ); + QVector idsArr( idsList.count() ); + QValueList::const_iterator it = idsList.begin(); + QValueList::const_iterator itEnd = idsList.end(); + for ( i = 0; it != itEnd; ++it, ++i ) + idsArr[ i ] = *it; + + if ( row ) + removeRows( idsArr ); + else + removeColumns( idsArr ); + */ +} + +QtxTable::HeaderVector* QtxTable::headerVector( const Qt::Orientation o ) const +{ + return 0;//o == Qt::Horizontal ? (HeaderVector*)&myHorHeaders : (HeaderVector*)&myVerHeaders; +} + +QtxStyleWrap* QtxTable::styleWrapper() +{ + /* if ( !myStyleWrapper ) + { + myStyleWrapper = new QtxStyleWrap( &style() ); + new StyleItem( myStyleWrapper ); + } + return myStyleWrapper; + */ + return 0; +} + +void QtxTable::updateHeaders( const Qt::Orientation o ) +{ + /* + HeaderVector& vec = o == Qt::Vertical ? myVerHeaders : myHorHeaders; + QScrollBar* sb = o == Qt::Vertical ? verticalScrollBar() : horizontalScrollBar(); + QHeaderView* main = o == Qt::Vertical ? verticalHeader() : horizontalHeader(); + + main->setShown( !vec.size() ); + + for ( uint i = 0; i < vec.size(); i++ ) + { + if ( vec.at( i ) ) + continue; + + QHeaderView* hdr = new Header( o == Qt::Horizontal ? numCols() : numRows(), this ); + vec.insert( i, hdr ); + hdr->setStyle( styleWrapper() ); + hdr->setMovingEnabled( false ); + hdr->setOrientation( o ); + hdr->installEventFilter( this ); + hdr->show(); + + connect( sb, SIGNAL( valueChanged( int ) ), hdr, SLOT( setOffset( int ) ) ); + if ( o == Qt::Horizontal ) + connect( hdr, SIGNAL( sectionHandleDoubleClicked( int ) ), this, SLOT( adjustColumn( int ) ) ); + else + connect( hdr, SIGNAL( sectionHandleDoubleClicked( int ) ), this, SLOT( adjustRow( int ) ) ); + } + + if ( o == Qt::Horizontal ) + { + for ( uint j = 0; j < vec.size(); j++ ) + { + QHeaderView* hdr = vec.at( j ); + bool upd = hdr->isUpdatesEnabled(); + hdr->setUpdatesEnabled( false ); + for ( int s = 0; s < (int)hdr->count(); s++ ) + hdr->setLabel( s, QString( "" ) ); + hdr->setUpdatesEnabled( upd ); + } + } + + // slot onScrollBarMoved should be last connection. + // QHeaderView::setOffset() should be invoked before it for every header. + // Otherwise header editor geometry will not properly updated. + disconnect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + disconnect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + connect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); + */ +} + +void QtxTable::updateHeaderSpace( const Qt::Orientation o ) +{ + /* + HeaderVector& vec = o == Qt::Vertical ? myVerHeaders : myHorHeaders; + + int size = 0; + for ( uint i = 0; i < vec.size(); i++ ) + { + QHeaderView* hdr = vec.at( i ); + int sz = o == Qt::Vertical ? hdr->width() : hdr->height(); + if ( o == Qt::Vertical ) + hdr->move( size, 0 ); + else + hdr->move( 0, size ); + size += sz; + } + + if ( vec.size() == 0 ) + size = o == Qt::Vertical ? verticalHeader()->width() : horizontalHeader()->height(); + + if ( o == Qt::Vertical ) + setLeftMargin( size ); + else + setTopMargin( size ); + */ +} + +void QtxTable::updateHeaderSizes( const Qt::Orientation o ) +{ + /* + HeaderVector& vec = o == Qt::Vertical ? myVerHeaders : myHorHeaders; + + for ( uint j = 0; j < vec.count(); j++ ) + { + QHeaderView* hdr = vec.at( j ); + for ( int s = 0; s < (int)hdr->count(); s++ ) + hdr->resizeSection( s, o == Qt::Vertical ? rowHeight( s ) : columnWidth( s ) ); + if ( o == Qt::Vertical ) + hdr->resize( hdr->sizeHint().width(), hdr->height() ); + else + hdr->resize( hdr->width(), hdr->sizeHint().height() ); + } + */ +} + +/* +void QtxTable::updateGeometries() +{ + QSize sz = horizontalHeader()->size(); + int size = frameWidth(); + for ( int h = 0; h < (int)myHorHeaders.size(); h++ ) + { + QHeaderView* hdr = myHorHeaders.at( h ); + hdr->setGeometry( frameWidth() + leftMargin(), size, sz.width(), hdr->height() ); + size += hdr->height(); + } + + sz = verticalHeader()->size(); + size = frameWidth(); + for ( int v = 0; v < (int)myVerHeaders.size(); v++ ) + { + QHeaderView* hdr = myVerHeaders.at( v ); + hdr->setGeometry( size, frameWidth() + topMargin(), hdr->width(), sz.height() ); + size += hdr->width(); + } +} +*/ + +void QtxTable::updateHeaderGeometries( const Qt::Orientation o ) +{ + /* + if ( !isUpdatesEnabled() ) + return; + + updateHeaderSizes( o ); + updateHeaderSpace( o ); + updateGeometries(); + */ +} + +void QtxTable::updateSelectAllButton() +{ + /* + if ( !mySelectAll ) + return; + + mySelectAll->setShown( selectionMode() == Multi || selectionMode() == MultiRow ); + if ( mySelectAll->isVisibleTo( this ) ) + mySelectAll->setGeometry( frameWidth(), frameWidth(), leftMargin(), topMargin() ); + */ +} + +#endif diff --git a/src/Qtx/QtxTable.h b/src/Qtx/QtxTable.h new file mode 100644 index 000000000..077dc9cb0 --- /dev/null +++ b/src/Qtx/QtxTable.h @@ -0,0 +1,199 @@ +// 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: QtxTable.h +// Author: Sergey TELKOV + +#ifndef QTX_TABLE_H +#define QTX_TABLE_H + +#include "Qtx.h" + +#include +#include +#include +#include +#include +//#include +//#include + +#ifndef QT_NO_TABLE + +class QHeaderView; +class QToolButton; +class QVariant; +class QtxStyleWrap; + +#ifdef WIN32 +#pragma warning( disable : 4251 ) +#endif + +class QTX_EXPORT QtxTable : public QTableWidget +{ + Q_OBJECT + + //Q_PROPERTY( bool selectAllEnabled READ isSelectAllEnabled WRITE setSelectAllEnabled ) + + class Header; + class StyleItem; + +public: + QtxTable( QWidget* = 0, const char* = 0 ); + QtxTable( int, int, QWidget* = 0, const char* = 0 ); + virtual ~QtxTable(); + + bool headerEditable( Qt::Orientation, const int = -1 ) const; + + bool editHeader( Qt::Orientation, const int ); + void endEditHeader( const bool = true ); + + virtual void setSelectionMode( SelectionMode ); + + void removeSelected( const bool row = true ); + + virtual bool eventFilter( QObject*, QEvent* ); + + //virtual void setNumRows( int ); + //virtual void setNumCols( int ); + + bool isSelectAllEnabled() const; + virtual void setSelectAllEnabled( const bool ); + + QHeaderView* header( const Qt::Orientation, const int ) const; + int numHeaders( const Qt::Orientation ) const; + void setNumHeaders( const Qt::Orientation, const int ); + + QVariant headerData( const Qt::Orientation, const int, const int = Qt::DisplayRole ) const; + QFont headerFont( const Qt::Orientation, const int ) const; + QColor headerForeground( const Qt::Orientation, const int ) const; + QColor headerBackground( const Qt::Orientation, const int ) const; + QIcon headerIcon( const Qt::Orientation, const int ) const; + + void setHeaderData( const Qt::Orientation, const int, const QVariant&, + const int = Qt::DisplayRole ); + void setHeaderFont( const Qt::Orientation, const int, const QFont& ); + void setHeaderForeground( const Qt::Orientation, const int, const QColor& ); + void setHeaderBackground( const Qt::Orientation, const int, const QColor& ); + void setHeaderIcon( const Qt::Orientation, const int, const QIcon& ); + + QVariant cellData( const int, const int ) const; + QFont cellFont( const int, const int ) const; + QColor cellForeground( const int, const int ) const; + QColor cellBackground( const int, const int ) const; + QIcon cellIcon( const int, const int ) const; + + void setCellData( const int, const int, const QVariant& ); + void setCellFont( const int, const int, const QFont& ); + void setCellForeground( const int, const int, const QColor& ); + void setCellBackground( const int, const int, const QColor& ); + void setCellIcont( const int, const int, QIcon& ); + + //virtual void paintCell( QPainter*, int, int, const QRect&, bool, const QColorGroup& ); + + virtual void clear( const bool = true ); + +signals: + void headerEdited( QHeaderView*, int ); + void headerEdited( Qt::Orientation, int ); + +public slots: + virtual void selectAll(); + virtual void setTopMargin( int ); + virtual void setLeftMargin( int ); + void setHeadersEditable( Qt::Orientation, bool ); + virtual void setHeaderEditable( Qt::Orientation, bool, const int = -1 ); + + //virtual void insertRows( int, int = 1 ); + //virtual void insertColumns( int, int = 1 ); + //virtual void removeRow( int ); + //virtual void removeRows( const QVector& ); + //virtual void removeColumn( int ); + //virtual void removeColumns( const QVector& ); + + virtual void setUpdatesEnabled( bool enable ); + + virtual void adjustRow( int ); + virtual void adjustColumn( int ); + +protected slots: + virtual void rowHeightChanged( int ); + virtual void columnWidthChanged( int ); + +private slots: + void onScrollBarMoved( int ); + void onHeaderSizeChange( int, int, int ); + +protected: + virtual void hideEvent( QHideEvent* ); + virtual void resizeEvent( QResizeEvent* ); + + virtual bool beginHeaderEdit( QHeaderView*, const int ); + bool beginHeaderEdit( Qt::Orientation, const int, const int = -1 ); + virtual void endHeaderEdit( const bool = true ); + bool isHeaderEditing() const; + virtual QWidget* createHeaderEditor( QHeaderView*, const int, const bool = true ); + virtual void setHeaderContentFromEditor( QHeaderView*, const int, QWidget* ); + + QHeaderView* header( Qt::Orientation o ) const; + virtual QRect headerSectionRect( QHeaderView*, const int, int* = 0 ) const; + + QTableWidgetItem* getItem( const int, const int, const bool = true ); + +private: + typedef QMap HeaderState; + typedef QVector HeaderVector; + +private: + void updateHeaderEditor(); + bool beginHeaderEdit( QHeaderView*, const QPoint& ); + + QtxStyleWrap* styleWrapper(); + HeaderVector* headerVector( const Qt::Orientation ) const; + + //void updateGeometries(); + void updateSelectAllButton(); + + void updateHeaders( const Qt::Orientation ); + void updateHeaderSizes( const Qt::Orientation ); + void updateHeaderSpace( const Qt::Orientation ); + void updateHeaderGeometries( const Qt::Orientation ); + +private: + /* + HeaderVector myVerHeaders; + HeaderVector myHorHeaders; + QtxStyleWrap* myStyleWrapper; + + QWidget* myHeaderEditor; + QHeaderView* myEditedHeader; + int myEditedSection; + HeaderState myHeaderEditable; + + QToolButton* mySelectAll; + */ + + friend class QtxTable::Header; +}; + +#ifdef WIN32 +#pragma warning( default: 4251 ) +#endif + +#endif + +#endif diff --git a/src/VTKViewer/VTKViewer.pro b/src/VTKViewer/VTKViewer.pro index 16fa2898d..aecb9d512 100644 --- a/src/VTKViewer/VTKViewer.pro +++ b/src/VTKViewer/VTKViewer.pro @@ -1,8 +1,8 @@ TEMPLATE = lib -DESTDIR = ../../${CONFIG_ID}/lib +DESTDIR = ../../$(CONFIG_ID)/lib MOC_DIR = ../../moc -OBJECTS_DIR = ../../${CONFIG_ID}/obj/$$TARGET +OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET VTKHOME = $$(VTKHOME) VTK_INCLUDES = $${VTKHOME}/include/vtk @@ -15,7 +15,7 @@ CAS_CPPFLAGS = $${CASROOT}/inc CAS_KERNEL = -L$${CASROOT}/Linux/lib -lTKernel INCLUDEPATH += ../../include $${VTK_INCLUDES} $${CAS_CPPFLAGS} ../Qtx ../SUIT -LIBS += -L../../${CONFIG_ID}/lib -lqtx -lsuit $${VTK_LIBS} $${CAS_KERNEL} +LIBS += -L../../$(CONFIG_ID)/lib -lQtx -lSUIT $${VTK_LIBS} $${CAS_KERNEL} CONFIG -= debug release debug_and_release CONFIG += qt thread debug dll shared