Added a primitive guess of the executable's language.
[kdbg.git] / DockWidget / knewpanner.cpp
blobb687fe45240236c6e386b593dbb2a9c5d42bbcc1
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 <qcursor.h>
25 #include <stdio.h>
27 KNewPanner::KNewPanner(QWidget *parent, const char *name, Orientation orient, Units units, int pos)
28 : QWidget(parent, name)
30 divider = 0L;
31 orientation= orient;
32 currentunits= units;
33 position= pos;
34 initialised= false;
35 startHeight= 0;
38 KNewPanner::~KNewPanner()
42 void KNewPanner::activate(QWidget *c0, QWidget *c1)
44 int minx, maxx, miny, maxy, pos;
46 child0= c0;
47 child1= c1;
49 // Set the minimum and maximum sizes
50 if (orientation == Horizontal) {
51 miny= c0->minimumSize().height() + c1->minimumSize().height()+4;
52 maxy= c0->maximumSize().height() + c1->maximumSize().height()+4;
53 minx= (c0->minimumSize().width() > c1->minimumSize().width())
54 ? c0->minimumSize().width() : c1->minimumSize().width();
55 maxx= (c0->maximumSize().width() > c1->maximumSize().width())
56 ? c0->maximumSize().width() : c1->maximumSize().width();
58 miny= (miny > 4) ? miny : 4;
59 maxy= (maxy < 2000) ? maxy : 2000;
60 minx= (minx > 2) ? minx : 2;
61 maxx= (maxx < 2000) ? maxx : 2000;
63 setMinimumSize(minx, miny);
64 setMaximumSize(maxx, maxy);
66 else {
67 minx= c0->minimumSize().width() + c1->minimumSize().width()+4;
68 maxx= c0->maximumSize().width() + c1->maximumSize().width()+4;
69 miny= (c0->minimumSize().height() > c1->minimumSize().height())
70 ? c0->minimumSize().height() : c1->minimumSize().height();
71 maxy= (c0->maximumSize().height() > c1->maximumSize().height())
72 ? c0->maximumSize().height() : c1->maximumSize().height();
74 minx= (minx > 4) ? minx : 4;
75 maxx= (maxx < 2000) ? maxx : 2000;
76 miny= (miny > 2) ? miny : 2;
77 maxy= (maxy < 2000) ? maxy : 2000;
79 setMinimumSize(minx, miny);
80 setMaximumSize(maxx, maxy);
83 divider= new QFrame(this, "pannerdivider");
84 divider->setFrameStyle(QFrame::Panel | QFrame::Raised);
85 divider->setLineWidth(1);
86 divider->raise();
88 if (orientation == Horizontal)
89 divider->setCursor(QCursor(sizeVerCursor));
90 else
91 divider->setCursor(QCursor(sizeHorCursor));
93 divider->installEventFilter(this);
95 initialised= true;
97 pos= position;
98 position=0;
100 setSeparatorPos(pos);
101 divider->show();
104 void KNewPanner::deactivate()
106 if (divider != 0L) delete divider;
107 divider = 0L;
108 initialised= false;
111 int KNewPanner::separatorPos()
113 return position;
116 void KNewPanner::setSeparatorPos(int pos)
118 position = pos;
121 void KNewPanner::setAbsSeparatorPos(int pos, bool do_resize)
123 pos= checkValue(pos);
125 if (pos != absSeparatorPos()) {
126 if (currentunits == Percent)
127 position= pos * 100 / (orientation == Vertical?width():height());
128 else
129 position= pos;
130 if (do_resize)
131 resizeEvent(0);
135 int KNewPanner::absSeparatorPos()
137 int value;
139 if (currentunits == Percent)
140 value= (orientation == Vertical?width():height())*position/100;
141 else
142 value= position;
144 return value;
147 KNewPanner::Units KNewPanner::units()
149 return currentunits;
152 void KNewPanner::setUnits(Units u)
154 currentunits= u;
157 void KNewPanner::resizeEvent(QResizeEvent*)
159 if (initialised) {
160 if (orientation == Horizontal) {
161 child0->setGeometry(0, 0, width(), absSeparatorPos());
162 child1->setGeometry(0, absSeparatorPos()+4, width(),
163 height()-absSeparatorPos()-4);
164 divider->setGeometry(0, absSeparatorPos(), width(), 4);
166 else {
167 startHeight = 0;
168 child0->setGeometry(0, startHeight, absSeparatorPos(),
169 (height())-startHeight);
170 child1->setGeometry(absSeparatorPos()+4, startHeight,
171 (width())-(absSeparatorPos()+4),
172 (height())-startHeight);
173 divider->setGeometry(absSeparatorPos(), startHeight, 4,
174 (height())-startHeight);
179 int KNewPanner::checkValue(int pos)
181 if (initialised) {
182 if (orientation == Vertical) {
183 if (pos < (child0->minimumSize().width()))
184 pos= child0->minimumSize().width();
185 if ((width()-4-pos) < (child1->minimumSize().width()))
186 pos= width() - (child1->minimumSize().width()) -4;
188 else {
189 if (pos < (child0->minimumSize().height()))
190 pos= (child0->minimumSize().height());
191 if ((height()-4-pos) < (child1->minimumSize().height()))
192 pos= height() - (child1->minimumSize().height()) -4;
196 if (pos < 0) pos= 0;
198 if ((orientation == Vertical) && (pos > width()))
199 pos= width();
200 if ((orientation == Horizontal) && (pos > height()))
201 pos= height();
203 return pos;
206 bool KNewPanner::eventFilter(QObject *, QEvent *e)
208 QMouseEvent *mev;
209 bool handled= false;
211 switch (e->type()) {
212 case QEvent::MouseMove:
213 mev= (QMouseEvent *)e;
214 child0->setUpdatesEnabled(false);
215 child1->setUpdatesEnabled(false);
216 if (orientation == Horizontal) {
217 setAbsSeparatorPos(divider->mapToParent(mev->pos()).y(), false);
218 divider->setGeometry(0, absSeparatorPos(), width(), 4);
219 divider->repaint(0);
221 else {
222 setAbsSeparatorPos(divider->mapToParent(mev->pos()).x(), false);
223 divider->setGeometry(absSeparatorPos(), 0, 4, height());
224 divider->repaint(0);
226 handled= true;
227 break;
228 case QEvent::MouseButtonRelease:
229 mev= (QMouseEvent *)e;
231 child0->setUpdatesEnabled(true);
232 child1->setUpdatesEnabled(true);
234 if (orientation == Horizontal) {
235 resizeEvent(0);
236 divider->repaint(true);
238 else {
239 resizeEvent(0);
240 divider->repaint(true);
242 handled= true;
243 break;
244 default:
245 break;
248 return handled;