Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a26b7f4
Add toolbar customization: separator, show/hide buttons, lock
FTA7700 May 17, 2026
4b87e1f
Add drag-to-reorder functionality to CustomizableToolBar
FTA7700 May 21, 2026
8ff49ca
Fix file encoding and line endings to UTF-8/LF
FTA7700 May 21, 2026
f8fc283
Fix drag reorder for edge separators
FTA7700 May 23, 2026
3076b78
Fix separator swap threshold for rightward drag
FTA7700 May 23, 2026
5d1ec50
Handle queue actions in toolbar customization: dynamic show/hide, sub…
FTA7700 May 26, 2026
72473e4
Fix menu bar preservation and drag shuffle for hidden buttons
FTA7700 May 27, 2026
7b2ba19
Fix menu bar preservation and uniform drag shuffle threshold
FTA7700 May 27, 2026
47662d5
Style fixes: asConst, const bool, include order, drag threshold
FTA7700 May 28, 2026
8890914
Style: parenthesize comparisons in boolean chains
FTA7700 May 30, 2026
b11d4b8
Drag: reduce swap threshold for sooner response
FTA7700 May 31, 2026
d3dc11b
Test #2: Drag feel improvements — smoother separator crossing and no …
FTA7700 Jun 6, 2026
2dc63d0
Style: add missing asConst() and parenthesize comparisons
FTA7700 Jun 7, 2026
d3308c9
Style: revert redundant asConst(); fix separator 1-tick asymmetry
FTA7700 Jun 9, 2026
f5c8f86
Test #3: correct movingLeft detection on first drag tick for symmetri…
FTA7700 Jun 9, 2026
5c3249d
Merge remote-tracking branch 'upstream/master' into feature/toolbar-c…
FTA7700 Jul 2, 2026
285d593
Merge remote-tracking branch 'upstream/master' into feature/toolbar-c…
FTA7700 Jul 17, 2026
bcc6bed
Fix: remove duplicate managePlugins() left over from previous merge
FTA7700 Jul 17, 2026
876e32e
Add Reset Toolbar Buttons option to empty-space context menu
FTA7700 Jul 21, 2026
39d173d
Address review feedback: destructor, access, naming, GPL headers, met…
FTA7700 Jul 24, 2026
3c65914
[Style]: Add braces to multi-line if conditions, fix header path, rev…
FTA7700 Jul 25, 2026
7d44010
Retrigger CI
FTA7700 Jul 25, 2026
7249294
Apply style fixes from glassez's review round
FTA7700 Aug 1, 2026
5938a68
Encapsulate toolbar state in CustomizableToolBar
FTA7700 Aug 2, 2026
9f43254
Hide disabled toolbar actions automatically
FTA7700 Aug 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/base/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,30 @@ void Preferences::setMainGeometry(const QByteArray &geometry)
setValue(u"MainWindow/geometry"_s, geometry);
}

QByteArray Preferences::getToolbarState() const
{
return value<QByteArray>(u"MainWindow/toolbarState"_s);
}

void Preferences::setToolbarState(const QByteArray &state)
{
if (state == getToolbarState())
return;
setValue(u"MainWindow/toolbarState"_s, state);
}

bool Preferences::isToolbarLocked() const
{
return value(u"MainWindow/toolbarLocked"_s, true);
}

void Preferences::setToolbarLocked(const bool locked)
{
if (locked == isToolbarLocked())
return;
setValue(u"MainWindow/toolbarLocked"_s, locked);
}

bool Preferences::isFiltersSidebarVisible() const
{
return value(u"GUI/MainWindow/FiltersSidebarVisible"_s, true);
Expand Down
4 changes: 4 additions & 0 deletions src/base/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class Preferences final : public QObject
void setDNSLastIP(const QString &ip);
QByteArray getMainGeometry() const;
void setMainGeometry(const QByteArray &geometry);
QByteArray getToolbarState() const;
void setToolbarState(const QByteArray &state);
bool isToolbarLocked() const;
void setToolbarLocked(const bool locked);
bool isFiltersSidebarVisible() const;
void setFiltersSidebarVisible(bool value);
int getFiltersSidebarWidth() const;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_library(qbt_gui STATIC
log/logfiltermodel.h
log/loglistview.h
log/logmodel.h
customizabletoolbar.h

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect order.

mainwindow.h
optionsdialog.h
powermanagement/inhibitor.h
Expand Down Expand Up @@ -175,6 +176,7 @@ add_library(qbt_gui STATIC
log/logfiltermodel.cpp
log/loglistview.cpp
log/logmodel.cpp
customizabletoolbar.cpp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

mainwindow.cpp
optionsdialog.cpp
powermanagement/inhibitor.cpp
Expand Down
338 changes: 338 additions & 0 deletions src/gui/customizabletoolbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2026 FTA7700
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/

#include "customizabletoolbar.h"

#include <QAction>
#include <QActionEvent>
#include <QApplication>
#include <QCursor>
#include <QGraphicsOpacityEffect>
#include <QLabel>
#include <QMouseEvent>
#include <QPixmap>
#include <QTimer>

#include "base/global.h"

CustomizableToolBar::CustomizableToolBar(QWidget *parent)
: QToolBar(parent)
{
setMouseTracking(true);
}

CustomizableToolBar::CustomizableToolBar(const QString &title, QWidget *parent)
: QToolBar(title, parent)
{
setMouseTracking(true);
}

void CustomizableToolBar::lockAction(QAction *action)
{
if (action && !m_lockedActions.contains(action))
m_lockedActions.append(action);
}

void CustomizableToolBar::setLocked(const bool locked)
{
m_locked = locked;
}

void CustomizableToolBar::actionEvent(QActionEvent *event)
{
QToolBar::actionEvent(event);
if (event->type() == QEvent::ActionAdded)
{
if (QWidget *widget = widgetForAction(event->action()))
widget->installEventFilter(this);
}
}

bool CustomizableToolBar::eventFilter(QObject *watched, QEvent *event)
Comment thread
glassez marked this conversation as resolved.
{
if (m_locked)
return QToolBar::eventFilter(watched, event);

auto *widget = qobject_cast<QWidget *>(watched);
if (!widget)
return QToolBar::eventFilter(watched, event);

auto *mouseEvent = static_cast<QMouseEvent *>(event);

switch (event->type())
{
case QEvent::MouseButtonPress:
if (handleMousePress(widget, mouseEvent))
return true;
break;

case QEvent::MouseMove:
if (handleMouseMove(mouseEvent))
return true;
break;

case QEvent::MouseButtonRelease:
if (handleMouseRelease(mouseEvent))
return true;
break;

default:
break;
}

return QToolBar::eventFilter(watched, event);
}

bool CustomizableToolBar::handleMousePress(QWidget *widget, QMouseEvent *mouseEvent)
{
m_dragJustFinished = false;

if (mouseEvent->button() != Qt::LeftButton)
return false;

QAction *action = nullptr;
for (QAction *a : asConst(actions()))
{
if (widgetForAction(a) == widget)
{
action = a;
break;
}
}

if (!action || m_lockedActions.contains(action) || action->isSeparator())
return false;

m_dragAction = action;
m_dragWidget = widget;
m_dragStartPos = mouseEvent->globalPosition().toPoint();
m_dragOffsetX = mouseEvent->position().toPoint().x();
return false;
}

bool CustomizableToolBar::handleMouseMove(QMouseEvent *mouseEvent)
{
if (!m_dragAction)
return false;

const QPoint globalPos = mouseEvent->globalPosition().toPoint();

if (!m_dragging)
{
if ((globalPos - m_dragStartPos).manhattanLength() < QApplication::startDragDistance())
return false;
startDrag(m_dragWidget, globalPos);
}

return m_dragging;
}

bool CustomizableToolBar::handleMouseRelease(QMouseEvent *mouseEvent)
{
if (m_dragJustFinished)
{
m_dragJustFinished = false;
return true;
}
if (m_dragging)
{
endDrag(mouseEvent->globalPosition().toPoint());
return true;
}
if (m_dragAction)
m_dragAction = nullptr;
return false;
}

void CustomizableToolBar::onDragTimer()
{
if (!m_dragging)
return;

updateDrag(QCursor::pos());

if (!(QApplication::mouseButtons() & Qt::LeftButton))
endDrag(QCursor::pos());
}

void CustomizableToolBar::startDrag(QWidget *widget, const QPoint &globalPos)
{
m_dragging = true;

// Snapshot BEFORE making transparent
const QPixmap snap = widget->grab();

// Make drag widget invisible but keep it in layout, avoiding reflow
auto *effect = new QGraphicsOpacityEffect(widget);
effect->setOpacity(0.0);
widget->setGraphicsEffect(effect);

// Float label follows cursor globally
m_floatLabel = new QLabel(nullptr, Qt::ToolTip | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
m_floatLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
m_floatLabel->setAttribute(Qt::WA_ShowWithoutActivating);
m_floatLabel->setPixmap(snap);
m_floatLabel->setFixedSize(snap.size());
m_floatLabel->show();

m_dragTimer = new QTimer(this);
m_dragTimer->setInterval(16);
connect(m_dragTimer, &QTimer::timeout, this, &CustomizableToolBar::onDragTimer);
m_dragTimer->start();

updateDrag(globalPos);
}

void CustomizableToolBar::updateDrag(const QPoint &globalPos)
{
if (!m_floatLabel)
return;

const int fw = m_floatLabel->width();
const int fh = m_floatLabel->height();
const QPoint toolbarTopLeft = mapToGlobal(QPoint(0, 0));
const int boundaryGX = getBoundaryGlobalX();

const int clampedX = qBound(toolbarTopLeft.x(), globalPos.x() - m_dragOffsetX, boundaryGX - fw + 20);
const int clampedY = toolbarTopLeft.y() + (height() - fh) / 2;
m_floatLabel->move(clampedX, clampedY);

const int dragFloatLeft = mapFromGlobal(QPoint(clampedX, 0)).x();
const int dragFloatRight = mapFromGlobal(QPoint(clampedX + fw, 0)).x();
const int dragFloatCentre = mapFromGlobal(QPoint(clampedX + fw / 2, 0)).x();
const bool atLeftWall = (clampedX <= toolbarTopLeft.x());
const bool movingLeft = atLeftWall || (dragFloatCentre < m_lastFloatCentreX)
|| ((m_lastFloatCentreX == 0) && (globalPos.x() < m_dragStartPos.x()));
m_lastFloatCentreX = dragFloatCentre;

const int bi = findBoundaryIndex();
const QList<QAction *> acts = actions();

if (!acts.isEmpty() && (acts.first() == m_dragAction) && !movingLeft
&& (m_lastSwapX >= 0) && (qAbs(dragFloatLeft - m_lastSwapX) < 20))
{
return;
}
QAction *newInsertBefore = (bi >= 0) ? acts[bi] : nullptr;
for (int i = 0; i < bi; ++i)
{
QAction *a = acts[i];
if (a == m_dragAction)
continue;
QWidget *w = widgetForAction(a);
if (!w && !a->isSeparator())
continue;

const int threshold = w ? (a->isSeparator() ? (movingLeft ? w->x() + w->width() + fw / 2 : w->x() - fw / 2) : w->x() + w->width() / 2) : 0;

const int compareX = a->isSeparator() ? dragFloatCentre : (movingLeft ? dragFloatLeft : dragFloatRight);
if (compareX < threshold)
{
newInsertBefore = a;
break;
}
}

const bool targetIsSeparator = newInsertBefore && newInsertBefore->isSeparator();
if (!targetIsSeparator && (m_lastSwapX >= 0) && (qAbs(dragFloatLeft - m_lastSwapX) < 14))
return;
// Only swap when target slot changes, one atomic reorder per crossing
if (newInsertBefore == m_gapTarget)
return;

m_gapTarget = newInsertBefore;
m_lastSwapX = dragFloatLeft;

// Briefly remove opacity effect during reorder, reapply to new widget
if (m_dragWidget)
m_dragWidget->setGraphicsEffect(nullptr);

removeAction(m_dragAction);
insertAction(m_gapTarget, m_dragAction);

QWidget *newWidget = widgetForAction(m_dragAction);
if (newWidget)
{
m_dragWidget = newWidget;
auto *effect = new QGraphicsOpacityEffect(newWidget);
effect->setOpacity(0.0);
newWidget->setGraphicsEffect(effect);
}
}

void CustomizableToolBar::endDrag(const QPoint &)
{

if (m_dragTimer)
{
m_dragTimer->stop();
delete m_dragTimer;
m_dragTimer = nullptr;
}

delete m_floatLabel;
m_floatLabel = nullptr;

// Remove opacity effect, restore widget appearance
if (m_dragWidget)
m_dragWidget->setGraphicsEffect(nullptr);

// Reorder already committed live in updateDrag, just save state
emit actionOrderChanged();

m_gapTarget = nullptr;
m_lastSwapX = -1;
m_lastFloatCentreX = 0;
m_dragAction = nullptr;
m_dragWidget = nullptr;
m_dragJustFinished = true;
m_dragging = false;
}

int CustomizableToolBar::findBoundaryIndex() const
{
const QList<QAction *> acts = actions();
for (int i = 0; i < acts.size(); ++i)
{
if (m_lockedActions.contains(acts[i]))
return i;
}
return -1;
}

int CustomizableToolBar::getBoundaryGlobalX() const
{
const int bi = findBoundaryIndex();
if (bi >= 0)
{
QWidget *bw = widgetForAction(actions()[bi]);
if (bw)
return mapToGlobal(QPoint(bw->x(), 0)).x();
}
return mapToGlobal(QPoint(width(), 0)).x();
}
Loading
Loading