Keep section widths sensible

This commit is contained in:
David Sansome 2009-12-25 17:05:19 +00:00
parent 18b7cc2870
commit 203bd77f38
2 changed files with 41 additions and 2 deletions

View File

@ -16,12 +16,14 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
show_action->setMenu(show_menu_);
connect(show_mapper_, SIGNAL(mapped(int)), SLOT(ToggleVisible(int)));
connect(this, SIGNAL(sectionMoved(int,int,int)), SLOT(SectionMoved()));
}
void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
menu_section_ = logicalIndexAt(e->pos());
if (menu_section_ == -1)
if (menu_section_ == -1 || (
menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
hide_action_->setVisible(false);
else {
hide_action_->setVisible(true);
@ -31,7 +33,7 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
}
show_menu_->clear();
for (int i=0 ; i<model()->columnCount() ; ++i) {
for (int i=0 ; i<count() ; ++i) {
AddColumnAction(i);
}
@ -59,4 +61,37 @@ void PlaylistHeader::ToggleVisible(int section) {
setSectionHidden(section, !isSectionHidden(section));
}
void PlaylistHeader::resizeEvent(QResizeEvent *event) {
if (!event->oldSize().isValid())
return;
const float scale = float(event->size().width()) / event->oldSize().width();
for (int i=0 ; i<count() ; ++i) {
resizeSection(i, sectionSize(i) * scale);
}
}
void PlaylistHeader::SectionMoved() {
for (int i=0 ; i<count() ; ++i) {
setResizeMode(i, Interactive);
if (sectionSize(i) < 20)
resizeSection(i, 50);
}
setResizeMode(logicalIndex(LastVisualIndex()), Stretch);
}
int PlaylistHeader::LastVisualIndex() const {
int ret = -1;
for (int i=0 ; i<count() ; ++i) {
if (isSectionHidden(i))
continue;
ret = qMax(visualIndex(i), ret);
}
return ret;
}

View File

@ -14,13 +14,17 @@ class PlaylistHeader : public QHeaderView {
// QWidget
void contextMenuEvent(QContextMenuEvent* e);
void resizeEvent(QResizeEvent *event);
private slots:
void HideCurrent();
void ToggleVisible(int section);
void SectionMoved();
private:
void AddColumnAction(int index);
int LastVisualIndex() const;
private:
int menu_section_;