summaryrefslogtreecommitdiffstats
path: root/arts/gui/kde/klayoutbox_impl.cpp
blob: 7f9efa9b295915c3b927b819b9c6e31770601e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
    Copyright ( C ) 2002, 2003 Arnold Krille <arnold@arnoldarts.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or ( at your option ) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include "klayoutbox_impl.h"

#include <qframe.h>
#include <qlayout.h>
#include <kdebug.h>
#include <qpainter.h>
#include <qstyle.h>
#include <qpen.h>
#include "kwidgetrepo.h"

using namespace Arts;
using namespace std;

KLayoutBox_impl::KLayoutBox_impl( QFrame *widget ) : KFrame_impl( widget ? widget :new QFrame( 0 ) )
{
	_qframe = static_cast<QFrame*>( _qwidget );
	_layout = new QBoxLayout( _qframe, QBoxLayout::LeftToRight );
}
KLayoutBox_impl::~KLayoutBox_impl() {
}

void KLayoutBox_impl::addWidget( Arts::Widget widget, long stretch, long align ) {
	widget.parent( self() );
	this->_addChild( widget, "layoutbox_item" );
	QWidget * tmp = KWidgetRepo::the()->lookupQWidget( widget.widgetID() );
	_layout->addWidget( tmp, stretch, align );
}

void KLayoutBox_impl::insertWidget( long index, Arts::Widget widget, long stretch, long align ) {
	widget.parent( self() );
	this->_addChild( widget, "layoutbox_item" );
	QWidget * tmp = KWidgetRepo::the()->lookupQWidget( widget.widgetID() );
	_layout->insertWidget( index, tmp, stretch, align );
}

void KLayoutBox_impl::addStretch( long n ) { _layout->addStretch( n ); }
void KLayoutBox_impl::addSpace( long n ) { _layout->addSpacing( n ); }
void KLayoutBox_impl::addStrut( long n ) { _layout->addStrut( n ); }
void KLayoutBox_impl::addSeparator( long stretch, long align ) {
	_layout->addWidget( new KLayoutBox_Separator( _qframe ), stretch, align );
}
void KLayoutBox_impl::addLine( long width, long space, long stretch, long align ) {
	_layout->addWidget( new KLayoutBox_Line( width, space, _qframe ), stretch, align );
}

long KLayoutBox_impl::spacing() { return _layout->spacing(); }
void KLayoutBox_impl::spacing( long n ) { _layout->setSpacing( n ); }

long KLayoutBox_impl::layoutmargin() { return _layout->margin(); }
void KLayoutBox_impl::layoutmargin( long n ) { _layout->setMargin( n ); this->margin( n ); }

Direction KLayoutBox_impl::direction() { return Arts::Direction( _layout->direction() ); }
void KLayoutBox_impl::direction( Direction d ) { _layout->setDirection( QBoxLayout::Direction( d ) ); }

REGISTER_IMPLEMENTATION( KLayoutBox_impl );

KLayoutBox_Separator::KLayoutBox_Separator( QWidget* p, const char* n ) : QWidget( p,n ) {
//kdDebug() << k_funcinfo << endl;
}

void KLayoutBox_Separator::resizeEvent( QResizeEvent* ) { kdDebug() << k_funcinfo << size() << endl; }

void KLayoutBox_Separator::paintEvent( QPaintEvent* ) {
//kdDebug() << k_funcinfo << size() << endl;
	QPainter p( this );
	QStyle::SFlags flags = QStyle::Style_Default;
	if ( width() < height() ) flags |= QStyle::Style_Horizontal;
	style().drawPrimitive( QStyle::PE_Splitter, &p, rect(), colorGroup(), flags );
}

QSize KLayoutBox_Separator::minimumSizeHint() const {
	int wh = style().pixelMetric( QStyle::PM_SplitterWidth, this );
	return QSize( wh, wh );
}

KLayoutBox_Line::KLayoutBox_Line( int width, int space, QWidget* p, const char* n )
  : QWidget( p,n )
  , _width( width )
  , _space( space )
{
//kdDebug() << k_funcinfo << size() << endl;
}


void KLayoutBox_Line::paintEvent( QPaintEvent* ) {
//kdDebug() << k_funcinfo << size() << endl;
	QPainter p( this );
	p.setPen( QPen( colorGroup().foreground(), _width ) );
	if ( width() > height() ) p.drawLine( 0, height()/2, width(), height()/2 );
		else p.drawLine( width()/2, 0, width()/2, height() );
}

QSize KLayoutBox_Line::minimumSizeHint() const {
//kdDebug() << k_funcinfo << size() << endl;
	int wh = _width + 2* _space;
	return QSize( wh, wh );
}

#include <klayoutbox_impl.moc>

// vim: sw=4 ts=4