#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)) { // force check if widget in container was deleted: 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) { //qWarning() << "wide: put main"; m_childContainerMain->setWidget(widget); } void LtsScreenWide::putWidgetUnmanagedRight(QWidget *widget) { //qWarning() << "wide: put right"; m_childContainerRight->setWidget(widget); } void LtsScreenWide::putWidgetUnmanagedLeft(QWidget *widget) { //qWarning() << "wide: put left"; 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 main is currently occupied but left / right is requested, then put * the widget from main to the other side respective (as main means left * & right is empty, there is no need to check left & right occupancy) */ 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 main is currently occupied but left / right is requested, then put * the widget from main to the other side respective (as main means left * & right is empty, there is no need to check left & right occupancy) */ if (!m_childContainerMain->isEmpty()) putWidgetUnmanagedLeft(m_childContainerMain->stealWidget()); putWidgetUnmanagedRight(widget); return m_childContainerRight; } default: { throw "unknown screen part id"; } } } void LtsScreenWide::check() { /*qWarning() << "check @ " << (quintptr)this; qWarning() << "check: occupied? " << "- main:" << !childMain()->isEmpty() << "- left:" << !childLeft()->isEmpty() << "- right:" << !childRight()->isEmpty();*/ // if main is occupied but left and / or right is occupied, too, then assert: Q_ASSERT( (!m_childContainerMain->isEmpty() && m_childContainerLeft->isEmpty() && m_childContainerRight->isEmpty()) || m_childContainerMain->isEmpty() ); // if main is empty AND either left or right (but not both) are empty, widget must move from left/right to main!!! if (m_childContainerMain->isEmpty()) { if (m_childContainerLeft->isEmpty() && !m_childContainerRight->isEmpty()) { try { QWidget *widget = m_childContainerRight->stealWidget(); m_childContainerMain->setWidget(widget); } catch(...) { //qWarning() << "oops#2"; //Q_ASSERT(false); } } else if (!m_childContainerLeft->isEmpty() && m_childContainerRight->isEmpty()) { try { QWidget *widget = m_childContainerLeft->stealWidget(); m_childContainerMain->setWidget(widget); } catch(...) { //qWarning() << "oops#1"; //Q_ASSERT(false); } } } // now do the visibility checks if (!m_childContainerMain->isEmpty()) { //qWarning() << "wide: check main"; m_childContainerMain->show(); m_splitter->hide(); return; } //qWarning() << "wide: check left & right"; m_childContainerMain->hide(); m_splitter->setVisible(!m_childContainerLeft->isEmpty() || !m_childContainerRight->isEmpty()); m_childContainerLeft->setVisible(!m_childContainerLeft->isEmpty()); m_childContainerRight->setVisible(!m_childContainerRight->isEmpty()); } } // namespace LtsMultiMonitor