myEditedHeader( 0 ),
myEditedSection( -1 )
{
+ 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 ) ) );
}
QtxTable::QtxTable( int numRows, int numCols, QWidget* parent, const char* name )
myEditedHeader( 0 ),
myEditedSection( -1 )
{
+ 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 ) ) );
}
QtxTable::~QtxTable()
endHeaderEdit( accept );
}
+void QtxTable::hide()
+{
+ endHeaderEdit();
+
+ QTable::hide();
+}
+
bool QtxTable::eventFilter( QObject* o, QEvent* e )
{
if ( e->type() == QEvent::MouseButtonDblClick )
return QTable::eventFilter( o, e );
}
+void QtxTable::onScrollBarMoved( int )
+{
+ updateHeaderEditor();
+}
+
+void QtxTable::onHeaderSizeChange( int, int, int )
+{
+ if ( sender() == myEditedHeader )
+ updateHeaderEditor();
+}
+
+void QtxTable::resizeEvent( QResizeEvent* e )
+{
+ QTable::resizeEvent( e );
+
+ updateHeaderEditor();
+}
+
bool QtxTable::beginHeaderEdit( Orientation o, const int section )
{
if ( !headerEditable( o ) || !header( o ) || !header( o )->isVisibleTo( this ) )
myEditedSection = section;
myHeaderEditor->reparent( this, QPoint( 0, 0 ), false );
- myHeaderEditor->resize( r.size() );
- myHeaderEditor->move( r.topLeft() );
+
+ updateHeaderEditor();
+
myHeaderEditor->show();
+
myHeaderEditor->setActiveWindow();
myHeaderEditor->setFocus();
+
myHeaderEditor->installEventFilter( this );
return true;
return r;
}
+void QtxTable::updateHeaderEditor()
+{
+ if ( !myHeaderEditor || !myEditedHeader || myEditedSection < 0 )
+ return;
+
+ QRect r = headerSectionRect( myEditedHeader, myEditedSection );
+ if ( !r.isValid() )
+ return;
+
+ if ( myEditedHeader == horizontalHeader() )
+ {
+ 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() );
+}
+
#endif
void headerEdited( Orientation, int );
public slots:
+ virtual void hide();
virtual void setHeaderEditable( Orientation, bool );
+private slots:
+ void onScrollBarMoved( int );
+ void onHeaderSizeChange( int, int, int );
+
protected:
+ virtual void resizeEvent( QResizeEvent* );
+
virtual bool beginHeaderEdit( Orientation, const int );
virtual void endHeaderEdit( const bool = true );
bool isHeaderEditing() const;
QHeader* header( Orientation o ) const;
private:
+ void updateHeaderEditor();
void beginHeaderEdit( Orientation, const QPoint& );
QRect headerSectionRect( QHeader*, const int ) const;