#include <windows.h> #include <QMouseEvent> #include <QMessageBox> FloatingWindow::FloatingWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); ui.pushButton->setFlat(true); ui.pushButton->setStyleSheet("background-image:url(./pic/2smallsetdown.jpg)"); ui.widget->setGeometry(-ui.widget->width(),ui.widget->y(),ui.widget->width(),ui.widget->height()); //ui.widget->setFeatures(QDockWidget::NoDockWidgetFeatures); atout=false; status=true; this->setMouseTracking(true); //ui.widget->setMouseTracking(true); ui.centralWidget->setMouseTracking(true); ui.axWidget->setMouseTracking(true); //添加flash connect(ui.axWidget,SIGNAL(FSCommand(QString,QString)),this,SLOT(flashAction(QString,QString))); ui.axWidget->dynamicCall("LoadMovie(long,string)",0,"E://MLCN//topo_show.swf"); ui.axWidget->dynamicCall("Play()");
}
FloatingWindow::~FloatingWindow() {
}
void FloatingWindow::mouseMoveEvent (QMouseEvent *event){ int x=event->x(); int y=event->y(); if (status) { if (x<20&&atout==false) { movein(); } else if(atout==true&&x>120) { moveout(); } } } void FloatingWindow::movein (){ for (pos=-ui.widget->width();pos<=0;pos=pos+8) { ui.widget->setGeometry(QRect(pos, ui.widget->y(), ui.widget->width(), ui.widget->height())); Sleep(1); } atout=true;
} void FloatingWindow::moveout (){ for (pos=0;pos>=-ui.widget->width();pos=pos-ui.widget->width()) { ui.widget->setGeometry(QRect(pos, ui.widget->y(), ui.widget->width(), ui.widget->height())); Sleep(1); } atout=false; }
void FloatingWindow::mouseDoubleClickEvent ( QMouseEvent * event ){ int x=event->x(); int y=event->y(); int x1=ui.widget->x(); int y1=ui.widget->y(); int wi=ui.widget->width(); int he=ui.widget->height(); if (x>x1&&x<x1+wi&&y>y1&&y<y1+he) { status=!status; } }
void FloatingWindow::flashAction(QString command,QString args) { QMessageBox::information(this,command,args); }
void FloatingWindow::on_pushButton_clicked() { status=!status; }
void FloatingWindow::on_pushButton_2_clicked() { QApplication::exit(); }