From 41998df8e04905f07af5f4e8c9045653634e734d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Mon, 21 Dec 2020 16:32:38 +0300 Subject: [PATCH] New toolbar layout --- sources/widgets/toolbar.cpp | 63 +++++++++++++++++++++---------------- sources/widgets/toolbar.h | 26 +++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/sources/widgets/toolbar.cpp b/sources/widgets/toolbar.cpp index 4de14e7..1128e12 100644 --- a/sources/widgets/toolbar.cpp +++ b/sources/widgets/toolbar.cpp @@ -38,6 +38,7 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #include #include #include +#include ToolBar::ToolBar(const QMap &actMap, QWidget *parent) : QToolBar(tr("Instruments"), parent), mActMap(actMap) @@ -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]); @@ -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")); @@ -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); @@ -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) diff --git a/sources/widgets/toolbar.h b/sources/widgets/toolbar.h index e1d7f9f..344b3fc 100644 --- a/sources/widgets/toolbar.h +++ b/sources/widgets/toolbar.h @@ -32,8 +32,10 @@ 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 +#include #include QT_BEGIN_NAMESPACE @@ -41,10 +43,6 @@ class QToolButton; class ColorChooser; QT_END_NAMESPACE -/** - * @brief Toolbar with instrumets buttons, color choosers and etc. - * - */ class ToolBar : public QToolBar { Q_OBJECT @@ -53,25 +51,17 @@ class ToolBar : public QToolBar explicit ToolBar(const QMap &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 &mActMap; @@ -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);