~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/stylemanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2007-08-11 17:41:51 UTC
  • mfrom: (0.1.1 upstream) (4.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20070811174151-tmkgjvjuc0mtk8ul
Tags: 1.3.4.dfsg+svn20071115-1
* Upstream svn update (Closes: #447480, #448949).
* debian/NEWS: Added a note for users wanting stable Scribus to switch to
  the "scribus" package (Closes: #427638).
* debian/watch: Updated the watch regex to properly track sourceforge
  releases for this branch (Closes: #449700).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Riku Leino                                      *
3
 
 *   riku@scribus.info                                                     *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
 
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
*/
20
7
 
21
8
#include "stylemanager.h"
22
9
#include "stylemanager.moc"
23
10
#include "styleitem.h"
24
11
#include "scribusdoc.h"
 
12
#include "scribusview.h"
 
13
#include "smreplacedia.h"
 
14
#include "smtextstyles.h"
 
15
#include "smlinestyle.h"
 
16
#include "styleitem.h"
 
17
#include "selection.h"
 
18
#include "prefsmanager.h"
 
19
#include "prefsfile.h"
 
20
#include "prefscontext.h"
 
21
#include "commonstrings.h"
 
22
#include "customfdialog.h"
 
23
#include "fileloader.h"
 
24
#include "smstyleimport.h"
25
25
#include <qheader.h>
26
26
#include <qlabel.h>
27
27
#include <qlistview.h>
30
30
#include <qevent.h>
31
31
#include <qlineedit.h>
32
32
#include <qlayout.h>
33
 
 
34
 
StyleManager::StyleManager(QWidget *parent, const char *name) : SMBase(parent, name), item_(0), widget_(0)
 
33
#include <qbuttongroup.h>
 
34
#include <qradiobutton.h>
 
35
#include <qpushbutton.h>
 
36
#include <qsplitter.h>
 
37
#include <qsize.h>
 
38
#include <qfont.h>
 
39
#include <qpainter.h>
 
40
#include <qtooltip.h>
 
41
#include <qpair.h>
 
42
#include <qmessagebox.h>
 
43
 
 
44
const QString StyleManager::SEPARATOR = "$$$$"; // dumb but it works
 
45
 
 
46
StyleManager::StyleManager(QWidget *parent, const char *name) : SMBase(parent, name), item_(0), widget_(0), shortcutWidget_(0), currentType_(QString::null), isEditMode_(true), doc_(0)
35
47
{
36
 
        typeView->header()->hide();
 
48
        splitter->setMinimumWidth(0);
 
49
        splitter->setResizeMode(leftFrame, QSplitter::KeepSize);
 
50
        splitter->setResizeMode(rightFrame, QSplitter::Stretch);
 
51
        uniqueLabel->hide();
 
52
        rightFrame->hide();
 
53
        svLayout = new QHBoxLayout(styleViewFrame);
 
54
        styleView = new StyleView(styleViewFrame);
 
55
        svLayout->addWidget(styleView);
 
56
        styleView->addColumn( tr("Name"));
 
57
        styleView->addColumn( tr("Shortcut"));
 
58
        styleView->setColumnWidthMode(NAME_COL, QListView::Maximum);
 
59
        styleView->setColumnWidthMode(SHORTCUT_COL, QListView::Maximum);
 
60
        styleView->setColumnWidth(NAME_COL, 0);
 
61
        styleView->setColumnWidth(SHORTCUT_COL, 0);
37
62
        styleView->header()->hide();
 
63
        applyButton->setEnabled(false);
 
64
        resetButton->setEnabled(false);
38
65
        layout_ = new QGridLayout(mainFrame);
39
 
}
40
 
 
41
 
void StyleManager::currentDoc(ScribusDoc *doc)
42
 
{
43
 
        for (uint i = 0; i < items_.count(); ++i)
 
66
        newPopup_ = new QPopupMenu(newButton, "newPopup_");
 
67
        rightClickPopup_ = new QPopupMenu(styleView, "rightClickPopup_");
 
68
        newButton->setPopup(newPopup_);
 
69
        QString pname(name);
 
70
        if (pname.isEmpty())
 
71
                pname = "styleManager";
 
72
        prefs_ = PrefsManager::instance()->prefsFile->getContext(pname);
 
73
        isEditMode_ = true;
 
74
        isStoryEditMode_ = false;
 
75
        editPosition_.setX(prefs_->getInt("eX", x()));
 
76
        editPosition_.setY(prefs_->getInt("eY", y()));
 
77
 
 
78
        width_ = prefs_->getInt("Width", 212);
 
79
        widthEm_ = prefs_->getInt("WidthEM", 500);
 
80
        height_ = prefs_->getInt("Height", 450);
 
81
        widthLeft_ = prefs_->getInt("WidthLeft", 192);
 
82
        widthRight_ = prefs_->getInt("WidthRight", 474);
 
83
 
 
84
        newButton->setEnabled(false);
 
85
        cloneButton->setEnabled(false);
 
86
        importButton->setEnabled(false);
 
87
        deleteButton->setEnabled(false);
 
88
        rightClickPopup_->setEnabled(false);
 
89
        newPopup_->setEnabled(false);
 
90
 
 
91
        connect(newPopup_, SIGNAL(activated(int)), this, SLOT(slotNewPopup(int)));
 
92
        connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()));
 
93
        connect(importButton, SIGNAL(clicked()), this, SLOT(slotImport()));
 
94
        connect(resetButton, SIGNAL(clicked()), this, SLOT(slotClean()));
 
95
        connect(applyButton, SIGNAL(clicked()), this, SLOT(slotApply()));
 
96
        connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDelete()));
 
97
        connect(cloneButton, SIGNAL(clicked()), this, SLOT(slotClone()));
 
98
        connect(newButton, SIGNAL(clicked()), this, SLOT(slotNew()));
 
99
        connect(styleView, SIGNAL(rightButtonClicked(QListViewItem*, const QPoint&, int)),
 
100
                        this, SLOT(slotRightClick(QListViewItem*, const QPoint&, int)));
 
101
        connect(styleView, SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)),
 
102
                        this, SLOT(slotDoubleClick(QListViewItem*, const QPoint&, int)));
 
103
 
 
104
        languageChange();
 
105
        slotOk();
 
106
}
 
107
 
 
108
void StyleManager::languageChange()
 
109
{
 
110
/***********************************/
 
111
/*      Begin Tooltips             */
 
112
/***********************************/
 
113
// These are for general Style Manager widgets (not for c/pstyles except the name field
 
114
 
 
115
        // for the "<< Done" button when in edit mode
 
116
        exitEditModeOk_ = tr("Apply all changes and exit edit mode");
 
117
        // for the "Edit >>" button when not in edit mode
 
118
        enterEditModeOk_= tr("Edit styles");
 
119
 
 
120
        QToolTip::add(nameEdit,     tr("Name of the selected style"));
 
121
        QToolTip::add(resetButton,  tr("Reset all changes"));
 
122
        QToolTip::add(applyButton,  tr("Apply all changes"));
 
123
        QToolTip::add(newButton,    tr("Create a new style"));
 
124
        QToolTip::add(importButton, tr("Import styles from another document"));
 
125
        QToolTip::add(cloneButton,  tr("Clone selected style"));
 
126
        QToolTip::add(deleteButton, tr("Delete selected styles"));
 
127
 
 
128
/***********************************/
 
129
/*      End Tooltips               */
 
130
/***********************************/
 
131
 
 
132
        nameLabel->setText( tr("Name:"));
 
133
        resetButton->setText( tr("&Reset"));
 
134
        applyButton->setText( tr("&Apply"));
 
135
        doneText= tr("&Done");
 
136
        editText= tr("&Edit");
 
137
        setOkButtonText();
 
138
        newButton->setText( tr("&New"));
 
139
        importButton->setText( tr("&Import"));
 
140
        cloneButton->setText( tr("&Clone"));
 
141
        deleteButton->setText( tr("&Delete"));
 
142
 
 
143
        if (isEditMode_)
 
144
                QToolTip::add(okButton, exitEditModeOk_);
 
145
        else
 
146
                QToolTip::add(okButton, enterEditModeOk_);
 
147
 
 
148
        if (shortcutWidget_)
 
149
                shortcutWidget_->languageChange();
 
150
 
 
151
        newPopup_->clear();
 
152
        QStringList popupStrings;
 
153
        for (uint i = 0; i < items_.count(); ++i)
 
154
        {
 
155
                popupStrings << items_.at(i)->typeNameSingular();
 
156
                items_.at(i)->languageChange();
 
157
                styleClassesPS_[items_.at(i)->typeNamePlural()] = items_.at(i)->typeNameSingular();
 
158
                styleClassesSP_[items_.at(i)->typeNameSingular()] = items_.at(i)->typeNamePlural();
 
159
        }
 
160
        popupStrings.sort();
 
161
        for (uint i = 0; i < popupStrings.count(); ++i)
 
162
                newPopup_->insertItem(popupStrings[i]);
 
163
 
 
164
        styleView->clear();
 
165
        for (uint i = 0; i < items_.count(); ++i)
 
166
                addNewType(items_.at(i));
 
167
 
 
168
        rightClickPopup_->clear();
 
169
        rcpNewId_ = rightClickPopup_->insertItem( tr("New"), newPopup_);
 
170
        rightClickPopup_->insertItem( tr("Import"), this, SLOT(slotImport()));
 
171
        rightClickPopup_->insertSeparator();
 
172
        rcpEditId_ = rightClickPopup_->insertItem( tr("Edit"), this, SLOT(slotEdit()));
 
173
        rcpCloneId_ = rightClickPopup_->insertItem( tr("Clone"), this, SLOT(slotClone()));
 
174
        rcpToScrapId_ = rightClickPopup_->insertItem( tr("Send to Scrapbook"), this, SLOT(slotScrap()));
 
175
        rightClickPopup_->insertSeparator();
 
176
        rcpDeleteId_ = rightClickPopup_->insertItem( tr("Delete"), this, SLOT(slotDelete()));
 
177
}
 
178
 
 
179
void StyleManager::unitChange()
 
180
{
 
181
        if (doc_)
 
182
        {
 
183
                for (uint i = 0; i < items_.count(); ++i)
 
184
                        items_.at(i)->unitChange();
 
185
 
 
186
                slotSetupWidget();
 
187
        }
 
188
}
 
189
 
 
190
void StyleManager::setOkButtonText()
 
191
{
 
192
        if (!isStoryEditMode_)
 
193
                okButton->setText(isEditMode_ ? "<< " + doneText : editText + " >>");
 
194
        else
 
195
                okButton->setText(CommonStrings::tr_OK);
 
196
}
 
197
 
 
198
void StyleManager::setDoc(ScribusDoc *doc)
 
199
{
 
200
        if (doc)
 
201
        {
 
202
                doc_ = doc;
 
203
                newButton->setEnabled(true);
 
204
                cloneButton->setEnabled(true);
 
205
                importButton->setEnabled(true);
 
206
                deleteButton->setEnabled(true);
 
207
                rightClickPopup_->setEnabled(true);
 
208
                newPopup_->setEnabled(true);
 
209
                connect(doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(slotDocSelectionChanged()));
 
210
        }
 
211
        else
 
212
        {
 
213
                doc_ = 0;
 
214
                newButton->setEnabled(false);
 
215
                cloneButton->setEnabled(false);
 
216
                importButton->setEnabled(false);
 
217
                deleteButton->setEnabled(false);
 
218
                rightClickPopup_->setEnabled(false);
 
219
                newPopup_->setEnabled(false);
 
220
        }
 
221
 
 
222
        // clear the style list and reload from new doc
 
223
        styleView->clear();
 
224
        styleActions_.clear();
 
225
        for (uint i = 0; i < items_.count(); ++i)
 
226
        {
44
227
                items_.at(i)->currentDoc(doc);
45
 
        slotTypeChanged(typeView->currentItem()); // refresh the style view
 
228
                addNewType(items_.at(i)); // forces a reload
 
229
                if (doc_)
 
230
                        items_.at(i)->unitChange();
 
231
        }
46
232
}
47
233
 
48
 
void StyleManager::languageChange()
 
234
void StyleManager::updateColorList()
49
235
{
50
 
 
 
236
        for (uint i = 0; i < items_.count(); ++i)
 
237
        {
 
238
                items_.at(i)->currentDoc(doc_);
 
239
                items_.at(i)->reload();
 
240
        }
51
241
}
52
242
 
53
243
void StyleManager::addStyle(StyleItem *item)
54
244
{
55
245
        items_.append(item);
56
 
        new QListViewItem(typeView, item->typeName());
 
246
        addNewType(item);
 
247
        connect(item, SIGNAL(selectionDirty()), this, SLOT(slotDirty()));
57
248
}
58
249
 
59
250
void StyleManager::slotApply()
60
251
{
61
 
        
 
252
        if (applyButton->isEnabled())
 
253
        {
 
254
                for (uint i = 0; i < items_.count(); ++i)
 
255
                        items_.at(i)->apply();
 
256
        }
 
257
 
 
258
        slotClean();
62
259
}
63
260
 
64
 
 
65
261
void StyleManager::slotDelete()
66
262
{
67
 
        
 
263
        if (!isEditMode_)
 
264
                slotOk(); // switch to edit mode before deleting
 
265
 
 
266
        QStringList selected;
 
267
 
 
268
        if (!rcStyle_.isNull())
 
269
                selected << rcStyle_;
 
270
        else
 
271
        {
 
272
                QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
 
273
                while (it.current()) {
 
274
                        selected << it.current()->text(0);
 
275
                        ++it;
 
276
                }
 
277
        }
 
278
        if (selected.isEmpty())
 
279
                return; // nothing to delete
 
280
 
 
281
        QStringList tmp;
 
282
        QValueList<StyleName> styles = item_->styles(false); // get list from cache
 
283
        for (uint i = 0; i < styles.count(); ++i)
 
284
                tmp << styles[i].first;
 
285
        SMReplaceDia *dia = new SMReplaceDia(selected, tmp, this);
 
286
        if (dia->exec() && item_)
 
287
        {
 
288
                item_->deleteStyles(dia->items());
 
289
                applyButton->setEnabled(true);
 
290
                resetButton->setEnabled(true);
 
291
                reloadStyleView(false);
 
292
        }
 
293
 
 
294
        delete dia;
68
295
}
69
296
 
70
297
 
71
298
void StyleManager::slotImport()
72
299
{
 
300
        if (!doc_)
 
301
                return;
 
302
 
 
303
        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
 
304
        QString wdir = dirs->get("editformats", ".");
 
305
        CustomFDialog dia(this, wdir, tr("Open"), tr("documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)"));
 
306
        if (dia.exec() == QDialog::Accepted)
 
307
        {
 
308
                QString selectedFile = dia.selectedFile();
 
309
                dirs->set("editformats", selectedFile.left(selectedFile.findRev("/")));
 
310
 
 
311
                StyleSet<ParagraphStyle> tmpParaStyles;
 
312
                StyleSet<CharStyle> tmpCharStyles;
 
313
                QMap<QString, multiLine> tmpLineStyles;
 
314
 
 
315
                doc_->loadStylesFromFile(selectedFile, &tmpParaStyles, &tmpCharStyles, &tmpLineStyles);
 
316
 
 
317
// FIXME Once all styles are derived from Style remove this and make a proper
 
318
//       implementation
 
319
// Start hack
 
320
 
 
321
                SMParagraphStyle *pstyle = 0;
 
322
                SMCharacterStyle *cstyle = 0;
 
323
                SMLineStyle      *lstyle = 0;
 
324
                for (uint i = 0; i < items_.count(); ++i)
 
325
                {
 
326
                        pstyle = dynamic_cast<SMParagraphStyle*>(items_.at(i));
 
327
                        if (pstyle)
 
328
                                break;
 
329
                }
 
330
                for (uint i = 0; i < items_.count(); ++i)
 
331
                {
 
332
                        cstyle = dynamic_cast<SMCharacterStyle*>(items_.at(i));
 
333
                        if (cstyle)
 
334
                                break;
 
335
                }
 
336
                for (uint i = 0; i < items_.count(); ++i)
 
337
                {
 
338
                        lstyle = dynamic_cast<SMLineStyle*>(items_.at(i));
 
339
                        if (lstyle)
 
340
                                break;
 
341
                }
 
342
 
 
343
                Q_ASSERT(pstyle && cstyle && lstyle);
 
344
 
 
345
                ImportDialog *dia2 = new ImportDialog(this, &tmpParaStyles, &tmpCharStyles, &tmpLineStyles);
 
346
// end hack
 
347
 
 
348
                QValueList<QPair<QString, QString> > selected;
 
349
                if (dia2->exec())
 
350
                {
 
351
                        if (!isEditMode_)
 
352
                                slotOk();
 
353
                        QStringList neededColors;
 
354
                        neededColors.clear();
 
355
                        QMap<QCheckListItem*, QString>::Iterator it;
 
356
                        for (it = dia2->storedStyles.begin(); it != dia2->storedStyles.end(); ++it)
 
357
                        {
 
358
                                ParagraphStyle& sty(tmpParaStyles[tmpParaStyles.find(it.data())]);
 
359
                                if (it.key()->isOn())
 
360
                                {
 
361
                                        if (dia2->clashRename())
 
362
                                        {
 
363
                                                sty.setName(pstyle->getUniqueName(sty.name()));
 
364
                                                pstyle->tmpStyles()->create(sty);
 
365
                                        }
 
366
                                        else
 
367
                                        {
 
368
                                                if (pstyle->tmpStyles()->find(sty.name()) >= 0)
 
369
                                                        (*(pstyle->tmpStyles()))[pstyle->tmpStyles()->find(it.data())] = sty;
 
370
                                                else
 
371
                                                        pstyle->tmpStyles()->create(sty);
 
372
                                        }
 
373
                                        selected << QPair<QString, QString>(pstyle->typeName(), sty.name());
 
374
                                        if ((!doc_->PageColors.contains(sty.charStyle().strokeColor())) && (!neededColors.contains(sty.charStyle().strokeColor())))
 
375
                                                neededColors.append(sty.charStyle().strokeColor());
 
376
                                        if ((!doc_->PageColors.contains(sty.charStyle().fillColor())) && (!neededColors.contains(sty.charStyle().fillColor())))
 
377
                                                neededColors.append(sty.charStyle().fillColor());
 
378
                                }
 
379
                        }
 
380
 
 
381
                        for (it = dia2->storedCharStyles.begin(); it != dia2->storedCharStyles.end(); ++it)
 
382
                        {
 
383
                                CharStyle& sty(tmpCharStyles[tmpCharStyles.find(it.data())]);
 
384
                                if (it.key()->isOn())
 
385
                                {
 
386
                                        if (dia2->clashRename())
 
387
                                        {
 
388
                                                sty.setName(cstyle->getUniqueName(sty.name()));
 
389
                                                cstyle->tmpStyles()->create(sty);
 
390
                                        }
 
391
                                        else
 
392
                                        {
 
393
                                                if (cstyle->tmpStyles()->find(sty.name()) >= 0)
 
394
                                                        (*(cstyle->tmpStyles()))[cstyle->tmpStyles()->find(it.data())] = sty;
 
395
                                                else
 
396
                                                        cstyle->tmpStyles()->create(sty);
 
397
                                        }
 
398
                                        selected << QPair<QString, QString>(cstyle->typeName(), sty.name());
 
399
                                        if ((!doc_->PageColors.contains(sty.strokeColor())) && (!neededColors.contains(sty.strokeColor())))
 
400
                                                neededColors.append(sty.strokeColor());
 
401
                                        if ((!doc_->PageColors.contains(sty.fillColor())) && (!neededColors.contains(sty.fillColor())))
 
402
                                                neededColors.append(sty.fillColor());
 
403
                                }
 
404
                        }
 
405
 
 
406
                        for (it = dia2->storedLineStyles.begin(); it != dia2->storedLineStyles.end(); ++it)
 
407
                        {
 
408
                                multiLine &sty = tmpLineStyles[it.data()];
 
409
                                QString styName = it.data();
 
410
 
 
411
                                if (it.key()->isOn())
 
412
                                {
 
413
                                        if (dia2->clashRename())
 
414
                                                styName = lstyle->getUniqueName(styName);
 
415
 
 
416
                                        lstyle->tmpLines[styName] = sty;
 
417
                                        selected << QPair<QString, QString>(lstyle->typeName(), styName);
 
418
                                        
 
419
                                        for (uint i = 0; i < sty.count(); ++i)
 
420
                                        {
 
421
                                                if ((!doc_->PageColors.contains(sty[i].Color)) && (!neededColors.contains(sty[i].Color)))
 
422
                                                        neededColors.append(sty[i].Color);
 
423
                                        }
 
424
                                }
 
425
                        }
 
426
 
 
427
                        if (!neededColors.isEmpty())
 
428
                        {
 
429
                                FileLoader fl(selectedFile);
 
430
                                if (fl.TestFile() == -1)
 
431
                                { //TODO put in nice user warning
 
432
                                        delete dia2;
 
433
                                        return;
 
434
                                }
 
435
                                ColorList LColors;
 
436
                                if (fl.ReadColors(selectedFile, LColors))
 
437
                                {
 
438
                                        ColorList::Iterator itc;
 
439
                                        for (itc = LColors.begin(); itc != LColors.end(); ++itc)
 
440
                                        {
 
441
                                                if (neededColors.contains(itc.key()))
 
442
                                                        doc_->PageColors.insert(itc.key(), itc.data());
 
443
                                        }
 
444
                                }
 
445
                        }
 
446
                }
 
447
                delete dia2;
 
448
// Start hack part 2
 
449
                pstyle->currentDoc(doc_);
 
450
                cstyle->currentDoc(doc_);
 
451
// end hack part 2
 
452
                reloadStyleView(false);
 
453
                setSelection(selected);
 
454
                slotDirty();
 
455
                slotSetupWidget();
 
456
        }
 
457
        else
 
458
                return;
 
459
}
 
460
 
 
461
void StyleManager::setSelection(const QValueList<QPair<QString, QString> > &selected)
 
462
{
 
463
        styleView->clearSelection();
73
464
        
 
465
        QListViewItemIterator it(styleView, QListViewItemIterator::Selectable);
 
466
        StyleViewItem *item;
 
467
 
 
468
        while (it.current())
 
469
        {
 
470
                item = dynamic_cast<StyleViewItem*>(it.current());
 
471
                if (item)
 
472
                {
 
473
                        for (uint i = 0; i < selected.count(); ++i)
 
474
                        {
 
475
                                if (item->rootName() == selected[i].first && item->text(NAME_COL) == selected[i].second)
 
476
                                {
 
477
                                        styleView->setCurrentItem(item);
 
478
                                        item->setSelected(true);
 
479
                                        item->repaint();
 
480
                                }
 
481
                        }
 
482
                }
 
483
                ++it;
 
484
        }
 
485
 
 
486
        styleView->triggerUpdate();
 
487
}
 
488
 
 
489
void StyleManager::slotEdit()
 
490
{
 
491
        if (!isEditMode_)
 
492
                slotOk(); // switch to edit mode for cloning
 
493
 
 
494
        if (!rcStyle_.isNull())
 
495
        {
 
496
                QListViewItemIterator it(styleView);
 
497
                while (it.current())
 
498
                {
 
499
                        StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
500
                        if (item && !item->isRoot())
 
501
                        {
 
502
                                if (item->rootName() == styleClassesSP_[rcType_] &&
 
503
                                    item->text(0) == rcStyle_)
 
504
                                {
 
505
                                        styleView->setCurrentItem(item);
 
506
                                        item->setSelected(true);
 
507
                                        item->repaint();
 
508
                                        break;
 
509
                                }
 
510
                        }
 
511
                        ++it;
 
512
                }
 
513
                rcStyle_ = QString::null;
 
514
                rcType_ = QString::null;
 
515
        }
74
516
}
75
517
 
76
518
 
77
519
void StyleManager::slotClone()
78
520
{
 
521
        if (!isEditMode_)
 
522
                slotOk(); // switch to edit mode for cloning
 
523
 
 
524
        if (!rcStyle_.isNull())
 
525
        {
 
526
                QListViewItemIterator it(styleView);
 
527
                while (it.current())
 
528
                {
 
529
                        StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
530
                        if (item && !item->isRoot())
 
531
                        {
 
532
                                if (item->rootName() == styleClassesSP_[rcType_] &&
 
533
                                    item->text(0) == rcStyle_)
 
534
                                {
 
535
                                        styleView->setCurrentItem(item);
 
536
                                        item->setSelected(true);
 
537
                                        item->repaint();
 
538
                                        break;
 
539
                                }
 
540
                        }
 
541
                        ++it;
 
542
                }
 
543
                rcStyle_ = QString::null;
 
544
                rcType_ = QString::null;
 
545
        }
 
546
 
 
547
        QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
 
548
        QValueList<QPair<QString, QString> > names;
 
549
 
 
550
        while (it.current())
 
551
        { // can't create styles here cause createNewStyle() alters the selection
 
552
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
553
                if (item)
 
554
                        names << QPair<QString, QString>(item->rootName(), item->text(NAME_COL));
 
555
                ++it;
 
556
        }
 
557
 
 
558
        for (uint i = 0; i < names.count(); ++i)
 
559
                createNewStyle(names[i].first, names[i].second);
 
560
}
 
561
 
 
562
void StyleManager::slotScrap()
 
563
{
79
564
        
80
565
}
81
566
 
82
567
 
83
568
void StyleManager::slotNew()
84
569
{
85
 
        
86
 
}
87
 
 
88
 
void StyleManager::slotStyleChanged()
89
 
{
90
 
        QStringList selected;
91
 
        QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
92
 
        while (it.current()) {
93
 
                selected << it.current()->text(0);
 
570
//#5334: Dont open into edit mdoe until user has selected a style type
 
571
//      if (!isEditMode_)
 
572
//              slotOk(); // switch to edit mode for a new style
 
573
 
 
574
        // TODO maybe there's something more clever for this
 
575
        newPopup_->exec(newButton->mapToGlobal(QPoint(0, newButton->height() + 2)));
 
576
}
 
577
 
 
578
void StyleManager::slotNewPopup(int i)
 
579
{
 
580
        if (!isEditMode_)
 
581
                slotOk(); // switch to edit mode for a new style
 
582
 
 
583
        QString typeName = rcType_;
 
584
        if (typeName.isNull())
 
585
                typeName = newPopup_->text(i);
 
586
        else if (typeName.isNull() && i < 0)
 
587
                return; // nothing to create
 
588
 
 
589
        rcType_ = QString::null;
 
590
        rcStyle_ = QString::null;
 
591
 
 
592
        createNewStyle(typeName);
 
593
}
 
594
 
 
595
void StyleManager::slotRightClick(QListViewItem *item, const QPoint &point, int col)
 
596
{
 
597
        rcStyle_ = QString::null;
 
598
        rcType_ = QString::null;
 
599
 
 
600
        if (isEditMode_ && item) // make item the only selection if in edit mode
 
601
        {                        // default behaviour for right clicking is not to select the item
 
602
                styleView->clearSelection();
 
603
                styleView->setCurrentItem(item);
 
604
                item->setSelected(true);
 
605
                item->repaint();
 
606
        }
 
607
 
 
608
        StyleViewItem *sitem = dynamic_cast<StyleViewItem*>(item);
 
609
        if (sitem && !sitem->isRoot())
 
610
        {
 
611
                rightClickPopup_->removeItem(rcpNewId_);
 
612
                rcpNewId_ = rightClickPopup_->insertItem( tr("New %1").arg(styleClassesPS_[sitem->rootName()]),
 
613
                                                         this, SLOT(slotNewPopup(int)), 0, -1, 0);
 
614
                rightClickPopup_->setItemEnabled(rcpDeleteId_, true);
 
615
                rightClickPopup_->setItemEnabled(rcpEditId_, true);
 
616
                rightClickPopup_->setItemEnabled(rcpCloneId_, true);
 
617
                rightClickPopup_->setItemEnabled(rcpToScrapId_, true);
 
618
                rcStyle_ = sitem->text(0);
 
619
                rcType_ = styleClassesPS_[sitem->rootName()];
 
620
                loadType(styleClassesPS_[sitem->rootName()]);
 
621
        }
 
622
        else if (sitem && sitem->isRoot())
 
623
        {
 
624
                rightClickPopup_->removeItem(rcpNewId_);
 
625
                rcpNewId_ = rightClickPopup_->insertItem( tr("New %1").arg(styleClassesPS_[sitem->text(0)]),
 
626
                                                         this, SLOT(slotNewPopup(int)), 0, -1, 0);
 
627
                rightClickPopup_->setItemEnabled(rcpDeleteId_, false);
 
628
                rightClickPopup_->setItemEnabled(rcpEditId_, false);
 
629
                rightClickPopup_->setItemEnabled(rcpCloneId_, false);
 
630
                rightClickPopup_->setItemEnabled(rcpToScrapId_, false);
 
631
                rcType_ = styleClassesPS_[sitem->text(0)];
 
632
                loadType(rcType_);
 
633
        }
 
634
        else
 
635
        {
 
636
                rightClickPopup_->removeItem(rcpNewId_);
 
637
                rcpNewId_ = rightClickPopup_->insertItem( tr("New"), newPopup_, -1, 0);
 
638
                rightClickPopup_->setItemEnabled(rcpDeleteId_, false);
 
639
                rightClickPopup_->setItemEnabled(rcpEditId_, false);
 
640
                rightClickPopup_->setItemEnabled(rcpCloneId_, false);
 
641
                rightClickPopup_->setItemEnabled(rcpToScrapId_, false);
 
642
        }
 
643
 
 
644
        rightClickPopup_->exec(point);
 
645
}
 
646
 
 
647
void StyleManager::slotDoubleClick(QListViewItem *item, const QPoint &point, int col)
 
648
{
 
649
        rcStyle_ = QString::null;
 
650
        rcType_ = QString::null;
 
651
 
 
652
        if (isEditMode_ && item) // make item the only selection if in edit mode
 
653
        {
 
654
                styleView->clearSelection();
 
655
                styleView->setCurrentItem(item);
 
656
                item->setSelected(true);
 
657
                item->repaint();
 
658
                return; // work done, already in edit mode
 
659
        }
 
660
 
 
661
        StyleViewItem *sitem = dynamic_cast<StyleViewItem*>(item);
 
662
        if (sitem && !sitem->isRoot())
 
663
        {
 
664
                rcType_ = sitem->rootName();
 
665
                rcStyle_ = sitem->text(0);
 
666
                slotOk(); // switch to edit mode
 
667
        }
 
668
        else if (sitem && sitem->isRoot())
 
669
        {
 
670
                rcType_ = sitem->text(0);
 
671
                slotNewPopup(-1);
 
672
        }
 
673
        rcStyle_ = QString::null;
 
674
        rcType_ = QString::null;
 
675
}
 
676
 
 
677
void StyleManager::createNewStyle(const QString &typeName, const QString &fromParent)
 
678
{
 
679
        if (!doc_)
 
680
                return;
 
681
 
 
682
        loadType(typeName); // get the right style class
 
683
        Q_ASSERT(item_);
 
684
 
 
685
        QString newName = fromParent.isNull() ?
 
686
                        item_->newStyle() : item_->newStyle(fromParent);
 
687
 
 
688
        if (newName.isNull())
 
689
                return;
 
690
 
 
691
        QListViewItem *root = 0;
 
692
        QListViewItemIterator it(styleView, QListViewItemIterator::NotSelectable);
 
693
        while (it.current())
 
694
        {
 
695
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
696
                if (item)
 
697
                {
 
698
                        if (item->text(NAME_COL) == item_->typeName())
 
699
                        {
 
700
                                root = item;
 
701
                                break;
 
702
                        }
 
703
                }
94
704
                ++it;
95
705
        }
96
 
 
97
 
        uint count = selected.count();
98
 
        disconnect(nameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotNameChanged(const QString&)));
99
 
        if (count > 1) {
100
 
                cloneButton->setEnabled(true);
101
 
                deleteButton->setEnabled(true);
102
 
                nameEdit->setText( tr("More than one item selected"));
103
 
                nameEdit->setEnabled(false);
104
 
                widget_->setEnabled(true);
105
 
        } else if (count == 1) {
106
 
                cloneButton->setEnabled(true);
107
 
                deleteButton->setEnabled(true);
108
 
                nameEdit->setEnabled(true);
109
 
                nameEdit->setText(selected[0]);
110
 
                widget_->setEnabled(true);
111
 
        } else {
112
 
                cloneButton->setEnabled(false);
113
 
                deleteButton->setEnabled(false);
114
 
                nameEdit->setText("");
115
 
                nameEdit->setEnabled(false);
116
 
                widget_->setEnabled(false);
117
 
        }
118
 
        connect(nameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotNameChanged(const QString&)));
119
 
        if (item_) {
120
 
                item_->selected(selected);
121
 
        }
122
 
}
123
 
 
124
 
// f.e. Line Styles --> Paragraph Styles
125
 
void StyleManager::slotTypeChanged(QListViewItem *item)
 
706
        Q_ASSERT(root);
 
707
        styleView->clearSelection();
 
708
        StyleViewItem *newItem = new StyleViewItem(root, newName, item_->typeName());
 
709
        Q_CHECK_PTR(newItem);
 
710
        newItem->setDirty(true);
 
711
        styleView->setCurrentItem(newItem);
 
712
        newItem->setSelected(true);
 
713
        newItem->repaint();
 
714
        slotSetupWidget();
 
715
        nameEdit->setFocus();
 
716
        nameEdit->selectAll();
 
717
        applyButton->setEnabled(true);
 
718
        resetButton->setEnabled(true);
 
719
}
 
720
 
 
721
void StyleManager::show()
 
722
{
 
723
        QDialog::show();
 
724
}
 
725
 
 
726
 
 
727
// open or close edit mode
 
728
void StyleManager::slotOk()
 
729
{
 
730
        static bool isFirst = true;
 
731
        if (isEditMode_)
 
732
        {
 
733
                disconnect(styleView, SIGNAL(selectionChanged()), this, SLOT(slotSetupWidget()));
 
734
                widthEm_ = width();
 
735
                prefs_->set("WidthEM", widthEm_);
 
736
                height_ = height();
 
737
                prefs_->set("Height", height_);
 
738
                QValueList<int> l = splitter->sizes();
 
739
                widthLeft_ = l[0];
 
740
                widthRight_ = l[1];
 
741
                prefs_->set("WidthLeft", widthLeft_);
 
742
                prefs_->set("WidthRight", widthRight_);
 
743
                slotApply();
 
744
                styleView->setSelectionMode(QListView::Multi);
 
745
                okButton->setText(QString("%1 >>").arg( tr("&Edit")));
 
746
                editFrame->hide();
 
747
                applyButton->hide();
 
748
                resetButton->hide();
 
749
//              editButtonsFrame->hide();
 
750
                rightFrame->hide();
 
751
                isEditMode_ = false;
 
752
                for (uint i = 0; i < items_.count(); ++i)
 
753
                {
 
754
                        items_.at(i)->apply();
 
755
                        items_.at(i)->editMode(false);
 
756
                }
 
757
                QToolTip::add(okButton, enterEditModeOk_);
 
758
                slotClean();
 
759
                slotDocSelectionChanged();
 
760
                adjustSize();
 
761
                resize(width_, height_);
 
762
                if (!isFirst)
 
763
                        move(editPosition_);
 
764
                prefs_->set("isEditMode", isEditMode_);
 
765
                connect(styleView, SIGNAL(selectionChanged(QListViewItem*)),
 
766
                        this, SLOT(slotApplyStyle(QListViewItem*)));
 
767
                connect(styleView, SIGNAL(clicked(QListViewItem*)),
 
768
                                this, SLOT(slotApplyStyle(QListViewItem*)));
 
769
                if (isStoryEditMode_)
 
770
                {
 
771
                        isStoryEditMode_=false;
 
772
                        hide();
 
773
                }
 
774
        }
 
775
        else
 
776
        {
 
777
                disconnect(styleView, SIGNAL(selectionChanged(QListViewItem*)),
 
778
                           this, SLOT(slotApplyStyle(QListViewItem*)));
 
779
                disconnect(styleView, SIGNAL(clicked(QListViewItem*)),
 
780
                                this, SLOT(slotApplyStyle(QListViewItem*)));
 
781
                if (!isFirst)
 
782
                {
 
783
                        width_ = width();
 
784
                        prefs_->set("Width", width_);
 
785
                }
 
786
                height_ = height();
 
787
                prefs_->set("Height", height_);
 
788
                slotSetupWidget();
 
789
                styleView->setSelectionMode(QListView::Extended);
 
790
                editPosition_.setX(x());
 
791
                editPosition_.setY(y());
 
792
                prefs_->set("eX", x());
 
793
                prefs_->set("eY", y());
 
794
//              okButton->setText(QString("<< %1").arg( tr("&Done")));
 
795
                editFrame->show();
 
796
                applyButton->show();
 
797
                resetButton->show();
 
798
//              editButtonsFrame->show();
 
799
                rightFrame->show();
 
800
                isEditMode_ = true;
 
801
                for (uint i = 0; i < items_.count(); ++i)
 
802
                        items_.at(i)->editMode(true);
 
803
                QToolTip::add(okButton, exitEditModeOk_);
 
804
                slotClean();
 
805
                adjustSize();
 
806
                QValueList<int> l;
 
807
                l << widthLeft_ << widthRight_;
 
808
                splitter->setSizes(l);
 
809
                resize(widthEm_, height_);
 
810
                prefs_->set("isEditMode", isEditMode_);
 
811
                connect(styleView, SIGNAL(selectionChanged()), this, SLOT(slotSetupWidget()));
 
812
        }
 
813
        setOkButtonText();
 
814
        isFirst = false;
 
815
}
 
816
 
 
817
void StyleManager::addNewType(StyleItem *item, bool loadFromDoc)
126
818
{
127
819
        if (item) {
128
 
                item_ = 0;
 
820
                item_ = item;
 
821
 
 
822
                QValueList<StyleName> styles = item_->styles(loadFromDoc);
 
823
                StyleViewItem *rootItem = new StyleViewItem(styleView, item_->typeName());
 
824
                rootItem->setOpen(true);
 
825
                QMap<QString, StyleViewItem*> sitems;
 
826
 
 
827
                for (uint i = 0; i < styles.count(); ++i) // set the list of styles of this type
 
828
                {
 
829
                        StyleViewItem *sitem;
 
830
                        if (styles[i].second.isNull())
 
831
                        {
 
832
                                sitem = new StyleViewItem(rootItem, styles[i].first, item_->typeName());
 
833
                        }
 
834
                        else if (sitems.contains(styles[i].second))
 
835
                        {
 
836
                                StyleViewItem *parent = sitems[styles[i].second];
 
837
                                sitem = new StyleViewItem(parent, styles[i].first, item_->typeName());
 
838
                                parent->setOpen(true);
 
839
                        }
 
840
                        else 
 
841
                        {
 
842
                                bool postpone = false;
 
843
                                // search if parent is in remaing styles
 
844
                                for (uint j = i+1; j < styles.count(); ++j)
 
845
                                {
 
846
                                        if (styles[j].first == styles[i].second)
 
847
                                        {
 
848
                                                styles.append(styles[i]); // postpone
 
849
                                                postpone = true;
 
850
                                        }
 
851
                                }
 
852
                                if (postpone)
 
853
                                        continue;
 
854
                                else 
 
855
                                {
 
856
                                        qDebug(QString("stylemanager: unknown parent '%1' of %2 style '%3'").arg(styles[i].second).arg(item_->typeName()).arg(styles[i].first));
 
857
                                        sitem = new StyleViewItem(rootItem, styles[i].first, item_->typeName());
 
858
                                }
 
859
                        }
 
860
                        
 
861
                        sitems[styles[i].first] = sitem;
 
862
                        sitem->setText(SHORTCUT_COL, item_->shortcut(sitem->text(NAME_COL)));
 
863
                        
 
864
                        QString key = sitem->rootName() + SEPARATOR + sitem->text(NAME_COL);
 
865
                        if (styleActions_.contains(key))
 
866
                                continue;
 
867
 
 
868
                        styleActions_[key] =
 
869
                                new ScrAction(ScrAction::DataQString, QIconSet(), "",
 
870
                                                        sitem->text(SHORTCUT_COL), doc_->view(), key, 0, 0.0, key);
 
871
                        connect(styleActions_[key], SIGNAL(activatedData(QString)),
 
872
                                        this, SLOT(slotApplyStyle(QString)));
 
873
                }
 
874
        }
 
875
}
 
876
 
 
877
void StyleManager::slotDirty()
 
878
{
 
879
        QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
 
880
 
 
881
        while (it.current()) {
 
882
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
883
                if (item)
 
884
                {
 
885
                        item->setDirty(true);
 
886
                        item->repaint();
 
887
                        applyButton->setEnabled(true);
 
888
                        resetButton->setEnabled(true);
 
889
                }
 
890
                ++it;
 
891
        }
 
892
        applyButton->setEnabled(true);
 
893
        resetButton->setEnabled(true);
 
894
}
 
895
 
 
896
void StyleManager::slotClean()
 
897
{
 
898
        QListViewItemIterator it(styleView);
 
899
 
 
900
        while (it.current()) {
 
901
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
902
                if (item)
 
903
                {
 
904
                        item->setDirty(false);
 
905
                        item->repaint();
 
906
                }
 
907
                ++it;
 
908
        }
 
909
 
 
910
        if (isEditMode_)
 
911
        {
 
912
                StyleItem *tmp = item_;
 
913
 
129
914
                for (uint i = 0; i < items_.count(); ++i)
130
 
                { // search the selected StyleItem based on selection
131
 
                        if (items_.at(i)->typeName() == item->text(0))
 
915
                {
 
916
                        item_ = items_.at(i);
 
917
                        reloadStyleView();
 
918
                }
 
919
                slotSetupWidget();
 
920
                item_ = tmp;
 
921
        }
 
922
        applyButton->setEnabled(false);
 
923
        resetButton->setEnabled(false);
 
924
        uniqueLabel->hide();
 
925
}
 
926
 
 
927
void StyleManager::reloadStyleView(bool loadFromDoc)
 
928
{
 
929
        QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
 
930
        QValueList<QPair<QString, QString> > selected;
 
931
 
 
932
        while (it.current())
 
933
        {
 
934
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
935
                if (item)
 
936
                        selected << QPair<QString, QString>(item->rootName(), item->text(NAME_COL));
 
937
                ++it;
 
938
        }
 
939
 
 
940
        styleView->clear();
 
941
        if (item_ && loadFromDoc)
 
942
                item_->reload();
 
943
 
 
944
        for (uint i = 0; i < items_.count(); ++i)
 
945
                addNewType(items_.at(i), false);
 
946
 
 
947
        QListViewItemIterator it2(styleView, QListViewItemIterator::Selectable);
 
948
 
 
949
        while (it2.current())
 
950
        {
 
951
                StyleViewItem *item = dynamic_cast<StyleViewItem*>(it2.current());
 
952
                if (item)
 
953
                {
 
954
                        for (uint i = 0; i < selected.count(); ++i)
132
955
                        {
133
 
                                item_ = items_.at(i);
134
 
                                break;
 
956
                                if (selected[i].first == item->rootName() &&
 
957
                                    selected[i].second == item->text(NAME_COL))
 
958
                                {
 
959
                                        item->setDirty(false);
 
960
                                        styleView->setCurrentItem(item);
 
961
                                        item->setSelected(true);
 
962
                                        break;
 
963
                                }
135
964
                        }
136
965
                }
137
 
                styleView->clear();
138
 
                if (item_)
 
966
                ++it2;
 
967
        }
 
968
 
 
969
        styleView->repaint();
 
970
}
 
971
 
 
972
void StyleManager::insertShortcutPage(QTabWidget *twidget)
 
973
{
 
974
        if (twidget)
 
975
        {
 
976
                if (!shortcutWidget_)
139
977
                {
140
 
                        QStringList styles = item_->styles();
141
 
                        for (uint i = 0; i < styles.count(); ++i) // set the list of styles of this type
142
 
                                new QListViewItem(styleView, styles[i]);
143
 
 
144
 
                        if (widget_)
145
 
                        {   // remove the old style type's widget
146
 
                                widget_->hide();
147
 
                                layout_->remove(widget_);
148
 
                                widget_->reparent(0,0, QPoint(0,0), false);
149
 
                        }
150
 
                        // show the widget for the new style type
151
 
                        widget_ = item_->widget(); // show the widget for the style type
152
 
                        widget_->reparent(mainFrame, 0, QPoint(0,0), true);
153
 
                        layout_->addWidget(widget_, 0, 0);
 
978
                        shortcutWidget_ = new ShortcutWidget(0, "shortcutWidget_");
 
979
                        connect(shortcutWidget_, SIGNAL(newKey(const QString&)),
 
980
                                        this, SLOT(slotShortcutChanged(const QString&)));
154
981
                }
 
982
                twidget->addTab(shortcutWidget_, tr("Shortcut"));
155
983
        }
156
984
}
157
985
 
158
 
void StyleManager::slotPageChanged(QWidget *widget)
159
 
{
160
 
 
161
 
}
162
 
 
163
986
void StyleManager::slotNameChanged(const QString& name)
164
987
{
165
 
        styleView->currentItem()->setText(0, name);
 
988
        if (!nameIsUnique(name))
 
989
        {
 
990
                uniqueLabel->show();
 
991
                okButton->setEnabled(false);
 
992
                applyButton->setEnabled(false);
 
993
                return;
 
994
        }
 
995
        else if (uniqueLabel->isVisible())
 
996
        {
 
997
                uniqueLabel->hide();
 
998
                okButton->setEnabled(true);
 
999
                applyButton->setEnabled(true);
 
1000
        }
 
1001
 
 
1002
 
166
1003
        if (item_)
 
1004
        {
167
1005
                item_->nameChanged(name);
 
1006
                updateActionName(styleView->currentItem()->text(NAME_COL), name);
 
1007
                styleView->currentItem()->setText(NAME_COL, name);
 
1008
                applyButton->setEnabled(true);
 
1009
                resetButton->setEnabled(true);
 
1010
        }
 
1011
}
 
1012
 
 
1013
 
 
1014
void StyleManager::updateActionName(const QString &oldName, const QString &newName)
 
1015
{
 
1016
        if (!item_)
 
1017
                return;
 
1018
        QString oldKey = item_->typeName() + SEPARATOR + oldName;
 
1019
        QString newKey = item_->typeName() + SEPARATOR + newName;
 
1020
 
 
1021
        if (styleActions_.contains(oldKey))
 
1022
        {
 
1023
                ScrAction *a = styleActions_[oldKey];
 
1024
                disconnect(a, SIGNAL(activatedData(QString)), this, SLOT(slotApplyStyle(QString)));
 
1025
                ScrAction *b = new ScrAction(ScrAction::DataQString, QIconSet(), "",
 
1026
                                       a->accel(), doc_->view(), newKey, 0, 0.0, newKey);
 
1027
                styleActions_.remove(oldKey);
 
1028
                delete a;
 
1029
                styleActions_[newKey] = b;
 
1030
                connect(b, SIGNAL(activatedData(QString)), this, SLOT(slotApplyStyle(QString)));
 
1031
        }
 
1032
}
 
1033
 
 
1034
void StyleManager::slotShortcutChanged(const QString& shortcut)
 
1035
{
 
1036
        if (!doc_)
 
1037
                return;
 
1038
 
 
1039
        StyleViewItem *sitem = dynamic_cast<StyleViewItem*>(styleView->currentItem());
 
1040
        if (!sitem)
 
1041
                return;
 
1042
 
 
1043
        if (!shortcut.isNull() && shortcutExists(shortcut))
 
1044
        {
 
1045
                QMessageBox::information(this, CommonStrings::trWarning,
 
1046
                                         tr("This key sequence is already in use"),
 
1047
                                         CommonStrings::tr_OK);
 
1048
                shortcutWidget_->setShortcut(item_->shortcut(sitem->text(NAME_COL)));
 
1049
                return;
 
1050
        }
 
1051
 
 
1052
        sitem->setText(SHORTCUT_COL, shortcut.isNull() ? "" : shortcut);
 
1053
        QString key = sitem->rootName() + SEPARATOR + sitem->text(NAME_COL);
 
1054
        if (styleActions_.contains(key))
 
1055
                styleActions_[key]->setAccel(shortcut);
 
1056
        else
 
1057
        {
 
1058
                styleActions_[key] =
 
1059
                        new ScrAction(ScrAction::DataQString, QIconSet(), "",
 
1060
                                      shortcut, doc_->view(), key, 0, 0.0, key);
 
1061
                connect(styleActions_[key], SIGNAL(activatedData(QString)),
 
1062
                        this, SLOT(slotApplyStyle(QString)));
 
1063
        }
 
1064
 
 
1065
        if (item_)
 
1066
                item_->setShortcut(shortcut);
 
1067
}
 
1068
 
 
1069
bool StyleManager::shortcutExists(const QString &keys)
 
1070
{
 
1071
        QKeySequence key(keys);
 
1072
 
 
1073
        QMap<QString, QGuardedPtr<ScrAction> >::iterator it;
 
1074
        for (it = styleActions_.begin(); it != styleActions_.end(); ++it)
 
1075
        {
 
1076
                if ((*it)->accel() == key)
 
1077
                        return true;
 
1078
        }
 
1079
 
 
1080
        ApplicationPrefs *prefsData=&(PrefsManager::instance()->appPrefs);
 
1081
        for (QMap<QString,Keys>::Iterator it=prefsData->KeyActions.begin();
 
1082
             it!=prefsData->KeyActions.end(); ++it)
 
1083
        {
 
1084
                if (key.matches(it.data().keySequence) != Qt::NoMatch)
 
1085
                        return true;
 
1086
        }
 
1087
 
 
1088
        return false;
 
1089
}
 
1090
 
 
1091
void StyleManager::slotApplyStyle(QString keyString)
 
1092
{
 
1093
        if (isEditMode_)
 
1094
                return;
 
1095
 
 
1096
        QStringList slist = QStringList::split(SEPARATOR, keyString);
 
1097
        Q_ASSERT(slist.count() == 2);
 
1098
 
 
1099
        loadType(slist[0]);
 
1100
        item_->toSelection(slist[1]);
 
1101
        slotDocSelectionChanged();
 
1102
}
 
1103
 
 
1104
bool StyleManager::nameIsUnique(const QString &name)
 
1105
{
 
1106
        QValueList<StyleName> names = item_->styles(false);
 
1107
        for (uint i = 0; i < names.count(); ++i)
 
1108
        {
 
1109
                if (names[i].first == name)
 
1110
                        return false;
 
1111
        }
 
1112
        return true;
 
1113
}
 
1114
 
 
1115
// setups the selected type and edit widgets related to it
 
1116
void StyleManager::slotSetupWidget()
 
1117
{
 
1118
        QPair<QString, QStringList> selection = namesFromSelection();
 
1119
        QString typeName = selection.first;
 
1120
 
 
1121
        if (typeName.isNull() && widget_)
 
1122
                widget_->setEnabled(false); // nothing selected or two or more different types
 
1123
        else if (!item_ || item_->typeName() != typeName || widget_ != item_->widget())
 
1124
                loadType(typeName); // new type selected
 
1125
        else if (widget_ && !widget_->isEnabled())
 
1126
                widget_->setEnabled(true);
 
1127
 
 
1128
        disconnect(nameEdit, SIGNAL(textChanged(const QString&)),
 
1129
                   this, SLOT(slotNameChanged(const QString&)));
 
1130
        if (!typeName.isNull())
 
1131
        {
 
1132
                item_->selected(selection.second);
 
1133
                if (selection.second.count() > 1)
 
1134
                {
 
1135
                        nameEdit->setText( tr("More than one style selected"));
 
1136
                        nameEdit->setEnabled(false);
 
1137
                        shortcutWidget_->setEnabled(false);
 
1138
                        shortcutWidget_->setShortcut(QString::null);
 
1139
                }
 
1140
                else
 
1141
                {
 
1142
                        nameEdit->setText(selection.second[0]);
 
1143
                        nameEdit->setEnabled(true);
 
1144
                        shortcutWidget_->setEnabled(true);
 
1145
                        shortcutWidget_->setShortcut(item_->shortcut(selection.second[0]));
 
1146
                }
 
1147
        }
 
1148
        else
 
1149
        {
 
1150
                nameEdit->setText("");
 
1151
                nameEdit->setEnabled(false);
 
1152
        }
 
1153
 
 
1154
        connect(nameEdit, SIGNAL(textChanged(const QString&)),
 
1155
                this, SLOT(slotNameChanged(const QString&)));
 
1156
 
 
1157
}
 
1158
 
 
1159
void StyleManager::slotApplyStyle(QListViewItem *item)
 
1160
{
 
1161
        StyleViewItem *sitem = dynamic_cast<StyleViewItem*>(item);
 
1162
 
 
1163
        if (isEditMode_ || !sitem || sitem->isRoot())
 
1164
                return; // don't apply a style in edit mode or if there was no item/type selected
 
1165
 
 
1166
        styleView->clearSelection();
 
1167
 
 
1168
        if (!item_ || item_->typeName() != sitem->rootName())
 
1169
                loadType(sitem->rootName()); // load the type where we want to apply this style
 
1170
 
 
1171
        Q_ASSERT(item_);
 
1172
 
 
1173
        item_->toSelection(sitem->text(NAME_COL)); // apply selected style to the selection
 
1174
 
 
1175
        slotDocSelectionChanged();
 
1176
}
 
1177
 
 
1178
void StyleManager::slotDocSelectionChanged()
 
1179
{
 
1180
        if (isEditMode_)
 
1181
                return; // don't track changes when in edit mode
 
1182
 
 
1183
        disconnect(styleView, SIGNAL(currentChanged(QListViewItem*)),
 
1184
                   this, SLOT(slotApplyStyle(QListViewItem*)));
 
1185
 
 
1186
        styleView->clearSelection();
 
1187
 
 
1188
        QValueList<QPair<QString, QString> > selected;
 
1189
 
 
1190
        for (uint i = 0; i < items_.count(); ++i)
 
1191
                selected << QPair<QString, QString>(items_.at(i)->typeName(), items_.at(i)->fromSelection());
 
1192
        
 
1193
        QListViewItemIterator it(styleView, QListViewItemIterator::Selectable);
 
1194
        StyleViewItem *item;
 
1195
 
 
1196
        while (it.current())
 
1197
        {
 
1198
                item = dynamic_cast<StyleViewItem*>(it.current());
 
1199
                if (item)
 
1200
                {
 
1201
                        for (uint i = 0; i < selected.count(); ++i)
 
1202
                        {
 
1203
                                if (item->rootName() == selected[i].first && item->text(NAME_COL) == selected[i].second)
 
1204
                                {
 
1205
                                        styleView->setCurrentItem(item);
 
1206
                                        item->setSelected(true);
 
1207
                                        item->repaint();
 
1208
                                }
 
1209
                        }
 
1210
                }
 
1211
                ++it;
 
1212
        }
 
1213
 
 
1214
        styleView->triggerUpdate();
 
1215
 
 
1216
        connect(styleView, SIGNAL(currentChanged(QListViewItem*)),
 
1217
                this, SLOT(slotApplyStyle(QListViewItem*)));
 
1218
}
 
1219
 
 
1220
void StyleManager::slotDocStylesChanged()
 
1221
{
 
1222
        qDebug("slotDocStylesChanged()");
 
1223
}
 
1224
 
 
1225
// QPair.first == QString::null if nothing is selected or if
 
1226
// there are items from more than one type in the selection
 
1227
// if selection is valid (only from single type) QPair.first will
 
1228
// include the type name and QPair.second will have all the selected
 
1229
// stylenames in it
 
1230
QPair<QString, QStringList> StyleManager::namesFromSelection()
 
1231
{
 
1232
        QString typeName(QString::null);
 
1233
        QStringList styleNames;
 
1234
 
 
1235
        if (rcStyle_.isNull())
 
1236
        {
 
1237
                QListViewItemIterator it(styleView, QListViewItemIterator::Selected);
 
1238
                while (it.current())
 
1239
                {
 
1240
                        StyleViewItem *item = dynamic_cast<StyleViewItem*>(it.current());
 
1241
                        if (!item)
 
1242
                        {
 
1243
                                ++it;
 
1244
                                continue;
 
1245
                        }
 
1246
                        else if (typeName.isNull())
 
1247
                                typeName = item->rootName();
 
1248
                        else if (!typeName.isNull() && typeName != item->rootName())
 
1249
                        {
 
1250
                                typeName = QString::null;
 
1251
                                break; // two different types selected returning null
 
1252
                        }
 
1253
        
 
1254
                        if (!item->isRoot())
 
1255
                                styleNames << item->text(NAME_COL);
 
1256
        
 
1257
                        ++it;
 
1258
                }
 
1259
        }
 
1260
        else // right click selection which doesn't show in the gui
 
1261
        {
 
1262
                typeName = rcType_;
 
1263
                styleNames << rcStyle_;
 
1264
        }
 
1265
        return QPair<QString, QStringList>(typeName, styleNames);
 
1266
}
 
1267
 
 
1268
// sets the current type to name including item_ and the main widget
 
1269
// for editing styles
 
1270
void StyleManager::loadType(const QString &name)
 
1271
{
 
1272
        item_ = 0;
 
1273
        for (uint i = 0; i < items_.count(); ++i)
 
1274
        {
 
1275
                if (items_.at(i)->typeNameSingular() == name || items_.at(i)->typeName() == name)
 
1276
                {
 
1277
                        item_ = items_.at(i);
 
1278
                        break;
 
1279
                }
 
1280
        }
 
1281
        if (!item_)
 
1282
                return;
 
1283
 
 
1284
        if (widget_)
 
1285
        {   // remove the old style type's widget
 
1286
                widget_->hide();
 
1287
                layout_->remove(widget_);
 
1288
                widget_->reparent(0,0, QPoint(0,0), false);
 
1289
        }
 
1290
        // show the widget for the new style type
 
1291
        if (shortcutWidget_)
 
1292
                widget_->removePage(shortcutWidget_);
 
1293
        widget_ = item_->widget(); // show the widget for the style type
 
1294
        insertShortcutPage(widget_);
 
1295
        widget_->reparent(mainFrame, 0, QPoint(0,0), true);
 
1296
        layout_->addWidget(widget_, 0, 0);
168
1297
}
169
1298
 
170
1299
void StyleManager::hideEvent(QHideEvent *e)
171
1300
{
 
1301
        if (isEditMode_)
 
1302
        {
 
1303
                QValueList<int> l = splitter->sizes();
 
1304
                widthLeft_ = l[0];
 
1305
                widthRight_ = l[1];
 
1306
                widthEm_ = width();
 
1307
        }
 
1308
        else
 
1309
                width_ = width();
 
1310
 
 
1311
        height_ = height();
 
1312
        prefs_->set("eX", x());
 
1313
        prefs_->set("eY", y());
 
1314
        prefs_->set("isEditMode", isEditMode_);
 
1315
        prefs_->set("Width", width_);
 
1316
        prefs_->set("WidthEM", widthEm_);
 
1317
        prefs_->set("WidthLeft", widthLeft_);
 
1318
        prefs_->set("WidthRight", widthRight_);
 
1319
        prefs_->set("Height", height_);
 
1320
        prefs_->set("InitX", x());
 
1321
        prefs_->set("InitY", y());
 
1322
        storeVisibility(false);
 
1323
        storePosition();
172
1324
        SMBase::hideEvent(e);
173
1325
        emit closed();
174
1326
}
175
1327
 
 
1328
void StyleManager::closeEvent(QCloseEvent *e)
 
1329
{
 
1330
        if (isEditMode_)
 
1331
        {
 
1332
                QValueList<int> l = splitter->sizes();
 
1333
                widthLeft_ = l[0];
 
1334
                widthRight_ = l[1];
 
1335
                widthEm_ = width();
 
1336
        }
 
1337
        else
 
1338
                width_ = width();
 
1339
 
 
1340
        height_ = height();
 
1341
        prefs_->set("eX", x());
 
1342
        prefs_->set("eY", y());
 
1343
        prefs_->set("isEditMode", isEditMode_);
 
1344
        prefs_->set("Width", width_);
 
1345
        prefs_->set("WidthEM", widthEm_);
 
1346
        prefs_->set("WidthLeft", widthLeft_);
 
1347
        prefs_->set("WidthRight", widthRight_);
 
1348
        prefs_->set("Height", height_);
 
1349
        prefs_->set("InitX", x());
 
1350
        prefs_->set("InitY", y());
 
1351
        storeVisibility(false);
 
1352
        storePosition();
 
1353
        SMBase::closeEvent(e);
 
1354
        emit closed();
 
1355
}
 
1356
 
 
1357
void StyleManager::showEvent(QShowEvent *e)
 
1358
{
 
1359
        static bool isFirst = true;
 
1360
        if (isModal())
 
1361
        {
 
1362
                isStoryEditMode_=true;
 
1363
                applyButton->setEnabled(false);
 
1364
                slotEdit();
 
1365
        }
 
1366
        setOkButtonText();
 
1367
        SMBase::showEvent(e);
 
1368
        if (isFirst)
 
1369
        {
 
1370
                QPoint p(prefs_->getInt("InitX", x()), prefs_->getInt("InitY", y()));
 
1371
                move(p);
 
1372
                isFirst = false;
 
1373
        }
 
1374
}
 
1375
 
176
1376
StyleManager::~StyleManager()
177
1377
{
178
 
        
179
 
}
180
 
 
 
1378
        if (isEditMode_)
 
1379
        {
 
1380
                QValueList<int> l = splitter->sizes();
 
1381
                widthLeft_ = l[0];
 
1382
                widthRight_ = l[1];
 
1383
                widthEm_ = width();
 
1384
        }
 
1385
        else
 
1386
                width_ = width();
 
1387
 
 
1388
        height_ = height();
 
1389
        prefs_->set("eX", x());
 
1390
        prefs_->set("eY", y());
 
1391
        prefs_->set("isEditMode", isEditMode_);
 
1392
        prefs_->set("Width", width_);
 
1393
        prefs_->set("WidthEM", widthEm_);
 
1394
        prefs_->set("WidthLeft", widthLeft_);
 
1395
        prefs_->set("WidthRight", widthRight_);
 
1396
        prefs_->set("InitX", x());
 
1397
        prefs_->set("InitY", y());
 
1398
        prefs_->set("Height", height_);
 
1399
        storeVisibility(this->isVisible());
 
1400
        storePosition();
 
1401
}
 
1402
 
 
1403
 
 
1404
 
 
1405
/*** StyleViewItem *******************************************************************/
 
1406
 
 
1407
StyleView::StyleView(QWidget *parent) : QListView(parent, "StyleView")
 
1408
{
 
1409
 
 
1410
}
 
1411
 
 
1412
StyleView::~StyleView()
 
1413
{
 
1414
 
 
1415
}
 
1416
 
 
1417
void StyleView::contentsMousePressEvent(QMouseEvent *e)
 
1418
{
 
1419
        if (e->button() == Qt::RightButton)
 
1420
                emit rightButtonClicked(itemAt(e->pos()), e->globalPos(), 0);
 
1421
        else
 
1422
                QListView::contentsMousePressEvent(e);
 
1423
}
 
1424
 
 
1425
void StyleView::contentsMouseDoubleClickEvent(QMouseEvent *e)
 
1426
{
 
1427
        if (e->button() == Qt::LeftButton)
 
1428
                emit doubleClicked(itemAt(e->pos()), e->globalPos(), 0);
 
1429
        else
 
1430
                QListView::contentsMouseDoubleClickEvent(e);
 
1431
}
 
1432
 
 
1433
/*** StyleViewItem *******************************************************************/
 
1434
 
 
1435
StyleViewItem::StyleViewItem(QListView *view, const QString &text) : QListViewItem(view, text),
 
1436
isRoot_(true), isDirty_(false), parentName_(QString::null), rootName_(QString::null)
 
1437
{
 
1438
        setSelectable(false);
 
1439
}
 
1440
 
 
1441
StyleViewItem::StyleViewItem(QListViewItem *parent, const QString &text, const QString &rootName)
 
1442
: QListViewItem(parent, text),
 
1443
  isRoot_(false), isDirty_(false), parentName_(parent->text(0)), rootName_(rootName)
 
1444
{
 
1445
 
 
1446
}
 
1447
 
 
1448
void StyleViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align)
 
1449
{
 
1450
        if (column == 0)
 
1451
        {
 
1452
                QFont f(p->font());
 
1453
                f.setBold(isDirty_);
 
1454
                p->setFont(f);
 
1455
        }
 
1456
 
 
1457
        QListViewItem::paintCell(p, cg, column, width, align);
 
1458
}
 
1459
 
 
1460
void StyleViewItem::setDirty(bool isDirty)
 
1461
{
 
1462
        isDirty_ = isDirty;
 
1463
}
 
1464
 
 
1465
bool StyleViewItem::isDirty()
 
1466
{
 
1467
        return isDirty_;
 
1468
}
 
1469
 
 
1470
bool StyleViewItem::isRoot()
 
1471
{
 
1472
        return isRoot_;
 
1473
}
 
1474
 
 
1475
QString StyleViewItem::parentName()
 
1476
{
 
1477
        return parentName_;
 
1478
}
 
1479
 
 
1480
QString StyleViewItem::rootName()
 
1481
{
 
1482
        return rootName_;
 
1483
}
 
1484
 
 
1485
StyleViewItem::~StyleViewItem()
 
1486
{
 
1487
 
 
1488
}
 
1489
 
 
1490
/*** ShortcutWidget ******************************************************************/
 
1491
 
 
1492
ShortcutWidget::ShortcutWidget(QWidget *parent, const char *name) : QWidget(parent, name)
 
1493
{
 
1494
        Part0 = "";
 
1495
        Part1 = "";
 
1496
        Part2 = "";
 
1497
        Part3 = "";
 
1498
        keyCode = 0;
 
1499
        keyManagerLayout = new QVBoxLayout( this, 0, 6); 
 
1500
        keyManagerLayout->setAlignment( Qt::AlignHCenter );
 
1501
 
 
1502
        keyGroup = new QButtonGroup( this, "keyGroup" );
 
1503
        keyGroup->setFrameStyle(0);
 
1504
        keyGroup->setColumnLayout(0, Qt::Vertical );
 
1505
        keyGroup->layout()->setSpacing( 0 );
 
1506
        keyGroup->layout()->setMargin( 0 );
 
1507
        keyGroupLayout = new QGridLayout( keyGroup->layout() );
 
1508
        keyGroupLayout->setAlignment( Qt::AlignTop );
 
1509
        keyGroupLayout->setSpacing( 6 );
 
1510
        keyGroupLayout->setMargin( 11 );
 
1511
 
 
1512
        noKey = new QRadioButton( tr( "&No Key" ), keyGroup, "noKey" );
 
1513
        keyGroupLayout->addMultiCellWidget( noKey, 0, 1, 0, 1 );
 
1514
        userDef = new QRadioButton( tr( "&User Defined Key" ), keyGroup, "userDef" );
 
1515
        keyGroupLayout->addWidget( userDef, 2, 0 );
 
1516
 
 
1517
        keyDisplay = new QLabel( tr( "ALT+SHIFT+T" ), keyGroup, "keyDisplay" );
 
1518
        keyDisplay->setFrameShape( QLabel::Panel );
 
1519
        keyDisplay->setFrameShadow( QLabel::Sunken );
 
1520
        keyDisplay->setAlignment( static_cast<int>( QLabel::AlignCenter ) );
 
1521
        keyDisplay->setMinimumHeight(40);
 
1522
 
 
1523
        keyGroupLayout->addMultiCellWidget( keyDisplay, 3, 4, 0, 2 );
 
1524
 
 
1525
        setKeyButton = new QPushButton( tr( "Set &Key" ), keyGroup, "setKeyButton" );
 
1526
        setKeyButton->setToggleButton(true);
 
1527
 
 
1528
        languageChange();
 
1529
 
 
1530
        keyGroupLayout->addMultiCellWidget( setKeyButton, 0, 2, 1, 1, Qt::AlignCenter );
 
1531
        keyManagerLayout->addWidget( keyGroup );
 
1532
 
 
1533
        connect(noKey, SIGNAL(clicked()), this, SLOT(setNoKey()));
 
1534
        connect(setKeyButton, SIGNAL(clicked()), this, SLOT(setKeyText()));
 
1535
}
 
1536
 
 
1537
void ShortcutWidget::languageChange()
 
1538
{
 
1539
/***********************************/
 
1540
/*      Begin Tooltips             */
 
1541
/***********************************/
 
1542
 
 
1543
        QToolTip::add(noKey,        tr("No shortcut for the style")); // set no shortcut for this style
 
1544
        QToolTip::add(userDef,      tr("Style has user defined shortcut")); // not sure what this thing does
 
1545
        QToolTip::add(setKeyButton, tr("Assign a shortcut for the style")); // activate shorcut assigning
 
1546
 
 
1547
/***********************************/
 
1548
/*      End Tooltips               */
 
1549
/***********************************/
 
1550
 
 
1551
        noKey->setText( tr("&No Key"));
 
1552
        userDef->setText( tr("&User Defined Key"));
 
1553
        setKeyButton->setText( tr("Set &Key"));
 
1554
}
 
1555
 
 
1556
bool ShortcutWidget::event( QEvent* ev )
 
1557
{
 
1558
        bool ret = QWidget::event( ev );
 
1559
        if ( ev->type() == QEvent::KeyPress )
 
1560
                keyPressEvent((QKeyEvent*)ev);
 
1561
        if ( ev->type() == QEvent::KeyRelease )
 
1562
                keyReleaseEvent((QKeyEvent*)ev);
 
1563
        return ret;
 
1564
}
 
1565
 
 
1566
void ShortcutWidget::keyPressEvent(QKeyEvent *k)
 
1567
{
 
1568
        if (setKeyButton->isOn())
 
1569
        {
 
1570
                QStringList tl;
 
1571
                if (!keyDisplay->text().isEmpty())
 
1572
                {
 
1573
                        tl = tl.split("+", keyDisplay->text());
 
1574
                        Part4 = tl[tl.count()-1];
 
1575
                        if (Part4 == tr("Alt") || Part4 == tr("Ctrl") || Part4 == tr("Shift") || Part4 == tr("Meta"))
 
1576
                                Part4 = "";
 
1577
                }
 
1578
                else
 
1579
                        Part4 = "";
 
1580
                switch (k->key())
 
1581
                {
 
1582
                        case Key_Meta:
 
1583
                                Part0 = tr("Meta+");
 
1584
                                keyCode |= META;
 
1585
                                break;
 
1586
                        case Key_Shift:
 
1587
                                Part3 = tr("Shift+");
 
1588
                                keyCode |= SHIFT;
 
1589
                                break;
 
1590
                        case Key_Alt:
 
1591
                                Part2 = tr("Alt+");
 
1592
                                keyCode |= ALT;
 
1593
                                break;
 
1594
                        case Key_Control:
 
1595
                                Part1 = tr("Ctrl+");
 
1596
                                keyCode |= CTRL;
 
1597
                                break;
 
1598
                        default:
 
1599
                                keyCode |= k->key();
 
1600
                                keyDisplay->setText(getKeyText(keyCode));
 
1601
//                              if (checkKey(keyCode))
 
1602
//                              {
 
1603
//                                      QMessageBox::information(this,
 
1604
//                                                                                      CommonStrings::trWarning,
 
1605
//                                                                                      tr("This key sequence is already in use"),
 
1606
//                                                                                      CommonStrings::tr_OK);
 
1607
//                                      keyTable->setText(currRow, 1, "");
 
1608
//                                      keyDisplay->setText("");
 
1609
//                                      if (currentKeyMapRow!=NULL)
 
1610
//                                              currentKeyMapRow.data().keySequence=QKeySequence();
 
1611
//                                      noKey->setChecked(true);
 
1612
//                              }
 
1613
//                              else
 
1614
//                              {
 
1615
//                                      QKeySequence newKeySequence(keyCode);
 
1616
//                                      keyTable->setText(currRow, 1, QString(newKeySequence));
 
1617
//                                      if (currentKeyMapRow!=NULL)
 
1618
//                                              currentKeyMapRow.data().keySequence=newKeySequence;
 
1619
//                                      userDef->setChecked(true);
 
1620
//                              }
 
1621
                                setKeyButton->setOn(false);
 
1622
                                userDef->setChecked(true);
 
1623
                                releaseKeyboard();
 
1624
                                emit newKey(keyDisplay->text());
 
1625
                }
 
1626
        }
 
1627
        if (setKeyButton->isOn())
 
1628
        {
 
1629
                keyDisplay->setText(Part0+Part1+Part2+Part3+Part4);
 
1630
        }
 
1631
}
 
1632
 
 
1633
void ShortcutWidget::keyReleaseEvent(QKeyEvent *k)
 
1634
{
 
1635
        if (setKeyButton->isOn())
 
1636
        {
 
1637
                if (!keyDisplay->text().isEmpty())
 
1638
                {
 
1639
                        QStringList tl;
 
1640
                        tl = tl.split("+", keyDisplay->text());
 
1641
                        Part4 = tl[tl.count()-1];
 
1642
                        if (Part4 == tr("Alt") || Part4 == tr("Ctrl") || Part4 == tr("Shift") || Part4 == tr("Meta"))
 
1643
                                Part4 = "";
 
1644
                }
 
1645
                else
 
1646
                        Part4 = "";
 
1647
                if (k->key() == Key_Meta)
 
1648
                {
 
1649
                        Part0 = "";
 
1650
                        keyCode &= ~META;
 
1651
                }
 
1652
                if (k->key() == Key_Shift)
 
1653
                {
 
1654
                        Part3 = "";
 
1655
                        keyCode &= ~SHIFT;
 
1656
                }
 
1657
                if (k->key() == Key_Alt)
 
1658
                {
 
1659
                        Part2 = "";
 
1660
                        keyCode &= ~ALT;
 
1661
                }
 
1662
                if (k->key() == Key_Control)
 
1663
                {
 
1664
                        Part1 = "";
 
1665
                        keyCode &= ~CTRL;
 
1666
                }
 
1667
                keyDisplay->setText(Part0+Part1+Part2+Part3+Part4);
 
1668
        }
 
1669
}
 
1670
 
 
1671
QString ShortcutWidget::getKeyText(int KeyC)
 
1672
{
 
1673
        if ((KeyC & ~(Qt::META | Qt::CTRL | Qt::ALT | Qt::SHIFT)) == 0)
 
1674
                return "";
 
1675
        // on OSX Qt translates modifiers to forsaken symbols, arrows and the like
 
1676
        // we prefer plain English
 
1677
        QString res;
 
1678
        if ((KeyC & Qt::META) != 0)
 
1679
                res += "Meta+";
 
1680
        if ((KeyC & Qt::CTRL) != 0)
 
1681
                res += "Ctrl+";
 
1682
        if ((KeyC & Qt::ALT) != 0)
 
1683
                res += "Alt+";
 
1684
        if ((KeyC & Qt::SHIFT) != 0)
 
1685
                res += "Shift+";
 
1686
        return res + QString(QKeySequence(KeyC & ~(Qt::META | Qt::CTRL | Qt::ALT | Qt::SHIFT)));
 
1687
}
 
1688
 
 
1689
void ShortcutWidget::setKeyText()
 
1690
{
 
1691
        if (setKeyButton->isOn())
 
1692
        {
 
1693
                keyCode = 0;
 
1694
                Part0 = "";
 
1695
                Part1 = "";
 
1696
                Part2 = "";
 
1697
                Part3 = "";
 
1698
                Part4 = "";
 
1699
                grabKeyboard();
 
1700
        }
 
1701
        else
 
1702
                releaseKeyboard();
 
1703
}
 
1704
 
 
1705
void ShortcutWidget::setShortcut(const QString &shortcut)
 
1706
{
 
1707
        disconnect(noKey, SIGNAL(clicked()), this, SLOT(setNoKey()));
 
1708
        disconnect(setKeyButton, SIGNAL(clicked()), this, SLOT(setKeyText()));
 
1709
 
 
1710
        setKeyButton->setOn(false);
 
1711
        if (shortcut.length() > 0)
 
1712
        {
 
1713
                userDef->setChecked(true);
 
1714
                keyDisplay->setText(shortcut);
 
1715
        }
 
1716
        else
 
1717
        {
 
1718
                noKey->setChecked(true);
 
1719
                keyDisplay->setText("");
 
1720
        }
 
1721
 
 
1722
        connect(noKey, SIGNAL(clicked()), this, SLOT(setNoKey()));
 
1723
        connect(setKeyButton, SIGNAL(clicked()), this, SLOT(setKeyText()));
 
1724
}
 
1725
 
 
1726
void ShortcutWidget::setNoKey()
 
1727
{
 
1728
        if (noKey->isChecked())
 
1729
        {
 
1730
                keyDisplay->setText("");
 
1731
                emit newKey(QString::null);
 
1732
        }
 
1733
}
 
1734
 
 
1735
ShortcutWidget::~ShortcutWidget()
 
1736
{
 
1737
 
 
1738
}