[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Fri Sep 16 03:48:50 CEST 2005


SVN commit 460986 by staikos:

Add a context menu for tabs, and make them movable via drag and drop too.  I
think this needs some testing in realtime mode.  I'm afraid it will be crashy.
Close doesn't work right, but a bug is already filed for that.


 M  +58 -1     kst.cpp  
 M  +11 -6     kst.h  


--- trunk/extragear/graphics/kst/kst/kst.cpp #460985:460986
@@ -32,6 +32,7 @@
 #include <kfiledialog.h>
 #include <kkeydialog.h>
 #include <kmessagebox.h>
+#include <kpopupmenu.h>
 #include <kprinter.h>
 #include <kprogress.h>
 #include <kstandarddirs.h>
@@ -2277,6 +2278,7 @@
   }
 }
 
+
 QString KstApp::newWindow(bool prompt, QWidget *parent) {
   QString nameUsed;
   QString name = windowName(prompt, defaultTag, false, parent);
@@ -2287,9 +2289,10 @@
   return nameUsed;
 }
 
+
 QString KstApp::newWindow(const QString& name_in) {
   KstViewWindow *w = new KstViewWindow;
-  QString nameToUse = QString::null;
+  QString nameToUse;
   QString name  = name_in;
 
   while (name.isEmpty() || findWindow(name)) {
@@ -2405,6 +2408,11 @@
   KTabWidget *tw = tabWidget();
   if (tw) {
     tw->setHoverCloseButton(false);
+    disconnect(tw, SIGNAL(contextMenu(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
+    disconnect(tw, SIGNAL(contextMenu(QWidget*, const QPoint&)), this, SLOT(showContextMenu(QWidget*, const QPoint&)));
+    connect(tw, SIGNAL(contextMenu(const QPoint&)), SLOT(showContextMenu(const QPoint&)));
+    connect(tw, SIGNAL(contextMenu(QWidget*, const QPoint&)), SLOT(showContextMenu(QWidget*, const QPoint&)));
+    tw->setTabReorderingEnabled(true);
   }
 }
 
@@ -2424,5 +2432,54 @@
 }
 
 
+void KstApp::showContextMenu(QWidget *w, const QPoint& pos) {
+  KPopupMenu *pm = new KPopupMenu(this);
+  KstViewWindow *vw = dynamic_cast<KstViewWindow*>(w);
+  if (vw) {
+    pm->insertTitle(vw->caption());
+  }
+
+  pm->insertItem(i18n("&New..."), this, SLOT(slotFileNewWindow()));
+  if (vw) {
+    KTabWidget *tw = tabWidget();
+    if (tw) { // should always be true, but who knows how KMdi might change
+      int id = pm->insertItem(i18n("Move &Left"), this, SLOT(moveTabLeft()));
+      pm->setItemEnabled(id, tw->indexOf(w) > 0);
+      id = pm->insertItem(i18n("Move &Right"), this, SLOT(moveTabRight()));
+      pm->setItemEnabled(id, tw->indexOf(w) < tw->count() - 1);
+    }
+    pm->insertItem(i18n("R&ename..."), this, SLOT(slotFileRenameWindow()));
+    pm->insertItem(i18n("&Close"), this, SLOT(slotFileClose()));
+  }
+
+  pm->exec(pos);
+  delete pm;
+}
+
+
+void KstApp::showContextMenu(const QPoint& pos) {
+  KPopupMenu *pm = new KPopupMenu(this);
+  pm->insertItem(i18n("&New..."), this, SLOT(slotFileNewWindow()));
+  pm->exec(pos);
+  delete pm;
+}
+
+
+void KstApp::moveTabLeft() {
+  KTabWidget *tw = tabWidget();
+  int cur = tw->currentPageIndex();
+  tw->moveTab(cur, cur - 1);
+  tw->setCurrentPage(cur - 1);
+}
+
+
+void KstApp::moveTabRight() {
+  KTabWidget *tw = tabWidget();
+  int cur = tw->currentPageIndex();
+  tw->moveTab(cur, cur + 1);
+  tw->setCurrentPage(cur + 1);
+}
+
+
 #include "kst.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kst.h #460985:460986
@@ -89,7 +89,7 @@
     static void initialize(); // for main to call
 
     KstApp(QWidget* parent=0, const char* name=0);
-    virtual ~KstApp();
+    ~KstApp();
 
     static KstApp* inst();
     static void doubleCheckCleanup();
@@ -155,8 +155,9 @@
     bool paused() const;
 
   protected:
-    virtual void customEvent(QCustomEvent *e);
+    void customEvent(QCustomEvent *e);
 
+
     /** save options to the configuration file
      *  Geometry, Toolbar status, Statusbar status */
     void saveOptions();
@@ -181,22 +182,22 @@
      * @see saveModified()
      * @see KMainWindow#queryClose
      * @see KMainWindow#closeEvent */
-    virtual bool queryClose();
+    bool queryClose();
 
     /** Calls queryClose */
-    virtual bool queryExit();
+    bool queryExit();
 
     /** saves the window properties for each open window during session
      * end to the session config file, including saving the currently
      * opened file by a temporary filename provided by KApplication.
      * @see KMainWindow#saveProperties */
-    virtual void saveProperties(KConfig *_cfg);
+    void saveProperties(KConfig *cfg);
 
     /** reads the session config file and restores the application's
      * state including the last opened files and documents by reading
      * the temporary files saved by saveProperties()
      * @see KMainWindow#readProperties */
-    virtual void readProperties(KConfig *_cfg);
+    void readProperties(KConfig *cfg);
 
   private slots:
     // Hack to update KStdActions
@@ -210,6 +211,10 @@
     void addNewWindowMenu();
 
     void fixKMdi();
+    void showContextMenu(QWidget *w, const QPoint& pos);
+    void showContextMenu(const QPoint& pos);
+    void moveTabLeft();
+    void moveTabRight();
 
   public slots:
     void fromEnd();


More information about the Kst mailing list