Skip to content

Commit

Permalink
Merge pull request #38 from smolnp/develop
Browse files Browse the repository at this point in the history
New toolbar layout
.
#15 (comment)
  • Loading branch information
maifeeulasad authored Dec 21, 2020
2 parents 629ba53 + 41998df commit 974521f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
63 changes: 36 additions & 27 deletions sources/widgets/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE
#include <QSpinBox>
#include <QAction>
#include <QtCore/QMap>
#include <QLabel>

ToolBar::ToolBar(const QMap<InstrumentsEnum, QAction *> &actMap, QWidget *parent) :
QToolBar(tr("Instruments"), parent), mActMap(actMap)
Expand All @@ -59,6 +60,7 @@ QToolButton* ToolBar::createToolButton(QAction *act)

void ToolBar::initializeItems()
{
QLabel *InstrumentText = new QLabel(tr("Instruments"), this);
mCursorButton = createToolButton(mActMap[CURSOR]);
mEraserButton = createToolButton(mActMap[ERASER]);
mPenButton = createToolButton(mActMap[PEN]);
Expand All @@ -73,25 +75,36 @@ void ToolBar::initializeItems()
mTextButton = createToolButton(mActMap[TEXT]);
mCropButton = createToolButton(mActMap[CROP]);

textPenSize = new QLabel(tr("Pen size: 1 "), this);
mPenSize = new QSlider(Qt::Horizontal);
mPenSize->setMinimum(1);
mPenSize->setMaximum(25);
mPenSize->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
connect(mPenSize, &QAbstractSlider::valueChanged, this, &ToolBar::valuePenSize);

QGridLayout *bLayout = new QGridLayout();
bLayout->setMargin(3);
bLayout->addWidget(mPenButton, 0, 0);
bLayout->addWidget(mEraserButton, 0, 1);
bLayout->addWidget(mColorPickerPaletteButton, 1, 0);
bLayout->addWidget(mMagnifierButton, 1, 1);
bLayout->addWidget(mCursorButton, 2, 0);
bLayout->addWidget(mLineButton, 2, 1);
bLayout->addWidget(mSprayButton, 3, 0);
bLayout->addWidget(mFillButton, 3, 1);
bLayout->addWidget(mRectangleButton, 4, 0);
bLayout->addWidget(mEllipseButton, 4, 1);
bLayout->addWidget(mCurveButton, 5, 0);
bLayout->addWidget(mTextButton, 5, 1);
bLayout->addWidget(mCropButton, 6, 0);
bLayout->setMargin(1);
bLayout->addWidget(InstrumentText, 0, 0, 1, 4, Qt::AlignCenter);
bLayout->addWidget(mPenButton, 1, 0);
bLayout->addWidget(mSprayButton, 1, 1);
bLayout->addWidget(mEraserButton, 1, 2);
bLayout->addWidget(mLineButton, 1, 3);
bLayout->addWidget(mCurveButton, 2, 0);
bLayout->addWidget(mRectangleButton, 2, 1);
bLayout->addWidget(mEllipseButton, 2, 2);
bLayout->addWidget(mCropButton, 2, 3);
bLayout->addWidget(mCursorButton, 3, 0);
bLayout->addWidget(mMagnifierButton, 3, 1);
bLayout->addWidget(mTextButton, 3, 2);
bLayout->addWidget(textPenSize, 4, 0, 1, 4);
bLayout->addWidget(mPenSize, 5, 0, 1, 4);


QWidget *bWidget = new QWidget();
bWidget->setLayout(bLayout);

QLabel *ColorText = new QLabel(tr("Color"), this);

mPColorChooser = new ColorChooser(0, 0, 0, this);
mPColorChooser->setStatusTip(tr("Primary color"));
mPColorChooser->setToolTip(tr("Primary color"));
Expand All @@ -102,18 +115,13 @@ void ToolBar::initializeItems()
mSColorChooser->setToolTip(tr("Secondary color"));
connect(mSColorChooser, &ColorChooser::sendColor, this, &ToolBar::secondaryColorChanged);

QSpinBox *penSizeSpin = new QSpinBox();
penSizeSpin->setRange(1, 20);
penSizeSpin->setValue(1);
penSizeSpin->setStatusTip(tr("Pen size"));
penSizeSpin->setToolTip(tr("Pen size"));
connect(penSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(penValueChanged(int)));

QGridLayout *tLayout = new QGridLayout();
tLayout->setMargin(3);
tLayout->addWidget(mPColorChooser, 0, 0);
tLayout->addWidget(mSColorChooser, 0, 1);
tLayout->addWidget(penSizeSpin, 1, 0, 1, 2);
tLayout->setMargin(1);
tLayout->addWidget(ColorText, 0, 0, 1, 4, Qt::AlignCenter);
tLayout->addWidget(mColorPickerPaletteButton, 1, 0);
tLayout->addWidget(mFillButton, 1, 1);
tLayout->addWidget(mPColorChooser, 1, 2);
tLayout->addWidget(mSColorChooser, 1, 3);

QWidget *tWidget = new QWidget();
tWidget->setLayout(tLayout);
Expand All @@ -123,9 +131,10 @@ void ToolBar::initializeItems()
addWidget(tWidget);
}

void ToolBar::penValueChanged(const int &value)
void ToolBar::valuePenSize(const int &value)
{
DataSingleton::Instance()->setPenSize(value);
DataSingleton::Instance()->setPenSize(value);
textPenSize->setText(QString(tr("Pen size: %1")).arg(mPenSize->value()));
}

void ToolBar::primaryColorChanged(const QColor &color)
Expand Down
26 changes: 8 additions & 18 deletions sources/widgets/toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE
#ifndef TOOLBAR_H
#define TOOLBAR_H

#include "palettebutton.h"
#include "../josspaintenums.h"

#include <QLabel>
#include <QSlider>
#include <QToolBar>

QT_BEGIN_NAMESPACE
class QToolButton;
class ColorChooser;
QT_END_NAMESPACE

/**
* @brief Toolbar with instrumets buttons, color choosers and etc.
*
*/
class ToolBar : public QToolBar
{
Q_OBJECT
Expand All @@ -53,25 +51,17 @@ class ToolBar : public QToolBar
explicit ToolBar(const QMap<InstrumentsEnum, QAction*> &actMap, QWidget *parent = 0);

private:
/**
* @brief Initialize all buttons, color choosers and etc.
*
*/
void initializeItems();
/**
* @brief Create new QToolButton
*
* @param name Name of button
* @param iconPath Path to button icon.
* @return QToolButton Created QToolButton.
*/
QToolButton* createToolButton(QAction *act);

QToolButton* createToolButton(QAction *act);
QToolButton *mCursorButton, *mEraserButton, *mPenButton, *mLineButton,
*mColorPickerButton,*mColorPickerPaletteButton, *mMagnifierButton,
*mSprayButton, *mFillButton,
*mRectangleButton, *mEllipseButton, *mCurveButton, *mTextButton, *mCropButton;
ColorChooser *mPColorChooser, *mSColorChooser;
QSlider *mPenSize;
QLabel *textPenSize;

bool mPrevInstrumentSetted;
const QMap<InstrumentsEnum, QAction*> &mActMap;

Expand All @@ -84,7 +74,7 @@ public slots:
void setSecondaryColorView();

private slots:
void penValueChanged(const int &value);
void valuePenSize(const int &value);
void primaryColorChanged(const QColor &color);
void secondaryColorChanged(const QColor &color);

Expand Down

0 comments on commit 974521f

Please sign in to comment.