Fixed crash with separator - #158.
This commit is contained in:
parent
a889db4f6b
commit
ae9a6e7d61
@ -69,9 +69,11 @@ void PlainToolButton::setChecked(bool checked) {
|
|||||||
void PlainToolButton::reactOnActionChange(QAction *action) {
|
void PlainToolButton::reactOnActionChange(QAction *action) {
|
||||||
QAction *real_action = action == NULL ? qobject_cast<QAction*>(sender()) : action;
|
QAction *real_action = action == NULL ? qobject_cast<QAction*>(sender()) : action;
|
||||||
|
|
||||||
setEnabled(real_action->isEnabled());
|
if (real_action != NULL) {
|
||||||
setCheckable(real_action->isCheckable());
|
setEnabled(real_action->isEnabled());
|
||||||
setChecked(real_action->isChecked());
|
setCheckable(real_action->isCheckable());
|
||||||
setIcon(real_action->icon());
|
setChecked(real_action->isChecked());
|
||||||
setToolTip(real_action->toolTip());
|
setIcon(real_action->icon());
|
||||||
|
setToolTip(real_action->toolTip());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,17 +152,26 @@ void StatusBar::loadChangeableActions(const QStringList &action_names) {
|
|||||||
widget_to_add->setVisible(false);
|
widget_to_add->setVisible(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Add originally toolbar action.
|
if (action_name == SEPARATOR_ACTION_NAME) {
|
||||||
PlainToolButton *tool_button = new PlainToolButton(this);
|
QLabel *lbl = new QLabel(QSL("•"));
|
||||||
|
|
||||||
tool_button->reactOnActionChange(matching_action);
|
widget_to_add = lbl;
|
||||||
|
action_to_add = new QAction(this);
|
||||||
|
action_to_add->setProperty("should_remove_action", true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Add originally toolbar action.
|
||||||
|
PlainToolButton *tool_button = new PlainToolButton(this);
|
||||||
|
tool_button->reactOnActionChange(matching_action);
|
||||||
|
|
||||||
action_to_add = matching_action;
|
widget_to_add = tool_button;
|
||||||
widget_to_add = tool_button;
|
action_to_add = matching_action;
|
||||||
|
|
||||||
matching_action->setProperty("should_remove", true);
|
connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger()));
|
||||||
connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger()));
|
connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange()));
|
||||||
connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange()));
|
}
|
||||||
|
|
||||||
|
action_to_add->setProperty("should_remove_widget", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add));
|
action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add));
|
||||||
@ -185,18 +194,23 @@ void StatusBar::clear() {
|
|||||||
while (!actions().isEmpty()) {
|
while (!actions().isEmpty()) {
|
||||||
QAction *act = actions().at(0);
|
QAction *act = actions().at(0);
|
||||||
QWidget *widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : NULL;
|
QWidget *widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : NULL;
|
||||||
bool should_remove = act->property("remove_widget").isValid();
|
bool should_remove_widget = act->property("should_remove_widget").isValid();
|
||||||
|
bool should_remove_action = act->property("should_remove_action").isValid();
|
||||||
|
|
||||||
|
removeAction(act);
|
||||||
|
|
||||||
if (widget != NULL) {
|
if (widget != NULL) {
|
||||||
removeWidget(widget);
|
removeWidget(widget);
|
||||||
widget->setVisible(false);
|
widget->setVisible(false);
|
||||||
|
|
||||||
if (should_remove) {
|
if (should_remove_widget) {
|
||||||
widget->deleteLater();
|
widget->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
removeAction(act);
|
if (should_remove_action) {
|
||||||
|
act->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user