From 4fe210b93af2ee93d81bf8703492729f9ee77eff Mon Sep 17 00:00:00 2001 From: trnsmkot Date: Fri, 23 May 2025 20:26:00 +0700 Subject: [PATCH] Refactor MainWindow and add dynamic theming to CollapsibleSection Commented out unused tutorial window logic in MainWindow to simplify initialization. Updated CollapsibleSection to support light and dark themes dynamically, improving visual consistency based on the application's palette. --- views/MainWindow.cpp | 12 +++---- views/widget/common/CollapsibleSection.cpp | 37 ++++++++++++++-------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/views/MainWindow.cpp b/views/MainWindow.cpp index fccd975..3cdde7e 100644 --- a/views/MainWindow.cpp +++ b/views/MainWindow.cpp @@ -61,12 +61,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { m_tutorialWindow->activateWindow(); }); - m_tutorialWindow = new TutorialWindow(this); - m_tutorialWindow->show(); - QTimer::singleShot(0, m_tutorialWindow, [w = m_tutorialWindow]() { - w->raise(); - w->activateWindow(); - }); + // m_tutorialWindow = new TutorialWindow(this); + // m_tutorialWindow->show(); + // QTimer::singleShot(0, m_tutorialWindow, [w = m_tutorialWindow]() { + // w->raise(); + // w->activateWindow(); + // }); } diff --git a/views/widget/common/CollapsibleSection.cpp b/views/widget/common/CollapsibleSection.cpp index ff1f003..e1498be 100644 --- a/views/widget/common/CollapsibleSection.cpp +++ b/views/widget/common/CollapsibleSection.cpp @@ -3,6 +3,7 @@ #include #include #include +#include CollapsibleSection::CollapsibleSection( const QString &title, @@ -10,6 +11,9 @@ CollapsibleSection::CollapsibleSection( QWidget *parent, const bool expanded ): QWidget(parent) { + QColor bg = qApp->palette().color(QPalette::Window); + bool dark = bg.lightness() < 128; + // Кнопка заголовка с стрелкой m_toggleButton = new QToolButton(this); m_toggleButton->setText(title); @@ -28,10 +32,7 @@ CollapsibleSection::CollapsibleSection( m_contentBrowser->setFrameShape(QFrame::NoFrame); m_contentBrowser->setVisible(expanded); m_contentBrowser->document()->adjustSize(); - // после создания textBrowser: m_contentBrowser->setReadOnly(true); - - // 1) Отключаем встроенные переходы m_contentBrowser->setOpenLinks(false); // 2) Подключаемся к клику по ссылке @@ -39,18 +40,29 @@ CollapsibleSection::CollapsibleSection( this, [](const QUrl &url) { QDesktopServices::openUrl(url); }); - m_contentBrowser->setStyleSheet( - "QTextBrowser {" - " border: 1px solid #ccc;" // рамка (по желанию) - " border-radius: 3px;" // радиус скругления - " background-color: white;" // фон (по желанию) - "}" - ); - updateContentHeight(); + if (dark) { + m_contentBrowser->setStyleSheet(R"( + QTextBrowser { + background-color: #2b2b2b; + border: 1px solid #ccc; + color: #dddddd; + border-radius:3px; + } + )"); + } else { + m_contentBrowser->setStyleSheet(R"( + QTextBrowser { + background-color: white; + border: 1px solid #ccc; + color: black; + border-radius: 3px; + } + )"); + } + updateContentHeight(); m_contentBrowser->viewport()->installEventFilter(this); - // Компоновка auto *layout = new QVBoxLayout(this); layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); @@ -59,7 +71,6 @@ CollapsibleSection::CollapsibleSection( layout->addWidget(m_contentBrowser); } -// Перестраховка: запрещаем прокрутку колесом bool CollapsibleSection::eventFilter(QObject *watched, QEvent *event) { if (watched == m_contentBrowser->viewport() && event->type() == QEvent::Resize) { updateContentHeight();