Skip to content

Commit e2e8cb4

Browse files
committed
Add namespace to all classes
1 parent 0a4b6d2 commit e2e8cb4

13 files changed

+176
-128
lines changed

example/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <QVBoxLayout>
2222
#include <kColorPicker/KColorPicker.h>
2323

24+
using kColorPicker::KColorPicker;
25+
2426
int main(int argc, char **argv)
2527
{
2628
QApplication app(argc, argv);

include/kColorPicker/KColorPicker.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,36 @@
2626

2727
#include <kColorPicker/KColorPickerExport.h>
2828

29+
namespace kColorPicker {
30+
2931
class KColorPickerPrivate;
3032

3133
class KCOLORPICKER_EXPORT KColorPicker : public QToolButton
3234
{
3335
Q_OBJECT
3436

3537
Q_DECLARE_PRIVATE(KColorPicker)
38+
3639
public:
37-
explicit KColorPicker();
38-
~KColorPicker();
39-
void setFixedSize(const QSize& size);
40-
void setFixedSize(int width, int height);
40+
explicit KColorPicker();
41+
~KColorPicker();
42+
void setFixedSize(const QSize &size);
43+
void setFixedSize(int width, int height);
4144

4245
public slots:
4346
void setColor(const QColor &color);
4447

4548
signals:
46-
void colorChanged(const QColor &color) const;
49+
void colorChanged(const QColor &color) const;
4750

4851
private:
4952
QScopedPointer<KColorPickerPrivate> const d_ptr;
5053

5154
private slots:
52-
void setColorIcon(const QColor& color);
55+
void setColorIcon(const QColor &color);
5356
void setIconSize(const QSize &size);
54-
void colorSelected(const QColor &color);
57+
void colorSelected(const QColor &color);
5558
};
5659

60+
}
5761
#endif //KCOLORPICKER_KCOLORPICKER_H

src/IconCreator.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919

2020
#include "IconCreator.h"
2121

22-
QIcon IconCreator::createIcon(const QColor &color, const QSize& size)
22+
namespace kColorPicker {
23+
24+
QIcon IconCreator::createIcon(const QColor &color, const QSize &size)
2325
{
2426
QPixmap pixmap(size);
2527
pixmap.fill(color);
2628
QPainter painter(&pixmap);
2729
auto penWidth = painter.pen().width();
2830
painter.setPen(QColor(Qt::gray));
29-
painter.drawRect(0,0, size.width() - penWidth, size.height() - penWidth);
31+
painter.drawRect(0, 0, size.width() - penWidth, size.height() - penWidth);
3032

3133
return QIcon(pixmap);
3234
}
35+
36+
} // namespace kColorPicker

src/IconCreator.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
#include <QColor>
2525
#include <QPainter>
2626

27+
namespace kColorPicker {
28+
2729
class IconCreator
2830
{
2931
public:
30-
explicit IconCreator() = delete;
31-
~IconCreator() = delete;
32-
static QIcon createIcon(const QColor& color, const QSize& size = QSize(25, 25));
32+
explicit IconCreator() = delete;
33+
~IconCreator() = delete;
34+
static QIcon createIcon(const QColor &color, const QSize &size = QSize(25, 25));
3335
};
3436

37+
} // namespace kColorPicker
38+
3539
#endif //KCOLORPICKER_ICONCREATOR_H

src/KColorPicker.cpp

+28-24
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222
#include "IconCreator.h"
2323
#include "PopupMenu.h"
2424

25+
namespace kColorPicker {
26+
2527
class KColorPickerPrivate
2628
{
2729
Q_DISABLE_COPY(KColorPickerPrivate)
2830

2931
Q_DECLARE_PUBLIC(KColorPicker)
3032

31-
explicit KColorPickerPrivate(KColorPicker *kColorPicker);
33+
explicit KColorPickerPrivate(KColorPicker *kColorPicker);
3234

33-
KColorPicker *const q_ptr;
35+
KColorPicker *const q_ptr;
3436
QSize mIconSize;
35-
PopupMenu mPopupMenu;
36-
QColor mSelectedColor;
37+
PopupMenu mPopupMenu;
38+
QColor mSelectedColor;
3739
};
3840

3941
KColorPicker::KColorPicker() : d_ptr(new KColorPickerPrivate(this))
@@ -44,46 +46,46 @@ KColorPicker::~KColorPicker()
4446

4547
void KColorPicker::setColor(const QColor &color)
4648
{
47-
Q_D(KColorPicker);
48-
setColorIcon(color);
49-
d->mPopupMenu.selectColor(color);
49+
Q_D(KColorPicker);
50+
setColorIcon(color);
51+
d->mPopupMenu.selectColor(color);
5052
}
5153

5254
void KColorPicker::colorSelected(const QColor &color)
5355
{
54-
setColorIcon(color);
55-
emit colorChanged(color);
56+
setColorIcon(color);
57+
emit colorChanged(color);
5658
}
5759

5860
void KColorPicker::setFixedSize(const QSize &size)
5961
{
60-
Q_D(const KColorPicker);
61-
QToolButton::setFixedSize(size);
62-
setIconSize(size);
63-
setColorIcon(d->mSelectedColor);
62+
Q_D(const KColorPicker);
63+
QToolButton::setFixedSize(size);
64+
setIconSize(size);
65+
setColorIcon(d->mSelectedColor);
6466
}
6567

6668
void KColorPicker::setFixedSize(int width, int height)
6769
{
68-
Q_D(const KColorPicker);
69-
QToolButton::setFixedSize(width, height);
70-
setIconSize(QSize(width, height));
71-
setColorIcon(d->mSelectedColor);
70+
Q_D(const KColorPicker);
71+
QToolButton::setFixedSize(width, height);
72+
setIconSize(QSize(width, height));
73+
setColorIcon(d->mSelectedColor);
7274
}
7375

7476
void KColorPicker::setIconSize(const QSize &size)
7577
{
76-
Q_D(KColorPicker);
77-
auto scaleFactor = 0.6;
78-
d->mIconSize = size * scaleFactor;
79-
QToolButton::setIconSize(d->mIconSize);
78+
Q_D(KColorPicker);
79+
auto scaleFactor = 0.6;
80+
d->mIconSize = size * scaleFactor;
81+
QToolButton::setIconSize(d->mIconSize);
8082
}
8183

8284
void KColorPicker::setColorIcon(const QColor &color)
8385
{
84-
Q_D(KColorPicker);
85-
auto icon = IconCreator::createIcon(color, d->mIconSize);
86-
setIcon(icon);
86+
Q_D(KColorPicker);
87+
auto icon = IconCreator::createIcon(color, d->mIconSize);
88+
setIcon(icon);
8789
}
8890

8991
//
@@ -109,3 +111,5 @@ KColorPickerPrivate::KColorPickerPrivate(KColorPicker *kColorPicker) : q_ptr(kCo
109111
mPopupMenu.addColor(QColor(Qt::black));
110112

111113
}
114+
115+
} // namespace kColorPicker

src/PopupMenu.cpp

+57-53
Original file line numberDiff line numberDiff line change
@@ -19,102 +19,106 @@
1919

2020
#include "PopupMenu.h"
2121

22+
namespace kColorPicker {
23+
2224
PopupMenu::PopupMenu()
2325
{
24-
mButtonGroup = new QButtonGroup();
25-
mLayout = new QGridLayout();
26-
mLayout->setSpacing(0);
27-
mLayout->setMargin(5);
28-
setLayout(mLayout);
29-
addColorDialogButton();
26+
mButtonGroup = new QButtonGroup();
27+
mLayout = new QGridLayout();
28+
mLayout->setSpacing(0);
29+
mLayout->setMargin(5);
30+
setLayout(mLayout);
31+
addColorDialogButton();
3032
}
3133

3234
PopupMenu::~PopupMenu()
3335
{
34-
delete mButtonGroup;
35-
delete mColorDialogButton;
36+
delete mButtonGroup;
37+
delete mColorDialogButton;
3638
}
3739

3840
void PopupMenu::addColor(const QColor &color)
3941
{
40-
if(!isColorInGrid(color)) {
41-
addColorButton(color);
42-
}
42+
if (!isColorInGrid(color)) {
43+
addColorButton(color);
44+
}
4345
}
4446

4547
void PopupMenu::selectColor(const QColor &color)
4648
{
47-
addColor(color);
48-
49-
for(auto button : mColorButtons) {
50-
if(button->color() == color) {
51-
button->setChecked(true);
52-
return;
53-
}
54-
}
49+
addColor(color);
50+
51+
for (auto button : mColorButtons) {
52+
if (button->color() == color) {
53+
button->setChecked(true);
54+
return;
55+
}
56+
}
5557
}
5658

5759
void PopupMenu::generateGrid()
5860
{
59-
auto row = 0;
60-
auto column = 0;
61+
auto row = 0;
62+
auto column = 0;
6163

62-
clearGrid();
64+
clearGrid();
6365

64-
for(auto button : mColorButtons) {
65-
mLayout->addWidget(button, row, column % 4);
66-
column++;
67-
if(column % 4 == 0) {
68-
row++;
69-
}
70-
}
66+
for (auto button : mColorButtons) {
67+
mLayout->addWidget(button, row, column % 4);
68+
column++;
69+
if (column % 4 == 0) {
70+
row++;
71+
}
72+
}
7173

72-
mLayout->addWidget(mColorDialogButton, row, column % 4);
74+
mLayout->addWidget(mColorDialogButton, row, column % 4);
7375
}
7476

7577
ColorButton *PopupMenu::createButton(const QColor &color)
7678
{
77-
auto icon = IconCreator::createIcon(color);
78-
auto button = new ColorButton(icon, color);
79-
return button;
79+
auto icon = IconCreator::createIcon(color);
80+
auto button = new ColorButton(icon, color);
81+
return button;
8082
}
8183

8284
void PopupMenu::addColorButton(const QColor &color)
8385
{
84-
auto button = createButton(color);
85-
mButtonGroup->addButton(button);
86-
mColorButtons.append(button);
87-
connect(button, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected);
88-
generateGrid();
86+
auto button = createButton(color);
87+
mButtonGroup->addButton(button);
88+
mColorButtons.append(button);
89+
connect(button, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected);
90+
generateGrid();
8991
}
9092

9193
void PopupMenu::clearGrid()
9294
{
93-
for(auto button : mColorButtons) {
94-
mLayout->removeWidget(button);
95-
}
95+
for (auto button : mColorButtons) {
96+
mLayout->removeWidget(button);
97+
}
9698
}
9799

98100
bool PopupMenu::isColorInGrid(const QColor &color)
99101
{
100-
for(auto button : mColorButtons) {
101-
if(button->color() == color) {
102-
return true;
103-
}
104-
}
105-
return false;
102+
for (auto button : mColorButtons) {
103+
if (button->color() == color) {
104+
return true;
105+
}
106+
}
107+
return false;
106108
}
107109

108110
void PopupMenu::colorSelected(const QColor &color)
109111
{
110-
emit colorChanged(color);
111-
addColor(color);
112-
hide();
112+
emit colorChanged(color);
113+
addColor(color);
114+
hide();
113115
}
114116

115117
void PopupMenu::addColorDialogButton()
116118
{
117-
auto icon = QIcon(QStringLiteral(":/icons/ellipsis"));
118-
mColorDialogButton = new ColorDialogButton(icon);
119-
connect(mColorDialogButton, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected);
119+
auto icon = QIcon(QStringLiteral(":/icons/ellipsis"));
120+
mColorDialogButton = new ColorDialogButton(icon);
121+
connect(mColorDialogButton, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected);
120122
}
123+
124+
} // namespace kColorPicker

0 commit comments

Comments
 (0)