mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Stubbed out a SearchLayout and fixed some key handling and focus order issues.
This commit is contained in:
parent
c7a0377632
commit
45bd3f4c0d
@ -316,14 +316,18 @@ int main(int argc, char* argv[])
|
||||
changeLayout(state, libraryLayout);
|
||||
}
|
||||
else if (!globalHotkeys.Handle(kn)) {
|
||||
bool processed = false;
|
||||
if (state.input) {
|
||||
state.input->Write(kn);
|
||||
processed = state.input->Write(kn);
|
||||
}
|
||||
|
||||
/* otherwise, send the unhandled keypress directly to the
|
||||
focused window. if it can't do anything with it, send it to
|
||||
the layout for special processing, if necessary */
|
||||
else if (!state.keyHandler || !state.keyHandler->KeyPress(kn)) {
|
||||
state.layout->KeyPress(kn);
|
||||
if (!processed) {
|
||||
if (!state.keyHandler || !state.keyHandler->KeyPress(kn)) {
|
||||
state.layout->KeyPress(kn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +75,6 @@ void BrowseLayout::Layout() {
|
||||
|
||||
this->MoveAndResize(x, y, cx, cy);
|
||||
|
||||
this->SetSize(cx, cy);
|
||||
this->SetPosition(x, y);
|
||||
|
||||
this->categoryList->MoveAndResize(x, y, CATEGORY_WIDTH, cy);
|
||||
|
||||
this->trackList->MoveAndResize(
|
||||
|
@ -77,9 +77,13 @@ void LibraryLayout::Layout() {
|
||||
|
||||
this->browseLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
|
||||
this->browseLayout->Layout();
|
||||
|
||||
this->nowPlayingLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
|
||||
this->nowPlayingLayout->Layout();
|
||||
|
||||
this->searchLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
|
||||
this->searchLayout->Layout();
|
||||
|
||||
this->transportView->MoveAndResize(
|
||||
1,
|
||||
cy - TRANSPORT_HEIGHT,
|
||||
@ -117,9 +121,15 @@ void LibraryLayout::ShowBrowse() {
|
||||
this->ChangeMainLayout(this->browseLayout);
|
||||
}
|
||||
|
||||
void LibraryLayout::ShowSearch() {
|
||||
this->ChangeMainLayout(this->searchLayout);
|
||||
}
|
||||
|
||||
void LibraryLayout::InitializeWindows() {
|
||||
this->browseLayout.reset(new BrowseLayout(this->playback, this->library));
|
||||
this->nowPlayingLayout.reset(new NowPlayingLayout(this->playback, this->library));
|
||||
this->searchLayout.reset(new SearchLayout(this->library));
|
||||
|
||||
this->transportView.reset(new TransportWindow(this->playback));
|
||||
|
||||
this->AddWindow(this->transportView);
|
||||
@ -141,8 +151,16 @@ IWindowPtr LibraryLayout::GetFocus() {
|
||||
|
||||
bool LibraryLayout::KeyPress(const std::string& key) {
|
||||
if (key == "^[" || key == "M-n") { /* escape switches between browse/now playing */
|
||||
(this->visibleLayout == this->nowPlayingLayout)
|
||||
? this->ShowBrowse() : this->ShowNowPlaying();
|
||||
if (this->visibleLayout == this->nowPlayingLayout ||
|
||||
this->visibleLayout == this->searchLayout) {
|
||||
this->ShowBrowse();
|
||||
}
|
||||
else {
|
||||
this->ShowNowPlaying();
|
||||
}
|
||||
}
|
||||
else if (key == "M-f") {
|
||||
this->ShowSearch();
|
||||
}
|
||||
/* forward to the visible layout */
|
||||
else if (this->visibleLayout && this->visibleLayout->KeyPress(key)) {
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include <app/layout/BrowseLayout.h>
|
||||
#include <app/layout/NowPlayingLayout.h>
|
||||
#include <app/layout/SearchLayout.h>
|
||||
#include <app/window/TransportWindow.h>
|
||||
#include <app/service/PlaybackService.h>
|
||||
|
||||
@ -68,6 +69,7 @@ namespace musik {
|
||||
void InitializeWindows();
|
||||
void ShowNowPlaying();
|
||||
void ShowBrowse();
|
||||
void ShowSearch();
|
||||
void ChangeMainLayout(std::shared_ptr<cursespp::LayoutBase> newLayout);
|
||||
|
||||
PlaybackService& playback;
|
||||
@ -76,6 +78,7 @@ namespace musik {
|
||||
std::shared_ptr<BrowseLayout> browseLayout;
|
||||
std::shared_ptr<TransportWindow> transportView;
|
||||
std::shared_ptr<NowPlayingLayout> nowPlayingLayout;
|
||||
std::shared_ptr<SearchLayout> searchLayout;
|
||||
std::shared_ptr<cursespp::LayoutBase> visibleLayout;
|
||||
};
|
||||
}
|
||||
|
125
src/musikbox/app/layout/SearchLayout.cpp
Executable file
125
src/musikbox/app/layout/SearchLayout.cpp
Executable file
@ -0,0 +1,125 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <cursespp/Colors.h>
|
||||
#include <cursespp/Screen.h>
|
||||
#include <core/library/LocalLibraryConstants.h>
|
||||
#include <app/query/CategoryTrackListQuery.h>
|
||||
#include "SearchLayout.h"
|
||||
|
||||
using namespace musik::core::library::constants;
|
||||
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::audio;
|
||||
using namespace musik::core::library;
|
||||
using namespace musik::box;
|
||||
using namespace cursespp;
|
||||
|
||||
#define SEARCH_HEIGHT 3
|
||||
|
||||
SearchLayout::SearchLayout(LibraryPtr library)
|
||||
: LayoutBase() {
|
||||
this->library = library;
|
||||
this->InitializeWindows();
|
||||
}
|
||||
|
||||
SearchLayout::~SearchLayout() {
|
||||
|
||||
}
|
||||
|
||||
void SearchLayout::Layout() {
|
||||
size_t cx = this->GetWidth(), cy = this->GetHeight();
|
||||
|
||||
if (cx == 0 || cy == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t x = this->GetX(), y = this->GetY();
|
||||
|
||||
this->MoveAndResize(x, y, cx, cy);
|
||||
|
||||
size_t inputWidth = cx / 2;
|
||||
size_t inputX = x + ((cx - inputWidth) / 2);
|
||||
this->input->MoveAndResize(inputX, 0, cx / 2, SEARCH_HEIGHT);
|
||||
|
||||
size_t categoryWidth = cx / 3;
|
||||
size_t categoryY = SEARCH_HEIGHT;
|
||||
size_t categoryHeight = cy - SEARCH_HEIGHT;
|
||||
size_t lastCategoryWidth = cx - (categoryWidth * 2);
|
||||
|
||||
this->albums->MoveAndResize(0, categoryY, categoryWidth, categoryHeight);
|
||||
this->artists->MoveAndResize(categoryWidth, categoryY, categoryWidth, categoryHeight);
|
||||
this->genres->MoveAndResize(categoryWidth * 2, categoryY, lastCategoryWidth, categoryHeight);
|
||||
}
|
||||
|
||||
void SearchLayout::InitializeWindows() {
|
||||
this->input.reset(new cursespp::TextInput());
|
||||
this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
this->input->SetFocusOrder(0);
|
||||
this->AddWindow(this->input);
|
||||
|
||||
this->albums.reset(new CategoryListView(this->library, constants::Track::ALBUM));
|
||||
this->AddWindow(this->albums);
|
||||
this->albums->SetFocusOrder(1);
|
||||
|
||||
this->artists.reset(new CategoryListView(this->library, constants::Track::ARTIST));
|
||||
this->AddWindow(this->artists);
|
||||
this->artists->SetFocusOrder(2);
|
||||
|
||||
this->genres.reset(new CategoryListView(this->library, constants::Track::GENRE));
|
||||
this->AddWindow(this->genres);
|
||||
this->genres->SetFocusOrder(3);
|
||||
|
||||
//this->categoryList->SelectionChanged.connect(
|
||||
// this, &BrowseLayout::OnCategoryViewSelectionChanged);
|
||||
|
||||
//this->categoryList->Invalidated.connect(
|
||||
// this, &BrowseLayout::OnCategoryViewInvalidated);
|
||||
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
void SearchLayout::OnVisibilityChanged(bool visible) {
|
||||
LayoutBase::OnVisibilityChanged(visible);
|
||||
|
||||
//if (visible) {
|
||||
// this->categoryList->Requery();
|
||||
//}
|
||||
}
|
||||
|
||||
bool SearchLayout::KeyPress(const std::string& key) {
|
||||
return LayoutBase::KeyPress(key);
|
||||
}
|
77
src/musikbox/app/layout/SearchLayout.h
Executable file
77
src/musikbox/app/layout/SearchLayout.h
Executable file
@ -0,0 +1,77 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cursespp/LayoutBase.h>
|
||||
#include <cursespp/TextInput.h>
|
||||
|
||||
#include <app/window/CategoryListView.h>
|
||||
#include <app/window/TrackListView.h>
|
||||
#include <app/window/TransportWindow.h>
|
||||
#include <app/service/PlaybackService.h>
|
||||
|
||||
#include <core/library/ILibrary.h>
|
||||
|
||||
#include <sigslot/sigslot.h>
|
||||
|
||||
namespace musik {
|
||||
namespace box {
|
||||
class SearchLayout :
|
||||
public cursespp::LayoutBase,
|
||||
#if (__clang_major__ == 7 && __clang_minor__ == 3)
|
||||
public std::enable_shared_from_this<SearchLayout>,
|
||||
#endif
|
||||
public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
SearchLayout(musik::core::LibraryPtr library);
|
||||
|
||||
virtual ~SearchLayout();
|
||||
|
||||
virtual void Layout();
|
||||
virtual void OnVisibilityChanged(bool visible);
|
||||
virtual bool KeyPress(const std::string& key);
|
||||
|
||||
private:
|
||||
void InitializeWindows();
|
||||
|
||||
musik::core::LibraryPtr library;
|
||||
std::shared_ptr<CategoryListView> artists;
|
||||
std::shared_ptr<CategoryListView> albums;
|
||||
std::shared_ptr<CategoryListView> genres;
|
||||
std::shared_ptr<cursespp::TextInput> input;
|
||||
};
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ namespace cursespp {
|
||||
class IInput {
|
||||
public:
|
||||
virtual ~IInput() { }
|
||||
virtual void Write(const std::string& key) = 0;
|
||||
virtual bool Write(const std::string& key) = 0;
|
||||
virtual size_t Length() = 0;
|
||||
};
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) {
|
||||
int orderB = b->GetFocusOrder();
|
||||
|
||||
if (orderA == orderB) {
|
||||
return a->GetId() > b->GetId();
|
||||
return a->GetId() < b->GetId();
|
||||
}
|
||||
|
||||
return orderA > orderB;
|
||||
return orderA < orderB;
|
||||
}
|
||||
|
||||
static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
||||
|
@ -73,7 +73,7 @@ void TextInput::Show() {
|
||||
redrawContents(*this, buffer);
|
||||
}
|
||||
|
||||
void TextInput::Write(const std::string& key) {
|
||||
bool TextInput::Write(const std::string& key) {
|
||||
if (key == "M-bksp") {
|
||||
this->buffer = "";
|
||||
redrawContents(*this, "");
|
||||
@ -93,10 +93,14 @@ void TextInput::Write(const std::string& key) {
|
||||
this->buffer += key;
|
||||
this->TextChanged(this, this->buffer);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this->bufferLength = u8len(buffer);
|
||||
redrawContents(*this, buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextInput::SetText(const std::string& value) {
|
||||
|
@ -48,7 +48,7 @@ namespace cursespp {
|
||||
TextInput();
|
||||
virtual ~TextInput();
|
||||
|
||||
virtual void Write(const std::string& key);
|
||||
virtual bool Write(const std::string& key);
|
||||
virtual size_t Length() { return this->bufferLength; }
|
||||
virtual void Show();
|
||||
|
||||
|
@ -119,6 +119,7 @@
|
||||
<ClCompile Include="app\layout\LibraryLayout.cpp" />
|
||||
<ClCompile Include="app\layout\ConsoleLayout.cpp" />
|
||||
<ClCompile Include="app\layout\NowPlayingLayout.cpp" />
|
||||
<ClCompile Include="app\layout\SearchLayout.cpp" />
|
||||
<ClCompile Include="app\query\CategoryListViewQuery.cpp" />
|
||||
<ClCompile Include="app\query\NowPlayingTrackListQuery.cpp" />
|
||||
<ClCompile Include="app\query\CategoryTrackListQuery.cpp" />
|
||||
@ -159,6 +160,7 @@
|
||||
<ClInclude Include="app\layout\LibraryLayout.h" />
|
||||
<ClInclude Include="app\layout\ConsoleLayout.h" />
|
||||
<ClInclude Include="app\layout\NowPlayingLayout.h" />
|
||||
<ClInclude Include="app\layout\SearchLayout.h" />
|
||||
<ClInclude Include="app\query\CategoryListViewQuery.h" />
|
||||
<ClInclude Include="app\query\NowPlayingTrackListQuery.h" />
|
||||
<ClInclude Include="app\query\TrackListQueryBase.h" />
|
||||
|
@ -102,6 +102,9 @@
|
||||
<ClCompile Include="cursespp\TextInput.cpp">
|
||||
<Filter>cursespp</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app\layout\SearchLayout.cpp">
|
||||
<Filter>app\layout</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -246,6 +249,9 @@
|
||||
<ClInclude Include="cursespp\TextInput.h">
|
||||
<Filter>cursespp</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="app\layout\SearchLayout.h">
|
||||
<Filter>app\layout</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cursespp">
|
||||
|
Loading…
x
Reference in New Issue
Block a user