diff --git a/src/libs/utils/filewizardpage.cpp b/src/libs/utils/filewizardpage.cpp index cceb06ece3abef16b622c22afbdd18a9cd56b537..59f1bbc56bafe22afbf1d997d05a147dc7e97c3b 100644 --- a/src/libs/utils/filewizardpage.cpp +++ b/src/libs/utils/filewizardpage.cpp @@ -88,6 +88,7 @@ void FileWizardPage::setName(const QString &name) void FileWizardPage::changeEvent(QEvent *e) { + QWizardPage::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_d->m_ui.retranslateUi(this); diff --git a/src/libs/utils/projectintropage.cpp b/src/libs/utils/projectintropage.cpp index c10d6e07a8e8df61a97686ef12cf932d4e6a4f0b..085cafe7bf04a2980617535396cb3d161fbf9207 100644 --- a/src/libs/utils/projectintropage.cpp +++ b/src/libs/utils/projectintropage.cpp @@ -113,6 +113,7 @@ void ProjectIntroPage::setDescription(const QString &description) void ProjectIntroPage::changeEvent(QEvent *e) { + QWizardPage::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_d->m_ui.retranslateUi(this); diff --git a/src/libs/utils/submiteditorwidget.cpp b/src/libs/utils/submiteditorwidget.cpp index 1f27b463ece793ec3eaf584bfa34fca36fb54f5b..a047682b81502b4fd8d98d434487768b05657cb0 100644 --- a/src/libs/utils/submiteditorwidget.cpp +++ b/src/libs/utils/submiteditorwidget.cpp @@ -366,6 +366,7 @@ bool SubmitEditorWidget::hasCheckedFiles() const void SubmitEditorWidget::changeEvent(QEvent *e) { + QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_d->m_ui.retranslateUi(this); diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 5e2914df46d10bfd43b4a220146c8f019a9e2578..822636d5359413d5488daf4edf4fb869c1eb02ef 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -986,6 +986,7 @@ void MainWindow::removeContextObject(IContext *context) void MainWindow::changeEvent(QEvent *e) { + QMainWindow::changeEvent(e); if (e->type() == QEvent::ActivationChange) { if (isActiveWindow()) { if (debugMainWindow) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 7711ae7777872090dd8c5f4c1bed54c74bac5cb0..c4fc65a1045c9777c65dc9d8b249e7ed05950955 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -185,6 +185,7 @@ CPPEditor::CPPEditor(QWidget *parent) { setParenthesesMatchingEnabled(true); setMarksVisible(true); + setCodeFoldingSupported(true); setCodeFoldingVisible(true); baseTextDocument()->setSyntaxHighlighter(new CppHighlighter); // new QShortcut(QKeySequence("Ctrl+Alt+M"), this, SLOT(foo()), 0, Qt::WidgetShortcut); diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro index 5660b26b1e9a72e25a63c9a6bff9545090b54326..2ea6fb53245cd1eee2e9ea09efa20586b58f4765 100644 --- a/src/plugins/cppeditor/cppeditor.pro +++ b/src/plugins/cppeditor/cppeditor.pro @@ -8,7 +8,6 @@ include(../../qworkbenchplugin.pri) include(cppeditor_dependencies.pri) HEADERS += cppplugin.h \ cppeditor.h \ - cppeditoractionhandler.h \ cpphighlighter.h \ cpphoverhandler.h \ cppfilewizard.h \ @@ -16,13 +15,10 @@ HEADERS += cppplugin.h \ cppeditorenums.h \ cppeditor_global.h \ cppclasswizard.h - SOURCES += cppplugin.cpp \ - cppeditoractionhandler.cpp \ cppeditor.cpp \ cpphighlighter.cpp \ cpphoverhandler.cpp \ cppfilewizard.cpp \ cppclasswizard.cpp - RESOURCES += cppeditor.qrc diff --git a/src/plugins/cppeditor/cppeditoractionhandler.cpp b/src/plugins/cppeditor/cppeditoractionhandler.cpp deleted file mode 100644 index e28a8fead8b036f21e0bf651d996f137ad7ab25a..0000000000000000000000000000000000000000 --- a/src/plugins/cppeditor/cppeditoractionhandler.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (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 qt-sales@nokia.com. -** -**************************************************************************/ - -#include "cppeditoractionhandler.h" -#include "cppeditorconstants.h" -#include "cppeditor.h" -#include <QAction> - -using namespace CppEditor::Internal; - -CPPEditorActionHandler::CPPEditorActionHandler(const QString &context, - uint optionalActions) - : TextEditor::TextEditorActionHandler(context, optionalActions) -{ } - -CPPEditorActionHandler::~CPPEditorActionHandler() -{ } - -void CPPEditorActionHandler::createActions() -{ - TextEditor::TextEditorActionHandler::createActions(); -} - -void CPPEditorActionHandler::updateActions(UpdateMode um) -{ - TextEditor::TextEditorActionHandler::updateActions(um); -} diff --git a/src/plugins/cppeditor/cppeditoractionhandler.h b/src/plugins/cppeditor/cppeditoractionhandler.h deleted file mode 100644 index f9ccd363ae7f7be4c6b5be559ec79af8988c23a1..0000000000000000000000000000000000000000 --- a/src/plugins/cppeditor/cppeditoractionhandler.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (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 qt-sales@nokia.com. -** -**************************************************************************/ - -#ifndef CPPEDITORACTIONHANDLER_H -#define CPPEDITORACTIONHANDLER_H - -#include <texteditor/texteditoractionhandler.h> - -namespace CppEditor { -namespace Internal { - -class CPPEditorActionHandler : public TextEditor::TextEditorActionHandler -{ - Q_OBJECT - -public: - CPPEditorActionHandler(const QString &context, - uint optionalActions = None); - virtual ~CPPEditorActionHandler(); - - using TextEditor::TextEditorActionHandler::updateActions; - -protected: - virtual void createActions(); - virtual void updateActions(UpdateMode um); -}; - -} // namespace Internal -} // namespace CppEditor - -#endif // CPPEDITORACTIONHANDLER_H diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index 804c9f98b8267903dd528532c7d2ce0a4a599ee7..cb6ef53f63a87125df395ad8dd3375f18502a6d6 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -30,7 +30,6 @@ #include "cppplugin.h" #include "cppclasswizard.h" #include "cppeditor.h" -#include "cppeditoractionhandler.h" #include "cppeditorconstants.h" #include "cppeditorenums.h" #include "cppfilewizard.h" @@ -47,6 +46,8 @@ #include <texteditor/completionsupport.h> #include <texteditor/fontsettings.h> #include <texteditor/storagesettings.h> +#include <texteditor/texteditoractionhandler.h> +#include <texteditor/texteditorplugin.h> #include <texteditor/texteditorsettings.h> #include <cpptools/cpptoolsconstants.h> @@ -60,9 +61,9 @@ static const char *sourceSuffixKeyC = "CppEditor/SourceSuffix"; using namespace CppEditor::Internal; -//////////////////////////// CppPluginEditorFactory ///////////////////////////// +//////////////////////////// CppEditorFactory ///////////////////////////// -CppPluginEditorFactory::CppPluginEditorFactory(CppPlugin *owner) : +CppEditorFactory::CppEditorFactory(CppPlugin *owner) : m_kind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND)), m_owner(owner) { @@ -77,18 +78,18 @@ CppPluginEditorFactory::CppPluginEditorFactory(CppPlugin *owner) : QLatin1String("h")); } -QString CppPluginEditorFactory::kind() const +QString CppEditorFactory::kind() const { return m_kind; } -Core::IFile *CppPluginEditorFactory::open(const QString &fileName) +Core::IFile *CppEditorFactory::open(const QString &fileName) { Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, kind()); return iface ? iface->file() : 0; } -Core::IEditor *CppPluginEditorFactory::createEditor(QWidget *parent) +Core::IEditor *CppEditorFactory::createEditor(QWidget *parent) { CPPEditor *editor = new CPPEditor(parent); editor->setRevisionsVisible(true); @@ -97,7 +98,7 @@ Core::IEditor *CppPluginEditorFactory::createEditor(QWidget *parent) return editor->editableInterface(); } -QStringList CppPluginEditorFactory::mimeTypes() const +QStringList CppEditorFactory::mimeTypes() const { return m_mimeTypes; } @@ -128,25 +129,9 @@ CppPlugin *CppPlugin::instance() void CppPlugin::initializeEditor(CPPEditor *editor) { - // common actions m_actionHandler->setupActions(editor); - // settings - TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance(); - connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), - editor, SLOT(setFontSettings(TextEditor::FontSettings))); - connect(settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), - editor, SLOT(setTabSettings(TextEditor::TabSettings))); - connect(settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), - editor, SLOT(setStorageSettings(TextEditor::StorageSettings))); - connect(settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), - editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); - - // tab settings rely on font settings - editor->setFontSettings(settings->fontSettings()); - editor->setTabSettings(settings->tabSettings()); - editor->setStorageSettings(settings->storageSettings()); - editor->setDisplaySettings(settings->displaySettings()); + TextEditor::TextEditorSettings::instance()->initializeEditor(editor); // auto completion connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)), @@ -159,7 +144,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage)) return false; - m_factory = new CppPluginEditorFactory(this); + m_factory = new CppEditorFactory(this); addObject(m_factory); addAutoReleasedObject(new CppHoverHandler); @@ -207,7 +192,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd); - m_actionHandler = new CPPEditorActionHandler(CppEditor::Constants::C_CPPEDITOR, + m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR, TextEditor::TextEditorActionHandler::Format | TextEditor::TextEditorActionHandler::UnCommentSelection | TextEditor::TextEditorActionHandler::UnCollapseAll); diff --git a/src/plugins/cppeditor/cppplugin.h b/src/plugins/cppeditor/cppplugin.h index 84c107ecca3c3e2c82ea0438702fe385ad50b463..151eda3888532ce4d181b550a53f8d4dce94f2ba 100644 --- a/src/plugins/cppeditor/cppplugin.h +++ b/src/plugins/cppeditor/cppplugin.h @@ -44,8 +44,7 @@ namespace CppEditor { namespace Internal { class CPPEditor; -class CPPEditorActionHandler; -class CppPluginEditorFactory; +class CppEditorFactory; class CppPlugin : public ExtensionSystem::IPlugin { @@ -68,21 +67,21 @@ private slots: void jumpToDefinition(); private: - friend class CppPluginEditorFactory; + friend class CppEditorFactory; Core::IEditor *createEditor(QWidget *parent); static CppPlugin *m_instance; - CPPEditorActionHandler *m_actionHandler; - CppPluginEditorFactory *m_factory; + TextEditor::TextEditorActionHandler *m_actionHandler; + CppEditorFactory *m_factory; }; -class CppPluginEditorFactory : public Core::IEditorFactory +class CppEditorFactory : public Core::IEditorFactory { Q_OBJECT public: - CppPluginEditorFactory(CppPlugin *owner); + CppEditorFactory(CppPlugin *owner); virtual QStringList mimeTypes() const; diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp index 45142a21591fd1dc6288d48da81adfecec508e95..bc189a09e56dab529a5d0c3ebab90fe68d255191 100644 --- a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp +++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp @@ -39,7 +39,7 @@ Manager *ProjectFilesFactory::manager() const Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent) { ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, _actionHandler); - ed->initialize(); + TextEditor::TextEditorSettings::instance()->initializeEditor(ed); return ed->editableInterface(); } @@ -98,7 +98,7 @@ Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent) ProjectFilesEditor *editor = new ProjectFilesEditor(parent, parentEditor->factory(), parentEditor->actionHandler()); - editor->initialize(); + TextEditor::TextEditorSettings::instance()->initializeEditor(editor); return editor->editableInterface(); } @@ -122,16 +122,6 @@ ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *fac ProjectFilesEditor::~ProjectFilesEditor() { } -void ProjectFilesEditor::initialize() -{ - TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance(); - - connect(settings, SIGNAL(fontSettingsChanged(const TextEditor::FontSettings&)), - this, SLOT(setFontSettings(const TextEditor::FontSettings&))); - - setFontSettings(settings->fontSettings()); -} - ProjectFilesFactory *ProjectFilesEditor::factory() const { return _factory; diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.h b/src/plugins/genericprojectmanager/genericprojectfileseditor.h index 96981f7471cc8ae44bc631ee0ee3ae4498c41a04..14077aca5b738c244e5c9384c109ab5fa84751cb 100644 --- a/src/plugins/genericprojectmanager/genericprojectfileseditor.h +++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.h @@ -64,8 +64,6 @@ public: TextEditor::TextEditorActionHandler *handler); virtual ~ProjectFilesEditor(); - void initialize(); - ProjectFilesFactory *factory() const; TextEditor::TextEditorActionHandler *actionHandler() const; diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp index 5a1aa5d00d635f9ce95ab96c690b22da64cfd577..f348ac0188165eb92e9936119611748c42aea130 100644 --- a/src/plugins/git/branchdialog.cpp +++ b/src/plugins/git/branchdialog.cpp @@ -258,6 +258,7 @@ void BranchDialog::slotRemoteBranchActivated(const QModelIndex &i) void BranchDialog::changeEvent(QEvent *e) { + QDialog::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_ui->retranslateUi(this); diff --git a/src/plugins/git/branchdialog.h b/src/plugins/git/branchdialog.h index 5656c9e5c67c8149ccb6ebcf1255cddd0796abd1..dcad691d6048f45348930015cf75e263615a64a6 100644 --- a/src/plugins/git/branchdialog.h +++ b/src/plugins/git/branchdialog.h @@ -3,64 +3,68 @@ #include <QtGui/QDialog> - QT_BEGIN_NAMESPACE class QPushButton; class QModelIndex; QT_END_NAMESPACE namespace Git { - namespace Internal { - namespace Ui { - class BranchDialog; - } - - class GitClient; - class LocalBranchModel; - class RemoteBranchModel; - - /* Branch dialog: Display a list of local branches at the top - * and remote branches below. Offers to checkout/delete local - * branches. - * TODO: Add new branch (optionally tracking a remote one). - * How to find out that a local branch is a tracking one? */ - class BranchDialog : public QDialog { - Q_OBJECT - Q_DISABLE_COPY(BranchDialog) - public: - explicit BranchDialog(QWidget *parent = 0); - - bool init(GitClient *client, const QString &workingDirectory, QString *errorMessage); - - virtual ~BranchDialog(); - - protected: - virtual void changeEvent(QEvent *e); - - private slots: - void slotEnableButtons(); - void slotCheckoutSelectedBranch(); - void slotDeleteSelectedBranch(); - void slotLocalBranchActivated(); - void slotRemoteBranchActivated(const QModelIndex &); - void slotCreateLocalBranch(const QString &branchName); - - private: - bool ask(const QString &title, const QString &what, bool defaultButton); - void selectLocalBranch(const QString &b); - - int selectedLocalBranchIndex() const; - int selectedRemoteBranchIndex() const; - - GitClient *m_client; - Ui::BranchDialog *m_ui; - QPushButton *m_checkoutButton; - QPushButton *m_deleteButton; - - LocalBranchModel *m_localModel; - RemoteBranchModel *m_remoteModel; - QString m_repoDirectory; - }; - } // namespace Internal +namespace Internal { + +namespace Ui { +class BranchDialog; +} + +class GitClient; +class LocalBranchModel; +class RemoteBranchModel; + +/** + * Branch dialog. Displays a list of local branches at the top and remote + * branches below. Offers to checkout/delete local branches. + * + * TODO: Add new branch (optionally tracking a remote one). + * How to find out that a local branch is a tracking one? + */ +class BranchDialog : public QDialog { + Q_OBJECT + Q_DISABLE_COPY(BranchDialog) +public: + explicit BranchDialog(QWidget *parent = 0); + + bool init(GitClient *client, const QString &workingDirectory, QString *errorMessage); + + virtual ~BranchDialog(); + +protected: + virtual void changeEvent(QEvent *e); + +private slots: + void slotEnableButtons(); + void slotCheckoutSelectedBranch(); + void slotDeleteSelectedBranch(); + void slotLocalBranchActivated(); + void slotRemoteBranchActivated(const QModelIndex &); + void slotCreateLocalBranch(const QString &branchName); + +private: + bool ask(const QString &title, const QString &what, bool defaultButton); + void selectLocalBranch(const QString &b); + + int selectedLocalBranchIndex() const; + int selectedRemoteBranchIndex() const; + + GitClient *m_client; + Ui::BranchDialog *m_ui; + QPushButton *m_checkoutButton; + QPushButton *m_deleteButton; + + LocalBranchModel *m_localModel; + RemoteBranchModel *m_remoteModel; + QString m_repoDirectory; +}; + +} // namespace Internal } // namespace Git + #endif // BRANCHDIALOG_H diff --git a/src/plugins/help/helpfindsupport.cpp b/src/plugins/help/helpfindsupport.cpp index 7254afbc29d768d35cc285e0cde3d38c3e227705..0f28634ad39beb71ccecf5812e77df5382728d69 100644 --- a/src/plugins/help/helpfindsupport.cpp +++ b/src/plugins/help/helpfindsupport.cpp @@ -78,3 +78,67 @@ bool HelpFindSupport::findStep(const QString &txt, QTextDocument::FindFlags find QTC_ASSERT(m_centralWidget, return false); return m_centralWidget->find(txt, findFlags, false); } + +HelpViewerFindSupport::HelpViewerFindSupport(HelpViewer *viewer) + : m_viewer(viewer) +{ +} + +QString HelpViewerFindSupport::currentFindString() const +{ + QTC_ASSERT(m_viewer, return QString()); + return m_viewer->selectedText(); +} + +bool HelpViewerFindSupport::findIncremental(const QString &txt, QTextDocument::FindFlags findFlags) +{ + QTC_ASSERT(m_viewer, return false); + findFlags &= ~QTextDocument::FindBackward; + return find(txt, findFlags, true); +} + +bool HelpViewerFindSupport::findStep(const QString &txt, QTextDocument::FindFlags findFlags) +{ + QTC_ASSERT(m_viewer, return false); + return find(txt, findFlags, false); +} + +bool HelpViewerFindSupport::find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental) +{ + QTC_ASSERT(m_viewer, return false); +#if !defined(QT_NO_WEBKIT) + Q_UNUSED(incremental); + QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; + if (findFlags & QTextDocument::FindBackward) + options |= QWebPage::FindBackward; + if (findFlags & QTextDocument::FindCaseSensitively) + options |= QWebPage::FindCaseSensitively; + + return m_viewer->findText(txt, options); +#else + QTextCursor cursor = viewer->textCursor(); + QTextDocument *doc = viewer->document(); + QTextBrowser *browser = qobject_cast<QTextBrowser*>(viewer); + + if (!browser || !doc || cursor.isNull()) + return false; + if (incremental) + cursor.setPosition(cursor.selectionStart()); + + QTextCursor found = doc->find(txt, cursor, findFlags); + if (found.isNull()) { + if ((findFlags&QTextDocument::FindBackward) == 0) + cursor.movePosition(QTextCursor::Start); + else + cursor.movePosition(QTextCursor::End); + found = doc->find(txt, cursor, findFlags); + if (found.isNull()) { + return false; + } + } + if (!found.isNull()) { + viewer->setTextCursor(found); + } + return true; +#endif +} diff --git a/src/plugins/help/helpfindsupport.h b/src/plugins/help/helpfindsupport.h index bb77724222063934f189468b9d1dadd45e1462ae..e7aedeb8bf7ae36f25bb78311e072fdcf96b77d7 100644 --- a/src/plugins/help/helpfindsupport.h +++ b/src/plugins/help/helpfindsupport.h @@ -34,6 +34,10 @@ #include <find/ifindsupport.h> +QT_BEGIN_NAMESPACE +class HelpViewer; +QT_END_NAMESPACE + namespace Help { namespace Internal { @@ -65,6 +69,31 @@ private: CentralWidget *m_centralWidget; }; +class HelpViewerFindSupport : public Find::IFindSupport +{ + Q_OBJECT +public: + HelpViewerFindSupport(HelpViewer *viewer); + + bool isEnabled() const { return true; } + bool supportsReplace() const { return false; } + void resetIncrementalSearch() {} + void clearResults() {} + QString currentFindString() const; + QString completedFindString() const { return QString(); } + + bool findIncremental(const QString &txt, QTextDocument::FindFlags findFlags); + bool findStep(const QString &txt, QTextDocument::FindFlags findFlags); + bool replaceStep(const QString &, const QString &, + QTextDocument::FindFlags ) { return false; } + int replaceAll(const QString &, const QString &, + QTextDocument::FindFlags ) { return 0; } + +private: + bool find(const QString &ttf, QTextDocument::FindFlags findFlags, bool incremental); + HelpViewer *m_viewer; +}; + } // namespace Internal } // namespace Help diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 55f8690af2e1574c7b9128581319cb2ab4be0a39..af4765d547cd07c695e859f240410f1467d948c3 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -373,6 +373,9 @@ void HelpPlugin::createRightPaneSideBar() rightPaneLayout->addWidget(rightPaneToolBar); m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0); + Aggregation::Aggregate *agg = new Aggregation::Aggregate(); + agg->add(m_helpViewerForSideBar); + agg->add(new HelpViewerFindSupport(m_helpViewerForSideBar)); rightPaneLayout->addWidget(m_helpViewerForSideBar); m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>() << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR), diff --git a/src/plugins/projectexplorer/buildstepspage.cpp b/src/plugins/projectexplorer/buildstepspage.cpp index 16c2a2d415210c155f97822fad4dc8c6f63a70b8..bcb8945f6214435af953c8e38f41d8d85ec34f9b 100644 --- a/src/plugins/projectexplorer/buildstepspage.cpp +++ b/src/plugins/projectexplorer/buildstepspage.cpp @@ -236,6 +236,7 @@ void BuildStepsPage::downBuildStep() void BuildStepsPage::changeEvent(QEvent *e) { + BuildStepConfigWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_ui->retranslateUi(this); diff --git a/src/plugins/projectexplorer/projectwizardpage.cpp b/src/plugins/projectexplorer/projectwizardpage.cpp index 36eaab884bc38c2638b28b0aaca6deb56e582a8d..2c294e898817b64e282680ede4501ac4a5b8c3f0 100644 --- a/src/plugins/projectexplorer/projectwizardpage.cpp +++ b/src/plugins/projectexplorer/projectwizardpage.cpp @@ -95,6 +95,7 @@ void ProjectWizardPage::setAddToVersionControlEnabled(bool b) void ProjectWizardPage::changeEvent(QEvent *e) { + QWizardPage::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_ui->retranslateUi(this); diff --git a/src/plugins/projectexplorer/removefiledialog.cpp b/src/plugins/projectexplorer/removefiledialog.cpp index 8e6964aa9c8ab865195ca2a62459130560232636..20e7eb8333d04ccbfc78cd9c83552fe9fbaddffd 100644 --- a/src/plugins/projectexplorer/removefiledialog.cpp +++ b/src/plugins/projectexplorer/removefiledialog.cpp @@ -55,6 +55,7 @@ bool RemoveFileDialog::isDeleteFileChecked() const void RemoveFileDialog::changeEvent(QEvent *e) { + QDialog::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_ui->retranslateUi(this); diff --git a/src/plugins/qt4projectmanager/profileeditor.cpp b/src/plugins/qt4projectmanager/profileeditor.cpp index 567e14f2e2569e24faf1d8c0be8d4bd39d0d9009..2a0cc2eb2eb22151e1688ab89bd8b577aba2388c 100644 --- a/src/plugins/qt4projectmanager/profileeditor.cpp +++ b/src/plugins/qt4projectmanager/profileeditor.cpp @@ -68,7 +68,7 @@ Core::IEditor *ProFileEditorEditable::duplicate(QWidget *parent) ProFileEditor *ret = new ProFileEditor(parent, qobject_cast<ProFileEditor*>(editor())->factory(), qobject_cast<ProFileEditor*>(editor())->actionHandler()); ret->duplicateFrom(editor()); - ret->initialize(); + TextEditor::TextEditorSettings::instance()->initializeEditor(ret); return ret->editableInterface(); } @@ -103,16 +103,6 @@ TextEditor::BaseTextEditorEditable *ProFileEditor::createEditableInterface() return new ProFileEditorEditable(this); } -void ProFileEditor::initialize() -{ - TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance(); - - connect(settings, SIGNAL(fontSettingsChanged(const TextEditor::FontSettings&)), - this, SLOT(setFontSettings(const TextEditor::FontSettings&))); - - setFontSettings(settings->fontSettings()); -} - void ProFileEditor::setFontSettings(const TextEditor::FontSettings &fs) { TextEditor::BaseTextEditor::setFontSettings(fs); diff --git a/src/plugins/qt4projectmanager/profileeditor.h b/src/plugins/qt4projectmanager/profileeditor.h index 35fa885efb26c7a896867809ba6560e770f855ff..ba7c70b734c338613bb1d5f24e18c57e5dbbcf8a 100644 --- a/src/plugins/qt4projectmanager/profileeditor.h +++ b/src/plugins/qt4projectmanager/profileeditor.h @@ -74,7 +74,6 @@ public: ProFileEditor(QWidget *parent, ProFileEditorFactory *factory, TextEditor::TextEditorActionHandler *ah); ~ProFileEditor(); - void initialize(); bool save(const QString &fileName = QString()); diff --git a/src/plugins/qt4projectmanager/profileeditorfactory.cpp b/src/plugins/qt4projectmanager/profileeditorfactory.cpp index 0812a1a3d69d1bef7a8590fd06081c69ca44f63a..a5bfe022661cce303a70356303fed5707f7885e1 100644 --- a/src/plugins/qt4projectmanager/profileeditorfactory.cpp +++ b/src/plugins/qt4projectmanager/profileeditorfactory.cpp @@ -36,6 +36,7 @@ #include <coreplugin/fileiconprovider.h> #include <coreplugin/editormanager/editormanager.h> #include <texteditor/texteditoractionhandler.h> +#include <texteditor/texteditorsettings.h> #include <QtCore/QFileInfo> #include <QtGui/QAction> @@ -76,7 +77,7 @@ Core::IFile *ProFileEditorFactory::open(const QString &fileName) Core::IEditor *ProFileEditorFactory::createEditor(QWidget *parent) { ProFileEditor *rc = new ProFileEditor(parent, this, m_actionHandler); - rc->initialize(); + TextEditor::TextEditorSettings::instance()->initializeEditor(rc); return rc->editableInterface(); } diff --git a/src/plugins/qtscripteditor/qtscripteditor.cpp b/src/plugins/qtscripteditor/qtscripteditor.cpp index bbd2cd0db555e9403d83cffab4231da09b00c7fc..e33a1f85263f3910602deca0c8c3616b62257004 100644 --- a/src/plugins/qtscripteditor/qtscripteditor.cpp +++ b/src/plugins/qtscripteditor/qtscripteditor.cpp @@ -49,7 +49,6 @@ namespace Internal { ScriptEditorEditable::ScriptEditorEditable(ScriptEditor *editor, const QList<int>& context) : BaseTextEditorEditable(editor), m_context(context) { - } ScriptEditor::ScriptEditor(const Context &context, @@ -61,6 +60,7 @@ ScriptEditor::ScriptEditor(const Context &context, { setParenthesesMatchingEnabled(true); setMarksVisible(true); + setCodeFoldingSupported(true); setCodeFoldingVisible(true); setMimeType(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE); diff --git a/src/plugins/qtscripteditor/qtscripteditorplugin.cpp b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp index 4e3b14cd5448a8e25617fe169aa4350fbc24379f..a86b509844383d52da5b9e788b78cf07546dc439 100644 --- a/src/plugins/qtscripteditor/qtscripteditorplugin.cpp +++ b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp @@ -109,21 +109,7 @@ void QtScriptEditorPlugin::initializeEditor(QtScriptEditor::Internal::ScriptEdit { QTC_ASSERT(m_instance, /**/); - TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance(); - connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), - editor, SLOT(setFontSettings(TextEditor::FontSettings))); - connect(settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), - editor, SLOT(setTabSettings(TextEditor::TabSettings))); - connect(settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), - editor, SLOT(setStorageSettings(TextEditor::StorageSettings))); - connect(settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), - editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); - - // tab settings rely on font settings - editor->setFontSettings(settings->fontSettings()); - editor->setTabSettings(settings->tabSettings()); - editor->setStorageSettings(settings->storageSettings()); - editor->setDisplaySettings(settings->displaySettings()); + TextEditor::TextEditorSettings::instance()->initializeEditor(editor); } void QtScriptEditorPlugin::registerActions() diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 0caa502d7570a23d708104f05da1526e1c5f2f22..e5fb77e259a03623b26ae4e6f6838430d39e081b 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1198,7 +1198,7 @@ bool BaseTextEditor::lineSeparatorsAllowed() const void BaseTextEditor::setCodeFoldingVisible(bool b) { - d->m_codeFoldingVisible = b; + d->m_codeFoldingVisible = b && d->m_codeFoldingSupported; slotUpdateExtraAreaWidth(); } @@ -1207,6 +1207,22 @@ bool BaseTextEditor::codeFoldingVisible() const return d->m_codeFoldingVisible; } +/** + * Sets whether code folding is supported by the syntax highlighter. When not + * supported (the default), this makes sure the code folding is not shown. + * + * Needs to be called before calling setCodeFoldingVisible. + */ +void BaseTextEditor::setCodeFoldingSupported(bool b) +{ + d->m_codeFoldingSupported = b; +} + +bool BaseTextEditor::codeFoldingSupported() const +{ + return d->m_codeFoldingSupported; +} + void BaseTextEditor::setRevisionsVisible(bool b) { d->m_revisionsVisible = b; @@ -1229,61 +1245,6 @@ int BaseTextEditor::visibleWrapColumn() const return d->m_visibleWrapColumn; } -void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs) -{ - const QTextCharFormat textFormat = fs.toTextCharFormat(QLatin1String(Constants::C_TEXT)); - const QTextCharFormat selectionFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SELECTION)); - const QTextCharFormat lineNumberFormat = fs.toTextCharFormat(QLatin1String(Constants::C_LINE_NUMBER)); - const QTextCharFormat searchResultFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_RESULT)); - const QTextCharFormat searchScopeFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_SCOPE)); - const QTextCharFormat parenthesesFormat = fs.toTextCharFormat(QLatin1String(Constants::C_PARENTHESES)); - const QTextCharFormat currentLineFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE)); - const QTextCharFormat ifdefedOutFormat = fs.toTextCharFormat(QLatin1String(Constants::C_DISABLED_CODE)); - QFont font(textFormat.font()); - - const QColor foreground = textFormat.foreground().color(); - const QColor background = textFormat.background().color(); - QPalette p = palette(); - p.setColor(QPalette::Text, foreground); - p.setColor(QPalette::Foreground, foreground); - p.setColor(QPalette::Base, background); - p.setColor(QPalette::Highlight, (selectionFormat.background().style() != Qt::NoBrush) ? - selectionFormat.background().color() : - QApplication::palette().color(QPalette::Highlight)); - p.setColor(QPalette::HighlightedText, selectionFormat.foreground().color()); - p.setBrush(QPalette::Inactive, QPalette::Highlight, p.highlight()); - p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText()); - setPalette(p); - setFont(font); - setTabSettings(d->m_document->tabSettings()); // update tabs, they depend on the font - - // Line numbers - QPalette ep = d->m_extraArea->palette(); - ep.setColor(QPalette::Dark, lineNumberFormat.foreground().color()); - ep.setColor(QPalette::Background, lineNumberFormat.background().style() != Qt::NoBrush ? - lineNumberFormat.background().color() : background); - d->m_extraArea->setPalette(ep); - - // Search results - d->m_searchResultFormat.setBackground(searchResultFormat.background()); - d->m_searchScopeFormat.setBackground(searchScopeFormat.background()); - d->m_currentLineFormat.setBackground(currentLineFormat.background()); - - // Matching braces - d->m_matchFormat.setForeground(parenthesesFormat.foreground()); - d->m_rangeFormat.setBackground(parenthesesFormat.background()); - - // Disabled code - d->m_ifdefedOutFormat.setForeground(ifdefedOutFormat.foreground()); - - slotUpdateExtraAreaWidth(); -} - -void BaseTextEditor::setStorageSettings(const StorageSettings &storageSettings) -{ - d->m_document->setStorageSettings(storageSettings); -} - //--------- BaseTextEditorPrivate ----------- BaseTextEditorPrivate::BaseTextEditorPrivate() @@ -1294,6 +1255,7 @@ BaseTextEditorPrivate::BaseTextEditorPrivate() m_extraArea(0), m_marksVisible(false), m_codeFoldingVisible(false), + m_codeFoldingSupported(false), m_revisionsVisible(false), m_lineNumbersVisible(true), m_highlightCurrentLine(true), @@ -1681,6 +1643,18 @@ void BaseTextEditorPrivate::removeBlockSelection(const QString &text) q->setTextCursor(cursor); } +void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible) +{ + QTextCursor cursor = q->textCursor(); + if (!cursor.block().isVisible()) { + cursor.setVisualNavigation(true); + cursor.movePosition(QTextCursor::Up); + q->setTextCursor(cursor); + } + if (ensureVisible) + q->ensureCursorVisible(); +} + void BaseTextEditor::paintEvent(QPaintEvent *e) { /* @@ -2057,15 +2031,6 @@ void BaseTextEditor::paintEvent(QPaintEvent *e) } } -void BaseTextEditor::slotUpdateExtraAreaWidth() -{ - if (isLeftToRight()) - setViewportMargins(extraAreaWidth(), 0, 0, 0); - else - setViewportMargins(0, 0, extraAreaWidth(), 0); -} - - QWidget *BaseTextEditor::extraArea() const { return d->m_extraArea; @@ -2113,65 +2078,12 @@ int BaseTextEditor::extraAreaWidth(int *markWidthPtr) const return space; } -void BaseTextEditor::slotModificationChanged(bool m) -{ - if (m) - return; - - QTextDocument *doc = document(); - TextEditDocumentLayout *documentLayout = qobject_cast<TextEditDocumentLayout*>(doc->documentLayout()); - QTC_ASSERT(documentLayout, return); - int oldLastSaveRevision = documentLayout->lastSaveRevision; - documentLayout->lastSaveRevision = doc->revision(); - - if (oldLastSaveRevision != documentLayout->lastSaveRevision) { - QTextBlock block = doc->begin(); - while (block.isValid()) { - if (block.revision() < 0 || block.revision() != oldLastSaveRevision) { - block.setRevision(-documentLayout->lastSaveRevision - 1); - } else { - block.setRevision(documentLayout->lastSaveRevision); - } - block = block.next(); - } - } - d->m_extraArea->update(); -} - -void BaseTextEditor::slotUpdateBlockNotify(const QTextBlock &block) -{ - static bool blockRecursion = false; - if (blockRecursion) - return; - if (block.previous().isValid() && block.userState() != block.previous().userState()) { - /* The syntax highlighting state changes. This opens up for - the possibility that the paragraph has braces that support - code folding. In this case, do the save thing and also - update the previous block, which might contain a collapse - box which now is invalid.*/ - blockRecursion = true; - emit requestBlockUpdate(block.previous()); - blockRecursion = false; - } -} - -void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy) -{ - if (dy) - d->m_extraArea->scroll(0, dy); - else if (r.width() > 4) { // wider than cursor width, not just cursor blinking - d->m_extraArea->update(0, r.y(), d->m_extraArea->width(), r.height()); - } - - if (r.contains(viewport()->rect())) - slotUpdateExtraAreaWidth(); -} - - -void BaseTextEditor::setCollapseIndicatorAlpha(int alpha) +void BaseTextEditor::slotUpdateExtraAreaWidth() { - d->extraAreaCollapseAlpha = alpha; - d->m_extraArea->update(); + if (isLeftToRight()) + setViewportMargins(extraAreaWidth(), 0, 0, 0); + else + setViewportMargins(0, 0, extraAreaWidth(), 0); } void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) @@ -2372,6 +2284,85 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) } } +void BaseTextEditor::slotModificationChanged(bool m) +{ + if (m) + return; + + QTextDocument *doc = document(); + TextEditDocumentLayout *documentLayout = qobject_cast<TextEditDocumentLayout*>(doc->documentLayout()); + QTC_ASSERT(documentLayout, return); + int oldLastSaveRevision = documentLayout->lastSaveRevision; + documentLayout->lastSaveRevision = doc->revision(); + + if (oldLastSaveRevision != documentLayout->lastSaveRevision) { + QTextBlock block = doc->begin(); + while (block.isValid()) { + if (block.revision() < 0 || block.revision() != oldLastSaveRevision) { + block.setRevision(-documentLayout->lastSaveRevision - 1); + } else { + block.setRevision(documentLayout->lastSaveRevision); + } + block = block.next(); + } + } + d->m_extraArea->update(); +} + +void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy) +{ + if (dy) + d->m_extraArea->scroll(0, dy); + else if (r.width() > 4) { // wider than cursor width, not just cursor blinking + d->m_extraArea->update(0, r.y(), d->m_extraArea->width(), r.height()); + } + + if (r.contains(viewport()->rect())) + slotUpdateExtraAreaWidth(); +} + +void BaseTextEditor::slotCursorPositionChanged() +{ + QList<QTextEdit::ExtraSelection> extraSelections; + setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear + if (d->m_parenthesesMatchingEnabled) + d->m_parenthesesMatchingTimer->start(50); + + if (d->m_highlightCurrentLine) { + QTextEdit::ExtraSelection sel; + sel.format.setBackground(d->m_currentLineFormat.background()); + sel.format.setProperty(QTextFormat::FullWidthSelection, true); + sel.cursor = textCursor(); + sel.cursor.clearSelection(); + extraSelections.append(sel); + } + + setExtraSelections(CurrentLineSelection, extraSelections); +} + +void BaseTextEditor::slotUpdateBlockNotify(const QTextBlock &block) +{ + static bool blockRecursion = false; + if (blockRecursion) + return; + if (block.previous().isValid() && block.userState() != block.previous().userState()) { + /* The syntax highlighting state changes. This opens up for + the possibility that the paragraph has braces that support + code folding. In this case, do the save thing and also + update the previous block, which might contain a collapse + box which now is invalid.*/ + blockRecursion = true; + emit requestBlockUpdate(block.previous()); + blockRecursion = false; + } +} + +void BaseTextEditor::setCollapseIndicatorAlpha(int alpha) +{ + d->extraAreaCollapseAlpha = alpha; + d->m_extraArea->update(); +} + void BaseTextEditor::timerEvent(QTimerEvent *e) { if (e->timerId() == d->autoScrollTimer.timerId()) { @@ -2563,25 +2554,6 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e) } } -void BaseTextEditor::slotCursorPositionChanged() -{ - QList<QTextEdit::ExtraSelection> extraSelections; - setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear - if (d->m_parenthesesMatchingEnabled) - d->m_parenthesesMatchingTimer->start(50); - - if (d->m_highlightCurrentLine) { - QTextEdit::ExtraSelection sel; - sel.format.setBackground(d->m_currentLineFormat.background()); - sel.format.setProperty(QTextFormat::FullWidthSelection, true); - sel.cursor = textCursor(); - sel.cursor.clearSelection(); - extraSelections.append(sel); - } - - setExtraSelections(CurrentLineSelection, extraSelections); -} - QTextBlock TextBlockUserData::testCollapse(const QTextBlock& block) { QTextBlock info = block; @@ -2825,50 +2797,6 @@ void BaseTextEditor::handleBackspaceKey() cursor.endEditBlock(); } - -void BaseTextEditor::format() -{ - QTextCursor cursor = textCursor(); - cursor.beginEditBlock(); - indent(document(), cursor, QChar::Null); - cursor.endEditBlock(); -} - -void BaseTextEditor::unCommentSelection() -{ -} - -void BaseTextEditor::setTabSettings(const TabSettings &ts) -{ - d->m_document->setTabSettings(ts); - int charWidth = QFontMetrics(font()).width(QChar(' ')); - setTabStopWidth(charWidth * ts.m_tabSize); -} - -void BaseTextEditor::setDisplaySettings(const DisplaySettings &ds) -{ - setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); - setLineNumbersVisible(ds.m_displayLineNumbers); - setVisibleWrapColumn(ds.m_showWrapColumn ? ds.m_wrapColumn : 0); - setCodeFoldingVisible(ds.m_displayFoldingMarkers); - setHighlightCurrentLine(ds.m_highlightCurrentLine); - - if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) { - if (QSyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter()) - highlighter->rehighlight(); - QTextOption option = document()->defaultTextOption(); - if (ds.m_visualizeWhitespace) - option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); - else - option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); - option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); - document()->setDefaultTextOption(option); - } - - d->m_displaySettings = ds; -} - - void BaseTextEditor::wheelEvent(QWheelEvent *e) { d->clearVisibleCollapsedBlock(); @@ -2945,7 +2873,8 @@ void BaseTextEditorPrivate::updateMarksLineNumber() } } -void BaseTextEditor::markBlocksAsChanged(QList<int> blockNumbers) { +void BaseTextEditor::markBlocksAsChanged(QList<int> blockNumbers) +{ QTextBlock block = document()->begin(); while (block.isValid()) { if (block.revision() < 0) @@ -3386,17 +3315,101 @@ void BaseTextEditor::setIfdefedOutBlocks(const QList<BaseTextEditor::BlockRange> documentLayout->requestUpdate(); } +void BaseTextEditor::format() +{ + QTextCursor cursor = textCursor(); + cursor.beginEditBlock(); + indent(document(), cursor, QChar::Null); + cursor.endEditBlock(); +} + +void BaseTextEditor::unCommentSelection() +{ +} -void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible) +void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs) { - QTextCursor cursor = q->textCursor(); - if (!cursor.block().isVisible()) { - cursor.setVisualNavigation(true); - cursor.movePosition(QTextCursor::Up); - q->setTextCursor(cursor); + const QTextCharFormat textFormat = fs.toTextCharFormat(QLatin1String(Constants::C_TEXT)); + const QTextCharFormat selectionFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SELECTION)); + const QTextCharFormat lineNumberFormat = fs.toTextCharFormat(QLatin1String(Constants::C_LINE_NUMBER)); + const QTextCharFormat searchResultFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_RESULT)); + const QTextCharFormat searchScopeFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_SCOPE)); + const QTextCharFormat parenthesesFormat = fs.toTextCharFormat(QLatin1String(Constants::C_PARENTHESES)); + const QTextCharFormat currentLineFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE)); + const QTextCharFormat ifdefedOutFormat = fs.toTextCharFormat(QLatin1String(Constants::C_DISABLED_CODE)); + QFont font(textFormat.font()); + + const QColor foreground = textFormat.foreground().color(); + const QColor background = textFormat.background().color(); + QPalette p = palette(); + p.setColor(QPalette::Text, foreground); + p.setColor(QPalette::Foreground, foreground); + p.setColor(QPalette::Base, background); + p.setColor(QPalette::Highlight, (selectionFormat.background().style() != Qt::NoBrush) ? + selectionFormat.background().color() : + QApplication::palette().color(QPalette::Highlight)); + p.setColor(QPalette::HighlightedText, selectionFormat.foreground().color()); + p.setBrush(QPalette::Inactive, QPalette::Highlight, p.highlight()); + p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText()); + setPalette(p); + setFont(font); + setTabSettings(d->m_document->tabSettings()); // update tabs, they depend on the font + + // Line numbers + QPalette ep = d->m_extraArea->palette(); + ep.setColor(QPalette::Dark, lineNumberFormat.foreground().color()); + ep.setColor(QPalette::Background, lineNumberFormat.background().style() != Qt::NoBrush ? + lineNumberFormat.background().color() : background); + d->m_extraArea->setPalette(ep); + + // Search results + d->m_searchResultFormat.setBackground(searchResultFormat.background()); + d->m_searchScopeFormat.setBackground(searchScopeFormat.background()); + d->m_currentLineFormat.setBackground(currentLineFormat.background()); + + // Matching braces + d->m_matchFormat.setForeground(parenthesesFormat.foreground()); + d->m_rangeFormat.setBackground(parenthesesFormat.background()); + + // Disabled code + d->m_ifdefedOutFormat.setForeground(ifdefedOutFormat.foreground()); + + slotUpdateExtraAreaWidth(); +} + +void BaseTextEditor::setTabSettings(const TabSettings &ts) +{ + d->m_document->setTabSettings(ts); + int charWidth = QFontMetrics(font()).width(QChar(' ')); + setTabStopWidth(charWidth * ts.m_tabSize); +} + +void BaseTextEditor::setDisplaySettings(const DisplaySettings &ds) +{ + setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); + setLineNumbersVisible(ds.m_displayLineNumbers); + setVisibleWrapColumn(ds.m_showWrapColumn ? ds.m_wrapColumn : 0); + setCodeFoldingVisible(ds.m_displayFoldingMarkers); + setHighlightCurrentLine(ds.m_highlightCurrentLine); + + if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) { + if (QSyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter()) + highlighter->rehighlight(); + QTextOption option = document()->defaultTextOption(); + if (ds.m_visualizeWhitespace) + option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); + else + option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); + option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); + document()->setDefaultTextOption(option); } - if (ensureVisible) - q->ensureCursorVisible(); + + d->m_displaySettings = ds; +} + +void BaseTextEditor::setStorageSettings(const StorageSettings &storageSettings) +{ + d->m_document->setStorageSettings(storageSettings); } void BaseTextEditor::collapse() diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 24b5382b79e2c342909aaf3bbe19c94191d1fb58..1813f4e4a91c0e86247db315e3499a1f36dacb2e 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -68,6 +68,7 @@ struct StorageSettings; struct Parenthesis; typedef QVector<Parenthesis> Parentheses; + struct TEXTEDITOR_EXPORT Parenthesis { enum Type { Opened, Closed }; @@ -84,7 +85,6 @@ struct TEXTEDITOR_EXPORT Parenthesis }; - class TEXTEDITOR_EXPORT TextBlockUserData : public QTextBlockUserData { public: @@ -285,6 +285,9 @@ public: void setCodeFoldingVisible(bool b); bool codeFoldingVisible() const; + void setCodeFoldingSupported(bool b); + bool codeFoldingSupported() const; + void setRevisionsVisible(bool b); bool revisionsVisible() const; @@ -303,10 +306,6 @@ public: public slots: void setDisplayName(const QString &title); - virtual void setFontSettings(const TextEditor::FontSettings &); - virtual void format(); - virtual void unCommentSelection(); - virtual void setStorageSettings(const TextEditor::StorageSettings &); void paste(); void cut(); @@ -352,6 +351,7 @@ protected: public: void duplicateFrom(BaseTextEditor *editor); + protected: BaseTextDocument *baseTextDocument() const; void setBaseTextDocument(BaseTextDocument *doc); @@ -377,8 +377,8 @@ public: QWidget *extraArea() const; virtual int extraAreaWidth(int *markWidthPtr = 0) const; virtual void extraAreaPaintEvent(QPaintEvent *); - virtual void extraAreaMouseEvent(QMouseEvent *); virtual void extraAreaLeaveEvent(QEvent *); + virtual void extraAreaMouseEvent(QMouseEvent *); const TabSettings &tabSettings() const; const DisplaySettings &displaySettings() const; @@ -415,8 +415,12 @@ public: void setIfdefedOutBlocks(const QList<BlockRange> &blocks); public slots: + virtual void format(); + virtual void unCommentSelection(); + virtual void setFontSettings(const TextEditor::FontSettings &); virtual void setTabSettings(const TextEditor::TabSettings &); virtual void setDisplaySettings(const TextEditor::DisplaySettings &); + virtual void setStorageSettings(const TextEditor::StorageSettings &); protected: bool viewportEvent(QEvent *event); @@ -434,7 +438,6 @@ protected: // Indent at cursor. Calls indentBlock for selection or current line. virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar); - protected slots: virtual void slotUpdateExtraAreaWidth(); virtual void slotModificationChanged(bool); diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 1fa3a46d063025b505243f8792dd743f3c02432f..9609d3c6ea14c541583f39fb892b904053300792 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -180,6 +180,7 @@ public: void updateMarksBlock(const QTextBlock &block); uint m_marksVisible : 1; uint m_codeFoldingVisible : 1; + uint m_codeFoldingSupported : 1; uint m_revisionsVisible : 1; uint m_lineNumbersVisible : 1; uint m_highlightCurrentLine : 1; diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 8557e4431d46c830a2f00bb97291f0f4bef26a9e..edb7349eb01ca3c9d51792770d2510bc6417383b 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -88,7 +88,7 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context, m_contextId << Core::UniqueIDManager::instance()->uniqueIdentifier(context); connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), - this, SLOT(updateCurrentEditor(Core::IEditor *))); + this, SLOT(updateCurrentEditor(Core::IEditor*))); } void TextEditorActionHandler::setupActions(BaseTextEditor *editor) diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 15c1b61668020638b89c1a378174768c2da76a10..bd9556d8328b60b487cc76a597ca1fe76b79886a 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -140,26 +140,12 @@ void TextEditorPlugin::extensionsInitialized() m_editorFactory->actionHandler()->initializeActions(); } -void TextEditorPlugin::initializeEditor(TextEditor::PlainTextEditor *editor) +void TextEditorPlugin::initializeEditor(PlainTextEditor *editor) { // common actions m_editorFactory->actionHandler()->setupActions(editor); - // settings - connect(m_settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), - editor, SLOT(setFontSettings(TextEditor::FontSettings))); - connect(m_settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), - editor, SLOT(setTabSettings(TextEditor::TabSettings))); - connect(m_settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), - editor, SLOT(setStorageSettings(TextEditor::StorageSettings))); - connect(m_settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), - editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); - - // tab settings rely on font settings - editor->setFontSettings(m_settings->fontSettings()); - editor->setTabSettings(m_settings->tabSettings()); - editor->setStorageSettings(m_settings->storageSettings()); - editor->setDisplaySettings(m_settings->displaySettings()); + TextEditorSettings::instance()->initializeEditor(editor); } void TextEditorPlugin::invokeCompletion() diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index d81f27a089ea34021b4379e597315fa74087a97c..cc55dec6b24c6726a8c1abd655bd36a98d6a394d 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -29,6 +29,7 @@ #include "texteditorsettings.h" +#include "basetexteditor.h" #include "behaviorsettingspage.h" #include "displaysettings.h" #include "displaysettingspage.h" @@ -138,6 +139,29 @@ TextEditorSettings *TextEditorSettings::instance() return m_instance; } +/** + * Initializes editor settings. Also connects signals to keep them up to date + * when they are changed. + */ +void TextEditorSettings::initializeEditor(BaseTextEditor *editor) +{ + // Connect to settings change signals + connect(this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), + editor, SLOT(setFontSettings(TextEditor::FontSettings))); + connect(this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), + editor, SLOT(setTabSettings(TextEditor::TabSettings))); + connect(this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), + editor, SLOT(setStorageSettings(TextEditor::StorageSettings))); + connect(this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), + editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); + + // Apply current settings (tab settings depend on font settings) + editor->setFontSettings(fontSettings()); + editor->setTabSettings(tabSettings()); + editor->setStorageSettings(storageSettings()); + editor->setDisplaySettings(displaySettings()); +} + FontSettings TextEditorSettings::fontSettings() const { return m_fontSettingsPage->fontSettings(); diff --git a/src/plugins/texteditor/texteditorsettings.h b/src/plugins/texteditor/texteditorsettings.h index 1abf92441ab5f7bdb75ab1d39cbdb18b28e94479..e3987efddbfc4f66dc17ad0b324d81071e2d7b3c 100644 --- a/src/plugins/texteditor/texteditorsettings.h +++ b/src/plugins/texteditor/texteditorsettings.h @@ -36,6 +36,7 @@ namespace TextEditor { +class BaseTextEditor; class BehaviorSettingsPage; class DisplaySettingsPage; class FontSettingsPage; @@ -59,6 +60,8 @@ public: static TextEditorSettings *instance(); + void initializeEditor(BaseTextEditor *editor); + FontSettings fontSettings() const; TabSettings tabSettings() const; StorageSettings storageSettings() const;