qt与html实现移动效果

来源:互联网 发布:周灏 数据财经新浪网 编辑:程序博客网 时间:2024/06/06 02:10

/****yan*****************view to move********************/
void HtmlView::addJavaScriptObject()//遍历每个frame将namein暴露给js
{
    QWebFrame *mFrame=this->page()->mainFrame();
    mFrame->addToJavaScriptWindowObject("namein",this);
    for(int i=0;i<mFrame->childFrames().count();i++)
    {
        QWebFrame *sFrame=mFrame->childFrames().at(i);
        sFrame->addToJavaScriptWindowObject("namein",this);
        for(int j=0;j<sFrame->childFrames().count();j++)
        {
            sFrame->childFrames().at(j)->addToJavaScriptWindowObject("namein",this);
        }
    }

}
void HtmlView::msdown(QVariant isx,QVariant isy,QVariant mousetype){
    qDebug() <<"mousedown";
    QString tagneme="INPUT";
    if(mousetype.toString()!=tagneme)//判断点击的是不是输入框
    {
        //如果不是 获取相应的坐标
        windowPos=this->parentWidget()->pos();
        mousePos.setX(isx.toInt());
        mousePos.setY(isy.toInt());
        qDebug() <<windowPos<<"窗口位置";
        qDebug () << mousePos<<"事件发生的位置";
        qDebug() <<this->pos()<<"thispos";
        dPos=mousePos-windowPos;
        moving=true;
        isinput=false;
    }
    if (mousetype==tagneme){
        isinput=true;
    }
}
//设置只有鼠标按下时移动窗口可用接受js中的鼠标移动时的坐标 移动
void HtmlView::msmove(QVariant isgx, QVariant isgy)
{
    qDebug () <<"mousemove";
    if(this->url().toString().contains("Login")==false)
    {
        emit mousemoving();
    }else
    {
        qDebug()<<"登录页不锁定!!";
    }
    msmovepoint.setX(isgx.toInt());
    msmovepoint.setY(isgy.toInt());
    //窗口可以移动并且不是输入框的时候 设置可以移动
    qDebug()<<"asfdasfdsaf"<<is_max<<moving<<isinput;

    if(is_max==false){ if(moving==true&&isinput==false)
        {
            this->parentWidget()->move(msmovepoint-dPos);
            qDebug()<<this->parentWidget();
        }
    }}

void HtmlView::mouse_up(){//鼠标松开时设置不可移动 判断是否是输入框isinput值设为空
    qDebug () <<"mouseup";
    moving=false;
    isinput=NULL;
    qDebug () <<moving<<isinput;
}


关于首页  设置js交互

/*  先设置js交互可用  qt 与 网页 不能同时响应 鼠标事件 如果在qt中重写qt的事件 造成在网页中鼠的经过事件不可用
即在鼠标经过一些标签的时候无法显示对用的特效  贴图的话无法实现在全局的空白处拖动 用户的体验不好
在qt中写对应的函数 在网页中响应鼠标事件 调用qt函数 完美解决问题!



js中对应的代码:
//鼠标按下事件 相当于qt中的mousepress
<script>
function show_down(event)
{
var targ = event.target;
var tname = targ.tagName;
var x=event.screenX;
var y=event.screenY;
namein.msdown(x,y,tname);//调用qt对应的槽函数接受数据并判断(点击的位置是否可以移动)
//alert("X coords: " + x + ", Y coords: " + y);
}
</script>

//mousemove事件
<script>
function show_move(event){
 var gx = event.screenX;
 var gy = event.screenY;
 namein.msmove(gx,gy);//调用qt槽函数接收数据并作出相应的判断(是否移动)

}
</script>
//鼠标松开事件
<script>
function mouse_up(event){

namein.mouse_up();//重置bool数据 ismoving input设为空

}
</script>

全局设置响应对应的鼠标事件 mouse down move up
<htmllang="en"   onmousedown="show_down(event)"onmousemove="show_move(event)"onmouseup="mouse_up(event)">

双击标题变为最大化 使用qt中的双击事件 对应的是点击qt中的bar  label  新增判断当前的窗口是否是最大化判断
*/

关于index页面  
移动:
移动双击最大化的标题栏 和网页 实现移动
但是最大化的时候都设置移动不可用


最大化时的移动和不是最大话的移动
因为要实现在程序的标题头双击实现程序全屏(qt中的实现 判断鼠标双击事件)还要实现网页的移动  就需要在主窗体和webview控件中监控
方法 在mainwindow中和view中分别设置移动情况的判断 在view中新增bool值is_max 当mainwindow时最大化的时候 调用view.ismax=true 从而在最大化的时候都设置移动不可用  
设置最大化的时候不能移动 新增bool 值


index.html中要做的
<html lang="en" onmousedown="show_down(event)"onmousemove="show_move(event)"onmouseup="mouse_up(event)">
最大化最小化
<div class="btnbtn">
                    <i class="skin"></i>
                    <i class="xiao" onclick="min_click()"></i>
                    <i class="big" onclick="max_click()"></i>
                    <i class="close" onclick="close_click()"></i>
                </div>






对应的js函数


<script>
function show_down(event)
{

var targ = event.target;  
var tname = targ.tagName;  
var x=event.screenX;
var y=event.screenY;

 namein.msdown(x,y,tname);

//alert("X coords: " + x + ", Y coords: " + y);
}
</script>

<script>
function show_move(event){
 var gx = event.screenX;
 var gy = event.screenY;
 namein.msmove(gx,gy);
 
}
</script>

<script>
function mouse_up(event){
 
namein.mouse_up();

 
}
</script>

<script>
function close_click(){
 
mainwindow.slot_close();

 
}
</script>
<script>
function max_click(){
 
mainwindow.slot_max();

 
}

</script>
<script>
function min_click(){
 
mainwindow.slot_min();

 
}
</script>








0 0
原创粉丝点击