[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [vidalia/alpha] First phase of detach tabs
commit 6dcf75a834e65715a1d3cd90664be377f3312c60
Author: Tomas Touceda <chiiph@xxxxxxxxxx>
Date: Mon May 23 14:05:14 2011 -0300
First phase of detach tabs
Commentted is the code that handles drag and drop for re-attaching the tabs
again. It will probably work on windows, but I need to figure out a way to
handle this in a generic way first, and then go for the ifdefs.
---
src/vidalia/CMakeLists.txt | 2 +
src/vidalia/MainWindow.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-
src/vidalia/MainWindow.h | 8 ++++++
src/vidalia/VAttachButton.cpp | 39 ++++++++++++++++++++++++++++
src/vidalia/VAttachButton.h | 30 +++++++++++++++++++++
src/vidalia/VTabWidget.cpp | 9 +++++-
src/vidalia/VTabWidget.h | 3 ++
src/vidalia/VidaliaTab.cpp | 18 +++++++++++++
src/vidalia/VidaliaTab.h | 6 ++++
9 files changed, 169 insertions(+), 3 deletions(-)
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index f340b65..9fd58ca 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -176,6 +176,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
Vidalia.cpp
LanguageSupport.cpp
VTabWidget.cpp
+ VAttachButton.cpp
MainWindow.cpp
VidaliaWindow.cpp
VMessageBox.cpp
@@ -187,6 +188,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
qt4_wrap_cpp(vidalia_SRCS
Vidalia.h
VTabWidget.h
+ VAttachButton.h
MainWindow.h
VidaliaWindow.h
VMessageBox.h
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 56b24c7..22949b0 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -25,6 +25,7 @@
#include "ServerSettings.h"
#include "AboutDialog.h"
#include "HelpBrowser.h"
+#include "VAttachButton.h"
#ifdef USE_AUTOUPDATE
#include "UpdatesAvailableDialog.h"
#endif
@@ -112,6 +113,8 @@ MainWindow::MainWindow()
_status = Unset;
_isVidaliaRunningTor = false;
updateTorStatus(Stopped);
+
+ setAcceptDrops(true);
}
/** Destructor */
@@ -1497,6 +1500,44 @@ MainWindow::handleCloseTab(int index)
}
void
+MainWindow::attachTab()
+{
+ qWarning() << "ATTACHHHHHHHHHH";
+}
+
+void
+MainWindow::dettachTab()
+{
+ VAttachButton *but = qobject_cast<VAttachButton *>(sender());
+ VidaliaTab *tab = but->getTab();
+ int index = ui.tabWidget->indexOf(tab);
+
+ ui.tabWidget->removeTab(index);
+ tab->setParent(0);
+ tab->show();
+
+ QString key = _tabMap.at(index);
+ _tabMap.removeAll(key);
+ _dettachedTabMap << key;
+}
+
+void
+MainWindow::handleAttachedClose()
+{
+ VidaliaTab *tab = qobject_cast<VidaliaTab *>(sender());
+ int index = ui.tabWidget->indexOf(tab);
+ qWarning() << index;
+ if(index < 0) {
+ qWarning() << "DETACHEEEEDDDDDDDDDDDDD";
+ tab->setParent(ui.tabWidget);
+ addTab(tab);
+ delTab(ui.tabWidget->currentIndex());
+ } else {
+ qWarning() << "ATTACHEEEEEDDDD";
+ }
+}
+
+void
MainWindow::addTab(VidaliaTab *tab)
{
/** If the tab's already open, display it and delete the
@@ -1518,8 +1559,22 @@ MainWindow::addTab(VidaliaTab *tab)
return;
}
+ VAttachButton *atb = new VAttachButton();
+
ui.tabWidget->addTab(tab, tab->getTitle());
- ui.tabWidget->setCurrentIndex(ui.tabWidget->count() - 1);
+ int pos = ui.tabWidget->count() - 1;
+ ui.tabWidget->setCurrentIndex(pos);
+
+ atb->setTab(tab);
+ ui.tabWidget->setTabButton(pos, QTabBar::LeftSide, atb);
+
+ connect(tab, SIGNAL(closeTab()),
+ this, SLOT(handleAttachedClose()));
+
+ connect(atb, SIGNAL(attachTab()),
+ this, SLOT(attachTab()));
+ connect(atb, SIGNAL(dettachTab()),
+ this, SLOT(dettachTab()));
/** The new tab is added to the last position */
_tabMap << tab->getTitle();
connect(tab, SIGNAL(helpRequested(QString)),
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 3b7d544..2bfd02f 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -60,6 +60,10 @@ protected:
/** Called when the user changes the UI translation. */
virtual void retranslateUi();
+// void dropEvent(QDropEvent *de);
+// void dragMoveEvent(QDragMoveEvent *de);
+// void dragEnterEvent(QDragEnterEvent *event);
+
private slots:
/** Respond to a double-click on the tray icon by opening the Control Panel
* window. */
@@ -147,6 +151,9 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
+ void attachTab();
+ void dettachTab();
+
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -283,6 +290,7 @@ private:
MessageLog *_messageLog; /**< Message log that displays a more detailed log from Tor */
NetViewer _netViewer; /**< Network map that draws circuits */
QStringList _tabMap; /**< Map to handle opened tabs */
+ QStringList _dettachedTabMap;
BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
PluginEngine *_engine;
diff --git a/src/vidalia/VAttachButton.cpp b/src/vidalia/VAttachButton.cpp
new file mode 100644
index 0000000..80e512b
--- /dev/null
+++ b/src/vidalia/VAttachButton.cpp
@@ -0,0 +1,39 @@
+#include "VAttachButton.h"
+
+VAttachButton::VAttachButton(QWidget *parent) :
+ QPushButton(parent)
+{
+ _tab = 0;
+ _attached = true;
+ setText(QString("X"));
+}
+
+VAttachButton::~VAttachButton()
+{
+ disconnect(0,0,0,0);
+}
+
+void
+VAttachButton::setTab(VidaliaTab *tab)
+{
+ _tab = tab;
+ connect(this, SIGNAL(clicked()), this, SLOT(toggleAttach()));
+}
+
+VidaliaTab *
+VAttachButton::getTab()
+{
+ return _tab;
+}
+
+void
+VAttachButton::toggleAttach()
+{
+ if(_attached) {
+ emit dettachTab();
+ } else {
+ emit attachTab();
+ }
+ _attached = !_attached;
+}
+
diff --git a/src/vidalia/VAttachButton.h b/src/vidalia/VAttachButton.h
new file mode 100644
index 0000000..e1ad3de
--- /dev/null
+++ b/src/vidalia/VAttachButton.h
@@ -0,0 +1,30 @@
+#ifndef VATTACHBUTTON_H
+#define VATTACHBUTTON_H
+
+#include <QtGui>
+
+#include "VidaliaTab.h"
+
+class VAttachButton : public QPushButton {
+ Q_OBJECT
+
+ public:
+ VAttachButton(QWidget *parent = 0);
+ ~VAttachButton();
+
+ void setTab(VidaliaTab *tab);
+ VidaliaTab *getTab();
+
+ signals:
+ void attachTab();
+ void dettachTab();
+
+ public slots:
+ void toggleAttach();
+
+ private:
+ VidaliaTab *_tab;
+ bool _attached;
+};
+
+#endif
diff --git a/src/vidalia/VTabWidget.cpp b/src/vidalia/VTabWidget.cpp
index 421f069..a1bef76 100644
--- a/src/vidalia/VTabWidget.cpp
+++ b/src/vidalia/VTabWidget.cpp
@@ -1,5 +1,3 @@
-#include <QTabBar>
-
#include "VTabWidget.h"
#include "VidaliaTab.h"
@@ -50,3 +48,10 @@ VTabWidget::retranslateUi()
setTabText(i, qobject_cast<VidaliaTab *>(widget(i))->getTitle());
}
}
+
+void
+VTabWidget::setTabButton(int pos, QTabBar::ButtonPosition butpos, QWidget *w)
+{
+ tabBar()->setTabButton(pos, butpos, w);
+}
+
diff --git a/src/vidalia/VTabWidget.h b/src/vidalia/VTabWidget.h
index c3eb8ce..45028e8 100644
--- a/src/vidalia/VTabWidget.h
+++ b/src/vidalia/VTabWidget.h
@@ -17,6 +17,7 @@
#define _VTABWIDGET_H
#include <QTabWidget>
+#include <QTabBar>
class VTabWidget : public QTabWidget
{
@@ -31,6 +32,8 @@ public:
/** Makes the tab at position unclosable */
void pinTab(int position);
+ void setTabButton(int pos, QTabBar::ButtonPosition butpos, QWidget *w);
+
protected:
void changeEvent(QEvent *e);
void retranslateUi();
diff --git a/src/vidalia/VidaliaTab.cpp b/src/vidalia/VidaliaTab.cpp
index ec5f1bf..a35838e 100644
--- a/src/vidalia/VidaliaTab.cpp
+++ b/src/vidalia/VidaliaTab.cpp
@@ -64,3 +64,21 @@ VidaliaTab::setOnTop(bool top)
{
_onTop = top;
}
+
+void
+VidaliaTab::closeEvent(QCloseEvent *event)
+{
+ event->ignore();
+ emit closeTab();
+}
+
+//void
+//VidaliaTab::mouseMoveEvent(QMouseEvent *event)
+//{
+// QDrag *dr = new QDrag(this);
+// QMimeData *data = new QMimeData();
+// qWarning() << "THIS" << this;
+// data->setData(tr("vidalia/pointer"), QByteArray().setNum((int)this));
+// dr->setMimeData(data);
+// dr->start();
+//}
diff --git a/src/vidalia/VidaliaTab.h b/src/vidalia/VidaliaTab.h
index ac6edb1..df26c8a 100644
--- a/src/vidalia/VidaliaTab.h
+++ b/src/vidalia/VidaliaTab.h
@@ -51,6 +51,8 @@ signals:
* <b>topic</b>. */
void helpRequested(const QString &topic);
+ void closeTab();
+
protected:
/** Reimplement the windows' changeEvent() method to check if the event
* is a QEvent::LanguageChange event. If so, call retranslateUi(), which
@@ -59,6 +61,10 @@ protected:
/** Called when the user wants to change the currently visible language. */
virtual void retranslateUi();
+ virtual void closeEvent(QCloseEvent *event);
+
+// virtual void mouseMoveEvent(QMouseEvent *event);
+
bool _onTop; /**< True if the current tab is the one being displayed */
private:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits