1 /*********
2 *
3 * This file is part of BibleTime's source code, http://www.bibletime.info/.
4 *
5 * Copyright 1999-2016 by the BibleTime developers.
6 * The BibleTime source code is licensed under the GNU General Public License version 2.0.
7 *
8 **********/
9
10 #include "frontend/searchdialog/analysis/csearchanalysisdialog.h"
11
12 #include <QAbstractButton>
13 #include <QApplication>
14 #include <QDesktopWidget>
15 #include <QDialog>
16 #include <QDialogButtonBox>
17 #include <QtGlobal>
18 #include <QVBoxLayout>
19 #include "backend/drivers/cswordmoduleinfo.h"
20 #include "frontend/searchdialog/analysis/csearchanalysisscene.h"
21 #include "frontend/searchdialog/analysis/csearchanalysisview.h"
22 #include "frontend/messagedialog.h"
23 #include "util/btconnect.h"
24
25
26 namespace Search {
27
28 static const int DIALOG_HEIGHT = 400;
29 static const int DIALOG_BORDER = 30;
30
CSearchAnalysisDialog(const CSwordModuleSearch::Results & results,QWidget * parentDialog)31 CSearchAnalysisDialog::CSearchAnalysisDialog(
32 const CSwordModuleSearch::Results &results,
33 QWidget *parentDialog)
34 : QDialog(parentDialog)
35 {
36 initView();
37 m_analysis->reset();
38 m_analysis->analyse(results);
39
40 // Set initial width based on the search data, but limit to the
41 // width of the desktop
42 int const width = static_cast<int>(m_analysis->width() + DIALOG_BORDER);
43 int const desktopWidth =
44 QApplication::desktop()->screenGeometry(this).width();
45 resize(qMin(width, desktopWidth), DIALOG_HEIGHT);
46 }
47
48 /** Initializes this dialog. */
initView()49 void CSearchAnalysisDialog::initView() {
50
51 QVBoxLayout *vboxLayout = new QVBoxLayout(this);
52
53 m_analysis = new CSearchAnalysisScene(this);
54 m_analysisView = new CSearchAnalysisView(m_analysis, this);
55 //// m_analysisView->show();
56 vboxLayout->addWidget(m_analysisView);
57
58 m_buttonBox = new QDialogButtonBox(this);
59 m_buttonBox->setOrientation(Qt::Horizontal);
60 m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
61 m_buttonBox->addButton(QDialogButtonBox::Save);
62 //tr("Save as HTML"),
63 message::prepareDialogBox(m_buttonBox);
64 vboxLayout->addWidget(m_buttonBox);
65
66 BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
67 BT_CONNECT(m_buttonBox, SIGNAL(clicked(QAbstractButton *)),
68 this, SLOT(buttonClicked(QAbstractButton *)));
69 }
70
buttonClicked(QAbstractButton * button)71 void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button) {
72 if (m_buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
73 m_analysis->saveAsHTML();
74 }
75 }
76
resizeEvent(QResizeEvent * event)77 void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event) {
78 QDialog::resizeEvent(event);
79 m_analysis->resizeHeight(height());
80 }
81
82 }
83