Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/widgets/sidebar.cc Wed Jan 24 20:18:59 2024 -0500 +++ b/src/gui/widgets/sidebar.cc Sun Feb 04 21:17:17 2024 -0500 @@ -4,6 +4,8 @@ #include <QListWidgetItem> #include <QMouseEvent> +#include <iostream> + SideBar::SideBar(QWidget* parent) : QListWidget(parent) { setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -30,6 +32,7 @@ void SideBar::SetBackgroundColor(QColor color) { viewport()->setAutoFillBackground(color != Qt::transparent); + QPalette pal(palette()); pal.setColor(QPalette::Window, color); setPalette(pal); @@ -66,26 +69,30 @@ } int SideBar::AddSeparatorsToIndex(int index) { - int i, j; - for (i = 0, j = 0; i < index;) { - i++; - if (IndexIsSeparator(indexFromItem(item(i)))) - j++; + int i = 0, separators = 0, items = 0; + + for (; items <= index; ) { + if (IndexIsSeparator(indexFromItem(item(i++)))) { + separators++; + } else { + items++; + } } - return i + j; + + return index + separators; } int SideBar::RemoveSeparatorsFromIndex(int index) { - int i, j; - for (i = 0, j = 0; i < index; i++) { + int i = 0, items = 0; + for (; i < index; i++) { if (!IndexIsSeparator(indexFromItem(item(i)))) - j++; + items++; } - return j; + return items; } bool SideBar::IndexIsSeparator(QModelIndex index) const { - return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); + return !index.isValid() || !(index.flags() & Qt::ItemIsEnabled); } QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const {