annotate src/gui/sidebar.cpp @ 36:2743011a6042

*: mass update formatted all source files, converted ALL instances of setStyleSheet() to palettes and fonts (stylesheets suck), and I changed the clang-format file because it wasn't working on my laptop for some reason.
author Paper <mrpapersonic@gmail.com>
date Thu, 21 Sep 2023 15:17:47 -0400
parents cde8f67a7c7d
children 9ae9365dd4ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "gui/sidebar.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
2 #include <QFrame>
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #include <QListWidget>
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 #include <QListWidgetItem>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
5 #include <QMessageBox>
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
6 #include <QMouseEvent>
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
8 SideBar::SideBar(QWidget* parent) : QListWidget(parent) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 setObjectName("sidebar");
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 setFrameShape(QFrame::NoFrame);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
11 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
12 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
13 setSelectionMode(QAbstractItemView::SingleSelection);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
14 setSelectionBehavior(QAbstractItemView::SelectItems);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
15 setMouseTracking(true);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 viewport()->setAutoFillBackground(false);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
17 QFont font;
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
18 font.setPointSize(9);
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
19 setFont(font);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
20 connect(this, &QListWidget::currentRowChanged, this,
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
21 [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); });
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
25 QListWidgetItem* item = new QListWidgetItem(this);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
26 item->setText(name);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27 if (!icon.isNull())
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 item->setIcon(icon);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 return item;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
32 QIcon SideBar::CreateIcon(const char* file) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
33 QPixmap pixmap(file, "PNG");
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
34 QIcon result;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
35 result.addPixmap(pixmap, QIcon::Normal);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
36 result.addPixmap(pixmap, QIcon::Selected);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
37 return result;
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
38 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
39
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 QListWidgetItem* SideBar::AddSeparator() {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 QListWidgetItem* item = new QListWidgetItem(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 QFrame* line = new QFrame(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43 line->setFrameShape(QFrame::HLine);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 line->setFrameShadow(QFrame::Sunken);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
45 line->setMouseTracking(true);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 line->setEnabled(false);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
47
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
48 QPalette pal;
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
49 pal.setColor(QPalette::Window, QColor(0, 0, 0, 0));
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
50 line->setPalette(pal);
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
51
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 setItemWidget(item, line);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
53 item->setFlags(Qt::NoItemFlags);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54 return item;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 }
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
56
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
57 int SideBar::RemoveSeparatorsFromIndex(int index) {
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
58 int i, j;
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
59 for (i = 0, j = 0; i < index; i++) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
60 if (!IndexIsSeparator(indexFromItem(item(i))))
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
61 j++;
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
62 }
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
63 return j;
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
64 }
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
65
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
66 bool SideBar::IndexIsSeparator(QModelIndex index) const {
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
67 return !(index.isValid() && index.flags() & Qt::ItemIsEnabled);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
68 }
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
69
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
70 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const {
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
71 if (IndexIsSeparator(index))
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
72 return QItemSelectionModel::NoUpdate;
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
73 return QItemSelectionModel::ClearAndSelect;
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
74 }
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
75
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
76 void SideBar::mouseMoveEvent(QMouseEvent* event) {
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
77 if (!IndexIsSeparator(indexAt(event->pos())))
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
78 setCursor(Qt::PointingHandCursor);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
79 else
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
80 unsetCursor();
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
81 QListView::mouseMoveEvent(event);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
82 }
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
83
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
84 #include "gui/moc_sidebar.cpp"