1 /***************************************************************************
2 ** **
3 ** Polyphone, a soundfont editor **
4 ** Copyright (C) 2013-2020 Davy Triponney **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Davy Triponney **
21 ** Website/Contact: https://www.polyphone-soundfonts.com **
22 ** Date: 01.01.2013 **
23 ***************************************************************************/
24
25 #include "treesplitter.h"
26 #include "contextmanager.h"
27
TreeSplitter(QWidget * parent,QWidget * left,QWidget * right)28 TreeSplitter::TreeSplitter(QWidget *parent, QWidget *left, QWidget *right) : QSplitter(Qt::Horizontal, parent)
29 {
30 // Initial the widgets
31 this->setHandleWidth(0);
32 this->addWidget(left);
33 this->addWidget(right);
34 this->setCollapsible(0, false);
35 this->setCollapsible(1, false);
36
37 // Restore the geometry
38 this->setSizes(fromVariantList(ContextManager::configuration()->getValue(
39 ConfManager::SECTION_DISPLAY, "tree_splitter_sizes",
40 QVariantList()).toList()));
41
42 // Reaction to a manual move
43 connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(splitterMoved(int, int)));
44 }
45
resizeEvent(QResizeEvent * event)46 void TreeSplitter::resizeEvent(QResizeEvent * event)
47 {
48 QSplitter::resizeEvent(event);
49 ContextManager::configuration()->setValue(ConfManager::SECTION_DISPLAY, "tree_splitter_sizes",
50 toVariantList(this->sizes()));
51 }
52
splitterMoved(int pos,int index)53 void TreeSplitter::splitterMoved(int pos, int index)
54 {
55 Q_UNUSED(pos)
56 Q_UNUSED(index)
57 ContextManager::configuration()->setValue(ConfManager::SECTION_DISPLAY, "tree_splitter_sizes",
58 toVariantList(this->sizes()));
59 }
60
toVariantList(QList<int> list)61 QVariantList TreeSplitter::toVariantList(QList<int> list)
62 {
63 QVariantList listRet;
64 foreach (int elt, list)
65 listRet << elt;
66 return listRet;
67 }
68
fromVariantList(QVariantList list)69 QList<int> TreeSplitter::fromVariantList(QVariantList list)
70 {
71 QList<int> listRet;
72 foreach (QVariant elt, list)
73 listRet << elt.toInt();
74 return listRet;
75 }
76