summaryrefslogtreecommitdiffstats
path: root/src/gui/studio/NameSetEditor.cpp
blob: d7917bfd449740439492250d732888bccaa08220 (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
/* -*- 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   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <richard.bown@ferventsoftware.com>
 
    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 "NameSetEditor.h"
#include "BankEditorDialog.h"
#include <kcompletion.h>
#include <kglobalsettings.h>
#include <klineedit.h>
#include <klocale.h>
#include <tqframe.h>
#include <tqgroupbox.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqtabwidget.h>
#include <tqtooltip.h>
#include <tqvbox.h>
#include <tqvgroupbox.h>
#include <tqwidget.h>
#include <iostream>

namespace Rosegarden
{

NameSetEditor::NameSetEditor(BankEditorDialog* bankEditor,
                             TQString title,
                             TQWidget* parent,
                             const char* name,
                             TQString headingPrefix,
                             bool showEntryButtons)
        : TQVGroupBox(title, parent, name),
        m_bankEditor(bankEditor),
        m_mainFrame(new TQFrame(this))
{
    m_mainLayout = new TQGridLayout(m_mainFrame,
                                   4,   // rows
                                   6,   // cols
                                   2); // margin

    // Librarian
    //
    TQGroupBox *groupBox = new TQGroupBox(2,
                                        Qt::Horizontal,
                                        i18n("Librarian"),
                                        m_mainFrame);
    m_mainLayout->addMultiCellWidget(groupBox, 0, 2, 3, 5);

    new TQLabel(i18n("Name"), groupBox);
    m_librarian = new TQLabel(groupBox);

    new TQLabel(i18n("Email"), groupBox);
    m_librarianEmail = new TQLabel(groupBox);

    TQToolTip::add
        (groupBox,
                i18n("The librarian maintains the Rosegarden device data for this device.\nIf you've made modifications to suit your own device, it might be worth\nliaising with the librarian in order to publish your information for the benefit\nof others."));

    TQTabWidget* tabw = new TQTabWidget(this);

    tabw->setMargin(10);

    TQHBox *h;
    TQVBox *v;
    TQHBox *numBox;

    unsigned int tabs = 4;
    unsigned int cols = 2;
    unsigned int labelId = 0;

    for (unsigned int tab = 0; tab < tabs; ++tab) {
        h = new TQHBox(tabw);

        for (unsigned int col = 0; col < cols; ++col) {
            v = new TQVBox(h);

            for (unsigned int row = 0; row < 128 / (tabs*cols); ++row) {
                numBox = new TQHBox(v);
                TQString numberText = TQString("%1").tqarg(labelId + 1);

                if (tab == 0 && col == 0 && row == 0) {
                    // Initial label; button to adjust whether labels start at 0 or 1
                    m_initialLabel = new TQPushButton(numberText, numBox);
                    connect(m_initialLabel,
                            TQT_SIGNAL(clicked()),
                            this,
                            TQT_SLOT(slotToggleInitialLabel()));
                } else {
                    TQLabel *label = new TQLabel(numberText, numBox);
                    label->setFixedWidth(40);
                    label->tqsetAlignment(AlignCenter);
                    m_labels.push_back(label);
                }



                if (showEntryButtons) {
                    TQPushButton *button = new TQPushButton("", numBox, numberText.ascii());
                    button->setMaximumWidth(40);
                    button->setMaximumHeight(20);
                    button->setFlat(true);
                    connect(button, TQT_SIGNAL(clicked()),
                            this, TQT_SLOT(slotEntryButtonPressed()));
                    m_entryButtons.push_back(button);
                }

                KLineEdit* lineEdit = new KLineEdit(numBox, numberText.ascii());
                lineEdit->setMinimumWidth(110);
                lineEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
                lineEdit->setCompletionObject(&m_completion);
                m_names.push_back(lineEdit);

                connect(m_names[labelId],
                        TQT_SIGNAL(textChanged(const TQString&)),
                        this,
                        TQT_SLOT(slotNameChanged(const TQString&)));

                ++labelId;
            }
        }

        tabw->addTab(h,
                     (tab == 0 ? headingPrefix + TQString(" %1 - %2") :
                      TQString("%1 - %2")).
                     arg(tab * (128 / tabs) + 1).
                     arg((tab + 1) * (128 / tabs)));
    }

    m_initialLabel->setMaximumSize(m_labels.front()->size());
}

void
NameSetEditor::slotToggleInitialLabel()
{
    TQString initial = m_initialLabel->text();

    // strip some unrequested nice-ification.. urg!
    if (initial.startsWith("&")) {
        initial = initial.right(initial.length() - 1);
    }

    bool ok;
    unsigned index = initial.toUInt(&ok);

    if (!ok) {
        std::cerr << "conversion of '"
        << initial.ascii()
        << "' to number failed"
        << std::endl;
        return ;
    }

    if (index == 0)
        index = 1;
    else
        index = 0;

    m_initialLabel->setText(TQString("%1").tqarg(index++));
    for (std::vector<TQLabel*>::iterator it( m_labels.begin() );
            it != m_labels.end();
            ++it) {
        (*it)->setText(TQString("%1").tqarg(index++));
    }
}

}
#include "NameSetEditor.moc"