File: StatusWindow.cpp

package info (click to toggle)
dyssol 1.5.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,204 kB
  • sloc: cpp: 53,870; sh: 85; python: 59; makefile: 11
file content (112 lines) | stat: -rw-r--r-- 2,575 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Copyright (c) 2020, Dyssol Development Team. All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#include "StatusWindow.h"
#include <QMessageBox>
#include <QCloseEvent>
#include <QFileInfo>

CStatusWindow::CStatusWindow(QWidget *parent)
	: QDialog(parent)
{
	InitClass( tr("Status"), tr("In progress..."), tr(""), tr("Terminate?"), true, parent );
}

CStatusWindow::CStatusWindow(const QString &_sWindowTitle, const QString &_sText, const QString &_sQuestion, bool _bStopEnabled, QWidget *parent /*= 0 */)
	: QDialog(parent)
{
	InitClass( _sWindowTitle, _sText, tr(""), _sQuestion, _bStopEnabled, parent );
}

CStatusWindow::~CStatusWindow()
{

}

void CStatusWindow::SetWindowTitle(const QString &_sTitle)
{
	m_sWindowTitle = _sTitle;
	this->setWindowTitle( _sTitle );
}

void CStatusWindow::SetText(const QString &_sText)
{
	m_sText = _sText;
	SetMessage();
}

void CStatusWindow::SetFileName(const QString &_sFileName)
{
	m_sFileName = _sFileName;
	SetMessage();
}

void CStatusWindow::SetConfirmQuestion(const QString &_sQuestion)
{
	m_sQuestion = _sQuestion;
}

void CStatusWindow::SetStopEnable(bool _bEnable)
{
	m_bStopEnabled = _bEnable;
	ui.buttonStop->setEnabled( _bEnable );
}

void CStatusWindow::InitClass(const QString &_sWindowTitle, const QString &_sText, const QString &_sFileName, const QString &_sQuestion, bool _bStopEnabled, QWidget *parent /*= 0 */)
{
	ui.setupUi(this);

	m_sText = _sText;
	m_sFileName = _sFileName;
	m_sQuestion = _sQuestion;

	SetWindowTitle( _sWindowTitle );

	SetMessage();

	SetStopEnable( _bStopEnabled );

	InitializeConnections();

	//move(parentWidget()->window()->frameGeometry().topLeft() + parentWidget()->window()->rect().center() - rect().center());
}

void CStatusWindow::InitializeConnections()
{
	connect( ui.buttonStop, SIGNAL(clicked()), this, SLOT(StopButtonPressed()) );
}

bool CStatusWindow::GetConfirmation()
{
	if( !m_bStopEnabled )
		return false;

	QMessageBox box( QMessageBox::Question, tr("Termination"), m_sQuestion, QMessageBox::Yes | QMessageBox::No, this );
	box.setDefaultButton( QMessageBox::No );
	int ans = box.exec();
	return ans == QMessageBox::Yes;
}

void CStatusWindow::SetMessage()
{
	QString sText;
	if( !m_sFileName.isEmpty() )
	{
		QFileInfo fi( m_sFileName );
		sText += "<b>" + fi.fileName() + "</b><br/>";
	}
	sText += m_sText;
	ui.label->setText( sText );
}

void CStatusWindow::closeEvent(QCloseEvent *event)
{
	if( GetConfirmation() )
		emit StopRequested();

	event->ignore();
}

void CStatusWindow::StopButtonPressed()
{
	close();
}