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"
26 KNewPanner::KNewPanner(QWidget
*parent
, const char *name
, Orientation orient
, Units units
, int pos
)
27 : QWidget(parent
, name
)
37 KNewPanner::~KNewPanner()
41 void KNewPanner::activate(QWidget
*c0
, QWidget
*c1
)
43 int minx
, maxx
, miny
, maxy
, pos
;
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
);
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);
87 if (orientation
== Horizontal
)
88 divider
->setCursor(QCursor(sizeVerCursor
));
90 divider
->setCursor(QCursor(sizeHorCursor
));
92 divider
->installEventFilter(this);
103 void KNewPanner::deactivate()
105 if (divider
!= 0L) delete divider
;
110 int KNewPanner::separatorPos()
115 void KNewPanner::setSeparatorPos(int 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());
134 int KNewPanner::absSeparatorPos()
138 if (currentunits
== Percent
)
139 value
= (orientation
== Vertical
?width():height())*position
/100;
146 KNewPanner::Units
KNewPanner::units()
151 void KNewPanner::setUnits(Units u
)
156 void KNewPanner::resizeEvent(QResizeEvent
*)
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);
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
)
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;
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;
197 if ((orientation
== Vertical
) && (pos
> width()))
199 if ((orientation
== Horizontal
) && (pos
> height()))
205 #if QT_VERSION >= 200
211 bool KNewPanner::eventFilter(QObject
*, QEvent
*e
)
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);
227 setAbsSeparatorPos(divider
->mapToParent(mev
->pos()).x(), false);
228 divider
->setGeometry(absSeparatorPos(), 0, 4, height());
233 case EV(QEvent::MouseButtonRelease
,Event_MouseButtonRelease
):
234 mev
= (QMouseEvent
*)e
;
236 child0
->setUpdatesEnabled(true);
237 child1
->setUpdatesEnabled(true);
239 if (orientation
== Horizontal
) {
241 divider
->repaint(true);
245 divider
->repaint(true);