KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kistatusbar.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) 2023 Mark Roszko <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <wx/button.h>
26#include <wx/statusbr.h>
27#include <wx/gauge.h>
28#include <wx/stattext.h>
29#include <array>
30#include <widgets/kistatusbar.h>
32#include <pgm_base.h>
35#include <bitmaps.h>
36
37
38#define FIELD_OFFSET_BGJOB_TEXT 0
39#define FIELD_OFFSET_BGJOB_GAUGE 1
40#define FIELD_OFFSET_BGJOB_CANCEL 2
41#define FIELD_OFFSET_NOTIFICATION_BUTTON 3
42
43
44KISTATUSBAR::KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ) :
45 wxStatusBar( parent, id ),
46 m_normalFieldsCount( aNumberFields )
47{
48#ifdef __WXOSX__
49 // we need +1 extra field on OSX to offset from the rounded corner on the right
50 // OSX doesnt use resize grippers like the other platforms and the statusbar field
51 // includes the rounded part
52 const int ExtraFields = 5;
53#else
54 const int ExtraFields = 4;
55#endif
56 SetFieldsCount( aNumberFields + ExtraFields );
57
58 int* widths = new int[aNumberFields + ExtraFields];
59
60 for( int i = 0; i < aNumberFields; i++ )
61 widths[i] = -1;
62
63 widths[aNumberFields + FIELD_OFFSET_BGJOB_TEXT] = 200; // background status text field
64 widths[aNumberFields + FIELD_OFFSET_BGJOB_GAUGE] = 75; // background progress button
65 widths[aNumberFields + FIELD_OFFSET_BGJOB_CANCEL] = 20; // background stop button
66 widths[aNumberFields + FIELD_OFFSET_NOTIFICATION_BUTTON] = 20; // notifications button
67#ifdef __WXOSX__
68 // offset from the right edge
69 widths[aNumberFields + ExtraFields - 1] = 10;
70#endif
71
72 SetStatusWidths( aNumberFields + ExtraFields, widths );
73 delete[] widths;
74
75
76 int* styles = new int[aNumberFields + ExtraFields];
77 for( int i = 0; i < aNumberFields + ExtraFields; i++ )
78 styles[i] = wxSB_FLAT;
79
80 SetStatusStyles( aNumberFields + ExtraFields, styles );
81 delete[] styles;
82
83 m_backgroundTxt = new wxStaticText( this, wxID_ANY, wxT( "" ) );
84
85 m_backgroundProgressBar = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize,
86 wxGA_HORIZONTAL | wxGA_SMOOTH );
87
88 m_backgroundStopButton = new wxButton( this, wxID_ANY, "X", wxDefaultPosition, wxDefaultSize,
89 wxBU_EXACTFIT );
90
91 m_notificationsButton = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
92 wxDefaultSize, wxBU_EXACTFIT );
93
95 m_notificationsButton->SetBitmap( KiBitmapBundle( BITMAPS::notifications ) );
98
100
101 Bind( wxEVT_SIZE, &KISTATUSBAR::onSize, this );
103
105 Layout();
106}
107
108
109void KISTATUSBAR::onNotificationsIconClick( wxCommandEvent& aEvent )
110{
111 wxPoint pos = m_notificationsButton->GetScreenPosition();
112
113 wxRect r;
114 GetFieldRect( m_normalFieldsCount + 3, r );
115 pos.x += r.GetWidth();
116
117 Pgm().GetNotificationsManager().ShowList( this, pos );
118}
119
120
121void KISTATUSBAR::onBackgroundProgressClick( wxMouseEvent& aEvent )
122{
123 wxPoint pos = m_backgroundProgressBar->GetScreenPosition();
124
125 wxRect r;
126 GetFieldRect( m_normalFieldsCount + 1, r );
127 pos.x += r.GetWidth();
128
129 Pgm().GetBackgroundJobMonitor().ShowList( this, pos );
130}
131
132void KISTATUSBAR::onSize( wxSizeEvent& aEvent )
133{
134 wxRect r;
135 GetFieldRect( m_normalFieldsCount + FIELD_OFFSET_BGJOB_TEXT, r );
136 int x = r.GetLeft();
137 int y = r.GetTop();
138
139 m_backgroundTxt->SetPosition( { x, y } );
140
142 x = r.GetLeft();
143 y = r.GetTop();
144 int w = r.GetWidth();
145 int h = r.GetHeight();
146 constexpr int b = 5;
147
148 auto buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
149 m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
150 m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
151
152 m_backgroundProgressBar->SetPosition( { x, y } );
153 m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - b, h );
154
156 x = r.GetLeft();
157 y = r.GetTop();
158 h = r.GetHeight();
159 buttonSize = m_notificationsButton->GetEffectiveMinSize();
160 m_notificationsButton->SetPosition( { x, y } );
161 m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
162}
163
164
166{
168
169 if( aCancellable )
171 else
173}
174
175
177{
180}
181
182
184{
185 m_backgroundProgressBar->SetValue( aAmount );
186}
187
188
190{
191 m_backgroundProgressBar->SetRange( aAmount );
192}
193
194
195void KISTATUSBAR::SetBackgroundStatusText( const wxString& aTxt )
196{
197 m_backgroundTxt->SetLabel( aTxt );
198}
199
200
202{
203 wxString cnt = "";
204 if( aCount > 0 )
205 {
206 cnt = wxString::Format( "%d", aCount );
207 }
208
210
211 // force a repaint or it wont until it gets activity
212 Refresh();
213}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void SetBadgeText(const wxString &aText)
void SetBitmapCentered(bool aCentered=true)
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
void SetShowBadge(bool aShowBadge)
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
BITMAP_BUTTON * m_notificationsButton
Definition: kistatusbar.h:79
void SetBackgroundStatusText(const wxString &aTxt)
Sets the status text that displays next to the progress bar.
void onBackgroundProgressClick(wxMouseEvent &aEvent)
void onSize(wxSizeEvent &aEvent)
int m_normalFieldsCount
Definition: kistatusbar.h:80
void SetBackgroundProgress(int aAmount)
Sets the current progress of the progress bar.
wxGauge * m_backgroundProgressBar
Definition: kistatusbar.h:76
wxButton * m_backgroundStopButton
Definition: kistatusbar.h:77
void HideBackgroundProgressBar()
Hides the background progress bar.
void onNotificationsIconClick(wxCommandEvent &aEvent)
void SetBackgroundProgressMax(int aAmount)
Sets the maX progress of the progress bar.
KISTATUSBAR(int aNumberFields, wxWindow *parent, wxWindowID id)
Definition: kistatusbar.cpp:44
wxStaticText * m_backgroundTxt
Definition: kistatusbar.h:78
void ShowBackgroundProgressBar(bool aCancellable=false)
Shows the background progress bar.
void SetNotificationCount(int aCount)
Sets the notification count on the notifications button A value of 0 will hide the count.
#define FIELD_OFFSET_BGJOB_TEXT
Definition: kistatusbar.cpp:38
#define FIELD_OFFSET_BGJOB_GAUGE
Definition: kistatusbar.cpp:39
#define FIELD_OFFSET_NOTIFICATION_BUTTON
Definition: kistatusbar.cpp:41
#define FIELD_OFFSET_BGJOB_CANCEL
Definition: kistatusbar.cpp:40
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119