Rev 14046 | Rev 14116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
13761 | 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 | */ |
||
7 | |||
8 | #include <QDebug> |
||
9 | #include <QPushButton> |
||
10 | #include <QLayout> |
||
11 | #include <QListWidget> |
||
12 | #include <QVBoxLayout> |
||
13 | |||
14 | #include "preferencesdialog.h" |
||
15 | |||
16 | #include "commonstrings.h" |
||
13870 | cbradney | 17 | #include "prefsmanager.h" |
18 | #include "scribus.h" |
||
19 | #include "units.h" |
||
13761 | cbradney | 20 | #include "util_icon.h" |
21 | |||
22 | PreferencesDialog::PreferencesDialog( QWidget* parent ) |
||
23 | : QDialog(parent), |
||
24 | counter(0) |
||
25 | { |
||
26 | setupUi(this); |
||
27 | setObjectName(QString::fromLocal8Bit("PreferencesDialog")); |
||
28 | setupListWidget(); |
||
29 | while (prefsStackWidget->currentWidget()!=0) |
||
30 | prefsStackWidget->removeWidget(prefsStackWidget->currentWidget()); |
||
31 | prefs_UserInterface = new Prefs_UserInterface(this); |
||
32 | addItem( tr("User Interface"), loadIcon("scribus.png"), prefs_UserInterface); |
||
33 | prefs_Paths = new Prefs_Paths(this); |
||
34 | addItem( tr("Paths"), loadIcon("tools.png"), prefs_Paths); |
||
35 | prefs_DocumentSetup = new Prefs_DocumentSetup(this); |
||
36 | addItem( tr("Document Setup"), loadIcon("scribusdoc.png"), prefs_DocumentSetup); |
||
37 | prefs_Guides = new Prefs_Guides(this); |
||
38 | addItem( tr("Guides"), loadIcon("guides.png"), prefs_Guides); |
||
39 | prefs_Typography = new Prefs_Typography(this); |
||
40 | addItem( tr("Typography"), loadIcon("typography.png"), prefs_Typography); |
||
41 | prefs_ItemTools = new Prefs_ItemTools(this); |
||
42 | addItem( tr("Item Tools"), loadIcon("tools.png"), prefs_ItemTools); |
||
43 | prefs_OperatorTools = new Prefs_OperatorTools(this); |
||
44 | addItem( tr("Operator Tools"), loadIcon("tools.png"), prefs_OperatorTools); |
||
45 | prefs_Hyphenator = new Prefs_Hyphenator(this); |
||
46 | addItem( tr("Hyphenator"), loadIcon("hyphenate.png"), prefs_Hyphenator); |
||
47 | prefs_Fonts = new Prefs_Fonts(this); |
||
48 | addItem( tr("Fonts"), loadIcon("font.png"), prefs_Fonts); |
||
49 | prefs_Printer = new Prefs_Printer(this); |
||
50 | addItem( tr("Printer"), loadIcon("printer.png"), prefs_Printer); |
||
51 | prefs_ColorManagement = new Prefs_ColorManagement(this); |
||
52 | addItem( tr("Color Management"), loadIcon("blend.png"), prefs_ColorManagement); |
||
53 | prefs_PDFExport = new Prefs_PDFExport(this); |
||
54 | addItem( tr("PDF Export"), loadIcon("acroread32.png"), prefs_PDFExport); |
||
55 | prefs_DocumentItemAttributes = new Prefs_DocumentItemAttributes(this); |
||
56 | addItem( tr("Document Item Attributes"), loadIcon("docattributes.png"), prefs_DocumentItemAttributes); |
||
57 | prefs_TableOfContents = new Prefs_TableOfContents(this); |
||
58 | addItem( tr("Tables of Contents"), loadIcon("tabtocindex.png"), prefs_TableOfContents); |
||
59 | prefs_KeyboardShortcuts = new Prefs_KeyboardShortcuts(this); |
||
60 | addItem( tr("Keyboard Shortcuts"), loadIcon("key_bindings.png"), prefs_KeyboardShortcuts); |
||
61 | prefs_Scrapbook = new Prefs_Scrapbook(this); |
||
62 | addItem( tr("Scrapbook"), loadIcon("scrap.png"), prefs_Scrapbook); |
||
63 | prefs_Display = new Prefs_Display(this); |
||
64 | addItem( tr("Display"), loadIcon("screen.png"), prefs_Display); |
||
65 | prefs_ExternalTools = new Prefs_ExternalTools(this); |
||
66 | addItem( tr("External Tools"), loadIcon("externaltools.png"), prefs_ExternalTools); |
||
67 | prefs_Miscellaneous = new Prefs_Miscellaneous(this); |
||
68 | addItem( tr("Miscellaneous"), loadIcon("misc.png"), prefs_Miscellaneous); |
||
69 | prefs_Plugins = new Prefs_Plugins(this); |
||
70 | addItem( tr("Plugins"), loadIcon("plugins.png"), prefs_Plugins); |
||
71 | prefs_ShortWords = new Prefs_ShortWords(this); |
||
72 | addItem( tr("Short Words"), loadIcon("tools.png"), prefs_ShortWords); |
||
73 | prefs_Scripter = new Prefs_Scripter(this); |
||
74 | addItem( tr("Scripter"), loadIcon("tools.png"), prefs_Scripter); |
||
75 | |||
76 | arrangeIcons(); |
||
77 | preferencesTypeList->item(0)->setSelected(true); |
||
78 | itemSelected(preferencesTypeList->item(0)); |
||
79 | |||
80 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
||
81 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
||
14046 | cbradney | 82 | connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked())); |
13761 | cbradney | 83 | connect(preferencesTypeList, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* ))); |
13870 | cbradney | 84 | |
85 | initPreferenceValues(); |
||
14046 | cbradney | 86 | setupGui(); |
14023 | cbradney | 87 | |
13761 | cbradney | 88 | } |
89 | |||
14046 | cbradney | 90 | void PreferencesDialog::restoreDefaults() |
91 | { |
||
92 | prefsManager->initDefaults(); |
||
93 | setupGui(); |
||
94 | } |
||
95 | |||
96 | void PreferencesDialog::initPreferenceValues() |
||
97 | { |
||
98 | prefsManager=PrefsManager::instance(); |
||
99 | localPrefs=prefsManager->appPrefs; |
||
100 | mainWin = (ScribusMainWindow*)parent(); |
||
101 | docUnitIndex = localPrefs.docSetupPrefs.docUnitIndex; |
||
102 | unitRatio = unitGetRatioFromIndex(docUnitIndex); |
||
103 | } |
||
104 | |||
105 | void PreferencesDialog::setupGui() |
||
106 | { |
||
14091 | cbradney | 107 | prefs_Scrapbook->restoreDefaults(&localPrefs); |
14046 | cbradney | 108 | prefs_Display->restoreDefaults(&localPrefs); |
109 | } |
||
110 | |||
13761 | cbradney | 111 | PreferencesDialog::~PreferencesDialog() |
112 | { |
||
113 | } |
||
114 | |||
14046 | cbradney | 115 | void PreferencesDialog::accept() |
116 | { |
||
117 | saveGuiToPrefs(); |
||
118 | QDialog::accept (); |
||
119 | } |
||
120 | |||
13761 | cbradney | 121 | void PreferencesDialog::setupListWidget() |
122 | { |
||
123 | preferencesTypeList->setDragEnabled(false); |
||
124 | preferencesTypeList->setViewMode(QListView::ListMode); |
||
125 | preferencesTypeList->setFlow(QListView::TopToBottom); |
||
126 | preferencesTypeList->setIconSize(QSize(32,32)); |
||
127 | preferencesTypeList->setSortingEnabled(false); |
||
128 | preferencesTypeList->setWrapping(false); |
||
129 | preferencesTypeList->setWordWrap(true); |
||
130 | preferencesTypeList->setAcceptDrops(false); |
||
131 | preferencesTypeList->setDropIndicatorShown(false); |
||
132 | preferencesTypeList->setDragDropMode(QAbstractItemView::NoDragDrop); |
||
133 | //preferencesTypeList->setResizeMode(QListView::Adjust); |
||
134 | preferencesTypeList->setSelectionMode(QAbstractItemView::SingleSelection); |
||
135 | |||
136 | preferencesTypeList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||
137 | preferencesTypeList->clear(); |
||
138 | |||
139 | } |
||
140 | |||
141 | int PreferencesDialog::addItem(QString name, QPixmap icon, QWidget *tab) |
||
142 | { |
||
13870 | cbradney | 143 | //TODO: Can we avoid using this name and duplicating strings by getting it from the tab UIs |
13761 | cbradney | 144 | QListWidgetItem* newItem = new QListWidgetItem(icon, name, preferencesTypeList); |
145 | newItem->setTextAlignment(Qt::AlignHCenter); |
||
146 | prefsStackWidget->addWidget(tab); |
||
147 | stackWidgetMap.insert(newItem, counter); |
||
148 | counter++; |
||
149 | return counter-1; |
||
150 | } |
||
151 | |||
152 | |||
153 | void PreferencesDialog::itemSelected(QListWidgetItem* ic) |
||
154 | { |
||
155 | if (ic == 0) |
||
156 | return; |
||
157 | if (stackWidgetMap.contains(ic)) |
||
158 | { |
||
159 | //emit aboutToShow(prefsWidgets->widget(itemMap[ic])); |
||
160 | prefsStackWidget->setCurrentIndex(stackWidgetMap[ic]); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | void PreferencesDialog::changeEvent(QEvent *e) |
||
165 | { |
||
166 | if (e->type() == QEvent::LanguageChange) |
||
167 | { |
||
168 | languageChange(); |
||
169 | } |
||
170 | else |
||
171 | QWidget::changeEvent(e); |
||
172 | } |
||
173 | |||
174 | void PreferencesDialog::languageChange() |
||
175 | { |
||
13870 | cbradney | 176 | setWindowTitle( tr( "Preferences" ) ); |
13761 | cbradney | 177 | } |
178 | |||
179 | void PreferencesDialog::arrangeIcons() |
||
180 | {/* |
||
181 | int maxWidth = 0; |
||
182 | QListWidgetItem* ic; |
||
183 | int startY = 5; |
||
184 | for (int cc = 0; cc < preferencesTypeList->count(); ++cc) |
||
185 | { |
||
186 | ic = preferencesTypeList->item(cc); |
||
187 | QRect ir = preferencesTypeList->visualItemRect(ic); |
||
188 | maxWidth = qMax(ir.width(), maxWidth); |
||
189 | } |
||
190 | preferencesTypeList->setMaximumWidth(maxWidth+16); |
||
191 | preferencesTypeList->setResizeMode(QListView::Fixed); |
||
192 | #ifdef _WIN32 |
||
193 | int scrollBarWidth = 0; |
||
194 | QList<QScrollBar*> scrollBars = preferencesTypeList->findChildren<QScrollBar*>(); |
||
195 | for (int cc = 0; cc < scrollBars.count(); ++cc) |
||
196 | { |
||
197 | if (scrollBars.at(cc)->orientation() == Qt::Vertical) |
||
198 | { |
||
199 | scrollBarWidth = scrollBars.at(cc)->height(); |
||
200 | break; |
||
201 | } |
||
202 | } |
||
203 | #else |
||
204 | int scrollBarWidth = maxWidth; |
||
205 | #endif |
||
206 | int startX = qMax((preferencesTypeList->viewport()->width() - scrollBarWidth) / 2, 0); |
||
207 | for (int cc = 0; cc < preferencesTypeList->count(); ++cc) |
||
208 | { |
||
209 | ic = preferencesTypeList->item(cc); |
||
210 | QRect ir = preferencesTypeList->visualItemRect(ic); |
||
211 | |||
212 | #ifdef _WIN32 |
||
213 | preferencesTypeList->setPositionForIndex(QPoint(qMax(startX - ir.width() / 2, 0), startY), preferencesTypeList->indexFromItem(ic)); |
||
214 | #else |
||
215 | int moveW = (maxWidth - ir.width()) / 2; |
||
216 | preferencesTypeList->setPositionForIndex(QPoint(moveW + startX, startY), preferencesTypeList->indexFromItem(ic)); |
||
217 | #endif |
||
218 | |||
219 | startY += ir.height()+5; |
||
220 | }*/ |
||
221 | } |
||
13870 | cbradney | 222 | |
14046 | cbradney | 223 | void PreferencesDialog::applyButtonClicked() |
13870 | cbradney | 224 | { |
14046 | cbradney | 225 | Prefs_Pane* pp=qobject_cast<Prefs_Pane *>(prefsStackWidget->currentWidget()); |
226 | if (pp) |
||
227 | pp->saveGuiToPrefs(&localPrefs); |
||
13870 | cbradney | 228 | } |
14046 | cbradney | 229 | |
230 | void PreferencesDialog::saveGuiToPrefs() |
||
231 | { |
||
14091 | cbradney | 232 | prefs_Scrapbook->saveGuiToPrefs(&localPrefs); |
14046 | cbradney | 233 | prefs_Display->saveGuiToPrefs(&localPrefs); |
234 | } |
||
235 |