#include "viewermainwindow.h" #include "viewwidget.h" #include "viewerinterfaceimpl.h" #include #include #include namespace VCtrl { //////////////////////////////////////////////////////////////////////////////// TransparencyDialog::TransparencyDialog(QWidget *parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) { setWindowTitle(tr("BgViewer - Set Global Transparency")); auto plabel = new QLabel(tr("Set transparency value:")); m_pSlider = new QSlider(Qt::Horizontal); m_pSlider->setMinimum(0); m_pSlider->setMaximum(100); m_pSlider->setValue(50); m_pSlider->setMinimumWidth(200); auto pButton = new QPushButton(tr("Apply")); connect(pButton, &QPushButton::clicked, this, &VCtrl::TransparencyDialog::accept); auto pLayout = new QHBoxLayout(this); pLayout->addWidget(plabel); pLayout->addWidget(m_pSlider); pLayout->addWidget(pButton); pLayout->setSizeConstraint(QLayout::SetFixedSize); } //////////////////////////////////////////////////////////////////////////////// CtrlMainWindow::CtrlMainWindow(QWidget *parent) : QWidget(parent) { connect(&m_highlighterTimer, &QTimer::timeout, this, &CtrlMainWindow::onHighlighterTimerTimeout); setWindowTitle(tr("BgViewer")); // Remove minimize/maximize and close button setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); new QGridLayout(this); } //////////////////////////////////////////////////////////////////////////////// void CtrlMainWindow::updateHighlightThreads(ViewWidget *pWidget) { m_highlighterCounter[pWidget] = 6; if (!m_highlighterTimer.isActive()) m_highlighterTimer.start(500); } //////////////////////////////////////////////////////////////////////////////// void CtrlMainWindow::onHighlighterTimerTimeout() { auto it = m_highlighterCounter.begin(); while (it != m_highlighterCounter.end()) { ViewWidget *ww = it.key(); ww->highlightBorder(it.value() % 2 == 0); it.value() = it.value() - 1; if (it.value() <= 0) it = m_highlighterCounter.erase(it); else ++it; } if (m_highlighterCounter.isEmpty()) m_highlighterTimer.stop(); } //////////////////////////////////////////////////////////////////////////////// void CtrlMainWindow::openView(ViewWidget *pViewWidget) { openViews({pViewWidget}); } //////////////////////////////////////////////////////////////////////////////// void CtrlMainWindow::openViews(const std::vector &vecMainWindowSubWidgets) { constexpr int maxViewsPerCol = 4; // Append where we stopped last time QGridLayout *gridLayout = static_cast(layout()); int row = gridLayout->count() / maxViewsPerCol, col = gridLayout->count() % maxViewsPerCol; // Add all requested ViewWidgets which are actually new for (auto &pWidget : vecMainWindowSubWidgets) { auto itm = gridLayout->itemAtPosition(row, col); if (itm && itm->widget() == pWidget) continue; gridLayout->addWidget(pWidget, row, col); pWidget->show(); if (++col >= maxViewsPerCol) { col = 0; ++row; } } } void CtrlMainWindow::closeView(ViewWidget *pViewWidget) { if (!pViewWidget) return; QGridLayout *gridLayout = dynamic_cast(layout()); std::vector currentViews; currentViews.reserve(gridLayout->count()); for (int idx = 0; idx < gridLayout->count(); idx++) { QLayoutItem *item = gridLayout->itemAt(idx); ViewWidget *vw = static_cast(item->widget()); if (vw != pViewWidget) currentViews.push_back(vw); } m_highlighterCounter.remove(pViewWidget); pViewWidget->close(); delete gridLayout; setLayout(new QGridLayout); openViews(currentViews); } //////////////////////////////////////////////////////////////////////////////// void CtrlMainWindow::clearGridLayout() { QGridLayout *gridLayout = dynamic_cast(layout()); for (int idx = 0; idx < gridLayout->count(); idx++) { QLayoutItem *item = gridLayout->itemAt(idx); item->widget()->hide(); } m_highlighterCounter.clear(); delete gridLayout; setLayout(new QGridLayout); } }