Subversion Repositories Scribus

Rev

Rev 24967 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3 paul 7
#include "query.h"
24837 jghali 8
 
8501 cbradney 9
#include <QPixmap>
9339 fschmid 10
#include <QLabel>
11
#include <QLineEdit>
12
#include <QPushButton>
14438 fschmid 13
#include <QMessageBox>
17895 fschmid 14
#include <QValidator>
24837 jghali 15
#include <QRegularExpressionValidator>
16
 
2952 cbradney 17
#include "commonstrings.h"
19605 jghali 18
#include "ui/scmessagebox.h"
20185 craig 19
#include "iconmanager.h"
2952 cbradney 20
 
24700 jghali 21
Query::Query( QWidget* parent,  const char* name, bool modal, const QString& text, const QString& title ) : QDialog( parent )
3 paul 22
{
24700 jghali 23
        setWindowTitle( title );
23054 craig 24
        setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
9339 fschmid 25
        setModal(modal);
26
        queryLayout = new QVBoxLayout( this );
24521 jghali 27
        queryLayout->setContentsMargins(9, 9, 9, 9);
28
        queryLayout->setSpacing(6);
9339 fschmid 29
        editLayout = new QHBoxLayout;
24521 jghali 30
        editLayout->setSpacing(6);
31
        editLayout->setContentsMargins(0, 0, 0, 0);
10553 fschmid 32
        answerEdit = new QLineEdit( this );
33
        questionLabel = new QLabel( text, this );
34
        questionLabel->setBuddy(answerEdit);
7272 fschmid 35
        questionLabel->adjustSize();
36
        editLayout->addWidget( questionLabel );
37
        editLayout->addWidget( answerEdit );
38
        queryLayout->addLayout( editLayout );
9339 fschmid 39
        okCancelLayout = new QHBoxLayout;
24521 jghali 40
        okCancelLayout->setSpacing(6);
41
        okCancelLayout->setContentsMargins(0, 0, 0, 0);
7272 fschmid 42
        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
43
        okCancelLayout->addItem( spacer );
10553 fschmid 44
        okButton = new QPushButton( CommonStrings::tr_OK, this);
7272 fschmid 45
        okButton->setDefault( true );
46
        okCancelLayout->addWidget( okButton );
10553 fschmid 47
        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
7272 fschmid 48
        okCancelLayout->addWidget( cancelButton );
49
        queryLayout->addLayout( okCancelLayout );
50
        setMaximumSize(sizeHint());
51
        answerEdit->setFocus();
14438 fschmid 52
        checkList = QStringList();
15063 fschmid 53
        checkMode = false;
3 paul 54
 
7272 fschmid 55
        // signals and slots connections
56
        connect( okButton, SIGNAL( clicked() ), this, SLOT( Leave() ) );
57
        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
3 paul 58
 
7272 fschmid 59
        // tab order
60
        setTabOrder( answerEdit, okButton );
61
        setTabOrder( okButton, cancelButton );
3 paul 62
}
63
 
151 Franz 64
void Query::Leave()
65
{
2877 cbradney 66
        if (answerEdit->text().isEmpty())
151 Franz 67
                return;
17006 fschmid 68
        if (!forbiddenList.isEmpty())
69
        {
70
                if (forbiddenList.contains(answerEdit->text()))
71
                {
19605 jghali 72
                        ScMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not allowed.\nPlease choose another.").arg(answerEdit->text()));
17006 fschmid 73
                        return;
74
                }
75
        }
14438 fschmid 76
        if (!checkList.isEmpty())
77
        {
78
                if (checkList.contains(answerEdit->text()))
79
                {
15063 fschmid 80
                        if (checkMode)
81
                        {
19605 jghali 82
                                int ret = ScMessageBox::warning(this,
15063 fschmid 83
                                                                                                CommonStrings::trWarning,
84
                                                                                                tr("Name \"%1\" already exists.\nDo you want to replace the current contents?").arg(answerEdit->text()),
85
                                                                                                QMessageBox::Yes | QMessageBox::No,
19605 jghali 86
                                                                                                QMessageBox::No,        // GUI default
87
                                                                                                QMessageBox::Yes);      // batch default
15063 fschmid 88
                                if (ret == QMessageBox::No)
89
                                        return;
22638 craig 90
                                accept();
15063 fschmid 91
                        }
92
                        else
93
                        {
19605 jghali 94
                                ScMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(answerEdit->text()));
15063 fschmid 95
                                return;
96
                        }
14438 fschmid 97
                }
14508 jghali 98
                accept();
14438 fschmid 99
        }
151 Franz 100
        else
101
                accept();
102
}
103
 
23671 jghali 104
QString Query::getEditText() const
702 cbradney 105
{
106
        return answerEdit->text();
107
}
108
 
22635 craig 109
void Query::setEditText(const QString& newText, bool setSelected)
702 cbradney 110
{
111
        answerEdit->setText(newText);
112
        if (setSelected)
113
                answerEdit->selectAll();
114
}
14438 fschmid 115
 
22635 craig 116
void Query::setTestList(const QStringList& tList)
14438 fschmid 117
{
118
        checkList = tList;
119
}
15063 fschmid 120
 
22635 craig 121
void Query::setForbiddenList(const QStringList& tList)
17006 fschmid 122
{
123
        forbiddenList = tList;
124
}
125
 
15063 fschmid 126
void Query::setCheckMode(bool mode)
127
{
128
        checkMode = mode;
129
}
17895 fschmid 130
 
24837 jghali 131
void Query::setValidator(const QRegularExpression& rx)
17895 fschmid 132
{
25089 jghali 133
        QValidator* valid = new QRegularExpressionValidator( rx, this );
134
        answerEdit->setValidator(valid);
17895 fschmid 135
}