libyui-qt  2.53.0
YQPushButton.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQPushButton.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qpushbutton.h>
27 #include <qsize.h>
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 
31 #include "utf8.h"
32 #include "YQUI.h"
33 #include <yui/YEvent.h>
34 #include "YQPushButton.h"
35 
36 using std::string;
37 
38 
39 YQPushButton::YQPushButton( YWidget * parent,
40  const string & label )
41  : YQGenericButton( parent, label )
42 {
43  setWidgetRep( this );
44 
45  QPushButton * button = new QPushButton( fromUTF8( label ), this );
46  Q_CHECK_PTR( button );
47 
48  setQPushButton( button );
49 
50  button->setMinimumSize( 2, 2 );
51  button->move( YQButtonBorder, YQButtonBorder );
52  setMinimumSize( button->minimumSize()
53  + 2 * QSize( YQButtonBorder, YQButtonBorder ) );
54 
55  connect( button, &pclass(button)::clicked,
56  this, &pclass(this)::hit );
57 }
58 
59 
61 {
62  // NOP
63 }
64 
65 
67 {
68  return 2 * YQButtonBorder + qPushButton()->sizeHint().width();
69 }
70 
71 
73 {
74  return 2 * YQButtonBorder + qPushButton()->sizeHint().height();
75 }
76 
77 
78 void YQPushButton::setSize( int newWidth, int newHeight )
79 {
80  qPushButton()->resize( newWidth - 2 * YQButtonBorder,
81  newHeight - 2 * YQButtonBorder );
82  resize( newWidth, newHeight );
83 }
84 
85 
87 {
88  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) );
89 }
90 
91 
93 {
94  hit();
95 }
YQPushButton::hit
void hit()
Triggered when the button is activated (clicked or via keyboard).
Definition: YQPushButton.cc:86
YQUI::sendEvent
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:480
YQPushButton::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQPushButton.cc:78
YQPushButton::activate
virtual void activate()
Activate the button.
Definition: YQPushButton.cc:92
YQPushButton::~YQPushButton
virtual ~YQPushButton()
Destructor.
Definition: YQPushButton.cc:60
YQPushButton::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQPushButton.cc:72
YQPushButton::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQPushButton.cc:66
YQUI::ui
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:83
YQGenericButton
Abstract base class for push button and similar widgets - all that can become a YQDialog's "default b...
Definition: YQGenericButton.h:45
YQGenericButton::qPushButton
QPushButton * qPushButton() const
Returns the internal Qt PushButton.
Definition: YQGenericButton.h:124
YQPushButton::YQPushButton
YQPushButton(YWidget *parent, const std::string &label)
Constructor.
Definition: YQPushButton.cc:39
YQGenericButton::setQPushButton
void setQPushButton(QPushButton *pb)
Set the corresponding QPushButton.
Definition: YQGenericButton.cc:55