123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- /*
- Copyright (C) 2025 mio <stigma@disroot.org>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- #include "playlist_window.h"
- #include "playlist.h"
- #include <tqlayout.h>
- #include <tqpalette.h>
- #include <tqtable.h>
- #include <tqpainter.h>
- #include <tdefilemetainfo.h>
- #include <tdelocale.h>
- #include <tdemenubar.h>
- class PlaylistTable : public TQTable
- {
- public:
- PlaylistTable(TQWidget *parent, const char *name)
- : TQTable(parent, name)
- , m_currentRow(0)
- {}
- void paintCell(TQPainter *p, int row, int col, const TQRect& cr, bool selected, const TQColorGroup& cg) override
- {
- if (row == m_currentRow)
- {
- // TODO: This should be configurable via settings.
- TQColorGroup group = cg;
- group.setColor(TQColorGroup::Text, palette().active().buttonText());
- group.setBrush(TQColorGroup::Base, palette().active().button());
- TQTable::paintCell(p, row, col, cr, selected, group);
- }
- else
- {
- TQTable::paintCell(p, row, col, cr, selected, cg);
- }
- }
- void setCurrentRow(int row)
- {
- m_currentRow = row;
- repaintContents(visibleRect());
- }
- private:
- int m_currentRow;
- };
- PlaylistWindow::PlaylistWindow(Playlist *playlist, TQWidget *parent, const char *name)
- : TQWidget(parent, name, WType_TopLevel)
- , m_playlist(playlist)
- {
- setCaption(i18n("Aster - Playlist"));
- auto layout = new TQVBoxLayout(this);
- m_menuBar = new KMenuBar(this, "playlist_window_menubar");
- m_menuBar->insertItem("Open File...", 0); // TODO: Should this just emit a signal?
- m_menuBar->insertItem("Remove Item", this, TQ_SLOT(slotRemoveCurrent()), Key_Delete, 1);
- m_menuBar->setItemEnabled(1, m_playlist->count() > 1);
- m_table = new PlaylistTable(this, "playlist_window_table");
- m_table->setFocusStyle(TQTable::FollowStyle);
- m_table->setLeftMargin(0);
- m_table->setNumCols(2);
- m_table->setReadOnly(true);
- m_table->setSelectionMode(TQTable::SingleRow);
- m_table->horizontalHeader()->setLabel(0, i18n("Title"));
- m_table->horizontalHeader()->setLabel(1, i18n("Duration"));
- m_table->setColumnStretchable(0, true);
- connect(m_playlist, TQ_SIGNAL(currentIndexChanged(int)), TQ_SLOT(slotIndexChanged(int)));
- connect(m_playlist, TQ_SIGNAL(itemsInserted(int, int)), TQ_SLOT(slotItemsInserted(int, int)));
- connect(m_playlist, TQ_SIGNAL(itemsRemoved(int, int)), TQ_SLOT(slotItemsRemoved(int, int)));
- connect(m_table, TQ_SIGNAL(doubleClicked(int, int, int, const TQPoint&)),
- TQ_SLOT(slotTableDoubleClicked(int, int, int, const TQPoint&)));
- layout->add(m_menuBar);
- layout->add(m_table);
- /* FIXME: No way to iterate playlist */
- m_table->insertRows(0, m_playlist->count());
- for (size_t i = 0; i < m_playlist->count(); ++i)
- {
- KFileMetaInfo info(m_playlist->at(i));
- if (info.isEmpty())
- {
- m_table->setText(i, 0, m_playlist->at(i).fileName());
- m_table->setText(i, 1, TQString::fromLatin1("00:00:00"));
- }
- else
- {
- m_table->setText(i, 0, "TITLE!");
- m_table->setText(i, 1, TQString::fromLatin1("00:00:00"));
- }
- }
- static_cast<PlaylistTable*>(m_table)->setCurrentRow(m_playlist->currentIndex());
- resize(500, 200);
- move(parent->x() + (parent->width() / 2) - (width() / 2),
- parent->y() + (parent->height() / 2) - (height() / 2));
- }
- void PlaylistWindow::keyReleaseEvent(TQKeyEvent *event)
- {
- switch (event->key())
- {
- case Key_Enter:
- case Key_Return: {
- int current = m_table->selection(m_table->currentSelection()).topRow();
- if (current == m_playlist->currentIndex()) {
- // Should this restart? (as with double-clicking)
- return;
- }
- m_playlist->setCurrentIndex(current);
- break;
- }
- default:
- break;
- }
- }
- void PlaylistWindow::slotIndexChanged(int index)
- {
- static_cast<PlaylistTable*>(m_table)->setCurrentRow(index);
- }
- void PlaylistWindow::slotItemsInserted(int start, int end)
- {
- const int count = end - start;
- m_table->insertRows(m_table->numRows(), count);
- for (int i = 0; i < count; ++i)
- {
- KFileMetaInfo info(m_playlist->at(start + i));
- if (info.isEmpty())
- {
- m_table->setText(start + i, 0, m_playlist->at(start + i).fileName());
- m_table->setText(start + i, 1, TQString::fromLatin1("00:00:00"));
- }
- else
- {
- m_table->setText(start + i, 0, "TITLE!");
- m_table->setText(start + i, 1, TQString::fromLatin1("00:00:00"));
- }
- }
- // Ensure the 'remove item' is active.
- m_menuBar->setItemEnabled(1, true);
- }
- void PlaylistWindow::slotItemsRemoved(int start, int end)
- {
- m_table->removeRow(start);
- if (m_playlist->count() == 0)
- m_menuBar->setItemEnabled(1, false);
- tqWarning("PlaylistWindow::slotItemsRemoved: implementation isn't finished as multiple selections are not supported.");
- }
- void PlaylistWindow::slotRemoveCurrent()
- {
- m_playlist->remove(m_table->currentRow());
- }
- void PlaylistWindow::slotTableDoubleClicked(int row, int, int button, const TQPoint&)
- {
- if (button != TQt::LeftButton)
- {
- return;
- }
- // Should this restart?
- if (m_playlist->currentIndex() == row)
- {
- return;
- }
- m_playlist->setCurrentIndex(row);
- }
- #include "playlist_window.moc"
|