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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Nov 4 22:44:43 UTC 2007


Revision: 2176
          http://rkward.svn.sourceforge.net/rkward/?rev=2176&view=rev
Author:   tfry
Date:     2007-11-04 14:44:42 -0800 (Sun, 04 Nov 2007)

Log Message:
-----------
Save/restore toolwindow bar splitter sizes

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

Modified: branches/KDE4_port/rkward/robjectbrowser.h
===================================================================
--- branches/KDE4_port/rkward/robjectbrowser.h	2007-11-04 21:19:58 UTC (rev 2175)
+++ branches/KDE4_port/rkward/robjectbrowser.h	2007-11-04 22:44:42 UTC (rev 2176)
@@ -28,7 +28,6 @@
 class QRadioButton;
 class QCheckBox;
 class RObject;
-class RKCommandEditorWindow;
 class RObjectBrowserInternal;
 class KVBox;
 

Modified: branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp	2007-11-04 21:19:58 UTC (rev 2175)
+++ branches/KDE4_port/rkward/windows/rktoolwindowbar.cpp	2007-11-04 22:44:42 UTC (rev 2176)
@@ -35,22 +35,65 @@
 #include "../debug.h"
 
 #define CHANGE_ATTACHMENT_ACTION_ID 10
+#define DEFAULT_SPLITTER_SIZE 200
+#define SPLITTER_MIN_SIZE 10
 
 RKToolWindowBar::RKToolWindowBar (KMultiTabBarPosition position, QWidget *parent) : KMultiTabBar (position, parent),
 	container (0) {
 	RK_TRACE (APP);
 
 	setStyle (KMultiTabBar::KDEV3ICON);
+	initial_size = -1;
 }
 
 RKToolWindowBar::~RKToolWindowBar () {
 	RK_TRACE (APP);
 }
 
+void RKToolWindowBar::restoreSize (const KConfigGroup &cg) {
+	RK_TRACE (APP);
+
+	initial_size = cg.readEntry (QString ("view_size_%1").arg (position ()), DEFAULT_SPLITTER_SIZE);
+}
+
+void RKToolWindowBar::saveSize (KConfigGroup &cg) const {
+	RK_TRACE (APP);
+
+	int save_size = getSplitterSize ();
+	if (save_size >= SPLITTER_MIN_SIZE) {
+		cg.writeEntry (QString ("view_size_%1").arg (position ()), save_size);
+	}
+}
+
+int RKToolWindowBar::getSplitterSize () const {
+	RK_TRACE (APP);
+
+	int pos = splitter->indexOf (container);
+	if (pos < 0) {
+		RK_ASSERT (false);
+		return 0;
+	}
+	return (splitter->sizes ()[pos]);
+}
+
+void RKToolWindowBar::setSplitterSize (int new_size) {
+	RK_TRACE (APP);
+
+	int pos = splitter->indexOf (container);
+	if (pos < 0) {
+		RK_ASSERT (false);
+		return;
+	}
+	QList<int> sizes = splitter->sizes ();
+	sizes[pos] = new_size;
+	splitter->setSizes (sizes);
+}
+
 void RKToolWindowBar::setSplitter (QSplitter *splitter) {
 	RK_TRACE (APP);
 	RK_ASSERT (!container);
 
+	RKToolWindowBar::splitter = splitter;
 	container = new KHBox (splitter);
 	splitter->setContentsMargins (0, 0, 0, 0);
 	container->layout ()->setContentsMargins (0, 0, 0, 0);
@@ -126,7 +169,6 @@
 			if (cur->isAttached ()) {
 				cur->active = false;
 				cur->hide ();
-	
 			}
 			setTab (it.value (), false);
 		}
@@ -135,6 +177,13 @@
 	if (widget->isAttached ()) {
 		setTab (id, true);
 		container->show ();
+
+		if (initial_size >= 0) {	// first show
+			setSplitterSize (initial_size);
+			initial_size = -1;
+		} else if (getSplitterSize () < SPLITTER_MIN_SIZE) {
+			setSplitterSize (DEFAULT_SPLITTER_SIZE);
+		}
 	} else {
 		widget->topLevelWidget ()->show ();
 		widget->topLevelWidget ()->raise ();
@@ -177,7 +226,7 @@
 	}
 }
 
-RKMDIWindow* RKToolWindowBar::idToWidget (int id) {
+RKMDIWindow* RKToolWindowBar::idToWidget (int id) const {
 	RK_TRACE (APP);
 
 	for (QMap<RKMDIWindow*, int>::const_iterator it = widget_to_id.constBegin (); it != widget_to_id.constEnd (); ++it) {

Modified: branches/KDE4_port/rkward/windows/rktoolwindowbar.h
===================================================================
--- branches/KDE4_port/rkward/windows/rktoolwindowbar.h	2007-11-04 21:19:58 UTC (rev 2175)
+++ branches/KDE4_port/rkward/windows/rktoolwindowbar.h	2007-11-04 22:44:42 UTC (rev 2176)
@@ -21,6 +21,7 @@
 #define RKTOOLWINDOWBAR_H
 
 #include <kmultitabbar.h>
+#include <kconfiggroup.h>
 
 #include <QMap>
 
@@ -46,21 +47,28 @@
 
 	void showWidget (RKMDIWindow *widget);
 	void hideWidget (RKMDIWindow *widget);
+
+	void restoreSize (const KConfigGroup &cg);
+	void saveSize (KConfigGroup &cg) const;
 private slots:
 	void tabClicked (int id);
 	void buttonPopupActivate (QAction *a);
-
 protected:
 	bool eventFilter (QObject *obj, QEvent *ev);
 private:
 friend class RKWorkplace;
 	void reclaimDetached (RKMDIWindow *window);
 
+	int getSplitterSize () const;
+	void setSplitterSize (int new_size);
+
 	QMap<RKMDIWindow*, int> widget_to_id;
-	RKMDIWindow * idToWidget (int id);
+	RKMDIWindow* idToWidget (int id) const;
 
-	KHBox *container;
+	QSplitter* splitter;
+	KHBox* container;
 
+	int initial_size;
 	int id_of_popup;
 };
 

Modified: branches/KDE4_port/rkward/windows/rkworkplace.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkworkplace.cpp	2007-11-04 21:19:58 UTC (rev 2175)
+++ branches/KDE4_port/rkward/windows/rkworkplace.cpp	2007-11-04 22:44:42 UTC (rev 2176)
@@ -87,12 +87,20 @@
 	tool_window_bars[KMultiTabBar::Right] = new RKToolWindowBar (KMultiTabBar::Right, hbox);
 	tool_window_bars[KMultiTabBar::Right]->setSplitter (horiz_splitter);
 
+	KConfigGroup toolbar_config = KGlobal::config ()->group ("ToolwindowBars");
+	tool_window_bars[KMultiTabBar::Top]->restoreSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Left]->restoreSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Bottom]->restoreSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Right]->restoreSize (toolbar_config);
+
 	// now add it all to this widget
 	QVBoxLayout *box = new QVBoxLayout (this);
 	box->setContentsMargins (0, 0, 0, 0);
 	box->addWidget (vbox);
 
 	history = new RKMDIWindowHistory (this);
+
+	connect (RKWardMainWindow::getMain (), SIGNAL (aboutToQuitRKWard()), this, SLOT (saveSettings()));
 }
 
 RKWorkplace::~RKWorkplace () {
@@ -101,6 +109,16 @@
 //	closeAll ();	// not needed, as the windows will autodelete themselves using QObject mechanism. Of course, closeAll () should be called *before* quitting.
 }
 
+void RKWorkplace::saveSettings () {
+	RK_TRACE (APP);
+
+	KConfigGroup toolbar_config = KGlobal::config ()->group ("ToolwindowBars");
+	tool_window_bars[KMultiTabBar::Top]->saveSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Left]->saveSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Bottom]->saveSize (toolbar_config);
+	tool_window_bars[KMultiTabBar::Right]->saveSize (toolbar_config);
+}
+
 void RKWorkplace::initActions (KActionCollection *ac, const char *prev_id, const char *next_id, const char *left_id, const char *right_id) {
 	RK_TRACE (APP);
 

Modified: branches/KDE4_port/rkward/windows/rkworkplace.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkworkplace.h	2007-11-04 21:19:58 UTC (rev 2175)
+++ branches/KDE4_port/rkward/windows/rkworkplace.h	2007-11-04 22:44:42 UTC (rev 2176)
@@ -159,6 +159,7 @@
 public slots:
 /** When windows are attached to the workplace, their QObject::destroyed () signal is connected to this slot. Thereby deleted objects are removed from the workplace automatically */
 	void windowDestroyed (QObject *window);
+	void saveSettings ();
 protected:
 /** handles the result of the command issued in restoreWorkplace. */
 	void rCommandDone (RCommand *command);


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