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.
This commit is contained in:
parent
52040fe3b9
commit
aeb7a2e4e0
@ -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();
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QTextBrowser>
|
||||
#include <QEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QApplication>
|
||||
|
||||
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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user