13#include "../shared/collectionconfiguration.h"
15#include <QtWidgets/QApplication>
16#include <QtWidgets/QTreeView>
20using namespace Qt::StringLiterals;
25 bool defaultCollection,
const QUrl &cmdLineUrl)
28 Q_ASSERT(!m_instance);
41 const QUrl &cmdLineUrl)
43 , m_model(
new OpenPagesModel(
this))
46 m_openPagesWidget =
new OpenPagesWidget(m_model);
47 m_openPagesWidget->setFrameStyle(QFrame::NoFrame);
48 connect(m_openPagesWidget, &OpenPagesWidget::setCurrentPage,
49 this, QOverload<
const QModelIndex &>::of(&OpenPagesManager::setCurrentPage));
50 connect(m_openPagesWidget, &OpenPagesWidget::closePage,
51 this, QOverload<
const QModelIndex &>::of(&OpenPagesManager::closePage));
55 m_openPagesSwitcher =
new OpenPagesSwitcher(m_model);
56 connect(m_openPagesSwitcher, &OpenPagesSwitcher::closePage,
57 this, QOverload<
const QModelIndex &>::of(&OpenPagesManager::closePage));
58 connect(m_openPagesSwitcher, &OpenPagesSwitcher::setCurrentPage,
59 this, QOverload<
const QModelIndex &>::of(&OpenPagesManager::setCurrentPage));
61 setupInitialPages(defaultCollection, cmdLineUrl);
68 delete m_openPagesSwitcher;
78 const QUrl &cmdLineUrl)
81 if (cmdLineUrl.isValid()) {
82 createPage(cmdLineUrl);
90 m_model->addPage(helpEngine.homePage());
93 m_model->addPage(QUrl(
"about:blank"_L1));
96 const QStringList &lastShownPageList = helpEngine.lastShownPages();
97 const int pageCount = lastShownPageList.size();
99 if (defaultCollection)
100 m_helpPageViewer = m_model->addPage(QUrl(
"help"_L1));
102 m_model->addPage(QUrl(
"about:blank"_L1));
104 QStringList zoomFactors = helpEngine.lastZoomFactors();
105 while (zoomFactors.size() < pageCount)
106 zoomFactors.append(CollectionConfiguration::DefaultZoomFactor);
108 if (initialPage >= pageCount) {
109 qWarning(
"Initial page set to %d, maximum possible value is %d",
110 initialPage, pageCount - 1);
113 for (
int curPage = 0; curPage < pageCount; ++curPage) {
114 const QString &curFile = lastShownPageList.at(curPage);
115 if (helpEngine.findFile(curFile).isValid()
116 || curFile ==
"about:blank"_L1) {
117 m_model->addPage(curFile, zoomFactors.at(curPage).toFloat());
118 }
else if (curPage <= initialPage && initialPage > 0)
129 m_model->addPage(helpEngine.homePage());
140 return createPage(QUrl(
"about:blank"_L1));
147 const QModelIndexList selectedIndexes
148 = m_openPagesWidget->selectionModel()->selectedRows();
149 if (selectedIndexes.isEmpty())
151 Q_ASSERT(selectedIndexes.size() == 1);
152 removePage(selectedIndexes.first().row());
161 emit aboutToAddPage();
163 m_model->addPage(url);
169 emit pageAdded(index);
176 return createPage(url,
true);
194 removePage(index.row());
200 closeOrReloadPages(nameSpace,
false);
206 closeOrReloadPages(nameSpace,
true);
210void OpenPagesManager::closeOrReloadPages(
const QString &nameSpace,
bool tryReload)
215 if (page
->source().host() != nameSpace)
220 page->setSource(QUrl(
"about:blank"_L1));
239 setCurrentPage(index.row());
250 if (m_helpPageViewer)
251 m_helpPageViewer->reload();
264 emit aboutToClosePage(index);
277 if (!index.isValid())
293 return m_openPagesWidget;
299 nextOrPreviousPage(1);
305 if (!m_openPagesSwitcher->isVisible()) {
308 showSwitcherOrSelectPage();
317 nextOrPreviousPage(-1);
323 if (!m_openPagesSwitcher->isVisible()) {
326 showSwitcherOrSelectPage();
342 if (QApplication::keyboardModifiers() != Qt::NoModifier) {
345 const QPoint p(CentralWidget::instance()->mapToGlobal(QPoint(0, 0)));
346 m_openPagesSwitcher->move((width - m_openPagesSwitcher->width()) / 2 + p.x(),
347 (height - m_openPagesSwitcher->height()) / 2 + p.y());
static HelpEngineWrapper & instance()
void previousPageWithSwitcher()
QAbstractItemView * openPagesWidget() const
void setCurrentPage(HelpViewer *page)
bool pagesOpenForNamespace(const QString &nameSpace) const
HelpViewer * createNewPageFromSearch(const QUrl &url)
void nextPageWithSwitcher()
void closePage(HelpViewer *page)
void reloadPages(const QString &nameSpace)
HelpViewer * createBlankPage()
static OpenPagesManager * instance()
void setCurrentPage(int index)
void closePages(const QString &nameSpace)
void removePage(int index)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
HelpViewer * pageAt(int index) const
void setVisible(bool visible) override
void closePagesExcept(const QModelIndex &index)
Combined button and popup list for selecting options.