BibleTime
csearchanalysisdialog.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "csearchanalysisdialog.h"
14 
15 #include <QApplication>
16 #include <QDialog>
17 #include <QDialogButtonBox>
18 #include <QRect>
19 #include <QScreen>
20 #include <QtGlobal>
21 #include <QVBoxLayout>
22 #include <utility>
23 #include "../../../backend/cswordmodulesearch.h"
24 #include "../../../util/btconnect.h"
25 #include "../../messagedialog.h"
26 #include "csearchanalysisscene.h"
27 #include "csearchanalysisview.h"
28 
29 
30 namespace Search {
31 
32 static const int DIALOG_HEIGHT = 400;
33 static const int DIALOG_BORDER = 30;
34 
36  QString searchedText,
37  const CSwordModuleSearch::Results &results,
38  QWidget *parentDialog)
39  : QDialog(parentDialog)
40 {
41  QVBoxLayout *vboxLayout = new QVBoxLayout(this);
42 
43  m_analysis =
44  new CSearchAnalysisScene(std::move(searchedText), results, this);
46  //// m_analysisView->show();
47  vboxLayout->addWidget(m_analysisView);
48 
49  m_buttonBox = new QDialogButtonBox(
50  QDialogButtonBox::Save | QDialogButtonBox::Close,
51  this);
52  //tr("Save as HTML"),
54  vboxLayout->addWidget(m_buttonBox);
55 
56  BT_CONNECT(m_buttonBox, &QDialogButtonBox::rejected,
57  this, &CSearchAnalysisDialog::reject);
58  BT_CONNECT(m_buttonBox, &QDialogButtonBox::accepted,
59  [this]{ m_analysis->saveAsHTML(); });
60 
61  retranslateUi();
62 }
63 
64 void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event) {
65  QDialog::resizeEvent(event);
66  m_analysis->resizeHeight(height());
67 }
68 
69 void CSearchAnalysisDialog::showEvent(QShowEvent * const event) {
70  QDialog::showEvent(event);
71 
72  /* Set initial width based on the search data, but limit to the width of the
73  desktop. */
74  if (m_shown)
75  return;
76  m_shown = true;
77  int const width = static_cast<int>(m_analysis->width() + DIALOG_BORDER);
78  int const desktopWidth = screen()->availableSize().width();
79  resize(qMin(width, desktopWidth), DIALOG_HEIGHT);
80 }
81 
83 { setWindowTitle(tr("Analysis of search results")); }
84 
85 }
#define BT_CONNECT(...)
Definition: btconnect.h:20
void showEvent(QShowEvent *event) override
CSearchAnalysisDialog(QString searchedText, CSwordModuleSearch::Results const &results, QWidget *parentDialog=nullptr)
CSearchAnalysisScene * m_analysis
void resizeEvent(QResizeEvent *event) override
CSearchAnalysisView * m_analysisView
std::vector< ModuleSearchResult > Results
static const int DIALOG_HEIGHT
static const int DIALOG_BORDER
void prepareDialogBox(QDialogButtonBox *box)