31 #include <QMouseEvent> 32 #include <QPaintEvent> 44 , first_column_size_ratio_( 0.5
f )
45 , color_( 128, 128, 128, 64 )
47 setCursor( Qt::SplitHCursor );
49 parent_->installEventFilter(
this );
54 if( event_target ==
parent_ && (event->type() == QEvent::Resize ||
55 event->type() == QEvent::Paint))
65 int content_width =
parent_->contentsRect().width();
67 if ( new_column_width !=
parent_->columnWidth(0) ) {
68 parent_->setColumnWidth( 0, new_column_width );
69 parent_->setColumnWidth( 1, content_width - new_column_width );
71 int new_x = new_column_width - w / 2 +
parent_->columnViewportPosition(0);
72 if ( new_x !=
x() ||
parent_->height() != height() )
73 setGeometry( new_x, 0, w,
parent_->height() );
89 if( event->button() == Qt::LeftButton )
100 if( event->buttons() & Qt::LeftButton )
102 QPoint pos_rel_parent =
parent_->mapFromGlobal( event->globalPos() );
106 if( new_x >
parent_->width() - width() - padding )
108 new_x =
parent_->width() - width() - padding;
111 if( new_x < padding )
118 int new_column_width = new_x + width() / 2 -
parent_->contentsRect().x();
127 QPainter painter(
this );
129 painter.drawLine( 1+width() / 2, 0, 1+width() / 2, height() );
virtual void paintEvent(QPaintEvent *event)
float getRatio()
Get the ratio of the parent's left column to the parent widget width.
virtual void mousePressEvent(QMouseEvent *event)
SplitterHandle(QTreeView *parent=0)
void updateGeometry()
Update the parent's column widths and this splitter's geometry based on first_column_size_ratio_.
virtual void mouseMoveEvent(QMouseEvent *event)
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
float first_column_size_ratio_
bool eventFilter(QObject *event_target, QEvent *event)
Catch resize events sent to parent to update splitter's geometry. Always returns false.
void setRatio(float ratio)
Set the ratio of the parent's left column to the parent widget width.