Skip to content

Commit

Permalink
Make expanding the canvas open the resize dialog
Browse files Browse the repository at this point in the history
Which will continue to let you hit the expand shortcut, but you then
have to hit return to apply it (or do whatever else in that dialog you
want to do.) This avoids the all too common accidental resizes and has
better performance than doing a bunch of separate resize steps. The
keyboard shortcuts in this dialog now also auto-repeat.

Relates to #901.
  • Loading branch information
askmeaboutlo0m committed Oct 25, 2024
1 parent f3df730 commit c3b1574
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 59 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Unreleased Version 2.2.2-pre
* Feature: Replace GIF export with ffmpeg's libraries, since they are also used for videos. It's way faster, generates much better palettes and . Thanks dAVePAGE and JJ for reporting issues in this regard.
* Fix: Constrain aspect ratio of transform scaling properly, it was getting offset by the distance between the clicked point and the actual corner. Thanks Blozzom for reporting.
* Feature: Allow configuring flood fill preview and confirmation behavior, defaulting to the simplest mode similar to single-user software, but still previewing fills locally first. The magic wand always works this way for now, since selections are local only anyway.
* Feature: Show resize dialog when expanding canvas, to avoid accidental resizes and improve performance by doing the expansions all in one step. The keyboard shortcuts to expand the canvas work in this dialog now and also auto-repeat if you hold them down. Thanks Bluestrings and tobiasBora for suggesting things in this regard.

2024-08-09 Version 2.2.2-beta.3
* Fix: Use more accurate timers for performance profiles if the platform supports it.
Expand Down
22 changes: 22 additions & 0 deletions src/desktop/assets/theme/dark/drawpile_expanddown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/desktop/assets/theme/dark/drawpile_expandleft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/desktop/assets/theme/dark/drawpile_expandright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/desktop/assets/theme/dark/drawpile_expandup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/desktop/assets/theme/light/drawpile_expanddown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/desktop/assets/theme/light/drawpile_expandleft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/desktop/assets/theme/light/drawpile_expandright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/desktop/assets/theme/light/drawpile_expandup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 83 additions & 2 deletions src/desktop/dialogs/resizedialog.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "desktop/dialogs/resizedialog.h"
#include "desktop/utils/widgetutils.h"
#include "libclient/utils/images.h"
#include "ui_resizedialog.h"
#include <QAction>
#include <QMessageBox>
#include <QPushButton>
#include <QSignalBlocker>
#include <tuple>

namespace dialogs {

ResizeDialog::ResizeDialog(const QSize &oldsize, QWidget *parent)
ResizeDialog::ResizeDialog(
const QSize &oldsize, const QAction *expandUpAction,
const QAction *expandLeftAction, const QAction *expandRightAction,
const QAction *expandDownAction, QWidget *parent)
: QDialog(parent)
, m_oldsize(oldsize)
{
Expand All @@ -18,6 +24,22 @@ ResizeDialog::ResizeDialog(const QSize &oldsize, QWidget *parent)
m_ui->resizer->setOriginalSize(oldsize);
m_ui->resizer->setTargetSize(oldsize);

std::tuple<QToolButton *, const QAction *, QString> buttonActions[] = {
{m_ui->expandUp, expandUpAction, tr("Expand up")},
{m_ui->expandLeft, expandLeftAction, tr("Expand left")},
{m_ui->expandRight, expandRightAction, tr("Expand right")},
{m_ui->expandDown, expandDownAction, tr("Expand down")},
};
for(const auto &[button, action, text] : buttonActions) {
m_ui->grid->setAlignment(button, Qt::AlignCenter);
QAction *buttonAction = new QAction(action->icon(), text, this);
buttonAction->setToolTip(
utils::makeActionShortcutText(action->text(), action->shortcut()));
buttonAction->setShortcuts(action->shortcuts());
buttonAction->setAutoRepeat(true);
button->setDefaultAction(buttonAction);
}

m_ui->buttons->button(QDialogButtonBox::Ok)->setText(tr("Resize"));

QPushButton *centerButton = new QPushButton(tr("Center"));
Expand All @@ -35,7 +57,18 @@ ResizeDialog::ResizeDialog(const QSize &oldsize, QWidget *parent)
connect(
m_ui->keepaspect, &QCheckBox::toggled, this,
&ResizeDialog::toggleAspectRatio);

connect(
m_ui->expandUp->defaultAction(), &QAction::triggered, this,
&ResizeDialog::expandUp);
connect(
m_ui->expandLeft->defaultAction(), &QAction::triggered, this,
&ResizeDialog::expandLeft);
connect(
m_ui->expandRight->defaultAction(), &QAction::triggered, this,
&ResizeDialog::expandRight);
connect(
m_ui->expandDown->defaultAction(), &QAction::triggered, this,
&ResizeDialog::expandDown);
connect(
centerButton, &QPushButton::clicked, m_ui->resizer,
&widgets::ResizerWidget::center);
Expand Down Expand Up @@ -70,6 +103,32 @@ void ResizeDialog::setBounds(const QRect &rect)
m_ui->resizer->setTargetSize(rectIn.size());
}

void ResizeDialog::initialExpand(int expandDirection)
{
QToolButton *button;
switch(expandDirection) {
case int(ExpandDirection::Up):
button = m_ui->expandUp;
break;
case int(ExpandDirection::Left):
button = m_ui->expandLeft;
break;
case int(ExpandDirection::Right):
button = m_ui->expandRight;
break;
case int(ExpandDirection::Down):
button = m_ui->expandDown;
break;
default:
button = nullptr;
break;
}
if(button) {
button->click();
m_ui->buttons->button(QDialogButtonBox::Ok)->setFocus();
}
}

void ResizeDialog::done(int r)
{
if(r == QDialog::Accepted) {
Expand Down Expand Up @@ -113,6 +172,28 @@ void ResizeDialog::toggleAspectRatio(bool keep)
}
}

void ResizeDialog::expandUp()
{
m_ui->height->setValue(m_ui->height->value() + EXPAND);
m_ui->resizer->changeOffsetBy(QPoint(0, EXPAND));
}

void ResizeDialog::expandLeft()
{
m_ui->width->setValue(m_ui->width->value() + EXPAND);
m_ui->resizer->changeOffsetBy(QPoint(EXPAND, 0));
}

void ResizeDialog::expandRight()
{
m_ui->width->setValue(m_ui->width->value() + EXPAND);
}

void ResizeDialog::expandDown()
{
m_ui->height->setValue(m_ui->height->value() + EXPAND);
}

void ResizeDialog::reset()
{
m_ui->width->blockSignals(true);
Expand Down
15 changes: 14 additions & 1 deletion src/desktop/dialogs/resizedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define DESKTOP_DIALOGS_RESIZEDIALOG_H
#include <QDialog>

class QAction;
class Ui_ResizeDialog;

namespace dialogs {
Expand All @@ -19,12 +20,18 @@ struct ResizeVector {
class ResizeDialog final : public QDialog {
Q_OBJECT
public:
explicit ResizeDialog(const QSize &oldsize, QWidget *parent = nullptr);
enum class ExpandDirection { None, Up, Left, Right, Down };

ResizeDialog(
const QSize &oldsize, const QAction *expandUpAction,
const QAction *expandLeftAction, const QAction *expandRightAction,
const QAction *expandDownAction, QWidget *parent = nullptr);
~ResizeDialog() override;

void setBackgroundColor(const QColor &bgColor);
void setPreviewImage(const QImage &image);
void setBounds(const QRect &rect);
void initialExpand(int expandDirection);

QSize newSize() const;
QPoint newOffset() const;
Expand All @@ -37,9 +44,15 @@ private slots:
void widthChanged(int);
void heightChanged(int);
void toggleAspectRatio(bool keep);
void expandUp();
void expandLeft();
void expandRight();
void expandDown();
void reset();

private:
static constexpr int EXPAND = 64;

Ui_ResizeDialog *m_ui;

QSize m_oldsize;
Expand Down
Loading

0 comments on commit c3b1574

Please sign in to comment.