Add convenience View::is(Type)
This commit is contained in:
@@ -168,4 +168,9 @@ Controller *View::controller() const
|
||||
QSize View::hardcodedMinimumSize()
|
||||
{
|
||||
return Layouting::Item::hardcodedMinimumSize;
|
||||
}
|
||||
}
|
||||
|
||||
bool View::is(Type t) const
|
||||
{
|
||||
return m_type == t;
|
||||
}
|
||||
|
||||
@@ -218,6 +218,11 @@ public:
|
||||
return max;
|
||||
}
|
||||
|
||||
/// @brief Returns whether the view is of the specified type
|
||||
/// Virtual so it can be overridden by ViewWrapper. When we're wrapping an existing GUI element
|
||||
/// only the specific frontend can know what's the actual type
|
||||
virtual bool is(Type) const;
|
||||
|
||||
protected:
|
||||
virtual void free_impl();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace KDDockWidgets::Views {
|
||||
|
||||
class DOCKS_EXPORT Separator_qtwidgets : public View_qtwidgets<QWidget>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Separator_qtwidgets(Controllers::Separator *controller, QWidget *parent = nullptr);
|
||||
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
*/
|
||||
|
||||
#include "ViewWrapper_qtwidgets.h"
|
||||
#include "views_qtwidgets/DockWidget_qtwidgets.h"
|
||||
#include "views_qtwidgets/FloatingWindow_qtwidgets.h"
|
||||
#include "views_qtwidgets/Frame_qtwidgets.h"
|
||||
#include "views_qtwidgets/MainWindow_qtwidgets.h"
|
||||
#include "views_qtwidgets/Separator_qtwidgets.h"
|
||||
#include "views_qtwidgets/SideBar_qtwidgets.h"
|
||||
#include "views_qtwidgets/Stack_qtwidgets.h"
|
||||
#include "views_qtwidgets/TabBar_qtwidgets.h"
|
||||
#include "views_qtwidgets/TitleBar_qtwidgets.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -95,3 +104,42 @@ void ViewWrapper_qtwidgets::setSize(int x, int y)
|
||||
{
|
||||
m_widget->resize(x, y);
|
||||
}
|
||||
|
||||
bool ViewWrapper_qtwidgets::is(Type t) const
|
||||
{
|
||||
if (t == Type::ViewWrapper)
|
||||
return true;
|
||||
|
||||
switch (t) {
|
||||
|
||||
case Type::Frame:
|
||||
return qobject_cast<Views::Frame_qtwidgets *>(m_widget);
|
||||
case Type::TitleBar:
|
||||
return qobject_cast<Views::TitleBar_qtwidgets *>(m_widget);
|
||||
case Type::TabBar:
|
||||
return qobject_cast<Views::TabBar_qtwidgets *>(m_widget);
|
||||
case Type::Stack:
|
||||
return qobject_cast<Views::Stack_qtwidgets *>(m_widget);
|
||||
case Type::FloatingWindow:
|
||||
return qobject_cast<Views::FloatingWindow_qtwidgets *>(m_widget);
|
||||
case Type::Separator:
|
||||
return qobject_cast<Views::Separator_qtwidgets *>(m_widget);
|
||||
case Type::DockWidget:
|
||||
return qobject_cast<Views::DockWidget_qtwidgets *>(m_widget);
|
||||
case Type::SideBar:
|
||||
return qobject_cast<Views::SideBar_qtwidgets *>(m_widget);
|
||||
case Type::MainWindow:
|
||||
return qobject_cast<Views::MainWindow_qtwidgets *>(m_widget);
|
||||
case Type::Layout:
|
||||
return qobject_cast<LayoutWidget *>(m_widget);
|
||||
case Type::LayoutItem:
|
||||
case Type::DropIndicatorOverlayInterface:
|
||||
qWarning() << Q_FUNC_INFO << "These are framework internals that are not wrapped";
|
||||
return false;
|
||||
case Type::ViewWrapper:
|
||||
return true;
|
||||
}
|
||||
|
||||
qWarning() << Q_FUNC_INFO << "Unknown type" << static_cast<int>(t);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
bool isMaximized() const override;
|
||||
QSize maximumSize() const override;
|
||||
void setSize(int width, int height) override;
|
||||
bool is(Type) const override;
|
||||
|
||||
private:
|
||||
QWidget *const m_widget;
|
||||
|
||||
Reference in New Issue
Block a user