Commit 4b30b30d authored by Eike Ziller's avatar Eike Ziller

Merge remote-tracking branch 'origin/master' into 4.0

Change-Id: Iad8f5ab4bc44e890cd0c72d5bcbceb6f18f6e995
parents bc9ffac3 2d7f9c56
......@@ -7,8 +7,8 @@ DefaultTextEditorColorScheme=dark.xml
shadowBackground=ff232323
text=ffe7e7e7
textDisabled=7fffffff
hoverBackground=35ffffff
selectedBackground=66000000
hoverBackground=ff515151
selectedBackground=ff151515
normalBackground=ff333333
alternateBackground=ff515151
error=ffff0000
......@@ -19,7 +19,7 @@ BackgroundColorDark=shadowBackground
BackgroundColorHover=hoverBackground
BackgroundColorNormal=normalBackground
BackgroundColorDisabled=ff444444
BackgroundColorSelected=7effffff
BackgroundColorSelected=ff909090
BadgeLabelBackgroundColorChecked=normalBackground
BadgeLabelBackgroundColorUnchecked=selectedBackground
BadgeLabelTextColorChecked=text
......@@ -46,8 +46,8 @@ FancyTabWidgetDisabledSelectedTextColor=textDisabled
FancyTabWidgetDisabledUnselectedTextColor=textDisabled
FancyTabWidgetEnabledSelectedTextColor=text
FancyTabWidgetEnabledUnselectedTextColor=text
FancyToolButtonHoverColor=hoverBackground
FancyToolButtonSelectedColor=selectedBackground
FancyToolButtonHoverColor=35ffffff
FancyToolButtonSelectedColor=7effffff
FutureProgressBackgroundColor=shadowBackground
IconsBaseColor=ffdcdcdc
IconsDisabledColor=textDisabled
......
include(../../qtcreatorlibrary.pri)
QT += svg
!isEmpty(QT.svg.name): QT += svg
else: DEFINES += QT_NO_SVG
DEFINES += QMT_LIBRARY
......
......@@ -9,9 +9,15 @@ QtcLibrary {
"./qtserialization/inc",
])
Depends { name: "Qt"; submodules: ["widgets", "svg"] }
Depends { name: "Qt"; submodules: ["widgets"] }
Depends { name: "Qt.svg"; required: false }
Depends { name: "Utils" }
Properties {
condition: !Qt.svg.present
cpp.defines: base.concat("QT_NO_SVG")
}
Group {
name: "Qmt"
prefix: "./qmt/"
......
......@@ -59,7 +59,9 @@
#include <QPdfWriter>
#include <QFile>
#ifndef QT_NO_SCG
#include <QtSvg/QSvgGenerator>
#endif
namespace qmt {
......@@ -339,59 +341,6 @@ void DiagramSceneModel::copyToClipboard()
mimeData->setImageData(image);
}
#ifdef USE_PDF_CLIPBOARD
{
const double scaleFactor = 1.0;
const double border = 5;
const double baseDpi = 100;
const double dotsPerMm = 25.4 / baseDpi;
QBuffer pdfBuffer;
pdfBuffer.open(QIODevice::WriteOnly);
QPdfWriter pdfWriter(&pdfBuffer);
QSizeF pageSize = sceneBoundingRect.size();
pageSize += QSizeF(2.0 * border, 2.0 * border);
pageSize *= scaleFactor;
pdfWriter.setPageSize(QPdfWriter::Custom);
pdfWriter.setPageSizeMM(pageSize * dotsPerMm);
QPainter pdfPainter;
pdfPainter.begin(&pdfWriter);
m_graphicsScene->render(&pdfPainter,
QRectF(border, border,
pdfPainter.device()->width() - 2 * border,
pdfPainter.device()->height() - 2 * border),
sceneBoundingRect);
pdfPainter.end();
pdfBuffer.close();
mimeData->setData(QStringLiteral("application/pdf"), pdfBuffer.buffer());
}
#endif
#ifdef USE_SVG_CLIPBOARD
{
const double border = 5;
QBuffer svgBuffer;
QSvgGenerator svgGenerator;
svgGenerator.setOutputDevice(&svgBuffer);
QSize svgSceneSize = sceneBoundingRect.size().toSize();
svgGenerator.setSize(svgSceneSize);
svgGenerator.setViewBox(QRect(QPoint(0,0), svgSceneSize));
QPainter svgPainter;
svgPainter.begin(&svgGenerator);
svgPainter.setRenderHint(QPainter::Antialiasing);
m_graphicsScene->render(&svgPainter,
QRectF(border, border,
svgPainter.device()->width() - 2 * border,
svgPainter.device()->height() - 2 * border),
sceneBoundingRect);
svgPainter.end();
mimeData->setData(QStringLiteral("image/svg+xml"), svgBuffer.buffer());
}
#endif
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
if (!copyAll) {
......@@ -489,6 +438,7 @@ bool DiagramSceneModel::exportPdf(const QString &fileName)
bool DiagramSceneModel::exportSvg(const QString &fileName)
{
#ifndef QT_NO_SVG
// TODO support exporting selected elements only
removeExtraSceneItems();
......@@ -515,6 +465,10 @@ bool DiagramSceneModel::exportSvg(const QString &fileName)
// TODO how to know that file was successfully created?
return true;
#else // QT_NO_SVG
Q_UNUSED(fileName);
return false;
#endif // QT_NO_SVG
}
void DiagramSceneModel::selectItem(QGraphicsItem *item, bool multiSelect)
......
......@@ -542,17 +542,10 @@ void IconButton::paintEvent(QPaintEvent *)
void IconButton::animateShow(bool visible)
{
if (visible) {
QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
animation->setDuration(FADE_TIME);
animation->setEndValue(1.0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
animation->setDuration(FADE_TIME);
animation->setEndValue(0.0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
animation->setDuration(FADE_TIME);
animation->setEndValue(visible ? 1.0 : 0.0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
QSize IconButton::sizeHint() const
......
......@@ -440,11 +440,11 @@ bool GoogleTestTreeItem::modifyTestSetContent(const QString &fileName,
TestTreeItem *GoogleTestTreeItem::findChildByNameStateAndFile(const QString &name,
GoogleTestTreeItem::TestStates state,
const QString &referencingFile)
const QString &proFile)
{
return findChildBy([name, state, referencingFile](const TestTreeItem *other) -> bool {
return findChildBy([name, state, proFile](const TestTreeItem *other) -> bool {
GoogleTestTreeItem *gtestItem = const_cast<TestTreeItem *>(other)->asGoogleTestTreeItem();
return other->proFile() == referencingFile
return other->proFile() == proFile
&& other->name() == name
&& gtestItem->state() == state;
});
......
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include <QSignalMapper>
namespace Core { class IEditor; }
namespace TextEditor { class TextEditorWidget; }
namespace Beautifier {
namespace Internal {
......@@ -44,6 +45,10 @@ class BeautifierAbstractTool;
struct FormatTask
{
FormatTask() :
startPos(-1),
endPos(0) {}
FormatTask(QPlainTextEdit *_editor, const QString &_filePath, const QString &_sourceData,
const Command &_command, int _startPos = -1, int _endPos = 0) :
editor(_editor),
......@@ -51,8 +56,7 @@ struct FormatTask
sourceData(_sourceData),
command(_command),
startPos(_startPos),
endPos(_endPos),
timeout(false) {}
endPos(_endPos) {}
QPointer<QPlainTextEdit> editor;
QString filePath;
......@@ -60,8 +64,8 @@ struct FormatTask
Command command;
int startPos;
int endPos;
bool timeout;
QString formattedData;
QString error;
};
class BeautifierPlugin : public ExtensionSystem::IPlugin
......@@ -70,35 +74,30 @@ class BeautifierPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Beautifier.json")
public:
BeautifierPlugin();
~BeautifierPlugin();
bool initialize(const QStringList &arguments, QString *errorString) override;
void extensionsInitialized() override;
ShutdownFlag aboutToShutdown() override;
QString format(const QString &text, const Command &command, const QString &fileName,
bool *timeout = 0);
void formatCurrentFile(const Command &command, int startPos = -1, int endPos = 0);
void formatAsync(QFutureInterface<FormatTask> &future, FormatTask task);
static QString msgCannotGetConfigurationFile(const QString &command);
static QString msgFormatCurrentFile();
static QString msgFormatSelectedText();
static QString msgCommandPromptDialogTitle(const QString &command);
public slots:
static void showError(const QString &error);
private slots:
void updateActions(Core::IEditor *editor = 0);
void formatCurrentFileContinue(QObject *watcher = 0);
signals:
void pipeError(QString);
private:
QList<BeautifierAbstractTool *> m_tools;
QSignalMapper *m_asyncFormatMapper;
void formatEditor(TextEditor::TextEditorWidget *editor, const Command &command,
int startPos = -1, int endPos = 0);
void formatEditorAsync(TextEditor::TextEditorWidget *editor, const Command &command,
int startPos = -1, int endPos = 0);
void checkAndApplyTask(const FormatTask &task);
void updateEditorText(QPlainTextEdit *editor, const QString &text);
};
} // namespace Internal
......
......@@ -300,8 +300,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
if (selected) {
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
// background color of a fancy tab that is active
painter->fillRect(rect.adjusted(0, 0, 0, -1),
creatorTheme()->color(Theme::BackgroundColorSelected));
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonSelectedColor));
} else {
paintSelectedTabBackground(painter, rect);
}
......@@ -324,7 +323,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->save();
painter->setOpacity(fader);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
painter->fillRect(rect, creatorTheme()->color(Theme::BackgroundColorHover));
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
else
FancyToolButton::hoverOverlay(painter, rect);
painter->restore();
......
......@@ -48,6 +48,7 @@
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cppeditoroutline.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cppselectionchanger.h>
#include <cpptools/cppsemanticinfo.h>
#include <cpptools/cpptoolsconstants.h>
#include <cpptools/cpptoolsplugin.h>
......@@ -55,6 +56,7 @@
#include <cpptools/cppworkingcopy.h>
#include <cpptools/symbolfinder.h>
#include <texteditor/behaviorsettings.h>
#include <texteditor/completionsettings.h>
#include <texteditor/convenience.h>
#include <texteditor/textdocument.h>
......@@ -119,6 +121,8 @@ public:
QScopedPointer<FollowSymbolUnderCursor> m_followSymbolUnderCursor;
QToolButton *m_preprocessorButton;
CppSelectionChanger m_cppSelectionChanger;
};
CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q)
......@@ -130,6 +134,7 @@ CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q)
, m_declDefLinkFinder(new FunctionDeclDefLinkFinder(q))
, m_followSymbolUnderCursor(new FollowSymbolUnderCursor(q))
, m_preprocessorButton(0)
, m_cppSelectionChanger()
{
}
......@@ -201,6 +206,9 @@ void CppEditorWidget::finalizeInitialization()
connect(this, &CppEditorWidget::cursorPositionChanged, [this]() {
if (!d->m_localRenaming.isActive())
d->m_useSelectionsUpdater.scheduleUpdate();
// Notify selection expander about the changed cursor.
d->m_cppSelectionChanger.onCursorPositionChanged(textCursor());
});
// Tool bar creation
......@@ -328,6 +336,44 @@ void CppEditorWidget::renameUsages(const QString &replacement)
}
}
bool CppEditorWidget::selectBlockUp()
{
if (!behaviorSettings().m_smartSelectionChanging)
return TextEditorWidget::selectBlockUp();
QTextCursor cursor = textCursor();
d->m_cppSelectionChanger.startChangeSelection();
const bool changed =
d->m_cppSelectionChanger.changeSelection(
CppSelectionChanger::ExpandSelection,
cursor,
d->m_lastSemanticInfo.doc);
if (changed)
setTextCursor(cursor);
d->m_cppSelectionChanger.stopChangeSelection();
return changed;
}
bool CppEditorWidget::selectBlockDown()
{
if (!behaviorSettings().m_smartSelectionChanging)
return TextEditorWidget::selectBlockDown();
QTextCursor cursor = textCursor();
d->m_cppSelectionChanger.startChangeSelection();
const bool changed =
d->m_cppSelectionChanger.changeSelection(
CppSelectionChanger::ShrinkSelection,
cursor,
d->m_lastSemanticInfo.doc);
if (changed)
setTextCursor(cursor);
d->m_cppSelectionChanger.stopChangeSelection();
return changed;
}
void CppEditorWidget::renameSymbolUnderCursor()
{
d->m_useSelectionsUpdater.abortSchedule();
......
......@@ -92,6 +92,9 @@ public slots:
void renameSymbolUnderCursor();
void renameUsages(const QString &replacement = QString());
bool selectBlockUp() override;
bool selectBlockDown() override;
protected:
bool event(QEvent *e) override;
void contextMenuEvent(QContextMenuEvent *) override;
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef CPPSELECTIONCHANGER_H
#define CPPSELECTIONCHANGER_H
#include "cpptools_global.h"
#include <cplusplus/ASTPath.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/TranslationUnit.h>
#include <QObject>
#include <QTextCursor>
namespace CppTools {
class ASTNodePositions {
public:
ASTNodePositions() {}
ASTNodePositions(CPlusPlus::AST *_ast) : ast(_ast) {}
operator bool() const { return ast; }
CPlusPlus::AST *ast = 0;
unsigned firstTokenIndex = 0;
unsigned lastTokenIndex = 0;
unsigned secondToLastTokenIndex = 0;
int astPosStart = -1;
int astPosEnd = -1;
};
class CPPTOOLS_EXPORT CppSelectionChanger : public QObject
{
Q_OBJECT
public:
explicit CppSelectionChanger(QObject *parent = 0);
enum Direction {
ExpandSelection,
ShrinkSelection
};
enum NodeIndexAndStepState {
NodeIndexAndStepNotSet,
NodeIndexAndStepWholeDocument,
};
bool changeSelection(Direction direction,
QTextCursor &cursorToModify,
const CPlusPlus::Document::Ptr doc);
void startChangeSelection();
void stopChangeSelection();
public slots:
void onCursorPositionChanged(const QTextCursor &newCursor);
protected slots:
void fineTuneForStatementPositions(unsigned firstParensTokenIndex,
unsigned lastParensTokenIndex,
ASTNodePositions &positions) const;
private:
bool performSelectionChange(QTextCursor &cursorToModify);
ASTNodePositions getASTPositions(CPlusPlus::AST *ast, const QTextCursor &cursor) const;
void updateCursorSelection(QTextCursor &cursorToModify, ASTNodePositions positions);
int possibleASTStepCount(CPlusPlus::AST *ast) const;
int currentASTStep() const;
ASTNodePositions findNextASTStepPositions(const QTextCursor &cursor);
void fineTuneASTNodePositions(ASTNodePositions &positions) const;
ASTNodePositions getFineTunedASTPositions(CPlusPlus::AST *ast, const QTextCursor &cursor) const;
int getFirstCurrentStepForASTNode(CPlusPlus::AST *ast) const;
bool isLastPossibleStepForASTNode(CPlusPlus::AST *ast) const;
ASTNodePositions findRelevantASTPositionsFromCursor(const QList<CPlusPlus::AST *> &astPath,
const QTextCursor &cursor,
int startingFromNodeIndex = -1);
ASTNodePositions findRelevantASTPositionsFromCursorWhenNodeIndexNotSet(
const QList<CPlusPlus::AST *> astPath,
const QTextCursor &cursor);
ASTNodePositions findRelevantASTPositionsFromCursorWhenWholeDocumentSelected(
const QList<CPlusPlus::AST *> astPath,
const QTextCursor &cursor);
ASTNodePositions findRelevantASTPositionsFromCursorFromPreviousNodeIndex(
const QList<CPlusPlus::AST *> astPath,
const QTextCursor &cursor);
bool shouldSkipASTNodeBasedOnPosition(const ASTNodePositions &positions,
const QTextCursor &cursor) const;
void setNodeIndexAndStep(NodeIndexAndStepState state);
int getTokenStartCursorPosition(unsigned tokenIndex, const QTextCursor &cursor) const;
int getTokenEndCursorPosition(unsigned tokenIndex, const QTextCursor &cursor) const;
void printTokenDebugInfo(unsigned tokenIndex, const QTextCursor &cursor, QString prefix) const;
QTextCursor m_initialChangeSelectionCursor;
QTextCursor m_workingCursor;
CPlusPlus::Document::Ptr m_doc;
CPlusPlus::TranslationUnit *m_unit;
Direction m_direction;
int m_changeSelectionNodeIndex;
int m_nodeCurrentStep;
bool m_inChangeSelection;
};
} // namespace CppTools
#endif // CPPSELECTIONCHANGER_H
......@@ -245,7 +245,8 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ
if (it != m_fileNameCache.constEnd())
return it.value();
const QString fn = resolveFile_helper(fileName, type);
m_fileNameCache.insert(fileName, fn);
if (!fn.isEmpty())
m_fileNameCache.insert(fileName, fn);
return fn;
}
......
......@@ -43,6 +43,7 @@ HEADERS += \
cppprojectfile.h \
cppqtstyleindenter.h \
cpprefactoringchanges.h \
cppselectionchanger.h \
cppsemanticinfo.h \
cppsemanticinfoupdater.h \
cppsourceprocessor.h \
......@@ -117,6 +118,7 @@ SOURCES += \
cppprojectfile.cpp \
cppqtstyleindenter.cpp \
cpprefactoringchanges.cpp \
cppselectionchanger.cpp \
cppsemanticinfo.cpp \
cppsemanticinfoupdater.cpp \
cppsourceprocessor.cpp \
......
......@@ -66,6 +66,7 @@ QtcPlugin {
"cppprojectfile.cpp", "cppprojectfile.h",
"cppqtstyleindenter.cpp", "cppqtstyleindenter.h",
"cpprefactoringchanges.cpp", "cpprefactoringchanges.h",
"cppselectionchanger.cpp", "cppselectionchanger.h",
"cppsemanticinfo.cpp", "cppsemanticinfo.h",
"cppsemanticinfoupdater.cpp", "cppsemanticinfoupdater.h",
"cppsourceprocessor.cpp", "cppsourceprocessor.h",
......
......@@ -524,10 +524,13 @@ void ModelEditor::exportDiagram()
if (diagram) {
if (d->lastExportDirPath.isEmpty())
d->lastExportDirPath = d->document->filePath().toFileInfo().canonicalPath();
QString filter = tr("Images (*.png *.jpeg *.jpg *.tif *.tiff);;PDF (*.pdf)");
#ifndef QT_NO_SVG
filter += tr(";;SVG (*.svg)");
#endif // QT_NO_SVG
QString fileName = QFileDialog::getSaveFileName(
Core::ICore::dialogParent(),
tr("Export Diagram"), d->lastExportDirPath,
tr("Images (*.png *.jpeg *.jpg *.tif *.tiff);;PDF (*.pdf);;SVG (*.svg)"));
tr("Export Diagram"), d->lastExportDirPath, filter);
if (!fileName.isEmpty()) {
qmt::DocumentController *documentController = d->document->documentController();
qmt::DiagramSceneModel *sceneModel = documentController->diagramsManager()->diagramSceneModel(diagram);
......@@ -535,13 +538,15 @@ void ModelEditor::exportDiagram()
QString suffix = QFileInfo(fileName).suffix().toLower();
// TODO use QFileDialog::selectedNameFilter() as fallback if no suffix is given
if (suffix.isEmpty()) {
suffix = QStringLiteral(".png");
fileName += suffix;
suffix = QStringLiteral("png");
fileName += QStringLiteral(".png");
}
if (suffix == QStringLiteral(".pdf"))
if (suffix == QStringLiteral("pdf"))
success = sceneModel->exportPdf(fileName);
else if (suffix == QStringLiteral(".svg"))
#ifndef QT_NO_SVG
else if (suffix == QStringLiteral("svg"))
success = sceneModel->exportSvg(fileName);
#endif // QT_NO_SVG
else
success = sceneModel->exportImage(fileName);
if (success)
......
......@@ -4,27 +4,7 @@ DEFINES += MODELEDITOR_LIBRARY
QT += core gui widgets
!win32:CONFIG(pdf) {
DEFINES += USE_PDF_CLIPBOARD
}
!win32:CONFIG(svg): {
QT += svg
DEFINES += USE_SVG_CLIPBOARD
}
#win32:CONFIG(emf): {
# DEFINES += USE_EMF USE_EMF_CLIPBOARD
#
# SOURCES += \
# emf-engine/qemfpaintengine.cpp \
# emf-engine/qemfwriter.cpp
#
# HEADERS += \
# emf-engine/qemfpaintengine.h \
# emf-engine/qemfwriter.h
#
#}
isEmpty(QT.svg.name): DEFINES += QT_NO_SVG
SOURCES += \
actionhandler.cpp \
......
......@@ -6,12 +6,18 @@ QtcPlugin {
name: "ModelEditor"
Depends { name: "Qt.widgets" }
Depends { name: "Qt.svg"; required: false }
Depends { name: "Core" }