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"
27 KNewPanner::KNewPanner(QWidget
*parent
, const char *name
, Orientation orient
, Units units
, int pos
)
28 : QWidget(parent
, name
)
38 KNewPanner::~KNewPanner()
42 void KNewPanner::activate(QWidget
*c0
, QWidget
*c1
)
44 int minx
, maxx
, miny
, maxy
, pos
;
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
);
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);
88 if (orientation
== Horizontal
)
89 divider
->setCursor(QCursor(sizeVerCursor
));
91 divider
->setCursor(QCursor(sizeHorCursor
));
93 divider
->installEventFilter(this);
100 setSeparatorPos(pos
);
104 void KNewPanner::deactivate()
106 if (divider
!= 0L) delete divider
;
111 int KNewPanner::separatorPos()
116 void KNewPanner::setSeparatorPos(int 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());
135 int KNewPanner::absSeparatorPos()
139 if (currentunits
== Percent
)
140 value
= (orientation
== Vertical
?width():height())*position
/100;
147 KNewPanner::Units
KNewPanner::units()
152 void KNewPanner::setUnits(Units u
)
157 void KNewPanner::resizeEvent(QResizeEvent
*)
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);
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
)
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;
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;
198 if ((orientation
== Vertical
) && (pos
> width()))
200 if ((orientation
== Horizontal
) && (pos
> height()))
206 bool KNewPanner::eventFilter(QObject
*, QEvent
*e
)
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);
222 setAbsSeparatorPos(divider
->mapToParent(mev
->pos()).x(), false);
223 divider
->setGeometry(absSeparatorPos(), 0, 4, height());
228 case QEvent::MouseButtonRelease
:
229 mev
= (QMouseEvent
*)e
;
231 child0
->setUpdatesEnabled(true);
232 child1
->setUpdatesEnabled(true);
234 if (orientation
== Horizontal
) {
236 divider
->repaint(true);
240 divider
->repaint(true);