mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Add context menu to pick what columns are visible in the classic comics view
This commit is contained in:
parent
e6e5208001
commit
3747c71c66
@ -60,10 +60,7 @@ ClassicComicsView::ClassicComicsView(QWidget *parent)
|
|||||||
sVertical->addWidget(comics);
|
sVertical->addWidget(comics);
|
||||||
|
|
||||||
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
tableView->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
// config--------------------------------------------------
|
|
||||||
if (settings->contains(COMICS_VIEW_HEADERS))
|
|
||||||
tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray());
|
|
||||||
|
|
||||||
// connections---------------------------------------------
|
// connections---------------------------------------------
|
||||||
connect(tableView, &QAbstractItemView::clicked, this, &ClassicComicsView::centerComicFlow);
|
connect(tableView, &QAbstractItemView::clicked, this, &ClassicComicsView::centerComicFlow);
|
||||||
@ -75,6 +72,7 @@ ClassicComicsView::ClassicComicsView(QWidget *parent)
|
|||||||
connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &ClassicComicsView::saveTableHeadersStatus);
|
connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &ClassicComicsView::saveTableHeadersStatus);
|
||||||
connect(comicFlow, &QWidget::customContextMenuRequested, this, &ClassicComicsView::requestedViewContextMenu);
|
connect(comicFlow, &QWidget::customContextMenuRequested, this, &ClassicComicsView::requestedViewContextMenu);
|
||||||
connect(tableView, &QWidget::customContextMenuRequested, this, &ClassicComicsView::requestedItemContextMenu);
|
connect(tableView, &QWidget::customContextMenuRequested, this, &ClassicComicsView::requestedItemContextMenu);
|
||||||
|
connect(tableView->horizontalHeader(), &QWidget::customContextMenuRequested, this, &ClassicComicsView::requestedHeaderContextMenu);
|
||||||
layout->addWidget(sVertical);
|
layout->addWidget(sVertical);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
@ -84,8 +82,13 @@ ClassicComicsView::ClassicComicsView(QWidget *parent)
|
|||||||
sVertical->setCollapsible(1, false);
|
sVertical->setCollapsible(1, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (settings->contains(COMICS_VIEW_FLOW_SPLITTER_STATUS))
|
if (settings->contains(COMICS_VIEW_FLOW_SPLITTER_STATUS)) {
|
||||||
sVertical->restoreState(settings->value(COMICS_VIEW_FLOW_SPLITTER_STATUS).toByteArray());
|
try {
|
||||||
|
sVertical->restoreState(settings->value(COMICS_VIEW_FLOW_SPLITTER_STATUS).toByteArray());
|
||||||
|
} catch (...) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// hide flow widgets
|
// hide flow widgets
|
||||||
hideFlowViewAction = new QAction(this);
|
hideFlowViewAction = new QAction(this);
|
||||||
@ -150,34 +153,38 @@ void ClassicComicsView::setModel(ComicModel *model)
|
|||||||
#else
|
#else
|
||||||
tableView->horizontalHeader()->setMovable(true);
|
tableView->horizontalHeader()->setMovable(true);
|
||||||
#endif
|
#endif
|
||||||
// TODO parametrizar la configuración de las columnas
|
|
||||||
/*if(!settings->contains(COMICS_VIEW_HEADERS))
|
|
||||||
{*/
|
|
||||||
for (int i = 0; i < tableView->horizontalHeader()->count(); i++)
|
|
||||||
tableView->horizontalHeader()->hideSection(i);
|
|
||||||
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::Number);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::Title);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::FileName);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::NumPages);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::Hash); // Size is part of the Hash...TODO add Columns::Size to Columns
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::ReadColumn);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::CurrentPage);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::PublicationDate);
|
|
||||||
tableView->horizontalHeader()->showSection(ComicModel::Rating);
|
|
||||||
//}
|
|
||||||
|
|
||||||
// debido a un bug, qt4 no es capaz de ajustar el ancho teniendo en cuenta todas la filas (no sólo las visibles)
|
|
||||||
// así que se ecala la primera vez y después se deja el control al usuario.
|
|
||||||
// if(!settings->contains(COMICS_VIEW_HEADERS))
|
|
||||||
|
|
||||||
QStringList paths = model->getPaths(model->getCurrentPath()); // TODO ComicsView: get currentpath from somewhere currentPath());
|
QStringList paths = model->getPaths(model->getCurrentPath()); // TODO ComicsView: get currentpath from somewhere currentPath());
|
||||||
comicFlow->setImagePaths(paths);
|
comicFlow->setImagePaths(paths);
|
||||||
comicFlow->setMarks(model->getReadList());
|
comicFlow->setMarks(model->getReadList());
|
||||||
// comicFlow->setFocus(Qt::OtherFocusReason);
|
|
||||||
|
|
||||||
if (settings->contains(COMICS_VIEW_HEADERS))
|
bool loadDefaults = false;
|
||||||
tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray());
|
if (settings->contains(COMICS_VIEW_HEADERS)) {
|
||||||
|
try {
|
||||||
|
loadDefaults = !tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray());
|
||||||
|
} catch (...) {
|
||||||
|
loadDefaults = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadDefaults) {
|
||||||
|
// default columns and order
|
||||||
|
for (int i = 0; i < tableView->horizontalHeader()->count(); i++)
|
||||||
|
tableView->horizontalHeader()->hideSection(i);
|
||||||
|
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::Number);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::Title);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::FileName);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::NumPages);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::Size);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::ReadColumn);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::CurrentPage);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::PublicationDate);
|
||||||
|
tableView->horizontalHeader()->showSection(ComicModel::Rating);
|
||||||
|
|
||||||
|
tableView->horizontalHeader()->moveSection(ComicModel::CurrentPage, 3);
|
||||||
|
tableView->horizontalHeader()->moveSection(ComicModel::Rating, 12);
|
||||||
|
tableView->horizontalHeader()->moveSection(ComicModel::Size, 5);
|
||||||
|
}
|
||||||
|
|
||||||
tableView->resizeColumnsToContents();
|
tableView->resizeColumnsToContents();
|
||||||
|
|
||||||
@ -290,6 +297,27 @@ void ClassicComicsView::requestedItemContextMenu(const QPoint &point)
|
|||||||
emit customContextMenuItemRequested(tableView->mapTo(this, point));
|
emit customContextMenuItemRequested(tableView->mapTo(this, point));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassicComicsView::requestedHeaderContextMenu(const QPoint &point)
|
||||||
|
{
|
||||||
|
QMenu menu;
|
||||||
|
|
||||||
|
for (int i = 0; i < tableView->model()->columnCount(); ++i) {
|
||||||
|
auto title = tableView->model()->headerData(i, Qt::Horizontal).toString();
|
||||||
|
|
||||||
|
if (!title.isEmpty()) {
|
||||||
|
auto action = menu.addAction(tableView->model()->headerData(i, Qt::Horizontal).toString());
|
||||||
|
action->setCheckable(true);
|
||||||
|
action->setChecked(!tableView->isColumnHidden(i));
|
||||||
|
connect(action, &QAction::toggled, tableView, [this, i](bool checked) {
|
||||||
|
tableView->horizontalHeader()->setSectionHidden(i, !checked);
|
||||||
|
});
|
||||||
|
connect(action, &QAction::toggled, this, &ClassicComicsView::saveTableHeadersStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.exec(this->tableView->horizontalHeader()->mapToGlobal(point));
|
||||||
|
}
|
||||||
|
|
||||||
void ClassicComicsView::setShowMarks(bool show)
|
void ClassicComicsView::setShowMarks(bool show)
|
||||||
{
|
{
|
||||||
comicFlow->setShowMarks(show);
|
comicFlow->setShowMarks(show);
|
||||||
|
@ -52,6 +52,7 @@ protected slots:
|
|||||||
void hideComicFlow(bool hide);
|
void hideComicFlow(bool hide);
|
||||||
void requestedViewContextMenu(const QPoint &point);
|
void requestedViewContextMenu(const QPoint &point);
|
||||||
void requestedItemContextMenu(const QPoint &point);
|
void requestedItemContextMenu(const QPoint &point);
|
||||||
|
void requestedHeaderContextMenu(const QPoint &point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
YACReaderTableView *tableView;
|
YACReaderTableView *tableView;
|
||||||
|
Loading…
Reference in New Issue
Block a user