-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
97 lines (77 loc) · 2.28 KB
/
PluginEditor.cpp
File metadata and controls
97 lines (77 loc) · 2.28 KB
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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: BSD-3-Clause
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <QtCore/qloggingcategory.h>
#include <QtGui/qguiapplication.h>
Q_LOGGING_CATEGORY(qtEditor, "juce.qt.editor")
#if defined(QT_QUICK_LIB)
#include <QtQuick/qquickview.h>
class EditorWindow : public QQuickView
{
public:
EditorWindow()
{
setSource(QUrl("qrc:/main.qml"));
setResizeMode(QQuickView::SizeRootObjectToView);
}
};
#else // Plain QRasterWindow
#include <QtGui/qrasterwindow.h>
#include <QtGui/qpainter.h>
#include <QtGui/qfont.h>
class EditorWindow : public QRasterWindow
{
public:
EditorWindow()
{
resize(400, 200);
}
protected:
void paintEvent(QPaintEvent *) override
{
QPainter p(this);
p.fillRect(QRect(0, 0, width(), height()), QGradient::DustyGrass);
QFont font;
font.setPointSize(36);
p.setFont(font);
p.drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, QStringLiteral("Hello Qt 🥳"));
}
};
#endif
using namespace juce;
PluginEditor::PluginEditor(AudioProcessor& p)
: AudioProcessorEditor(p)
{
qCDebug(qtEditor) << "Creating editor" << this;
setResizable(true, false);
setWantsKeyboardFocus(true);
if (!qGuiApp) {
QCoreApplication::setAttribute(Qt::AA_PluginApplication);
static int argc = 1; static char *argv[] = { const_cast<char*>("") };
new QGuiApplication(argc, argv); // FIXME: Ref-count and dispose
}
m_qtComponent.setWindow(new EditorWindow);
addAndMakeVisible(m_qtComponent);
childBoundsChanged(&m_qtComponent);
}
PluginEditor::~PluginEditor()
{
qCDebug(qtEditor) << "Deleting editor" << this;
}
void PluginEditor::resized()
{
qCDebug(qtEditor) << "Editor" << this << "resized";
m_qtComponent.setBounds(getLocalBounds());
}
void PluginEditor::childBoundsChanged(Component*)
{
qCDebug(qtEditor) << "Editor" << this << "child bounds changed";
setSize(m_qtComponent.getWidth(), m_qtComponent.getHeight());
}
void PluginEditor::paint(juce::Graphics&)
{
// FIXME: We're still being asked to paint by JUCE. Ideally
// there would be a way to tell JUCE to skip this component.
qCDebug(qtEditor) << "Editor" << this << "asked to paint";
}