Header cleanup in coreplugin, part 1

This commit is contained in:
Friedemann Kleint
2010-09-16 12:26:28 +02:00
parent b8cc8e210c
commit d6057ae600
22 changed files with 2007 additions and 1597 deletions

View File

@@ -104,7 +104,10 @@ SOURCES += mainwindow.cpp \
ssh/sftpoperation.cpp \
ssh/sftpincomingpacket.cpp \
ssh/sftpdefs.cpp \
ssh/sftpchannel.cpp
ssh/sftpchannel.cpp \
outputpanemanager.cpp \
navigationsubwidget.cpp \
sidebarwidget.cpp
HEADERS += mainwindow.h \
editmode.h \
@@ -212,7 +215,10 @@ HEADERS += mainwindow.h \
ssh/sftpincomingpacket_p.h \
ssh/sftpdefs.h \
ssh/sftpchannel.h \
ssh/sftpchannel_p.h
ssh/sftpchannel_p.h \
outputpanemanager.h \
navigationsubwidget.h \
sidebarwidget.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \

View File

@@ -43,6 +43,7 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QWidget>
#include <QtGui/QSplitter>
#include <QtGui/QIcon>
using namespace Core;
using namespace Core::Internal;

View File

@@ -50,7 +50,9 @@
#include <QtCore/QSettings>
#include <QtCore/QEvent>
#include <QtCore/QDir>
#include <QtCore/QPointer>
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QScrollArea>
@@ -69,79 +71,100 @@ enum {
namespace Core {
struct EditorToolBarPrivate {
explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q);
Core::OpenEditorsModel *m_editorsListModel;
QComboBox *m_editorList;
QToolButton *m_closeButton;
QToolButton *m_lockButton;
QAction *m_goBackAction;
QAction *m_goForwardAction;
QToolButton *m_backButton;
QToolButton *m_forwardButton;
QWidget *m_activeToolBar;
QWidget *m_toolBarPlaceholder;
QWidget *m_defaultToolBar;
bool m_isStandalone;
};
EditorToolBarPrivate::EditorToolBarPrivate(QWidget *parent, EditorToolBar *q) :
m_editorList(new QComboBox(q)),
m_closeButton(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_activeToolBar(0),
m_toolBarPlaceholder(new QWidget),
m_defaultToolBar(new QWidget(q)),
m_isStandalone(false)
{
}
/*!
Mimic the look of the text editor toolbar as defined in e.g. EditorView::EditorView
*/
EditorToolBar::EditorToolBar(QWidget *parent) :
Utils::StyledBar(parent),
m_editorList(new QComboBox(this)),
m_closeButton(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_activeToolBar(0),
m_toolBarPlaceholder(new QWidget),
m_defaultToolBar(new QWidget(this)),
m_isStandalone(false)
Utils::StyledBar(parent), d(new EditorToolBarPrivate(parent, this))
{
QHBoxLayout *toolBarLayout = new QHBoxLayout(this);
toolBarLayout->setMargin(0);
toolBarLayout->setSpacing(0);
toolBarLayout->addWidget(m_defaultToolBar);
m_toolBarPlaceholder->setLayout(toolBarLayout);
m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
toolBarLayout->addWidget(d->m_defaultToolBar);
d->m_toolBarPlaceholder->setLayout(toolBarLayout);
d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_activeToolBar = m_defaultToolBar;
d->m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
d->m_activeToolBar = d->m_defaultToolBar;
m_editorsListModel = EditorManager::instance()->openedEditorsModel();
connect(m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
connect(m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
d->m_editorsListModel = EditorManager::instance()->openedEditorsModel();
connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_editorList->setMinimumContentsLength(20);
m_editorList->setModel(m_editorsListModel);
m_editorList->setMaxVisibleItems(40);
m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
d->m_editorList->setMinimumContentsLength(20);
d->m_editorList->setModel(d->m_editorsListModel);
d->m_editorList->setMaxVisibleItems(40);
d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
m_lockButton->setAutoRaise(true);
m_lockButton->setProperty("type", QLatin1String("dockbutton"));
m_lockButton->setVisible(false);
d->m_lockButton->setAutoRaise(true);
d->m_lockButton->setProperty("type", QLatin1String("dockbutton"));
d->m_lockButton->setVisible(false);
m_closeButton->setAutoRaise(true);
m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
m_closeButton->setProperty("type", QLatin1String("dockbutton"));
m_closeButton->setEnabled(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);
m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_backButton = new QToolButton(this);
m_backButton->setDefaultAction(m_goBackAction);
d->m_backButton = new QToolButton(this);
d->m_backButton->setDefaultAction(d->m_goBackAction);
m_forwardButton= new QToolButton(this);
m_forwardButton->setDefaultAction(m_goForwardAction);
d->m_forwardButton= new QToolButton(this);
d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
QHBoxLayout *toplayout = new QHBoxLayout(this);
toplayout->setSpacing(0);
toplayout->setMargin(0);
toplayout->addWidget(m_backButton);
toplayout->addWidget(m_forwardButton);
toplayout->addWidget(m_editorList);
toplayout->addWidget(m_toolBarPlaceholder, 1); // Custom toolbar stretches
toplayout->addWidget(m_lockButton);
toplayout->addWidget(m_closeButton);
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_lockButton);
toplayout->addWidget(d->m_closeButton);
setLayout(toplayout);
// this signal is disconnected for standalone toolbars and replaced with
// a private slot connection
connect(m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
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);
ActionManager *am = ICore::instance()->actionManager();
connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
@@ -153,6 +176,10 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
}
EditorToolBar::~EditorToolBar()
{
}
void EditorToolBar::removeToolbarForEditor(IEditor *editor)
{
QTC_ASSERT(editor, return)
@@ -160,11 +187,11 @@ void EditorToolBar::removeToolbarForEditor(IEditor *editor)
QWidget *toolBar = editor->toolBar();
if (toolBar != 0) {
if (m_activeToolBar == toolBar) {
m_activeToolBar = m_defaultToolBar;
m_activeToolBar->setVisible(true);
if (d->m_activeToolBar == toolBar) {
d->m_activeToolBar = d->m_defaultToolBar;
d->m_activeToolBar->setVisible(true);
}
m_toolBarPlaceholder->layout()->removeWidget(toolBar);
d->m_toolBarPlaceholder->layout()->removeWidget(toolBar);
toolBar->setVisible(false);
toolBar->setParent(0);
}
@@ -175,7 +202,7 @@ void EditorToolBar::closeView()
if (!currentEditor())
return;
if (m_isStandalone) {
if (d->m_isStandalone) {
EditorManager *em = ICore::instance()->editorManager();
if (IEditor *editor = currentEditor()) {
em->closeEditor(editor);
@@ -190,7 +217,7 @@ void EditorToolBar::addEditor(IEditor *editor)
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
QWidget *toolBar = editor->toolBar();
if (toolBar && !m_isStandalone)
if (toolBar && !d->m_isStandalone)
addCenterToolBar(toolBar);
updateEditorStatus(editor);
@@ -200,7 +227,7 @@ void EditorToolBar::addCenterToolBar(QWidget *toolBar)
{
QTC_ASSERT(toolBar, return)
toolBar->setVisible(false); // will be made visible in setCurrentEditor
m_toolBarPlaceholder->layout()->addWidget(toolBar);
d->m_toolBarPlaceholder->layout()->addWidget(toolBar);
updateToolBar(toolBar);
}
@@ -208,34 +235,34 @@ void EditorToolBar::addCenterToolBar(QWidget *toolBar)
void EditorToolBar::updateToolBar(QWidget *toolBar)
{
if (!toolBar)
toolBar = m_defaultToolBar;
if (m_activeToolBar == toolBar)
toolBar = d->m_defaultToolBar;
if (d->m_activeToolBar == toolBar)
return;
toolBar->setVisible(true);
m_activeToolBar->setVisible(false);
m_activeToolBar = toolBar;
d->m_activeToolBar->setVisible(false);
d->m_activeToolBar = toolBar;
}
void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
{
m_isStandalone = flags & FlagsStandalone;
if (m_isStandalone) {
d->m_isStandalone = flags & FlagsStandalone;
if (d->m_isStandalone) {
EditorManager *em = EditorManager::instance();
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*)));
disconnect(m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int)));
disconnect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(d->m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int)));
}
}
void EditorToolBar::setCurrentEditor(IEditor *editor)
{
QTC_ASSERT(editor, return)
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row());
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
// If we never added the toolbar from the editor, we will never change
// the editor, so there's no need to update the toolbar either.
if (!m_isStandalone)
if (!d->m_isStandalone)
updateToolBar(editor->toolBar());
updateEditorStatus(editor);
@@ -244,13 +271,13 @@ void EditorToolBar::setCurrentEditor(IEditor *editor)
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
{
if (newSelection)
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row());
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(newSelection).row());
}
void EditorToolBar::changeActiveEditor(int row)
{
EditorManager *em = ICore::instance()->editorManager();
QAbstractItemModel *model = m_editorList->model();
QAbstractItemModel *model = d->m_editorList->model();
const QModelIndex modelIndex = model->index(row, 0);
IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>();
@@ -264,19 +291,19 @@ void EditorToolBar::changeActiveEditor(int row)
editor = em->openEditor(fileName, kind);
}
if (editor) {
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row());
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
}
}
void EditorToolBar::listContextMenu(QPoint pos)
{
QModelIndex index = m_editorsListModel->index(m_editorList->currentIndex(), 0);
QString fileName = m_editorsListModel->data(index, Qt::UserRole + 1).toString();
QModelIndex index = d->m_editorsListModel->index(d->m_editorList->currentIndex(), 0);
QString fileName = d->m_editorsListModel->data(index, Qt::UserRole + 1).toString();
if (fileName.isEmpty())
return;
QMenu menu;
menu.addAction(tr("Copy Full Path to Clipboard"));
if (menu.exec(m_editorList->mapToGlobal(pos))) {
if (menu.exec(d->m_editorList->mapToGlobal(pos))) {
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
}
}
@@ -289,20 +316,20 @@ void EditorToolBar::makeEditorWritable()
void EditorToolBar::setCanGoBack(bool canGoBack)
{
m_goBackAction->setEnabled(canGoBack);
d->m_goBackAction->setEnabled(canGoBack);
}
void EditorToolBar::setCanGoForward(bool canGoForward)
{
m_goForwardAction->setEnabled(canGoForward);
d->m_goForwardAction->setEnabled(canGoForward);
}
void EditorToolBar::updateActionShortcuts()
{
ActionManager *am = ICore::instance()->actionManager();
m_closeButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close")));
m_goBackAction->setToolTip(am->command(Constants::GO_BACK)->action()->toolTip());
m_goForwardAction->setToolTip(am->command(Constants::GO_FORWARD)->action()->toolTip());
d->m_closeButton->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());
}
IEditor *EditorToolBar::currentEditor() const
@@ -321,27 +348,27 @@ void EditorToolBar::checkEditorStatus()
void EditorToolBar::updateEditorStatus(IEditor *editor)
{
m_lockButton->setVisible(editor != 0);
m_closeButton->setEnabled(editor != 0);
d->m_lockButton->setVisible(editor != 0);
d->m_closeButton->setEnabled(editor != 0);
if (!editor || !editor->file()) {
m_editorList->setToolTip(QString());
d->m_editorList->setToolTip(QString());
return;
}
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row());
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
if (editor->file()->isReadOnly()) {
m_lockButton->setIcon(QIcon(m_editorsListModel->lockedIcon()));
m_lockButton->setEnabled(!editor->file()->fileName().isEmpty());
m_lockButton->setToolTip(tr("Make writable"));
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon()));
d->m_lockButton->setEnabled(!editor->file()->fileName().isEmpty());
d->m_lockButton->setToolTip(tr("Make writable"));
} else {
m_lockButton->setIcon(QIcon(m_editorsListModel->unlockedIcon()));
m_lockButton->setEnabled(false);
m_lockButton->setToolTip(tr("File is writable"));
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->unlockedIcon()));
d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(tr("File is writable"));
}
if (editor == currentEditor())
m_editorList->setToolTip(
d->m_editorList->setToolTip(
currentEditor()->file()->fileName().isEmpty()
? currentEditor()->displayName()
: QDir::toNativeSeparators(editor->file()->fileName())
@@ -351,10 +378,10 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
void EditorToolBar::setNavigationVisible(bool isVisible)
{
m_goBackAction->setVisible(isVisible);
m_goForwardAction->setVisible(isVisible);
m_backButton->setVisible(isVisible);
m_forwardButton->setVisible(isVisible);
d->m_goBackAction->setVisible(isVisible);
d->m_goForwardAction->setVisible(isVisible);
d->m_backButton->setVisible(isVisible);
d->m_forwardButton->setVisible(isVisible);
}
} // Core

View File

@@ -31,25 +31,15 @@
#define FAKETOOLBAR_H
#include "core_global.h"
#include <QWidget>
#include <QtCore/QPointer>
#include <QtCore/QScopedPointer>
#include <utils/styledbar.h>
QT_BEGIN_NAMESPACE
class QComboBox;
class QToolButton;
class QToolBar;
QT_END_NAMESPACE
namespace Core {
class IEditor;
class OpenEditorsModel;
namespace Internal {
class EditorView;
}
struct EditorToolBarPrivate;
/**
* Fakes an IEditor-like toolbar for design mode widgets such as Qt Designer and Bauhaus.
@@ -61,6 +51,7 @@ class CORE_EXPORT EditorToolBar : public Utils::StyledBar
Q_DISABLE_COPY(EditorToolBar)
public:
explicit EditorToolBar(QWidget *parent = 0);
virtual ~EditorToolBar();
enum ToolbarCreationFlags { FlagsNone = 0, FlagsStandalone = 1 };
@@ -109,23 +100,10 @@ private slots:
private:
void updateToolBar(QWidget *toolBar);
IEditor *currentEditor() const;
Core::OpenEditorsModel *m_editorsListModel;
QComboBox *m_editorList;
QToolButton *m_closeButton;
QToolButton *m_lockButton;
QAction *m_goBackAction;
QAction *m_goForwardAction;
QToolButton *m_backButton;
QToolButton *m_forwardButton;
QWidget *m_activeToolBar;
QWidget *m_toolBarPlaceholder;
QWidget *m_defaultToolBar;
bool m_isStandalone;
QScopedPointer<EditorToolBarPrivate> d;
};
}
} // namespace Core
#endif // FAKETOOLBAR_H

View File

@@ -47,7 +47,22 @@
namespace Core {
HelpManager *HelpManager::m_instance = 0;
struct HelpManagerPrivate {
HelpManagerPrivate() :
m_needsSetup(true), m_helpEngine(0), m_collectionWatcher(0) {}
static HelpManager *m_instance;
bool m_needsSetup;
QHelpEngineCore *m_helpEngine;
QFileSystemWatcher *m_collectionWatcher;
QStringList m_filesToRegister;
QStringList m_nameSpacesToUnregister;
QHash<QString, QVariant> m_customValues;
};
HelpManager *HelpManagerPrivate::m_instance = 0;
static const char linksForKeyQuery[] = "SELECT d.Title, f.Name, e.Name, "
"d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, "
@@ -67,13 +82,11 @@ struct DbCleaner {
// -- HelpManager
HelpManager::HelpManager(QObject *parent)
: QObject(parent)
, m_needsSetup(true)
, m_helpEngine(0)
HelpManager::HelpManager(QObject *parent) :
QObject(parent), d(new HelpManagerPrivate)
{
Q_ASSERT(!m_instance);
m_instance = this;
Q_ASSERT(!HelpManagerPrivate::m_instance);
HelpManagerPrivate::m_instance = this;
connect(Core::ICore::instance(), SIGNAL(coreOpened()), this,
SLOT(setupHelpManager()));
@@ -81,16 +94,16 @@ HelpManager::HelpManager(QObject *parent)
HelpManager::~HelpManager()
{
delete m_helpEngine;
m_helpEngine = 0;
delete d->m_helpEngine;
d->m_helpEngine = 0;
m_instance = 0;
HelpManagerPrivate::m_instance = 0;
}
HelpManager* HelpManager::instance()
{
Q_ASSERT(m_instance);
return m_instance;
Q_ASSERT(HelpManagerPrivate::m_instance);
return HelpManagerPrivate::m_instance;
}
QString HelpManager::collectionFilePath()
@@ -101,33 +114,33 @@ QString HelpManager::collectionFilePath()
void HelpManager::registerDocumentation(const QStringList &files)
{
if (m_needsSetup) {
m_filesToRegister.append(files);
if (d->m_needsSetup) {
d->m_filesToRegister.append(files);
return;
}
bool docsChanged = false;
foreach (const QString &file, files) {
const QString &nameSpace = m_helpEngine->namespaceName(file);
const QString &nameSpace = d->m_helpEngine->namespaceName(file);
if (nameSpace.isEmpty())
continue;
if (!m_helpEngine->registeredDocumentations().contains(nameSpace)) {
if (m_helpEngine->registerDocumentation(file)) {
if (!d->m_helpEngine->registeredDocumentations().contains(nameSpace)) {
if (d->m_helpEngine->registerDocumentation(file)) {
docsChanged = true;
} else {
qWarning() << "Error registering namespace '" << nameSpace
<< "' from file '" << file << "':" << m_helpEngine->error();
<< "' from file '" << file << "':" << d->m_helpEngine->error();
}
} else {
const QLatin1String key("CreationDate");
const QString &newDate = m_helpEngine->metaData(file, key).toString();
const QString &oldDate = m_helpEngine->metaData(
m_helpEngine->documentationFileName(nameSpace), key).toString();
const QString &newDate = d->m_helpEngine->metaData(file, key).toString();
const QString &oldDate = d->m_helpEngine->metaData(
d->m_helpEngine->documentationFileName(nameSpace), key).toString();
if (QDateTime::fromString(newDate, Qt::ISODate)
> QDateTime::fromString(oldDate, Qt::ISODate)) {
if (m_helpEngine->unregisterDocumentation(nameSpace)) {
if (d->m_helpEngine->unregisterDocumentation(nameSpace)) {
docsChanged = true;
m_helpEngine->registerDocumentation(file);
d->m_helpEngine->registerDocumentation(file);
}
}
}
@@ -138,19 +151,19 @@ void HelpManager::registerDocumentation(const QStringList &files)
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
{
if (m_needsSetup) {
m_nameSpacesToUnregister.append(nameSpaces);
if (d->m_needsSetup) {
d->m_nameSpacesToUnregister.append(nameSpaces);
return;
}
bool docsChanged = false;
foreach (const QString &nameSpace, nameSpaces) {
if (m_helpEngine->unregisterDocumentation(nameSpace)) {
if (d->m_helpEngine->unregisterDocumentation(nameSpace)) {
docsChanged = true;
} else {
qWarning() << "Error unregistering namespace '" << nameSpace
<< "' from file '" << m_helpEngine->documentationFileName(nameSpace)
<< "': " << m_helpEngine->error();
<< "' from file '" << d->m_helpEngine->documentationFileName(nameSpace)
<< "': " << d->m_helpEngine->error();
}
}
if (docsChanged)
@@ -172,7 +185,7 @@ QUrl buildQUrl(const QString &nameSpace, const QString &folder,
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
{
QMap<QString, QUrl> links;
if (m_needsSetup)
if (d->m_needsSetup)
return links;
const QLatin1String sqlite("QSQLITE");
@@ -181,9 +194,9 @@ QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
DbCleaner cleaner(name);
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
const QStringList &registeredDocs = m_helpEngine->registeredDocumentations();
const QStringList &registeredDocs = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
db.setDatabaseName(m_helpEngine->documentationFileName(nameSpace));
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
if (db.open()) {
QSqlQuery query = QSqlQuery(db);
query.setForwardOnly(true);
@@ -204,16 +217,16 @@ QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QMap<QString, QUrl>();
return m_helpEngine->linksForIdentifier(id);
return d->m_helpEngine->linksForIdentifier(id);
}
// This should go into Qt 4.8 once we start using it for Qt Creator
QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
{
QStringList keywords;
if (m_needsSetup)
if (d->m_needsSetup)
return keywords;
const QLatin1String sqlite("QSQLITE");
@@ -222,9 +235,9 @@ QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
DbCleaner cleaner(name);
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
const QStringList &registeredDocs = m_helpEngine->registeredDocumentations();
const QStringList &registeredDocs = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
db.setDatabaseName(m_helpEngine->documentationFileName(nameSpace));
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
if (db.open()) {
QSqlQuery query = QSqlQuery(db);
query.setForwardOnly(true);
@@ -246,16 +259,16 @@ QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
QUrl HelpManager::findFile(const QUrl &url) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QUrl();
return m_helpEngine->findFile(url);
return d->m_helpEngine->findFile(url);
}
QByteArray HelpManager::fileData(const QUrl &url) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QByteArray();
return m_helpEngine->fileData(url);
return d->m_helpEngine->fileData(url);
}
void HelpManager::handleHelpRequest(const QString &url)
@@ -265,58 +278,58 @@ void HelpManager::handleHelpRequest(const QString &url)
QStringList HelpManager::registeredNamespaces() const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QStringList();
return m_helpEngine->registeredDocumentations();
return d->m_helpEngine->registeredDocumentations();
}
QString HelpManager::namespaceFromFile(const QString &file) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QString();
return m_helpEngine->namespaceName(file);
return d->m_helpEngine->namespaceName(file);
}
QString HelpManager::fileFromNamespace(const QString &nameSpace) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QString();
return m_helpEngine->documentationFileName(nameSpace);
return d->m_helpEngine->documentationFileName(nameSpace);
}
void HelpManager::setCustomValue(const QString &key, const QVariant &value)
{
if (m_needsSetup) {
m_customValues.insert(key, value);
if (d->m_needsSetup) {
d->m_customValues.insert(key, value);
return;
}
if (m_helpEngine->setCustomValue(key, value))
if (d->m_helpEngine->setCustomValue(key, value))
emit collectionFileChanged();
}
QVariant HelpManager::customValue(const QString &key, const QVariant &value) const
{
if (m_needsSetup)
if (d->m_needsSetup)
return QVariant();
return m_helpEngine->customValue(key, value);
return d->m_helpEngine->customValue(key, value);
}
HelpManager::Filters HelpManager::filters() const
{
if (m_needsSetup)
if (d->m_needsSetup)
return Filters();
Filters filters;
const QStringList &customFilters = m_helpEngine->customFilters();
const QStringList &customFilters = d->m_helpEngine->customFilters();
foreach (const QString &filter, customFilters)
filters.insert(filter, m_helpEngine->filterAttributes(filter));
filters.insert(filter, d->m_helpEngine->filterAttributes(filter));
return filters;
}
HelpManager::Filters HelpManager::fixedFilters() const
{
Filters fixedFilters;
if (m_needsSetup)
if (d->m_needsSetup)
return fixedFilters;
const QLatin1String sqlite("QSQLITE");
@@ -325,16 +338,16 @@ HelpManager::Filters HelpManager::fixedFilters() const
DbCleaner cleaner(name);
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
const QStringList &registeredDocs = m_helpEngine->registeredDocumentations();
const QStringList &registeredDocs = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
db.setDatabaseName(m_helpEngine->documentationFileName(nameSpace));
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
if (db.open()) {
QSqlQuery query = QSqlQuery(db);
query.setForwardOnly(true);
query.exec(QLatin1String("SELECT Name FROM FilterNameTable"));
while (query.next()) {
const QString &filter = query.value(0).toString();
fixedFilters.insert(filter, m_helpEngine->filterAttributes(filter));
fixedFilters.insert(filter, d->m_helpEngine->filterAttributes(filter));
}
}
}
@@ -344,7 +357,7 @@ HelpManager::Filters HelpManager::fixedFilters() const
HelpManager::Filters HelpManager::userDefinedFilters() const
{
if (m_needsSetup)
if (d->m_needsSetup)
return Filters();
Filters all = filters();
@@ -356,19 +369,19 @@ HelpManager::Filters HelpManager::userDefinedFilters() const
void HelpManager::removeUserDefinedFilter(const QString &filter)
{
if (m_needsSetup)
if (d->m_needsSetup)
return;
if (m_helpEngine->removeCustomFilter(filter))
if (d->m_helpEngine->removeCustomFilter(filter))
emit collectionFileChanged();
}
void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList &attr)
{
if (m_needsSetup)
if (d->m_needsSetup)
return;
if (m_helpEngine->addCustomFilter(filter, attr))
if (d->m_helpEngine->addCustomFilter(filter, attr))
emit collectionFileChanged();
}
@@ -376,42 +389,42 @@ void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList
void HelpManager::setupHelpManager()
{
if (!m_needsSetup)
if (!d->m_needsSetup)
return;
m_needsSetup = false;
d->m_needsSetup = false;
m_helpEngine = new QHelpEngineCore(collectionFilePath(), this);
m_helpEngine->setAutoSaveFilter(false);
m_helpEngine->setCurrentFilter(tr("Unfiltered"));
m_helpEngine->setupData();
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), this);
d->m_helpEngine->setAutoSaveFilter(false);
d->m_helpEngine->setCurrentFilter(tr("Unfiltered"));
d->m_helpEngine->setupData();
verifyDocumenation();
if (!m_nameSpacesToUnregister.isEmpty()) {
unregisterDocumentation(m_nameSpacesToUnregister);
m_nameSpacesToUnregister.clear();
if (!d->m_nameSpacesToUnregister.isEmpty()) {
unregisterDocumentation(d->m_nameSpacesToUnregister);
d->m_nameSpacesToUnregister.clear();
}
// this might come from the installer
const QLatin1String key("AddedDocs");
const QString addedDocs = m_helpEngine->customValue(key).toString();
const QString addedDocs = d->m_helpEngine->customValue(key).toString();
if (!addedDocs.isEmpty()) {
m_helpEngine->removeCustomValue(key);
m_filesToRegister += addedDocs.split(QLatin1Char(';'));
d->m_helpEngine->removeCustomValue(key);
d->m_filesToRegister += addedDocs.split(QLatin1Char(';'));
}
if (!m_filesToRegister.isEmpty()) {
registerDocumentation(m_filesToRegister);
m_filesToRegister.clear();
if (!d->m_filesToRegister.isEmpty()) {
registerDocumentation(d->m_filesToRegister);
d->m_filesToRegister.clear();
}
QHash<QString, QVariant>::const_iterator it;
for (it = m_customValues.constBegin(); it != m_customValues.constEnd(); ++it)
for (it = d->m_customValues.constBegin(); it != d->m_customValues.constEnd(); ++it)
setCustomValue(it.key(), it.value());
m_collectionWatcher = new QFileSystemWatcher(QStringList() << collectionFilePath(),
d->m_collectionWatcher = new QFileSystemWatcher(QStringList() << collectionFilePath(),
this);
connect(m_collectionWatcher, SIGNAL(fileChanged(QString)), this,
connect(d->m_collectionWatcher, SIGNAL(fileChanged(QString)), this,
SLOT(collectionFileModified()));
emit setupFinished();
@@ -420,9 +433,9 @@ void HelpManager::setupHelpManager()
void HelpManager::collectionFileModified()
{
const QLatin1String key("AddedDocs");
const QString addedDocs = m_helpEngine->customValue(key).toString();
const QString addedDocs = d->m_helpEngine->customValue(key).toString();
if (!addedDocs.isEmpty()) {
m_helpEngine->removeCustomValue(key);
d->m_helpEngine->removeCustomValue(key);
registerDocumentation(addedDocs.split(QLatin1Char(';')));
}
}
@@ -431,10 +444,10 @@ void HelpManager::collectionFileModified()
void HelpManager::verifyDocumenation()
{
const QStringList &registeredDocs = m_helpEngine->registeredDocumentations();
const QStringList &registeredDocs = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
if (!QFileInfo(m_helpEngine->documentationFileName(nameSpace)).exists())
m_nameSpacesToUnregister.append(nameSpace);
if (!QFileInfo(d->m_helpEngine->documentationFileName(nameSpace)).exists())
d->m_nameSpacesToUnregister.append(nameSpace);
}
}

View File

@@ -32,20 +32,18 @@
#include "core_global.h"
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QtCore/QVariant>
#include <QtCore/QByteArray>
#include <QtCore/QScopedPointer>
QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
QT_FORWARD_DECLARE_CLASS(QHelpEngineCore)
QT_FORWARD_DECLARE_CLASS(QSqlQuery)
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtCore/QMap>
#include <QtCore/QHash>
QT_FORWARD_DECLARE_CLASS(QUrl)
namespace Core {
struct HelpManagerPrivate;
class CORE_EXPORT HelpManager : public QObject
{
@@ -54,7 +52,6 @@ class CORE_EXPORT HelpManager : public QObject
public:
typedef QHash<QString, QStringList> Filters;
explicit HelpManager(QObject *parent = 0);
virtual ~HelpManager();
@@ -99,16 +96,7 @@ private slots:
private:
void verifyDocumenation();
private:
bool m_needsSetup;
QHelpEngineCore *m_helpEngine;
QFileSystemWatcher *m_collectionWatcher;
QStringList m_filesToRegister;
QStringList m_nameSpacesToUnregister;
QHash<QString, QVariant> m_customValues;
static HelpManager *m_instance;
QScopedPointer<HelpManagerPrivate> d;
};
} // Core

View File

@@ -43,6 +43,7 @@
#include "modemanager.h"
#include "mimedatabase.h"
#include "newdialog.h"
#include "outputpanemanager.h"
#include "outputpane.h"
#include "plugindialog.h"
#include "progressmanager_p.h"

View File

@@ -0,0 +1,222 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "navigationsubwidget.h"
#include "navigationwidget.h"
#include "icore.h"
#include "icontext.h"
#include "coreconstants.h"
#include "inavigationwidgetfactory.h"
#include "modemanager.h"
#include "actionmanager/actionmanager.h"
#include "actionmanager/command.h"
#include "uniqueidmanager.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/styledbar.h>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtGui/QAction>
#include <QtGui/QHBoxLayout>
#include <QtGui/QResizeEvent>
#include <QtGui/QToolButton>
#include <QtGui/QShortcut>
#include <QtGui/QStandardItemModel>
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
namespace Core {
namespace Internal {
////
// NavigationSubWidget
////
NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int position, int factoryIndex)
: m_parentWidget(parentWidget),
m_position(position)
{
m_navigationComboBox = new NavComboBox(this);
m_navigationComboBox->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
m_navigationComboBox->setFocusPolicy(Qt::TabFocus);
m_navigationComboBox->setMinimumContentsLength(0);
m_navigationComboBox->setModel(parentWidget->factoryModel());
m_navigationWidget = 0;
m_navigationWidgetFactory = 0;
m_toolBar = new Utils::StyledBar(this);
QHBoxLayout *toolBarLayout = new QHBoxLayout;
toolBarLayout->setMargin(0);
toolBarLayout->setSpacing(0);
m_toolBar->setLayout(toolBarLayout);
toolBarLayout->addWidget(m_navigationComboBox);
QToolButton *splitAction = new QToolButton();
splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
splitAction->setToolTip(tr("Split"));
QToolButton *close = new QToolButton();
close->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
close->setToolTip(tr("Close"));
toolBarLayout->addWidget(splitAction);
toolBarLayout->addWidget(close);
QVBoxLayout *lay = new QVBoxLayout();
lay->setMargin(0);
lay->setSpacing(0);
setLayout(lay);
lay->addWidget(m_toolBar);
connect(splitAction, SIGNAL(clicked()), this, SIGNAL(splitMe()));
connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe()));
setFactoryIndex(factoryIndex);
connect(m_navigationComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(comboBoxIndexChanged(int)));
comboBoxIndexChanged(factoryIndex);
}
NavigationSubWidget::~NavigationSubWidget()
{
}
void NavigationSubWidget::comboBoxIndexChanged(int factoryIndex)
{
saveSettings();
// Remove toolbutton
foreach (QWidget *w, m_additionalToolBarWidgets)
delete w;
m_additionalToolBarWidgets.clear();
// Remove old Widget
delete m_navigationWidget;
m_navigationWidget = 0;
m_navigationWidgetFactory = 0;
if (factoryIndex == -1)
return;
// Get new stuff
m_navigationWidgetFactory = m_navigationComboBox->itemData(factoryIndex,
NavigationWidget::FactoryObjectRole).value<INavigationWidgetFactory *>();
NavigationView n = m_navigationWidgetFactory->createWidget();
m_navigationWidget = n.widget;
layout()->addWidget(m_navigationWidget);
// Add Toolbutton
m_additionalToolBarWidgets = n.dockToolBarWidgets;
QHBoxLayout *layout = qobject_cast<QHBoxLayout *>(m_toolBar->layout());
foreach (QToolButton *w, m_additionalToolBarWidgets) {
layout->insertWidget(layout->count()-2, w);
}
restoreSettings();
}
void NavigationSubWidget::setFocusWidget()
{
if (m_navigationWidget)
m_navigationWidget->setFocus();
}
INavigationWidgetFactory *NavigationSubWidget::factory()
{
return m_navigationWidgetFactory;
}
void NavigationSubWidget::saveSettings()
{
if (!m_navigationWidget || !factory())
return;
factory()->saveSettings(position(), m_navigationWidget);
}
void NavigationSubWidget::restoreSettings()
{
if (!m_navigationWidget || !factory())
return;
factory()->restoreSettings(position(), m_navigationWidget);
}
Core::Command *NavigationSubWidget::command(const QString &title) const
{
const QHash<QString, Core::Command*> commandMap = m_parentWidget->commandMap();
QHash<QString, Core::Command*>::const_iterator r = commandMap.find(title);
if (r != commandMap.end())
return r.value();
return 0;
}
int NavigationSubWidget::factoryIndex() const
{
return m_navigationComboBox->currentIndex();
}
void NavigationSubWidget::setFactoryIndex(int i)
{
m_navigationComboBox->setCurrentIndex(i);
}
int NavigationSubWidget::position() const
{
return m_position;
}
void NavigationSubWidget::setPosition(int position)
{
m_position = position;
}
CommandComboBox::CommandComboBox(QWidget *parent) : QComboBox(parent)
{
}
bool CommandComboBox::event(QEvent *e)
{
if (e->type() == QEvent::ToolTip) {
const QString text = currentText();
if (const Core::Command *cmd = command(text)) {
const QString tooltip = tr("Activate %1").arg(text);
setToolTip(cmd->stringWithAppendedShortcut(tooltip));
} else {
setToolTip(text);
}
}
return QComboBox::event(e);
}
} // namespace Internal
} // namespace Core

View File

@@ -0,0 +1,127 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef NAVIGATIONSSUBWIDGET_H
#define NAVIGATIONSSUBWIDGET_H
#include <QtGui/QComboBox>
#include <QtCore/QList>
QT_BEGIN_NAMESPACE
class QToolButton;
QT_END_NAMESPACE
namespace Utils {
class StyledBar;
}
namespace Core {
class INavigationWidgetFactory;
class IMode;
class Command;
class NavigationWidget;
namespace Internal {
class NavigationSubWidget : public QWidget
{
Q_OBJECT
public:
NavigationSubWidget(NavigationWidget *parentWidget, int position, int index);
virtual ~NavigationSubWidget();
INavigationWidgetFactory *factory();
int factoryIndex() const;
void setFactoryIndex(int i);
void setFocusWidget();
int position() const;
void setPosition(int i);
void saveSettings();
void restoreSettings();
Core::Command *command(const QString &title) const;
signals:
void splitMe();
void closeMe();
private slots:
void comboBoxIndexChanged(int);
private:
NavigationWidget *m_parentWidget;
QComboBox *m_navigationComboBox;
QWidget *m_navigationWidget;
INavigationWidgetFactory *m_navigationWidgetFactory;
Utils::StyledBar *m_toolBar;
QList<QToolButton *> m_additionalToolBarWidgets;
int m_position;
};
// A combo associated with a command. Shows the command text
// and shortcut in the tooltip.
class CommandComboBox : public QComboBox
{
Q_OBJECT
public:
explicit CommandComboBox(QWidget *parent = 0);
protected:
bool event(QEvent *event);
private:
virtual const Core::Command *command(const QString &text) const = 0;
};
class NavComboBox : public CommandComboBox
{
Q_OBJECT
public:
explicit NavComboBox(NavigationSubWidget *navSubWidget) :
m_navSubWidget(navSubWidget) {}
private:
virtual const Core::Command *command(const QString &text) const
{ return m_navSubWidget->command(text); }
NavigationSubWidget *m_navSubWidget;
};
} // namespace Internal
} // namespace Core
#endif // NAVIGATIONSSUBWIDGET_H

View File

@@ -28,7 +28,7 @@
**************************************************************************/
#include "navigationwidget.h"
#include "navigationsubwidget.h"
#include "icore.h"
#include "icontext.h"
#include "coreconstants.h"
@@ -54,8 +54,7 @@
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
using namespace Core;
using namespace Core::Internal;
namespace Core {
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::m_current = 0;
@@ -135,29 +134,49 @@ void NavigationWidgetPlaceHolder::currentModeAboutToChange(Core::IMode *mode)
}
}
NavigationWidget *NavigationWidget::m_instance = 0;
struct NavigationWidgetPrivate {
explicit NavigationWidgetPrivate(QAction *toggleSideBarAction);
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction) :
QList<Internal::NavigationSubWidget *> m_subWidgets;
QHash<QShortcut *, QString> m_shortcutMap;
QHash<QString, Core::Command*> m_commandMap;
QStandardItemModel *m_factoryModel;
bool m_shown;
bool m_suppressed;
int m_width;
static NavigationWidget* m_instance;
QAction *m_toggleSideBarAction;
};
NavigationWidgetPrivate::NavigationWidgetPrivate(QAction *toggleSideBarAction) :
m_factoryModel(new QStandardItemModel),
m_shown(true),
m_suppressed(false),
m_width(0),
m_toggleSideBarAction(toggleSideBarAction)
{
m_factoryModel->setSortRole(FactoryPriorityRole);
}
NavigationWidget *NavigationWidgetPrivate::m_instance = 0;
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction) :
d(new NavigationWidgetPrivate(toggleSideBarAction))
{
d->m_factoryModel->setSortRole(FactoryPriorityRole);
setOrientation(Qt::Vertical);
insertSubItem(0, -1); // we don't have any entry to show yet
m_instance = this;
d->m_instance = this;
}
NavigationWidget::~NavigationWidget()
{
m_instance = 0;
NavigationWidgetPrivate::m_instance = 0;
}
NavigationWidget *NavigationWidget::instance()
{
return m_instance;
return NavigationWidgetPrivate::m_instance;
}
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> factories)
@@ -172,65 +191,65 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact
QShortcut *shortcut = new QShortcut(this);
shortcut->setWhatsThis(tr("Activate %1 Pane").arg(factory->displayName()));
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSubWidget()));
m_shortcutMap.insert(shortcut, id);
d->m_shortcutMap.insert(shortcut, id);
Command *cmd = am->registerShortcut(shortcut,
Id(QLatin1String("QtCreator.Sidebar.") + id), navicontext);
cmd->setDefaultKeySequence(factory->activationSequence());
m_commandMap.insert(id, cmd);
d->m_commandMap.insert(id, cmd);
QStandardItem *newRow = new QStandardItem(factory->displayName());
newRow->setData(qVariantFromValue(factory), FactoryObjectRole);
newRow->setData(factory->id(), FactoryIdRole);
newRow->setData(factory->priority(), FactoryPriorityRole);
m_factoryModel->appendRow(newRow);
d->m_factoryModel->appendRow(newRow);
}
m_factoryModel->sort(0);
d->m_factoryModel->sort(0);
}
int NavigationWidget::storedWidth()
{
return m_width;
return d->m_width;
}
QAbstractItemModel *NavigationWidget::factoryModel() const
{
return m_factoryModel;
return d->m_factoryModel;
}
void NavigationWidget::updateToggleText()
{
if (isShown())
m_toggleSideBarAction->setText(tr("Hide Sidebar"));
d->m_toggleSideBarAction->setText(tr("Hide Sidebar"));
else
m_toggleSideBarAction->setText(tr("Show Sidebar"));
d->m_toggleSideBarAction->setText(tr("Show Sidebar"));
}
void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder)
{
m_toggleSideBarAction->setEnabled(holder);
m_toggleSideBarAction->setChecked(holder && isShown());
d->m_toggleSideBarAction->setEnabled(holder);
d->m_toggleSideBarAction->setChecked(holder && isShown());
updateToggleText();
}
void NavigationWidget::resizeEvent(QResizeEvent *re)
{
if (m_width && re->size().width())
m_width = re->size().width();
if (d->m_width && re->size().width())
d->m_width = re->size().width();
MiniSplitter::resizeEvent(re);
}
NavigationSubWidget *NavigationWidget::insertSubItem(int position,int index)
Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int index)
{
for (int pos = position + 1; pos < m_subWidgets.size(); ++pos) {
m_subWidgets.at(pos)->setPosition(pos + 1);
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
d->m_subWidgets.at(pos)->setPosition(pos + 1);
}
NavigationSubWidget *nsw = new NavigationSubWidget(this, position, index);
Internal::NavigationSubWidget *nsw = new Internal::NavigationSubWidget(this, position, index);
connect(nsw, SIGNAL(splitMe()), this, SLOT(splitSubWidget()));
connect(nsw, SIGNAL(closeMe()), this, SLOT(closeSubWidget()));
insertWidget(position, nsw);
m_subWidgets.insert(position, nsw);
d->m_subWidgets.insert(position, nsw);
return nsw;
}
@@ -238,14 +257,14 @@ NavigationSubWidget *NavigationWidget::insertSubItem(int position,int index)
void NavigationWidget::activateSubWidget()
{
QShortcut *original = qobject_cast<QShortcut *>(sender());
QString id = m_shortcutMap[original];
QString id = d->m_shortcutMap[original];
activateSubWidget(id);
}
void NavigationWidget::activateSubWidget(const QString &factoryId)
{
setShown(true);
foreach (NavigationSubWidget *subWidget, m_subWidgets) {
foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) {
if (subWidget->factory()->id() == factoryId) {
subWidget->setFocusWidget();
return;
@@ -254,24 +273,24 @@ void NavigationWidget::activateSubWidget(const QString &factoryId)
int index = factoryIndex(factoryId);
if (index >= 0) {
m_subWidgets.first()->setFactoryIndex(index);
m_subWidgets.first()->setFocusWidget();
d->m_subWidgets.first()->setFactoryIndex(index);
d->m_subWidgets.first()->setFocusWidget();
}
}
void NavigationWidget::splitSubWidget()
{
NavigationSubWidget *original = qobject_cast<NavigationSubWidget *>(sender());
Internal::NavigationSubWidget *original = qobject_cast<Internal::NavigationSubWidget *>(sender());
int pos = indexOf(original) + 1;
insertSubItem(pos, original->factoryIndex());
}
void NavigationWidget::closeSubWidget()
{
if (m_subWidgets.count() != 1) {
NavigationSubWidget *subWidget = qobject_cast<NavigationSubWidget *>(sender());
if (d->m_subWidgets.count() != 1) {
Internal::NavigationSubWidget *subWidget = qobject_cast<Internal::NavigationSubWidget *>(sender());
subWidget->saveSettings();
m_subWidgets.removeOne(subWidget);
d->m_subWidgets.removeOne(subWidget);
subWidget->hide();
subWidget->deleteLater();
} else {
@@ -282,14 +301,14 @@ void NavigationWidget::closeSubWidget()
void NavigationWidget::saveSettings(QSettings *settings)
{
QStringList viewIds;
for (int i=0; i<m_subWidgets.count(); ++i) {
m_subWidgets.at(i)->saveSettings();
viewIds.append(m_subWidgets.at(i)->factory()->id());
for (int i=0; i<d->m_subWidgets.count(); ++i) {
d->m_subWidgets.at(i)->saveSettings();
viewIds.append(d->m_subWidgets.at(i)->factory()->id());
}
settings->setValue("Navigation/Views", viewIds);
settings->setValue("Navigation/Visible", isShown());
settings->setValue("Navigation/VerticalPosition", saveState());
settings->setValue("Navigation/Width", m_width);
settings->setValue("Navigation/Width", d->m_width);
}
void NavigationWidget::restoreSettings(QSettings *settings)
@@ -312,10 +331,10 @@ void NavigationWidget::restoreSettings(QSettings *settings)
const QString &view = viewIds.at(i);
int index = factoryIndex(view);
if (i >= m_subWidgets.size()) {
if (i >= d->m_subWidgets.size()) {
insertSubItem(i, index);
} else {
m_subWidgets.at(i)->setFactoryIndex(index);
d->m_subWidgets.at(i)->setFactoryIndex(index);
}
}
@@ -336,229 +355,74 @@ void NavigationWidget::restoreSettings(QSettings *settings)
}
if (settings->contains("Navigation/Width")) {
m_width = settings->value("Navigation/Width").toInt();
if (!m_width)
m_width = 240;
d->m_width = settings->value("Navigation/Width").toInt();
if (!d->m_width)
d->m_width = 240;
} else {
m_width = 240; //pixel
d->m_width = 240; //pixel
}
// Apply
if (NavigationWidgetPlaceHolder::m_current) {
NavigationWidgetPlaceHolder::m_current->applyStoredSize(m_width);
NavigationWidgetPlaceHolder::m_current->applyStoredSize(d->m_width);
}
}
void NavigationWidget::closeSubWidgets()
{
foreach (NavigationSubWidget *subWidget, m_subWidgets) {
foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) {
subWidget->saveSettings();
delete subWidget;
}
m_subWidgets.clear();
d->m_subWidgets.clear();
}
void NavigationWidget::setShown(bool b)
{
if (m_shown == b)
if (d->m_shown == b)
return;
m_shown = b;
d->m_shown = b;
if (NavigationWidgetPlaceHolder::m_current) {
NavigationWidgetPlaceHolder::m_current->setVisible(m_shown && !m_suppressed);
m_toggleSideBarAction->setChecked(m_shown);
NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed);
d->m_toggleSideBarAction->setChecked(d->m_shown);
} else {
m_toggleSideBarAction->setChecked(false);
d->m_toggleSideBarAction->setChecked(false);
}
updateToggleText();
}
bool NavigationWidget::isShown() const
{
return m_shown;
return d->m_shown;
}
bool NavigationWidget::isSuppressed() const
{
return m_suppressed;
return d->m_suppressed;
}
void NavigationWidget::setSuppressed(bool b)
{
if (m_suppressed == b)
if (d->m_suppressed == b)
return;
m_suppressed = b;
d->m_suppressed = b;
if (NavigationWidgetPlaceHolder::m_current)
NavigationWidgetPlaceHolder::m_current->setVisible(m_shown && !m_suppressed);
NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed);
}
int NavigationWidget::factoryIndex(const QString &id)
{
for (int row = 0; row < m_factoryModel->rowCount(); ++row) {
if (m_factoryModel->data(m_factoryModel->index(row, 0), FactoryIdRole).toString() == id) {
for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) {
if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).toString() == id) {
return row;
}
}
return -1;
}
////
// NavigationSubWidget
////
NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int position, int factoryIndex)
: m_parentWidget(parentWidget),
m_position(position)
QHash<QString, Core::Command*> NavigationWidget::commandMap() const
{
m_navigationComboBox = new NavComboBox(this);
m_navigationComboBox->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
m_navigationComboBox->setFocusPolicy(Qt::TabFocus);
m_navigationComboBox->setMinimumContentsLength(0);
m_navigationComboBox->setModel(parentWidget->factoryModel());
m_navigationWidget = 0;
m_navigationWidgetFactory = 0;
m_toolBar = new Utils::StyledBar(this);
QHBoxLayout *toolBarLayout = new QHBoxLayout;
toolBarLayout->setMargin(0);
toolBarLayout->setSpacing(0);
m_toolBar->setLayout(toolBarLayout);
toolBarLayout->addWidget(m_navigationComboBox);
QToolButton *splitAction = new QToolButton();
splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
splitAction->setToolTip(tr("Split"));
QToolButton *close = new QToolButton();
close->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
close->setToolTip(tr("Close"));
toolBarLayout->addWidget(splitAction);
toolBarLayout->addWidget(close);
QVBoxLayout *lay = new QVBoxLayout();
lay->setMargin(0);
lay->setSpacing(0);
setLayout(lay);
lay->addWidget(m_toolBar);
connect(splitAction, SIGNAL(clicked()), this, SIGNAL(splitMe()));
connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe()));
setFactoryIndex(factoryIndex);
connect(m_navigationComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(comboBoxIndexChanged(int)));
comboBoxIndexChanged(factoryIndex);
return d->m_commandMap;
}
NavigationSubWidget::~NavigationSubWidget()
{
}
} // namespace Core
void NavigationSubWidget::comboBoxIndexChanged(int factoryIndex)
{
saveSettings();
// Remove toolbutton
foreach (QWidget *w, m_additionalToolBarWidgets)
delete w;
m_additionalToolBarWidgets.clear();
// Remove old Widget
delete m_navigationWidget;
m_navigationWidget = 0;
m_navigationWidgetFactory = 0;
if (factoryIndex == -1)
return;
// Get new stuff
m_navigationWidgetFactory = m_navigationComboBox->itemData(factoryIndex,
NavigationWidget::FactoryObjectRole).value<INavigationWidgetFactory *>();
NavigationView n = m_navigationWidgetFactory->createWidget();
m_navigationWidget = n.widget;
layout()->addWidget(m_navigationWidget);
// Add Toolbutton
m_additionalToolBarWidgets = n.dockToolBarWidgets;
QHBoxLayout *layout = qobject_cast<QHBoxLayout *>(m_toolBar->layout());
foreach (QToolButton *w, m_additionalToolBarWidgets) {
layout->insertWidget(layout->count()-2, w);
}
restoreSettings();
}
void NavigationSubWidget::setFocusWidget()
{
if (m_navigationWidget)
m_navigationWidget->setFocus();
}
INavigationWidgetFactory *NavigationSubWidget::factory()
{
return m_navigationWidgetFactory;
}
void NavigationSubWidget::saveSettings()
{
if (!m_navigationWidget || !factory())
return;
factory()->saveSettings(position(), m_navigationWidget);
}
void NavigationSubWidget::restoreSettings()
{
if (!m_navigationWidget || !factory())
return;
factory()->restoreSettings(position(), m_navigationWidget);
}
Core::Command *NavigationSubWidget::command(const QString &title) const
{
const QHash<QString, Core::Command*> commandMap = m_parentWidget->commandMap();
QHash<QString, Core::Command*>::const_iterator r = commandMap.find(title);
if (r != commandMap.end())
return r.value();
return 0;
}
int NavigationSubWidget::factoryIndex() const
{
return m_navigationComboBox->currentIndex();
}
void NavigationSubWidget::setFactoryIndex(int i)
{
m_navigationComboBox->setCurrentIndex(i);
}
int NavigationSubWidget::position() const
{
return m_position;
}
void NavigationSubWidget::setPosition(int position)
{
m_position = position;
}
NavComboBox::NavComboBox(NavigationSubWidget *navSubWidget)
: m_navSubWidget(navSubWidget)
{
}
bool NavComboBox::event(QEvent *e)
{
if (e->type() == QEvent::ToolTip) {
QString txt = currentText();
Core::Command *cmd = m_navSubWidget->command(txt);
if (cmd) {
txt = tr("Activate %1").arg(txt);
setToolTip(cmd->stringWithAppendedShortcut(txt));
} else {
setToolTip(txt);
}
}
return QComboBox::event(e);
}

View File

@@ -32,24 +32,25 @@
#include <coreplugin/minisplitter.h>
#include <QtGui/QComboBox>
#include <QtCore/QHash>
#include <QtCore/QScopedPointer>
QT_BEGIN_NAMESPACE
class QSettings;
class QShortcut;
class QToolButton;
class QAbstractItemModel;
class QStandardItemModel;
QT_END_NAMESPACE
namespace Utils {
class StyledBar;
}
namespace Core {
class INavigationWidgetFactory;
class IMode;
class Command;
class NavigationWidget;
struct NavigationWidgetPrivate;
namespace Internal {
class NavigationSubWidget;
}
class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget
{
@@ -57,20 +58,18 @@ class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget
Q_OBJECT
public:
explicit NavigationWidgetPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
~NavigationWidgetPlaceHolder();
virtual ~NavigationWidgetPlaceHolder();
static NavigationWidgetPlaceHolder* current();
void applyStoredSize(int width);
private slots:
void currentModeAboutToChange(Core::IMode *);
private:
Core::IMode *m_mode;
static NavigationWidgetPlaceHolder* m_current;
};
namespace Internal {
class NavigationSubWidget;
}
class CORE_EXPORT NavigationWidget : public MiniSplitter
{
Q_OBJECT
@@ -81,9 +80,8 @@ public:
FactoryPriorityRole
};
NavigationWidget(QAction *toggleSideBarAction);
~NavigationWidget();
explicit NavigationWidget(QAction *toggleSideBarAction);
virtual ~NavigationWidget();
void setFactories(const QList<INavigationWidgetFactory*> factories);
@@ -106,7 +104,7 @@ public:
// Called from the place holders
void placeHolderChanged(NavigationWidgetPlaceHolder *holder);
QHash<QString, Core::Command*> commandMap() const { return m_commandMap; }
QHash<QString, Core::Command*> commandMap() const;
QAbstractItemModel *factoryModel() const;
protected:
@@ -122,74 +120,9 @@ private:
Internal::NavigationSubWidget *insertSubItem(int position, int index);
int factoryIndex(const QString &id);
QList<Internal::NavigationSubWidget *> m_subWidgets;
QHash<QShortcut *, QString> m_shortcutMap;
QHash<QString, Core::Command*> m_commandMap;
QStandardItemModel *m_factoryModel;
bool m_shown;
bool m_suppressed;
int m_width;
static NavigationWidget* m_instance;
QAction *m_toggleSideBarAction;
QScopedPointer<NavigationWidgetPrivate> d;
};
namespace Internal {
class NavigationSubWidget : public QWidget
{
Q_OBJECT
public:
NavigationSubWidget(NavigationWidget *parentWidget, int position, int index);
virtual ~NavigationSubWidget();
INavigationWidgetFactory *factory();
int factoryIndex() const;
void setFactoryIndex(int i);
void setFocusWidget();
int position() const;
void setPosition(int i);
void saveSettings();
void restoreSettings();
Core::Command *command(const QString &title) const;
signals:
void splitMe();
void closeMe();
private slots:
void comboBoxIndexChanged(int);
private:
NavigationWidget *m_parentWidget;
QComboBox *m_navigationComboBox;
QWidget *m_navigationWidget;
INavigationWidgetFactory *m_navigationWidgetFactory;
Utils::StyledBar *m_toolBar;
QList<QToolButton *> m_additionalToolBarWidgets;
int m_position;
};
class NavComboBox : public QComboBox
{
Q_OBJECT
public:
NavComboBox(NavigationSubWidget *navSubWidget);
protected:
bool event(QEvent *event);
private:
NavigationSubWidget *m_navSubWidget;
};
} // namespace Internal
} // namespace Core
#endif // NAVIGATIONWIDGET_H

View File

@@ -28,47 +28,37 @@
**************************************************************************/
#include "outputpane.h"
#include "outputpanemanager.h"
#include "coreconstants.h"
#include "icore.h"
#include "ioutputpane.h"
#include "mainwindow.h"
#include "modemanager.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/uniqueidmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QFocusEvent>
#include <QtGui/QHBoxLayout>
#include <QtGui/QSplitter>
#include <QtGui/QPainter>
#include <QtGui/QToolButton>
#include <QtGui/QStackedWidget>
#include <QtGui/QMenu>
#include <QtGui/QVBoxLayout>
using namespace Core;
using namespace Core::Internal;
namespace Core {
OutputPanePlaceHolder *OutputPanePlaceHolder::m_current = 0;
struct OutputPanePlaceHolderPrivate {
explicit OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent);
Core::IMode *m_mode;
QSplitter *m_splitter;
bool m_closeable;
static OutputPanePlaceHolder* m_current;
};
OutputPanePlaceHolderPrivate::OutputPanePlaceHolderPrivate(Core::IMode *mode, QSplitter *parent) :
m_mode(mode), m_splitter(parent), m_closeable(true)
{
}
OutputPanePlaceHolder *OutputPanePlaceHolderPrivate::m_current = 0;
OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* parent)
: QWidget(parent), m_mode(mode), m_closeable(true)
: QWidget(parent), d(new OutputPanePlaceHolderPrivate(mode, parent))
{
m_splitter = parent;
setVisible(false);
setLayout(new QVBoxLayout);
QSizePolicy sp;
@@ -83,48 +73,50 @@ OutputPanePlaceHolder::OutputPanePlaceHolder(Core::IMode *mode, QSplitter* paren
OutputPanePlaceHolder::~OutputPanePlaceHolder()
{
if (m_current == this) {
OutputPaneManager::instance()->setParent(0);
OutputPaneManager::instance()->hide();
if (d->m_current == this) {
Internal::OutputPaneManager::instance()->setParent(0);
Internal::OutputPaneManager::instance()->hide();
}
}
void OutputPanePlaceHolder::setCloseable(bool b)
{
m_closeable = b;
d->m_closeable = b;
}
bool OutputPanePlaceHolder::closeable()
{
return m_closeable;
return d->m_closeable;
}
void OutputPanePlaceHolder::currentModeChanged(Core::IMode *mode)
{
if (m_current == this) {
m_current = 0;
OutputPaneManager::instance()->setParent(0);
OutputPaneManager::instance()->hide();
OutputPaneManager::instance()->updateStatusButtons(false);
if (d->m_current == this) {
d->m_current = 0;
Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
om->setParent(0);
om->hide();
om->updateStatusButtons(false);
}
if (m_mode == mode) {
m_current = this;
layout()->addWidget(OutputPaneManager::instance());
OutputPaneManager::instance()->show();
OutputPaneManager::instance()->updateStatusButtons(isVisible());
OutputPaneManager::instance()->setCloseable(m_closeable);
if (d->m_mode == mode) {
d->m_current = this;
Internal::OutputPaneManager *om = Internal::OutputPaneManager::instance();
layout()->addWidget(om);
om->show();
om->updateStatusButtons(isVisible());
om->setCloseable(d->m_closeable);
}
}
void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
{
if (!m_splitter)
if (!d->m_splitter)
return;
int idx = m_splitter->indexOf(this);
int idx = d->m_splitter->indexOf(this);
if (idx < 0)
return;
QList<int> sizes = m_splitter->sizes();
QList<int> sizes = d->m_splitter->sizes();
if (maximize) {
int sum = 0;
@@ -145,537 +137,36 @@ void OutputPanePlaceHolder::maximizeOrMinimize(bool maximize)
}
}
m_splitter->setSizes(sizes);
d->m_splitter->setSizes(sizes);
}
bool OutputPanePlaceHolder::isMaximized() const
{
return OutputPaneManager::instance()->isMaximized();
return Internal::OutputPaneManager::instance()->isMaximized();
}
void OutputPanePlaceHolder::unmaximize()
{
if (OutputPaneManager::instance()->isMaximized())
OutputPaneManager::instance()->slotMinMax();
if (Internal::OutputPaneManager::instance()->isMaximized())
Internal::OutputPaneManager::instance()->slotMinMax();
}
////
// OutputPaneManager
////
static OutputPaneManager *m_instance = 0;
void OutputPaneManager::create()
OutputPanePlaceHolder *OutputPanePlaceHolder::getCurrent()
{
m_instance = new OutputPaneManager;
return OutputPanePlaceHolderPrivate::m_current;
}
void OutputPaneManager::destroy()
bool OutputPanePlaceHolder::canMaximizeOrMinimize() const
{
delete m_instance;
m_instance = 0;
return d->m_splitter != 0;
}
OutputPaneManager *OutputPaneManager::instance()
bool OutputPanePlaceHolder::isCurrentVisible()
{
return m_instance;
return OutputPanePlaceHolderPrivate::m_current && OutputPanePlaceHolderPrivate::m_current->isVisible();
}
void OutputPaneManager::updateStatusButtons(bool visible)
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_buttons.value(idx))
m_buttons.value(idx)->setChecked(visible);
m_minMaxAction->setVisible(OutputPanePlaceHolder::m_current
&& OutputPanePlaceHolder::m_current->canMaximizeOrMinimize());
}
} // namespace Core
OutputPaneManager::OutputPaneManager(QWidget *parent) :
QWidget(parent),
m_widgetComboBox(new QComboBox),
m_clearButton(new QToolButton),
m_closeButton(new QToolButton),
m_minMaxAction(0),
m_minMaxButton(new QToolButton),
m_nextAction(0),
m_prevAction(0),
m_lastIndex(-1),
m_outputWidgetPane(new QStackedWidget),
m_opToolBarWidgets(new QStackedWidget),
m_minimizeIcon(":/core/images/arrowdown.png"),
m_maximizeIcon(":/core/images/arrowup.png"),
m_maximised(false)
{
setWindowTitle(tr("Output"));
connect(m_widgetComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changePage()));
m_clearButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLEAN_PANE)));
m_clearButton->setToolTip(tr("Clear"));
connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearPage()));
m_nextAction = new QAction(this);
m_nextAction->setIcon(QIcon(QLatin1String(Constants::ICON_NEXT)));
m_nextAction->setText(tr("Next Item"));
connect(m_nextAction, SIGNAL(triggered()), this, SLOT(slotNext()));
m_prevAction = new QAction(this);
m_prevAction->setIcon(QIcon(QLatin1String(Constants::ICON_PREV)));
m_prevAction->setText(tr("Previous Item"));
connect(m_prevAction, SIGNAL(triggered()), this, SLOT(slotPrev()));
m_minMaxAction = new QAction(this);
m_minMaxAction->setIcon(m_maximizeIcon);
m_minMaxAction->setText(tr("Maximize Output Pane"));
m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(slotHide()));
QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->setSpacing(0);
mainlayout->setMargin(0);
m_toolBar = new Utils::StyledBar;
QHBoxLayout *toolLayout = new QHBoxLayout(m_toolBar);
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->addWidget(m_widgetComboBox);
toolLayout->addWidget(m_clearButton);
m_prevToolButton = new QToolButton;
toolLayout->addWidget(m_prevToolButton);
m_nextToolButton = new QToolButton;
toolLayout->addWidget(m_nextToolButton);
toolLayout->addWidget(m_opToolBarWidgets);
toolLayout->addWidget(m_minMaxButton);
toolLayout->addWidget(m_closeButton);
mainlayout->addWidget(m_toolBar);
mainlayout->addWidget(m_outputWidgetPane, 10);
mainlayout->addWidget(new Core::FindToolBarPlaceHolder(this));
setLayout(mainlayout);
m_buttonsWidget = new QWidget;
m_buttonsWidget->setLayout(new QHBoxLayout);
m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
m_buttonsWidget->layout()->setSpacing(4);
}
OutputPaneManager::~OutputPaneManager()
{
}
QWidget *OutputPaneManager::buttonsWidget()
{
return m_buttonsWidget;
}
// Return shortcut as Ctrl+<number>
static inline int paneShortCut(int number)
{
#ifdef Q_WS_MAC
int modifier = Qt::CTRL;
#else
int modifier = Qt::ALT;
#endif
return modifier | (Qt::Key_0 + number);
}
void OutputPaneManager::init()
{
ActionManager *am = Core::ICore::instance()->actionManager();
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
const Context globalcontext(Core::Constants::C_GLOBAL);
// Window->Output Panes
ActionContainer *mpanes = am->createMenu(Constants::M_WINDOW_PANES);
mwindow->addMenu(mpanes, Constants::G_WINDOW_PANES);
mpanes->menu()->setTitle(tr("Output &Panes"));
mpanes->appendGroup("Coreplugin.OutputPane.ActionsGroup");
mpanes->appendGroup("Coreplugin.OutputPane.PanesGroup");
Core::Command *cmd;
cmd = am->registerAction(m_prevAction, "Coreplugin.OutputPane.previtem", globalcontext);
cmd->setDefaultKeySequence(QKeySequence("Shift+F6"));
m_prevToolButton->setDefaultAction(cmd->action());
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = am->registerAction(m_nextAction, "Coreplugin.OutputPane.nextitem", globalcontext);
m_nextToolButton->setDefaultAction(cmd->action());
cmd->setDefaultKeySequence(QKeySequence("F6"));
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = am->registerAction(m_minMaxAction, "Coreplugin.OutputPane.minmax", globalcontext);
#ifdef Q_WS_MAC
cmd->setDefaultKeySequence(QKeySequence("Ctrl+9"));
#else
cmd->setDefaultKeySequence(QKeySequence("Alt+9"));
#endif
cmd->setAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateIcon);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
connect(m_minMaxAction, SIGNAL(triggered()), this, SLOT(slotMinMax()));
m_minMaxButton->setDefaultAction(cmd->action());
QAction *sep = new QAction(this);
sep->setSeparator(true);
cmd = am->registerAction(sep, "Coreplugin.OutputPane.Sep", globalcontext);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
QList<IOutputPane*> panes = ExtensionSystem::PluginManager::instance()
->getObjects<IOutputPane>();
QMultiMap<int, IOutputPane*> sorted;
foreach (IOutputPane* outPane, panes)
sorted.insertMulti(outPane->priorityInStatusBar(), outPane);
QMultiMap<int, IOutputPane*>::const_iterator it, begin;
begin = sorted.constBegin();
it = sorted.constEnd();
int shortcutNumber = 1;
do {
--it;
IOutputPane* outPane = it.value();
const int idx = m_outputWidgetPane->addWidget(outPane->outputWidget(this));
m_pageMap.insert(idx, outPane);
connect(outPane, SIGNAL(showPage(bool)), this, SLOT(showPage(bool)));
connect(outPane, SIGNAL(hidePage()), this, SLOT(slotHide()));
connect(outPane, SIGNAL(togglePage(bool)), this, SLOT(togglePage(bool)));
connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState()));
QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets);
QHBoxLayout *toolButtonsLayout = new QHBoxLayout;
toolButtonsLayout->setMargin(0);
toolButtonsLayout->setSpacing(0);
foreach (QWidget *toolButton, outPane->toolBarWidgets())
toolButtonsLayout->addWidget(toolButton);
toolButtonsLayout->addStretch(5);
toolButtonsContainer->setLayout(toolButtonsLayout);
m_opToolBarWidgets->addWidget(toolButtonsContainer);
QString actionId = QString("QtCreator.Pane.%1").arg(outPane->displayName().simplified());
actionId.remove(QLatin1Char(' '));
QAction *action = new QAction(outPane->displayName(), this);
Command *cmd = am->registerAction(action, actionId, Context(Constants::C_GLOBAL));
mpanes->addAction(cmd, "Coreplugin.OutputPane.PanesGroup");
m_actions.insert(cmd->action(), idx);
if (outPane->priorityInStatusBar() != -1) {
cmd->setDefaultKeySequence(QKeySequence(paneShortCut(shortcutNumber)));
QPushButton *button = new OutputPaneToggleButton(shortcutNumber, outPane->displayName(),
cmd->action());
++shortcutNumber;
m_buttonsWidget->layout()->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(buttonTriggered()));
m_buttons.insert(idx, button);
}
// Now add the entry to the combobox, since the first item we add sets the currentIndex, thus we need to be set up for that
m_widgetComboBox->addItem(outPane->displayName(), idx);
connect(cmd->action(), SIGNAL(triggered()), this, SLOT(shortcutTriggered()));
} while (it != begin);
changePage();
}
void OutputPaneManager::shortcutTriggered()
{
QAction *action = qobject_cast<QAction*>(sender());
if (action && m_actions.contains(action)) {
int idx = m_actions.value(action);
Core::IOutputPane *outputPane = m_pageMap.value(idx);
// Now check the special case, the output window is already visible,
// we are already on that page
// but the outputpane doesn't have focus
// then just give it focus
// else do the same as clicking on the button does
if (OutputPanePlaceHolder::m_current
&& OutputPanePlaceHolder::m_current->isVisible()
&& m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
if (!outputPane->hasFocus() && outputPane->canFocus())
outputPane->setFocus();
else
slotHide();
} else {
outputPane->popup(true);
}
}
}
bool OutputPaneManager::isMaximized()const
{
return m_maximised;
}
void OutputPaneManager::slotMinMax()
{
QTC_ASSERT(OutputPanePlaceHolder::m_current, return);
if (!OutputPanePlaceHolder::m_current->isVisible()) // easier than disabling/enabling the action
return;
m_maximised = !m_maximised;
OutputPanePlaceHolder::m_current->maximizeOrMinimize(m_maximised);
m_minMaxAction->setIcon(m_maximised ? m_minimizeIcon : m_maximizeIcon);
m_minMaxAction->setText(m_maximised ? tr("Minimize Output Pane")
: tr("Maximize Output Pane"));
}
void OutputPaneManager::buttonTriggered()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
QMap<int, QPushButton *>::const_iterator it, end;
end = m_buttons.constEnd();
for (it = m_buttons.begin(); it != end; ++it) {
if (it.value() == button)
break;
}
int idx = it.key();
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx &&
OutputPanePlaceHolder::m_current &&
OutputPanePlaceHolder::m_current->isVisible() &&
OutputPanePlaceHolder::m_current->closeable()) {
// we should toggle and the page is already visible and we are actually closeable
slotHide();
} else {
showPage(idx, true);
}
}
void OutputPaneManager::slotNext()
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
ensurePageVisible(idx);
IOutputPane *out = m_pageMap.value(idx);
if (out->canNext())
out->goToNext();
}
void OutputPaneManager::slotPrev()
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
ensurePageVisible(idx);
IOutputPane *out = m_pageMap.value(idx);
if (out->canPrevious())
out->goToPrev();
}
void OutputPaneManager::slotHide()
{
if (OutputPanePlaceHolder::m_current) {
OutputPanePlaceHolder::m_current->setVisible(false);
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_buttons.value(idx))
m_buttons.value(idx)->setChecked(false);
if (IEditor *editor = Core::EditorManager::instance()->currentEditor())
editor->widget()->setFocus();
}
}
int OutputPaneManager::findIndexForPage(IOutputPane *out)
{
if (!out)
return -1;
int stackIndex = -1;
QMap<int, IOutputPane*>::const_iterator it = m_pageMap.constBegin();
while (it != m_pageMap.constEnd()) {
if (it.value() == out) {
stackIndex = it.key();
break;
}
++it;
}
if (stackIndex > -1)
return m_widgetComboBox->findData(stackIndex);
else
return -1;
}
void OutputPaneManager::ensurePageVisible(int idx)
{
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() != idx) {
m_widgetComboBox->setCurrentIndex(m_widgetComboBox->findData(idx));
} else {
changePage();
}
}
void OutputPaneManager::updateNavigateState()
{
IOutputPane* pane = qobject_cast<IOutputPane*>(sender());
int idx = findIndexForPage(pane);
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
m_prevAction->setEnabled(pane->canNavigate() && pane->canPrevious());
m_nextAction->setEnabled(pane->canNavigate() && pane->canNext());
}
}
// Slot connected to showPage signal of each page
void OutputPaneManager::showPage(bool focus)
{
int idx = findIndexForPage(qobject_cast<IOutputPane*>(sender()));
showPage(idx, focus);
}
void OutputPaneManager::showPage(int idx, bool focus)
{
IOutputPane *out = m_pageMap.value(idx);
if (idx > -1) {
if (!OutputPanePlaceHolder::m_current) {
// In this mode we don't have a placeholder
// switch to the output mode and switch the page
ICore::instance()->modeManager()->activateMode(Constants::MODE_EDIT);
}
if (OutputPanePlaceHolder::m_current) {
// make the page visible
OutputPanePlaceHolder::m_current->setVisible(true);
ensurePageVisible(idx);
if (focus && out->canFocus())
out->setFocus();
}
}
}
void OutputPaneManager::togglePage(bool focus)
{
int idx = findIndexForPage(qobject_cast<IOutputPane*>(sender()));
if (OutputPanePlaceHolder::m_current
&& OutputPanePlaceHolder::m_current->isVisible()
&& m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
slotHide();
} else {
showPage(idx, focus);
}
}
void OutputPaneManager::setCloseable(bool b)
{
m_closeButton->setVisible(b);
}
bool OutputPaneManager::closeable()
{
return m_closeButton->isVisibleTo(m_closeButton->parentWidget());
}
void OutputPaneManager::focusInEvent(QFocusEvent *e)
{
if (m_outputWidgetPane->currentWidget())
m_outputWidgetPane->currentWidget()->setFocus(e->reason());
}
void OutputPaneManager::changePage()
{
if (m_outputWidgetPane->count() <= 0)
return;
if (!m_pageMap.contains(m_lastIndex)) {
int idx = m_outputWidgetPane->currentIndex();
m_pageMap.value(idx)->visibilityChanged(true);
if (m_buttons.value(idx)) {
if (OutputPanePlaceHolder::m_current)
m_buttons.value(idx)->setChecked(OutputPanePlaceHolder::m_current->isVisible());
else
m_buttons.value(idx)->setChecked(false);
}
m_lastIndex = idx;
return;
}
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_lastIndex != idx) {
m_outputWidgetPane->setCurrentIndex(idx);
m_opToolBarWidgets->setCurrentIndex(idx);
m_pageMap.value(idx)->visibilityChanged(true);
m_pageMap.value(m_lastIndex)->visibilityChanged(false);
bool canNavigate = m_pageMap.value(idx)->canNavigate();
m_prevAction->setEnabled(canNavigate && m_pageMap.value(idx)->canPrevious());
m_nextAction->setEnabled(canNavigate && m_pageMap.value(idx)->canNext());
}
if (m_buttons.value(m_lastIndex))
m_buttons.value(m_lastIndex)->setChecked(false);
if (m_buttons.value(idx)) {
if (OutputPanePlaceHolder::m_current)
m_buttons.value(idx)->setChecked(OutputPanePlaceHolder::m_current->isVisible());
else
m_buttons.value(idx)->setChecked(false);
}
m_lastIndex = idx;
}
void OutputPaneManager::clearPage()
{
if (m_pageMap.contains(m_outputWidgetPane->currentIndex()))
m_pageMap.value(m_outputWidgetPane->currentIndex())->clearContents();
}
OutputPaneToggleButton::OutputPaneToggleButton(int number, const QString &text,
QAction *action, QWidget *parent)
: QPushButton(parent)
, m_number(QString::number(number))
, m_text(text)
, m_action(action)
{
setFocusPolicy(Qt::NoFocus);
setCheckable(true);
setStyleSheet(
"QPushButton { border-image: url(:/core/images/panel_button.png) 2 2 2 19;"
" border-width: 2px 2px 2px 19px; padding-left: -17; padding-right: 4 } "
"QPushButton:checked { border-image: url(:/core/images/panel_button_checked.png) 2 2 2 19 } "
"QPushButton::menu-indicator { width:0; height:0 }"
#ifndef Q_WS_MAC // Mac UIs usually don't hover
"QPushButton:checked:hover { border-image: url(:/core/images/panel_button_checked_hover.png) 2 2 2 19 } "
"QPushButton:pressed:hover { border-image: url(:/core/images/panel_button_pressed.png) 2 2 2 19 } "
"QPushButton:hover { border-image: url(:/core/images/panel_button_hover.png) 2 2 2 19 } "
#endif
);
if (m_action)
connect(m_action, SIGNAL(changed()), this, SLOT(updateToolTip()));
}
void OutputPaneToggleButton::updateToolTip()
{
Q_ASSERT(m_action);
setToolTip(m_action->toolTip());
}
QSize OutputPaneToggleButton::sizeHint() const
{
ensurePolished();
QSize s = fontMetrics().size(Qt::TextSingleLine, m_text);
// Expand to account for border image set by stylesheet above
s.rwidth() += 19 + 5 + 2;
s.rheight() += 2 + 2;
return s.expandedTo(QApplication::globalStrut());
}
void OutputPaneToggleButton::paintEvent(QPaintEvent *event)
{
// For drawing the style sheet stuff
QPushButton::paintEvent(event);
const QFontMetrics fm = fontMetrics();
const int baseLine = (height() - fm.height() + 1) / 2 + fm.ascent();
const int numberWidth = fm.width(m_number);
QPainter p(this);
p.setFont(font());
p.setPen(Qt::white);
p.drawText((20 - numberWidth) / 2, baseLine, m_number);
if (!isChecked())
p.setPen(Qt::black);
int leftPart = 22;
p.drawText(leftPart, baseLine, fm.elidedText(m_text, Qt::ElideRight, width() - leftPart - 1));
}

View File

@@ -32,28 +32,22 @@
#include "core_global.h"
#include <QtCore/QMap>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
#include <QtCore/QScopedPointer>
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QToolButton;
class QStackedWidget;
class QSplitter;
QT_END_NAMESPACE
namespace Core {
class IMode;
class IOutputPane;
namespace Internal {
class OutputPaneManager;
class MainWindow;
}
struct OutputPanePlaceHolderPrivate;
class CORE_EXPORT OutputPanePlaceHolder : public QWidget
{
@@ -62,116 +56,25 @@ class CORE_EXPORT OutputPanePlaceHolder : public QWidget
public:
explicit OutputPanePlaceHolder(Core::IMode *mode, QSplitter *parent = 0);
~OutputPanePlaceHolder();
void setCloseable(bool b);
bool closeable();
static OutputPanePlaceHolder *getCurrent() { return m_current; }
static OutputPanePlaceHolder *getCurrent();
static bool isCurrentVisible();
void unmaximize();
bool isMaximized() const;
private slots:
void currentModeChanged(Core::IMode *);
private:
inline bool canMaximizeOrMinimize() const { return m_splitter != 0; }
bool canMaximizeOrMinimize() const;
void maximizeOrMinimize(bool maximize);
Core::IMode *m_mode;
QSplitter *m_splitter;
bool m_closeable;
static OutputPanePlaceHolder* m_current;
QScopedPointer<OutputPanePlaceHolderPrivate> d;
};
namespace Internal {
class OutputPaneManager : public QWidget
{
Q_OBJECT
public:
void init();
static OutputPaneManager *instance();
void setCloseable(bool b);
bool closeable();
QWidget *buttonsWidget();
void updateStatusButtons(bool visible);
bool isMaximized()const;
public slots:
void slotHide();
void slotNext();
void slotPrev();
void shortcutTriggered();
void slotMinMax();
protected:
void focusInEvent(QFocusEvent *e);
private slots:
void changePage();
void showPage(bool focus);
void togglePage(bool focus);
void clearPage();
void buttonTriggered();
void updateNavigateState();
private:
// the only class that is allowed to create and destroy
friend class MainWindow;
static void create();
static void destroy();
OutputPaneManager(QWidget *parent = 0);
~OutputPaneManager();
void showPage(int idx, bool focus);
void ensurePageVisible(int idx);
int findIndexForPage(IOutputPane *out);
QComboBox *m_widgetComboBox;
QToolButton *m_clearButton;
QToolButton *m_closeButton;
QAction *m_minMaxAction;
QToolButton *m_minMaxButton;
QAction *m_nextAction;
QAction *m_prevAction;
QToolButton *m_prevToolButton;
QToolButton *m_nextToolButton;
QWidget *m_toolBar;
QMap<int, Core::IOutputPane*> m_pageMap;
int m_lastIndex;
QStackedWidget *m_outputWidgetPane;
QStackedWidget *m_opToolBarWidgets;
QWidget *m_buttonsWidget;
QMap<int, QPushButton *> m_buttons;
QMap<QAction *, int> m_actions;
QPixmap m_minimizeIcon;
QPixmap m_maximizeIcon;
bool m_maximised;
};
class OutputPaneToggleButton : public QPushButton
{
Q_OBJECT
public:
OutputPaneToggleButton(int number, const QString &text, QAction *action,
QWidget *parent = 0);
QSize sizeHint() const;
void paintEvent(QPaintEvent *event);
private slots:
void updateToolTip();
private:
QString m_number;
QString m_text;
QAction *m_action;
};
} // namespace Internal
} // namespace Core
#endif // OUTPUTPANE_H

View File

@@ -0,0 +1,583 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "outputpanemanager.h"
#include "outputpane.h"
#include "coreconstants.h"
#include "findplaceholder.h"
#include "coreconstants.h"
#include "icore.h"
#include "ioutputpane.h"
#include "mainwindow.h"
#include "modemanager.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/uniqueidmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QFocusEvent>
#include <QtGui/QHBoxLayout>
#include <QtGui/QSplitter>
#include <QtGui/QPainter>
#include <QtGui/QToolButton>
#include <QtGui/QStackedWidget>
#include <QtGui/QMenu>
namespace Core {
namespace Internal {
////
// OutputPaneManager
////
static OutputPaneManager *m_instance = 0;
void OutputPaneManager::create()
{
m_instance = new OutputPaneManager;
}
void OutputPaneManager::destroy()
{
delete m_instance;
m_instance = 0;
}
OutputPaneManager *OutputPaneManager::instance()
{
return m_instance;
}
void OutputPaneManager::updateStatusButtons(bool visible)
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_buttons.value(idx))
m_buttons.value(idx)->setChecked(visible);
m_minMaxAction->setVisible(OutputPanePlaceHolder::getCurrent()
&& OutputPanePlaceHolder::getCurrent()->canMaximizeOrMinimize());
}
OutputPaneManager::OutputPaneManager(QWidget *parent) :
QWidget(parent),
m_widgetComboBox(new QComboBox),
m_clearButton(new QToolButton),
m_closeButton(new QToolButton),
m_minMaxAction(0),
m_minMaxButton(new QToolButton),
m_nextAction(0),
m_prevAction(0),
m_lastIndex(-1),
m_outputWidgetPane(new QStackedWidget),
m_opToolBarWidgets(new QStackedWidget),
m_minimizeIcon(":/core/images/arrowdown.png"),
m_maximizeIcon(":/core/images/arrowup.png"),
m_maximised(false)
{
setWindowTitle(tr("Output"));
connect(m_widgetComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changePage()));
m_clearButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLEAN_PANE)));
m_clearButton->setToolTip(tr("Clear"));
connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearPage()));
m_nextAction = new QAction(this);
m_nextAction->setIcon(QIcon(QLatin1String(Constants::ICON_NEXT)));
m_nextAction->setText(tr("Next Item"));
connect(m_nextAction, SIGNAL(triggered()), this, SLOT(slotNext()));
m_prevAction = new QAction(this);
m_prevAction->setIcon(QIcon(QLatin1String(Constants::ICON_PREV)));
m_prevAction->setText(tr("Previous Item"));
connect(m_prevAction, SIGNAL(triggered()), this, SLOT(slotPrev()));
m_minMaxAction = new QAction(this);
m_minMaxAction->setIcon(m_maximizeIcon);
m_minMaxAction->setText(tr("Maximize Output Pane"));
m_closeButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(slotHide()));
QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->setSpacing(0);
mainlayout->setMargin(0);
m_toolBar = new Utils::StyledBar;
QHBoxLayout *toolLayout = new QHBoxLayout(m_toolBar);
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->addWidget(m_widgetComboBox);
toolLayout->addWidget(m_clearButton);
m_prevToolButton = new QToolButton;
toolLayout->addWidget(m_prevToolButton);
m_nextToolButton = new QToolButton;
toolLayout->addWidget(m_nextToolButton);
toolLayout->addWidget(m_opToolBarWidgets);
toolLayout->addWidget(m_minMaxButton);
toolLayout->addWidget(m_closeButton);
mainlayout->addWidget(m_toolBar);
mainlayout->addWidget(m_outputWidgetPane, 10);
mainlayout->addWidget(new Core::FindToolBarPlaceHolder(this));
setLayout(mainlayout);
m_buttonsWidget = new QWidget;
m_buttonsWidget->setLayout(new QHBoxLayout);
m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
m_buttonsWidget->layout()->setSpacing(4);
}
OutputPaneManager::~OutputPaneManager()
{
}
QWidget *OutputPaneManager::buttonsWidget()
{
return m_buttonsWidget;
}
// Return shortcut as Ctrl+<number>
static inline int paneShortCut(int number)
{
#ifdef Q_WS_MAC
int modifier = Qt::CTRL;
#else
int modifier = Qt::ALT;
#endif
return modifier | (Qt::Key_0 + number);
}
void OutputPaneManager::init()
{
ActionManager *am = Core::ICore::instance()->actionManager();
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
const Context globalcontext(Core::Constants::C_GLOBAL);
// Window->Output Panes
ActionContainer *mpanes = am->createMenu(Constants::M_WINDOW_PANES);
mwindow->addMenu(mpanes, Constants::G_WINDOW_PANES);
mpanes->menu()->setTitle(tr("Output &Panes"));
mpanes->appendGroup("Coreplugin.OutputPane.ActionsGroup");
mpanes->appendGroup("Coreplugin.OutputPane.PanesGroup");
Core::Command *cmd;
cmd = am->registerAction(m_prevAction, "Coreplugin.OutputPane.previtem", globalcontext);
cmd->setDefaultKeySequence(QKeySequence("Shift+F6"));
m_prevToolButton->setDefaultAction(cmd->action());
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = am->registerAction(m_nextAction, "Coreplugin.OutputPane.nextitem", globalcontext);
m_nextToolButton->setDefaultAction(cmd->action());
cmd->setDefaultKeySequence(QKeySequence("F6"));
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = am->registerAction(m_minMaxAction, "Coreplugin.OutputPane.minmax", globalcontext);
#ifdef Q_WS_MAC
cmd->setDefaultKeySequence(QKeySequence("Ctrl+9"));
#else
cmd->setDefaultKeySequence(QKeySequence("Alt+9"));
#endif
cmd->setAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateIcon);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
connect(m_minMaxAction, SIGNAL(triggered()), this, SLOT(slotMinMax()));
m_minMaxButton->setDefaultAction(cmd->action());
QAction *sep = new QAction(this);
sep->setSeparator(true);
cmd = am->registerAction(sep, "Coreplugin.OutputPane.Sep", globalcontext);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
QList<IOutputPane*> panes = ExtensionSystem::PluginManager::instance()
->getObjects<IOutputPane>();
QMultiMap<int, IOutputPane*> sorted;
foreach (IOutputPane* outPane, panes)
sorted.insertMulti(outPane->priorityInStatusBar(), outPane);
QMultiMap<int, IOutputPane*>::const_iterator it, begin;
begin = sorted.constBegin();
it = sorted.constEnd();
int shortcutNumber = 1;
do {
--it;
IOutputPane* outPane = it.value();
const int idx = m_outputWidgetPane->addWidget(outPane->outputWidget(this));
m_pageMap.insert(idx, outPane);
connect(outPane, SIGNAL(showPage(bool)), this, SLOT(showPage(bool)));
connect(outPane, SIGNAL(hidePage()), this, SLOT(slotHide()));
connect(outPane, SIGNAL(togglePage(bool)), this, SLOT(togglePage(bool)));
connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState()));
QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets);
QHBoxLayout *toolButtonsLayout = new QHBoxLayout;
toolButtonsLayout->setMargin(0);
toolButtonsLayout->setSpacing(0);
foreach (QWidget *toolButton, outPane->toolBarWidgets())
toolButtonsLayout->addWidget(toolButton);
toolButtonsLayout->addStretch(5);
toolButtonsContainer->setLayout(toolButtonsLayout);
m_opToolBarWidgets->addWidget(toolButtonsContainer);
QString actionId = QString("QtCreator.Pane.%1").arg(outPane->displayName().simplified());
actionId.remove(QLatin1Char(' '));
QAction *action = new QAction(outPane->displayName(), this);
Command *cmd = am->registerAction(action, actionId, Context(Constants::C_GLOBAL));
mpanes->addAction(cmd, "Coreplugin.OutputPane.PanesGroup");
m_actions.insert(cmd->action(), idx);
if (outPane->priorityInStatusBar() != -1) {
cmd->setDefaultKeySequence(QKeySequence(paneShortCut(shortcutNumber)));
QPushButton *button = new OutputPaneToggleButton(shortcutNumber, outPane->displayName(),
cmd->action());
++shortcutNumber;
m_buttonsWidget->layout()->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(buttonTriggered()));
m_buttons.insert(idx, button);
}
// Now add the entry to the combobox, since the first item we add sets the currentIndex, thus we need to be set up for that
m_widgetComboBox->addItem(outPane->displayName(), idx);
connect(cmd->action(), SIGNAL(triggered()), this, SLOT(shortcutTriggered()));
} while (it != begin);
changePage();
}
void OutputPaneManager::shortcutTriggered()
{
QAction *action = qobject_cast<QAction*>(sender());
if (action && m_actions.contains(action)) {
int idx = m_actions.value(action);
Core::IOutputPane *outputPane = m_pageMap.value(idx);
// Now check the special case, the output window is already visible,
// we are already on that page
// but the outputpane doesn't have focus
// then just give it focus
// else do the same as clicking on the button does
if (OutputPanePlaceHolder::isCurrentVisible()
&& m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
if (!outputPane->hasFocus() && outputPane->canFocus())
outputPane->setFocus();
else
slotHide();
} else {
outputPane->popup(true);
}
}
}
bool OutputPaneManager::isMaximized()const
{
return m_maximised;
}
void OutputPaneManager::slotMinMax()
{
QTC_ASSERT(OutputPanePlaceHolder::getCurrent(), return);
if (!OutputPanePlaceHolder::getCurrent()->isVisible()) // easier than disabling/enabling the action
return;
m_maximised = !m_maximised;
OutputPanePlaceHolder::getCurrent()->maximizeOrMinimize(m_maximised);
m_minMaxAction->setIcon(m_maximised ? m_minimizeIcon : m_maximizeIcon);
m_minMaxAction->setText(m_maximised ? tr("Minimize Output Pane")
: tr("Maximize Output Pane"));
}
void OutputPaneManager::buttonTriggered()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
QMap<int, QPushButton *>::const_iterator it, end;
end = m_buttons.constEnd();
for (it = m_buttons.begin(); it != end; ++it) {
if (it.value() == button)
break;
}
int idx = it.key();
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx &&
OutputPanePlaceHolder::isCurrentVisible()
&& OutputPanePlaceHolder::getCurrent()->closeable()) {
// we should toggle and the page is already visible and we are actually closeable
slotHide();
} else {
showPage(idx, true);
}
}
void OutputPaneManager::slotNext()
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
ensurePageVisible(idx);
IOutputPane *out = m_pageMap.value(idx);
if (out->canNext())
out->goToNext();
}
void OutputPaneManager::slotPrev()
{
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
ensurePageVisible(idx);
IOutputPane *out = m_pageMap.value(idx);
if (out->canPrevious())
out->goToPrev();
}
void OutputPaneManager::slotHide()
{
if (OutputPanePlaceHolder::getCurrent()) {
OutputPanePlaceHolder::getCurrent()->setVisible(false);
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_buttons.value(idx))
m_buttons.value(idx)->setChecked(false);
if (IEditor *editor = Core::EditorManager::instance()->currentEditor())
editor->widget()->setFocus();
}
}
int OutputPaneManager::findIndexForPage(IOutputPane *out)
{
if (!out)
return -1;
int stackIndex = -1;
QMap<int, IOutputPane*>::const_iterator it = m_pageMap.constBegin();
while (it != m_pageMap.constEnd()) {
if (it.value() == out) {
stackIndex = it.key();
break;
}
++it;
}
if (stackIndex > -1)
return m_widgetComboBox->findData(stackIndex);
else
return -1;
}
void OutputPaneManager::ensurePageVisible(int idx)
{
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() != idx) {
m_widgetComboBox->setCurrentIndex(m_widgetComboBox->findData(idx));
} else {
changePage();
}
}
void OutputPaneManager::updateNavigateState()
{
IOutputPane* pane = qobject_cast<IOutputPane*>(sender());
int idx = findIndexForPage(pane);
if (m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
m_prevAction->setEnabled(pane->canNavigate() && pane->canPrevious());
m_nextAction->setEnabled(pane->canNavigate() && pane->canNext());
}
}
// Slot connected to showPage signal of each page
void OutputPaneManager::showPage(bool focus)
{
int idx = findIndexForPage(qobject_cast<IOutputPane*>(sender()));
showPage(idx, focus);
}
void OutputPaneManager::showPage(int idx, bool focus)
{
IOutputPane *out = m_pageMap.value(idx);
if (idx > -1) {
if (!OutputPanePlaceHolder::getCurrent()) {
// In this mode we don't have a placeholder
// switch to the output mode and switch the page
ICore::instance()->modeManager()->activateMode(Constants::MODE_EDIT);
}
if (OutputPanePlaceHolder::getCurrent()) {
// make the page visible
OutputPanePlaceHolder::getCurrent()->setVisible(true);
ensurePageVisible(idx);
if (focus && out->canFocus())
out->setFocus();
}
}
}
void OutputPaneManager::togglePage(bool focus)
{
int idx = findIndexForPage(qobject_cast<IOutputPane*>(sender()));
if (OutputPanePlaceHolder::isCurrentVisible()
&& m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt() == idx) {
slotHide();
} else {
showPage(idx, focus);
}
}
void OutputPaneManager::setCloseable(bool b)
{
m_closeButton->setVisible(b);
}
bool OutputPaneManager::closeable()
{
return m_closeButton->isVisibleTo(m_closeButton->parentWidget());
}
void OutputPaneManager::focusInEvent(QFocusEvent *e)
{
if (m_outputWidgetPane->currentWidget())
m_outputWidgetPane->currentWidget()->setFocus(e->reason());
}
void OutputPaneManager::changePage()
{
if (m_outputWidgetPane->count() <= 0)
return;
if (!m_pageMap.contains(m_lastIndex)) {
int idx = m_outputWidgetPane->currentIndex();
m_pageMap.value(idx)->visibilityChanged(true);
if (m_buttons.value(idx)) {
m_buttons.value(idx)->setChecked(OutputPanePlaceHolder::isCurrentVisible());
}
m_lastIndex = idx;
return;
}
int idx = m_widgetComboBox->itemData(m_widgetComboBox->currentIndex()).toInt();
if (m_lastIndex != idx) {
m_outputWidgetPane->setCurrentIndex(idx);
m_opToolBarWidgets->setCurrentIndex(idx);
m_pageMap.value(idx)->visibilityChanged(true);
m_pageMap.value(m_lastIndex)->visibilityChanged(false);
bool canNavigate = m_pageMap.value(idx)->canNavigate();
m_prevAction->setEnabled(canNavigate && m_pageMap.value(idx)->canPrevious());
m_nextAction->setEnabled(canNavigate && m_pageMap.value(idx)->canNext());
}
if (m_buttons.value(m_lastIndex))
m_buttons.value(m_lastIndex)->setChecked(false);
if (m_buttons.value(idx))
m_buttons.value(idx)->setChecked(OutputPanePlaceHolder::isCurrentVisible());
m_lastIndex = idx;
}
void OutputPaneManager::clearPage()
{
if (m_pageMap.contains(m_outputWidgetPane->currentIndex()))
m_pageMap.value(m_outputWidgetPane->currentIndex())->clearContents();
}
OutputPaneToggleButton::OutputPaneToggleButton(int number, const QString &text,
QAction *action, QWidget *parent)
: QPushButton(parent)
, m_number(QString::number(number))
, m_text(text)
, m_action(action)
{
setFocusPolicy(Qt::NoFocus);
setCheckable(true);
setStyleSheet(
"QPushButton { border-image: url(:/core/images/panel_button.png) 2 2 2 19;"
" border-width: 2px 2px 2px 19px; padding-left: -17; padding-right: 4 } "
"QPushButton:checked { border-image: url(:/core/images/panel_button_checked.png) 2 2 2 19 } "
"QPushButton::menu-indicator { width:0; height:0 }"
#ifndef Q_WS_MAC // Mac UIs usually don't hover
"QPushButton:checked:hover { border-image: url(:/core/images/panel_button_checked_hover.png) 2 2 2 19 } "
"QPushButton:pressed:hover { border-image: url(:/core/images/panel_button_pressed.png) 2 2 2 19 } "
"QPushButton:hover { border-image: url(:/core/images/panel_button_hover.png) 2 2 2 19 } "
#endif
);
if (m_action)
connect(m_action, SIGNAL(changed()), this, SLOT(updateToolTip()));
}
void OutputPaneToggleButton::updateToolTip()
{
Q_ASSERT(m_action);
setToolTip(m_action->toolTip());
}
QSize OutputPaneToggleButton::sizeHint() const
{
ensurePolished();
QSize s = fontMetrics().size(Qt::TextSingleLine, m_text);
// Expand to account for border image set by stylesheet above
s.rwidth() += 19 + 5 + 2;
s.rheight() += 2 + 2;
return s.expandedTo(QApplication::globalStrut());
}
void OutputPaneToggleButton::paintEvent(QPaintEvent *event)
{
// For drawing the style sheet stuff
QPushButton::paintEvent(event);
const QFontMetrics fm = fontMetrics();
const int baseLine = (height() - fm.height() + 1) / 2 + fm.ascent();
const int numberWidth = fm.width(m_number);
QPainter p(this);
p.setFont(font());
p.setPen(Qt::white);
p.drawText((20 - numberWidth) / 2, baseLine, m_number);
if (!isChecked())
p.setPen(Qt::black);
int leftPart = 22;
p.drawText(leftPart, baseLine, fm.elidedText(m_text, Qt::ElideRight, width() - leftPart - 1));
}
} // namespace Internal
} // namespace Core

View File

@@ -0,0 +1,148 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef OUTPUTPANEMANAGER_H
#define OUTPUTPANEMANAGER_H
#include <QtCore/QMap>
#include <QtGui/QPushButton>
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QToolButton;
class QStackedWidget;
class QSplitter;
QT_END_NAMESPACE
namespace Core {
class IMode;
class IOutputPane;
namespace Internal {
class OutputPaneManager;
class MainWindow;
}
namespace Internal {
class OutputPaneManager : public QWidget
{
Q_OBJECT
public:
void init();
static OutputPaneManager *instance();
void setCloseable(bool b);
bool closeable();
QWidget *buttonsWidget();
void updateStatusButtons(bool visible);
bool isMaximized()const;
public slots:
void slotHide();
void slotNext();
void slotPrev();
void shortcutTriggered();
void slotMinMax();
protected:
void focusInEvent(QFocusEvent *e);
private slots:
void changePage();
void showPage(bool focus);
void togglePage(bool focus);
void clearPage();
void buttonTriggered();
void updateNavigateState();
private:
// the only class that is allowed to create and destroy
friend class MainWindow;
static void create();
static void destroy();
explicit OutputPaneManager(QWidget *parent = 0);
~OutputPaneManager();
void showPage(int idx, bool focus);
void ensurePageVisible(int idx);
int findIndexForPage(IOutputPane *out);
QComboBox *m_widgetComboBox;
QToolButton *m_clearButton;
QToolButton *m_closeButton;
QAction *m_minMaxAction;
QToolButton *m_minMaxButton;
QAction *m_nextAction;
QAction *m_prevAction;
QToolButton *m_prevToolButton;
QToolButton *m_nextToolButton;
QWidget *m_toolBar;
QMap<int, Core::IOutputPane*> m_pageMap;
int m_lastIndex;
QStackedWidget *m_outputWidgetPane;
QStackedWidget *m_opToolBarWidgets;
QWidget *m_buttonsWidget;
QMap<int, QPushButton *> m_buttons;
QMap<QAction *, int> m_actions;
QPixmap m_minimizeIcon;
QPixmap m_maximizeIcon;
bool m_maximised;
};
class OutputPaneToggleButton : public QPushButton
{
Q_OBJECT
public:
OutputPaneToggleButton(int number, const QString &text, QAction *action,
QWidget *parent = 0);
QSize sizeHint() const;
void paintEvent(QPaintEvent *event);
private slots:
void updateToolTip();
private:
QString m_number;
QString m_text;
QAction *m_action;
};
} // namespace Internal
} // namespace Core
#endif // OUTPUTPANEMANAGER_H

View File

@@ -30,6 +30,12 @@
#include "futureprogress.h"
#include "progressbar.h"
#include <QtCore/QFutureWatcher>
#include <QtCore/QTimer>
#include <QtCore/QCoreApplication>
#include <QtCore/QPropertyAnimation>
#include <QtCore/QSequentialAnimationGroup>
#include <QtGui/QColor>
#include <QtGui/QVBoxLayout>
#include <QtGui/QMenu>
@@ -37,15 +43,8 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QPainter>
#include <QtGui/QMouseEvent>
#include <QtCore/QTimer>
#include <QtCore/QCoreApplication>
#include <QtCore/QPropertyAnimation>
#include <QtCore/QSequentialAnimationGroup>
#include <utils/stylehelper.h>
using namespace Core;
using namespace Core::Internal;
const int notificationTimeout = 8000;
const int shortNotificationTimeout = 1000;
@@ -69,9 +68,6 @@ private:
float m_opacity;
};
} // namespace Internal
} // namespace Core
void FadeWidgetHack::paintEvent(QPaintEvent *)
{
if (m_opacity == 0)
@@ -83,6 +79,28 @@ void FadeWidgetHack::paintEvent(QPaintEvent *)
Utils::StyleHelper::verticalGradient(&p, rect(), rect());
}
} // namespace Internal
struct FutureProgressPrivate {
explicit FutureProgressPrivate(FutureProgress *q);
QFutureWatcher<void> m_watcher;
Internal::ProgressBar *m_progress;
QWidget *m_widget;
QHBoxLayout *m_widgetLayout;
QString m_type;
bool m_keep;
bool m_waitingForUserInteraction;
Internal::FadeWidgetHack *m_faderWidget;
};
FutureProgressPrivate::FutureProgressPrivate(FutureProgress *q) :
m_progress(new Internal::ProgressBar), m_widget(0), m_widgetLayout(new QHBoxLayout),
m_keep(false), m_waitingForUserInteraction(false),
m_faderWidget(new Internal::FadeWidgetHack(q))
{
}
/*!
\mainclass
\class Core::FutureProgress
@@ -118,32 +136,25 @@ void FadeWidgetHack::paintEvent(QPaintEvent *)
\fn FutureProgress::FutureProgress(QWidget *parent)
\internal
*/
FutureProgress::FutureProgress(QWidget *parent)
: QWidget(parent),
m_progress(new ProgressBar),
m_widget(0),
m_widgetLayout(new QHBoxLayout)
FutureProgress::FutureProgress(QWidget *parent) :
QWidget(parent), d(new FutureProgressPrivate(this))
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
layout->addWidget(m_progress);
layout->addWidget(d->m_progress);
layout->setMargin(0);
layout->setSpacing(0);
layout->addLayout(m_widgetLayout);
m_widgetLayout->setContentsMargins(7, 0, 7, 2);
m_widgetLayout->setSpacing(0);
layout->addLayout(d->m_widgetLayout);
d->m_widgetLayout->setContentsMargins(7, 0, 7, 2);
d->m_widgetLayout->setSpacing(0);
connect(&m_watcher, SIGNAL(started()), this, SLOT(setStarted()));
connect(&m_watcher, SIGNAL(finished()), this, SLOT(setFinished()));
connect(&m_watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRange(int,int)));
connect(&m_watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgressValue(int)));
connect(&m_watcher, SIGNAL(progressTextChanged(const QString&)),
connect(&d->m_watcher, SIGNAL(started()), this, SLOT(setStarted()));
connect(&d->m_watcher, SIGNAL(finished()), this, SLOT(setFinished()));
connect(&d->m_watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRange(int,int)));
connect(&d->m_watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgressValue(int)));
connect(&d->m_watcher, SIGNAL(progressTextChanged(const QString&)),
this, SLOT(setProgressText(const QString&)));
connect(m_progress, SIGNAL(clicked()), this, SLOT(cancel()));
m_keep = false;
m_waitingForUserInteraction = false;
m_faderWidget = new FadeWidgetHack(this);
connect(d->m_progress, SIGNAL(clicked()), this, SLOT(cancel()));
}
/*!
@@ -152,8 +163,8 @@ FutureProgress::FutureProgress(QWidget *parent)
*/
FutureProgress::~FutureProgress()
{
if (m_widget)
delete m_widget;
if (d->m_widget)
delete d->m_widget;
}
/*!
@@ -164,14 +175,14 @@ FutureProgress::~FutureProgress()
*/
void FutureProgress::setWidget(QWidget *widget)
{
if (m_widget)
delete m_widget;
if (d->m_widget)
delete d->m_widget;
QSizePolicy sp = widget->sizePolicy();
sp.setHorizontalPolicy(QSizePolicy::Ignored);
widget->setSizePolicy(sp);
m_widget = widget;
if (m_widget)
m_widgetLayout->addWidget(m_widget);
d->m_widget = widget;
if (d->m_widget)
d->m_widgetLayout->addWidget(d->m_widget);
}
/*!
@@ -180,7 +191,7 @@ void FutureProgress::setWidget(QWidget *widget)
*/
void FutureProgress::setTitle(const QString &title)
{
m_progress->setTitle(title);
d->m_progress->setTitle(title);
}
/*!
@@ -189,12 +200,12 @@ void FutureProgress::setTitle(const QString &title)
*/
QString FutureProgress::title() const
{
return m_progress->title();
return d->m_progress->title();
}
void FutureProgress::cancel()
{
m_watcher.future().cancel();
d->m_watcher.future().cancel();
}
void FutureProgress::updateToolTip(const QString &text)
@@ -204,16 +215,16 @@ void FutureProgress::updateToolTip(const QString &text)
void FutureProgress::setStarted()
{
m_progress->reset();
m_progress->setError(false);
m_progress->setRange(m_watcher.progressMinimum(), m_watcher.progressMaximum());
m_progress->setValue(m_watcher.progressValue());
d->m_progress->reset();
d->m_progress->setError(false);
d->m_progress->setRange(d->m_watcher.progressMinimum(), d->m_watcher.progressMaximum());
d->m_progress->setValue(d->m_watcher.progressValue());
}
bool FutureProgress::eventFilter(QObject *, QEvent *e)
{
if (m_waitingForUserInteraction
if (d->m_waitingForUserInteraction
&& (e->type() == QEvent::MouseMove || e->type() == QEvent::KeyPress)) {
qApp->removeEventFilter(this);
QTimer::singleShot(notificationTimeout, this, SLOT(fadeAway()));
@@ -223,36 +234,36 @@ bool FutureProgress::eventFilter(QObject *, QEvent *e)
void FutureProgress::setFinished()
{
updateToolTip(m_watcher.future().progressText());
updateToolTip(d->m_watcher.future().progressText());
// Special case for concurrent jobs that don't use QFutureInterface to report progress
if (m_watcher.progressMinimum() == 0 && m_watcher.progressMaximum() == 0) {
m_progress->setRange(0, 1);
m_progress->setValue(1);
if (d->m_watcher.progressMinimum() == 0 && d->m_watcher.progressMaximum() == 0) {
d->m_progress->setRange(0, 1);
d->m_progress->setValue(1);
}
if (m_watcher.future().isCanceled()) {
m_progress->setError(true);
if (d->m_watcher.future().isCanceled()) {
d->m_progress->setError(true);
} else {
m_progress->setError(false);
d->m_progress->setError(false);
}
emit finished();
if (m_keep) {
m_waitingForUserInteraction = true;
if (d->m_keep) {
d->m_waitingForUserInteraction = true;
qApp->installEventFilter(this);
} else if (!m_progress->hasError()) {
} else if (!d->m_progress->hasError()) {
QTimer::singleShot(shortNotificationTimeout, this, SLOT(fadeAway()));
}
}
void FutureProgress::setProgressRange(int min, int max)
{
m_progress->setRange(min, max);
d->m_progress->setRange(min, max);
}
void FutureProgress::setProgressValue(int val)
{
m_progress->setValue(val);
d->m_progress->setValue(val);
}
void FutureProgress::setProgressText(const QString &text)
@@ -266,7 +277,7 @@ void FutureProgress::setProgressText(const QString &text)
*/
void FutureProgress::setFuture(const QFuture<void> &future)
{
m_watcher.setFuture(future);
d->m_watcher.setFuture(future);
}
/*!
@@ -275,7 +286,7 @@ void FutureProgress::setFuture(const QFuture<void> &future)
*/
QFuture<void> FutureProgress::future() const
{
return m_watcher.future();
return d->m_watcher.future();
}
/*!
@@ -291,7 +302,7 @@ void FutureProgress::mousePressEvent(QMouseEvent *event)
void FutureProgress::resizeEvent(QResizeEvent *)
{
m_faderWidget->setGeometry(rect());
d->m_faderWidget->setGeometry(rect());
}
/*!
@@ -300,14 +311,14 @@ void FutureProgress::resizeEvent(QResizeEvent *)
*/
bool FutureProgress::hasError() const
{
return m_progress->hasError();
return d->m_progress->hasError();
}
void FutureProgress::fadeAway()
{
m_faderWidget->raise();
d->m_faderWidget->raise();
QSequentialAnimationGroup *group = new QSequentialAnimationGroup;
QPropertyAnimation *animation = new QPropertyAnimation(m_faderWidget, "opacity");
QPropertyAnimation *animation = new QPropertyAnimation(d->m_faderWidget, "opacity");
animation->setDuration(600);
animation->setEndValue(1.0);
group->addAnimation(animation);
@@ -322,4 +333,31 @@ void FutureProgress::fadeAway()
connect(group, SIGNAL(finished()), this, SIGNAL(removeMe()));
}
void FutureProgress::setType(const QString &type)
{
d->m_type = type;
}
QString FutureProgress::type() const
{
return d->m_type;
}
void FutureProgress::setKeepOnFinish(bool keep)
{
d->m_keep = keep;
}
bool FutureProgress::keepOnFinish() const
{
return d->m_keep;
}
QWidget *FutureProgress::widget() const
{
return d->m_widget;
}
} // namespace Core
#include "futureprogress.moc"

View File

@@ -33,31 +33,23 @@
#include <coreplugin/core_global.h>
#include <QtCore/QString>
#include <QtCore/QScopedPointer>
#include <QtCore/QFuture>
#include <QtCore/QFutureWatcher>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QProgressBar;
class QHBoxLayout;
QT_END_NAMESPACE
namespace Core {
namespace Internal {
class ProgressBar;
class FadeWidgetHack;
} // namespace Internal
struct FutureProgressPrivate;
class CORE_EXPORT FutureProgress : public QWidget
{
Q_OBJECT
public:
FutureProgress(QWidget *parent = 0);
~FutureProgress();
explicit FutureProgress(QWidget *parent = 0);
virtual ~FutureProgress();
bool eventFilter(QObject *object, QEvent *);
virtual bool eventFilter(QObject *object, QEvent *);
void setFuture(const QFuture<void> &future);
QFuture<void> future() const;
@@ -65,16 +57,16 @@ public:
void setTitle(const QString &title);
QString title() const;
void setType(const QString &type) {m_type = type; }
QString type() const { return m_type; }
void setType(const QString &type);
QString type() const;
void setKeepOnFinish(bool keep) { m_keep = keep; }
bool keepOnFinish() const { return m_keep; }
void setKeepOnFinish(bool keep);
bool keepOnFinish() const;
bool hasError() const;
void setWidget(QWidget *widget);
QWidget *widget() const { return m_widget; }
QWidget *widget() const;
signals:
void clicked();
@@ -96,14 +88,7 @@ private slots:
void fadeAway();
private:
QFutureWatcher<void> m_watcher;
Internal::ProgressBar *m_progress;
QWidget *m_widget;
QHBoxLayout *m_widgetLayout;
QString m_type;
bool m_keep;
bool m_waitingForUserInteraction;
Internal::FadeWidgetHack *m_faderWidget;
QScopedPointer<FutureProgressPrivate> d;
};
} // namespace Core

View File

@@ -28,6 +28,7 @@
**************************************************************************/
#include "sidebar.h"
#include "sidebarwidget.h"
#include "imode.h"
#include <coreplugin/coreconstants.h>
@@ -42,35 +43,72 @@
#include <QtGui/QAction>
#include <QtGui/QToolButton>
using namespace Core;
using namespace Core::Internal;
namespace Core {
SideBarItem::SideBarItem(QWidget *widget, const QString &id) :
m_id(id), m_widget(widget)
{
}
SideBarItem::~SideBarItem()
{
delete m_widget;
}
QWidget *SideBarItem::widget() const
{
return m_widget;
}
QString SideBarItem::id() const
{
return m_id;
}
QString SideBarItem::title() const
{
return m_widget->windowTitle();
}
QList<QToolButton *> SideBarItem::createToolBarWidgets()
{
return QList<QToolButton *>();
}
struct SideBarPrivate {
SideBarPrivate() :m_closeWhenEmpty(false) {}
QList<Internal::SideBarWidget*> m_widgets;
QMap<QString, QWeakPointer<SideBarItem> > m_itemMap;
QStringList m_availableItemIds;
QStringList m_availableItemTitles;
QStringList m_unavailableItemIds;
QStringList m_defaultVisible;
QMap<QString, Core::Command*> m_shortcutMap;
bool m_closeWhenEmpty;
};
SideBar::SideBar(QList<SideBarItem*> itemList,
QList<SideBarItem*> defaultVisible) :
m_closeWhenEmpty(false)
d(new SideBarPrivate)
{
setOrientation(Qt::Vertical);
foreach (SideBarItem *item, itemList) {
m_itemMap.insert(item->id(), item);
m_availableItemIds.append(item->id());
m_availableItemTitles.append(item->title());
d->m_itemMap.insert(item->id(), item);
d->m_availableItemIds.append(item->id());
d->m_availableItemTitles.append(item->title());
}
foreach (SideBarItem *item, defaultVisible) {
if (!itemList.contains(item))
continue;
m_defaultVisible.append(item->id());
d->m_defaultVisible.append(item->id());
}
}
SideBar::~SideBar()
{
QMutableMapIterator<QString, QWeakPointer<SideBarItem> > iter(m_itemMap);
QMutableMapIterator<QString, QWeakPointer<SideBarItem> > iter(d->m_itemMap);
while(iter.hasNext()) {
iter.next();
if (!iter.value().isNull())
@@ -80,7 +118,7 @@ SideBar::~SideBar()
QString SideBar::idForTitle(const QString &title) const
{
QMapIterator<QString, QWeakPointer<SideBarItem> > iter(m_itemMap);
QMapIterator<QString, QWeakPointer<SideBarItem> > iter(d->m_itemMap);
while(iter.hasNext()) {
iter.next();
if (iter.value().data()->title() == title)
@@ -91,37 +129,37 @@ QString SideBar::idForTitle(const QString &title) const
QStringList SideBar::availableItemIds() const
{
return m_availableItemIds;
return d->m_availableItemIds;
}
QStringList SideBar::availableItemTitles() const
{
return m_availableItemTitles;
return d->m_availableItemTitles;
}
QStringList SideBar::unavailableItemIds() const
{
return m_unavailableItemIds;
return d->m_unavailableItemIds;
}
bool SideBar::closeWhenEmpty() const
{
return m_closeWhenEmpty;
return d->m_closeWhenEmpty;
}
void SideBar::setCloseWhenEmpty(bool value)
{
m_closeWhenEmpty = value;
d->m_closeWhenEmpty = value;
}
void SideBar::makeItemAvailable(SideBarItem *item)
{
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = m_itemMap.constBegin();
while (it != m_itemMap.constEnd()) {
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = d->m_itemMap.constBegin();
while (it != d->m_itemMap.constEnd()) {
if (it.value().data() == item) {
m_availableItemIds.append(it.key());
m_availableItemTitles.append(it.value().data()->title());
m_unavailableItemIds.removeAll(it.key());
qSort(m_availableItemTitles);
d->m_availableItemIds.append(it.key());
d->m_availableItemTitles.append(it.value().data()->title());
d->m_unavailableItemIds.removeAll(it.key());
qSort(d->m_availableItemTitles);
emit availableItemsChanged();
//updateWidgets();
break;
@@ -135,61 +173,61 @@ void SideBar::makeItemAvailable(SideBarItem *item)
void SideBar::setUnavailableItemIds(const QStringList &itemIds)
{
// re-enable previous items
foreach(const QString &id, m_unavailableItemIds) {
m_availableItemIds.append(id);
m_availableItemTitles.append(m_itemMap.value(id).data()->title());
foreach(const QString &id, d->m_unavailableItemIds) {
d->m_availableItemIds.append(id);
d->m_availableItemTitles.append(d->m_itemMap.value(id).data()->title());
}
m_unavailableItemIds.clear();
d->m_unavailableItemIds.clear();
foreach (const QString &id, itemIds) {
if (!m_unavailableItemIds.contains(id))
m_unavailableItemIds.append(id);
m_availableItemIds.removeAll(id);
m_availableItemTitles.removeAll(m_itemMap.value(id).data()->title());
if (!d->m_unavailableItemIds.contains(id))
d->m_unavailableItemIds.append(id);
d->m_availableItemIds.removeAll(id);
d->m_availableItemTitles.removeAll(d->m_itemMap.value(id).data()->title());
}
qSort(m_availableItemTitles);
qSort(d->m_availableItemTitles);
updateWidgets();
}
SideBarItem *SideBar::item(const QString &id)
{
if (m_itemMap.contains(id)) {
m_availableItemIds.removeAll(id);
m_availableItemTitles.removeAll(m_itemMap.value(id).data()->title());
if (d->m_itemMap.contains(id)) {
d->m_availableItemIds.removeAll(id);
d->m_availableItemTitles.removeAll(d->m_itemMap.value(id).data()->title());
if (!m_unavailableItemIds.contains(id))
m_unavailableItemIds.append(id);
if (!d->m_unavailableItemIds.contains(id))
d->m_unavailableItemIds.append(id);
emit availableItemsChanged();
return m_itemMap.value(id).data();
return d->m_itemMap.value(id).data();
}
return 0;
}
SideBarWidget *SideBar::insertSideBarWidget(int position, const QString &id)
Internal::SideBarWidget *SideBar::insertSideBarWidget(int position, const QString &id)
{
SideBarWidget *item = new SideBarWidget(this, id);
Internal::SideBarWidget *item = new Internal::SideBarWidget(this, id);
connect(item, SIGNAL(splitMe()), this, SLOT(splitSubWidget()));
connect(item, SIGNAL(closeMe()), this, SLOT(closeSubWidget()));
connect(item, SIGNAL(currentWidgetChanged()), this, SLOT(updateWidgets()));
insertWidget(position, item);
m_widgets.insert(position, item);
d->m_widgets.insert(position, item);
updateWidgets();
return item;
}
void SideBar::removeSideBarWidget(SideBarWidget *widget)
void SideBar::removeSideBarWidget(Internal::SideBarWidget *widget)
{
widget->removeCurrentItem();
m_widgets.removeOne(widget);
d->m_widgets.removeOne(widget);
widget->hide();
widget->deleteLater();
}
void SideBar::splitSubWidget()
{
SideBarWidget *original = qobject_cast<SideBarWidget*>(sender());
Internal::SideBarWidget *original = qobject_cast<Internal::SideBarWidget*>(sender());
int pos = indexOf(original) + 1;
insertSideBarWidget(pos);
updateWidgets();
@@ -197,21 +235,21 @@ void SideBar::splitSubWidget()
void SideBar::closeSubWidget()
{
if (m_widgets.count() != 1) {
SideBarWidget *widget = qobject_cast<SideBarWidget*>(sender());
if (d->m_widgets.count() != 1) {
Internal::SideBarWidget *widget = qobject_cast<Internal::SideBarWidget*>(sender());
if (!widget)
return;
removeSideBarWidget(widget);
updateWidgets();
} else {
if (m_closeWhenEmpty)
if (d->m_closeWhenEmpty)
setVisible(false);
}
}
void SideBar::updateWidgets()
{
foreach (SideBarWidget *i, m_widgets)
foreach (Internal::SideBarWidget *i, d->m_widgets)
i->updateAvailableItems();
}
@@ -220,13 +258,13 @@ void SideBar::saveSettings(QSettings *settings, const QString &name)
const QString prefix = name.isEmpty() ? name : (name + QLatin1Char('/'));
QStringList views;
for (int i = 0; i < m_widgets.count(); ++i) {
QString currentItemId = m_widgets.at(i)->currentItemId();
for (int i = 0; i < d->m_widgets.count(); ++i) {
QString currentItemId = d->m_widgets.at(i)->currentItemId();
if (!currentItemId.isEmpty())
views.append(currentItemId);
}
if (views.isEmpty() && m_itemMap.size()) {
QMapIterator<QString, QWeakPointer<SideBarItem> > iter(m_itemMap);
if (views.isEmpty() && d->m_itemMap.size()) {
QMapIterator<QString, QWeakPointer<SideBarItem> > iter(d->m_itemMap);
iter.next();
views.append(iter.key());
}
@@ -239,7 +277,7 @@ void SideBar::saveSettings(QSettings *settings, const QString &name)
void SideBar::closeAllWidgets()
{
foreach (SideBarWidget *widget, m_widgets)
foreach (Internal::SideBarWidget *widget, d->m_widgets)
removeSideBarWidget(widget);
}
@@ -253,14 +291,14 @@ void SideBar::readSettings(QSettings *settings, const QString &name)
QStringList views = settings->value(prefix + "Views").toStringList();
if (views.count()) {
foreach (const QString &id, views)
insertSideBarWidget(m_widgets.count(), id);
insertSideBarWidget(d->m_widgets.count(), id);
} else {
insertSideBarWidget(0);
}
} else {
foreach (const QString &id, m_defaultVisible)
insertSideBarWidget(m_widgets.count(), id);
foreach (const QString &id, d->m_defaultVisible)
insertSideBarWidget(d->m_widgets.count(), id);
}
if (settings->contains(prefix + "Visible"))
@@ -278,9 +316,9 @@ void SideBar::readSettings(QSettings *settings, const QString &name)
void SideBar::activateItem(SideBarItem *item)
{
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = m_itemMap.constBegin();
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = d->m_itemMap.constBegin();
QString id;
while (it != m_itemMap.constEnd()) {
while (it != d->m_itemMap.constEnd()) {
if (it.value().data() == item) {
id = it.key();
break;
@@ -291,14 +329,14 @@ void SideBar::activateItem(SideBarItem *item)
if (id.isEmpty())
return;
for (int i = 0; i < m_widgets.count(); ++i) {
if (m_widgets.at(i)->currentItemId() == id) {
for (int i = 0; i < d->m_widgets.count(); ++i) {
if (d->m_widgets.at(i)->currentItemId() == id) {
item->widget()->setFocus();
return;
}
}
SideBarWidget *widget = m_widgets.first();
Internal::SideBarWidget *widget = d->m_widgets.first();
widget->setCurrentItem(id);
updateWidgets();
item->widget()->setFocus();
@@ -306,180 +344,12 @@ void SideBar::activateItem(SideBarItem *item)
void SideBar::setShortcutMap(const QMap<QString, Core::Command*> &shortcutMap)
{
m_shortcutMap = shortcutMap;
d->m_shortcutMap = shortcutMap;
}
QMap<QString, Core::Command*> SideBar::shortcutMap() const
{
return m_shortcutMap;
return d->m_shortcutMap;
}
} // namespace Core
SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
: m_currentItem(0)
, m_sideBar(sideBar)
{
m_comboBox = new ComboBox(this);
m_comboBox->setMinimumContentsLength(15);
m_toolbar = new QToolBar(this);
m_toolbar->setContentsMargins(0, 0, 0, 0);
m_toolbar->addWidget(m_comboBox);
QWidget *spacerItem = new QWidget(this);
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
m_toolbar->addWidget(spacerItem);
m_splitAction = new QAction(tr("Split"), m_toolbar);
m_splitAction->setToolTip(tr("Split"));
m_splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
connect(m_splitAction, SIGNAL(triggered()), this, SIGNAL(splitMe()));
m_toolbar->addAction(m_splitAction);
QAction *closeAction = new QAction(tr("Close"), m_toolbar);
closeAction->setToolTip(tr("Close"));
closeAction->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
connect(closeAction, SIGNAL(triggered()), this, SIGNAL(closeMe()));
m_toolbar->addAction(closeAction);
QVBoxLayout *lay = new QVBoxLayout();
lay->setMargin(0);
lay->setSpacing(0);
setLayout(lay);
lay->addWidget(m_toolbar);
QStringList titleList = m_sideBar->availableItemTitles();
qSort(titleList);
QString t = id;
if (titleList.count()) {
foreach(const QString &itemTitle, titleList)
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
m_comboBox->setCurrentIndex(0);
if (t.isEmpty())
t = m_comboBox->itemData(0, ComboBox::IdRole).toString();
}
setCurrentItem(t);
connect(m_comboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(setCurrentIndex(int)));
}
SideBarWidget::~SideBarWidget()
{
}
QString SideBarWidget::currentItemTitle() const
{
return m_comboBox->currentText();
}
QString SideBarWidget::currentItemId() const
{
if (m_currentItem)
return m_currentItem->id();
return QString();
}
void SideBarWidget::setCurrentItem(const QString &id)
{
if (!id.isEmpty()) {
int idx = m_comboBox->findData(QVariant(id), ComboBox::IdRole);
if (idx < 0)
idx = 0;
bool blocked = m_comboBox->blockSignals(true);
m_comboBox->setCurrentIndex(idx);
m_comboBox->blockSignals(blocked);
}
SideBarItem *item = m_sideBar->item(id);
if (!item)
return;
removeCurrentItem();
m_currentItem = item;
layout()->addWidget(m_currentItem->widget());
m_currentItem->widget()->show();
// Add buttons and remember their actions for later removal
foreach (QToolButton *b, m_currentItem->createToolBarWidgets())
m_addedToolBarActions.append(m_toolbar->insertWidget(m_splitAction, b));
}
void SideBarWidget::updateAvailableItems()
{
bool blocked = m_comboBox->blockSignals(true);
QString currentTitle = m_comboBox->currentText();
m_comboBox->clear();
QStringList titleList = m_sideBar->availableItemTitles();
if (!currentTitle.isEmpty() && !titleList.contains(currentTitle))
titleList.append(currentTitle);
qSort(titleList);
foreach(const QString &itemTitle, titleList)
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
int idx = m_comboBox->findText(currentTitle);
if (idx < 0)
idx = 0;
m_comboBox->setCurrentIndex(idx);
m_splitAction->setEnabled(titleList.count() > 1);
m_comboBox->blockSignals(blocked);
}
void SideBarWidget::removeCurrentItem()
{
if (!m_currentItem)
return;
QWidget *w = m_currentItem->widget();
w->hide();
layout()->removeWidget(w);
w->setParent(0);
m_sideBar->makeItemAvailable(m_currentItem);
// Delete custom toolbar widgets
qDeleteAll(m_addedToolBarActions);
m_addedToolBarActions.clear();
m_currentItem = 0;
}
void SideBarWidget::setCurrentIndex(int)
{
setCurrentItem(m_comboBox->itemData(m_comboBox->currentIndex(),
ComboBox::IdRole).toString());
emit currentWidgetChanged();
}
Core::Command *SideBarWidget::command(const QString &id) const
{
const QMap<QString, Core::Command*> shortcutMap = m_sideBar->shortcutMap();
QMap<QString, Core::Command*>::const_iterator r = shortcutMap.find(id);
if (r != shortcutMap.end())
return r.value();
return 0;
}
ComboBox::ComboBox(SideBarWidget *sideBarWidget)
: m_sideBarWidget(sideBarWidget)
{
}
bool ComboBox::event(QEvent *e)
{
if (e->type() == QEvent::ToolTip) {
QString txt = currentText();
Core::Command *cmd = m_sideBarWidget->command(txt);
if (cmd) {
txt = tr("Activate %1").arg(txt);
setToolTip(cmd->stringWithAppendedShortcut(txt));
} else {
setToolTip(txt);
}
}
return QComboBox::event(e);
}

View File

@@ -30,27 +30,25 @@
#ifndef SIDEBAR_H
#define SIDEBAR_H
#include <QtCore/QMap>
#include <QtCore/QPointer>
#include <QtGui/QWidget>
#include <QtGui/QComboBox>
#include "core_global.h"
#include "minisplitter.h"
#include <coreplugin/minisplitter.h>
#include <QtCore/QMap>
#include <QtCore/QList>
#include <QtCore/QScopedPointer>
QT_BEGIN_NAMESPACE
class QSettings;
class QToolBar;
class QAction;
class QToolButton;
QT_END_NAMESPACE
namespace Core {
class Command;
struct SideBarPrivate;
namespace Internal {
class SideBarWidget;
class ComboBox;
} // namespace Internal
/*
@@ -65,14 +63,12 @@ class CORE_EXPORT SideBarItem : public QObject
Q_OBJECT
public:
// id is non-localized string of the item that's used to store the settings.
SideBarItem(QWidget *widget, const QString &id)
: m_widget(widget), m_id(id)
{}
explicit SideBarItem(QWidget *widget, const QString &id);
virtual ~SideBarItem();
QWidget *widget() { return m_widget; }
QString id() const { return m_id; }
QString title() const { return m_widget->windowTitle(); }
QWidget *widget() const;
QString id() const;
QString title() const;
/* Should always return a new set of tool buttons.
*
@@ -80,14 +76,12 @@ public:
* that have been added to a QToolBar without either not deleting the
* associated QAction or causing the QToolButton to be deleted.
*/
virtual QList<QToolButton *> createToolBarWidgets()
{
return QList<QToolButton *>();
}
virtual QList<QToolButton *> createToolBarWidgets();
private:
const QString m_id;
QWidget *m_widget;
QString m_id;
};
class CORE_EXPORT SideBar : public MiniSplitter
@@ -99,9 +93,9 @@ public:
* if you have one SideBar, or shared ownership in case
* of multiple SideBars.
*/
SideBar(QList< SideBarItem*> widgetList,
explicit SideBar(QList< SideBarItem*> widgetList,
QList< SideBarItem*> defaultVisible);
~SideBar();
virtual ~SideBar();
QStringList availableItemIds() const;
QStringList availableItemTitles() const;
@@ -136,70 +130,9 @@ private:
const QString &title = QString());
void removeSideBarWidget(Internal::SideBarWidget *widget);
QList<Internal::SideBarWidget*> m_widgets;
QMap<QString, QWeakPointer<SideBarItem> > m_itemMap;
QStringList m_availableItemIds;
QStringList m_availableItemTitles;
QStringList m_unavailableItemIds;
QStringList m_defaultVisible;
QMap<QString, Core::Command*> m_shortcutMap;
bool m_closeWhenEmpty;
QScopedPointer<SideBarPrivate> d;
};
namespace Internal {
class SideBarWidget : public QWidget
{
Q_OBJECT
public:
SideBarWidget(SideBar *sideBar, const QString &title);
~SideBarWidget();
QString currentItemId() const;
QString currentItemTitle() const;
void setCurrentItem(const QString &id);
void updateAvailableItems();
void removeCurrentItem();
Core::Command *command(const QString &id) const;
signals:
void splitMe();
void closeMe();
void currentWidgetChanged();
private slots:
void setCurrentIndex(int);
private:
ComboBox *m_comboBox;
SideBarItem *m_currentItem;
QToolBar *m_toolbar;
QAction *m_splitAction;
QList<QAction *> m_addedToolBarActions;
SideBar *m_sideBar;
};
class ComboBox : public QComboBox
{
Q_OBJECT
public:
enum DataRoles {
IdRole = Qt::UserRole
};
ComboBox(SideBarWidget *sideBarWidget);
protected:
bool event(QEvent *event);
private:
SideBarWidget *m_sideBarWidget;
};
} // namespace Internal
} // namespace Core
#endif // SIDEBAR_H

View File

@@ -0,0 +1,211 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "sidebarwidget.h"
#include "sidebar.h"
#include "navigationsubwidget.h"
#include <coreplugin/coreconstants.h>
#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
#include <QtGui/QAction>
#include <QtGui/QVBoxLayout>
namespace Core {
namespace Internal {
class SideBarComboBox : public CommandComboBox
{
public:
enum DataRoles {
IdRole = Qt::UserRole
};
explicit SideBarComboBox(SideBarWidget *sideBarWidget) : m_sideBarWidget(sideBarWidget) {}
private:
virtual const Core::Command *command(const QString &text) const
{ return m_sideBarWidget->command(text); }
SideBarWidget *m_sideBarWidget;
};
SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
: m_currentItem(0)
, m_sideBar(sideBar)
{
m_comboBox = new SideBarComboBox(this);
m_comboBox->setMinimumContentsLength(15);
m_toolbar = new QToolBar(this);
m_toolbar->setContentsMargins(0, 0, 0, 0);
m_toolbar->addWidget(m_comboBox);
QWidget *spacerItem = new QWidget(this);
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
m_toolbar->addWidget(spacerItem);
m_splitAction = new QAction(tr("Split"), m_toolbar);
m_splitAction->setToolTip(tr("Split"));
m_splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
connect(m_splitAction, SIGNAL(triggered()), this, SIGNAL(splitMe()));
m_toolbar->addAction(m_splitAction);
QAction *closeAction = new QAction(tr("Close"), m_toolbar);
closeAction->setToolTip(tr("Close"));
closeAction->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
connect(closeAction, SIGNAL(triggered()), this, SIGNAL(closeMe()));
m_toolbar->addAction(closeAction);
QVBoxLayout *lay = new QVBoxLayout();
lay->setMargin(0);
lay->setSpacing(0);
setLayout(lay);
lay->addWidget(m_toolbar);
QStringList titleList = m_sideBar->availableItemTitles();
qSort(titleList);
QString t = id;
if (titleList.count()) {
foreach(const QString &itemTitle, titleList)
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
m_comboBox->setCurrentIndex(0);
if (t.isEmpty())
t = m_comboBox->itemData(0, SideBarComboBox::IdRole).toString();
}
setCurrentItem(t);
connect(m_comboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(setCurrentIndex(int)));
}
SideBarWidget::~SideBarWidget()
{
}
QString SideBarWidget::currentItemTitle() const
{
return m_comboBox->currentText();
}
QString SideBarWidget::currentItemId() const
{
if (m_currentItem)
return m_currentItem->id();
return QString();
}
void SideBarWidget::setCurrentItem(const QString &id)
{
if (!id.isEmpty()) {
int idx = m_comboBox->findData(QVariant(id), SideBarComboBox::IdRole);
if (idx < 0)
idx = 0;
bool blocked = m_comboBox->blockSignals(true);
m_comboBox->setCurrentIndex(idx);
m_comboBox->blockSignals(blocked);
}
SideBarItem *item = m_sideBar->item(id);
if (!item)
return;
removeCurrentItem();
m_currentItem = item;
layout()->addWidget(m_currentItem->widget());
m_currentItem->widget()->show();
// Add buttons and remember their actions for later removal
foreach (QToolButton *b, m_currentItem->createToolBarWidgets())
m_addedToolBarActions.append(m_toolbar->insertWidget(m_splitAction, b));
}
void SideBarWidget::updateAvailableItems()
{
bool blocked = m_comboBox->blockSignals(true);
QString currentTitle = m_comboBox->currentText();
m_comboBox->clear();
QStringList titleList = m_sideBar->availableItemTitles();
if (!currentTitle.isEmpty() && !titleList.contains(currentTitle))
titleList.append(currentTitle);
qSort(titleList);
foreach(const QString &itemTitle, titleList)
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
int idx = m_comboBox->findText(currentTitle);
if (idx < 0)
idx = 0;
m_comboBox->setCurrentIndex(idx);
m_splitAction->setEnabled(titleList.count() > 1);
m_comboBox->blockSignals(blocked);
}
void SideBarWidget::removeCurrentItem()
{
if (!m_currentItem)
return;
QWidget *w = m_currentItem->widget();
w->hide();
layout()->removeWidget(w);
w->setParent(0);
m_sideBar->makeItemAvailable(m_currentItem);
// Delete custom toolbar widgets
qDeleteAll(m_addedToolBarActions);
m_addedToolBarActions.clear();
m_currentItem = 0;
}
void SideBarWidget::setCurrentIndex(int)
{
setCurrentItem(m_comboBox->itemData(m_comboBox->currentIndex(),
SideBarComboBox::IdRole).toString());
emit currentWidgetChanged();
}
Core::Command *SideBarWidget::command(const QString &id) const
{
const QMap<QString, Core::Command*> shortcutMap = m_sideBar->shortcutMap();
QMap<QString, Core::Command*>::const_iterator r = shortcutMap.find(id);
if (r != shortcutMap.end())
return r.value();
return 0;
}
} // namespace Internal
} // namespace Core

View File

@@ -0,0 +1,87 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef SIDEBARWIDGET_H
#define SIDEBARWIDGET_H
#include <QtCore/QMap>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QSettings;
class QToolBar;
class QAction;
class QToolButton;
QT_END_NAMESPACE
namespace Core {
class SideBar;
class SideBarItem;
class Command;
namespace Internal {
class SideBarComboBox;
class SideBarWidget : public QWidget
{
Q_OBJECT
public:
explicit SideBarWidget(SideBar *sideBar, const QString &title);
virtual ~SideBarWidget();
QString currentItemId() const;
QString currentItemTitle() const;
void setCurrentItem(const QString &id);
void updateAvailableItems();
void removeCurrentItem();
Core::Command *command(const QString &id) const;
signals:
void splitMe();
void closeMe();
void currentWidgetChanged();
private slots:
void setCurrentIndex(int);
private:
SideBarComboBox *m_comboBox;
SideBarItem *m_currentItem;
QToolBar *m_toolbar;
QAction *m_splitAction;
QList<QAction *> m_addedToolBarActions;
SideBar *m_sideBar;
};
} // namespace Internal
} // namespace Core
#endif // SIDEBARWIDGET_H

View File

@@ -41,6 +41,7 @@
#include <texteditor/helpitem.h>
#include <QtGui/QTextCursor>
#include <QtCore/QUrl>
using namespace CppEditor::Internal;
using namespace Core;