- if (action->isChecked()) {
- const int index = keys.indexOf(info) + 1;
- visibleRoles.insert(index, selectedRole);
- infoList.insert(index, info);
+ menu->addSeparator();
+
+ QActionGroup* widthsGroup = new QActionGroup(menu);
+ const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
+
+ QAction* autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
+ autoAdjustWidthsAction->setCheckable(true);
+ autoAdjustWidthsAction->setChecked(autoColumnWidths);
+ autoAdjustWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* customWidthsAction = menu->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
+ customWidthsAction->setCheckable(true);
+ customWidthsAction->setChecked(!autoColumnWidths);
+ customWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* action = menu->exec(pos.toPoint());
+ if (menu && action) {
+ KItemListHeader* header = view->header();
+
+ if (action == autoAdjustWidthsAction) {
+ // Clear the column-widths from the viewproperties and turn on
+ // the automatic resizing of the columns
+ props.setHeaderColumnWidths(QList<int>());
+ header->setAutomaticColumnResizing(true);
+ } else if (action == customWidthsAction) {
+ // Apply the current column-widths as custom column-widths and turn
+ // off the automatic resizing of the columns
+ QList<int> columnWidths;
+ foreach (const QByteArray& role, view->visibleRoles()) {
+ columnWidths.append(header->columnWidth(role));
+ }
+ props.setHeaderColumnWidths(columnWidths);
+ header->setAutomaticColumnResizing(false);