[rkward-cvs] SF.net SVN: rkward: [1510] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Feb 28 22:51:45 UTC 2007


Revision: 1510
          http://svn.sourceforge.net/rkward/?rev=1510&view=rev
Author:   tfry
Date:     2007-02-28 14:51:44 -0800 (Wed, 28 Feb 2007)

Log Message:
-----------
Add window history with simple back and forward actions.
Still needs icons, shortcuts, and stuff, but works in principle

Modified Paths:
--------------
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkwardui.rc
    trunk/rkward/rkward/windows/rkmdiwindow.cpp
    trunk/rkward/rkward/windows/rkmdiwindow.h
    trunk/rkward/rkward/windows/rkworkplace.cpp
    trunk/rkward/rkward/windows/rkworkplace.h

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/rkward.cpp	2007-02-28 22:51:44 UTC (rev 1510)
@@ -118,6 +118,14 @@
 	initActions();
 	initStatusBar();
 
+	KMdiChildView *dummy = new KMdiChildView (this);
+	QVBoxLayout *layout = new QVBoxLayout (dummy);
+	addWindow (dummy);
+	new RKWorkplace (dummy);
+	RKWorkplace::mainWorkplace ()->initActions (actionCollection (), "prev_window", "next_window");
+	layout->addWidget (RKWorkplace::mainWorkplace ()->view ());
+	connect (RKWorkplace::mainWorkplace ()->view (), SIGNAL (captionChanged (const QString &)), this, SLOT (setCaption (const QString &)));
+
 	///////////////////////////////////////////////////////////////////
 	// build the interface
 
@@ -141,13 +149,6 @@
 	connect (partManager (), SIGNAL (partAdded (KParts::Part *)), this, SLOT (partAdded (KParts::Part *)));
 	connect (partManager (), SIGNAL (partRemoved (KParts::Part *)), this, SLOT (partRemoved (KParts::Part *)));
 
-	KMdiChildView *dummy = new KMdiChildView (this);
-	QVBoxLayout *layout = new QVBoxLayout (dummy);
-	addWindow (dummy);
-	new RKWorkplace (dummy);
-	layout->addWidget (RKWorkplace::mainWorkplace ()->view ());
-	connect (RKWorkplace::mainWorkplace ()->view (), SIGNAL (captionChanged (const QString &)), this, SLOT (setCaption (const QString &)));
-
 	if (!kapp->dcopClient ()->isRegistered ()) {
 		kapp->dcopClient ()->registerAs ("rkward");
 		kapp->dcopClient ()->setDefaultObject (objId ());

Modified: trunk/rkward/rkward/rkwardui.rc
===================================================================
--- trunk/rkward/rkward/rkwardui.rc	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/rkwardui.rc	2007-02-28 22:51:44 UTC (rev 1510)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward" version="0.4.6">
+<kpartgui name="rkward" version="0.4.7">
 <MenuBar>
 	<Menu name="file"><text>&File</text>
 		<Menu name="new_data"><text>&New</text>
@@ -40,6 +40,9 @@
 		<Action name="window_close_all"/>
 		<Action name="close_all_editors"/>
 		<Separator/>
+		<Action name="next_window"/>
+		<Action name="prev_window"/>
+		<Separator/>
 		<Action name="window_detach"/>
 	</Menu>
 	

Modified: trunk/rkward/rkward/windows/rkmdiwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.cpp	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/windows/rkmdiwindow.cpp	2007-02-28 22:51:44 UTC (rev 1510)
@@ -111,12 +111,11 @@
 bool RKMDIWindow::eventFilter (QObject *watched, QEvent *e) {
 	//RK_TRACE (APP);
 
-#warning TODO
-// TODO: use partmanager's activePartChanged in rkward.cpp instead. There will have to be special handling in DetachedWindowContainer, anyway
 	RK_ASSERT (watched == getPart ());
 	if (KParts::PartActivateEvent::test (e)) {
 		KParts::PartActivateEvent *ev = static_cast<KParts::PartActivateEvent *> (e);
 		if (ev->activated ()) {
+			emit (windowActivated (this));
 			qDebug ("activated: %s", getDescription ().latin1 ());
 		} else {
 			qDebug ("deactivated: %s", getDescription ().latin1 ());

Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h	2007-02-28 22:51:44 UTC (rev 1510)
@@ -91,6 +91,8 @@
 /** This signal is emitted, whenever the window caption was changed.
 @param RKMDIWindow* a pointer to this window */
 	void captionChanged (RKMDIWindow *);
+/** This signal is emitted, when the window was activated *with* focus */
+	void windowActivated (RKMDIWindow *);
 protected:
 	void initializeActivationSignals ();
 friend class RKWorkplace;

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2007-02-28 22:51:44 UTC (rev 1510)
@@ -53,6 +53,7 @@
 
 	main_workplace = this;
 	wview = new RKWorkplaceView (parent);
+	history = new RKMDIWindowHistory (this);
 }
 
 RKWorkplace::~RKWorkplace () {
@@ -61,6 +62,12 @@
 //	closeAll ();	// not needed, as the windows will autodelete themselves using QObject mechanism. Of course, closeAll () should be called *before* quitting.
 }
 
+void RKWorkplace::initActions (KActionCollection *ac, const char *prev_id, const char *next_id) {
+	RK_TRACE (APP);
+
+	history->addActions (ac, prev_id, next_id);
+}
+
 void RKWorkplace::attachWindow (RKMDIWindow *window) {
 	RK_TRACE (APP);
 	RK_ASSERT (windows.find (window) != windows.end ());		// This should not happen for now.
@@ -98,6 +105,7 @@
 
 	windows.append (window);
 	connect (window, SIGNAL (destroyed (QObject *)), this, SLOT (windowDestroyed (QObject *)));
+	connect (window, SIGNAL (windowActivated(RKMDIWindow*)), history, SLOT (windowActivated(RKMDIWindow*)));
 	if (attached) attachWindow (window);
 	else detachWindow (window, false);
 }
@@ -391,4 +399,91 @@
 }
 
 
+///////////////////////// END RKWorkplace ////////////////////////////
+///////////////////// BEGIN RKMDIWindowHistory ///////////////////////
+
+RKMDIWindowHistory::RKMDIWindowHistory (QObject *parent) : QObject (parent) {
+	RK_TRACE (APP);
+
+	current = 0;
+	prev_action = next_action = 0;
+}
+
+RKMDIWindowHistory::~RKMDIWindowHistory () {
+	RK_TRACE (APP);
+}
+
+void RKMDIWindowHistory::addActions (KActionCollection *ac, const char *prev_id, const char *next_id) {
+	RK_TRACE (APP);
+
+	prev_action = new KAction (i18n ("Previous Window"), 0, 0, this, SLOT (prev ()), ac, prev_id);
+	next_action = new KAction (i18n ("Next Window"), 0, 0, this, SLOT (next ()), ac, next_id);
+	updateActions ();
+}
+
+void RKMDIWindowHistory::windowActivated (RKMDIWindow *window) {
+	RK_TRACE (APP);
+
+	if (!window) return;
+	if (window == current) return;
+
+	forward_list.clear ();
+	if (current) back_list.append (current);
+
+	current = window;
+	updateActions ();
+}
+
+void RKMDIWindowHistory::next () {
+	RK_TRACE (APP);
+
+	if (!haveNext ()) return;
+	back_list.append (current);
+	current = forward_list.first ();
+	forward_list.pop_front ();
+
+	updateActions ();
+
+	RK_ASSERT (current);
+	current->activate ();
+}
+
+void RKMDIWindowHistory::prev () {
+	RK_TRACE (APP);
+
+	if (!havePrev ()) return;
+	forward_list.push_front (current);
+	current = back_list.last ();
+	back_list.pop_back ();
+
+	updateActions ();
+
+	RK_ASSERT (current);
+	current->activate ();
+}
+
+bool RKMDIWindowHistory::haveNext () {
+	RK_TRACE (APP);
+
+	return (!forward_list.isEmpty ());
+}
+
+bool RKMDIWindowHistory::havePrev () {
+	RK_TRACE (APP);
+
+	return (!back_list.isEmpty ());
+}
+
+void RKMDIWindowHistory::updateActions () {
+	RK_TRACE (APP);
+
+	if (next_action) {
+		next_action->setEnabled (haveNext ());
+	}
+
+	if (prev_action) {
+		prev_action->setEnabled (havePrev ());
+	}
+}
+
 #include "rkworkplace.moc"

Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h	2007-02-28 19:06:33 UTC (rev 1509)
+++ trunk/rkward/rkward/windows/rkworkplace.h	2007-02-28 22:51:44 UTC (rev 1510)
@@ -31,7 +31,33 @@
 class RCommandChain;
 class RKWorkplaceView;
 class RKEditor;
+class KActionCollection;
+class KAction;
 
+/** Simple class to store the history of recently used RKMDIWindow */
+class RKMDIWindowHistory : public QObject {
+	Q_OBJECT
+public:
+	RKMDIWindowHistory (QObject *parent);
+	~RKMDIWindowHistory ();
+
+	void addActions (KActionCollection *ac, const char *prev_id, const char *next_id);
+	bool haveNext ();
+	bool havePrev ();
+public slots:
+	void next ();
+	void prev ();
+	void windowActivated (RKMDIWindow *window);
+private:
+	void updateActions ();
+
+	RKMDIWindow *current;
+	QValueList<RKMDIWindow *> back_list;
+	QValueList<RKMDIWindow *> forward_list;
+	KAction *next_action;
+	KAction *prev_action;
+};
+
 /** This class (only one instance will probably be around) keeps track of which windows are opened in the workplace, which are detached, etc. Also it is responsible for creating and manipulating those windows.
 It also provides a QWidget (RKWorkplace::view ()), which actually manages the document windows (only those, so far. I.e. this is a half-replacement for KMdi, which will be gone in KDE 4). Currently layout of the document windows is always tabbed. */
 class RKWorkplace : public QObject, public RCommandReceiver {
@@ -41,6 +67,7 @@
 @param parent: The parent widget for the workspace view (see view ()) */
 	explicit RKWorkplace (QWidget *parent);
 	~RKWorkplace ();
+	void initActions (KActionCollection *ac, const char *prev_id, const char *next_id);
 
 /** @returns a pointer to the view of the workplace. Since possibly the workplace layout might change, better not rely on this pointer being valid for long */
 	RKWorkplaceView *view () { return wview; };
@@ -141,6 +168,7 @@
 	static RKWorkplace *main_workplace;
 
 	void restoreWorkplaceItem (const QString &desc);
+	RKMDIWindowHistory *history;
 };
 
 #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