mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-09 03:31:41 +00:00
parent
7f64cc3e0b
commit
903de8188d
@ -1,3 +1,9 @@
|
||||
2015-09-01 Moritz Bunkus <moritz@bunkus.org>
|
||||
|
||||
* MKVToolNix GUI: new feature: the state of all columns in all
|
||||
list/tree views can be reset (both the shown/hidden state as well
|
||||
as their order) from the column's context menu. See #1268.
|
||||
|
||||
2015-08-30 Moritz Bunkus <moritz@bunkus.org>
|
||||
|
||||
* MKVToolNix GUI: new feature: the column headers of all list/tree
|
||||
|
@ -91,8 +91,8 @@ Tab::setupUi() {
|
||||
|
||||
Util::fixScrollAreaBackground(ui->scrollArea);
|
||||
Util::preventScrollingWithoutFocus(this);
|
||||
Util::HeaderViewManager::create(*ui->elements->header(), "ChapterEditor::Elements");
|
||||
Util::HeaderViewManager::create(*ui->tvChNames->header(), "ChapterEditor::ChapterNames");
|
||||
Util::HeaderViewManager::create(*ui->elements, "ChapterEditor::Elements");
|
||||
Util::HeaderViewManager::create(*ui->tvChNames, "ChapterEditor::ChapterNames");
|
||||
|
||||
auto mw = MainWindow::get();
|
||||
connect(ui->elements, &Util::BasicTreeView::customContextMenuRequested, this, &Tab::showChapterContextMenu);
|
||||
|
@ -70,7 +70,7 @@ Tool::setupUi() {
|
||||
ui->jobs->setModel(m_model);
|
||||
|
||||
Util::preventScrollingWithoutFocus(this);
|
||||
Util::HeaderViewManager::create(*ui->jobs->header(), "Jobs::Jobs");
|
||||
Util::HeaderViewManager::create(*ui->jobs, "Jobs::Jobs");
|
||||
|
||||
m_jobsMenu->addAction(m_viewOutputAction);
|
||||
m_jobsMenu->addAction(m_openFolderAction);
|
||||
|
@ -52,7 +52,7 @@ Tab::setupAttachmentsControls() {
|
||||
|
||||
onAttachmentSelectionChanged();
|
||||
|
||||
Util::HeaderViewManager::create(*ui->attachments->header(), "Merge::Attachments");
|
||||
Util::HeaderViewManager::create(*ui->attachments, "Merge::Attachments");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -207,8 +207,8 @@ Tab::setupInputControls() {
|
||||
enableMoveFilesButtons();
|
||||
onTrackSelectionChanged();
|
||||
|
||||
Util::HeaderViewManager::create(*ui->files->header(), "Merge::Files");
|
||||
Util::HeaderViewManager::create(*ui->tracks->header(), "Merge::Tracks");
|
||||
Util::HeaderViewManager::create(*ui->files, "Merge::Files");
|
||||
Util::HeaderViewManager::create(*ui->tracks, "Merge::Tracks");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "common/qt.h"
|
||||
#include "mkvtoolnix-gui/main_window/main_window.h"
|
||||
@ -19,7 +20,7 @@ namespace mtx { namespace gui { namespace Util {
|
||||
class HeaderViewManagerPrivate {
|
||||
friend class HeaderViewManager;
|
||||
|
||||
QHeaderView *headerView{};
|
||||
QTreeView *treeView{};
|
||||
QString name;
|
||||
bool restoringState{};
|
||||
};
|
||||
@ -34,17 +35,19 @@ HeaderViewManager::~HeaderViewManager() {
|
||||
}
|
||||
|
||||
void
|
||||
HeaderViewManager::manage(QHeaderView &headerView,
|
||||
HeaderViewManager::manage(QTreeView &treeView,
|
||||
QString const &name) {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
d->name = name;
|
||||
d->headerView = &headerView;
|
||||
d->name = name;
|
||||
d->treeView = &treeView;
|
||||
|
||||
d->headerView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
auto headerView = d->treeView->header();
|
||||
|
||||
connect(d->headerView, &QHeaderView::customContextMenuRequested, this, &HeaderViewManager::showContextMenu);
|
||||
connect(d->headerView, &QHeaderView::sectionMoved, this, &HeaderViewManager::saveState);
|
||||
headerView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(headerView, &QHeaderView::customContextMenuRequested, this, &HeaderViewManager::showContextMenu);
|
||||
connect(headerView, &QHeaderView::sectionMoved, this, &HeaderViewManager::saveState);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(restoreState()));
|
||||
}
|
||||
@ -57,10 +60,11 @@ HeaderViewManager::saveState() {
|
||||
return;
|
||||
|
||||
QStringList hiddenFlags, visualIndexes;
|
||||
auto headerView = d->treeView->header();
|
||||
|
||||
for (auto logicalIndex = 0, columnCount = d->headerView->count(); logicalIndex < columnCount; ++logicalIndex) {
|
||||
hiddenFlags << Q("%1").arg(d->headerView->isSectionHidden(logicalIndex));
|
||||
visualIndexes << Q("%1").arg(d->headerView->visualIndex(logicalIndex));
|
||||
for (auto logicalIndex = 0, columnCount = headerView->count(); logicalIndex < columnCount; ++logicalIndex) {
|
||||
hiddenFlags << Q("%1").arg(headerView->isSectionHidden(logicalIndex));
|
||||
visualIndexes << Q("%1").arg(headerView->visualIndex(logicalIndex));
|
||||
}
|
||||
|
||||
auto reg = Settings::registry();
|
||||
@ -99,21 +103,23 @@ void
|
||||
HeaderViewManager::restoreHidden(QStringList hiddenFlags) {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
auto const columnCount = d->headerView->count();
|
||||
auto headerView = d->treeView->header();
|
||||
auto const columnCount = headerView->count();
|
||||
|
||||
while (hiddenFlags.count() < columnCount)
|
||||
hiddenFlags << Q("0");
|
||||
|
||||
for (auto logicalIndex = 0; logicalIndex < columnCount; ++logicalIndex)
|
||||
d->headerView->setSectionHidden(logicalIndex, !!hiddenFlags[logicalIndex].toInt());
|
||||
headerView->setSectionHidden(logicalIndex, !!hiddenFlags[logicalIndex].toInt());
|
||||
}
|
||||
|
||||
void
|
||||
HeaderViewManager::restoreVisualIndexes(QStringList visualIndexes) {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
auto headerView = d->treeView->header();
|
||||
auto visualToLogical = QHash<int, int>{};
|
||||
auto const columnCount = d->headerView->count();
|
||||
auto const columnCount = headerView->count();
|
||||
|
||||
while (visualIndexes.count() < columnCount)
|
||||
visualIndexes << Q("%1").arg(visualIndexes.count());
|
||||
@ -131,18 +137,18 @@ HeaderViewManager::restoreVisualIndexes(QStringList visualIndexes) {
|
||||
if ((0 > logicalIndex) || (columnCount <= logicalIndex))
|
||||
continue;
|
||||
|
||||
auto currentVisualIndex = d->headerView->visualIndex(logicalIndex);
|
||||
auto currentVisualIndex = headerView->visualIndex(logicalIndex);
|
||||
|
||||
if (currentVisualIndex != visualIndex)
|
||||
d->headerView->moveSection(currentVisualIndex, visualIndex);
|
||||
headerView->moveSection(currentVisualIndex, visualIndex);
|
||||
}
|
||||
}
|
||||
|
||||
HeaderViewManager *
|
||||
HeaderViewManager::create(QHeaderView &headerView,
|
||||
HeaderViewManager::create(QTreeView &treeView,
|
||||
QString const &name) {
|
||||
auto manager = new HeaderViewManager{&headerView};
|
||||
manager->manage(headerView, name);
|
||||
auto manager = new HeaderViewManager{&treeView};
|
||||
manager->manage(treeView, name);
|
||||
|
||||
return manager;
|
||||
}
|
||||
@ -151,27 +157,52 @@ void
|
||||
HeaderViewManager::toggleColumn(int column) {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
d->headerView->setSectionHidden(column, !d->headerView->isSectionHidden(column));
|
||||
auto headerView = d->treeView->header();
|
||||
headerView->setSectionHidden(column, !headerView->isSectionHidden(column));
|
||||
|
||||
saveState();
|
||||
}
|
||||
|
||||
void
|
||||
HeaderViewManager::resetColumns() {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
d->restoringState = true;
|
||||
|
||||
restoreVisualIndexes({});
|
||||
restoreHidden({});
|
||||
|
||||
d->restoringState = false;
|
||||
|
||||
saveState();
|
||||
|
||||
resizeViewColumnsToContents(d->treeView);
|
||||
}
|
||||
|
||||
void
|
||||
HeaderViewManager::showContextMenu(QPoint const &pos) {
|
||||
Q_D(HeaderViewManager);
|
||||
|
||||
auto menu = new QMenu{d->headerView};
|
||||
auto headerView = d->treeView->header();
|
||||
auto menu = new QMenu{headerView};
|
||||
auto action = new QAction{menu};
|
||||
|
||||
for (int column = 1, columnCount = d->headerView->count(); column < columnCount; ++column) {
|
||||
action->setText(QY("Reset all columns"));
|
||||
menu->addAction(action);
|
||||
menu->addSeparator();
|
||||
|
||||
connect(action, &QAction::triggered, this, &HeaderViewManager::resetColumns);
|
||||
|
||||
for (int column = 1, columnCount = headerView->count(); column < columnCount; ++column) {
|
||||
auto action = new QAction{menu};
|
||||
auto text = d->headerView->model()->headerData(column, Qt::Horizontal, Util::HiddenDescriptionRole).toString();
|
||||
auto text = headerView->model()->headerData(column, Qt::Horizontal, Util::HiddenDescriptionRole).toString();
|
||||
|
||||
if (text.isEmpty())
|
||||
text = d->headerView->model()->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString();
|
||||
text = headerView->model()->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString();
|
||||
|
||||
action->setText(text);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(!d->headerView->isSectionHidden(column));
|
||||
action->setChecked(!headerView->isSectionHidden(column));
|
||||
|
||||
menu->addAction(action);
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QHeaderView;
|
||||
class QString;
|
||||
class QTreeView;
|
||||
|
||||
namespace mtx { namespace gui { namespace Util {
|
||||
|
||||
@ -18,7 +18,7 @@ public:
|
||||
explicit HeaderViewManager(QObject *parent = nullptr);
|
||||
virtual ~HeaderViewManager();
|
||||
|
||||
void manage(QHeaderView &headerView, QString const &name);
|
||||
void manage(QTreeView &treeView, QString const &name);
|
||||
|
||||
public slots:
|
||||
void saveState();
|
||||
@ -29,7 +29,7 @@ public slots:
|
||||
void resetColumns();
|
||||
|
||||
public:
|
||||
static HeaderViewManager *create(QHeaderView &headerView, QString const &name);
|
||||
static HeaderViewManager *create(QTreeView &treeView, QString const &name);
|
||||
|
||||
protected:
|
||||
void restoreHidden(QStringList hiddenFlags);
|
||||
|
@ -3,20 +3,12 @@
|
||||
#include <QAbstractItemView>
|
||||
#include <QItemSelection>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QTableView>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "mkvtoolnix-gui/util/model.h"
|
||||
|
||||
namespace mtx { namespace gui { namespace Util {
|
||||
|
||||
void
|
||||
resizeViewColumnsToContents(QTableView *view) {
|
||||
auto columnCount = view->model()->columnCount(QModelIndex{});
|
||||
for (auto column = 0; columnCount > column; ++column)
|
||||
view->resizeColumnToContents(column);
|
||||
}
|
||||
|
||||
void
|
||||
resizeViewColumnsToContents(QTreeView *view) {
|
||||
auto columnCount = view->model()->columnCount(QModelIndex{});
|
||||
|
@ -6,7 +6,6 @@
|
||||
class QAbstractItemView;
|
||||
class QItemSelection;
|
||||
class QItemSelectionModel;
|
||||
class QTableView;
|
||||
class QTreeView;
|
||||
|
||||
namespace mtx { namespace gui { namespace Util {
|
||||
@ -23,7 +22,6 @@ enum MtxGuiRoles {
|
||||
HiddenDescriptionRole,
|
||||
};
|
||||
|
||||
void resizeViewColumnsToContents(QTableView *view);
|
||||
void resizeViewColumnsToContents(QTreeView *view);
|
||||
int numSelectedRows(QItemSelection &selection);
|
||||
QModelIndex selectedRowIdx(QItemSelection const &selection);
|
||||
|
Loading…
Reference in New Issue
Block a user