Mercurial > minori
comparison src/gui/widgets/sidebar.cpp @ 46:d0adc4aedfc8
*: update...
this commit:
1. consolidates dark theme stuff to dark_theme.cpp
2. creates a new widgets folder to store all of our
custom widgets
3. creates the list settings page in the information
dialog, although much of it is nonfunctional: it
doesn't save, and the status doesn't even get filled
in... we'll fix this later!
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 23 Sep 2023 01:02:15 -0400 |
parents | |
children | b7a1c0010ffd |
comparison
equal
deleted
inserted
replaced
45:4b05bc7668eb | 46:d0adc4aedfc8 |
---|---|
1 #include "gui/widgets/sidebar.h" | |
2 #include <QFrame> | |
3 #include <QListWidget> | |
4 #include <QListWidgetItem> | |
5 #include <QMessageBox> | |
6 #include <QMouseEvent> | |
7 | |
8 SideBar::SideBar(QWidget* parent) : QListWidget(parent) { | |
9 setFrameShape(QFrame::NoFrame); | |
10 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
11 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
12 setSelectionMode(QAbstractItemView::SingleSelection); | |
13 setSelectionBehavior(QAbstractItemView::SelectItems); | |
14 setMouseTracking(true); | |
15 /* FIXME: is there an easy way to do this with palettes? */ | |
16 setStyleSheet("QListWidget::item:disabled { background: transparent }"); | |
17 viewport()->setAutoFillBackground(false); | |
18 | |
19 QFont font; | |
20 font.setPointSize(9); | |
21 setFont(font); | |
22 | |
23 connect(this, &QListWidget::currentRowChanged, this, | |
24 [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); }); | |
25 } | |
26 | |
27 QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) { | |
28 QListWidgetItem* item = new QListWidgetItem(this); | |
29 item->setText(name); | |
30 if (!icon.isNull()) | |
31 item->setIcon(icon); | |
32 return item; | |
33 } | |
34 | |
35 QIcon SideBar::CreateIcon(const char* file) { | |
36 QPixmap pixmap(file, "PNG"); | |
37 QIcon result; | |
38 result.addPixmap(pixmap, QIcon::Normal); | |
39 result.addPixmap(pixmap, QIcon::Selected); | |
40 return result; | |
41 } | |
42 | |
43 QListWidgetItem* SideBar::AddSeparator() { | |
44 QListWidgetItem* item = new QListWidgetItem(this); | |
45 QFrame* line = new QFrame(this); | |
46 line->setFrameShape(QFrame::HLine); | |
47 line->setFrameShadow(QFrame::Sunken); | |
48 line->setMouseTracking(true); | |
49 line->setEnabled(false); | |
50 | |
51 /* | |
52 QPalette pal; | |
53 pal.setColor(QPalette::Window, Qt::transparent); | |
54 line->setPalette(pal); | |
55 */ | |
56 | |
57 setItemWidget(item, line); | |
58 item->setFlags(Qt::NoItemFlags); | |
59 return item; | |
60 } | |
61 | |
62 int SideBar::RemoveSeparatorsFromIndex(int index) { | |
63 int i, j; | |
64 for (i = 0, j = 0; i < index; i++) { | |
65 if (!IndexIsSeparator(indexFromItem(item(i)))) | |
66 j++; | |
67 } | |
68 return j; | |
69 } | |
70 | |
71 bool SideBar::IndexIsSeparator(QModelIndex index) const { | |
72 return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); | |
73 } | |
74 | |
75 QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent*) const { | |
76 if (IndexIsSeparator(index)) | |
77 return QItemSelectionModel::NoUpdate; | |
78 return QItemSelectionModel::ClearAndSelect; | |
79 } | |
80 | |
81 void SideBar::mouseMoveEvent(QMouseEvent* event) { | |
82 if (!IndexIsSeparator(indexAt(event->pos()))) | |
83 setCursor(Qt::PointingHandCursor); | |
84 else | |
85 unsetCursor(); | |
86 QListView::mouseMoveEvent(event); | |
87 } | |
88 | |
89 #include "gui/widgets/moc_sidebar.cpp" |