Mercurial > minori
diff src/gui/widgets/sidebar.cpp @ 58:b7a1c0010ffd
sidebar: link view menu and sidebar together
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 28 Sep 2023 13:32:21 -0400 |
parents | d0adc4aedfc8 |
children | 4c6dd5999b39 |
line wrap: on
line diff
--- 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++) {