-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
wlibrary.cpp
170 lines (151 loc) · 5.37 KB
/
wlibrary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "widget/wlibrary.h"
#include <QKeyEvent>
#include <QtDebug>
#include "library/libraryview.h"
#include "moc_wlibrary.cpp"
#include "skin/legacy/skincontext.h"
#include "util/math.h"
#include "widget/wtracktableview.h"
WLibrary::WLibrary(QWidget* parent)
: QStackedWidget(parent),
WBaseWidget(this),
m_mutex(QT_RECURSIVE_MUTEX_INIT),
m_trackTableBackgroundColorOpacity(kDefaultTrackTableBackgroundColorOpacity),
m_bShowButtonText(true) {
}
void WLibrary::setup(const QDomNode& node, const SkinContext& context) {
m_bShowButtonText =
context.selectBool(
node,
"ShowButtonText",
true);
m_trackTableBackgroundColorOpacity = math_clamp(
context.selectDouble(
node,
"TrackTableBackgroundColorOpacity",
kDefaultTrackTableBackgroundColorOpacity),
kMinTrackTableBackgroundColorOpacity,
kMaxTrackTableBackgroundColorOpacity);
}
bool WLibrary::registerView(const QString& name, QWidget* pView) {
//qDebug() << "WLibrary::registerView" << name;
const auto lock = lockMutex(&m_mutex);
if (m_viewMap.contains(name)) {
return false;
}
if (dynamic_cast<LibraryView*>(pView) == nullptr) {
qDebug() << "WARNING: Attempted to register view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. "
<< "Ignoring.";
return false;
}
addWidget(pView);
m_viewMap[name] = pView;
return true;
}
void WLibrary::switchToView(const QString& name) {
const auto lock = lockMutex(&m_mutex);
//qDebug() << "WLibrary::switchToView" << name;
LibraryView* pOldLibrartView = dynamic_cast<LibraryView*>(
currentWidget());
QWidget* pWidget = m_viewMap.value(name, nullptr);
if (pWidget != nullptr) {
LibraryView* pLibraryView = dynamic_cast<LibraryView*>(pWidget);
if (pLibraryView == nullptr) {
qDebug() << "WARNING: Attempted to switch to view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. "
<< "Ignoring.";
return;
}
if (currentWidget() != pWidget) {
if (pOldLibrartView) {
pOldLibrartView->saveCurrentViewState();
}
//qDebug() << "WLibrary::setCurrentWidget" << name;
setCurrentWidget(pWidget);
pLibraryView->onShow();
pLibraryView->restoreCurrentViewState();
}
}
}
void WLibrary::pasteFromSidebar() {
QWidget* pCurrent = currentWidget();
LibraryView* pView = dynamic_cast<LibraryView*>(pCurrent);
if (pView) {
pView->pasteFromSidebar();
}
}
void WLibrary::search(const QString& name) {
auto lock = lockMutex(&m_mutex);
QWidget* pCurrent = currentWidget();
LibraryView* pView = dynamic_cast<LibraryView*>(pCurrent);
if (pView == nullptr) {
qDebug() << "WARNING: Attempted to search in view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. Ignoring.";
return;
}
lock.unlock();
pView->onSearch(name);
}
LibraryView* WLibrary::getActiveView() const {
return dynamic_cast<LibraryView*>(currentWidget());
}
WTrackTableView* WLibrary::getCurrentTrackTableView() const {
QWidget* pCurrent = currentWidget();
WTrackTableView* pTracksView = qobject_cast<WTrackTableView*>(pCurrent);
if (!pTracksView) {
// This view is no tracks view, but maybe a special tracks view with a
// controls row (DlgAutoDJ, DlgRecording)?
// qDebug() << " view is no tracks view. look for tracks view child";
pTracksView = pCurrent->findChild<WTrackTableView*>();
}
return pTracksView; // might be nullptr
}
bool WLibrary::isTrackInCurrentView(const TrackId& trackId) {
// qDebug() << "WLibrary::isTrackInCurrentView" << trackId;
VERIFY_OR_DEBUG_ASSERT(trackId.isValid()) {
return false;
}
WTrackTableView* pTracksView = getCurrentTrackTableView();
if (!pTracksView) {
return false;
}
return pTracksView->isTrackInCurrentView(trackId);
}
void WLibrary::slotSelectTrackInActiveTrackView(const TrackId& trackId) {
//qDebug() << "WLibrary::slotSelectTrackInActiveTrackView" << trackId;
if (!trackId.isValid()) {
return;
}
WTrackTableView* pTracksView = getCurrentTrackTableView();
if (!pTracksView) {
return;
}
pTracksView->slotSelectTrack(trackId);
}
void WLibrary::saveCurrentViewState() const {
WTrackTableView* pTracksView = getCurrentTrackTableView();
if (!pTracksView) {
return;
}
pTracksView->slotSaveCurrentViewState();
}
void WLibrary::restoreCurrentViewState() const {
WTrackTableView* pTracksView = getCurrentTrackTableView();
if (!pTracksView) {
return;
}
pTracksView->slotRestoreCurrentViewState();
}
bool WLibrary::event(QEvent* pEvent) {
if (pEvent->type() == QEvent::ToolTip) {
updateTooltip();
}
return QStackedWidget::event(pEvent);
}
void WLibrary::keyPressEvent(QKeyEvent* pEvent) {
if (pEvent->key() == Qt::Key_Left && pEvent->modifiers() & Qt::ControlModifier) {
emit setLibraryFocus(FocusWidget::Sidebar);
}
QStackedWidget::keyPressEvent(pEvent);
}