From b89b55735212064944af2233c6cbe94b3ccf6ea3 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 8 Nov 2016 01:35:34 -0500 Subject: [PATCH] More flexible bookmark buttons --- src/forms/Bookmark/BookmarkPanel.cpp | 19 +-- src/forms/Bookmark/BookmarkPanel.fbp | 226 +++------------------------ src/forms/Bookmark/BookmarkPanel.h | 8 +- src/forms/Bookmark/BookmarkView.cpp | 113 ++++++++++---- src/forms/Bookmark/BookmarkView.h | 20 ++- 5 files changed, 134 insertions(+), 252 deletions(-) diff --git a/src/forms/Bookmark/BookmarkPanel.cpp b/src/forms/Bookmark/BookmarkPanel.cpp index 7c7d50d..008ef47 100644 --- a/src/forms/Bookmark/BookmarkPanel.cpp +++ b/src/forms/Bookmark/BookmarkPanel.cpp @@ -61,14 +61,15 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po fgPropSizer->Fit( m_propPanel ); bSizer1->Add( m_propPanel, 1, wxBOTTOM|wxEXPAND|wxTOP, 5 ); - m_bookmarkButton = new wxButton( this, wxID_ANY, wxT("Bookmark"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer1->Add( m_bookmarkButton, 0, wxEXPAND, 5 ); + m_buttonPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + wxBoxSizer* m_buttonPanelSizer; + m_buttonPanelSizer = new wxBoxSizer( wxVERTICAL ); - m_activateButton = new wxButton( this, wxID_ANY, wxT("Activate"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer1->Add( m_activateButton, 0, wxEXPAND, 5 ); - m_removeButton = new wxButton( this, wxID_ANY, wxT("Remove"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer1->Add( m_removeButton, 0, wxEXPAND, 5 ); + m_buttonPanel->SetSizer( m_buttonPanelSizer ); + m_buttonPanel->Layout(); + m_buttonPanelSizer->Fit( m_buttonPanel ); + bSizer1->Add( m_buttonPanel, 1, wxEXPAND, 5 ); this->SetSizer( bSizer1 ); @@ -93,9 +94,6 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po m_labelText->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onLabelText ), NULL, this ); m_frequencyVal->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( BookmarkPanel::onDoubleClickFreq ), NULL, this ); m_bandwidthVal->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( BookmarkPanel::onDoubleClickBandwidth ), NULL, this ); - m_bookmarkButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onBookmark ), NULL, this ); - m_activateButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onActivate ), NULL, this ); - m_removeButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onRemove ), NULL, this ); this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( BookmarkPanel::onUpdateTimer ) ); } @@ -119,9 +117,6 @@ BookmarkPanel::~BookmarkPanel() m_labelText->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onLabelText ), NULL, this ); m_frequencyVal->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( BookmarkPanel::onDoubleClickFreq ), NULL, this ); m_bandwidthVal->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( BookmarkPanel::onDoubleClickBandwidth ), NULL, this ); - m_bookmarkButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onBookmark ), NULL, this ); - m_activateButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onActivate ), NULL, this ); - m_removeButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onRemove ), NULL, this ); this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( BookmarkPanel::onUpdateTimer ) ); } diff --git a/src/forms/Bookmark/BookmarkPanel.fbp b/src/forms/Bookmark/BookmarkPanel.fbp index aa64d86..d0f3adc 100644 --- a/src/forms/Bookmark/BookmarkPanel.fbp +++ b/src/forms/Bookmark/BookmarkPanel.fbp @@ -189,7 +189,7 @@ 5 wxBOTTOM|wxEXPAND|wxTOP 1 - + 1 1 1 @@ -263,7 +263,7 @@ - + 2 wxBOTH 1 @@ -449,11 +449,11 @@ - + 5 wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT 0 - + 1 1 1 @@ -532,11 +532,11 @@ - + 5 wxALL 0 - + 1 1 1 @@ -615,11 +615,11 @@ - + 5 wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT 0 - + 1 1 1 @@ -698,11 +698,11 @@ - + 5 wxALL 0 - + 1 1 1 @@ -781,11 +781,11 @@ - + 5 wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT 0 - + 1 1 1 @@ -864,11 +864,11 @@ - + 5 wxALL 0 - + 1 1 1 @@ -953,8 +953,8 @@ 5 wxEXPAND - 0 - + 1 + 1 1 1 @@ -971,7 +971,6 @@ 1 1 - 0 0 Dock 0 @@ -983,7 +982,6 @@ 0 0 wxID_ANY - Bookmark 0 @@ -991,7 +989,7 @@ 0 1 - m_bookmarkButton + m_buttonPanel 1 @@ -1001,194 +999,12 @@ Resizable 1 - 0 - - wxFILTER_NONE - wxDefaultValidator - - - onBookmark - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Activate - - 0 - - - 0 - - 1 - m_activateButton - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - onActivate - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Remove - - 0 - - - 0 - - 1 - m_removeButton - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - onRemove + wxTAB_TRAVERSAL @@ -1212,6 +1028,12 @@ + + + m_buttonPanelSizer + wxVERTICAL + none + diff --git a/src/forms/Bookmark/BookmarkPanel.h b/src/forms/Bookmark/BookmarkPanel.h index 45904a1..99c78fd 100644 --- a/src/forms/Bookmark/BookmarkPanel.h +++ b/src/forms/Bookmark/BookmarkPanel.h @@ -20,7 +20,6 @@ #include #include #include -#include #include /////////////////////////////////////////////////////////////////////////// @@ -44,9 +43,7 @@ class BookmarkPanel : public wxPanel wxStaticText* m_bandwidthVal; wxStaticText* m_modulationLabel; wxStaticText* m_modulationVal; - wxButton* m_bookmarkButton; - wxButton* m_activateButton; - wxButton* m_removeButton; + wxPanel* m_buttonPanel; wxTimer m_updateTimer; // Virtual event handlers, overide them in your derived class @@ -67,9 +64,6 @@ class BookmarkPanel : public wxPanel virtual void onLabelText( wxCommandEvent& event ) { event.Skip(); } virtual void onDoubleClickFreq( wxMouseEvent& event ) { event.Skip(); } virtual void onDoubleClickBandwidth( wxMouseEvent& event ) { event.Skip(); } - virtual void onBookmark( wxCommandEvent& event ) { event.Skip(); } - virtual void onActivate( wxCommandEvent& event ) { event.Skip(); } - virtual void onRemove( wxCommandEvent& event ) { event.Skip(); } virtual void onUpdateTimer( wxTimerEvent& event ) { event.Skip(); } diff --git a/src/forms/Bookmark/BookmarkView.cpp b/src/forms/Bookmark/BookmarkView.cpp index 9db31e0..58b1756 100644 --- a/src/forms/Bookmark/BookmarkView.cpp +++ b/src/forms/Bookmark/BookmarkView.cpp @@ -52,6 +52,8 @@ void BookmarkView::updateTheme() { wxColour btn(ThemeMgr::mgr.currentTheme->button); wxColour btnHl(ThemeMgr::mgr.currentTheme->buttonHighlight); + this->SetBackgroundColour(ThemeMgr::mgr.currentTheme->generalBackground * 4.0); + m_treeView->SetBackgroundColour(bgColor); m_treeView->SetForegroundColour(textColor); @@ -65,10 +67,11 @@ void BookmarkView::updateTheme() { m_bandwidthLabel->SetForegroundColour(textColor); m_modulationVal->SetForegroundColour(textColor); m_modulationLabel->SetForegroundColour(textColor); - - m_bookmarkButton->SetBackgroundColour(bgColor); - m_removeButton->SetBackgroundColour(bgColor); - m_activateButton->SetBackgroundColour(bgColor); + + m_buttonPanel->SetBackgroundColour(bgColor); + for (auto p : m_buttonPanel->GetChildren()) { + p->SetBackgroundColour(bgColor); + } } @@ -243,7 +246,7 @@ void BookmarkView::onMenuItem(wxCommandEvent& event) { wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", ""); if (stringVal.ToStdString() != "") { wxGetApp().getBookmarkMgr().getGroup(stringVal.ToStdString()); - wxGetApp().getBookmarkMgr().updateActiveList(); + wxGetApp().getBookmarkMgr().updateBookmarks(); } } } @@ -267,9 +270,34 @@ void BookmarkView::hideProps() { m_labelText->Hide(); m_labelLabel->Hide(); - m_bookmarkButton->Hide(); - m_activateButton->Hide(); - m_removeButton->Hide(); + m_buttonPanel->Hide(); +} + + +void BookmarkView::clearButtons() { + m_buttonPanel->DestroyChildren(); + m_buttonPanel->Hide(); +} + +void BookmarkView::showButtons() { + m_buttonPanel->Show(); +// m_buttonPanel->Layout(); + m_buttonPanel->GetSizer()->Layout(); +} + + +wxButton *BookmarkView::makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler) { + wxButton *nButton = new wxButton( m_buttonPanel, wxID_ANY, labelVal); + nButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, handler, NULL, this); + nButton->SetBackgroundColour(ThemeMgr::mgr.currentTheme->generalBackground); + return nButton; +} + + +wxButton *BookmarkView::addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler) { + wxButton *nButton = makeButton(parent, labelVal, handler); + parent->GetSizer()->Add( nButton, 0, wxEXPAND); + return nButton; } @@ -286,7 +314,7 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) { m_frequencyVal->Show(); m_frequencyLabel->Show(); - + m_bandwidthVal->Show(); m_bandwidthLabel->Show(); @@ -296,9 +324,13 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) { m_labelText->Show(); m_labelLabel->Show(); - m_bookmarkButton->Show(); - m_removeButton->Show(); + clearButtons(); + addButton(m_buttonPanel, "Bookmark Active", wxCommandEventHandler( BookmarkView::onBookmarkActive )); + addButton(m_buttonPanel, "Remove Active", wxCommandEventHandler( BookmarkView::onRemoveActive )); + + showButtons(); + this->Layout(); } @@ -340,10 +372,13 @@ void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) { m_labelText->Show(); m_labelLabel->Show(); - m_activateButton->Show(); - m_bookmarkButton->Hide(); - m_removeButton->Show(); + clearButtons(); + addButton(m_buttonPanel, "Activate Bookmark", wxCommandEventHandler( BookmarkView::onActivateBookmark )); + addButton(m_buttonPanel, "Remove Bookmark", wxCommandEventHandler( BookmarkView::onRemoveBookmark )); + + showButtons(); + this->Layout(); } @@ -372,10 +407,13 @@ void BookmarkView::recentSelection(BookmarkEntry *bmSel) { m_labelText->Show(); m_labelLabel->Show(); - m_activateButton->Show(); - m_bookmarkButton->Show(); - m_removeButton->Hide(); + clearButtons(); + addButton(m_buttonPanel, "Activate Recent", wxCommandEventHandler( BookmarkView::onActivateRecent )); + addButton(m_buttonPanel, "Bookmark Recent", wxCommandEventHandler( BookmarkView::onBookmarkRecent )); + + showButtons(); + this->Layout(); } @@ -384,6 +422,9 @@ void BookmarkView::onTreeSelect( wxTreeEvent& event ) { TreeViewItem* tvi = dynamic_cast(m_treeView->GetItemData(event.GetItem())); if (!tvi) { + m_propPanel->Hide(); + hideProps(); + this->Layout(); return; } @@ -431,30 +472,46 @@ void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) { } -void BookmarkView::onBookmark( wxCommandEvent& event ) { +void BookmarkView::onBookmarkActive( wxCommandEvent& event ) { if (activeSel) { wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", activeSel); wxGetApp().getBookmarkMgr().updateBookmarks(); } } - -void BookmarkView::onActivate( wxCommandEvent& event ) { - if (recentSel) { - activateBookmark(recentSel); +void BookmarkView::onBookmarkRecent( wxCommandEvent& event ) { + if (bookmarkSel) { + wxGetApp().getBookmarkMgr().removeRecent(bookmarkSel); + wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", bookmarkSel); } +} + + +void BookmarkView::onRemoveActive( wxCommandEvent& event ) { + if (activeSel != nullptr) { + wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false); + wxGetApp().removeDemodulator(activeSel); + wxGetApp().getDemodMgr().deleteThread(activeSel); + activeSel = nullptr; + } +} + + +void BookmarkView::onRemoveBookmark( wxCommandEvent& event ) { + // todo +} + + +void BookmarkView::onActivateBookmark( wxCommandEvent& event ) { if (bookmarkSel) { activateBookmark(bookmarkSel); } } -void BookmarkView::onRemove( wxCommandEvent& event ) { - if (activeSel != nullptr) { - wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false); - wxGetApp().removeDemodulator(activeSel); - wxGetApp().getDemodMgr().deleteThread(activeSel); - activeSel = nullptr; +void BookmarkView::onActivateRecent( wxCommandEvent& event ) { + if (recentSel) { + activateBookmark(recentSel); } } diff --git a/src/forms/Bookmark/BookmarkView.h b/src/forms/Bookmark/BookmarkView.h index 6bf2625..d444014 100644 --- a/src/forms/Bookmark/BookmarkView.h +++ b/src/forms/Bookmark/BookmarkView.h @@ -60,9 +60,6 @@ protected: void onLabelText( wxCommandEvent& event ); void onDoubleClickFreq( wxMouseEvent& event ); void onDoubleClickBandwidth( wxMouseEvent& event ); - void onBookmark( wxCommandEvent& event ); - void onActivate( wxCommandEvent& event ); - void onRemove( wxCommandEvent& event ); void onTreeBeginDrag( wxTreeEvent& event ); void onTreeEndDrag( wxTreeEvent& event ); void onTreeDeleteItem( wxTreeEvent& event ); @@ -70,6 +67,23 @@ protected: void onEnterWindow( wxMouseEvent& event ); void onLeaveWindow( wxMouseEvent& event ); + + void clearButtons(); + void showButtons(); + + wxButton *makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler); + wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler); + + void onBookmarkActive( wxCommandEvent& event ); + void onBookmarkRecent( wxCommandEvent& event ); + + void onRemoveActive( wxCommandEvent& event ); + void onRemoveBookmark( wxCommandEvent& event ); + + void onActivateBookmark( wxCommandEvent& event ); + void onActivateRecent( wxCommandEvent& event ); + + std::atomic_bool mouseInView; wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch;