Removed redundant "numbers" field from Account model and database queries to simplify account structure. Introduced a TutorialWindow class for displaying application tutorials, integrated into the main window, and updated file paths accordingly. Improved string handling and logic in Payment routines and enhanced overall UI structure.
86 lines
3.2 KiB
C++
86 lines
3.2 KiB
C++
#include "CollapsibleSection.h"
|
||
#include <QVBoxLayout>
|
||
#include <QTextBrowser>
|
||
#include <QEvent>
|
||
#include <QDesktopServices>
|
||
|
||
CollapsibleSection::CollapsibleSection(
|
||
const QString &title,
|
||
const QString &markdownContent,
|
||
QWidget *parent,
|
||
const bool expanded
|
||
): QWidget(parent) {
|
||
// Кнопка заголовка с стрелкой
|
||
m_toggleButton = new QToolButton(this);
|
||
m_toggleButton->setText(title);
|
||
m_toggleButton->setCheckable(true);
|
||
m_toggleButton->setChecked(expanded);
|
||
m_toggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||
m_toggleButton->setArrowType(expanded ? Qt::DownArrow : Qt::RightArrow);
|
||
|
||
connect(m_toggleButton, &QToolButton::toggled, this, &CollapsibleSection::onToggled);
|
||
|
||
// Контент без собственного скрола, займёт доступное пространство
|
||
m_contentBrowser = new QTextBrowser(this);
|
||
m_contentBrowser->setMarkdown(markdownContent);
|
||
m_contentBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
m_contentBrowser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
m_contentBrowser->setFrameShape(QFrame::NoFrame);
|
||
m_contentBrowser->setVisible(expanded);
|
||
m_contentBrowser->document()->adjustSize();
|
||
// после создания textBrowser:
|
||
m_contentBrowser->setReadOnly(true);
|
||
|
||
// 1) Отключаем встроенные переходы
|
||
m_contentBrowser->setOpenLinks(false);
|
||
|
||
// 2) Подключаемся к клику по ссылке
|
||
connect(m_contentBrowser, &QTextBrowser::anchorClicked,
|
||
this, [](const QUrl &url) {
|
||
QDesktopServices::openUrl(url);
|
||
});
|
||
m_contentBrowser->setStyleSheet(
|
||
"QTextBrowser {"
|
||
" border: 1px solid #ccc;" // рамка (по желанию)
|
||
" border-radius: 3px;" // радиус скругления
|
||
" background-color: white;" // фон (по желанию)
|
||
"}"
|
||
);
|
||
updateContentHeight();
|
||
|
||
m_contentBrowser->viewport()->installEventFilter(this);
|
||
|
||
// Компоновка
|
||
auto *layout = new QVBoxLayout(this);
|
||
layout->setSpacing(0);
|
||
layout->setContentsMargins(0, 0, 0, 0);
|
||
layout->addWidget(m_toggleButton);
|
||
layout->addSpacing(5);
|
||
layout->addWidget(m_contentBrowser);
|
||
}
|
||
|
||
// Перестраховка: запрещаем прокрутку колесом
|
||
bool CollapsibleSection::eventFilter(QObject *watched, QEvent *event) {
|
||
if (watched == m_contentBrowser->viewport() && event->type() == QEvent::Resize) {
|
||
updateContentHeight();
|
||
}
|
||
return QWidget::eventFilter(watched, event);
|
||
}
|
||
|
||
void CollapsibleSection::updateContentHeight() const {
|
||
const qreal w = m_contentBrowser->viewport()->width();
|
||
m_contentBrowser->document()->setTextWidth(w);
|
||
const qreal h = m_contentBrowser->document()->size().height();
|
||
// Можно добавить +1 пиксел на погрешность:
|
||
m_contentBrowser->setFixedHeight(static_cast<int>(h) + 5);
|
||
}
|
||
|
||
void CollapsibleSection::onToggled(const bool checked) const {
|
||
m_toggleButton->setArrowType(checked ? Qt::DownArrow : Qt::RightArrow);
|
||
m_contentBrowser->setVisible(checked);
|
||
|
||
if (checked) {
|
||
updateContentHeight();
|
||
}
|
||
}
|