Skip to content

Commit

Permalink
Tix toggle action drag and drop (#723)
Browse files Browse the repository at this point in the history
* Refactor

Move action drag behavior to specific WidgetActionDrag class
Remove virtual + final from WidgetAction class
Override WidgetAction destructor

* Check for dragging inside the ToggleAction and some housekeeping
  • Loading branch information
ThomasKroes authored Nov 20, 2024
1 parent fcdf193 commit b1e70ec
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 120 deletions.
2 changes: 2 additions & 0 deletions ManiVault/cmake/CMakeMvSourcesPublic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ set(PUBLIC_ACTIONS_INTERNAL_HEADERS
src/actions/WidgetActionMimeData.h
src/actions/WidgetActionHighlightWidget.h
src/actions/WidgetActionBadge.h
src/actions/WidgetActionDrag.h
src/actions/TasksTreeAction.h
src/actions/TasksListAction.h
src/actions/SplashScreenAction.h
Expand Down Expand Up @@ -356,6 +357,7 @@ set(PUBLIC_ACTIONS_INTERNAL_SOURCES
src/actions/WidgetActionMimeData.cpp
src/actions/WidgetActionHighlightWidget.cpp
src/actions/WidgetActionBadge.cpp
src/actions/WidgetActionDrag.cpp
src/actions/TasksTreeAction.cpp
src/actions/TasksListAction.cpp
src/actions/SplashScreenAction.cpp
Expand Down
8 changes: 6 additions & 2 deletions ManiVault/src/actions/ToggleAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ bool ToggleAction::CheckBoxWidget::eventFilter(QObject* target, QEvent* event)
{
case QEvent::MouseButtonPress:
{
auto mouseEvent = static_cast<QMouseEvent*>(event);
auto mouseEvent = dynamic_cast<QMouseEvent*>(event);

if (_toggleAction->isEnabled() && mouseEvent->button() == Qt::LeftButton)
if (_toggleAction->isEnabled() && mouseEvent->button() == Qt::LeftButton && !_toggleAction->getDrag().isDragging())
{
qDebug() << "Toggle!";
_toggleAction->setChecked(!_toggleAction->isChecked());
}


return true;
}
Expand Down
35 changes: 9 additions & 26 deletions ManiVault/src/actions/WidgetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include <QMenu>
#include <QJsonArray>
#include <QDrag>
#include <QDialog>
#include <QDialogButtonBox>
#include <QEventLoop>

#ifdef _DEBUG
//#define WIDGET_ACTION_VERBOSE
Expand All @@ -34,13 +32,12 @@ bool isInPopupMode(QWidget* parent) {
}

QMap<WidgetAction::Scope, QString> WidgetAction::scopeNames {
{ WidgetAction::Scope::Private, "Private" },
{ WidgetAction::Scope::Public, "Public" }
{ Scope::Private, "Private" },
{ Scope::Public, "Public" }
};

WidgetAction::WidgetAction(QObject* parent, const QString& title) :
QWidgetAction(parent),
util::Serializable(),
_defaultWidgetFlags(),
_sortIndex(-1),
_stretch(-1),
Expand All @@ -50,16 +47,11 @@ WidgetAction::WidgetAction(QObject* parent, const QString& title) :
_cachedConnectionPermissions(static_cast<std::int32_t>(ConnectionPermissionFlag::None)),
_scope(Scope::Private),
_publicAction(nullptr),
_connectedActions(),
_settingsPrefix(),
_highlighting(HighlightOption::None),
_popupSizeHint(),
_overrideSizeHint(),
_configuration(static_cast<std::int32_t>(ConfigurationFlag::Default)),
_location(),
_namedIcon(""),
_widgetConfigurationFunction(),
_badge(this)
_badge(this),
_drag(this)
{
Q_ASSERT(!title.isEmpty());

Expand Down Expand Up @@ -581,20 +573,6 @@ void WidgetAction::restoreConnectionPermissions(bool recursive /*= false*/)
childAction->restoreConnectionPermissions(recursive);
}

void WidgetAction::startDrag()
{
if (!mayConnect(WidgetAction::Gui))
return;

auto drag = new QDrag(this);
auto mimeData = new WidgetActionMimeData(this);

drag->setMimeData(mimeData);
drag->setPixmap(Application::getIconFont("FontAwesome").getIcon("link").pixmap(QSize(12, 12)));

drag->exec();
}

void WidgetAction::setSettingsPrefix(const QString& settingsPrefix, const bool& load /*= true*/)
{
_settingsPrefix = settingsPrefix;
Expand Down Expand Up @@ -964,6 +942,11 @@ WidgetActionBadge& WidgetAction::getBadge()
return _badge;
}

WidgetActionDrag& WidgetAction::getDrag()
{
return _drag;
}

void WidgetAction::setOverrideSizeHint(const QSize& sizeHint)
{
_overrideSizeHint = sizeHint;
Expand Down
Loading

0 comments on commit b1e70ec

Please sign in to comment.