summaryrefslogtreecommitdiffstats
path: root/scribus/hyask.cpp
blob: 8b3ebb58dcabf57285bc38c6ea3a018db30169d2 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
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 "hyask.h"
#include <QPixmap>
#include <QRegExp>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QKeyEvent>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>

#include "util_icon.h"

WortEdit::WortEdit ( QWidget* parent ) : QLineEdit ( parent )
{}

void WortEdit::keyPressEvent ( QKeyEvent *k )
{
	int p = cursorPosition();
	QChar cc = text() [p];
	if ( ( k->key() == Qt::Key_Left ) || ( k->key() == Qt::Key_Right ) )
		QLineEdit::keyPressEvent ( k );
	if ( k->key() == Qt::Key_Delete )
	{
		if ( cc == '-' )
			QLineEdit::keyPressEvent ( k );
		setCursorPosition ( p );
	}
	if ( ( k->key() == Qt::Key_Backspace ) && ( p != 0 ) )
	{
		cc = text() [p-1];
		if ( cc == '-' )
			QLineEdit::keyPressEvent ( k );
		setCursorPosition ( p-1 );
	}
	if ( k->key() == Qt::Key_Minus )
		QLineEdit::keyPressEvent ( k );
}

HyAsk::HyAsk ( QWidget* parent, QString HWort ) : QDialog ( parent )
{
	setModal(true);
	setWindowTitle( tr( "Possible Hyphenation" ));
	setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
	HyAskLayout = new QVBoxLayout(this);
	HyAskLayout->setMargin(10);
	HyAskLayout->setSpacing(5);

	Wort = new WortEdit ( this );
	Wort->setMinimumSize ( QSize ( 300, 0 ) );
	Wort->setDragEnabled ( false );
	Wort->setText ( HWort );
	HyAskLayout->addWidget ( Wort );

	Layout1 = new QHBoxLayout;
	Layout1->setMargin(0);
	Layout1->setSpacing(5);

	vboxLayout1 = new QVBoxLayout();
	vboxLayout1->setSpacing(5);
	vboxLayout1->setMargin(0);
	OK = new QPushButton(this);
	OK->setText( tr("Accept"));
	OK->setDefault(true);
	vboxLayout1->addWidget(OK);
	hboxLayout1 = new QHBoxLayout();
	hboxLayout1->setSpacing(0);
	hboxLayout1->setMargin(0);
	addToExceptionList = new QCheckBox(this);
	hboxLayout1->addWidget(addToExceptionList);
	addToExceptionListText = new QLabel(this);
	addToExceptionListText->setText( tr("Add to the\nException List"));
	hboxLayout1->addWidget(addToExceptionListText);
	vboxLayout1->addLayout(hboxLayout1);
	Layout1->addLayout(vboxLayout1);
	addToExceptionList->setEnabled(false);
	addToExceptionListText->setEnabled(false);
	addToExceptionList->setChecked(false);

	vboxLayout2 = new QVBoxLayout();
	vboxLayout2->setSpacing(5);
	vboxLayout2->setMargin(0);
	Skip = new QPushButton(this);
	Skip->setText( tr("Skip"));
	vboxLayout2->addWidget(Skip);
	hboxLayout2 = new QHBoxLayout();
	hboxLayout2->setSpacing(0);
	hboxLayout2->setMargin(0);
	addToIgnoreList = new QCheckBox(this);
	hboxLayout2->addWidget(addToIgnoreList);
	addToIgnoreListText = new QLabel(this);
	addToIgnoreListText->setText( tr("Add to the\nIgnore List"));
	hboxLayout2->addWidget(addToIgnoreListText);
	vboxLayout2->addLayout(hboxLayout2);
	Layout1->addLayout(vboxLayout2);
	addToIgnoreList->setChecked(false);

	vboxLayout3 = new QVBoxLayout();
	vboxLayout3->setSpacing(5);
	vboxLayout3->setMargin(0);
	Cancel = new QPushButton(this);
	Cancel->setText( tr("Cancel"));
	vboxLayout3->addWidget(Cancel);
	QSpacerItem* spacer = new QSpacerItem(2, 2, QSizePolicy::Minimum, QSizePolicy::Expanding);
	vboxLayout3->addItem(spacer);
	Layout1->addLayout(vboxLayout3);
	HyAskLayout->addLayout ( Layout1 );

	connect ( OK, SIGNAL ( clicked() ), this, SLOT ( accept() ) );
	connect ( Cancel, SIGNAL ( clicked() ), this, SLOT ( reject() ) );
	connect ( Skip, SIGNAL ( clicked() ), this, SLOT ( DoSkip() ) );
	connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
	resize(minimumSizeHint());
}

void HyAsk::accept()
{
	xpos = pos().x();
	ypos = pos().y();
	QDialog::accept();
}

void HyAsk::reject()
{
	xpos = pos().x();
	ypos = pos().y();
	QDialog::reject();
}

void HyAsk::Check()
{
	disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
	QString in = Wort->text();
	QString out = in.replace ( QRegExp ( "(-)+" ), "-" );
	Wort->setText ( out );
	addToExceptionList->setEnabled(true);
	addToExceptionListText->setEnabled(true);
	connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
}

void HyAsk::DoSkip()
{
	disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
	QString in = Wort->text();
	QString out = in.replace ( QRegExp ( "(-)+" ), "" );
	Wort->setText ( out );
	accept();
}