• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kate

katemdi.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
00004 
00005    GUIClient partly based on ktoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "katemdi.h"
00024 #include "katemdi.moc"
00025 
00026 #include <kaction.h>
00027 #include <kdebug.h>
00028 #include <kglobal.h>
00029 #include <kglobalsettings.h>
00030 #include <kapplication.h>
00031 #include <klocale.h>
00032 #include <kconfig.h>
00033 #include <kiconloader.h>
00034 #include <kpopupmenu.h>
00035 #include <kmessagebox.h>
00036 
00037 #include <qvbox.h>
00038 #include <qhbox.h>
00039 #include <qevent.h>
00040 
00041 namespace KateMDI {
00042 
00043 //BEGIN SPLITTER
00044 
00045 Splitter::Splitter(Orientation o, QWidget* parent, const char* name)
00046   : QSplitter(o, parent, name)
00047 {
00048 }
00049 
00050 Splitter::~Splitter()
00051 {
00052 }
00053 
00054 bool Splitter::isLastChild(QWidget* w) const
00055 {
00056   return ( idAfter( w ) == 0 );
00057 }
00058 
00059 int Splitter::idAfter ( QWidget * w ) const
00060 {
00061   return QSplitter::idAfter (w);
00062 }
00063 
00064 //END SPLITTER
00065 
00066 
00067 //BEGIN TOGGLETOOLVIEWACTION
00068 
00069 ToggleToolViewAction::ToggleToolViewAction ( const QString& text, const KShortcut& cut, ToolView *tv,
00070                                              QObject* parent, const char* name )
00071  : KToggleAction(text,cut,parent,name)
00072  , m_tv(tv)
00073 {
00074   connect(this,SIGNAL(toggled(bool)),this,SLOT(slotToggled(bool)));
00075   connect(m_tv,SIGNAL(visibleChanged(bool)),this,SLOT(visibleChanged(bool)));
00076 
00077   setChecked(m_tv->visible());
00078 }
00079 
00080 ToggleToolViewAction::~ToggleToolViewAction()
00081 {
00082   unplugAll();
00083 }
00084 
00085 void ToggleToolViewAction::visibleChanged(bool)
00086 {
00087   if (isChecked() != m_tv->visible())
00088     setChecked (m_tv->visible());
00089 }
00090 
00091 void ToggleToolViewAction::slotToggled(bool t)
00092 {
00093   if (t)
00094   {
00095     m_tv->mainWindow()->showToolView (m_tv);
00096     m_tv->setFocus ();
00097   }
00098   else
00099   {
00100     m_tv->mainWindow()->hideToolView (m_tv);
00101     m_tv->mainWindow()->centralWidget()->setFocus ();
00102   }
00103 }
00104 
00105 //END TOGGLETOOLVIEWACTION
00106 
00107 
00108 //BEGIN GUICLIENT
00109 
00110 static const char *actionListName = "kate_mdi_window_actions";
00111 
00112 static const char *guiDescription = ""
00113         "<!DOCTYPE kpartgui><kpartgui name=\"kate_mdi_window_actions\">"
00114         "<MenuBar>"
00115         "    <Menu name=\"window\">"
00116         "        <ActionList name=\"%1\" />"
00117         "    </Menu>"
00118         "</MenuBar>"
00119         "</kpartgui>";
00120 
00121 GUIClient::GUIClient ( MainWindow *mw )
00122  : QObject ( mw )
00123  , KXMLGUIClient ( mw )
00124  , m_mw (mw)
00125 {
00126   connect( m_mw->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ),
00127            this, SLOT( clientAdded( KXMLGUIClient * ) ) );
00128 
00129   if ( domDocument().documentElement().isNull() )
00130   {
00131     QString completeDescription = QString::fromLatin1( guiDescription )
00132           .arg( actionListName );
00133 
00134     setXML( completeDescription, false /*merge*/ );
00135   }
00136 
00137   if (actionCollection()->kaccel()==0)
00138     actionCollection()->setWidget(m_mw);
00139 
00140   m_toolMenu = new KActionMenu(i18n("Tool &Views"),actionCollection(),"kate_mdi_toolview_menu");
00141   m_showSidebarsAction = new KToggleAction( i18n("Show Side&bars"),
00142                                             CTRL|ALT|SHIFT|Key_F, actionCollection(), "kate_mdi_sidebar_visibility" );
00143   m_showSidebarsAction->setCheckedState(i18n("Hide Side&bars"));
00144   m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
00145   connect( m_showSidebarsAction, SIGNAL( toggled( bool ) ),
00146            m_mw, SLOT( setSidebarsVisible( bool ) ) );
00147 
00148   m_toolMenu->insert( m_showSidebarsAction );
00149   m_toolMenu->insert( new KActionSeparator( m_toolMenu ) );
00150 
00151   // read shortcuts
00152   actionCollection()->readShortcutSettings( "Shortcuts", kapp->config() );
00153 }
00154 
00155 GUIClient::~GUIClient()
00156 {
00157 }
00158 
00159 void GUIClient::updateSidebarsVisibleAction()
00160 {
00161   m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
00162 }
00163 
00164 void GUIClient::registerToolView (ToolView *tv)
00165 {
00166   QString aname = QString("kate_mdi_toolview_") + tv->id;
00167 
00168   // try to read the action shortcut
00169   KShortcut sc;
00170   KConfig *cfg = kapp->config();
00171   QString _grp = cfg->group();
00172   cfg->setGroup("Shortcuts");
00173   sc = KShortcut( cfg->readEntry( aname, "" ) );
00174   cfg->setGroup( _grp );
00175 
00176   KToggleAction *a = new ToggleToolViewAction(i18n("Show %1").arg(tv->text),
00177     sc,tv, actionCollection(), aname.latin1() );
00178 
00179   a->setCheckedState(i18n("Hide %1").arg(tv->text));
00180 
00181   m_toolViewActions.append(a);
00182   m_toolMenu->insert(a);
00183 
00184   m_toolToAction.insert (tv, a);
00185 
00186   updateActions();
00187 }
00188 
00189 void GUIClient::unregisterToolView (ToolView *tv)
00190 {
00191   KAction *a = m_toolToAction[tv];
00192 
00193   if (!a)
00194     return;
00195 
00196   m_toolViewActions.remove(a);
00197   delete a;
00198 
00199   m_toolToAction.remove (tv);
00200 
00201   updateActions();
00202 }
00203 
00204 void GUIClient::clientAdded( KXMLGUIClient *client )
00205 {
00206   if ( client == this )
00207     updateActions();
00208 }
00209 
00210 void GUIClient::updateActions()
00211 {
00212   if ( !factory() )
00213     return;
00214 
00215   unplugActionList( actionListName );
00216 
00217   QPtrList<KAction> addList;
00218   addList.append(m_toolMenu);
00219 
00220   plugActionList( actionListName, addList );
00221 }
00222 
00223 //END GUICLIENT
00224 
00225 
00226 //BEGIN TOOLVIEW
00227 
00228 ToolView::ToolView (MainWindow *mainwin, Sidebar *sidebar, QWidget *parent)
00229  : QVBox (parent)
00230  , m_mainWin (mainwin)
00231  , m_sidebar (sidebar)
00232  , m_visible (false)
00233  , persistent (false)
00234 {
00235 }
00236 
00237 ToolView::~ToolView ()
00238 {
00239   m_mainWin->toolViewDeleted (this);
00240 }
00241 
00242 void ToolView::setVisible (bool vis)
00243 {
00244   if (m_visible == vis)
00245     return;
00246 
00247   m_visible = vis;
00248   emit visibleChanged (m_visible);
00249 }
00250 
00251 bool ToolView::visible () const
00252 {
00253   return m_visible;
00254 }
00255 
00256 void ToolView::childEvent ( QChildEvent *ev )
00257 {
00258   // set the widget to be focus proxy if possible
00259   if (ev->inserted() && ev->child() && ev->child()->qt_cast("QWidget"))
00260     setFocusProxy ((QWidget *)(ev->child()->qt_cast("QWidget")));
00261 
00262   QVBox::childEvent (ev);
00263 }
00264 
00265 //END TOOLVIEW
00266 
00267 
00268 //BEGIN SIDEBAR
00269 
00270 Sidebar::Sidebar (KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, QWidget *parent)
00271   : KMultiTabBar ((pos == KMultiTabBar::Top || pos == KMultiTabBar::Bottom) ? KMultiTabBar::Horizontal : KMultiTabBar::Vertical, parent)
00272   , m_mainWin (mainwin)
00273   , m_splitter (0)
00274   , m_ownSplit (0)
00275   , m_lastSize (0)
00276 {
00277   setPosition( pos );
00278   hide ();
00279 }
00280 
00281 Sidebar::~Sidebar ()
00282 {
00283 }
00284 
00285 void Sidebar::setSplitter (Splitter *sp)
00286 {
00287   m_splitter = sp;
00288   m_ownSplit = new Splitter ((position() == KMultiTabBar::Top || position() == KMultiTabBar::Bottom) ? Qt::Horizontal : Qt::Vertical, m_splitter);
00289   m_ownSplit->setOpaqueResize( KGlobalSettings::opaqueResize() );
00290   m_ownSplit->setChildrenCollapsible( false );
00291   m_splitter->setResizeMode( m_ownSplit, QSplitter::KeepSize );
00292   m_ownSplit->hide ();
00293 }
00294 
00295 ToolView *Sidebar::addWidget (const QPixmap &icon, const QString &text, ToolView *widget)
00296 {
00297   static int id = 0;
00298 
00299   if (widget)
00300   {
00301     if (widget->sidebar() == this)
00302       return widget;
00303 
00304     widget->sidebar()->removeWidget (widget);
00305   }
00306 
00307   int newId = ++id;
00308 
00309   appendTab (icon, newId, text);
00310 
00311   if (!widget)
00312   {
00313     widget = new ToolView (m_mainWin, this, m_ownSplit);
00314     widget->hide ();
00315     widget->icon = icon;
00316     widget->text = text;
00317   }
00318   else
00319   {
00320     widget->hide ();
00321     widget->reparent (m_ownSplit, 0, QPoint());
00322     widget->m_sidebar = this;
00323   }
00324 
00325   // save it's pos ;)
00326   widget->persistent = false;
00327 
00328   m_idToWidget.insert (newId, widget);
00329   m_widgetToId.insert (widget, newId);
00330   m_toolviews.push_back (widget);
00331 
00332   show ();
00333 
00334   connect(tab(newId),SIGNAL(clicked(int)),this,SLOT(tabClicked(int)));
00335   tab(newId)->installEventFilter(this);
00336 
00337   return widget;
00338 }
00339 
00340 bool Sidebar::removeWidget (ToolView *widget)
00341 {
00342   if (!m_widgetToId.contains(widget))
00343     return false;
00344 
00345   removeTab(m_widgetToId[widget]);
00346 
00347   m_idToWidget.remove (m_widgetToId[widget]);
00348   m_widgetToId.remove (widget);
00349   m_toolviews.remove (widget);
00350 
00351   bool anyVis = false;
00352   QIntDictIterator<ToolView> it( m_idToWidget );
00353   for ( ; it.current(); ++it )
00354   {
00355     if (!anyVis)
00356       anyVis =  it.current()->isVisible();
00357   }
00358 
00359   if (m_idToWidget.isEmpty())
00360   {
00361     m_ownSplit->hide ();
00362     hide ();
00363   }
00364   else if (!anyVis)
00365     m_ownSplit->hide ();
00366 
00367   return true;
00368 }
00369 
00370 bool Sidebar::showWidget (ToolView *widget)
00371 {
00372   if (!m_widgetToId.contains(widget))
00373     return false;
00374 
00375   // hide other non-persistent views
00376   QIntDictIterator<ToolView> it( m_idToWidget );
00377   for ( ; it.current(); ++it )
00378     if ((it.current() != widget) && !it.current()->persistent)
00379     {
00380       it.current()->hide();
00381       setTab (it.currentKey(), false);
00382       it.current()->setVisible(false);
00383     }
00384 
00385   setTab (m_widgetToId[widget], true);
00386 
00387   m_ownSplit->show ();
00388   widget->show ();
00389 
00390   widget->setVisible (true);
00391 
00392   return true;
00393 }
00394 
00395 bool Sidebar::hideWidget (ToolView *widget)
00396 {
00397   if (!m_widgetToId.contains(widget))
00398     return false;
00399 
00400   bool anyVis = false;
00401 
00402    updateLastSize ();
00403 
00404   for ( QIntDictIterator<ToolView> it( m_idToWidget ); it.current(); ++it )
00405   {
00406     if (it.current() == widget)
00407     {
00408       it.current()->hide();
00409       continue;
00410     }
00411 
00412     if (!anyVis)
00413       anyVis =  it.current()->isVisible();
00414   }
00415 
00416   // lower tab
00417   setTab (m_widgetToId[widget], false);
00418 
00419   if (!anyVis)
00420     m_ownSplit->hide ();
00421 
00422   widget->setVisible (false);
00423 
00424   return true;
00425 }
00426 
00427 void Sidebar::tabClicked(int i)
00428 {
00429   ToolView *w = m_idToWidget[i];
00430 
00431   if (!w)
00432     return;
00433 
00434   if (isTabRaised(i))
00435   {
00436     showWidget (w);
00437     w->setFocus ();
00438   }
00439   else
00440   {
00441     hideWidget (w);
00442     m_mainWin->centralWidget()->setFocus ();
00443   }
00444 }
00445 
00446 bool Sidebar::eventFilter(QObject *obj, QEvent *ev)
00447 {
00448   if (ev->type()==QEvent::ContextMenu)
00449   {
00450     QContextMenuEvent *e = (QContextMenuEvent *) ev;
00451     KMultiTabBarTab *bt = dynamic_cast<KMultiTabBarTab*>(obj);
00452     if (bt)
00453     {
00454       kdDebug()<<"Request for popup"<<endl;
00455 
00456       m_popupButton = bt->id();
00457 
00458       ToolView *w = m_idToWidget[m_popupButton];
00459 
00460       if (w)
00461       {
00462         KPopupMenu *p = new KPopupMenu (this);
00463 
00464         p->insertTitle(SmallIcon("view_remove"), i18n("Behavior"), 50);
00465 
00466         p->insertItem(w->persistent ? SmallIconSet("window_nofullscreen") : SmallIconSet("window_fullscreen"), w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent"), 10);
00467 
00468         p->insertTitle(SmallIcon("move"), i18n("Move To"), 51);
00469 
00470         if (position() != 0)
00471           p->insertItem(SmallIconSet("back"), i18n("Left Sidebar"),0);
00472 
00473         if (position() != 1)
00474           p->insertItem(SmallIconSet("forward"), i18n("Right Sidebar"),1);
00475 
00476         if (position() != 2)
00477           p->insertItem(SmallIconSet("up"), i18n("Top Sidebar"),2);
00478 
00479         if (position() != 3)
00480           p->insertItem(SmallIconSet("down"), i18n("Bottom Sidebar"),3);
00481 
00482         connect(p, SIGNAL(activated(int)),
00483               this, SLOT(buttonPopupActivate(int)));
00484 
00485         p->exec(e->globalPos());
00486         delete p;
00487 
00488         return true;
00489       }
00490     }
00491   }
00492 
00493   return false;
00494 }
00495 
00496 void Sidebar::show()
00497 {
00498   if (m_idToWidget.isEmpty() || !m_mainWin->sidebarsVisible() )
00499     return;
00500 
00501   KMultiTabBar::show(  );
00502 }
00503 
00504 void Sidebar::buttonPopupActivate (int id)
00505 {
00506   ToolView *w = m_idToWidget[m_popupButton];
00507 
00508   if (!w)
00509     return;
00510 
00511   // move ids
00512   if (id < 4)
00513   {
00514     // move + show ;)
00515     m_mainWin->moveToolView (w, (KMultiTabBar::KMultiTabBarPosition) id);
00516     m_mainWin->showToolView (w);
00517   }
00518 
00519   // toggle persistent
00520   if (id == 10)
00521     w->persistent = !w->persistent;
00522 }
00523 
00524 void Sidebar::updateLastSize ()
00525 {
00526    QValueList<int> s = m_splitter->sizes ();
00527 
00528   int i = 0;
00529   if ((position() == KMultiTabBar::Right || position() == KMultiTabBar::Bottom))
00530     i = 2;
00531 
00532   // little threshold
00533   if (s[i] > 2)
00534     m_lastSize = s[i];
00535 }
00536 
00537 class TmpToolViewSorter
00538 {
00539   public:
00540     ToolView *tv;
00541     unsigned int pos;
00542 };
00543 
00544 void Sidebar::restoreSession (KConfig *config)
00545 {
00546   // get the last correct placed toolview
00547   unsigned int firstWrong = 0;
00548   for ( ; firstWrong < m_toolviews.size(); ++firstWrong )
00549   {
00550     ToolView *tv = m_toolviews[firstWrong];
00551 
00552     unsigned int pos = config->readUnsignedNumEntry (QString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), firstWrong);
00553 
00554     if (pos != firstWrong)
00555       break;
00556   }
00557 
00558   // we need to reshuffle, ahhh :(
00559   if (firstWrong < m_toolviews.size())
00560   {
00561     // first: collect the items to reshuffle
00562     QValueList<TmpToolViewSorter> toSort;
00563     for (unsigned int i=firstWrong; i < m_toolviews.size(); ++i)
00564     {
00565       TmpToolViewSorter s;
00566       s.tv = m_toolviews[i];
00567       s.pos = config->readUnsignedNumEntry (QString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(m_toolviews[i]->id), i);
00568       toSort.push_back (s);
00569     }
00570 
00571     // now: sort the stuff we need to reshuffle
00572     for (unsigned int m=0; m < toSort.size(); ++m)
00573       for (unsigned int n=m+1; n < toSort.size(); ++n)
00574         if (toSort[n].pos < toSort[m].pos)
00575         {
00576           TmpToolViewSorter tmp = toSort[n];
00577           toSort[n] = toSort[m];
00578           toSort[m] = tmp;
00579         }
00580 
00581     // then: remove this items from the button bar
00582     // do this backwards, to minimize the relayout efforts
00583     for (int i=m_toolviews.size()-1; i >= (int)firstWrong; --i)
00584     {
00585       removeTab (m_widgetToId[m_toolviews[i]]);
00586     }
00587 
00588     // insert the reshuffled things in order :)
00589     for (unsigned int i=0; i < toSort.size(); ++i)
00590     {
00591       ToolView *tv = toSort[i].tv;
00592 
00593       m_toolviews[firstWrong+i] = tv;
00594 
00595       // readd the button
00596       int newId = m_widgetToId[tv];
00597       appendTab (tv->icon, newId, tv->text);
00598       connect(tab(newId),SIGNAL(clicked(int)),this,SLOT(tabClicked(int)));
00599       tab(newId)->installEventFilter(this);
00600 
00601       // reshuffle in splitter
00602       m_ownSplit->moveToLast (tv);
00603     }
00604   }
00605 
00606   // update last size if needed
00607   updateLastSize ();
00608 
00609   // restore the own splitter sizes
00610   QValueList<int> s = config->readIntListEntry (QString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()));
00611   m_ownSplit->setSizes (s);
00612 
00613   // show only correct toolviews, remember persistent values ;)
00614   bool anyVis = false;
00615   for ( unsigned int i=0; i < m_toolviews.size(); ++i )
00616   {
00617     ToolView *tv = m_toolviews[i];
00618 
00619     tv->persistent = config->readBoolEntry (QString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), false);
00620     tv->setVisible (config->readBoolEntry (QString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), false));
00621 
00622     if (!anyVis)
00623       anyVis = tv->visible();
00624 
00625     setTab (m_widgetToId[tv],tv->visible());
00626 
00627     if (tv->visible())
00628       tv->show();
00629     else
00630       tv->hide ();
00631   }
00632 
00633   if (anyVis)
00634     m_ownSplit->show();
00635   else
00636     m_ownSplit->hide();
00637 }
00638 
00639 void Sidebar::saveSession (KConfig *config)
00640 {
00641   // store the own splitter sizes
00642   QValueList<int> s = m_ownSplit->sizes();
00643   config->writeEntry (QString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()), s);
00644 
00645   // store the data about all toolviews in this sidebar ;)
00646   for ( unsigned int i=0; i < m_toolviews.size(); ++i )
00647   {
00648     ToolView *tv = m_toolviews[i];
00649 
00650     config->writeEntry (QString ("Kate-MDI-ToolView-%1-Position").arg(tv->id), tv->sidebar()->position());
00651     config->writeEntry (QString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), i);
00652     config->writeEntry (QString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), tv->visible());
00653     config->writeEntry (QString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), tv->persistent);
00654   }
00655 }
00656 
00657 //END SIDEBAR
00658 
00659 
00660 //BEGIN MAIN WINDOW
00661 
00662 MainWindow::MainWindow (QWidget* parentWidget, const char* name)
00663  : KParts::MainWindow( parentWidget, name)
00664  , m_sidebarsVisible(true)
00665  , m_restoreConfig (0)
00666  , m_guiClient (new GUIClient (this))
00667 {
00668   // init the internal widgets
00669   QHBox *hb = new QHBox (this);
00670   setCentralWidget(hb);
00671 
00672   m_sidebars[KMultiTabBar::Left] = new Sidebar (KMultiTabBar::Left, this, hb);
00673 
00674   m_hSplitter = new Splitter (Qt::Horizontal, hb);
00675   m_hSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() );
00676 
00677   m_sidebars[KMultiTabBar::Left]->setSplitter (m_hSplitter);
00678 
00679   QVBox *vb = new QVBox (m_hSplitter);
00680   m_hSplitter->setCollapsible(vb, false);
00681 
00682   m_sidebars[KMultiTabBar::Top] = new Sidebar (KMultiTabBar::Top, this, vb);
00683 
00684   m_vSplitter = new Splitter (Qt::Vertical, vb);
00685   m_vSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() );
00686 
00687   m_sidebars[KMultiTabBar::Top]->setSplitter (m_vSplitter);
00688 
00689   m_centralWidget = new QVBox (m_vSplitter);
00690   m_vSplitter->setCollapsible(m_centralWidget, false);
00691 
00692   m_sidebars[KMultiTabBar::Bottom] = new Sidebar (KMultiTabBar::Bottom, this, vb);
00693   m_sidebars[KMultiTabBar::Bottom]->setSplitter (m_vSplitter);
00694 
00695   m_sidebars[KMultiTabBar::Right] = new Sidebar (KMultiTabBar::Right, this, hb);
00696   m_sidebars[KMultiTabBar::Right]->setSplitter (m_hSplitter);
00697 }
00698 
00699 MainWindow::~MainWindow ()
00700 {
00701   // cu toolviews
00702   while (!m_toolviews.isEmpty())
00703     delete m_toolviews[0];
00704 
00705   // seems like we really should delete this by hand ;)
00706   delete m_centralWidget;
00707 
00708   for (unsigned int i=0; i < 4; ++i)
00709     delete m_sidebars[i];
00710 }
00711 
00712 QWidget *MainWindow::centralWidget () const
00713 {
00714   return m_centralWidget;
00715 }
00716 
00717 ToolView *MainWindow::createToolView (const QString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const QPixmap &icon, const QString &text)
00718 {
00719   if (m_idToWidget[identifier])
00720     return 0;
00721 
00722   // try the restore config to figure out real pos
00723   if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
00724   {
00725     m_restoreConfig->setGroup (m_restoreGroup);
00726     pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (QString ("Kate-MDI-ToolView-%1-Position").arg(identifier), pos);
00727   }
00728 
00729   ToolView *v  = m_sidebars[pos]->addWidget (icon, text, 0);
00730   v->id = identifier;
00731 
00732   m_idToWidget.insert (identifier, v);
00733   m_toolviews.push_back (v);
00734 
00735   // register for menu stuff
00736   m_guiClient->registerToolView (v);
00737 
00738   return v;
00739 }
00740 
00741 ToolView *MainWindow::toolView (const QString &identifier) const
00742 {
00743   return m_idToWidget[identifier];
00744 }
00745 
00746 void MainWindow::toolViewDeleted (ToolView *widget)
00747 {
00748   if (!widget)
00749     return;
00750 
00751   if (widget->mainWindow() != this)
00752     return;
00753 
00754   // unregister from menu stuff
00755   m_guiClient->unregisterToolView (widget);
00756 
00757   widget->sidebar()->removeWidget (widget);
00758 
00759   m_idToWidget.remove (widget->id);
00760   m_toolviews.remove (widget);
00761 }
00762 
00763 void MainWindow::setSidebarsVisible( bool visible )
00764 {
00765   m_sidebarsVisible = visible;
00766 
00767   m_sidebars[0]->setShown(visible);
00768   m_sidebars[1]->setShown(visible);
00769   m_sidebars[2]->setShown(visible);
00770   m_sidebars[3]->setShown(visible);
00771 
00772   m_guiClient->updateSidebarsVisibleAction();
00773 
00774   // show information message box, if the users hides the sidebars
00775   if( !m_sidebarsVisible )
00776   {
00777     KMessageBox::information( this,
00778                               i18n("<qt>You are about to hide the sidebars. With "
00779                                    "hidden sidebars it is not possible to directly "
00780                                    "access the tool views with the mouse anymore, "
00781                                    "so if you need to access the sidebars again "
00782                                    "invoke <b>Window &gt; Tool Views &gt; Show Sidebars</b> "
00783                                    "in the menu. It is still possible to show/hide "
00784                                    "the tool views with the assigned shortcuts.</qt>"),
00785                               QString::null, "Kate hide sidebars notification message" );
00786   }
00787 }
00788 
00789 bool MainWindow::sidebarsVisible() const
00790 {
00791   return m_sidebarsVisible;
00792 }
00793 
00794 void MainWindow::setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style)
00795 {
00796   m_sidebars[0]->setStyle(style);
00797   m_sidebars[1]->setStyle(style);
00798   m_sidebars[2]->setStyle(style);
00799   m_sidebars[3]->setStyle(style);
00800 }
00801 
00802 KMultiTabBar::KMultiTabBarStyle MainWindow::toolViewStyle () const
00803 {
00804   // all sidebars have the same style, so just take Top
00805   return m_sidebars[KMultiTabBar::Top]->tabStyle();
00806 }
00807 
00808 bool MainWindow::moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos)
00809 {
00810   if (!widget || widget->mainWindow() != this)
00811     return false;
00812 
00813   // try the restore config to figure out real pos
00814   if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
00815   {
00816     m_restoreConfig->setGroup (m_restoreGroup);
00817     pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (QString ("Kate-MDI-ToolView-%1-Position").arg(widget->id), pos);
00818   }
00819 
00820   m_sidebars[pos]->addWidget (widget->icon, widget->text, widget);
00821 
00822   return true;
00823 }
00824 
00825 bool MainWindow::showToolView (ToolView *widget)
00826 {
00827   if (!widget || widget->mainWindow() != this)
00828     return false;
00829 
00830   // skip this if happens during restoring, or we will just see flicker
00831   if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
00832     return true;
00833 
00834   return widget->sidebar()->showWidget (widget);
00835 }
00836 
00837 bool MainWindow::hideToolView (ToolView *widget)
00838 {
00839   if (!widget || widget->mainWindow() != this)
00840     return false;
00841 
00842   // skip this if happens during restoring, or we will just see flicker
00843   if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
00844     return true;
00845 
00846   return widget->sidebar()->hideWidget (widget);
00847 }
00848 
00849 void MainWindow::startRestore (KConfig *config, const QString &group)
00850 {
00851   // first save this stuff
00852   m_restoreConfig = config;
00853   m_restoreGroup = group;
00854 
00855   if (!m_restoreConfig || !m_restoreConfig->hasGroup (m_restoreGroup))
00856   {
00857     // set sane default sizes
00858     QValueList<int> hs;
00859     hs << 200 << 100 << 200;
00860     QValueList<int> vs;
00861     vs << 150 << 100 << 200;
00862 
00863     m_sidebars[0]->setLastSize (hs[0]);
00864     m_sidebars[1]->setLastSize (hs[2]);
00865     m_sidebars[2]->setLastSize (vs[0]);
00866     m_sidebars[3]->setLastSize (vs[2]);
00867 
00868     m_hSplitter->setSizes(hs);
00869     m_vSplitter->setSizes(vs);
00870     return;
00871   }
00872 
00873   // apply size once, to get sizes ready ;)
00874   m_restoreConfig->setGroup (m_restoreGroup);
00875   restoreWindowSize (m_restoreConfig);
00876 
00877   m_restoreConfig->setGroup (m_restoreGroup);
00878 
00879   // get main splitter sizes ;)
00880   QValueList<int> hs = m_restoreConfig->readIntListEntry ("Kate-MDI-H-Splitter");
00881   QValueList<int> vs = m_restoreConfig->readIntListEntry ("Kate-MDI-V-Splitter");
00882 
00883   m_sidebars[0]->setLastSize (hs[0]);
00884   m_sidebars[1]->setLastSize (hs[2]);
00885   m_sidebars[2]->setLastSize (vs[0]);
00886   m_sidebars[3]->setLastSize (vs[2]);
00887 
00888   m_hSplitter->setSizes(hs);
00889   m_vSplitter->setSizes(vs);
00890 
00891   setToolViewStyle( (KMultiTabBar::KMultiTabBarStyle)m_restoreConfig->readNumEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()) );
00892 
00893   // after reading m_sidebarsVisible, update the GUI toggle action
00894   m_sidebarsVisible = m_restoreConfig->readBoolEntry ("Kate-MDI-Sidebar-Visible", true );
00895   m_guiClient->updateSidebarsVisibleAction();
00896 }
00897 
00898 void MainWindow::finishRestore ()
00899 {
00900   if (!m_restoreConfig)
00901     return;
00902 
00903   if (m_restoreConfig->hasGroup (m_restoreGroup))
00904   {
00905     // apply all settings, like toolbar pos and more ;)
00906     applyMainWindowSettings(m_restoreConfig, m_restoreGroup);
00907 
00908     // reshuffle toolviews only if needed
00909     m_restoreConfig->setGroup (m_restoreGroup);
00910     for ( unsigned int i=0; i < m_toolviews.size(); ++i )
00911     {
00912       KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (QString ("Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->id), m_toolviews[i]->sidebar()->position());
00913 
00914       if (m_toolviews[i]->sidebar()->position() != newPos)
00915       {
00916         moveToolView (m_toolviews[i], newPos);
00917       }
00918     }
00919 
00920     // restore the sidebars
00921     m_restoreConfig->setGroup (m_restoreGroup);
00922     for (unsigned int i=0; i < 4; ++i)
00923       m_sidebars[i]->restoreSession (m_restoreConfig);
00924   }
00925 
00926   // clear this stuff, we are done ;)
00927   m_restoreConfig = 0;
00928   m_restoreGroup = "";
00929 }
00930 
00931 void MainWindow::saveSession (KConfig *config, const QString &group)
00932 {
00933   if (!config)
00934     return;
00935 
00936   saveMainWindowSettings (config, group);
00937 
00938   config->setGroup (group);
00939 
00940   // save main splitter sizes ;)
00941   QValueList<int> hs = m_hSplitter->sizes();
00942   QValueList<int> vs = m_vSplitter->sizes();
00943 
00944   if (hs[0] <= 2 && !m_sidebars[0]->splitterVisible ())
00945     hs[0] = m_sidebars[0]->lastSize();
00946   if (hs[2] <= 2 && !m_sidebars[1]->splitterVisible ())
00947     hs[2] = m_sidebars[1]->lastSize();
00948   if (vs[0] <= 2 && !m_sidebars[2]->splitterVisible ())
00949     vs[0] = m_sidebars[2]->lastSize();
00950   if (vs[2] <= 2 && !m_sidebars[3]->splitterVisible ())
00951     vs[2] = m_sidebars[3]->lastSize();
00952 
00953   config->writeEntry ("Kate-MDI-H-Splitter", hs);
00954   config->writeEntry ("Kate-MDI-V-Splitter", vs);
00955 
00956   // save sidebar style
00957   config->writeEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle());
00958   config->writeEntry ("Kate-MDI-Sidebar-Visible", m_sidebarsVisible );
00959 
00960   // save the sidebars
00961   for (unsigned int i=0; i < 4; ++i)
00962     m_sidebars[i]->saveSession (config);
00963 }
00964 
00965 //END MAIN WINDOW
00966 
00967 } // namespace KateMDI
00968 
00969 // kate: space-indent on; indent-width 2;

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kate
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal