⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ktmainwindow.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* This file is part of the KDE libraries    Copyright  (C) 1997 Stephan Kulow (coolo@kde.org)               (C) 1997 Sven Radej (sven.radej@iname.com)               (C) 1997 Matthias Ettrich (ettrich@kde.org)    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Library General Public    License as published by the Free Software Foundation; either    version 2 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Library General Public License for more details.    You should have received a copy of the GNU Library General Public License    along with this library; see the file COPYING.LIB.  If not, write to    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,    Boston, MA 02111-1307, USA.*/#include <ktmainwindow.h>#include <ktmainwindow.h>#include <kapp.h>#include <kdebug.h>#include <kconfig.h>#include <qstrlist.h>#include <kwm.h>//#include <qobjcoll.h>// a static pointer (too bad we cannot have static objects in libraries)QList<KTMainWindow>* KTMainWindow::memberList = 0L;KTMainWindow::KTMainWindow( const char *name )    : QWidget( 0L, name ){    kmenubar = 0L;    kmainwidget = 0L;    kstatusbar = 0L;    borderwidth = 0;    // set the specified icons    KWM::setIcon(winId(), kapp->getIcon());    KWM::setMiniIcon(winId(), kapp->getMiniIcon());    // set a short icon text    XSetIconName( qt_xdisplay(), winId(), kapp->getCaption() );    kmainwidgetframe = new QFrame( this );    CHECK_PTR( kmainwidgetframe );    kmainwidgetframe ->setFrameStyle( QFrame::Panel | QFrame::Sunken);    kmainwidgetframe ->setLineWidth(0);    kmainwidgetframe ->hide();    // If the application does not yet have a top widget, make it this one    // Enable session management (Matthias)    setUnsavedData(False);    if( !kapp->topWidget() ){      kapp->setTopWidget( this );      kapp->enableSessionManagement();      connect(kapp, SIGNAL(saveYourself()), SLOT(saveYourself()));    }    // see if there already is a member list    if( !memberList )      memberList = new QList<KTMainWindow>;    // enter the widget in the list of all KTWs    memberList->append( this );    // finally set the caption    setCaption(kapp->getCaption());    localKill = false;}KTMainWindow::~KTMainWindow(){  localKill = true;  // remove this widget from the member list  memberList->remove( this );  // delete all toolbars (necessary if they are floating)  KToolBar *toolbar = 0;  for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next() ) {    if (toolbar->barPos() == KToolBar::Floating        && !QApplication::closingDown())    {      delete toolbar;      //debug ("KTM destructor: deleted toolbar");    }  }  // delete the menubar (necessary if floating)  if (kmenubar && kmenubar->menuBarPos() == KMenuBar::Floating      && !QApplication::closingDown())  {    delete kmenubar;    //debug ("KTM destructor: deleted menubar");  }  // if this was the topWidget, find a new one to be it  if( kapp && kapp->topWidget() == this ){    KTMainWindow* pTemp = 0;    if( ( pTemp = memberList->getFirst() ) )	kapp->setTopWidget( pTemp );    else	kapp->setTopWidget( 0 );  }  //debug ("KTM destructor: end");}void KTMainWindow::deleteAll(){  KTMainWindow* w;  if (memberList){    for (w = memberList->first(); w; w = memberList->next()){      delete w;    }    memberList->clear();  }}void KTMainWindow::closeEvent ( QCloseEvent *e){  if (queryClose())  {    e->accept();    if (memberList->count() == 1) // last window close accepted?    {      if (queryExit())            // Yes, Quit app?      {        delete this;              // Yes, delete this...        kapp->quit();             // ...and quit aplication.      }                           //--------------------------------    }    else                         // It was not last window...      delete this;               // ...so only delete this. (sven)  }}bool KTMainWindow::queryClose(){  return true;}bool KTMainWindow::queryExit(){  return true;}int KTMainWindow::addToolBar( KToolBar *toolbar, int index ){  if ( index == -1 )    toolbars.append( toolbar );  else    toolbars.insert( index, toolbar );  index = toolbars.at();  connect ( toolbar, SIGNAL( moved (BarPosition) ),            this, SLOT( updateRects() ) );  connect (toolbar, SIGNAL(destroyed ()), this, SLOT(toolbarKilled ()));  updateRects();  return index;}void KTMainWindow::setView( QWidget *view, bool show_frame ){  kmainwidget = view;  if( show_frame ){    // Set a default frame borderwidth, for a toplevelwidget with    // frame.    if(borderwidth == 0 )      setFrameBorderWidth(0);    kmainwidgetframe->show();  }  // In the case setView(...,TRUE),  // we leave the default frame borderwith at 0 so that we don't get  // an unwanted border -- after all we didn't request a frame. If you  // still want a border ( though no frame, call setFrameBorderWidth()  // before setView(...,FALSE).}void KTMainWindow::focusInEvent( QFocusEvent *){  repaint( FALSE );}void KTMainWindow::focusOutEvent( QFocusEvent *){  repaint( FALSE );}void KTMainWindow::show (){    if (kmenubar && kmenubar->menuBarPos() == KMenuBar::Floating)	kmenubar->show();    QWidget::show();    updateRects();}void KTMainWindow::updateRects(){  // This thing is first against the wall as  // soon as I have some free time.  //debug ("Update");  int t=0, b=0, l=0, r=0;  int to=-1, bo=-1, lo=-1, ro=-1;  int h, w;  int freeHeight, freeWidth;  int widest; // To find widest toolbar  bool fixedY = FALSE;  int flatX=0;  int flatY=0;  int FlatHeight=0;#define vSpace 2  if (kmainwidget && kmainwidget->minimumSize().height() ==      kmainwidget->maximumSize().height())    fixedY = TRUE;  if (kmainwidget && kmainwidget->minimumSize() ==      kmainwidget->maximumSize())    {      KToolBar *toolbar;      w = kmainwidget->width()+2*borderwidth;      h = kmainwidget->height()+2*borderwidth;      // left toolbars first      widest = 0;      for (toolbar=toolbars.first(); toolbar != 0L; toolbar=toolbars.next())	if ( toolbar->barPos() == KToolBar::Left && toolbar->isVisible() )	  {	    toolbar->setMaxHeight(h);   // Sven: You have to do this here	    toolbar->updateRects (TRUE);        // Sven: You have to this	    if ( lo < 0 )	      {		lo = 0;		l += toolbar->width();	      }	    if ( lo + toolbar->height() > h)	      {		lo = 0;		l += toolbar->width();	      }	    toolbar->move( l-toolbar->width(), t  + lo );	    lo += toolbar->height();	  }      w+=l; //AAAARRRGGGHHH!!!      // Now right (I'm ok now)      for ( toolbar = toolbars.first();	    toolbar != 0L; toolbar = toolbars.next() )	if ( toolbar->barPos() == KToolBar::Right && toolbar->isVisible() )	  {	    toolbar->setMaxHeight(h);   // Sven: You have to do this here	    toolbar->updateRects (TRUE);   // Sven: You have to this	    if ( ro < 0 )	      {		ro = 0;		r += toolbar->width();	      }	    if (ro + toolbar->height() > h)	      {		ro = 0;		r += toolbar->width();	      }	    toolbar->move(w+r-toolbar->width(), t + ro);	    ro += toolbar->height();	  }      w+=r;      // Now kmenubar and top toolbars      // No, first I'll have a beer.      // Aaah, kold beer.. my nerves ar circulating better now...      if (kmenubar && kmenubar->isVisible())   // (gulp)	if (kmenubar->menuBarPos() == KMenuBar::Top)      // !? This beer isn't cold!        {          int mh = kmenubar->heightForWidth(w);          kmenubar->setGeometry(0, 0, w, mh);          t += mh;          flatY=t;          flatX=0;        }        else if (kmenubar->menuBarPos() == KMenuBar::Flat) //flat menubar        {          kmenubar->move(0, 0);          FlatHeight=kmenubar->height();          flatX += kmenubar->width() + vSpace;          flatY=0;        }      //flat toolbars      for (toolbar=toolbars.first(); toolbar != 0L; toolbar=toolbars.next())        if (toolbar->barPos() == KToolBar::Flat && toolbar->isVisible() )        {          toolbar->move(flatX, flatY);          flatX+=toolbar->width()+vSpace;          FlatHeight=toolbar->height();        }      if (FlatHeight)        t+=FlatHeight;      // Top toolbars      for ( toolbar = toolbars.first() ;	    toolbar != 0L ; toolbar = toolbars.next() )	if ( toolbar->barPos() == KToolBar::Top && toolbar->isVisible() )	  {	    toolbar->setMaxWidth(w);	    toolbar->updateRects (TRUE);     // Sven: You have to do this	    if ( to < 0 )	      {		to = 0;		t += toolbar->height();	      }	    if (to + toolbar->width() > w)	      {		to = 0;		t += toolbar->height();	      }	    toolbar->move( to, t-toolbar->height() );	    to += toolbar->width();	  }      h+=t;      // move vertical toolbar for t down.      for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next())	if (toolbar->isVisible())	  if (toolbar->barPos() == KToolBar::Left ||	      toolbar->barPos() == KToolBar::Right)	    toolbar->move(toolbar->x(), t);      // Bottom toolbars      for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next())	if ( toolbar->barPos() == KToolBar::Bottom && toolbar->isVisible() )	  {	    toolbar->setMaxWidth(w);	    toolbar->updateRects (TRUE);   // Sven: You have to this	    if ( bo < 0 )	      {		bo = 0;		b += toolbar->height();	      }	    if (bo + toolbar->width() > w)	      {		bo = 0;		b += toolbar->height();	      }	    toolbar->move(bo, h+b-toolbar->height());	    bo += toolbar->width();	  }      // Statusbar      if ( kstatusbar && kstatusbar->isVisible() )        {	  kstatusbar->setGeometry(0, h+b, w, kstatusbar->height());	  b += kstatusbar->height();        }      // Bottom menubar      if (kmenubar && kmenubar->isVisible())	if (kmenubar->menuBarPos() == KMenuBar::Bottom)	  {	    int mh = kmenubar->heightForWidth(w);	    kmenubar->setGeometry(0, h+b, w, mh);	    b+=mh;	  }      h+=b;      // Move everything      if (kmainwidgetframe)	kmainwidgetframe->move(l, t);      if (kmainwidget)	kmainwidget->move(l+borderwidth, t+borderwidth);      // Set geometry      setFixedSize(w, h);      resize(w,h);      view_left = l;      view_right = width()-r;      view_top = t;      view_bottom = height()-b;      return;    }  else // resizable and y-fixed widgets    {      KToolBar *toolbar;      if (fixedY)        h=kmainwidget->height()+2*borderwidth;      else        h = height();      w = width();      // menubar if on top      if (kmenubar && kmenubar->isVisible())        if (kmenubar->menuBarPos() == KMenuBar::Top)        {          int mh = kmenubar->heightForWidth(w);          kmenubar->setGeometry(0, 0, w, mh);          t = mh;          flatY=t;          flatX=0;        }        else if (kmenubar->menuBarPos() == KMenuBar::Flat) //flat menubar        {          kmenubar->move(0, 0);          FlatHeight=kmenubar->height();          flatX = kmenubar->width() + vSpace;          flatY=0;        }      //flat toolbars      for (toolbar=toolbars.first(); toolbar != 0L; toolbar=toolbars.next())        if (toolbar->barPos() == KToolBar::Flat && toolbar->isVisible() )        {          toolbar->move(flatX, flatY);          flatX+=toolbar->width()+vSpace;          FlatHeight=toolbar->height();        }      if (FlatHeight)        t+=FlatHeight;      // top toolbars      for (toolbar = toolbars.first(); toolbar != 0L ; toolbar = toolbars.next())        if ( toolbar->barPos() == KToolBar::Top && toolbar->isVisible() )        {          toolbar->updateRects (TRUE);     // Sven: You have to do this          if ( to < 0 )          {            to = 0;            t += toolbar->height();	      }          if (to + toolbar->width() > width())          {            to = 0;            t += toolbar->height();          }          toolbar->move( to, t-toolbar->height() );          to += toolbar->width();        }      if (fixedY == TRUE)      {        // Bottom toolbars        for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next())          if ( toolbar->barPos() == KToolBar::Bottom && toolbar->isVisible() )          {            toolbar->updateRects (TRUE);   // Sven: You have to this            if ( bo < 0 )            {              bo = 0;              b += toolbar->height();            }            if (bo + toolbar->width() > w)            {              bo = 0;              b += toolbar->height();            }            toolbar->move(bo, h+b+t-toolbar->height());            bo += toolbar->width();          }        // Statusbar        if ( kstatusbar && kstatusbar->isVisible() )        {          b += kstatusbar->height();          kstatusbar->setGeometry(0, h+b+t-kstatusbar->height(), w, kstatusbar->height());        }        // menubar if on bottom        if (kmenubar && kmenubar->isVisible())          if (kmenubar->menuBarPos() == KMenuBar::Bottom)          {            b+=kmenubar->height();            kmenubar->setGeometry(0, h+b+t-kmenubar->height(), w, kmenubar->height());          }        freeHeight = h;      }      else      {        // menubar if on bottom        if (kmenubar && kmenubar->isVisible())          if (kmenubar->menuBarPos() == KMenuBar::Bottom)          {            b+=kmenubar->height();            kmenubar->setGeometry(0, h-b, w, kmenubar->height());          }        // statusbar        if ( kstatusbar && kstatusbar->isVisible() )        {          b += kstatusbar->height();          kstatusbar->setGeometry(0, h-b, w, kstatusbar->height());        }        // Bottom toolbars        for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next())          if ( toolbar->barPos() == KToolBar::Bottom && toolbar->isVisible() )          {            toolbar->updateRects (TRUE);   // Sven: You have to this            if ( bo < 0 )            {              bo = 0;              b += toolbar->height();            }            if (bo + toolbar->width() > w)            {              bo = 0;              b += toolbar->height();            }            toolbar->move(bo, h-b);            bo += toolbar->width();          }        freeHeight = h-b-t;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -