Skip to content

Commit

Permalink
Label list actions in settings dialog more clearly
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Nov 23, 2024
1 parent 710d1b1 commit fe75dab
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 48 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Unreleased Version 2.2.2-pre
* Server Fix: Work around too many authenticated users in a session, which could cause a crash. Thanks Liz for reporting.
* Fix: Don't crash when filling with feathering and a canvas-filling selection. Thanks Meru for reporting.
* Fix: Don't carry over HUD button presses to dock UI in small screen mode. Thanks Meru for reporting.
* Feature: Make list action buttons in settings dialog clearer, adding an edit button for canvas shortcuts. Thanks Maffi for suggesting.

2024-11-06 Version 2.2.2-beta.4
* Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting.
Expand Down
122 changes: 94 additions & 28 deletions src/desktop/dialogs/settingsdialog/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,62 @@
namespace dialogs {
namespace settingsdialog {

inline void setUpToolButton(
QToolButton *button, const QIcon &icon, const QString &text,
const QString &toolTip)
{
button->setIcon(icon);
button->setToolButtonStyle(
text.isEmpty() ? Qt::ToolButtonIconOnly : Qt::ToolButtonTextBesideIcon);
button->setText(text);
button->setToolTip(toolTip);
}

template <
typename AddCallback, typename RemoveCallback, typename MoveUpCallback,
typename MoveDownCallback>
typename AddCallback, typename EditCallback, typename RemoveCallback,
typename MoveUpCallback, typename MoveDownCallback>
utils::EncapsulatedLayout *listActions(
QAbstractItemView *view, const QString &addLabel, AddCallback addCallback,
const QString &removeLabel, RemoveCallback removeCallback,
const QString &moveUpLabel, MoveUpCallback moveUpCallback,
const QString &moveDownLabel, MoveDownCallback moveDownCallback,
bool includeMove = true)
QAbstractItemView *view, const QString &addText, const QString &addToolTip,
AddCallback addCallback, const QString &editText,
const QString &editToolTip, EditCallback editCallback,
const QString &removeText, const QString &removeToolTip,
RemoveCallback removeCallback, const QString &moveUpText,
const QString &moveUpToolTip, MoveUpCallback moveUpCallback,
const QString &moveDownText, const QString &moveDownToolTip,
MoveDownCallback moveDownCallback, bool includeEdit, bool includeMove)
{
auto *buttons = new utils::EncapsulatedLayout;
utils::EncapsulatedLayout *buttons = new utils::EncapsulatedLayout;
buttons->setContentsMargins(0, 0, 0, 0);
buttons->setSpacing(0);

auto *add =
widgets::GroupedToolButton *add =
new widgets::GroupedToolButton(widgets::GroupedToolButton::GroupLeft);
add->setText(addLabel);
add->setIcon(QIcon::fromTheme("list-add"));
setUpToolButton(add, QIcon::fromTheme("list-add"), addText, addToolTip);
QObject::connect(
add, &widgets::GroupedToolButton::clicked, view, addCallback);
buttons->addWidget(add);

auto *remove = new widgets::GroupedToolButton(
if(includeEdit) {
widgets::GroupedToolButton *edit = new widgets::GroupedToolButton(
widgets::GroupedToolButton::GroupCenter);
setUpToolButton(
edit, QIcon::fromTheme("edit-rename"), editText, editToolTip);
edit->setEnabled(view->selectionModel()->hasSelection());
QObject::connect(
view->selectionModel(), &QItemSelectionModel::selectionChanged,
view, [=] {
edit->setEnabled(view->selectionModel()->hasSelection());
});
QObject::connect(
edit, &widgets::GroupedToolButton::clicked, view, editCallback);
buttons->addWidget(edit);
}

widgets::GroupedToolButton *remove = new widgets::GroupedToolButton(
includeMove ? widgets::GroupedToolButton::GroupCenter
: widgets::GroupedToolButton::GroupRight);
remove->setText(removeLabel);
remove->setIcon(QIcon::fromTheme("list-remove"));
setUpToolButton(
remove, QIcon::fromTheme("list-remove"), removeText, removeToolTip);
remove->setEnabled(view->selectionModel()->hasSelection());
QObject::connect(
view->selectionModel(), &QItemSelectionModel::selectionChanged, view,
Expand All @@ -57,13 +86,13 @@ utils::EncapsulatedLayout *listActions(
buttons->addWidget(remove);

if(includeMove) {
auto *moveUp = new widgets::GroupedToolButton(
widgets::GroupedToolButton *moveUp = new widgets::GroupedToolButton(
widgets::GroupedToolButton::GroupCenter);
moveUp->setText(moveUpLabel);
moveUp->setIcon(QIcon::fromTheme("arrow-up"));
setUpToolButton(
moveUp, QIcon::fromTheme("arrow-up"), moveUpText, moveUpToolTip);
moveUp->setEnabled(view->selectionModel()->hasSelection());
auto updateMoveUp = [=] {
auto selectionModel = view->selectionModel();
std::function<void()> updateMoveUp = [=] {
QItemSelectionModel *selectionModel = view->selectionModel();
moveUp->setEnabled(
selectionModel->hasSelection() &&
selectionModel->selectedIndexes().size() == 1 &&
Expand All @@ -78,13 +107,14 @@ utils::EncapsulatedLayout *listActions(
moveUp, &widgets::GroupedToolButton::clicked, view, moveUpCallback);
buttons->addWidget(moveUp);

auto *moveDown = new widgets::GroupedToolButton(
widgets::GroupedToolButton *moveDown = new widgets::GroupedToolButton(
widgets::GroupedToolButton::GroupRight);
moveDown->setText(moveDownLabel);
moveDown->setIcon(QIcon::fromTheme("arrow-down"));
setUpToolButton(
moveDown, QIcon::fromTheme("arrow-down"), moveDownText,
moveDownToolTip);
moveDown->setEnabled(view->selectionModel()->hasSelection());
auto updateMoveDown = [=] {
auto selectionModel = view->selectionModel();
std::function<void()> updateMoveDown = [=] {
QItemSelectionModel *selectionModel = view->selectionModel();
moveDown->setEnabled(
selectionModel->hasSelection() &&
selectionModel->selectedIndexes().size() == 1 &&
Expand All @@ -106,15 +136,51 @@ utils::EncapsulatedLayout *listActions(
return buttons;
}

template <
typename AddCallback, typename RemoveCallback, typename MoveUpCallback,
typename MoveDownCallback>
utils::EncapsulatedLayout *listActions(
QAbstractItemView *view, const QString &addText, const QString &addToolTip,
AddCallback addCallback, const QString &removeText,
const QString &removeToolTip, RemoveCallback removeCallback,
const QString &moveUpText, const QString &moveUpToolTip,
MoveUpCallback moveUpCallback, const QString &moveDownText,
const QString &moveDownToolTip, MoveDownCallback moveDownCallback)
{
void (*noop)() = nullptr;
return listActions(
view, addText, addToolTip, addCallback, QString(), QString(), noop,
removeText, removeToolTip, removeCallback, moveUpText, moveUpToolTip,
moveUpCallback, moveDownText, moveDownToolTip, moveDownCallback, false,
true);
}

template <typename AddCallback, typename EditCallback, typename RemoveCallback>
utils::EncapsulatedLayout *listActions(
QAbstractItemView *view, const QString &addText, const QString &addToolTip,
AddCallback addCallback, const QString &editText,
const QString &editToolTip, EditCallback editCallback,
const QString &removeText, const QString &removeToolTip,
RemoveCallback removeCallback)
{
void (*noop)() = nullptr;
return listActions(
view, addText, addToolTip, addCallback, editText, editToolTip,
editCallback, removeText, removeToolTip, removeCallback, QString(),
QString(), noop, QString(), QString(), noop, true, false);
}

template <typename AddCallback, typename RemoveCallback>
utils::EncapsulatedLayout *listActions(
QAbstractItemView *view, const QString &addLabel, AddCallback addCallback,
const QString &removeLabel, RemoveCallback removeCallback)
QAbstractItemView *view, const QString &addText, const QString &addToolTip,
AddCallback addCallback, const QString &removeText,
const QString &removeToolTip, RemoveCallback removeCallback)
{
void (*noop)() = nullptr;
return listActions(
view, addLabel, addCallback, removeLabel, removeCallback, QString{},
noop, QString{}, noop, false);
view, addText, addToolTip, addCallback, QString(), QString(), noop,
removeText, removeToolTip, removeCallback, QString(), QString(), noop,
QString(), QString(), noop, false, false);
}

inline bool
Expand Down
4 changes: 2 additions & 2 deletions src/desktop/dialogs/settingsdialog/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ void Network::initAvatars(QVBoxLayout *layout)

layout->addWidget(avatars);
layout->addLayout(listActions(
avatars, tr("Add avatar…"),
avatars, tr("Add"), tr("Add avatar…"),
[=] {
AvatarImport::importAvatar(avatarsModel, this);
},
tr("Delete selected avatars…"),
tr("Remove"), tr("Delete selected avatars…"),
makeDefaultDeleter(
this, avatars, tr("Delete avatars"),
QT_TR_N_NOOP("Really delete %n avatar(s)?"))));
Expand Down
19 changes: 8 additions & 11 deletions src/desktop/dialogs/settingsdialog/servers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,19 @@ void Servers::initListingServers(
servers, Qt::ScrollBarAlwaysOff, Qt ::ScrollBarAsNeeded);
form->addWidget(servers, 1);
form->addLayout(listActions(
servers, tr("Add list servers…"),
servers, tr("Add"), tr("Add list servers…"),
[=] {
addListServer(serversModel);
},

tr("Remove selected list servers…"),
tr("Remove"), tr("Remove selected list servers…"),
makeDefaultDeleter(
this, servers, tr("Remove list servers"),
QT_TR_N_NOOP("Really remove %n list server(s)?")),

tr("Move up"),
QString(), tr("Move up"),
[=] {
moveListServer(serversModel, servers->selectionModel(), -1);
},

tr("Move down"),
QString(), tr("Move down"),
[=] {
moveListServer(serversModel, servers->selectionModel(), 1);
}));
Expand Down Expand Up @@ -124,12 +121,12 @@ void Servers::initKnownHosts(QVBoxLayout *form)
knownHosts->setModel(knownHostsModel);

auto *actions = listActions(
knownHosts, tr("Import trusted certificate…"),
knownHosts, tr("Add"), tr("Import trusted certificate…"),
[=] {
importCertificates(knownHostsModel);
},

tr("Remove selected hosts…"),
tr("Remove"), tr("Remove selected hosts…"),
makeDefaultDeleter(
this, knownHosts, tr("Remove known hosts"),
QT_TR_N_NOOP("Really remove %n known host(s)?")));
Expand Down Expand Up @@ -190,9 +187,9 @@ askToContinue(const QString &title, const QString &message, QWidget *parent)
const auto *ok =
box.addButton(Servers::tr("Continue"), QMessageBox::AcceptRole);
box.setDefaultButton(QMessageBox::Cancel);
#ifndef __EMSCRIPTEN__
# ifndef __EMSCRIPTEN__
box.setWindowModality(Qt::WindowModal);
#endif
# endif
box.exec();
return box.clickedButton() == ok;
}
Expand Down
32 changes: 25 additions & 7 deletions src/desktop/dialogs/settingsdialog/shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,13 @@ QWidget *Shortcuts::initCanvasShortcuts(desktop::settings::Settings &settings)
connect(
m_canvasTable, &QAbstractItemView::activated, this,
[=](const QModelIndex &index) {
if(const auto *shortcut = m_canvasShortcutsModel->shortcutAt(
mapFromView(m_canvasTable, index).row())) {
if(const CanvasShortcuts::Shortcut *shortcut =
m_canvasShortcutsModel->shortcutAt(
mapFromView(m_canvasTable, index).row())) {
execCanvasShortcutDialog(
m_canvasTable, shortcut, m_canvasShortcutsModel, this,
tr("Edit Canvas Shortcut"), [=](auto newShortcut) {
tr("Edit Canvas Shortcut"),
[=](const CanvasShortcuts::Shortcut &newShortcut) {
return m_canvasShortcutsModel->editShortcut(
*shortcut, newShortcut);
});
Expand All @@ -318,15 +320,31 @@ QWidget *Shortcuts::initCanvasShortcuts(desktop::settings::Settings &settings)
layout->addWidget(m_canvasTable, 1);

utils::EncapsulatedLayout *actions = listActions(
m_canvasTable, tr("Add canvas shortcut…"),
[=] {
m_canvasTable, tr("Add"), tr("Add canvas shortcut…"),
[this] {
execCanvasShortcutDialog(
m_canvasTable, nullptr, m_canvasShortcutsModel, this,
tr("New Canvas Shortcut"), [=](auto newShortcut) {
tr("New Canvas Shortcut"),
[this](const CanvasShortcuts::Shortcut &newShortcut) {
return m_canvasShortcutsModel->addShortcut(newShortcut);
});
},
tr("Remove selected canvas shortcut…"),
tr("Edit"), tr("Edit selected canvas shortcut…"),
[this] {
if(const CanvasShortcuts::Shortcut *shortcut =
m_canvasShortcutsModel->shortcutAt(
mapFromView(m_canvasTable, m_canvasTable->currentIndex())
.row())) {
execCanvasShortcutDialog(
m_canvasTable, shortcut, m_canvasShortcutsModel, this,
tr("Edit Canvas Shortcut"),
[=](const CanvasShortcuts::Shortcut &newShortcut) {
return m_canvasShortcutsModel->editShortcut(
*shortcut, newShortcut);
});
}
},
tr("Remove"), tr("Remove selected canvas shortcut…"),
makeDefaultDeleter(
this, m_canvasTable, tr("Remove canvas shortcut"),
QT_TR_N_NOOP("Really remove %n canvas shortcut(s)?")));
Expand Down

0 comments on commit fe75dab

Please sign in to comment.