KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_kicad_launcher.cpp
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 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <bitmaps.h>
21#include <bitmap_store.h>
22#include <kicad_manager_frame.h>
23#include <kiplatform/policy.h>
24#include <policy_keys.h>
25#include <tool/tool_manager.h>
28#include <wx/stattext.h>
29
31
32
35{
36 m_frame = static_cast<KICAD_MANAGER_FRAME*>( aParent->GetParent() );
38
39 Bind( wxEVT_SYS_COLOUR_CHANGED,
40 wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
41}
42
43
45{
46 for( wxWindow* window : m_scrolledWindow->GetChildren() )
47 {
48 if( dynamic_cast<BITMAP_BUTTON*>( window ) != nullptr )
49 {
50 window->Unbind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
51 }
52 }
53
54 Unbind( wxEVT_SYS_COLOUR_CHANGED,
55 wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
56}
57
58
59void PANEL_KICAD_LAUNCHER::onLauncherButtonClick( wxCommandEvent& aEvent )
60{
61 // Defocus the button because leaving the large buttons
62 // focused after a click looks out of place in the launcher
63 m_frame->SetFocus();
64 // Gives a slice of time to update the button state (mandatory on GTK,
65 // useful on MSW to avoid some cosmetic issues).
66 wxSafeYield();
67
68 BITMAP_BUTTON* button = (BITMAP_BUTTON*) aEvent.GetEventObject();
69 const TOOL_ACTION* action = static_cast<const TOOL_ACTION*>( button->GetClientData() );
70
71 if( action == nullptr )
72 return;
73
74 OPT_TOOL_EVENT evt = action->MakeEvent();
75 evt->SetHasPosition( false );
77}
78
79
81{
82 m_frame->SetPcmButton( nullptr );
83
84 if( m_toolsSizer->GetEffectiveRowsCount() > 0 )
85 {
86 m_toolsSizer->Clear( true );
87 m_toolsSizer->SetRows( 0 );
88 }
89
90 wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
91#ifndef __WXGTK__
92 titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
93#endif
94 titleFont.SetWeight( wxFONTWEIGHT_BOLD );
95
96 wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
97 helpFont.SetStyle( wxFONTSTYLE_ITALIC );
98
99 auto addLauncher = [&]( const TOOL_ACTION& aAction, BITMAPS aBitmaps, const wxString& aHelpText,
100 bool enabled = true )
101 {
102 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_scrolledWindow, wxID_ANY );
103 btn->SetBitmap( KiBitmapBundle( aBitmaps ) );
104 btn->SetDisabledBitmap( KiDisabledBitmapBundle( aBitmaps ) );
105 btn->SetPadding( FromDIP( 4 ) );
106 btn->SetToolTip( aAction.GetTooltip() );
107
108 wxStaticText* label = new wxStaticText( m_scrolledWindow, wxID_ANY, wxEmptyString );
109 wxStaticText* help = new wxStaticText( m_scrolledWindow, wxID_ANY, wxEmptyString );
110
111 label->SetToolTip( aAction.GetTooltip() );
112 label->SetFont( titleFont );
113 label->SetLabel( aAction.GetFriendlyName() );
114
115 help->SetFont( helpFont );
116 help->SetLabel( aHelpText );
117
118 btn->Bind( wxEVT_BUTTON, &PANEL_KICAD_LAUNCHER::onLauncherButtonClick, this );
119 btn->SetClientData( (void*) &aAction );
120
121 // The bug fix below makes this handler active for the entire window width. Without
122 // any visual feedback that's a bit odd. Disabling for now.
123 // label->Bind( wxEVT_LEFT_UP, handler );
124
125 m_toolsSizer->Add( btn, 1, wxALIGN_CENTER_VERTICAL );
126
127 wxBoxSizer* textSizer = new wxBoxSizer( wxVERTICAL );
128
129 textSizer->Add( label );
130 textSizer->Add( help );
131
132 m_toolsSizer->Add( textSizer, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL );
133
134 btn->Enable( enabled );
135 if( !enabled )
136 {
137 help->Disable();
138 label->Disable();
139 }
140
141 return btn;
142 };
143
144 addLauncher( KICAD_MANAGER_ACTIONS::editSchematic, BITMAPS::icon_eeschema,
145 _( "Edit the project schematic" ) );
146
147 addLauncher( KICAD_MANAGER_ACTIONS::editSymbols, BITMAPS::icon_libedit,
148 _( "Edit global and/or project schematic symbol libraries" ) );
149
150 addLauncher( KICAD_MANAGER_ACTIONS::editPCB, BITMAPS::icon_pcbnew,
151 _( "Edit the project PCB design" ) );
152
153 addLauncher( KICAD_MANAGER_ACTIONS::editFootprints, BITMAPS::icon_modedit,
154 _( "Edit global and/or project PCB footprint libraries" ) );
155
156 addLauncher( KICAD_MANAGER_ACTIONS::viewGerbers, BITMAPS::icon_gerbview,
157 _( "Preview Gerber files" ) );
158
159 addLauncher( KICAD_MANAGER_ACTIONS::convertImage, BITMAPS::icon_bitmap2component,
160 _( "Convert bitmap images to schematic symbols or PCB footprints" ) );
161
162 addLauncher( KICAD_MANAGER_ACTIONS::showCalculator, BITMAPS::icon_pcbcalculator,
163 _( "Show tools for calculating resistance, current capacity, etc." ) );
164
165 addLauncher( KICAD_MANAGER_ACTIONS::editDrawingSheet, BITMAPS::icon_pagelayout_editor,
166 _( "Edit drawing sheet borders and title blocks for use in schematics and PCB "
167 "designs" ) );
168
169 BITMAP_BUTTON* bb =
170 addLauncher( KICAD_MANAGER_ACTIONS::showPluginManager, BITMAPS::icon_pcm,
171 _( "Manage downloadable packages from KiCad and 3rd party repositories" ),
174
175 m_frame->SetPcmButton( bb );
176
177 Layout();
178}
179
180
181void PANEL_KICAD_LAUNCHER::onThemeChanged( wxSysColourChangedEvent& aEvent )
182{
185
186 aEvent.Skip();
187}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:92
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:116
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
bool Enable(bool aEnable=true) override
Enable the button.
void SetDisabledBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is disabled.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
static TOOL_ACTION editPCB
static TOOL_ACTION editSchematic
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION editFootprints
static TOOL_ACTION showPluginManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION editSymbols
The main KiCad project manager frame.
void SetPcmButton(BITMAP_BUTTON *aButton)
Class PANEL_KICAD_LAUNCHER_BASE.
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void onLauncherButtonClick(wxCommandEvent &aEvent)
PANEL_KICAD_LAUNCHER(wxWindow *aParent)
KICAD_MANAGER_FRAME * m_frame
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Represent a single user action.
Definition: tool_action.h:269
wxString GetTooltip(bool aIncludeHotkey=true) const
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
wxString GetFriendlyName() const
Return the translated user-friendly name of the action.
void SetHasPosition(bool aHasPosition)
Returns if the action associated with this event should be treated as immediate regardless of the cur...
Definition: tool_event.h:257
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define _(s)
PBOOL GetPolicyBool(const wxString &aKey)
Definition: unix/policy.cpp:26
#define POLICY_KEY_PCM
Definition: policy_keys.h:31
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:629