#include "lts_screen_wide.h" #include "lts_dummy_widget.h" #include "lts_screen_container.h" #include #include #include #include #include #ifdef Q_OS_WIN #include #endif namespace LtsMultiMonitor { LtsScreenWide::LtsScreenWide(const QRect &screenGeo, int screenId, bool debugMargins, const QString &serial) : LtsScreenBase(screenGeo, screenId, debugMargins, serial) , m_childContainerMain(new LtsScreenContainer(screenGeo)) , m_childContainerLeft(new LtsScreenContainer(screenGeo)) , m_childContainerRight(new LtsScreenContainer(screenGeo)) { connect(m_childContainerMain, &LtsScreenContainer::check, this, &LtsScreenWide::check); connect(m_childContainerLeft, &LtsScreenContainer::check, this, &LtsScreenWide::check); connect(m_childContainerRight, &LtsScreenContainer::check, this, &LtsScreenWide::check); auto *theLayout = new QHBoxLayout; theLayout->setContentsMargins(0, 0, 0, 0); theLayout->setMargin(0); theLayout->setSpacing(0); theLayout->setStretch(0, 9999); m_splitter = new QSplitter; m_splitter->setContentsMargins(0, 0, 0, 0); m_splitter->addWidget(m_childContainerLeft); m_splitter->addWidget(m_childContainerRight); theLayout->addWidget(m_splitter); theLayout->addWidget(m_childContainerMain); m_screenDialog->setLayout(theLayout); m_splitter->hide(); } void LtsScreenWide::putWidgetUnmanagedMain(QWidget *widget) { m_childContainerMain->setWidget(widget); } void LtsScreenWide::putWidgetUnmanagedRight(QWidget *widget) { m_childContainerRight->setWidget(widget); } void LtsScreenWide::putWidgetUnmanagedLeft(QWidget *widget) { m_childContainerLeft->setWidget(widget); } bool LtsScreenWide::hasWidget(QWidget *widget) const { return (m_childContainerMain->hasWidget(widget) || m_childContainerLeft->hasWidget(widget) || m_childContainerRight->hasWidget(widget)); } bool LtsScreenWide::isIrreplaceable() const { return (childLeft()->isIrreplaceable() && childRight()->isIrreplaceable() && childMain()->isIrreplaceable()); } bool LtsScreenWide::isEmpty() const { return (m_childContainerLeft->isEmpty() && m_childContainerRight->isEmpty() && m_childContainerMain->isEmpty()); } int LtsScreenWide::containerIdOfWidget(QWidget *widget) const noexcept(false) { if (m_childContainerMain->hasWidget(widget)) return 0; if (m_childContainerLeft->hasWidget(widget)) return 1; if (m_childContainerRight->hasWidget(widget)) return 2; throw "widget not on this screen"; } LtsScreenContainer *LtsScreenWide::containerOfWidget(QWidget *widget) noexcept(false) { if (m_childContainerMain->hasWidget(widget)) return m_childContainerMain; if (m_childContainerLeft->hasWidget(widget)) return m_childContainerLeft; if (m_childContainerRight->hasWidget(widget)) return m_childContainerRight; throw "widget is not present on this container"; } LtsScreenContainer *LtsScreenWide::putWidget(QWidget *widget, int screenPart) noexcept(false) { if (screenPart == -1) { if (!isEmpty()) throw "cannot put widget as at least one container is occupied and screen part was not specified"; putWidgetUnmanagedMain(widget); return m_childContainerMain; } switch (screenPart) { case 0: { if (!m_childContainerMain->isEmpty()) throw "cannot put widget as main container is already occupied"; putWidgetUnmanagedMain(widget); return m_childContainerMain; } case 1: { if (!m_childContainerLeft->isEmpty()) throw "cannot put widget as left container is already occupied"; if (!m_childContainerMain->isEmpty()) putWidgetUnmanagedRight(m_childContainerMain->stealWidget()); putWidgetUnmanagedLeft(widget); return m_childContainerLeft; } case 2: { if (!m_childContainerRight->isEmpty()) throw "cannot put widget as right container is already occupied"; if (!m_childContainerMain->isEmpty()) putWidgetUnmanagedLeft(m_childContainerMain->stealWidget()); putWidgetUnmanagedRight(widget); return m_childContainerRight; } default: { throw "unknown screen part id"; } } } void LtsScreenWide::check() { Q_ASSERT( (!m_childContainerMain->isEmpty() && m_childContainerLeft->isEmpty() && m_childContainerRight->isEmpty()) || m_childContainerMain->isEmpty() ); if (m_childContainerMain->isEmpty()) { if (m_childContainerLeft->isEmpty() && !m_childContainerRight->isEmpty()) { try { QWidget *widget = m_childContainerRight->stealWidget(); m_childContainerMain->setWidget(widget); } catch(...) { } } else if (!m_childContainerLeft->isEmpty() && m_childContainerRight->isEmpty()) { try { QWidget *widget = m_childContainerLeft->stealWidget(); m_childContainerMain->setWidget(widget); } catch(...) { } } } if (!m_childContainerMain->isEmpty()) { m_childContainerMain->show(); m_splitter->hide(); return; } m_childContainerMain->hide(); m_splitter->setVisible(!m_childContainerLeft->isEmpty() || !m_childContainerRight->isEmpty()); m_childContainerLeft->setVisible(!m_childContainerLeft->isEmpty()); m_childContainerRight->setVisible(!m_childContainerRight->isEmpty()); } }