починил цвета
This commit is contained in:
+189
-30
@@ -69,17 +69,78 @@ void FCreateChat::loadExistingServer(HttpServerChat *server, const QString &name
|
||||
|
||||
FColorSetting *colorSetting = ui->wBlock;
|
||||
if (colorSetting) {
|
||||
QString backgroundColor = colorSetting->hexToColorName(server->getBackgroundColor());
|
||||
colorSetting->cbBackgroundColor->setCurrentText(backgroundColor);
|
||||
QString backgroundColor = server->getBackgroundColor();
|
||||
QColor bgColor(backgroundColor);
|
||||
if (!bgColor.isValid()) {
|
||||
// Если не удалось распознать цвет, используем значение по умолчанию
|
||||
bgColor = QColor("#89F336");
|
||||
}
|
||||
|
||||
// Ищем индекс цвета в комбобоксе
|
||||
int bgIndex = -1;
|
||||
for (int i = 0; i < colorSetting->cbBackgroundColor->count(); ++i) {
|
||||
QVariant itemData = colorSetting->cbBackgroundColor->itemData(i);
|
||||
if (itemData.canConvert<QColor>()) {
|
||||
QColor itemColor = itemData.value<QColor>();
|
||||
if (itemColor == bgColor || itemColor.name() == bgColor.name()) {
|
||||
bgIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString blockColor = colorSetting->hexToColorName(server->getBlockColor());
|
||||
colorSetting->cbBlockColor->setCurrentText(blockColor);
|
||||
if (bgIndex >= 0) {
|
||||
colorSetting->cbBackgroundColor->setCurrentIndex(bgIndex);
|
||||
} else {
|
||||
// Если цвет не найден, устанавливаем по тексту (резервный вариант)
|
||||
colorSetting->cbBackgroundColor->setCurrentText(bgColor.name());
|
||||
}
|
||||
|
||||
// Аналогично для blockColor
|
||||
QString blockColorHex = server->getBlockColor();
|
||||
QColor blColor(blockColorHex);
|
||||
if (!blColor.isValid()) blColor = QColor("#FFFFFF");
|
||||
|
||||
QString borderColor = colorSetting->hexToColorName(server->getBorderColor());
|
||||
colorSetting->cbBorderColor->setCurrentText(borderColor);
|
||||
int blIndex = -1;
|
||||
for (int i = 0; i < colorSetting->cbBlockColor->count(); ++i) {
|
||||
QVariant itemData = colorSetting->cbBlockColor->itemData(i);
|
||||
if (itemData.canConvert<QColor>()) {
|
||||
QColor itemColor = itemData.value<QColor>();
|
||||
if (itemColor == blColor || itemColor.name() == blColor.name()) {
|
||||
blIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (blIndex >= 0) {
|
||||
colorSetting->cbBlockColor->setCurrentIndex(blIndex);
|
||||
} else {
|
||||
colorSetting->cbBlockColor->setCurrentText(blColor.name());
|
||||
}
|
||||
|
||||
// Аналогично для borderColor
|
||||
QString borderColorHex = server->getBorderColor();
|
||||
QColor brColor(borderColorHex);
|
||||
if (!brColor.isValid()) brColor = QColor("#000000");
|
||||
|
||||
int brIndex = -1;
|
||||
for (int i = 0; i < colorSetting->cbBorderColor->count(); ++i) {
|
||||
QVariant itemData = colorSetting->cbBorderColor->itemData(i);
|
||||
if (itemData.canConvert<QColor>()) {
|
||||
QColor itemColor = itemData.value<QColor>();
|
||||
if (itemColor == brColor || itemColor.name() == brColor.name()) {
|
||||
brIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (brIndex >= 0) {
|
||||
colorSetting->cbBorderColor->setCurrentIndex(brIndex);
|
||||
} else {
|
||||
colorSetting->cbBorderColor->setCurrentText(brColor.name());
|
||||
}
|
||||
|
||||
colorSetting->sbBorderSize->setValue(server->getBorderSize());
|
||||
colorSetting->sbPadding->setValue(server->getPadding());
|
||||
@@ -88,13 +149,39 @@ void FCreateChat::loadExistingServer(HttpServerChat *server, const QString &name
|
||||
|
||||
FFontSetting *fontSetting = ui->wFont;
|
||||
if (fontSetting) {
|
||||
QString fontFamily = colorSetting->hexToColorName(server->getFontFamily());
|
||||
fontSetting->cbFontStyle->setCurrentText(fontFamily);
|
||||
// Загрузка шрифта
|
||||
QString fontFamily = server->getFontFamily();
|
||||
int fontIndex = fontSetting->cbFontStyle->findText(fontFamily);
|
||||
if (fontIndex >= 0) {
|
||||
fontSetting->cbFontStyle->setCurrentIndex(fontIndex);
|
||||
} else {
|
||||
fontSetting->cbFontStyle->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
fontSetting->sbFontSize->setValue(server->getFontSize());
|
||||
|
||||
QString fontColor = colorSetting->hexToColorName(server->getFontColor());
|
||||
fontSetting->cbFontColor->setCurrentText(fontColor);
|
||||
// Загрузка цвета шрифта
|
||||
QString fontColorHex = server->getFontColor();
|
||||
QColor fcColor(fontColorHex);
|
||||
if (!fcColor.isValid()) fcColor = QColor("#000000");
|
||||
|
||||
int fcIndex = -1;
|
||||
for (int i = 0; i < fontSetting->cbFontColor->count(); ++i) {
|
||||
QVariant itemData = fontSetting->cbFontColor->itemData(i);
|
||||
if (itemData.canConvert<QColor>()) {
|
||||
QColor itemColor = itemData.value<QColor>();
|
||||
if (itemColor == fcColor || itemColor.name() == fcColor.name()) {
|
||||
fcIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fcIndex >= 0) {
|
||||
fontSetting->cbFontColor->setCurrentIndex(fcIndex);
|
||||
} else {
|
||||
fontSetting->cbFontColor->setCurrentText(fcColor.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,40 +220,112 @@ void FCreateChat::createServer()
|
||||
QString backgroundColor = "#89F336"; // По умолчанию черный
|
||||
|
||||
if (colorSetting && colorSetting->cbBackgroundColor) {
|
||||
QColor bgColor = colorSetting->cbBackgroundColor->currentData().value<QColor>();
|
||||
if (!bgColor.isValid()) {
|
||||
bgColor = QColor(colorSetting->cbBackgroundColor->currentText());
|
||||
QVariant bgData = colorSetting->cbBackgroundColor->currentData();
|
||||
if (bgData.canConvert<QColor>()) {
|
||||
QColor bgColor = bgData.value<QColor>();
|
||||
backgroundColor = bgColor.name();
|
||||
} else {
|
||||
// Резервный вариант
|
||||
QColor bgColor(colorSetting->cbBackgroundColor->currentText());
|
||||
if (bgColor.isValid()) {
|
||||
backgroundColor = bgColor.name();
|
||||
}
|
||||
}
|
||||
backgroundColor = bgColor.name();
|
||||
}
|
||||
|
||||
// Создаем сервер с полученными настройками
|
||||
m_chatServer = new HttpServerChat(fontList, port, backgroundColor, nullptr);
|
||||
|
||||
// Запускаем сервер
|
||||
if (!m_chatServer->start()) {
|
||||
QMessageBox::warning(this, "Ошибка",
|
||||
QString("Не удалось запустить сервер чата на порту %1").arg(port));
|
||||
} else {
|
||||
// Применяем остальные настройки сразу
|
||||
if (m_chatServer) {
|
||||
applyCurrentSettingsToServer();
|
||||
|
||||
if (!m_chatServer->start()) {
|
||||
QMessageBox::warning(this, "Ошибка",
|
||||
QString("Не удалось запустить сервер чата на порту %1").arg(port));
|
||||
delete m_chatServer;
|
||||
m_chatServer = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FCreateChat::applyCurrentSettingsToServer()
|
||||
{
|
||||
if (!m_chatServer) return;
|
||||
|
||||
FColorSetting *colorSetting = ui->wBlock;
|
||||
FFontSetting *fontSetting = ui->wFont;
|
||||
FSettingsWS *settingsWS = ui->widget;
|
||||
|
||||
if (!colorSetting || !fontSetting || !settingsWS) return;
|
||||
|
||||
// Применяем цвета
|
||||
QColor bgColor;
|
||||
QVariant bgData = colorSetting->cbBackgroundColor->currentData();
|
||||
if (bgData.canConvert<QColor>()) {
|
||||
bgColor = bgData.value<QColor>();
|
||||
} else {
|
||||
bgColor = QColor(colorSetting->cbBackgroundColor->currentText());
|
||||
}
|
||||
m_chatServer->changeBackground(bgColor.isValid() ? bgColor.name() : "#89F336");
|
||||
|
||||
// Цвет блока
|
||||
QColor blockColor;
|
||||
QVariant blockData = colorSetting->cbBlockColor->currentData();
|
||||
if (blockData.canConvert<QColor>()) {
|
||||
blockColor = blockData.value<QColor>();
|
||||
m_chatServer->setBlockColor(blockColor.name());
|
||||
} else {
|
||||
m_chatServer->setBlockColor(colorSetting->cbBlockColor->currentText());
|
||||
}
|
||||
|
||||
// Цвет границы
|
||||
QColor borderColor;
|
||||
QVariant borderData = colorSetting->cbBorderColor->currentData();
|
||||
if (borderData.canConvert<QColor>()) {
|
||||
borderColor = borderData.value<QColor>();
|
||||
m_chatServer->setBorderColor(borderColor.name());
|
||||
} else {
|
||||
m_chatServer->setBorderColor(colorSetting->cbBorderColor->currentText());
|
||||
}
|
||||
|
||||
m_chatServer->setBorderSize(colorSetting->sbBorderSize->value());
|
||||
m_chatServer->setPadding(colorSetting->sbPadding->value());
|
||||
m_chatServer->setTransparency(colorSetting->hsBlockTransparant->value());
|
||||
|
||||
// Настройки шрифта
|
||||
m_chatServer->setFontFamily(fontSetting->cbFontStyle->currentText());
|
||||
m_chatServer->setFontSize(fontSetting->sbFontSize->value());
|
||||
|
||||
QColor fontColor;
|
||||
QVariant fontData = fontSetting->cbFontColor->currentData();
|
||||
if (fontData.canConvert<QColor>()) {
|
||||
fontColor = fontData.value<QColor>();
|
||||
m_chatServer->setFontColor(fontColor.name());
|
||||
} else {
|
||||
m_chatServer->setFontColor(fontSetting->cbFontColor->currentText());
|
||||
}
|
||||
|
||||
// Настройки сервера
|
||||
bool freez = settingsWS->cbFreez->isChecked();
|
||||
m_chatServer->setFreez(freez);
|
||||
m_chatServer->setDeleteMode(!freez, settingsWS->sbCount->value());
|
||||
m_chatServer->setMessageTimeout(settingsWS->sbTime->value());
|
||||
}
|
||||
|
||||
void FCreateChat::onBtnTestClicked()
|
||||
{
|
||||
// Для теста создаем временный сервер или используем существующий
|
||||
if (!m_chatServer || !m_isEditMode) {
|
||||
// Если нет сервера или это не режим редактирования, создаем временный
|
||||
if (m_chatServer && !m_isEditMode) {
|
||||
m_chatServer->stop();
|
||||
delete m_chatServer;
|
||||
}
|
||||
// Если сервер не создан, создаем временный
|
||||
if (!m_chatServer) {
|
||||
createServer();
|
||||
if (!m_chatServer) {
|
||||
QMessageBox::warning(this, "Ошибка", "Не удалось создать сервер для теста");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_chatServer) {
|
||||
QMessageBox::warning(this, "Ошибка", "Не удалось создать сервер");
|
||||
return;
|
||||
}
|
||||
// Применяем текущие настройки к серверу
|
||||
applyCurrentSettingsToServer();
|
||||
|
||||
// Создаем тестовое сообщение
|
||||
createTestMessage(true);
|
||||
|
||||
Reference in New Issue
Block a user