Commit c363c1d4 authored by Eike Ziller's avatar Eike Ziller

Add locator input widget to help windows

And move the "Show Sidebar" button into the status bar that we
need now anyhow.

Change-Id: I24bfa0991cbdcdba4d1a8cd6cbacde28d459972d
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent acc86aee
......@@ -31,9 +31,8 @@
#include <aggregation/aggregate.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/locator/locator.h>
#include <coreplugin/locator/locatorwidget.h>
#include <coreplugin/statusbarmanager.h>
#include <coreplugin/locator/locatormanager.h>
#include <coreplugin/minisplitter.h>
#include <QStatusBar>
#include <QVBoxLayout>
......@@ -56,7 +55,7 @@ EditorWindow::EditorWindow(QWidget *parent) :
auto splitter = new NonResizingSplitter(statusBar);
splitter->setChildrenCollapsible(false);
statusBar->addPermanentWidget(splitter, 10);
auto locatorWidget = createStaticLocatorWidget(Locator::instance());
auto locatorWidget = LocatorManager::createLocatorInputWidget(this);
splitter->addWidget(locatorWidget);
splitter->addWidget(new QWidget);
setAttribute(Qt::WA_DeleteOnClose);
......@@ -74,11 +73,6 @@ EditorWindow::EditorWindow(QWidget *parent) :
deleteLater();
});
updateWindowTitle();
// register locator widget for this window
auto agg = new Aggregation::Aggregate;
agg->add(this);
agg->add(locatorWidget);
}
EditorWindow::~EditorWindow()
......
......@@ -108,9 +108,9 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
ActionContainer *mtools = ActionManager::actionContainer(Constants::M_TOOLS);
mtools->addAction(cmd);
m_locatorWidget = createStaticLocatorWidget(this);
auto locatorWidget = LocatorManager::createLocatorInputWidget(ICore::mainWindow());
StatusBarWidget *view = new StatusBarWidget;
view->setWidget(m_locatorWidget);
view->setWidget(locatorWidget);
view->setContext(Context("LocatorWidget"));
view->setPosition(StatusBarWidget::First);
m_corePlugin->addAutoReleasedObject(view);
......@@ -139,11 +139,6 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
void Locator::extensionsInitialized()
{
// register locator widget for main window
auto agg = new Aggregation::Aggregate;
agg->add(ICore::mainWindow());
agg->add(m_locatorWidget);
m_filters = ExtensionSystem::PluginManager::getObjects<ILocatorFilter>();
Utils::sort(m_filters, [](const ILocatorFilter *first, const ILocatorFilter *second) -> bool {
if (first->priority() != second->priority())
......@@ -350,11 +345,6 @@ void Locator::setRefreshInterval(int interval)
m_refreshTimer.start();
}
LocatorWidget *Locator::mainLocatorWidget()
{
return m_instance->m_locatorWidget;
}
void Locator::refresh(QList<ILocatorFilter *> filters)
{
if (filters.isEmpty())
......
......@@ -43,7 +43,6 @@ class CorePlugin;
class OpenDocumentsFilter;
class FileSystemFilter;
class LocatorSettingsPage;
class LocatorWidget;
class ExternalToolsFilter;
class Locator : public QObject
......@@ -66,7 +65,6 @@ public:
void setCustomFilters(QList<ILocatorFilter *> f);
int refreshInterval();
void setRefreshInterval(int interval);
static LocatorWidget *mainLocatorWidget();
signals:
void filtersChanged();
......@@ -93,7 +91,6 @@ private:
ExecuteFilter *m_executeFilter;
CorePlugin *m_corePlugin = nullptr;
ExternalToolsFilter *m_externalToolsFilter;
LocatorWidget *m_locatorWidget;
};
} // namespace Internal
......
......@@ -85,4 +85,14 @@ void LocatorManager::show(const QString &text,
locatorWidget()->showText(text, selectionStart, selectionLength);
}
QWidget *LocatorManager::createLocatorInputWidget(QWidget *window)
{
auto locatorWidget = createStaticLocatorWidget(Locator::instance());
// register locator widget for this window
auto agg = new Aggregation::Aggregate;
agg->add(window);
agg->add(locatorWidget);
return locatorWidget;
}
} // namespace Core
......@@ -44,6 +44,8 @@ public:
static void showFilter(ILocatorFilter *filter);
static void show(const QString &text, int selectionStart = -1, int selectionLength = 0);
static QWidget *createLocatorInputWidget(QWidget *window);
};
} // namespace Core
......@@ -100,3 +100,33 @@ MiniSplitter::MiniSplitter(Qt::Orientation orientation, SplitterStyle style)
setChildrenCollapsible(false);
setProperty("minisplitter", true);
}
/*!
\class NonResizingSplitter
\inmodule Qt Creator
The NonResizingSplitter class is a MiniSplitter that keeps its first widget's size fixed
when it is resized.
*/
/*!
Constructs a non-resizing splitter with \a parent and \a style.
The default style is MiniSplitter::Light.
*/
NonResizingSplitter::NonResizingSplitter(QWidget *parent, SplitterStyle style)
: MiniSplitter(parent, style)
{
}
/*!
\internal
*/
void NonResizingSplitter::resizeEvent(QResizeEvent *ev)
{
// bypass QSplitter magic
int leftSplitWidth = qMin(sizes().at(0), ev->size().width());
int rightSplitWidth = qMax(0, ev->size().width() - leftSplitWidth);
setSizes(QList<int>() << leftSplitWidth << rightSplitWidth);
QWidget::resizeEvent(ev);
}
......@@ -51,4 +51,14 @@ private:
SplitterStyle m_style;
};
class CORE_EXPORT NonResizingSplitter : public MiniSplitter
{
public:
explicit NonResizingSplitter(QWidget *parent, SplitterStyle style = Light);
protected:
void resizeEvent(QResizeEvent *ev);
};
} // namespace Core
......@@ -26,6 +26,7 @@
#include "statusbarmanager.h"
#include "mainwindow.h"
#include "minisplitter.h"
#include "statusbarwidget.h"
#include <extensionsystem/pluginmanager.h>
......@@ -145,17 +146,3 @@ void StatusBarManager::restoreSettings()
sum += w;
m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth));
}
NonResizingSplitter::NonResizingSplitter(QWidget *parent)
: MiniSplitter(parent, Light)
{
}
void NonResizingSplitter::resizeEvent(QResizeEvent *ev)
{
// bypass QSplitter magic
int leftSplitWidth = qMin(sizes().at(0), ev->size().width());
int rightSplitWidth = qMax(0, ev->size().width() - leftSplitWidth);
setSizes(QList<int>() << leftSplitWidth << rightSplitWidth);
QWidget::resizeEvent(ev);
}
......@@ -25,12 +25,11 @@
#pragma once
#include "minisplitter.h"
#include <QList>
#include <QObject>
QT_BEGIN_NAMESPACE
class QSplitter;
class QWidget;
QT_END_NAMESPACE
......@@ -39,17 +38,6 @@ namespace Internal {
class MainWindow;
class NonResizingSplitter : public MiniSplitter
{
Q_OBJECT
public:
explicit NonResizingSplitter(QWidget *parent);
protected:
void resizeEvent(QResizeEvent *ev);
};
class StatusBarManager : public QObject
{
Q_OBJECT
......
......@@ -43,8 +43,10 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/locator/locatormanager.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/sidebar.h>
#include <coreplugin/minisplitter.h>
#include <texteditor/texteditorconstants.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
......@@ -56,6 +58,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QStackedWidget>
#include <QStatusBar>
#include <QToolButton>
static const char kWindowSideBarSettingsKey[] = "Help/WindowSideBar";
......@@ -83,9 +86,15 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
{
m_viewerStack = new QStackedWidget;
auto hLayout = new QHBoxLayout(this);
auto topLayout = new QVBoxLayout;
topLayout->setMargin(0);
topLayout->setSpacing(0);
setLayout(topLayout);
auto hLayout = new QHBoxLayout;
hLayout->setMargin(0);
hLayout->setSpacing(0);
topLayout->addLayout(hLayout, 10);
m_sideBarSplitter = new Core::MiniSplitter(this);
m_sideBarSplitter->setOpaqueResize(false);
......@@ -144,9 +153,23 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
connect(m_sideBar, &Core::SideBar::sideBarClosed, m_toggleSideBarAction, [this]() {
m_toggleSideBarAction->setChecked(false);
});
if (style == ExternalWindow) {
auto statusBar = new QStatusBar;
topLayout->addWidget(statusBar);
auto splitter = new Core::NonResizingSplitter(statusBar);
statusBar->addPermanentWidget(splitter, 10);
auto statusBarWidget = new QWidget;
auto statusBarWidgetLayout = new QHBoxLayout;
statusBarWidgetLayout->setContentsMargins(0, 0, 3, 0);
statusBarWidget->setLayout(statusBarWidgetLayout);
splitter->addWidget(statusBarWidget);
splitter->addWidget(new QWidget);
auto locatorWidget = Core::LocatorManager::createLocatorInputWidget(window());
statusBarWidgetLayout->addWidget(Core::Command::toolButtonWithAppendedShortcut(
m_toggleSideBarAction, cmd));
statusBarWidgetLayout->addWidget(locatorWidget);
}
}
if (style == ExternalWindow)
layout->addWidget(Core::Command::toolButtonWithAppendedShortcut(m_toggleSideBarAction, cmd));
if (style != ModeWidget) {
m_switchToHelp = new QAction(tr("Open in Help Mode"), toolBar);
......
Markdown is supported
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