#include "library/librarycontrol.h"
#include <QApplication>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <QModelIndexList>
#include <QWindow>
#include <QtDebug>
#include "control/controlobject.h"
#include "control/controlpushbutton.h"
#include "library/library.h"
#include "library/libraryview.h"
#include "mixer/playermanager.h"
#include "moc_librarycontrol.cpp"
#include "util/cmdlineargs.h"
#include "widget/wlibrary.h"
#include "widget/wlibrarysidebar.h"
#include "widget/wsearchlineedit.h"
#include "widget/wtracktableview.h"
LoadToGroupController::LoadToGroupController(LibraryControl* pParent, const QString& group)
: QObject(pParent),
m_group(group) {
m_pLoadControl = std::make_unique<ControlPushButton>(ConfigKey(group, "LoadSelectedTrack"));
connect(m_pLoadControl.get(),
&ControlObject::valueChanged,
this,
&LoadToGroupController::slotLoadToGroup);
m_pLoadAndPlayControl = std::make_unique<ControlPushButton>(ConfigKey(group, "LoadSelectedTrackAndPlay"));
connect(m_pLoadAndPlayControl.get(),
&ControlObject::valueChanged,
this,
&LoadToGroupController::slotLoadToGroupAndPlay);
connect(this,
&LoadToGroupController::loadToGroup,
pParent,
&LibraryControl::slotLoadSelectedTrackToGroup);
}
LoadToGroupController::~LoadToGroupController() = default;
void LoadToGroupController::slotLoadToGroup(double v) {
if (v > 0) {
emit loadToGroup(m_group, false);
}
}
void LoadToGroupController::slotLoadToGroupAndPlay(double v) {
if (v > 0) {
emit loadToGroup(m_group, true);
}
}
LibraryControl::LibraryControl(Library* pLibrary)
: QObject(pLibrary),
m_pLibrary(pLibrary),
m_pFocusedWidget(FocusWidget::None),
m_pLibraryWidget(nullptr),
m_pSidebarWidget(nullptr),
m_pSearchbox(nullptr),
m_numDecks("[Master]", "num_decks", this),
m_numSamplers("[Master]", "num_samplers", this),
m_numPreviewDecks("[Master]", "num_preview_decks", this) {
qRegisterMetaType<FocusWidget>("FocusWidget");
slotNumDecksChanged(m_numDecks.get());
slotNumSamplersChanged(m_numSamplers.get());
slotNumPreviewDecksChanged(m_numPreviewDecks.get());
m_numDecks.connectValueChanged(this, &LibraryControl::slotNumDecksChanged);
m_numSamplers.connectValueChanged(this, &LibraryControl::slotNumSamplersChanged);
m_numPreviewDecks.connectValueChanged(this, &LibraryControl::slotNumPreviewDecksChanged);
// Controls to navigate vertically within currently focused widget (up/down buttons)
m_pMoveUp = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveUp"));
m_pMoveDown = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveDown"));
m_pMoveVertical = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "MoveVertical"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pMoveUp.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveUp);
connect(m_pMoveDown.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveDown);
connect(m_pMoveVertical.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotMoveVertical);
#endif
// Controls to navigate vertically within currently focused widget (up/down buttons)
m_pScrollUp = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "ScrollUp"));
m_pScrollDown = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "ScrollDown"));
m_pScrollVertical = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "ScrollVertical"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pScrollUp.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotScrollUp);
connect(m_pScrollDown.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotScrollDown);
connect(m_pScrollVertical.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotScrollVertical);
#endif
// Controls to navigate horizontally within currently selected item (left/right buttons)
m_pMoveLeft = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveLeft"));
m_pMoveRight = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveRight"));
m_pMoveHorizontal = std::make_unique