comparison src/gui/widgets/sidebar.cc @ 250:c130f47f6f48

*: many many changes e.g. the search page is actually implemented now!
author Paper <paper@paper.us.eu.org>
date Sun, 04 Feb 2024 21:17:17 -0500
parents 4d461ef7d424
children a0eeb2cc7e6d
comparison
equal deleted inserted replaced
249:6b2441c776dd 250:c130f47f6f48
1 #include "gui/widgets/sidebar.h" 1 #include "gui/widgets/sidebar.h"
2 #include <QFrame> 2 #include <QFrame>
3 #include <QListWidget> 3 #include <QListWidget>
4 #include <QListWidgetItem> 4 #include <QListWidgetItem>
5 #include <QMouseEvent> 5 #include <QMouseEvent>
6
7 #include <iostream>
6 8
7 SideBar::SideBar(QWidget* parent) : QListWidget(parent) { 9 SideBar::SideBar(QWidget* parent) : QListWidget(parent) {
8 setFrameShape(QFrame::NoFrame); 10 setFrameShape(QFrame::NoFrame);
9 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 11 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
10 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 12 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
28 return RemoveSeparatorsFromIndex(currentRow()); 30 return RemoveSeparatorsFromIndex(currentRow());
29 } 31 }
30 32
31 void SideBar::SetBackgroundColor(QColor color) { 33 void SideBar::SetBackgroundColor(QColor color) {
32 viewport()->setAutoFillBackground(color != Qt::transparent); 34 viewport()->setAutoFillBackground(color != Qt::transparent);
35
33 QPalette pal(palette()); 36 QPalette pal(palette());
34 pal.setColor(QPalette::Window, color); 37 pal.setColor(QPalette::Window, color);
35 setPalette(pal); 38 setPalette(pal);
36 } 39 }
37 40
64 item->setBackground(QBrush(Qt::transparent)); 67 item->setBackground(QBrush(Qt::transparent));
65 return item; 68 return item;
66 } 69 }
67 70
68 int SideBar::AddSeparatorsToIndex(int index) { 71 int SideBar::AddSeparatorsToIndex(int index) {
69 int i, j; 72 int i = 0, separators = 0, items = 0;
70 for (i = 0, j = 0; i < index;) { 73
71 i++; 74 for (; items <= index; ) {
72 if (IndexIsSeparator(indexFromItem(item(i)))) 75 if (IndexIsSeparator(indexFromItem(item(i++)))) {
73 j++; 76 separators++;
77 } else {
78 items++;
79 }
74 } 80 }
75 return i + j; 81
82 return index + separators;
76 } 83 }
77 84
78 int SideBar::RemoveSeparatorsFromIndex(int index) { 85 int SideBar::RemoveSeparatorsFromIndex(int index) {
79 int i, j; 86 int i = 0, items = 0;
80 for (i = 0, j = 0; i < index; i++) { 87 for (; i < index; i++) {
81 if (!IndexIsSeparator(indexFromItem(item(i)))) 88 if (!IndexIsSeparator(indexFromItem(item(i))))
82 j++; 89 items++;
83 } 90 }
84 return j; 91 return items;
85 } 92 }
86 93
87 bool SideBar::IndexIsSeparator(QModelIndex index) const { 94 bool SideBar::IndexIsSeparator(QModelIndex index) const {
88 return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); 95 return !index.isValid() || !(index.flags() & Qt::ItemIsEnabled);
89 } 96 }
90 97
91 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const { 98 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const {
92 if (IndexIsSeparator(index)) 99 if (IndexIsSeparator(index))
93 return QItemSelectionModel::NoUpdate; 100 return QItemSelectionModel::NoUpdate;