Mercurial > minori
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/widgets/sidebar.cpp Sat Sep 23 01:02:15 2023 -0400 @@ -0,0 +1,89 @@ +#include "gui/widgets/sidebar.h" +#include <QFrame> +#include <QListWidget> +#include <QListWidgetItem> +#include <QMessageBox> +#include <QMouseEvent> + +SideBar::SideBar(QWidget* parent) : QListWidget(parent) { + setFrameShape(QFrame::NoFrame); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setSelectionMode(QAbstractItemView::SingleSelection); + setSelectionBehavior(QAbstractItemView::SelectItems); + setMouseTracking(true); + /* FIXME: is there an easy way to do this with palettes? */ + setStyleSheet("QListWidget::item:disabled { background: transparent }"); + viewport()->setAutoFillBackground(false); + + QFont font; + font.setPointSize(9); + setFont(font); + + 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); + QFrame* line = new QFrame(this); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + line->setMouseTracking(true); + line->setEnabled(false); + + /* + QPalette pal; + pal.setColor(QPalette::Window, Qt::transparent); + line->setPalette(pal); + */ + + 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*) const { + if (IndexIsSeparator(index)) + return QItemSelectionModel::NoUpdate; + return QItemSelectionModel::ClearAndSelect; +} + +void SideBar::mouseMoveEvent(QMouseEvent* event) { + if (!IndexIsSeparator(indexAt(event->pos()))) + setCursor(Qt::PointingHandCursor); + else + unsetCursor(); + QListView::mouseMoveEvent(event); +} + +#include "gui/widgets/moc_sidebar.cpp"