00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 #include "kmdichildview.h"
00033 #include "kmdichildview.moc"
00034 
00035 #include <qdatetime.h>
00036 #include <qobjectlist.h>
00037 
00038 #include "kmdimainfrm.h"
00039 #include "kmdichildfrm.h"
00040 #include "kmdidefines.h"
00041 #include <kdebug.h>
00042 #include <klocale.h>
00043 #include <qiconset.h>
00044 
00045 
00046 
00047 KMdiChildView::KMdiChildView( const QString& caption, QWidget* parentWidget, const char* name, WFlags f)
00048 : QWidget(parentWidget, name, f)
00049   ,m_focusedChildWidget(0L)
00050   ,m_firstFocusableChildWidget(0L)
00051   ,m_lastFocusableChildWidget(0L)
00052   ,m_stateChanged(true)
00053   ,m_bToolView(false)
00054   ,m_bInterruptActivation(false)
00055   ,m_bMainframesActivateViewIsPending(false)
00056   ,m_bFocusInEventIsPending(false)
00057   ,m_trackChanges(0)
00058 {
00059    setGeometry( 0, 0, 0, 0);  
00060    if(caption != 0L) {
00061       m_szCaption = caption;
00062    }
00063    else {
00064       m_szCaption = QString(i18n("Unnamed"));
00065    }
00066    m_sTabCaption = m_szCaption;
00067 
00068    setFocusPolicy(ClickFocus);
00069 
00070    installEventFilter(this);
00071 
00072    
00073    updateTimeStamp();
00074 }
00075 
00076 
00077 
00078 
00079 KMdiChildView::KMdiChildView( QWidget* parentWidget, const char* name, WFlags f)
00080 : QWidget(parentWidget, name, f)
00081   ,m_focusedChildWidget(0L)
00082   ,m_firstFocusableChildWidget(0L)
00083   ,m_lastFocusableChildWidget(0L)
00084   ,m_stateChanged(true)
00085   ,m_bToolView(false)
00086   ,m_bInterruptActivation(false)
00087   ,m_bMainframesActivateViewIsPending(false)
00088   ,m_bFocusInEventIsPending(false)
00089 {
00090    setGeometry( 0, 0, 0, 0);  
00091    m_szCaption = QString(i18n("Unnamed"));
00092    m_sTabCaption = m_szCaption;
00093 
00094    setFocusPolicy(ClickFocus);
00095 
00096    installEventFilter(this);
00097 
00098    
00099    updateTimeStamp();
00100 }
00101 
00102 
00103 
00104 KMdiChildView::~KMdiChildView()
00105 {
00106   kdDebug(760)<<"~KMdiChildView()"<<endl;
00107 }
00108 
00109 void KMdiChildView::trackIconAndCaptionChanges(QWidget *view) {
00110     m_trackChanges=view;
00111 }
00112 
00113 
00114 
00115 
00116 QRect KMdiChildView::internalGeometry() const
00117 {
00118    if(mdiParent()) { 
00119       
00120       QRect    posInFrame = geometry();
00121       
00122       
00123       QPoint ptTopLeft = mdiParent()->mapToParent(posInFrame.topLeft());
00124       QSize sz = size();
00125       return QRect(ptTopLeft, sz);
00126    }
00127    else {
00128       QRect    geo = geometry();
00129       QRect    frameGeo = externalGeometry();
00130       return QRect(frameGeo.x(), frameGeo.y(), geo.width(), geo.height());
00131 
00132    }
00133 }
00134 
00135 
00136 
00137 void KMdiChildView::setInternalGeometry(const QRect& newGeometry)
00138 {
00139    if(mdiParent()) { 
00140       
00141       QRect    geo      = internalGeometry();
00142       QRect    frameGeo = externalGeometry();
00143       int      nFrameSizeTop  = geo.y() - frameGeo.y();
00144       int      nFrameSizeLeft = geo.x() - frameGeo.x();
00145 
00146       
00147       QRect    newGeoQt;
00148       newGeoQt.setX(newGeometry.x()-nFrameSizeLeft);
00149       newGeoQt.setY(newGeometry.y()-nFrameSizeTop);
00150 
00151       newGeoQt.setWidth(newGeometry.width()+nFrameSizeLeft+KMDI_CHILDFRM_DOUBLE_BORDER/2);
00152       newGeoQt.setHeight(newGeometry.height()+nFrameSizeTop+KMDI_CHILDFRM_DOUBLE_BORDER/2);
00153 
00154 
00155 
00156       
00157       mdiParent()->setGeometry(newGeoQt);
00158    }
00159    else {
00160       
00161       QRect    geo      = internalGeometry();
00162       QRect    frameGeo = externalGeometry();
00163       int      nFrameSizeTop  = geo.y() - frameGeo.y();
00164       int      nFrameSizeLeft = geo.x() - frameGeo.x();
00165 
00166       
00167       QRect    newGeoQt;
00168 
00169       newGeoQt.setX(newGeometry.x()-nFrameSizeLeft);
00170       newGeoQt.setY(newGeometry.y()-nFrameSizeTop);
00171 
00172       newGeoQt.setWidth(newGeometry.width());
00173       newGeoQt.setHeight(newGeometry.height());
00174 
00175       
00176       setGeometry(newGeoQt);
00177    }
00178 }
00179 
00180 
00181 
00182 QRect KMdiChildView::externalGeometry() const
00183 {
00184    return mdiParent() ? mdiParent()->frameGeometry() : frameGeometry();
00185 }
00186 
00187 
00188 
00189 void KMdiChildView::setExternalGeometry(const QRect& newGeometry)
00190 {
00191    if(mdiParent()) { 
00192        mdiParent()->setGeometry(newGeometry);
00193    }
00194    else {
00195       
00196       QRect    geo      = internalGeometry();
00197       QRect    frameGeo = externalGeometry();
00198       int      nTotalFrameWidth = frameGeo.width() - geo.width();
00199       int      nTotalFrameHeight = frameGeo.height() - geo.height();
00200       int      nFrameSizeTop  = geo.y() - frameGeo.y();
00201       int      nFrameSizeLeft = geo.x() - frameGeo.x();
00202 
00203       
00204       
00205       QRect    newGeoQt;
00206       newGeoQt.setX(newGeometry.x()+nFrameSizeLeft);
00207       newGeoQt.setY(newGeometry.y()+nFrameSizeTop);
00208       newGeoQt.setWidth(newGeometry.width()-nTotalFrameWidth);
00209       newGeoQt.setHeight(newGeometry.height()-nTotalFrameHeight);
00210 
00211       
00212       setGeometry(newGeoQt);
00213    }
00214 }
00215 
00216 
00217 
00218 void KMdiChildView::minimize(bool bAnimate)
00219 {
00220    if(mdiParent()) {
00221       if(!isMinimized()) {
00222          mdiParent()->setState(KMdiChildFrm::Minimized,bAnimate);
00223       }
00224    }
00225    else {
00226       showMinimized();
00227    }
00228 }
00229 
00230 void KMdiChildView::showMinimized()
00231 {
00232    
00233    emit isMinimizedNow();
00234    QWidget::showMinimized();
00235 }
00236 
00237 
00238 void KMdiChildView::minimize() { minimize(true); }
00239 
00240 
00241 
00242 void KMdiChildView::maximize(bool bAnimate)
00243 {
00244    if(mdiParent()) {
00245       if(!isMaximized()) {
00246          mdiParent()->setState(KMdiChildFrm::Maximized,bAnimate);
00247          emit mdiParentNowMaximized(true);
00248       }
00249    }
00250    else {
00251       showMaximized();
00252    }
00253 }
00254 
00255 void KMdiChildView::showMaximized()
00256 {
00257    
00258    emit isMaximizedNow();
00259    QWidget::showMaximized();
00260 }
00261 
00262 
00263 void KMdiChildView::maximize() { maximize(true); }
00264 
00265 
00266 
00267 QRect KMdiChildView::restoreGeometry()
00268 {
00269    if(mdiParent()) {
00270       return mdiParent()->restoreGeometry();
00271    }
00272    else {
00273       
00274       return geometry();
00275    }
00276 }
00277 
00278 
00279 
00280 void  KMdiChildView::setRestoreGeometry(const QRect& newRestGeo)
00281 {
00282    if(mdiParent()) {
00283       mdiParent()->setRestoreGeometry(newRestGeo);
00284    }
00285    else {
00286       
00287    }
00288 }
00289 
00290 
00291 
00292 void KMdiChildView::attach()
00293 {
00294    emit attachWindow(this,true);
00295 }
00296 
00297 
00298 
00299 void KMdiChildView::detach()
00300 {
00301    emit detachWindow(this, true);
00302 }
00303 
00304 
00305 
00306 bool KMdiChildView::isMinimized() const
00307 {
00308    if(mdiParent()) {
00309       return (mdiParent()->state() == KMdiChildFrm::Minimized);
00310    }
00311    else {
00312       return QWidget::isMinimized();
00313    }
00314 }
00315 
00316 
00317 
00318 bool KMdiChildView::isMaximized() const
00319 {
00320    if(mdiParent()) {
00321       return (mdiParent()->state() == KMdiChildFrm::Maximized);
00322    }
00323    else {
00324       return QWidget::isMaximized();
00325    }
00326 }
00327 
00328 
00329 
00330 void KMdiChildView::restore()
00331 {
00332    if(mdiParent()) {
00333       if(isMaximized()) {
00334          emit mdiParentNowMaximized(false);
00335       }
00336       if(isMinimized()||isMaximized()) {
00337          mdiParent()->setState(KMdiChildFrm::Normal);
00338       }
00339    }
00340    else {
00341       showNormal();
00342    }
00343 }
00344 
00345 void KMdiChildView::showNormal()
00346 {
00347    
00348    emit isRestoredNow();
00349    QWidget::showNormal();
00350 }
00351 
00352 
00353 
00354 void KMdiChildView::youAreAttached(KMdiChildFrm *lpC)
00355 {
00356    lpC->setCaption(m_szCaption);
00357 
00358    emit isAttachedNow();
00359 }
00360 
00361 
00362 
00363 void KMdiChildView::youAreDetached()
00364 {
00365    setCaption(m_szCaption);
00366 
00367    setTabCaption(m_sTabCaption);
00368    if(myIconPtr())setIcon(*(myIconPtr()));
00369    setFocusPolicy(QWidget::StrongFocus);
00370 
00371    emit isDetachedNow();
00372 }
00373 
00374 
00375 
00376 void KMdiChildView::setCaption(const QString& szCaption)
00377 {
00378   
00379    m_szCaption=szCaption;
00380    if(mdiParent()) {
00381      mdiParent()->setCaption(m_szCaption);
00382    }
00383    else {
00384      
00385      QWidget::setCaption(m_szCaption);
00386    }
00387    emit windowCaptionChanged(m_szCaption);
00388 }
00389 
00390 
00391 
00392 void KMdiChildView::closeEvent(QCloseEvent *e)
00393 {
00394    e->ignore(); 
00395    emit childWindowCloseRequest(this);
00396 }
00397 
00398 
00399 
00400 QPixmap* KMdiChildView::myIconPtr()
00401 {
00402    return 0;
00403 }
00404 
00405 
00406 
00407 void KMdiChildView::focusInEvent(QFocusEvent *e)
00408 {
00409    QWidget::focusInEvent(e);
00410 
00411    
00412    if(e && ((e->reason())==QFocusEvent::Popup)) {
00413       return;
00414    }
00415 
00416    m_bFocusInEventIsPending = true;
00417    activate();
00418    m_bFocusInEventIsPending = false;
00419 
00420    emit gotFocus(this);
00421 }
00422 
00423 
00424 
00425 void KMdiChildView::activate()
00426 {
00427    
00428    static bool s_bActivateIsPending = false;
00429    if(s_bActivateIsPending) {
00430       return;
00431    }
00432    s_bActivateIsPending = true;
00433 
00434    
00435    if(!m_bMainframesActivateViewIsPending) {
00436      emit focusInEventOccurs( this);
00437    }
00438 
00439    
00440    if(m_bInterruptActivation) {
00441       m_bInterruptActivation = false;
00442    }
00443    else {
00444       if(!m_bFocusInEventIsPending) {
00445          setFocus();
00446       }
00447       
00448       emit activated(this);
00449    }
00450 
00451    if(m_focusedChildWidget != 0L) {
00452       m_focusedChildWidget->setFocus();
00453    }
00454    else {
00455       if(m_firstFocusableChildWidget != 0L) {
00456          m_firstFocusableChildWidget->setFocus();
00457          m_focusedChildWidget = m_firstFocusableChildWidget;
00458       }
00459    }
00460    s_bActivateIsPending = false;
00461 }
00462 
00463 
00464 
00465 void KMdiChildView::focusOutEvent(QFocusEvent* e)
00466 {
00467    QWidget::focusOutEvent(e);
00468 
00469    emit lostFocus( this);
00470 }
00471 
00472 
00473 
00474 void KMdiChildView::resizeEvent(QResizeEvent* e)
00475 {
00476    QWidget::resizeEvent( e);
00477 
00478    if(m_stateChanged) {
00479       m_stateChanged = false;
00480       if(isMaximized()) {
00481          
00482          emit isMaximizedNow();
00483       }
00484       else if(isMinimized()) {
00485          
00486          emit isMinimizedNow();
00487       }
00488       else {   
00489          
00490          emit isRestoredNow();
00491       }
00492    }
00493 }
00494 
00495 void KMdiChildView::slot_childDestroyed()
00496 {
00497    
00498 
00499    
00500    
00501    const QObject* pLostChild = QObject::sender();
00502    if ((pLostChild != 0L) && (pLostChild->isWidgetType())) {
00503       QObjectList *list = ((QObject*)(pLostChild))->queryList( "QWidget" );
00504       list->insert(0, pLostChild);        
00505       QObjectListIt it( *list );          
00506       QObject * obj;
00507       while ( (obj=it.current()) != 0 ) { 
00508          QWidget* widg = (QWidget*)obj;
00509          ++it;
00510          widg->removeEventFilter(this);
00511          if(m_firstFocusableChildWidget == widg) {
00512             m_firstFocusableChildWidget = 0L;   
00513          }
00514          if(m_lastFocusableChildWidget == widg) {
00515             m_lastFocusableChildWidget = 0L;    
00516          }
00517          if(m_focusedChildWidget == widg) {
00518             m_focusedChildWidget = 0L;          
00519          }
00520       }
00521       delete list;                        
00522    }
00523 }
00524 
00525 
00526 bool KMdiChildView::eventFilter(QObject *obj, QEvent *e )
00527 {
00528    if(e->type() == QEvent::KeyPress && isAttached()) {
00529       QKeyEvent* ke = (QKeyEvent*) e;
00530       if(ke->key() == Qt::Key_Tab) {
00531          
00532          QWidget* w = (QWidget*) obj;
00533          if((w->focusPolicy() == QWidget::StrongFocus) ||
00534             (w->focusPolicy() == QWidget::TabFocus   ) ||
00535             (w->focusPolicy() == QWidget::WheelFocus ))
00536          {
00537             
00538             if(m_lastFocusableChildWidget != 0) {
00539                if(w == m_lastFocusableChildWidget) {
00540                   if(w != m_firstFocusableChildWidget) {
00541                      
00542                      m_firstFocusableChildWidget->setFocus();
00543                      
00544                   }
00545                }
00546             }
00547          }
00548       }
00549    }
00550    else if(e->type() == QEvent::FocusIn) {
00551       if(obj->isWidgetType()) {
00552          QObjectList *list = queryList( "QWidget" );
00553          if(list->find(obj) != -1) {
00554             m_focusedChildWidget = (QWidget*)obj;
00555          }
00556          delete list;   
00557       }
00558       if (!isAttached()) {   
00559          static bool m_bActivationIsPending = false;
00560          if(!m_bActivationIsPending) {
00561             m_bActivationIsPending = true;
00562             activate(); 
00563             m_bActivationIsPending = false;
00564          }
00565       }
00566    }
00567    else if (e->type() == QEvent::ChildRemoved) {
00568       
00569       
00570       QObject* pLostChild = ((QChildEvent*)e)->child();
00571       if ((pLostChild != 0L) && (pLostChild->isWidgetType())) {
00572          QObjectList *list = pLostChild->queryList( "QWidget" );
00573          list->insert(0, pLostChild);        
00574          QObjectListIt it( *list );          
00575          QObject * o;
00576          while ( (o=it.current()) != 0 ) { 
00577             QWidget* widg = (QWidget*)o;
00578             ++it;
00579             widg->removeEventFilter(this);
00580             if((widg->focusPolicy() == QWidget::StrongFocus) ||
00581                (widg->focusPolicy() == QWidget::TabFocus   ) ||
00582                (widg->focusPolicy() == QWidget::WheelFocus ))
00583             {
00584                if(m_firstFocusableChildWidget == widg) {
00585                   m_firstFocusableChildWidget = 0L;   
00586                }
00587                if(m_lastFocusableChildWidget == widg) {
00588                   m_lastFocusableChildWidget = 0L;    
00589                }
00590             }
00591          }
00592          delete list;                        
00593       }
00594    }
00595    else if (e->type() == QEvent::ChildInserted) {
00596       
00597       
00598       
00599       QObject* pNewChild = ((QChildEvent*)e)->child();
00600       if ((pNewChild != 0L) && (pNewChild->isWidgetType()))
00601       {
00602          QWidget* pNewWidget = (QWidget*)pNewChild;
00603          if (pNewWidget->testWFlags(Qt::WType_Dialog | Qt::WShowModal))
00604              return false;
00605          QObjectList *list = pNewWidget->queryList( "QWidget" );
00606          list->insert(0, pNewChild);         
00607          QObjectListIt it( *list );          
00608          QObject * o;
00609          while ( (o=it.current()) != 0 ) { 
00610             QWidget* widg = (QWidget*)o;
00611             ++it;
00612             widg->installEventFilter(this);
00613             connect(widg, SIGNAL(destroyed()), this, SLOT(slot_childDestroyed()));
00614             if((widg->focusPolicy() == QWidget::StrongFocus) ||
00615                (widg->focusPolicy() == QWidget::TabFocus   ) ||
00616                (widg->focusPolicy() == QWidget::WheelFocus ))
00617             {
00618                if(m_firstFocusableChildWidget == 0) {
00619                   m_firstFocusableChildWidget = widg;  
00620                }
00621                m_lastFocusableChildWidget = widg; 
00622                
00623             }
00624          }
00625          delete list;                        
00626       }
00627    }
00628    else
00629    {
00630        if (e->type()==QEvent::IconChange) {
00631 
00632           if  (obj==this)
00633              iconUpdated(this,icon()?(*icon()):QPixmap());
00634           else if (obj==m_trackChanges)
00635              setIcon(m_trackChanges->icon()?(*(m_trackChanges->icon())):QPixmap());
00636        }
00637        if (e->type()==QEvent::CaptionChange) {
00638           if (obj==this)
00639              captionUpdated(this,caption());
00640        }
00641    }
00642 
00643    return false;                           
00644 }
00645 
00647 void KMdiChildView::removeEventFilterForAllChildren()
00648 {
00649    QObjectList *list = queryList( "QWidget" );
00650    QObjectListIt it( *list );          
00651    QObject * obj;
00652    while ( (obj=it.current()) != 0 ) { 
00653       QWidget* widg = (QWidget*)obj;
00654       ++it;
00655       widg->removeEventFilter(this);
00656    }
00657    delete list;                        
00658 }
00659 
00660 QWidget* KMdiChildView::focusedChildWidget()
00661 {
00662    return m_focusedChildWidget;
00663 }
00664 
00665 void KMdiChildView::setFirstFocusableChildWidget(QWidget* firstFocusableChildWidget)
00666 {
00667    m_firstFocusableChildWidget = firstFocusableChildWidget;
00668 }
00669 
00670 void KMdiChildView::setLastFocusableChildWidget(QWidget* lastFocusableChildWidget)
00671 {
00672    m_lastFocusableChildWidget = lastFocusableChildWidget;
00673 }
00675 void KMdiChildView::setTabCaption (const QString& stbCaption) {
00676 
00677   m_sTabCaption = stbCaption;
00678   emit tabCaptionChanged(m_sTabCaption);
00679 
00680 }
00681 void KMdiChildView::setMDICaption (const QString& caption) {
00682   setCaption(caption);
00683   setTabCaption(caption);
00684 }
00685 
00687 void KMdiChildView::setWindowMenuID( int id)
00688 {
00689    m_windowMenuID = id;
00690 }
00691 
00692 
00693 
00695 void KMdiChildView::slot_clickedInWindowMenu()
00696 {
00697    updateTimeStamp();
00698    emit clickedInWindowMenu( m_windowMenuID);
00699 }
00700 
00701 
00702 
00704 void KMdiChildView::slot_clickedInDockMenu()
00705 {
00706    emit clickedInDockMenu( m_windowMenuID);
00707 }
00708 
00709 
00710 
00711 void KMdiChildView::setMinimumSize( int minw, int minh)
00712 {
00713    QWidget::setMinimumSize( minw, minh);
00714    if ( (mdiParent() != 0L) && (mdiParent()->state() != KMdiChildFrm::Minimized) ) {
00715       mdiParent()->setMinimumSize( minw + KMDI_CHILDFRM_DOUBLE_BORDER,
00716                                    minh + KMDI_CHILDFRM_DOUBLE_BORDER
00717                                         + KMDI_CHILDFRM_SEPARATOR
00718                                         + mdiParent()->captionHeight());
00719    }
00720 }
00721 
00722 
00723 
00724 void KMdiChildView::setMaximumSize( int maxw, int maxh)
00725 {
00726    if ( (mdiParent() != 0L) && (mdiParent()->state() == KMdiChildFrm::Normal) ) {
00727       int w = maxw + KMDI_CHILDFRM_DOUBLE_BORDER;
00728       if(w > QWIDGETSIZE_MAX) { w = QWIDGETSIZE_MAX; }
00729       int h = maxh + KMDI_CHILDFRM_DOUBLE_BORDER + KMDI_CHILDFRM_SEPARATOR + mdiParent()->captionHeight();
00730       if(h > QWIDGETSIZE_MAX) { h = QWIDGETSIZE_MAX; }
00731       mdiParent()->setMaximumSize( w, h);
00732    }
00733    QWidget::setMaximumSize( maxw, maxh);
00734 }
00735 
00736 
00737 
00738 void KMdiChildView::show()
00739 {
00740    QWidget* pParent = mdiParent();
00741    if(pParent != 0L) {
00742       pParent->show();
00743    }
00744    QWidget::show();
00745 }
00746 
00747 
00748 
00749 void KMdiChildView::hide()
00750 {
00751    if(mdiParent() != 0L) {
00752       mdiParent()->hide();
00753    }
00754    QWidget::hide();
00755 }
00756 
00757 
00758 
00759 void KMdiChildView::raise()
00760 {
00761    if(mdiParent() != 0L) {
00762       mdiParent()->raise();
00763       
00764    }
00765    QWidget::raise();
00766 }
00767 
00768