1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: comboQuant.cpp,v 1.1.1.1 2003/10/27 18:54:52 wschweer Exp $
5 // (C) Copyright 2001 Werner Schweer (ws@seh.de)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; version 2 of
10 // the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 //=========================================================
22
23 #include <stdio.h>
24
25 #include <QTableWidget>
26 #include <QTableWidgetItem>
27 #include <QHeaderView>
28
29 #include "comboQuant.h"
30
31 namespace MusEGui {
32
33 static int quantTable[] = {
34 1, 16, 32, 64, 128, 256, 512, 1024,
35 1, 24, 48, 96, 192, 384, 768, 1536,
36 1, 36, 72, 144, 288, 576, 1152, 2304
37 };
38
39 static const char* quantStrings[] = {
40 QT_TRANSLATE_NOOP("MusEGui::ComboQuant", "Off"), "64T", "32T", "16T", "8T", "4T", "2T", "1T",
41 QT_TRANSLATE_NOOP("MusEGui::ComboQuant", "Off"), "64", "32", "16", "8", "4", "2", "1",
42 QT_TRANSLATE_NOOP("MusEGui::ComboQuant", "Off"), "64.", "32.", "16.", "8.", "4.", "2.", "1."
43 };
44
45 //---------------------------------------------------------
46 // ComboQuant
47 //---------------------------------------------------------
48
ComboQuant(QWidget * parent)49 ComboQuant::ComboQuant(QWidget* parent)
50 : QComboBox(parent)
51 {
52 ///Q3ListBox* qlist = new Q3ListBox(this);
53 ///qlist->setMinimumWidth(95);
54 //setListBox(qlist); ddskrjo
55 ///qlist->setColumnMode(3);
56
57
58 qlist = new QTableWidget(8, 3);
59 qlist->verticalHeader()->setDefaultSectionSize(22);
60 qlist->horizontalHeader()->setDefaultSectionSize(32);
61 qlist->setSelectionMode(QAbstractItemView::SingleSelection);
62 qlist->verticalHeader()->hide();
63 qlist->horizontalHeader()->hide();
64
65 qlist->setMinimumWidth(96);
66
67 setView(qlist);
68
69 ///for (int i = 0; i < 24; i++)
70 /// qlist->insertItem(tr(quantStrings[i]), i);
71 for (int j = 0; j < 3; j++)
72 for (int i = 0; i < 8; i++)
73 qlist->setItem(i, j, new QTableWidgetItem(tr(quantStrings[i + j * 8])));
74
75
76 connect(this, SIGNAL(activated(int)), SLOT(activated(int)));
77 }
78
79 //---------------------------------------------------------
80 // activated
81 //---------------------------------------------------------
82
activated(int)83 void ComboQuant::activated(int /*index*/)
84 {
85 ///emit valueChanged(quantTable[index]);
86 emit valueChanged(quantTable[qlist->currentRow() + qlist->currentColumn() * 8]);
87 }
88
89 //---------------------------------------------------------
90 // setQuant
91 //---------------------------------------------------------
92
setValue(int val)93 void ComboQuant::setValue(int val)
94 {
95 for (int i = 0; i < 24; i++) {
96 if (val == quantTable[i]) {
97 setCurrentIndex(i);
98 return;
99 }
100 }
101
102 for (unsigned i = 0; i < sizeof(quantTable)/sizeof(*quantTable); i++) {
103 if (val == quantTable[i]) {
104 setCurrentIndex(i);
105 return;
106 }
107 }
108 printf("ComboQuant::setValue(%d) not defined\n", val);
109 setCurrentIndex(0);
110 }
111
112 } // namespace MusEGui
113