kmdi Library API Documentation

kmdichildfrm.cpp

00001 //---------------------------------------------------------------------------- 00002 // filename : kmdichildfrm.cpp 00003 //---------------------------------------------------------------------------- 00004 // Project : KDE MDI extension 00005 // 00006 // begin : 07/1999 by Szymon Stefanek as part of kvirc 00007 // (an IRC application) 00008 // changes : 09/1999 by Falk Brettschneider to create an 00009 // - 06/2000 stand-alone Qt extension set of 00010 // classes and a Qt-based library 00011 // : 01/2003 by Jens Zurheide to allow switching 00012 // between views based on timestamps 00013 // 2000-2003 maintained by the KDevelop project 00014 // 00015 // copyright : (C) 1999-2003 by Szymon Stefanek (stefanek@tin.it) 00016 // and 00017 // Falk Brettschneider 00018 // email : falkbr@kdevelop.org (Falk Brettschneider) 00019 //---------------------------------------------------------------------------- 00020 // 00021 //---------------------------------------------------------------------------- 00022 // 00023 // This program is free software; you can redistribute it and/or modify 00024 // it under the terms of the GNU Library General Public License as 00025 // published by the Free Software Foundation; either version 2 of the 00026 // License, or (at your option) any later version. 00027 // 00028 //---------------------------------------------------------------------------- 00029 00030 #include "kmdichildfrm.h" 00031 #include "kmdichildfrm.moc" 00032 00033 #include "kmdidefines.h" 00034 #include "kmdichildfrmcaption.h" 00035 #include "kmdichildarea.h" 00036 #include "kmdimainfrm.h" 00037 00038 #include <qpainter.h> 00039 #include <qapplication.h> 00040 #include <qcursor.h> 00041 #include <qobjectlist.h> 00042 #include <qframe.h> 00043 #include <qpopupmenu.h> 00044 #include <qtoolbutton.h> 00045 #include <qnamespace.h> 00046 #include <qimage.h> 00047 00048 #include <klocale.h> 00049 #include <kiconloader.h> 00050 00052 // KMdiChildFrm 00054 00055 #define KMDI_NORESIZE 0 00056 #define KMDI_RESIZE_TOP 1 00057 #define KMDI_RESIZE_LEFT 2 00058 #define KMDI_RESIZE_RIGHT 4 00059 #define KMDI_RESIZE_BOTTOM 8 00060 #define KMDI_RESIZE_TOPLEFT (1|2) 00061 #define KMDI_RESIZE_TOPRIGHT (1|4) 00062 #define KMDI_RESIZE_BOTTOMLEFT (8|2) 00063 #define KMDI_RESIZE_BOTTOMRIGHT (8|4) 00064 00065 #include "filenew.xpm" 00066 #include "win_closebutton.xpm" 00067 #include "win_minbutton.xpm" 00068 #include "win_maxbutton.xpm" 00069 #include "win_restorebutton.xpm" 00070 #include "win_undockbutton.xpm" 00071 #include "kde_closebutton.xpm" 00072 #include "kde_minbutton.xpm" 00073 #include "kde_maxbutton.xpm" 00074 #include "kde_restorebutton.xpm" 00075 #include "kde_undockbutton.xpm" 00076 #include "kde2_closebutton.xpm" 00077 #include "kde2_minbutton.xpm" 00078 #include "kde2_maxbutton.xpm" 00079 #include "kde2_restorebutton.xpm" 00080 #include "kde2_undockbutton.xpm" 00081 #include "kde2laptop_closebutton.xpm" 00082 #include "kde2laptop_minbutton.xpm" 00083 #include "kde2laptop_maxbutton.xpm" 00084 #include "kde2laptop_restorebutton.xpm" 00085 #include "kde2laptop_undockbutton.xpm" 00086 00087 00088 KMdiWin32IconButton::KMdiWin32IconButton( QWidget* parent, const char* name) 00089 : QLabel( parent, name) 00090 { 00091 } 00092 00093 //============ mousePressEvent ============// 00094 00095 void KMdiWin32IconButton::mousePressEvent( QMouseEvent*) 00096 { 00097 //emit pressed(); 00098 } 00099 00100 //============ KMdiChildFrm ============// 00101 00102 KMdiChildFrm::KMdiChildFrm(KMdiChildArea *parent) 00103 : QFrame(parent, "kmdi_childfrm") 00104 ,m_pClient(0L) 00105 ,m_pManager(0L) 00106 ,m_pCaption(0L) 00107 ,m_pWinIcon(0L) 00108 ,m_pUnixIcon(0L) 00109 ,m_pMinimize(0L) 00110 ,m_pMaximize(0L) 00111 ,m_pClose(0L) 00112 ,m_pUndock(0L) 00113 ,m_state(Normal) 00114 ,m_restoredRect() 00115 ,m_iResizeCorner(KMDI_NORESIZE) 00116 ,m_iLastCursorCorner(KMDI_NORESIZE) 00117 ,m_bResizing(false) 00118 ,m_bDragging(false) 00119 ,m_pIconButtonPixmap(0L) 00120 ,m_pMinButtonPixmap(0L) 00121 ,m_pMaxButtonPixmap(0L) 00122 ,m_pRestoreButtonPixmap(0L) 00123 ,m_pCloseButtonPixmap(0L) 00124 ,m_pUndockButtonPixmap(0L) 00125 ,m_windowMenuID(0) 00126 ,m_pSystemMenu(0L) 00127 ,m_oldClientMinSize() 00128 ,m_oldClientMaxSize() 00129 ,m_oldLayoutResizeMode(QLayout::Minimum) 00130 { 00131 m_pCaption = new KMdiChildFrmCaption(this); 00132 00133 m_pManager = parent; 00134 00135 m_pWinIcon = new KMdiWin32IconButton(m_pCaption, "kmdi_iconbutton_icon"); 00136 m_pUnixIcon = new QToolButton(m_pCaption, "kmdi_toolbutton_icon"); 00137 m_pMinimize = new QToolButton(m_pCaption, "kmdi_toolbutton_min"); 00138 m_pMaximize = new QToolButton(m_pCaption, "kmdi_toolbutton_max"); 00139 m_pClose = new QToolButton(m_pCaption, "kmdi_toolbutton_close"); 00140 m_pUndock = new QToolButton(m_pCaption, "kmdi_toolbutton_undock"); 00141 00142 QObject::connect(m_pMinimize,SIGNAL(clicked()),this,SLOT(minimizePressed())); 00143 QObject::connect(m_pMaximize,SIGNAL(clicked()),this,SLOT(maximizePressed())); 00144 QObject::connect(m_pClose,SIGNAL(clicked()),this,SLOT(closePressed())); 00145 QObject::connect(m_pUndock,SIGNAL(clicked()),this,SLOT(undockPressed())); 00146 00147 m_pIconButtonPixmap = new QPixmap( SmallIcon("filenew") ); 00148 if (m_pIconButtonPixmap->isNull()) 00149 *m_pIconButtonPixmap = QPixmap(filenew); 00150 00151 redecorateButtons(); 00152 00153 m_pWinIcon->setFocusPolicy(NoFocus); 00154 m_pUnixIcon->setFocusPolicy(NoFocus); 00155 m_pClose->setFocusPolicy(NoFocus); 00156 m_pMinimize->setFocusPolicy(NoFocus); 00157 m_pMaximize->setFocusPolicy(NoFocus); 00158 m_pUndock->setFocusPolicy(NoFocus); 00159 00160 setFrameStyle(QFrame::WinPanel|QFrame::Raised); 00161 setFocusPolicy(NoFocus); 00162 00163 setMouseTracking(true); 00164 00165 setMinimumSize(KMDI_CHILDFRM_MIN_WIDTH, m_pCaption->heightHint()); 00166 00167 m_pSystemMenu = new QPopupMenu(); 00168 } 00169 00170 //============ ~KMdiChildFrm ============// 00171 00172 KMdiChildFrm::~KMdiChildFrm() 00173 { 00174 delete m_pMinButtonPixmap; 00175 delete m_pMaxButtonPixmap; 00176 delete m_pRestoreButtonPixmap; 00177 delete m_pCloseButtonPixmap; 00178 delete m_pUndockButtonPixmap; 00179 delete m_pSystemMenu; 00180 delete m_pIconButtonPixmap; 00181 } 00182 00183 //============ mousePressEvent =============// 00184 void KMdiChildFrm::mousePressEvent(QMouseEvent *e) 00185 { 00186 if( m_bResizing) { 00187 if(QApplication::overrideCursor()) { QApplication::restoreOverrideCursor(); } 00188 m_bResizing = false; 00189 releaseMouse(); 00190 } 00191 00192 m_pCaption->setActive(true); 00193 m_pManager->setTopChild(this,false); 00194 00195 m_iResizeCorner=getResizeCorner(e->pos().x(),e->pos().y()); 00196 if(m_iResizeCorner != KMDI_NORESIZE) { 00197 m_bResizing = true; 00198 //notify child view 00199 KMdiChildFrmResizeBeginEvent ue(e); 00200 if( m_pClient != 0L) { 00201 QApplication::sendEvent( m_pClient, &ue); 00202 } 00203 } 00204 } 00205 00206 //============ mouseReleaseEvent ==============// 00207 00208 void KMdiChildFrm::mouseReleaseEvent(QMouseEvent *e) 00209 { 00210 if(m_bResizing) { 00211 if(QApplication::overrideCursor()) { QApplication::restoreOverrideCursor(); } 00212 00213 m_bResizing = false; 00214 //notify child view 00215 KMdiChildFrmResizeEndEvent ue(e); 00216 if( m_pClient != 0L) { 00217 QApplication::sendEvent( m_pClient, &ue); 00218 } 00219 } 00220 } 00221 00222 //============= setResizeCursor ===============// 00223 00224 void KMdiChildFrm::setResizeCursor(int resizeCorner) 00225 { 00226 if(resizeCorner == m_iLastCursorCorner)return; //Don't do it twice 00227 m_iLastCursorCorner = resizeCorner; 00228 switch (resizeCorner) { 00229 case KMDI_NORESIZE: 00230 if(QApplication::overrideCursor())QApplication::restoreOverrideCursor(); 00231 break; 00232 case KMDI_RESIZE_LEFT: 00233 case KMDI_RESIZE_RIGHT: 00234 QApplication::setOverrideCursor(Qt::sizeHorCursor,true); 00235 break; 00236 case KMDI_RESIZE_TOP: 00237 case KMDI_RESIZE_BOTTOM: 00238 QApplication::setOverrideCursor(Qt::sizeVerCursor,true); 00239 break; 00240 case KMDI_RESIZE_TOPLEFT: 00241 case KMDI_RESIZE_BOTTOMRIGHT: 00242 QApplication::setOverrideCursor(Qt::sizeFDiagCursor,true); 00243 break; 00244 case KMDI_RESIZE_BOTTOMLEFT: 00245 case KMDI_RESIZE_TOPRIGHT: 00246 QApplication::setOverrideCursor(Qt::sizeBDiagCursor,true); 00247 break; 00248 } 00249 } 00250 00251 //============= unsetResizeCursor ===============// 00252 00253 void KMdiChildFrm::unsetResizeCursor() 00254 { 00255 if ( !m_bResizing && (m_iResizeCorner != KMDI_NORESIZE) ) { 00256 m_iResizeCorner=KMDI_NORESIZE; 00257 m_iLastCursorCorner=KMDI_NORESIZE; 00258 if(QApplication::overrideCursor())QApplication::restoreOverrideCursor(); 00259 } 00260 } 00261 00262 //============= mouseMoveEvent ===============// 00263 00264 void KMdiChildFrm::mouseMoveEvent(QMouseEvent *e) 00265 { 00266 if(m_state != Normal) return; 00267 if(!m_pClient) return; 00268 if(m_pClient->minimumSize() == m_pClient->maximumSize()) return; 00269 00270 if(m_bResizing) { 00271 if( !(e->state() & RightButton) && !(e->state() & MidButton)) { 00272 // same as: if no button or left button pressed 00273 QPoint p = parentWidget()->mapFromGlobal( e->globalPos() ); 00274 resizeWindow(m_iResizeCorner, p.x(), p.y()); 00275 } 00276 else 00277 m_bResizing = false; 00278 } 00279 else { 00280 m_iResizeCorner = getResizeCorner(e->pos().x(), e->pos().y()); 00281 setResizeCursor( m_iResizeCorner); 00282 } 00283 } 00284 00285 //============= moveEvent ===============// 00286 00287 void KMdiChildFrm::moveEvent(QMoveEvent* me) 00288 { 00289 // give its child view the chance to notify a childframe move 00290 KMdiChildFrmMoveEvent cfme( me); 00291 if( m_pClient != 0L) { 00292 QApplication::sendEvent( m_pClient, &cfme); 00293 } 00294 } 00295 00296 //=============== leaveEvent ===============// 00297 00298 void KMdiChildFrm::leaveEvent(QEvent *) 00299 { 00300 unsetResizeCursor(); 00301 } 00302 00303 void KMdiChildFrm::resizeWindow(int resizeCorner, int xPos, int yPos) 00304 { 00305 QRect resizeRect(x(),y(),width(),height()); 00306 00307 // Calculate the minimum width & height 00308 int minWidth=0; 00309 int minHeight=0; 00310 int maxWidth=QWIDGETSIZE_MAX; 00311 int maxHeight=QWIDGETSIZE_MAX; 00312 // it could be the client forces the childframe to enlarge its minimum size 00313 if(m_pClient){ 00314 minWidth = m_pClient->minimumSize().width() + KMDI_CHILDFRM_DOUBLE_BORDER; 00315 minHeight = m_pClient->minimumSize().height()+ KMDI_CHILDFRM_DOUBLE_BORDER + 00316 m_pCaption->heightHint() + KMDI_CHILDFRM_SEPARATOR; 00317 maxWidth = m_pClient->maximumSize().width() + KMDI_CHILDFRM_DOUBLE_BORDER; 00318 maxHeight = m_pClient->maximumSize().height()+ KMDI_CHILDFRM_DOUBLE_BORDER + 00319 m_pCaption->heightHint() + KMDI_CHILDFRM_SEPARATOR; 00320 } 00321 if(minWidth<minimumWidth())minWidth=minimumWidth(); 00322 if(minHeight<minimumHeight())minHeight=minimumHeight(); 00323 if(maxWidth>maximumWidth())maxWidth=maximumWidth(); 00324 if(maxHeight>maximumHeight())maxHeight=maximumHeight(); 00325 00326 QPoint mousePos( xPos, yPos); 00327 00328 // manipulate width 00329 switch (resizeCorner){ 00330 case KMDI_RESIZE_TOPLEFT: // no break 00331 case KMDI_RESIZE_LEFT: // no break 00332 case KMDI_RESIZE_BOTTOMLEFT: 00333 resizeRect.setLeft(mousePos.x()); 00334 if(resizeRect.width() < minWidth)resizeRect.setLeft(resizeRect.right() - minWidth + 1); 00335 if(resizeRect.width() > maxWidth)resizeRect.setLeft(resizeRect.right() - maxWidth + 1); 00336 break; 00337 case KMDI_RESIZE_TOPRIGHT: // no break 00338 case KMDI_RESIZE_RIGHT: // no break 00339 case KMDI_RESIZE_BOTTOMRIGHT: 00340 resizeRect.setRight(mousePos.x()); 00341 if(resizeRect.width() < minWidth)resizeRect.setRight(resizeRect.left() + minWidth - 1); 00342 if(resizeRect.width() > maxWidth)resizeRect.setRight(resizeRect.left() + maxWidth - 1); 00343 break; 00344 default: 00345 // nothing to do 00346 break; 00347 } 00348 // manipulate height 00349 switch (resizeCorner){ 00350 case KMDI_RESIZE_TOPLEFT: // no break 00351 case KMDI_RESIZE_TOP: // no break 00352 case KMDI_RESIZE_TOPRIGHT: 00353 resizeRect.setTop(mousePos.y()); 00354 if(resizeRect.height() < minHeight)resizeRect.setTop(resizeRect.bottom() - minHeight + 1); 00355 if(resizeRect.height() > maxHeight)resizeRect.setTop(resizeRect.bottom() - maxHeight + 1); 00356 break; 00357 case KMDI_RESIZE_BOTTOMLEFT: // no break 00358 case KMDI_RESIZE_BOTTOM: // no break 00359 case KMDI_RESIZE_BOTTOMRIGHT: 00360 resizeRect.setBottom(mousePos.y()); 00361 if(resizeRect.height() < minHeight)resizeRect.setBottom(resizeRect.top() + minHeight - 1); 00362 if(resizeRect.height() > maxHeight)resizeRect.setBottom(resizeRect.top() + maxHeight - 1); 00363 break; 00364 default: 00365 // nothing to do 00366 break; 00367 } 00368 // actually resize 00369 setGeometry( resizeRect); 00370 00371 if(m_state==Maximized){ 00372 m_state=Normal; 00373 m_pMaximize->setPixmap( *m_pMaxButtonPixmap); 00374 } 00375 } 00376 00377 //================= getResizeCorner =============// 00378 00379 int KMdiChildFrm::getResizeCorner(int ax,int ay) 00380 { 00381 int ret = KMDI_NORESIZE; 00382 if(m_pClient->minimumWidth() != m_pClient->maximumWidth()) { 00383 if((ax>0)&&(ax<(KMDI_CHILDFRM_BORDER+2))) ret |= KMDI_RESIZE_LEFT; 00384 if((ax<width())&&(ax>(width()-(KMDI_CHILDFRM_BORDER+2)))) ret |= KMDI_RESIZE_RIGHT; 00385 } 00386 if(m_pClient->minimumHeight() != m_pClient->maximumHeight()) { 00387 if((ay>0)&&(ay<(KMDI_CHILDFRM_BORDER+2))) ret |= KMDI_RESIZE_TOP; 00388 if((ay<(height()))&&(ay>(height()-(KMDI_CHILDFRM_BORDER+2)))) ret |= KMDI_RESIZE_BOTTOM; 00389 } 00390 return ret; 00391 } 00392 00393 //============= maximizePressed ============// 00394 00395 void KMdiChildFrm::maximizePressed() 00396 { 00397 switch(m_state){ 00398 case Maximized: 00399 emit m_pManager->nowMaximized(false); 00400 setState(Normal); 00401 break; 00402 case Normal: 00403 case Minimized: 00404 setState(Maximized); 00405 emit m_pManager->nowMaximized(true); 00406 break; 00407 } 00408 } 00409 00410 void KMdiChildFrm::restorePressed() 00411 { 00412 if( m_state == Normal) 00413 return; 00414 if( m_state == Maximized) 00415 emit m_pManager->nowMaximized(false); 00416 setState(Normal); 00417 } 00418 00419 //============= minimizePressed ============// 00420 00421 void KMdiChildFrm::minimizePressed() 00422 { 00423 switch(m_state){ 00424 case Minimized: setState(Normal); break; 00425 case Normal: setState(Minimized); break; 00426 case Maximized: 00427 emit m_pManager->nowMaximized(false); 00428 setState(Normal); 00429 setState(Minimized); 00430 break; 00431 } 00432 } 00433 00434 //============= closePressed ============// 00435 00436 void KMdiChildFrm::closePressed() 00437 { 00438 if(m_pClient) 00439 m_pClient->close(); 00440 } 00441 00442 //============= undockPressed ============// 00443 00444 void KMdiChildFrm::undockPressed() 00445 { 00446 if(m_pClient) { 00447 if( m_state == Minimized) 00448 setState( Normal); 00449 m_pClient->detach(); 00450 } 00451 } 00452 00453 //============ setState =================// 00454 00455 void KMdiChildFrm::setState(MdiWindowState state, bool /*bAnimate*/) 00456 { 00457 if(m_state==Normal){ //save the current rect 00458 m_restoredRect=QRect(x(),y(),width(),height()); 00459 } 00460 switch(state){ 00461 case Normal: 00462 switch(m_state){ 00463 case Maximized: 00464 m_pClient->m_stateChanged = true; 00465 m_state=state; 00466 // client min / max size / layout behavior don't change 00467 // set frame max size indirectly by setting the clients max size to 00468 // it's current value (calls setMaxSize() of frame) 00469 m_pClient->setMaximumSize(m_pClient->maximumSize().width(), m_pClient->maximumSize().height()); 00470 m_pMaximize->setPixmap( *m_pMaxButtonPixmap); 00471 setGeometry(m_restoredRect); 00472 break; 00473 case Minimized: 00474 m_pClient->m_stateChanged = true; 00475 m_state=state; 00476 // restore client min / max size / layout behavior 00477 m_pClient->setMinimumSize(m_oldClientMinSize.width(),m_oldClientMinSize.height()); 00478 m_pClient->setMaximumSize(m_oldClientMaxSize.width(),m_oldClientMaxSize.height()); 00479 if (m_pClient->layout() != 0L) { 00480 m_pClient->layout()->setResizeMode(m_oldLayoutResizeMode); 00481 } 00482 m_pMinimize->setPixmap( *m_pMinButtonPixmap); 00483 m_pMaximize->setPixmap( *m_pMaxButtonPixmap); 00484 QObject::disconnect(m_pMinimize,SIGNAL(clicked()),this,SLOT(restorePressed())); 00485 QObject::connect(m_pMinimize,SIGNAL(clicked()),this,SLOT(minimizePressed())); 00486 setGeometry(m_restoredRect); 00487 break; 00488 case Normal: 00489 break; 00490 } 00491 break; 00492 case Maximized: 00493 switch(m_state){ 00494 case Minimized: { 00495 m_pClient->m_stateChanged = true; 00496 m_state=state; 00497 // restore client min / max size / layout behavior 00498 m_pClient->setMinimumSize(m_oldClientMinSize.width(),m_oldClientMinSize.height()); 00499 m_pClient->setMaximumSize(m_oldClientMaxSize.width(),m_oldClientMaxSize.height()); 00500 if (m_pClient->layout() != 0L) { 00501 m_pClient->layout()->setResizeMode(m_oldLayoutResizeMode); 00502 } 00503 setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX); 00504 // reset to maximize-captionbar 00505 m_pMaximize->setPixmap( *m_pRestoreButtonPixmap); 00506 m_pMinimize->setPixmap( *m_pMinButtonPixmap); 00507 QObject::disconnect(m_pMinimize,SIGNAL(clicked()),this,SLOT(restorePressed())); 00508 QObject::connect(m_pMinimize,SIGNAL(clicked()),this,SLOT(minimizePressed())); 00509 int nFrameWidth = KMDI_CHILDFRM_DOUBLE_BORDER; 00510 int nFrameHeight = KMDI_CHILDFRM_DOUBLE_BORDER + KMDI_CHILDFRM_SEPARATOR + 00511 m_pCaption->heightHint(); 00512 setGeometry(-m_pClient->x(), -m_pClient->y(), 00513 m_pManager->width() + nFrameWidth, 00514 m_pManager->height() + nFrameHeight); 00515 raise(); 00516 } 00517 break; 00518 case Normal: { 00519 m_pClient->m_stateChanged = true; 00520 m_state=state; 00521 // client min / max size / layout behavior don't change 00522 setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX); 00523 m_pMaximize->setPixmap( *m_pRestoreButtonPixmap); 00524 int nFrameWidth = KMDI_CHILDFRM_DOUBLE_BORDER; 00525 int nFrameHeight = KMDI_CHILDFRM_DOUBLE_BORDER + KMDI_CHILDFRM_SEPARATOR + 00526 m_pCaption->heightHint(); 00527 QRect maximizedFrmRect(-m_pClient->x(), -m_pClient->y(), 00528 m_pManager->width() + nFrameWidth, 00529 m_pManager->height() + nFrameHeight); 00530 if (geometry() != maximizedFrmRect) { 00531 setGeometry(maximizedFrmRect); 00532 } 00533 raise(); 00534 } 00535 break; 00536 case Maximized: 00537 break; 00538 } 00539 break; 00540 case Minimized: 00541 switch(m_state){ 00542 case Maximized: 00543 m_pClient->m_stateChanged = true; 00544 m_state=state; 00545 // save client min / max size / layout behavior 00546 m_oldClientMinSize = m_pClient->minimumSize(); 00547 m_oldClientMaxSize = m_pClient->maximumSize(); 00548 if (m_pClient->layout() != 0L) { 00549 m_oldLayoutResizeMode = m_pClient->layout()->resizeMode(); 00550 } 00551 m_pClient->setMinimumSize(0, 0); 00552 m_pClient->setMaximumSize(0, 0); 00553 if (m_pClient->layout() != 0L) { 00554 m_pClient->layout()->setResizeMode(QLayout::FreeResize); 00555 } 00556 switchToMinimizeLayout(); 00557 m_pManager->childMinimized(this,true); 00558 break; 00559 case Normal: 00560 m_pClient->m_stateChanged = true; 00561 m_state=state; 00562 // save client min / max size / layout behavior 00563 m_oldClientMinSize = m_pClient->minimumSize(); 00564 m_oldClientMaxSize = m_pClient->maximumSize(); 00565 if (m_pClient->layout() != 0L) { 00566 m_oldLayoutResizeMode = m_pClient->layout()->resizeMode(); 00567 } 00568 m_restoredRect = geometry(); 00569 m_pClient->setMinimumSize(0, 0); 00570 m_pClient->setMaximumSize(0, 0); 00571 if (m_pClient->layout() != 0L) { 00572 m_pClient->layout()->setResizeMode(QLayout::FreeResize); 00573 } 00574 switchToMinimizeLayout(); 00575 m_pManager->childMinimized(this,false); 00576 break; 00577 case Minimized: 00578 break; 00579 } 00580 break; 00581 } 00582 00583 KMdiChildFrm* pTopFrame = m_pManager->topChild(); 00584 KMdiChildView* pTopChild = 0L; 00585 if (pTopFrame != 0L) { 00586 pTopChild = pTopFrame->m_pClient; 00587 } 00588 if ( (pTopChild != 0L) && pTopChild->isMaximized() ) { 00589 m_pManager->setMinimumSize(pTopChild->minimumWidth(), pTopChild->minimumHeight()); 00592 } 00593 else { 00594 m_pManager->setMinimumSize(0, 0); 00595 m_pManager->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); 00596 } 00597 } 00598 00599 //============== restoreGeometry ================// 00600 00601 QRect KMdiChildFrm::restoreGeometry() const 00602 { 00603 return m_restoredRect; 00604 } 00605 00606 //============== setRestoreGeometry ================// 00607 00608 void KMdiChildFrm::setRestoreGeometry(const QRect& newRestGeo) 00609 { 00610 m_restoredRect = newRestGeo; 00611 } 00612 00613 //============ setCaption ===============// 00614 00615 void KMdiChildFrm::setCaption(const QString& text) 00616 { 00617 m_pCaption->setCaption(text); 00618 } 00619 00620 //============ enableClose ==============// 00621 00622 void KMdiChildFrm::enableClose(bool bEnable) 00623 { 00624 m_pClose->setEnabled(bEnable); 00625 m_pClose->repaint(false); 00626 } 00627 00628 //============ setIcon ==================// 00629 00630 void KMdiChildFrm::setIcon(const QPixmap& pxm) 00631 { 00632 QPixmap p = pxm; 00633 if (p.width()!=18 || p.height()!=18) { 00634 QImage img = p.convertToImage(); 00635 p = img.smoothScale(18,18,QImage::ScaleMin); 00636 } 00637 const bool do_resize = m_pIconButtonPixmap->size()!=p.size(); 00638 *m_pIconButtonPixmap = p; 00639 m_pWinIcon->setPixmap( p ); 00640 m_pUnixIcon->setPixmap( p ); 00641 if (do_resize) 00642 doResize(true); 00643 } 00644 00645 //============ icon =================// 00646 00647 QPixmap* KMdiChildFrm::icon() const 00648 { 00649 return m_pIconButtonPixmap; 00650 } 00651 00652 //============ setClient ============// 00653 void KMdiChildFrm::setClient(KMdiChildView *w, bool bAutomaticResize) 00654 { 00655 m_pClient=w; 00656 00657 if (w->icon()) 00658 setIcon( *(w->icon())); 00659 00660 //resize to match the client 00661 int clientYPos=m_pCaption->heightHint()+KMDI_CHILDFRM_SEPARATOR+KMDI_CHILDFRM_BORDER; 00662 if (bAutomaticResize || w->size().isEmpty() || (w->size() == QSize(1,1))) { 00663 if (m_pManager->topChild()) { 00664 resize(m_pManager->topChild()->size()); 00665 } 00666 else { 00667 resize(m_pManager->m_defaultChildFrmSize.width()+KMDI_CHILDFRM_DOUBLE_BORDER,m_pManager->m_defaultChildFrmSize.height()+KMDI_CHILDFRM_BORDER+clientYPos); 00668 } 00669 } 00670 else { 00671 resize(w->width()+KMDI_CHILDFRM_DOUBLE_BORDER,w->height()+KMDI_CHILDFRM_BORDER+clientYPos); 00672 } 00673 00674 // memorize the focuses in a dictionary because they will get lost during reparenting 00675 QDict<FocusPolicy>* pFocPolDict = new QDict<FocusPolicy>; 00676 pFocPolDict->setAutoDelete(true); 00677 QObjectList *list = m_pClient->queryList( "QWidget" ); 00678 QObjectListIt it( *list ); // iterate over the buttons 00679 QObject * obj; 00680 int i = 1; 00681 while ( (obj=it.current()) != 0 ) { // for each found object... 00682 ++it; 00683 QWidget* widg = (QWidget*)obj; 00684 if( widg->name(0) == 0) { 00685 QString tmpStr; 00686 tmpStr.setNum( i); 00687 tmpStr = "unnamed" + tmpStr; 00688 widg->setName( tmpStr.latin1() ); 00689 i++; 00690 } 00691 FocusPolicy* pFocPol = new FocusPolicy; 00692 *pFocPol = widg->focusPolicy(); 00693 pFocPolDict->insert( widg->name(), pFocPol); 00694 } 00695 delete list; // delete the list, not the objects 00696 00697 //Reparent if needed 00698 if(w->parent()!=this){ 00699 //reparent to this widget , no flags , point , show it 00700 QPoint pnt2(KMDI_CHILDFRM_BORDER,clientYPos); 00701 QSize mincs = w->minimumSize(); 00702 QSize maxcs = w->maximumSize(); 00703 w->setMinimumSize(0,0); 00704 w->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX); 00705 00706 // min/max sizes, flags, DND get lost. :-( 00707 w->reparent(this,0,pnt2,w->isVisible()); 00708 00709 w->setMinimumSize(mincs.width(),mincs.height()); 00710 w->setMaximumSize(maxcs.width(),maxcs.height()); 00711 } else w->move(KMDI_CHILDFRM_BORDER,clientYPos); 00712 00713 linkChildren( pFocPolDict); 00714 00715 QObject::connect( m_pClient, SIGNAL(mdiParentNowMaximized(bool)), m_pManager, SIGNAL(nowMaximized(bool)) ); 00716 00717 if( m_pClient->minimumSize().width() > m_pManager->m_defaultChildFrmSize.width()) { 00718 setMinimumWidth(m_pClient->minimumSize().width() + KMDI_CHILDFRM_DOUBLE_BORDER); 00719 } 00720 if( m_pClient->minimumSize().height() > m_pManager->m_defaultChildFrmSize.height()) { 00721 setMinimumHeight( m_pClient->minimumSize().height()+ KMDI_CHILDFRM_DOUBLE_BORDER + 00722 m_pCaption->heightHint() + KMDI_CHILDFRM_SEPARATOR); 00723 } 00724 } 00725 00726 //============ unsetClient ============// 00727 00728 void KMdiChildFrm::unsetClient( QPoint positionOffset) 00729 { 00730 if(!m_pClient)return; 00731 00732 QObject::disconnect( m_pClient, SIGNAL(mdiParentNowMaximized(bool)), m_pManager, SIGNAL(nowMaximized(bool)) ); 00733 00734 //reparent to desktop widget , no flags , point , show it 00735 QDict<FocusPolicy>* pFocPolDict; 00736 pFocPolDict = unlinkChildren(); 00737 00738 // get name of focused child widget 00739 QWidget* focusedChildWidget = m_pClient->focusedChildWidget(); 00740 const char* nameOfFocusedWidget = ""; 00741 if( focusedChildWidget != 0) 00742 nameOfFocusedWidget = focusedChildWidget->name(); 00743 00744 QSize mins = m_pClient->minimumSize(); 00745 QSize maxs = m_pClient->maximumSize(); 00746 m_pClient->reparent(0,0,mapToGlobal(pos())-pos()+positionOffset,isVisible()); 00747 m_pClient->setMinimumSize(mins.width(),mins.height()); 00748 m_pClient->setMaximumSize(maxs.width(),maxs.height()); 00749 00750 // remember the focus policies using the dictionary and reset them 00751 QObjectList *list = m_pClient->queryList( "QWidget" ); 00752 QObjectListIt it( *list ); // iterate over all child widgets of child frame 00753 QObject * obj; 00754 QWidget* firstFocusableChildWidget = 0; 00755 QWidget* lastFocusableChildWidget = 0; 00756 while ( (obj=it.current()) != 0 ) { // for each found object... 00757 QWidget* widg = (QWidget*)obj; 00758 ++it; 00759 FocusPolicy* pFocPol = pFocPolDict->find( widg->name()); // remember the focus policy from before the reparent 00760 if( pFocPol) 00761 widg->setFocusPolicy( *pFocPol); 00762 // reset focus to old position (doesn't work :-( for its own unexplicable reasons) 00763 if( widg->name() == nameOfFocusedWidget) { 00764 widg->setFocus(); 00765 } 00766 // get first and last focusable widget 00767 if( (widg->focusPolicy() == QWidget::StrongFocus) || (widg->focusPolicy() == QWidget::TabFocus)) { 00768 if( firstFocusableChildWidget == 0) 00769 firstFocusableChildWidget = widg; // first widget 00770 lastFocusableChildWidget = widg; // last widget 00771 //qDebug("*** %s (%s)",widg->name(),widg->className()); 00772 } 00773 else { 00774 if( widg->focusPolicy() == QWidget::WheelFocus) { 00775 if( firstFocusableChildWidget == 0) 00776 firstFocusableChildWidget = widg; // first widget 00777 lastFocusableChildWidget = widg; // last widget 00778 //qDebug("*** %s (%s)",widg->name(),widg->className()); 00779 } 00780 } 00781 } 00782 delete list; // delete the list, not the objects 00783 delete pFocPolDict; 00784 00785 // reset first and last focusable widget 00786 m_pClient->setFirstFocusableChildWidget( firstFocusableChildWidget); 00787 m_pClient->setLastFocusableChildWidget( lastFocusableChildWidget); 00788 00789 // reset the focus policy of the view 00790 m_pClient->setFocusPolicy(QWidget::ClickFocus); 00791 00792 // lose information about the view (because it's undocked now) 00793 m_pClient=0; 00794 } 00795 00796 //============== linkChildren =============// 00797 void KMdiChildFrm::linkChildren( QDict<FocusPolicy>* pFocPolDict) 00798 { 00799 // reset the focus policies for all widgets in the view (take them from the dictionary) 00800 QObjectList *list = m_pClient->queryList( "QWidget" ); 00801 QObjectListIt it( *list ); // iterate over all child widgets of child frame 00802 QObject * obj; 00803 while ( (obj=it.current()) != 0 ) { // for each found object... 00804 QWidget* widg = (QWidget*)obj; 00805 ++it; 00806 FocusPolicy* pFocPol = pFocPolDict->find(widg->name()); // remember the focus policy from before the reparent 00807 if( pFocPol != 0) 00808 widg->setFocusPolicy( *pFocPol); 00809 if (!(widg->inherits("QPopupMenu"))) { 00810 widg->installEventFilter(this); 00811 } 00812 } 00813 delete list; // delete the list, not the objects 00814 delete pFocPolDict; 00815 00816 // reset the focus policies for the rest 00817 m_pWinIcon->setFocusPolicy(QWidget::NoFocus); 00818 m_pUnixIcon->setFocusPolicy(QWidget::NoFocus); 00819 m_pClient->setFocusPolicy(QWidget::ClickFocus); 00820 m_pCaption->setFocusPolicy(QWidget::NoFocus); 00821 m_pUndock->setFocusPolicy(QWidget::NoFocus); 00822 m_pMinimize->setFocusPolicy(QWidget::NoFocus); 00823 m_pMaximize->setFocusPolicy(QWidget::NoFocus); 00824 m_pClose->setFocusPolicy(QWidget::NoFocus); 00825 00826 // install the event filter (catch mouse clicks) for the rest 00827 m_pWinIcon->installEventFilter(this); 00828 m_pUnixIcon->installEventFilter(this); 00829 m_pCaption->installEventFilter(this); 00830 m_pUndock->installEventFilter(this); 00831 m_pMinimize->installEventFilter(this); 00832 m_pMaximize->installEventFilter(this); 00833 m_pClose->installEventFilter(this); 00834 m_pClient->installEventFilter(this); 00835 // m_pClient->installEventFilterForAllChildren(); 00836 } 00837 00838 //============== unlinkChildren =============// 00839 00840 QDict<QWidget::FocusPolicy>* KMdiChildFrm::unlinkChildren() 00841 { 00842 // memorize the focuses in a dictionary because they will get lost during reparenting 00843 QDict<FocusPolicy>* pFocPolDict = new QDict<FocusPolicy>; 00844 pFocPolDict->setAutoDelete(true); 00845 00846 QObjectList *list = m_pClient->queryList( "QWidget" ); 00847 QObjectListIt it( *list ); // iterate over all child widgets of child frame 00848 QObject * obj; 00849 int i = 1; 00850 while ( (obj=it.current()) != 0 ) { // for each found object... 00851 ++it; 00852 QWidget* widg = (QWidget*)obj; 00853 // get current widget object name 00854 if( widg->name(0) == 0) { 00855 QString tmpStr; 00856 tmpStr.setNum( i); 00857 tmpStr = "unnamed" + tmpStr; 00858 widg->setName( tmpStr.latin1() ); 00859 i++; 00860 } 00861 FocusPolicy* pFocPol = new FocusPolicy; 00862 *pFocPol = widg->focusPolicy(); 00863 // memorize focus policy 00864 pFocPolDict->insert( widg->name(), pFocPol); 00865 // remove event filter 00866 ((QWidget*)obj)->removeEventFilter(this); 00867 } 00868 delete list; // delete the list, not the objects 00869 00870 // remove the event filter (catch mouse clicks) for the rest 00871 m_pWinIcon->removeEventFilter(this); 00872 m_pUnixIcon->removeEventFilter(this); 00873 m_pCaption->removeEventFilter(this); 00874 m_pUndock->removeEventFilter(this); 00875 m_pMinimize->removeEventFilter(this); 00876 m_pMaximize->removeEventFilter(this); 00877 m_pClose->removeEventFilter(this); 00878 m_pClient->removeEventFilter(this); 00879 00880 //SCHEDULED_FOR_REMOVE m_pClient->removeEventFilterForAllChildren(); 00881 00882 return pFocPolDict; 00883 } 00884 00885 //============== resizeEvent ===============// 00886 00887 void KMdiChildFrm::resizeEvent(QResizeEvent *) 00888 { 00889 doResize(); // an extra method because it can also called directly 00890 } 00891 00892 void KMdiChildFrm::doResize() 00893 { 00894 doResize(false); 00895 } 00896 00897 void KMdiChildFrm::doResize(bool captionOnly) 00898 { 00899 //Resize the caption 00900 int captionHeight = m_pCaption->heightHint(); 00901 int captionWidth = width() - KMDI_CHILDFRM_DOUBLE_BORDER; 00902 int buttonHeight = m_pClose->pixmap()->height(); 00903 int buttonWidth = m_pClose->pixmap()->width(); 00904 int heightOffset = captionHeight/2 - buttonHeight/2; 00905 int rightOffset1 = 1; 00906 int rightOffset2 = 1; 00907 int frmIconHeight = m_pWinIcon->pixmap()->height(); 00908 int frmIconWidth = m_pWinIcon->pixmap()->width(); 00909 int frmIconOffset = 1; 00910 QWidget* pIconWidget = m_pWinIcon; 00911 m_pCaption->setGeometry( KMDI_CHILDFRM_BORDER, KMDI_CHILDFRM_BORDER, captionWidth, captionHeight); 00912 //The buttons are caption children 00913 if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::Win95Look) { 00914 rightOffset2 += 2; 00915 m_pUnixIcon->hide(); 00916 } 00917 else if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDE1Look) { 00918 buttonWidth += 4; 00919 buttonHeight += 4; 00920 heightOffset -= 2; 00921 rightOffset1 = 0; 00922 rightOffset2 = 0; 00923 m_pWinIcon->hide(); 00924 frmIconHeight = buttonHeight; 00925 frmIconWidth = buttonWidth; 00926 frmIconOffset = 0; 00927 pIconWidget = m_pUnixIcon; 00928 } 00929 else if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDELook) { 00930 buttonWidth += 3; 00931 buttonHeight += 3; 00932 heightOffset -= 1; 00933 m_pUnixIcon->hide(); 00934 } 00935 if (KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::KDELaptopLook) { 00936 pIconWidget->setGeometry(frmIconOffset,captionHeight/2-frmIconHeight/2,frmIconWidth,frmIconHeight); 00937 m_pClose->setGeometry((captionWidth-buttonWidth)-rightOffset1,heightOffset,buttonWidth,buttonHeight); 00938 m_pMaximize->setGeometry((captionWidth-(buttonWidth*2))-rightOffset2,heightOffset,buttonWidth,buttonHeight); 00939 m_pMinimize->setGeometry((captionWidth-(buttonWidth*3))-rightOffset2,heightOffset,buttonWidth,buttonHeight); 00940 m_pUndock->setGeometry((captionWidth-(buttonWidth*4))-rightOffset2,heightOffset,buttonWidth,buttonHeight); 00941 } 00942 else { // KDELaptopLook 00943 m_pWinIcon->hide(); 00944 m_pUnixIcon->hide(); 00945 buttonHeight += 5; 00946 heightOffset -= 2; 00947 m_pClose->setGeometry ( 0, heightOffset, 27, buttonHeight); 00948 m_pMaximize->setGeometry( captionWidth-27, heightOffset, 27, buttonHeight); 00949 m_pMinimize->setGeometry( captionWidth-27*2, heightOffset, 27, buttonHeight); 00950 m_pUndock->setGeometry ( captionWidth-27*3, heightOffset, 27, buttonHeight); 00951 } 00952 //Resize the client 00953 if (!captionOnly && m_pClient) { 00954 QSize newClientSize(captionWidth, 00955 height()-(KMDI_CHILDFRM_DOUBLE_BORDER+captionHeight+KMDI_CHILDFRM_SEPARATOR)); 00956 if (newClientSize != m_pClient->size()) { 00957 m_pClient->setGeometry(KMDI_CHILDFRM_BORDER, 00958 m_pCaption->heightHint()+KMDI_CHILDFRM_SEPARATOR+KMDI_CHILDFRM_BORDER, 00959 newClientSize.width(), newClientSize.height()); 00960 } 00961 } 00962 } 00963 00964 static bool hasParent(QObject* par, QObject* o) { 00965 while (o && o!=par) 00966 o = o->parent(); 00967 return o==par; 00968 } 00969 00970 //============= eventFilter ===============// 00971 00972 bool KMdiChildFrm::eventFilter( QObject *obj, QEvent *e ) 00973 { 00974 switch (e->type()) { 00975 case QEvent::Enter: 00976 { 00977 // check if the receiver is really a child of this frame 00978 bool bIsChild = false; 00979 QObject* pObj = obj; 00980 while ( (pObj != 0L) && !bIsChild) { 00981 bIsChild = (pObj == this); 00982 pObj = pObj->parent(); 00983 } 00984 // unset the resize cursor if the cursor moved from the frame into a inner widget 00985 if (bIsChild) { 00986 unsetResizeCursor(); 00987 } 00988 } 00989 break; 00990 case QEvent::MouseButtonPress: 00991 { 00992 // if ( (QWidget*)obj != m_pClient ) { 00993 if (!hasParent(m_pClient, obj)) { 00994 bool bIsSecondClick = false; 00995 if (m_timeMeasure.elapsed() <= QApplication::doubleClickInterval()) { 00996 bIsSecondClick = true; // of a possible double click 00997 } 00998 if ( !(((obj == m_pWinIcon) || (obj == m_pUnixIcon)) && bIsSecondClick) ) { 00999 // in case we didn't click on the icon button 01000 QFocusEvent* pFE = new QFocusEvent(QFocusEvent::FocusIn); 01001 QApplication::sendEvent(qApp->mainWidget(), pFE); 01002 if (m_pClient) { 01003 m_pClient->updateTimeStamp(); 01004 m_pClient->activate(); 01005 } 01006 QWidget* w = (QWidget*) obj; 01007 if( (w->parent() != m_pCaption) && (w != m_pCaption)) { 01008 if ((w->focusPolicy() == QWidget::ClickFocus) || (w->focusPolicy() == QWidget::StrongFocus)) { 01009 w->setFocus(); 01010 } 01011 } 01012 } 01013 if ((obj == m_pWinIcon) || (obj == m_pUnixIcon)) { 01014 // in case we clicked on the icon button 01015 if (m_timeMeasure.elapsed() > QApplication::doubleClickInterval()) { 01016 showSystemMenu(); 01017 m_timeMeasure.start(); 01018 } 01019 else { 01020 closePressed(); // double click on icon button closes the view 01021 } 01022 return true; 01023 } 01024 } 01025 } 01026 break; 01027 case QEvent::Resize: 01028 { 01029 if ( ( (QWidget*)obj == m_pClient ) && (m_state == Normal) ) { 01030 QResizeEvent* re = (QResizeEvent*)e; 01031 int captionHeight = m_pCaption->heightHint(); 01032 QSize newChildFrmSize( re->size().width() + KMDI_CHILDFRM_DOUBLE_BORDER, 01033 re->size().height() + captionHeight + KMDI_CHILDFRM_SEPARATOR + KMDI_CHILDFRM_DOUBLE_BORDER ); 01034 if( newChildFrmSize != size()) 01035 resize( newChildFrmSize ); 01036 } 01037 } 01038 break; 01039 case QEvent::ChildRemoved: 01040 { 01041 // if we lost a child we uninstall ourself as event filter for the lost 01042 // child and its children 01043 QObject* pLostChild = ((QChildEvent*)e)->child(); 01044 if ((pLostChild != 0L) /*&& (pLostChild->inherits("QWidget"))*/ ) { 01045 QObjectList *list = pLostChild->queryList(); 01046 list->insert(0, pLostChild); // add the lost child to the list too, just to save code 01047 QObjectListIt it( *list ); // iterate over all lost child widgets 01048 QObject * obj; 01049 while ( (obj=it.current()) != 0 ) { // for each found object... 01050 QWidget* widg = (QWidget*)obj; 01051 ++it; 01052 widg->removeEventFilter(this); 01053 } 01054 delete list; // delete the list, not the objects 01055 } 01056 } 01057 break; 01058 case QEvent::ChildInserted: 01059 { 01060 // if we got a new child we install ourself as event filter for the new 01061 // child and its children (as we did when we got our client). 01062 // XXX see linkChildren() and focus policy stuff 01063 QObject* pNewChild = ((QChildEvent*)e)->child(); 01064 if ( (pNewChild != 0L) && (pNewChild->inherits("QWidget")) ) { 01065 QWidget* pNewWidget = (QWidget*)pNewChild; 01066 QObjectList *list = pNewWidget->queryList( "QWidget" ); 01067 list->insert(0, pNewChild); // add the new child to the list too, just to save code 01068 QObjectListIt it( *list ); // iterate over all new child widgets 01069 QObject * obj; 01070 while ( (obj=it.current()) != 0 ) { // for each found object... 01071 QWidget* widg = (QWidget*)obj; 01072 ++it; 01073 if (!(widg->inherits("QPopupMenu"))) { 01074 widg->installEventFilter(this); 01075 } 01076 } 01077 delete list; // delete the list, not the objects 01078 } 01079 } 01080 break; 01081 default: 01082 break; 01083 } 01084 // return QWidget::eventFilter( obj, e); // standard event processing 01085 return false; // standard event processing (see Qt documentation) 01086 } 01087 01088 //============= raiseAndActivate ===============// 01089 01090 void KMdiChildFrm::raiseAndActivate() 01091 { 01092 //qDebug("ChildFrm::raiseAndActivate"); 01093 m_pCaption->setActive(true); 01094 m_pManager->setTopChild(this,false); //Do not focus by now... 01095 } 01096 01097 //============= setMinimumSize ===============// 01098 01099 void KMdiChildFrm::setMinimumSize ( int minw, int minh ) 01100 { 01101 QWidget::setMinimumSize(minw, minh); 01102 if (m_state == Maximized) { 01103 m_pManager->setMinimumSize(minw, minh); 01104 } 01105 } 01106 01107 //============= systemMenu ===============// 01108 01109 QPopupMenu* KMdiChildFrm::systemMenu() const 01110 { 01111 if( m_pSystemMenu == 0) 01112 return 0; 01113 01114 m_pSystemMenu->clear(); 01115 01116 if (KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::Win95Look) { 01117 m_pSystemMenu->insertItem(i18n("&Restore"),this,SLOT(restorePressed())); 01118 m_pSystemMenu->insertItem(i18n("&Move"),m_pCaption, SLOT(slot_moveViaSystemMenu())); 01119 m_pSystemMenu->insertItem(i18n("R&esize"),this, SLOT(slot_resizeViaSystemMenu())); 01120 m_pSystemMenu->insertItem(i18n("M&inimize"),this, SLOT(minimizePressed())); 01121 m_pSystemMenu->insertItem(i18n("M&aximize"),this, SLOT(maximizePressed())); 01122 if( state() == Normal) 01123 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(0),false); 01124 else if( state() == Maximized) { 01125 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(1),false); 01126 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(2),false); 01127 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(4),false); 01128 } 01129 else if( state() == Minimized) { 01130 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(2),false); 01131 m_pSystemMenu->setItemEnabled(m_pSystemMenu->idAt(3),false); 01132 } 01133 } 01134 else { 01135 if( state() != Normal) 01136 m_pSystemMenu->insertItem(i18n("&Restore"),this,SLOT(restorePressed())); 01137 if( state() != Maximized) 01138 m_pSystemMenu->insertItem(i18n("&Maximize"),this, SLOT(maximizePressed())); 01139 if( state() != Minimized) 01140 m_pSystemMenu->insertItem(i18n("&Minimize"),this, SLOT(minimizePressed())); 01141 if( state() != Maximized) 01142 m_pSystemMenu->insertItem(i18n("M&ove"),m_pCaption, SLOT(slot_moveViaSystemMenu())); 01143 if( state() == Normal) 01144 m_pSystemMenu->insertItem(i18n("&Resize"),this, SLOT(slot_resizeViaSystemMenu())); 01145 } 01146 01147 m_pSystemMenu->insertItem(i18n("&Undock"),this, SLOT(undockPressed())); 01148 m_pSystemMenu->insertSeparator(); 01149 m_pSystemMenu->insertItem(i18n("&Close"),this, SLOT(closePressed())); 01150 01151 return m_pSystemMenu; 01152 } 01153 01155 void KMdiChildFrm::showSystemMenu() 01156 { 01157 if (KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::Win95Look) { 01158 m_pUnixIcon->setDown( false); 01159 } 01160 QPoint popupmenuPosition; 01161 //qDebug("%d,%d,%d,%d,%d",m_pIcon->pos().x(),x(),m_pIcon->pos().y(),m_pIcon->height(),y()); 01162 QRect iconGeom; 01163 if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::Win95Look) 01164 iconGeom = m_pWinIcon->geometry(); 01165 else 01166 iconGeom = m_pUnixIcon->geometry(); 01167 popupmenuPosition = QPoint( iconGeom.x(), 01168 iconGeom.y() + captionHeight() + KMDI_CHILDFRM_BORDER ); 01169 systemMenu()->popup( mapToGlobal( popupmenuPosition)); 01170 } 01171 01172 void KMdiChildFrm::switchToMinimizeLayout() 01173 { 01174 setMinimumWidth(KMDI_CHILDFRM_MIN_WIDTH); 01175 setFixedHeight(m_pCaption->height()+KMDI_CHILDFRM_DOUBLE_BORDER); 01176 01177 m_pMaximize->setPixmap( *m_pMaxButtonPixmap); 01178 01179 // temporary use of minimize button for restore function 01180 m_pMinimize->setPixmap( *m_pRestoreButtonPixmap); 01181 QObject::disconnect(m_pMinimize,SIGNAL(clicked()),this,SLOT(minimizePressed())); 01182 QObject::connect(m_pMinimize,SIGNAL(clicked()),this,SLOT(restorePressed())); 01183 01184 // resizing 01185 resize( 300, minimumHeight()); 01186 01187 // positioning 01188 m_pManager->layoutMinimizedChildren(); 01189 } 01190 01191 void KMdiChildFrm::slot_resizeViaSystemMenu() 01192 { 01193 grabMouse(); 01194 m_bResizing = true; 01195 m_iResizeCorner = KMDI_RESIZE_BOTTOMLEFT; 01196 setResizeCursor( m_iResizeCorner); 01197 } 01198 01199 void KMdiChildFrm::redecorateButtons() 01200 { 01201 if (m_pMinButtonPixmap) 01202 delete m_pMinButtonPixmap; 01203 if (m_pMaxButtonPixmap) 01204 delete m_pMaxButtonPixmap; 01205 if (m_pRestoreButtonPixmap) 01206 delete m_pRestoreButtonPixmap; 01207 if (m_pCloseButtonPixmap) 01208 delete m_pCloseButtonPixmap; 01209 if (m_pUndockButtonPixmap) 01210 delete m_pUndockButtonPixmap; 01211 01212 if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::Win95Look) { 01213 m_pMinButtonPixmap = new QPixmap( win_minbutton); 01214 m_pMaxButtonPixmap = new QPixmap( win_maxbutton); 01215 m_pRestoreButtonPixmap = new QPixmap( win_restorebutton); 01216 m_pCloseButtonPixmap = new QPixmap( win_closebutton); 01217 m_pUndockButtonPixmap = new QPixmap( win_undockbutton); 01218 } 01219 else if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDE1Look) { 01220 m_pMinButtonPixmap = new QPixmap( kde_minbutton); 01221 m_pMaxButtonPixmap = new QPixmap( kde_maxbutton); 01222 m_pRestoreButtonPixmap = new QPixmap( kde_restorebutton); 01223 m_pCloseButtonPixmap = new QPixmap( kde_closebutton); 01224 m_pUndockButtonPixmap = new QPixmap( kde_undockbutton); 01225 } 01226 else if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDELook) { 01227 m_pMinButtonPixmap = new QPixmap( kde2_minbutton); 01228 m_pMaxButtonPixmap = new QPixmap( kde2_maxbutton); 01229 m_pRestoreButtonPixmap = new QPixmap( kde2_restorebutton); 01230 m_pCloseButtonPixmap = new QPixmap( kde2_closebutton); 01231 m_pUndockButtonPixmap = new QPixmap( kde2_undockbutton); 01232 } 01233 else { // kde2laptop look 01234 m_pMinButtonPixmap = new QPixmap( kde2laptop_minbutton); 01235 m_pMaxButtonPixmap = new QPixmap( kde2laptop_maxbutton); 01236 m_pRestoreButtonPixmap = new QPixmap( kde2laptop_restorebutton); 01237 m_pCloseButtonPixmap = new QPixmap( kde2laptop_closebutton); 01238 m_pUndockButtonPixmap = new QPixmap( kde2laptop_undockbutton); 01239 } 01240 01241 m_pUnixIcon->setAutoRaise(true); 01242 if (KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDE1Look) { 01243 m_pMinimize->setAutoRaise(true); 01244 m_pMaximize->setAutoRaise(true); 01245 m_pClose->setAutoRaise(true); 01246 m_pUndock->setAutoRaise(true); 01247 } 01248 else { 01249 m_pMinimize->setAutoRaise(false); 01250 m_pMaximize->setAutoRaise(false); 01251 m_pClose->setAutoRaise(false); 01252 m_pUndock->setAutoRaise(false); 01253 } 01254 01255 if (m_pClient && m_pClient->icon()) { 01256 m_pWinIcon->setPixmap( *(m_pClient)->icon()); 01257 m_pUnixIcon->setPixmap( *(m_pClient)->icon()); 01258 } 01259 else { 01260 m_pWinIcon->setPixmap( *m_pIconButtonPixmap); 01261 m_pUnixIcon->setPixmap( *m_pIconButtonPixmap); 01262 } 01263 m_pClose->setPixmap( *m_pCloseButtonPixmap); 01264 m_pMinimize->setPixmap( *m_pMinButtonPixmap); 01265 m_pMaximize->setPixmap( *m_pMaxButtonPixmap); 01266 m_pUndock->setPixmap( *m_pUndockButtonPixmap); 01267 } 01268 01269 QRect KMdiChildFrm::mdiAreaContentsRect() const 01270 { 01271 QFrame* p = (QFrame*)parentWidget(); 01272 if (p) { 01273 return p->contentsRect(); 01274 } 01275 else { 01276 QRect empty; 01277 return empty; 01278 } 01279 } 01280 01281 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kmdi Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:33:17 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003