Merge branch 'tglbtn' of https://github.com/catalinr/wxWidgets
Reimplement wxToggleButton correctly for wxQt. See https://github.com/wxWidgets/wxWidgets/pull/1228
This commit is contained in:
@@ -29,6 +29,7 @@ public:
|
||||
|
||||
// implementation only
|
||||
void QtUpdateState();
|
||||
virtual int GetEventType() const = 0;
|
||||
|
||||
protected:
|
||||
virtual wxBitmap DoGetBitmap(State state) const wxOVERRIDE;
|
||||
|
@@ -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);
|
||||
};
|
||||
|
@@ -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_
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
@@ -23,38 +23,9 @@
|
||||
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user