Mercurial > minori
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 |
rev | line source |
---|---|
9 | 1 #include "gui/sidebar.h" |
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 | 5 #include <QMessageBox> |
7 | 6 #include <QMouseEvent> |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
7 |
9 | 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 | 11 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
12 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
7 | 13 setSelectionMode(QAbstractItemView::SingleSelection); |
14 setSelectionBehavior(QAbstractItemView::SelectItems); | |
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 | 17 QFont font; |
18 font.setPointSize(9); | |
19 setFont(font); | |
9 | 20 connect(this, &QListWidget::currentRowChanged, this, |
15 | 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 | 25 QListWidgetItem* item = new QListWidgetItem(this); |
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 | 32 QIcon SideBar::CreateIcon(const char* file) { |
33 QPixmap pixmap(file, "PNG"); | |
34 QIcon result; | |
35 result.addPixmap(pixmap, QIcon::Normal); | |
36 result.addPixmap(pixmap, QIcon::Selected); | |
37 return result; | |
38 } | |
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 | 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 | 47 |
48 QPalette pal; | |
49 pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); | |
50 line->setPalette(pal); | |
51 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
52 setItemWidget(item, line); |
7 | 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 | 56 |
57 int SideBar::RemoveSeparatorsFromIndex(int index) { | |
58 int i, j; | |
59 for (i = 0, j = 0; i < index; i++) { | |
9 | 60 if (!IndexIsSeparator(indexFromItem(item(i)))) |
61 j++; | |
7 | 62 } |
63 return j; | |
64 } | |
65 | |
66 bool SideBar::IndexIsSeparator(QModelIndex index) const { | |
67 return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); | |
68 } | |
69 | |
36 | 70 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const { |
7 | 71 if (IndexIsSeparator(index)) |
72 return QItemSelectionModel::NoUpdate; | |
73 return QItemSelectionModel::ClearAndSelect; | |
74 } | |
75 | |
9 | 76 void SideBar::mouseMoveEvent(QMouseEvent* event) { |
7 | 77 if (!IndexIsSeparator(indexAt(event->pos()))) |
78 setCursor(Qt::PointingHandCursor); | |
79 else | |
80 unsetCursor(); | |
81 QListView::mouseMoveEvent(event); | |
82 } | |
83 | |
9 | 84 #include "gui/moc_sidebar.cpp" |