| 339 | } |
| 340 | |
| 341 | class IdealToolBar : public QToolBar |
| 342 | { |
| 343 | Q_OBJECT |
| 344 | public: |
| 345 | explicit IdealToolBar(const QString& title, bool hideWhenEmpty, IdealButtonBarWidget* buttons, QMainWindow* parent) |
| 346 | : QToolBar(title, parent) |
| 347 | , m_buttons(hideWhenEmpty ? buttons : nullptr) |
| 348 | { |
| 349 | setMovable(false); |
| 350 | setFloatable(false); |
| 351 | setObjectName(title); |
| 352 | layout()->setContentsMargins(0, 0, 0, 0); |
| 353 | |
| 354 | addWidget(buttons); |
| 355 | |
| 356 | // This code determines the initial visibility of the toolbar only if KMainWindow::applyMainWindowSettings() |
| 357 | // fails to restore the main window state from config. |
| 358 | if (hideWhenEmpty) { |
| 359 | updateVisibility(); |
| 360 | connect(m_buttons, &IdealButtonBarWidget::emptyChanged, this, &IdealToolBar::updateVisibility); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void updateVisibility() |
| 365 | { |
| 366 | // if (!m_buttons) do not hide if empty, therefore always show |
| 367 | setVisible(!m_buttons || !m_buttons->isEmpty()); |
| 368 | } |
| 369 | |
| 370 | private: |
| 371 | IdealButtonBarWidget* const m_buttons; |