Commit 297b444d authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Add add/remove splitter buttons to the editor view



Task-number: QTCREATORBUG-232

Change-Id: I71b517e09455bfdbe1b835515161e818a4f618f0
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 51511a3c
......@@ -606,6 +606,11 @@ Core::Internal::SplitterOrView *EditorManager::currentSplitterOrView() const
return view;
}
Core::Internal::SplitterOrView *EditorManager::topSplitterOrView() const
{
return d->m_splitter;
}
Core::Internal::EditorView *EditorManager::currentEditorView() const
{
return currentSplitterOrView()->view();
......@@ -1758,6 +1763,8 @@ void EditorManager::updateActions()
#endif
}
setCloseSplitEnabled(d->m_splitter, d->m_splitter->isSplitter());
d->m_saveAction->setEnabled(curEditor != 0 && curEditor->file()->isModified());
d->m_saveAsAction->setEnabled(curEditor != 0 && curEditor->file()->isSaveAsAllowed());
d->m_revertToSavedAction->setEnabled(curEditor != 0
......@@ -1789,6 +1796,19 @@ void EditorManager::updateActions()
d->m_gotoOtherSplitAction->setEnabled(hasSplitter);
}
void EditorManager::setCloseSplitEnabled(SplitterOrView *splitterOrView, bool enable)
{
if (splitterOrView->isView())
splitterOrView->view()->setCloseSplitEnabled(enable);
QSplitter *splitter = splitterOrView->splitter();
if (splitter) {
for (int i = 0; i < splitter->count(); ++i) {
if (SplitterOrView *subSplitterOrView = qobject_cast<SplitterOrView*>(splitter->widget(i)))
setCloseSplitEnabled(subSplitterOrView, enable);
}
}
}
bool EditorManager::hasSplitter() const
{
return d->m_splitter->isSplitter();
......
......@@ -254,6 +254,7 @@ private:
IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
Internal::SplitterOrView *currentSplitterOrView() const;
Internal::SplitterOrView *topSplitterOrView() const;
void closeEditor(IEditor *editor);
void closeDuplicate(IEditor *editor);
......@@ -264,6 +265,7 @@ private:
void addFileToRecentFiles(IFile *file);
void switchToPreferedMode();
void updateAutoSave();
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
EditorManagerPrivate *d;
......
......@@ -93,6 +93,9 @@ EditorView::EditorView(QWidget *parent) :
connect(m_toolBar, SIGNAL(goForwardClicked()), this, SLOT(goForwardInNavigationHistory()));
connect(m_toolBar, SIGNAL(closeClicked()), this, SLOT(closeView()));
connect(m_toolBar, SIGNAL(listSelectionActivated(int)), this, SLOT(listSelectionActivated(int)));
connect(m_toolBar, SIGNAL(horizontalSplitClicked()), this, SLOT(splitHorizontally()));
connect(m_toolBar, SIGNAL(verticalSplitClicked()), this, SLOT(splitVertically()));
connect(m_toolBar, SIGNAL(closeSplitClicked()), this, SLOT(closeSplit()));
tl->addWidget(m_toolBar);
}
......@@ -167,6 +170,11 @@ void EditorView::hideEditorStatusBar(const QString &id)
}
}
void EditorView::setCloseSplitEnabled(bool enable)
{
m_toolBar->setCloseSplitEnabled(enable);
}
void EditorView::addEditor(IEditor *editor)
{
if (m_editors.contains(editor))
......@@ -220,6 +228,31 @@ void EditorView::listSelectionActivated(int index)
EditorManager::instance()->activateEditorForIndex(this, model->index(index, 0), Core::EditorManager::ModeSwitch);
}
void EditorView::splitHorizontally()
{
EditorManager *editorManager = EditorManager::instance();
SplitterOrView *splitterOrView = editorManager->topSplitterOrView()->findView(this);
if (splitterOrView)
splitterOrView->split(Qt::Vertical);
editorManager->updateActions();
}
void EditorView::splitVertically()
{
EditorManager *editorManager = EditorManager::instance();
SplitterOrView *splitterOrView = editorManager->topSplitterOrView()->findView(this);
if (splitterOrView)
splitterOrView->split(Qt::Horizontal);
editorManager->updateActions();
}
void EditorView::closeSplit()
{
EditorManager *editorManager = EditorManager::instance();
editorManager->closeView(this);
editorManager->updateActions();
}
void EditorView::setCurrentEditor(IEditor *editor)
{
if (!editor || m_container->count() <= 0
......
......@@ -93,10 +93,14 @@ public:
const QString &buttonText,
QObject *object, const char *member);
void hideEditorStatusBar(const QString &id);
void setCloseSplitEnabled(bool enable);
private slots:
void closeView();
void listSelectionActivated(int index);
void splitHorizontally();
void splitVertically();
void closeSplit();
private:
void updateNavigatorActions();
......
......@@ -77,12 +77,16 @@ struct EditorToolBarPrivate {
Core::OpenEditorsModel *m_editorsListModel;
QComboBox *m_editorList;
QToolButton *m_closeButton;
QToolButton *m_closeEditorButton;
QToolButton *m_lockButton;
QAction *m_goBackAction;
QAction *m_goForwardAction;
QToolButton *m_backButton;
QToolButton *m_forwardButton;
QToolButton *m_splitButton;
QAction *m_horizontalSplitAction;
QAction *m_verticalSplitAction;
QToolButton *m_closeSplitButton;
QWidget *m_activeToolBar;
QWidget *m_toolBarPlaceholder;
......@@ -93,10 +97,14 @@ struct EditorToolBarPrivate {
EditorToolBarPrivate::EditorToolBarPrivate(QWidget *parent, EditorToolBar *q) :
m_editorList(new QComboBox(q)),
m_closeButton(new QToolButton),
m_closeEditorButton(new QToolButton),
m_lockButton(new QToolButton),
m_goBackAction(new QAction(QIcon(QLatin1String(Constants::ICON_PREV)), EditorManager::tr("Go Back"), parent)),
m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), parent)),
m_splitButton(new QToolButton),
m_horizontalSplitAction(new QAction(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)), EditorManager::tr("Split"), parent)),
m_verticalSplitAction(new QAction(EditorManager::tr("Split Side by Side"), parent)),
m_closeSplitButton(new QToolButton),
m_activeToolBar(0),
m_toolBarPlaceholder(new QWidget),
m_defaultToolBar(new QWidget(q)),
......@@ -129,15 +137,16 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_editorList->setModel(d->m_editorsListModel);
d->m_editorList->setMaxVisibleItems(40);
d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
d->m_editorList->setProperty("hideborder", true);
d->m_lockButton->setAutoRaise(true);
d->m_lockButton->setProperty("type", QLatin1String("dockbutton"));
d->m_lockButton->setProperty("showborder", true);
d->m_lockButton->setVisible(false);
d->m_closeButton->setAutoRaise(true);
d->m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
d->m_closeButton->setProperty("type", QLatin1String("dockbutton"));
d->m_closeButton->setEnabled(false);
d->m_closeEditorButton->setAutoRaise(true);
d->m_closeEditorButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
d->m_closeEditorButton->setToolTip(tr("Close Document"));
d->m_closeEditorButton->setEnabled(false);
d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
......@@ -147,15 +156,34 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_forwardButton= new QToolButton(this);
d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
#ifdef Q_WS_MAC
d->m_horizontalSplitAction->setIconVisibleInMenu(false);
d->m_verticalSplitAction->setIconVisibleInMenu(false);
#endif
d->m_splitButton->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
d->m_splitButton->setToolTip(tr("Split"));
d->m_splitButton->setPopupMode(QToolButton::InstantPopup);
QMenu *splitMenu = new QMenu(d->m_splitButton);
splitMenu->addAction(d->m_horizontalSplitAction);
splitMenu->addAction(d->m_verticalSplitAction);
d->m_splitButton->setMenu(splitMenu);
d->m_closeSplitButton->setAutoRaise(true);
d->m_closeSplitButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
d->m_closeSplitButton->setToolTip(tr("Remove Split"));
QHBoxLayout *toplayout = new QHBoxLayout(this);
toplayout->setSpacing(0);
toplayout->setMargin(0);
toplayout->addWidget(d->m_backButton);
toplayout->addWidget(d->m_forwardButton);
toplayout->addWidget(d->m_editorList);
toplayout->addWidget(d->m_toolBarPlaceholder, 1); // Custom toolbar stretches
toplayout->addWidget(d->m_closeEditorButton);
toplayout->addWidget(d->m_lockButton);
toplayout->addWidget(d->m_closeButton);
toplayout->addWidget(d->m_toolBarPlaceholder, 1); // Custom toolbar stretches
toplayout->addWidget(d->m_splitButton);
toplayout->addWidget(d->m_closeSplitButton);
setLayout(toplayout);
......@@ -165,7 +193,14 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
connect(d->m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
connect(d->m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
connect(d->m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
connect(d->m_closeEditorButton, SIGNAL(clicked()), this, SLOT(closeEditor()), Qt::QueuedConnection);
connect(d->m_horizontalSplitAction, SIGNAL(triggered()),
this, SIGNAL(horizontalSplitClicked()), Qt::QueuedConnection);
connect(d->m_verticalSplitAction, SIGNAL(triggered()),
this, SIGNAL(verticalSplitClicked()), Qt::QueuedConnection);
connect(d->m_closeSplitButton, SIGNAL(clicked()),
this, SIGNAL(closeSplitClicked()), Qt::QueuedConnection);
ActionManager *am = ICore::instance()->actionManager();
connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
......@@ -199,7 +234,12 @@ void EditorToolBar::removeToolbarForEditor(IEditor *editor)
}
}
void EditorToolBar::closeView()
void EditorToolBar::setCloseSplitEnabled(bool enable)
{
d->m_closeSplitButton->setVisible(enable);
}
void EditorToolBar::closeEditor()
{
if (!currentEditor())
return;
......@@ -254,6 +294,8 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
disconnect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(d->m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int)));
d->m_splitButton->setVisible(false);
d->m_closeSplitButton->setVisible(false);
}
}
......@@ -320,7 +362,7 @@ void EditorToolBar::setCanGoForward(bool canGoForward)
void EditorToolBar::updateActionShortcuts()
{
ActionManager *am = ICore::instance()->actionManager();
d->m_closeButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close")));
d->m_closeEditorButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close")));
d->m_goBackAction->setToolTip(am->command(Constants::GO_BACK)->action()->toolTip());
d->m_goForwardAction->setToolTip(am->command(Constants::GO_FORWARD)->action()->toolTip());
}
......@@ -342,7 +384,7 @@ void EditorToolBar::checkEditorStatus()
void EditorToolBar::updateEditorStatus(IEditor *editor)
{
d->m_lockButton->setVisible(editor != 0);
d->m_closeButton->setEnabled(editor != 0);
d->m_closeEditorButton->setEnabled(editor != 0);
if (!editor || !editor->file()) {
d->m_editorList->setToolTip(QString());
......
......@@ -78,6 +78,7 @@ public:
void setCanGoBack(bool canGoBack);
void setCanGoForward(bool canGoForward);
void removeToolbarForEditor(IEditor *editor);
void setCloseSplitEnabled(bool enable);
public slots:
void updateEditorStatus(IEditor *editor);
......@@ -86,6 +87,9 @@ signals:
void closeClicked();
void goBackClicked();
void goForwardClicked();
void horizontalSplitClicked();
void verticalSplitClicked();
void closeSplitClicked();
void listSelectionActivated(int row);
private slots:
......@@ -95,7 +99,7 @@ private slots:
void makeEditorWritable();
void checkEditorStatus();
void closeView();
void closeEditor();
void updateActionShortcuts();
private:
......
......@@ -843,6 +843,12 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
switch (control) {
case CC_ToolButton:
if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
bool reverse = option->direction == Qt::RightToLeft;
bool drawborder = (widget && widget->property("showborder").toBool());
if (drawborder)
drawButtonSeparator(painter, rect, reverse);
QRect button, menuarea;
button = subControlRect(control, toolbutton, SC_ToolButton, widget);
menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
......@@ -918,25 +924,9 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
bool drawborder = !(widget && widget->property("hideborder").toBool());
bool alignarrow = !(widget && widget->property("alignarrow").toBool());
// Draw tool button
if (drawborder) {
QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
grad.setColorAt(0, QColor(255, 255, 255, 20));
grad.setColorAt(0.4, QColor(255, 255, 255, 60));
grad.setColorAt(0.7, QColor(255, 255, 255, 50));
grad.setColorAt(1, QColor(255, 255, 255, 40));
painter->setPen(QPen(grad, 0));
painter->drawLine(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(0, 0, 0, 30));
grad.setColorAt(0.4, QColor(0, 0, 0, 70));
grad.setColorAt(0.7, QColor(0, 0, 0, 70));
grad.setColorAt(1, QColor(0, 0, 0, 40));
painter->setPen(QPen(grad, 0));
if (!reverse)
painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
else
painter->drawLine(rect.topLeft(), rect.bottomLeft());
}
if (drawborder)
drawButtonSeparator(painter, rect, reverse);
QStyleOption toolbutton = *option;
if (isEmpty)
toolbutton.state &= ~(State_Enabled | State_Sunken);
......@@ -985,3 +975,23 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
break;
}
}
void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const
{
QLinearGradient grad(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(255, 255, 255, 20));
grad.setColorAt(0.4, QColor(255, 255, 255, 60));
grad.setColorAt(0.7, QColor(255, 255, 255, 50));
grad.setColorAt(1, QColor(255, 255, 255, 40));
painter->setPen(QPen(grad, 0));
painter->drawLine(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(0, 0, 0, 30));
grad.setColorAt(0.4, QColor(0, 0, 0, 70));
grad.setColorAt(0.7, QColor(0, 0, 0, 70));
grad.setColorAt(1, QColor(0, 0, 0, 40));
painter->setPen(QPen(grad, 0));
if (!reverse)
painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
else
painter->drawLine(rect.topLeft(), rect.bottomLeft());
}
......@@ -77,6 +77,8 @@ protected slots:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const;
private:
void drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const;
ManhattanStylePrivate *d;
};
......
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