obs-aitum-multistream/config-utils.cpp

102 lines
3.2 KiB
C++
Raw Normal View History

2024-07-26 15:18:09 +02:00
#include "config-utils.hpp"
#include <QPushButton>
#include <QString>
#include <QFormLayout>
#include <QGroupBox>
#include <QComboBox>
#include <QAbstractButton>
#include <QWidget>
#include <QIcon>
2024-07-29 12:43:29 +02:00
#include <QToolButton>
2024-07-31 15:02:47 +02:00
#include <QPainter>
#include <QPixmap>
#include <QFont>
2024-07-26 15:18:09 +02:00
#include "obs.h"
#include "obs-module.h"
#include "obs-frontend-api.h"
#include <util/dstr.h>
// Generate buttons for default/custom stuff
2024-07-29 16:46:37 +02:00
QPushButton *ConfigUtils::generateButton(QString buttonText)
{
2024-07-26 15:18:09 +02:00
auto styles = QString::fromUtf8("QPushButton[unselected=\"true\"] { background: pink; }");
2024-07-29 16:46:37 +02:00
2024-07-26 15:18:09 +02:00
auto button = new QPushButton(buttonText);
button->setStyleSheet(styles);
2024-07-29 16:46:37 +02:00
2024-07-26 15:18:09 +02:00
return button;
}
2024-07-29 12:43:29 +02:00
// Generate settings groupbox
2024-07-29 16:46:37 +02:00
QGroupBox *ConfigUtils::generateSettingsGroupBox(QString headingText)
{
2024-07-29 12:43:29 +02:00
auto group = headingText == nullptr ? new QGroupBox : new QGroupBox(headingText);
2024-07-29 16:46:37 +02:00
// group->setProperty("altColor", QVariant(true));
2024-07-29 12:43:29 +02:00
return group;
}
// Generate menu button
2024-07-29 16:46:37 +02:00
QToolButton *ConfigUtils::generateMenuButton(QString title, QIcon icon)
{
2024-07-29 12:43:29 +02:00
auto button = new QToolButton;
button->setText(title);
button->setIcon(icon);
button->setIconSize(QSize(32, 32));
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
button->setStyleSheet(
"min-width: 110px; max-width: 110px; min-height: 90px; max-height: 90px; padding-top: 16px; font-weight: bold;");
return button;
}
2024-07-31 15:02:47 +02:00
// Generate QIcon from emoji
2024-11-01 15:00:39 +01:00
QIcon ConfigUtils::generateEmojiQIcon(QString emoji)
{
2024-07-31 15:02:47 +02:00
QPixmap pixmap(32, 32);
pixmap.fill(Qt::transparent);
2024-11-01 15:00:39 +01:00
2024-07-31 15:02:47 +02:00
QPainter painter(&pixmap);
QFont font = painter.font();
font.setPixelSize(32);
painter.setFont(font);
painter.drawText(pixmap.rect(), Qt::AlignCenter, emoji);
2024-11-01 15:00:39 +01:00
2024-07-31 15:02:47 +02:00
return QIcon(pixmap);
}
2024-07-26 15:18:09 +02:00
// For setting the active property stuff on buttons
2024-07-29 16:46:37 +02:00
void ConfigUtils::updateButtonStyles(QPushButton *defaultButton, QPushButton *customButton, int activeIndex)
{
2024-07-26 15:18:09 +02:00
defaultButton->setProperty("unselected", activeIndex != 0 ? true : false);
customButton->setProperty("unselected", activeIndex != 1 ? true : false);
}
// Platform icons deciphered from endpoints
QIcon ConfigUtils::getPlatformIconFromEndpoint(QString endpoint)
{
2024-11-01 15:00:39 +01:00
if (endpoint.contains(QString::fromUtf8("ingest.global-contribute.live-video.net")) ||
endpoint.contains(QString::fromUtf8(".contribute.live-video.net")) ||
2024-07-29 16:46:37 +02:00
endpoint.contains(QString::fromUtf8(".twitch.tv"))) { // twitch
2024-07-26 15:18:09 +02:00
return QIcon(":/aitum/media/twitch.png");
} else if (endpoint.contains(QString::fromUtf8(".youtube.com"))) { // youtube
return QIcon(":/aitum/media/youtube.png");
} else if (endpoint.contains(QString::fromUtf8("fa723fc1b171.global-contribute.live-video.net"))) { // kick
return QIcon(":/aitum/media/kick.png");
2024-08-01 13:03:42 +02:00
} else if (endpoint.contains(QString::fromUtf8(".tiktokcdn"))) { // tiktok
2024-07-26 15:18:09 +02:00
return QIcon(":/aitum/media/tiktok.png");
} else if (endpoint.contains(QString::fromUtf8(".pscp.tv"))) { // twitter
return QIcon(":/aitum/media/twitter.png");
} else if (endpoint.contains(QString::fromUtf8("livepush.trovo.live"))) { // trovo
return QIcon(":/aitum/media/trovo.png");
} else if (endpoint.contains(QString::fromUtf8(".facebook.com"))) { // facebook
return QIcon(":/aitum/media/facebook.png");
} else { // unknown
return QIcon(":/aitum/media/unknown.png");
}
}