summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <sergio.martins@kdab.com>2016-11-29 18:58:55 +0000
committerSérgio Martins <sergio.martins@kdab.com>2016-12-15 15:37:00 +0000
commit7797c13131574f369e09970834f96d67e11a5e1d (patch)
tree0f3d7033b6c81f3e3ffb58c3a6d88aa72bbe4e6f
parentf9b1ec2d797b9a44dc983cddc15b5f00a0094cd1 (diff)
QDockWidgetGroupWindow now honors custom title bar
When you change tab it will loose or gain native window decos depending on if the current dock widget has them or not. Change-Id: I1171f43fa5ee897ce7d695fc447255dcb0d1d5a1 Task-Id: QTBUG-56866 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/widgets/widgets/qdockwidget.cpp6
-rw-r--r--src/widgets/widgets/qmainwindowlayout.cpp47
-rw-r--r--src/widgets/widgets/qmainwindowlayout_p.h5
3 files changed, 53 insertions, 5 deletions
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index c9cb826213..53cb21186f 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -219,8 +219,10 @@ QDockWidgetLayout::~QDockWidgetLayout()
bool QDockWidgetLayout::nativeWindowDeco() const
{
bool floating = parentWidget()->isWindow();
- if (!floating && qobject_cast<QDockWidgetGroupWindow*>(parentWidget()->parentWidget()))
- return wmSupportsNativeWindowDeco();
+ if (!floating) {
+ if (auto groupWindow = qobject_cast<const QDockWidgetGroupWindow*>(parentWidget()->parentWidget()))
+ return groupWindow->hasNativeDecos();
+ }
return nativeWindowDeco(floating);
}
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index 8df197e05c..aef8b9cbd5 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -183,7 +183,7 @@ class QDockWidgetGroupLayout : public QLayout {
QDockAreaLayoutInfo info;
QWidgetResizeHandler *resizer;
public:
- QDockWidgetGroupLayout(QWidget* parent) : QLayout(parent) {
+ QDockWidgetGroupLayout(QDockWidgetGroupWindow* parent) : QLayout(parent) {
setSizeConstraint(QLayout::SetMinAndMaxSize);
resizer = new QWidgetResizeHandler(parent);
resizer->setMovingEnabled(false);
@@ -221,7 +221,7 @@ public:
}
void setGeometry(const QRect&r) Q_DECL_OVERRIDE
{
- static_cast<QDockWidgetGroupWindow *>(parent())->destroyOrHideIfEmpty();
+ groupWindow()->destroyOrHideIfEmpty();
QDockAreaLayoutInfo *li = layoutInfo();
if (li->isEmpty())
return;
@@ -239,7 +239,7 @@ public:
bool nativeWindowDeco() const
{
- return QDockWidgetLayout::wmSupportsNativeWindowDeco();
+ return groupWindow()->hasNativeDecos();
}
int frameWidth() const
@@ -247,6 +247,11 @@ public:
return nativeWindowDeco() ? 0 :
parentWidget()->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, parentWidget());
}
+
+ QDockWidgetGroupWindow *groupWindow() const
+ {
+ return static_cast<QDockWidgetGroupWindow *>(parent());
+ }
};
bool QDockWidgetGroupWindow::event(QEvent *e)
@@ -390,16 +395,49 @@ void QDockWidgetGroupWindow::adjustFlags()
flags.setFlag(Qt::WindowCloseButtonHint, top->features() & QDockWidget::DockWidgetClosable);
flags &= ~Qt::FramelessWindowHint;
} else {
+ flags &= ~(Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
flags |= Qt::FramelessWindowHint;
}
+
if (oldFlags != flags) {
setWindowFlags(flags);
+ const bool gainedNativeDecos = (oldFlags & Qt::FramelessWindowHint) && !(flags & Qt::FramelessWindowHint);
+ const bool lostNativeDecos = !(oldFlags & Qt::FramelessWindowHint) && (flags & Qt::FramelessWindowHint);
+
+ // Adjust the geometry after gaining/losing decos, so that the client area appears always
+ // at the same place when tabbing
+ if (lostNativeDecos) {
+ QRect newGeometry = geometry();
+ newGeometry.setTop(frameGeometry().top());
+ const int bottomFrame = geometry().top() - frameGeometry().top();
+ m_removedFrameSize = QSize((frameSize() - size()).width(), bottomFrame);
+ setGeometry(newGeometry);
+ } else if (gainedNativeDecos && m_removedFrameSize.isValid()) {
+ QRect r = geometry();
+ r.adjust(-m_removedFrameSize.width() / 2, 0,
+ -m_removedFrameSize.width() / 2, -m_removedFrameSize.height());
+ setGeometry(r);
+ m_removedFrameSize = QSize();
+ }
+
show(); // setWindowFlags hides the window
}
setWindowTitle(top->windowTitle());
setWindowIcon(top->windowIcon());
}
+
+bool QDockWidgetGroupWindow::hasNativeDecos() const
+{
+ if (!QDockWidgetLayout::wmSupportsNativeWindowDeco())
+ return false;
+
+ if (QDockWidget *dw = topDockWidget())
+ return dw->titleBarWidget() == nullptr;
+
+ return true;
+}
+
#endif
/******************************************************************************
@@ -1704,6 +1742,9 @@ void QMainWindowLayout::tabChanged()
if (activated)
emit static_cast<QMainWindow *>(parentWidget())->tabifiedDockWidgetActivated(activated);
+ if (auto dwgw = qobject_cast<QDockWidgetGroupWindow*>(tb->parentWidget()))
+ dwgw->adjustFlags();
+
if (QWidget *w = centralWidget())
w->raise();
}
diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h
index 6e8b965431..40336caeba 100644
--- a/src/widgets/widgets/qmainwindowlayout_p.h
+++ b/src/widgets/widgets/qmainwindowlayout_p.h
@@ -83,9 +83,14 @@ public:
QDockWidget *topDockWidget() const;
void destroyOrHideIfEmpty();
void adjustFlags();
+ bool hasNativeDecos() const;
+
protected:
bool event(QEvent *) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
+
+private:
+ QSize m_removedFrameSize;
};
// This item will be used in the layout for the gap item. We cannot use QWidgetItem directly