Commit fd549343 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

unified left & right sidebars in bauhaus

SideBar was patched to give it extra functionality:
 - closeWhenEmpty: when all sidebar widgets are closed, the whole
   sidebar will disappear, too.
 - unavailableItems: a list of non-openable windowTitles can be given
   to the sidebar.

Reviewed-by: con
parent 6cbf5205
......@@ -50,7 +50,8 @@ SideBarItem::~SideBarItem()
}
SideBar::SideBar(QList<SideBarItem*> itemList,
QList<SideBarItem*> defaultVisible)
QList<SideBarItem*> defaultVisible) :
m_closeWhenEmpty(false)
{
setOrientation(Qt::Vertical);
foreach (SideBarItem *item, itemList) {
......@@ -76,23 +77,64 @@ QStringList SideBar::availableItems() const
return m_availableItems;
}
QStringList SideBar::unavailableItems() const
{
return m_unavailableItems;
}
bool SideBar::closeWhenEmpty() const
{
return m_closeWhenEmpty;
}
void SideBar::setCloseWhenEmpty(bool value)
{
m_closeWhenEmpty = value;
}
void SideBar::makeItemAvailable(SideBarItem *item)
{
QMap<QString, SideBarItem*>::const_iterator it = m_itemMap.constBegin();
while (it != m_itemMap.constEnd()) {
if (it.value() == item) {
m_availableItems.append(it.key());
m_unavailableItems.removeAll(it.key());
qSort(m_availableItems);
emit availableItemsChanged();
//updateWidgets();
break;
}
++it;
}
}
// sets a list of externally used, unavailable items. For example,
// another sidebar could set
void SideBar::setUnavailableItems(const QStringList &itemTitles)
{
// re-enable previous items
foreach(const QString &title, m_unavailableItems)
m_availableItems.append(title);
m_unavailableItems.clear();
foreach (const QString &title, itemTitles) {
if (!m_unavailableItems.contains(title))
m_unavailableItems.append(title);
m_availableItems.removeAll(title);
}
qSort(m_availableItems);
updateWidgets();
}
SideBarItem *SideBar::item(const QString &title)
{
if (m_itemMap.contains(title)) {
m_availableItems.removeAll(title);
if (!m_unavailableItems.contains(title))
m_unavailableItems.append(title);
emit availableItemsChanged();
return m_itemMap.value(title);
}
return 0;
......@@ -134,6 +176,9 @@ void SideBar::closeSubWidget()
return;
removeSideBarWidget(widget);
updateWidgets();
} else {
if (m_closeWhenEmpty)
setVisible(false);
}
}
......@@ -227,8 +272,6 @@ QMap<QString, Core::Command*> SideBar::shortcutMap() const
return m_shortcutMap;
}
SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &title)
: m_currentItem(0)
, m_sideBar(sideBar)
......@@ -302,6 +345,7 @@ void SideBarWidget::setCurrentItem(const QString &title)
return;
removeCurrentItem();
m_currentItem = item;
layout()->addWidget(m_currentItem->widget());
// Add buttons and remember their actions for later removal
......@@ -359,8 +403,6 @@ Core::Command *SideBarWidget::command(const QString &title) const
return 0;
}
ComboBox::ComboBox(SideBarWidget *sideBarWidget)
: m_sideBarWidget(sideBarWidget)
{
......
......@@ -98,9 +98,15 @@ public:
~SideBar();
QStringList availableItems() const;
QStringList unavailableItems() const;
void makeItemAvailable(SideBarItem *item);
void setUnavailableItems(const QStringList &itemTitles);
SideBarItem *item(const QString &title);
bool closeWhenEmpty() const;
void setCloseWhenEmpty(bool value);
void saveSettings(QSettings *settings, const QString &name);
void readSettings(QSettings *settings, const QString &name);
......@@ -109,6 +115,9 @@ public:
void setShortcutMap(const QMap<QString, Core::Command*> &shortcutMap);
QMap<QString, Core::Command*> shortcutMap() const;
signals:
void availableItemsChanged();
private slots:
void splitSubWidget();
void closeSubWidget();
......@@ -120,11 +129,12 @@ private:
void removeSideBarWidget(Internal::SideBarWidget *widget);
QList<Internal::SideBarWidget*> m_widgets;
QMap<QString, SideBarItem*> m_itemMap;
QStringList m_availableItems;
QStringList m_unavailableItems;
QStringList m_defaultVisible;
QMap<QString, Core::Command*> m_shortcutMap;
bool m_closeWhenEmpty;
};
namespace Internal {
......
......@@ -578,11 +578,8 @@ void DesignModeWidget::setup()
m_formEditorView = new FormEditorView(this);
//m_designToolBar = new QToolBar;
m_fakeToolBar = Core::EditorManager::createToolBar(this);
m_mainSplitter = new MiniSplitter(this);
m_mainSplitter->setObjectName("mainSplitter");
......@@ -590,34 +587,35 @@ void DesignModeWidget::setup()
m_warningWidget = new DocumentWarningWidget(this);
m_warningWidget->setVisible(false);
// Left area:
Core::SideBarItem *navigatorItem = new Core::SideBarItem(m_navigator->widget());
Core::SideBarItem *libraryItem = new Core::SideBarItem(m_itemLibrary.data());
Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_allPropertiesBox.data());
QList<Core::SideBarItem*> sideBarItems;
QList<Core::SideBarItem*> leftSideBarItems, rightSideBarItems;
leftSideBarItems << navigatorItem << libraryItem;
rightSideBarItems << propertiesItem;
// default items
sideBarItems << navigatorItem << libraryItem << propertiesItem;
if (projectsExplorer) {
Core::SideBarItem *projectExplorerItem = new Core::SideBarItem(projectsExplorer);
rightSideBarItems << projectExplorerItem;
sideBarItems << projectExplorerItem;
}
if (fileSystemExplorer) {
Core::SideBarItem *fileSystemExplorerItem = new Core::SideBarItem(fileSystemExplorer);
rightSideBarItems << fileSystemExplorerItem;
sideBarItems << fileSystemExplorerItem;
}
if (openDocumentsWidget) {
if (openDocumentsWidget) {
Core::SideBarItem *openDocumentsItem = new Core::SideBarItem(openDocumentsWidget);
rightSideBarItems << openDocumentsItem;
sideBarItems << openDocumentsItem;
}
m_leftSideBar = new Core::SideBar(leftSideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
m_rightSideBar = new Core::SideBar(rightSideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
m_leftSideBar = new Core::SideBar(sideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
m_rightSideBar = new Core::SideBar(sideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
connect(m_leftSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
connect(m_rightSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsLeft()));
m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
//m_fakeToolBar->addEditor(textEditor()); ### what does this mean?
......@@ -664,6 +662,8 @@ void DesignModeWidget::setup()
m_statesEditorWidget->setEnabled(true);
m_leftSideBar->setEnabled(true);
m_rightSideBar->setEnabled(true);
m_leftSideBar->setCloseWhenEmpty(true);
m_rightSideBar->setCloseWhenEmpty(true);
readSettings();
......@@ -671,6 +671,18 @@ void DesignModeWidget::setup()
QApplication::processEvents();
}
void DesignModeWidget::updateAvailableSidebarItemsRight()
{
// event comes from m_leftSidebar, so update right side.
m_rightSideBar->setUnavailableItems(m_leftSideBar->unavailableItems());
}
void DesignModeWidget::updateAvailableSidebarItemsLeft()
{
// event comes from m_rightSidebar, so update left side.
m_leftSideBar->setUnavailableItems(m_rightSideBar->unavailableItems());
}
void DesignModeWidget::resizeEvent(QResizeEvent *event)
{
if (m_warningWidget)
......
......@@ -138,6 +138,8 @@ private slots:
void enable();
void disable(const QList<RewriterView::Error> &errors);
void updateErrorStatus(const QList<RewriterView::Error> &errors);
void updateAvailableSidebarItemsLeft();
void updateAvailableSidebarItemsRight();
protected:
void resizeEvent(QResizeEvent *event);
......
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