Mercurial > minori
annotate src/gui/sidebar.cpp @ 30:4dc59e1a81a3
ci/win32: fix echo-ing to binfmt
ok, so apparently bash AUTOMATICALLY writes a newline to the end of
a file. why does it do this? nobody knows, but we can avoid it by
simply adding the `-n` flag
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 20 Sep 2023 00:53:11 -0400 |
| parents | cde8f67a7c7d |
| children | 2743011a6042 |
| 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, |
| 15 | 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 | |
| 15 | 64 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, |
| 65 const QEvent*) const { | |
| 7 | 66 if (IndexIsSeparator(index)) |
| 67 return QItemSelectionModel::NoUpdate; | |
| 68 return QItemSelectionModel::ClearAndSelect; | |
| 69 } | |
| 70 | |
| 9 | 71 void SideBar::mouseMoveEvent(QMouseEvent* event) { |
| 7 | 72 if (!IndexIsSeparator(indexAt(event->pos()))) |
| 73 setCursor(Qt::PointingHandCursor); | |
| 74 else | |
| 75 unsetCursor(); | |
| 76 QListView::mouseMoveEvent(event); | |
| 77 } | |
| 78 | |
| 9 | 79 #include "gui/moc_sidebar.cpp" |
