Example #1
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;
}
Example #2
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);
  }
}
Example #3
0
void GameList::LoadInterfaceLayout() {
    auto header = tree_view->header();
    if (!header->restoreState(UISettings::values.gamelist_header_state)) {
        // We are using the name column to display icons and titles
        // so make it as large as possible as default.
        header->resizeSection(COLUMN_NAME, header->width());
    }

    item_model->sort(header->sortIndicatorSection(), header->sortIndicatorOrder());
}
Example #4
0
void RotatedHeader::read_settings() {
	QSettings *s = DT->user_settings();
	int cell_size = s->value("options/grid/cell_size", DEFAULT_CELL_SIZE).toInt();
	for(int i=1; i < count(); ++i) {
		if (!m_spacer_indexes.contains(i)) {
			resizeSection(i, cell_size);
		}
	}
	m_shade_column_headers = s->value("options/grid/shade_column_headers", true).toBool();
}
Example #5
0
void HeaderView::showEvent(QShowEvent* event)
{
    if (m_resizeOnShow) {
        for (int i = 0; i < m_sectionSizes.count(); ++i) {
            int size = m_parent->width() * m_sectionSizes.at(i);
            resizeSection(i, size);
        }
    }

    QHeaderView::showEvent(event);
}
Example #6
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);
    }
}
/*!
  adjust geometry and repaint header .
*/
void SpreadsheetHeaderView::refresh() {
	//TODO
	// adjust geometry and repaint header (still looking for a more elegant solution)
	int width = sectionSize(count()-1);
	m_slave->setStretchLastSection(true);  // ugly hack /*(flaw in Qt? Does anyone know a better way?)*/
	m_slave->updateGeometry();
	m_slave->setStretchLastSection(false); // ugly hack part 2
	setStretchLastSection(true);  // ugly hack (flaw in Qt? Does anyone know a better way?)
	updateGeometry();
	setStretchLastSection(false); // ugly hack part 2
	resizeSection(count()-1, width);
	update();
}
Example #8
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;
}
Example #9
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);
}
Example #10
0
	AggregatorTab::AggregatorTab (const InitParams& params, QObject *plugin)
	: TabClass_ { params.TabClass_ }
	, ParentPlugin_ { plugin }
	, ChannelActions_ { params.ChannelActions_ }
	, FlatToFolders_ { std::make_shared<Util::FlatToFoldersProxyModel> (params.TagsManager_) }
	, ChannelsFilterModel_ { new ChannelsFilterModel { this } }
	{
		ChannelsFilterModel_->setSourceModel (params.ChannelsModel_);
		ChannelsFilterModel_->setFilterKeyColumn (0);

		Ui_.setupUi (this);

		auto itemsWidgetDeps = params.ItemsWidgetDeps_;
		itemsWidgetDeps.ChannelsModel_ = ChannelsFilterModel_;
		Ui_.ItemsWidget_->InjectDependencies (itemsWidgetDeps);

		connect (Ui_.ItemsWidget_,
				&ItemsWidget::movedToChannel,
				this,
				&AggregatorTab::handleItemsMovedToChannel);

		Ui_.MergeItems_->setChecked (XmlSettingsManager::Instance ()->Property ("MergeItems", false).toBool ());

		Ui_.Feeds_->addAction (ChannelActions_->ActionMarkChannelAsRead_);
		Ui_.Feeds_->addAction (ChannelActions_->ActionMarkChannelAsUnread_);
		Ui_.Feeds_->addAction (Util::CreateSeparator (Ui_.Feeds_));
		Ui_.Feeds_->addAction (ChannelActions_->ActionRemoveFeed_);
		Ui_.Feeds_->addAction (ChannelActions_->ActionUpdateSelectedFeed_);
		Ui_.Feeds_->addAction (ChannelActions_->ActionRenameFeed_);
		Ui_.Feeds_->addAction (Util::CreateSeparator (Ui_.Feeds_));
		Ui_.Feeds_->addAction (ChannelActions_->ActionRemoveChannel_);
		Ui_.Feeds_->addAction (Util::CreateSeparator (Ui_.Feeds_));
		Ui_.Feeds_->addAction (ChannelActions_->ActionChannelSettings_);
		Ui_.Feeds_->addAction (Util::CreateSeparator (Ui_.Feeds_));
		Ui_.Feeds_->addAction (params.AppWideActions_.ActionAddFeed_);

		connect (Ui_.Feeds_,
				&QWidget::customContextMenuRequested,
				this,
				&AggregatorTab::handleFeedsContextMenuRequested);

		const auto fm = fontMetrics ();
		int dateTimeSize = fm.width (QDateTime::currentDateTime ().toString (Qt::SystemLocaleShortDate) + "__");
		const auto channelsHeader = Ui_.Feeds_->header ();
		channelsHeader->resizeSection (0, fm.width ("Average channel name"));
		channelsHeader->resizeSection (1, fm.width ("_9999_"));
		channelsHeader->resizeSection (2, dateTimeSize);

		connect (Ui_.TagsLine_,
				&QLineEdit::textChanged,
				ChannelsFilterModel_,
				&QSortFilterProxyModel::setFilterFixedString);

		new Util::TagsCompleter (Ui_.TagsLine_);
		Ui_.TagsLine_->AddSelector ();

		Ui_.MainSplitter_->setStretchFactor (0, 5);
		Ui_.MainSplitter_->setStretchFactor (1, 9);

		connect (FlatToFolders_.get (),
				&QAbstractItemModel::rowsInserted,
				Ui_.Feeds_,
				&QTreeView::expand);

		LoadColumnWidth (Ui_.Feeds_, "feeds");
		Ui_.ItemsWidget_->ConstructBrowser ();
		Ui_.ItemsWidget_->LoadUIState ();

		UiStateGuard_ = Util::MakeScopeGuard ([this]
				{
					SaveColumnWidth (Ui_.Feeds_, "feeds");
					Ui_.ItemsWidget_->SaveUIState ();
				});

		handleGroupChannels ();
		XmlSettingsManager::Instance ()->RegisterObject ("GroupChannelsByTags", this, "handleGroupChannels");

		currentChannelChanged ();
	}
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);
        }
    }
}
Example #12
0
ColorListWidget::ColorListWidget(Map* map, MainWindow* window, QWidget* parent)
: QWidget(parent)
, map(map)
, window(window)
{
	react_to_changes = true;
	
	setWhatsThis(Util::makeWhatThis("color_dock_widget.html"));
	
	// Color table
	color_table = new QTableWidget(map->getNumColors(), 7);
	color_table->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::AnyKeyPressed);
	color_table->setSelectionMode(QAbstractItemView::SingleSelection);
	color_table->setSelectionBehavior(QAbstractItemView::SelectRows);
	color_table->verticalHeader()->setVisible(false);
	color_table->setHorizontalHeaderLabels(QStringList() <<
	  QString{} << tr("Name") << tr("Spot color") << tr("CMYK") << tr("RGB") << tr("K.o.") << tr("Opacity") );
	color_table->setItemDelegateForColumn(0, new ColorItemDelegate(this));
	color_table->setItemDelegateForColumn(6, new PercentageDelegate(this));
	color_table->setColumnHidden(6, true);
	
	auto new_button_menu = new QMenu(this);
	(void) new_button_menu->addAction(tr("New"), this, SLOT(newColor()));
	duplicate_action = new_button_menu->addAction(tr("Duplicate"), this, SLOT(duplicateColor()));
	duplicate_action->setIcon(QIcon(QString::fromLatin1(":/images/tool-duplicate.png")));
	
	// Buttons
	auto new_button = newToolButton(QIcon(QString::fromLatin1(":/images/plus.png")), tr("New"));
	new_button->setPopupMode(QToolButton::DelayedPopup); // or MenuButtonPopup
	new_button->setMenu(new_button_menu);
	delete_button = newToolButton(QIcon(QString::fromLatin1(":/images/minus.png")), tr("Delete"));
	
	auto add_remove_layout = new SegmentedButtonLayout();
	add_remove_layout->addWidget(new_button);
	add_remove_layout->addWidget(delete_button);
	
	move_up_button = newToolButton(QIcon(QString::fromLatin1(":/images/arrow-up.png")), tr("Move Up"));
	move_up_button->setAutoRepeat(true);
	move_down_button = newToolButton(QIcon(QString::fromLatin1(":/images/arrow-down.png")), tr("Move Down"));
	move_down_button->setAutoRepeat(true);
	
	auto up_down_layout = new SegmentedButtonLayout();
	up_down_layout->addWidget(move_up_button);
	up_down_layout->addWidget(move_down_button);
	
	// TODO: In Mapper >= 0.6, switch to ColorWidget (or generic) translation context.
	edit_button = newToolButton(QIcon(QString::fromLatin1(":/images/settings.png")), QApplication::translate("OpenOrienteering::MapEditorController", "&Edit").remove(QLatin1Char('&')));
	edit_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	
	auto help_button = newToolButton(QIcon(QString::fromLatin1(":/images/help.png")), tr("Help"));
	help_button->setAutoRaise(true);
	
	// The buttons row layout
	auto buttons_group_layout = new QHBoxLayout();
	buttons_group_layout->addLayout(add_remove_layout);
	buttons_group_layout->addLayout(up_down_layout);
	buttons_group_layout->addWidget(edit_button);
	buttons_group_layout->addWidget(new QLabel(QString::fromLatin1("   ")), 1);
	buttons_group_layout->addWidget(help_button);
	
	// The layout of all components below the table
	auto bottom_layout = new QVBoxLayout();
	QStyleOption style_option(QStyleOption::Version, QStyleOption::SO_DockWidget);
	bottom_layout->setContentsMargins(
		style()->pixelMetric(QStyle::PM_LayoutLeftMargin, &style_option) / 2,
		0, // Covered by the main layout's spacing.
		style()->pixelMetric(QStyle::PM_LayoutRightMargin, &style_option) / 2,
		style()->pixelMetric(QStyle::PM_LayoutBottomMargin, &style_option) / 2
	);
	bottom_layout->addLayout(buttons_group_layout);
	bottom_layout->addWidget(new QLabel(tr("Double-click a color value to open a dialog.")));
	
	// The main layout
	auto layout = new QVBoxLayout();
	layout->setContentsMargins(QMargins());
	layout->addWidget(color_table, 1);
	layout->addLayout(bottom_layout);
	setLayout(layout);
	
	for (int i = 0; i < map->getNumColors(); ++i)
		addRow(i);
	
	auto header_view = color_table->horizontalHeader();
	header_view->setSectionResizeMode(QHeaderView::Interactive);
	header_view->resizeSections(QHeaderView::ResizeToContents);
	header_view->setSectionResizeMode(0, QHeaderView::Fixed); // Color
	header_view->resizeSection(0, 32);
	header_view->setSectionResizeMode(1, QHeaderView::Stretch); // Name
	header_view->setSectionResizeMode(1, QHeaderView::Interactive); // Spot colors
	header_view->setSectionResizeMode(5, QHeaderView::Fixed); // Knockout
	header_view->resizeSection(5, 32);
	header_view->setSectionsClickable(false);
	
	currentCellChange(color_table->currentRow(), 0, 0, 0);	// enable / disable move color buttons
	
	// Connections
	connect(color_table, &QTableWidget::cellChanged, this, &ColorListWidget::cellChange);
	connect(color_table, &QTableWidget::currentCellChanged, this, &ColorListWidget::currentCellChange);
	connect(color_table, &QTableWidget::cellDoubleClicked, this, &ColorListWidget::editCurrentColor);
	
	connect(new_button, &QAbstractButton::clicked, this, &ColorListWidget::newColor);
	connect(delete_button, &QAbstractButton::clicked, this, &ColorListWidget::deleteColor);
	connect(move_up_button, &QAbstractButton::clicked, this, &ColorListWidget::moveColorUp);
	connect(move_down_button, &QAbstractButton::clicked, this, &ColorListWidget::moveColorDown);
	connect(edit_button, &QAbstractButton::clicked, this, &ColorListWidget::editCurrentColor);
	connect(help_button, &QAbstractButton::clicked, this, &ColorListWidget::showHelp);
	
	connect(map, &Map::colorAdded, this, &ColorListWidget::colorAdded);
	connect(map, &Map::colorChanged, this, &ColorListWidget::colorChanged);
	connect(map, &Map::colorDeleted, this, &ColorListWidget::colorDeleted);
}
Example #13
0
// makes sure the column will apear no matter what
void StretchHeaderView::AssertMinimalColumnWidth(int logical) {
  if (sectionSize(logical) < kMinimumColumnWidth) {
    resizeSection(logical, kMinimumColumnWidth);
  }
}