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 <tool/tool_manager.h>
24 #include <tools/kicad_manager_actions.h>
25 #include <widgets/bitmap_button.h>
26 #include <wx/stattext.h>
27
28 #include "panel_kicad_launcher.h"
29
30
PANEL_KICAD_LAUNCHER(wxWindow * aParent)31 PANEL_KICAD_LAUNCHER::PANEL_KICAD_LAUNCHER( wxWindow* aParent ) :
32 PANEL_KICAD_LAUNCHER_BASE( aParent )
33 {
34 m_frame = static_cast<KICAD_MANAGER_FRAME*>( aParent );
35 m_toolManager = m_frame->GetToolManager();
36 CreateLaunchers();
37
38 Bind( wxEVT_SYS_COLOUR_CHANGED,
39 wxSysColourChangedEventHandler( PANEL_KICAD_LAUNCHER::onThemeChanged ), this );
40 }
41
42
CreateLaunchers()43 void PANEL_KICAD_LAUNCHER::CreateLaunchers()
44 {
45 if( m_toolsSizer->GetRows() > 0 )
46 {
47 m_toolsSizer->Clear( true );
48 m_toolsSizer->SetRows( 0 );
49 }
50
51 wxFont titleFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
52 #ifndef __WXGTK__
53 titleFont.SetPointSize( titleFont.GetPointSize() + 2 );
54 #endif
55 titleFont.SetWeight( wxFONTWEIGHT_BOLD );
56
57 wxFont helpFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
58 helpFont.SetStyle( wxFONTSTYLE_ITALIC );
59
60 auto addLauncher =
61 [&]( const TOOL_ACTION& aAction, const wxBitmap& aBitmap, const wxString& aHelpText )
62 {
63 BITMAP_BUTTON* btn = new BITMAP_BUTTON( this, wxID_ANY );
64 btn->SetBitmap( aBitmap );
65 btn->SetPadding( 5 );
66 btn->SetToolTip( aAction.GetDescription() );
67
68 auto handler =
69 [&]( wxEvent& aEvent )
70 {
71 // Defocus the button because leaving the large buttons
72 // focused after a click looks out of place in the launcher
73 m_frame->SetFocus();
74 // Gives a slice of time to update the button state (mandatory on GTK,
75 // useful on MSW to avoid some cosmetic issues).
76 wxSafeYield();
77
78 OPT_TOOL_EVENT evt = aAction.MakeEvent();
79 evt->SetHasPosition( false );
80 m_toolManager->ProcessEvent( *evt );
81 };
82
83 wxStaticText* label = new wxStaticText( this, wxID_ANY, aAction.GetLabel() );
84 wxStaticText* help;
85
86 label->SetToolTip( aAction.GetDescription() );
87 label->SetFont( titleFont );
88
89 help = new wxStaticText( this, wxID_ANY, aHelpText );
90 help->SetFont( helpFont );
91
92 btn->Bind( wxEVT_BUTTON, handler );
93
94 // The bug fix below makes this handler active for the entire window width. Without
95 // any visual feedback that's a bit odd. Disabling for now.
96 // label->Bind( wxEVT_LEFT_UP, handler );
97
98 int row = m_toolsSizer->GetRows();
99
100 m_toolsSizer->Add( btn, wxGBPosition( row, 0 ), wxGBSpan( 2, 1 ), wxBOTTOM, 12 );
101
102 // Due to https://trac.wxwidgets.org/ticket/16088?cversion=0&cnum_hist=7 GTK fails to
103 // correctly set the BestSize of non-default-size or styled text so we need to make
104 // sure that the BestSize isn't needed by setting wxEXPAND. Unfortunately this makes
105 // wxALIGN_BOTTOM non-functional, so we have to jump through a bunch more hoops to
106 // try and align the title and help text in the middle of the icon.
107 m_toolsSizer->Add( label, wxGBPosition( row, 1 ), wxGBSpan( 1, 1 ),
108 wxTOP | wxEXPAND, 10 );
109
110 m_toolsSizer->Add( help, wxGBPosition( row + 1, 1 ), wxGBSpan( 1, 1 ),
111 wxALIGN_TOP | wxTOP, 1 );
112 };
113
114 addLauncher( KICAD_MANAGER_ACTIONS::editSchematic,
115 KiScaledBitmap( BITMAPS::icon_eeschema, this, 48, true ),
116 _( "Edit the project schematic" ) );
117
118 addLauncher( KICAD_MANAGER_ACTIONS::editSymbols,
119 KiScaledBitmap( BITMAPS::icon_libedit, this, 48, true ),
120 _( "Edit global and/or project schematic symbol libraries" ) );
121
122 addLauncher( KICAD_MANAGER_ACTIONS::editPCB,
123 KiScaledBitmap( BITMAPS::icon_pcbnew, this, 48, true ),
124 _( "Edit the project PCB design" ) );
125
126 addLauncher( KICAD_MANAGER_ACTIONS::editFootprints,
127 KiScaledBitmap( BITMAPS::icon_modedit, this, 48, true ),
128 _( "Edit global and/or project PCB footprint libraries" ) );
129
130 addLauncher( KICAD_MANAGER_ACTIONS::viewGerbers,
131 KiScaledBitmap( BITMAPS::icon_gerbview, this, 48, true ),
132 _( "Preview Gerber files" ) );
133
134 addLauncher( KICAD_MANAGER_ACTIONS::convertImage,
135 KiScaledBitmap( BITMAPS::icon_bitmap2component, this, 48, true ),
136 _( "Convert bitmap images to schematic symbols or PCB footprints" ) );
137
138 addLauncher( KICAD_MANAGER_ACTIONS::showCalculator,
139 KiScaledBitmap( BITMAPS::icon_pcbcalculator, this, 48, true ),
140 _( "Show tools for calculating resistance, current capacity, etc." ) );
141
142 addLauncher( KICAD_MANAGER_ACTIONS::editDrawingSheet,
143 KiScaledBitmap( BITMAPS::icon_pagelayout_editor, this, 48, true ),
144 _( "Edit drawing sheet borders and title blocks for use in schematics and PCB "
145 "designs" ) );
146
147 #ifdef PCM
148 addLauncher( KICAD_MANAGER_ACTIONS::showPluginManager,
149 KiScaledBitmap( BITMAPS::icon_pcm, this, 48, true ),
150 _( "Manage downloadable packages from KiCad and 3rd party repositories" ) );
151 #endif
152
153 Layout();
154 }
155
156
onThemeChanged(wxSysColourChangedEvent & aEvent)157 void PANEL_KICAD_LAUNCHER::onThemeChanged( wxSysColourChangedEvent &aEvent )
158 {
159 GetBitmapStore()->ThemeChanged();
160 CreateLaunchers();
161
162 aEvent.Skip();
163 }
164
165
166