forked from qt-creator/qt-creator
Add project tab to navigator
This makes navigation the project a lot easier and the layout of the side bars can be locked. Change-Id: I3ad7b85cb8704aedf8f5ec9ea9b2930c5a0986d1 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -25,19 +25,23 @@
|
|||||||
|
|
||||||
#include "navigatorwidget.h"
|
#include "navigatorwidget.h"
|
||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
#include "qmldesignerconstants.h"
|
|
||||||
#include "qmldesignericons.h"
|
|
||||||
#include <designersettings.h>
|
#include <designersettings.h>
|
||||||
|
#include <qmldesignerconstants.h>
|
||||||
|
#include <qmldesignericons.h>
|
||||||
|
#include <qmldesignerplugin.h>
|
||||||
#include <theme.h>
|
#include <theme.h>
|
||||||
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QMenu>
|
#include <QBoxLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QtDebug>
|
#include <QMenu>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -54,18 +58,43 @@ NavigatorWidget::NavigatorWidget(NavigatorView *view) :
|
|||||||
m_treeView->setDefaultDropAction(Qt::LinkAction);
|
m_treeView->setDefaultDropAction(Qt::LinkAction);
|
||||||
m_treeView->setHeaderHidden(true);
|
m_treeView->setHeaderHidden(true);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
auto layout = new QVBoxLayout;
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
layout->addWidget(m_treeView);
|
|
||||||
|
|
||||||
|
auto tabBar = new QTabBar(this);
|
||||||
|
tabBar->addTab(tr("Navigator"));
|
||||||
|
tabBar->addTab(tr("Project"));
|
||||||
|
tabBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
QWidget *spacer = new QWidget(this);
|
||||||
|
spacer->setObjectName(QStringLiteral("itemLibrarySearchInputSpacer"));
|
||||||
|
spacer->setFixedHeight(4);
|
||||||
|
|
||||||
|
layout->addWidget(tabBar);
|
||||||
|
layout->addWidget(spacer);
|
||||||
|
|
||||||
|
auto stackedWidget = new QStackedWidget(this);
|
||||||
|
stackedWidget->addWidget(m_treeView);
|
||||||
|
|
||||||
|
#ifndef QMLDESIGNER_TEST
|
||||||
|
auto projectManager = QmlDesignerPlugin::instance()->createProjectExplorerWidget(this);
|
||||||
|
|
||||||
|
QTC_ASSERT(projectManager, ;);
|
||||||
|
if (projectManager)
|
||||||
|
stackedWidget->addWidget(projectManager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
connect(tabBar, &QTabBar::currentChanged, stackedWidget, &QStackedWidget::setCurrentIndex);
|
||||||
|
|
||||||
|
layout->addWidget(stackedWidget);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
setWindowTitle(tr("Navigator", "Title of navigator view"));
|
setWindowTitle(tr("Navigator", "Title of navigator view"));
|
||||||
|
|
||||||
#ifndef QMLDESIGNER_TEST
|
#ifndef QMLDESIGNER_TEST
|
||||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/stylesheet.css")))));
|
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||||
m_treeView->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css")))));
|
m_treeView->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css"))));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,6 +72,12 @@ const char SB_PROJECTS[] = "Projects";
|
|||||||
const char SB_FILESYSTEM[] = "FileSystem";
|
const char SB_FILESYSTEM[] = "FileSystem";
|
||||||
const char SB_OPENDOCUMENTS[] = "OpenDocuments";
|
const char SB_OPENDOCUMENTS[] = "OpenDocuments";
|
||||||
|
|
||||||
|
static void hideToolButtons(QList<QToolButton*> &buttons)
|
||||||
|
{
|
||||||
|
foreach (QToolButton *button, buttons)
|
||||||
|
button->hide();
|
||||||
|
}
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -169,6 +175,32 @@ void DesignModeWidget::toggleRightSidebar()
|
|||||||
m_rightSideBar->setVisible(!m_rightSideBar->isVisible());
|
m_rightSideBar->setVisible(!m_rightSideBar->isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *DesignModeWidget::createProjectExplorerWidget(QWidget *parent)
|
||||||
|
{
|
||||||
|
QList<Core::INavigationWidgetFactory *> factories =
|
||||||
|
ExtensionSystem::PluginManager::getObjects<Core::INavigationWidgetFactory>();
|
||||||
|
|
||||||
|
Core::NavigationView navigationView;
|
||||||
|
navigationView.widget = nullptr;
|
||||||
|
|
||||||
|
foreach (Core::INavigationWidgetFactory *factory, factories) {
|
||||||
|
if (factory->id() == "Projects") {
|
||||||
|
navigationView = factory->createWidget();
|
||||||
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navigationView.widget) {
|
||||||
|
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||||
|
sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
|
||||||
|
sheet += "QLabel { background-color: #4f4f4f; }";
|
||||||
|
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||||
|
navigationView.widget->setParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return navigationView.widget;
|
||||||
|
}
|
||||||
|
|
||||||
void DesignModeWidget::readSettings()
|
void DesignModeWidget::readSettings()
|
||||||
{
|
{
|
||||||
QSettings *settings = Core::ICore::settings();
|
QSettings *settings = Core::ICore::settings();
|
||||||
@@ -221,12 +253,6 @@ void DesignModeWidget::switchTextOrForm()
|
|||||||
m_centralTabWidget->switchTo(viewManager().widget("TextEditor"));
|
m_centralTabWidget->switchTo(viewManager().widget("TextEditor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hideToolButtons(QList<QToolButton*> &buttons)
|
|
||||||
{
|
|
||||||
foreach (QToolButton *button, buttons)
|
|
||||||
button->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DesignModeWidget::setup()
|
void DesignModeWidget::setup()
|
||||||
{
|
{
|
||||||
auto &actionManager = viewManager().designerActionManager();
|
auto &actionManager = viewManager().designerActionManager();
|
||||||
|
@@ -85,6 +85,8 @@ public:
|
|||||||
void toggleLeftSidebar();
|
void toggleLeftSidebar();
|
||||||
void toggleRightSidebar();
|
void toggleRightSidebar();
|
||||||
|
|
||||||
|
static QWidget *createProjectExplorerWidget(QWidget *parent);
|
||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
enum InitializeStatus { NotInitialized, Initializing, Initialized };
|
enum InitializeStatus { NotInitialized, Initializing, Initialized };
|
||||||
|
|
||||||
|
@@ -455,6 +455,11 @@ Internal::DesignModeWidget *QmlDesignerPlugin::mainWidget() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *QmlDesignerPlugin::createProjectExplorerWidget(QWidget *parent) const
|
||||||
|
{
|
||||||
|
return Internal::DesignModeWidget::createProjectExplorerWidget(parent);
|
||||||
|
}
|
||||||
|
|
||||||
void QmlDesignerPlugin::switchToTextModeDeferred()
|
void QmlDesignerPlugin::switchToTextModeDeferred()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(0, this, [] () {
|
QTimer::singleShot(0, this, [] () {
|
||||||
|
@@ -82,6 +82,8 @@ public:
|
|||||||
DesignDocument *currentDesignDocument() const;
|
DesignDocument *currentDesignDocument() const;
|
||||||
Internal::DesignModeWidget *mainWidget() const;
|
Internal::DesignModeWidget *mainWidget() const;
|
||||||
|
|
||||||
|
QWidget *createProjectExplorerWidget(QWidget *parent) const;
|
||||||
|
|
||||||
void switchToTextModeDeferred();
|
void switchToTextModeDeferred();
|
||||||
void emitCurrentTextEditorChanged(Core::IEditor *editor);
|
void emitCurrentTextEditorChanged(Core::IEditor *editor);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user