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::Group:
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);
213 case Core::ViewType::Group:
214 return qobject_cast<QtWidgets::Group *>(m_widget);
215 case Core::ViewType::TitleBar:
216 return qobject_cast<QtWidgets::TitleBar *>(m_widget);
217 case Core::ViewType::TabBar:
218 return qobject_cast<QtWidgets::TabBar *>(m_widget);
219 case Core::ViewType::Stack:
220 return qobject_cast<QtWidgets::Stack *>(m_widget);
221 case Core::ViewType::FloatingWindow:
222 return qobject_cast<QtWidgets::FloatingWindow *>(m_widget);
223 case Core::ViewType::Separator:
224 return qobject_cast<QtWidgets::Separator *>(m_widget);
225 case Core::ViewType::DockWidget:
226 return qobject_cast<QtWidgets::DockWidget *>(m_widget);
227 case Core::ViewType::SideBar:
228 return qobject_cast<QtWidgets::SideBar *>(m_widget);
229 case Core::ViewType::MainWindow:
230 return qobject_cast<QtWidgets::MainWindow *>(m_widget);
231 case Core::ViewType::DropArea:
232 return qobject_cast<QtWidgets::DropArea *>(m_widget);
233 case Core::ViewType::MDILayout:
234 return qobject_cast<MDILayout *>(m_widget);
235 case Core::ViewType::RubberBand:
236 return qobject_cast<RubberBand *>(m_widget);
237 case Core::ViewType::LayoutItem:
238 case Core::ViewType::None:
239 case Core::ViewType::DropAreaIndicatorOverlay:
240 qWarning() << Q_FUNC_INFO <<
"These are framework internals that are not wrapped";
242 case Core::ViewType::ViewWrapper:
246 qWarning() << Q_FUNC_INFO <<
"Unknown type" <<
static_cast<int>(t);
250std::shared_ptr<Core::View> ViewWrapper::rootView()
const
252 if (
auto w = m_widget->window())
253 return std::shared_ptr<Core::View>(
new ViewWrapper(w));
258std::shared_ptr<Core::View> ViewWrapper::parentView()
const
260 if (
auto p = m_widget->parentWidget())
261 return std::shared_ptr<Core::View>(
new ViewWrapper(p));
266std::shared_ptr<Core::View> ViewWrapper::childViewAt(
QPoint localPos)
const
269 return std::shared_ptr<Core::View>(
new ViewWrapper(child));
274void ViewWrapper::grabMouse()
276 m_widget->grabMouse();
279void ViewWrapper::releaseMouse()
281 m_widget->releaseMouse();
286 m_widget->setFocus(reason);
289QString ViewWrapper::viewName()
const
291 return m_widget->QWidget::objectName();
294bool ViewWrapper::isNull()
const
296 return m_widget.
data() ==
nullptr;
299QWidget *ViewWrapper::widget()
const
304void ViewWrapper::setWindowTitle(
const QString &title)
311 return m_widget->mapTo(View_qt::asQWidget(someAncestor), pos);
316 return m_widget->testAttribute(attr);
321 m_widget->setCursor(cursor);
324QSize ViewWrapper::minSize()
const
326 const int minW = m_widget->minimumWidth() > 0 ? m_widget->minimumWidth()
327 : m_widget->minimumSizeHint().
width();
329 const int minH = m_widget->minimumHeight() > 0 ? m_widget->minimumHeight()
330 : m_widget->minimumSizeHint().height();
340void ViewWrapper::setParent(
Core::View *parent)
345bool ViewWrapper::close()
347 return m_widget->close();
352 return m_widget->focusPolicy();
357 m_widget->setFocusPolicy(policy);
360bool ViewWrapper::hasFocus()
const
362 return m_widget->hasFocus();
365QSize ViewWrapper::maxSizeHint()
const
367 return m_widget->maximumSize();
370void ViewWrapper::raiseAndActivate()
QSize expandedTo(const QSize &otherSize) const const
QMainWindow sub-class to enable KDDockWidgets support.