1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: splitter.cpp,v 1.1.1.1 2003/10/27 18:54:59 wschweer Exp $
5 // (C) Copyright 1999 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 "splitter.h"
24 #include "xml.h"
25
26 #include <QList>
27 #include <QStringList>
28
29 namespace MusEGui {
30
31 //---------------------------------------------------------
32 // Splitter
33 //---------------------------------------------------------
34
Splitter(QWidget * parent,const char * name)35 Splitter::Splitter(QWidget* parent, const char* name)
36 : QSplitter(parent)
37 {
38 if(name)
39 setObjectName(name);
40 setOpaqueResize(true);
41 }
42
Splitter(Qt::Orientation o,QWidget * parent,const char * name)43 Splitter::Splitter(Qt::Orientation o, QWidget* parent, const char* name)
44 : QSplitter(o, parent)
45 {
46 if(name)
47 setObjectName(name);
48 setOpaqueResize(true);
49 }
50
51 //---------------------------------------------------------
52 // saveConfiguration
53 //---------------------------------------------------------
54
writeStatus(int level,MusECore::Xml & xml)55 void Splitter::writeStatus(int level, MusECore::Xml& xml)
56 {
57 QList<int> vl = sizes();
58 //xml.nput(level++, "<%s>", name());
59 xml.nput(level++, "<%s>", MusECore::Xml::xmlString(objectName()).toLatin1().constData());
60 QList<int>::iterator ivl = vl.begin();
61 for (; ivl != vl.end(); ++ivl) {
62 xml.nput("%d ", *ivl);
63 }
64 //xml.nput("</%s>\n", name());
65 xml.nput("</%s>\n", MusECore::Xml::xmlString(objectName()).toLatin1().constData());
66 }
67
68 //---------------------------------------------------------
69 // loadConfiguration
70 //---------------------------------------------------------
71
readStatus(MusECore::Xml & xml)72 void Splitter::readStatus(MusECore::Xml& xml)
73 {
74 QList<int> vl;
75
76 for (;;) {
77 MusECore::Xml::Token token = xml.parse();
78 const QString& tag = xml.s1();
79 switch (token) {
80 case MusECore::Xml::Error:
81 case MusECore::Xml::End:
82 return;
83 case MusECore::Xml::TagStart:
84 xml.unknown("Splitter");
85 break;
86 case MusECore::Xml::Text:
87 {
88 //QStringList sl = QStringList::split(' ', tag);
89 // QString::*EmptyParts is deprecated, use Qt::*EmptyParts, new as of 5.14.
90 #if QT_VERSION >= 0x050e00
91 QStringList sl = tag.split(QString(" "), Qt::SkipEmptyParts);
92 #else
93 QStringList sl = tag.split(QString(" "), QString::SkipEmptyParts);
94 #endif
95 for (QStringList::Iterator it = sl.begin(); it != sl.end(); ++it) {
96 int val = (*it).toInt();
97 vl.append(val);
98 }
99
100 // fix for allowing the arranger split to work nicely with old songs
101 // that have only two splitters, we add a first splitter with the
102 // standard strip width 53 pixels
103 if (objectName() == "split") {
104 if (vl.size() < 3) {
105 vl.prepend(53);
106 }
107 }
108 //
109 //
110 }
111 break;
112 case MusECore::Xml::TagEnd:
113 if (tag == objectName()) {
114 setSizes(vl);
115 return;
116 }
117 default:
118 break;
119 }
120 }
121 }
122
123 } // namespace MusEGui
124