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 "iconmanager.h"
18
WortEdit(QWidget * parent)19 WortEdit::WortEdit ( QWidget* parent ) : QLineEdit ( parent )
20 {}
21
keyPressEvent(QKeyEvent * k)22 void WortEdit::keyPressEvent ( QKeyEvent *k )
23 {
24 int p = cursorPosition();
25 QChar cc = text().at(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().at(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
HyAsk(QWidget * parent,const QString & HWort)45 HyAsk::HyAsk ( QWidget* parent, const QString& HWort ) : QDialog ( parent )
46 {
47 xpos = ypos = 0;
48
49 setModal(true);
50 setWindowTitle( tr( "Possible Hyphenation" ));
51 setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
52 HyAskLayout = new QVBoxLayout(this);
53 HyAskLayout->setContentsMargins(9, 9, 9, 9);
54 HyAskLayout->setSpacing(6);
55
56 Wort = new WortEdit ( this );
57 Wort->setMinimumSize ( QSize ( 300, 0 ) );
58 Wort->setDragEnabled ( false );
59 Wort->setText ( HWort );
60 HyAskLayout->addWidget ( Wort );
61
62 Layout1 = new QHBoxLayout;
63 Layout1->setContentsMargins(0, 0, 0, 0);
64 Layout1->setSpacing(6);
65
66 vboxLayout1 = new QVBoxLayout();
67 vboxLayout1->setSpacing(6);
68 vboxLayout1->setContentsMargins(0, 0, 0, 0);
69 OK = new QPushButton(this);
70 OK->setText( tr("Accept"));
71 OK->setToolTip(tr("Accept the proposed hyphenation"));
72 OK->setDefault(true);
73 vboxLayout1->addWidget(OK);
74 hboxLayout1 = new QHBoxLayout();
75 hboxLayout1->setSpacing(6);
76 hboxLayout1->setContentsMargins(0, 0, 0, 0);
77 addToExceptionList = new QCheckBox(this);
78 addToExceptionList->setToolTip(tr("Add edited hyphen to local hyphenation dictionary list"));
79 hboxLayout1->addWidget(addToExceptionList);
80 addToExceptionListText = new QLabel(this);
81 addToExceptionListText->setText( tr("Add to the\nException List"));
82 hboxLayout1->addWidget(addToExceptionListText);
83 vboxLayout1->addLayout(hboxLayout1);
84 Layout1->addLayout(vboxLayout1);
85 addToExceptionList->setEnabled(false);
86 addToExceptionListText->setEnabled(false);
87 addToExceptionList->setChecked(false);
88
89 vboxLayout2 = new QVBoxLayout();
90 vboxLayout2->setSpacing(6);
91 vboxLayout2->setContentsMargins(0, 0, 0, 0);
92 Skip = new QPushButton(this);
93 Skip->setText( tr("Skip"));
94 vboxLayout2->addWidget(Skip);
95 hboxLayout2 = new QHBoxLayout();
96 hboxLayout2->setSpacing(6);
97 hboxLayout2->setContentsMargins(0, 0, 0, 0);
98 addToIgnoreList = new QCheckBox(this);
99 addToIgnoreList->setToolTip(tr("Add edited word to words that should not be hyphenated"));
100 hboxLayout2->addWidget(addToIgnoreList);
101 addToIgnoreListText = new QLabel(this);
102 addToIgnoreListText->setText( tr("Add to the\nIgnore List"));
103 hboxLayout2->addWidget(addToIgnoreListText);
104 vboxLayout2->addLayout(hboxLayout2);
105 Layout1->addLayout(vboxLayout2);
106 addToIgnoreList->setChecked(false);
107
108 vboxLayout3 = new QVBoxLayout();
109 vboxLayout3->setSpacing(6);
110 vboxLayout3->setContentsMargins(0, 0, 0, 0);
111 Cancel = new QPushButton(this);
112 Cancel->setText( tr("Cancel"));
113 Cancel->setToolTip(tr("Do not apply the proposed hyphenation"));
114 vboxLayout3->addWidget(Cancel);
115 QSpacerItem* spacer = new QSpacerItem(2, 2, QSizePolicy::Minimum, QSizePolicy::Expanding);
116 vboxLayout3->addItem(spacer);
117 Layout1->addLayout(vboxLayout3);
118 HyAskLayout->addLayout ( Layout1 );
119
120 connect ( OK, SIGNAL ( clicked() ), this, SLOT ( accept() ) );
121 connect ( Cancel, SIGNAL ( clicked() ), this, SLOT ( reject() ) );
122 connect ( Skip, SIGNAL ( clicked() ), this, SLOT ( DoSkip() ) );
123 connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
124 resize(minimumSizeHint());
125 }
126
accept()127 void HyAsk::accept()
128 {
129 xpos = pos().x();
130 ypos = pos().y();
131 QDialog::accept();
132 }
133
reject()134 void HyAsk::reject()
135 {
136 xpos = pos().x();
137 ypos = pos().y();
138 QDialog::reject();
139 }
140
Check()141 void HyAsk::Check()
142 {
143 disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
144 QString in = Wort->text();
145 QString out = in.replace ( QRegExp ( "(-)+" ), "-" );
146 Wort->setText ( out );
147 addToExceptionList->setEnabled(true);
148 addToExceptionListText->setEnabled(true);
149 connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
150 }
151
DoSkip()152 void HyAsk::DoSkip()
153 {
154 disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
155 QString in = Wort->text();
156 QString out = in.replace ( QRegExp ( "(-)+" ), "" );
157 Wort->setText ( out );
158 accept();
159 }
160
161