Make KoToolBox::addButton a private method, pass complete button argument

parent e4e0ae80
......@@ -105,7 +105,7 @@ KoToolBox::KoToolBox()
d->buttonGroup = new QButtonGroup(this);
setLayout(d->layout);
foreach(const KoToolButton & button, KoToolManager::instance()->createToolList()) {
addButton(button.button, button.section, button.priority, button.buttonGroupId);
addButton(button);
d->visibilityCodes.insert(button.button, button.visibilityCode);
}
......@@ -129,30 +129,30 @@ KoToolBox::~KoToolBox()
delete d;
}
void KoToolBox::addButton(QToolButton *button, const QString &section, int priority, int buttonGroupId)
void KoToolBox::addButton(const KoToolButton &button)
{
d->buttons << button;
d->buttons << button.button;
// ensure same L&F
button->setCheckable(true);
button->setAutoRaise(true);
button.button->setCheckable(true);
button.button->setAutoRaise(true);
int toolbuttonSize = buttonSize(qApp->desktop()->screenNumber(this));
KConfigGroup cfg = KGlobal::config()->group("KoToolBox");
int iconSize = cfg.readEntry("iconSize", toolbuttonSize);
button->setIconSize(QSize(iconSize, iconSize));
button.button->setIconSize(QSize(iconSize, iconSize));
foreach (Section *section, d->sections.values()) {
section->setButtonSize(QSize(iconSize + BUTTON_MARGIN, iconSize + BUTTON_MARGIN));
}
QString sectionToBeAddedTo;
if (section.contains(qApp->applicationName())) {
if (button.section.contains(qApp->applicationName())) {
sectionToBeAddedTo = "main";
} else if (section.contains("main")) {
} else if (button.section.contains("main")) {
sectionToBeAddedTo = "main";
} else if (section.contains("dynamic")) {
} else if (button.section.contains("dynamic")) {
sectionToBeAddedTo = "dynamic";
} else {
sectionToBeAddedTo = section;
sectionToBeAddedTo = button.section;
}
Section *sectionWidget = d->sections.value(sectionToBeAddedTo);
......@@ -160,12 +160,12 @@ void KoToolBox::addButton(QToolButton *button, const QString &section, int prior
sectionWidget = new Section(this);
d->addSection(sectionWidget, sectionToBeAddedTo);
}
sectionWidget->addButton(button, priority);
sectionWidget->addButton(button.button, button.priority);
if (buttonGroupId < 0)
d->buttonGroup->addButton(button);
if (button.buttonGroupId < 0)
d->buttonGroup->addButton(button.button);
else
d->buttonGroup->addButton(button, buttonGroupId);
d->buttonGroup->addButton(button.button, button.buttonGroupId);
}
void KoToolBox::setActiveTool(KoCanvasController *canvas, int id)
......@@ -280,7 +280,7 @@ void KoToolBox::setFloating(bool v)
void KoToolBox::toolAdded(const KoToolButton &button, KoCanvasController *canvas)
{
Q_UNUSED(canvas);
addButton(button.button, button.section, button.priority, button.buttonGroupId);
addButton(button);
d->visibilityCodes.insert(button.button, button.visibilityCode);
setButtonsVisible(QList<QString>());
......
......@@ -54,21 +54,6 @@ public:
explicit KoToolBox();
~KoToolBox();
/**
* Add a button to the toolbox.
* The buttons should all be added before the first showing since adding will not really add
* them to the UI until setup() is called.
*
* @param button the new button. Please make sure you connect to the button yourself.
* @param section the section in which this button will be shown. Each section will be its own
* widget.
* @param priority the priority in the section. Lowest value means it will be shown first.
* @param buttonGroupId if passed this will allow you to use setActiveTool() to trigger
* this button
* @see setup()
*/
void addButton(QToolButton *button, const QString &section, int priority, int buttonGroupId=-1);
public Q_SLOTS:
/**
* Using the buttongroup id passed in addButton() you can set the new active button.
......@@ -94,6 +79,17 @@ public Q_SLOTS:
void setFloating(bool v);
private:
/**
* Add a button to the toolbox.
* The buttons should all be added before the first showing since adding will not really add
* them to the UI until setup() is called.
*
* @param button the new button. Please make sure you connect to the button yourself.
* @see setup()
*/
void addButton(const KoToolButton &button);
private Q_SLOTS:
void setCurrentLayer(const KoCanvasController *canvas, const KoShapeLayer* newLayer);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment