summaryrefslogtreecommitdiffstats
path: root/arts/gui/kde/kwidget_impl.cpp
blob: 261cf30b105b555f777eeec8bb256853fca9ae4c (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
    /*

    Copyright (C) 2000 Stefan Westerfeld
                       stefan@space.twc.de
                  2002 Matthias Kretz <kretz@kde.org>

    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., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

    */

#include "kwidget_impl.h"
#include "kwidgetrepo.h"
#include "debug.h"
#include <stdio.h>

using namespace Arts;

KWidget_impl::KWidget_impl( QWidget * widget )
	: _qwidget( widget ? widget : new QWidget )
{
	_widgetID = KWidgetRepo::the()->add( this, _qwidget );

	/*
	 * KWidgetGuard will protect us against deleting the widget if Qt already
	 * has done so (for instance if our widget was inside a panel, and
	 * the panel got deleted, our widget will be gone, too)
	 */
	_guard = new KWidgetGuard(this);
	QObject::connect(_qwidget, SIGNAL(destroyed()),
			_guard, SLOT(widgetDestroyed()));
}

KWidget_impl::~KWidget_impl()
{
	if(_qwidget)
	{
		delete _qwidget;
		arts_assert(_qwidget == 0);	// should be true due to KWidgetGuard
	}
	delete _guard;
}

void KWidget_impl::widgetDestroyed()
{
	KWidgetRepo::the()->remove(_widgetID);
	_widgetID = 0;
	_qwidget = 0;
}

long KWidget_impl::widgetID()
{
	return _widgetID;
}

Widget KWidget_impl::parent()
{
	return KWidgetRepo::the()->lookupWidget(_parentID);
}

void KWidget_impl::parent(Arts::Widget newParent)
{
	if(!newParent.isNull())
	{
		_parentID = newParent.widgetID();

		QWidget *qparent;
		qparent = KWidgetRepo::the()->lookupQWidget(newParent.widgetID());
		if( qparent != 0 )
		{
			QPoint pos(x(),y());
			bool showIt = visible();
			_qwidget->reparent(qparent, pos, showIt);
		}
	}
	else
	{
		_parentID = 0;
	}
}

long KWidget_impl::x()
{
	return _qwidget->x();
}

void KWidget_impl::x(long newX)
{
	_qwidget->move(newX,y());
}

long KWidget_impl::y()
{
	return _qwidget->y();
}

void KWidget_impl::y(long newY)
{
	_qwidget->move(x(),newY);
}

long KWidget_impl::width()
{
	return _qwidget->width();
}

void KWidget_impl::width(long newWidth)
{
	_qwidget->resize(newWidth,height());
}

long KWidget_impl::height()
{
	return _qwidget->height();
}

void KWidget_impl::height(long newHeight)
{
	_qwidget->resize(width(),newHeight);
}

bool KWidget_impl::visible()
{
	return _qwidget->isVisible();
}

void KWidget_impl::visible(bool newVisible)
{
	if(newVisible) show(); else hide();
}

SizePolicy KWidget_impl::hSizePolicy()
{
	return ( SizePolicy )_qwidget->sizePolicy().horData();
}

void KWidget_impl::hSizePolicy( SizePolicy p )
{
	QSizePolicy sp = _qwidget->sizePolicy();
	sp.setHorData( ( QSizePolicy::SizeType )p );
	_qwidget->setSizePolicy( sp );
}

SizePolicy KWidget_impl::vSizePolicy()
{
	return ( SizePolicy )_qwidget->sizePolicy().verData();
}

void KWidget_impl::vSizePolicy( SizePolicy p )
{
	QSizePolicy sp = _qwidget->sizePolicy();
	sp.setVerData( ( QSizePolicy::SizeType )p );
	_qwidget->setSizePolicy( sp );
}

void KWidget_impl::show()
{
	_qwidget->show();
}

void KWidget_impl::hide()
{
	_qwidget->hide();
}

REGISTER_IMPLEMENTATION(KWidget_impl);
#include "kwidget_impl.moc"

// vim: sw=4 ts=4