summaryrefslogtreecommitdiffstats
path: root/src/gui/configuration/NotationConfigurationPage.cpp
blob: 7bf857aada1245b520a00bde630ac4162ceae662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */

/*
    Rosegarden
    A MIDI and audio sequencer and musical notation editor.
 
    This program is Copyright 2000-2008
        Guillaume Laurent   <[email protected]>,
        Chris Cannam        <[email protected]>,
        Richard Bown        <[email protected]>
 
    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
    Bown to claim authorship of this work have been asserted.
 
    Other copyrights also apply to some parts of this work.  Please
    see the AUTHORS file and individual file headers for details.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/


#include "NotationConfigurationPage.h"
#include <tqlayout.h>

#include "misc/Strings.h"
#include "document/ConfigGroups.h"
#include "base/Exception.h"
#include "base/NotationTypes.h"
#include "commands/edit/PasteEventsCommand.h"
#include "ConfigurationPage.h"
#include "document/RosegardenGUIDoc.h"
#include "gui/editors/notation/HeadersGroup.h"
#include "gui/editors/notation/NotationHLayout.h"
#include "gui/editors/notation/NoteFontFactory.h"
#include "gui/editors/notation/NoteFont.h"
#include "gui/editors/notation/NoteFontMap.h"
#include "gui/editors/notation/NoteFontViewer.h"
#include "gui/editors/notation/NotePixmapFactory.h"
#include "gui/editors/notation/NoteStyleFactory.h"
#include "gui/widgets/QuantizeParameters.h"
#include "TabbedConfigurationPage.h"
#include <kcombobox.h>
#include <kconfig.h>
#include <kfontrequester.h>
#include <kmessagebox.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqfont.h>
#include <tqframe.h>
#include <tqgroupbox.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqobject.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqtabwidget.h>
#include <tqwidget.h>
#include <tqtooltip.h>
#include <algorithm>

namespace Rosegarden
{

NotationConfigurationPage::NotationConfigurationPage(KConfig *cfg,
        TQWidget *parent,
        const char *name) :
        TabbedConfigurationPage(cfg, parent, name)
{
    m_cfg->setGroup(NotationViewConfigGroup);

    TQFrame *frame;
    TQGridLayout *tqlayout;

    frame = new TQFrame(m_tabWidget);
    tqlayout = new TQGridLayout(frame, 9, 3, 10, 5);

    int row = 0;

    tqlayout->setRowSpacing(row, 15);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Default tqlayout mode"), frame), row, 0);

    m_layoutMode = new KComboBox(frame);
    m_layoutMode->setEditable(false);
    m_layoutMode->insertItem(i18n("Linear tqlayout"));
    m_layoutMode->insertItem(i18n("Continuous page tqlayout"));
    m_layoutMode->insertItem(i18n("Multiple page tqlayout"));
    int defaultLayoutMode = m_cfg->readNumEntry("layoutmode", 0);
    if (defaultLayoutMode >= 0 && defaultLayoutMode <= 2) {
        m_layoutMode->setCurrentItem(defaultLayoutMode);
    }
    tqlayout->addMultiCellWidget(m_layoutMode, row, row, 1, 2);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Default spacing"), frame), row, 0);

    m_spacing = new KComboBox(frame);
    m_spacing->setEditable(false);

    std::vector<int> s = NotationHLayout::getAvailableSpacings();
    int defaultSpacing = m_cfg->readNumEntry("spacing", 100);

    for (std::vector<int>::iterator i = s.begin(); i != s.end(); ++i) {

        TQString text("%1 %");
        if (*i == 100)
            text = "%1 % (normal)";
        m_spacing->insertItem(text.arg(*i));

        if (*i == defaultSpacing) {
            m_spacing->setCurrentItem(m_spacing->count() - 1);
        }
    }

    tqlayout->addMultiCellWidget(m_spacing, row, row, 1, 2);

    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Default duration factor"), frame), row, 0);

    m_proportion = new KComboBox(frame);
    m_proportion->setEditable(false);

    s = NotationHLayout::getAvailableProportions();
    int defaultProportion = m_cfg->readNumEntry("proportion", 60);

    for (std::vector<int>::iterator i = s.begin(); i != s.end(); ++i) {

        TQString text = TQString("%1 %").arg(*i);
        if (*i == 40)
            text = "40 % (normal)";
        else if (*i == 0)
            text = i18n("None");
        else if (*i == 100)
            text = i18n("Full");
        m_proportion->insertItem(text);

        if (*i == defaultProportion) {
            m_proportion->setCurrentItem(m_proportion->count() - 1);
        }
    }

    tqlayout->addMultiCellWidget(m_proportion, row, row, 1, 2);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Show track headers (linear tqlayout only)"),
                                      frame), row, 0);

    m_showTrackHeaders = new KComboBox(frame);
    m_showTrackHeaders->setEditable(false);
    m_showTrackHeaders->insertItem(i18n("Never"), HeadersGroup::ShowNever);
    m_showTrackHeaders->insertItem(i18n("When needed"), HeadersGroup::ShowWhenNeeded);
    m_showTrackHeaders->insertItem(i18n("Always"), HeadersGroup::ShowAlways);
    int defaultShowTrackHeaders = m_cfg->readNumEntry("shownotationheader", 
                                                 HeadersGroup::DefaultShowMode);
    if (HeadersGroup::isValidShowMode(defaultShowTrackHeaders)) {
        m_showTrackHeaders->setCurrentItem(defaultShowTrackHeaders);
    }
    TQToolTip::add(m_showTrackHeaders, TQString(i18n(
        "\"Always\" and \"Never\" mean what they usually mean\n"
        "\"When needed\" means \"when staves are too many to all fit"
        " in the current window\"")));

    tqlayout->addMultiCellWidget(m_showTrackHeaders, row, row, 1, 2);
    ++row;

    tqlayout->setRowSpacing(row, 20);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Show non-notation events as question marks"), frame),
         row, row, 0, 1);
    m_showUnknowns = new TQCheckBox(frame);
    bool defaultShowUnknowns = m_cfg->readBoolEntry("showunknowns", false);
    m_showUnknowns->setChecked(defaultShowUnknowns);
    tqlayout->addWidget(m_showUnknowns, row, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Show notation-quantized notes in a different color"), frame),
         row, row, 0, 1);
    m_colourQuantize = new TQCheckBox(frame);
    bool defaultColourQuantize = m_cfg->readBoolEntry("colourquantize", false);
    m_colourQuantize->setChecked(defaultColourQuantize);
    tqlayout->addWidget(m_colourQuantize, row, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Show \"invisible\" events in grey"), frame),
         row, row, 0, 1);
    m_showInvisibles = new TQCheckBox(frame);
    bool defaultShowInvisibles = m_cfg->readBoolEntry("showinvisibles", true);
    m_showInvisibles->setChecked(defaultShowInvisibles);
    tqlayout->addWidget(m_showInvisibles, row, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Show notes outside suggested playable range in red"), frame),
         row, row, 0, 1);
    m_showRanges = new TQCheckBox(frame);
    bool defaultShowRanges = m_cfg->readBoolEntry("showranges", true);
    m_showRanges->setChecked(defaultShowRanges);
    tqlayout->addWidget(m_showRanges, row, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Highlight superimposed notes with a halo effect"), frame),
         row, row, 0, 1);
    m_showCollisions = new TQCheckBox(frame);
    bool defaultShowCollisions = m_cfg->readBoolEntry("showcollisions", true);
    m_showCollisions->setChecked(defaultShowCollisions);
    tqlayout->addWidget(m_showCollisions, row, 2);
    ++row;

    tqlayout->setRowSpacing(row, 20);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("When recording MIDI, split-and-tie long notes at barlines"), frame),
         row, row, 0, 1);
    m_splitAndTie = new TQCheckBox(frame);
    bool defaultSplitAndTie = m_cfg->readBoolEntry("quantizemakeviable", false);
    m_splitAndTie->setChecked(defaultSplitAndTie);
    tqlayout->addWidget(m_splitAndTie, row, 2);
    ++row;

    tqlayout->setRowStretch(row, 10);


    addTab(frame, i18n("Layout"));



    frame = new TQFrame(m_tabWidget);
    tqlayout = new TQGridLayout(frame, 6, 3, 10, 5);

    row = 0;

    tqlayout->setRowSpacing(row, 15);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel(i18n("Default note style for new notes"), frame),
         row, row, 0, 1);

    tqlayout->setColStretch(2, 10);

    m_noteStyle = new KComboBox(frame);
    m_noteStyle->setEditable(false);
    m_untranslatedNoteStyle.clear();

    TQString defaultStyle =
        m_cfg->readEntry("style", strtoqstr(NoteStyleFactory::DefaultStyle));
    std::vector<NoteStyleName> styles
    (NoteStyleFactory::getAvailableStyleNames());

    for (std::vector<NoteStyleName>::iterator i = styles.begin();
            i != styles.end(); ++i) {

        TQString styleTQName(strtoqstr(*i));
        m_untranslatedNoteStyle.append(styleTQName);
        m_noteStyle->insertItem(i18n(styleTQName.utf8()));
        if (styleTQName == defaultStyle) {
            m_noteStyle->setCurrentItem(m_noteStyle->count() - 1);
        }
    }

    tqlayout->addWidget(m_noteStyle, row, 2);
    ++row;

    tqlayout->setRowSpacing(row, 20);
    ++row;

    tqlayout->addWidget
    (new TQLabel(i18n("When inserting notes..."), frame), row, 0);

    int defaultInsertType = m_cfg->readNumEntry("inserttype", 0);

    m_insertType = new KComboBox(frame);
    m_insertType->setEditable(false);
    m_insertType->insertItem
    (i18n("Split notes into ties to make durations match"));
    m_insertType->insertItem(i18n("Ignore existing durations"));
    m_insertType->setCurrentItem(defaultInsertType);

    tqlayout->addMultiCellWidget(m_insertType, row, row, 1, 2);
    ++row;

    bool autoBeam = m_cfg->readBoolEntry("autobeam", true);

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Auto-beam on insert when appropriate"), frame),
         row, row, 0, 1);
    m_autoBeam = new TQCheckBox(frame);
    m_autoBeam->setChecked(autoBeam);
    tqlayout->addMultiCellWidget(m_autoBeam, row, row, 2, 2);

    ++row;

    bool collapse = m_cfg->readBoolEntry("collapse", false);

    tqlayout->addMultiCellWidget
        (new TQLabel
         (i18n("Collapse rests after erase"), frame),
         row, row, 0, 1);
    m_collapseRests = new TQCheckBox(frame);
    m_collapseRests->setChecked(collapse);
    tqlayout->addMultiCellWidget(m_collapseRests, row, row, 2, 2);
    ++row;

    tqlayout->setRowSpacing(row, 20);
    ++row;

    tqlayout->addWidget
    (new TQLabel(i18n("Default paste type"), frame), row, 0);

    m_pasteType = new KComboBox(frame);
    m_pasteType->setEditable(false);

    unsigned int defaultPasteType = m_cfg->readUnsignedNumEntry
                                    ("pastetype", PasteEventsCommand::Restricted);

    PasteEventsCommand::PasteTypeMap pasteTypes =
        PasteEventsCommand::getPasteTypes();

    for (PasteEventsCommand::PasteTypeMap::iterator i = pasteTypes.begin();
            i != pasteTypes.end(); ++i) {
        m_pasteType->insertItem(i->second);
    }

    m_pasteType->setCurrentItem(defaultPasteType);
    tqlayout->addMultiCellWidget(m_pasteType, row, row, 1, 2);
    ++row;

    tqlayout->setRowStretch(row, 10);

    addTab(frame, i18n("Editing"));



    frame = new TQFrame(m_tabWidget);
    tqlayout = new TQGridLayout(frame, 4, 2, 10, 5);
    
    row = 0;

    tqlayout->setRowSpacing(row, 15);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Accidentals in one octave..."), frame), row, 0);
    m_accOctavePolicy = new KComboBox(frame);
    m_accOctavePolicy->insertItem(i18n("Affect only that octave"));
    m_accOctavePolicy->insertItem(i18n("Require cautionaries in other octaves"));
    m_accOctavePolicy->insertItem(i18n("Affect all subsequent octaves"));
    int accOctaveMode = m_cfg->readNumEntry("accidentaloctavemode", 1);
    if (accOctaveMode >= 0 && accOctaveMode < 3) {
        m_accOctavePolicy->setCurrentItem(accOctaveMode);
    }
    tqlayout->addWidget(m_accOctavePolicy, row, 1);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Accidentals in one bar..."), frame), row, 0);
    m_accBarPolicy = new KComboBox(frame);
    m_accBarPolicy->insertItem(i18n("Affect only that bar"));
    m_accBarPolicy->insertItem(i18n("Require cautionary resets in following bar"));
    m_accBarPolicy->insertItem(i18n("Require explicit resets in following bar"));
    int accBarMode = m_cfg->readNumEntry("accidentalbarmode", 0);
    if (accBarMode >= 0 && accBarMode < 3) {
        m_accBarPolicy->setCurrentItem(accBarMode);
    }
    tqlayout->addWidget(m_accBarPolicy, row, 1);
    ++row;

    tqlayout->addWidget(new TQLabel(i18n("Key signature cancellation style"), frame), row, 0);
    m_keySigCancelMode = new KComboBox(frame);
    m_keySigCancelMode->insertItem(i18n("Cancel only when entering C major or A minor"));
    m_keySigCancelMode->insertItem(i18n("Cancel whenever removing sharps or flats"));
    m_keySigCancelMode->insertItem(i18n("Cancel always"));
    int cancelMode = m_cfg->readNumEntry("keysigcancelmode", 1);
    if (cancelMode >= 0 && cancelMode < 3) {
        m_keySigCancelMode->setCurrentItem(cancelMode);
    }
    tqlayout->addWidget(m_keySigCancelMode, row, 1);
    ++row;

    tqlayout->setRowStretch(row, 10);

    addTab(frame, i18n("Accidentals"));

/*
    TQString preamble =
        (i18n("Rosegarden can apply automatic quantization to recorded "
              "or imported MIDI data for notation purposes only. "
              "This does not affect playback, and does not affect "
              "editing in any of the views except notation."));

    // force to default of 2 if not used before
    int quantizeType = m_cfg->readNumEntry("quantizetype", 2);
    m_cfg->writeEntry("quantizetype", quantizeType);
    m_cfg->writeEntry("quantizenotationonly", true);

    m_quantizeFrame = new QuantizeParameters
                      (m_tabWidget, QuantizeParameters::Notation,
                       false, false, "Notation Options", preamble);

    addTab(m_quantizeFrame, i18n("Quantize"));
*/
    row = 0;

//    TQFrame *mainFrame = new TQFrame(m_tabWidget);
//    TQGridLayout *mainLayout = new TQGridLayout(mainFrame, 2, 4, 10, 5);

//    TQGroupBox *noteFontBox = new TQGroupBox(1, Horizontal, i18n("Notation font"), mainFrame);
//    TQGroupBox *otherFontBox = new TQGroupBox(1, Horizontal, i18n("Other fonts"), mainFrame);
//    TQGroupBox *descriptionBox = new TQGroupBox(1, Horizontal, i18n("Description"), mainFrame);

//    mainLayout->addWidget(noteFontBox, 0, 0);
//    mainLayout->addWidget(otherFontBox, 1, 0);

//    TQFrame *mainFrame = new TQFrame(m_tabWidget);
    frame = new TQFrame(m_tabWidget);
    tqlayout = new TQGridLayout(frame, 2, 4, 10, 5);

//    frame = new TQFrame(noteFontBox);
//    tqlayout = new TQGridLayout(frame, 5, 2, 10, 5);

    m_viewButton = 0;

    tqlayout->addWidget(new TQLabel(i18n("Notation font"), frame), 0, 0);

    m_font = new KComboBox(frame);

#ifdef HAVE_XFT
    m_viewButton = new TQPushButton(i18n("View"), frame);
    tqlayout->addMultiCellWidget(m_font, row, row, 1, 2);
    tqlayout->addWidget(m_viewButton, row, 3);
    TQObject::connect(m_viewButton, TQT_SIGNAL(clicked()),
                     this, TQT_SLOT(slotViewButtonPressed()));
#else
    tqlayout->addMultiCellWidget(m_font, row, row, 1, 3);
#endif
    m_font->setEditable(false);
    TQObject::connect(m_font, TQT_SIGNAL(activated(int)),
                     this, TQT_SLOT(slotFontComboChanged(int)));
    ++row;

    TQFrame *subFrame = new TQFrame(frame);
    TQGridLayout *subLayout = new TQGridLayout(subFrame,
                                             4, 2,  // nbrow, nbcol
                                             12, 2);

    TQFont font = m_font->font();
    font.setPointSize((font.pointSize() * 9) / 10);

    TQLabel *originLabel = new TQLabel(i18n("Origin:"), subFrame);
    originLabel->setFont(font);
    subLayout->addWidget(originLabel, 0, 0);

    TQLabel *copyrightLabel = new TQLabel(i18n("Copyright:"), subFrame);
    copyrightLabel->setFont(font);
    subLayout->addWidget(copyrightLabel, 1, 0);

    TQLabel *mappedLabel = new TQLabel(i18n("Mapped by:"), subFrame); 
    mappedLabel->setFont(font);
    subLayout->addWidget(mappedLabel, 2, 0);

    TQLabel *typeLabel = new TQLabel(i18n("Type:"), subFrame);
    typeLabel->setFont(font);
    subLayout->addWidget(typeLabel, 3, 0);

    m_fontOriginLabel = new TQLabel(subFrame);
    m_fontOriginLabel->setAlignment(TQt::WordBreak);
    m_fontOriginLabel->setFont(font);
//    m_fontOriginLabel->setFixedWidth(250);
    m_fontCopyrightLabel = new TQLabel(subFrame);
    m_fontCopyrightLabel->setAlignment(TQt::WordBreak);
    m_fontCopyrightLabel->setFont(font);
//    m_fontCopyrightLabel->setFixedWidth(250);
    m_fontMappedByLabel = new TQLabel(subFrame);
    m_fontMappedByLabel->setFont(font);
    m_fontTypeLabel = new TQLabel(subFrame);
    m_fontTypeLabel->setFont(font);
    subLayout->addWidget(m_fontOriginLabel, 0, 1);
    subLayout->addWidget(m_fontCopyrightLabel, 1, 1);
    subLayout->addWidget(m_fontMappedByLabel, 2, 1);
    subLayout->addWidget(m_fontTypeLabel, 3, 1);

    subLayout->setColStretch(1, 10);

    tqlayout->addMultiCellWidget(subFrame,
                               row, row,
                               0, 3);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel(i18n("Font size for single-staff views"), frame),
         row, row, 0, 1);
    m_singleStaffSize = new KComboBox(frame);
    m_singleStaffSize->setEditable(false);
    tqlayout->addMultiCellWidget(m_singleStaffSize, row, row, 2, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel(i18n("Font size for multi-staff views"), frame),
         row, row, 0, 1);
    m_multiStaffSize = new KComboBox(frame);
    m_multiStaffSize->setEditable(false);
    tqlayout->addMultiCellWidget(m_multiStaffSize, row, row, 2, 2);
    ++row;

    tqlayout->addMultiCellWidget
        (new TQLabel(i18n("Font size for printing (pt)"), frame),
         row, row, 0, 1);
    m_printingSize = new KComboBox(frame);
    m_printingSize->setEditable(false);
    tqlayout->addMultiCellWidget(m_printingSize, row, row, 2, 2);
    ++row;

    slotPopulateFontCombo(false);

    tqlayout->setRowSpacing(row, 15);
    ++row;

    TQFont defaultTextFont(NotePixmapFactory::defaultSerifFontFamily),
        defaultSansFont(NotePixmapFactory::defaultSansSerifFontFamily),
        defaultTimeSigFont(NotePixmapFactory::defaultTimeSigFontFamily);

    tqlayout->addWidget
        (new TQLabel(i18n("Text font"), frame), row, 0);
    m_textFont = new KFontRequester(frame);
    TQFont textFont = m_cfg->readFontEntry("textfont", &defaultTextFont);
    m_textFont->setFont(textFont);
    tqlayout->addMultiCellWidget(m_textFont, row, row, 1, 3);
    ++row;

    tqlayout->addWidget
        (new TQLabel(i18n("Sans-serif font"), frame), row, 0);
    m_sansFont = new KFontRequester(frame);
    TQFont sansFont = m_cfg->readFontEntry("sansfont", &defaultSansFont);
    m_sansFont->setFont(sansFont);
    tqlayout->addMultiCellWidget(m_sansFont, row, row, 1, 3);
    ++row;

/*!!! No -- not much point in having the time sig font here: it's only
 * used if the time sig characters are not found in the notation font,
 * and our default notation font has all the characters we need

    tqlayout->addWidget
        (new TQLabel(i18n("Time Signature font"), frame), row, 0);
    m_timeSigFont = new KFontRequester(frame);
    TQFont timeSigFont = m_cfg->readFontEntry("timesigfont", &defaultTimeSigFont);
    m_timeSigFont->setFont(timeSigFont);
    tqlayout->addMultiCellWidget(m_timeSigFont, row, row, 1, 3);
    ++row;
*/

//    addTab(mainFrame, i18n("Font"));
    addTab(frame, i18n("Font"));


}

void
NotationConfigurationPage::slotViewButtonPressed()
{
#ifdef HAVE_XFT
    std::string fontName = qstrtostr(m_untranslatedFont[m_font->currentItem()]);

    try {
        NoteFont *noteFont = NoteFontFactory::getFont
                             (fontName, NoteFontFactory::getDefaultSize(fontName));
        const NoteFontMap &map(noteFont->getNoteFontMap());
        TQStringList systemFontNames(map.getSystemFontNames());
        if (systemFontNames.count() == 0) {
            m_viewButton->setEnabled(false); // oops
        } else {
            NoteFontViewer *viewer =
                new NoteFontViewer(0, m_untranslatedFont[m_font->currentItem()],
                                   systemFontNames, 24);
            (void)viewer->exec(); // no return value
        }
    } catch (Exception f) {
        KMessageBox::error(0, i18n(strtoqstr(f.getMessage()).ascii()));
    }
#endif
}

void
NotationConfigurationPage::slotPopulateFontCombo(bool rescan)
{
    TQString defaultFont = m_cfg->readEntry
                          ("notefont", strtoqstr(NoteFontFactory::getDefaultFontName()));

    try {
        (void)NoteFontFactory::getFont
        (qstrtostr(defaultFont),
         NoteFontFactory::getDefaultSize(qstrtostr(defaultFont)));
    } catch (Exception e) {
        defaultFont = strtoqstr(NoteFontFactory::getDefaultFontName());
    }

    std::set
        <std::string> fs(NoteFontFactory::getFontNames(rescan));
    std::vector<std::string> f(fs.begin(), fs.end());
    std::sort(f.begin(), f.end());

    m_untranslatedFont.clear();
    m_font->clear();

    for (std::vector<std::string>::iterator i = f.begin(); i != f.end(); ++i) {
        TQString s(strtoqstr(*i));
        m_untranslatedFont.append(s);
        m_font->insertItem(i18n(s.utf8()));
        if (s == defaultFont)
            m_font->setCurrentItem(m_font->count() - 1);
    }

    slotFontComboChanged(m_font->currentItem());
}

void
NotationConfigurationPage::slotFontComboChanged(int index)
{
    std::string fontStr = qstrtostr(m_untranslatedFont[index]);

    populateSizeCombo(m_singleStaffSize, fontStr,
                      m_cfg->readUnsignedNumEntry
                      ("singlestaffnotesize",
                       NoteFontFactory::getDefaultSize(fontStr)));
    populateSizeCombo(m_multiStaffSize, fontStr,
                      m_cfg->readUnsignedNumEntry
                      ("multistaffnotesize",
                       NoteFontFactory::getDefaultSize(fontStr)));

    int printpt = m_cfg->readUnsignedNumEntry("printingnotesize", 5);
    for (int i = 2; i < 16; ++i) {
        m_printingSize->insertItem(TQString("%1").arg(i));
        if (i == printpt) {
            m_printingSize->setCurrentItem(m_printingSize->count() - 1);
        }
    }

    try {
        NoteFont *noteFont = NoteFontFactory::getFont
                             (fontStr, NoteFontFactory::getDefaultSize(fontStr));
        const NoteFontMap &map(noteFont->getNoteFontMap());
        m_fontOriginLabel->setText(i18n(strtoqstr(map.getOrigin()).ascii()));
        m_fontCopyrightLabel->setText(i18n(strtoqstr(map.getCopyright()).ascii()));
        m_fontMappedByLabel->setText(i18n(strtoqstr(map.getMappedBy()).ascii()));
        if (map.isSmooth()) {
            m_fontTypeLabel->setText(
                i18n("%1 (smooth)").arg(i18n(strtoqstr(map.getType()).ascii())));
        } else {
            m_fontTypeLabel->setText(
                i18n("%1 (jaggy)").arg(i18n(strtoqstr(map.getType()).ascii())));
        }
        if (m_viewButton) {
            m_viewButton->setEnabled(map.getSystemFontNames().count() > 0);
        }
    } catch (Exception f) {
        KMessageBox::error(0, i18n(strtoqstr(f.getMessage()).ascii()));
    }
}

void
NotationConfigurationPage::populateSizeCombo(TQComboBox *combo,
        std::string font,
        int defaultSize)
{
    std::vector<int> sizes = NoteFontFactory::getScreenSizes(font);
    combo->clear();

    for (std::vector<int>::iterator i = sizes.begin(); i != sizes.end(); ++i) {
        combo->insertItem(TQString("%1").arg(*i));
        if (*i == defaultSize)
            combo->setCurrentItem(combo->count() - 1);
    }
}

void
NotationConfigurationPage::apply()
{
    m_cfg->setGroup(NotationViewConfigGroup);

    m_cfg->writeEntry("notefont", m_untranslatedFont[m_font->currentItem()]);
    m_cfg->writeEntry("singlestaffnotesize",
                      m_singleStaffSize->currentText().toUInt());
    m_cfg->writeEntry("multistaffnotesize",
                      m_multiStaffSize->currentText().toUInt());
    m_cfg->writeEntry("printingnotesize",
                      m_printingSize->currentText().toUInt());
    m_cfg->writeEntry("textfont",
                      m_textFont->font());
    m_cfg->writeEntry("sansfont",
                      m_sansFont->font());
/*!!!
    m_cfg->writeEntry("timesigfont",
                      m_timeSigFont->font());
*/
    std::vector<int> s = NotationHLayout::getAvailableSpacings();
    m_cfg->writeEntry("spacing", s[m_spacing->currentItem()]);

    s = NotationHLayout::getAvailableProportions();
    m_cfg->writeEntry("proportion", s[m_proportion->currentItem()]);

    m_cfg->writeEntry("layoutmode", m_layoutMode->currentItem());
    m_cfg->writeEntry("colourquantize", m_colourQuantize->isChecked());
    m_cfg->writeEntry("showunknowns", m_showUnknowns->isChecked());
    m_cfg->writeEntry("showinvisibles", m_showInvisibles->isChecked());
    m_cfg->writeEntry("showranges", m_showRanges->isChecked());
    m_cfg->writeEntry("showcollisions", m_showCollisions->isChecked());
    m_cfg->writeEntry("shownotationheader",
                       m_showTrackHeaders->currentItem());
    m_cfg->writeEntry("style", m_untranslatedNoteStyle[m_noteStyle->currentItem()]);
    m_cfg->writeEntry("inserttype", m_insertType->currentItem());
    m_cfg->writeEntry("autobeam", m_autoBeam->isChecked());
    m_cfg->writeEntry("collapse", m_collapseRests->isChecked());
    m_cfg->writeEntry("pastetype", m_pasteType->currentItem());
    m_cfg->writeEntry("accidentaloctavemode", m_accOctavePolicy->currentItem());
    m_cfg->writeEntry("accidentalbarmode", m_accBarPolicy->currentItem());
    m_cfg->writeEntry("keysigcancelmode", m_keySigCancelMode->currentItem());

    m_cfg->writeEntry("quantizemakeviable", m_splitAndTie->isChecked());

//    (void)m_quantizeFrame->getQuantizer(); // this also writes to the config
}

}
#include "NotationConfigurationPage.moc"