Skip to content

Commit

Permalink
Merge remote-tracking branch 'pencil2d/master' into compact-dock-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Apr 30, 2024
2 parents d388e69 + 8c3b530 commit b7a3d9f
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 23 deletions.
22 changes: 22 additions & 0 deletions app/src/exportmoviedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ ExportMovieDialog::ExportMovieDialog(QWidget *parent, Mode mode, FileType fileTy
} else {
setWindowTitle(tr("Export Movie"));
}

QSizePolicy policy = ui->unevenWidthLabel->sizePolicy();
policy.setRetainSizeWhenHidden(true);
ui->unevenWidthLabel->setSizePolicy(policy);
policy = ui->unevenHeightLabel->sizePolicy();
policy.setRetainSizeWhenHidden(true);
ui->unevenHeightLabel->setSizePolicy(policy);

connect(this, &ExportMovieDialog::filePathsChanged, this, &ExportMovieDialog::onFilePathsChanged);
connect(ui->widthSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
connect(ui->heightSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
}

ExportMovieDialog::~ExportMovieDialog()
Expand Down Expand Up @@ -66,6 +76,7 @@ void ExportMovieDialog::updateResolutionCombo( int index )

ui->widthSpinBox->setValue( camSize.width() );
ui->heightSpinBox->setValue( camSize.height() );
validateResolution();
}

void ExportMovieDialog::setDefaultRange(int startFrame, int endFrame, int endFrameWithSounds)
Expand Down Expand Up @@ -128,6 +139,7 @@ void ExportMovieDialog::onFilePathsChanged(QStringList filePaths)
ui->loopCheckBox->setChecked(false);
}
ui->transparencyCheckBox->setEnabled(supportsTransparency(filePath));
validateResolution();
}

bool ExportMovieDialog::supportsLooping(QString filePath) const
Expand All @@ -141,3 +153,13 @@ bool ExportMovieDialog::supportsTransparency(QString filePath) const
return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
filePath.endsWith(".webm", Qt::CaseInsensitive);
}

void ExportMovieDialog::validateResolution()
{
const bool isMp4 = getFilePath().endsWith(".mp4", Qt::CaseInsensitive);
const bool widthValid = !isMp4 || ui->widthSpinBox->value() % 2 == 0;
const bool heightValid = !isMp4 || ui->heightSpinBox->value() % 2 == 0;
ui->unevenWidthLabel->setHidden(widthValid);
ui->unevenHeightLabel->setHidden(heightValid);
setOkButtonEnabled(widthValid && heightValid);
}
1 change: 1 addition & 0 deletions app/src/exportmoviedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ExportMovieDialog : public ImportExportDialog

bool supportsLooping(QString filePath) const;
bool supportsTransparency(QString filePath) const;
void validateResolution();

int mEndFrameWithSounds = 0;
int mEndFrame = 0;
Expand Down
17 changes: 14 additions & 3 deletions app/src/generalpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GNU General Public License for more details.

#include <QMessageBox>
#include <QSettings>
#include <QTranslator>

#include "pencildef.h"
#include "preferencemanager.h"
Expand Down Expand Up @@ -197,9 +198,19 @@ void GeneralPage::languageChanged(int i)
QString strLocale = ui->languageCombo->itemData(i).toString();
mManager->set(SETTING::LANGUAGE, strLocale);

QMessageBox::warning(this,
tr("Restart Required"),
tr("The language change will take effect after a restart of Pencil2D"));
QLocale locale = strLocale.isEmpty() ? QLocale::system() : QLocale(strLocale);
std::unique_ptr<QTranslator> newlangTr(new QTranslator(this));
if (newlangTr->load(locale, "pencil", "_", ":/i18n/"))
{
QMessageBox::warning(this,
newlangTr->translate(staticMetaObject.className(), "Restart Required"),
newlangTr->translate(staticMetaObject.className(), "The language change will take effect after a restart of Pencil2D"));
} else {
Q_ASSERT(false);
QMessageBox::warning(this,
tr("Restart Required"),
tr("The language change will take effect after a restart of Pencil2D"));
}
}

void GeneralPage::backgroundChanged(QAbstractButton* button)
Expand Down
5 changes: 5 additions & 0 deletions app/src/importexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void ImportExportDialog::setInstructionsLabel(const QString& text)
ui->instructionsLabel->setText(text);
}

void ImportExportDialog::setOkButtonEnabled(const bool enabled)
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
}

void ImportExportDialog::init()
{
switch (mMode)
Expand Down
1 change: 1 addition & 0 deletions app/src/importexportdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ImportExportDialog : public QDialog
void hideInstructionsLabel(bool hide);

void setInstructionsLabel(const QString& text);
void setOkButtonEnabled(bool enabled);

private slots:
void browse();
Expand Down
22 changes: 21 additions & 1 deletion app/ui/exportmovieoptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<property name="title">
<string>Resolution</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,1,1,0,1">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
Expand All @@ -60,6 +60,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="unevenWidthLabel">
<property name="toolTip">
<string>The MP4 format does not support odd width. Please specify an even width or use a different file format.</string>
</property>
<property name="text">
<string notr="true">⚠</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="widthSpinBox">
<property name="maximum">
Expand Down Expand Up @@ -89,6 +99,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="unevenHeightLabel">
<property name="toolTip">
<string>The MP4 format does not support odd height. Please specify an even height or use a different file format.</string>
</property>
<property name="text">
<string notr="true">⚠</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="heightSpinBox">
<property name="maximum">
Expand Down
26 changes: 22 additions & 4 deletions core_lib/src/graphics/bitmap/tiledbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ Tile* TiledBuffer::getTileFromIndex(const TileIndex& tileIndex)
return selectedTile;
}

void TiledBuffer::drawBrush(const QPointF& point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) {
const QRectF brushRect(point.x() - 0.5 * brushWidth, point.y() - 0.5 * brushWidth, brushWidth, brushWidth);
void TiledBuffer::drawBrush(QPointF point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) {
const float tileSize = UNIFORM_TILE_SIZE;

// Gather the number of tiles that fits the size of the brush width
Expand All @@ -58,6 +57,21 @@ void TiledBuffer::drawBrush(const QPointF& point, qreal brushWidth, QPen pen, QB
const int yTop = qFloor(qFloor(point.y() - brushWidth) / tileSize);
const int yBottom = qFloor(qFloor(point.y() + brushWidth) / tileSize);

// If we are not using antialiasing, make sure at least one pixel is within the brush's circle
bool drawPoint = false;
if (!antialiasing && brushWidth < 1.42) { // Overestimated approximation of 2*sqrt(2), which is the maximum distance a point can be from the center of a pixel
// Measure the actual distance to the center of the nearest pixel
const QPointF nearestPixelCenter(qRound(point.x()+0.5)-0.5, qRound(point.y()+0.5)-0.5);
const qreal distanceToNearest = QLineF(point, nearestPixelCenter).length();
if (distanceToNearest >= brushWidth/2) {
// Nothing will be drawn with drawEllipse, so prepare to draw the nearest pixel with drawPoint
drawPoint = true;
point = QPointF(nearestPixelCenter.x() - 0.5, nearestPixelCenter.y() - 0.5);
pen = QPen(brush, 1);
}
}
const QRectF brushRect(point.x() - 0.5 * brushWidth, point.y() - 0.5 * brushWidth, brushWidth, brushWidth);

for (int tileY = yTop; tileY <= yBottom; tileY++) {
for (int tileX = xLeft; tileX <= xRight; tileX++) {

Expand All @@ -70,7 +84,11 @@ void TiledBuffer::drawBrush(const QPointF& point, qreal brushWidth, QPen pen, QB
painter.setPen(pen);
painter.setBrush(brush);
painter.setCompositionMode(cm);
painter.drawEllipse(brushRect);
if (drawPoint) {
painter.drawPoint(point);
} else {
painter.drawEllipse(brushRect);
}
painter.end();

mTileBounds.extend(tile->bounds());
Expand Down Expand Up @@ -110,7 +128,7 @@ void TiledBuffer::drawImage(const QImage& image, const QRect& imageBounds, QPain
void TiledBuffer::drawPath(QPainterPath path, QPen pen, QBrush brush,
QPainter::CompositionMode cm, bool antialiasing)
{
const int width = pen.width();
const qreal width = pen.widthF();
const float tileSize = UNIFORM_TILE_SIZE;
const QRectF pathRect = path.boundingRect();

Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/graphics/bitmap/tiledbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TiledBuffer: public QObject
bool isValid() const { return !mTiles.isEmpty(); }

/** Draws a brush with the specified parameters to the tiled buffer */
void drawBrush(const QPointF& point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing);
void drawBrush(QPointF point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing);
/** Draws a path with the specified parameters to the tiled buffer */
void drawPath(QPainterPath path, QPen pen, QBrush brush,
QPainter::CompositionMode cm, bool antialiasing);
Expand Down
7 changes: 6 additions & 1 deletion core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,14 @@ bool ScribbleArea::event(QEvent *event)
{
editor()->tools()->clearTemporaryTool();
processed = true;
} else if (event->type() == QEvent::Enter)
{
processed = currentTool()->enterEvent(static_cast<QEnterEvent*>(event)) || processed;
} else if (event->type() == QEvent::Leave)
{
processed = currentTool()->leaveEvent(event) || processed;
}

processed = currentTool()->event(event) || processed;
return QWidget::event(event) || processed;
}

Expand Down
5 changes: 4 additions & 1 deletion core_lib/src/tool/basetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ GNU General Public License for more details.
#include <QString>
#include <QCursor>
#include <QPainter>
#include <QPointF>
#include <QHash>
#include <QEvent>
#include "pencildef.h"

class QPixmap;
class Editor;
class ScribbleArea;
class QEnterEvent;
class QKeyEvent;
class QMouseEvent;
class QTabletEvent;
Expand Down Expand Up @@ -90,6 +90,9 @@ class BaseTool : public QObject
virtual bool keyPressEvent(QKeyEvent*) { return false; }
virtual bool keyReleaseEvent(QKeyEvent*) { return false; }

virtual bool enterEvent(QEnterEvent*) { return false; }
virtual bool leaveEvent(QEvent*) { return false; }

virtual void clearToolData() {}
virtual void resetToDefault() {}

Expand Down
25 changes: 14 additions & 11 deletions core_lib/src/tool/stroketool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,22 @@ void StrokeTool::pointerReleaseEvent(PointerEvent*)
updateCanvasCursor();
}

bool StrokeTool::event(QEvent *event)
bool StrokeTool::enterEvent(QEnterEvent*)
{
if (event->type() == QEvent::Leave && !isActive()) {
mCanvasCursorEnabled = false;
updateCanvasCursor();
QObject::event(event);
return true;
} else if (event->type() == QEvent::Enter) {
mCanvasCursorEnabled = mEditor->preference()->isOn(SETTING::CANVAS_CURSOR);
QObject::event(event);
return true;
mCanvasCursorEnabled = mEditor->preference()->isOn(SETTING::CANVAS_CURSOR);
return true;
}

bool StrokeTool::leaveEvent(QEvent*)
{
if (isActive())
{
return false;
}
return QObject::event(event);

mCanvasCursorEnabled = false;
updateCanvasCursor();
return true;
}

void StrokeTool::updateCanvasCursor()
Expand Down
3 changes: 2 additions & 1 deletion core_lib/src/tool/stroketool.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class StrokeTool : public BaseTool
void pointerPressEvent(PointerEvent* event) override;
void pointerMoveEvent(PointerEvent* event) override;
void pointerReleaseEvent(PointerEvent* event) override;
bool event(QEvent *event) override;
bool enterEvent(QEnterEvent*) override;
bool leaveEvent(QEvent*) override;

bool handleQuickSizing(PointerEvent* event);

Expand Down

0 comments on commit b7a3d9f

Please sign in to comment.