add windows code for bringWidowToFront

This commit is contained in:
Patrick von Reth 2015-04-12 14:54:10 +02:00
parent 76f1279aa7
commit db60a9efd3
11 changed files with 118 additions and 3 deletions

View File

@ -50,7 +50,7 @@ set_package_properties(Doxygen PROPERTIES
TYPE OPTIONAL)
if(DOXYGEN_FOUND)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @only)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile

View File

@ -28,6 +28,7 @@ list(APPEND SnoreNotify_SRCS
hint.cpp
log.cpp
settingsdialog.cpp
utils.cpp
${UI}
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${SNORENOTIFY_RCS}
@ -42,6 +43,7 @@ list(APPEND SnoreNotify_HDR
log.h
settingsdialog.h
snoreglobals.h
utils.h
${CMAKE_CURRENT_BINARY_DIR}/snore_exports.h
version.h
)

View File

@ -1,6 +1,6 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
Copyright (C) 2013-2015 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@ -118,4 +118,5 @@ private:
};
}
#endif // SNORECOREPRIVATE_H

61
src/libsnore/utils.cpp Normal file
View File

@ -0,0 +1,61 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
#include "log.h"
#ifdef Q_OS_WIN
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#include <winuser.h>
#endif
using namespace Snore;
void Utils::bringWindowToFront(qlonglong _wid)
{
snoreDebug(SNORE_DEBUG) << _wid;
#ifdef Q_OS_WIN
HWND wid = (HWND)_wid;
HWND hwndActiveWin = GetForegroundWindow();
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
if (AttachThreadInput(GetCurrentThreadId(), idActive, TRUE)) {
SetForegroundWindow(wid);
SetFocus(wid);
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
} else {
// try it anyhow
SetForegroundWindow(wid);
SetFocus(wid);
}
#endif
}
Utils::Utils(QObject *parent):
QObject(parent)
{
}
Utils::~Utils()
{
}

39
src/libsnore/utils.h Normal file
View File

@ -0,0 +1,39 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2015 Patrick von Reth <vonreth@kde.org>
SnoreNotify is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SnoreNotify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H
#define UTILS_H
#include "snore_exports.h"
#include <QApplication>
namespace Snore {
class SNORE_EXPORT Utils : public QObject {
Q_OBJECT
public:
Utils(QObject *parent = nullptr);
~Utils();
//TODO: make Wid usable with the meta system and change signature.
Q_INVOKABLE void bringWindowToFront(qlonglong wid);
};
}
#endif // UTILS_H

View File

@ -45,6 +45,7 @@ Rectangle {
animation.start()
window.visible = true
utils.bringWindowToFront(window.wid)
}
}

View File

@ -19,6 +19,7 @@
#include "notifywidget.h"
#include "snorenotifier.h"
#include "libsnore/log.h"
#include "libsnore/utils.h"
using namespace Snore;
@ -30,6 +31,7 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
m_ready(true)
{
rootContext()->setContextProperty("window", this);
rootContext()->setContextProperty("utils", new Utils(this));
m_qmlNotification = rootObject();
setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus
@ -149,6 +151,11 @@ Qt::Corner NotifyWidget::corner()
return static_cast<Qt::Corner>(m_parent->value("Position").toInt());
}
qlonglong NotifyWidget::wid()
{
return this->winId();
}
void NotifyWidget::slotDismissed()
{
emit dismissed();

View File

@ -44,6 +44,7 @@ class NotifyWidget : public QQuickView
public:
Q_PROPERTY(int id READ id)
Q_PROPERTY(Qt::Corner corner READ corner)
Q_PROPERTY(qlonglong wid READ wid)
explicit NotifyWidget(int pos, const SnoreNotifier *parent);
~NotifyWidget();
@ -56,6 +57,7 @@ public:
int id();
Qt::Corner corner();
qlonglong wid();
signals:
void invoked();

View File

@ -65,7 +65,7 @@ void Sound::slotNotify(Snore::Notification notification)
QTimer *timeout = new QTimer(this);
timeout->setSingleShot(true);
timeout->setInterval(notification.timeout() * 1000);
connect(timeout, &QTimer::timeout, [&,timeout]{
connect(timeout, &QTimer::timeout, [this,timeout]{
m_player->stop();
timeout->deleteLater();
});

View File

@ -30,7 +30,9 @@ SoundSettings::SoundSettings(SnorePlugin *snorePlugin, QWidget *parent) :
m_lineEditFileName(new QLineEdit),
m_spinBoxVolume(new QSpinBox)
{
m_spinBoxVolume->setRange(0,100);
addRow(tr("Volume:"), m_spinBoxVolume);
addRow(tr("Audio file:"), m_lineEditFileName);
QPushButton *button = new QPushButton(tr("Select a audio file"));
connect(button, &QPushButton::clicked, [this]() {