MCPcopy Create free account
hub / github.com/KDE/kdevelop / setUpWidgetForDockWidget

Function setUpWidgetForDockWidget

kdevplatform/sublime/idealcontroller.cpp:71–110  ·  view source on GitHub ↗

* If a given tool view has toolbar actions, create a new QMainWindow with a * toolbar that displays the actions and with @p viewWidget as the central widget. * * @param mainWindow the main window ancestor of @p viewWidget * @param view the tool view, for which a dock widget is being set up * @param viewWidget just-created non-null @p view->widget() * @param toolViewTitle the title of the too

Source from the content-addressed store, hash-verified

69 * @return a widget that should become the dock widget's widget (@p viewWidget itself or its new QMainWindow parent)
70 */
71[[nodiscard]] QWidget* setUpWidgetForDockWidget(const Sublime::MainWindow& mainWindow, const Sublime::View& view,
72 QWidget* viewWidget, const QString& toolViewTitle)
73{
74 Q_ASSERT(viewWidget);
75 Q_ASSERT(view.widget() == viewWidget);
76
77 const auto toolBarActions = view.toolBarActions();
78 if (toolBarActions.empty()) {
79 return viewWidget;
80 }
81
82 auto* const toolView = new QMainWindow();
83 auto* const toolBar = new QToolBar(toolView);
84
85 const auto iconSize = mainWindow.style()->pixelMetric(QStyle::PM_SmallIconSize);
86 toolBar->setIconSize(QSize(iconSize, iconSize));
87 toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
88 toolBar->setWindowTitle(i18nc("@title:window", "%1 Toolbar", toolViewTitle));
89 toolBar->setFloatable(false);
90 toolBar->setMovable(false);
91 toolBar->addActions(toolBarActions);
92
93 toolView->setCentralWidget(viewWidget);
94 toolView->setFocusProxy(viewWidget);
95 toolView->addToolBar(toolBar);
96
97 static const auto configGroupName = QStringLiteral("UiSettings/Docks/ToolbarEnabled");
98 const auto configEntryKey = view.document()->documentSpecifier();
99
100 const KConfigGroup cg(KSharedConfig::openConfig(), configGroupName);
101 toolBar->setVisible(cg.readEntry(configEntryKey, true));
102
103 const auto* const toggleViewAction = toolBar->toggleViewAction();
104 QObject::connect(toggleViewAction, &QAction::toggled, toggleViewAction, [toggleViewAction, configEntryKey] {
105 KConfigGroup cg(KSharedConfig::openConfig(), configGroupName);
106 cg.writeEntry(configEntryKey, toggleViewAction->isChecked());
107 });
108
109 return toolView;
110}
111
112/**
113 * Return a widget that used to be and can again become a dock widget's widget

Callers 1

addViewMethod · 0.85

Calls 9

emptyMethod · 0.80
styleMethod · 0.80
readEntryMethod · 0.80
writeEntryMethod · 0.80
widgetMethod · 0.45
toolBarActionsMethod · 0.45
documentSpecifierMethod · 0.45
documentMethod · 0.45
setVisibleMethod · 0.45

Tested by

no test coverage detected