libyui-qt  2.46.13
YQAlignment.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: YQAlignment.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
28 #include <qpixmap.h>
29 #include <QPainter>
30 #include "YQAlignment.h"
31 
32 using std::string;
33 
34 
35 YQAlignment::YQAlignment( YWidget * parent,
36  YAlignmentType horAlign,
37  YAlignmentType vertAlign )
38  : QWidget( (QWidget *) parent->widgetRep() )
39  , YAlignment( parent, horAlign, vertAlign ), _pixmapFileName()
40 {
41  setWidgetRep( this );
42 }
43 
44 
45 YQAlignment::YQAlignment( YWidget * yParent,
46  QWidget * qParent,
47  YAlignmentType horAlign,
48  YAlignmentType vertAlign )
49  : QWidget( qParent )
50  , YAlignment( yParent, horAlign, vertAlign ), _pixmapFileName()
51 {
52  setWidgetRep( this );
53 }
54 
55 
56 void YQAlignment::setEnabled( bool enabled )
57 {
58  QWidget::setEnabled( enabled );
59  YWidget::setEnabled( enabled );
60 }
61 
62 
63 void YQAlignment::moveChild( YWidget * child, int newX, int newY )
64 {
65  QWidget * qw = (QWidget *) ( child->widgetRep() );
66  qw->move( newX, newY );
67 }
68 
69 
70 void YQAlignment::setSize( int newWidth, int newHeight )
71 {
72  resize( newWidth, newHeight );
73  YAlignment::setSize( newWidth, newHeight );
74 }
75 
76 void YQAlignment::paintEvent ( QPaintEvent * event )
77 {
78  QPainter painter(this);
79  painter.drawPixmap(rect(), QPixmap(_pixmapFileName.c_str()));
80 
81  QWidget::paintEvent(event);
82 }
83 
84 void YQAlignment::setBackgroundPixmap( const std::string & pixmapFileName )
85 {
86  _pixmapFileName = pixmapFileName;
87 
88  YAlignment::setBackgroundPixmap( _pixmapFileName ); // Prepend path etc.
89  _pixmapFileName = YAlignment::backgroundPixmap();
90 
91  this->update();
92 }
93 
94 #include "YQAlignment.moc"
virtual void setBackgroundPixmap(const std::string &pixmapFileName)
Set the background pixmap.
Definition: YQAlignment.cc:84
virtual void setEnabled(bool enabled)
Enable or disable this widget and its child.
Definition: YQAlignment.cc:56
virtual void moveChild(YWidget *child, int newX, int newY)
Move the child widget to a new position.
Definition: YQAlignment.cc:63
YQAlignment(YWidget *parent, YAlignmentType horAlign, YAlignmentType vertAlign)
Constructor.
Definition: YQAlignment.cc:35
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQAlignment.cc:70