Mercurial > minori
changeset 58:b7a1c0010ffd
sidebar: link view menu and sidebar together
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 28 Sep 2023 13:32:21 -0400 |
parents | 3c802806b74a |
children | 327e9a5c72f1 |
files | include/gui/widgets/sidebar.h src/gui/widgets/sidebar.cpp src/gui/window.cpp |
diffstat | 3 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/include/gui/widgets/sidebar.h Thu Sep 28 13:09:11 2023 -0400 +++ b/include/gui/widgets/sidebar.h Thu Sep 28 13:32:21 2023 -0400 @@ -16,10 +16,14 @@ signals: void CurrentItemChanged(int index); + public slots: + void SetCurrentItem(int index); + protected: virtual void mouseMoveEvent(QMouseEvent* event) override; QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex& index, const QEvent* event) const override; int RemoveSeparatorsFromIndex(int index); + int AddSeparatorsToIndex(int index); }; #endif // __gui__sidebar_h
--- a/src/gui/widgets/sidebar.cpp Thu Sep 28 13:09:11 2023 -0400 +++ b/src/gui/widgets/sidebar.cpp Thu Sep 28 13:32:21 2023 -0400 @@ -4,6 +4,7 @@ #include <QListWidgetItem> #include <QMessageBox> #include <QMouseEvent> +#include <QDebug> SideBar::SideBar(QWidget* parent) : QListWidget(parent) { setFrameShape(QFrame::NoFrame); @@ -24,6 +25,11 @@ [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); }); } +void SideBar::SetCurrentItem(int index) { + qDebug() << AddSeparatorsToIndex(index) << "\n"; + setCurrentRow(AddSeparatorsToIndex(index)); +} + QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) { QListWidgetItem* item = new QListWidgetItem(this); item->setText(name); @@ -59,6 +65,16 @@ return item; } +int SideBar::AddSeparatorsToIndex(int index) { + int i, j; + for (i = 0, j = 0; i < index; ) { + i++; + if (IndexIsSeparator(indexFromItem(item(i)))) + j++; + } + return i+j; +} + int SideBar::RemoveSeparatorsFromIndex(int index) { int i, j; for (i = 0, j = 0; i < index; i++) {
--- a/src/gui/window.cpp Thu Sep 28 13:09:11 2023 -0400 +++ b/src/gui/window.cpp Thu Sep 28 13:32:21 2023 -0400 @@ -64,7 +64,7 @@ stack->addWidget(new TorrentsWidget(main_widget)); connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); - sidebar->setCurrentRow(2); + sidebar->SetCurrentItem((int)Pages::ANIME_LIST); /* Menu Bar */ QAction* action; @@ -145,9 +145,9 @@ action = pages_group->addAction(menu->addAction(tr("&Anime List"))); page_to_index_map[action] = 1; - action->setCheckable(true); action->setChecked(true); + action = pages_group->addAction(menu->addAction(tr("&History"))); action->setCheckable(true); page_to_index_map[action] = 2; @@ -168,12 +168,12 @@ action->setCheckable(true); page_to_index_map[action] = 6; - connect(stack, &QStackedWidget::currentChanged, this, [pages_group, sidebar](int index){ + connect(sidebar, &SideBar::CurrentItemChanged, this, [pages_group](int index){ pages_group->actions()[index]->setChecked(true); }); - connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { - stack->setCurrentIndex(page_to_index_map.at(action)); + connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, sidebar](QAction* action) { + sidebar->SetCurrentItem(page_to_index_map.at(action)); }); menu->addSeparator();