summaryrefslogtreecommitdiff
path: root/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
blob: 7ce07e8835b75aef94c15412590f88a5b7abe680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "csearchanalysisdialog.h"
#include "csearchanalysisscene.h"
#include "csearchanalysisview.h"

#include "backend/drivers/cswordmoduleinfo.h"
#include "util/dialogutil.h"

#include <QDialog>
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QApplication>
#include <QDesktopWidget>

namespace Search {

static const int DIALOG_HEIGHT=400;
static const int DIALOG_BORDER=30;

CSearchAnalysisDialog::CSearchAnalysisDialog( QList<CSwordModuleInfo*> modules, QWidget* parentDialog )
	: QDialog(parentDialog)
{
	initView();
	m_analysis->reset();
	m_analysis->analyse(modules);

	// Set initial width based on the search data, but limit to the
	// width of the desktop
	int width = (int)( m_analysis->width()+DIALOG_BORDER );
	int desktopWidth = QApplication::desktop()->screenGeometry(this).width();
	if (width > desktopWidth)
		width = desktopWidth;
	resize(width, DIALOG_HEIGHT);

}

/** Initializes this dialog. */
void CSearchAnalysisDialog::initView()
{

	QVBoxLayout *vboxLayout = new QVBoxLayout(this);

	m_analysis = new CSearchAnalysisScene(this);
	m_analysisView = new CSearchAnalysisView(m_analysis, this);
////	m_analysisView->show();
	vboxLayout->addWidget(m_analysisView);

	m_buttonBox = new QDialogButtonBox(this);
	m_buttonBox->setOrientation(Qt::Horizontal);
	m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
	m_buttonBox->addButton(QDialogButtonBox::Save);
	//tr("Save as HTML"),
	util::prepareDialogBox(m_buttonBox);
	vboxLayout->addWidget(m_buttonBox);

	bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	Q_ASSERT(ok);
	ok = QObject::connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
	Q_ASSERT(ok);
}

void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button)
{
	if (m_buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
		m_analysis->saveAsHTML();
	}
}

void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event)
{
	QDialog::resizeEvent(event);
	m_analysis->resizeHeight(height());
}

}