Пример #1
0
/*!
  \reimp
*/
void QHeader::mousePressEvent( QMouseEvent *e )
{
    if ( e->button() != LeftButton || state != Idle )
	return;
    handleIdx = 0;
    int c = orient == Horizontal ? e->pos().x() : e->pos().y();
    c += offset();

    int section = sectionAt( c );
    if ( section < 0 )
	return;
    int index = d->s2i[section];

    if ( (index > 0 && c < d->positions[index] + GRIPMARGIN) ||
	 (c > d->positions[index] + d->sizes[section] - GRIPMARGIN) ) {
	if ( c < d->positions[index]  + GRIPMARGIN )
	    handleIdx = index-1;
	else
	    handleIdx = index;
	oldHIdxSize = d->sizes[ d->i2s[handleIdx] ];
	state = d->resize[d->i2s[handleIdx]  ] ? Sliding : Blocked;
    } else if ( index >= 0 ) {
	handleIdx = index;
	moveToIdx = -1;
	state = d->clicks[ d->i2s[handleIdx]  ] ? Pressed : Blocked;
	clickPos = c;
	repaint( sRect( handleIdx ) );
	emit pressed( section );
    }
}
Пример #2
0
bool KexiTableViewHeader::eventFilter(QObject * watched, QEvent * e)
{
    if (e->type() == QEvent::MouseMove) {
        const int section = sectionAt(static_cast<QMouseEvent*>(e)->x());
        if (section != m_lastToolTipSection && section >= 0 && section < (int)m_toolTips.count()) {
            //QToolTip::remove(this, m_toolTipRect);
#ifdef __GNUC__
#warning TODO KexiTableViewHeader::eventFilter
#else
#pragma WARNING( TODO KexiTableViewHeader::eventFilter  )
#endif
            QString tip = m_toolTips[ section ];
            if (tip.isEmpty()) { //try label
                QFontMetrics fm(font());
                int minWidth = fm.width(label(section))
                               + style()->pixelMetric(QStyle::PM_HeaderMargin);
                QIcon *iset = iconSet(section);
                if (iset)
                    minWidth += (2 + iset->pixmap(IconSize(KIconLoader::Small)).width()); //taken from QHeader::sectionSizeHint()
                if (minWidth > sectionSize(section))
                    tip = label(section);
            }
            if (tip.isEmpty()) {
                m_lastToolTipSection = -1;
            } else {
#ifdef __GNUC__
#warning QToolTip::showText() OK?
#else
#pragma WARNING( QToolTip::showText() OK? )
#endif
                QToolTip::showText(static_cast<QMouseEvent*>(e)->globalPos(), tip,
                                   this, m_toolTipRect = sectionRect(section));
                m_lastToolTipSection = section;
            }
        }
    } else if (e->type() == QEvent::ToolTip) {
//        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e);
#ifdef __GNUC__
#warning TODO
#else
#pragma WARNING( TODO )
#endif
    }
//   if (e->type()==QEvent::MouseButtonPress) {
// todo
//   }
    return Q3Header::eventFilter(watched, e);
}
Пример #3
0
/*!
  Tries to find a line that is not a neighbor of  \c handleIdx.
 */
int QHeader::findLine( int c )
{
    int lastpos = d->positions[d->count-1] + d->sizes[d->i2s[d->count-1]];
    int i = 0;
    if ( c > lastpos ) {
	return d->count;
    } else {
	int section = sectionAt( c );
	if ( section < 0 )
	    return handleIdx;
	i = d->s2i[section];
    }
    if ( i == handleIdx )
	return i;
    if ( i == handleIdx - 1 &&  pPos( handleIdx ) - c > MARKSIZE/2 )
	return i;
    if ( i == handleIdx + 1 && c - pPos( i ) > MARKSIZE/2 )
	return i + 1;
    if ( c - pPos( i ) > pSize( i ) / 2 )
	return i + 1;
    else
	return i;
}
Пример #4
0
/*!
  \reimp
*/
void QHeader::mouseMoveEvent( QMouseEvent *e )
{
    int section;
    bool hit;

    int c = orient == Horizontal ? e->pos().x() : e->pos().y();
    c += offset();

    switch( state ) {
    case Idle:
	hit = FALSE;
	if ( (section = sectionAt( c )) >= 0 ) {
	    int index = d->s2i[section];
	    if ( (index > 0 && c < d->positions[index] + GRIPMARGIN) ||
		 (c > d->positions[index] + d->sizes[section] - GRIPMARGIN) ) {
		if ( index > 0 && c < d->positions[index]  + GRIPMARGIN )
		    section = d->i2s[--index];
		if ( d->resize.testBit(section) ) {
		    hit = TRUE;
#ifndef QT_NO_CURSOR
		    if ( orient == Horizontal )
			setCursor( splitHCursor );
		    else
			setCursor( splitVCursor );
#endif
		}
	    }
	}
#ifndef QT_NO_CURSOR
	if ( !hit )
	    unsetCursor();
#endif
	break;
    case Blocked:
	break;
    case Pressed:
	if ( QABS( c - clickPos ) > 4 && d->move ) {
	    state = Moving;
	    moveToIdx = -1;
#ifndef QT_NO_CURSOR
	    if ( orient == Horizontal )
		setCursor( sizeHorCursor );
	    else
		setCursor( sizeVerCursor );
#endif
	}
	break;
    case Sliding:
	handleColumnResize( handleIdx, c, FALSE );
	break;
    case Moving: {
	int newPos = findLine( c );
	if ( newPos != moveToIdx ) {
	    if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		repaint( sRect(handleIdx) );
	    else
		unMarkLine( moveToIdx );
	    moveToIdx = newPos;
	    if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		paintRect( pPos( handleIdx ), pSize( handleIdx ) );
	    else
		markLine( moveToIdx );
	}
	break;
    }
    default:
	qWarning( "QHeader::mouseMoveEvent: (%s) unknown state", name() );
	break;
    }
}
Пример #5
0
int QHeader::cellAt( int pos ) const
{
    return mapToIndex( sectionAt(pos + offset()) );
}