12#include "ViewWrapper_p.h"
13#include "core/View_p.h"
26#include "qtwidgets/Window_p.h"
29#include "kddockwidgets/core/MDILayout.h"
30#include "kddockwidgets/core/DropArea.h"
31#include "kddockwidgets/core/SideBar.h"
45 for (
int i =
int(Core::ViewType::FIRST); i <= int(Core::ViewType::LAST); i *= 2) {
49 case Core::ViewType::Frame:
50 if (
auto view = qobject_cast<Group *>(widget))
51 return view->controller();
53 case Core::ViewType::TitleBar:
54 if (
auto view = qobject_cast<TitleBar *>(widget))
55 return view->controller();
57 case Core::ViewType::TabBar:
58 if (
auto view = qobject_cast<TabBar *>(widget))
59 return view->controller();
61 case Core::ViewType::Stack:
62 if (
auto view = qobject_cast<Stack *>(widget))
63 return view->controller();
65 case Core::ViewType::FloatingWindow:
66 if (
auto view = qobject_cast<FloatingWindow *>(widget))
67 return view->controller();
69 case Core::ViewType::Separator:
70 if (
auto view = qobject_cast<Separator *>(widget))
71 return view->controller();
73 case Core::ViewType::DockWidget:
74 if (
auto view = qobject_cast<DockWidget *>(widget))
75 return view->controller();
77 case Core::ViewType::DropArea:
78 if (
auto view = qobject_cast<DropArea *>(widget))
79 return view->controller();
81 case Core::ViewType::MDILayout:
82 if (
auto view = qobject_cast<MDILayout *>(widget))
83 return view->controller();
85 case Core::ViewType::SideBar:
86 if (
auto view = qobject_cast<SideBar *>(widget))
87 return view->controller();
89 case Core::ViewType::MainWindow:
90 if (
auto view = qobject_cast<MainWindow *>(widget))
91 return view->controller();
93 case Core::ViewType::RubberBand:
94 case Core::ViewType::LayoutItem:
95 case Core::ViewType::ViewWrapper:
96 case Core::ViewType::DropAreaIndicatorOverlay:
97 case Core::ViewType::None:
108std::shared_ptr<Core::View> ViewWrapper::create(
QObject *widget)
110 return create(qobject_cast<QWidget *>(widget));
114std::shared_ptr<Core::View> ViewWrapper::create(
QWidget *widget)
120 auto sharedptr = std::shared_ptr<View>(wrapper);
121 wrapper->d->m_thisWeakPtr = sharedptr;
126ViewWrapper::ViewWrapper(
QObject *widget)
131ViewWrapper::ViewWrapper(
QWidget *widget)
137QRect ViewWrapper::geometry()
const
139 return m_widget->geometry();
144 return m_widget->mapToGlobal(localPt);
149 return m_widget->mapFromGlobal(globalPt);
152void ViewWrapper::setGeometry(
QRect rect)
154 m_widget->setGeometry(rect);
157std::shared_ptr<Core::Window> ViewWrapper::window()
const
159 if (m_widget->window()->windowHandle())
160 return std::shared_ptr<Core::Window>(
new Window(m_widget->window()));
165bool ViewWrapper::isRootView()
const
167 return m_widget->isWindow();
170void ViewWrapper::setVisible(
bool is)
172 m_widget->setVisible(is);
175bool ViewWrapper::isVisible()
const
177 return m_widget->isVisible();
180bool ViewWrapper::isExplicitlyHidden()
const
182 return m_widget->isHidden();
185void ViewWrapper::move(
int x,
int y)
187 m_widget->move(x, y);
190void ViewWrapper::activateWindow()
192 m_widget->activateWindow();
195bool ViewWrapper::isMaximized()
const
197 return m_widget->isMaximized();
200bool ViewWrapper::isMinimized()
const
202 return m_widget->isMinimized();
205void ViewWrapper::setSize(
int x,
int y)
207 m_widget->resize(x, y);
212 if (t == Core::ViewType::ViewWrapper)
217 case Core::ViewType::Frame:
218 return qobject_cast<QtWidgets::Group *>(m_widget);
219 case Core::ViewType::TitleBar:
220 return qobject_cast<QtWidgets::TitleBar *>(m_widget);
221 case Core::ViewType::TabBar:
222 return qobject_cast<QtWidgets::TabBar *>(m_widget);
223 case Core::ViewType::Stack:
224 return qobject_cast<QtWidgets::Stack *>(m_widget);
225 case Core::ViewType::FloatingWindow:
226 return qobject_cast<QtWidgets::FloatingWindow *>(m_widget);
227 case Core::ViewType::Separator:
228 return qobject_cast<QtWidgets::Separator *>(m_widget);
229 case Core::ViewType::DockWidget:
230 return qobject_cast<QtWidgets::DockWidget *>(m_widget);
231 case Core::ViewType::SideBar:
232 return qobject_cast<QtWidgets::SideBar *>(m_widget);
233 case Core::ViewType::MainWindow:
234 return qobject_cast<QtWidgets::MainWindow *>(m_widget);
235 case Core::ViewType::DropArea:
236 return qobject_cast<QtWidgets::DropArea *>(m_widget);
237 case Core::ViewType::MDILayout:
238 return qobject_cast<MDILayout *>(m_widget);
239 case Core::ViewType::RubberBand:
240 return qobject_cast<RubberBand *>(m_widget);
241 case Core::ViewType::LayoutItem:
242 case Core::ViewType::None:
243 case Core::ViewType::DropAreaIndicatorOverlay:
244 qWarning() << Q_FUNC_INFO <<
"These are framework internals that are not wrapped";
246 case Core::ViewType::ViewWrapper:
250 qWarning() << Q_FUNC_INFO <<
"Unknown type" <<
static_cast<int>(t);
254std::shared_ptr<Core::View> ViewWrapper::rootView()
const
256 if (
auto w = m_widget->window())
257 return std::shared_ptr<Core::View>(
new ViewWrapper(w));
262std::shared_ptr<Core::View> ViewWrapper::parentView()
const
264 if (
auto p = m_widget->parentWidget())
265 return std::shared_ptr<Core::View>(
new ViewWrapper(p));
270std::shared_ptr<Core::View> ViewWrapper::childViewAt(
QPoint localPos)
const
273 return std::shared_ptr<Core::View>(
new ViewWrapper(child));
278void ViewWrapper::grabMouse()
280 m_widget->grabMouse();
283void ViewWrapper::releaseMouse()
285 m_widget->releaseMouse();
290 m_widget->setFocus(reason);
293QString ViewWrapper::viewName()
const
295 return m_widget->QWidget::objectName();
298bool ViewWrapper::isNull()
const
300 return m_widget.
data() ==
nullptr;
303QWidget *ViewWrapper::widget()
const
308void ViewWrapper::setWindowTitle(
const QString &title)
315 return m_widget->mapTo(View_qt::asQWidget(someAncestor), pos);
320 return m_widget->testAttribute(attr);
325 m_widget->setCursor(cursor);
328QSize ViewWrapper::minSize()
const
330 const int minW = m_widget->minimumWidth() > 0 ? m_widget->minimumWidth()
331 : m_widget->minimumSizeHint().
width();
333 const int minH = m_widget->minimumHeight() > 0 ? m_widget->minimumHeight()
334 : m_widget->minimumSizeHint().height();
344void ViewWrapper::setParent(
Core::View *parent)
349bool ViewWrapper::close()
351 return m_widget->close();
356 return m_widget->focusPolicy();
361 m_widget->setFocusPolicy(policy);
364bool ViewWrapper::hasFocus()
const
366 return m_widget->hasFocus();
369QSize ViewWrapper::maxSizeHint()
const
371 return m_widget->maximumSize();
374void ViewWrapper::raiseAndActivate()
QSize expandedTo(const QSize &otherSize) const const
QMainWindow sub-class to enable KDDockWidgets support.