~ubuntu-branches/ubuntu/trusty/scribus-ng/trusty

« back to all changes in this revision

Viewing changes to scribus/hyask.cpp

  • Committer: Package Import Robot
  • Author(s): Oleksandr Moskalenko
  • Date: 2012-02-15 15:57:12 UTC
  • mfrom: (4.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20120215155712-biimoc8o875jht80
Tags: 1.4.0.dfsg+r17300-1
* Prepare a dummy transitional package to converge on the 1.4.0 release.
* debian/NEWS: update the news.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
*/
7
 
#include "hyask.h"
8
 
#include <QPixmap>
9
 
#include <QRegExp>
10
 
#include <QHBoxLayout>
11
 
#include <QVBoxLayout>
12
 
#include <QKeyEvent>
13
 
#include <QPushButton>
14
 
#include <QCheckBox>
15
 
#include <QLabel>
16
 
 
17
 
#include "util_icon.h"
18
 
 
19
 
WortEdit::WortEdit ( QWidget* parent ) : QLineEdit ( parent )
20
 
{}
21
 
 
22
 
void WortEdit::keyPressEvent ( QKeyEvent *k )
23
 
{
24
 
        int p = cursorPosition();
25
 
        QChar cc = text() [p];
26
 
        if ( ( k->key() == Qt::Key_Left ) || ( k->key() == Qt::Key_Right ) )
27
 
                QLineEdit::keyPressEvent ( k );
28
 
        if ( k->key() == Qt::Key_Delete )
29
 
        {
30
 
                if ( cc == '-' )
31
 
                        QLineEdit::keyPressEvent ( k );
32
 
                setCursorPosition ( p );
33
 
        }
34
 
        if ( ( k->key() == Qt::Key_Backspace ) && ( p != 0 ) )
35
 
        {
36
 
                cc = text() [p-1];
37
 
                if ( cc == '-' )
38
 
                        QLineEdit::keyPressEvent ( k );
39
 
                setCursorPosition ( p-1 );
40
 
        }
41
 
        if ( k->key() == Qt::Key_Minus )
42
 
                QLineEdit::keyPressEvent ( k );
43
 
}
44
 
 
45
 
HyAsk::HyAsk ( QWidget* parent, QString HWort ) : QDialog ( parent )
46
 
{
47
 
        setModal(true);
48
 
        setWindowTitle( tr( "Possible Hyphenation" ));
49
 
        setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
50
 
        HyAskLayout = new QVBoxLayout(this);
51
 
        HyAskLayout->setMargin(10);
52
 
        HyAskLayout->setSpacing(5);
53
 
 
54
 
        Wort = new WortEdit ( this );
55
 
        Wort->setMinimumSize ( QSize ( 300, 0 ) );
56
 
        Wort->setDragEnabled ( false );
57
 
        Wort->setText ( HWort );
58
 
        HyAskLayout->addWidget ( Wort );
59
 
 
60
 
        Layout1 = new QHBoxLayout;
61
 
        Layout1->setMargin(0);
62
 
        Layout1->setSpacing(5);
63
 
 
64
 
        vboxLayout1 = new QVBoxLayout();
65
 
        vboxLayout1->setSpacing(5);
66
 
        vboxLayout1->setMargin(0);
67
 
        OK = new QPushButton(this);
68
 
        OK->setText( tr("Accept"));
69
 
        OK->setDefault(true);
70
 
        vboxLayout1->addWidget(OK);
71
 
        hboxLayout1 = new QHBoxLayout();
72
 
        hboxLayout1->setSpacing(0);
73
 
        hboxLayout1->setMargin(0);
74
 
        addToExceptionList = new QCheckBox(this);
75
 
        hboxLayout1->addWidget(addToExceptionList);
76
 
        addToExceptionListText = new QLabel(this);
77
 
        addToExceptionListText->setText( tr("Add to the\nException List"));
78
 
        hboxLayout1->addWidget(addToExceptionListText);
79
 
        vboxLayout1->addLayout(hboxLayout1);
80
 
        Layout1->addLayout(vboxLayout1);
81
 
        addToExceptionList->setEnabled(false);
82
 
        addToExceptionListText->setEnabled(false);
83
 
        addToExceptionList->setChecked(false);
84
 
 
85
 
        vboxLayout2 = new QVBoxLayout();
86
 
        vboxLayout2->setSpacing(5);
87
 
        vboxLayout2->setMargin(0);
88
 
        Skip = new QPushButton(this);
89
 
        Skip->setText( tr("Skip"));
90
 
        vboxLayout2->addWidget(Skip);
91
 
        hboxLayout2 = new QHBoxLayout();
92
 
        hboxLayout2->setSpacing(0);
93
 
        hboxLayout2->setMargin(0);
94
 
        addToIgnoreList = new QCheckBox(this);
95
 
        hboxLayout2->addWidget(addToIgnoreList);
96
 
        addToIgnoreListText = new QLabel(this);
97
 
        addToIgnoreListText->setText( tr("Add to the\nIgnore List"));
98
 
        hboxLayout2->addWidget(addToIgnoreListText);
99
 
        vboxLayout2->addLayout(hboxLayout2);
100
 
        Layout1->addLayout(vboxLayout2);
101
 
        addToIgnoreList->setChecked(false);
102
 
 
103
 
        vboxLayout3 = new QVBoxLayout();
104
 
        vboxLayout3->setSpacing(5);
105
 
        vboxLayout3->setMargin(0);
106
 
        Cancel = new QPushButton(this);
107
 
        Cancel->setText( tr("Cancel"));
108
 
        vboxLayout3->addWidget(Cancel);
109
 
        QSpacerItem* spacer = new QSpacerItem(2, 2, QSizePolicy::Minimum, QSizePolicy::Expanding);
110
 
        vboxLayout3->addItem(spacer);
111
 
        Layout1->addLayout(vboxLayout3);
112
 
        HyAskLayout->addLayout ( Layout1 );
113
 
 
114
 
        connect ( OK, SIGNAL ( clicked() ), this, SLOT ( accept() ) );
115
 
        connect ( Cancel, SIGNAL ( clicked() ), this, SLOT ( reject() ) );
116
 
        connect ( Skip, SIGNAL ( clicked() ), this, SLOT ( DoSkip() ) );
117
 
        connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
118
 
        resize(minimumSizeHint());
119
 
}
120
 
 
121
 
void HyAsk::accept()
122
 
{
123
 
        xpos = pos().x();
124
 
        ypos = pos().y();
125
 
        QDialog::accept();
126
 
}
127
 
 
128
 
void HyAsk::reject()
129
 
{
130
 
        xpos = pos().x();
131
 
        ypos = pos().y();
132
 
        QDialog::reject();
133
 
}
134
 
 
135
 
void HyAsk::Check()
136
 
{
137
 
        disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
138
 
        QString in = Wort->text();
139
 
        QString out = in.replace ( QRegExp ( "(-)+" ), "-" );
140
 
        Wort->setText ( out );
141
 
        addToExceptionList->setEnabled(true);
142
 
        addToExceptionListText->setEnabled(true);
143
 
        connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
144
 
}
145
 
 
146
 
void HyAsk::DoSkip()
147
 
{
148
 
        disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
149
 
        QString in = Wort->text();
150
 
        QString out = in.replace ( QRegExp ( "(-)+" ), "" );
151
 
        Wort->setText ( out );
152
 
        accept();
153
 
}
154