Subversion Repositories Scribus

Rev

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