18#include <tqapplication.h>
19#include <tqdockarea.h>
20#include <tqdockwindow.h>
26#include <tdeparts/event.h>
27#include <tdeapplication.h>
28#include <tdepopupmenu.h>
30#include <tdeactionclasses.h>
36#include <KoMainWindow.h>
39#include <kotabpalette.h>
40#include <kotoolboxpalette.h>
42#include <kopalettemanager.h>
46 : TQObject(view,
name)
50 m_view->installEventFilter(
this);
51 m_actionCollection = ac;
53 m_actions =
new TQDict<TDEToggleAction>();
54 m_widgets =
new TQDict<TQWidget>();
55 m_palettes =
new TQDict<KoPalette>();
56 m_palettes->setAutoDelete(
true);
57 m_defaultMapping =
new TQMap<TQString, TQString>();
58 m_currentMapping =
new TQMap<TQString, TQString>();
60 m_setFixedWidth =
false;
62 m_widgetNames =
new TQStringList();
64 m_mapper =
new TQSignalMapper(
this);
65 connect(m_mapper, TQ_SIGNAL(mapped(
int)),
this, TQ_SLOT(slotTogglePalette(
int)));
66 m_viewActionMenu =
new TDEActionMenu(i18n(
"Palettes"), m_actionCollection,
"view_palette_action_menu");
68 TDEConfig * cfg = TDEGlobal::config();
69 cfg->setGroup(
"palettes");
71 bool palettesShown = cfg->readBoolEntry(
"palettesshown",
true);
75 m_toggleShowHidePalettes =
new TDEToggleAction(i18n(
"Hide All Palette Windows"),
77 TQ_SLOT(slotToggleAllPalettes()),
78 m_actionCollection,
"toggleAllPaletteWindows");
80 m_toggleShowHidePalettes->
setCheckedState(i18n(
"Show Palette Windows Again"));
83 m_toggleShowHidePalettes =
new TDEToggleAction(i18n(
"Show Palette Windows Again"),
85 TQ_SLOT(slotToggleAllPalettes()),
86 m_actionCollection,
"toggleAllPaletteWindows");
88 m_toggleShowHidePalettes->
setCheckedState(i18n(
"Hide All Palette Windows"));
90 m_viewActionMenu->insert(m_toggleShowHidePalettes);
93 TQStringList paletteList = TQStringList::split(
",", cfg->readEntry(
"palettes"));
94 TQStringList::iterator it;
95 for (it = paletteList.begin(); it != paletteList.end(); ++it) {
96 if (cfg->hasGroup(
"palette-" + (*it))) {
98 cfg->setGroup(
"palette-" + (*it));
100 enumKoPaletteStyle style = (enumKoPaletteStyle)cfg->readNumEntry(
"style", 0);
101 TQString caption = cfg->readEntry(
"caption",
"");
103 createPalette((*it), caption, style);
114 m_viewActionMenu->popupMenu()->insertSeparator();
118KoPaletteManager::~KoPaletteManager()
122 delete m_viewActionMenu;
123 delete m_widgetNames;
128 delete m_defaultMapping;
129 delete m_currentMapping;
133 const TQString & name,
134 const TQString & paletteName,
136 enumKoPaletteStyle style,
142 TQString pname = paletteName;
144 TQWidget * w = m_widgets->find(name);
152 TDEConfig * cfg = TDEGlobal::config();
153 if (cfg->hasGroup(
"palettetab-" + name)) {
154 cfg->setGroup(
"palettetab-" + name);
156 pname = cfg->readEntry(
"docker");
157 visible = cfg->readBoolEntry(
"visible");
160 KoPalette * palette = m_palettes->find(pname);
164 m_defaultPaletteOrder.append(pname+
"," + TQString::number(style));
168 a =
new TDEToggleAction(i18n(
"Show %1").arg(
widget->caption()), 0, m_mapper, TQ_SLOT(map()), m_actionCollection);
171 m_mapper->setMapping(a, m_widgetNames->count());
172 m_actions->insert( name, a );
173 m_viewActionMenu->insert(a);
175 palette->plug(
widget, name, position);
177 m_widgets->insert(name,
widget);
180 m_defaultMapping->insert(name, pname);
181 m_defaultWidgetOrder.append(name);
184 if(m_widgetNames->contains(name))
188 if(m_hiddenWidgets.contains(name))
189 palette->hidePage(
widget );
193 palette->showPage(
widget );
198 cfg->setGroup(
"palettes");
199 if( cfg->readBoolEntry(
"palettesshown", shown))
204 palette->showPage(
widget );
207 palette->hidePage(
widget );
212 m_hiddenWidgets.push(name);
213 palette->hidePage(
widget );
218 m_widgetNames->append(name);
219 m_currentMapping->insert(name, pname);
226 m_palettes->setAutoDelete(
true );
229 m_widgetNames->clear();
232 TQStringList::iterator it;
233 for (it = m_defaultPaletteOrder.begin(); it != m_defaultPaletteOrder.end(); ++it) {
235 TQString pname = s.section(
",", 0, 0 );;
236 enumKoPaletteStyle style = (enumKoPaletteStyle)s.section(
",", 1,1).toInt();
241 for (it = m_defaultWidgetOrder.begin(); it != m_defaultWidgetOrder.end(); ++it) {
243 TQString widgetName = *it;
244 TQWidget * w = m_widgets->find(widgetName);
249 TQString paletteName = *m_defaultMapping->find(widgetName);
250 KoPalette * p = m_palettes->find(paletteName);
257 p->plug(w, widgetName, -1);
258 m_widgetNames->append(widgetName);
259 m_currentMapping->insert(widgetName, paletteName);
265 TQDictIterator<KoPalette> it(*m_palettes);
266 for (; it.current(); ++it) {
267 it.current()->resetFont();
274 return m_widgets->find(name);
279 TQWidget * w = m_widgets->find(name);
282 TQString pname = *m_currentMapping->find(name);
283 if (pname.isNull())
return;
294 TQWidget * w = m_widgets->find(name);
297 TQString pname = *m_currentMapping->find(name);
298 if (pname.isNull())
return;
309 TQString palette = *(m_currentMapping->find(name));
310 if (palette.isNull())
return;
312 TQWidget * w = m_widgets->find(name);
315 KoPalette * p = m_palettes->find(palette);
320 m_widgets->remove(name);
321 m_currentMapping->remove(name);
324 m_viewActionMenu->remove(a);
325 m_actionCollection->
remove(a);
334 palette = m_palettes->find(name);
335 if (palette)
return palette;
339 case (PALETTE_DOCKER):
342 case (PALETTE_TOOLBOX):
350 if(!palette)
return 0;
353 palette->setFixedWidth(m_fixedWidth);
355 palette->setCaption(caption);
356 m_palettes->insert(name, palette);
364 Q_ASSERT(!name.isNull());
365 KoPalette * palette = m_palettes->find(name);
367 if (!palette)
return;
370 TDEConfig * cfg = TDEGlobal::config();
372 if (cfg->hasGroup(
"palette-" + name)) {
373 cfg->setGroup(
"palette-" + name);
374 TQString dockarea = cfg->readEntry(
"dockarea",
"right");
375 TQString caption = cfg->readEntry(
"caption",
"");
376 int height = cfg->readNumEntry(
"height", 120);
377 int place = cfg->readNumEntry(
"place", 0);
378 int width = cfg->readNumEntry(
"width", 200);
379 int x = cfg->readNumEntry(
"x", 0);
380 int y = cfg->readNumEntry(
"y", 0);
381 int offset = cfg->readNumEntry(
"offset", 0);
382 palette->setGeometry(x, y, width, height);
383 palette->setOffset(offset);
384 if (dockarea ==
"left" && place == 0) {
385 location = TQt::DockLeft;
387 else if (dockarea ==
"right" && place == 0) {
388 location = TQt::DockRight;
391 location = DockTornOff;
396 m_dockability = (enumKoDockability) cfg->readNumEntry(
"palettesdockability");
399 m_view->
mainWindow()->topDock()->setAcceptDockWindow(palette,
false);
400 m_view->
mainWindow()->bottomDock()->setAcceptDockWindow(palette,
false);
403 int h = tqApp->desktop()->height();
404 switch (m_dockability) {
406 m_view->
mainWindow()->leftDock()->setAcceptDockWindow(palette,
true);
407 m_view->
mainWindow()->rightDock()->setAcceptDockWindow(palette,
true);
408 m_view->
mainWindow()->addDockWindow(palette, location);
410 case (DOCK_DISABLED):
411 m_view->
mainWindow()->leftDock()->setAcceptDockWindow(palette,
false);
412 m_view->
mainWindow()->rightDock()->setAcceptDockWindow(palette,
false);
413 m_view->
mainWindow()->addDockWindow(palette, TQt::DockTornOff);
417 m_view->
mainWindow()->leftDock()->setAcceptDockWindow(palette,
true);
418 m_view->
mainWindow()->rightDock()->setAcceptDockWindow(palette,
true);
419 m_view->
mainWindow()->addDockWindow(palette, location);
422 m_view->
mainWindow()->leftDock()->setAcceptDockWindow(palette,
false);
423 m_view->
mainWindow()->rightDock()->setAcceptDockWindow(palette,
false);
424 m_view->
mainWindow()->addDockWindow(palette, TQt::DockTornOff);
434 Q_ASSERT(!name.isNull());
436 m_palettes->insert(name, palette);
440void KoPaletteManager::slotTogglePalette(
int paletteIndex)
443 TQString name = *m_widgetNames->at(paletteIndex);
444 TQWidget * w = m_widgets->find(name);
445 TQString pname = *m_currentMapping->find(name);
447 p->togglePageHidden( w );
449 m_hiddenWidgets.clear();
452void KoPaletteManager::slotToggleAllPalettes()
454 if( ! m_hiddenWidgets.isEmpty())
457 while(!m_hiddenWidgets.isEmpty())
459 TQString
name = m_hiddenWidgets.pop();
460 TQWidget *w = m_widgets->find(name);
464 TQString pname = *m_currentMapping->find(name);
472 m_hiddenWidgets.clear();
473 TQDictIterator<TQWidget> it(*m_widgets);
474 for (; it.current(); ++it)
480 m_hiddenWidgets.push(it.currentKey());
482 TQString pname = *m_currentMapping->find(it.currentKey());
484 p->hidePage(it.current());
490void KoPaletteManager::showAllPalettes(
bool shown)
492 TQDictIterator<KoPalette> it(*m_palettes);
493 for (; it.current(); ++it) {
494 it.current()->makeVisible(shown);
498bool KoPaletteManager::eventFilter( TQObject *o, TQEvent *e )
500 if (o != m_view)
return false;
502 if(e && e->type() == (TQEvent::User + 42)) {
504 if(pae && pae->widget() && pae->widget() == m_view) {
505 if (pae->activated()) {
506 showAllPalettes(
true );
509 showAllPalettes(
false );
518void KoPaletteManager::save()
532 TDEConfig * cfg = TDEGlobal::config();
539 TQDictIterator<KoPalette> itP(*m_palettes);
541 TQStringList paletteList;
543 for (; itP.current(); ++itP) {
547 cfg->setGroup(
"palette-" + itP.currentKey());
549 if ( p->area() == m_view->
mainWindow()->leftDock() ) {
550 cfg->writeEntry(
"dockarea",
"left");
553 cfg->writeEntry(
"dockarea",
"right");
555 cfg->writeEntry(
"place", p->place());
556 cfg->writeEntry(
"x", p->x());
557 cfg->writeEntry(
"y", p->y());
558 cfg->writeEntry(
"height", p->height());
559 cfg->writeEntry(
"width", p->width());
560 cfg->writeEntry(
"palettestyle", p->style());
561 cfg->writeEntry(
"caption", p->caption());
562 cfg->writeEntry(
"offset", p->offset());
566 if (paletteList.isEmpty()) {
567 paletteList.append(itP.currentKey());
570 TQStringList::iterator it;
571 bool inserted =
false;
572 for (it = paletteList.begin(); it != paletteList.end(); ++it) {
573 KoPalette * p2 = m_palettes->find((*it));
574 if (p2->y() > p->y()) {
575 paletteList.insert(it, itP.currentKey());
581 paletteList.append(itP.currentKey());
586 cfg->setGroup(
"palettes");
588 cfg->writeEntry(
"palettes", paletteList.join(
","));
589 bool palettesShown = m_hiddenWidgets.isEmpty();
590 cfg->writeEntry(
"palettesshown", palettesShown);
592 TQDictIterator<TQWidget> itW(*m_widgets);
593 for (; itW.current(); ++itW) {
594 cfg->setGroup(
"palettetab-" + itW.currentKey());
595 TQString pname = *m_currentMapping->find(itW.currentKey());
597 TQWidget * w = itW.current();
598 cfg->writeEntry(
"docker", pname);
601 cfg->writeEntry(
"visible", !p->isHidden(w));
603 if(m_hiddenWidgets.contains(itW.currentKey()))
604 cfg->writeEntry(
"visible",
true);
606 cfg->writeEntry(
"visible",
false);
613 m_setFixedWidth =
true;
616#include "kopalettemanager.moc"
virtual KoPalette * createPalette(const TQString &name, const TQString &caption, enumKoPaletteStyle style=PALETTE_DOCKER)
Create an empty palette in the given style.
virtual void addPalette(KoPalette *palette, const TQString &name, Dock location=DockRight)
Add a palette; this can be used to add palettes other than those in the two default styles.
virtual TQWidget * widget(const TQString &name)
Get a certain widget by name.
virtual void slotReset()
Restores the palette configuration to the default layout, i.e, the layout preferred by each docker.
virtual void addWidget(TQWidget *widget, const TQString &name, const TQString &paletteName, int position=-1, enumKoPaletteStyle style=PALETTE_DOCKER, bool shown=true)
Add a new tab with the given name an description to the specified palette.
virtual void slotResetFont()
Reset the font for all palettes.
virtual void removeWidget(const TQString &name)
Remove the widget with the specified name from whichever palette it is currently in.
virtual void hideWidget(const TQString &name)
hide the specified widget
virtual void showWidget(const TQString &name)
Show a the specified palette wherever it currently is.
virtual void placePalette(const TQString &name, Dock location=DockRight)
Move the specified palette to the specified location.
virtual void setFixedWidth(int w)
Sets all palettes to the specified fixed width.
A floating palette that allows the adding and removing of widgets to its organzing principle.
This is a palette with a tabwidget.
This class is used to display a KoDocument.
TDEMainWindow * mainWindow() const
void remove(TDEAction *action)
void setCheckedState(const KGuiItem &checkedItem)
virtual void setChecked(bool)
const char * name(StdAction id)