//========================================================= // MusE // Linux Music Editor // $Id: cobject.cpp,v 1.4 2004/02/02 12:10:09 wschweer Exp $ // // (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) // // 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; 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // //========================================================= #include "cobject.h" #include "xml.h" #include "gui.h" #include "globals.h" #include "app.h" #include "shortcuts.h" #include #include #include #include using std::list; using MusEGlobal::muse; namespace MusEGui { int TopWin::_widthInit[TOPLEVELTYPE_LAST_ENTRY]; int TopWin::_heightInit[TOPLEVELTYPE_LAST_ENTRY]; QByteArray TopWin::_toolbarSharedInit[TOPLEVELTYPE_LAST_ENTRY]; QByteArray TopWin::_toolbarNonsharedInit[TOPLEVELTYPE_LAST_ENTRY]; bool TopWin::_sharesWhenFree[TOPLEVELTYPE_LAST_ENTRY]; bool TopWin::_sharesWhenSubwin[TOPLEVELTYPE_LAST_ENTRY]; bool TopWin::_defaultSubwin[TOPLEVELTYPE_LAST_ENTRY]; bool TopWin::initInited=false; TopWin::TopWin(ToplevelType t, QWidget* parent, const char* name, Qt::WindowFlags f) : QMainWindow(parent, f) { _isDeleting = false; if (initInited==false) initConfiguration(); _type=t; setObjectName(QString(name)); // Allow multiple rows. Tim. //setDockNestingEnabled(true); setIconSize(ICON_SIZE); subwinAction=new QAction(tr("As subwindow"), this); subwinAction->setCheckable(true); connect(subwinAction, SIGNAL(toggled(bool)), SLOT(setIsMdiWin(bool))); shareAction=new QAction(tr("Shares tools and menu"), this); shareAction->setCheckable(true); connect(shareAction, SIGNAL(toggled(bool)), SLOT(shareToolsAndMenu(bool))); fullscreenAction=new QAction(tr("Fullscreen"), this); fullscreenAction->setCheckable(true); fullscreenAction->setChecked(false); fullscreenAction->setShortcut(shortcuts[SHRT_FULLSCREEN].key); connect(fullscreenAction, SIGNAL(toggled(bool)), SLOT(setFullscreen(bool))); mdisubwin=NULL; _sharesToolsAndMenu=_defaultSubwin[_type] ? _sharesWhenSubwin[_type] : _sharesWhenFree[_type]; if (_defaultSubwin[_type]) setIsMdiWin(true); if (_sharesToolsAndMenu) menuBar()->hide(); subwinAction->setChecked(isMdiWin()); shareAction->setChecked(_sharesToolsAndMenu); fullscreenAction->setEnabled(!isMdiWin()); if (mdisubwin) mdisubwin->resize(_widthInit[_type], _heightInit[_type]); else resize(_widthInit[_type], _heightInit[_type]); } //--------------------------------------------------------- // readStatus //--------------------------------------------------------- void TopWin::readStatus(MusECore::Xml& xml) { for (;;) { MusECore::Xml::Token token = xml.parse(); if (token == MusECore::Xml::Error || token == MusECore::Xml::End) break; QString tag = xml.s1(); switch (token) { case MusECore::Xml::TagStart: if (tag == "geometry_state") { if (!restoreGeometry(QByteArray::fromHex(xml.parse1().toAscii()))) fprintf(stderr,"ERROR: couldn't restore geometry. however, this is probably not really a problem.\n"); } else if (tag == "toolbars") { if (!sharesToolsAndMenu()) { if (!restoreState(QByteArray::fromHex(xml.parse1().toAscii()))) fprintf(stderr,"ERROR: couldn't restore toolbars. however, this is not really a problem.\n"); } else { _savedToolbarState=QByteArray::fromHex(xml.parse1().toAscii()); if (_savedToolbarState.isEmpty()) _savedToolbarState=_toolbarNonsharedInit[_type]; } } else if (tag == "shares_menu") { shareToolsAndMenu(xml.parseInt()); } else if (tag == "is_subwin") { setIsMdiWin(xml.parseInt()); } else xml.unknown("TopWin"); break; case MusECore::Xml::TagEnd: if (tag == "topwin") return; default: break; } } } //--------------------------------------------------------- // writeStatus //--------------------------------------------------------- void TopWin::writeStatus(int level, MusECore::Xml& xml) const { xml.tag(level++, "topwin"); // the order of these tags has a certain sense // changing it won't break muse, but it may break proper // restoring of the positions xml.intTag(level, "is_subwin", isMdiWin()); xml.strTag(level, "geometry_state", saveGeometry().toHex().data()); xml.intTag(level, "shares_menu", sharesToolsAndMenu()); if (!sharesToolsAndMenu()) xml.strTag(level, "toolbars", saveState().toHex().data()); else xml.strTag(level, "toolbars", _savedToolbarState.toHex().data()); xml.tag(level, "/topwin"); } void TopWin::hide() { if (mdisubwin) mdisubwin->close(); QMainWindow::hide(); } void TopWin::show() { if (mdisubwin) mdisubwin->show(); QMainWindow::show(); } void TopWin::setVisible(bool param) { if (mdisubwin) { if (param) mdisubwin->show(); else mdisubwin->close(); } QMainWindow::setVisible(param); } QMdiSubWindow* TopWin::createMdiWrapper() { if (mdisubwin==NULL) { mdisubwin = new QMdiSubWindow(); mdisubwin->setWidget(this); } return mdisubwin; } void TopWin::setIsMdiWin(bool val) { if (val) { if (!isMdiWin()) { _savedToolbarState = saveState(); int width_temp=width(); int height_temp=height(); bool vis=isVisible(); QMdiSubWindow* subwin = createMdiWrapper(); muse->addMdiSubWindow(subwin); subwin->resize(width_temp, height_temp); subwin->move(0,0); subwin->setVisible(vis); this->QMainWindow::show(); //bypass the delegation to the subwin if (_sharesToolsAndMenu == _sharesWhenFree[_type]) shareToolsAndMenu(_sharesWhenSubwin[_type]); fullscreenAction->setEnabled(false); fullscreenAction->setChecked(false); subwinAction->setChecked(true); muse->updateWindowMenu(); } else { if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(true) called, but window is already a MDI win\n"); } } else { if (isMdiWin()) { int width_temp=width(); int height_temp=height(); bool vis=isVisible(); QMdiSubWindow* mdisubwin_temp=mdisubwin; mdisubwin=NULL; setParent(NULL); mdisubwin_temp->hide(); delete mdisubwin_temp; resize(width_temp, height_temp); setVisible(vis); if (_sharesToolsAndMenu == _sharesWhenSubwin[_type]) shareToolsAndMenu(_sharesWhenFree[_type]); fullscreenAction->setEnabled(true); subwinAction->setChecked(false); muse->updateWindowMenu(); } else { if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(false) called, but window is not a MDI win\n"); } } } bool TopWin::isMdiWin() const { return (mdisubwin!=NULL); } void TopWin::insertToolBar(QToolBar*, QToolBar*) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::insertToolBar called, but it's not implemented! ignoring it\n"); } void TopWin::insertToolBarBreak(QToolBar*) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::insertToolBarBreak called, but it's not implemented! ignoring it\n"); } void TopWin::removeToolBar(QToolBar*) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::removeToolBar called, but it's not implemented! ignoring it\n"); } void TopWin::removeToolBarBreak(QToolBar*) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::removeToolBarBreak called, but it's not implemented! ignoring it\n"); } void TopWin::addToolBar(Qt::ToolBarArea, QToolBar* tb) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::addToolBar(Qt::ToolBarArea, QToolBar*) called, but it's not implemented!\nusing addToolBar(QToolBar*) instead\n"); addToolBar(tb);} void TopWin::addToolBar(QToolBar* toolbar) { _toolbars.push_back(toolbar); if (!_sharesToolsAndMenu) QMainWindow::addToolBar(toolbar); else toolbar->hide(); toolbar->setIconSize(ICON_SIZE); } QToolBar* TopWin::addToolBar(const QString& title) { QToolBar* toolbar = new QToolBar(title, this); addToolBar(toolbar); return toolbar; } void TopWin::shareToolsAndMenu(bool val) { if (_sharesToolsAndMenu == val) { if (MusEGlobal::debugMsg) printf("TopWin::shareToolsAndMenu() called but has no effect\n"); return; } _sharesToolsAndMenu = val; if (!val) { muse->shareMenuAndToolbarChanged(this, false); for (list::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) if (*it != NULL) { QMainWindow::addToolBar(*it); (*it)->show(); } else QMainWindow::addToolBarBreak(); restoreState(_savedToolbarState); _savedToolbarState.clear(); menuBar()->show(); } else { if (_savedToolbarState.isEmpty()) // this check avoids overwriting a previously saved state _savedToolbarState = saveState(); // (by setIsMdiWin) with a now incorrect (empty) state for (list::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) if (*it != NULL) { QMainWindow::removeToolBar(*it); // this does NOT delete the toolbar, which is good (*it)->setParent(NULL); } menuBar()->hide(); muse->shareMenuAndToolbarChanged(this, true); } shareAction->setChecked(val); } //--------------------------------------------------------- // storeInitialState //--------------------------------------------------------- void TopWin::storeInitialState() const { if (mdisubwin) { _widthInit[_type] = mdisubwin->width(); _heightInit[_type] = mdisubwin->height(); } else { _widthInit[_type] = width(); _heightInit[_type] = height(); } if (sharesToolsAndMenu()) { if (muse->getCurrentMenuSharingTopwin() == this) _toolbarSharedInit[_type] = muse->saveState(); } else _toolbarNonsharedInit[_type] = saveState(); } //initConfiguration() restores default "traditional muse" configuration void TopWin::initConfiguration() { if (initInited==false) { for (int i=0;igetCurrentMenuSharingTopwin()) muse->restoreState(_toolbarSharedInit[_type]); } else restoreState(_toolbarNonsharedInit[_type]); } void TopWin::restoreMainwinState() { if (sharesToolsAndMenu()) initTopwinState(); } QString TopWin::typeName(ToplevelType t) { switch (t) { case PIANO_ROLL: return tr("Piano roll"); case LISTE: return tr("List editor"); case DRUM: return tr("Drum editor"); case MASTER: return tr("Master track editor"); case LMASTER: return tr("Master track list editor"); case WAVE: return tr("Wave editor"); case CLIPLIST: return tr("Clip list"); case MARKER: return tr("Marker view"); case SCORE: return tr("Score editor"); case ARRANGER: return tr("Arranger"); default: return tr(""); } } void TopWin::setFullscreen(bool val) { if (val) showFullScreen(); else showNormal(); } void TopWin::resize(int w, int h) { QMainWindow::resize(w,h); if (isMdiWin()) mdisubwin->resize(w,h); } void TopWin::resize(const QSize& s) { resize(s.width(), s.height()); } } // namespace MusEGui