Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
fix: cannot input text
Browse files Browse the repository at this point in the history
  • Loading branch information
justforlxz committed May 28, 2019
1 parent 44a612b commit 63121fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
29 changes: 22 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ MainWindow::MainWindow(QWidget *parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::X11BypassWindowManagerHint);

installEventFilter(this);

connect(this, &MainWindow::releaseEvent, this, [=]{
qDebug() << "release event !!!";
m_keyboardReleased = true;
m_keyboardGrabbed = windowHandle()->setKeyboardGrabEnabled(false);
qDebug() << "keyboardGrabbed:" << m_keyboardGrabbed;
removeEventFilter(this);
});

connect(this, &MainWindow::hideScreenshotUI, this, &MainWindow::hide);
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -516,19 +528,22 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *ev)
QLabel::mouseReleaseEvent(ev);
}

void MainWindow::showEvent(QShowEvent *event)
{
QTimer::singleShot(100, this, &MainWindow::grabKeyboard);

return QLabel::showEvent(event);
}

void MainWindow::hideEvent(QHideEvent *event)
{
qApp->setOverrideCursor(Qt::ArrowCursor);
QLabel::hideEvent(event);
}

bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (!m_keyboardGrabbed && this->windowHandle() != NULL) {
m_keyboardGrabbed = this->windowHandle()->setKeyboardGrabEnabled(true);
qDebug() << "m_keyboardGrabbed:" << m_keyboardGrabbed;
}

return QLabel::eventFilter(watched, event);
}

void MainWindow::mouseMoveEvent(QMouseEvent *ev)
{
bool needRepaint = false;
Expand Down
4 changes: 3 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public slots:
void mousePressEvent(QMouseEvent* ev) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
bool eventFilter(QObject* watched, QEvent* event) override;

private:
QPixmap getPixmapofRect(const QRect &rect);
Expand Down Expand Up @@ -161,6 +161,8 @@ public slots:
bool m_isShiftPressed = false;
bool m_noNotify = false;
bool m_needSaveScreenshot = false;
bool m_keyboardGrabbed = false;
bool m_keyboardReleased = false;

QString m_selectAreaName;
QPixmap m_resizeBigPix;
Expand Down
12 changes: 0 additions & 12 deletions src/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ Screenshot::Screenshot(QObject *parent)
void Screenshot::initUI() {
m_eventContainer = new EventContainer(this);
m_window = new MainWindow;

connect(m_window, &MainWindow::releaseEvent, this, [=]{
qDebug() << "release event !!!";
m_keyboardReleased = true;
m_keyboardGrabbed = m_window->windowHandle()->setKeyboardGrabEnabled(false);
qDebug() << "keyboardGrabbed:" << m_keyboardGrabbed;
removeEventFilter(this);
});
connect(m_window, &MainWindow::hideScreenshotUI, this, [=]{
m_window->hide();
});
}

void Screenshot::startScreenshot()
Expand Down Expand Up @@ -108,4 +97,3 @@ void Screenshot::savePathScreenshot(const QString &path)
}

Screenshot::~Screenshot() {}

3 changes: 0 additions & 3 deletions src/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public slots:
void initUI();

EventContainer* m_eventContainer = nullptr;
bool m_keyboardGrabbed = false;
bool m_keyboardReleased = false;

MainWindow* m_window = nullptr;

};
Expand Down

0 comments on commit 63121fc

Please # to comment.