Skip to content

Commit

Permalink
Merge pull request #619 from CandyFace/interpolation
Browse files Browse the repository at this point in the history
Interpolation levels and refactoring
  • Loading branch information
chchwy committed Mar 13, 2017
2 parents 46a208d + 816bd15 commit 3235fa2
Show file tree
Hide file tree
Showing 29 changed files with 764 additions and 195 deletions.
4 changes: 2 additions & 2 deletions core_lib/interface/scribblearea.cpp
Expand Up @@ -1080,7 +1080,7 @@ void ScribbleArea::drawPencil( QPointF thePoint, qreal brushWidth, QColor fillCo
drawBrush(thePoint, brushWidth, 50, fillColour, opacity, true);
}

void ScribbleArea::drawBrush( QPointF thePoint, qreal brushWidth, qreal mOffset, QColor fillColour, qreal opacity, bool usingFeather )
void ScribbleArea::drawBrush( QPointF thePoint, qreal brushWidth, qreal mOffset, QColor fillColour, qreal opacity, bool usingFeather, int useAA )
{
QRectF rectangle( thePoint.x() - 0.5 * brushWidth, thePoint.y() - 0.5 * brushWidth, brushWidth, brushWidth );

Expand All @@ -1096,7 +1096,7 @@ void ScribbleArea::drawBrush( QPointF thePoint, qreal brushWidth, qreal mOffset,
else
{
mBufferImg->drawEllipse( rectangle, Qt::NoPen, QBrush(fillColour, Qt::SolidPattern),
QPainter::CompositionMode_Source, true );
QPainter::CompositionMode_Source, useAA );
}
mBufferImg->paste( &tempBitmapImage );
}
Expand Down
2 changes: 1 addition & 1 deletion core_lib/interface/scribblearea.h
Expand Up @@ -165,7 +165,7 @@ public slots:
void drawPath( QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm );
void drawPen( QPointF thePoint, qreal brushWidth, QColor fillColour, qreal opacity, bool useAA = true );
void drawPencil( QPointF thePoint, qreal brushWidth, QColor fillColour, qreal opacity );
void drawBrush( QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColour, qreal opacity, bool usingFeather = true );
void drawBrush( QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColour, qreal opacity, bool usingFeather = true, int useAA = 0 );
void blurBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );
void liquifyBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );

Expand Down
2 changes: 1 addition & 1 deletion core_lib/interface/spinslider.cpp
Expand Up @@ -28,7 +28,7 @@ SpinSlider::SpinSlider( QString text, GROWTH_TYPE type, VALUE_TYPE dataType, qre
mSlider = new QSlider(Qt::Horizontal, this);
mSlider->setMinimum( 0 );
mSlider->setMaximum( 100 );
mSlider->setMaximumWidth( 70 );
mSlider->setMaximumWidth( 500 );

QGridLayout* layout = new QGridLayout();
layout->setMargin( 2 );
Expand Down
113 changes: 99 additions & 14 deletions core_lib/interface/tooloptiondockwidget.cpp
Expand Up @@ -3,6 +3,8 @@
#include <QCheckBox>
#include <QSpinBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QRadioButton>
#include <QSettings>
#include <QDebug>
#include "spinslider.h"
Expand Down Expand Up @@ -43,7 +45,8 @@ void ToolOptionWidget::updateUI()
mUsePressureBox->setVisible( currentTool->isPropertyEnabled( PRESSURE ) );
mMakeInvisibleBox->setVisible( currentTool->isPropertyEnabled( INVISIBILITY ) );
mPreserveAlphaBox->setVisible( currentTool->isPropertyEnabled( PRESERVEALPHA ) );
mUseAABox->setVisible(currentTool->isPropertyEnabled(ANTI_ALIASING ) );
mUseAABox->setVisible(currentTool->isPropertyEnabled( ANTI_ALIASING ) );
mInpolLevelsBox->setVisible(currentTool->isPropertyEnabled( INTERPOLATION ) );

auto currentLayerType = editor()->layers()->currentLayer()->type();

Expand All @@ -61,11 +64,13 @@ void ToolOptionWidget::updateUI()
setPreserveAlpha( p.preserveAlpha );
setVectorMergeEnabled( p.vectorMergeEnabled );
setAA(p.useAA);
setInpolLevel(p.inpolLevel);
}

void ToolOptionWidget::createUI()
{
setMinimumWidth( 115 );
setMaximumWidth(300);

QFrame* optionGroup = new QFrame();
QGridLayout* pLayout = new QGridLayout();
Expand Down Expand Up @@ -110,6 +115,47 @@ void ToolOptionWidget::createUI()
mUseAABox->setFont( QFont( "Helvetica", 10 ) );
mUseAABox->setChecked( true );

mInpolLevelsBox = new QGroupBox ( tr( "Stabilization level" ) );
mInpolLevelsBox->setFlat(true);
mInpolLevelsBox->setFont(QFont( "Helvetica", 10 ) );
mInpolLevelsBox->setStyleSheet(
"QGroupBox"
"{"
"margin-top: 1.0em"
"}"
"QGroupBox::title"
"{"
"subcontrol-origin: margin;"
"left: 5px;"
"padding: 0.7em 3px 0 3px;"
"}");

mNoInpol = new QRadioButton ( tr( "" ) );
mNoInpol->setToolTip( tr( "No line interpolation" ) );
mNoInpol->setFont( QFont( "Helvetica", 10) );
mNoInpol->setChecked ( true );

mSimpleInpol = new QRadioButton (tr( "" ) );
mSimpleInpol->setToolTip( tr( "Simple line interpolation" ) );
mSimpleInpol->setChecked ( false );

mStrongInpol = new QRadioButton (tr( "" ) );
mStrongInpol->setToolTip( tr( "Strong line interpolation" ) );
mStrongInpol->setChecked ( false );

// mExtremeInpol = new QRadioButton (tr( "" ) );
// mExtremeInpol->setToolTip( tr( "Extreme line interpolation" ) );
// mExtremeInpol->setFont( QFont( "Helvetica", 10) );
// mExtremeInpol->setChecked ( false );

QGridLayout* inpolLayout = new QGridLayout();
inpolLayout->addWidget( mNoInpol, 16, 0, 2, 1 );
inpolLayout->addWidget( mSimpleInpol, 16, 1, 2, 1 );
inpolLayout->addWidget( mStrongInpol, 16, 2, 2, 1 );
// inpolLayout->addWidget( mExtremeInpol, 16, 3, 2, 1 );
mInpolLevelsBox->setLayout(inpolLayout);
inpolLayout->setSpacing(2);

mMakeInvisibleBox = new QCheckBox( tr( "Invisible" ) );
mMakeInvisibleBox->setToolTip( tr( "Make invisible" ) );
mMakeInvisibleBox->setFont( QFont( "Helvetica", 10 ) );
Expand All @@ -125,19 +171,20 @@ void ToolOptionWidget::createUI()
mVectorMergeBox->setFont( QFont( "Helvetica", 10 ) );
mVectorMergeBox->setChecked( false );

pLayout->addWidget( mSizeSlider, 8, 0, 1, 2 );
pLayout->addWidget( mBrushSpinBox, 8, 10, 1, 2);
pLayout->addWidget( mFeatherSlider, 9, 0, 1, 2 );
pLayout->addWidget( mFeatherSpinBox, 9, 10, 1, 2 );
pLayout->addWidget( mUseBezierBox, 10, 0, 1, 2 );
pLayout->addWidget( mUsePressureBox, 11, 0, 1, 2 );
pLayout->addWidget( mUseAABox, 12, 0, 1, 2);
pLayout->addWidget( mPreserveAlphaBox, 13, 0, 1, 2 );
pLayout->addWidget( mUseFeatherBox, 13, 0, 1, 2 );
pLayout->addWidget( mMakeInvisibleBox, 14, 0, 1, 2 );
pLayout->addWidget( mVectorMergeBox, 15, 0, 1, 2 );

pLayout->setRowStretch( 16, 1 );
pLayout->addWidget( mSizeSlider, 1, 0, 1, 2 );
pLayout->addWidget( mBrushSpinBox, 1, 2, 1, 2);
pLayout->addWidget( mFeatherSlider, 2, 0, 1, 2 );
pLayout->addWidget( mFeatherSpinBox, 2, 2, 1, 2 );
pLayout->addWidget( mUseFeatherBox, 3, 0, 1, 2 );
pLayout->addWidget( mUseBezierBox, 4, 0, 1, 2 );
pLayout->addWidget( mUsePressureBox, 5, 0, 1, 2 );
pLayout->addWidget( mUseAABox, 6, 0, 1, 2);
pLayout->addWidget( mPreserveAlphaBox, 7, 0, 1, 2 );
pLayout->addWidget( mMakeInvisibleBox, 8, 0, 1, 2 );
pLayout->addWidget( mVectorMergeBox, 9, 0, 1, 2 );
pLayout->addWidget( mInpolLevelsBox, 10, 0, 1, 4);

pLayout->setRowStretch( 17, 1 );

optionGroup->setLayout( pLayout );

Expand All @@ -164,6 +211,12 @@ void ToolOptionWidget::makeConnectionToEditor( Editor* editor )
connect( mVectorMergeBox, &QCheckBox::clicked, toolManager, &ToolManager::setVectorMergeEnabled );
connect( mUseAABox, &QCheckBox::clicked, toolManager, &ToolManager::setAA );

connect( mNoInpol, &QRadioButton::clicked, toolManager, &ToolManager::noInpolSelected);
connect( mSimpleInpol, &QRadioButton::clicked, toolManager, &ToolManager::SimplepolSelected);
connect( mStrongInpol, &QRadioButton::clicked, toolManager, &ToolManager::StrongpolSelected);
connect( mExtremeInpol, &QRadioButton::clicked, toolManager, &ToolManager::ExtremepolSelected);


connect( toolManager, &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged );
connect( toolManager, &ToolManager::toolPropertyChanged, this, &ToolOptionWidget::onToolPropertyChanged );
}
Expand Down Expand Up @@ -195,6 +248,9 @@ void ToolOptionWidget::onToolPropertyChanged( ToolType, ToolPropertyType eProper
case ANTI_ALIASING:
setAA(p.useAA);
break;
case INTERPOLATION:
setInpolLevel(p.inpolLevel);
break;
}
}

Expand Down Expand Up @@ -263,9 +319,37 @@ void ToolOptionWidget::setAA(int x)

SignalBlocker b( mUseAABox );
mUseAABox->setEnabled( true );

if (x == -1) {
mUseAABox->setEnabled(false);
mUseAABox->hide();
} else {
mUseAABox->show();
}
mUseAABox->setChecked( x > 0 );
}

void ToolOptionWidget::setInpolLevel(int x)
{
qDebug() << "Setting - Interpolation level:" << x;

SignalBlocker b( mNoInpol );
SignalBlocker c( mSimpleInpol );
SignalBlocker d( mStrongInpol );
if (x == 0) {
mNoInpol->setChecked(true);
}
else if (x == 1) {
mSimpleInpol->setChecked(true);
} else if (x == 2) {
mStrongInpol->setChecked(true);
} else if (x == 3) {
mExtremeInpol->setChecked(true);
} else if (x == -1) {
mNoInpol->setChecked(true);
}
}

void ToolOptionWidget::disableAllOptions()
{
mSizeSlider->hide();
Expand All @@ -279,4 +363,5 @@ void ToolOptionWidget::disableAllOptions()
mPreserveAlphaBox->hide();
mVectorMergeBox->hide();
mUseAABox->hide();
mInpolLevelsBox->hide();
}
9 changes: 9 additions & 0 deletions core_lib/interface/tooloptiondockwidget.h
Expand Up @@ -6,7 +6,9 @@
class QToolButton;
class SpinSlider;
class QCheckBox;
class QRadioButton;
class QSpinBox;
class QGroupBox;
class Editor;
class BaseTool;

Expand Down Expand Up @@ -36,6 +38,7 @@ public slots:
void setPreserveAlpha( int );
void setVectorMergeEnabled( int );
void setAA( int );
void setInpolLevel( int );

void disableAllOptions();
void createUI();
Expand All @@ -51,6 +54,12 @@ public slots:
SpinSlider* mSizeSlider = nullptr;
SpinSlider* mFeatherSlider = nullptr;
QCheckBox* mUseAABox = nullptr;
QRadioButton* mNoInpol = nullptr;
QRadioButton* mSimpleInpol = nullptr;
QRadioButton* mStrongInpol = nullptr;
QRadioButton* mExtremeInpol = nullptr;
QGroupBox* mInpolLevelsBox = nullptr;

};

#endif // TOOLOPTIONDOCKWIDGET_H
40 changes: 39 additions & 1 deletion core_lib/managers/toolmanager.cpp
Expand Up @@ -94,13 +94,16 @@ void ToolManager::resetAllTools()
// Betatesters should be recommended to reset before sending tool related issues.
// This can prevent from users to stop working on their project.
getTool( PEN )->properties.width = 1.5; // not supposed to use feather
getTool( PEN )->properties.inpolLevel = -1;
getTool( POLYLINE )->properties.width = 1.5; // PEN dependent
getTool( PENCIL )->properties.width = 1.0;
getTool( PENCIL )->properties.feather = -1.0; // locks feather usage (can be changed)
getTool( PENCIL )->properties.inpolLevel = -1;
getTool( ERASER )->properties.width = 25.0;
getTool( ERASER )->properties.feather = 50.0;
getTool( BRUSH )->properties.width = 15.0;
getTool( BRUSH )->properties.feather = 200.0;
getTool( BRUSH )->properties.inpolLevel = -1;
getTool( SMUDGE )->properties.width = 25.0;
getTool( SMUDGE )->properties.feather = 200.0;

Expand Down Expand Up @@ -135,8 +138,13 @@ void ToolManager::setFeather( float newFeather )

void ToolManager::setUseFeather( bool usingFeather )
{
int usingAA = currentTool()->properties.useAA;
int value = propertySwitch(usingFeather, usingAA);

currentTool()->setAA(value);
currentTool()->setUseFeather( usingFeather );
Q_EMIT toolPropertyChanged( currentTool()->type(), USEFEATHER );
Q_EMIT toolPropertyChanged( currentTool()->type(), ANTI_ALIASING );
}

void ToolManager::setInvisibility( bool isInvisible )
Expand Down Expand Up @@ -169,12 +177,42 @@ void ToolManager::setPressure( bool isPressureOn )
Q_EMIT toolPropertyChanged( currentTool()->type(), PRESSURE );
}

void ToolManager::setAA( bool usingAA )
void ToolManager::setAA( int usingAA )
{
currentTool()->setAA( usingAA );
Q_EMIT toolPropertyChanged( currentTool()->type(), ANTI_ALIASING );
}

void ToolManager::setInpolLevel(int level)
{
currentTool()->setInpolLevel( level );
Q_EMIT toolPropertyChanged(currentTool()->type(), INTERPOLATION );
}


// Switches on/off two actions
// eg. if x = true, then y = false
int ToolManager::propertySwitch(bool condition, int tool)
{
int value = 0;
int newValue = 0;

if (condition == true){
value = -1;
newValue = oldValue;
oldValue = tool;
}

if (condition == false) {
if (newValue == 1) {
value = 1;
} else {
value = oldValue;
}
}
return value;
}

void ToolManager::tabletSwitchToEraser()
{
if (!mIsSwitchedToEraser)
Expand Down
12 changes: 10 additions & 2 deletions core_lib/managers/toolmanager.h
Expand Up @@ -8,7 +8,6 @@

class ScribbleArea;


class ToolManager : public BaseManager
{
Q_OBJECT
Expand All @@ -27,6 +26,7 @@ class ToolManager : public BaseManager

void tabletSwitchToEraser();
void tabletRestorePrevTool();
int propertySwitch( bool condition, int property );

Q_SIGNALS:
void penWidthValueChanged( float );
Expand All @@ -38,6 +38,11 @@ class ToolManager : public BaseManager
public slots:
void resetAllTools();

void noInpolSelected() { setInpolLevel( 0 ); }
void SimplepolSelected() { setInpolLevel( 1 ); }
void StrongpolSelected() { setInpolLevel( 2 ); }
void ExtremepolSelected() { setInpolLevel( 3 ); }

void setWidth( float );
void setFeather( float );
void setUseFeather( bool );
Expand All @@ -46,14 +51,17 @@ public slots:
void setVectorMergeEnabled( bool );
void setBezier( bool );
void setPressure( bool );
void setAA( bool );
void setAA(int );
void setInpolLevel (int );

private:
BaseTool* mCurrentTool = nullptr;
ToolType meTabletBackupTool = PENCIL;
bool mIsSwitchedToEraser = false;
QHash<ToolType, BaseTool*> mToolSetHash;

int oldValue = 0;

};

#endif // TOOLMANAGER_H
7 changes: 6 additions & 1 deletion core_lib/tool/basetool.cpp
Expand Up @@ -44,6 +44,7 @@ BaseTool::BaseTool( QObject *parent ) : QObject( parent )
m_enabledProperties.insert( PRESERVEALPHA, false );
m_enabledProperties.insert( BEZIER, false );
m_enabledProperties.insert( ANTI_ALIASING, false );
m_enabledProperties.insert( INTERPOLATION, false );
}

QCursor BaseTool::cursor()
Expand Down Expand Up @@ -328,8 +329,12 @@ void BaseTool::setVectorMergeEnabled(const bool vectorMergeEnabled)
properties.vectorMergeEnabled = vectorMergeEnabled;
}

void BaseTool::setAA(const bool useAA)
void BaseTool::setAA(const int useAA)
{
properties.useAA = useAA;
}

void BaseTool::setInpolLevel (const int level)
{
properties.inpolLevel = level;
}

0 comments on commit 3235fa2

Please sign in to comment.