24 #include "katemdi.moc"
26 #include <tdeaction.h>
28 #include <tdeglobal.h>
29 #include <tdeglobalsettings.h>
30 #include <tdeapplication.h>
31 #include <tdelocale.h>
32 #include <tdeconfig.h>
33 #include <kiconloader.h>
34 #include <tdepopupmenu.h>
35 #include <tdemessagebox.h>
45 Splitter::Splitter(Orientation o, TQWidget* parent,
const char* name)
46 : TQSplitter(o, parent, name)
54 bool Splitter::isLastChild(TQWidget* w)
const
56 return ( idAfter( w ) == 0 );
59 int Splitter::idAfter ( TQWidget * w )
const
61 return TQSplitter::idAfter (w);
69 ToggleToolViewAction::ToggleToolViewAction (
const TQString& text,
const TDEShortcut& cut, ToolView *tv,
70 TQObject* parent,
const char* name )
71 : TDEToggleAction(text,cut,parent,name)
74 connect(
this,TQ_SIGNAL(toggled(
bool)),
this,TQ_SLOT(slotToggled(
bool)));
75 connect(m_tv,TQ_SIGNAL(visibleChanged(
bool)),
this,TQ_SLOT(visibleChanged(
bool)));
77 setChecked(m_tv->visible());
80 ToggleToolViewAction::~ToggleToolViewAction()
85 void ToggleToolViewAction::visibleChanged(
bool)
87 if (isChecked() != m_tv->visible())
88 setChecked (m_tv->visible());
91 void ToggleToolViewAction::slotToggled(
bool t)
95 m_tv->mainWindow()->showToolView (m_tv);
100 m_tv->mainWindow()->hideToolView (m_tv);
101 m_tv->mainWindow()->centralWidget()->setFocus ();
110 static const char *actionListName =
"kate_mdi_window_actions";
112 static const char *guiDescription =
""
113 "<!DOCTYPE kpartgui><kpartgui name=\"kate_mdi_window_actions\">"
115 " <Menu name=\"window\">"
116 " <ActionList name=\"%1\" />"
121 GUIClient::GUIClient ( MainWindow *mw )
123 , KXMLGUIClient ( mw )
126 connect( m_mw->guiFactory(), TQ_SIGNAL( clientAdded( KXMLGUIClient * ) ),
127 this, TQ_SLOT( clientAdded( KXMLGUIClient * ) ) );
129 if ( domDocument().documentElement().isNull() )
131 TQString completeDescription = TQString::fromLatin1( guiDescription )
132 .arg( actionListName );
134 setXML( completeDescription,
false );
137 if (actionCollection()->tdeaccel()==0)
138 actionCollection()->setWidget(m_mw);
140 m_toolMenu =
new TDEActionMenu(i18n(
"Tool &Views"),actionCollection(),
"kate_mdi_toolview_menu");
141 m_showSidebarsAction =
new TDEToggleAction( i18n(
"Show Side&bars"),
142 CTRL|ALT|SHIFT|Key_F, actionCollection(),
"kate_mdi_sidebar_visibility" );
143 m_showSidebarsAction->setCheckedState(i18n(
"Hide Side&bars"));
144 m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
145 connect( m_showSidebarsAction, TQ_SIGNAL( toggled(
bool ) ),
146 m_mw, TQ_SLOT( setSidebarsVisible(
bool ) ) );
148 m_toolMenu->insert( m_showSidebarsAction );
149 m_toolMenu->insert(
new TDEActionSeparator( m_toolMenu ) );
152 actionCollection()->readShortcutSettings(
"Shortcuts", kapp->config() );
155 GUIClient::~GUIClient()
159 void GUIClient::updateSidebarsVisibleAction()
161 m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
164 void GUIClient::registerToolView (ToolView *tv)
166 TQString aname = TQString(
"kate_mdi_toolview_") + tv->id;
170 TDEConfig *cfg = kapp->config();
171 TQString _grp = cfg->group();
172 cfg->setGroup(
"Shortcuts");
173 sc = TDEShortcut( cfg->readEntry( aname,
"" ) );
174 cfg->setGroup( _grp );
176 TDEToggleAction *a =
new ToggleToolViewAction(i18n(
"Show %1").arg(tv->text),
177 sc,tv, actionCollection(), aname.latin1() );
179 a->setCheckedState(TQString(i18n(
"Hide %1").arg(tv->text)));
181 m_toolViewActions.append(a);
182 m_toolMenu->insert(a);
184 m_toolToAction.insert (tv, a);
189 void GUIClient::unregisterToolView (ToolView *tv)
191 TDEAction *a = m_toolToAction[tv];
196 m_toolViewActions.remove(a);
199 m_toolToAction.remove (tv);
204 void GUIClient::clientAdded( KXMLGUIClient *client )
206 if ( client ==
this )
210 void GUIClient::updateActions()
215 unplugActionList( actionListName );
217 TQPtrList<TDEAction> addList;
218 addList.append(m_toolMenu);
220 plugActionList( actionListName, addList );
228 ToolView::ToolView (MainWindow *mainwin, Sidebar *sidebar, TQWidget *parent)
230 , m_mainWin (mainwin)
231 , m_sidebar (sidebar)
237 ToolView::~ToolView ()
239 m_mainWin->toolViewDeleted (
this);
242 void ToolView::setVisible (
bool vis)
244 if (m_visible == vis)
248 emit visibleChanged (m_visible);
251 bool ToolView::visible ()
const
256 void ToolView::childEvent ( TQChildEvent *ev )
259 if (ev->inserted() && ev->child() && ev->child()->tqt_cast(
"TQWidget")) {
260 setFocusProxy (::tqt_cast<TQWidget*>(ev->child()));
263 TQVBox::childEvent (ev);
271 Sidebar::Sidebar (KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, TQWidget *parent)
272 : KMultiTabBar ((pos == KMultiTabBar::Top || pos == KMultiTabBar::Bottom) ? KMultiTabBar::Horizontal : KMultiTabBar::Vertical, parent)
273 , m_mainWin (mainwin)
286 void Sidebar::setSplitter (Splitter *sp)
289 m_ownSplit =
new Splitter ((position() == KMultiTabBar::Top || position() == KMultiTabBar::Bottom) ? TQt::Horizontal : TQt::Vertical, m_splitter);
290 m_ownSplit->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
291 m_ownSplit->setChildrenCollapsible(
false );
292 m_splitter->setResizeMode( m_ownSplit, TQSplitter::KeepSize );
296 ToolView *Sidebar::addWidget (
const TQPixmap &icon,
const TQString &text, ToolView *widget)
302 if (widget->sidebar() ==
this)
305 widget->sidebar()->removeWidget (widget);
310 appendTab (icon, newId, text);
314 widget =
new ToolView (m_mainWin,
this, m_ownSplit);
322 widget->reparent (m_ownSplit, 0, TQPoint());
323 widget->m_sidebar =
this;
327 widget->persistent =
false;
329 m_idToWidget.insert (newId, widget);
330 m_widgetToId.insert (widget, newId);
331 m_toolviews.push_back (widget);
335 connect(tab(newId),TQ_SIGNAL(clicked(
int)),
this,TQ_SLOT(tabClicked(
int)));
336 tab(newId)->installEventFilter(
this);
341 bool Sidebar::removeWidget (ToolView *widget)
343 if (!m_widgetToId.contains(widget))
346 removeTab(m_widgetToId[widget]);
348 m_idToWidget.remove (m_widgetToId[widget]);
349 m_widgetToId.remove (widget);
350 m_toolviews.remove (widget);
353 TQIntDictIterator<ToolView> it( m_idToWidget );
354 for ( ; it.current(); ++it )
357 anyVis = it.current()->isVisible();
360 if (m_idToWidget.isEmpty())
371 bool Sidebar::showWidget (ToolView *widget)
373 if (!m_widgetToId.contains(widget))
377 TQIntDictIterator<ToolView> it( m_idToWidget );
378 for ( ; it.current(); ++it )
379 if ((it.current() != widget) && !it.current()->persistent)
381 it.current()->hide();
382 setTab (it.currentKey(),
false);
383 it.current()->setVisible(
false);
386 setTab (m_widgetToId[widget],
true);
391 widget->setVisible (
true);
396 bool Sidebar::hideWidget (ToolView *widget)
398 if (!m_widgetToId.contains(widget))
405 for ( TQIntDictIterator<ToolView> it( m_idToWidget ); it.current(); ++it )
407 if (it.current() == widget)
409 it.current()->hide();
414 anyVis = it.current()->isVisible();
418 setTab (m_widgetToId[widget],
false);
423 widget->setVisible (
false);
428 void Sidebar::tabClicked(
int i)
430 ToolView *w = m_idToWidget[i];
443 m_mainWin->centralWidget()->setFocus ();
447 bool Sidebar::eventFilter(TQObject *obj, TQEvent *ev)
449 if (ev->type()==TQEvent::ContextMenu)
451 TQContextMenuEvent *e = (TQContextMenuEvent *) ev;
452 KMultiTabBarTab *bt =
dynamic_cast<KMultiTabBarTab*
>(obj);
455 kdDebug()<<
"Request for popup"<<endl;
457 m_popupButton = bt->id();
459 ToolView *w = m_idToWidget[m_popupButton];
463 TDEPopupMenu *p =
new TDEPopupMenu (
this);
465 p->insertTitle(SmallIcon(
"view_remove"), i18n(
"Behavior"), 50);
467 p->insertItem(w->persistent ? SmallIconSet(
"view-restore") : SmallIconSet(
"view-fullscreen"), w->persistent ? i18n(
"Make Non-Persistent") : i18n(
"Make Persistent"), 10);
469 p->insertTitle(SmallIcon(
"move"), i18n(
"Move To"), 51);
472 p->insertItem(SmallIconSet(
"back"), i18n(
"Left Sidebar"),0);
475 p->insertItem(SmallIconSet(
"forward"), i18n(
"Right Sidebar"),1);
478 p->insertItem(SmallIconSet(
"go-up"), i18n(
"Top Sidebar"),2);
481 p->insertItem(SmallIconSet(
"go-down"), i18n(
"Bottom Sidebar"),3);
483 connect(p, TQ_SIGNAL(activated(
int)),
484 this, TQ_SLOT(buttonPopupActivate(
int)));
486 p->exec(e->globalPos());
499 if (m_idToWidget.isEmpty() || !m_mainWin->sidebarsVisible() )
502 KMultiTabBar::show( );
505 void Sidebar::buttonPopupActivate (
int id)
507 ToolView *w = m_idToWidget[m_popupButton];
516 m_mainWin->moveToolView (w, (KMultiTabBar::KMultiTabBarPosition)
id);
517 m_mainWin->showToolView (w);
522 w->persistent = !w->persistent;
525 void Sidebar::updateLastSize ()
527 TQValueList<int> s = m_splitter->sizes ();
530 if ((position() == KMultiTabBar::Right || position() == KMultiTabBar::Bottom))
538 class TmpToolViewSorter
545 void Sidebar::restoreSession (TDEConfig *config)
548 unsigned int firstWrong = 0;
549 for ( ; firstWrong < m_toolviews.size(); ++firstWrong )
551 ToolView *tv = m_toolviews[firstWrong];
553 unsigned int pos = config->readUnsignedNumEntry (TQString (
"Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), firstWrong);
555 if (pos != firstWrong)
560 if (firstWrong < m_toolviews.size())
563 TQValueList<TmpToolViewSorter> toSort;
564 for (
unsigned int i=firstWrong; i < m_toolviews.size(); ++i)
567 s.tv = m_toolviews[i];
568 s.pos = config->readUnsignedNumEntry (TQString (
"Kate-MDI-ToolView-%1-Sidebar-Position").arg(m_toolviews[i]->
id), i);
569 toSort.push_back (s);
573 for (
unsigned int m=0; m < toSort.size(); ++m)
574 for (
unsigned int n=m+1; n < toSort.size(); ++n)
575 if (toSort[n].pos < toSort[m].pos)
577 TmpToolViewSorter tmp = toSort[n];
578 toSort[n] = toSort[m];
584 for (
int i=m_toolviews.size()-1; i >= (
int)firstWrong; --i)
586 removeTab (m_widgetToId[m_toolviews[i]]);
590 for (
unsigned int i=0; i < toSort.size(); ++i)
592 ToolView *tv = toSort[i].tv;
594 m_toolviews[firstWrong+i] = tv;
597 int newId = m_widgetToId[tv];
598 appendTab (tv->icon, newId, tv->text);
599 connect(tab(newId),TQ_SIGNAL(clicked(
int)),
this,TQ_SLOT(tabClicked(
int)));
600 tab(newId)->installEventFilter(
this);
603 m_ownSplit->moveToLast (tv);
611 TQValueList<int> s = config->readIntListEntry (TQString (
"Kate-MDI-Sidebar-%1-Splitter").arg(position()));
612 m_ownSplit->setSizes (s);
616 for (
unsigned int i=0; i < m_toolviews.size(); ++i )
618 ToolView *tv = m_toolviews[i];
620 tv->persistent = config->readBoolEntry (TQString (
"Kate-MDI-ToolView-%1-Persistent").arg(tv->id),
false);
621 tv->setVisible (config->readBoolEntry (TQString (
"Kate-MDI-ToolView-%1-Visible").arg(tv->id),
false));
624 anyVis = tv->visible();
626 setTab (m_widgetToId[tv],tv->visible());
640 void Sidebar::saveSession (TDEConfig *config)
643 TQValueList<int> s = m_ownSplit->sizes();
644 config->writeEntry (TQString (
"Kate-MDI-Sidebar-%1-Splitter").arg(position()), s);
647 for (
unsigned int i=0; i < m_toolviews.size(); ++i )
649 ToolView *tv = m_toolviews[i];
651 config->writeEntry (TQString (
"Kate-MDI-ToolView-%1-Position").arg(tv->id), tv->sidebar()->position());
652 config->writeEntry (TQString (
"Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), i);
653 config->writeEntry (TQString (
"Kate-MDI-ToolView-%1-Visible").arg(tv->id), tv->visible());
654 config->writeEntry (TQString (
"Kate-MDI-ToolView-%1-Persistent").arg(tv->id), tv->persistent);
663 MainWindow::MainWindow (TQWidget* parentWidget,
const char* name)
664 : KParts::MainWindow( parentWidget, name)
665 , m_sidebarsVisible(true)
666 , m_restoreConfig (0)
667 , m_guiClient (new GUIClient (this))
670 TQHBox *hb =
new TQHBox (
this);
671 setCentralWidget(hb);
673 m_sidebars[KMultiTabBar::Left] =
new Sidebar (KMultiTabBar::Left,
this, hb);
675 m_hSplitter =
new Splitter (TQt::Horizontal, hb);
676 m_hSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
678 m_sidebars[KMultiTabBar::Left]->setSplitter (m_hSplitter);
680 TQVBox *vb =
new TQVBox (m_hSplitter);
681 m_hSplitter->setCollapsible(vb,
false);
683 m_sidebars[KMultiTabBar::Top] =
new Sidebar (KMultiTabBar::Top,
this, vb);
685 m_vSplitter =
new Splitter (TQt::Vertical, vb);
686 m_vSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
688 m_sidebars[KMultiTabBar::Top]->setSplitter (m_vSplitter);
690 m_centralWidget =
new TQVBox (m_vSplitter);
691 m_vSplitter->setCollapsible(m_centralWidget,
false);
693 m_sidebars[KMultiTabBar::Bottom] =
new Sidebar (KMultiTabBar::Bottom,
this, vb);
694 m_sidebars[KMultiTabBar::Bottom]->setSplitter (m_vSplitter);
696 m_sidebars[KMultiTabBar::Right] =
new Sidebar (KMultiTabBar::Right,
this, hb);
697 m_sidebars[KMultiTabBar::Right]->setSplitter (m_hSplitter);
700 MainWindow::~MainWindow ()
703 while (!m_toolviews.isEmpty())
704 delete m_toolviews[0];
707 delete m_centralWidget;
709 for (
unsigned int i=0; i < 4; ++i)
710 delete m_sidebars[i];
713 TQWidget *MainWindow::centralWidget ()
const
715 return m_centralWidget;
718 ToolView *MainWindow::createToolView (
const TQString &identifier, KMultiTabBar::KMultiTabBarPosition pos,
const TQPixmap &icon,
const TQString &text)
720 if (m_idToWidget[identifier])
724 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
726 m_restoreConfig->setGroup (m_restoreGroup);
727 pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString (
"Kate-MDI-ToolView-%1-Position").arg(identifier), pos);
730 ToolView *v = m_sidebars[pos]->addWidget (icon, text, 0);
733 m_idToWidget.insert (identifier, v);
734 m_toolviews.push_back (v);
737 m_guiClient->registerToolView (v);
742 ToolView *MainWindow::toolView (
const TQString &identifier)
const
744 return m_idToWidget[identifier];
747 void MainWindow::toolViewDeleted (ToolView *widget)
752 if (widget->mainWindow() !=
this)
756 m_guiClient->unregisterToolView (widget);
758 widget->sidebar()->removeWidget (widget);
760 m_idToWidget.remove (widget->id);
761 m_toolviews.remove (widget);
764 void MainWindow::setSidebarsVisible(
bool visible )
766 m_sidebarsVisible = visible;
768 m_sidebars[0]->setShown(visible);
769 m_sidebars[1]->setShown(visible);
770 m_sidebars[2]->setShown(visible);
771 m_sidebars[3]->setShown(visible);
773 m_guiClient->updateSidebarsVisibleAction();
776 if( !m_sidebarsVisible )
778 KMessageBox::information(
this,
779 i18n(
"<qt>You are about to hide the sidebars. With "
780 "hidden sidebars it is not possible to directly "
781 "access the tool views with the mouse anymore, "
782 "so if you need to access the sidebars again "
783 "invoke <b>Window > Tool Views > Show Sidebars</b> "
784 "in the menu. It is still possible to show/hide "
785 "the tool views with the assigned shortcuts.</qt>"),
786 TQString::null,
"Kate hide sidebars notification message" );
790 bool MainWindow::sidebarsVisible()
const
792 return m_sidebarsVisible;
795 void MainWindow::setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style)
797 m_sidebars[0]->setStyle(style);
798 m_sidebars[1]->setStyle(style);
799 m_sidebars[2]->setStyle(style);
800 m_sidebars[3]->setStyle(style);
803 KMultiTabBar::KMultiTabBarStyle MainWindow::toolViewStyle ()
const
806 return m_sidebars[KMultiTabBar::Top]->tabStyle();
809 bool MainWindow::moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos)
811 if (!widget || widget->mainWindow() !=
this)
815 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
817 m_restoreConfig->setGroup (m_restoreGroup);
818 pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString (
"Kate-MDI-ToolView-%1-Position").arg(widget->id), pos);
821 m_sidebars[pos]->addWidget (widget->icon, widget->text, widget);
826 bool MainWindow::showToolView (ToolView *widget)
828 if (!widget || widget->mainWindow() !=
this)
832 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
835 return widget->sidebar()->showWidget (widget);
838 bool MainWindow::hideToolView (ToolView *widget)
840 if (!widget || widget->mainWindow() !=
this)
844 if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
847 return widget->sidebar()->hideWidget (widget);
850 void MainWindow::startRestore (TDEConfig *config,
const TQString &group)
853 m_restoreConfig = config;
854 m_restoreGroup = group;
856 if (!m_restoreConfig || !m_restoreConfig->hasGroup (m_restoreGroup))
860 hs << 200 << 100 << 200;
862 vs << 150 << 100 << 200;
864 m_sidebars[0]->setLastSize (hs[0]);
865 m_sidebars[1]->setLastSize (hs[2]);
866 m_sidebars[2]->setLastSize (vs[0]);
867 m_sidebars[3]->setLastSize (vs[2]);
869 m_hSplitter->setSizes(hs);
870 m_vSplitter->setSizes(vs);
875 m_restoreConfig->setGroup (m_restoreGroup);
876 restoreWindowSize (m_restoreConfig);
878 m_restoreConfig->setGroup (m_restoreGroup);
881 TQValueList<int> hs = m_restoreConfig->readIntListEntry (
"Kate-MDI-H-Splitter");
882 TQValueList<int> vs = m_restoreConfig->readIntListEntry (
"Kate-MDI-V-Splitter");
884 m_sidebars[0]->setLastSize (hs[0]);
885 m_sidebars[1]->setLastSize (hs[2]);
886 m_sidebars[2]->setLastSize (vs[0]);
887 m_sidebars[3]->setLastSize (vs[2]);
889 m_hSplitter->setSizes(hs);
890 m_vSplitter->setSizes(vs);
892 setToolViewStyle( (KMultiTabBar::KMultiTabBarStyle)m_restoreConfig->readNumEntry (
"Kate-MDI-Sidebar-Style", (
int)toolViewStyle()) );
895 m_sidebarsVisible = m_restoreConfig->readBoolEntry (
"Kate-MDI-Sidebar-Visible",
true );
896 m_guiClient->updateSidebarsVisibleAction();
899 void MainWindow::finishRestore ()
901 if (!m_restoreConfig)
904 if (m_restoreConfig->hasGroup (m_restoreGroup))
907 applyMainWindowSettings(m_restoreConfig, m_restoreGroup);
910 m_restoreConfig->setGroup (m_restoreGroup);
911 for (
unsigned int i=0; i < m_toolviews.size(); ++i )
913 KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString (
"Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->
id), m_toolviews[i]->sidebar()->position());
915 if (m_toolviews[i]->sidebar()->position() != newPos)
917 moveToolView (m_toolviews[i], newPos);
922 m_restoreConfig->setGroup (m_restoreGroup);
923 for (
unsigned int i=0; i < 4; ++i)
924 m_sidebars[i]->restoreSession (m_restoreConfig);
932 void MainWindow::saveSession (TDEConfig *config,
const TQString &group)
937 saveMainWindowSettings (config, group);
939 config->setGroup (group);
942 TQValueList<int> hs = m_hSplitter->sizes();
943 TQValueList<int> vs = m_vSplitter->sizes();
945 if (hs[0] <= 2 && !m_sidebars[0]->splitterVisible ())
946 hs[0] = m_sidebars[0]->lastSize();
947 if (hs[2] <= 2 && !m_sidebars[1]->splitterVisible ())
948 hs[2] = m_sidebars[1]->lastSize();
949 if (vs[0] <= 2 && !m_sidebars[2]->splitterVisible ())
950 vs[0] = m_sidebars[2]->lastSize();
951 if (vs[2] <= 2 && !m_sidebars[3]->splitterVisible ())
952 vs[2] = m_sidebars[3]->lastSize();
954 config->writeEntry (
"Kate-MDI-H-Splitter", hs);
955 config->writeEntry (
"Kate-MDI-V-Splitter", vs);
958 config->writeEntry (
"Kate-MDI-Sidebar-Style", (
int)toolViewStyle());
959 config->writeEntry (
"Kate-MDI-Sidebar-Visible", m_sidebarsVisible );
962 for (
unsigned int i=0; i < 4; ++i)
963 m_sidebars[i]->saveSession (config);