KiCad PCB EDA Suite
panel_package.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef PANEL_PACKAGE_H_
22 #define PANEL_PACKAGE_H_
23 
24 #include <functional>
25 
26 #include "panel_package_base.h"
27 #include "pcm.h"
28 
31 {
33  wxBitmap* bitmap;
35  wxString repository_id;
36  wxString repository_name;
37  wxString current_version;
38  PACKAGE_VIEW_DATA( const PCM_PACKAGE aPackage ) :
39  package( std::move( aPackage ) ), bitmap( nullptr ), state( PPS_INSTALLED ){};
41  package( std::move( aEntry.package ) ), bitmap( nullptr )
42  {
47  }
48 };
49 
50 
52 using ActionCallback = std::function<void( const PACKAGE_VIEW_DATA& aData,
53  PCM_PACKAGE_ACTION aAction, const wxString& aVersion )>;
54 
55 
57 {
58 public:
59  PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
60  const PACKAGE_VIEW_DATA& aData );
61 
63  void SetSelectCallback( const std::function<void()>& aCallback );
64 
66  void SetSelected( bool aSelected );
67 
68  void OnButtonClicked( wxCommandEvent& event ) override;
69 
71  void SetState( PCM_PACKAGE_STATE aState );
72 
74  void OnClick( wxMouseEvent& event ) override;
75 
76  void OnSize( wxSizeEvent& event ) override;
77 
79  wxString GetPreferredVersion() const;
80 
81  const PACKAGE_VIEW_DATA& GetPackageData() const { return m_data; };
82 
83 private:
84  void OnPaint( wxPaintEvent& event ) override;
85 
86 private:
87  std::function<void()> m_selectCallback;
88  bool m_selected = false;
92 };
93 
94 
95 #endif // PANEL_PACKAGE_H_
void OnPaint(wxPaintEvent &event) override
std::function< void()> m_selectCallback
Definition: panel_package.h:87
void SetState(PCM_PACKAGE_STATE aState)
Called when anywhere on the panel is clicked (except install button)
wxString repository_id
Definition: panel_package.h:35
Definition: bitmap.cpp:64
PACKAGE_VIEW_DATA(const PCM_PACKAGE aPackage)
Definition: panel_package.h:38
const PCM_PACKAGE package
Definition: panel_package.h:32
PACKAGE_VIEW_DATA(const PCM_INSTALLATION_ENTRY &aEntry)
Definition: panel_package.h:40
const ActionCallback & m_actionCallback
Definition: panel_package.h:89
< Collection of data relevant to the package display panel Callback for (un)install button
Definition: panel_package.h:30
void SetSelected(bool aSelected)
Repository reference to a resource.
Definition: pcm_data.h:93
wxBitmap * bitmap
Definition: panel_package.h:33
wxString repository_name
Definition: panel_package.h:36
void OnClick(wxMouseEvent &event) override
void SetSelectCallback(const std::function< void()> &aCallback)
Marks panel as selected.
void OnButtonClicked(wxCommandEvent &event) override
Changes state of the (un)install button.
PCM_PACKAGE_STATE
Definition: pcm.h:52
wxString current_version
Definition: pcm_data.h:136
Class PANEL_PACKAGE_BASE.
PCM_PACKAGE_STATE state
Definition: panel_package.h:34
const PACKAGE_VIEW_DATA & GetPackageData() const
Definition: panel_package.h:81
void OnSize(wxSizeEvent &event) override
Get preferred version. If criteria are not met, return wxEmptyString.
wxString current_version
Definition: panel_package.h:37
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90
wxString repository_id
Definition: pcm_data.h:137
std::function< void(const PACKAGE_VIEW_DATA &aData, PCM_PACKAGE_ACTION aAction, const wxString &aVersion)> ActionCallback
Definition: panel_package.h:53
PANEL_PACKAGE(wxWindow *parent, const ActionCallback &aCallback, const PACKAGE_VIEW_DATA &aData)
Sets callback for OnClick action.
wxString GetPreferredVersion() const
wxString repository_name
Definition: pcm_data.h:138
Definition: pcm_data.h:133
PCM_PACKAGE_ACTION
Definition: pcm.h:63