1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Sérgio Martins <sergio.martins@kdab.com>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include "utils.h"
#include "Config.h"
#include "core/ViewFactory.h"
#include "QtCompat_p.h"
#include "core/DropArea.h"
#include "core/MainWindow.h"
#include "core/Platform.h"
#include "core/ViewGuard.h"
#include "core/Logging_p.h"
#include "core/Window_p.h"
using namespace KDDockWidgets;
using namespace KDDockWidgets::Core;
using namespace KDDockWidgets::Tests;
// clazy:excludeall=ctor-missing-parent-argument,missing-qobject-macro,range-loop,missing-typeinfo,detaching-member,function-args-by-ref,non-pod-global-static,reserve-candidates
std::unique_ptr<Core::MainWindow>
KDDockWidgets::Tests::createMainWindow(Size sz, KDDockWidgets::MainWindowOptions options,
const QString &name, bool show)
{
static int count = 0;
count++;
if (!sz.isValid())
sz = Size(1000, 1000);
const QString mainWindowName =
name.isEmpty() ? (QString("MyMainWindow") + QString::number(count)) : name;
CreateViewOptions viewOpts;
viewOpts.isVisible = show;
viewOpts.size = sz;
auto ptr = std::unique_ptr<Core::MainWindow>(
Platform::instance()->createMainWindow(mainWindowName, viewOpts, options));
if (show)
ptr->show();
ptr->view()->resize(sz);
return ptr;
}
Core::DockWidget *
KDDockWidgets::Tests::createDockWidget(const QString &name, View *guest, DockWidgetOptions options,
LayoutSaverOptions layoutSaverOptions, bool show,
const QString &affinityName)
{
assert(guest);
guest->setFocusPolicy(Qt::StrongFocus);
auto dock = Config::self()
.viewFactory()
->createDockWidget(name, options, layoutSaverOptions)
->asDockWidgetController();
dock->setAffinityName(affinityName);
dock->setGuestView(guest->asWrapper());
dock->setObjectName(name);
dock->view()->setGeometry(Rect(0, 0, 400, 400));
if (show) {
dock->open();
dock->dptr()->morphIntoFloatingWindow();
assert(dock->floatingWindow() || dock->isInMainWindow());
dock->view()->activateWindow();
assert(dock->view()->window());
#if defined(KDDW_FRONTEND_FLUTTER)
// Wait for window activation once we have flutter multi window
return dock;
#else
if (Platform::instance()->tests_waitForWindowActive(dock->view()->window(), 1000)) {
return dock;
}
#endif
KDDW_INFO("KDDockWidgets::Tests::createDockWidget: Couldn't activate window");
assert(false);
return nullptr;
} else {
return dock;
}
}
Core::DockWidget *KDDockWidgets::Tests::createDockWidget(const QString &name, LayoutSaverOptions layoutSaverOptions)
{
return createDockWidget(name,
Platform::instance()->tests_createView({ true, {}, { 100, 100 } }), {}, layoutSaverOptions);
}
std::unique_ptr<MainWindow> KDDockWidgets::Tests::createMainWindow(std::vector<DockDescriptor> &docks)
{
static int count = 0;
count++;
View *parent = nullptr;
CreateViewOptions viewOpts;
viewOpts.isVisible = true;
viewOpts.size = Size(1000, 1000);
auto m = std::unique_ptr<Core::MainWindow>(Platform::instance()->createMainWindow(
(QString("MyMainWindow") + QString::number(count)), viewOpts, MainWindowOption_None, parent));
auto layout = m->layout();
m->show();
m->view()->resize(Size(700, 700));
int i = 0;
for (DockDescriptor &desc : docks) {
auto guest = Platform::instance()->tests_createView({ true, {}, { 100, 100 } });
desc.createdDock =
createDockWidget((QString::number(i) + QString::number(count)), guest, {}, {}, false);
Core::DockWidget *relativeTo = nullptr;
if (desc.relativeToIndex != -1)
relativeTo = docks.at(desc.relativeToIndex).createdDock;
m->addDockWidget(desc.createdDock, desc.loc, relativeTo, desc.option);
layout->checkSanity();
++i;
}
return m;
}
bool KDDockWidgets::Tests::shouldBlacklistWarning(const QString &msg, const QString &category)
{
if (category == QLatin1String("qt.qpa.xcb"))
return true;
return msg.contains(QLatin1String("QSocketNotifier: Invalid socket"))
|| msg.contains(QLatin1String("QWindowsWindow::setGeometry"))
|| msg.contains(QLatin1String("This plugin does not support"))
|| msg.contains(QLatin1String("Note that Qt no longer ships fonts"))
|| msg.contains(QLatin1String("Another dock KDDockWidgets::DockWidget"))
|| msg.contains(
QLatin1String("There's multiple MainWindows, not sure what to do about parenting"));
}
void KDDockWidgets::Tests::doubleClickOn(Point globalPos, Window::Ptr receiver)
{
Platform::instance()->tests_doubleClickOn(globalPos, receiver);
}
void KDDockWidgets::Tests::pressOn(Point globalPos, View *receiver)
{
Platform::instance()->tests_pressOn(globalPos, receiver);
}
void KDDockWidgets::Tests::pressOn(Point globalPos, Window::Ptr receiver)
{
Platform::instance()->tests_pressOn(globalPos, receiver);
}
bool KDDockWidgets::Tests::releaseOn(Point globalPos, View *receiver)
{
auto instance = Platform::instance(); // separate variable due to weird clang-format issue
instance->tests_releaseOn(globalPos, receiver);
return true;
}
void KDDockWidgets::Tests::clickOn(Point globalPos, View *receiver)
{
pressOn(globalPos, receiver);
releaseOn(globalPos, receiver);
}
bool KDDockWidgets::Tests::moveMouseTo(Point globalDest, View *receiver)
{
Point globalSrc = receiver->mapToGlobal(Point(5, 5));
while (globalSrc != globalDest) {
if (globalSrc.x() < globalDest.x()) {
globalSrc.setX(globalSrc.x() + 1);
} else if (globalSrc.x() > globalDest.x()) {
globalSrc.setX(globalSrc.x() - 1);
}
if (globalSrc.y() < globalDest.y()) {
globalSrc.setY(globalSrc.y() + 1);
} else if (globalSrc.y() > globalDest.y()) {
globalSrc.setY(globalSrc.y() - 1);
}
if (!Platform::instance()->tests_mouseMove(globalSrc, receiver))
return true;
}
return true;
}
void KDDockWidgets::Tests::nestDockWidget(Core::DockWidget *dock, DropArea *dropArea,
Core::Group *relativeTo, Location location)
{
auto group = new Core::Group();
group->addTab(dock);
dock->d->group()->setObjectName(dock->objectName());
dropArea->addWidget(group->view(), location, relativeTo ? relativeTo->layoutItem() : nullptr);
assert(dropArea->checkSanity());
}
|