173 lines
3.5 KiB
C++
Executable File
173 lines
3.5 KiB
C++
Executable File
|
|
|
|
|
|
#include "lts_dialog_helper.h"
|
|
#include "lts_dialog.h"
|
|
#include "ui_lts_dialog_helper.h"
|
|
|
|
#include <QScrollArea>
|
|
#include <QScrollBar>
|
|
#include <QDebug>
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
class LDHScrollBar : public QScrollBar
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
using QScrollBar::QScrollBar;
|
|
|
|
void showEvent(QShowEvent *e) override
|
|
{
|
|
QScrollBar::showEvent(e);
|
|
emit scrollbarVisiblityChanged(true);
|
|
}
|
|
void hideEvent(QHideEvent *e) override
|
|
{
|
|
QScrollBar::hideEvent(e);
|
|
emit scrollbarVisiblityChanged(false);
|
|
}
|
|
Q_SIGNALS:
|
|
void scrollbarVisiblityChanged(bool visible);
|
|
};
|
|
|
|
|
|
LtsDialogHelper::LtsDialogHelper(QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_ui(new Ui::LtsDialogHelper())
|
|
, m_dialog(nullptr)
|
|
{
|
|
m_ui->setupUi(this);
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
auto hScroll = new LDHScrollBar(this);
|
|
auto vScroll = new LDHScrollBar(this);
|
|
m_ui->scrollArea->setHorizontalScrollBar(hScroll);
|
|
m_ui->scrollArea->setVerticalScrollBar(vScroll);
|
|
connect(hScroll, &LDHScrollBar::scrollbarVisiblityChanged,
|
|
this, &LtsDialogHelper::onHScrollBarVisibilityChanged);
|
|
connect(vScroll, &LDHScrollBar::scrollbarVisiblityChanged,
|
|
this, &LtsDialogHelper::onVScrollBarVisibilityChanged);
|
|
|
|
#ifdef TABLET_MODE
|
|
QList<QWidget *> scrollWidgets = findChildren<QWidget *>();
|
|
|
|
for (auto i = scrollWidgets.begin(); i != scrollWidgets.end(); ++i)
|
|
{
|
|
QWidget *widget = *i;
|
|
|
|
QVariant isConst = widget->property("const");
|
|
if (isConst.isValid() && isConst.toBool())
|
|
continue;
|
|
|
|
LtsWidgets::addTouchScroll(widget);
|
|
}
|
|
#endif
|
|
m_ui->buttonBox->setMinimumHeight(m_ui->buttonBox->sizeHint().height());
|
|
}
|
|
|
|
|
|
LtsDialogHelper::~LtsDialogHelper()
|
|
{
|
|
m_ui->scrollArea->horizontalScrollBar()->disconnect(this);
|
|
m_ui->scrollArea->verticalScrollBar()->disconnect(this);
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
LtsDialogButtonBox *LtsDialogHelper::getButtonBox()
|
|
{
|
|
return m_ui->buttonBox;
|
|
}
|
|
|
|
|
|
void LtsDialogHelper::setDialog(LtsDialog *dialog)
|
|
{
|
|
if (m_dialog != nullptr)
|
|
return;
|
|
|
|
m_dialog = dialog;
|
|
m_dialog->setContentsMargins(QMargins());
|
|
if (m_dialog->layout())
|
|
m_dialog->layout()->setContentsMargins(QMargins());
|
|
m_ui->scrollArea->setWidget(m_dialog);
|
|
|
|
|
|
{
|
|
connect(dialog, &LtsDialog::destroyed, this, [this]()
|
|
{
|
|
m_dialog = nullptr;
|
|
deleteLater();
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
LtsDialog *LtsDialogHelper::getDialog()
|
|
{
|
|
return m_dialog;
|
|
}
|
|
|
|
void LtsDialogHelper::retranslate()
|
|
{
|
|
if (m_dialog == nullptr)
|
|
return;
|
|
|
|
m_dialog->setContentsMargins(QMargins());
|
|
if (m_dialog->layout())
|
|
m_dialog->layout()->setContentsMargins(QMargins());
|
|
|
|
bool oldChangesFlag = m_dialog->m_changesMade;
|
|
|
|
|
|
|
|
m_dialog->retranslate();
|
|
|
|
if (oldChangesFlag)
|
|
m_dialog->slotChangesMade();
|
|
else
|
|
m_dialog->resetChanges();
|
|
}
|
|
|
|
|
|
void LtsDialogHelper::resizeEvent(QResizeEvent *e)
|
|
{
|
|
emit signalSizeChanged(e->size());
|
|
}
|
|
|
|
|
|
void LtsDialogHelper::changeEvent(QEvent *e)
|
|
{
|
|
QWidget::changeEvent(e);
|
|
if (e->type() == QEvent::LanguageChange)
|
|
retranslate();
|
|
}
|
|
|
|
|
|
void LtsDialogHelper::onHScrollBarVisibilityChanged(bool visible)
|
|
{
|
|
if (m_dialog == nullptr || !m_dialog->layout())
|
|
return;
|
|
|
|
QMargins m = m_dialog->layout()->contentsMargins();
|
|
m.setBottom(visible ? -1 : 0);
|
|
m_dialog->layout()->setContentsMargins(m);
|
|
}
|
|
|
|
|
|
void LtsDialogHelper::onVScrollBarVisibilityChanged(bool visible)
|
|
{
|
|
if (m_dialog == nullptr || !m_dialog->layout())
|
|
return;
|
|
|
|
QMargins m = m_dialog->layout()->contentsMargins();
|
|
m.setRight(visible ? -1 : 0);
|
|
m_dialog->layout()->setContentsMargins(m);
|
|
}
|
|
|
|
}
|
|
|
|
#include "lts_dialog_helper.moc"
|