Present Window's close button ported to QtQuick 2

remotes/origin/Plasma/5.0
Martin Gräßlin 13 years ago
parent 35bb48df2c
commit 47cf35720f
  1. 1
      effects/CMakeLists.txt
  2. 9
      effects/presentwindows/main.qml
  3. 34
      effects/presentwindows/presentwindows.cpp
  4. 8
      effects/presentwindows/presentwindows.h

@ -13,6 +13,7 @@ set(kwin_effect_KDE_LIBS
set(kwin_effect_QT_LIBS set(kwin_effect_QT_LIBS
${Qt5Declarative_LIBRARIES} ${Qt5Declarative_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5X11Extras_LIBRARIES} ${Qt5X11Extras_LIBRARIES}
${Qt5DBus_LIBRARIES} ${Qt5DBus_LIBRARIES}
) )

@ -17,16 +17,17 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.1 import QtQuick 2.0
import org.kde.plasma.components 0.1 as Plasma import org.kde.plasma.components 2.0 as Plasma
Item { Item {
width: 32
height: 32
Plasma.Button { Plasma.Button {
id: closeButton id: closeButton
objectName: "closeButton" objectName: "closeButton"
enabled: armed enabled: armed
width: 32
height: 32
iconSource: "window-close" iconSource: "window-close"
anchors.fill: parent
} }
} }

@ -41,8 +41,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <QApplication> #include <QApplication>
#include <QDeclarativeContext> #include <QQmlContext>
#include <QDeclarativeEngine> #include <QQmlEngine>
#include <QQuickItem>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QTimer> #include <QTimer>
@ -1478,7 +1479,7 @@ void PresentWindowsEffect::setActive(bool active)
if (!m_doNotCloseWindows) { if (!m_doNotCloseWindows) {
m_closeView = new CloseWindowView(); m_closeView = new CloseWindowView();
connect(m_closeView, SIGNAL(close()), SLOT(closeWindow())); connect(m_closeView, &CloseWindowView::requestClose, this, &PresentWindowsEffect::closeWindow);
} }
// Add every single window to m_windowData (Just calling [w] creates it) // Add every single window to m_windowData (Just calling [w] creates it)
@ -1690,12 +1691,12 @@ void PresentWindowsEffect::updateCloseWindow()
return; return;
const QRectF rect(m_motionManager.targetGeometry(m_highlightedWindow)); const QRectF rect(m_motionManager.targetGeometry(m_highlightedWindow));
if (2*m_closeView->sceneRect().width() > rect.width() && 2*m_closeView->sceneRect().height() > rect.height()) { if (2*m_closeView->width() > rect.width() && 2*m_closeView->height() > rect.height()) {
// not for tiny windows (eg. with many windows) - they might become unselectable // not for tiny windows (eg. with many windows) - they might become unselectable
m_closeView->hide(); m_closeView->hide();
return; return;
} }
QRect cvr(QPoint(0,0), m_closeView->sceneRect().size().toSize()); QRect cvr(QPoint(0,0), m_closeView->size());
switch (m_closeButtonCorner) switch (m_closeButtonCorner)
{ {
case Qt::TopLeftCorner: case Qt::TopLeftCorner:
@ -1938,31 +1939,18 @@ void PresentWindowsEffect::screenCountChanged()
/************************************************ /************************************************
* CloseWindowView * CloseWindowView
************************************************/ ************************************************/
CloseWindowView::CloseWindowView(QWidget *parent) CloseWindowView::CloseWindowView(QWindow *parent)
: QDeclarativeView(parent) : QQuickView(parent)
, m_armTimer(new QTimer(this)) , m_armTimer(new QTimer(this))
{ {
setWindowFlags(Qt::X11BypassWindowManagerHint); setFlags(Qt::X11BypassWindowManagerHint);
setAttribute(Qt::WA_TranslucentBackground); setColor(Qt::transparent);
QPalette pal = palette();
pal.setColor(backgroundRole(), Qt::transparent);
setPalette(pal);
for (const QString &importPath : KGlobal::dirs()->findDirs("module", QStringLiteral("imports"))) {
engine()->addImportPath(importPath);
}
#warning Port declarative code to QtQuick2
#if KWIN_QT5_PORTING
KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.initialize();
kdeclarative.setupBindings();
#endif
rootContext()->setContextProperty(QStringLiteral("armed"), QVariant(false)); rootContext()->setContextProperty(QStringLiteral("armed"), QVariant(false));
setSource(QUrl(KStandardDirs::locate("data", QStringLiteral("kwin/effects/presentwindows/main.qml")))); setSource(QUrl(KStandardDirs::locate("data", QStringLiteral("kwin/effects/presentwindows/main.qml"))));
if (QObject *item = rootObject()->findChild<QObject*>(QStringLiteral("closeButton"))) { if (QObject *item = rootObject()->findChild<QObject*>(QStringLiteral("closeButton"))) {
connect(item, SIGNAL(clicked()), SIGNAL(close())); connect(item, SIGNAL(clicked()), SIGNAL(requestClose()));
} }
// setup the timer - attempt to prevent accidental clicks // setup the timer - attempt to prevent accidental clicks

@ -26,24 +26,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwineffects.h> #include <kwineffects.h>
#include <kshortcut.h> #include <kshortcut.h>
#include <QDeclarativeView> #include <QQuickView>
class QTimer; class QTimer;
namespace KWin namespace KWin
{ {
class CloseWindowView : public QDeclarativeView class CloseWindowView : public QQuickView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CloseWindowView(QWidget *parent = 0); explicit CloseWindowView(QWindow *parent = 0);
void windowInputMouseEvent(QMouseEvent* e); void windowInputMouseEvent(QMouseEvent* e);
void disarm(); void disarm();
public Q_SLOTS: public Q_SLOTS:
void arm(); void arm();
Q_SIGNALS: Q_SIGNALS:
void close(); void requestClose();
private: private:
QTimer* m_armTimer; QTimer* m_armTimer;

Loading…
Cancel
Save