Exemplo n.º 1
0
void RDHeaderView::cacheSectionMinSizes()
{
  m_sectionMinSizes.resize(count());
  m_sectionMinSizesTotal = 0;

  for(int i = 0; i < m_sectionMinSizes.count(); i++)
  {
    int sz = 0;

    // see if we can fetch the column/row size hint from the item view
    QAbstractItemView *view = qobject_cast<QAbstractItemView *>(parent());
    if(view)
    {
      if(orientation() == Qt::Horizontal)
        sz = view->sizeHintForColumn(i);
      else
        sz = view->sizeHintForRow(i);
    }

    // also include the size for the header as another minimum
    if(orientation() == Qt::Horizontal)
      sz = qMax(sz, sectionSizeFromContents(i).width());
    else
      sz = qMax(sz, sectionSizeFromContents(i).height());

    // finally respect the minimum section size specified
    sz = qMax(sz, minimumSectionSize());

    // update the minimum size for this section and count the total which we'll need
    m_sectionMinSizes[i] = sz;
    m_sectionMinSizesTotal += m_sectionMinSizes[i];
  }
}
Exemplo n.º 2
0
bool
ViewHeader::checkState()
{
    if ( !count() || m_init )
        return false;

    QByteArray state = TomahawkSettings::instance()->playlistColumnSizes( m_guid );
    if ( !state.isEmpty() )
    {
        restoreState( state );

        if ( m_guid.startsWith( "playlistview" ) ) // HACK
            setSortIndicator( -1, Qt::AscendingOrder );
    }
    else
    {
        for ( int i = 0; i < count() - 1; i++ )
        {
            if ( isSectionHidden( i ) )
                continue;

            double nw = (double)m_parent->width() * m_columnWeights.at( i );
            resizeSection( i, qMax( minimumSectionSize(), int( nw - 0.5 ) ) );
        }
    }

    m_init = true;
    connect( this, SIGNAL( sectionMoved( int, int, int ) ), SLOT( onSectionsChanged() ) );
    connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionsChanged() ) );

    return true;
}
int QHeaderView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractItemView::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 21)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 21;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = isSortIndicatorShown(); break;
        case 1: *reinterpret_cast< bool*>(_v) = highlightSections(); break;
        case 2: *reinterpret_cast< bool*>(_v) = stretchLastSection(); break;
        case 3: *reinterpret_cast< bool*>(_v) = cascadingSectionResizes(); break;
        case 4: *reinterpret_cast< int*>(_v) = defaultSectionSize(); break;
        case 5: *reinterpret_cast< int*>(_v) = minimumSectionSize(); break;
        case 6: *reinterpret_cast< Qt::Alignment*>(_v) = defaultAlignment(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setSortIndicatorShown(*reinterpret_cast< bool*>(_v)); break;
        case 1: setHighlightSections(*reinterpret_cast< bool*>(_v)); break;
        case 2: setStretchLastSection(*reinterpret_cast< bool*>(_v)); break;
        case 3: setCascadingSectionResizes(*reinterpret_cast< bool*>(_v)); break;
        case 4: setDefaultSectionSize(*reinterpret_cast< int*>(_v)); break;
        case 5: setMinimumSectionSize(*reinterpret_cast< int*>(_v)); break;
        case 6: setDefaultAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 4
0
/*!
    \reimp
 */
void QxtHeaderView::resizeEvent(QResizeEvent* event)
{
    QHeaderView::resizeEvent(event);
    if (qxt_d().proportional)
    {
        int total = 0;
        for (int i = 0; i < count(); ++i)
            total += qxt_d().factors.value(i, 1);

        int totalSize = 0;
        for (int i = 0; i < count() - 1; ++i)
        {
            qreal factor = qxt_d().factors.value(i, 1) / static_cast<qreal>(total);
            int sectionSize = factor * (orientation() == Qt::Horizontal ? width() : height());
            sectionSize = qMax(minimumSectionSize(), sectionSize);
            resizeSection(i, sectionSize);
            totalSize += sectionSize;
        }
        // avoid rounding errors, give rest to the last section
        resizeSection(count() - 1, width() - totalSize);
    }
}
Exemplo n.º 5
0
bool
ViewHeader::checkState()
{
    if ( !count() || m_init )
        return false;

    disconnect( this, SIGNAL( sectionMoved( int, int, int ) ), this, SLOT( onSectionsChanged() ) );
    disconnect( this, SIGNAL( sectionResized( int, int, int ) ), this, SLOT( onSectionsChanged() ) );

    QByteArray state;
    if ( !m_guid.isEmpty() )
        state = TomahawkSettings::instance()->playlistColumnSizes( m_guid );

    if ( !state.isEmpty() )
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Restoring columns state for view:" << m_guid;
        restoreState( state );
    }
    else
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Giving columns of view" << m_guid << "initial weighting:" << m_columnWeights << "for" << count() << "columns";
        for ( int i = 0; i < count() - 1; i++ )
        {
            if ( isSectionHidden( i ) )
                continue;
            if ( i >= m_columnWeights.count() )
                break;

            double nw = (double)m_parent->width() * m_columnWeights.at( i );
            resizeSection( i, qMax( minimumSectionSize(), int( nw - 0.5 ) ) );
        }
    }

    connect( this, SIGNAL( sectionMoved( int, int, int ) ), SLOT( onSectionsChanged() ) );
    connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionsChanged() ) );

    m_init = true;
    return true;
}
Exemplo n.º 6
0
void RDHeaderView::mouseMoveEvent(QMouseEvent *event)
{
  if(m_movingSection >= 0)
  {
    m_sectionPreview->move(event->x() - m_sectionPreviewOffset, 0);
    return;
  }

  if(m_customSizing)
  {
    if(m_resizeState.first == NoResize || m_resizeState.second < 0 ||
       m_resizeState.second >= m_sections.count())
    {
      auto res = checkResizing(event);

      bool hasCursor = testAttribute(Qt::WA_SetCursor);

      if(res.first != NoResize)
      {
        if(!hasCursor)
          setCursor(Qt::SplitHCursor);
      }
      else if(hasCursor)
      {
        unsetCursor();
      }
    }
    else
    {
      int curX = QCursor::pos().x();
      int delta = curX - m_cursorPos;

      int idx = m_resizeState.second;

      if(m_resizeState.first == LeftResize && idx > 0)
        idx--;

      // batch the cache update
      m_suppressSectionCache = true;

      int firstCol = idx;
      int lastCol = idx;

      // idx is the last in a group, so search backwards to see if there are neighbour sections we
      // should share the resize with
      while(firstCol > 0 && m_sections[firstCol - 1].group == m_sections[lastCol].group)
        firstCol--;

      // how much space could we lose on the columns, in total
      int freeSpace = 0;
      for(int col = firstCol; col <= lastCol; col++)
        freeSpace += m_sections[col].size - minimumSectionSize();

      int numCols = lastCol - firstCol + 1;

      // spread the delta amonst the colummns
      int perSectionDelta = delta / numCols;

      // call resizeSection to emit the sectionResized signal but we set m_suppressSectionCache so
      // we won't cache sections.
      for(int col = firstCol; col <= lastCol; col++)
        resizeSection(col, qMax(minimumSectionSize(), m_sections[col].size + perSectionDelta));

      // if there was an uneven spread, a few pixels will remain
      int remainder = delta - perSectionDelta * numCols;

      // loop around for the remainder pixels, assigning them one by one to the smallest/largest
      // column.
      // this is inefficient but remainder is very small - at most 3.
      int step = remainder < 0 ? -1 : 1;
      for(int i = 0; i < qAbs(remainder); i++)
      {
        int chosenCol = firstCol;
        for(int col = firstCol; col <= lastCol; col++)
        {
          if(step > 0 && m_sections[col].size < m_sections[chosenCol].size)
            chosenCol = col;
          else if(step < 0 && m_sections[col].size > m_sections[chosenCol].size)
            chosenCol = col;
        }

        resizeSection(chosenCol, qMax(minimumSectionSize(), m_sections[chosenCol].size + step));
      }

      // only updating the cursor when the section is moving means that it becomes 'sticky'. If we
      // try to size down below the minimum size and keep going then it doesn't start resizing up
      // until it passes the divider again.
      int appliedDelta = delta;

      // if we were resizing down, at best we removed the remaining free space
      if(delta < 0)
        appliedDelta = qMax(delta, -freeSpace);

      m_cursorPos += appliedDelta;

      m_suppressSectionCache = false;

      cacheSections();
    }

    return QAbstractItemView::mouseMoveEvent(event);
  }

  QHeaderView::mouseMoveEvent(event);
}