quick: Implement separator support
you can now drag separators in the QML example
This commit is contained in:
@@ -39,7 +39,9 @@ if (BUILD_MULTISPLITTER_QTQUICK_FRONTEND)
|
||||
add_definitions(-DKDMULTISPLITTER_QTQUICK)
|
||||
endif()
|
||||
|
||||
add_library(kddockwidgets_multisplitter SHARED ${MULTISPLITTER_SRCS})
|
||||
qt5_add_resources(MULTISPLITTER_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/multisplitter.qrc)
|
||||
|
||||
add_library(kddockwidgets_multisplitter SHARED ${MULTISPLITTER_SRCS} ${MULTISPLITTER_RESOURCES})
|
||||
add_library(KDAB::kddockwidgets_multisplitter ALIAS kddockwidgets_multisplitter)
|
||||
target_link_libraries(kddockwidgets_multisplitter Qt5::Core Qt5::Widgets)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ struct Separator::Private
|
||||
Private(Widget *host)
|
||||
: m_hostWidget(host) {}
|
||||
|
||||
Qt::Orientation orientation;
|
||||
Qt::Orientation orientation = Qt::Horizontal;
|
||||
QRect geometry;
|
||||
int lazyPosition = 0;
|
||||
// SeparatorOptions m_options; TODO: Have a Layouting::Config
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
|
||||
///@brief Returns whether we're dragging a separator. Can be useful for the app to stop other work while we're not in the final size
|
||||
static bool isResizing();
|
||||
|
||||
virtual Widget* asWidget() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "Logging_p.h"
|
||||
#include "Item_p.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
using namespace Layouting;
|
||||
|
||||
namespace Layouting {
|
||||
@@ -34,7 +36,8 @@ class RubberBand : public QQuickItem
|
||||
public:
|
||||
RubberBand(Layouting::Widget *parent)
|
||||
: QQuickItem(parent ? qobject_cast<QQuickItem*>(parent->asQObject()) : nullptr)
|
||||
, Layouting::Widget_quick(this) {
|
||||
, Layouting::Widget_quick(this)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,6 +48,15 @@ SeparatorQuick::SeparatorQuick(Layouting::Widget *parent)
|
||||
, Separator(parent)
|
||||
, Layouting::Widget_quick(this)
|
||||
{
|
||||
createQQuickItem(QStringLiteral(":/kddockwidgets/multisplitter/qml/Separator.qml"), this);
|
||||
|
||||
// Only set on Separator::init(), so single-shot
|
||||
QTimer::singleShot(0, this, &SeparatorQuick::isVerticalChanged);
|
||||
}
|
||||
|
||||
bool SeparatorQuick::isVertical() const
|
||||
{
|
||||
return Separator::isVertical();
|
||||
}
|
||||
|
||||
Layouting::Widget *SeparatorQuick::createRubberBand(Layouting::Widget *parent)
|
||||
@@ -61,3 +73,24 @@ Widget *SeparatorQuick::asWidget()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void SeparatorQuick::onMousePressed()
|
||||
{
|
||||
Separator::onMousePress();
|
||||
}
|
||||
|
||||
void SeparatorQuick::onMouseMoved(QPointF localPos)
|
||||
{
|
||||
const QPointF pos = QQuickItem::mapToItem(parentItem(), localPos);
|
||||
Separator::onMouseMove(pos.toPoint());
|
||||
}
|
||||
|
||||
void SeparatorQuick::onMouseReleased()
|
||||
{
|
||||
Separator::onMouseReleased();
|
||||
}
|
||||
|
||||
void SeparatorQuick::onMouseDoubleClicked()
|
||||
{
|
||||
Separator::onMouseDoubleClick();
|
||||
}
|
||||
|
||||
@@ -35,12 +35,25 @@ class MULTISPLITTER_EXPORT SeparatorQuick
|
||||
, public Layouting::Widget_quick
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isVertical READ isVertical NOTIFY isVerticalChanged)
|
||||
public:
|
||||
explicit SeparatorQuick(Layouting::Widget *parent = nullptr);
|
||||
protected:
|
||||
|
||||
bool isVertical() const;
|
||||
|
||||
protected:
|
||||
Widget* createRubberBand(Widget *parent) override;
|
||||
Widget *asWidget() override;
|
||||
|
||||
public:
|
||||
// Interface with QML:
|
||||
Q_INVOKABLE void onMousePressed();
|
||||
Q_INVOKABLE void onMouseMoved(QPointF localPos);
|
||||
Q_INVOKABLE void onMouseReleased();
|
||||
Q_INVOKABLE void onMouseDoubleClicked();
|
||||
Q_SIGNALS:
|
||||
// constant but it's only set after Separator::init
|
||||
void isVerticalChanged();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
5
src/private/multisplitter/multisplitter.qrc
Normal file
5
src/private/multisplitter/multisplitter.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/kddockwidgets/multisplitter/">
|
||||
<file>qml/Separator.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
30
src/private/multisplitter/qml/Separator.qml
Normal file
30
src/private/multisplitter/qml/Separator.qml
Normal file
@@ -0,0 +1,30 @@
|
||||
import QtQuick 2.6
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
anchors.fill: parent
|
||||
color: "yellow"
|
||||
|
||||
readonly property QtObject kddwSeparator: parent
|
||||
|
||||
MouseArea {
|
||||
cursorShape: kddwSeparator ? (kddwSeparator.isVertical ? Qt.SizeVerCursor : Qt.SizeHorCursor)
|
||||
: Qt.SizeHorCursor
|
||||
anchors.fill: parent
|
||||
onPressed: {
|
||||
kddwSeparator.onMousePressed();
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
kddwSeparator.onMouseReleased();
|
||||
}
|
||||
|
||||
onPositionChanged: {
|
||||
kddwSeparator.onMouseMoved(Qt.point(mouse.x, mouse.y));
|
||||
}
|
||||
|
||||
onDoubleClicked: {
|
||||
kddwSeparator.onMouseDoubleClicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user