]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
robomon2: now it's possible to close tabs (using icon or Ctrl+W).
authorTran Duy Khanh <trandk1@fel.cvut.cz>
Sat, 26 Apr 2008 20:21:45 +0000 (22:21 +0200)
committerTran Duy Khanh <trandk1@fel.cvut.cz>
Sat, 26 Apr 2008 20:21:45 +0000 (22:21 +0200)
src/robomon/src2/MainWindow.cpp
src/robomon/src2/MainWindow.h
src/robomon/src2/SimMcl.cpp
src/robomon/src2/SimMcl.h
src/robomon/src2/images/close.png [new file with mode: 0644]
src/robomon/src2/robomon.qrc

index 916839f6345bb818bbe3a754fdad870040216d35..140e75571241f41f74508cde167a0d6c344f03bb 100644 (file)
@@ -36,9 +36,6 @@ MainWindow::MainWindow()
 
 void MainWindow::closeEvent(QCloseEvent *event)
 {
-       for (int i=0; i<tabWidget->count(); i++)
-               tabWidget->removeTab(i);
-
        event->accept();
 }
 
@@ -153,6 +150,8 @@ void MainWindow::createActions()
        aboutAct = new QAction(tr("&About"), this);
        aboutAct->setStatusTip(tr("Show information about the application"));
        connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+       connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
 }
 
 void MainWindow::createMenus()
@@ -195,6 +194,13 @@ void MainWindow::createStatusBar()
 void MainWindow::createTabs()
 {
        tabWidget = new QTabWidget;
+       closeToolButton = new QToolButton();
+
+       closeToolButton->setIcon(QIcon(":/images/close.png"));
+       closeToolButton->setIconSize(QSize(14, 14));
+       closeToolButton->setShortcut(tr("Ctrl+W"));
+       closeToolButton->setToolTip(tr("Close tab (Ctrl+W)"));
+       tabWidget->setCornerWidget(closeToolButton);
 
 //     addMclTab();
 //     addLaserNavTab();
@@ -202,3 +208,14 @@ void MainWindow::createTabs()
 //     addRobomonTuningTab();
        addRobomonExplorerTab();
 }
+
+void MainWindow::closeCurrentTab()
+{
+       int index = tabWidget->currentIndex();
+       if (index < 0)
+               return;
+       QWidget* tabPage = tabWidget->widget(index);
+       tabPage->close();
+       tabWidget->removeTab(index);
+       delete tabPage;
+}
index 7c3f7ec66727028dfb0b16a29264493e76fac390..ef9f6eac206d493a08407e94cb6726f58d4325bd 100644 (file)
@@ -18,6 +18,7 @@
 class QAction;
 class QMenu;
 class QTabWidget;
+class QToolButton;
 
 class MainWindow : public QMainWindow
 {
@@ -37,6 +38,7 @@ private slots:
        void addRobomonTuningTab();
        void addMclTab();
        void addLaserNavTab();
+       void closeCurrentTab();
 
 private:
        void createTabs();
@@ -48,6 +50,7 @@ private:
        void writeSettings();
        
        QTabWidget *tabWidget;
+       QToolButton *closeToolButton;
 
        /* menus and tool bars */
        QMenu *fileMenu;
index c0921dd92878d0828bd10bc2cefd9f079f6da6bd..87572c6cec98aa7531dd125f6ee53edcf411115e 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <QtGui>
 #include <QKeyEvent>
+#include <QCloseEvent>
 #include <QEvent>
 #include <QGLWidget>
 
@@ -736,8 +737,6 @@ bool SimMcl::event(QEvent *event)
                                grabKeyboard();
                        else if (event->type() == QEvent::FocusOut)
                                releaseKeyboard();
-                       else if (event->type() == QEvent::Close)
-                               closeEvent((QCloseEvent *)event);
                        else {
                                event->ignore();
                                return false;
@@ -801,13 +800,6 @@ void SimMcl::keyReleaseEvent(QKeyEvent *event)
        event->accept();
 }
 
-void SimMcl::closeEvent(QCloseEvent *event)
-{
-       printf("tady koncim\n");
-       generic_roboorte_destroy(&orte_generic);
-       eb2008_roboorte_destroy(&orte_eb2008);
-}
-
 /**********************************************************************
  * ORTE
  **********************************************************************/
index cdf75b3d7d1f88f8a024d75059217bf158204f71..22935eee3622f59c63233decf43ff649157b6e5a 100644 (file)
@@ -50,7 +50,6 @@ protected:
        bool event(QEvent *event);
        void keyPressEvent(QKeyEvent *event);
        void keyReleaseEvent(QKeyEvent *event);
-       void closeEvent(QCloseEvent *event);
 
 signals:
        void laserDataReceivedSignal();
diff --git a/src/robomon/src2/images/close.png b/src/robomon/src2/images/close.png
new file mode 100644 (file)
index 0000000..c8adce6
Binary files /dev/null and b/src/robomon/src2/images/close.png differ
index 6aa7f1dc5990b1e2e1190cc26b0a49911ece534f..11816d27871073b5123db0f7867311b3f96c39de 100644 (file)
@@ -4,5 +4,6 @@
     <file>images/robomon_explorer.png</file>
     <file>images/sim_mcl.png</file>
     <file>images/sim_laser.png</file>
+    <file>images/close.png</file>
 </qresource>
 </RCC>