KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_fields_table.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) Mike Williams
5 * Copyright The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "dialog_fields_table.h"
23
24#include <algorithm>
25#include <bitmaps.h>
28#include <widgets/ui_common.h>
29#include <wx/filename.h>
30
31#ifdef __WXMAC__
32#define COLUMN_MARGIN 4
33#else
34#define COLUMN_MARGIN 15
35#endif
36
37
39{
40 m_nbPages->SetSelection( 0 );
41}
42
43
45{
46 m_nbPages->SetSelection( 1 );
47}
48
49
50wxString DIALOG_FIELDS_TABLE::GetDefaultBomFileName( const wxString& aInputFileName )
51{
52 if( aInputFileName.IsEmpty() )
53 return wxEmptyString;
54
55 wxFileName fn( aInputFileName );
56 fn.SetExt( FILEEXT::CsvFileExtension );
57
58 return fn.GetFullPath();
59}
60
61
62void DIALOG_FIELDS_TABLE::setSideBarButtonLook( bool aIsLeftPanelCollapsed )
63{
64 // Set bitmap and tooltip according to left panel visibility
65
66 if( aIsLeftPanelCollapsed )
67 {
69 m_sidebarButton->SetToolTip( _( "Expand left panel" ) );
70 }
71 else
72 {
74 m_sidebarButton->SetToolTip( _( "Collapse left panel" ) );
75 }
76}
77
78
80{
81 m_grid->ForceRefresh();
82}
83
84
85void DIALOG_FIELDS_TABLE::OnTableColSize( wxGridSizeEvent& aEvent )
86{
87 aEvent.Skip();
88
89 m_grid->ForceRefresh();
90}
91
92
93void DIALOG_FIELDS_TABLE::OnFilterMouseMoved( wxMouseEvent& aEvent )
94{
95#if defined( __WXOSX__ ) // Doesn't work properly on other ports
96 wxPoint pos = aEvent.GetPosition();
97 wxRect ctrlRect = m_filter->GetScreenRect();
98 int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
99
100 // TODO: restore cursor when mouse leaves the filter field (or is it a MSW bug?)
101 if( m_filter->IsSearchButtonVisible() && pos.x < buttonWidth )
102 SetCursor( wxCURSOR_ARROW );
103 else if( m_filter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
104 SetCursor( wxCURSOR_ARROW );
105 else
106 SetCursor( wxCURSOR_IBEAM );
107#endif
108}
109
110
112{
113 const wxString& showColLabel = m_viewControlsGrid->GetColLabelValue( SHOW_FIELD_COLUMN );
114 const wxString& groupByColLabel = m_viewControlsGrid->GetColLabelValue( GROUP_BY_COLUMN );
115 int showColWidth = KIUI::GetTextSize( showColLabel, m_viewControlsGrid ).x + COLUMN_MARGIN;
116 int groupByColWidth = KIUI::GetTextSize( groupByColLabel, m_viewControlsGrid ).x + COLUMN_MARGIN;
117 int remainingWidth = m_viewControlsGrid->GetSize().GetX() - showColWidth - groupByColWidth;
118
119 m_viewControlsGrid->SetColSize( showColWidth, SHOW_FIELD_COLUMN );
120 m_viewControlsGrid->SetColSize( groupByColWidth, GROUP_BY_COLUMN );
121
122 if( m_viewControlsGrid->IsColShown( DISPLAY_NAME_COLUMN ) && m_viewControlsGrid->IsColShown( LABEL_COLUMN ) )
123 {
124 m_viewControlsGrid->SetColSize( DISPLAY_NAME_COLUMN, std::max( remainingWidth / 2, 60 ) );
125 m_viewControlsGrid->SetColSize( LABEL_COLUMN, std::max( remainingWidth - ( remainingWidth / 2 ), 60 ) );
126 }
127 else if( m_viewControlsGrid->IsColShown( DISPLAY_NAME_COLUMN ) )
128 {
129 m_viewControlsGrid->SetColSize( DISPLAY_NAME_COLUMN, std::max( remainingWidth, 60 ) );
130 }
131 else if( m_viewControlsGrid->IsColShown( LABEL_COLUMN ) )
132 {
133 m_viewControlsGrid->SetColSize( LABEL_COLUMN, std::max( remainingWidth, 60 ) );
134 }
135
136 event.Skip();
137}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
void OnSizeViewControlsGrid(wxSizeEvent &event) override
void OnTableColSize(wxGridSizeEvent &event) override
void OnFilterMouseMoved(wxMouseEvent &event) override
void OnTableValueChanged(wxGridEvent &event) override
static wxString GetDefaultBomFileName(const wxString &aInputFileName)
Derive the default BOM output file name from the input file name by swapping the extension to CSV.
void setSideBarButtonLook(bool aIsLeftPanelCollapsed)
#define COLUMN_MARGIN
#define _(s)
static const std::string CsvFileExtension
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
Functions to provide common constants and other functions to assist in making a consistent UI.
Definition of file extensions used in Kicad.