[rkward-cvs] SF.net SVN: rkward: [2044] branches/KDE4_port/rkward/windows

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Oct 12 13:15:36 UTC 2007


Revision: 2044
          http://rkward.svn.sourceforge.net/rkward/?rev=2044&view=rev
Author:   tfry
Date:     2007-10-12 06:15:36 -0700 (Fri, 12 Oct 2007)

Log Message:
-----------
Start replacing the no longer available KMDI stuff

Modified Paths:
--------------
    branches/KDE4_port/rkward/windows/rkmdiwindow.cpp
    branches/KDE4_port/rkward/windows/rkmdiwindow.h
    branches/KDE4_port/rkward/windows/rkworkplace.cpp
    branches/KDE4_port/rkward/windows/rkworkplace.h

Added Paths:
-----------
    branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp
    branches/KDE4_port/rkward/windows/rktoolwindowbar.h

Modified: branches/KDE4_port/rkward/windows/rkmdiwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkmdiwindow.cpp	2007-10-08 18:03:25 UTC (rev 2043)
+++ branches/KDE4_port/rkward/windows/rkmdiwindow.cpp	2007-10-12 13:15:36 UTC (rev 2044)
@@ -42,7 +42,7 @@
 	}
 	RKMDIWindow::type = type;
 	state = Attached;
-	wrapper = 0;
+	tool_window_bar = 0;
 	part = 0;
 	active = false;
 }
@@ -83,18 +83,15 @@
 	// WORKAROUND for KMDI: it will always grab focus, so we need to make sure to release it again, if needed
 	QWidget *old_focus = qApp->focusWidget ();
 
-	if (isAttached ()) {
-		if (isToolWindow ()) {
-			RK_ASSERT (wrapper);
-			wrapper->show ();
-			wrapper->wrapperWidget ()->topLevelWidget ()->show ();
-			wrapper->wrapperWidget ()->topLevelWidget ()->raise ();
-		} else {
-			RKWorkplace::mainWorkplace ()->view ()->setActivePage (this);
-		}
+	if (isToolWindow ()) {
+		RK_ASSERT (tool_window_bar);
+		tool_window_bar->showWidget (this);
 	} else {
-		topLevelWidget ()->show ();
-		topLevelWidget ()->raise ();
+		if (isAttached ()) RKWorkplace::mainWorkplace ()->view ()->setActivePage (this);
+		else {
+			topLevelWidget ()->show ();
+			topLevelWidget ()->raise ();
+		}
 	}
 
 	if (with_focus) {
@@ -115,8 +112,8 @@
 			RKWorkplace::mainWorkplace ()->attachWindow (this);
 		}
 
-		RK_ASSERT (wrapper);
-		wrapper->hide ();
+		RK_ASSERT (tool_window_bar);
+		tool_window_bar->hideWidget (this);
 		return true;
 	}
 
@@ -126,18 +123,14 @@
 void RKMDIWindow::prepareToBeAttached () {
 	RK_TRACE (APP);
 
-	if (isToolWindow ()) {
-		static_cast<KDockWidget *>(wrapper->wrapperWidget ())->setWidget (this);
-		wrapper->show ();
-	}
+	// TODO: KDE4 do we still need this?
 }
 
 void RKMDIWindow::prepareToBeDetached () {
 	RK_TRACE (APP);
 
-	if (isToolWindow ()) {
-		wrapper->hide ();
-	}
+
+	// TODO: KDE4 do we still need this?
 }
 
 bool RKMDIWindow::eventFilter (QObject *watched, QEvent *e) {
@@ -162,19 +155,6 @@
 			}
 			update ();
 		}
-	} else {
-		RK_ASSERT (isToolWindow ());
-		if (watched == wrapper->wrapperWidget ()) {
-			// don't show the wrapper if detached. Instead, show this window.
-			if (e->type () == QEvent::Show) {
-				if (!isAttached ()) {
-					// calling hide() on the wrapper directly is unsafe for some obscure reason
-					QTimer::singleShot (0, wrapper, SLOT (hide()));
-					activate (true);
-					return true;
-				}
-			}
-		}
 	}
 	return false;
 }
@@ -183,7 +163,6 @@
 	// called very often. Don't trace
 
 	if (object == getPart ()) return true;
-	if (isToolWindow () && (object == wrapper->wrapperWidget ())) return true;
 	return false;
 }
 
@@ -210,14 +189,6 @@
 	}
 }
 
-void RKMDIWindow::setToolWrapper (KMdiToolViewAccessor *wrapper_widget) {
-	RK_TRACE (APP);
-
-	wrapper = wrapper_widget;
-	wrapper->wrapperWidget ()->installEventFilter (this);
-	static_cast<KDockWidget *> (wrapper->wrapperWidget ())->setEnableDocking (KDockWidget::DockFullSite);
-}
-
 void RKMDIWindow::windowActivationChange (bool) {
 	RK_TRACE (APP);
 

Modified: branches/KDE4_port/rkward/windows/rkmdiwindow.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkmdiwindow.h	2007-10-08 18:03:25 UTC (rev 2043)
+++ branches/KDE4_port/rkward/windows/rkmdiwindow.h	2007-10-12 13:15:36 UTC (rev 2044)
@@ -25,9 +25,9 @@
 #include <QPaintEvent>
 
 #include <kparts/part.h>
-#include <k3mdimainfrm.h>
 
 class RKWorkplace;
+class RKToolWindowBar;
 
 /** Base class for rkward document mdi windows */
 class RKMDIWindow : public Q3Frame {
@@ -91,8 +91,7 @@
 	virtual void prepareToBeDetached ();
 /** Tool windows will only hide themselves, and ignore the also_delete flag */
 	virtual bool close (bool also_delete);
-/** For tool windows only (and perhaps for KDE3 only): set the wrapper widget that should be shown/raised on activation */
-	void setToolWrapper (KMdiToolViewAccessor *wrapper_widget);
+
 	bool eventFilter (QObject *watched, QEvent *e);
 	bool acceptsEventsFor (QObject *object);
 /** Whether the window is active. This seems to be more reliable than hasFocus () */
@@ -112,10 +111,11 @@
 /** type of this window */
 	int type;
 private:
+friend class RKToolWindowBar;
 /** state of this window (attached / detached). This is usually set from the RKWorkplace */
 	KParts::Part *part;
 	State state;
-	KMdiToolViewAccessor *wrapper;
+	RKToolWindowBar *tool_window_bar;
 	bool active;
 };
 

Added: branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp	                        (rev 0)
+++ branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp	2007-10-12 13:15:36 UTC (rev 2044)
@@ -0,0 +1,228 @@
+/***************************************************************************
+                          rktoolwindowbar  -  description
+                             -------------------
+    begin                : Fri Oct 12 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+/* This code is based substantially on kate's katemdi! */
+
+#include "rktoolwindowbar.h"
+
+#include "../debug.h"
+
+#define CHANGE_ATTACHMENT_ACTION_ID 10
+
+RKToolWindowBar::RKToolWindowBar (KMultiTabBarPosition position, QWidget *parent) : KMultiTabBar (position, parent),
+	container (0) {
+	RK_TRACE (APP);
+}
+
+RKToolWindowBar::~RKToolWindowBar () {
+	RK_TRACE (APP);
+}
+
+void RKToolWindowBar::setSplitter (QSplitter *splitter) {
+	RK_TRACE (APP);
+	RK_ASSERT (!container);
+
+	container = new KHBox (splitter);
+	container->layout ()->setSpacing (0);
+	container->layout ()->setMargin (0);
+	container->hide ();
+}
+
+void RKToolWindowBar::addWidget (const QPixmap &icon, const QString &text, RKMDIWindow *widget) {
+	RK_TRACE (APP);
+	RK_ASSERT (window);
+	RK_ASSERT (container);
+
+	if (window->toolWindowBar ()) {
+		RK_ASSERT (window->toolWindowBar () != this);	// no problem, but would be useless code
+		window->toolWindowBar ()->removeWidget (widget);
+	}
+
+	int id = appendTab (widget->windowIcon (), widget->shortCaption (), widget);
+
+	widget->tool_window_bar = this;
+	widget_to_id.insert (widget, id);
+
+	connect (tab(int), SIGNAL (clicked(int)), this, SLOT (tabClicked(int)));
+	tab (int)->installEventFilter (this);
+
+	if (widget->isAttached ()) {
+		widget->hide();
+		widget->setParent (container);
+	}
+
+	show ();
+}
+
+void RKToolWindowBar::removeWidget (RKMDIWindow *widget) {
+	RK_TRACE (APP);
+	RK_ASSERT (widget_to_id.contains[widget]);
+
+	int id = widget_to_id[widget];
+	bool was_active_in_bar = isTabRaised (id);
+
+	removeTab (id);
+	widget_to_id.remove (widget);
+	widget->tool_window_bar = 0;
+
+	if (was_active_in_bar) {
+		RK_ASSERT (widget->isAttached ());
+		container->hide ();
+		widget->active = false;
+	}
+	if (widget_to_id.isEmpty ()) hide ();
+}
+
+void RKToolWindowBar::showWidget (RKMDIWindow *widget) {
+	RK_TRACE (APP);
+	RK_ASSERT (widget_to_id.contains[widget]);
+
+	int id = widget_to_id[widget];
+
+	// close any others
+	QMap<RKMDIWindow*, int>::const_iterator it = widget_to_id.constBegin ();
+	while (it != widget_to_id.constEnd()) {
+		RKMDIWindow *cur = it.key ();
+		if (cur != widget) {
+			if (cur->isAttached ()) {
+				cur->active = false;
+				cur->hide ();
+	
+			}
+			setTab (it.value (false));
+		}
+	}
+
+	if (widget->isAttached ()) {
+		setTab (id);
+		container->show ();
+	} else {
+		widget->topLevelWidget ()->show ();
+		widget->topLevelWidget ()->raise ();
+	}
+	widget->active = true;
+	widget->show ();
+}
+
+void RKToolWindowBar::hideWidget (RKMDIWindow *widget) {
+	RK_TRACE (APP);
+	RK_ASSERT (widget_to_id.contains[widget]);
+
+	// prevent recursion
+	if (!widget->active) return;
+	int id = widget_to_id[widget];
+
+	bool was_active_in_bar = widget->isTabRaised (id);
+	if (was_active_in_bar) {
+		RK_ASSERT (window->isAttached ());
+		container->hide ();
+	}
+
+	widget->active = false;
+	widget->close (false);
+
+	setTab (id, false);
+
+	RKWorkplace::mainWorkplace ()->view ()->setFocus ();
+}
+
+void RKToolWindowBar::tabClicked (int id) {
+	RK_TRACE (APP);
+
+	RKMDIWindow widget = idToWidget (id);
+	RK_ASSERT (widget);
+
+	if (widget->isActive ()) {
+		widget->close ();
+	} else {
+		widget->activate (true);
+	}
+}
+
+RKToolWindowBar::RKMDIWindow * idToWidget (int id) {
+	RK_TRACE (APP);
+
+	RKMDIWindow widget = 0;
+	QMap<RKMDIWindow*, int>::const_iterator it = widget_to_id.constBegin ();
+	while (it != widget_to_id.constEnd()) {
+		if (it.value () == id) {
+			return (it.key ());
+		}
+	}
+}
+
+bool RKToolWindowBar::eventFilter (QObject *obj, QEvent *ev) {
+	if (ev->type() == QEvent::ContextMenu) {
+		RK_TRACE (APP);
+
+		QContextMenuEvent *e = (QContextMenuEvent *) ev;
+		KMultiTabBarTab *bt = dynamic_cast<KMultiTabBarTab*>(obj);
+
+		if (bt) {
+			id_of_popup = bt->id ();
+
+			RKMDIWindow widget = idToWidget (id);
+			RK_ASSERT (widget);
+			if (widget) {
+				KMenu *p = new KMenu (this);
+
+				p->addTitle (SmallIcon("view_remove"), i18n("Attachment"));
+				
+				p->addAction (widget->isAttached () ? KIcon("view-restore") : KIcon("view-fullscreen"), w->isAttached () ? i18n("Detach") : i18n("Attach"))->setData (CHANGE_ATTACHMENT_ACTION_ID);
+
+				p->addTitle (SmallIcon("move"), i18n("Move To"));
+	
+				if (position () != KMultiTabBar::Left) p->addAction(KIcon("go-previous"), i18n("Left Sidebar"))->setData(KMultiTabBar::Left);
+	
+				if (position () != KMultiTabBar::Right) p->addAction(KIcon("go-next"), i18n("Right Sidebar"))->setData(KMultiTabBar::Right);
+				if (position () != KMultiTabBar::Top) p->addAction(KIcon("go-up"), i18n("Top Sidebar"))->setData(KMultiTabBar::Top);
+				if (position () != KMultiTabBar::Bottom) p->addAction(KIcon("go-down"), i18n("Bottom Sidebar"))->setData(KMultiTabBar::Bottom);
+	
+				connect (p, SIGNAL (triggered(QAction *)), this, SLOT (buttonPopupActivate(QAction *)));
+				p->exec (e->globalPos());
+				delete p;
+	
+				return true;
+			}
+		}
+	}
+	
+	return false;
+}
+
+void RKToolWindowBar::buttonPopupActivate (QAction *a) {
+	RK_TRACE (APP);
+
+	int id = a->data().toInt();
+	RKMDIWindow *window = idToWidget[id];
+	RK_ASSERT (window);
+
+	// move to another bar
+	if (id < 4) {
+		// move + show ;)
+		RKWorkplace::mainWorkplace ()->placeInToolWindowBar (window, (KMultiTabBar::KMultiTabBarPosition) id);
+		window->activate ();
+	}
+
+	// toggle attachment
+	if (id == CHANGE_ATTACHMENT_ACTION_ID) {
+		if (window->isAttached ()) RKWorkplace::mainWorkplace ()->detachWindow (window);
+		else RKWorkplace::mainWorkplace ()->attachWindow (window);
+	}
+}
+
+#include "rktoolwindowbar.moc"

Added: branches/KDE4_port/rkward/windows/rktoolwindowbar.h
===================================================================
--- branches/KDE4_port/rkward/windows/rktoolwindowbar.h	                        (rev 0)
+++ branches/KDE4_port/rkward/windows/rktoolwindowbar.h	2007-10-12 13:15:36 UTC (rev 2044)
@@ -0,0 +1,65 @@
+/***************************************************************************
+                          rktoolwindowbar  -  description
+                             -------------------
+    begin                : Fri Oct 12 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+/* This code is based substantially on kate's katemdi! */
+
+#ifndef RKTOOLWINDOWBAR_H
+#define RKTOOLWINDOWBAR_H
+
+#include <KMultiTabBar>
+
+#include <QMap>
+
+class QSplitter;
+class QObject;
+class QEvent;
+class QAction;
+class KHBox;
+
+/** This class represents one of the bar which tool windows can dock into (top, left, bottom, right). It contains heavy copying from Kate's katemdi SideBar class. I wish this was available as a library, but it isn't, yet.
+
+Some more would need to be copied for full functionality (session saving / restoring), but for now, I focussed on the bare essentials */
+class RKToolWindowBar : public KMultiTabBar {
+	Q_OBJECT
+public:
+	RKToolWindowBar (KMultiTabBar::KMultiTabBarPosition position, QWidget *parent);
+	~RKToolWindowBar ();
+
+	void setSplitter (QSplitter *splitter);
+	void addWidget (RKMDIWindow *widget);
+	void removeWidget (RKMDIWindow *widget);
+
+	void showWidget (RKMDIWindow *widget);
+	void hideWidget (RKMDIWindow *widget);
+
+private slots:
+	void tabClicked (int id);
+	void buttonPopupActivate (QAction *a);
+
+protected:
+	bool eventFilter (QObject *obj, QEvent *ev);
+
+private:
+	QMap<RKMDIWindow*, int> widget_to_id;
+	RKMDIWindow * idToWidget (int id);
+
+	KHBox *container;
+
+	int id_of_popup;
+};
+
+#endif

Modified: branches/KDE4_port/rkward/windows/rkworkplace.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkworkplace.cpp	2007-10-08 18:03:25 UTC (rev 2043)
+++ branches/KDE4_port/rkward/windows/rkworkplace.cpp	2007-10-12 13:15:36 UTC (rev 2044)
@@ -21,11 +21,14 @@
 #include <kmessagebox.h>
 #include <klocale.h>
 #include <kiconloader.h>
+#include <KHBox>
+#include <KVBox>
 
 #include "detachedwindowcontainer.h"
 #include "rkcommandeditorwindow.h"
 #include "rkhtmlwindow.h"
 #include "rkworkplaceview.h"
+#include "rktoolwindowbar.h"
 #include "../core/robject.h"
 #include "../core/rcontainerobject.h"
 #include "../core/robjectlist.h"
@@ -54,7 +57,40 @@
 	RK_ASSERT (main_workplace == 0);
 
 	main_workplace = this;
-	wview = new RKWorkplaceView (parent);
+
+	/* Splitter setup contains heavy copying from Kate's katemdi! */
+	hbox = new KHBox (this);
+	setCentralWidget (hbox);
+	tool_window_bars[KMultiTabBar::Left] = new RKToolWindowBar (KMultiTabBar::Left, hbox);
+
+	horiz_splitter = new QSplitter (Qt::Horizontal, hbox);
+	horiz_splitter->setOpaqueResize (KGlobalSettings::opaqueResize ());
+
+	tool_window_bars[KMultiTabBar::Left]->setSplitter (horiz_splitter);
+
+	KVBox *vbox = new KVBox (horiz_splitter);
+	horiz_splitter->setCollapsible (horiz_splitter->indexOf (vbox), false);
+	horiz_splitter->setStretchFactor (horiz_splitter->indexOf (vbox), 1);
+
+	tool_window_bars[KMultiTabBar::Top] = new RKToolWindowBar (KMultiTabBar::Top, vbox);
+	vert_splitter = new QSplitter (Qt::Vertical, vbox);
+	vert_splitter->setOpaqueResize (KGlobalSettings::opaqueResize ());
+
+	tool_window_bars[KMultiTabBar::Top]->setSplitter (vert_splitter);
+	wview = new RKWorkplaceView (vert_splitter);
+	wview->layout ()->setSpacing (0);
+	wview->layout ()->setMargin (0);
+
+	vert_splitter->setCollapsible (vert_splitter->indexOf (wview), false);
+	vert_splitter->setStretchFactor(vert_splitter->indexOf (wview), 1);
+
+	tool_window_bars[KMultiTabBar::Bottom] = new RKToolWindowBar (KMultiTabBar::Bottom, vbox);
+	tool_window_bars[KMultiTabBar::Bottom]->setSplitter (vert_splitter);
+
+	tool_window_bars[KMultiTabBar::Right] = new RKToolWindowBar (KMultiTabBar::Right, hbox);
+	tool_window_bars[KMultiTabBar::Right]->setSplitter (horiz_splitter);
+
+
 	history = new RKMDIWindowHistory (this);
 }
 
@@ -117,6 +153,12 @@
 	else detachWindow (window, false);
 }
 
+void RKWorkplace::placeInToolWindowBar (RKMDIWindow *window, KMultiTabBar::KMultiTabBarPosition position) {
+	RK_TRACE (APP);
+
+	tool_window_bars[position]->addWidget (window);
+}
+
 void RKWorkplace::registerToolWindow (RKMDIWindow *window) {
 	RK_TRACE (APP);
 

Modified: branches/KDE4_port/rkward/windows/rkworkplace.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkworkplace.h	2007-10-08 18:03:25 UTC (rev 2043)
+++ branches/KDE4_port/rkward/windows/rkworkplace.h	2007-10-12 13:15:36 UTC (rev 2044)
@@ -21,6 +21,7 @@
 #include <q3valuelist.h>
 #include <qstring.h>
 #include <qtabwidget.h>
+#include <QSplitter>
 
 #include <kurl.h>
 
@@ -33,6 +34,7 @@
 class RKEditor;
 class KActionCollection;
 class KAction;
+class RKToolWindowBar;
 
 /** Simple class to store the history of recently used RKMDIWindow */
 class RKMDIWindowHistory : public QObject {
@@ -149,6 +151,7 @@
 /** In the current design there is only ever one workplace. Use this static function to reference it.
 @returns a pointer to the workplace */
 	static RKWorkplace *mainWorkplace () { return main_workplace; };
+	void placeInToolWindowBar (RKMDIWindow *window, KMultiTabBar::KMultiTabBarPosition position);
 	void registerToolWindow (RKMDIWindow *window);
 signals:
 /** TODO: For future expansion. This signal is neither emitted nor used so far. It could be used to deactivate some options in the "Window" menu. Or maybe it can be removed? */
@@ -173,6 +176,11 @@
 
 	void restoreWorkplaceItem (const QString &desc);
 	RKMDIWindowHistory *history;
+
+	QSplitter horiz_splitter;
+	QSplitter vert_splitter;
+
+	RKToolWindowBar* tool_window_bars[4];
 };
 
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list