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 4b20ac2f75..f2b361e579 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -10,40 +10,6 @@ #include "wx/tglbtn.h" -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 { @@ -69,11 +35,41 @@ public: virtual void SetValue(bool state); virtual bool GetValue() const; - virtual QWidget *GetHandle() const; + // implementation only + virtual int GetEventType() const wxOVERRIDE { return wxEVT_TOGGLEBUTTON; } private: wxDECLARE_DYNAMIC_CLASS(wxToggleButton); }; + + +class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButton +{ +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); + + +private: + wxDECLARE_DYNAMIC_CLASS(wxBitmapToggleButton); + +}; + #endif // _WX_QT_TGLBTN_H_ 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 8434179b9e..5244627091 100644 --- a/src/qt/tglbtn.cpp +++ b/src/qt/tglbtn.cpp @@ -23,38 +23,9 @@ #include -class wxQtToggleButton : public wxQtEventSignalHandler< QPushButton, wxAnyButton > -{ +wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); -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_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent ); - -wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl); +wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton); wxBitmapToggleButton::wxBitmapToggleButton() { @@ -80,25 +51,22 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { + if ( !wxToggleButton::Create(parent, id, wxString(), pos, size, style, validator, name) ) + { + return false; + } + // this button is toggleable and has a bitmap label: - QtSetBitmap( label ); + if ( label.IsOk() ) + { + SetBitmapLabel(label); - return QtCreateControl( parent, id, pos, size, style, validator, name ); -} + // we need to adjust the size after setting the bitmap as it may be too + // big for the default button size + SetInitialSize(size); + } -void wxBitmapToggleButton::SetValue(bool state) -{ - m_qtPushButton->setChecked( state ); -} - -bool wxBitmapToggleButton::GetValue() const -{ - return m_qtPushButton->isChecked(); -} - -QWidget *wxBitmapToggleButton::GetHandle() const -{ - return m_qtPushButton; + return true; } //############################################################################## @@ -130,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 ); @@ -147,8 +116,3 @@ bool wxToggleButton::GetValue() const { return m_qtPushButton->isChecked(); } - -QWidget *wxToggleButton::GetHandle() const -{ - return m_qtPushButton; -}