diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2b94280..01b0818 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -15,7 +15,7 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { move(0, 0); - setFixedSize(600, 555); + setFixedSize(590, 555); setWindowTitle(tr("Slide Controller 9000")); const auto mainWidget = new QWidget(this); const auto rootLyt = new QVBoxLayout; diff --git a/src/slideview.cpp b/src/slideview.cpp index 198b3c8..69177b4 100644 --- a/src/slideview.cpp +++ b/src/slideview.cpp @@ -8,15 +8,16 @@ #include #include +#include #include +#include #include -#include #include "slideview.hpp" SlideView::SlideView(QWidget *parent): QWidget(parent) { - auto lyt = new QVBoxLayout(this); - m_songSelector = new QComboBox(this); + auto lyt = new QHBoxLayout(this); + m_songSelector = new QListWidget(this); m_slideTable = new QTableWidget(this); auto header = m_slideTable->horizontalHeader(); header->setVisible(false); @@ -35,17 +36,22 @@ SlideView::SlideView(QWidget *parent): QWidget(parent) { QString SlideView::getNextSong() const { const auto cnt = m_songSelector->count(); - const auto idx = m_songSelector->currentIndex() + 1; + const auto idx = m_songSelector->currentRow() + 1; if (idx < cnt) { - return m_songSelector->itemText(idx); + return m_songSelector->currentItem()->text(); } return ""; } void SlideView::pollUpdate(QString songName, int slide) { - if (songName != m_currentSong) { + auto songItems = m_songSelector->findItems(songName, Qt::MatchExactly); + if (songItems.size() < 1) { + return; + } + auto songItem = songItems.first(); + if (songItem != m_songSelector->currentItem()) { m_currentSong = songName; - m_songSelector->setCurrentText(songName); + m_songSelector->setCurrentItem(songItem); } if (slide != m_currentSlide) { m_currentSlide = slide; @@ -54,7 +60,8 @@ void SlideView::pollUpdate(QString songName, int slide) { } void SlideView::changeSong(int song) { - if (m_songSelector->currentText() != m_currentSong) { + auto songItem = m_songSelector->item(song); + if (songItem->text() != m_currentSong) { emit songChanged(song); } } diff --git a/src/slideview.hpp b/src/slideview.hpp index 6abf69f..78f2308 100644 --- a/src/slideview.hpp +++ b/src/slideview.hpp @@ -13,12 +13,14 @@ class SlideView: public QWidget { Q_OBJECT private: class QTableWidget *m_slideTable = nullptr; - class QComboBox *m_songSelector = nullptr; + class QListWidget *m_songSelector = nullptr; QString m_currentSong; int m_currentSlide = -1; + public: explicit SlideView(QWidget *parent = nullptr); + [[nodiscard]] QString getNextSong() const; public slots: