📄 qmconfigdialog.cpp
字号:
/* qmconfigdialog.cpp * * $Id: qmconfigdialog.cpp,v 1.21 2002/03/14 09:42:28 amos Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team. See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmconfigdialog.h"#include <qfont.h>#include <qheader.h>#include <qlabel.h>#include <qlayout.h>#include <qlistview.h>#include <qpixmap.h>#include <qpushbutton.h>#include <qsplitter.h>#include <qwidgetstack.h>#include <qmap.h>#include "qmapollopage.h"#include "qmlogopage.h"#include "qmmpg123page.h"// #include "qmnonepage.h"#include "qmpixmapsupplier.h"#include "qmshortcutpage.h"#include "qmstuffpage.h"/** * \file qmconfigdialog.cpp * \brief Widget for changing the preferences *//*! \class QmConfigDialog qmconfigdialog.h \brief The configuration dialog. This is the configuration dialog in Apollo. It provides the user with a treeview on the left, and the right will change according to the item selected in the treeview. This is like the typical configuration dialog GUI design you'll find in many, if not most, applications today. One such example is the Netscape 'Preferences' dialog.*//*! Initializes the dialog.*/QmConfigDialog::QmConfigDialog( QWidget *parent, const char *name) : QDialog(parent, name, true), m_CurrentPageChanged(false){ setCaption(tr("Apollo - Settings")); QVBoxLayout *main = new QVBoxLayout(this, 2); QHBoxLayout *bottom = new QHBoxLayout; QSplitter *splitter = new QSplitter(this); m_pTree = new QListView(splitter); m_pTree->addColumn(tr("Settings")); m_pTree->header()->hide(); m_pTree->setRootIsDecorated(false); m_pTree->setMaximumWidth(150); QListViewItem *ui = new QListViewItem(m_pTree, tr("User interface")); ui->setExpandable(true); ui->setOpen(true); (void) new QListViewItem(ui, tr("Stuff")); (void) new QListViewItem(ui, tr("Shortcut keys")); QListViewItem *player = new QListViewItem(m_pTree, tr("Player")); player->setExpandable(true); player->setOpen(true); (void) new QListViewItem(player, tr("mpg123")); (void) new QListViewItem(m_pTree, tr("Information")); connect(m_pTree, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(selectionChanged(QListViewItem*))); m_pClose = new QPushButton(tr("&Close"), this); m_pApply = new QPushButton(tr("&Apply"), this); m_pApply->setEnabled(false); connect(m_pClose, SIGNAL(clicked()), this, SLOT(accept())); connect(m_pApply, SIGNAL(clicked()), this, SLOT(apply())); m_pStack = new QWidgetStack(splitter); bottom->addStretch(); bottom->addWidget(m_pApply); bottom->addWidget(m_pClose); main->addWidget(splitter); main->addLayout(bottom); resize(600, 400); setPage(tr("none"));}/*! Destroys the dialog.*/QmConfigDialog::~QmConfigDialog(){}voidQmConfigDialog::currentPageChanged(){ m_CurrentPageChanged = true; m_pApply->setEnabled(true);}/*! Shows the approriate page. */voidQmConfigDialog::selectionChanged( QListViewItem *i){ QString str = i->text(0); setPage(str);}/*! Saves the current page \sa accept()*/voidQmConfigDialog::apply(){ QmConfigPage *p = static_cast<QmConfigPage *>(m_pStack->visibleWidget()); p->save(); m_pApply->setEnabled(false); m_CurrentPageChanged = false;}/*! Calls askAboutApply() and then closes the dialog \sa apply() */voidQmConfigDialog::accept(){ askAboutApply(); QDialog::accept();}/*! Calls askAboutApply() and then closes the dialog \sa apply() */voidQmConfigDialog::reject(){ askAboutApply(); QDialog::reject();}/*! Shows the correct page according to the name \c name.*/voidQmConfigDialog::setPage( const QString &name){ QmConfigPage *w; askAboutApply(); if(name == tr("mpg123")) { if(m_Pages.find(tr("mpg123")) != m_Pages.end()) w = m_Pages[tr("mpg123")]; else { w = new QmMpg123Page(this); addPage(tr("mpg123"), w);// w = new QmMpg123Page(this);// m_Pages.insert(tr("mpg123"), w);// m_pStack->addWidget(w, m_Pages.count()); } } else if(name == tr("Shortcut keys")) { if(m_Pages.find(tr("Shortcut keys")) != m_Pages.end()) w = m_Pages[tr("Shortcut keys")]; else { w = new QmShortcutPage(this); addPage(tr("Shortcut keys"), w);// w = new QmShortcutPage(this);// m_Pages.insert(tr("Shortcut keys"), w);// m_pStack->addWidget(w, m_Pages.count()); } } else if(name == tr("Stuff")) { if(m_Pages.find(tr("Stuff")) != m_Pages.end()) w = m_Pages[tr("Stuff")]; else { w = new QmStuffPage(this); addPage(tr("Stuff"), w);// m_Pages.insert(tr("Stuff"), w);// m_pStack->addWidget(w, m_Pages.count()); } } else if(name == tr("Information")) { if(m_Pages.find(tr("Information")) != m_Pages.end()) w = m_Pages[tr("Information")]; else { w = new QmApolloPage(this); addPage(tr("Information"), w);// m_Pages.insert(tr("Information"), w);// m_pStack->addWidget(w, m_Pages.count()); } } else { if(m_Pages.find(tr("none")) != m_Pages.end()) w = m_Pages[tr("none")]; else {// w = new QmNonePage(this); w = new QmLogoPage(this); addPage(tr("none"), w); } } w->load(); m_pStack->raiseWidget(w);}/*! Inserts the page \a w with title \a name. The page will \e not be automatically shown, unless it's the very first page. */voidQmConfigDialog::addPage( const QString &name, QmConfigPage *w){ m_Pages.insert(name, w); m_pStack->addWidget(w, m_Pages.count());}/// \todo not sure which to use// /*!// Iterates through all the configuration pages and saves each one.// */// void// QmConfigDialog::accept()// {// QMap<QString, QmConfigPage*>::Iterator it;// for(it = m_Pages.begin(); it != m_Pages.end(); ++it)// {// it.data()->save();// }// w->load();// m_pStack->raiseWidget(w);// QDialog::accept();// }/*! If the current page is changed it pops up a modal apply/discard dialog, otherwise does noting.*/voidQmConfigDialog::askAboutApply(){ if (m_CurrentPageChanged) { AskDialog *tmp = new AskDialog (this); int applyp = tmp->exec(); delete tmp; if (applyp == QDialog::Accepted) static_cast<QmConfigPage*>(m_pStack->visibleWidget())->save(); else static_cast<QmConfigPage*>(m_pStack->visibleWidget())->discard(); m_pApply->setEnabled(false); m_CurrentPageChanged = false; }}QmConfigDialog::AskDialog::AskDialog(QWidget *parent) : QDialog(parent, "Apply changes?", true){ setCaption( "Apollo - Settings modified" ); QVBoxLayout* vb = new QVBoxLayout(this,8); vb->setAutoAdd(TRUE); (void) new QLabel( tr( "The settings has been modified but not applied.\n" "Do you want to apply the changes before exiting\n" "the settings or discard the changes?" ), this ); QHBox *hb = new QHBox(this); (void) new QLabel( hb ); QPushButton *ok = new QPushButton(tr("Apply"), hb); connect(ok, SIGNAL(clicked()), this, SLOT(accept())); (void) new QLabel( hb ); QPushButton *cancel = new QPushButton(tr("Discard"), hb); connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); (void) new QLabel( hb );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -