Mercurial > minori
view src/gui/sidebar.cpp @ 10:4b198a111713
Update
things actually compile now btw
qttest wants to fuck over the model but that might be my fault so /shrug
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 16 Sep 2023 02:06:01 -0400 |
parents | 5c0397762b53 |
children | fc1bf97c528b |
line wrap: on
line source
#include "gui/sidebar.h" #include <QFrame> #include <QListWidget> #include <QListWidgetItem> #include <QMessageBox> #include <QMouseEvent> SideBar::SideBar(QWidget* parent) : QListWidget(parent) { setObjectName("sidebar"); setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSelectionMode(QAbstractItemView::SingleSelection); setSelectionBehavior(QAbstractItemView::SelectItems); setMouseTracking(true); viewport()->setAutoFillBackground(false); setStyleSheet("font-size: 12px"); connect(this, &QListWidget::currentRowChanged, this, [this](int index) { emit CurrentItemChanged(RemoveSeparatorsFromIndex(index)); }); } QListWidgetItem* SideBar::AddItem(QString name, QIcon icon) { QListWidgetItem* item = new QListWidgetItem(this); item->setText(name); if (!icon.isNull()) item->setIcon(icon); return item; } QIcon SideBar::CreateIcon(const char* file) { QPixmap pixmap(file, "PNG"); QIcon result; result.addPixmap(pixmap, QIcon::Normal); result.addPixmap(pixmap, QIcon::Selected); return result; } QListWidgetItem* SideBar::AddSeparator() { QListWidgetItem* item = new QListWidgetItem(this); setStyleSheet("QListWidget::item:disabled {background: transparent;}"); QFrame* line = new QFrame(this); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); line->setMouseTracking(true); line->setEnabled(false); setItemWidget(item, line); item->setFlags(Qt::NoItemFlags); return item; } int SideBar::RemoveSeparatorsFromIndex(int index) { int i, j; for (i = 0, j = 0; i < index; i++) { if (!IndexIsSeparator(indexFromItem(item(i)))) j++; } return j; } bool SideBar::IndexIsSeparator(QModelIndex index) const { return !(index.isValid() && index.flags() & Qt::ItemIsEnabled); } QItemSelectionModel::SelectionFlags SideBar::selectionCommand(const QModelIndex& index, const QEvent* event) const { if (IndexIsSeparator(index)) return QItemSelectionModel::NoUpdate; return QItemSelectionModel::ClearAndSelect; /* silence unused parameter warnings */ (void)event; } void SideBar::mouseMoveEvent(QMouseEvent* event) { if (!IndexIsSeparator(indexAt(event->pos()))) setCursor(Qt::PointingHandCursor); else unsetCursor(); QListView::mouseMoveEvent(event); } #include "gui/moc_sidebar.cpp"