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
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "query.h"
#include <QPixmap>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>
#include "commonstrings.h"
#include "util_icon.h"
Query::Query( QWidget* parent, const char* name, bool modal, Qt::WFlags fl, QString text, QString titel )
: QDialog( parent )
{
setWindowTitle( titel );
setWindowIcon(loadIcon("AppIcon.png"));
setModal(modal);
queryLayout = new QVBoxLayout( this );
queryLayout->setMargin(5);
queryLayout->setSpacing(10);
editLayout = new QHBoxLayout;
editLayout->setSpacing( 5 );
editLayout->setMargin( 0 );
answerEdit = new QLineEdit( this );
questionLabel = new QLabel( text, this );
questionLabel->setBuddy(answerEdit);
questionLabel->adjustSize();
editLayout->addWidget( questionLabel );
editLayout->addWidget( answerEdit );
queryLayout->addLayout( editLayout );
okCancelLayout = new QHBoxLayout;
okCancelLayout->setSpacing( 5 );
okCancelLayout->setMargin( 0 );
QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
okCancelLayout->addItem( spacer );
okButton = new QPushButton( CommonStrings::tr_OK, this);
okButton->setDefault( true );
okCancelLayout->addWidget( okButton );
cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
okCancelLayout->addWidget( cancelButton );
queryLayout->addLayout( okCancelLayout );
setMaximumSize(sizeHint());
answerEdit->setFocus();
checkList = QStringList();
checkMode = false;
// signals and slots connections
connect( okButton, SIGNAL( clicked() ), this, SLOT( Leave() ) );
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
// tab order
setTabOrder( answerEdit, okButton );
setTabOrder( okButton, cancelButton );
}
void Query::Leave()
{
if (answerEdit->text().isEmpty())
return;
if (!forbiddenList.isEmpty())
{
if (forbiddenList.contains(answerEdit->text()))
{
QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not allowed.\nPlease choose another.").arg(answerEdit->text()), CommonStrings::tr_OK);
return;
}
}
if (!checkList.isEmpty())
{
if (checkList.contains(answerEdit->text()))
{
if (checkMode)
{
int ret = QMessageBox::warning(this,
CommonStrings::trWarning,
tr("Name \"%1\" already exists.\nDo you want to replace the current contents?").arg(answerEdit->text()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (ret == QMessageBox::No)
return;
else
accept();
}
else
{
QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(answerEdit->text()), CommonStrings::tr_OK);
return;
}
}
accept();
}
else
accept();
}
const QString Query::getEditText()
{
return answerEdit->text();
}
void Query::setEditText(QString newText, bool setSelected)
{
answerEdit->setText(newText);
if (setSelected)
answerEdit->selectAll();
}
void Query::setTestList(QStringList tList)
{
checkList = tList;
}
void Query::setForbiddenList(QStringList tList)
{
forbiddenList = tList;
}
void Query::setCheckMode(bool mode)
{
checkMode = mode;
}
|