diff --git a/shell/settings/uiconfig.kcfg b/shell/settings/uiconfig.kcfg --- a/shell/settings/uiconfig.kcfg +++ b/shell/settings/uiconfig.kcfg @@ -21,5 +21,8 @@ true + + false + diff --git a/shell/settings/uiconfig.ui b/shell/settings/uiconfig.ui --- a/shell/settings/uiconfig.ui +++ b/shell/settings/uiconfig.ui @@ -6,8 +6,8 @@ 0 0 - 521 - 399 + 584 + 440 @@ -19,77 +19,88 @@ Dock Window Behavior - - - - - <p>Controls whether the bottom left corner is occupied by the dock at the left, or by the dock at the bottom.</p> - - - Bottom left corner occupied by: - - - - - - - <p>Controls whether the bottom right corner is occupied by the dock at the right, or by the dock at the bottom.</p> - - - Bottom right corner occupied by: - - - - - - - - 0 - 0 - - - - <p>Controls whether the bottom left corner is occupied by the dock at the left, or by the dock at the bottom.</p> - - - - Left Dock - + + + + + + + <p>Controls whether the bottom left corner is occupied by the dock at the left, or by the dock at the bottom.</p> + + + Bottom left corner occupied by: + + - - - Bottom Dock - + + + + + 0 + 0 + + + + <p>Controls whether the bottom left corner is occupied by the dock at the left, or by the dock at the bottom.</p> + + + + Left Dock + + + + + Bottom Dock + + + - - - - - - - 0 - 0 - - - - <p>Controls whether the bottom right corner is occupied by the dock at the right, or by the dock at the bottom.</p> - - - - Right Dock - + + + + <p>Controls whether the bottom right corner is occupied by the dock at the right, or by the dock at the bottom.</p> + + + Bottom right corner occupied by: + + - - - Bottom Dock - + + + + + 0 + 0 + + + + <p>Controls whether the bottom right corner is occupied by the dock at the right, or by the dock at the bottom.</p> + + + + Right Dock + + + + + Bottom Dock + + + + + + + + + Enable QtCreator-style "Focus Editor or Hide Docks" behavior + - + Qt::Vertical @@ -170,8 +181,33 @@ + + + + true + + + false + + + + + + KMessageWidget + QFrame +
kmessagewidget.h
+
+
+ + kcfg_BottomLeftCornerOwner + kcfg_BottomRightCornerOwner + kcfg_TabBarVisibility + kcfg_TabBarOpenAfterCurrent + kcfg_TabBarArrangeBuddies + kcfg_ColorizeByProject + diff --git a/shell/settings/uipreferences.h b/shell/settings/uipreferences.h --- a/shell/settings/uipreferences.h +++ b/shell/settings/uipreferences.h @@ -48,6 +48,7 @@ void apply() override; private: Ui::UiConfig* m_uiconfigUi; + bool m_focusEditorOrHideDocks; }; #endif diff --git a/shell/settings/uipreferences.cpp b/shell/settings/uipreferences.cpp --- a/shell/settings/uipreferences.cpp +++ b/shell/settings/uipreferences.cpp @@ -40,6 +40,20 @@ m_uiconfigUi = new Ui::UiConfig(); m_uiconfigUi->setupUi( w ); l->addWidget( w ); + + m_focusEditorOrHideDocks = UiConfig::self()->focusEditorOrHideDocks(); + m_uiconfigUi->messageWidget->setText(i18n( + "Changed setting \"Focus Editor or Hide Docks\"" + "will be applied after KDevelop restart")); + m_uiconfigUi->messageWidget->hide(); + + connect(this, &ConfigPage::changed, [this]() { + qDebug() << "ConfigPage::changed()"; + if (m_uiconfigUi->kcfg_FocusEditorOrHideDocks->isChecked() == m_focusEditorOrHideDocks) + m_uiconfigUi->messageWidget->hide(); + else + m_uiconfigUi->messageWidget->show(); + }); } UiPreferences::~UiPreferences() @@ -55,6 +69,9 @@ foreach (Sublime::MainWindow *window, uiController->mainWindows()) (static_cast(window))->loadSettings(); uiController->loadSettings(); + + m_uiconfigUi->messageWidget->hide(); + m_focusEditorOrHideDocks = UiConfig::self()->focusEditorOrHideDocks(); } QString UiPreferences::name() const diff --git a/sublime/idealbuttonbarwidget.h b/sublime/idealbuttonbarwidget.h --- a/sublime/idealbuttonbarwidget.h +++ b/sublime/idealbuttonbarwidget.h @@ -37,6 +37,8 @@ class View; class Area; +class LockButton; + class IdealButtonBarWidget: public QWidget { Q_OBJECT @@ -64,6 +66,9 @@ void saveShowState(); bool lastShowState(); + bool isLocked(); + void setLocked(bool); + private Q_SLOTS: void showWidget(bool checked); void buttonPressed(bool state); @@ -79,6 +84,9 @@ IdealController *_controller; QWidget *_corner; bool _showState; + bool _focusEditorOrHideDocks; + bool _isLocked; + LockButton* _lockButton; }; } diff --git a/sublime/idealbuttonbarwidget.cpp b/sublime/idealbuttonbarwidget.cpp --- a/sublime/idealbuttonbarwidget.cpp +++ b/sublime/idealbuttonbarwidget.cpp @@ -92,20 +92,80 @@ QPointer m_button; }; +class Sublime::LockButton : public IdealToolButton +{ +public: + LockButton(IdealButtonBarWidget* barWidget) + : IdealToolButton(barWidget->area(), barWidget) + , _barWidget(barWidget) + { + QAction* lockAction = new QAction(this); + lockAction->setCheckable(true); + lockAction->setToolTip(i18nc("@info:tooltip", "Lock/Unlock the Panel")); + setDefaultAction(lockAction); + + setLocked(barWidget->isLocked()); + setEnabled(barWidget->isShown()); + + connect(lockAction, &QAction::toggled, this, &LockButton::setLocked); + } + + bool isLocked() + { + return defaultAction()->isChecked(); + } + + void setLocked(bool lockValue) + { + defaultAction()->setIcon(lockIcon(lockValue)); + + + if (isLocked() != lockValue) + defaultAction()->setChecked(lockValue); + + if (_barWidget->isLocked() != lockValue) + _barWidget->setLocked(lockValue); + } + + QSize sizeHint() const override + { + QSize size = IdealToolButton::sizeHint(); + + size.setHeight(std::min(size.height(), size.width())); + size.setWidth(size.height()); + + return size; + } + +private: + QIcon lockIcon(bool lockValue) + { + if (lockValue) + return QIcon::fromTheme("lock"); + else + return QIcon::fromTheme("unlock"); + } + + IdealButtonBarWidget* _barWidget; +}; + IdealButtonBarWidget::IdealButtonBarWidget(Qt::DockWidgetArea area, IdealController *controller, Sublime::MainWindow *parent) : QWidget(parent) , _area(area) , _controller(controller) , _corner(nullptr) , _showState(false) + , _isLocked(false) + , _lockButton(nullptr) { setContextMenuPolicy(Qt::CustomContextMenu); setToolTip(i18nc("@info:tooltip", "Right click to add new tool views.")); if (area == Qt::BottomDockWidgetArea) { QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::RightToLeft, this); + statusLayout->setMargin(0); statusLayout->setSpacing(IDEAL_LAYOUT_SPACING); statusLayout->setContentsMargins(0, IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN); @@ -122,6 +182,18 @@ } else (void) new IdealButtonBarLayout(orientation(), this); + + KConfigGroup config = KSharedConfig::openConfig()->group("UiSettings"); + _focusEditorOrHideDocks = config.readEntry(QStringLiteral("FocusEditorOrHideDocks"), false); + + if (_focusEditorOrHideDocks && _area != Qt::TopDockWidgetArea) { + KConfigGroup config = KSharedConfig::openConfig()->group("UI"); + bool defaultLockValue = (_area == Qt::LeftDockWidgetArea) ? true : false; + setLocked(config.readEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(_area), defaultLockValue)); + + _lockButton = new LockButton(this); + layout()->addWidget(_lockButton); + } } QAction* IdealButtonBarWidget::addWidget(IdealDockWidget *dock, @@ -177,6 +249,24 @@ return _showState; } +bool IdealButtonBarWidget::isLocked() +{ + return _isLocked; +} + +void IdealButtonBarWidget::setLocked(bool lockValue) +{ + _isLocked = lockValue; + + if (_lockButton) { + KConfigGroup config = KSharedConfig::openConfig()->group("UI"); + config.writeEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(_area), _isLocked); + + if (_lockButton->isLocked() != lockValue) + _lockButton->setLocked(lockValue); + } +} + Qt::Orientation IdealButtonBarWidget::orientation() const { if (_area == Qt::LeftDockWidgetArea || _area == Qt::RightDockWidgetArea) @@ -226,8 +316,10 @@ _controller->showDockWidget(widgetAction->dockWidget(), checked); widgetAction->setChecked(checked); button->setChecked(checked); -} + if (_lockButton) + _lockButton->setEnabled(isShown()); +} void IdealButtonBarWidget::actionEvent(QActionEvent *event) { @@ -251,7 +343,12 @@ Q_ASSERT(action->dockWidget()); - layout()->addWidget(button); + if (_focusEditorOrHideDocks && _area == Qt::BottomDockWidgetArea) { + layout()->replaceWidget(_lockButton, button); + layout()->addWidget(_lockButton); + } else + layout()->addWidget(button); + connect(action, &QAction::toggled, this, static_cast(&IdealButtonBarWidget::showWidget)); connect(button, &IdealToolButton::clicked, this, &IdealButtonBarWidget::buttonPressed); connect(button, &IdealToolButton::customContextMenuRequested, diff --git a/sublime/mainwindow_p.h b/sublime/mainwindow_p.h --- a/sublime/mainwindow_p.h +++ b/sublime/mainwindow_p.h @@ -135,11 +135,13 @@ void showRightDock(bool b); void showBottomDock(bool b); void focusEditor(); + void focusEditorOrHideUnlockedDocks(); void selectNextDock(); void selectPreviousDock(); private: void restoreConcentrationMode(); + void hideUnlockedDocks(); void setBackgroundVisible(bool v); Qt::DockWidgetArea positionToDockArea(Position position); diff --git a/sublime/mainwindow_p.cpp b/sublime/mainwindow_p.cpp --- a/sublime/mainwindow_p.cpp +++ b/sublime/mainwindow_p.cpp @@ -114,6 +114,14 @@ connect(action, &QAction::triggered, this, &MainWindowPrivate::focusEditor); ac->addAction(QStringLiteral("focus_editor"), action); + KConfigGroup config = KSharedConfig::openConfig()->group("UiSettings"); + if (config.readEntry(QStringLiteral("FocusEditorOrHideDocks"), false)) { + action = new QAction(i18nc("@action", "Focus Editor or Hide Unlocked Docks"), this); + ac->setDefaultShortcut(action, Qt::Key_Escape); + connect(action, &QAction::triggered, this, &MainWindowPrivate::focusEditorOrHideUnlockedDocks); + ac->addAction(QStringLiteral("focus_editor_or_hide_unlocked_docks"), action); + } + action = new QAction(i18n("Hide/Restore Docks"), this); ac->setDefaultShortcut(action, Qt::META | Qt::CTRL | Qt::Key_Up); connect(action, &QAction::triggered, this, &MainWindowPrivate::toggleDocksShown); @@ -282,6 +290,43 @@ view->widget()->setFocus(Qt::ShortcutFocusReason); } +void MainWindowPrivate::focusEditorOrHideUnlockedDocks() +{ + View* view = m_mainWindow->activeView(); + + if (!view || (view && !view->hasWidget())) { + hideUnlockedDocks(); + return; + } + + if (view->widget()->hasFocus()) + hideUnlockedDocks(); + else + focusEditor(); +} + +void MainWindowPrivate::hideUnlockedDocks() +{ + // Due IdealController::showBottomDock() logic, + // first call focuses Dock, second - hide it + // TODO: add 'force' param to showXXXDock() ? + + if (!idealController->leftBarWidget->isLocked()) { + idealController->showLeftDock(false); + idealController->showLeftDock(false); + } + + if (!idealController->bottomBarWidget->isLocked()) { + idealController->showBottomDock(false); + idealController->showBottomDock(false); + } + + if (!idealController->rightBarWidget->isLocked()) { + idealController->showRightDock(false); + idealController->showRightDock(false); + } +} + void MainWindowPrivate::toggleDocksShown() { idealController->toggleDocksShown();