Mercurial > minori
annotate src/gui/sidebar.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 10 Sep 2023 03:59:16 -0400 |
| parents | src/sidebar.cpp@07a9095eaeed |
| children | fc1bf97c528b |
| 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); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
17 setStyleSheet("font-size: 12px"); |
| 9 | 18 connect(this, &QListWidget::currentRowChanged, this, |
| 19 [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
|
20 } |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
21 |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
22 QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) { |
| 9 | 23 QListWidgetItem* item = new QListWidgetItem(this); |
| 24 item->setText(name); | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
25 if (!icon.isNull()) |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
26 item->setIcon(icon); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
27 return item; |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
28 } |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
29 |
| 9 | 30 QIcon SideBar::CreateIcon(const char* file) { |
| 31 QPixmap pixmap(file, "PNG"); | |
| 32 QIcon result; | |
| 33 result.addPixmap(pixmap, QIcon::Normal); | |
| 34 result.addPixmap(pixmap, QIcon::Selected); | |
| 35 return result; | |
| 36 } | |
| 37 | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
38 QListWidgetItem* SideBar::AddSeparator() { |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
39 QListWidgetItem* item = new QListWidgetItem(this); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
40 setStyleSheet("QListWidget::item:disabled {background: transparent;}"); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
41 QFrame* line = new QFrame(this); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
42 line->setFrameShape(QFrame::HLine); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
43 line->setFrameShadow(QFrame::Sunken); |
| 7 | 44 line->setMouseTracking(true); |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
45 line->setEnabled(false); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
46 setItemWidget(item, line); |
| 7 | 47 item->setFlags(Qt::NoItemFlags); |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
48 return item; |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
49 } |
| 7 | 50 |
| 51 int SideBar::RemoveSeparatorsFromIndex(int index) { | |
| 52 int i, j; | |
| 53 for (i = 0, j = 0; i < index; i++) { | |
| 9 | 54 if (!IndexIsSeparator(indexFromItem(item(i)))) |
| 55 j++; | |
| 7 | 56 } |
| 57 return j; | |
| 58 } | |
| 59 | |
| 60 bool SideBar::IndexIsSeparator(QModelIndex index) const { | |
| 61 return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); | |
| 62 } | |
| 63 | |
| 9 | 64 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent* event) const { |
| 7 | 65 if (IndexIsSeparator(index)) |
| 66 return QItemSelectionModel::NoUpdate; | |
| 67 return QItemSelectionModel::ClearAndSelect; | |
| 68 /* silence unused parameter warnings */ | |
| 69 (void)event; | |
| 70 } | |
| 71 | |
| 9 | 72 void SideBar::mouseMoveEvent(QMouseEvent* event) { |
| 7 | 73 if (!IndexIsSeparator(indexAt(event->pos()))) |
| 74 setCursor(Qt::PointingHandCursor); | |
| 75 else | |
| 76 unsetCursor(); | |
| 77 QListView::mouseMoveEvent(event); | |
| 78 } | |
| 79 | |
| 9 | 80 #include "gui/moc_sidebar.cpp" |
