summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp16
-rw-r--r--src/gui/kernel/qplatformcursor.cpp4
-rw-r--r--src/gui/kernel/qplatformmenu.h10
-rw-r--r--src/gui/kernel/qwindow.cpp69
-rw-r--r--src/gui/kernel/qwindow.h5
-rw-r--r--src/gui/kernel/qwindow_p.h5
6 files changed, 89 insertions, 20 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 3044c1dee2..fc1b537f90 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2629,6 +2629,13 @@ static inline void applyCursor(QWindow *w, QCursor c)
cursor->changeCursor(&c, w);
}
+static inline void unsetCursor(QWindow *w)
+{
+ if (const QScreen *screen = w->screen())
+ if (QPlatformCursor *cursor = screen->handle()->cursor())
+ cursor->changeCursor(0, w);
+}
+
static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
{
for (int i = 0; i < l.size(); ++i) {
@@ -2642,8 +2649,13 @@ static inline void applyWindowCursor(const QList<QWindow *> &l)
{
for (int i = 0; i < l.size(); ++i) {
QWindow *w = l.at(i);
- if (w->handle() && w->type() != Qt::Desktop)
- applyCursor(w, w->cursor());
+ if (w->handle() && w->type() != Qt::Desktop) {
+ if (qt_window_private(w)->hasCursor) {
+ applyCursor(w, w->cursor());
+ } else {
+ unsetCursor(w);
+ }
+ }
}
}
diff --git a/src/gui/kernel/qplatformcursor.cpp b/src/gui/kernel/qplatformcursor.cpp
index 16a59f5d07..c2f510b496 100644
--- a/src/gui/kernel/qplatformcursor.cpp
+++ b/src/gui/kernel/qplatformcursor.cpp
@@ -95,6 +95,10 @@ QList<QPlatformCursor *> QPlatformCursorPrivate::getInstances()
\a windowCursor is a pointer to the QCursor that should be displayed.
+ To unset the cursor of \a window, 0 is passed. This means \a window does not have
+ a cursor set and the cursor of a the first parent window which has a cursor explicitly
+ set or the system default cursor should take effect.
+
\a window is a pointer to the window currently displayed at QCursor::pos(). Note
that this may be 0 if the current position is not occupied by a displayed widget.
diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h
index b02998940b..acaa57f071 100644
--- a/src/gui/kernel/qplatformmenu.h
+++ b/src/gui/kernel/qplatformmenu.h
@@ -103,6 +103,16 @@ public:
virtual void setText(const QString &text) = 0;
virtual void setEnabled(bool enabled) = 0;
virtual void setVisible(bool visible) = 0;
+ virtual void setMinimumWidth(int width) { Q_UNUSED(width); }
+ virtual void setFont(const QFont &font) { Q_UNUSED(font); }
+
+ virtual void showPopup(const QWindow *parentWindow, QPoint pos, const QPlatformMenuItem *item)
+ {
+ Q_UNUSED(parentWindow);
+ Q_UNUSED(pos);
+ Q_UNUSED(item);
+ setVisible(true);
+ }
virtual QPlatformMenuItem *menuItemAt(int position) const = 0;
virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0;
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index db19aa9366..db6afe1faa 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -284,7 +284,7 @@ void QWindow::setVisible(bool visible)
}
#ifndef QT_NO_CURSOR
- if (visible)
+ if (visible && d->hasCursor)
d->applyCursor();
#endif
d->platformWindow->setVisible(visible);
@@ -642,7 +642,8 @@ void QWindow::lower()
}
/*!
- Sets the window's opacity in the windowing system to \a level.
+ \property QWindow::opacity
+ \brief The opacity of the window in the windowing system.
If the windowing system supports window opacity, this can be used to fade the
window in and out, or to make it semitransparent.
@@ -650,15 +651,25 @@ void QWindow::lower()
A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below
is treated as fully transparent. Values inbetween represent varying levels of
translucency between the two extremes.
+
+ The default value is 1.0.
*/
void QWindow::setOpacity(qreal level)
{
Q_D(QWindow);
- if (level == d->opacity) // #fixme: Add property for 5.1
+ if (level == d->opacity)
return;
d->opacity = level;
- if (d->platformWindow)
+ if (d->platformWindow) {
d->platformWindow->setOpacity(level);
+ emit opacityChanged(level);
+ }
+}
+
+qreal QWindow::opacity() const
+{
+ Q_D(const QWindow);
+ return d->opacity;
}
/*!
@@ -1436,13 +1447,15 @@ QObject *QWindow::focusObject() const
Shows the window.
This equivalent to calling showFullScreen() or showNormal(), depending
- on whether the platform defaults to windows being fullscreen or not.
+ on whether the platform defaults to windows being fullscreen or not, and
+ whether the window is a popup.
- \sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen()
+ \sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags()
*/
void QWindow::show()
{
- if (qApp->styleHints()->showIsFullScreen())
+ bool isPopup = d_func()->windowFlags & Qt::Popup & ~Qt::Window;
+ if (!isPopup && qApp->styleHints()->showIsFullScreen())
showFullScreen();
else
showNormal();
@@ -1946,13 +1959,7 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed()
void QWindow::setCursor(const QCursor &cursor)
{
Q_D(QWindow);
- d->cursor = cursor;
- // Only attempt to set cursor and emit signal if there is an actual platform cursor
- if (d->screen->handle()->cursor()) {
- d->applyCursor();
- QEvent event(QEvent::CursorChange);
- QGuiApplication::sendEvent(this, &event);
- }
+ d->setCursor(&cursor);
}
/*!
@@ -1960,7 +1967,8 @@ void QWindow::setCursor(const QCursor &cursor)
*/
void QWindow::unsetCursor()
{
- setCursor(Qt::ArrowCursor);
+ Q_D(QWindow);
+ d->setCursor(0);
}
/*!
@@ -1974,14 +1982,39 @@ QCursor QWindow::cursor() const
return d->cursor;
}
+void QWindowPrivate::setCursor(const QCursor *newCursor)
+{
+
+ Q_Q(QWindow);
+ if (newCursor) {
+ const Qt::CursorShape newShape = newCursor->shape();
+ if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
+ return; // Unchanged and no bitmap/custom cursor.
+ cursor = *newCursor;
+ hasCursor = true;
+ } else {
+ if (!hasCursor)
+ return;
+ cursor = QCursor(Qt::ArrowCursor);
+ hasCursor = false;
+ }
+ // Only attempt to set cursor and emit signal if there is an actual platform cursor
+ if (screen->handle()->cursor()) {
+ applyCursor();
+ QEvent event(QEvent::CursorChange);
+ QGuiApplication::sendEvent(q, &event);
+ }
+}
+
void QWindowPrivate::applyCursor()
{
Q_Q(QWindow);
if (platformWindow) {
if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
- QCursor *oc = QGuiApplication::overrideCursor();
- QCursor c = oc ? *oc : cursor;
- platformCursor->changeCursor(&c, q);
+ QCursor *c = QGuiApplication::overrideCursor();
+ if (!c && hasCursor)
+ c = &cursor;
+ platformCursor->changeCursor(c, q);
}
}
}
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index 2e2f12a8ab..478262da3f 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -112,6 +112,7 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
+ Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
public:
@@ -148,6 +149,8 @@ public:
QString title() const;
void setOpacity(qreal level);
+ qreal opacity() const;
+
void requestActivate();
bool isActive() const;
@@ -287,6 +290,8 @@ Q_SIGNALS:
void focusObjectChanged(QObject *object);
+ void opacityChanged(qreal opacity);
+
private Q_SLOTS:
void screenDestroyed(QObject *screen);
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index ed34693faa..dd526cb505 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -98,6 +98,7 @@ public:
, screen(0)
#ifndef QT_NO_CURSOR
, cursor(Qt::ArrowCursor)
+ , hasCursor(false)
#endif
{
isWindow = true;
@@ -109,6 +110,7 @@ public:
void maybeQuitOnLastWindowClosed();
#ifndef QT_NO_CURSOR
+ void setCursor(const QCursor *c = 0);
void applyCursor();
#endif
@@ -120,6 +122,8 @@ public:
return offset;
}
+ virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; }
+
QWindow::SurfaceType surfaceType;
Qt::WindowFlags windowFlags;
QWindow *parentWindow;
@@ -151,6 +155,7 @@ public:
#ifndef QT_NO_CURSOR
QCursor cursor;
+ bool hasCursor;
#endif
};