20 #include "kdockwidget.h"
21 #include "kdockwidget_p.h"
22 #include "kdockwidget_private.h"
24 #include <tqpainter.h>
28 #include <tqapplication.h>
33 : TQWidget(parent, name)
44 m_orientation = orient;
45 mOpaqueResize =
false;
53 if ( c0 ) child0 = c0;
54 if ( c1 ) child1 = c1;
58 if (divider)
delete divider;
59 divider =
new TQFrame(
this,
"pannerdivider");
60 divider->setFrameStyle(TQFrame::Panel | TQFrame::Raised);
61 divider->setLineWidth(1);
64 if (m_orientation == TQt::Horizontal)
65 divider->setCursor(TQCursor(TQt::sizeVerCursor));
67 divider->setCursor(TQCursor(TQt::sizeHorCursor));
68 divider->installEventFilter(
this);
83 if( fixedWidth0 != -1 || fixedHeight0 != -1 ) restoreFromForcedFixedSize( dw0 );
84 if( fixedWidth1 != -1 || fixedHeight1 != -1 ) restoreFromForcedFixedSize( dw1 );
110 void KDockSplitter::setForcedFixedWidth(
KDockWidget *dw,
int w)
114 if (fixedWidth0==-1) savedXPos=xpos;
115 if (w==fixedWidth0)
return;
122 if (fixedWidth1==-1) savedXPos=xpos;
123 if (w==fixedWidth1)
return;
129 if (divider) divider->hide();
132 void KDockSplitter::setForcedFixedHeight(
KDockWidget *dw,
int h)
136 if (fixedHeight0==-1) savedXPos=xpos;
137 if (h==fixedHeight0)
return;
144 if (fixedHeight1==-1) savedXPos=xpos;
145 if (h==fixedHeight1)
return;
151 if (divider) divider->hide();
154 void KDockSplitter::restoreFromForcedFixedSize(
KDockWidget *dw)
156 if (divider) divider->show();
172 void KDockSplitter::setupMinMaxSize()
175 int minx, maxx, miny, maxy;
176 if (m_orientation == TQt::Horizontal) {
177 miny = child0->minimumHeight() + child1->minimumHeight() + 4;
178 maxy = child0->maximumHeight() + child1->maximumHeight() + 4;
179 minx = (child0->minimumWidth() > child1->minimumWidth()) ? child0->minimumWidth() : child1->minimumWidth();
180 maxx = (child0->maximumWidth() > child1->maximumWidth()) ? child0->maximumWidth() : child1->maximumWidth();
182 if (miny < 4) miny = 4;
183 if (maxy > 32000) maxy = 32000;
184 if (minx < 2) minx = 2;
185 if (maxx > 32000) maxx = 32000;
189 minx = child0->minimumWidth() + child1->minimumWidth() + 4;
190 maxx = child0->maximumWidth() + child1->maximumWidth() + 4;
191 miny = (child0->minimumHeight() > child1->minimumHeight()) ? child0->minimumHeight() : child1->minimumHeight();
192 maxy = (child0->maximumHeight() > child1->maximumHeight()) ? child0->maximumHeight() : child1->maximumHeight();
194 if (miny < 2) miny = 2;
195 if (maxy > 32000) maxy = 32000;
196 if (minx < 4) minx = 4;
197 if (maxx > 32000) maxx = 32000;
200 setMinimumSize(minx, miny);
201 setMaximumSize(maxx, maxy);
206 if (divider)
delete divider;
213 return xpos / (factor/100);
218 xpos = percent * (factor/100);
256 KDockContainer *dc = 0L;
259 bool stdHandling=
false;
267 if (ev && isVisible() && divider->isVisible()) {
275 if (m_orientation == TQt::Horizontal) {
276 if (ev->oldSize().height() != ev->size().height()) {
279 xpos = (int)ceil(((
double)factor) *
checkValue(height() - child1->height() - 4) / height());
284 xpos = tqRound(((
double)xpos) * ev->oldSize().height() / height());
288 if (ev->oldSize().width() != width()) {
290 xpos = (int)ceil(((
double)factor) *
checkValue(width() - child1->width() - 4) / width());
294 xpos = tqRound(((
double)xpos) * ev->oldSize().width() / width());
310 if (m_orientation == TQt::Horizontal) {
311 if (fixedHeight0!=-1)
312 xpos =
checkValue(fixedHeight0) * factor / height();
313 else if (fixedHeight1!=-1)
314 xpos =
checkValue(height()-fixedHeight1) * factor / height();
319 xpos =
checkValue(fixedWidth0) * factor / width();
320 else if (fixedWidth1!=-1)
321 xpos =
checkValue(width()-fixedWidth1) * factor / width();
349 if( ( (m_orientation==TQt::Vertical) &&((fixedWidth0==-1) && (fixedWidth1==-1)) ) ||
350 ( (m_orientation==TQt::Horizontal) &&((fixedHeight0==-1) && (fixedHeight1==-1)) ) ) {
352 && (dc->isOverlapMode())) {
358 if (m_orientation == TQt::Horizontal) {
360 child0->setGeometry(0, 0, width(), position);
361 child1->setGeometry(0, dc->m_nonOverlapSize, width(), height()-dc->m_nonOverlapSize);
362 divider->setGeometry(0, position, width(), 4);
365 child0->setGeometry(0, 0, position, height());
366 child1->setGeometry(dc->m_nonOverlapSize, 0, width()-dc->m_nonOverlapSize, height());
367 divider->setGeometry(position, 0, 4, height());
371 && (dc->isOverlapMode())) {
377 if (m_orientation == TQt::Horizontal) {
379 child0->setGeometry(0, 0, width(), height()-dc->m_nonOverlapSize);
380 child1->setGeometry(0, position+4, width(), height()-position-4);
381 divider->setGeometry(0, position, width(), 4);
384 child0->setGeometry(0, 0, width()-dc->m_nonOverlapSize, height());
385 child1->setGeometry(position+4, 0, width()-position-4, height());
386 divider->setGeometry(position, 0, 4, height());
402 int position =
checkValue( (m_orientation == TQt::Vertical ? width() : height()) * xpos / factor );
405 if (m_orientation == TQt::Horizontal) {
408 if( divider->isVisible() ) {
409 child0->setGeometry(0, 0, width(), position);
410 child1->setGeometry(0, position+4, width(), height()-position-4);
412 child0->setGeometry(0, 0, width(), height()-dc->m_nonOverlapSize);
413 child1->setGeometry(0, height()-dc->m_nonOverlapSize, width(), height());
416 if( divider->isVisible() ) diff = 4;
417 child0->setGeometry(0, 0, width(), position);
418 child1->setGeometry(0, position+diff, width(), height()-position-diff);
420 divider->setGeometry(0, position, width(), 4);
424 if( divider->isVisible() ) {
425 child0->setGeometry(0, 0, position, height());
426 child1->setGeometry(position+4, 0, width()-position-4, height());
428 child0->setGeometry(0, 0, width()-dc->m_nonOverlapSize, height());
429 child1->setGeometry(width()-dc->m_nonOverlapSize, 0, width(), height());
432 if( divider->isVisible() ) diff = 4;
433 child0->setGeometry(0, 0, position, height());
434 child1->setGeometry(position+diff, 0, width()-position-diff, height());
436 divider->setGeometry(position, 0, 4, height());
445 if (m_orientation == TQt::Vertical) {
446 if (child0==overlappingWidget) {
447 if (position < child0->minimumWidth() || position > width())
448 position = child0->minimumWidth();
450 if (position > (width()-child1->minimumWidth()-4) || position < 0)
451 position = width()-child1->minimumWidth()-4;
454 if (child0==overlappingWidget) {
455 if (position < (child0->minimumHeight()) || position > height())
456 position = child0->minimumHeight();
458 if (position>(height()-child1->minimumHeight()-4) || position < 0)
459 position = height()-child1->minimumHeight()-4;
469 if (m_orientation == TQt::Vertical) {
470 if (position < child0->minimumWidth())
471 position = child0->minimumWidth();
472 if ((width()-4-position) < (child1->minimumWidth()))
473 position = width() - (child1->minimumWidth()) - 4;
475 if (position < (child0->minimumHeight()))
476 position = child0->minimumHeight();
477 if ((height()-4-position) < child1->minimumHeight())
478 position = height() - (child1->minimumHeight()) - 4;
482 if (position < 0) position = 0;
484 if ((m_orientation == TQt::Vertical) && (position > width()))
486 if ((m_orientation == TQt::Horizontal) && (position > height()))
495 bool handled =
false;
498 case TQEvent::MouseMove:
499 mev= (TQMouseEvent*)e;
500 child0->setUpdatesEnabled(mOpaqueResize);
501 child1->setUpdatesEnabled(mOpaqueResize);
502 if (m_orientation == TQt::Horizontal) {
503 if ((fixedHeight0!=-1) || (fixedHeight1!=-1))
508 if (!mOpaqueResize) {
509 int position =
checkValue( mapFromGlobal(mev->globalPos()).y() );
510 divider->move( 0, position );
512 int tmp_xpos = factor *
checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
513 if (tmp_xpos != xpos) {
516 divider->repaint(
true);
520 if ((fixedWidth0!=-1) || (fixedWidth1!=-1))
524 if (!mOpaqueResize) {
525 int position =
checkValue( mapFromGlobal(TQCursor::pos()).x() );
526 divider->move( position, 0 );
528 int tmp_xpos = factor *
checkValue( mapFromGlobal( mev->globalPos()).x() ) / width();
529 if (tmp_xpos != xpos) {
532 divider->repaint(
true);
538 case TQEvent::MouseButtonRelease:
539 child0->setUpdatesEnabled(
true);
540 child1->setUpdatesEnabled(
true);
541 mev= (TQMouseEvent*)e;
542 if (m_orientation == TQt::Horizontal){
543 if ((fixedHeight0!=-1) || (fixedHeight1!=-1))
547 xpos = factor*
checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
549 divider->repaint(
true);
551 if ((fixedWidth0!=-1) || (fixedWidth1!=-1))
555 xpos = factor*
checkValue( mapFromGlobal(mev->globalPos()).x() ) / width();
557 divider->repaint(
true);
564 return (handled) ? true : TQWidget::eventFilter( o, e );
567 bool KDockSplitter::event( TQEvent* e )
569 if ( e->type() == TQEvent::LayoutHint ){
575 return TQWidget::event(e);
580 return ( w == child0 ) ? child1 : child0;
583 void KDockSplitter::updateName()
585 if ( !initialised )
return;
587 TQString new_name = TQString( child0->name() ) +
"," + child1->name();
588 parentWidget()->setName( new_name.latin1() );
589 parentWidget()->setCaption( child0->caption() +
"," + child1->caption() );
590 parentWidget()->repaint(
false );
592 ((
KDockWidget*)parentWidget())->firstName = child0->name();
593 ((
KDockWidget*)parentWidget())->lastName = child1->name();
594 ((
KDockWidget*)parentWidget())->splitterOrientation = m_orientation;
596 TQWidget* p = parentWidget()->parentWidget();
597 if ( p && p->inherits(
"KDockSplitter" ) )
606 bool KDockSplitter::opaqueResize()
const
608 return mOpaqueResize;
616 bool KDockSplitter::keepSize()
const
624 KDockButton_Private::KDockButton_Private( TQWidget *parent,
const char * name )
625 :TQPushButton( parent,
name )
628 setFocusPolicy( TQWidget::NoFocus );
631 KDockButton_Private::~KDockButton_Private()
635 void KDockButton_Private::drawButton( TQPainter* p )
637 p->fillRect( 0,0, width(), height(), TQBrush(colorGroup().brush(TQColorGroup::Background)) );
638 p->drawPixmap( (width() - pixmap()->width()) / 2, (height() - pixmap()->height()) / 2, *pixmap() );
639 if ( moveMouse && !isDown() ){
641 p->moveTo( 0, height() - 1 );
643 p->lineTo( width() - 1, 0 );
645 p->setPen( colorGroup().dark() );
646 p->lineTo( width() - 1, height() - 1 );
647 p->lineTo( 0, height() - 1 );
649 if ( isOn() || isDown() ){
650 p->setPen( colorGroup().dark() );
651 p->moveTo( 0, height() - 1 );
653 p->lineTo( width() - 1, 0 );
656 p->lineTo( width() - 1, height() - 1 );
657 p->lineTo( 0, height() - 1 );
661 void KDockButton_Private::enterEvent( TQEvent * )
667 void KDockButton_Private::leaveEvent( TQEvent * )
674 KDockWidgetPrivate::KDockWidgetPrivate()
677 ,splitPosInPercent(50)
678 ,pendingFocusInEvent(false)
679 ,blockHasUndockedSignal(false)
689 windowType = NET::Normal;
696 KDockWidgetPrivate::~KDockWidgetPrivate()
703 TQWidget* embeddedWdg = ((
KDockWidget*)w)->getWidget();
704 if (embeddedWdg && ((embeddedWdg->focusPolicy() == TQWidget::ClickFocus) || (embeddedWdg->focusPolicy() == TQWidget::StrongFocus))) {
705 embeddedWdg->setFocus();
710 #ifndef NO_INCLUDE_MOCFILES
711 #include "kdockwidget_private.moc"
Like TQSplitter but specially designed for dockwidgets stuff.
void deactivate()
Disables the splitter.
TQWidget * getAnother(TQWidget *w) const
If w is child0, return child1, otherwise child0.
KDockSplitter(TQWidget *parent=0, const char *name=0, Orientation orient=TQt::Vertical, int pos=50)
Constructor.
void setSeparatorPos(int pos, bool do_resize=true)
set separator position.
int separatorPos() const
Return the separator position in the range [0..100000] To get the separator position in procent (%),...
void setOpaqueResize(bool b=true)
Set opaque flag.
int checkValueOverlapped(int position, TQWidget *child) const
Make sure the splitter position is not out of bounds.
void setSeparatorPosInPercent(int percent)
Set the separator position in percent (%), so the range must be [0..100].
void activate(TQWidget *c0, TQWidget *c1=0L)
Initialize the splitter.
int checkValue(int position) const
Make sure the splitter position is not out of bounds.
int separatorPosInPercent()
Return the separator position in percent (%), so the range is [0..100].
void setKeepSize(bool b=true)
If b is true, the splitter will keep its size on resize events.
virtual void resizeEvent(TQResizeEvent *ev)
The resize event resizes child0, child1 and the divider.
virtual bool eventFilter(TQObject *, TQEvent *)
The eventfilter installed on the divider processes all splitter resizing events.
void setSeparatorPosX(int pos, bool do_resize=false)
For usage from outside.
TQString name(StdAccel id)