0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-19 20:32:15 +02:00

UI: Add Single/Double click options to Multiview

The click to select scenes follows the same rules
as the main UI. The double click respects the option
under Settings -> General -> Studio -> Transition
to scene when Double Clicked.
This commit is contained in:
Shaolin 2017-12-12 18:45:15 -02:00
parent 2c20d42815
commit 864caee16c
2 changed files with 77 additions and 0 deletions

View File

@ -556,6 +556,69 @@ void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params)
UNUSED_PARAMETER(params);
}
static int getSourceByPosition(int x, int y)
{
struct obs_video_info ovi;
obs_get_video_info(&ovi);
float ratio = float(ovi.base_width) / float(ovi.base_height);
QWidget *rec = QApplication::activeWindow();
int cx = rec->width();
int cy = rec->height();
int minX = 0;
int minY = 0;
int maxX = cx;
int maxY = cy;
int halfX = cx / 2;
int halfY = cy / 2;
if (float(cx) / float(cy) > ratio) {
int validX = cy * ratio;
minX = halfX - (validX / 2);
maxX = halfX + (validX / 2);
} else {
int validY = cx / ratio;
maxY = halfY + (validY / 2);
}
minY = halfY;
if (x < minX || x > maxX || y < minY || y > maxY)
return -1;
int quarterX = (maxX - minX) / 4;
int pos = (x - minX) / quarterX;
if (y > minY + ((maxY - minY) / 2))
pos += 4;
return pos;
}
void OBSProjector::mouseDoubleClickEvent(QMouseEvent *event)
{
OBSQTDisplay::mouseDoubleClickEvent(event);
if (!config_get_bool(GetGlobalConfig(), "BasicWindow",
"TransitionOnDoubleClick"))
return;
OBSBasic *main = (OBSBasic*)obs_frontend_get_main_window();
if (!main->IsPreviewProgramMode())
return;
if (event->button() == Qt::LeftButton) {
int pos = getSourceByPosition(event->x(), event->y());
if (pos < 0)
return;
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
if (!src)
return;
if (main->GetProgramSource() != src)
main->TransitionToScene(src);
}
}
void OBSProjector::mousePressEvent(QMouseEvent *event)
{
OBSQTDisplay::mousePressEvent(event);
@ -565,6 +628,19 @@ void OBSProjector::mousePressEvent(QMouseEvent *event)
popup.addAction(QTStr("Close"), this, SLOT(EscapeTriggered()));
popup.exec(QCursor::pos());
}
if (event->button() == Qt::LeftButton) {
int pos = getSourceByPosition(event->x(), event->y());
if (pos < 0)
return;
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
if (!src)
return;
OBSBasic *main = (OBSBasic*)obs_frontend_get_main_window();
if (main->GetCurrentSceneSource() != src)
main->SetCurrentScene(src, false);
}
}
void OBSProjector::EscapeTriggered()

View File

@ -18,6 +18,7 @@ private:
static void OBSSourceRemoved(void *data, calldata_t *params);
void mousePressEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
int savedMonitor = 0;
bool isWindow = false;