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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun May 2 10:24:30 UTC 2010


Revision: 2856
          http://rkward.svn.sourceforge.net/rkward/?rev=2856&view=rev
Author:   tfry
Date:     2010-05-02 10:24:30 +0000 (Sun, 02 May 2010)

Log Message:
-----------
Add basic context menu to main window tab bar

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/windows/rkworkplaceview.cpp
    trunk/rkward/rkward/windows/rkworkplaceview.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-05-01 19:39:35 UTC (rev 2855)
+++ trunk/rkward/ChangeLog	2010-05-02 10:24:30 UTC (rev 2856)
@@ -1,5 +1,6 @@
 TODO: Do not use SmartInterface for KDE 4.5 and above
 
+- The tabbar in the main window now shows a context menu with options to close/detach a window
 - The tabs in the main window can now be re-ordered by dragging with the mouse (left click if compiled with Qt 4.5 or above, middle click for earlier versions)
 - Add alternating row backgrounds in data.frame-editor
 

Modified: trunk/rkward/rkward/windows/rkworkplaceview.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplaceview.cpp	2010-05-01 19:39:35 UTC (rev 2855)
+++ trunk/rkward/rkward/windows/rkworkplaceview.cpp	2010-05-02 10:24:30 UTC (rev 2856)
@@ -25,6 +25,7 @@
 #include <kicon.h>
 #include <kdeversion.h>
 #include <kacceleratormanager.h>
+#include <kmenu.h>
 
 #include <qapplication.h>
 #include <qevent.h>
@@ -32,6 +33,8 @@
 #include <QToolButton>
 
 #include "rkmdiwindow.h"
+#include "rkworkplace.h"
+#include "../misc/rkstandardicons.h"
 
 #include "../debug.h"
 
@@ -62,6 +65,9 @@
 	setTabReorderingEnabled (true);	// the KDE function is deprecated sind Qt 4.5 / KDE 4.4
 #endif
 
+	tabBar ()->setContextMenuPolicy (Qt::CustomContextMenu);
+	connect (tabBar (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (showContextMenu(const QPoint&)));
+
 	KAcceleratorManager::setNoAccel (tabBar ());	// TODO: This is a WORKAROUND for a bug in kdelibs where tabs named "a0.txt", "a1.txt", etc. will steal the Alt+0/1... shortcuts
 	setTabBarHidden (true);		// initially
 	connect (this, SIGNAL (currentChanged(int)), this, SLOT (currentPageChanged(int)));
@@ -204,6 +210,50 @@
 	closePage (widget (page));
 }
 
+void RKWorkplaceView::showContextMenu (const QPoint &pos) {
+	RK_TRACE (APP);
+
+	int tab = tabBar ()->tabAt (pos);
+	if (tab < 0) return;	// no context menu for the empty area
+
+	KMenu* m = new KMenu (this);
+	QAction *action = KStandardAction::close (this, SLOT (contextMenuClosePage()), this);
+	action->setData (tab);
+	m->addAction (action);
+	action = m->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionDetachWindow), i18n("Detach"), this, SLOT (contextMenuDetachWindow()));
+	action->setData (tab);
+	m->exec (mapToGlobal (pos));
+	delete m;
+}
+
+void RKWorkplaceView::contextMenuClosePage () {
+	RK_TRACE (APP);
+
+	QAction* action = dynamic_cast<QAction*> (sender ());
+	if (!action) {
+		RK_ASSERT (false);
+		return;
+	}
+
+	int tab = action->data ().toInt ();
+	RK_ASSERT (tab >= 0);
+	closePage (tab);
+}
+
+void RKWorkplaceView::contextMenuDetachWindow () {
+	RK_TRACE (APP);
+
+	QAction* action = dynamic_cast<QAction*> (sender ());
+	if (!action) {
+		RK_ASSERT (false);
+		return;
+	}
+
+	int tab = action->data ().toInt ();
+	RK_ASSERT (tab >= 0);
+	RKWorkplace::mainWorkplace ()->detachWindow (static_cast<RKMDIWindow*> (widget (tab)));
+}
+
 void RKWorkplaceView::childCaptionChanged (RKMDIWindow *widget) {
 	RK_TRACE (APP);
 

Modified: trunk/rkward/rkward/windows/rkworkplaceview.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplaceview.h	2010-05-01 19:39:35 UTC (rev 2855)
+++ trunk/rkward/rkward/windows/rkworkplaceview.h	2010-05-02 10:24:30 UTC (rev 2856)
@@ -24,9 +24,7 @@
 class KAction;
 class KActionCollection;
 
-/** The widget containing all the MDI document windows. Right now it mostly acts as a QTabWidget (is not one, as unfortunately, QTabWidget always has a sunken frame), but might be extended to allow switching between different view modes
-
-KDE4 TODO: We now use KTabWidget natively, hoping, we can avoid the sunken frame problem somehow. We may need to revisit this decision, later. TODO cleanup
+/** This is mostly a KTabWidget with some extras such as updating the caption, a context menu, etc.
  */
 
 class RKWorkplaceView : public KTabWidget {
@@ -60,7 +58,16 @@
 /** caption has changed
 @param new_caption the new caption */
 	void captionChanged (const QString &new_caption);
-public slots:
+private slots:
+/** (Attempts to) close the current tab */
+	void closeCurrentPage ();
+/** handle context menu requests */
+	void showContextMenu (const QPoint &pos);
+/** handle close request from context menu */
+	void contextMenuClosePage ();
+/** handle detach request from context menu */
+	void contextMenuDetachWindow ();
+/** Internal function to update caption and actions, when the current page has changed. */
 	void currentPageChanged (int page);
 /** called when the caption of a window changes. Updates the tab-label, and - if appropriate - the caption of this widget */
 	void childCaptionChanged (RKMDIWindow *widget);
@@ -72,9 +79,6 @@
 	void closePage (QWidget* page);
 /** Close a page given its index */
 	void closePage (int page);
-private slots:
-/** (Attempts to) close the current tab */
-	void closeCurrentPage ();
 private:
 	void updateActions ();
 


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