Permalink
Browse files

drag session to composer

  • Loading branch information...
1 parent 5794ba0 commit 88a15572139dc7a01ac855abb497736bb292628c @iptton iptton committed Apr 13, 2012
Showing with 89 additions and 32 deletions.
  1. +2 −1 Rythem.pro
  2. +13 −3 composer.cpp
  3. +13 −1 composer.ui
  4. +2 −2 main.cpp
  5. +0 −21 mainwindow.cpp
  6. +0 −3 mainwindow.h
  7. +35 −1 ryconnectiontableview.cpp
  8. +5 −0 ryconnectiontableview.h
  9. +19 −0 rymimedata.h
View
@@ -68,7 +68,8 @@ HEADERS += mainwindow.h \
quazip/quaadler32.h \
quazip/JlCompress.h \
quazip/ioapi.h \
- quazip/crypt.h
+ quazip/crypt.h \
+ rymimedata.h
win32:HEADERS += zlib/zutil.h \
zlib/zlib.h \
zlib/zconf.h \
View
@@ -1,6 +1,9 @@
#include "composer.h"
#include "ui_composer.h"
#include <QNetworkProxy>
+
+#include "rymimedata.h"
+
Composer::Composer(QWidget *parent) :
QWidget(parent),
ui(new Ui::Composer){
@@ -177,6 +180,7 @@ void Composer::setupProxy(QString host,qint16 port){
}
void Composer::dragEnterEvent(QDragEnterEvent *event){
+
qDebug()<<"drag enter";
if (event->mimeData()->hasText()) {
if (event->source() == this) {
@@ -188,12 +192,18 @@ void Composer::dragEnterEvent(QDragEnterEvent *event){
} else {
event->ignore();
}
+
}
void Composer::dropEvent(QDropEvent *event){
- qDebug()<<event->source();
- if (event->mimeData()->hasText()) {
- const QMimeData *mime = event->mimeData();
+ qDebug()<<"drop";
+ const RyMimeData* mime = dynamic_cast<const RyMimeData*>(event->mimeData());
+
+ if (mime) {
+ RyPipeData_ptr d = mime->pipeData();
+ this->ui->server->setText(d->host);
+ this->ui->port->setText(QString::number(d->port));
+ this->ui->request->setPlainText(QString(d->requestHeaderRawData()).append("\r\n\r\n").append(d->requestBodyRawData()));
qDebug()<<"drop text="<<mime->text();
event->acceptProposedAction();
} else {
View
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>624</width>
+ <width>727</width>
<height>385</height>
</rect>
</property>
@@ -22,6 +22,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="acceptDrops">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>w.l.qq.com</string>
</property>
@@ -50,6 +53,9 @@
<height>16777215</height>
</size>
</property>
+ <property name="acceptDrops">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>80</string>
</property>
@@ -101,6 +107,9 @@
</item>
<item row="1" column="0" colspan="6">
<widget class="QPlainTextEdit" name="request">
+ <property name="acceptDrops">
+ <bool>false</bool>
+ </property>
<property name="toolTip">
<string>request</string>
</property>
@@ -126,6 +135,9 @@ Range: bytes=48-6116217
</item>
<item row="2" column="0" colspan="6">
<widget class="QPlainTextEdit" name="response">
+ <property name="acceptDrops">
+ <bool>false</bool>
+ </property>
<property name="toolTip">
<string>response</string>
</property>
View
@@ -79,8 +79,8 @@ int main(int argc, char *argv[])
server->connect(server,SIGNAL(pipeError(RyPipeData_ptr)),&w,SLOT(onPipeUpdate(RyPipeData_ptr)));
server->listen(QHostAddress("127.0.0.1"),8889);
- w.showMaximized();
-
+ //w.showMaximized();
+ w.show();
return a.exec();
}
View
@@ -397,27 +397,6 @@ void MainWindow::onWaterfallActionTriggered(){
}
-void MainWindow::mousePressEvent(QMouseEvent *event){
- qDebug()<<"mouseenter";
- QTableView *table = static_cast<QTableView*>(childAt(event->pos()));
- if (!table || table!=ui->tableView){
- return;
- }
- qDebug()<<"is table";
- QPoint hotSpot = event->pos() - table->pos();
- QMimeData *mimeData = new QMimeData;
- mimeData->setText("child->text()");
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- //drag->setPixmap(pixmap);
- drag->setHotSpot(hotSpot);
- drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
-}
-
-void MainWindow::dragEnterEvent(QDragEnterEvent *){
-
-}
-
void MainWindow::toggleProxy(){
if(isUsingCapture){
isUsingCapture = false;
View
@@ -70,9 +70,6 @@ public slots:
}ProxyInfo;
RyTableModel pipeTableModel;
-protected:
- void mousePressEvent(QMouseEvent *);
- void dragEnterEvent(QDragEnterEvent *);
private:
Ui::MainWindow *ui;
View
@@ -4,11 +4,14 @@
#include "quazip/quazipfile.h"
#include "rytablemodel.h"
+#include "rymimedata.h"
+
extern QString appPath;
RyConnectionTableView::RyConnectionTableView(QWidget *parent) :
QTableView(parent){
-
+ _isMouseDown = false;
+ this->setDragEnabled(true);
createMenu();
}
@@ -46,6 +49,37 @@ void RyConnectionTableView::createMenu(){
}
+void RyConnectionTableView::mousePressEvent(QMouseEvent *event){
+ _isMouseDown = true;
+ QTableView::mousePressEvent(event);
+}
+void RyConnectionTableView::mouseReleaseEvent(QMouseEvent *event){
+ _isMouseDown = false;
+ QTableView::mouseReleaseEvent(event);
+}
+
+void RyConnectionTableView::mouseMoveEvent(QMouseEvent *event){
+ if(!_isMouseDown){
+ QTableView::mouseMoveEvent(event);
+ return;
+ }
+ QModelIndex index = this->indexAt(event->pos());
+ if (!index.isValid()){
+ return;
+ }
+ QPoint hotSpot = event->pos() - this->pos();
+ RyTableModel* model = qobject_cast<RyTableModel*>(this->model());
+ RyPipeData_ptr data = model->getItem(index.column());
+ RyMimeData *mimeData = new RyMimeData(data);
+ mimeData->setText(data->getRequestHeader("Host"));
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ //drag->setPixmap(pixmap);
+ drag->setHotSpot(hotSpot);
+ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
+}
+
+
void RyConnectionTableView::onAction(){
QAction *action = qobject_cast<QAction*>(sender());
if(0 == action){
View
@@ -17,6 +17,9 @@ public slots:
protected:
virtual void contextMenuEvent (QContextMenuEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
private slots:
void onAction();
private:
@@ -33,6 +36,8 @@ private slots:
QAction *_autoScrollAct;
+ bool _isMouseDown;
+
void createMenu();
};
View
@@ -0,0 +1,19 @@
+#ifndef RYMIMEDATA_H
+#define RYMIMEDATA_H
+#include <QtCore>
+#include <proxy/rypipedata.h>
+#include <QMimeData>
+
+class RyMimeData:public QMimeData{
+public:
+ RyMimeData(RyPipeData_ptr data):QMimeData(){
+ _data = data;
+ }
+ RyPipeData_ptr pipeData()const{
+ return _data;
+ }
+private:
+ RyPipeData_ptr _data;
+};
+
+#endif // RYMIMEDATA_H

0 comments on commit 88a1557

Please sign in to comment.