Added DockWidget::isInMainWindow()
For task #69. A signal would be nice too, though.
This commit is contained in:
@@ -77,6 +77,20 @@ public:
|
||||
return qobject_cast<FloatingWindow*>(q->window());
|
||||
}
|
||||
|
||||
MainWindowBase *mainWindow() const
|
||||
{
|
||||
// Note: Don't simply use window(), as the MainWindow might be embedded into something else
|
||||
QObject *p = q->parent();
|
||||
while (p) {
|
||||
if (auto window = qobject_cast<MainWindowBase*>(p))
|
||||
return window;
|
||||
|
||||
p = p->parent();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QPoint defaultCenterPosForFloating();
|
||||
|
||||
void updateTitle();
|
||||
@@ -430,6 +444,11 @@ bool DockWidgetBase::isMainWindow() const
|
||||
return qobject_cast<MainWindowBase*>(widget());
|
||||
}
|
||||
|
||||
bool DockWidgetBase::isInMainWindow() const
|
||||
{
|
||||
return d->mainWindow() != nullptr;
|
||||
}
|
||||
|
||||
bool DockWidgetBase::isFocused() const
|
||||
{
|
||||
auto f = this->frame();
|
||||
|
||||
@@ -320,6 +320,16 @@ public:
|
||||
*/
|
||||
bool isMainWindow() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns whether this dock widget is docked into a main window.
|
||||
*
|
||||
* Note that isFloating() returning false might either mean the dock widget is docked into a
|
||||
* main window or into a floating window (groupped/nested with other dock widgets. Use this function
|
||||
* then if you need to disambiguate
|
||||
*/
|
||||
bool isInMainWindow() const;
|
||||
|
||||
///@brief Returns whether This or any child of this dock widget is focused
|
||||
///Not to be confused with QWidget::hasFocus(), which just refers to 1 widget. This includes
|
||||
///variant includes children.
|
||||
|
||||
@@ -429,6 +429,7 @@ private Q_SLOTS:
|
||||
void tst_stuckSeparator();
|
||||
void tst_isFocused();
|
||||
void tst_setWidget();
|
||||
void tst_isInMainWindow();
|
||||
|
||||
private:
|
||||
std::unique_ptr<MultiSplitter> createMultiSplitterFromSetup(MultiSplitterSetup setup, QHash<QWidget *, Frame *> &frameMap) const;
|
||||
@@ -5822,6 +5823,19 @@ void TestDocks::tst_setWidget()
|
||||
delete dw;
|
||||
}
|
||||
|
||||
void TestDocks::tst_isInMainWindow()
|
||||
{
|
||||
EnsureTopLevelsDeleted e;
|
||||
auto dw = new DockWidget(QStringLiteral("FOO"));
|
||||
dw->show();
|
||||
auto fw = dw->window();
|
||||
QVERIFY(!dw->isInMainWindow());
|
||||
auto m1 = createMainWindow(QSize(2560, 809), MainWindowOption_None, "MainWindow1");
|
||||
m1->addDockWidget(dw, KDDockWidgets::Location_OnLeft);
|
||||
QVERIFY(dw->isInMainWindow());
|
||||
delete fw;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (!qpaPassedAsArgument(argc, argv)) {
|
||||
|
||||
Reference in New Issue
Block a user