Solaris' ln needs -s -f instead of -sf.
[kdbg.git] / DockWidget / knewpanner.cpp
blob95420cf904d8304be07bb4ca5a4890670f40c73b
1 // $Id$
3 /* This file is part of the KDE libraries
4 Copyright (C) 1997 Richard Moore (moorer@cs.man.ac.uk)
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
23 #include "knewpanner.h"
24 #include <stdio.h>
26 KNewPanner::KNewPanner(QWidget *parent, const char *name, Orientation orient, Units units, int pos)
27 : QWidget(parent, name)
29 divider = 0L;
30 orientation= orient;
31 currentunits= units;
32 position= pos;
33 initialised= false;
34 startHeight= 0;
37 KNewPanner::~KNewPanner()
41 void KNewPanner::activate(QWidget *c0, QWidget *c1)
43 int minx, maxx, miny, maxy, pos;
45 child0= c0;
46 child1= c1;
48 // Set the minimum and maximum sizes
49 if (orientation == Horizontal) {
50 miny= c0->minimumSize().height() + c1->minimumSize().height()+4;
51 maxy= c0->maximumSize().height() + c1->maximumSize().height()+4;
52 minx= (c0->minimumSize().width() > c1->minimumSize().width())
53 ? c0->minimumSize().width() : c1->minimumSize().width();
54 maxx= (c0->maximumSize().width() > c1->maximumSize().width())
55 ? c0->maximumSize().width() : c1->maximumSize().width();
57 miny= (miny > 4) ? miny : 4;
58 maxy= (maxy < 2000) ? maxy : 2000;
59 minx= (minx > 2) ? minx : 2;
60 maxx= (maxx < 2000) ? maxx : 2000;
62 setMinimumSize(minx, miny);
63 setMaximumSize(maxx, maxy);
65 else {
66 minx= c0->minimumSize().width() + c1->minimumSize().width()+4;
67 maxx= c0->maximumSize().width() + c1->maximumSize().width()+4;
68 miny= (c0->minimumSize().height() > c1->minimumSize().height())
69 ? c0->minimumSize().height() : c1->minimumSize().height();
70 maxy= (c0->maximumSize().height() > c1->maximumSize().height())
71 ? c0->maximumSize().height() : c1->maximumSize().height();
73 minx= (minx > 4) ? minx : 4;
74 maxx= (maxx < 2000) ? maxx : 2000;
75 miny= (miny > 2) ? miny : 2;
76 maxy= (maxy < 2000) ? maxy : 2000;
78 setMinimumSize(minx, miny);
79 setMaximumSize(maxx, maxy);
82 divider= new QFrame(this, "pannerdivider");
83 divider->setFrameStyle(QFrame::Panel | QFrame::Raised);
84 divider->setLineWidth(1);
85 divider->raise();
87 if (orientation == Horizontal)
88 divider->setCursor(QCursor(sizeVerCursor));
89 else
90 divider->setCursor(QCursor(sizeHorCursor));
92 divider->installEventFilter(this);
94 initialised= true;
96 pos= position;
97 position=0;
99 setSeparatorPos(pos);
100 divider->show();
103 void KNewPanner::deactivate()
105 if (divider != 0L) delete divider;
106 divider = 0L;
107 initialised= false;
110 int KNewPanner::separatorPos()
112 return position;
115 void KNewPanner::setSeparatorPos(int pos)
117 position = pos;
120 void KNewPanner::setAbsSeparatorPos(int pos, bool do_resize)
122 pos= checkValue(pos);
124 if (pos != absSeparatorPos()) {
125 if (currentunits == Percent)
126 position= pos * 100 / (orientation == Vertical?width():height());
127 else
128 position= pos;
129 if (do_resize)
130 resizeEvent(0);
134 int KNewPanner::absSeparatorPos()
136 int value;
138 if (currentunits == Percent)
139 value= (orientation == Vertical?width():height())*position/100;
140 else
141 value= position;
143 return value;
146 KNewPanner::Units KNewPanner::units()
148 return currentunits;
151 void KNewPanner::setUnits(Units u)
153 currentunits= u;
156 void KNewPanner::resizeEvent(QResizeEvent*)
158 if (initialised) {
159 if (orientation == Horizontal) {
160 child0->setGeometry(0, 0, width(), absSeparatorPos());
161 child1->setGeometry(0, absSeparatorPos()+4, width(),
162 height()-absSeparatorPos()-4);
163 divider->setGeometry(0, absSeparatorPos(), width(), 4);
165 else {
166 startHeight = 0;
167 child0->setGeometry(0, startHeight, absSeparatorPos(),
168 (height())-startHeight);
169 child1->setGeometry(absSeparatorPos()+4, startHeight,
170 (width())-(absSeparatorPos()+4),
171 (height())-startHeight);
172 divider->setGeometry(absSeparatorPos(), startHeight, 4,
173 (height())-startHeight);
178 int KNewPanner::checkValue(int pos)
180 if (initialised) {
181 if (orientation == Vertical) {
182 if (pos < (child0->minimumSize().width()))
183 pos= child0->minimumSize().width();
184 if ((width()-4-pos) < (child1->minimumSize().width()))
185 pos= width() - (child1->minimumSize().width()) -4;
187 else {
188 if (pos < (child0->minimumSize().height()))
189 pos= (child0->minimumSize().height());
190 if ((height()-4-pos) < (child1->minimumSize().height()))
191 pos= height() - (child1->minimumSize().height()) -4;
195 if (pos < 0) pos= 0;
197 if ((orientation == Vertical) && (pos > width()))
198 pos= width();
199 if ((orientation == Horizontal) && (pos > height()))
200 pos= height();
202 return pos;
205 #if QT_VERSION >= 200
206 #define EV(a,b) a
207 #else
208 #define EV(a,b) b
209 #endif
211 bool KNewPanner::eventFilter(QObject *, QEvent *e)
213 QMouseEvent *mev;
214 bool handled= false;
216 switch (e->type()) {
217 case EV(QEvent::MouseMove,Event_MouseMove):
218 mev= (QMouseEvent *)e;
219 child0->setUpdatesEnabled(false);
220 child1->setUpdatesEnabled(false);
221 if (orientation == Horizontal) {
222 setAbsSeparatorPos(divider->mapToParent(mev->pos()).y(), false);
223 divider->setGeometry(0, absSeparatorPos(), width(), 4);
224 divider->repaint(0);
226 else {
227 setAbsSeparatorPos(divider->mapToParent(mev->pos()).x(), false);
228 divider->setGeometry(absSeparatorPos(), 0, 4, height());
229 divider->repaint(0);
231 handled= true;
232 break;
233 case EV(QEvent::MouseButtonRelease,Event_MouseButtonRelease):
234 mev= (QMouseEvent *)e;
236 child0->setUpdatesEnabled(true);
237 child1->setUpdatesEnabled(true);
239 if (orientation == Horizontal) {
240 resizeEvent(0);
241 divider->repaint(true);
243 else {
244 resizeEvent(0);
245 divider->repaint(true);
247 handled= true;
248 break;
249 default:
250 break;
253 return handled;