Loading...
Searching...
No Matches
WindowContainer.hpp
1#pragma once
2#include <QApplication>
3#include <QDebug>
4#include <QDialog>
5#include <QWindow>
6
7#include <pluginterfaces/gui/iplugview.h>
8
9namespace vst3
10{
11class PlugFrame;
12
13inline const char* currentPlatform()
14{
15#if defined(__APPLE__)
16 return Steinberg::kPlatformTypeNSView;
17#elif defined(_WIN32)
18 return Steinberg::kPlatformTypeHWND;
19#elif (!(defined(__APPLE__) || defined(_WIN32))) && __has_include(<xcb/xcb.h>)
20 return Steinberg::kPlatformTypeX11EmbedWindowID;
21#endif
22 return "";
23}
24
26{
27 WId nativeId;
28 QWindow* qwindow{};
29 QWidget* container{};
30 vst3::PlugFrame* frame{};
31
32 double qtScaleFactor{1.};
33
35 {
36 double r = qEnvironmentVariable("QT_SCALE_FACTOR").toDouble();
37 if(r > 0.1)
38 {
39 qtScaleFactor = 1. / r;
40 }
41 }
42
43 auto setSizeFromQt(
44 Steinberg::IPlugView& view, const Steinberg::ViewRect& r,
45 QDialog& parentWindow) const
46 {
47 int w = r.getWidth();
48 int h = r.getHeight();
49 int qw = r.getWidth() * qtScaleFactor;
50 int qh = r.getHeight() * qtScaleFactor;
51
52 if(w == 0 || h == 0)
53 {
54 return std::make_pair(w, h);
55 }
56
57 if(view.canResize() == Steinberg::kResultTrue)
58 {
59 parentWindow.resize(QSize{qw, qh});
60 }
61 else
62 {
63 parentWindow.setFixedSize(QSize{qw, qh});
64 }
65 if(qwindow)
66 {
67 qwindow->resize(qw, qh);
68 }
69 if(container)
70 {
71 container->move(0, 0);
72 container->setFixedSize(qw, qh);
73 }
74
75 return std::make_pair(w, h);
76 }
77
78 void
79 setSizeFromUser(Steinberg::IPlugView& view, const QSize& sz, QDialog& parentWindow)
80 {
81 if(view.canResize() != Steinberg::kResultTrue)
82 return;
83
84 Steinberg::ViewRect r;
85 r.top = 0;
86 r.left = 0;
87 r.right = sz.width();
88 r.bottom = sz.height();
89 view.checkSizeConstraint(&r);
90
91 int qw = r.getWidth() * qtScaleFactor;
92 int qh = r.getHeight() * qtScaleFactor;
93
94 parentWindow.resize(QSize(qw, qh));
95
96 if(qwindow)
97 {
98 qwindow->resize(qw, qh);
99 }
100
101 if(container)
102 {
103 container->move(0, 0);
104 container->setFixedSize(qw, qh);
105 }
106
107 view.onSize(&r);
108 }
109
110 auto setSizeFromVst(
111 Steinberg::IPlugView& view, Steinberg::ViewRect& r, QDialog& parentWindow)
112 {
113 int w = r.getWidth();
114 int h = r.getHeight();
115 int qw = r.getWidth() * qtScaleFactor;
116 int qh = r.getHeight() * qtScaleFactor;
117
118 if(w == 0 || h == 0)
119 {
120 view.onSize(&r);
121 return std::make_pair(qw, qh);
122 }
123
124 if(view.canResize() == Steinberg::kResultTrue)
125 {
126 parentWindow.resize(QSize{qw, qh});
127 }
128 else
129 {
130 parentWindow.setFixedSize(QSize{qw, qh});
131 }
132
133 if(qwindow)
134 {
135 qwindow->resize(qw, qh);
136 }
137 if(container)
138 {
139 container->move(0, 0);
140 container->setFixedSize(qw, qh);
141 }
142
143 view.onSize(&r);
144
145 return std::make_pair(qw, qh);
146 }
147};
148
149class Window;
150}
Definition plugins/score-plugin-vst3/Vst3/UI/Window.hpp:21
Definition WindowContainer.hpp:26