예제 #1
0
void StretchHeaderView::UpdateWidths(const QList<int>& sections) {
  if (!stretch_enabled_)
    return;

  ColumnWidthType total_w = 0.0;

  for (int i=0 ; i<column_widths_.count() ; ++i) {
    const ColumnWidthType w = column_widths_[i];
    int pixels = w * width();

    if (pixels != 0 && total_w - int(total_w) > 0.5)
      pixels ++;

    total_w += w;

    if (!sections.isEmpty() && !sections.contains(i))
      continue;

    if (pixels == 0 && !isSectionHidden(i))
      hideSection(i);
    else if (pixels != 0 && isSectionHidden(i)) {
      showSection(i);
      AssertMinimalColumnWidth(i);
    }

    if (pixels != 0)
      resizeSection(i, pixels);
  }
}
예제 #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;
}
예제 #3
0
void StretchHeaderView::SectionResized(int logical, int, int new_size) {
  if (!stretch_enabled_)
    return;

  if (in_mouse_move_event_) {
    // Update this section's proportional width
    column_widths_[logical] = ColumnWidthType(new_size) / width();

    // Find the visible sections to the right of the section that's being resized
    int visual = visualIndex(logical);
    QList<int> logical_sections_to_resize;
    for (int i=0 ; i<count() ; ++i) {
      if (!isSectionHidden(i) && visualIndex(i) > visual)
        logical_sections_to_resize << i;
    }

    // Resize just those columns
    if (!logical_sections_to_resize.isEmpty()) {
      in_mouse_move_event_ = false;
      UpdateWidths(logical_sections_to_resize);
      NormaliseWidths(logical_sections_to_resize);
      in_mouse_move_event_ = true;
    }
  }
}
예제 #4
0
void HierarchicalHeaderView::on_sectionResized(int logicalIndex)
{
	if(isSectionHidden(logicalIndex))
		return;

	QModelIndex leafIndex(_pd->leafIndex(logicalIndex));
	if(leafIndex.isValid())
	{
		QModelIndexList leafsList(_pd->leafs(_pd->findRootIndex(leafIndex)));
		for(int n=leafsList.indexOf(leafIndex); n>0; --n)
		{
			--logicalIndex;

			int w = viewport()->width();
			int h = viewport()->height();
			int pos = sectionViewportPosition(logicalIndex);
			QRect r(pos, 0, w - pos, h);
			if(orientation() == Qt::Horizontal)
			{
				if (isRightToLeft())
					r.setRect(0, 0, pos + sectionSize(logicalIndex), h);
			}
			else
				r.setRect(0, pos, w, h - pos);

			viewport()->update(r.normalized());
		}
	}
}
예제 #5
0
void HeaderView::toggleSectionVisibility()
{
    if (QAction* act = qobject_cast<QAction*>(sender())) {
        int index = act->data().toInt();

        setSectionHidden(index, !isSectionHidden(index));
    }
}
예제 #6
0
void KNMusicListViewHeader::showContextMenu(const QPoint &mousePoint)
{
    for(int i=0; i<KNMusicGlobal::MusicDataCount; i++)
    {
        m_viewerMenu->setHeaderValue(i, !isSectionHidden(i));
    }
    m_viewerMenu->exec(mapToGlobal(mousePoint));
}
예제 #7
0
void
ViewHeader::toggleVisibility( int index )
{
    if ( isSectionHidden( index ) )
        showSection( index );
    else
        hideSection( index );
}
QRect QSpreadsheetHeaderView::nextRect(int logicalIndex) const
{
    if (isSectionHidden(logicalIndex))
        return QRect();

    QRect sr = sectionRect(logicalIndex);

    return QRect(sr.right() - 13, sr.center().y() - 6, 13, 13);
}
예제 #9
0
void
ViewHeader::toggleVisibility( int index )
{
    qDebug() << Q_FUNC_INFO << index;

    if ( isSectionHidden( index ) )
        showSection( index );
    else
        hideSection( index );
}
void PlaylistHeader::AddColumnAction(int index) {
  QString title(model()->headerData(index, Qt::Horizontal).toString());

  QAction* action = menu_->addAction(title, show_mapper_, SLOT(map()));
  action->setCheckable(true);
  action->setChecked(!isSectionHidden(index));
  show_actions_ << action;

  show_mapper_->setMapping(action, index);
}
예제 #11
0
void StretchHeaderView::SetColumnWidth(int logical, ColumnWidthType width) {
  if (!stretch_enabled_)
    return;

  column_widths_[logical] = width;

  QList<int> other_columns;
  for (int i=0 ; i<count() ; ++i)
    if (!isSectionHidden(i) && i != logical)
      other_columns << i;
  NormaliseWidths(other_columns);
}
예제 #12
0
void
ViewHeader::addColumnToMenu( int index )
{
    QString title = m_parent->model()->headerData( index, Qt::Horizontal, Qt::DisplayRole ).toString();

    QAction* action = m_menu->addAction( title, m_sigmap, SLOT( map() ) );
    action->setCheckable( true );
    action->setChecked( !isSectionHidden( index ) );
    m_visActions << action;

    m_sigmap->setMapping( action, index );
}
void QSpreadsheetHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
    painter->save();

    QHeaderView::paintSection(painter, rect, logicalIndex);

    painter->restore();

    if (!rect.isValid() || isSortIndicatorShown())
        return;

    if (isSectionHidden(logicalIndex - 1)) {
        drawPrevButton(painter, logicalIndex);
    }

    if (isSectionHidden(logicalIndex + 1)) {
        drawNextButton(painter, logicalIndex);
    }

    QPoint pos = mapFromGlobal(QCursor::pos());
    if (rect.contains(pos)) {
        drawMenuButton(painter, logicalIndex, buttonMenuRect(logicalIndex).contains(pos));
    }
}
예제 #14
0
void StretchHeaderView::ShowSection(int logical) {
  if (!stretch_enabled_) {
    showSection(logical);
    return;
  }

  // How many sections are visible already?
  int visible_count = 0;
  for (int i=0 ; i<count() ; ++i) {
    if (!isSectionHidden(i))
      visible_count ++;
  }

  column_widths_[logical] =
      visible_count == 0 ? 1.0 : 1.0 / visible_count;
  NormaliseWidths();
  UpdateWidths();
}
예제 #15
0
void TreeViewHeader::mousePressEvent(QMouseEvent* e)
{
    QHeaderView::mousePressEvent(e);

    if(e->button() == Qt::RightButton) {
        if(!m_menu) {
            m_menu = new QMenu(this);

            for(int i = 0; i < model()->columnCount(); ++i) {
                QString name = model()->headerData(i,Qt::Horizontal).toString();
                QAction *action = new QAction(name,m_menu);
                action->setData(i);
                action->setCheckable(true);
                action->setChecked(!isSectionHidden(i));
                connect(action,SIGNAL(toggled(bool)),this,SLOT(hideHeader(bool)));
                m_menu->addAction(action);
            }
        }
        m_menu->popup(e->globalPos());
    }
예제 #16
0
void StretchHeaderView::HideSection(int logical) {
  // Would this hide the last section?
  bool all_hidden = true;
  for (int i=0 ; i<count() ; ++i) {
    if (i != logical && !isSectionHidden(i) && sectionSize(i) > 0) {
      all_hidden = false;
      break;
    }
  }
  if (all_hidden) {
    return;
  }

  if (!stretch_enabled_) {
    hideSection(logical);
    return;
  }

  column_widths_[logical] = 0.0;
  NormaliseWidths();
  UpdateWidths();
}
예제 #17
0
void PlaylistHeaderView::setModel(QAbstractItemModel *model)
{
	QHeaderView::setModel(model);
	for (int i = 0; i < count(); i++) {
		QString label = labels.at(i);

		// Exclude hidden columns (should be improved?)
		if (QString::compare(label, "TrackDAO") != 0) {
			model->setHeaderData(i, Qt::Horizontal, tr(label.toStdString().data()), Qt::DisplayRole);

			// Match actions with columns using index of labels
			QAction *actionColumn = new QAction(label, this);
			actionColumn->setData(i);
			actionColumn->setEnabled(actionColumn->text() != tr("Title"));
			actionColumn->setCheckable(true);
			actionColumn->setChecked(!isSectionHidden(i));

			// Then populate the context menu
			_columns->addAction(actionColumn);
		}
	}
}
예제 #18
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;
}
예제 #19
0
void HeaderView::contextMenuEvent(QContextMenuEvent* event)
{
    if (!m_menu) {
        m_menu = new QMenu(this);

        for (int i = 0; i < count(); ++i) {
            QAction* act = new QAction(model()->headerData(i, Qt::Horizontal).toString(), m_menu);
            act->setCheckable(true);
            act->setData(i);

            connect(act, SIGNAL(triggered()), this, SLOT(toggleSectionVisibility()));
            m_menu->addAction(act);
        }
    }

    for (int i = 0; i < m_menu->actions().count(); ++i) {
        QAction* act = m_menu->actions().at(i);
        act->setEnabled(i > 0);
        act->setChecked(!isSectionHidden(i));
    }

    m_menu->popup(event->globalPos());
}
void PlaylistHeader::ToggleVisible(int section) {
  SetSectionHidden(section, !isSectionHidden(section));
  emit SectionVisibilityChanged(section, !isSectionHidden(section));
}
예제 #21
0
void WTrackTableViewHeader::setModel(QAbstractItemModel* model) {
    TrackModel* oldTrackModel = getTrackModel();

    if (dynamic_cast<QAbstractItemModel*>(oldTrackModel) == model) {
        // If the models are the same, do nothing but the redundant call.
        QHeaderView::setModel(model);
        return;
    }

    // Won't happen in practice since the WTrackTableView new's a new
    // WTrackTableViewHeader each time a new TrackModel is loaded.
    // if (oldTrackModel) {
    //     saveHeaderState();
    // }

    // First clear all the context menu actions for the old model.
    clearActions();

    // Now set the header view to show the new model
    QHeaderView::setModel(model);

    // Now build actions for the new TrackModel
    TrackModel* trackModel = dynamic_cast<TrackModel*>(model);

    if (!trackModel) {
        return;
    }

    // Restore saved header state to get sizes, column positioning, etc. back.
    restoreHeaderState();

    // Here we can override values to prevent restoring corrupt values from database
    setMovable(true);

    // Setting true in the next line causes Bug #925619 at least with Qt 4.6.1
    setCascadingSectionResizes(false);

    setMinimumSectionSize(WTTVH_MINIMUM_SECTION_SIZE);

    int columns = model->columnCount();
    for (int i = 0; i < columns; ++i) {
        if (trackModel->isColumnInternal(i)) {
            continue;
        }

        QString title = model->headerData(i, orientation()).toString();
        QAction* action = new QAction(title, &m_menu);
        action->setCheckable(true);

        /* If Mixxx starts the first time or the header states have been cleared
         * due to database schema evolution we gonna hide all columns that may
         * contain a potential large number of NULL values.  Here we uncheck
         * item in the context menu that are hidden by defualt (e.g., key
         * column)
         */
        if (!hasPersistedHeaderState() &&
            trackModel->isColumnHiddenByDefault(i)) {
            action->setChecked(false);
        } else {
            action->setChecked(!isSectionHidden(i));
        }

        // Map this action's signals via our QSignalMapper
        m_signalMapper.setMapping(action, i);
        m_columnActions.insert(i, action);
        connect(action, SIGNAL(triggered()),
                &m_signalMapper, SLOT(map()));
        m_menu.addAction(action);

        // force the section size to be a least WTTVH_MINIMUM_SECTION_SIZE
        if (sectionSize(i) <  WTTVH_MINIMUM_SECTION_SIZE) {
            // This might happen if  WTTVH_MINIMUM_SECTION_SIZ has changed or
            // the header state from database was corrupt
            resizeSection(i,WTTVH_MINIMUM_SECTION_SIZE);
        }
    }

    // Safety check against someone getting stuck with all columns hidden
    // (produces an empty library table). Just re-show them all.
    if (hiddenCount() == columns) {
        for (int i = 0; i < columns; ++i) {
            showSection(i);
        }
    }
}