katemdi.cpp
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 <tqvbox.h> 00038 #include <tqhbox.h> 00039 #include <tqevent.h> 00040 00041 namespace KateMDI { 00042 00043 //BEGIN SPLITTER 00044 00045 Splitter::Splitter(Orientation o, TQWidget* parent, const char* name) 00046 : TQSplitter(o, parent, name) 00047 { 00048 } 00049 00050 Splitter::~Splitter() 00051 { 00052 } 00053 00054 bool Splitter::isLastChild(TQWidget* w) const 00055 { 00056 return ( idAfter( w ) == 0 ); 00057 } 00058 00059 int Splitter::idAfter ( TQWidget * w ) const 00060 { 00061 return TQSplitter::idAfter (w); 00062 } 00063 00064 //END SPLITTER 00065 00066 00067 //BEGIN TOGGLETOOLVIEWACTION 00068 00069 ToggleToolViewAction::ToggleToolViewAction ( const TQString& text, const KShortcut& cut, ToolView *tv, 00070 TQObject* parent, const char* name ) 00071 : KToggleAction(text,cut,parent,name) 00072 , m_tv(tv) 00073 { 00074 connect(this,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotToggled(bool))); 00075 connect(m_tv,TQT_SIGNAL(visibleChanged(bool)),this,TQT_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 : TQObject ( mw ) 00123 , KXMLGUIClient ( mw ) 00124 , m_mw (mw) 00125 { 00126 connect( m_mw->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ), 00127 this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) ); 00128 00129 if ( domDocument().documentElement().isNull() ) 00130 { 00131 TQString completeDescription = TQString::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, TQT_SIGNAL( toggled( bool ) ), 00146 m_mw, TQT_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 TQString aname = TQString("kate_mdi_toolview_") + tv->id; 00167 00168 // try to read the action shortcut 00169 KShortcut sc; 00170 KConfig *cfg = kapp->config(); 00171 TQString _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(TQString(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 TQPtrList<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, TQWidget *parent) 00229 : TQVBox (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 ( TQChildEvent *ev ) 00257 { 00258 // set the widget to be focus proxy if possible 00259 if (ev->inserted() && ev->child() && TQT_TQOBJECT(ev->child())->qt_cast(TQWIDGET_OBJECT_NAME_STRING)) { 00260 setFocusProxy (::tqqt_cast<QWidget*>(TQT_TQOBJECT(ev->child()))); 00261 } 00262 00263 TQVBox::childEvent (ev); 00264 } 00265 00266 //END TOOLVIEW 00267 00268 00269 //BEGIN SIDEBAR 00270 00271 Sidebar::Sidebar (KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, TQWidget *parent) 00272 : KMultiTabBar ((pos == KMultiTabBar::Top || pos == KMultiTabBar::Bottom) ? KMultiTabBar::Horizontal : KMultiTabBar::Vertical, parent) 00273 , m_mainWin (mainwin) 00274 , m_splitter (0) 00275 , m_ownSplit (0) 00276 , m_lastSize (0) 00277 { 00278 setPosition( pos ); 00279 hide (); 00280 } 00281 00282 Sidebar::~Sidebar () 00283 { 00284 } 00285 00286 void Sidebar::setSplitter (Splitter *sp) 00287 { 00288 m_splitter = sp; 00289 m_ownSplit = new Splitter ((position() == KMultiTabBar::Top || position() == KMultiTabBar::Bottom) ? Qt::Horizontal : Qt::Vertical, m_splitter); 00290 m_ownSplit->setOpaqueResize( KGlobalSettings::opaqueResize() ); 00291 m_ownSplit->setChildrenCollapsible( false ); 00292 m_splitter->setResizeMode( m_ownSplit, TQSplitter::KeepSize ); 00293 m_ownSplit->hide (); 00294 } 00295 00296 ToolView *Sidebar::addWidget (const TQPixmap &icon, const TQString &text, ToolView *widget) 00297 { 00298 static int id = 0; 00299 00300 if (widget) 00301 { 00302 if (widget->sidebar() == this) 00303 return widget; 00304 00305 widget->sidebar()->removeWidget (widget); 00306 } 00307 00308 int newId = ++id; 00309 00310 appendTab (icon, newId, text); 00311 00312 if (!widget) 00313 { 00314 widget = new ToolView (m_mainWin, this, m_ownSplit); 00315 widget->hide (); 00316 widget->icon = icon; 00317 widget->text = text; 00318 } 00319 else 00320 { 00321 widget->hide (); 00322 widget->reparent (m_ownSplit, 0, TQPoint()); 00323 widget->m_sidebar = this; 00324 } 00325 00326 // save it's pos ;) 00327 widget->persistent = false; 00328 00329 m_idToWidget.insert (newId, widget); 00330 m_widgetToId.insert (widget, newId); 00331 m_toolviews.push_back (widget); 00332 00333 show (); 00334 00335 connect(tab(newId),TQT_SIGNAL(clicked(int)),this,TQT_SLOT(tabClicked(int))); 00336 tab(newId)->installEventFilter(this); 00337 00338 return widget; 00339 } 00340 00341 bool Sidebar::removeWidget (ToolView *widget) 00342 { 00343 if (!m_widgetToId.contains(widget)) 00344 return false; 00345 00346 removeTab(m_widgetToId[widget]); 00347 00348 m_idToWidget.remove (m_widgetToId[widget]); 00349 m_widgetToId.remove (widget); 00350 m_toolviews.remove (widget); 00351 00352 bool anyVis = false; 00353 TQIntDictIterator<ToolView> it( m_idToWidget ); 00354 for ( ; it.current(); ++it ) 00355 { 00356 if (!anyVis) 00357 anyVis = it.current()->isVisible(); 00358 } 00359 00360 if (m_idToWidget.isEmpty()) 00361 { 00362 m_ownSplit->hide (); 00363 hide (); 00364 } 00365 else if (!anyVis) 00366 m_ownSplit->hide (); 00367 00368 return true; 00369 } 00370 00371 bool Sidebar::showWidget (ToolView *widget) 00372 { 00373 if (!m_widgetToId.contains(widget)) 00374 return false; 00375 00376 // hide other non-persistent views 00377 TQIntDictIterator<ToolView> it( m_idToWidget ); 00378 for ( ; it.current(); ++it ) 00379 if ((it.current() != widget) && !it.current()->persistent) 00380 { 00381 it.current()->hide(); 00382 setTab (it.currentKey(), false); 00383 it.current()->setVisible(false); 00384 } 00385 00386 setTab (m_widgetToId[widget], true); 00387 00388 m_ownSplit->show (); 00389 widget->show (); 00390 00391 widget->setVisible (true); 00392 00393 return true; 00394 } 00395 00396 bool Sidebar::hideWidget (ToolView *widget) 00397 { 00398 if (!m_widgetToId.contains(widget)) 00399 return false; 00400 00401 bool anyVis = false; 00402 00403 updateLastSize (); 00404 00405 for ( TQIntDictIterator<ToolView> it( m_idToWidget ); it.current(); ++it ) 00406 { 00407 if (it.current() == widget) 00408 { 00409 it.current()->hide(); 00410 continue; 00411 } 00412 00413 if (!anyVis) 00414 anyVis = it.current()->isVisible(); 00415 } 00416 00417 // lower tab 00418 setTab (m_widgetToId[widget], false); 00419 00420 if (!anyVis) 00421 m_ownSplit->hide (); 00422 00423 widget->setVisible (false); 00424 00425 return true; 00426 } 00427 00428 void Sidebar::tabClicked(int i) 00429 { 00430 ToolView *w = m_idToWidget[i]; 00431 00432 if (!w) 00433 return; 00434 00435 if (isTabRaised(i)) 00436 { 00437 showWidget (w); 00438 w->setFocus (); 00439 } 00440 else 00441 { 00442 hideWidget (w); 00443 m_mainWin->centralWidget()->setFocus (); 00444 } 00445 } 00446 00447 bool Sidebar::eventFilter(TQObject *obj, TQEvent *ev) 00448 { 00449 if (ev->type()==TQEvent::ContextMenu) 00450 { 00451 TQContextMenuEvent *e = (TQContextMenuEvent *) ev; 00452 KMultiTabBarTab *bt = tqt_dynamic_cast<KMultiTabBarTab*>(obj); 00453 if (bt) 00454 { 00455 kdDebug()<<"Request for popup"<<endl; 00456 00457 m_popupButton = bt->id(); 00458 00459 ToolView *w = m_idToWidget[m_popupButton]; 00460 00461 if (w) 00462 { 00463 KPopupMenu *p = new KPopupMenu (this); 00464 00465 p->insertTitle(SmallIcon("view_remove"), i18n("Behavior"), 50); 00466 00467 p->insertItem(w->persistent ? SmallIconSet("window_nofullscreen") : SmallIconSet("window_fullscreen"), w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent"), 10); 00468 00469 p->insertTitle(SmallIcon("move"), i18n("Move To"), 51); 00470 00471 if (position() != 0) 00472 p->insertItem(SmallIconSet("back"), i18n("Left Sidebar"),0); 00473 00474 if (position() != 1) 00475 p->insertItem(SmallIconSet("forward"), i18n("Right Sidebar"),1); 00476 00477 if (position() != 2) 00478 p->insertItem(SmallIconSet("up"), i18n("Top Sidebar"),2); 00479 00480 if (position() != 3) 00481 p->insertItem(SmallIconSet("down"), i18n("Bottom Sidebar"),3); 00482 00483 connect(p, TQT_SIGNAL(activated(int)), 00484 this, TQT_SLOT(buttonPopupActivate(int))); 00485 00486 p->exec(e->globalPos()); 00487 delete p; 00488 00489 return true; 00490 } 00491 } 00492 } 00493 00494 return false; 00495 } 00496 00497 void Sidebar::show() 00498 { 00499 if (m_idToWidget.isEmpty() || !m_mainWin->sidebarsVisible() ) 00500 return; 00501 00502 KMultiTabBar::show( ); 00503 } 00504 00505 void Sidebar::buttonPopupActivate (int id) 00506 { 00507 ToolView *w = m_idToWidget[m_popupButton]; 00508 00509 if (!w) 00510 return; 00511 00512 // move ids 00513 if (id < 4) 00514 { 00515 // move + show ;) 00516 m_mainWin->moveToolView (w, (KMultiTabBar::KMultiTabBarPosition) id); 00517 m_mainWin->showToolView (w); 00518 } 00519 00520 // toggle persistent 00521 if (id == 10) 00522 w->persistent = !w->persistent; 00523 } 00524 00525 void Sidebar::updateLastSize () 00526 { 00527 TQValueList<int> s = m_splitter->sizes (); 00528 00529 int i = 0; 00530 if ((position() == KMultiTabBar::Right || position() == KMultiTabBar::Bottom)) 00531 i = 2; 00532 00533 // little threshold 00534 if (s[i] > 2) 00535 m_lastSize = s[i]; 00536 } 00537 00538 class TmpToolViewSorter 00539 { 00540 public: 00541 ToolView *tv; 00542 unsigned int pos; 00543 }; 00544 00545 void Sidebar::restoreSession (KConfig *config) 00546 { 00547 // get the last correct placed toolview 00548 unsigned int firstWrong = 0; 00549 for ( ; firstWrong < m_toolviews.size(); ++firstWrong ) 00550 { 00551 ToolView *tv = m_toolviews[firstWrong]; 00552 00553 unsigned int pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), firstWrong); 00554 00555 if (pos != firstWrong) 00556 break; 00557 } 00558 00559 // we need to reshuffle, ahhh :( 00560 if (firstWrong < m_toolviews.size()) 00561 { 00562 // first: collect the items to reshuffle 00563 TQValueList<TmpToolViewSorter> toSort; 00564 for (unsigned int i=firstWrong; i < m_toolviews.size(); ++i) 00565 { 00566 TmpToolViewSorter s; 00567 s.tv = m_toolviews[i]; 00568 s.pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(m_toolviews[i]->id), i); 00569 toSort.push_back (s); 00570 } 00571 00572 // now: sort the stuff we need to reshuffle 00573 for (unsigned int m=0; m < toSort.size(); ++m) 00574 for (unsigned int n=m+1; n < toSort.size(); ++n) 00575 if (toSort[n].pos < toSort[m].pos) 00576 { 00577 TmpToolViewSorter tmp = toSort[n]; 00578 toSort[n] = toSort[m]; 00579 toSort[m] = tmp; 00580 } 00581 00582 // then: remove this items from the button bar 00583 // do this backwards, to minimize the relayout efforts 00584 for (int i=m_toolviews.size()-1; i >= (int)firstWrong; --i) 00585 { 00586 removeTab (m_widgetToId[m_toolviews[i]]); 00587 } 00588 00589 // insert the reshuffled things in order :) 00590 for (unsigned int i=0; i < toSort.size(); ++i) 00591 { 00592 ToolView *tv = toSort[i].tv; 00593 00594 m_toolviews[firstWrong+i] = tv; 00595 00596 // readd the button 00597 int newId = m_widgetToId[tv]; 00598 appendTab (tv->icon, newId, tv->text); 00599 connect(tab(newId),TQT_SIGNAL(clicked(int)),this,TQT_SLOT(tabClicked(int))); 00600 tab(newId)->installEventFilter(this); 00601 00602 // reshuffle in splitter 00603 m_ownSplit->moveToLast (tv); 00604 } 00605 } 00606 00607 // update last size if needed 00608 updateLastSize (); 00609 00610 // restore the own splitter sizes 00611 TQValueList<int> s = config->readIntListEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position())); 00612 m_ownSplit->setSizes (s); 00613 00614 // show only correct toolviews, remember persistent values ;) 00615 bool anyVis = false; 00616 for ( unsigned int i=0; i < m_toolviews.size(); ++i ) 00617 { 00618 ToolView *tv = m_toolviews[i]; 00619 00620 tv->persistent = config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), false); 00621 tv->setVisible (config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), false)); 00622 00623 if (!anyVis) 00624 anyVis = tv->visible(); 00625 00626 setTab (m_widgetToId[tv],tv->visible()); 00627 00628 if (tv->visible()) 00629 tv->show(); 00630 else 00631 tv->hide (); 00632 } 00633 00634 if (anyVis) 00635 m_ownSplit->show(); 00636 else 00637 m_ownSplit->hide(); 00638 } 00639 00640 void Sidebar::saveSession (KConfig *config) 00641 { 00642 // store the own splitter sizes 00643 TQValueList<int> s = m_ownSplit->sizes(); 00644 config->writeEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()), s); 00645 00646 // store the data about all toolviews in this sidebar ;) 00647 for ( unsigned int i=0; i < m_toolviews.size(); ++i ) 00648 { 00649 ToolView *tv = m_toolviews[i]; 00650 00651 config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(tv->id), tv->sidebar()->position()); 00652 config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), i); 00653 config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), tv->visible()); 00654 config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), tv->persistent); 00655 } 00656 } 00657 00658 //END SIDEBAR 00659 00660 00661 //BEGIN MAIN WINDOW 00662 00663 MainWindow::MainWindow (TQWidget* parentWidget, const char* name) 00664 : KParts::MainWindow( parentWidget, name) 00665 , m_sidebarsVisible(true) 00666 , m_restoreConfig (0) 00667 , m_guiClient (new GUIClient (this)) 00668 { 00669 // init the internal widgets 00670 TQHBox *hb = new TQHBox (this); 00671 setCentralWidget(hb); 00672 00673 m_sidebars[KMultiTabBar::Left] = new Sidebar (KMultiTabBar::Left, this, hb); 00674 00675 m_hSplitter = new Splitter (Qt::Horizontal, hb); 00676 m_hSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() ); 00677 00678 m_sidebars[KMultiTabBar::Left]->setSplitter (m_hSplitter); 00679 00680 TQVBox *vb = new TQVBox (m_hSplitter); 00681 m_hSplitter->setCollapsible(vb, false); 00682 00683 m_sidebars[KMultiTabBar::Top] = new Sidebar (KMultiTabBar::Top, this, vb); 00684 00685 m_vSplitter = new Splitter (Qt::Vertical, vb); 00686 m_vSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() ); 00687 00688 m_sidebars[KMultiTabBar::Top]->setSplitter (m_vSplitter); 00689 00690 m_centralWidget = new TQVBox (m_vSplitter); 00691 m_vSplitter->setCollapsible(m_centralWidget, false); 00692 00693 m_sidebars[KMultiTabBar::Bottom] = new Sidebar (KMultiTabBar::Bottom, this, vb); 00694 m_sidebars[KMultiTabBar::Bottom]->setSplitter (m_vSplitter); 00695 00696 m_sidebars[KMultiTabBar::Right] = new Sidebar (KMultiTabBar::Right, this, hb); 00697 m_sidebars[KMultiTabBar::Right]->setSplitter (m_hSplitter); 00698 } 00699 00700 MainWindow::~MainWindow () 00701 { 00702 // cu toolviews 00703 while (!m_toolviews.isEmpty()) 00704 delete m_toolviews[0]; 00705 00706 // seems like we really should delete this by hand ;) 00707 delete m_centralWidget; 00708 00709 for (unsigned int i=0; i < 4; ++i) 00710 delete m_sidebars[i]; 00711 } 00712 00713 TQWidget *MainWindow::centralWidget () const 00714 { 00715 return m_centralWidget; 00716 } 00717 00718 ToolView *MainWindow::createToolView (const TQString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const TQPixmap &icon, const TQString &text) 00719 { 00720 if (m_idToWidget[identifier]) 00721 return 0; 00722 00723 // try the restore config to figure out real pos 00724 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) 00725 { 00726 m_restoreConfig->setGroup (m_restoreGroup); 00727 pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(identifier), pos); 00728 } 00729 00730 ToolView *v = m_sidebars[pos]->addWidget (icon, text, 0); 00731 v->id = identifier; 00732 00733 m_idToWidget.insert (identifier, v); 00734 m_toolviews.push_back (v); 00735 00736 // register for menu stuff 00737 m_guiClient->registerToolView (v); 00738 00739 return v; 00740 } 00741 00742 ToolView *MainWindow::toolView (const TQString &identifier) const 00743 { 00744 return m_idToWidget[identifier]; 00745 } 00746 00747 void MainWindow::toolViewDeleted (ToolView *widget) 00748 { 00749 if (!widget) 00750 return; 00751 00752 if (widget->mainWindow() != this) 00753 return; 00754 00755 // unregister from menu stuff 00756 m_guiClient->unregisterToolView (widget); 00757 00758 widget->sidebar()->removeWidget (widget); 00759 00760 m_idToWidget.remove (widget->id); 00761 m_toolviews.remove (widget); 00762 } 00763 00764 void MainWindow::setSidebarsVisible( bool visible ) 00765 { 00766 m_sidebarsVisible = visible; 00767 00768 m_sidebars[0]->setShown(visible); 00769 m_sidebars[1]->setShown(visible); 00770 m_sidebars[2]->setShown(visible); 00771 m_sidebars[3]->setShown(visible); 00772 00773 m_guiClient->updateSidebarsVisibleAction(); 00774 00775 // show information message box, if the users hides the sidebars 00776 if( !m_sidebarsVisible ) 00777 { 00778 KMessageBox::information( this, 00779 i18n("<qt>You are about to hide the sidebars. With " 00780 "hidden sidebars it is not possible to directly " 00781 "access the tool views with the mouse anymore, " 00782 "so if you need to access the sidebars again " 00783 "invoke <b>Window > Tool Views > Show Sidebars</b> " 00784 "in the menu. It is still possible to show/hide " 00785 "the tool views with the assigned shortcuts.</qt>"), 00786 TQString::null, "Kate hide sidebars notification message" ); 00787 } 00788 } 00789 00790 bool MainWindow::sidebarsVisible() const 00791 { 00792 return m_sidebarsVisible; 00793 } 00794 00795 void MainWindow::setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style) 00796 { 00797 m_sidebars[0]->setStyle(style); 00798 m_sidebars[1]->setStyle(style); 00799 m_sidebars[2]->setStyle(style); 00800 m_sidebars[3]->setStyle(style); 00801 } 00802 00803 KMultiTabBar::KMultiTabBarStyle MainWindow::toolViewStyle () const 00804 { 00805 // all sidebars have the same style, so just take Top 00806 return m_sidebars[KMultiTabBar::Top]->tabStyle(); 00807 } 00808 00809 bool MainWindow::moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos) 00810 { 00811 if (!widget || widget->mainWindow() != this) 00812 return false; 00813 00814 // try the restore config to figure out real pos 00815 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) 00816 { 00817 m_restoreConfig->setGroup (m_restoreGroup); 00818 pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(widget->id), pos); 00819 } 00820 00821 m_sidebars[pos]->addWidget (widget->icon, widget->text, widget); 00822 00823 return true; 00824 } 00825 00826 bool MainWindow::showToolView (ToolView *widget) 00827 { 00828 if (!widget || widget->mainWindow() != this) 00829 return false; 00830 00831 // skip this if happens during restoring, or we will just see flicker 00832 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) 00833 return true; 00834 00835 return widget->sidebar()->showWidget (widget); 00836 } 00837 00838 bool MainWindow::hideToolView (ToolView *widget) 00839 { 00840 if (!widget || widget->mainWindow() != this) 00841 return false; 00842 00843 // skip this if happens during restoring, or we will just see flicker 00844 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup)) 00845 return true; 00846 00847 return widget->sidebar()->hideWidget (widget); 00848 } 00849 00850 void MainWindow::startRestore (KConfig *config, const TQString &group) 00851 { 00852 // first save this stuff 00853 m_restoreConfig = config; 00854 m_restoreGroup = group; 00855 00856 if (!m_restoreConfig || !m_restoreConfig->hasGroup (m_restoreGroup)) 00857 { 00858 // set sane default sizes 00859 TQValueList<int> hs; 00860 hs << 200 << 100 << 200; 00861 TQValueList<int> vs; 00862 vs << 150 << 100 << 200; 00863 00864 m_sidebars[0]->setLastSize (hs[0]); 00865 m_sidebars[1]->setLastSize (hs[2]); 00866 m_sidebars[2]->setLastSize (vs[0]); 00867 m_sidebars[3]->setLastSize (vs[2]); 00868 00869 m_hSplitter->setSizes(hs); 00870 m_vSplitter->setSizes(vs); 00871 return; 00872 } 00873 00874 // apply size once, to get sizes ready ;) 00875 m_restoreConfig->setGroup (m_restoreGroup); 00876 restoreWindowSize (m_restoreConfig); 00877 00878 m_restoreConfig->setGroup (m_restoreGroup); 00879 00880 // get main splitter sizes ;) 00881 TQValueList<int> hs = m_restoreConfig->readIntListEntry ("Kate-MDI-H-Splitter"); 00882 TQValueList<int> vs = m_restoreConfig->readIntListEntry ("Kate-MDI-V-Splitter"); 00883 00884 m_sidebars[0]->setLastSize (hs[0]); 00885 m_sidebars[1]->setLastSize (hs[2]); 00886 m_sidebars[2]->setLastSize (vs[0]); 00887 m_sidebars[3]->setLastSize (vs[2]); 00888 00889 m_hSplitter->setSizes(hs); 00890 m_vSplitter->setSizes(vs); 00891 00892 setToolViewStyle( (KMultiTabBar::KMultiTabBarStyle)m_restoreConfig->readNumEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()) ); 00893 00894 // after reading m_sidebarsVisible, update the GUI toggle action 00895 m_sidebarsVisible = m_restoreConfig->readBoolEntry ("Kate-MDI-Sidebar-Visible", true ); 00896 m_guiClient->updateSidebarsVisibleAction(); 00897 } 00898 00899 void MainWindow::finishRestore () 00900 { 00901 if (!m_restoreConfig) 00902 return; 00903 00904 if (m_restoreConfig->hasGroup (m_restoreGroup)) 00905 { 00906 // apply all settings, like toolbar pos and more ;) 00907 applyMainWindowSettings(m_restoreConfig, m_restoreGroup); 00908 00909 // reshuffle toolviews only if needed 00910 m_restoreConfig->setGroup (m_restoreGroup); 00911 for ( unsigned int i=0; i < m_toolviews.size(); ++i ) 00912 { 00913 KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->id), m_toolviews[i]->sidebar()->position()); 00914 00915 if (m_toolviews[i]->sidebar()->position() != newPos) 00916 { 00917 moveToolView (m_toolviews[i], newPos); 00918 } 00919 } 00920 00921 // restore the sidebars 00922 m_restoreConfig->setGroup (m_restoreGroup); 00923 for (unsigned int i=0; i < 4; ++i) 00924 m_sidebars[i]->restoreSession (m_restoreConfig); 00925 } 00926 00927 // clear this stuff, we are done ;) 00928 m_restoreConfig = 0; 00929 m_restoreGroup = ""; 00930 } 00931 00932 void MainWindow::saveSession (KConfig *config, const TQString &group) 00933 { 00934 if (!config) 00935 return; 00936 00937 saveMainWindowSettings (config, group); 00938 00939 config->setGroup (group); 00940 00941 // save main splitter sizes ;) 00942 TQValueList<int> hs = m_hSplitter->sizes(); 00943 TQValueList<int> vs = m_vSplitter->sizes(); 00944 00945 if (hs[0] <= 2 && !m_sidebars[0]->splitterVisible ()) 00946 hs[0] = m_sidebars[0]->lastSize(); 00947 if (hs[2] <= 2 && !m_sidebars[1]->splitterVisible ()) 00948 hs[2] = m_sidebars[1]->lastSize(); 00949 if (vs[0] <= 2 && !m_sidebars[2]->splitterVisible ()) 00950 vs[0] = m_sidebars[2]->lastSize(); 00951 if (vs[2] <= 2 && !m_sidebars[3]->splitterVisible ()) 00952 vs[2] = m_sidebars[3]->lastSize(); 00953 00954 config->writeEntry ("Kate-MDI-H-Splitter", hs); 00955 config->writeEntry ("Kate-MDI-V-Splitter", vs); 00956 00957 // save sidebar style 00958 config->writeEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()); 00959 config->writeEntry ("Kate-MDI-Sidebar-Visible", m_sidebarsVisible ); 00960 00961 // save the sidebars 00962 for (unsigned int i=0; i < 4; ++i) 00963 m_sidebars[i]->saveSession (config); 00964 } 00965 00966 //END MAIN WINDOW 00967 00968 } // namespace KateMDI 00969 00970 // kate: space-indent on; indent-width 2;