| 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 |
#include <qevent.h> |
| 27 |
#include <qwidgetaction.h> |
| 28 |
|
| 29 |
list<View*> View::s_views; |
| 30 |
AutoQSettings* View::s_settings = NULL; |
| 31 |
|
| 32 |
void View::saveAll() |
| 33 |
{ |
| 34 |
assert(s_settings!=NULL); |
| 35 |
|
| 36 |
for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it) |
| 37 |
{ |
| 38 |
s_settings->beginGroup((*it)->getName()); |
| 39 |
s_settings->setValue("show", (*it)->setting_show->isChecked()); |
| 40 |
(*it)->save(); |
| 41 |
s_settings->endGroup(); |
| 42 |
} |
| 43 |
} |
| 44 |
void View::loadAll() |
| 45 |
{ |
| 46 |
assert(s_settings!=NULL); |
| 47 |
|
| 48 |
for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it) |
| 49 |
{ |
| 50 |
s_settings->beginGroup((*it)->getName()); |
| 51 |
(*it)->setting_show->setChecked(s_settings->value("show", (*it)->setting_show->isChecked()).toBool()); |
| 52 |
(*it)->load(); |
| 53 |
s_settings->endGroup(); |
| 54 |
} |
| 55 |
} |
| 56 |
void View::clearAllSettings() |
| 57 |
{ |
| 58 |
assert(s_settings!=NULL); |
| 59 |
|
| 60 |
for(list<View*>::iterator it=s_views.begin(); it!=s_views.end(); ++it) |
| 61 |
{ |
| 62 |
s_settings->beginGroup((*it)->getName()); |
| 63 |
s_settings->remove("show"); |
| 64 |
(*it)->clearSettings(); |
| 65 |
s_settings->endGroup(); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
// ------------------------- instances --------------------------- |
| 70 |
|
| 71 |
View::View(const QString& name, QWidget* parent) |
| 72 |
: m_name(name) |
| 73 |
, m_parent(parent) |
| 74 |
, m_popup_menu(parent) |
| 75 |
{ |
| 76 |
// settings |
| 77 |
QWidgetAction* caption = new QWidgetAction(&m_popup_menu); |
| 78 |
caption->setDefaultWidget(new Title(QString("<b>%1</b>").arg(m_name), &m_popup_menu)); |
| 79 |
m_popup_menu.addAction(caption); |
| 80 |
|
| 81 |
m_popup_menu.addSeparator(); |
| 82 |
|
| 83 |
setting_show = new QAction(m_name, parent); |
| 84 |
setting_show->setCheckable(true); |
| 85 |
parent->connect(setting_show, SIGNAL(toggled(bool)), parent, SLOT(setVisible(bool))); |
| 86 |
setting_show->setToolTip(QObject::tr("%1").arg(m_name)); |
| 87 |
|
| 88 |
parent->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
| 89 |
|
| 90 |
s_views.push_back(this); |
| 91 |
} |
| 92 |
|
| 93 |
void View::mouseReleaseEvent(QMouseEvent* e) |
| 94 |
{ |
| 95 |
if(e->button()==Qt::RightButton) |
| 96 |
m_popup_menu.exec(e->globalPosition().toPoint()); |
| 97 |
} |
| 98 |
|
| 99 |
// ----------------------- LabeledSpinBox ------------------------ |
| 100 |
|
| 101 |
//LabeledSpinBox::LabeledSpinBox(int min, int max, int step, QWidget* parent) |
| 102 |
//: QWidget(parent) |
| 103 |
//{ |
| 104 |
// |
| 105 |
//} |
| 106 |
|