From 193cf3fee973da0a248b13d597e7f9a3593108ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Feb 2019 00:55:00 +0200 Subject: [PATCH 1/5] Change the order of class declarations only --- include/wx/qt/tglbtn.h | 66 +++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index 4b20ac2f75..2ac87910e1 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -12,39 +12,6 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[]; -class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButtonBase -{ -public: - wxBitmapToggleButton(); - wxBitmapToggleButton(wxWindow *parent, - wxWindowID id, - const wxBitmap& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxCheckBoxNameStr); - - bool Create(wxWindow *parent, - wxWindowID id, - const wxBitmap& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxCheckBoxNameStr); - - virtual void SetValue(bool state); - virtual bool GetValue() const; - - virtual QWidget *GetHandle() const; - -private: - wxDECLARE_DYNAMIC_CLASS(wxBitmapToggleButton); - -}; - - - class WXDLLIMPEXP_CORE wxToggleButton : public wxToggleButtonBase { public: @@ -76,4 +43,37 @@ private: }; + + +class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButtonBase +{ +public: + wxBitmapToggleButton(); + wxBitmapToggleButton(wxWindow *parent, + wxWindowID id, + const wxBitmap& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr); + + bool Create(wxWindow *parent, + wxWindowID id, + const wxBitmap& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr); + + virtual void SetValue(bool state); + virtual bool GetValue() const; + + virtual QWidget *GetHandle() const; + +private: + wxDECLARE_DYNAMIC_CLASS(wxBitmapToggleButton); + +}; + #endif // _WX_QT_TGLBTN_H_ From 39c9992ec9ad234b3e3afa2520b4afbf574b3c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Feb 2019 00:58:54 +0200 Subject: [PATCH 2/5] Remove declaration already present in common code --- include/wx/qt/tglbtn.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index 2ac87910e1..72ff09347a 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -10,7 +10,6 @@ #include "wx/tglbtn.h" -extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[]; class WXDLLIMPEXP_CORE wxToggleButton : public wxToggleButtonBase { From 50edbf24cc309568c8081025000ebeb2f33787db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Feb 2019 01:09:16 +0200 Subject: [PATCH 3/5] Change the base class of wxBitmapToggleButton --- include/wx/qt/tglbtn.h | 2 +- src/qt/tglbtn.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index 72ff09347a..6cebfe34e1 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -44,7 +44,7 @@ private: -class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButtonBase +class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButton { public: wxBitmapToggleButton(); diff --git a/src/qt/tglbtn.cpp b/src/qt/tglbtn.cpp index 8434179b9e..b4e971f35c 100644 --- a/src/qt/tglbtn.cpp +++ b/src/qt/tglbtn.cpp @@ -52,9 +52,9 @@ void wxQtToggleButton::clicked( bool checked ) } } -wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent ); +wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); -wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl); +wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton); wxBitmapToggleButton::wxBitmapToggleButton() { From 7be9c8c6707430c4feaefbe79b0c6dc4ef6fee08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Feb 2019 01:15:19 +0200 Subject: [PATCH 4/5] Remove functions that are identical with the ones in base classes --- include/wx/qt/tglbtn.h | 5 ----- src/qt/tglbtn.cpp | 20 -------------------- 2 files changed, 25 deletions(-) diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index 6cebfe34e1..a2c9373974 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -35,7 +35,6 @@ public: virtual void SetValue(bool state); virtual bool GetValue() const; - virtual QWidget *GetHandle() const; private: wxDECLARE_DYNAMIC_CLASS(wxToggleButton); @@ -65,10 +64,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxCheckBoxNameStr); - virtual void SetValue(bool state); - virtual bool GetValue() const; - - virtual QWidget *GetHandle() const; private: wxDECLARE_DYNAMIC_CLASS(wxBitmapToggleButton); diff --git a/src/qt/tglbtn.cpp b/src/qt/tglbtn.cpp index b4e971f35c..a03d5a7cfa 100644 --- a/src/qt/tglbtn.cpp +++ b/src/qt/tglbtn.cpp @@ -86,21 +86,6 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, return QtCreateControl( parent, id, pos, size, style, validator, name ); } -void wxBitmapToggleButton::SetValue(bool state) -{ - m_qtPushButton->setChecked( state ); -} - -bool wxBitmapToggleButton::GetValue() const -{ - return m_qtPushButton->isChecked(); -} - -QWidget *wxBitmapToggleButton::GetHandle() const -{ - return m_qtPushButton; -} - //############################################################################## wxIMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl); @@ -147,8 +132,3 @@ bool wxToggleButton::GetValue() const { return m_qtPushButton->isChecked(); } - -QWidget *wxToggleButton::GetHandle() const -{ - return m_qtPushButton; -} From be9c18cbd6b72242f56d2c90ae485367f0ada9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Feb 2019 01:23:20 +0200 Subject: [PATCH 5/5] Reuse Qt implementation of normal button for toggle buttons --- include/wx/qt/anybutton.h | 1 + include/wx/qt/button.h | 3 +++ include/wx/qt/tglbtn.h | 2 ++ src/qt/anybutton.cpp | 8 +++++-- src/qt/tglbtn.cpp | 50 +++++++++++++-------------------------- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/include/wx/qt/anybutton.h b/include/wx/qt/anybutton.h index 57ca06bead..eb3951aca7 100644 --- a/include/wx/qt/anybutton.h +++ b/include/wx/qt/anybutton.h @@ -29,6 +29,7 @@ public: // implementation only void QtUpdateState(); + virtual int GetEventType() const = 0; protected: virtual wxBitmap DoGetBitmap(State state) const wxOVERRIDE; diff --git a/include/wx/qt/button.h b/include/wx/qt/button.h index 0bbce110a4..d1b11c1f51 100644 --- a/include/wx/qt/button.h +++ b/include/wx/qt/button.h @@ -31,6 +31,9 @@ public: virtual wxWindow *SetDefault(); + // implementation only + virtual int GetEventType() const wxOVERRIDE { return wxEVT_BUTTON; } + private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxButton); }; diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index a2c9373974..f2b361e579 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -35,6 +35,8 @@ public: virtual void SetValue(bool state); virtual bool GetValue() const; + // implementation only + virtual int GetEventType() const wxOVERRIDE { return wxEVT_TOGGLEBUTTON; } private: wxDECLARE_DYNAMIC_CLASS(wxToggleButton); diff --git a/src/qt/anybutton.cpp b/src/qt/anybutton.cpp index b0392263c4..acb5f4c6fd 100644 --- a/src/qt/anybutton.cpp +++ b/src/qt/anybutton.cpp @@ -40,12 +40,16 @@ wxQtPushButton::wxQtPushButton(wxWindow *parent, wxAnyButton *handler) connect(this, &QPushButton::released, this, &wxQtPushButton::action); } -void wxQtPushButton::clicked( bool WXUNUSED(checked) ) +void wxQtPushButton::clicked(bool checked) { wxAnyButton *handler = GetHandler(); if ( handler ) { - wxCommandEvent event( wxEVT_BUTTON, handler->GetId() ); + wxCommandEvent event( handler->GetEventType(), handler->GetId() ); + if ( isCheckable() ) // toggle buttons + { + event.SetInt(checked); + } EmitEvent( event ); } } diff --git a/src/qt/tglbtn.cpp b/src/qt/tglbtn.cpp index a03d5a7cfa..5244627091 100644 --- a/src/qt/tglbtn.cpp +++ b/src/qt/tglbtn.cpp @@ -23,35 +23,6 @@ #include -class wxQtToggleButton : public wxQtEventSignalHandler< QPushButton, wxAnyButton > -{ - -public: - wxQtToggleButton( wxWindow *parent, wxAnyButton *handler); - -private: - void clicked( bool checked ); -}; - -wxQtToggleButton::wxQtToggleButton(wxWindow *parent, wxAnyButton *handler) - : wxQtEventSignalHandler< QPushButton, wxAnyButton >( parent, handler ) -{ - setCheckable( true ); - connect(this, &QPushButton::clicked, this, &wxQtToggleButton::clicked); -} - -void wxQtToggleButton::clicked( bool checked ) -{ - wxAnyButton *handler = GetHandler(); - if ( handler ) - { - // for toggle buttons, send the checked state in the wx event: - wxCommandEvent event( wxEVT_TOGGLEBUTTON, handler->GetId() ); - event.SetInt( checked ); - EmitEvent( event ); - } -} - wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton); @@ -80,10 +51,22 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - // this button is toggleable and has a bitmap label: - QtSetBitmap( label ); + if ( !wxToggleButton::Create(parent, id, wxString(), pos, size, style, validator, name) ) + { + return false; + } - return QtCreateControl( parent, id, pos, size, style, validator, name ); + // this button is toggleable and has a bitmap label: + if ( label.IsOk() ) + { + SetBitmapLabel(label); + + // we need to adjust the size after setting the bitmap as it may be too + // big for the default button size + SetInitialSize(size); + } + + return true; } //############################################################################## @@ -115,7 +98,8 @@ bool wxToggleButton::Create(wxWindow *parent, const wxString& name) { // create a checkable push button - m_qtPushButton = new wxQtToggleButton( parent, this ); + QtCreate(parent); + m_qtPushButton->setCheckable(true); // this button is toggleable and has a text label SetLabel( wxIsStockID( id ) ? wxGetStockLabel( id ) : label );