StretchHeaderView: Refactor code and improve header view
Save what sections are visible, and always save sizes. Do not set section size to zero when hiding sections. When resizing columns in stretch mode, only resize the right column to fit the left column. Fixes #1085
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -42,31 +42,28 @@ class StretchHeaderView : public QHeaderView {
|
||||
|
||||
using ColumnWidthType = double;
|
||||
|
||||
static const int kMinimumColumnWidth;
|
||||
static const int kMagicNumber;
|
||||
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
|
||||
bool is_stretch_enabled() const { return stretch_enabled_; }
|
||||
|
||||
// Serialises the proportional and actual column widths.
|
||||
// Use these instead of QHeaderView::restoreState and QHeaderView::saveState to persist the proportional values directly and avoid floating point errors over time.
|
||||
bool RestoreState(const QByteArray &sdata);
|
||||
QByteArray SaveState() const;
|
||||
QByteArray ResetState();
|
||||
|
||||
// Hides a section and resizes all other sections to fill the gap. Does nothing if you try to hide the last section.
|
||||
void HideSection(const int logical);
|
||||
|
||||
// Shows a section and resizes all other sections to make room.
|
||||
void ShowSection(const int logical);
|
||||
void ShowSection(const int logical_index);
|
||||
|
||||
// Hides a section and resizes all other sections to fill the gap. Does nothing if you try to hide the last section.
|
||||
void HideSection(const int logical_index);
|
||||
|
||||
// Calls either HideSection or ShowSection.
|
||||
void SetSectionHidden(const int logical, const bool hidden);
|
||||
void SetSectionHidden(const int logical_index, const bool hidden);
|
||||
|
||||
// Sets the width of the given column and resizes other columns appropriately.
|
||||
// width is the proportion of the entire width from 0.0 to 1.0.
|
||||
void SetColumnWidth(const int logical, const ColumnWidthType width);
|
||||
|
||||
bool is_stretch_enabled() const { return stretch_enabled_; }
|
||||
void SetColumnWidth(const int logical_index, const ColumnWidthType width);
|
||||
|
||||
public slots:
|
||||
// Changes the stretch mode.
|
||||
@@ -88,7 +85,7 @@ class StretchHeaderView : public QHeaderView {
|
||||
void NormaliseWidths(const QList<int> §ions = QList<int>());
|
||||
|
||||
// Resizes the actual columns to make them match the proportional values in column_widths_.
|
||||
void UpdateWidths(const QList<int> §ions = QList<int>());
|
||||
void ResizeSections(const QList<int> §ions = QList<int>());
|
||||
|
||||
private slots:
|
||||
void SectionResized(const int logical, const int old_size, const int new_size);
|
||||
|
||||
Reference in New Issue
Block a user