summaryrefslogtreecommitdiffstats
path: root/lib/kopalette
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kopalette
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kopalette')
-rw-r--r--lib/kopalette/Makefile.am25
-rw-r--r--lib/kopalette/kopalette.cc91
-rw-r--r--lib/kopalette/kopalette.h75
-rw-r--r--lib/kopalette/kopalettemanager.cc616
-rw-r--r--lib/kopalette/kopalettemanager.h223
-rw-r--r--lib/kopalette/kotabpalette.cc136
-rw-r--r--lib/kopalette/kotabpalette.h64
-rw-r--r--lib/kopalette/kotoolboxpalette.cc121
-rw-r--r--lib/kopalette/kotoolboxpalette.h56
9 files changed, 1407 insertions, 0 deletions
diff --git a/lib/kopalette/Makefile.am b/lib/kopalette/Makefile.am
new file mode 100644
index 000000000..ad9a29e02
--- /dev/null
+++ b/lib/kopalette/Makefile.am
@@ -0,0 +1,25 @@
+# all_includes must remain last!
+INCLUDES = -I$(srcdir) \
+ $(KOFFICECORE_INCLUDES) \
+ $(all_includes)
+
+lib_LTLIBRARIES = libkopalette.la
+
+libkopalette_la_SOURCES = \
+ kopalette.cc \
+ kopalettemanager.cc \
+ kotoolboxpalette.cc \
+ kotabpalette.cc
+
+libkopalette_la_LDFLAGS = -version-info 1:0:0 -no-undefined $(all_libraries)
+libkopalette_la_LIBADD = $(LIB_KOFFICECORE)
+
+include_HEADERS = \
+ kopalettemanager.h
+
+noinst_HEADERS = \
+ kopalette.h \
+ kotabpalette.h \
+ kotoolboxpalette.h
+
+METASOURCES = AUTO
diff --git a/lib/kopalette/kopalette.cc b/lib/kopalette/kopalette.cc
new file mode 100644
index 000000000..67fcf4748
--- /dev/null
+++ b/lib/kopalette/kopalette.cc
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <qwidget.h>
+#include <qdockwindow.h>
+#include <qvariant.h>
+#include <qlabel.h>
+#include <qtoolbutton.h>
+#include <qtabwidget.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+#include <qimage.h>
+#include <qpixmap.h>
+#include <qlayout.h>
+
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kglobalsettings.h>
+#include <kaccelmanager.h>
+#include <kconfig.h>
+
+#include <KoView.h>
+
+#include "kopalette.h"
+
+KoPalette::KoPalette(QWidget * parent, const char * name)
+ : QDockWindow(parent, name)
+{
+
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,90)
+ KAcceleratorManager::setNoAccel(this);
+#endif
+ setCloseMode( QDockWindow::Never);
+ setResizeEnabled(true);
+ setOpaqueMoving(true);
+ setFocusPolicy(QWidget::NoFocus);
+ setVerticallyStretchable(false);
+ setHorizontallyStretchable(false);
+
+ setNewLine(true);
+ layout() -> setSpacing(0);
+ layout() -> setMargin(0);
+
+ resetFont();
+}
+
+void KoPalette::resetFont()
+{
+
+ KConfig * cfg = KGlobal::config();
+ Q_ASSERT(cfg);
+ cfg->setGroup("");
+ m_font = KGlobalSettings::generalFont();
+ float ps = QMIN(9, KGlobalSettings::generalFont().pointSize() * 0.8);
+ ps = cfg->readNumEntry("palettefontsize", (int)ps);
+ if (ps < 6) ps = 6;
+ m_font.setPointSize((int)ps);
+ setFont(m_font);
+
+}
+
+KoPalette::~KoPalette()
+{
+}
+
+void KoPalette::setMainWidget(QWidget * widget)
+{
+ setWidget(widget);
+ resize( QSize(285, 233).expandedTo(minimumSizeHint()) );
+ clearWState( WState_Polished );
+ widget->setFont(m_font);
+ m_page = widget;
+}
+
+#include "kopalette.moc"
diff --git a/lib/kopalette/kopalette.h b/lib/kopalette/kopalette.h
new file mode 100644
index 000000000..8c7a1f98a
--- /dev/null
+++ b/lib/kopalette/kopalette.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _KO_PALETTE_
+#define _KO_PALETTE_
+
+#include <qdockwindow.h>
+#include <qwidget.h>
+#include <qlabel.h>
+#include <qtoolbutton.h>
+#include <qpixmap.h>
+#include <qstring.h>
+#include <qfont.h>
+#include <qlayout.h>
+#include <koffice_export.h>
+
+#include "kopalettemanager.h"
+/**
+ * A floating palette that allows the adding and removing of widgets
+ * to its organzing principle.
+ *
+ * There is currently no titlebar with a shade button; I hope to be
+ * able to use QDockWidget's toggle view action for that.
+ */
+class KOPALETTE_EXPORT KoPalette : public QDockWindow {
+
+Q_OBJECT
+
+public:
+
+ KoPalette(QWidget * parent, const char * name);
+ virtual ~KoPalette();
+
+public:
+
+ virtual void resetFont();
+
+ void setStyle(enumKoPaletteStyle style) { m_style = style; };
+ enumKoPaletteStyle style() { return m_style; };
+
+ virtual void plug(QWidget * widget, const QString & name, int position) = 0;
+ virtual void unplug(const QWidget * widget) = 0;
+ virtual void showPage(QWidget *w) = 0;
+ virtual void togglePageHidden(QWidget *w) = 0;
+ virtual void hidePage(QWidget * w) = 0;
+ virtual void makeVisible(bool v) = 0;
+ virtual bool isHidden(QWidget * w) = 0;
+ virtual int indexOf(QWidget *w) = 0;
+
+protected:
+
+ virtual void setMainWidget(QWidget * widget);
+ QFont m_font;
+ enumKoPaletteStyle m_style;
+
+private:
+ QWidget * m_page;
+
+};
+
+#endif //_KO_PALETTE_
diff --git a/lib/kopalette/kopalettemanager.cc b/lib/kopalette/kopalettemanager.cc
new file mode 100644
index 000000000..e028a7aef
--- /dev/null
+++ b/lib/kopalette/kopalettemanager.cc
@@ -0,0 +1,616 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <qapplication.h>
+#include <qdockarea.h>
+#include <qdockwindow.h>
+#include <qdict.h>
+#include <qwidget.h>
+#include <qobject.h>
+#include <qevent.h>
+
+#include <kparts/event.h>
+#include <kapplication.h>
+#include <kpopupmenu.h>
+#include <kaction.h>
+#include <kactionclasses.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include <KoView.h>
+#include <KoMainWindow.h>
+
+#include <kopalette.h>
+#include <kotabpalette.h>
+#include <kotoolboxpalette.h>
+
+#include <kopalettemanager.h>
+
+
+KoPaletteManager::KoPaletteManager(KoView * view, KActionCollection *ac, const char * name)
+ : QObject(view, name)
+{
+
+ m_view = view;
+ m_view->installEventFilter(this);
+ m_actionCollection = ac;
+
+ m_actions = new QDict<KToggleAction>();
+ m_widgets = new QDict<QWidget>();
+ m_palettes = new QDict<KoPalette>();
+ m_palettes->setAutoDelete(true);
+ m_defaultMapping = new QMap<QString, QString>();
+ m_currentMapping = new QMap<QString, QString>();
+ m_fixedWidth = 0;
+ m_setFixedWidth = false;
+
+ m_widgetNames = new QStringList();
+
+ m_mapper = new QSignalMapper(this);
+ connect(m_mapper, SIGNAL(mapped(int)), this, SLOT(slotTogglePalette(int)));
+ m_viewActionMenu = new KActionMenu(i18n("Palettes"), m_actionCollection, "view_palette_action_menu");
+
+ KConfig * cfg = KGlobal::config();
+ cfg->setGroup("palettes");
+
+ bool palettesShown = cfg->readBoolEntry("palettesshown", true);
+ KToggleAction * m_toggleShowHidePalettes;
+
+ if ( palettesShown) {
+ m_toggleShowHidePalettes = new KToggleAction(i18n("Hide All Palette Windows"),
+ "CTRL+SHIFT+H", this,
+ SLOT(slotToggleAllPalettes()),
+ m_actionCollection, "toggleAllPaletteWindows");
+
+ m_toggleShowHidePalettes->setCheckedState(i18n("Show Palette Windows Again"));
+ }
+ else {
+ m_toggleShowHidePalettes = new KToggleAction(i18n("Show Palette Windows Again"),
+ "CTRL+SHIFT+H", this,
+ SLOT(slotToggleAllPalettes()),
+ m_actionCollection, "toggleAllPaletteWindows");
+
+ m_toggleShowHidePalettes->setCheckedState(i18n("Hide All Palette Windows"));
+ }
+ m_viewActionMenu->insert(m_toggleShowHidePalettes);
+
+ // Recreate the palettes in the saved order
+ QStringList paletteList = QStringList::split(",", cfg->readEntry("palettes"));
+ QStringList::iterator it;
+ for (it = paletteList.begin(); it != paletteList.end(); ++it) {
+ if (cfg->hasGroup("palette-" + (*it))) {
+
+ cfg->setGroup("palette-" + (*it));
+
+ enumKoPaletteStyle style = (enumKoPaletteStyle)cfg->readNumEntry("style", 0);
+ QString caption = cfg->readEntry("caption", "");
+
+ createPalette((*it), caption, style);
+ }
+ }
+
+/*
+ KAction * a = new KAction(i18n("Restore Palettes"),
+ 0, this,
+ SLOT(slotReset()),
+ this, "restorePalettes");
+ m_viewActionMenu->insert(a);
+*/
+ m_viewActionMenu->popupMenu()->insertSeparator();
+}
+
+
+KoPaletteManager::~KoPaletteManager()
+{
+ save();
+
+ delete m_viewActionMenu;
+ delete m_widgetNames;
+ delete m_widgets;
+ delete m_palettes;
+ delete m_actions;
+ delete m_mapper;
+ delete m_defaultMapping;
+ delete m_currentMapping;
+}
+
+void KoPaletteManager::addWidget(QWidget * widget,
+ const QString & name,
+ const QString & paletteName,
+ int position,
+ enumKoPaletteStyle style,
+ bool shown)
+{
+
+ if (!widget) return;
+
+ QString pname = paletteName;
+
+ QWidget * w = m_widgets->find(name);
+ if (w != 0 )
+ {
+ removeWidget(name);
+ }
+
+ bool visible = true;
+
+ KConfig * cfg = KGlobal::config();
+ if (cfg->hasGroup("palettetab-" + name)) {
+ cfg->setGroup("palettetab-" + name);
+
+ pname = cfg->readEntry("docker");
+ visible = cfg->readBoolEntry("visible");
+ }
+
+ KoPalette * palette = m_palettes->find(pname);
+
+ if (palette == 0) {
+ palette = createPalette(pname, widget->caption(), style);
+ m_defaultPaletteOrder.append(pname+ "," + QString::number(style));
+ }
+
+ KToggleAction * a;
+ a = new KToggleAction(i18n("Show %1").arg(widget->caption()), 0, m_mapper, SLOT(map()), m_actionCollection);
+ a->setCheckedState(i18n("Hide %1").arg(widget->caption()));
+
+ m_mapper->setMapping(a, m_widgetNames->count()); // This is the position at which we'll insert the action
+ m_actions->insert( name, a );
+ m_viewActionMenu->insert(a);
+
+ palette->plug(widget, name, position);
+
+ m_widgets->insert(name, widget);
+
+ // Default mappings ready for restoring
+ m_defaultMapping->insert(name, pname);
+ m_defaultWidgetOrder.append(name);
+
+ // Find out the hidden state
+ if(m_widgetNames->contains(name))
+ {
+
+ // The widget has already been added (and removed) during this session
+ if(m_hiddenWidgets.contains(name))
+ palette->hidePage( widget );
+ else
+ {
+ a->setChecked(true);
+ palette->showPage( widget );
+ }
+ }
+ else
+ {
+ cfg->setGroup("palettes");
+ if( cfg->readBoolEntry("palettesshown", shown))
+ {
+ if (visible)
+ {
+ a->setChecked(true);
+ palette->showPage( widget );
+ }
+ else
+ palette->hidePage( widget );
+ }
+ else
+ {
+ if (visible)
+ m_hiddenWidgets.push(name);
+ palette->hidePage( widget );
+ }
+ }
+
+ // Fill the current mappings
+ m_widgetNames->append(name);
+ m_currentMapping->insert(name, pname);
+}
+
+
+void KoPaletteManager::slotReset()
+{
+ // Clear all old palettes
+ m_palettes->setAutoDelete( true );
+ m_palettes->clear();
+
+ m_widgetNames->clear();
+
+ // Recreate the palettewindows in the saved order
+ QStringList::iterator it;
+ for (it = m_defaultPaletteOrder.begin(); it != m_defaultPaletteOrder.end(); ++it) {
+ QString s = *it;
+ QString pname = s.section( ",", 0, 0 );;
+ enumKoPaletteStyle style = (enumKoPaletteStyle)s.section(",", 1,1).toInt();
+ createPalette(pname, "", style);
+ }
+
+ // Place all existing (that we didn't throw away!) tabs in the right palette and in the right order
+ for (it = m_defaultWidgetOrder.begin(); it != m_defaultWidgetOrder.end(); ++it) {
+
+ QString widgetName = *it;
+ QWidget * w = m_widgets->find(widgetName);
+
+ if (!w) {
+ continue;
+ }
+ QString paletteName = *m_defaultMapping->find(widgetName);
+ KoPalette * p = m_palettes->find(paletteName);
+
+ if (p == 0) {
+ // Funny -- we should have a consistent set of palettes without holes!
+ createPalette(paletteName, "", PALETTE_DOCKER);
+ }
+
+ p->plug(w, widgetName, -1); // XXX: This is not good: we should add it in the same place as originally placed
+ m_widgetNames->append(widgetName);
+ m_currentMapping->insert(widgetName, paletteName);
+ }
+}
+
+void KoPaletteManager::slotResetFont()
+{
+ QDictIterator<KoPalette> it(*m_palettes);
+ for (; it.current(); ++it) {
+ it.current()->resetFont();
+ }
+
+}
+
+QWidget * KoPaletteManager::widget(const QString & name)
+{
+ return m_widgets->find(name);
+}
+
+void KoPaletteManager::showWidget(const QString & name)
+{
+ QWidget * w = m_widgets->find(name);
+ if (!w) return;
+
+ QString pname = *m_currentMapping->find(name);
+ if (pname.isNull()) return;
+
+ KoPalette * p = m_palettes->find(pname);
+ p->showPage(w);
+
+ KToggleAction * a = m_actions->find(name);
+ a->setChecked(true);
+}
+
+void KoPaletteManager::hideWidget(const QString & name)
+{
+ QWidget * w = m_widgets->find(name);
+ if (!w) return;
+
+ QString pname = *m_currentMapping->find(name);
+ if (pname.isNull()) return;
+
+ KoPalette * p = m_palettes->find(pname);
+ p->hidePage(w);
+
+ KToggleAction * a = m_actions->find(name);
+ a->setChecked(false);
+}
+
+void KoPaletteManager::removeWidget(const QString & name)
+{
+ QString palette = *(m_currentMapping->find(name));
+ if (palette.isNull()) return;
+
+ QWidget * w = m_widgets->find(name);
+ if (!w) return;
+
+ KoPalette * p = m_palettes->find(palette);
+ if (!p) return;
+
+ p->showPage(w);
+ p->unplug(w);
+ m_widgets->remove(name);
+ m_currentMapping->remove(name);
+
+ KAction * a = m_actions->take(name);
+ m_viewActionMenu->remove(a);
+ m_actionCollection->remove(a);
+}
+
+KoPalette * KoPaletteManager::createPalette(const QString & name, const QString & caption, enumKoPaletteStyle style)
+{
+ Q_ASSERT(m_view);
+ KoPalette * palette = 0;
+
+
+ palette = m_palettes->find(name);
+ if (palette) return palette;
+
+
+ switch (style) {
+ case (PALETTE_DOCKER):
+ palette = new KoTabPalette(m_view, name.latin1());
+ break;
+ case (PALETTE_TOOLBOX):
+ palette = new KoToolBoxPalette(m_view, name.latin1());
+ break;
+ default:
+ // This is a custom palette that we cannot create
+ return 0;
+ };
+
+ if(!palette) return 0;
+
+ if (m_setFixedWidth)
+ palette->setFixedWidth(m_fixedWidth);
+
+ palette->setCaption(caption);
+ m_palettes->insert(name, palette);
+ placePalette(name);
+
+ return palette;
+}
+
+void KoPaletteManager::placePalette(const QString & name, Qt::Dock location)
+{
+ Q_ASSERT(!name.isNull());
+ KoPalette * palette = m_palettes->find(name);
+
+ if (!palette) return;
+
+ //XXX: Check whether this name occurs in the config list, retrieve the location, set the location
+ KConfig * cfg = KGlobal::config();
+
+ if (cfg->hasGroup("palette-" + name)) {
+ cfg->setGroup("palette-" + name);
+ QString dockarea = cfg->readEntry("dockarea", "right");
+ QString caption = cfg->readEntry("caption", "");
+ int height = cfg->readNumEntry("height", 120);
+ int place = cfg->readNumEntry("place", 0);
+ int width = cfg->readNumEntry("width", 200);
+ int x = cfg->readNumEntry("x", 0);
+ int y = cfg->readNumEntry("y", 0);
+ int offset = cfg->readNumEntry("offset", 0);
+ palette->setGeometry(x, y, width, height);
+ palette->setOffset(offset);
+ if (dockarea == "left" && place == 0) {
+ location = Qt::DockLeft;
+ }
+ else if (dockarea == "right" && place == 0) {
+ location = Qt::DockRight;
+ }
+ else {
+ location = DockTornOff;
+ }
+ }
+
+ cfg->setGroup("");
+ m_dockability = (enumKoDockability) cfg->readNumEntry("palettesdockability");
+
+ // Top and bottom will never accept docks
+ m_view->mainWindow()->topDock()->setAcceptDockWindow(palette, false);
+ m_view->mainWindow()->bottomDock()->setAcceptDockWindow(palette, false);
+
+ // Left and right may accept docks. The height of the screen is important
+ int h = qApp->desktop()->height();
+ switch (m_dockability) {
+ case (DOCK_ENABLED):
+ m_view->mainWindow()->leftDock()->setAcceptDockWindow(palette, true);
+ m_view->mainWindow()->rightDock()->setAcceptDockWindow(palette, true);
+ m_view->mainWindow()->addDockWindow(palette, location);
+ break;
+ case (DOCK_DISABLED):
+ m_view->mainWindow()->leftDock()->setAcceptDockWindow(palette, false);
+ m_view->mainWindow()->rightDock()->setAcceptDockWindow(palette, false);
+ m_view->mainWindow()->addDockWindow(palette, Qt::DockTornOff);
+ break;
+ case (DOCK_SMART):
+ if (h > 768) {
+ m_view->mainWindow()->leftDock()->setAcceptDockWindow(palette, true);
+ m_view->mainWindow()->rightDock()->setAcceptDockWindow(palette, true);
+ m_view->mainWindow()->addDockWindow(palette, location);
+ }
+ else {
+ m_view->mainWindow()->leftDock()->setAcceptDockWindow(palette, false);
+ m_view->mainWindow()->rightDock()->setAcceptDockWindow(palette, false);
+ m_view->mainWindow()->addDockWindow(palette, Qt::DockTornOff);
+ }
+ break;
+ };
+ m_view->mainWindow()->lineUpDockWindows();
+}
+
+void KoPaletteManager::addPalette(KoPalette * palette, const QString & name, Qt::Dock location)
+{
+ Q_ASSERT(palette);
+ Q_ASSERT(!name.isNull());
+
+ m_palettes->insert(name, palette);
+ placePalette(name, location);
+}
+
+void KoPaletteManager::slotTogglePalette(int paletteIndex)
+{
+ // Toggle the right palette
+ QString name = *m_widgetNames->at(paletteIndex);
+ QWidget * w = m_widgets->find(name);
+ QString pname = *m_currentMapping->find(name);
+ KoPalette * p = m_palettes->find(pname);
+ p->togglePageHidden( w );
+
+ m_hiddenWidgets.clear();
+}
+
+void KoPaletteManager::slotToggleAllPalettes()
+{
+ if( ! m_hiddenWidgets.isEmpty())
+ {
+ // Restore previous visibility state
+ while(!m_hiddenWidgets.isEmpty())
+ {
+ QString name = m_hiddenWidgets.pop();
+ QWidget *w = m_widgets->find(name);
+ KToggleAction * a = m_actions->find(name);
+ a->setChecked(true);
+
+ QString pname = *m_currentMapping->find(name);
+ KoPalette * p = m_palettes->find(pname);
+ p->showPage(w);
+ }
+ }
+ else
+ {
+ // Save hidden state and hide all palettes
+ m_hiddenWidgets.clear();
+ QDictIterator<QWidget> it(*m_widgets);
+ for (; it.current(); ++it)
+ {
+ KToggleAction * a = m_actions->find(it.currentKey());
+ if(a->isChecked())
+ {
+ a->setChecked(false);
+ m_hiddenWidgets.push(it.currentKey());
+
+ QString pname = *m_currentMapping->find(it.currentKey());
+ KoPalette * p = m_palettes->find(pname);
+ p->hidePage(it.current());
+ }
+ }
+ }
+}
+
+void KoPaletteManager::showAllPalettes(bool shown)
+{
+ QDictIterator<KoPalette> it(*m_palettes);
+ for (; it.current(); ++it) {
+ it.current()->makeVisible(shown);
+ }
+}
+
+bool KoPaletteManager::eventFilter( QObject *o, QEvent *e )
+{
+ if (o != m_view) return false;
+
+ if(e && e->type() == (QEvent::User + 42)) {
+ KParts::PartActivateEvent * pae = dynamic_cast<KParts::PartActivateEvent *>(e);
+ if(pae && pae->widget() && pae->widget() == m_view) {
+ if (pae->activated()) {
+ showAllPalettes( true );
+ }
+ else {
+ showAllPalettes( false );
+ }
+ }
+ }
+ return false;
+}
+
+
+
+void KoPaletteManager::save()
+{
+ // XXX: Save to the configuration
+ // We save:
+ // * which tab at which place in which palette
+ // * which tab is hidden
+ // * whether a palette is floating or docked
+ // * dock location of a docked palette
+ // * float location of a floated palette
+ // * order in which the palettes are docked.
+
+ if (!m_view) return;
+ if (!m_view->mainWindow()) return;
+
+ KConfig * cfg = KGlobal::config();
+ Q_ASSERT(cfg);
+ cfg->setGroup("");
+
+ QString widgets;
+
+ // Save the list of palettes
+ QDictIterator<KoPalette> itP(*m_palettes);
+
+ QStringList paletteList;
+
+ for (; itP.current(); ++itP) {
+
+ KoPalette * p = itP.current();
+
+ cfg->setGroup("palette-" + itP.currentKey());
+
+ if ( p->area() == m_view->mainWindow()->leftDock() ) {
+ cfg->writeEntry("dockarea", "left");
+ }
+ else {
+ cfg->writeEntry("dockarea", "right");
+ }
+ cfg->writeEntry("place", p->place());
+ cfg->writeEntry("x", p->x());
+ cfg->writeEntry("y", p->y());
+ cfg->writeEntry("height", p->height());
+ cfg->writeEntry("width", p->width());
+ cfg->writeEntry("palettestyle", p->style());
+ cfg->writeEntry("caption", p->caption());
+ cfg->writeEntry("offset", p->offset());
+
+ // XXX: I dare say that it is immediately visible that I never have had
+ // any formal training in algorithms. BSAR.
+ if (paletteList.isEmpty()) {
+ paletteList.append(itP.currentKey());
+ }
+ else {
+ QStringList::iterator it;
+ bool inserted = false;
+ for (it = paletteList.begin(); it != paletteList.end(); ++it) {
+ KoPalette * p2 = m_palettes->find((*it));
+ if (p2->y() > p->y()) {
+ paletteList.insert(it, itP.currentKey());
+ inserted = true;
+ break;
+ }
+ }
+ if (!inserted) {
+ paletteList.append(itP.currentKey());
+ }
+ }
+ }
+
+ cfg->setGroup("palettes");
+
+ cfg->writeEntry("palettes", paletteList.join(","));
+ bool palettesShown = m_hiddenWidgets.isEmpty();
+ cfg->writeEntry("palettesshown", palettesShown);
+
+ QDictIterator<QWidget> itW(*m_widgets);
+ for (; itW.current(); ++itW) {
+ cfg->setGroup("palettetab-" + itW.currentKey());
+ QString pname = *m_currentMapping->find(itW.currentKey());
+ KoPalette * p = m_palettes->find(pname);
+ QWidget * w = itW.current();
+ cfg->writeEntry("docker", pname);
+
+ if(palettesShown)
+ cfg->writeEntry("visible", !p->isHidden(w));
+ else
+ if(m_hiddenWidgets.contains(itW.currentKey()))
+ cfg->writeEntry("visible", true);
+ else
+ cfg->writeEntry("visible", false);
+ }
+}
+
+void KoPaletteManager::setFixedWidth(int w)
+{
+ m_fixedWidth = w;
+ m_setFixedWidth = true;
+}
+
+#include "kopalettemanager.moc"
diff --git a/lib/kopalette/kopalettemanager.h b/lib/kopalette/kopalettemanager.h
new file mode 100644
index 000000000..977dbf552
--- /dev/null
+++ b/lib/kopalette/kopalettemanager.h
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _KO_PALETTE_MANAGER_
+#define _KO_PALETTE_MANAGER_
+
+#include <qobject.h>
+#include <qdockwindow.h>
+#include <qstring.h>
+#include <qmap.h>
+#include <qdict.h>
+#include <qvaluestack.h>
+#include <qwidget.h>
+#include <qsignalmapper.h>
+#include <qstringlist.h>
+
+#include <koffice_export.h>
+
+#include <KoView.h>
+
+class KoPalette;
+class KActionMenu;
+class KAction;
+class KActionCollection;
+class KToggleAction;
+
+enum enumKoDockability {
+ DOCK_ENABLED = 0, // It's possible to dock the dockers
+ DOCK_DISABLED = 1, // The dockers cannot be docked
+ DOCK_SMART = 2 // On small screens, don't dock, else dock, initially
+};
+
+enum enumKoPaletteStyle {
+ PALETTE_DOCKER, // QDockWindow based docker with tabs
+ PALETTE_TOOLBOX // QDockWindow based docker with a QToolBox
+};
+
+
+namespace {
+ struct DockerRecord {
+ int position;
+ int x;
+ int y;
+ int w;
+ int h;
+ };
+}
+
+/**
+ * Manages the set of dockwindow palettes and their widgets.
+ *
+ * You create one palette manager per view; then you can add widgets
+ * to your hearts content. Widgets are grouped into dock windows by
+ * palette names. To see the menu entries, add a the following line
+ * to your .rc file:
+ *
+ * <Action name="view_palette_action_menu"/>
+ *
+ * There are two styles: one that uses tabs and one that uses the vertical
+ * QToolBox style to separate and show individual widgets. By implementing
+ * the kopalette interface and extending the above enum, you can add
+ * more types.
+ *
+ * TODO:
+ * - Drag & Drop
+ * - Restore order of tabs in a docker
+ * - Set initial position of floating dockers on first startup
+ * - Restoration of the application default state
+ * - Make it impossible to close a floating palette window with alt-f4
+ */
+class KOPALETTE_EXPORT KoPaletteManager : public QObject {
+
+ Q_OBJECT
+
+
+public:
+
+ KoPaletteManager(KoView * view, KActionCollection * ac, const char * name);
+ virtual ~KoPaletteManager();
+
+public:
+
+ /**
+ * Add a new tab with the given name an description to the specified palette.
+ * The widget's caption is used, where necessary. If there is no
+ * palette with this name, a new palette is created with the given palette name
+ * and the widget's caption.
+ *
+ * If there is already a widget with the given name, that widget will be
+ * unplugged (but not destroyed) and the given widget will be plugged in place.
+ *
+ * If the widget occurs in the saved configuration, it is not added to the
+ * specified palette, but in the place where it was left.
+ *
+ * @param widget the widget that will be inserted as a tab or entry in the palette
+ * @param name the name under which the palette will be stored. Not the caption -- do not i18n this.
+ * @param paletteName the unique name of the palette this widget will be a child of. If the palette already exists, the current widget is added to it.
+ * @param position the position of the widget in the palettes
+ * @param style docker, toolbox or slider
+ */
+ virtual void addWidget(QWidget * widget, const QString & name, const QString & paletteName, int position = -1,
+ enumKoPaletteStyle style = PALETTE_DOCKER, bool shown = true);
+
+
+ /**
+ * Get a certain widget by name
+ */
+ virtual QWidget * widget(const QString & name);
+
+ /**
+ * Show a the specified palette wherever it currently is.
+ */
+ virtual void showWidget(const QString & name);
+
+ /**
+ * hide the specified widget
+ */
+ virtual void hideWidget(const QString & name);
+
+ /**
+ * Remove the widget with the specified name from whichever
+ * palette it is currently in. If it is the last widget in
+ * the palette, the palette is destroyed. If the name does
+ * not occur, nothing is done.
+ */
+ virtual void removeWidget(const QString & name);
+
+
+ /**
+ * Create an empty palette in the given style. with the given name and caption. If
+ * the palette already exists, nothing is done.
+ */
+ virtual KoPalette * createPalette(const QString & name, const QString & caption, enumKoPaletteStyle style = PALETTE_DOCKER);
+
+ /**
+ * Move the specified palette to the specified location. If there is already
+ * a location for the palette in the saved settings, then move it there
+ * instead of the specified location.
+ */
+ virtual void placePalette(const QString & name, Dock location = DockRight);
+
+ /**
+ * Add a palette; this can be used to add palettes other than those in the two
+ * default styles.
+ */
+ virtual void addPalette(KoPalette * palette, const QString & name, Dock location = DockRight);
+
+ /**
+ * Sets all palettes to the specified fixed width
+ */
+ virtual void setFixedWidth(int w);
+
+public slots:
+
+ void slotTogglePalette(int paletteIndex);
+ void slotToggleAllPalettes();
+ void showAllPalettes(bool shown);
+
+ /**
+ * Restores the palette configuration to the default layout, i.e, the layout
+ * preferred by each docker.
+ */
+ virtual void slotReset();
+
+ /**
+ * Reset the font for all palettes
+ */
+ virtual void slotResetFont();
+
+
+protected:
+
+ bool eventFilter( QObject *o, QEvent *e );
+
+private:
+
+
+ /**
+ * Saves the current palette configuration to the application config object.
+ */
+ virtual void save();
+
+
+private:
+
+ KoView * m_view;
+ KActionCollection * m_actionCollection;
+ KActionMenu * m_viewActionMenu;
+ KToggleAction * m_toggleShowHidePalettes;
+ enumKoDockability m_dockability;
+
+ QStringList * m_widgetNames;
+
+ QDict<QWidget> * m_widgets;
+ QDict<KoPalette> * m_palettes;
+ QValueStack<QString> m_hiddenWidgets; // names of widgets actively hidden by hide all
+ QDict<KToggleAction> * m_actions;
+ QSignalMapper * m_mapper;
+
+ QMap<QString, QString> * m_defaultMapping; // widget to docker
+ QStringList m_defaultPaletteOrder; // Order of palette creation
+ QStringList m_defaultWidgetOrder; // Order of widget addition
+ QMap<QString, QString> * m_currentMapping; // widget to docker
+
+ bool m_setFixedWidth;
+ int m_fixedWidth;
+};
+
+#endif
diff --git a/lib/kopalette/kotabpalette.cc b/lib/kopalette/kotabpalette.cc
new file mode 100644
index 000000000..3da34e581
--- /dev/null
+++ b/lib/kopalette/kotabpalette.cc
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#include <qdockwindow.h>
+
+#include <ktabwidget.h>
+#include <kdebug.h>
+
+#include <KoView.h>
+
+#include <kopalette.h>
+#include <kotabpalette.h>
+#include "kopalettemanager.h"
+
+KoTabPalette::KoTabPalette(QWidget * parent, const char * name)
+ : KoPalette(parent, name)
+{
+ m_page = new KTabWidget(this);
+ m_page->setTabShape(QTabWidget::Triangular);
+ m_page->setFocusPolicy(QWidget::TabFocus);
+ //m_page->setFont(m_font);
+ m_page->setMargin(1);
+ //m_page->setTabReorderingEnabled(true);
+ setMainWidget(m_page);
+ m_style = PALETTE_DOCKER;
+}
+
+KoTabPalette::~KoTabPalette()
+{
+}
+
+void KoTabPalette::plug(QWidget * w, const QString & /*name*/, int position)
+{
+ if (!w) return;
+
+ w -> unsetFont(); // Use the parent font
+
+ m_page -> insertTab(w, w -> caption(), position);
+ show();
+}
+
+void KoTabPalette::resetFont()
+{
+ KoPalette::resetFont();
+ m_page->unsetFont();
+}
+
+void KoTabPalette::unplug(const QWidget * w)
+{
+ m_page->removePage(const_cast<QWidget *>(w));
+ if (m_page->count() == 0)
+ hide();
+}
+
+void KoTabPalette::showPage(QWidget *w)
+{
+ m_page->showPage(w);
+ if (m_hiddenPages.find(w) == m_hiddenPages.end()) return;
+
+ int i = *m_hiddenPages.find(w);
+ m_page->insertTab(w, w->caption(), i);
+ m_hiddenPages.erase(w);
+ show();
+}
+
+void KoTabPalette::makeVisible(bool v)
+{
+ //kdDebug() << "make visible called for " << name() << ", " << v << "\n";
+ if (v && m_page->count() > 0)
+ show();
+ else
+ hide();
+}
+
+int KoTabPalette::indexOf(QWidget *w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) {
+ int i = m_page->indexOf(w);
+ return -i;
+ }
+ else {
+ return m_page->indexOf(w);
+ }
+}
+
+bool KoTabPalette::isHidden(QWidget * w)
+{
+ return (m_hiddenPages.find(w) != m_hiddenPages.end());
+}
+
+void KoTabPalette::hidePage( QWidget *w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) return;
+
+ int i = m_page->indexOf(w);
+ m_page->removePage(w);
+ m_hiddenPages[w] = i;
+ if (m_page->count() == 0) {
+ hide();
+ }
+}
+
+void KoTabPalette::togglePageHidden(QWidget *w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) {
+ int i = *m_hiddenPages.find(w);
+ m_page->insertTab(w, w->caption(), i);
+ m_hiddenPages.erase(w);
+ show();
+ }
+ else {
+ int i = m_page->indexOf(w);
+ m_page->removePage(w);
+ m_hiddenPages[w] = i;
+ if (m_page->count() == 0) {
+ hide();
+ }
+ }
+}
+
+#include "kotabpalette.moc"
diff --git a/lib/kopalette/kotabpalette.h b/lib/kopalette/kotabpalette.h
new file mode 100644
index 000000000..85ff086a5
--- /dev/null
+++ b/lib/kopalette/kotabpalette.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _KO_TAB_PALETTE_
+#define _KO_TAB_PALETTE_
+
+#include <qdockwindow.h>
+#include <ktabwidget.h>
+
+#include "kopalette.h"
+
+class KoView;
+class QWidget;
+
+
+
+/**
+ * This is a palette with a tabwidget. It supports
+ * reorganzing the pages and moving the pages to other
+ * palettes with drag and drop,
+ *
+ */
+class KoTabPalette : public KoPalette {
+
+Q_OBJECT
+
+public:
+
+ KoTabPalette(QWidget * parent, const char * name);
+ virtual ~KoTabPalette();
+
+public:
+ virtual void resetFont();
+ virtual void plug(QWidget * widget, const QString & name, int position = -1);
+ virtual void unplug(const QWidget * widget);
+ void showPage(QWidget *w);
+ void makeVisible(bool v);
+ virtual void hidePage(QWidget * w);
+ int indexOf(QWidget *w);
+ bool isHidden(QWidget *w);
+ virtual void togglePageHidden(QWidget *w);
+
+private:
+
+ KTabWidget * m_page;
+
+ QMap<QWidget*, int> m_hiddenPages;
+};
+
+#endif //_KO_TAB_PALETTE_
diff --git a/lib/kopalette/kotoolboxpalette.cc b/lib/kopalette/kotoolboxpalette.cc
new file mode 100644
index 000000000..12dbee550
--- /dev/null
+++ b/lib/kopalette/kotoolboxpalette.cc
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ */
+
+
+#include <qdockwindow.h>
+#include <qtoolbox.h>
+
+#include <kopalette.h>
+#include <kopalettemanager.h>
+#include <kotoolboxpalette.h>
+
+KoToolBoxPalette::KoToolBoxPalette(QWidget * parent, const char * name)
+ : KoPalette(parent, name)
+{
+ m_page = new QToolBox(this);
+ m_page->unsetFont();
+ setMainWidget(m_page);
+ m_style = PALETTE_TOOLBOX;
+}
+
+KoToolBoxPalette::~KoToolBoxPalette()
+{
+}
+
+
+void KoToolBoxPalette::resetFont()
+{
+ KoPalette::resetFont();
+ m_page->unsetFont();
+}
+
+
+void KoToolBoxPalette::plug(QWidget *w, const QString & label, int position)
+{
+ w->unsetFont();
+ m_page->insertItem( position, w, label );
+}
+
+
+void KoToolBoxPalette::unplug(const QWidget *w)
+{
+ m_page->removeItem( const_cast<QWidget*>(w) );
+}
+
+void KoToolBoxPalette::showPage(QWidget *w)
+{
+ m_page->setCurrentItem( w );
+}
+
+
+int KoToolBoxPalette::indexOf(QWidget *w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) {
+ return m_page->indexOf(w);
+ }
+ else {
+ return m_page->indexOf(w);
+ }
+}
+
+
+void KoToolBoxPalette::makeVisible(bool v)
+{
+ if (v && m_page->count() > 0) {
+ show();
+ }
+ else {
+ hide();
+ }
+}
+
+bool KoToolBoxPalette::isHidden(QWidget * w)
+{
+ return (m_hiddenPages.find(w) != m_hiddenPages.end());
+}
+
+void KoToolBoxPalette::togglePageHidden(QWidget *w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) {
+ int i = *m_hiddenPages.find(w);
+ m_page->insertItem(i, w, w->caption());
+ show();
+ }
+ else {
+ int i = m_page->indexOf(w);
+ m_page->removeItem(w);
+ m_hiddenPages[w] = i;
+ if (m_page->count() == 0) {
+ hide();
+ }
+ }
+
+}
+
+void KoToolBoxPalette::hidePage( QWidget * w)
+{
+ if (m_hiddenPages.find(w) != m_hiddenPages.end()) return;
+ int i = m_page->indexOf(w);
+ m_page->removeItem(w);
+ m_hiddenPages[w] = i;
+ if (m_page->count() == 0) {
+ hide();
+ }
+}
+
+#include "kotoolboxpalette.moc"
diff --git a/lib/kopalette/kotoolboxpalette.h b/lib/kopalette/kotoolboxpalette.h
new file mode 100644
index 000000000..5b5fa9916
--- /dev/null
+++ b/lib/kopalette/kotoolboxpalette.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
+ *
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2, as published by the Free Software Foundation.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _KO_TOOLBOX_PALETTE_
+#define _KO_TOOLBOX_PALETTE_
+
+#include <qdockwindow.h>
+#include <qtoolbox.h>
+
+#include <kopalettemanager.h>
+
+/**
+ * A palette based on a toolbox widget. This does not support drag and drop
+ * configuration of palette widgets
+ */
+class KoToolBoxPalette : public KoPalette {
+
+Q_OBJECT
+
+public:
+
+ KoToolBoxPalette(QWidget * parent, const char * name);
+ ~KoToolBoxPalette();
+
+public:
+ void resetFont();
+ virtual void plug(QWidget * widget, const QString & name, int position = INT_MAX);
+ virtual void unplug(const QWidget * widget);
+ void showPage(QWidget *w);
+ void makeVisible(bool v);
+ virtual void hidePage(QWidget * w);
+ int indexOf(QWidget *w);
+ bool isHidden(QWidget *w);
+ void togglePageHidden(QWidget *w);
+private:
+
+ QToolBox * m_page;
+
+ QMap<QWidget*, int> m_hiddenPages;
+};
+
+#endif //_KO_TOOLBOX_PALETTE_