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 /* This is the Scribus Short Words GUI class implementation.
8 
9 This code is based on the Scribus-Vlna plug in rewritten for
10 international use.
11 
12 2004 Petr Vanek <petr@yarpen.cz>
13 
14 This program is free software - see LICENSE file in the distribution
15 or documentation
16 */
17 
18 #include "version.h"
19 #include "swdialog.h"
20 
21 
22 #include "scpaths.h"
23 #include "configuration.h"
24 #include "ui/helpbrowser.h"
25 
26 #include <QGridLayout>
27 #include <QHBoxLayout>
28 #include <QVBoxLayout>
29 #include <QSpacerItem>
30 #include <QLabel>
31 #include <QPushButton>
32 #include <QGroupBox>
33 #include <QRadioButton>
34 #include <QToolTip>
35 
36 #include "commonstrings.h"
37 #include "langmgr.h"
38 
SWDialog(QWidget * parent)39 SWDialog::SWDialog(QWidget* parent) : QDialog(parent)
40 {
41 	setupUi(this);
42 
43 	cfg = new SWConfig();
44 
45 	QStringList langCodes = cfg->getAvailableLanguagesList();
46 	for (int i = 0; i< langCodes.count(); ++i)
47 	{
48 		const QString& code = langCodes.at(i);
49 		QString lang = LanguageManager::instance()->getLangFromAbbrev(code, true);
50 		languageComboBox->addItem(lang, code);
51 	}
52 
53 	languageChange();
54 	resize(minimumSizeHint());
55 
56 	// signals and slots connections
57 	connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
58 			 this, SLOT(okButton_pressed()));
59 	connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
60 			 this, SLOT(cancelButton_pressed()));
61 	connect(styleCheckBox, SIGNAL(toggled(bool)),
62 			 languageComboBox, SLOT(setDisabled(bool)));
63 
64 	selectAction(cfg->action);
65 	styleCheckBox->setChecked(cfg->useStyle);
66 
67 	int langIndex = languageComboBox->findData(cfg->currentLanguage);
68 	if (langIndex >= 0)
69 		languageComboBox->setCurrentIndex(langIndex);
70 }
71 
72 /*
73  *  Destroys the object and frees any allocated resources
74  */
~SWDialog()75 SWDialog::~SWDialog()
76 {
77 }
78 
actionSelected()79 int SWDialog::actionSelected()
80 {
81 	if (frameRadio->isChecked())
82 		return 0;
83 	if (pageRadio->isChecked())
84 		return 1;
85 	if (allRadio->isChecked())
86 		return 2;
87 	return 0;
88 }
89 
useStyleLang()90 bool SWDialog::useStyleLang()
91 {
92 	return styleCheckBox->isChecked();
93 }
94 
lang()95 QString SWDialog::lang()
96 {
97 	QVariant langCode = languageComboBox->currentData(Qt::UserRole);
98 	return langCode.toString();
99 }
100 
savePrefs()101 void SWDialog::savePrefs()
102 {
103 	cfg->action = actionSelected();
104 	cfg->useStyle = styleCheckBox->isChecked();
105 	cfg->currentLanguage = languageComboBox->currentData().toString();
106 	cfg->saveConfig();
107 }
108 
109 /*
110  *  Sets the strings of the subwidgets using the current
111  *  language.
112  */
languageChange()113 void SWDialog::languageChange()
114 {
115 	setWindowTitle( tr("Short Words", "short words plugin"));
116 	buttonGroup->setTitle( tr("Apply Unbreakable Space To:", "short words plugin"));
117 	frameRadio->setText( tr("&Selected Frames", "short words plugin"));
118 	pageRadio->setText( tr("Active &Page", "short words plugin"));
119 	allRadio->setText( tr("&All Items", "short words plugin"));
120 // 	okButton->setText(CommonStrings::tr_OK);
121 // 	cancelButton->setText(CommonStrings::tr_Cancel);
122 	frameRadio->setToolTip( tr("Only selected frames processed", "short words plugin"));
123 	pageRadio->setToolTip( tr("Only actual page processed", "short words plugin"));
124 	allRadio->setToolTip( tr("All items in document processed", "short words plugin"));
125 }
126 
okButton_pressed()127 void SWDialog::okButton_pressed()
128 {
129 	savePrefs();
130 	accept();
131 }
132 
cancelButton_pressed()133 void SWDialog::cancelButton_pressed()
134 {
135 	savePrefs();
136 	reject();
137 }
138 
selectAction(int aAction)139 void SWDialog::selectAction(int aAction)
140 {
141 	if (aAction!=0 && aAction!=1 && aAction!=2)
142 		aAction = 0;
143 	if (aAction == 0)
144 		frameRadio->setChecked(true);
145 	else if (aAction == 1)
146 		pageRadio->setChecked(true);
147 	else if (aAction == 2)
148 		allRadio->setChecked(true);
149 }
150