Commit 224ccceb authored by Ismael Asensio's avatar Ismael Asensio
Browse files

ModuleView: Correctly update button box visibility

When buttons are hidden externally use a button mask to avoid having
visibility conflicts between the parent button box and the individual
buttons, since visible property is inherited.

A small refactor is required to de-couple an updateButtons() method.

Also remove the ability to individually hide the reset button, as this
is not defined as a module button, but attached to the Apply button.
parent f69f6817
......@@ -126,6 +126,7 @@ public:
bool pageChangeSupressed = false;
bool mSaveStatistics = true;
bool mDefaultsIndicatorsVisible = false;
KCModule::Buttons mButtonMask = ~KCModule::Buttons(KCModule::NoAdditionalButton);
};
ModuleView::ModuleView(QWidget *parent)
......@@ -442,14 +443,24 @@ void ModuleView::activeModuleChanged(KPageWidgetItem *current, KPageWidgetItem *
}
void ModuleView::stateChanged()
{
updatePageIconHeader(d->mPageWidget->currentPage());
updateButtons();
KCModuleProxy *activeModule = d->mPages.value(d->mPageWidget->currentPage());
Q_EMIT moduleChanged(activeModule && activeModule->isChanged());
}
void ModuleView::updateButtons()
{
KCModuleProxy *activeModule = d->mPages.value(d->mPageWidget->currentPage());
KAuth::Action moduleAction;
bool change = false;
bool defaulted = false;
KCModule::Buttons buttons = KCModule::NoAdditionalButton;
if (activeModule) {
buttons = activeModule->buttons();
buttons = activeModule->buttons() & d->mButtonMask;
change = activeModule->isChanged();
defaulted = activeModule->defaulted();
......@@ -463,8 +474,6 @@ void ModuleView::stateChanged()
}
}
updatePageIconHeader(d->mPageWidget->currentPage());
d->mApplyAuthorize->setAuthAction(moduleAction);
d->mDefault->setEnabled(!defaulted);
d->mDefault->setVisible(buttons & KCModule::Default);
......@@ -476,8 +485,6 @@ void ModuleView::stateChanged()
d->mHelp->setVisible(buttons & KCModule::Help);
d->mButtons->setVisible(buttons != KCModule::NoAdditionalButton);
Q_EMIT moduleChanged(change);
}
void ModuleView::keyPressEvent(QKeyEvent *event)
......@@ -521,7 +528,8 @@ bool ModuleView::saveStatistics() const
void ModuleView::setApplyVisible(bool visible)
{
d->mApply->setVisible(visible);
d->mButtonMask.setFlag(KCModule::Apply, visible);
updateButtons();
}
bool ModuleView::isApplyVisible() const
......@@ -531,7 +539,8 @@ bool ModuleView::isApplyVisible() const
void ModuleView::setDefaultsVisible(bool visible)
{
d->mDefault->setVisible(visible);
d->mButtonMask.setFlag(KCModule::Default, visible);
updateButtons();
}
bool ModuleView::isDefaultsVisible() const
......@@ -539,11 +548,6 @@ bool ModuleView::isDefaultsVisible() const
return d->mDefault->isVisible();
}
void ModuleView::setResetVisible(bool visible)
{
d->mReset->setVisible(visible);
}
bool ModuleView::isResetVisible() const
{
return d->mReset->isVisible();
......
......@@ -111,11 +111,6 @@ public:
*/
bool isDefaultsVisible() const;
/**
* Shows or hides the Reset button.
*/
void setResetVisible(bool visible);
/**
* @returns True if the Reset button is visible.
*/
......@@ -168,6 +163,7 @@ private:
void addModule(MenuItem *item, const QStringList &args);
bool moduleSave(KCModuleProxy *module);
void updatePageIconHeader(KPageWidgetItem *page);
void updateButtons();
private Q_SLOTS:
void activeModuleChanged(KPageWidgetItem *current, KPageWidgetItem *previous);
......
......@@ -383,7 +383,6 @@ void SidebarMode::initEvent()
d->moduleView->setSaveStatistics(false);
d->moduleView->setApplyVisible(false);
d->moduleView->setDefaultsVisible(false);
d->moduleView->setResetVisible(false);
}
if (config().readEntry("HighlightNonDefaultSettings", false)) {
......@@ -588,7 +587,6 @@ void SidebarMode::moduleLoaded()
d->moduleView->setSaveStatistics(false);
d->moduleView->setApplyVisible(false);
d->moduleView->setDefaultsVisible(false);
d->moduleView->setResetVisible(false);
}
}
......
Supports Markdown
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