comparison 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
comparison
equal deleted inserted replaced
57:3c802806b74a 58:b7a1c0010ffd
2 #include <QFrame> 2 #include <QFrame>
3 #include <QListWidget> 3 #include <QListWidget>
4 #include <QListWidgetItem> 4 #include <QListWidgetItem>
5 #include <QMessageBox> 5 #include <QMessageBox>
6 #include <QMouseEvent> 6 #include <QMouseEvent>
7 #include <QDebug>
7 8
8 SideBar::SideBar(QWidget* parent) : QListWidget(parent) { 9 SideBar::SideBar(QWidget* parent) : QListWidget(parent) {
9 setFrameShape(QFrame::NoFrame); 10 setFrameShape(QFrame::NoFrame);
10 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 11 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
11 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 12 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
20 font.setPointSize(9); 21 font.setPointSize(9);
21 setFont(font); 22 setFont(font);
22 23
23 connect(this, &QListWidget::currentRowChanged, this, 24 connect(this, &QListWidget::currentRowChanged, this,
24 [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); }); 25 [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); });
26 }
27
28 void SideBar::SetCurrentItem(int index) {
29 qDebug() << AddSeparatorsToIndex(index) << "\n";
30 setCurrentRow(AddSeparatorsToIndex(index));
25 } 31 }
26 32
27 QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) { 33 QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) {
28 QListWidgetItem* item = new QListWidgetItem(this); 34 QListWidgetItem* item = new QListWidgetItem(this);
29 item->setText(name); 35 item->setText(name);
57 setItemWidget(item, line); 63 setItemWidget(item, line);
58 item->setFlags(Qt::NoItemFlags); 64 item->setFlags(Qt::NoItemFlags);
59 return item; 65 return item;
60 } 66 }
61 67
68 int SideBar::AddSeparatorsToIndex(int index) {
69 int i, j;
70 for (i = 0, j = 0; i < index; ) {
71 i++;
72 if (IndexIsSeparator(indexFromItem(item(i))))
73 j++;
74 }
75 return i+j;
76 }
77
62 int SideBar::RemoveSeparatorsFromIndex(int index) { 78 int SideBar::RemoveSeparatorsFromIndex(int index) {
63 int i, j; 79 int i, j;
64 for (i = 0, j = 0; i < index; i++) { 80 for (i = 0, j = 0; i < index; i++) {
65 if (!IndexIsSeparator(indexFromItem(item(i)))) 81 if (!IndexIsSeparator(indexFromItem(item(i))))
66 j++; 82 j++;