Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ HEADERS += \
src/generalpage.h \
src/shortcutspage.h \
src/strokeoptionswidget.h \
src/timecodecontrolwidget.h \
src/timelinepage.h \
src/toolboxwidget.h \
src/toolspage.h \
Expand Down Expand Up @@ -151,6 +152,7 @@ SOURCES += \
src/generalpage.cpp \
src/shortcutspage.cpp \
src/strokeoptionswidget.cpp \
src/timecodecontrolwidget.cpp \
src/timelinepage.cpp \
src/toolboxwidget.cpp \
src/toolspage.cpp \
Expand Down
1 change: 1 addition & 0 deletions app/data/app.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<file>icons/themes/playful/window/window-float-button-normal-darkm.svg</file>
<file>icons/themes/playful/window/window-float-button-normal.svg</file>
<file>icons/themes/playful/window/window-close-button-normal.svg</file>
<file>icons/themes/playful/controls/control-timecode.svg</file>
</qresource>
<qresource prefix="/app">
<file>pencil2d_quick_guide.pdf</file>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion app/src/basedockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ void BaseDockWidget::lock(bool locked)
// nullptr means removing the custom title bar and restoring the default one

if (locked) {
setTitleBarWidget(mNoTitleBarWidget);
if (mTitleBarWidget->hasChildWidget()) {
mTitleBarWidget->lock(locked);
} else {
setTitleBarWidget(mNoTitleBarWidget);
}
} else {
setTitleBarWidget(mTitleBarWidget);
mTitleBarWidget->lock(locked);
}

mLocked = locked;
Expand All @@ -77,6 +82,13 @@ void BaseDockWidget::setTitle(const QString& title)
mTitleBarWidget->setTitle(title);
}

void BaseDockWidget::setWidgetInTitleBarArea(QWidget* widget)
{
if (mTitleBarWidget) {
mTitleBarWidget->setChildWidget(widget);
}
}

void BaseDockWidget::resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);
Expand Down
4 changes: 4 additions & 0 deletions app/src/basedockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class BaseDockWidget : public QDockWidget
Editor* editor() const { return mEditor; }
void setEditor( Editor* e ) { mEditor = e; }

/// Sets a widget in addition to the normal titlebar buttons.
/// If the titlebar already has one widget, the previous one will be deleted.
void setWidgetInTitleBarArea(QWidget* widget);

protected:
void resizeEvent(QResizeEvent* event) override;

Expand Down
118 changes: 118 additions & 0 deletions app/src/timecodecontrolwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2012-2020 Matthew Chiawen Chang

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; version 2 of the License.

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.

*/
#include "timecodecontrolwidget.h"

#include "preferencemanager.h"
#include "pencildef.h"
#include "pencilsettings.h"

#include <QLabel>
#include <QToolButton>
#include <QHBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>

TimeCodeControlWidget::TimeCodeControlWidget(TimeCodeControls* controls, QWidget* parent)
: QWidget(parent, Qt::Popup), mControls(controls)
{
auto vboxLayout = new QVBoxLayout();

Check failure on line 33 in app/src/timecodecontrolwidget.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=pencil2d_pencil&issues=AZ2mpxhKCfudf6Z3FXZr&open=AZ2mpxhKCfudf6Z3FXZr&pullRequest=2006
vboxLayout->setContentsMargins(4,4,4,4);
setLayout(vboxLayout);

auto titlelabel = new QLabel(tr("Timecode controls"));

Check failure on line 37 in app/src/timecodecontrolwidget.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=pencil2d_pencil&issues=AZ2mpxhKCfudf6Z3FXZs&open=AZ2mpxhKCfudf6Z3FXZs&pullRequest=2006

vboxLayout->addWidget(titlelabel);

auto showTimeCodeCheckBox = new QCheckBox(this);
showTimeCodeCheckBox->setText(tr("Show"));
showTimeCodeCheckBox->setChecked(controls->enabled);

auto optionsGroupBox = new QGroupBox(this);
optionsGroupBox->setTitle(tr("Options"));
optionsGroupBox->setEnabled(controls->enabled);

auto showFramesCheckBox = new QCheckBox(this);
showFramesCheckBox->setText(tr("Frames"));
showFramesCheckBox->setChecked(controls->showFrames);

auto timecodeComboBox = new QComboBox(this);

auto groupBoxVBoxLayout = new QVBoxLayout();

Check failure on line 55 in app/src/timecodecontrolwidget.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=pencil2d_pencil&issues=AZ2mpxhKCfudf6Z3FXZt&open=AZ2mpxhKCfudf6Z3FXZt&pullRequest=2006
groupBoxVBoxLayout->setContentsMargins(4,4,4,4);
optionsGroupBox->setLayout(groupBoxVBoxLayout);

groupBoxVBoxLayout->addWidget(showFramesCheckBox);
groupBoxVBoxLayout->addWidget(timecodeComboBox);

timecodeComboBox->addItem(tr("No Timecode"), timecodeKindToInt(TimecodeKind::NONE));
timecodeComboBox->addItem(tr("SMPTE Timecode"), timecodeKindToInt(TimecodeKind::SMPTE));
timecodeComboBox->addItem(tr("SFF Timecode"), timecodeKindToInt(TimecodeKind::SFF));
timecodeComboBox->setCurrentIndex(timecodeKindToInt(controls->kind));

vboxLayout->addWidget(showTimeCodeCheckBox);
vboxLayout->addWidget(optionsGroupBox);

connect(showTimeCodeCheckBox, &QCheckBox::toggled, this, [this, optionsGroupBox](bool toggled) {
showTimecode(toggled);
optionsGroupBox->setEnabled(toggled);
});

connect(showFramesCheckBox, &QCheckBox::toggled, this, [this](bool toggled) {
showFrames(toggled);
});

auto comboBoxValueChanged = static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
connect(timecodeComboBox, comboBoxValueChanged, this, [this, controls](int index) {
auto timecodeKind = controls->timecodeKindFromInt(index);

setTimecodeTimerKind(timecodeKind);
});
}

void TimeCodeControlWidget::showFrames(bool shown)
{
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(SETTING_TIMECODE_FRAMES_ON, shown);

mControls->showFrames = shown;
emit timecodeUpdated();
}

int TimeCodeControlWidget::timecodeKindToInt(TimecodeKind kind) const
{
return static_cast<int>(kind);

Check warning on line 98 in app/src/timecodecontrolwidget.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::to_underlying" to cast enums to their underlying type.

See more on https://sonarcloud.io/project/issues?id=pencil2d_pencil&issues=AZ2mpxhKCfudf6Z3FXZu&open=AZ2mpxhKCfudf6Z3FXZu&pullRequest=2006
}

void TimeCodeControlWidget::showTimecode(bool shown)
{
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(SETTING_TIMECODE_ON, shown);

mControls->enabled = shown;
emit timecodeUpdated();
}

void TimeCodeControlWidget::setTimecodeTimerKind(TimecodeKind kind)
{
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(SETTING_TIMECODE_KIND, timecodeKindToInt(kind));
settings.remove(SETTING_TIMECODE_TEXT);
mControls->kind = kind;

emit timecodeUpdated();
}
66 changes: 66 additions & 0 deletions app/src/timecodecontrolwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2012-2020 Matthew Chiawen Chang

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; version 2 of the License.

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.

*/
#ifndef TIMECODECONTROLWIDGET_H
#define TIMECODECONTROLWIDGET_H

#include <QWidget>
#include "pencildef.h"

struct TimeCodeControls {
bool enabled = false;
bool showFrames = false;

TimecodeKind kind = TimecodeKind::NONE;

TimecodeKind timecodeKindFromInt(int value) const
{
switch (value)
{

Check warning on line 32 in app/src/timecodecontrolwidget.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce verbosity with "using enum" for "TimecodeKind".

See more on https://sonarcloud.io/project/issues?id=pencil2d_pencil&issues=AZ2mpxhACfudf6Z3FXZi&open=AZ2mpxhACfudf6Z3FXZi&pullRequest=2006
case 0:
return TimecodeKind::NONE;
case 1:
return TimecodeKind::SMPTE;
case 2:
return TimecodeKind::SFF;
default:
return TimecodeKind::NONE;
}
}
};

class TimeCodeControlWidget : public QWidget
{
Q_OBJECT

public:
explicit TimeCodeControlWidget(TimeCodeControls* controls, QWidget* parent = nullptr);

signals:
void timecodeUpdated();

private:

int timecodeKindToInt(TimecodeKind kind) const;

void setTimecodeTimerKind(TimecodeKind kind);
void showFrames(bool shown);
void showTimecode(bool shown);

TimeCodeControls* mControls = nullptr;
};

#endif // TIMECODECONTROLWIDGET_H
Loading
Loading