//-------------------------------------------------------------------------------------------------
void
BachFolderBrowserTreeView::setupColumns( IniConfig & ini, const BachFolderBrowserTreeView::ColumnStructEx columns [] )
{
	QHeaderView * hdr = header();
	int cnt = 0;
	QStringList labels;
	for( cnt=0; columns[cnt].name; ++cnt );
	QVector<int> indexVec(cnt);
	for( int i=0; i<cnt; i++ ) {
		labels << QString::fromLatin1(columns[i].name);
		indexVec[i] = ini.readInt( columns[i].iniName + QString("Index"), columns[i].defaultPos );
	}
	hdr->setStretchLastSection(false);
	for( int n=0; n<cnt; n++ ) {
		for( int i=0; i<cnt; i++ )
			if( indexVec[i] == n )
				hdr->moveSection( hdr->visualIndex(i), n );
	}
	hdr->resizeSections(QHeaderView::Stretch);
	for( int n=0; n<cnt; n++ ) {
		int size = ini.readInt( columns[n].iniName + QString("Size"), columns[n].defaultSize );
		hdr->resizeSection( n, size==0?columns[n].defaultSize:size );
	}
	for( int n=0; n<cnt; n++ ) {
		bool hidden = ini.readBool( columns[n].iniName + QString("Hidden"), columns[n].defaultHidden );
		hdr->setSectionHidden( n, hidden );
	}
	hdr->setResizeMode( QHeaderView::Interactive );
}
void ListingTable::headerSectionVisibilityActionTriggered()
{
	QAction* action = (QAction*) sender();
	int sect = action->data().toInt();

	QHeaderView* header = horizontalHeader();
	header->setSectionHidden(sect, !action->isChecked());
}
Esempio n. 3
0
// -------------------------------------------------------------------------
void ctkTreeComboBox::showPopup()
{
  Q_D(ctkTreeComboBox);
  QHeaderView* header = qobject_cast<QTreeView*>(this->view())->header();
  for (int i = 0; i < header->count(); ++i)
    {
    header->setSectionHidden(i, d->VisibleModelColumn != -1 &&
                                i != d->VisibleModelColumn);
    }
  this->QComboBox::showPopup();
  emit this->popupShow();
}
Esempio n. 4
0
void TreeComboBox::updateView()
{
    QTreeView *v = new QTreeView();
    setView( v );
    v->setSelectionMode( m_selectionmode );
    // don't want to have mouseover select an item
    v->disconnect(SIGNAL(entered(QModelIndex)));

    QHeaderView *h = v->header();
    for ( int i = 0; i < h->count(); ++i ) {
        h->setSectionHidden( i, ! m_showcolumns.contains( i ) );
    }
    h->setVisible( m_showheader );
    v->setRootIsDecorated( false );
}
Esempio n. 5
0
void FilmsViewList::ShowHeaderContextMenu( const QPoint& pos )
{
      // Setup
    QHeaderView* header = horizontalHeader();
    QMenu menu( tr("Columns") );

      // "Title" always enabled
      // "Filename" and "Poster" always disabled
    for( int column = 1; column < model()->columnCount() - 2; ++column )
    {
        QAction* action = menu.addAction( model()->headerData( column, Qt::Horizontal ).toString() );
        action->setCheckable( true );
        action->setChecked( !header->isSectionHidden( column ) );
        action->setData( column );
    }

    menu.addSeparator();
    QAction* resetAction = menu.addAction( tr("Reset to defaults") );
    resetAction->setData( model()->columnCount() );

      // Show
    QAction* triggered = menu.exec( header->viewport()->mapToGlobal(pos) );

      // Processing
    if( triggered != nullptr )
    {
        int i = triggered->data().toInt();

        if( i < model()->columnCount() )
        {
            header->setSectionHidden( i, !header->isSectionHidden( i ) );
        }
        else // "Reset to defaults" item
        {
            RestoreColumnsOrder();
            SetDefaultColumnsView();
        }

        SaveSettings();
    }
}
Esempio n. 6
0
void ResourceTableWidget::switchView(BibGlobals::ResourceSelection selection, BibGlobals::BibEntryType filter, Library *p)
{
    m_selection = selection;

    PublicationFilterModel * pfm = qobject_cast<PublicationFilterModel *>(p->viewModel(selection));
    if(pfm) {
        pfm->setResourceFilter(filter);
    }
    else {
        SeriesFilterModel * pfm = qobject_cast<SeriesFilterModel *>(p->viewModel(selection));
        if(pfm) {
            pfm->setResourceFilter(BibGlobals::SeriesType(filter));
        }
    }

    // if we only need to change the filter, forget the rest after this check
    QAbstractItemModel *oldModel = m_documentView->model();
    QAbstractItemModel *newModel = p->viewModel(selection);
    if(!newModel)
        return;
    if(oldModel == newModel)
        return;

    if(m_documentView->selectionModel()) {
        disconnect(m_documentView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                this, SLOT(selectedResource(QItemSelection,QItemSelection)));
    }

    switch(m_selection) {
    case BibGlobals::Resource_Event:
    case BibGlobals::Resource_Series:
        m_documentView->setItemDelegateForColumn(3, m_htmlDelegate);
        break;
    default:
        m_documentView->setItemDelegateForColumn(3, NULL);
    }

    m_documentView->setWordWrap(true);
    m_documentView->setModel(p->viewModel(selection));

    //load settings for visible/hidden columns
    KConfig config;
    QString group = QLatin1String("TableView");
    group.append((int)m_selection);
    KConfigGroup tableViewGroup( &config, group );

    // go through all header elements and apply last known visibility / size status
    // also add each header name to the search combobox for selection
    QString curSearchSelection =  m_searchSelection->currentText();
    m_searchSelection->clear();
    m_searchSelection->addItem(i18n("all entries"), -1); //additem NAME, TABLEHEADERINDEX
    QHeaderView *hv = m_documentView->horizontalHeader();
    int columnCount = m_documentView->model()->columnCount();

    NepomukModel *nm = qobject_cast<NepomukModel *>(newModel);
    if(!nm) {
        QSortFilterProxyModel *qsf = qobject_cast<QSortFilterProxyModel *>(newModel);
        if(qsf) {
            nm = qobject_cast<NepomukModel *>(qsf->sourceModel());
        }
    }

    for(int i=0; i < columnCount; i++) {
        // hidden status
        QString keyHidden = QLatin1String("hidden_") + QString::number(i);
        bool hidden = tableViewGroup.readEntry( keyHidden, false );

        hv->setSectionHidden(i, hidden);

        QString headerName = m_documentView->model()->headerData(i,Qt::Horizontal).toString();
        if(!headerName.isEmpty()) {
            m_searchSelection->addItem(headerName, i);
        }

        // size status
        int sectionSize = 50;
        QString keySize = QLatin1String("size_") + QString::number(i);
        int size = tableViewGroup.readEntry( keySize, -1 );
        if(size > 4) {
            sectionSize = size;
        }
        else {
            if(nm) {
                sectionSize = nm->defaultSectionSize(i);
            }
        }

        hv->resizeSection(i,sectionSize);
    }

    //try to be clever and set the same searchElement as before, if it exist
    int lastSelection = m_searchSelection->findText(curSearchSelection);
    if(lastSelection != -1)
        m_searchSelection->setCurrentIndex(lastSelection);

    hv->setResizeMode(QHeaderView::Interactive);

    m_documentView->setSelectionMode(QAbstractItemView::ExtendedSelection);

    connect(m_documentView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(selectedResource(QItemSelection,QItemSelection)));

    m_documentView->selectRow(0);

    QList<int> fixedWithList = nm->fixedWidthSections();
    foreach(int section, fixedWithList) {
        hv->setResizeMode(section, QHeaderView::Fixed);
    }
Esempio n. 7
0
int HeaderView::setSectionHidden(lua_State * L) // ( int logicalIndex, bool hide )
{
    QHeaderView* obj = QtObject<QHeaderView>::check( L, 1);
	obj->setSectionHidden( Util::toInt( L, 2 ), Util::toBool( L, 3 ) );
	return 0;
}
Esempio n. 8
0
TransfersWindow::TransfersWindow(StackedWindow *parent) :
    StackedWindow(parent),
    m_model(new TransferModel(this)),
    m_view(new QTreeView(this)),
    m_startAction(new QAction(tr("Start all transfers"), this)),
    m_pauseAction(new QAction(tr("Pause all transfers"), this)),
    m_contextMenu(new QMenu(this)),
    m_transferCommandAction(m_contextMenu->addAction(tr("Set custom command"),
                                                             this, SLOT(setCurrentTransferCustomCommand()))),
    m_transferStartAction(m_contextMenu->addAction(tr("Start"), this, SLOT(startCurrentTransfer()))),
    m_transferPauseAction(m_contextMenu->addAction(tr("Pause"), this, SLOT(pauseCurrentTransfer()))),
    m_transferCategoryMenu(m_contextMenu->addMenu(tr("Category"))),
    m_transferCategoryGroup(new QActionGroup(this)),
    m_transferPriorityMenu(m_contextMenu->addMenu(tr("Priority"))),
    m_transferPriorityGroup(new QActionGroup(this)),
    m_transferHighPriorityAction(m_transferPriorityMenu->addAction(tr("High"), this, SLOT(setCurrentTransferPriority()))),
    m_transferNormalPriorityAction(m_transferPriorityMenu->addAction(tr("Normal"), this, SLOT(setCurrentTransferPriority()))),
    m_transferLowPriorityAction(m_transferPriorityMenu->addAction(tr("Low"), this, SLOT(setCurrentTransferPriority()))),
    m_transferRemoveAction(m_contextMenu->addAction(tr("Remove"), this, SLOT(removeCurrentTransfer()))),
    m_label(new QLabel(QString("<p align='center'; style='font-size: 40px; color: %1'>%2</p>")
                              .arg(palette().color(QPalette::Mid).name()).arg(tr("No transfers queued")), this))
{
    setWindowTitle(tr("Transfers"));
    setCentralWidget(new QWidget);
        
    m_view->setModel(m_model);
    m_view->setSelectionBehavior(QTreeView::SelectRows);
    m_view->setContextMenuPolicy(Qt::CustomContextMenu);
    m_view->setEditTriggers(QTreeView::NoEditTriggers);
    m_view->setItemsExpandable(false);
    m_view->setIndentation(0);
    m_view->setUniformRowHeights(true);
    m_view->setAllColumnsShowFocus(true);
    m_view->setColumnHidden(1, true);
    
    QHeaderView *header = m_view->header();

    if (!header->restoreState(Settings::transfersHeaderViewState())) {
        const QFontMetrics fm = header->fontMetrics();
        header->resizeSection(0, fm.width("A long transfer name") + 10);
        header->resizeSection(2, fm.width(m_model->headerData(2).toString()) + 10);
        header->resizeSection(3, fm.width("999.99MB of 999.99MB (99.99%)") + 10);
        header->setSectionHidden(1, true);
    }
    
    m_transferCategoryGroup->setExclusive(true);
    m_transferPriorityGroup->setExclusive(true);
    m_transferHighPriorityAction->setCheckable(true);
    m_transferHighPriorityAction->setActionGroup(m_transferPriorityGroup);
    m_transferNormalPriorityAction->setCheckable(true);
    m_transferNormalPriorityAction->setActionGroup(m_transferPriorityGroup);
    m_transferLowPriorityAction->setCheckable(true);
    m_transferLowPriorityAction->setActionGroup(m_transferPriorityGroup);
    
    m_label->hide();
    
    m_layout = new QVBoxLayout(centralWidget());
    m_layout->addWidget(m_view);
    m_layout->addWidget(m_label);
    m_layout->setContentsMargins(0, 0, 0, 0);
    
    menuBar()->addAction(m_startAction);
    menuBar()->addAction(m_pauseAction);
    
    connect(m_model, SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int)));
    connect(m_startAction, SIGNAL(triggered()), Transfers::instance(), SLOT(start()));
    connect(m_pauseAction, SIGNAL(triggered()), Transfers::instance(), SLOT(pause()));
    connect(m_view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
    connect(m_contextMenu, SIGNAL(aboutToShow()), this, SLOT(setTransferMenuActions()));
    connect(Settings::instance(), SIGNAL(categoriesChanged()), this, SLOT(setCategoryMenuActions()));
    
    onCountChanged(m_model->rowCount());
    setCategoryMenuActions();
}