Skip to content

Commit

Permalink
蒙版按钮与软件之间的交互
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminyangguang520 committed Dec 9, 2015
1 parent 4ab30f1 commit e10eec1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 83 deletions.
7 changes: 1 addition & 6 deletions GCR/trunk/Glodon/demos/GLDMaskDemo/LogoinWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ LogoinWidget::LogoinWidget(QWidget *parent)
pwdLayout->addWidget(m_edtPwd);

QHBoxLayout *btnLayout = new QHBoxLayout;
m_logoin = new TestButton(this);
m_logoin->setText("login");
m_logoin = new QPushButton(tr("login"), this);
m_cancel = new QPushButton(tr("cancel"), this);
btnLayout->addWidget(m_logoin);
btnLayout->addWidget(m_cancel);
Expand Down Expand Up @@ -84,7 +83,3 @@ void LogoinWidget::showDialog()
m_dialog->show();
}

//void LogoinWidget::mousePressEvent(QMouseEvent *event)
//{
// qDebug() << "LoginWidget mousePressEvent";
//}
21 changes: 1 addition & 20 deletions GCR/trunk/Glodon/demos/GLDMaskDemo/LogoinWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@
class Dialog;
class GLDMaskBox;

class TestButton : public QPushButton
{
public:
explicit TestButton(QWidget * parent = nullptr)
: QPushButton(parent)
{

}
protected:
void mousePressEvent(QMouseEvent *e)
{
qDebug() << "testbutton mousePressEvent";
QPushButton::mousePressEvent(e);
}
};

class LogoinWidget : public QWidget
{
Q_OBJECT
Expand All @@ -39,17 +23,14 @@ class LogoinWidget : public QWidget
public slots:
void showDialog();

protected:
//void mousePressEvent(QMouseEvent *event);

private:
QLabel* m_name;
QLabel* m_password;

QLineEdit* m_edtName;
QLineEdit* m_edtPwd;

TestButton* m_logoin;
QPushButton* m_logoin;
QPushButton* m_cancel;

Dialog* m_dialog;
Expand Down
16 changes: 2 additions & 14 deletions GCR/trunk/Glodon/include/GLD/GLDMaskBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public slots:
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
bool eventFilter(QObject* watched, QEvent* event);

private:
/**
Expand Down Expand Up @@ -193,19 +192,8 @@ public slots:
*/
void drawRightBottomArrow(QPoint &startPoint, QPoint &endPoint, QPainter &painter);


HWND getHandle(QWidget *pWidget)
{
WId id = pWidget->winId();
HWND hwnd = (HWND)id;
while (!IsWindow(hwnd))
{
pWidget = (QWidget *)(pWidget->parent());
id = pWidget->winId();
hwnd = (HWND)id;
}
return hwnd;
}

HWND getHandle(QWidget *pWidget);

private:
static GLDMaskBox* m_pMaskBox;
Expand Down
61 changes: 18 additions & 43 deletions GCR/trunk/Glodon/src/GLD/Qt/Widgets/GLDMaskBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,63 +337,37 @@ void GLDMaskBox::drawRightBottomArrow(QPoint &startPoint, QPoint &endPoint, QPai
painter.drawLine(line2);
}

void GLDMaskBox::mousePressEvent(QMouseEvent * event)
HWND GLDMaskBox::getHandle(QWidget *pWidget)
{
QPoint ptGlobalOwnerCenter = m_pClippedWgt->mapToParent(m_pClippedWgt->rect().topLeft());
QRect rect(ptGlobalOwnerCenter.rx(), ptGlobalOwnerCenter.ry(),
m_pClippedWgt->width(), m_pClippedWgt->height());
WId id = pWidget->winId();
HWND hwnd = (HWND)id;

if (rect.contains(event->pos()))
while (!IsWindow(hwnd))
{
close();
//QPushButton* ptn = dynamic_cast<QPushButton*>(m_pClippedWgt);
//ptn->click();
//emit customClicked();
QCursor::setPos(QPoint(event->pos().x(), event->pos().y() + 20));

//QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(event->pos().x(), event->pos().y() + 20), (Qt::MouseButton)0, 0, 0);
//QMouseEvent e(QEvent::MouseButtonRelease, QPoint(event->pos().x(), event->pos().y() + 20), (Qt::MouseButton)0, 0, 0);
//QApplication::sendEvent(m_pClippedWgt, &pressEvent);
//QApplication::sendEvent(m_pClippedWgt, &e);

HWND hwnd = getHandle(m_pClippedWgt);
QPoint point = m_pClippedWgt->mapFromGlobal(event->pos());
SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(point.x(), point.y()));

pWidget = (QWidget *)(pWidget->parent());
id = pWidget->winId();
hwnd = (HWND)id;
}

QWidget::mousePressEvent(event);
return hwnd;
}

bool GLDMaskBox::eventFilter(QObject* watched, QEvent* event)
void GLDMaskBox::mousePressEvent(QMouseEvent * event)
{
QPoint ptGlobalOwnerCenter = m_pClippedWgt->mapToParent(m_pClippedWgt->rect().topLeft());
QRect rect(ptGlobalOwnerCenter.rx(), ptGlobalOwnerCenter.ry(),
m_pClippedWgt->width(), m_pClippedWgt->height());

//if (m_pClippedWgt == watched)
if (rect.contains(event->pos()))
{
qDebug() << event->type();
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent* mouseevent = static_cast<QMouseEvent*>(event);
if (rect.contains(mouseevent->pos()))
{
//QPushButton* ptn = dynamic_cast<QPushButton*>(m_pClippedWgt);
//ptn->click();
return true;
}
else
return false;
close();

}
else
{
return false;
}
HWND hwnd = getHandle(m_pClippedWgt);
QPoint point = m_pClippedWgt->mapFromGlobal(event->pos());
SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(point.x(), point.y()));
}

return QWidget::eventFilter(watched, event);
QWidget::mousePressEvent(event);
}

void GLDMaskBox::openIniFile(const QString& filePath)
Expand All @@ -415,9 +389,10 @@ bool GLDMaskBox::canShow()
if (!m_btnObjectName.isEmpty())
{
QSettings oInis(m_iniPath, QSettings::IniFormat);
int temp = oInis.value("GLDMask/next").toInt();
return oInis.value(m_btnObjectName, 0).toInt() == 0;
}

return false;
}

GLDMaskBox* GLDMaskBox::createMaskFor(QWidget* widget, QPushButton *btn, const QString & tipInfoPath, const QString & btnInfoPath, const QString & iniPath)
Expand Down Expand Up @@ -543,7 +518,7 @@ bool GLDMaskBox::getMaskShow(const QString &prefix, const QString &key)
{
if (strValue == "true")
{
// 这个函数是在最终发布的时候打开那么蒙版只会在第一次启动的时候被调用
// 这个函数是在最终发布的时候打开,那么蒙版只会在第一次启动的时候被调用
// 暂时在测试功能中,先注掉,方便调试
// setValue(prefix, key);
return true;
Expand Down

0 comments on commit e10eec1

Please sign in to comment.