24 #include <QtGui/QPainter>
25 #include <QtGui/QCursor>
27 #include <QtCore/QTimer>
28 #include <QtGui/QApplication>
29 #include <QResizeEvent>
45 m_orientation = orient;
46 mOpaqueResize =
false;
54 if ( c0 ) child0 = c0;
55 if ( c1 ) child1 = c1;
60 divider =
new QFrame(
this,
"pannerdivider");
61 divider->setFrameStyle(QFrame::Panel | QFrame::Raised);
62 divider->setLineWidth(1);
65 if (m_orientation == Qt::Horizontal)
66 divider->setCursor(
QCursor(Qt::SizeVerCursor));
68 divider->setCursor(
QCursor(Qt::SizeHorCursor));
69 divider->installEventFilter(
this);
115 if (fixedWidth0==-1) savedXPos=xpos;
116 if (w==fixedWidth0)
return;
123 if (fixedWidth1==-1) savedXPos=xpos;
124 if (w==fixedWidth1)
return;
130 if (divider) divider->hide();
137 if (fixedHeight0==-1) savedXPos=xpos;
138 if (h==fixedHeight0)
return;
145 if (fixedHeight1==-1) savedXPos=xpos;
146 if (h==fixedHeight1)
return;
152 if (divider) divider->hide();
157 if (divider) divider->show();
173 void K3DockSplitter::setupMinMaxSize()
176 int minx, maxx, miny, maxy;
177 if (m_orientation == Qt::Horizontal) {
178 miny = child0->minimumHeight() + child1->minimumHeight() + 4;
179 maxy = child0->maximumHeight() + child1->maximumHeight() + 4;
180 minx = (child0->minimumWidth() > child1->minimumWidth()) ? child0->minimumWidth() : child1->minimumWidth();
181 maxx = (child0->maximumWidth() > child1->maximumWidth()) ? child0->maximumWidth() : child1->maximumWidth();
183 if (miny < 4) miny = 4;
184 if (maxy > 32000) maxy = 32000;
185 if (minx < 2) minx = 2;
186 if (maxx > 32000) maxx = 32000;
190 minx = child0->minimumWidth() + child1->minimumWidth() + 4;
191 maxx = child0->maximumWidth() + child1->maximumWidth() + 4;
192 miny = (child0->minimumHeight() > child1->minimumHeight()) ? child0->minimumHeight() : child1->minimumHeight();
193 maxy = (child0->maximumHeight() > child1->maximumHeight()) ? child0->maximumHeight() : child1->maximumHeight();
195 if (miny < 2) miny = 2;
196 if (maxy > 32000) maxy = 32000;
197 if (minx < 4) minx = 4;
198 if (maxx > 32000) maxx = 32000;
201 setMinimumSize(minx, miny);
202 setMaximumSize(maxx, maxy);
214 return xpos / (factor/100);
219 xpos = percent * (factor/100);
260 bool stdHandling=
false;
268 if (ev && isVisible() && divider->isVisible()) {
276 if (m_orientation == Qt::Horizontal) {
277 if (ev->oldSize().height() != ev->size().height()) {
280 xpos = (int)ceil(((
double)factor) *
checkValue(height() - child1->height() - 4) / height());
285 xpos = qRound(((
double)xpos) * ev->oldSize().height() / height());
289 if (ev->oldSize().width() != width()) {
291 xpos = (int)ceil(((
double)factor) *
checkValue(width() - child1->width() - 4) / width());
295 xpos = qRound(((
double)xpos) * ev->oldSize().width() / width());
311 if (m_orientation == Qt::Horizontal) {
312 if (fixedHeight0!=-1)
313 xpos =
checkValue(fixedHeight0) * factor / height();
314 else if (fixedHeight1!=-1)
315 xpos =
checkValue(height()-fixedHeight1) * factor / height();
320 xpos =
checkValue(fixedWidth0) * factor / width();
321 else if (fixedWidth1!=-1)
322 xpos =
checkValue(width()-fixedWidth1) * factor / width();
350 if( ( (m_orientation==Qt::Vertical) &&((fixedWidth0==-1) && (fixedWidth1==-1)) ) ||
351 ( (m_orientation==Qt::Horizontal) &&((fixedHeight0==-1) && (fixedHeight1==-1)) ) ) {
359 if (m_orientation == Qt::Horizontal) {
361 child0->setGeometry(0, 0, width(), position);
362 child1->setGeometry(0, dc->m_nonOverlapSize, width(), height()-dc->m_nonOverlapSize);
363 divider->setGeometry(0, position, width(), 4);
366 child0->setGeometry(0, 0, position, height());
367 child1->setGeometry(dc->m_nonOverlapSize, 0, width()-dc->m_nonOverlapSize, height());
368 divider->setGeometry(position, 0, 4, height());
378 if (m_orientation == Qt::Horizontal) {
380 child0->setGeometry(0, 0, width(), height()-dc->m_nonOverlapSize);
381 child1->setGeometry(0, position+4, width(), height()-position-4);
382 divider->setGeometry(0, position, width(), 4);
385 child0->setGeometry(0, 0, width()-dc->m_nonOverlapSize, height());
386 child1->setGeometry(position+4, 0, width()-position-4, height());
387 divider->setGeometry(position, 0, 4, height());
403 int position =
checkValue( (m_orientation == Qt::Vertical ? width() : height()) * xpos / factor );
406 if (m_orientation == Qt::Horizontal) {
409 if( divider->isVisible() ) {
410 child0->setGeometry(0, 0, width(), position);
411 child1->setGeometry(0, position+4, width(), height()-position-4);
413 child0->setGeometry(0, 0, width(), height()-dc->m_nonOverlapSize);
414 child1->setGeometry(0, height()-dc->m_nonOverlapSize, width(), height());
417 if( divider->isVisible() ) diff = 4;
418 child0->setGeometry(0, 0, width(), position);
419 child1->setGeometry(0, position+diff, width(), height()-position-diff);
421 divider->setGeometry(0, position, width(), 4);
425 if( divider->isVisible() ) {
426 child0->setGeometry(0, 0, position, height());
427 child1->setGeometry(position+4, 0, width()-position-4, height());
429 child0->setGeometry(0, 0, width()-dc->m_nonOverlapSize, height());
430 child1->setGeometry(width()-dc->m_nonOverlapSize, 0, width(), height());
433 if( divider->isVisible() ) diff = 4;
434 child0->setGeometry(0, 0, position, height());
435 child1->setGeometry(position+diff, 0, width()-position-diff, height());
437 divider->setGeometry(position, 0, 4, height());
446 if (m_orientation == Qt::Vertical) {
447 if (child0==overlappingWidget) {
448 if (position < child0->minimumWidth() || position > width())
449 position = child0->minimumWidth();
451 if (position > (width()-child1->minimumWidth()-4) || position < 0)
452 position = width()-child1->minimumWidth()-4;
455 if (child0==overlappingWidget) {
456 if (position < (child0->minimumHeight()) || position > height())
457 position = child0->minimumHeight();
459 if (position>(height()-child1->minimumHeight()-4) || position < 0)
460 position = height()-child1->minimumHeight()-4;
470 if (m_orientation == Qt::Vertical) {
471 if (position < child0->minimumWidth())
472 position = child0->minimumWidth();
473 if ((width()-4-position) < (child1->minimumWidth()))
474 position = width() - (child1->minimumWidth()) - 4;
476 if (position < (child0->minimumHeight()))
477 position = child0->minimumHeight();
478 if ((height()-4-position) < child1->minimumHeight())
479 position = height() - (child1->minimumHeight()) - 4;
483 if (position < 0) position = 0;
485 if ((m_orientation == Qt::Vertical) && (position > width()))
487 if ((m_orientation == Qt::Horizontal) && (position > height()))
496 bool handled =
false;
499 case QEvent::MouseMove:
500 mev= (QMouseEvent*)e;
501 child0->setUpdatesEnabled(mOpaqueResize);
502 child1->setUpdatesEnabled(mOpaqueResize);
503 if (m_orientation == Qt::Horizontal) {
504 if ((fixedHeight0!=-1) || (fixedHeight1!=-1))
509 if (!mOpaqueResize) {
510 int position =
checkValue( mapFromGlobal(mev->globalPos()).y() );
511 divider->move( 0, position );
513 int tmp_xpos = factor *
checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
514 if (tmp_xpos != xpos) {
521 if ((fixedWidth0!=-1) || (fixedWidth1!=-1))
525 if (!mOpaqueResize) {
526 int position =
checkValue( mapFromGlobal(QCursor::pos()).x() );
527 divider->move( position, 0 );
529 int tmp_xpos = factor *
checkValue( mapFromGlobal( mev->globalPos()).x() ) / width();
530 if (tmp_xpos != xpos) {
539 case QEvent::MouseButtonRelease:
540 child0->setUpdatesEnabled(
true);
541 child1->setUpdatesEnabled(
true);
542 mev= (QMouseEvent*)e;
543 if (m_orientation == Qt::Horizontal){
544 if ((fixedHeight0!=-1) || (fixedHeight1!=-1))
548 xpos = factor*
checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
552 if ((fixedWidth0!=-1) || (fixedWidth1!=-1))
556 xpos = factor*
checkValue( mapFromGlobal(mev->globalPos()).x() ) / width();
570 if ( e->type() == QEvent::LayoutHint ){
581 return ( w == child0 ) ? child1 : child0;
586 if ( !initialised )
return;
588 QString new_name =
QString( child0->name() ) +
',' + child1->name();
589 parentWidget()->setName( new_name.toLatin1().constData() );
590 parentWidget()->setWindowTitle( child0->windowTitle() +
',' + child1->windowTitle() );
591 parentWidget()->repaint( );
593 ((
K3DockWidget*)parentWidget())->firstName = child0->name();
594 ((
K3DockWidget*)parentWidget())->lastName = child1->name();
595 ((
K3DockWidget*)parentWidget())->splitterOrientation = m_orientation;
597 QWidget* p = parentWidget()->parentWidget();
598 if ( p && p->inherits(
"K3DockSplitter" ) )
609 return mOpaqueResize;
629 setFocusPolicy( Qt::NoFocus );
638 p->fillRect( 0,0, width(), height(), QBrush(QColorGroup(palette()).brush(QPalette::Background)) );
641 icon().paint( p, rect() );
643 p->drawPixmap( (width() - pixmap()->width()) / 2, (height() - pixmap()->height()) / 2, *pixmap() );
645 if ( moveMouse && !isDown() ){
646 p->setPen( Qt::white );
647 p->drawLine( 0, height() - 1, 0, 0 );
648 p->drawLine( 0, 0, width() -1 , 0 );
650 p->setPen( QColorGroup(palette()).dark() );
651 p->drawLine( width() -1, 0, width() - 1, height() - 1 );
652 p->drawLine( width() - 1, height() - 1, 0, height() - 1 );
654 if ( isChecked() || isDown() ){
655 p->setPen( QColorGroup(palette()).dark() );
656 p->drawLine(0 , height() - 1, 0, 0);
657 p->drawLine(0, 0, width() -1 , 0);
659 p->setPen( Qt::white );
660 p->drawLine(width() - 1, height() - 1, 0, height() - 1);
678 QPainter painter(
this );
686 ,splitPosInPercent(50)
687 ,pendingFocusInEvent(false)
688 ,blockHasUndockedSignal(false)
713 if (embeddedWdg && ((embeddedWdg->focusPolicy() == Qt::ClickFocus) || (embeddedWdg->focusPolicy() == Qt::StrongFocus))) {
714 embeddedWdg->setFocus();
719 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
720 #include "k3dockwidget_private.moc"