Import fmit upstream version 0.97.6
[fmit.git] / src / modules / View.cpp
1 // Copyright 2005 "Gilles Degottex"
2
3 // This file is part of "Music"
4
5 // "Music" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
9 //
10 // "Music" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
20 #include "View.h"
21
22 #include <cassert>
23 #include <iostream>
24 using namespace std;
25 #include <qtooltip.h>
26
27 list<View*> View::s_views;
28 QSettings* View::s_settings = NULL;
29
30 void View::saveAll()
31 {
32         assert(s_settings!=NULL);
33
34         for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it)
35         {
36                 s_settings->beginGroup((*it)->getName());
37                 s_settings->writeEntry("show", (*it)->setting_show->isOn());
38                 (*it)->save();
39                 s_settings->endGroup();
40         }
41 }
42 void View::loadAll()
43 {
44         assert(s_settings!=NULL);
45
46         for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it)
47         {
48                 s_settings->beginGroup((*it)->getName());
49                 (*it)->setting_show->setOn(s_settings->readBoolEntry("show", (*it)->setting_show->isOn()));
50                 (*it)->load();
51                 s_settings->endGroup();
52         }
53 }
54 void View::clearAllSettings()
55 {
56         assert(s_settings!=NULL);
57
58         for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it)
59         {
60                 s_settings->beginGroup((*it)->getName());
61                 s_settings->removeEntry("show");
62                 (*it)->clearSettings();
63                 s_settings->endGroup();
64         }
65 }
66
67 // ------------------------- instances ---------------------------
68
69 View::View(const QString& name, QWidget* parent)
70 : m_name(name)
71 , m_parent(parent)
72 , m_popup_menu(parent)
73 {
74         // settings
75         m_popup_menu.insertItem(new Title("<b>"+QWidget::tr(m_name)+"</b>", &m_popup_menu));
76         m_popup_menu.insertSeparator();
77
78         setting_show = new QAction(parent);
79         setting_show->setMenuText(QWidget::tr("Show ")+getName()+QWidget::tr(" view"));
80         setting_show->setToggleAction(true);
81         parent->connect(setting_show, SIGNAL(toggled(bool)), parent, SLOT(setShown(bool)));
82         setting_show->setToolTip(QWidget::tr(m_name));
83
84         parent->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
85
86         s_views.push_back(this);
87 }
88
89 void View::mouseReleaseEvent(QMouseEvent* e)
90 {
91         if(e->button()==Qt::RightButton)
92                 m_popup_menu.exec(e->globalPos());
93 }
94
95 // ----------------------- LabeledSpinBox ------------------------
96
97 //LabeledSpinBox::LabeledSpinBox(int min, int max, int step, QWidget* parent)
98 //: QWidget(parent)
99 //{
100 //
101 //}
102