TestWidget.cpp_2

#include "TestWidget.h"
#include <Windows.h> 
#include "OfficeContainer.h"

DemoTestWidget::DemoTestWidget(QWidget *parent /*= NULL*/)
:m_index(1)
{
    initUI();
    initConnect();
    this->showMaximized();
}

DemoTestWidget::~DemoTestWidget()
{

}

void DemoTestWidget::initUI()
{
    pLblPath    = new QLabel(tr("Path:"),this);
    pTxtPath    = new QLineEdit(this);
    pBtnOpen    = new QPushButton(tr("Open"),this);
    pBtnSelect  = new QPushButton(tr("Select"),this);
    pBtnClose   = new QPushButton(tr("Close"),this);
    pComBox     = new QComboBox(this);

    /*
    officeDialogNew            = 0,
        officeDialogOpen           = 1,
        officeDialogSave           = 2,
        officeDialogSaveCopy       = 3,
        officeDialogPrint          = 4,
        officeDialogPageSetup      = 5,
        officeDialogProperties     = 6
    */
    pComBox->addItem("officeDialogNew");
    pComBox->addItem("officeDialogOpen");
    pComBox->addItem("officeDialogSave");
    pComBox->addItem("officeDialogSaveCopy");
    pComBox->addItem("officeDialogPrint");
    pComBox->addItem("officeDialogPageSetup");
    pComBox->addItem("officeDialogProperties");
    pBtnShowDlg = new QPushButton(tr("ShowDlg"),this);

    /*QHBoxLayout *hly001 = new QHBoxLayout();
    hly001->addWidget(pLblPath);
    hly001->addWidget(pTxtPath);
    hly001->addWidget(pBtnSelect);
    hly001->addWidget(pBtnOpen);
    hly001->addWidget(pBtnClose);
    hly001->addWidget(pComBox);
    hly001->addWidget(pBtnShowDlg);

    pCentrelWgt = new QWidget(this);
    pOfficeContainer    = new OfficeContainer(this);
    QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
    vly0010->addWidget(pOfficeContainer,1);

    QVBoxLayout *vly010 = new QVBoxLayout(this);
    vly010->addLayout(hly001);
    vly010->addWidget(pCentrelWgt,1);*/

    //test
    //officeContent=new QAxWidget("Powerpoint.Application",this);
    //officeContent->setGeometry(QRect(10, 10, 1000, 1000));
    //presentations = officeContent->querySubObject("Presentations"); 

    //QHBoxLayout *hly001 = new QHBoxLayout();
    //hly001->addWidget(pLblPath);
    //hly001->addWidget(pTxtPath);
    //hly001->addWidget(pBtnSelect);
    //hly001->addWidget(pBtnOpen);
    //hly001->addWidget(pBtnClose);
    //hly001->addWidget(pComBox);
    //hly001->addWidget(pBtnShowDlg);
    //pCentrelWgt   = new QWidget(this);

    pOfficeContainer    = new OfficeContainer(this);
    //QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
    //vly0010->addWidget(officeContent,1);

    //QVBoxLayout *vly010 = new QVBoxLayout(this);
    //vly010->addLayout(hly001);
    //vly010->addWidget(pCentrelWgt,1);

    //presentations->dynamicCall("Open(QString)", "C:\\Users\\LJ\\Desktop\\test.pptx");
    //word
    /*
    officeContent=new QAxWidget("Word.Document",this);
    officeContent->setGeometry(QRect(10, 10, 1000, 1000));officeContent->setControl("C:\\Users\\LJ\\Desktop\\test.docx");
    officeContent->show();*/


    //test2
    officeContent=new QAxWidget("Powerpoint.Application",this);
    officeContent->setGeometry(QRect(10, 10, 1000, 1000));
    presentations = static_cast<PowerPoint::Presentations*>(officeContent->querySubObject("Presentations"));
    //PowerPoint::Presentation *presentation;

    //pptApp = new PowerPoint::Application();
    //pptApp->dynamicCall("SetVisible(Office::MsoTriState)",true);
    //PowerPoint::Presentations* presentations = pptApp->Presentations();
    //PowerPoint::Presentation *presentation;
    if (presentations != NULL )
    {
        //PowerPoint::Presentation *presentation = presentations->Open("C:\\Users\\LJ\\Desktop\\test.pptx");
        //presentation = static_cast<PowerPoint::Presentation*>(presentations->querySubObject("Open(QString&)", "C:\\Users\\LJ\\Desktop\\test.pptx"));
        presentation = static_cast<PowerPoint::Presentation*>(presentations->querySubObject("Open(QString&)", "D:\\test.pptx"));


        //PowerPoint::Slides* slides = presentation->Slides();
        slides = static_cast<PowerPoint::Slides*>(presentation->querySubObject("Slides()"));

        QVariant index(m_index);
        //PowerPoint::Slide* slide = slides->Item(index);
        slide = static_cast<PowerPoint::Slide*>(slides->querySubObject("Item(QVariant&)", index));
        m_index++;


        //PowerPoint::SlideShowSettings* slideshow = presentation->SlideShowSettings();
        slideshow = static_cast<PowerPoint::SlideShowSettings*>(presentation->querySubObject("SlideShowSettings()"));

        //slideshow->Run();
        slideshow->dynamicCall("Run()");
    }

    QHBoxLayout *hly001 = new QHBoxLayout();
    hly001->addWidget(pLblPath);
    hly001->addWidget(pTxtPath);
    hly001->addWidget(pBtnSelect);
    hly001->addWidget(pBtnOpen);
    hly001->addWidget(pBtnClose);
    hly001->addWidget(pComBox);
    hly001->addWidget(pBtnShowDlg);
    pCentrelWgt = new QWidget(this);

    QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
    vly0010->addWidget(officeContent,1);

    QVBoxLayout *vly010 = new QVBoxLayout(this);
    vly010->addLayout(hly001);
    vly010->addWidget(pCentrelWgt,1);


    //test3:
    //officeContent=new QAxWidget("Powerpoint.Application",this);
    //officeContent->setGeometry(QRect(10, 10, 1000, 1000));
    //PowerPoint::Presentations* presentations = static_cast<PowerPoint::Presentations*>(officeContent->querySubObject("Presentations"));
    //PowerPoint::Presentation *presentation;

    pptApp = new PowerPoint::Application();
    pptApp->dynamicCall("SetVisible(Office::MsoTriState)",true);
    PowerPoint::Presentations* presentations = pptApp->Presentations();
    PowerPoint::Presentation *presentation;
    //if (presentations != NULL )
    //{
    //  /*PowerPoint::Presentation **/presentation = presentations->Open("C:\\Users\\LJ\\Desktop\\test.pptx");
    //}
    //


    //WId wid = (WId)FindWindow(L"PPTFrameClass",NULL);
    第三步:获取QWindow
    //QWindow *m_window;
    //m_window = QWindow::fromWinId(wid);
    //m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //这边可以设置一下属性
    第四步:获取代理QWidget
    //QWidget *m_widget;
    //m_widget = QWidget::createWindowContainer(m_window,this); //第二个参数是作为window的父类,也可以用layout,此处就不解释了
    //
    //QHBoxLayout *hly001 = new QHBoxLayout();
    //hly001->addWidget(pLblPath);
    //hly001->addWidget(pTxtPath);
    //hly001->addWidget(pBtnSelect);
    //hly001->addWidget(pBtnOpen);
    //hly001->addWidget(pBtnClose);
    //hly001->addWidget(pComBox);
    //hly001->addWidget(pBtnShowDlg);
    //pCentrelWgt   = new QWidget(this);

    //QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
    //vly0010->addWidget(m_widget,1);

    //QVBoxLayout *vly010 = new QVBoxLayout(this);
    //vly010->addLayout(hly001);
    //vly010->addWidget(pCentrelWgt,1);


    /*m_widget = new QWidget(this);
    m_widget->setStyleSheet(QString("background-color: rgb(0, 0, 0);"));
    m_widget->setGeometry(0,0,1000,1000);
    m_widget->show();
    m_widget->setWindowOpacity(0.1);
    m_widget->installEventFilter(this);*/

    setAutoFillBackground(false);
    setAttribute(Qt::WA_TranslucentBackground, true);
    setWindowFlags(Qt::FramelessWindowHint); 
    installEventFilter(this);


    HWND wid = (HWND)(this->winId());
    //SetWindowLong(wid, GWL_EXSTYLE, GetWindowLong(wid, GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_COMPOSITED); 
    SetWindowLong(wid, GWL_EXSTYLE, GetWindowLong(wid, GWL_EXSTYLE) | WS_EX_NOACTIVATE); 

    //HWND wid2 = (HWND)(m_widget->winId());
    //SetWindowLong(wid2, GWL_EXSTYLE, GetWindowLong(wid2, GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_COMPOSITED); 


    //slideShowWindow  = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
    //installEventFilter(this);
}

void DemoTestWidget::initConnect()
{
    BUTTON_ACT(pBtnOpen,sltBtnOpen());
    BUTTON_ACT(pBtnSelect,sltBtnSelect());
    BUTTON_ACT(pBtnClose,sltBtnClose());
    BUTTON_ACT(pBtnShowDlg,sltBtnShowDlg());
}


void DemoTestWidget::sltBtnOpen()
{
    /*QString strPath = pTxtPath->text();
    if (!strPath.isEmpty())
    {
        QVariant v(strPath);
        pOfficeContainer->Open(v);
    }*/
    qDebug() << "Btn Open";


    //test  
    //presentations->dynamicCall("Open(QString)", "C:\Users\LJ\Desktop\test.pptx");

    //test2
    //PowerPoint::Slides* slides = static_cast<PowerPoint::Slides*>(presentation->querySubObject("Slides()"));
    slideShowWindow  = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
    slideShowView  = static_cast<PowerPoint::SlideShowView*>(slideShowWindow->querySubObject("View()"));

    //slideShowView.Next();
    slideShowView->dynamicCall("Next()");
    //slideShowView->dynamicCall("GotoSlide(int)", 4);
    m_index++;
    //slideShowView->dynamicCall("GotoClick(int)", PowerPoint::msoClickStateAfterAllAnimations);


    int sum = slideShowView->GetClickCount(); //当前页的动画个数
    /*QMessageBox msgBox;
    msgBox.setText(QString::number(sum));
    msgBox.exec();*/

}

void DemoTestWidget::sltBtnSelect()
{
    QString filePath = QFileDialog::getOpenFileName(this,tr("Select Word"),"",tr("Word (*.doc;*.docx;*.docm);;Excel (*.xls;*.xlsx;*.xlsm;*.xlsb);;PPT (*.ppt;*.pptx;*.pptm)"));
    if (filePath.isEmpty())
    {
        //emit sigUpdateMsg("未选择Word文件");
    }
    else
    {
        pTxtPath->setText(filePath);
    }
    qDebug() << "Btn Select";
}

void DemoTestWidget::sltBtnClose()
{
    pOfficeContainer->Close();
}

void DemoTestWidget::sltBtnShowDlg()
{
    int index = pComBox->currentIndex();

    pOfficeContainer->ShowDialog((OfficeContainer::DialogType)(index));
}

bool DemoTestWidget::eventFilter(QObject *target, QEvent *event)  
{  
    //if(target == m_widget)  
    {  
        qDebug("The imageWidget generate the event!");  
        if(event->type() == QEvent::MouseButtonPress)  
        {  
            QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);  
            if(mouseEvent->buttons() & Qt::LeftButton)  
            {  
                qDebug("The Left Button Event!"); 
                slideShowWindow  = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
                slideShowView  = static_cast<PowerPoint::SlideShowView*>(slideShowWindow->querySubObject("View()"));

                SetCursorPos(500,0);//这个坐标是“开始”这个菜单在我当前电脑屏幕上的位置,大家可以自己去获取  
                mouse_event( MOUSEEVENTF_LEFTDOWN, 0,0,0,NULL);//鼠标down事件  
                mouse_event( MOUSEEVENTF_LEFTUP, 0,0,0,NULL);//鼠标up事件

                //QAxWidget* slideShowWindowWidget  = static_cast<QAxWidget*>(presentation->querySubObject("SlideShowWindow()"));
                //slideShowWindow->mousePressEvent( (QMouseEvent *)event); 

                //slideShowView.Next();
                //slideShowView->dynamicCall("Next()");

            }  
            return true;  
        } 

        /*switch (event->type())
        {
            case QEvent::KeyPress:
            {
                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(event);
                if (pKeyEvent->key() == Qt::Key_Escape)
                {
                    return true;
                }
            }
        }*/

    }  

    //其它部件产生的事件则交给基类处理  
    return QWidget::eventFilter(target, event);  
}


void DemoTestWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.fillRect(this->rect(), QColor(0, 0, 255, 50));  //QColor最后一个参数80代表背景的透明度
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
#include "widget.h" #include "ui_widget.h" #include <QSqlQuery> //操作数据库 #include <QDebug> //输出错误信息 #include <QSqlError> // #include <QMessageBox> //#include <TestWidget3.h> //跳转窗口头文件 #include <QCheckBox> Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); } Widget::~Widget() { delete ui; } void Widget::on_regButton_clicked() { //密码 //插入数据 QSqlQuery query; query.prepare("INSERT INTO userinfo(account,password) VALUES (':value1', ':value2')"); query.bindValue(":value1",ui->accountEdit->text() ); query.bindValue(":value2",ui->passwordedit->text()); if(query.exec()){ //如果插入数据成功 QMessageBox::information(this,"注册","注册成功"); }else{ QMessageBox::information(this,"注册","注册失败"); } } void Widget::on_loginButton_clicked() { //接收用户输入 QSqlQuery query; //操作数据库 query.prepare("select * from user where account = ':value1' and password= ':value2'"); query.bindValue(":value1", ui->accountEdit->text()); query.bindValue(":value2", ui->passwordedit->text()); if(!query.exec()){ //如果没有查到记录 QMessageBox::information(this,"登录","登录失败"); } //获取查询的数据: if(query.next()){ //获取到数据 QMessageBox::information(this,"登录","登录成功"); }else{ QMessageBox::information(this,"登录","登录失败"); } } 这段代码用于实现用户注册与登录功能,但运行时总是注册失败,登录失败,请帮我修改这段代码,修复bug
07-15
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值