summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor/diffshoweditor.cpp
blob: b8d732d0cbb6c1c1bde244873344fda3b5abec10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "diffshoweditor.h"
#include "diffeditorconstants.h"

#include <QToolBar>
#include <QToolButton>
#include <QCoreApplication>

#include <coreplugin/coreconstants.h>
#include <coreplugin/minisplitter.h>

#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/displaysettings.h>

using namespace TextEditor;

namespace DiffEditor {

namespace Internal {

class DiffShowEditorWidgetEditable : public BaseTextEditor
{
    Q_OBJECT
public:
    DiffShowEditorWidgetEditable(BaseTextEditorWidget *editorWidget) : BaseTextEditor(editorWidget) {}

    Core::Id id() const { return "DiffShowViewEditor"; }
};

class DiffShowEditorWidget : public BaseTextEditorWidget
{
    Q_OBJECT
public:
    DiffShowEditorWidget(QWidget *parent = 0);
    virtual QSize sizeHint() const;

public slots:
    void setDisplaySettings(const DisplaySettings &ds);

protected:
    BaseTextEditor *createEditor() { return new DiffShowEditorWidgetEditable(this); }

private:
};

DiffShowEditorWidget::DiffShowEditorWidget(QWidget *parent)
    : BaseTextEditorWidget(parent)
{
    DisplaySettings settings = displaySettings();
    settings.m_textWrapping = false;
    settings.m_displayLineNumbers = false;
    settings.m_highlightCurrentLine = false;
    settings.m_displayFoldingMarkers = false;
    settings.m_markTextChanges = false;
    settings.m_highlightBlocks = false;
    BaseTextEditorWidget::setDisplaySettings(settings);

    setCodeFoldingSupported(true);
    setFrameStyle(QFrame::NoFrame);

    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}

QSize DiffShowEditorWidget::sizeHint() const
{
    QSize size = BaseTextEditorWidget::sizeHint();
    size.setHeight(size.height() / 5);
    return size;
}

void DiffShowEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{
    DisplaySettings settings = displaySettings();
    settings.m_visualizeWhitespace = ds.m_visualizeWhitespace;
    BaseTextEditorWidget::setDisplaySettings(settings);
}

} // namespace Internal

DiffShowEditor::DiffShowEditor(DiffEditorWidget *editorWidget)
    : DiffEditor(editorWidget)
{
    document()->setDisplayName(QCoreApplication::translate("DiffShowEditor",
                                                           Constants::DIFF_SHOW_EDITOR_DISPLAY_NAME));
    QSplitter *splitter = new Core::MiniSplitter(Qt::Vertical);
    m_diffShowWidget = new Internal::DiffShowEditorWidget(splitter);
    m_diffShowWidget->setReadOnly(true);
    splitter->addWidget(m_diffShowWidget);
    splitter->addWidget(editorWidget);
    setWidget(splitter);

    connect(TextEditorSettings::instance(), SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
            m_diffShowWidget, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
    connect(TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
            m_diffShowWidget, SLOT(setFontSettings(TextEditor::FontSettings)));
    m_diffShowWidget->setDisplaySettings(TextEditorSettings::displaySettings());
    m_diffShowWidget->setCodeStyle(TextEditorSettings::codeStyle());
    m_diffShowWidget->setFontSettings(TextEditorSettings::fontSettings());
}

DiffShowEditor::~DiffShowEditor()
{
}

void DiffShowEditor::setDescription(const QString &description)
{
    m_diffShowWidget->setPlainText(description);
}

Core::Id DiffShowEditor::id() const
{
    return Constants::DIFF_SHOW_EDITOR_ID;
}

QWidget *DiffShowEditor::toolBar()
{
    if (m_toolWidget)
        return m_toolWidget;

    // Create
    DiffEditor::toolBar();

    m_toggleDescriptionButton = new QToolButton(m_toolWidget);
    m_toggleDescriptionButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_TOGGLE_TOPBAR)));
    m_toggleDescriptionButton->setCheckable(true);
    m_toggleDescriptionButton->setChecked(true);
    connect(m_toggleDescriptionButton, SIGNAL(clicked(bool)),
            this, SLOT(setDescriptionVisible(bool)));
    m_toolWidget->addWidget(m_toggleDescriptionButton);
    setDescriptionVisible(true);

    return m_toolWidget;
}

void DiffShowEditor::setDescriptionVisible(bool visible)
{
    if (visible)
        m_toggleDescriptionButton->setToolTip(tr("Hide Change Description"));
    else
        m_toggleDescriptionButton->setToolTip(tr("Show Change Description"));
    m_diffShowWidget->setVisible(visible);
}

} // namespace DiffEditor

#include "diffshoweditor.moc"