KiCad PCB EDA Suite
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 );
39
40 Bind( wxEVT_SYS_COLOUR_CHANGED,
41 wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
42}
43
44
46{
47 m_frame->SetPcmButton( nullptr );
48
49 if( m_toolsSizer->GetRows() > 0 )
50 {
51 m_toolsSizer->Clear( true );
52 m_toolsSizer->SetRows( 0 );
53 }
54
55 wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
56#ifndef __WXGTK__
57 titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
58#endif
59 titleFont.SetWeight( wxFONTWEIGHT_BOLD );
60
61 wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
62 helpFont.SetStyle( wxFONTSTYLE_ITALIC );
63
64 auto addLauncher =
65 [&]( const TOOL_ACTION& aAction, const wxBitmap& aBitmap, const wxString& aHelpText, bool enabled = true )
66 {
67 BITMAP_BUTTON* btn = new BITMAP_BUTTON( this, wxID_ANY );
68 btn->SetBitmap( aBitmap );
69 btn->SetDisabledBitmap( wxBitmap( aBitmap.ConvertToImage().ConvertToGreyscale() ) );
70 btn->SetPadding( 5 );
71 btn->SetToolTip( aAction.GetDescription() );
72
73 auto handler =
74 [&]( wxEvent& aEvent )
75 {
76 // Defocus the button because leaving the large buttons
77 // focused after a click looks out of place in the launcher
78 m_frame->SetFocus();
79 // Gives a slice of time to update the button state (mandatory on GTK,
80 // useful on MSW to avoid some cosmetic issues).
81 wxSafeYield();
82
83 OPT_TOOL_EVENT evt = aAction.MakeEvent();
84 evt->SetHasPosition( false );
86 };
87
88 wxStaticText* label = new wxStaticText( this, wxID_ANY, aAction.GetLabel() );
89 wxStaticText* help;
90
91 label->SetToolTip( aAction.GetDescription() );
92 label->SetFont( titleFont );
93
94 help = new wxStaticText( this, wxID_ANY, aHelpText );
95 help->SetFont( helpFont );
96
97 btn->Bind( wxEVT_BUTTON, handler );
98
99 // The bug fix below makes this handler active for the entire window width. Without
100 // any visual feedback that's a bit odd. Disabling for now.
101 // label->Bind( wxEVT_LEFT_UP, handler );
102
103 int row = m_toolsSizer->GetRows();
104
105 m_toolsSizer->Add( btn, wxGBPosition( row, 0 ), wxGBSpan( 2, 1 ), wxBOTTOM, 12 );
106
107 // Due to https://trac.wxwidgets.org/ticket/16088?cversion=0&cnum_hist=7 GTK fails to
108 // correctly set the BestSize of non-default-size or styled text so we need to make
109 // sure that the BestSize isn't needed by setting wxEXPAND. Unfortunately this makes
110 // wxALIGN_BOTTOM non-functional, so we have to jump through a bunch more hoops to
111 // try and align the title and help text in the middle of the icon.
112 m_toolsSizer->Add( label, wxGBPosition( row, 1 ), wxGBSpan( 1, 1 ),
113 wxTOP | wxEXPAND, 10 );
114
115 m_toolsSizer->Add( help, wxGBPosition( row + 1, 1 ), wxGBSpan( 1, 1 ),
116 wxALIGN_TOP | wxTOP, 1 );
117
118 btn->Enable( enabled );
119 if( !enabled )
120 {
121 help->Disable();
122 label->Disable();
123 }
124
125 return btn;
126 };
127
129 KiScaledBitmap( BITMAPS::icon_eeschema, this, 48, true ),
130 _( "Edit the project schematic" ) );
131
133 KiScaledBitmap( BITMAPS::icon_libedit, this, 48, true ),
134 _( "Edit global and/or project schematic symbol libraries" ) );
135
137 KiScaledBitmap( BITMAPS::icon_pcbnew, this, 48, true ),
138 _( "Edit the project PCB design" ) );
139
141 KiScaledBitmap( BITMAPS::icon_modedit, this, 48, true ),
142 _( "Edit global and/or project PCB footprint libraries" ) );
143
145 KiScaledBitmap( BITMAPS::icon_gerbview, this, 48, true ),
146 _( "Preview Gerber files" ) );
147
150 _( "Convert bitmap images to schematic symbols or PCB footprints" ) );
151
154 _( "Show tools for calculating resistance, current capacity, etc." ) );
155
158 _( "Edit drawing sheet borders and title blocks for use in schematics and PCB "
159 "designs" ) );
160
161 BITMAP_BUTTON* bb =
163 KiScaledBitmap( BITMAPS::icon_pcm, this, 48, true ),
164 _( "Manage downloadable packages from KiCad and 3rd party repositories" ),
167
168 m_frame->SetPcmButton( bb );
169
170 Layout();
171}
172
173
174void PANEL_KICAD_LAUNCHER::onThemeChanged( wxSysColourChangedEvent &aEvent )
175{
178
179 aEvent.Skip();
180}
181
182
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:93
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:156
@ icon_pagelayout_editor
@ icon_eeschema
@ icon_bitmap2component
@ icon_libedit
@ icon_pcbcalculator
@ icon_gerbview
@ icon_modedit
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
bool Enable(bool aEnable=true) override
Enable the button.
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
void SetDisabledBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is disabled.
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.
TOOL_MANAGER * m_toolManager
void onThemeChanged(wxSysColourChangedEvent &aEvent)
PANEL_KICAD_LAUNCHER(wxWindow *aParent)
KICAD_MANAGER_FRAME * m_frame
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
Represent a single user action.
Definition: tool_action.h:68
wxString GetLabel() const
Definition: tool_action.cpp:83
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:97
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
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:244
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define _(s)
STATE GetPolicyState(const wxString &aKey)
Definition: gtk/policy.cpp:25
#define POLICY_KEY_PCM
Definition: policy_keys.h:29
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:557